diff --git a/rust/cubestore/cubestore-sql-tests/src/tests.rs b/rust/cubestore/cubestore-sql-tests/src/tests.rs index 7b662d463c4d8..bff0c3b276583 100644 --- a/rust/cubestore/cubestore-sql-tests/src/tests.rs +++ b/rust/cubestore/cubestore-sql-tests/src/tests.rs @@ -2868,23 +2868,27 @@ 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 = '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), ("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