mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-29 05:54:21 +01:00
This PR integrates virtual tables into the query optimizer. It is a follow-up to https://github.com/tursodatabase/turso/pull/1727. The most immediate improvement is better support for inner joins involving TVFs, particularly when TVF arguments are column references. ### Example The following two queries are semantically equivalent, but require different join orders to be valid: ```sql -- TVF depends on `t.id`, so `t` must be evaluated in outer loop SELECT t.id, series.value FROM target t, generate_series(t.id, 3) series; -- Equivalent query, but with reversed table order in the FROM clause SELECT t.id, series.value FROM generate_series(t.id, 3) series, target t; ``` Without optimizer integration, the second query would fail because the planner would attempt to evaluate `generate_series` before `t`. With this change, the optimizer detects column dependencies and produces the correct join order in both cases. ### TODO Support for outer joins with TVFs is still missing and will be addressed in a follow-up PR. Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com> Closes #2439