-
Notifications
You must be signed in to change notification settings - Fork 4.1k
sql: query planning/execution correctness bug on a vtable anti join #88096
Copy link
Copy link
Closed
Labels
A-sql-executionRelating to SQL execution.Relating to SQL execution.A-sql-optimizerSQL logical planning and optimizations.SQL logical planning and optimizations.C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.S-3-erroneous-edge-caseDatabase produces or stores erroneous data without visible error/warning, in rare edge cases.Database produces or stores erroneous data without visible error/warning, in rare edge cases.T-sql-queriesSQL Queries TeamSQL Queries Team
Description
Solution needed for #88061.
Describe the problem
It's a compound problem:
- PostgreSQL and CockroachDB return different results on a simple query containing a correlated join on a vtable;
- CockroachDB also returns inconsistent results depending on which predicate is added to the query, where PostgreSQL would return the same results in any case.
Close inspection of the query plan suggest that the virtual table lookup join (anti) may be inverting its boolean predicate condition.
How to reproduce
After initial:
create type mytype as enum('hello');Crdb returns conflicting results on the following queries:
SELECT *
FROM pg_type AS t
WHERE NOT EXISTS(SELECT 1 FROM pg_type AS el WHERE el.oid = t.typelem AND el.typarray = t.oid)
AND t.typname LIKE 'myt%'(here, the output is correct)
and
SELECT *
FROM pg_type AS t
WHERE t.typrelid = 0
AND NOT EXISTS(SELECT 1 FROM pg_type AS el WHERE el.oid = t.typelem AND el.typarray = t.oid)
AND t.typname LIKE 'myt%'(here, the output is incorrect)
In PostgreSQL, both queries return the same output, that of the first query above.
This suggests that the query plan for the 2nd query is incorrect.
cc @mgartner for triage.
Jira issue: CRDB-19682
Epic: CRDB-23454
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-sql-executionRelating to SQL execution.Relating to SQL execution.A-sql-optimizerSQL logical planning and optimizations.SQL logical planning and optimizations.C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.S-3-erroneous-edge-caseDatabase produces or stores erroneous data without visible error/warning, in rare edge cases.Database produces or stores erroneous data without visible error/warning, in rare edge cases.T-sql-queriesSQL Queries TeamSQL Queries Team
Type
Projects
Status
Done