From d4a730cf126b5aad6e648abf702a88e9fd3ca0c6 Mon Sep 17 00:00:00 2001 From: Radu Berinde Date: Mon, 9 Sep 2019 19:33:03 -0400 Subject: [PATCH] opt: fix scalar building error handling We are incorrectly returning `nil` error in an error case. This leads to an assertion error instead of a "could not decorrelate subquery" error. Fixes #40590. Release note: None --- .../logictest/testdata/logic_test/apply_join | 33 +++++++++++++++++++ pkg/sql/opt/exec/execbuilder/relational.go | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/pkg/sql/logictest/testdata/logic_test/apply_join b/pkg/sql/logictest/testdata/logic_test/apply_join index 9b069f95abaf..9fbe76835c71 100644 --- a/pkg/sql/logictest/testdata/logic_test/apply_join +++ b/pkg/sql/logictest/testdata/logic_test/apply_join @@ -278,3 +278,36 @@ query II SELECT a, (SELECT a FROM y) FROM x ---- 1 1 + +# Regression test for #40590: non-executable apply join inside apply join. + +statement ok +CREATE TABLE IF NOT EXISTS tab_orig AS + SELECT + '2001-01-01'::TIMESTAMP + g * '1 day' AS _timestamp, + g AS _string + FROM + generate_series(NULL, NULL) AS g; + +statement error could not decorrelate subquery +SELECT + NULL +FROM + tab_orig AS tab_9962, + tab_orig AS tab_9963 + JOIN tab_orig AS tab_9964 ON true +WHERE + NOT + ( + tab_9964._timestamp + IN (SELECT tab_9962._timestamp) + OR EXISTS( + WITH + with_2063 AS (SELECT NULL) + SELECT + COALESCE( + tab_9962._string, + tab_9963._string + ) + ) + ) diff --git a/pkg/sql/opt/exec/execbuilder/relational.go b/pkg/sql/opt/exec/execbuilder/relational.go index 25c8ac38e608..89398a7b8f4c 100644 --- a/pkg/sql/opt/exec/execbuilder/relational.go +++ b/pkg/sql/opt/exec/execbuilder/relational.go @@ -666,7 +666,7 @@ func (b *Builder) buildApplyJoin(join memo.RelExpr) (execPlan, error) { if len(*filters) != 0 { onExpr, err = b.buildScalar(&ctx, filters) if err != nil { - return execPlan{}, nil + return execPlan{}, err } }