Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opt: fix remaining filters when using partitioned constraints
The index constraint code can use check expressions or partitioning information to better refine the spans. However, the code related to the handling of remaining filters is very fragile. For check constraints, the code needs to remove any remaining filters due to check constraints (to avoid unnecessary overhead). For the partitioning code, this is necessary for correctness - we can't have any "in-between" filters as part of the final remaining filters (see big comment in `GenerateConstrainedScans`). The code assumes that a remaining filter is identical to one of the input filters (and thus only keeps the remaining filters that are the same with an explicit filter); unfortunately, this is not necessarily the case - the library tries to simplify the filters w.r.t the spans to make them cheaper to evaluate. This change cleans this up by extending the index constraints library a little bit: we can now specify the "required" and "optional" filters separately, with the only difference being that optional filters don't generate remaining filters. This way we don't have to "guess" what filters we need to keep. Fixes #44154. Release note (bug fix): fixed invalid query results in some corner cases where part of a WHERE clause is incorrectly discarded.
- Loading branch information
1 parent
4654024
commit 789146a
Showing
7 changed files
with
185 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
index-constraints vars=(int, int) index=(@1) | ||
@1 > 2 AND @1 < 4 AND @2 = 2 | ||
---- | ||
[/3 - /3] | ||
Remaining filter: @2 = 2 | ||
|
||
index-constraints vars=(int, int) index=(@1) | ||
@1 > 2 | ||
optional: @1 < 4 AND @2 = 2 | ||
---- | ||
[/3 - /3] | ||
|
||
index-constraints vars=(int, int) index=(@1 desc, @2 desc) | ||
optional: @1 >= 2 AND @1 <= 4 AND @2 IN (1, 2, 3) | ||
---- | ||
[/4/3 - /2/1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.