Faster
ORDER BY: the sort keys are now evaluated once per row instead of on
every comparison. WithLIMIT, a bounded Top-N heap also caps peak memory at
O(offset + limit) instead of O(N). Output is unchanged.
Changed
ORDER BY ... LIMITuses a bounded Top-N heap (FQL\Results\BoundedSortHeap)
instead of buffering and sorting the whole stream. Peak memory drops from O(N)
to O(offset + limit) — aLIMIT 10over a huge source keeps ~10 rows, not all
of them. A stable insertion-order tie-break keeps the output identical to the
oldusort()path (incl. multi-key and mixedASC/DESC).ORDER BYwithoutLIMITevaluates the keys once per row (decorate-sort-
undecorate) and sorts a permutation of indices, instead of re-evaluating the
expressions inside the comparator. Same memory, much faster (~6× on 1M rows).
Output identical —usortis stable on PHP 8+. Key extraction is shared with
the bounded path viacompileOrderings()/evaluateOrderKeys().
Added
FQL\Results\BoundedSortHeap— fixed-capacity Top-N heap for the bounded
sort path. Covered bytests/Results/BoundedSortHeapTest.php(targeted cases
plus 60 randomized scenarios cross-checked againstusort+array_slice).
What's Changed
- Bounded-heap Top-N sort for ORDER BY ... LIMIT by @iammartinbelobrad in #24
New Contributors
- @iammartinbelobrad made their first contribution in #24
Full Changelog: v3.2.1...v3.2.2