Repository navigation
Description
What happens today
A SELECT builds each result row as an object and keeps helper values in the same object. compileSelect1 (src/select/columns.js) generates var r={'a':...,'b':...}. compileSelect2 adds the sort keys $$$0 and the DISTINCT ON key $$distinctOn, and compileGroup (src/select/groupby.js) adds running aggregates such as _SUM_x. All are listed in query.removeKeys, and queryfn3 (src/select/queryfn.js) deletes them at the end. Until then DISTINCT, set operations and user functions see the helper keys, and a column with the same name collides with one.
What to change
Give the engine one internal shape for the rows of a result, {columns, rows} with each row an array in column order, and build objects once, at output.
-
A SELECT takes the tuple path when it has no GROUP BY, no aggregate, no set operation, no ORDER BY, no DISTINCT or DISTINCT ON, no PIVOT or UNPIVOT, no window function, no ROWNUM, no INTO and no REMOVE COLUMNS, and the compiler knows every column (no
dirtyColumns). Decide this once incompileInScope(src/select/select.js) and keep it asquery.tuples = true. Everything else stays on the object path. -
Add
compileSelectTuple(query)next tocompileSelect1insrc/select/columns.js. It returnsnew Function('p,params,alasql', 'return [' + exprs + ']')in the order ofquery.columns, built with the sametoJScalls ascompileSelect1. -
In
doJoin(src/select/dojoin.js) and thejoinsortedbranch ofqueryfn3, push the tuple whenquery.tuplesis set. LIMIT and OFFSET work on the array of tuples. -
Add
toObjects(columns, rows)next toresultColumns(Decide the result columns of a SELECT in one function and let modify() read them from it #2651). Call it at the end ofqueryfn3before the result goes to the callback, somodify()and every modifier still receive objects.function toObjects(columns, rows) { const out = new Array(rows.length); for (let i = 0; i < rows.length; i++) { const t = rows[i], r = {}; for (let j = 0; j < columns.length; j++) r[columns[j].columnid] = t[j]; out[i] = r; } return out; }
Do not move the other paths here. ORDER BY is #3165, DISTINCT and set operations #3167, GROUP BY #2647 and #3168, modifiers and INTO #2699.
What stays the same
- Every result, column name and order, key order of the returned objects,
undefinedversus a missing key, and the shape of every modifier. The parity check shows no difference. SELECT a, a FROM ?gives[{a: 1}], and RECORDSET listsatwice.- Statements outside the scope above run as before.
Done when
- A new test file named after this issue runs the queries in scope (a table,
?with known columns, a join, WHERE, LIMIT and OFFSET, expressions, aliases, a duplicate column name, an empty result) with each modifier. It compares each result with the same query forced onto the object path. - The same file checks that a query in scope never puts a key starting with
$$or_SUM_into a row. test/performance/shows the tuple path is not slower than the object path on Node and Bun for a plain SELECT over 100,000 rows.- The full test suite and the CI checks (dialect test, parity check, run-state check, binding check) pass, and the pull request lists every parity difference.
Activity