Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
107146: opt: deflake join logic test r=DrewKimball a=DrewKimball

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 cockroachdb#107132

Release note: None

Co-authored-by: Drew Kimball <[email protected]>
  • Loading branch information
craig[bot] and DrewKimball committed Jul 19, 2023
2 parents b2ba2e5 + b7ccb81 commit c9fdac0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
6 changes: 3 additions & 3 deletions pkg/sql/logictest/testdata/logic_test/join
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 19 additions & 8 deletions pkg/sql/opt/xform/testdata/rules/join_order
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -3392,7 +3392,10 @@ Join Tree #1
│ ├── scan t106371
│ └── 1
├── distinct-on
│ ├── scan t106371
│ ├── select
│ │ ├── scan t106371
│ │ └── filters
│ │ └── y = 2
│ └── aggregations
│ └── first-agg
│ └── y
Expand All @@ -3405,7 +3408,10 @@ Vertexes
└── 1
B:
distinct-on
├── scan t106371
├── select
│ ├── scan t106371
│ └── filters
│ └── y = 2
└── aggregations
└── first-agg
└── y
Expand All @@ -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: ()
Expand Down

0 comments on commit c9fdac0

Please sign in to comment.