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 69.01874% with 281 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.40%. Comparing base (3d0afb0) to head (db51394).
⚠️ Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
src/planner/continuous_aggs_common.c 60.04% 82 Missing and 81 partials ⚠️
src/planner/continuous_agg_rewrites.c 76.30% 50 Missing and 41 partials ⚠️
src/planner/planner.c 60.00% 20 Missing and 2 partials ⚠️
src/ts_catalog/continuous_agg.c 64.28% 2 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8967      +/-   ##
==========================================
- Coverage   82.53%   82.40%   -0.14%     
==========================================
  Files         249      251       +2     
  Lines       48561    49142     +581     
  Branches    12395    12570     +175     
==========================================
+ Hits        40079    40494     +415     
- Misses       3512     3667     +155     
- Partials     4970     4981      +11     

☔ 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
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