Skip to content

Conversation

@natalya-aksman
Copy link
Member

@natalya-aksman natalya-aksman commented Nov 21, 2025

POC currently checks whether queries can be rewritten with Caggs and rewrites queries with Caggs if it can.

GUCs enable_cagg_rewites and cagg_rewrites_debug_info are OFF by default. If only cagg_rewrites_debug_info is ON diagnostics on whether query can be rewritten with Caggs will be printed but query won't be rewritten.

Only real-time Caggs are currently considered as candidates.
Reaggregation is out of scope for this POC i.e. we look for exact match on time buckets and aggregates provided by Caggs.

Validation methods in tsl/src/continuous_aggs/common.c were refactored and moved to src/planner/continuous_aggs_common.c so they could be reused by Cagg rewrites validations.

PG15 is currently not supported as view queries in PG15_LE have dummy range table entries which complicates expression matching. As we plan to stop PG15 support in 6 months it seems like an unnecessary complication to deal with.

TODO:

  • Comprehensive unit tests covering all negative and positive cases
  • Dealing with Hierarchical Caggs rewrites
  • Matching on equivalent expressions as in "a=5" matches "5=a".
  • Dealing with params, making sure all matches are done on immutable expressions.
  • Matching LATERAL subqueries in Caggs
  • Checking whether Caggs have active invalidations to exclude them from the candidates
  • Rewriting with UNION ALL on data above watermark instead of relying on Real-time Caggs.

@github-actions
Copy link

@melihmutlu, @svenklemm: please review this pull request.

Powered by pull-review

@natalya-aksman natalya-aksman marked this pull request as draft November 21, 2025 21:59
@natalya-aksman natalya-aksman force-pushed the poc_rewrite_queries_with_caggs branch 2 times, most recently from 76eabff to 259c405 Compare November 24, 2025 16:53
@codecov
Copy link

codecov bot commented Nov 24, 2025

Codecov Report

❌ Patch coverage is 81.43460% with 176 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.52%. Comparing base (27f3330) to head (cc21763).

Files with missing lines Patch % Lines
src/planner/continuous_aggs_common.c 73.38% 42 Missing and 65 partials ⚠️
src/planner/continuous_agg_rewrites.c 85.57% 32 Missing and 26 partials ⚠️
src/planner/planner.c 90.90% 2 Missing and 6 partials ⚠️
src/ts_catalog/continuous_agg.c 75.00% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8967      +/-   ##
==========================================
+ Coverage   82.42%   82.52%   +0.09%     
==========================================
  Files         243      245       +2     
  Lines       47916    48540     +624     
  Branches    12230    12424     +194     
==========================================
+ Hits        39497    40057     +560     
- Misses       3550     3626      +76     
+ Partials     4869     4857      -12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@natalya-aksman natalya-aksman force-pushed the poc_rewrite_queries_with_caggs branch 4 times, most recently from 24fb146 to a0273a4 Compare December 1, 2025 19:13
@natalya-aksman natalya-aksman force-pushed the poc_rewrite_queries_with_caggs branch from a0273a4 to db51394 Compare December 2, 2025 20:25
@natalya-aksman natalya-aksman force-pushed the poc_rewrite_queries_with_caggs branch 3 times, most recently from 7726617 to 5d112ca Compare December 17, 2025 22:34
@natalya-aksman natalya-aksman force-pushed the poc_rewrite_queries_with_caggs branch from 5d112ca to cc21763 Compare January 9, 2026 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants