From 4395fb846a6b8432b5515456205cf7abc567ca0c Mon Sep 17 00:00:00 2001 From: Yahor Yuzefovich Date: Mon, 3 Feb 2020 14:00:28 -0800 Subject: [PATCH] colexec: reject CASE operator with Bytes output type Currently, there is a contradiction between the way CASE operator works (which populates its output in arbitrary order) and the flat bytes implementation of Bytes type (which prohibits sets in arbitrary order), so we reject such scenario to fall back to row-by-row engine. Release note: None --- pkg/sql/colexec/execplan.go | 10 +++++++++- pkg/sql/logictest/testdata/logic_test/vectorize | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/sql/colexec/execplan.go b/pkg/sql/colexec/execplan.go index ac6985483ec9..b01bf2fe13b5 100644 --- a/pkg/sql/colexec/execplan.go +++ b/pkg/sql/colexec/execplan.go @@ -1193,7 +1193,15 @@ func planProjectionOperators( buffer := NewBufferOp(input) caseOps := make([]Operator, len(t.Whens)) caseOutputType := typeconv.FromColumnType(t.ResolvedType()) - if caseOutputType == coltypes.Unhandled { + switch caseOutputType { + case coltypes.Bytes: + // Currently, there is a contradiction between the way CASE operator + // works (which populates its output in arbitrary order) and the flat + // bytes implementation of Bytes type (which prohibits sets in arbitrary + // order), so we reject such scenario to fall back to row-by-row engine. + return nil, resultIdx, ct, internalMemUsed, errors.Newf( + "unsupported type %s in CASE operator", t.ResolvedType().String()) + case coltypes.Unhandled: return nil, resultIdx, ct, internalMemUsed, errors.Newf( "unsupported type %s", t.ResolvedType().String()) } diff --git a/pkg/sql/logictest/testdata/logic_test/vectorize b/pkg/sql/logictest/testdata/logic_test/vectorize index f3af0fc100dd..3ae847b29b12 100644 --- a/pkg/sql/logictest/testdata/logic_test/vectorize +++ b/pkg/sql/logictest/testdata/logic_test/vectorize @@ -1083,3 +1083,13 @@ CREATE TABLE t44304(c0 INT); INSERT INTO t44304 VALUES (0) query I SELECT * FROM t44304 WHERE CASE WHEN t44304.c0 > 0 THEN NULL END ---- + +# Regression test for CASE operator and flat bytes. +statement ok +CREATE TABLE t44624(c0 STRING, c1 BOOL); INSERT INTO t44624(rowid, c0, c1) VALUES (0, '', true), (1, '', NULL) + +query TB +SELECT * FROM t44624 ORDER BY CASE WHEN c1 IS NULL THEN c0 WHEN true THEN c0 END +---- +· true +· NULL