Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
release-19.2: opt: fix remaining filters when using partitioned constraints #44749
Backport 1/1 commits from #44668.
The index constraint code can use check expressions or partitioning
The code assumes that a remaining filter is identical to one of the
This change cleans this up by extending the index constraints library
Release note (bug fix): fixed invalid query results in some corner
Thanks to @mrigger for finding this bug.
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.