Skip to content

perf(sql): speed up min/max aggregates on designated timestamp#6593

Merged
bluestreak01 merged 4 commits intomasterfrom
puzpuzpuz_o1_min_max_designated_ts
Jan 5, 2026
Merged

perf(sql): speed up min/max aggregates on designated timestamp#6593
bluestreak01 merged 4 commits intomasterfrom
puzpuzpuz_o1_min_max_designated_ts

Conversation

@puzpuzpuz
Copy link
Copy Markdown
Contributor

In case of non-keyed GROUP BY queries with min()/max() functions over the designated timestamp column we can use O(1) operation (take the first/last value) instead of calling SIMD native function:

-- master: 21ms
-- patch: 1ms
SELECT MIN(EventTime), MAX(EventTime) FROM hits;

@puzpuzpuz puzpuzpuz self-assigned this Jan 4, 2026
@puzpuzpuz puzpuzpuz added SQL Issues or changes relating to SQL execution Performance Performance improvements labels Jan 4, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 4, 2026

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@puzpuzpuz puzpuzpuz force-pushed the puzpuzpuz_o1_min_max_designated_ts branch from e4a83d5 to abfcd56 Compare January 4, 2026 13:44
@bluestreak01
Copy link
Copy Markdown
Member

very cool PR @puzpuzpuz ! we also need this optimisation reflected in the query plan and have tests asserting the intended plan to ensure this perf optimisation does not regress

@puzpuzpuz puzpuzpuz marked this pull request as draft January 4, 2026 18:55
@puzpuzpuz puzpuzpuz marked this pull request as ready for review January 4, 2026 21:06
@puzpuzpuz
Copy link
Copy Markdown
Contributor Author

very cool PR @puzpuzpuz ! we also need this optimisation reflected in the query plan and have tests asserting the intended plan to ensure this perf optimisation does not regress

@bluestreak01 good idea. Addressed in 48de7da

@glasstiger
Copy link
Copy Markdown
Contributor

[PR Coverage check]

😍 pass : 45 / 45 (100.00%)

file detail

path covered line new line coverage
🔵 io/questdb/griffin/engine/groupby/vect/MaxDateVectorAggregateFunction.java 1 1 100.00%
🔵 io/questdb/griffin/engine/groupby/vect/AvgDoubleVectorAggregateFunction.java 1 1 100.00%
🔵 io/questdb/griffin/engine/groupby/vect/MaxLongVectorAggregateFunction.java 1 1 100.00%
🔵 io/questdb/griffin/engine/groupby/vect/AvgShortVectorAggregateFunction.java 1 1 100.00%
🔵 io/questdb/griffin/engine/groupby/vect/MinTimestampVectorAggregateFunction.java 8 8 100.00%
🔵 io/questdb/griffin/engine/groupby/vect/NSumDoubleVectorAggregateFunction.java 1 1 100.00%
🔵 io/questdb/griffin/engine/groupby/vect/AvgIntVectorAggregateFunction.java 1 1 100.00%
🔵 io/questdb/griffin/engine/groupby/vect/KSumDoubleVectorAggregateFunction.java 1 1 100.00%
🔵 io/questdb/griffin/engine/groupby/vect/MinShortVectorAggregateFunction.java 1 1 100.00%
🔵 io/questdb/griffin/SqlCodeGenerator.java 6 6 100.00%
🔵 io/questdb/griffin/engine/groupby/vect/MinDateVectorAggregateFunction.java 1 1 100.00%
🔵 io/questdb/griffin/engine/groupby/vect/MaxDoubleVectorAggregateFunction.java 1 1 100.00%
🔵 io/questdb/griffin/engine/groupby/vect/MinIntVectorAggregateFunction.java 1 1 100.00%
🔵 io/questdb/griffin/engine/groupby/vect/SumDoubleVectorAggregateFunction.java 1 1 100.00%
🔵 io/questdb/griffin/engine/groupby/vect/SumLong256VectorAggregateFunction.java 1 1 100.00%
🔵 io/questdb/griffin/engine/groupby/vect/SumShortVectorAggregateFunction.java 1 1 100.00%
🔵 io/questdb/griffin/engine/groupby/vect/SumLongVectorAggregateFunction.java 1 1 100.00%
🔵 io/questdb/griffin/engine/groupby/vect/AvgLongVectorAggregateFunction.java 1 1 100.00%
🔵 io/questdb/griffin/engine/groupby/vect/SumIntVectorAggregateFunction.java 1 1 100.00%
🔵 io/questdb/griffin/engine/groupby/vect/MinDoubleVectorAggregateFunction.java 1 1 100.00%
🔵 io/questdb/griffin/engine/groupby/vect/MaxShortVectorAggregateFunction.java 1 1 100.00%
🔵 io/questdb/griffin/engine/groupby/vect/MinLongVectorAggregateFunction.java 1 1 100.00%
🔵 io/questdb/griffin/engine/groupby/vect/MaxTimestampVectorAggregateFunction.java 11 11 100.00%

@bluestreak01 bluestreak01 merged commit 807cd23 into master Jan 5, 2026
43 checks passed
@bluestreak01 bluestreak01 deleted the puzpuzpuz_o1_min_max_designated_ts branch January 5, 2026 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Performance Performance improvements SQL Issues or changes relating to SQL execution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants