From 62cbd30b15b317e6743691579f4402a93f5bf6c1 Mon Sep 17 00:00:00 2001 From: Dmitriy Rusov Date: Wed, 21 Aug 2024 08:05:01 +0200 Subject: [PATCH 1/2] dev --- rust/cubestore/cubestore-sql-tests/src/tests.rs | 15 +++++++++------ .../src/queryplanner/physical_plan_flags.rs | 16 +++++++++------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/rust/cubestore/cubestore-sql-tests/src/tests.rs b/rust/cubestore/cubestore-sql-tests/src/tests.rs index 8d918cd7926c8..34cfa2b11d793 100644 --- a/rust/cubestore/cubestore-sql-tests/src/tests.rs +++ b/rust/cubestore/cubestore-sql-tests/src/tests.rs @@ -2867,23 +2867,26 @@ async fn physical_plan_flags(service: Box) { // (query, is_optimal) let cases = vec![ ("SELECT SUM(hits) FROM s.Data", true), - ("SELECT SUM(hits) FROM s.Data WHERE url = 'test'", true), - ("SELECT SUM(hits) FROM s.Data WHERE url = 'test' AND day > 'test'", true), + ("SELECT SUM(hits) FROM s.Data WHERE url = 'test'", false), + ("SELECT SUM(hits) FROM s.Data WHERE url = 'test' AND day > 'test'", false), ("SELECT SUM(hits) FROM s.Data WHERE day = 'test'", false), - ("SELECT SUM(hits) FROM s.Data WHERE url = 'test' AND day = 'test'", true), + ("SELECT SUM(hits) FROM s.Data WHERE url = 'test' AND day = 'test'", false), ("SELECT SUM(hits) FROM s.Data WHERE url = 'test' AND category = 'test'", false), - ("SELECT SUM(hits) FROM s.Data WHERE url = 'test' OR url = 'test_2'", true), + ("SELECT SUM(hits) FROM s.Data WHERE url = 'test' OR url = 'test_2'", false), ("SELECT SUM(hits) FROM s.Data WHERE url = 'test' OR category = 'test'", false), ("SELECT SUM(hits) FROM s.Data WHERE (url = 'test' AND day = 'test') OR (url = 'test' AND category = 'test')", false), - ("SELECT SUM(hits) FROM s.Data WHERE (url = 'test' AND day = 'test') OR (url = 'test_1' OR url = 'test_2')", true), + ("SELECT SUM(hits) FROM s.Data WHERE (url = 'test' AND day = 'test') OR (url = 'test_1' OR url = 'test_2')", false), ("SELECT SUM(hits) FROM s.Data WHERE (url = 'test' AND day = 'test') OR (url = 'test_1' OR day = 'test_2')", false), - ("SELECT SUM(hits) FROM s.Data WHERE (url = 'test' AND day = 'test') OR (url = 'test_1' OR day > 'test_2')", true), + ("SELECT SUM(hits) FROM s.Data WHERE (url = 'test' AND day = 'test') OR (url = 'test_1' OR day > 'test_2')", false), + ("SELECT SUM(hits) FROM s.Data WHERE (url = 'test' AND day = 'test' AND category = 'test')", true), + ("SELECT SUM(hits) FROM s.Data WHERE (url = 'test' AND day = 'test' AND category = 'test') OR (url = 'test_2' AND day = 'test_2' AND category = 'test_2')", true), ("SELECT SUM(hits) FROM s.Data WHERE url IN ('test_1', 'test_2')", false), ("SELECT SUM(hits) FROM s.Data WHERE url IS NOT NULL", false), ("SELECT SUM(hits), url FROM s.Data GROUP BY url", true), ("SELECT SUM(hits), url, day FROM s.Data GROUP BY url, day", true), ("SELECT SUM(hits), day FROM s.Data GROUP BY day", false), ("SELECT SUM(hits), day, category FROM s.Data GROUP BY day, category", false), + ("SELECT SUM(hits), day, category FROM s.Data GROUP BY day, category", false) ]; for (query, expected_optimal) in cases { diff --git a/rust/cubestore/cubestore/src/queryplanner/physical_plan_flags.rs b/rust/cubestore/cubestore/src/queryplanner/physical_plan_flags.rs index 786b338c34b83..82e16864135dd 100644 --- a/rust/cubestore/cubestore/src/queryplanner/physical_plan_flags.rs +++ b/rust/cubestore/cubestore/src/queryplanner/physical_plan_flags.rs @@ -81,10 +81,12 @@ impl PhysicalPlanFlags { if let Some(input_exec_any) = maybe_input_exec { if let Some(cte) = input_exec_any.downcast_ref::() { - let index_columns = cte.index_snapshot.index.row.columns(); + let sort_key_size = cte.index_snapshot.index.row.sort_key_size() as usize; + let index_columns = + cte.index_snapshot.index.row.columns()[..sort_key_size].to_vec(); flags.predicate_sorted = Some(check_predicate_order( predicate_column_groups, - index_columns, + &index_columns, )); } } @@ -127,13 +129,13 @@ fn check_predicate_order( for index_name in &index_column_names { if eq_column_names.contains(index_name) { checked_length += 1; - } else { - if eq_column_names.len() > checked_length { - return false; - } - continue 'group_loop; } } + + if index_column_names.len() > checked_length { + return false; + } + continue 'group_loop; } true From 93b612148120a8fca25677d6f1df144e1edc1b0e Mon Sep 17 00:00:00 2001 From: Dmitriy Rusov Date: Wed, 21 Aug 2024 08:27:59 +0200 Subject: [PATCH 2/2] add test --- rust/cubestore/cubestore-sql-tests/src/tests.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/rust/cubestore/cubestore-sql-tests/src/tests.rs b/rust/cubestore/cubestore-sql-tests/src/tests.rs index 34cfa2b11d793..13d9ac30e5309 100644 --- a/rust/cubestore/cubestore-sql-tests/src/tests.rs +++ b/rust/cubestore/cubestore-sql-tests/src/tests.rs @@ -2880,6 +2880,7 @@ async fn physical_plan_flags(service: Box) { ("SELECT SUM(hits) FROM s.Data WHERE (url = 'test' AND day = 'test') OR (url = 'test_1' OR day > 'test_2')", false), ("SELECT SUM(hits) FROM s.Data WHERE (url = 'test' AND day = 'test' AND category = 'test')", true), ("SELECT SUM(hits) FROM s.Data WHERE (url = 'test' AND day = 'test' AND category = 'test') OR (url = 'test_2' AND day = 'test_2' AND category = 'test_2')", true), + ("SELECT SUM(hits) FROM s.Data WHERE (url = 'test' AND day = 'test' AND category = 'test') OR (url = 'test_2' AND day = 'test_2' AND category > 'test_2')", false), ("SELECT SUM(hits) FROM s.Data WHERE url IN ('test_1', 'test_2')", false), ("SELECT SUM(hits) FROM s.Data WHERE url IS NOT NULL", false), ("SELECT SUM(hits), url FROM s.Data GROUP BY url", true),