-
Notifications
You must be signed in to change notification settings - Fork 4.1k
opt: filtersMatchAllLeftRows returns false positives #50059
Description
The filtersMatchAllLeftRows function in multiplicity_builder.go currently returns true when all filters conditions are either:
- Equating a column with itself.
- 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.