Skip to content

Commit

Permalink
Merge pull request #78975 from mgartner/backport21.2-78685
Browse files Browse the repository at this point in the history
release-21.2: opt: do not cross-join input of semi-join
  • Loading branch information
mgartner authored Mar 29, 2022
2 parents d54f5b7 + 95a3656 commit fe7aaea
Show file tree
Hide file tree
Showing 5 changed files with 402 additions and 265 deletions.
30 changes: 30 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/lookup_join
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,36 @@ SELECT * FROM (VALUES (1), (2)) AS u(y) WHERE NOT EXISTS (
1
2

# Regression test for #78681. Ensure that invalid lookup joins are not created
# for semi joins.
statement ok
CREATE TABLE t78681 (
x INT NOT NULL CHECK (x in (1, 3)),
y INT NOT NULL,
PRIMARY KEY (x, y)
)

# Insert stats so that a lookup semi-join is selected.
statement ok
ALTER TABLE t78681 INJECT STATISTICS '[
{
"columns": ["x"],
"created_at": "2018-05-01 1:00:00.00000+00:00",
"row_count": 10000000,
"distinct_count": 2
}
]'

statement ok
INSERT INTO t78681 VALUES (1, 1), (3, 1)

query I rowsort
SELECT * FROM (VALUES (1), (2)) AS u(y) WHERE EXISTS (
SELECT * FROM t78681 t WHERE u.y = t.y
)
----
1

statement ok
CREATE TABLE lookup_expr (
r STRING NOT NULL CHECK (r IN ('east', 'west')),
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/logictest/testdata/logic_test/unique
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ INSERT INTO uniq_enum VALUES ('us-west', 'foo', 1, 1), ('eu-west', 'bar', 2, 2)
# index, and the prefix of the index is an enum. This case uses the default
# value for columns r and j.
statement error pgcode 23505 pq: duplicate key value violates unique constraint "unique_i"\nDETAIL: Key \(i\)=\(1\) already exists\.
INSERT INTO uniq_enum (s, i) VALUES ('foo', 1), ('bar', 2)
INSERT INTO uniq_enum (s, i) VALUES ('foo', 1), ('bar', 3)

query TTII colnames,rowsort
SELECT * FROM uniq_enum
Expand Down
Loading

0 comments on commit fe7aaea

Please sign in to comment.