Skip to content

Commit d48b7bc

Browse files
authored
chore: refine cte profile (#18467)
* chore: refine cte profile * chore: add setting * make lint
1 parent 137b523 commit d48b7bc

File tree

5 files changed

+33
-9
lines changed

5 files changed

+33
-9
lines changed

src/query/settings/src/settings_default.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@ impl DefaultSettings {
228228
scope: SettingScope::Both,
229229
range: Some(SettingRange::Numeric(1..=1024)),
230230
}),
231+
("grouping_sets_channel_size", DefaultSettingValue {
232+
value: UserSettingValue::UInt64(2),
233+
desc: "Sets the channel size for grouping sets to union transformation.",
234+
mode: SettingMode::Both,
235+
scope: SettingScope::Both,
236+
range: Some(SettingRange::Numeric(1..=1024)),
237+
}),
231238
("max_storage_io_requests", DefaultSettingValue {
232239
value: UserSettingValue::UInt64(default_max_storage_io_requests),
233240
desc: "Sets the maximum number of concurrent storage I/O requests.",

src/query/settings/src/settings_getter_setter.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,16 @@ impl Settings {
877877
self.try_get_u64("max_spill_io_requests")
878878
}
879879

880+
// Get grouping_sets_channel_size.
881+
pub fn get_grouping_sets_channel_size(&self) -> Result<u64> {
882+
self.try_get_u64("grouping_sets_channel_size")
883+
}
884+
885+
// Set grouping_sets_channel_size.
886+
pub fn set_grouping_sets_channel_size(&self, val: u64) -> Result<()> {
887+
self.try_set_u64("grouping_sets_channel_size", val)
888+
}
889+
880890
pub fn get_short_sql_max_length(&self) -> Result<u64> {
881891
self.try_get_u64("short_sql_max_length")
882892
}

src/query/sql/src/executor/physical_plan.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,9 @@ impl PhysicalPlan {
10181018
.iter()
10191019
.map(|x| x.display_name.clone())
10201020
.join(", "),
1021+
PhysicalPlan::MaterializedCTE(v) => format!("CTE({})", v.cte_name),
1022+
PhysicalPlan::MaterializeCTERef(v) => format!("CTE_REF({})", v.cte_name),
1023+
10211024
_ => String::new(),
10221025
})
10231026
}

src/query/sql/src/planner/optimizer/optimizers/rule/agg_rules/rule_grouping_sets_to_union.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use crate::optimizer::ir::SExpr;
2727
use crate::optimizer::optimizers::rule::Rule;
2828
use crate::optimizer::optimizers::rule::RuleID;
2929
use crate::optimizer::optimizers::rule::TransformResult;
30+
use crate::optimizer::OptimizerContext;
3031
use crate::plans::walk_expr_mut;
3132
use crate::plans::Aggregate;
3233
use crate::plans::AggregateMode;
@@ -62,10 +63,11 @@ const ID: RuleID = RuleID::GroupingSetsToUnion;
6263
pub struct RuleGroupingSetsToUnion {
6364
id: RuleID,
6465
matchers: Vec<Matcher>,
66+
ctx: Arc<OptimizerContext>,
6567
}
6668

6769
impl RuleGroupingSetsToUnion {
68-
pub fn new() -> Self {
70+
pub fn new(ctx: Arc<OptimizerContext>) -> Self {
6971
Self {
7072
id: ID,
7173
// Aggregate
@@ -78,6 +80,7 @@ impl RuleGroupingSetsToUnion {
7880
children: vec![Matcher::Leaf],
7981
}],
8082
}],
83+
ctx,
8184
}
8285
}
8386
}
@@ -112,8 +115,15 @@ impl Rule for RuleGroupingSetsToUnion {
112115
let hash = hasher.finish();
113116
let temp_cte_name = format!("cte_groupingsets_{hash}");
114117

118+
let channel_size = self
119+
.ctx
120+
.get_table_ctx()
121+
.get_settings()
122+
.get_grouping_sets_channel_size()
123+
.unwrap_or(2);
124+
115125
let cte_materialized_sexpr = SExpr::create_unary(
116-
MaterializedCTE::new(temp_cte_name.clone(), None, Some(1)),
126+
MaterializedCTE::new(temp_cte_name.clone(), None, Some(channel_size as usize)),
117127
agg_input.clone(),
118128
);
119129

@@ -211,12 +221,6 @@ impl Rule for RuleGroupingSetsToUnion {
211221
}
212222
}
213223

214-
impl Default for RuleGroupingSetsToUnion {
215-
fn default() -> Self {
216-
Self::new()
217-
}
218-
}
219-
220224
struct ReplaceColumnForGroupingSetsVisitor {
221225
group_indexes: Vec<IndexType>,
222226
exclude_group_indexes: Vec<IndexType>,

src/query/sql/src/planner/optimizer/optimizers/rule/factory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl RuleFactory {
102102
RuleID::MergeEvalScalar => Ok(Box::new(RuleMergeEvalScalar::new())),
103103
RuleID::MergeFilter => Ok(Box::new(RuleMergeFilter::new())),
104104
RuleID::NormalizeScalarFilter => Ok(Box::new(RuleNormalizeScalarFilter::new())),
105-
RuleID::GroupingSetsToUnion => Ok(Box::new(RuleGroupingSetsToUnion::new())),
105+
RuleID::GroupingSetsToUnion => Ok(Box::new(RuleGroupingSetsToUnion::new(ctx))),
106106
RuleID::SplitAggregate => Ok(Box::new(RuleSplitAggregate::new())),
107107
RuleID::FoldCountAggregate => Ok(Box::new(RuleFoldCountAggregate::new())),
108108
RuleID::CommuteJoin => Ok(Box::new(RuleCommuteJoin::new())),

0 commit comments

Comments
 (0)