mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-29 14:04:22 +01:00
fix logic bug in check_index_scan() that swapped lhs/rhs but not the comparison op
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user