From 19a69e5970cd2e927f271758f211542b5201a04e Mon Sep 17 00:00:00 2001 From: jussisaurio Date: Sat, 27 Jul 2024 10:55:34 +0300 Subject: [PATCH] Don't evaluate left side of 'x IN (...)' if right side is empty --- core/translate/where_clause.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/translate/where_clause.rs b/core/translate/where_clause.rs index 4ac98c8d2..2a4d12e46 100644 --- a/core/translate/where_clause.rs +++ b/core/translate/where_clause.rs @@ -477,9 +477,6 @@ fn translate_condition_expr( // which is what SQLite also does for small lists of values. // TODO: Let's refactor this later to use a more efficient implementation conditionally based on the number of values. - let lhs_reg = program.alloc_register(); - let _ = translate_expr(program, select, lhs, lhs_reg, cursor_hint)?; - if rhs.is_none() { // If rhs is None, IN expressions are always false and NOT IN expressions are always true. if *not { @@ -506,6 +503,10 @@ fn translate_condition_expr( return Ok(()); } + // The left hand side only needs to be evaluated once we have a list of values to compare against. + let lhs_reg = program.alloc_register(); + let _ = translate_expr(program, select, lhs, lhs_reg, cursor_hint)?; + let rhs = rhs.as_ref().unwrap(); // The difference between a local jump and an "upper level" jump is that for example in this case: