Grouping and drill-down
Each request opens one level of a grouped grid and carries the path of groups above it. Group values are matched exactly, and the output columns are named at every level. A drill-down is compiled like any other filter, combined with the user's own filter.
aggregation addendum, and added by #1640 because BM-2's own two open contradictions could not be settled anywhere a fixture README would be the only record; GRP-6 added by #1641 for BM-3, which is subsidiary to BM-2 and answers the same bucket-identity question about a different construct)
BM-2 (row grouping over AG Grid SSRM) is a protocol, not a single query shape: one request per expanded level, each carrying the whole group path so far. #1630's fixtures pinned that protocol's output before anything compiled it, and left two points genuinely undecided — whether a grouped query folds case, and whether the drill-down conjunction is IR or clause text. Both are settled here, because a rule that lives only in a category README is a rule the next language port will re-derive differently.
GRP-1. One request, one level: the dispatch is groupKeys.length against groupCols.length. Fewer keys than columns → a grouped level: bucket by groupCols[groupKeys.length] (the next not-yet-consumed column, and only that one — never the whole remaining list), aggregate the valueCols, and restrict to the already-consumed keys. Equal → the drill-down leaf: every dimension is consumed, so the answer is raw rows restricted by those keys, with no GROUP BY and no aggregation (spec/fixtures/group-aggregation/005, 006). More keys than columns is a malformed request and MUST be rejected — consuming only as many as fit returns a different bucket's rows under a label the client did not ask for.
Where the arity check belongs. It is a property of the request, not of any one backend, and ir.schema.json cannot express it (JSON Schema has no way to compare two arrays' lengths) — so it belongs in the shared groupSpec validator every compiler already runs, not in a compiler. Put it in one of them and the others must each re-derive it; its failure mode is silent, so the one that forgets returns wrong rows rather than an error.
The colIds are client-controlled, and pass the same boundary as a filter's. rowGroupCols and valueCols arrive off the wire exactly as filterModel does, so every groupCols entry and every aggregation field MUST pass the SC-1 allowlist, and MUST additionally satisfy SC-2's per-field groupable / aggregatable capability flags. A CONSUMED groupCols entry (#1907) additionally satisfies filterable, on top of groupable: the not-yet-consumed suffix is bucketed across every value, which groupable alone already permits, but the consumed prefix becomes a literal drill-down predicate (GRP-2, below) — functionally a filter condition over a different wire channel, so it is held to the identical flag filterModel is, hard-failed in every mode (this is a structural colId, not a condition — the same reasoning the paragraph above already gives for groupCols/aggregation fields). See the BM-3 addendum's own remarks on filterable now spanning three surfaces (the ordinary filter tree, where Lenient MAY still strip it; setValuesRequest.colId; and this one) and why only the filter tree keeps Lenient's carve-out. SC-1's Lenient mode does not apply to either. Lenient may silently drop an unknown condition, because the result merely widens and a host can knowingly accept that; neither of these is a condition. Dropping a groupCol changes which level the response describes — and, with its groupKey, returns a different bucket's rows under the label the client asked for, arriving silently at exactly what the paragraph above rejects loudly. Dropping an aggregation hands the grid a response missing the key it asked for, i.e. a column of blanks indistinguishable from real nulls. Both are rejected in every mode. Pinned by spec/fixtures/adversarial/003-unknown-colid-row-group.
GRP-2. A grouping request is exact on the protocol's own keys: no case-folding mechanism is spelled on any of them. There are exactly three: the GROUP BY key, the drill-down WHERE predicates a consumed groupKeys entry compiles into, and a grouped level's ORDER BY keys. All render bare, whatever the column's declared caseSensitivity. So "EMEA" and "emea" are two buckets with two unambiguous labels — which is also what AG Grid's own client-side grouping does. (A fourth key answers to this rule without being part of BM-2's protocol at all: BM-3's SELECT DISTINCT column and its ORDER BY. GRP-6 makes the argument for it; everything below applies to it unchanged.)
Why the three must agree, and why "exact" is the only coherent answer. Bucket identity is decided by the GROUP BY; the drill-down that expands a bucket must select exactly the rows that produced it, or the child level stops summing to the parent's aggregate; and the ORDER BY of that same level orders the buckets the GROUP BY just produced. That rules out every mixed answer. Between the two coherent ones, "collate everywhere" is not merely undesirable, it is invalid SQL: SELECT "segment" … GROUP BY "segment" COLLATE craticula_ci groups by an expression the select list no longer contains, and Postgres and SQL Server both reject it. Exactness also avoids inventing a label rule for a folded bucket (is it EMEA or emea?), which nothing in AG Grid's wire contract supplies.
Scope — deliberately narrow, and narrower than #1640's first draft. GRP-2 governs the keys that decide or reproduce bucket identity, not "every key of a grouping request". Two things inside one are outside it:
- A user's own filter. A pre-aggregation row filter (AR-5) selects the rows that will be bucketed and has no say in bucket identity, so it keeps SEM-1's per-field mechanism. One statement may therefore compare the same column twice by two mechanisms —
WHERE ("region" = $1 AND "region" ILIKE '%' || $2 || '%' ESCAPE '\')— and that is correct, not the contradiction SEM-1 forbids: SEM-1 governs how a field's values are compared, GRP-2 governs bucket identity, a question SEM-1 never asks. - A drill-down leaf's
ORDER BY. #1640's first draft keyed theORDER BYrule on "the request carries agroupSpec", which swept the fully-consumed leaf in with it; its review found that wrong. A leaf has noGROUP BYand no buckets. It orders raw rows by whatever column the user picked, which need not be a group column at all —group-aggregation/005sorts onproduct, neither a group column nor a group key — so the bucket-identity argument above simply does not reach it. It is an ordinary row query in this respect and SEM-1 governs it, collation included. Leaving it bare was also a live defect and not merely an inconsistency: a leaf that filterslastName eq "smith"and sorts onlastNamewould emit a collatedWHEREbeside a bareORDER BY— one field, two mechanisms, one statement, which SEM-1's third Must-NOT forbids outright. Its drill-downWHEREis still exact, because that IS one of the protocol's keys. - A leaf that sorts on a consumed group column, which is the boundary between the two bullets above. It emits an exact
WHERE "region" = $1beside a collatedORDER BY "region" COLLATE craticula_ci— one field, two mechanisms, one statement, and yet correct: theWHEREhas pinned that column to a single group key, so the ordering is a no-op over the returned rows and there is no comparison for the two mechanisms to disagree about. Stated because it looks exactly like the SEM-1 violation the bullet above exists to prevent, and a reviewer who spots it should be able to find it already answered rather than re-derive it.
The one thing that must never happen is the mix SEM-1 does forbid: a grouped level whose GROUP BY and ORDER BY disagree with each other, which GRP-2's per-statement scope removes.
Accepted divergence, and the host obligation it creates. "Spell nothing" means "exact" only where the engine's own default already is. It is on Postgres (deterministic default collation) and SQLite (BINARY). It is not on SQL Server / Azure SQL (stock SQL_Latin1_General_CP1_CI_AS), MySQL / MariaDB (a _ci family default), or Oracle (default column collation USING_NLS_COMP, resolved through the session's NLS_COMP/NLS_SORT — the same fact SQL-6 cites as why the case-sensitive direction must be spelled COLLATE BINARY there): on all three, a grouped string column folds case and "EMEA"/"emea" land in one bucket. A host that wants exact buckets on those engines must declare the groupable column with a binary / _as_cs / BINARY collation in its DDL — or, on Oracle, run the session with NLS_COMP = BINARY (the default, and what the execution tier runs on; a column-level COLLATE BINARY needs MAX_STRING_SIZE = EXTENDED, measured in SQL-6 below) — the same kind of obligation SQL-6 already records for MySQL's case-sensitive direction, and for the same reason (no portable in-statement spelling exists that does not break the GROUP BY). Recorded here as a documented divergence rather than papered over; the execution-equality tier (T-1b, #1624) is what can grade it, and T-1a cannot see it at all.
Oracle is on that list for exactly the reason SQL-6 puts it there, and the two must not drift apart. A bucket-identity key resolves to NotApplicable, so on Oracle it emits nothing — while a caseSensitivity: "sensitive" filter on the same column emits COLLATE BINARY, precisely because bare is not exact there. A host running ALTER SESSION SET NLS_COMP = LINGUISTIC NLS_SORT = BINARY_CI therefore gets a drill-down "region" = :p1 that folds case, so expanding the "EMEA" bucket also returns 'emea''s rows and the children stop summing to the parent's aggregate — silently, on well-formed SQL, and invisibly to T-1a. Stated because the two paragraphs sit four lines apart in this document and an earlier draft of #1642 had them disagreeing.
Per-backend consequences beyond SQL. ES/OpenSearch drops the case_insensitive: true parameter from a drill-down term, leaving {"term": {"<field>.keyword": {"value": "EMEA"}}}, the same exact-term form dialect-parity/014 already uses; a composite terms source over a keyword field is exact already and needs nothing. Its per-clause granularity means it can satisfy the scope carve-outs above exactly — a bare drill-down term beside a wildcard/case_insensitive user filter, and beside a leaf sort on a search.normalizedSubField, all in one request.
Accepted divergence #3 — MongoDB cannot satisfy this rule and the carve-outs above at the same time. MongoDB's collation is a query-level option: it governs $match, $group and $sort together, and there is no per-stage form. So a grouping request whose scope carve-outs ask for a case-insensitive comparison somewhere and an exact one somewhere else has no pipeline that expresses both, and the "a grouping request's pipeline carries no collation at all" shorthand an earlier draft used hid a real choice rather than describing a consequence-free one. Three shapes reach it:
- a grouped request carrying a user
eq/infilter on a case-insensitive string (SEM-1 wants the collation; theGROUP BYand drill-down forbid it), - a drill-down leaf sorting a case-insensitive string (SEM-1 wants it; the drill-down
WHEREforbids it) — whichgroup-aggregation/005is, sorting onproduct. Not006, despite #1640's re-authoring touching the two together:006carries nosortModel, so its only key is SEM-6's appended tiebreaker, which resolves exact and never wanted a collation in the first place — and - a BM-3 distinct-values request (GRP-6) carrying a user filter on some other case-insensitive string — SEM-1 wants the collation for that
$match, while GRP-6(a)'s exact buckets forbid it on the$groupthat computes the distinct set. This one is easy to miss because the conflicting pair sits on two different fields: the collation is wanted forsegmentand forbidden forregion, yet MongoDB has only one switch for both.
The protocol's keys win, on all three: the pipeline carries no collation. Bucket identity is a correctness property — get it wrong and a child level's rows stop summing to the parent's aggregate, silently — while a case-folded filter or sort is a narrower, visible difference in which rows come back and in what order. So on MongoDB a user's own filter compares case-sensitively, and a leaf's $sort orders case-sensitively, where the five SQL dialects collate both. Recorded here as a documented, host-visible divergence, in the same register as GRP-2's SQL Server/MySQL DDL obligation and AGG-5. Exactly three fixtures reach it, and the list was wider than the truth until #1643 compiled the Mongo arm and could check: no fixture reaches the first shape — group-aggregation/023 is the only case in the suite carrying both a consumed groupKeys and a filterModel (#1644's review pass authored it for GRP-5's clause order), and its filter is on two int64 columns, so nothing in it ever wants a collation; 005 pins the second — its leaf sorts on product, a case-insensitive string, while 006's only sort key is the exact-resolved SEM-6 tiebreaker, so 006 never wanted a collation and is not an instance of the divergence at all; and 017/022 pin the third, 016/018/019 carrying no collation-mechanism construct in the first place (016 and 019 carry no filter at all, and 018's only predicate is its search prefix, which GRP-6(b) makes an ordinary startsWith and SEM-1 therefore assigns the pattern-match mechanism). The distinction is not bookkeeping: "suppressed a collation it wanted" and "never wanted one" are different compiler states, and only the first is evidence about this rule. CrossCompilerGroupingTests.The_Divergence_Is_Reached_By_Exactly_The_Three_Fixtures_The_Spec_Names asserts the set against this sentence. The execution-equality tier (T-1b, #1624) is what can grade the divergence itself; T-1a cannot see it.
Accepted divergence #4 — MySQL cannot serve exact buckets and a case-insensitive filter from one column. MySQL spells no collation in SQL (SQL-6), so one column has one collation: the binary one GRP-2 requires of a groupable string column for exact buckets, or the _ci one SEM-1's case-insensitive filters and prefixes rely on. A host that declares the groupable column binary (as the execution tier does) therefore gets case-sensitive filters and prefixes on it, on the BM-3 requests that combine a distinct set with a user filter or search prefix on a case-insensitive string: group-aggregation/017, 018 and 022, each declaring it as an XEQ-4 rows divergence for mysql.
How the third shape was found, because the same trap is waiting for every other backend with a query-level switch. 017's Mongo arm was authored in #1641 carrying a query-level collation beside a $group on region — the exact combination #1640 had already stripped from every grouped arm, reintroduced on a query nobody thought of as "grouped" because it carries no groupSpec. The SQL arms were right the whole time; only Mongo, where one option governs every stage at once, could express the contradiction at all. The test is not "does this request have a groupSpec" but "does this pipeline compute a distinct set" — and under GRP-6 a BM-3 request always does.
GRP-3. A grouping request names its output columns at every level; an ungrouped one does not. A grouped level projects <group column> AS <logical field name> — aliased always, even when the physical column and the logical name coincide — followed by one aggregate per valueCol. A drill-down leaf projects every field the schema declares, in declaration order, aliased back to its logical name only where the physical column differs ("fiscal_year" AS "fiscalYear", but plain "region"). "Declaration order" means the order of the fields object's members in the schema document, and an implementation must take it from there: the natural shortcut — enumerating whatever map the schema was deserialized into — is a language-specific accident (Dictionary<K,V> in .NET, dict in Python and Map in JS happen to preserve insertion order; Go's map and Java's HashMap emphatically do not), and group-aggregation/005/006 compare this column list byte for byte. SELECT * is not available to the protocol at either level: it returns physical column names, and a grid that asked for fiscalYear cannot read a fiscal_year key. An ordinary row query is out of GRP-3's scope and still renders SELECT *. Widening it belonged to the export feature, which owns the request-supplied column list any general projection rule has to compose with — and EXP-1(b) has now settled it, narrowly: an export names its columns, an ordinary row query still does not. So this sentence is no longer a deferral; the only projection a request can add is an export's. (Until #1650 this sentence cited that column list as EXP-3, and so did its restatement in SqlQueryBuilder. The TRD's EXP-3 is streaming; the column list is a clause of EXP-1, which is why the addendum numbers it EXP-1(b).) "Ordinary row query" and not "ungrouped": BM-3's distinct-values query also carries no groupSpec and is emphatically not SELECT * — it projects the one target column, unaliased (GRP-6(e)). The same distinction as in SEM-6's first blockquote, for the same reason.
GRP-4. A grouped level orders by what it projects, and breaks ties on its group column.
- A sort key naming an aggregated column orders by that aggregate's expression (
ORDER BY SUM("amount")—ORDER BY COALESCE(SUM("amount"), 0)for asum, since AGG-6), never by the raw column, which the projection does not contain. The key is matched againstalias ?? field, i.e. AGG-2'sColumnVO.idreconstructed — the grid sends the column's id, and AGG-2 sets the alias from that id exactly when it differs from the field. - Repeat the expression; do not refer back to the output name. An output column name is only conditionally usable in
ORDER BY: PostgreSQL'sSELECTdocumentation states that it "has to stand alone, that is, it cannot be used in an expression", and T-SQL binds the same way — an alias inside aCASEresolves against theFROMscope and raises "Invalid column name". It rarely stands alone here, because SEM-3's null placement is emulated on two of the five dialects (CASE WHEN … IS NULL THEN 1 ELSE 0 ENDon SQL Server,ISNULL(…)on MySQL), so the ordering target sits inside an expression on both. The expression form is unambiguously legal in either position on all five engines, so it is used uniformly rather than only where the wrapper forces it — a per-dialect split would make a semantic difference look like a spelling one. (#1640's first draft emitted the name; its review found020's mssql and mysql arms were the T-SQL failure above.) Mongo is unaffected and keeps the name: after$groupthe aggregate is a real field of the document a later$sortstage reads, not an alias in a scope. Search does not order a grouped level by an aggregate at all — the request has no rendering there and is refused (OSE-11(c)), so this bullet has no Search arm to reach. - An aggregate with no alias takes the compiler default
<field>_<func>(amount_sum,id_count) — stated here because it lands in query text as an identifier and every port must choose the same one. It names the aggregate in the projection and in the response, which is what the grid reads it back by; only theORDER BYavoids it. - SEM-6's tiebreaker still applies, but the group column plays the stable key's role: the schema's
stableKeyis not in the grouped projection, so ordering by it is invalid SQL, while the group column's values are unique across the level's rows by construction. Appended last, ascending, nulls last, and not appended twice when the (reduced) sort already reaches it — SEM-6's own rules, unchanged. - A sort key that is neither the group column nor an aggregate output MUST be rejected rather than rendered; the engine would refuse the statement anyway, and a compiler error names the reason. This is a statement about the IR's colId space, not AG Grid's — see AG-6 below, which is what makes the two the same space by the time a compiler sees them.
- A sort key that matches MORE THAN ONE aggregation's column id MUST be rejected too, not resolved to the first (#1886). AGG-2's alias rule and this bullet's own
alias ?? fieldmatch are independent of AGG-1's output-name uniqueness: two unaliased functions over one field (sum(amount)+avg(amount), AGG-2's own example) have distinct output names —amount_sum,amount_avg— while sharing the column idamount, because that id isalias ?? field, neveralias ?? "<field>_<func>". A sort key namingamounttherefore does not say which of the two the client means; a compiler that quietly picked one (the first declared, say) would produce the exact plausible-looking wrong statement the bullet above already refuses for a colId outside the projection entirely. Pinned by unit tests alone, there being no artifact for a request that does not compile (SQL-7(b)'s precedent) — a grouped request whose only aggregates collide on column id has no sort naming that id in the fixture suite, so nothing here moves an artifact. - A drill-down leaf is an ordinary row query in this respect and keeps SEM-6's
stableKey.
AG-6. AG Grid addresses a grouped sort through the row-group display column, whose colId the adapter must resolve before the IR is built. sortService.getSortModel() writes colId: column.getId(), and for the auto group column that id is columnUtils.ts's GROUP_AUTO_COLUMN_ID = 'ag-Grid-AutoColumn' — or, under groupDisplayType: 'multipleColumns', `${GROUP_AUTO_COLUMN_ID}-${rowGroupCol.getId()}` (autoColService.createOneAutoCol). Neither matches any GridSchema.fields key, because it is a colId in AG Grid's column space rather than the host's, and the SSRM sort listener passes it to the server untouched. Resolving it is therefore the adapter's job by definition — nothing downstream knows that AG Grid mints display columns — and until #1640's review nothing did it, which made the single most common grouped-grid interaction, clicking the group column's header, a hard failure against GRP-4's rejection above.
ag-Grid-AutoColumnshows the whole group path, so it resolves to the group column this request's own level buckets by:groupCols[groupKeys.length], GRP-1's dispatch exactly.ag-Grid-AutoColumn-<id>names its source column, and the suffix is that column'sColumnVO.id— looked up against therowGroupColsentries' ids, which differ from theirfields whenever a host gives a grouped column its own id.- On a drill-down leaf every group column is consumed, there is no level to name, and every row shares the whole group path — so the key would order nothing and is dropped. SEM-6's tiebreaker still guarantees a total order.
- A suffix naming no
rowGroupColsentry, and an auto-column colId on a request carrying no group state at all, are both left unresolved and carried through verbatim, so each fails downstream as the unknown colId it is. Dropping either is worse than mapping it: the response then comes back in a different order from the one the grid's own header shows, with no rejection and no log, and the auto-column prefix would be the only colId in the adapter with such a path — every other bogus colId reaches a compiler and is refused there. The refusal does come from the compiler, which resolves each sort field against the schema; sort colIds have no allowlist stage of their own yet (SEM-6's own note about the orchestrator that does not exist applies here too), so "it reaches the field allowlist" — which an earlier draft of this rule said — is aspirational rather than true. - Collapse the coupled set afterwards. AG Grid's sort coupling (
gridOptionsUtils._isColumnsSortingCoupledToGroup, true unlesstreeDataor a customautoGroupColumnDef.comparator) sets the sort on[column, ...sortableRowGroupColumns]— the display column and every source columnshowRowGroupColsService.getSourceColumnsForGroupColumnreturns for it — andgetIndexedSortMapgives them all the display column's index, so they are all emitted. For the default single display column that is every row-group column, not just the level it resolved to:autoColService.createBaseColDefsetsshowRowGroup: rowGroupCol?.getColId() ?? true, i.e. the literaltrue, and that service answerstruewithrowGroupColsSvc.columns.slice(0). So withrowGroupCols: [region, segment, product]one user click emits[ag-Grid-AutoColumn, region, segment, product]— 1 + N, not a pair — and AG Grid means one logical key by it. Collapse the whole coupled set into the entry the display column resolved to, keeping the first occurrence so the user's key precedence is preserved. A suffixed display column is the other arm of the same service method: itsshowRowGroupis one column's id, so its coupled set is that one column and only it collapses. Scoped to entries the resolution itself accounts for, and only after the display column that named them: a key the client sent on its own is left alone. Pinned bygroup-aggregation/021. (Keeping the surplus entries is not a cosmetic duplicate — with the payload above they leave the request sorting on a column the drill-down has pinned to one value and on a level this response does not produce, both of which GRP-4 rejects outright.)
GRP-5. The drill-down is materialised as real IR, and merged with the user's filter through the same merge primitive as everything else. Each consumed key becomes an eq comparison node against its group column (AGG-3's typed value), the set is wrapped in an and node when there is more than one, and the result is and-merged with the request's own filter tree exactly as customFilters and static filters are (AR-5/OQ-11's one merge primitive). It is not assembled as clause text.
Consequence, and the contradiction this closes. Because it is ordinary IR, SQL-2's "every composite wraps" applies to it with no exception: two or more consumed keys render ("region" = $1 AND "segment" = $2), wrapped. #1630's fixtures had them bare, on the reading that a synthesised conjunction is not an IR construct; that reading is rejected, because any compiler that reuses its filter renderer for the drill-down — which is every sensible one — gets the wrapped form for free. A single consumed key is not a composite and does not wrap.
Order. The drill-down leads: WHERE (<group path> AND <user filter>). Nothing in the fixture suite pins this (no case carries both), and it is stated rather than left open because the choice is visible in params, which is compared exactly.
Provenance must survive the merge. The two halves are ordinary IR and indistinguishable by shape — a groupKeys match on region and a user eq on region are the same node — yet GRP-2 gives them different answers. A compiler must therefore carry the distinction itself and must not try to recover it from the merged tree. Reference identity happens to work and is a trap: any later change that rebuilds nodes between synthesis and rendering (flattening nested ands, or routing the group columns through an allowlist/coercion stage, both of which mint new nodes) silently gives the drill-down the user's mechanism, "EMEA" starts matching "emea", and child rows stop summing to the parent — with no error and no failing artifact. Rendering each half under its own resolution context and composing the wrapped and from the two results is equivalent, byte for byte, and has no such invariant to break.
Resource limits (SEC-3), on two levels. groupKeys is as client-controlled as any filter value, so N consumed keys are N leaf predicates that must be counted against the SEC-3 leaf/depth budget together with the user's filter, over the merged tree. This is an amplification BM-2 introduced: before it, group state was ignored entirely. But that check only runs where the filter pipeline runs, and a host may hand a groupSpec straight to a compiler — so ir.schema.json additionally carries a structural maxItems on groupCols (and, since GRP-1's cross-array comparison is inexpressible there, on groupKeys too), enforced by the same shared validator GRP-1's arity rule lives in. That is an amplification cap in the register of fieldName.maxLength, deliberately not one of SEC-3's named, host-configurable limits — its value is fixed at SEC-3's own default max-leaves, so a structurally valid groupSpec can never exceed that budget by itself, while a host configuring something tighter still gets the tighter answer from the runtime validator.
Type coercion (SEM-5). A groupKey is a filter value, so it must satisfy its group column's declared type before a compiler sees it — a compiler that binds it is entitled to assume this, exactly as it does for a filter value. It differs from a filter value in one respect that decides how: the wire already carries each key pre-typed as a typedValue ($defs/groupSpec requires it, and a frontend adapter resolves the raw wire string using the group column's declared type before building the request), so there is nothing untyped to parse. A variant that disagrees with the declared type is therefore a wrongly-typed request, rejected at the typeCoercion stage with SEM-5's own uncoercible-value reason — never repaired, and never allowed to surface further downstream as a compiler precondition failure on ordinary client input.
GRP-6. BM-3's distinct-values query is a bucket query, and its cap is a ceiling rather than a page. A set filter asks the server "which values may I offer for this column, given the filters currently in effect?". The answer compiles to SELECT DISTINCT <col> … ORDER BY <col> <cap> (DISTINCT is the default spelling; SQL Server uses GROUP BY <col> instead, GRP-6(f); a terms aggregation on ES/OpenSearch, a $group on _id on MongoDB), and six things about it are decided here because each of them is a place a port would otherwise guess differently.
(a) The DISTINCT key and its ORDER BY are exact — GRP-2's rule, reached by GRP-2's argument. SELECT DISTINCT computes a distinct set exactly as GROUP BY does; it is a bucketing operation whose buckets happen to have no aggregate attached. A collated one folds "EMEA" and "emea" into a single entry whose label is unspecified — and that entry is precisely what the grid hands straight back, as an in value in the column's own filter or as a groupKey into a grouped request, where GRP-2 matches it exactly and it selects neither original row. So the values a set filter offers must be the values the data actually holds, one entry per distinct spelling. Read as an ordinary query instead, SEM-1 would collate both positions; that reading is rejected, and the reason is the same one GRP-2 gives: SEM-1 governs how a field's values are compared, not what a bucket is. The consequences GRP-2 records carry over verbatim — including that "spell nothing" is exact only where the engine's own default already is, so exact set-filter values on SQL Server and MySQL are the same host DDL obligation, gradeable only at the execution tier (T-1b, #1624).
(b) The target column's own filter is dropped; every other column's is honoured. This is BM-3's defining semantic and the AG Grid convention it names. A value list narrowed by the selection already made on its own column collapses to what is already selected, and the user can never widen it again. Everything else in the filter model still applies, so the list stays consistent with the rows the grid is showing. Where it happens matters: it is a semantic rule every backend shares, so it belongs in the request pipeline, not in one compiler and not in a frontend adapter — a host building the IR directly must get it too. Conditions are pruned, not branches: (region eq "EMEA" AND segment eq "Enterprise") targeting region leaves segment eq "Enterprise", and a not whose only condition was on the target vanishes with it rather than becoming a negation of nothing. Pinned by spec/fixtures/group-aggregation/017, whose artifacts are byte-identical with and without the region entry in its filterModel — which is the whole point of the fixture and, until #1641, was not true of it: it carried no region filter at all and therefore tested nothing.
(c) The search prefix is an ordinary startsWith predicate on the target column. The set filter's inline search box narrows the candidate values; modelled as IR it is a startsWith comparison carrying the raw text, so SEM-1 picks the field's own mechanism for it and SEM-7's escaping applies unchanged — a literal % typed into the box cannot widen into a wildcard. It is therefore not exempt from (a)'s exactness in the way that looks contradictory: on the SQL dialects and on MongoDB one statement legitimately matches the column case-insensitively and orders it exactly, which is GRP-2's own first carve-out (a filter selects rows, it does not decide bucket identity) applied to a single column. Order: the user's filter leads and the prefix trails — WHERE (<filter model, minus this column> AND <prefix>). It was stated here rather than left open because the choice is visible in params, which is compared exactly, and #1641's review then gave it an artifact of its own: spec/fixtures/group-aggregation/022 carries a filter on another column, the target column's own filter, and a searchPrefix, all in one request. (It is also the only case where the exclusion and the prefix act on the same column, which is what makes "prune the model, then inject the prefix" distinguishable from "prune the finished tree".) A prefix against a column that is not declared string has no meaning and is a wrongly-typed request, rejected at the typeCoercion stage with SEM-5's uncoercible-value.
Superseded in part by OSE-12 (#1644). Three claims above were written before a compiler for the third backend existed and are false there:
- "no backend needs a second prefix-matching path" — OpenSearch/Elasticsearch does. OSE-12 compiles this predicate to the
termsaggregation'sinclude, a Lucene regex evaluated at aggregation time, which is a third pattern language: different from thewildcardquery's syntax and different again from PCRE2. Its escape alphabet is MDB-11's, not SEM-7's.- "one statement legitimately matches the column case-insensitively and orders it exactly" — not on that backend.
includehas no case-insensitivity option in the pinned subset, so the prefix matches case-sensitively as typed where Postgres'sILIKEand Mongo's$regex/"i"fold. That is an accepted divergence in AGG-5's register, recorded in OSE-12 and ingroup-aggregation/018's description, and asserted as an expected difference byCrossCompilerGroupingTests.- "the order is now pinned on seven backends" — on six.
022's Search arm carries no query-level prefix at all: the prefix leaves the query entirely and becomesinclude: "eu.*"insideaggs, so there is no sequence there for a port to get backwards. Theparamsargument for stating the order still holds on the five SQL dialects and on MongoDB's$and.
(d) The cap is applied, never enforced, and never absent. The compiled limit is min(requested ?? default, maximum), from two host-configured SEC-3 numbers: a default for a request that asks for no cap of its own, and a maximum no request may exceed. A client asking for more values than the host will serve has not malformed anything — a set filter over a high-cardinality column asks for as many as it can get by design — so the server clamps and answers rather than rejecting; group-aggregation/019 requests 50,000 against a 10,000 maximum and compiles to 10,000, while 016-018 request none and compile to the 1,000 default. The two numbers are separate knobs, because they answer different questions (what a quiet client gets versus what the loudest one may ever get) and a host raising the ceiling for one explicit request has not agreed to send that many values to every set filter that opens. "No cap" is not an available answer at all.
(e) It is a cap, not a page — so there is no offset, and no tiebreaker. The list is fetched once; there is no second page. So the compiled statement carries the row limit alone: LIMIT $1 with no OFFSET, $limit with no $skip, "size" with no "from". On engines whose row-limiting syntax cannot stand alone this is a real per-dialect difference rather than a shortened clause — T-SQL has no LIMIT, and its FETCH NEXT is illegal without an OFFSET — so a Dialect seam needs its own member for it, distinct from the paging clause:
| Dialect | Row cap | Parameters bound |
|---|---|---|
| Postgres | LIMIT $1 | 1 |
| MySQL / MariaDB | LIMIT ? | 1 |
| SQLite | LIMIT ? | 1 |
| SQL Server | OFFSET 0 ROWS FETCH NEXT @p1 ROWS ONLY | 1 — the 0 is literal |
| Oracle (#1642) | FETCH FIRST :p1 ROWS ONLY | 1 |
SQL Server's zero is written rather than bound because it is not a value the request carries: it is the syntax that makes "no offset" expressible on an engine whose FETCH requires one, in the same register as the '%' anchors and the ESCAPE character a compiler already emits as literals. Oracle's row is a genuinely fifth answer and not SQL Server's with a different placeholder style — a third clause family across the five: its row-limiting clause admits a bare FETCH FIRST with no OFFSET before it at all, so it needs neither that literal zero nor Postgres's LIMIT. A port that assumes T-SQL's spelling generalises to every FETCH engine emits an OFFSET 0 Oracle does not want and fails the arm. Every dialect therefore binds exactly one parameter here, and params stays identical across the five arms of a BM-3 fixture. (SELECT DISTINCT TOP (@p1) … is idiomatic T-SQL and is deliberately not used: it would put the cap in the select list, giving one engine a different statement shape.)
For the same reason SEM-6's tiebreaker does not apply: the distinct column's values are unique across the result rows by construction, and the schema's stableKey is not in the projection at all, so ordering by it would be the invalid SQL GRP-4 avoids at a grouped level. The single ORDER BY key is the distinct column, ascending, nulls last. The projection carries no alias, unlike GRP-3's: the response is one column of scalars, not rows a grid maps by key, so there is no name for a client to look anything up by.
(f) SQL Server spells the distinct set GROUP BY, not SELECT DISTINCT. T-SQL refuses a SELECT DISTINCT whose ORDER BY item is not a select-list item (msg 145), and the nulls-last key SEM-3 requires on SQL Server is the expression CASE WHEN <col> IS NULL THEN 1 ELSE 0 END. So on SQL Server (and only there) the distinct-values statement is SELECT <col> FROM <source> [WHERE <tree>] GROUP BY <col> ORDER BY <SEM-3 key over <col>> OFFSET 0 ROWS FETCH NEXT @p1 ROWS ONLY; the ORDER BY expression is legal because it is a function of the grouping column alone. GROUP BY <col> computes exactly the set SELECT DISTINCT <col> does, so (a)–(e) apply unchanged: the key is exact (no collation folded), the WHERE tree and search prefix are as before, the ordering is ascending nulls last, the cap is the same literal-zero OFFSET/FETCH with one bound parameter, and params is unchanged. Every other dialect keeps SELECT DISTINCT. The mssql arm of a BM-3 fixture is therefore the one place the statement shape differs from the other four.
The target colId is client-controlled, and no mode may drop it. It passes the SC-1 allowlist in every schema mode, on GRP-1's reasoning taken one step further: a groupCol that Lenient dropped would at least leave a differently-shaped answer, whereas the colId here is the question — drop it and a compiler has no column to select, while an empty value list would tell the grid that the column has no values rather than that the server declined to say. The capability flag it is held to is SC-2's filterable (a set filter's value list is the filter UI's own data source, so groupable and sortable are the wrong questions even though the compiled query buckets and orders the column) — #1872 enforces the identical flag on the ordinary filter path too, so a host can no longer refuse a column's set-filter values while still honouring that same column's filterModel entry. #1907 extends it to a third surface: a CONSUMED groupCols entry (GRP-1, above) is likewise held to filterable, since a groupKeys drill-down predicate is functionally a filter condition arriving over a different wire channel.
The three paths are NOT all held to the same Lenient-mode rule, deliberately (#1872, #1907). On the ordinary filter path, a filterable:false colId referenced in filterModel/customFilters is treated exactly like an unknown one: Strict rejects it, Lenient silently strips the condition — it is still only a condition, and dropping one only widens the result set, the trade SC-1's Lenient mode already exists to let a host accept. As a setValuesRequest.colId, or as a CONSUMED groupCols entry, no mode may drop it, for the identical reason the paragraph above gives for the plain unknown-field case: each one is the question (or, for a consumed key, changes which bucket's rows come back under the label the client asked for), not a condition narrowing it, so there is no narrower answer left to give once it is gone.
GRP-7. A nullValue group key drills into the null group: eq against it is the null test, on every backend. A grouped level buckets rows whose group column is null into one group (AR-8/BM-2; GRP-4 sorts it with nullsPosition), so the level below it must be reachable: groupKeys carries that group's key as a nullValue (AR-7), and GRP-5 turns it into eq against the group column. Compiled as ordinary equality it expands nothing: SQL's = NULL matches no row, an engine's term with a null value is refused, and a compiler that binds it as a parameter answers 0 rows where MongoDB, whose $eq: null is the null test, answered the group's rows. The rule that replaces all of those: eq with a nullValue operand selects exactly the rows whose column is null, with no bound parameter (the null test already is the answer). It selects NULL and nothing else: the empty string is a different group at a grouped level (blank would merge the two, and the child level would then no longer sum to its parent's bucket), so eq null is not blank.
| Backend | Rendering |
|---|---|
| SQL (all five dialects) | <col> IS NULL |
| MongoDB | {<path>: {$eq: null}} (matches null and a missing path, the same set MDB-8's null bucket holds) |
| ES / OpenSearch | {bool: {must_not: {exists: {field}}}} on the raw field |
| EF Core | column == null, which EF translates to IS NULL |
Every other operator against a nullValue keeps its meaning (SEM-2's null-inclusive neq among them, a bound NULL parameter that matches no row on SQL, and EF's refusal): GRP-7 gives the null test one spelling, eq, and nothing else, because GRP-5 emits nothing else. A leaf drill-down, a grouped level below a null key, and an export of a drilled group (EXP-2) all inherit it, because they all read the drill-down GRP-5 builds. Fixtures group-aggregation/024 (leaf rows under the null key) and /025 (a grouped level under a null first key) pin it, with a row whose key is the empty string beside the null ones. On Oracle that row is not a different group: SQL-7 stores '' as NULL, so IS NULL selects it with the null group and both fixtures declare an XEQ-4 rows divergence for oracle (XEQ-2 requires the entry).
Cross-links. $defs/groupSpec (groupCols, groupKeys), $defs/aggregation, $defs/sortItem, $defs/setValuesSpec, AGG-1..AGG-4 (AGG-4 pins the terms ordering GRP-6(a)'s ES/OpenSearch arm depends on), SEM-1, SEM-5, SEM-6, SEM-7, SQL-2, SQL-6, and BM-2/BM-3/AR-8/AR-9 in the TRD. spec/fixtures/group-aggregation/ is the artifact oracle for all six.