mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-26 12:34:22 +01:00
Closes #2470 In a query like `SELECT * FROM t LEFT JOIN s ON t.a=s.a WHERE s.a = 'foo'` we can remove the LEFT JOIN because NULL values will be equal to 'foo'. In fact, we have this optimization already. However, there was a dumb bug where `WhereTerm`s involving this join still retained their `from_outer_join` state, resulting in forcing the evaluation of those terms at the original join index, which results in completely wrong bytecode if the join optimizer decides to reorder the join as `s JOIN t` instead. Effectively it will evaluate `t.a=s.a` after table `s` is open but table `t` is not open yet. This PR fixes that issue by clearing `from_outer_join` properly from the relevant `WhereTerm`s.