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.groupKeysdrill-down match, aGROUP BYkey and a grouped level'sORDER BYuse no case-folding mechanism at all (GRP-2) — as do BM-3'sSELECT DISTINCTkey and itsORDER BY(GRP-6). A port implementing SEM-1 from the pinned sentence alone would emit the collation and failgroup-aggregation/002(and016).
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":
- PostgreSQL — a case-insensitive collation on the comparison, never
ILIKE(see the mechanism note above). This project's fixtures and reference docs pin one canonical, explicitly host-created ICU collation name for this purpose —craticula_ci— rather than each host inventing its own name:-- One-time host DDL, documented in the per-backend index-guidance page (PERF-4): -- CREATE COLLATION craticula_ci (provider = icu, locale = 'und-u-ks-level2', deterministic = false); WHERE name COLLATE craticula_ci = :v - SQL Server / MySQL — unchanged from before: a case-insensitive collation on the column (or applied inline), so the engine's own comparison semantics do the folding and a plain B-tree index remains usable:
-- SQL Server: column declared/queried with a CI collation WHERE name COLLATE Latin1_General_CI_AS = @v -- MySQL: column already uses a _ci collation (e.g. utf8mb4_0900_ai_ci) WHERE name = :v - MongoDB — a query-level collation with
strength: 2makes$eq/$in/$gt/$lt/$sortcompare case-insensitively (and can still use a supporting index), which is the mechanism this document means wherever it says "the collation option for CI" (e.g. TRD §5's Mongo row):db.items.find( { name: "Smith" }, { collation: { locale: "en", strength: 2 } } ) - OpenSearch / Elasticsearch — a term-level query's
case_insensitiveparameter (available onterm,wildcard,prefix, andregexpsince 7.10 — notrange; ordering comparisons on ES/OpenSearch are covered separately below) against akeywordfield:{ "term": { "name.keyword": { "value": "Smith", "case_insensitive": true } } }
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:
- PostgreSQL —
ILIKE, backed by apg_trgmGIN index (PERF-4 index guidance) rather than a functional index onlower(name):WHERE name ILIKE '%' || :pattern || '%' ESCAPE '\' - MongoDB — no collation-compatible substring operator exists;
containsnecessarily compiles to$regexwith the"i"option, which is not index-friendly the way the collation/pg_trgmforms above are — SEM-7 covers this mechanism (and its escaping requirements) in full. - OpenSearch / Elasticsearch —
wildcard/case_insensitiveagainst thekeywordsub-field, no separate analyzed sub-field or runtime lowercasing required (SEM-7 governs the substring mechanics themselves):{ "wildcard": { "name.keyword": { "value": "*smith*", "case_insensitive": true } } }
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.
- Must NOT wrap the column/field in a bare
lower()/LOWER()/toLowerCasewhen the dialect offers an index-friendly alternative (ILIKE, a CI collation,case_insensitivequery option) — reserve the bare wrapper for the rare dialect that truly has nothing better, and document that exception per dialect (PERF-4). - Must NOT default to case-sensitive comparison "because SQL's default collation is case-sensitive on this engine" — the IR-level default is case-insensitive regardless of any one engine's own default; per-field case sensitivity is an explicit schema opt-in (SC-3), never an accidental inheritance from the underlying engine.
- Must NOT apply case-folding inconsistently between the comparison and any related
ORDER BY/sort on the same field — case sensitivity is a per-field property, not a per-operator or per-context one. (AgroupSpec.groupKeysdrill-down match is the documented carve-out: it is exact, together with theGROUP BYandORDER BYof the same statement — GRP-2, not this rule. So is BM-3'sSELECT DISTINCTkey with its ownORDER BY— GRP-6, and note that a set filter's search prefix over that same column IS governed here, which is why one such statement legitimately spells two mechanisms.) - Must NOT use
ILIKE/pattern-match as the mechanism foreq/neq/in/notIn/ordering/sort — that mechanism is a collation. ReserveILIKE/pattern-match forcontains/notContains/startsWith/endsWith, where the operator itself is a pattern match. - Must NOT assume an ES/OpenSearch
rangequery can be made case-insensitive at query time — it cannot in the pinned 7.10-era subset; case-insensitive ordering requires a schema-declaredsearch.normalizedSubField, index-time cost included.
Cross-links. $defs/binaryOperator, $defs/setOperator, $defs/stringValue.