Repository navigation
Backlog
Labels
Milestone
Description
What happens today
- For GROUP BY,
compileGroup(src/select/groupby.js) generates one block per grouping set. Each block builds a text key from the grouped values joined with a backtick (line 92), with the set number in front when there are several sets (lines 93-95), and looks it up inthis.xgroups, created per run inqueryfn3(src/select/queryfn.js, lines 127-128). - CUBE, ROLLUP and GROUPING SETS are expanded into those blocks by
decartes(src/select/rollup.js). - Aggregates without GROUP BY use the key
''(groupby.js, lines 86-88). With no rowsqueryfn3(lines 174-190) builds the group by hand. - DISTINCT has its own pass over the finished rows (
doDistinctor its successor from Compare the rows of set operations and DISTINCT with one key function #3167).
What to change
- Add
internal.partitioninsrc/select/groupby.js.find(set, values)returns the group for a grouping set and its key values, and creates it when it is new (callinginitof each aggregate from Give every aggregate the same init, step and result interface #2660 and storing the first row). Groups are kept in aMapby key and listed in first-seen order. - Add
compare.v4.groupKey(set, values)tosrc/engine/compare.js. It returns exactly today's text key. compileGroupgenerates, per grouping set, the key values, one call tofind, then thestepcalls of the aggregates.- Aggregates without GROUP BY are one grouping set with no key values. Create its group when the run starts and remove the special case in
queryfn3lines 174-190.resultof a state that saw no row gives today's values (0 for COUNT, SUM and TOTAL,undefinedfor the rest). - DISTINCT uses the same helper with one set made of all output columns and its current key rule. It keeps its row order and the last row of each key.
Window functions in src/select/select.js stay as they are.
What stays the same
- Which rows share a group and the order of groups.
- NULL in the keys of CUBE, ROLLUP and GROUPING SETS. GROUPING SETS with parenthesised sets gives a value instead of NULL for a column outside the set #3152 stays as it is.
- The results over no rows with and without GROUP BY.
- DISTINCT rows and their order.
- No result changes.
Done when
- A new test file named after this issue covers GROUP BY with one and two keys, values that share today's text key (
1and'1', NULL and'null'), CUBE, ROLLUP, GROUPING SETS, aggregates over no rows with and without GROUP BY, HAVING that removes every group, and DISTINCT, against results recorded on main before the change. bun test/performance/bench.js --group=group-byshows no slowdown beyond the noise described intest/performance/README.md.- 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