You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Try to add a spill mem session var to config spill threshold. right now it is NOT auto tuned, but this can be done at
either plan time (we know global resource) or run time (we know real time resource). But later.
PR Type
Enhancement
Description
Add agg_spill_mem session variable to configure aggregate spill threshold
Propagate agg_spill_mem from query builder through plan nodes to runtime operators
Define memory size constants (KiB, MiB, GiB, TiB, PiB) in common package
Update protobuf definitions to include spill_mem field in Group and Node messages
Diagram Walkthrough
flowchart LR
A["Session Variable: agg_spill_mem"] --> B["QueryBuilder"]
B --> C["Plan Nodes"]
C --> D["Protobuf Messages"]
D --> E["Runtime Operators"]
E --> F["Group Operator"]
Loading
File Walkthrough
Relevant files
Configuration changes
1 files
variables.go
Register new `agg_spill_mem` session variable with default 1GiB
Below is a summary of compliance checks for this PR:
Security Compliance
⚪
Type assertion risk
Description: Changed defaulting logic returns literal 1 instead of assigning and returning the session variable value, which can cause a panic if a non-int64 value is present (type assertion on line 82) or logic errors due to unexpected defaulting. compiler_context.go [77-82]
Instead of the aggregation-specific agg_spill_mem parameter, consider a more generic one like operator_spill_mem. This would be more extensible for future memory-intensive operators like hash joins.
// pkg/frontend/variables.govargSysVarsDefs=map[string]SystemVariable{
"operator_spill_mem": { // or a more generic nameName: "operator_spill_mem",
// ... generic for all spillable operators
},
}
// pkg/sql/plan/query_builder.gotypeQueryBuilderstruct {
operatorSpillMemint64
}
func (builder*QueryBuilder) appendAggNode(...) {
aggNode:=&plan.Node{
SpillMem: builder.operatorSpillMem,
}
}
// In the future, for other operators:func (builder*QueryBuilder) appendJoinNode(...) {
joinNode:=&plan.Node{
SpillMem: builder.operatorSpillMem, // Reuse the same parameter
}
}
Suggestion importance[1-10]: 8
__
Why: This is a significant design suggestion that improves extensibility, as the related ticket mentions both hash aggregation and hash join spilling, but the PR only implements a specific agg_spill_mem parameter.
Medium
Possible issue
Handle variable resolution errors gracefully
Explicitly set aggSpillMem to its default value of 1 GiB if resolving the variable fails or the type assertion is unsuccessful, instead of silently defaulting to 0.
Why: The suggestion correctly identifies that failing to resolve the agg_spill_mem variable results in a zero value, which contradicts the defined default of 1 GiB and could lead to unexpected behavior or performance issues.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
What type of PR is this?
Which issue(s) this PR fixes:
issue #3433
What this PR does / why we need it:
Try to add a spill mem session var to config spill threshold. right now it is NOT auto tuned, but this can be done at
either plan time (we know global resource) or run time (we know real time resource). But later.
PR Type
Enhancement
Description
Add
agg_spill_memsession variable to configure aggregate spill thresholdPropagate
agg_spill_memfrom query builder through plan nodes to runtime operatorsDefine memory size constants (KiB, MiB, GiB, TiB, PiB) in common package
Update protobuf definitions to include
spill_memfield in Group and Node messagesDiagram Walkthrough
File Walkthrough
1 files
Register new `agg_spill_mem` session variable with default 1GiB14 files
Add memory size constants (KiB through PiB)Add `aggSpillMem` field to QueryBuilder structInitialize `aggSpillMem` from session variable in QueryBuilderSet `SpillMem` on aggregate nodes in DML operationsSet `SpillMem` on aggregate nodes for distinct optimizationSet `SpillMem` on aggregate nodes during pushdown optimizationSet `SpillMem` when rewriting DISTINCT to aggregateSet `SpillMem` on aggregate nodes in INSERT plansSet `SpillMem` on aggregate nodes in constraint plansAdd `spill_mem` field to Node message definitionAdd `spill_mem` field to Group message definitionAdd `SpillMem` field to Group operator structCopy `SpillMem` when duplicating and constructing Group operatorsConvert `SpillMem` between pipeline and VM operator representations1 files
Fix return statement in `GetLowerCaseTableNames` method2 files