From b7ccb818f5a9705ed6804bd19cb742f798ddad18 Mon Sep 17 00:00:00 2001 From: Drew Kimball Date: Tue, 18 Jul 2023 22:16:24 -0600 Subject: [PATCH] opt: deflake join logic test A recently added logic test depends on a `DISTINCT` choosing a specific row when de-duplicating, but this isn't guaranteed during execution. This patch deflakes the test by using a filter to ensure the expected row is returned. Fixes #107132 Release note: None --- pkg/sql/logictest/testdata/logic_test/join | 6 ++--- pkg/sql/opt/xform/testdata/rules/join_order | 27 +++++++++++++++------ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/pkg/sql/logictest/testdata/logic_test/join b/pkg/sql/logictest/testdata/logic_test/join index d78e5378a766..59a8030516ce 100644 --- a/pkg/sql/logictest/testdata/logic_test/join +++ b/pkg/sql/logictest/testdata/logic_test/join @@ -1213,7 +1213,7 @@ CREATE TABLE t106371 (x INT NOT NULL, y INT NOT NULL); INSERT INTO t106371 VALUES (1, 1), (1, 2); query IIII -SELECT * FROM (SELECT * FROM t106371 ORDER BY y DESC LIMIT 1) a -JOIN (SELECT DISTINCT ON (x) * FROM t106371) b ON a.x = b.x; +SELECT * FROM (SELECT * FROM t106371 ORDER BY y LIMIT 1) a +JOIN (SELECT DISTINCT ON (x) * FROM (SELECT * FROM t106371 WHERE y = 2)) b ON a.x = b.x; ---- -1 2 1 1 +1 1 1 2 diff --git a/pkg/sql/opt/xform/testdata/rules/join_order b/pkg/sql/opt/xform/testdata/rules/join_order index 563dbd7ab9ea..dde1cfbb9a0d 100644 --- a/pkg/sql/opt/xform/testdata/rules/join_order +++ b/pkg/sql/opt/xform/testdata/rules/join_order @@ -3381,8 +3381,8 @@ CREATE TABLE t106371 (x INT NOT NULL, y INT NOT NULL); # Don't add an "a.y = b.y" filter. reorderjoins -SELECT * FROM (SELECT * FROM t106371 ORDER BY y DESC LIMIT 1) a -JOIN (SELECT DISTINCT ON (x) * FROM t106371) b ON a.x = b.x; +SELECT * FROM (SELECT * FROM t106371 ORDER BY y LIMIT 1) a +JOIN (SELECT DISTINCT ON (x) * FROM (SELECT * FROM t106371 WHERE y = 2)) b ON a.x = b.x; ---- -------------------------------------------------------------------------------- Join Tree #1 @@ -3392,7 +3392,10 @@ Join Tree #1 │ ├── scan t106371 │ └── 1 ├── distinct-on - │ ├── scan t106371 + │ ├── select + │ │ ├── scan t106371 + │ │ └── filters + │ │ └── y = 2 │ └── aggregations │ └── first-agg │ └── y @@ -3405,7 +3408,10 @@ Vertexes └── 1 B: distinct-on - ├── scan t106371 + ├── select + │ ├── scan t106371 + │ └── filters + │ └── y = 2 └── aggregations └── first-agg └── y @@ -3428,15 +3434,20 @@ inner-join (hash) │ ├── columns: x:6!null y:7!null │ ├── grouping columns: x:6!null │ ├── key: (6) - │ ├── fd: (6)-->(7) - │ ├── scan t106371 - │ │ └── columns: x:6!null y:7!null + │ ├── fd: ()-->(7) + │ ├── select + │ │ ├── columns: x:6!null y:7!null + │ │ ├── fd: ()-->(7) + │ │ ├── scan t106371 + │ │ │ └── columns: x:6!null y:7!null + │ │ └── filters + │ │ └── y:7 = 2 [outer=(7), constraints=(/7: [/2 - /2]; tight), fd=()-->(7)] │ └── aggregations │ └── first-agg [as=y:7, outer=(7)] │ └── y:7 ├── top-k │ ├── columns: x:1!null y:2!null - │ ├── internal-ordering: -2 + │ ├── internal-ordering: +2 │ ├── k: 1 │ ├── cardinality: [0 - 1] │ ├── key: ()