From 2afb586dc32bfcd1cba8671fa79fbd4b36fceee8 Mon Sep 17 00:00:00 2001 From: Mikhail Cheshkov Date: Tue, 29 Oct 2024 01:55:15 +0200 Subject: [PATCH] [WIP problem with aliasing+CubeScan+join+TD] feat(cubesql): Add zero_members_wrapper cost component --- rust/cubesql/cubesql/src/compile/mod.rs | 7 +++++-- .../cubesql/src/compile/rewrite/cost.rs | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/rust/cubesql/cubesql/src/compile/mod.rs b/rust/cubesql/cubesql/src/compile/mod.rs index 6f6ee121d3a14..7f42ad7e95d2e 100644 --- a/rust/cubesql/cubesql/src/compile/mod.rs +++ b/rust/cubesql/cubesql/src/compile/mod.rs @@ -2274,7 +2274,7 @@ from logical_plan.find_cube_scan().request, V1LoadRequestQuery { measures: Some(vec![]), - dimensions: Some(vec![]), + dimensions: Some(vec!["KibanaSampleDataEcommerce.order_date".to_string()]), segments: Some(vec![]), order: Some(vec![]), ungrouped: Some(true), @@ -7323,7 +7323,10 @@ ORDER BY "source"."str0" ASC query_plan.as_logical_plan().find_cube_scan().request, V1LoadRequestQuery { measures: Some(vec![]), - dimensions: Some(vec![]), + dimensions: Some(vec![ + "WideCube.dim1".to_string(), + "WideCube.dim2".to_string(), + ]), segments: Some(vec![]), order: Some(vec![]), ungrouped: Some(true), diff --git a/rust/cubesql/cubesql/src/compile/rewrite/cost.rs b/rust/cubesql/cubesql/src/compile/rewrite/cost.rs index 83f23e6dedef1..6ae446860960b 100644 --- a/rust/cubesql/cubesql/src/compile/rewrite/cost.rs +++ b/rust/cubesql/cubesql/src/compile/rewrite/cost.rs @@ -78,6 +78,11 @@ impl BestCubePlan { _ => 0, }; + let zero_members_wrapper = match enode { + LogicalPlanLanguage::WrappedSelect(_) => 1, + _ => 0, + }; + let cube_members = match enode { LogicalPlanLanguage::Measure(_) => 1, LogicalPlanLanguage::Dimension(_) => 1, @@ -196,6 +201,7 @@ impl BestCubePlan { non_pushed_down_window, non_pushed_down_grouping_sets, non_pushed_down_limit_sort, + zero_members_wrapper, cube_members, errors: this_errors, time_dimensions_used_as_dimensions, @@ -247,6 +253,11 @@ pub struct CubePlanCost { filters: i64, structure_points: i64, filter_members: i64, + // This is separate from both non_detected_cube_scans and cube_members + // Because it's ok to use all members inside wrapper (so non_detected_cube_scans would be zero) + // And we want to select representation with less members + // But only when members are present! + zero_members_wrapper: i64, cube_members: i64, errors: i64, time_dimensions_used_as_dimensions: i64, @@ -350,6 +361,11 @@ impl CubePlanCost { non_pushed_down_limit_sort: self.non_pushed_down_limit_sort + other.non_pushed_down_limit_sort, member_errors: self.member_errors + other.member_errors, + zero_members_wrapper: (if other.cube_members == 0 { + self.zero_members_wrapper + } else { + 0 + }) + other.zero_members_wrapper, cube_members: self.cube_members + other.cube_members, errors: self.errors + other.errors, structure_points: self.structure_points + other.structure_points, @@ -403,6 +419,8 @@ impl CubePlanCost { SortState::Current if top_down => self.non_pushed_down_limit_sort, _ => 0, }, + // Don't track state here: we want representation that have fewer wrappers with zero members _in total_ + zero_members_wrapper: self.zero_members_wrapper, cube_members: self.cube_members, errors: self.errors, structure_points: self.structure_points,