Skip to content

Commit c17a108

Browse files
authored
chore(cubestore): Updated suboptimal conditions, check if columns in predicate and index match completely (#8605)
1 parent 25d2bf4 commit c17a108

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

rust/cubestore/cubestore-sql-tests/src/tests.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2868,23 +2868,27 @@ async fn physical_plan_flags(service: Box<dyn SqlClient>) {
28682868
// (query, is_optimal)
28692869
let cases = vec![
28702870
("SELECT SUM(hits) FROM s.Data", true),
2871-
("SELECT SUM(hits) FROM s.Data WHERE url = 'test'", true),
2872-
("SELECT SUM(hits) FROM s.Data WHERE url = 'test' AND day > 'test'", true),
2871+
("SELECT SUM(hits) FROM s.Data WHERE url = 'test'", false),
2872+
("SELECT SUM(hits) FROM s.Data WHERE url = 'test' AND day > 'test'", false),
28732873
("SELECT SUM(hits) FROM s.Data WHERE day = 'test'", false),
2874-
("SELECT SUM(hits) FROM s.Data WHERE url = 'test' AND day = 'test'", true),
2874+
("SELECT SUM(hits) FROM s.Data WHERE url = 'test' AND day = 'test'", false),
28752875
("SELECT SUM(hits) FROM s.Data WHERE url = 'test' AND category = 'test'", false),
2876-
("SELECT SUM(hits) FROM s.Data WHERE url = 'test' OR url = 'test_2'", true),
2876+
("SELECT SUM(hits) FROM s.Data WHERE url = 'test' OR url = 'test_2'", false),
28772877
("SELECT SUM(hits) FROM s.Data WHERE url = 'test' OR category = 'test'", false),
28782878
("SELECT SUM(hits) FROM s.Data WHERE (url = 'test' AND day = 'test') OR (url = 'test' AND category = 'test')", false),
2879-
("SELECT SUM(hits) FROM s.Data WHERE (url = 'test' AND day = 'test') OR (url = 'test_1' OR url = 'test_2')", true),
2879+
("SELECT SUM(hits) FROM s.Data WHERE (url = 'test' AND day = 'test') OR (url = 'test_1' OR url = 'test_2')", false),
28802880
("SELECT SUM(hits) FROM s.Data WHERE (url = 'test' AND day = 'test') OR (url = 'test_1' OR day = 'test_2')", false),
2881-
("SELECT SUM(hits) FROM s.Data WHERE (url = 'test' AND day = 'test') OR (url = 'test_1' OR day > 'test_2')", true),
2881+
("SELECT SUM(hits) FROM s.Data WHERE (url = 'test' AND day = 'test') OR (url = 'test_1' OR day > 'test_2')", false),
2882+
("SELECT SUM(hits) FROM s.Data WHERE (url = 'test' AND day = 'test' AND category = 'test')", true),
2883+
("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),
2884+
("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),
28822885
("SELECT SUM(hits) FROM s.Data WHERE url IN ('test_1', 'test_2')", false),
28832886
("SELECT SUM(hits) FROM s.Data WHERE url IS NOT NULL", false),
28842887
("SELECT SUM(hits), url FROM s.Data GROUP BY url", true),
28852888
("SELECT SUM(hits), url, day FROM s.Data GROUP BY url, day", true),
28862889
("SELECT SUM(hits), day FROM s.Data GROUP BY day", false),
28872890
("SELECT SUM(hits), day, category FROM s.Data GROUP BY day, category", false),
2891+
("SELECT SUM(hits), day, category FROM s.Data GROUP BY day, category", false)
28882892
];
28892893

28902894
for (query, expected_optimal) in cases {

rust/cubestore/cubestore/src/queryplanner/physical_plan_flags.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,12 @@ impl PhysicalPlanFlags {
8181

8282
if let Some(input_exec_any) = maybe_input_exec {
8383
if let Some(cte) = input_exec_any.downcast_ref::<CubeTableExec>() {
84-
let index_columns = cte.index_snapshot.index.row.columns();
84+
let sort_key_size = cte.index_snapshot.index.row.sort_key_size() as usize;
85+
let index_columns =
86+
cte.index_snapshot.index.row.columns()[..sort_key_size].to_vec();
8587
flags.predicate_sorted = Some(check_predicate_order(
8688
predicate_column_groups,
87-
index_columns,
89+
&index_columns,
8890
));
8991
}
9092
}
@@ -127,13 +129,13 @@ fn check_predicate_order(
127129
for index_name in &index_column_names {
128130
if eq_column_names.contains(index_name) {
129131
checked_length += 1;
130-
} else {
131-
if eq_column_names.len() > checked_length {
132-
return false;
133-
}
134-
continue 'group_loop;
135132
}
136133
}
134+
135+
if index_column_names.len() > checked_length {
136+
return false;
137+
}
138+
continue 'group_loop;
137139
}
138140

139141
true

0 commit comments

Comments
 (0)