Skip to content

opt: filtersMatchAllLeftRows returns false positives #50059

@DrewKimball

Description

@DrewKimball

The filtersMatchAllLeftRows function in multiplicity_builder.go currently returns true when all filters conditions are either:

  1. Equating a column with itself.
  2. Equating a foreign key column with the column it references.

The problem occurs when (for example) a table has two foreign keys and the filters conditions contain equalities involving both. Each equality may be guaranteed a match with some right row individually, but they aren't guaranteed to match on the same row. The current logic will return true in this situation even though a match isn't guaranteed.

Example:

CREATE TABLE parent (p INT PRIMARY KEY, a INT NOT NULL UNIQUE, b INT NOT NULL UNIQUE);
CREATE TABLE child (
    c INT PRIMARY KEY, 
    a INT NOT NULL REFERENCES parent(a), 
    b INT NOT NULL REFERENCES parent(b)
);
SELECT * FROM parent INNER JOIN child ON parent.a = child.a AND parent.b = child.b;

filtersMatchAllLeftRows will incorrectly return true for the "child" side of this join.

The logic needs to be changed so that either all filter conditions have to fall under the self-join case between the same two TableIDs or all filter conditions have to be equalities between columns from a single foreign key and its referenced columns.

Metadata

Metadata

Assignees

Labels

A-sql-optimizerSQL logical planning and optimizations.C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions