fix(sql): error on group by with many aggregate functions#6689
fix(sql): error on group by with many aggregate functions#6689bluestreak01 merged 4 commits intomasterfrom
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 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. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
[PR Coverage check]😍 pass : 159 / 163 (97.55%) file detail
|
nwoolmer
left a comment
There was a problem hiding this comment.
Looks good to me, this makes it 3/3 places fixed. Let's triple check there's no fourth area we missed!
Fixes #3326
This PR fixes bug where GROUP BY queries with many aggregate functions fail with "Bytecode is too long" error, and includes significant performance optimizations for the SQL optimizer to speed up query compilation. We had a number of places with O(n²) complexity.
For instance, the following query:
was taking 4 seconds to compile. With this patch, the compilation takes around 300ms.
List of Changes
1. GroupByFunctionsUpdaterFactory Fallback (core fix)
SimpleGroupByFunctionUpdater- a loop-based fallback implementation that avoids JVM bytecode limits2. O(1) Amortized Alias Generation (performance)
LowerCaseCharSequenceIntHashMapto track the next sequence number for each base aliasaliasSequenceMaptoQueryModel(per-model state) and separate maps for pivot/cursor aliases inSqlOptimiserandSqlParser3. O(n) Duplicate Aggregate Detection (performance)
compareNodesExact()comparison to detect duplicate aggregatesExpressionNode.deepHashCode()- only compares nodes when hashes collidedetectDuplicateAggregates()method inSqlOptimiser4. Optimized findColumnByAst (performance)
findColumnByAst()call inside theif (useOuterModel)check