fix logic bug in check_index_scan() that swapped lhs/rhs but not the comparison op

This commit is contained in:
Jussi Saurio
2025-01-08 08:19:00 +02:00
parent 4a58898863
commit 925bd62cbc
2 changed files with 14 additions and 1 deletions

View File

@@ -743,9 +743,17 @@ impl Optimizable for ast::Expr {
rhs.check_index_scan(table_index, referenced_tables, available_indexes)?;
if rhs_index.is_some() {
// swap lhs and rhs
let swapped_operator = match *op {
ast::Operator::Equals => ast::Operator::Equals,
ast::Operator::Greater => ast::Operator::Less,
ast::Operator::GreaterEquals => ast::Operator::LessEquals,
ast::Operator::Less => ast::Operator::Greater,
ast::Operator::LessEquals => ast::Operator::GreaterEquals,
_ => unreachable!(),
};
let lhs_new = rhs.take_ownership();
let rhs_new = lhs.take_ownership();
*self = Self::Binary(Box::new(lhs_new), *op, Box::new(rhs_new));
*self = Self::Binary(Box::new(lhs_new), swapped_operator, Box::new(rhs_new));
return Ok(rhs_index);
}
Ok(None)

View File

@@ -338,3 +338,8 @@ do_execsql_test between-price-range-with-names {
AND (name = 'sweatshirt' OR name = 'sneakers');
} {5|sweatshirt|74.0
8|sneakers|82.0}
do_execsql_test where-between-true-and-2 {
select id from users where id between true and 2;
} {1
2}