mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-24 19:44:21 +01:00
This PR implements the `Sequence` and `SequenceTest` opcodes, although does not yet add plumbing to emit the latter. SQLite has two distinct mechanisms that determine the final row order with aggregates: Traversal order of GROUP BY, and ORDER BY tiebreaking. When ORDER BY contains only aggregate expressions and/or constants, SQLite has no extra tiebreak key, but when ORDER BY mixes aggregate and non-aggregate terms, SQLite adds an implicit, stable row `sequence` so “ties” respect the input order. This PR also fixes an issue with a query like the following: ```sql SELECT u.first_name, COUNT(*) AS c FROM users u JOIN orders o ON o.user_id = u.id GROUP BY u.first_name ORDER BY c DESC; ``` Because ORDER BY has only an aggregate (COUNT(*) DESC) and no non- aggregate terms, SQLite traverses the group key (u.first_name) in DESC order in this case, so ties on c naturally appear with group keys in descending order. Previously tursodb would return the group key sorted in ASC order, because it was used in all cases as the default Closes #3287
Turso Testing
Testing Extensions
When adding tests for extensions, please follow these guidelines:
- Tests that verify the internal logic or behavior of a particular extension should go into
cli_tests/extensions.py. - Tests that verify how extensions interact with the database engine, such as virtual table handling, should be written
in TCL (see
vtab.testas an example).
To check which extensions are available in TCL, or to add a new one, refer to the tester.tcl file and look at the extension_map.