Skip to content

Commit 94d2667

Browse files
committed
feat(cubesql): Add zero_members_wrapper cost component
1 parent 3171514 commit 94d2667

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

rust/cubesql/cubesql/src/compile/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,7 +2274,7 @@ from
22742274
logical_plan.find_cube_scan().request,
22752275
V1LoadRequestQuery {
22762276
measures: Some(vec![]),
2277-
dimensions: Some(vec![]),
2277+
dimensions: Some(vec!["KibanaSampleDataEcommerce.order_date".to_string()]),
22782278
segments: Some(vec![]),
22792279
order: Some(vec![]),
22802280
ungrouped: Some(true),
@@ -7362,7 +7362,10 @@ ORDER BY "source"."str0" ASC
73627362
query_plan.as_logical_plan().find_cube_scan().request,
73637363
V1LoadRequestQuery {
73647364
measures: Some(vec![]),
7365-
dimensions: Some(vec![]),
7365+
dimensions: Some(vec![
7366+
"WideCube.dim1".to_string(),
7367+
"WideCube.dim2".to_string(),
7368+
]),
73667369
segments: Some(vec![]),
73677370
order: Some(vec![]),
73687371
ungrouped: Some(true),

rust/cubesql/cubesql/src/compile/rewrite/cost.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ impl BestCubePlan {
7878
_ => 0,
7979
};
8080

81+
let zero_members_wrapper = match enode {
82+
LogicalPlanLanguage::WrappedSelect(_) => 1,
83+
_ => 0,
84+
};
85+
8186
let cube_members = match enode {
8287
LogicalPlanLanguage::Measure(_) => 1,
8388
LogicalPlanLanguage::Dimension(_) => 1,
@@ -196,6 +201,7 @@ impl BestCubePlan {
196201
non_pushed_down_window,
197202
non_pushed_down_grouping_sets,
198203
non_pushed_down_limit_sort,
204+
zero_members_wrapper,
199205
cube_members,
200206
errors: this_errors,
201207
time_dimensions_used_as_dimensions,
@@ -247,6 +253,11 @@ pub struct CubePlanCost {
247253
filters: i64,
248254
structure_points: i64,
249255
filter_members: i64,
256+
// This is separate from both non_detected_cube_scans and cube_members
257+
// Because it's ok to use all members inside wrapper (so non_detected_cube_scans would be zero)
258+
// And we want to select representation with less members
259+
// But only when members are present!
260+
zero_members_wrapper: i64,
250261
cube_members: i64,
251262
errors: i64,
252263
time_dimensions_used_as_dimensions: i64,
@@ -350,6 +361,11 @@ impl CubePlanCost {
350361
non_pushed_down_limit_sort: self.non_pushed_down_limit_sort
351362
+ other.non_pushed_down_limit_sort,
352363
member_errors: self.member_errors + other.member_errors,
364+
zero_members_wrapper: (if other.cube_members == 0 {
365+
self.zero_members_wrapper
366+
} else {
367+
0
368+
}) + other.zero_members_wrapper,
353369
cube_members: self.cube_members + other.cube_members,
354370
errors: self.errors + other.errors,
355371
structure_points: self.structure_points + other.structure_points,
@@ -403,6 +419,8 @@ impl CubePlanCost {
403419
SortState::Current if top_down => self.non_pushed_down_limit_sort,
404420
_ => 0,
405421
},
422+
// Don't track state here: we want representation that have fewer wrappers with zero members _in total_
423+
zero_members_wrapper: self.zero_members_wrapper,
406424
cube_members: self.cube_members,
407425
errors: self.errors,
408426
structure_points: self.structure_points,

0 commit comments

Comments
 (0)