Repository navigation
Support skip index analysis for mixed AND/OR filters - #87781
Conversation
|
Workflow [PR], commit [c3b3a2c] Summary: ❌
|
|
The failures in CI for |
|
Clean CI run at |
This comment was marked as resolved.
This comment was marked as resolved.
|
@shankar-iyer I plowed a bit through the code (sorry), you will nevertheless able to recognize it again. What we need to do to merge this PR:
|
No problem, only improves the code quality and reading!
I am adding a testcase in the next upload which has combinations of these 4 types. I have been manually testing over the last few weeks.
Will do
Yes, thanks! So, currently a predicate like |
| } | ||
|
|
||
| indexes->use_skip_indexes_for_disjunctions = settings[Setting::use_skip_indexes_for_disjunctions] | ||
| && !skip_indexes.useful_indices.empty() |
There was a problem hiding this comment.
03100_lwu_36_json_skip_indexes failure in previous commit :
Needs skip_indexes.useful_indices.size() > 1 so that extra processing is done only if 2 or more skip indices are involved. Otherwise, the extra processing will be done for a condition like A = 5 OR A = 6 which is redundant (existing code already handles A = 5 OR A = 6)
Resolves #75228
Background
Design
Assume this WHERE clause:
A = 5 OR B = 5 OR C = 5.The corresponding RPN is
A, B, OR, C, OR.We replace the literals by
unknownand getunknown(A), unknown(B), OR, unknown(C), OR.unknownis supposed to beTRUE(which makes it a no-op in the existing skip index analysis for AND).Now evaluate the skip index on A granule-by-granule. Suppose the skip index says "there could be matches". The sequence of RPN evaluation results will be
TRUE, TRUE, TRUE, TRUE, TRUE. The PR introduces a callbackUpdatePartialDisjunctionResultFnwhich updates results for each RPN element (= column). Skip index A evaluation will assumeTRUEforunknown(B)andunknown(C).Next, evaluate granule 2 using skip index A and suppose the skip index says "no row matches". Then the sequence of results for this granule is FALSE, TRUE, TRUE, TRUE, TRUE.
Evaluate all other granules in A using the skip index and save the result for each granule.
Now repeat the same for column B. Let’s say for granule 2, the check
B = 5again fails with skip index B. Then the sequence of RPN evaluation will beTRUE, FALSE, TRUE, TRUE, TRUE. The earlier saved partial result after skip index A for granule 2 wasFALSE, TRUE, TRUE, TRUE, TRUE. Now the saved partial result will be updated toFALSE, FALSE, TRUE, TRUE, TRUE.Let’s say granule 2 fails the skip index C check also. Then the final partial result state for granule 2 will be -
FALSE, FALSE, TRUE, FALSE, TRUEOnce all 3 skip indexes have been evaluated on a
part, we entermergePartialResultsForDisjunction(). Here, we go back to the original RPN skeleton -unknown(A), unknown(B), OR, unknown(C), ORand now for granule 2, we will evaluate the RPN skeleton with its corresponding partial results -
FALSE, FALSE, TRUE, FALSE, TRUE.unknown(A)isFALSE,unknown(B)isFALSE,unknown(C)is alsoFALSEfor granule 2. The RPN to be evaluated then isFALSE, FALSE, OR, FALSE, OR. The final result will beFALSEfor granule 2 and we can skip reading the actual granule.The code uses
boost::dynamic_bitset<> partial_eval_resultsfor tracking partial results for each mark as that is the fastest and low-memory instead of using something likeunordered_map<size_t, vector<bool>>This PR has a caveat: it doesn't support short-circuiting. All skip indexes are evaluated, even if an early evaluation of a skip index forces the WHERE clause to be false. Example:
x = 3 AND (y = 4 OR z = 5). If the skip index for x says for a granule that there are no matches, we probe y and z as well.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
ClickHouse now uses skip indexes to perform index analysis on WHERE clauses with mixed
AND- andOR-connected filter conditions. Previously, the WHERE clause needed to be a conjunction (AND) of filter conditions to utilize skip indexes. A new settinguse_skip_indexes_for_disjunctions(default: on) controls this feature. (issue #75228)