Files
turso/sqlite
Mikaël Francoeur c1e146642d Merge 'core/optimizer: keep required sorts across hash joins' from may
(i ran out of pangram credits lol, unlike the previous pr)
fixes #8574
updated `plan_satisfies_order_target` to the ff
these can no longer supply final order:
- table used to build hash lokup
- if hash prep captures and removes an earlier group of loops
also made sure a separate ordered outer loop can avoid a sorter when it
survives unchanges and supplies the complete requested order
tried other approaches:
- disabling hash joins (throws away fast plans)
- adding a sorter everywhere (causes unnecessary sorts)
there is a case tho where the build side is proven to contain one fixed
value will still sort unnecessarily which can be skipped but i think its
negligible to account for because i don't think the benefits outweigh
the risk also the perf is negligible (~13ms)
perf-wise (apple m2):
| Case | Before | After | Change |
|---|---:|---:|---:|
| Affected `ORDER BY ... LIMIT 100`, 100k rows | 1123.78 ms | 2713.00 ms
| +141.4% |
| No-`ORDER BY` hash-join control | 22.395 ms/query | 21.626 ms/query |
-3.4% |
| Safe outer-order planning, 300 statements | 195.98 ms | 197.12 ms |
+0.6% |
| Constant-key ordered control | 4.928 ms/query | 4.915 ms/query | -0.3%
|
| Affected query peak RSS | 35.72 MiB | 50.91 MiB | +42.5% |
| No-`ORDER BY` control peak RSS | 38.72 MiB | 38.75 MiB | +0.1% |
before patch was faster because it skipped the required work to give the
correct order
used ai to help understand the issue further, and to help with
debugging, doing benchmarking performance and a bit of implementation,
implementation + refining was steered by me

Reviewed-by: Mikaël Francoeur (@LeMikaelF)
Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #8661
2026-09-11 11:43:15 -04:00
..