-
Notifications
You must be signed in to change notification settings - Fork 715
feat: cache hist query with non ts col order by #8837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: loaki07 <[email protected]>
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|
| Status | Total | Passed | Failed | Skipped | Flaky | Pass Rate | Duration |
|---|---|---|---|---|---|---|---|
| All tests passed | 364 | 340 | 0 | 19 | 5 | 93% | 4m 47s |
|
| Status | Total | Passed | Failed | Skipped | Flaky | Pass Rate | Duration |
|---|---|---|---|---|---|---|---|
| All tests passed | 364 | 344 | 0 | 19 | 1 | 95% | 4m 40s |
|
| Status | Total | Passed | Failed | Skipped | Flaky | Pass Rate | Duration |
|---|---|---|---|---|---|---|---|
| 1 test failed | 292 | 271 | 1 | 17 | 3 | 93% | 5m 18s |
Test Failure Analysis
- dashboard.spec.js: Timeout issues during chart rendering due to network delays
- dashboard UI testcases should update the line chart correctly when used camel case in custom sql query: Timeout waiting for page to load, exceeding 60 seconds.
Root Cause Analysis
- The timeout error in the test is likely related to recent changes in the dashboard rendering logic, as indicated by the extensive modifications in the dashboard.spec.js file.
Recommended Actions
- Increase the timeout duration in the test to accommodate longer load times.
- Optimize the SQL query used in the test to improve performance.
- Investigate network conditions or server response times during test execution.
Signed-off-by: loaki07 <[email protected]>
|
| Status | Total | Passed | Failed | Skipped | Flaky | Pass Rate | Duration |
|---|---|---|---|---|---|---|---|
| All tests passed | 365 | 343 | 0 | 19 | 3 | 94% | 4m 39s |
|
Failed to generate code suggestions for PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Greptile Summary
This PR adds caching support for histogram queries with non-timestamp column ORDER BY (e.g., ORDER BY count DESC). When such queries are detected, the cache system scans all hits to find min/max timestamps instead of using the fast first/last optimization.
Key Changes:
- Added
is_histogram_non_ts_orderflag toCacheQueryRequestto track histogram queries ordered by non-timestamp columns - Created utility functions
is_timestamp_field(),has_non_timestamp_ordering(), andextract_timestamp_range()inresult_utils.rs - Modified cache check logic in
cacher.rsto allow histogram queries even when ORDER BY is not on timestamp - Updated
write_results()to scan all hits for time range whenis_histogram_non_ts_order=true - Propagated flag through both standard and streaming cache write paths
Critical Issue Found:
- Logic inconsistency between cache check path (
cacher.rs:213-215) and cache write paths (mod.rs:427-433,streaming/cache.rs:84-90) - Cache check uses
has_non_timestamp_ordering()which checks if ANY ORDER BY field is non-timestamp (.any()) - Cache write paths only check if the FIRST ORDER BY field is non-timestamp (
.first()) - For multi-column ORDER BY like
ORDER BY _timestamp, count DESC, this creates a mismatch that could cause incorrect caching behavior
Confidence Score: 2/5
- This PR has a critical logic bug that will cause cache inconsistencies for multi-column ORDER BY clauses
- The inconsistent logic between cache check and cache write paths is a blocking issue. While the overall approach is sound, the
.any()vs.first()mismatch in ORDER BY field checking will cause the cache check to flag queries as non-time-ordered when they're actually time-ordered (if timestamp is first), leading to unnecessary full-scan overhead and potential cache key mismatches - Pay close attention to
src/service/search/cache/cacher.rsandsrc/service/search/cache/result_utils.rs- the logic bug must be fixed before merge
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| src/service/search/cache/cacher.rs | 2/5 | Added histogram non-ts ORDER BY detection with logic mismatch bug between cache check and write paths |
| src/service/search/cache/result_utils.rs | 2/5 | Added utility functions for timestamp range extraction, but has_non_timestamp_ordering() uses wrong logic (any vs first) |
| src/service/search/cache/mod.rs | 4/5 | Correctly checks only first ORDER BY field for histogram non-ts ordering, uses extract_timestamp_range() for time range calculation |
| src/service/search/streaming/cache.rs | 4/5 | Correctly checks only first ORDER BY field for histogram non-ts ordering in streaming path |
| src/common/meta/search.rs | 5/5 | Added well-documented is_histogram_non_ts_order flag to CacheQueryRequest struct |
Sequence Diagram
sequenceDiagram
participant Client
participant Cacher as cache/cacher.rs
participant Utils as cache/result_utils.rs
participant Mod as cache/mod.rs
participant Stream as streaming/cache.rs
participant Disk as Cache Storage
Client->>Cacher: check_cache()
Cacher->>Cacher: Detect is_histogram_query
Cacher->>Utils: has_non_timestamp_ordering(order_by, ts_col)
Note over Utils: BUG: Uses .any() checks ALL fields
Utils-->>Cacher: is_histogram_non_ts_order
Cacher->>Cacher: Set flag in CacheQueryRequest
Cacher->>Disk: Check for cached results
alt Cache Miss - Execute Query
Cacher-->>Mod: Execute query
Mod->>Mod: Get results with order_by_metadata
Mod->>Mod: Compute is_histogram_non_ts_order
Note over Mod: Only checks FIRST field (.first())
Mod->>Utils: extract_timestamp_range(hits, is_time_ordered)
Utils->>Utils: Scan all hits if !is_time_ordered
Utils-->>Mod: (min_ts, max_ts)
Mod->>Disk: write_results(is_histogram_non_ts_order)
else Streaming Path
Stream->>Stream: Compute is_histogram_non_ts_order
Note over Stream: Only checks FIRST field (.first())
Stream->>Mod: write_results()
Mod->>Utils: extract_timestamp_range()
Utils-->>Mod: (min_ts, max_ts)
Mod->>Disk: write_results()
end
Note over Cacher,Stream: INCONSISTENCY: cacher uses .any(), mod/stream use .first()
5 files reviewed, 2 comments
Signed-off-by: loaki07 <[email protected]>
Signed-off-by: loaki07 <[email protected]>
User description
ref: #8731
PR Type
Enhancement, Bug fix
Description
Cache support for histogram with non-TS ORDER BY
Scan all hits to compute time range
Preserve ORDER BY metadata in cache writes
Refactor utils for ORDER BY timestamp checks
Diagram Walkthrough
File Walkthrough
search.rs
Add non-TS histogram order flag to requestsrc/common/meta/search.rs
is_histogram_non_ts_ordertoCacheQueryRequestcacher.rs
Detect and flag non-TS ordered histogramssrc/service/search/cache/cacher.rs
is_histogram_non_ts_ordermod.rs
Compute and pass histogram order flag to writersrc/service/search/cache/mod.rs
extract_timestamp_rangeis_histogram_non_ts_orderon writewrite_resultsresult_utils.rs
Utilities for timestamp/order checks and range extractionsrc/service/search/cache/result_utils.rs
is_timestamp_fieldhelperhas_non_timestamp_orderingextract_timestamp_rangewith scan fallbackcache.rs
Streaming cache supports non-TS histogram orderingsrc/service/search/streaming/cache.rs
write_resultsmod.rs
Hardcode partition timing and countsrc/service/search/mod.rs
total_secs = 4(debug change)part_num = 10(debug change)