Skip to content

Commit 5690d8d

Browse files
authored
fix(cubestore): Missing filter in the middle of an index prunes unnecessary partitions
1 parent d95e21b commit 5690d8d

File tree

1 file changed

+100
-1
lines changed

1 file changed

+100
-1
lines changed

rust/cubestore/cubestore/src/queryplanner/partition_filter.rs

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ impl MinMaxCondition {
9999
assert_eq!(n, max_row.len());
100100
let mut min_satisfied = false;
101101
let mut max_satisfied = false;
102+
let mut min_max_are_equal = true;
102103
for i in 0..n {
104+
if min_row[i] != max_row[i] {
105+
min_max_are_equal = false;
106+
}
103107
if !min_satisfied {
104108
if self.min[i].is_some() {
105109
match cmp_same_types(&max_row[i], self.min[i].as_ref().unwrap()) {
@@ -128,7 +132,7 @@ impl MinMaxCondition {
128132
}
129133
if max_satisfied && min_satisfied {
130134
//min and max value of the current part is equal so we can check rest of rows as separate range
131-
if min_row[i] == max_row[i] {
135+
if min_max_are_equal {
132136
min_satisfied = false;
133137
max_satisfied = false;
134138
} else {
@@ -1130,6 +1134,101 @@ mod tests {
11301134
assert!(!res);
11311135
}
11321136
#[test]
1137+
fn multipart_diffirent_conditions() {
1138+
let c = MinMaxCondition {
1139+
min: vec![
1140+
Some(TableValue::Int(90)),
1141+
Some(TableValue::Int(4)),
1142+
None,
1143+
Some(TableValue::Int(4)),
1144+
],
1145+
max: vec![
1146+
Some(TableValue::Int(90)),
1147+
Some(TableValue::Int(4)),
1148+
None,
1149+
Some(TableValue::Int(4)),
1150+
],
1151+
};
1152+
let res = c.can_match(
1153+
&[
1154+
TableValue::Int(90),
1155+
TableValue::Int(4),
1156+
TableValue::Int(10),
1157+
TableValue::Int(12),
1158+
],
1159+
&[
1160+
TableValue::Int(92),
1161+
TableValue::Int(1),
1162+
TableValue::Int(10),
1163+
TableValue::Int(12),
1164+
],
1165+
);
1166+
assert!(res);
1167+
1168+
let res = c.can_match(
1169+
&[
1170+
TableValue::Int(90),
1171+
TableValue::Int(3),
1172+
TableValue::Int(10),
1173+
TableValue::Int(12),
1174+
],
1175+
&[
1176+
TableValue::Int(92),
1177+
TableValue::Int(1),
1178+
TableValue::Int(10),
1179+
TableValue::Int(12),
1180+
],
1181+
);
1182+
assert!(res);
1183+
1184+
let res = c.can_match(
1185+
&[
1186+
TableValue::Int(90),
1187+
TableValue::Int(4),
1188+
TableValue::Int(10),
1189+
TableValue::Int(12),
1190+
],
1191+
&[
1192+
TableValue::Int(90),
1193+
TableValue::Int(4),
1194+
TableValue::Int(10),
1195+
TableValue::Int(12),
1196+
],
1197+
);
1198+
assert!(!res);
1199+
1200+
let res = c.can_match(
1201+
&[
1202+
TableValue::Int(90),
1203+
TableValue::Int(4),
1204+
TableValue::Int(10),
1205+
TableValue::Int(4),
1206+
],
1207+
&[
1208+
TableValue::Int(90),
1209+
TableValue::Int(4),
1210+
TableValue::Int(10),
1211+
TableValue::Int(4),
1212+
],
1213+
);
1214+
assert!(res);
1215+
let res = c.can_match(
1216+
&[
1217+
TableValue::Int(90),
1218+
TableValue::Int(4),
1219+
TableValue::Int(10),
1220+
TableValue::Int(2),
1221+
],
1222+
&[
1223+
TableValue::Int(90),
1224+
TableValue::Int(4),
1225+
TableValue::Int(10),
1226+
TableValue::Int(6),
1227+
],
1228+
);
1229+
assert!(res);
1230+
}
1231+
#[test]
11331232
fn multipart_open_end_conditions() {
11341233
let c = MinMaxCondition {
11351234
min: vec![Some(TableValue::Int(20)), None],

0 commit comments

Comments
 (0)