Craticula

Case sensitivity

Every comparison and ordering of text ignores case by default. Case sensitivity is a setting of the field, not of the operator or of the place where the comparison appears. A filter on a field therefore always agrees with a sort on the same field.

Rule. Every operator in $defs/binaryOperator (eq, neq, gt, gte, lt, lte, contains, notContains, startsWith, endsWith) and $defs/setOperator (in, notIn), when applied to a stringValue, is case-insensitive by default — including the four ordering comparisons (gt/gte/lt/lte), which fold case in their lexicographic comparison exactly as the equality/substring operators fold case in theirs: case sensitivity is a per-field property (SC-3), not a per-operator one, and — the scope of "not a per-operator one" pinned explicitly here — not a per-context one either: the identical mechanism governs an eq/in comparison and an ORDER BY/$sort/sort on that field. Per-field, a schema author may opt a field into case-sensitive comparison instead. Whichever mode is active, the compiler MUST reach it through an index-friendly, backend-native mechanism — and, critically, the same class of mechanism (collation vs. pattern-match) MUST be used consistently across every context on that field, never one mechanism for filtering and a different one for sorting.

The one carve-out, and it is not a per-context exception smuggled back in: grouping (GRP-2). This rule governs how a field's values are compared. It does not govern bucket identity, a question it never asks and which BM-2's protocol answers separately: inside a grouping request the GROUP BY key, the groupSpec.groupKeys drill-down match and the ORDER BY are all exact, because they have to agree with one another or a child level stops summing to its parent's aggregate — and because collating a GROUP BY key produces a statement the engines reject outright. That is a per-statement rule, not a per-construct one, so it cannot reintroduce the mix this section forbids; a user's own filter predicate inside that same grouped request is still governed here, in full. BM-3's distinct-values query answers to the same carve-out (GRP-6): its SELECT DISTINCT column and that column's ORDER BY are exact, because a distinct set is a set of buckets and its entries are handed back to the grid to be matched exactly — while the set filter's own search prefix over that very same column is a filter, and so is still governed here. See the grouping addendum (GRP-2, GRP-6) for the whole argument, the accepted divergence on engines whose default collation folds case, and why an earlier draft of this section — which read the drill-down match as an ordinary comparison — was wrong on this one point.

Two distinct mechanisms, not one — pick per shape, not per whim. This document previously left it ambiguous whether Postgres case-insensitive equality (eq/in/notIn, and by extension sort) should reuse ILIKE (the substring mechanism, §SEM-7's territory) or use a collation (the exact-comparison mechanism, as SQL Server/MySQL already do below). Reusing ILIKE for exact match turns out to be a trap: ILIKE's pattern-language treats a literal %/_ in the value as a wildcard, so an exact-match operator silently becomes a widened pattern match unless every value is escaped — and MongoDB's $eq/$in set-membership forms have no ESCAPE-clause equivalent at all, making that escaping structurally inapplicable to some backends' idiomatic forms. The rule, pinned: eq/neq/gt/gte/lt/lte/in/notIn, plus sorting on a case-insensitive field, use a case-insensitive COLLATION (an equality/ordering mechanism, no pattern language, nothing to escape). contains/notContains/startsWith/endsWith use ILIKE or the backend's substring mechanism (SEM-7 covers contains specifically) — a pattern-match mechanism is appropriate there because the operator itself is a pattern match; the value's own %/ _ are escaped there because the position is a pattern, not because the CI requirement demands it.

This paragraph says which mechanism when one is used at all; it does not say one always is. An earlier draft ended both sentences above with "plus sort and group-key matching", which #1640 made wrong and #1640's own review found still standing here — in the very sentence this section labels the rule, pinned — after the carve-out had been written into the intro and the Must-NOTs. A groupSpec.groupKeys drill-down match, a GROUP BY key and a grouped level's ORDER BY use no case-folding mechanism at all (GRP-2) — as do BM-3's SELECT DISTINCT key and its ORDER BY (GRP-6). A port implementing SEM-1 from the pinned sentence alone would emit the collation and fail group-aggregation/002 (and 016).

Rationale. AG Grid's in-memory (client-side) row model filters text case-insensitively by default. If the SSRM compiler defaults to case-sensitive comparison instead, the exact same filter typed into the exact same grid produces different rows depending on which row model happens to be active — a correctness regression that looks like a backend bug but is really a default mismatch. The "obvious" fix — wrap the column in lower()/LOWER() on both sides — reintroduces a different failure: on most SQL engines a bare function wrapper on the indexed column makes the predicate non-sargable, silently turning an indexed lookup into a full scan the moment a table grows past a trivial size. This is exactly the class of "broken null/case semantics" bug the TRD's problem statement (§1) calls out as endemic to hand-rolled OData/dynamic-LINQ translations. The rule exists so every dialect gets case-insensitivity and keeps its index.

Worked example, exact-match family — eq on name, case-insensitive, matching "Smith":

Worked example, substring family — contains on name, case-insensitive, matching "Bob Smith" against pattern "smith" — this is the pattern-match mechanism, distinct from the exact-match family above:

Ordering comparisons (gt/gte/lt/lte) on OpenSearch/Elasticsearch — the one real gap. Unlike term/wildcard, a range query has no case_insensitive parameter in the pinned 7.10-era subset, and there is no query-time equivalent. The compiler targets a schema-declared normalized sub-field (SC-3's search.normalizedSubField — a keyword sub-field maintained via an ICU-folding normalizer at index time, distinct from the plain .keyword exact-match sub-field search.keywordSubField used by term/in/notIn above) instead of the raw field:

// filtering `name > "Smith"` on a case-insensitive field:
{ "range": { "name.normalized": { "gt": "Smith" } } }

A field that needs case-insensitive ordering on ES/OpenSearch MUST declare search.normalizedSubField; a field that only needs case-insensitive equality/substring ops does not need one. This is a genuine index-time cost (SC-3, PERF-4), not a query-time toggle — document it per field, never assume it exists.

The compared VALUE is bound as typed — the sub-field is the mechanism, not a licence to fold the value too. The snippet above binds "Smith", unchanged, exactly as the collation arms bind it. A normalizer is applied at search time as well as at index time for a term-level query (which range is), so pre-folding is redundant; worse, it is unknowable — the schema declares the sub-field's name and nothing about what its normalizer does, and an ICU-folding one folds diacritics and width as well as case, so a compiler lowering "ÉCOLE" to "école" would miss every document the normalizer had reduced to "ecole". "Lowercase" is also not one operation across the four language ports G4 requires to agree. See OSE-6, and spec/fixtures/dialect-parity/015, whose Search arm pinned the folded value until #1644 compiled it.

Must NOT.

Cross-links. $defs/binaryOperator, $defs/setOperator, $defs/stringValue.