mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-30 14:34:22 +01:00
closes #1185 ## The Problem: The underlying schema of virtual tables is hidden from the query planner, and it currently has no way of optimizing select queries with vtab table refs by using indexes or removing non-constant predicates. All vtabs are currently rewound completely each time and any conditional filtering is done in the vdbe layer instead of in the `VFilter`. ## The solution: Add xBestIndex to the vtab module API to let extensions return some `IndexInfo` that will allow the query planner to make better optimizations and possibly omit conditionals ## Examples: table `t`: vtab: (key, value) table `t2`: table: (a,b) ### Join where vtab is outer table:  Properly pushes predicate to VFilter, which receives the idx_str `key_eq` arg, telling it that there is a useable where clause on the key "index" ### Join where vtab is inner table:  Constraint is not sent because it is marked as unusable ### Where clause on "indexed" column:  Pushed down and the predicate is omitted from the VDBE layer. ### Where clause on regular column:  No idx info received from BestIndex, VDBE handles conditional. ## TODO: OrderBy info needs to be sent to xBestIndex and its not in a great position in `open_loop` currently Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com> Closes #1264