-
Notifications
You must be signed in to change notification settings - Fork 4.1k
opt: incorrect results due to cross-joining input of semi-join #78681
Copy link
Copy link
Closed
Labels
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.C-technical-advisoryCaused a technical advisoryCaused a technical advisoryS-0-visible-logical-errorDatabase stores inconsistent data in some cases, or queries return invalid results silently.Database stores inconsistent data in some cases, or queries return invalid results silently.T-sql-queriesSQL Queries TeamSQL Queries Teambranch-release-21.1Used to mark GA and release blockers, technical advisories, and bugs for 21.1Used to mark GA and release blockers, technical advisories, and bugs for 21.1branch-release-21.2Used to mark GA and release blockers, technical advisories, and bugs for 21.2Used to mark GA and release blockers, technical advisories, and bugs for 21.2
Metadata
Metadata
Assignees
Labels
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.C-technical-advisoryCaused a technical advisoryCaused a technical advisoryS-0-visible-logical-errorDatabase stores inconsistent data in some cases, or queries return invalid results silently.Database stores inconsistent data in some cases, or queries return invalid results silently.T-sql-queriesSQL Queries TeamSQL Queries Teambranch-release-21.1Used to mark GA and release blockers, technical advisories, and bugs for 21.1Used to mark GA and release blockers, technical advisories, and bugs for 21.1branch-release-21.2Used to mark GA and release blockers, technical advisories, and bugs for 21.2Used to mark GA and release blockers, technical advisories, and bugs for 21.2
Type
Projects
Status
Done
GenerateLookupJoinscan cross-join the input of the join with a set of constant values, from aCHECKconstraint, in order to constrain index prefix columns. This enables lookup joins to be generated in more cases. It is valid for inner joins, but it is not valid for left, anti, and semi joins. We currently disable this only for left and anti-joins, but not semi-joins. This incorrect transformation can cause incorrect query results.Example:
The query plan reveals the problem. Notice how the input to the semi-join is cross-joined with all the possible values of
b. This incorrectly increases the number of rows output by the join.Version Affected
This bug has been present since version 21.1.0 and affects all later releases.
Workaround
The best known workaround is 1) determine the prefix columns in the lookup join for which the cross join is created (
bin the example above) and 2) make that column nullable or remove theCHECKconstraint. This will prevent the incorrect lookup join from being generated.Jira issue: CRDB-14215
gz#11864