feat: initial implementation for range cache with time filters#8130
Open
evenyag wants to merge 3 commits into
Open
feat: initial implementation for range cache with time filters#8130evenyag wants to merge 3 commits into
evenyag wants to merge 3 commits into
Conversation
Signed-off-by: evenyag <realevenyag@gmail.com>
Contributor
There was a problem hiding this comment.
Code Review
This pull request improves range cache efficiency by introducing a mechanism to derive implied timestamp ranges from query predicates. This allows time-only filters to be safely removed from cache keys when they fully cover a partition's range, facilitating cache sharing between different queries. The review feedback suggests refining the logic for the Less Than operator to provide tighter bounds when literals are not aligned with the column's time unit, which would maximize cache hit opportunities.
Signed-off-by: evenyag <realevenyag@gmail.com>
Signed-off-by: evenyag <realevenyag@gmail.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I hereby agree to the terms of the GreptimeDB CLA.
Refer to a related PR or issue link (optional)
What's changed and what's your intention?
Revives the range-cache optimization that strips time-only predicates from the cache key when the query covers a partition's file-time range, so that different queries with different-but-equally-covering time bounds can share a cache entry. The previous version was disabled because its cover check (
extract_time_range_from_expr+ aTimestampRangecontainment test) was not a sound implication check and could let the cache serve rows that should have been filtered out.implied_time_range_from_exprsinread::range_cache, a per-expression walker over time-onlyExprnodes that returns aTimestampRangein which every predicate is provably true. It handles=,<,<=,>,>=,BETWEEN, and AND-composition; lower bounds round up and upper bounds round down on unit conversion so containment of the partition'sFileTimeRangeis a sound implication. It bails (returnsNone) on unsupported shapes —OR,NOT,NOT BETWEEN,IN, non-literal RHS, column-name mismatch, string-timestamp literals,=literals not exactly representable in the column unit, or overflow.build_range_cache_keynow callswithout_time_filters()only when the scan's implied range contains both the partition'sfile_minandfile_max; otherwise it keeps the full fingerprint. Asserts that the file timestamps and the implied range share the time index column'sTimeUnit.build_scan_fingerprintreturns a newScanFingerprintBundle({ fingerprint, implied_time_range }).StreamContextcarriesscan_implied_time_rangealongsidescan_fingerprint. Time-only exprs that the legacy extractor recognizes are routed into the implication walker; unrecognized ones stay infiltersand are never stripped.table::predicateexportsis_string_timestamp_literal, which now coversUtf8,LargeUtf8, andUtf8View. The existingreturn_none_if_utf8!macro and the new walker both use it to reject string-timestamp literals consistently.ORdisabling the optimization. Adds unit tests forimplied_time_range_from_exprscovering supported shapes, unsupported shapes, and cross-unit literal conversion.PR Checklist
Please convert it to a draft if some of the following conditions are not met.