Skip to content

Commit

Permalink
coldata: respect SelOnDest flag when setting nulls
Browse files Browse the repository at this point in the history
Previously, when setting nulls, we would always set it at the offset
from DestIdx. However, this is incorrect, when SelOnDest flag is true -
we need to set the null at selIdx. Now this is fixed.

Release note: None
  • Loading branch information
yuzefovich committed Sep 9, 2019
1 parent 746d213 commit 0d357b7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/col/coldata/vec_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ func _COPY_WITH_SEL(
nulls := args.Src.Nulls()
for i, selIdx := range sel[args.SrcStartIdx:args.SrcEndIdx] {
if nulls.NullAt64(uint64(selIdx)) {
// {{if .SelOnDest}}
// Remove an unused warning in some cases.
_ = i
m.nulls.SetNull64(uint64(selIdx))
// {{else}}
m.nulls.SetNull64(uint64(i) + args.DestIdx)
// {{end}}
} else {
v := execgen.UNSAFEGET(fromCol, int(selIdx))
// {{if .SelOnDest}}
Expand Down
14 changes: 14 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/dist_vectorize
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,17 @@ EXPLAIN (VEC, VERBOSE) SELECT count(*) FROM kv NATURAL INNER HASH JOIN kv kv2
└ *exec.HashRouter
└ *exec.CancelChecker
└ *distsqlrun.colBatchScan

# Test that SelOnDest flag of coldata.SliceArgs is respected when setting
# nulls.
statement ok
CREATE TABLE t1(a INT PRIMARY KEY, b INT)

statement ok
INSERT INTO t1 VALUES (1, NULL), (2, NULL)

query I rowsort
SELECT CASE WHEN a>1 THEN b*2 ELSE b*10 END FROM t1
----
NULL
NULL

0 comments on commit 0d357b7

Please sign in to comment.