Skip to content

Support Postgres filters in columnar aggregation#9443

Open
akuzm wants to merge 12 commits intotimescale:mainfrom
akuzm:filter-postgres
Open

Support Postgres filters in columnar aggregation#9443
akuzm wants to merge 12 commits intotimescale:mainfrom
akuzm:filter-postgres

Conversation

@akuzm
Copy link
Copy Markdown
Member

@akuzm akuzm commented Mar 25, 2026

For some filters we don't have a vectorized implementation, but can still evaluate them inside the columnar pipeline using our standard way to evaluate the Postgres function. This allows us to use columnar aggregation when such filters are present, speeding up the queries.

In tsbench, the queries speed up 2x to 30%, cagg refresh included: https://grafana.dev-us-east-1.ops.dev.timescale.com/d/fasYic_4z/compare-benchmark-runs?orgId=1&var-run1=5528&var-run2=5526&var-postgres=16&var-branch=All&var-threshold=0.02&var-use_historical_thresholds=true&var-threshold_expression=2.0%20%2A%20percentile_cont%280.90%29&var-exact_suite_version=false

For some filters we don't have a vectorized implementation, but can
still evaluate them inside the columnar pipeline using our standard way
to evaluate the Postgres function. This allows us to use columnar
aggregation when such filters are present, speeding up the queries.
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 25, 2026

Codecov Report

❌ Patch coverage is 95.58824% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
tsl/src/nodes/vector_agg/exec.c 95.83% 1 Missing and 1 partial ⚠️
tsl/src/nodes/vector_agg/plan.c 94.44% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 10, 2026

CLA assistant check
All committers have signed the CLA.

@akuzm akuzm force-pushed the filter-postgres branch from bc950a3 to 7477df9 Compare April 10, 2026 12:53
@akuzm akuzm force-pushed the filter-postgres branch from 65a98ce to 4ced119 Compare April 14, 2026 09:32
@akuzm akuzm marked this pull request as ready for review April 14, 2026 10:01
@akuzm akuzm requested a review from a team April 14, 2026 10:01
@github-actions github-actions bot requested review from dbeck and kpan2034 April 14, 2026 10:21
@github-actions
Copy link
Copy Markdown

@kpan2034, @dbeck: please review this pull request.

Powered by pull-review

Copy link
Copy Markdown
Member

@antekresic antekresic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of nits/questions otherwise lgtm

DecompressContext *dcontext = &decompress_state->decompress_context;
BatchQueue *batch_queue = decompress_state->batch_queue;
DecompressBatchState *batch_state = batch_array_get_at(&batch_queue->batch_array, 0);
List *pg_quals =
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really necessary to fetch these quals for every slot?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, maybe we could copy them into a VectorAggState field, but on the other hand it's just an array access.

Comment thread tsl/src/nodes/vector_agg/exec.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants