Craticula

Index and database guidance

Craticula compiles queries; it never creates a table, an index or a collation. This page lists, for each database, what you have to set up so the compiled queries return the right rows and run fast. The rules behind it are in semantics; the per-database fixtures that pin the statements are in spec/fixtures/dialect-parity.

Two kinds of obligation appear below, and the difference matters:

At a glance #

DatabaseYou must provideIf you do not
PostgreSQLversion 12 or later with ICU; the craticula_ci collation; timestamptz for datetimesloud for the first two (every case-insensitive comparison fails), silent for timestamp
SQL Serverbinary or case-sensitive collation on grouping columns; datetime2 holding UTCsilent: EMEA and emea share a group
MySQL / MariaDB_bin or _as_cs collation on case-sensitive and grouping columns; DATETIME holding UTCsilent: the declaration is ignored
SQLiteversion 3.30.0 or later; datetimes stored as yyyy-MM-ddTHH:mm:ss.fffZloud for the version, silent for the datetime text
Oracle12.2 or later; quoted identifiers; binary collation on grouping columns (the default session setting)loud for the first two, silent for the last
MongoDBserver 4.2 or laterloud: the pipeline is rejected
OpenSearch / Elasticsearchkeyword sub-fields, a normalizer for case-insensitive sorting, a precise number type for decimalssilent for a missing keyword sub-field in a filter (no rows match), loud in a sort; silent for rounding

Every engine also needs the schema's stable key to be unique, with at most one NULL (Deterministic paging). Most engines let a unique constraint hold many NULLs, which breaks the paging guarantee; declare the key NOT NULL. A text stable key that is case-insensitive also needs a binary or case-sensitive collation on MySQL and SQL Server, or two keys that differ only by case tie.

Indexes for every database #

PostgreSQL #

Needs PostgreSQL 12 or later built with ICU (a nondeterministic collation). One-time setup, in the database that holds your tables:

CREATE COLLATION craticula_ci (provider = icu, locale = 'und-u-ks-level2', deterministic = false);

Without it every case-insensitive =, IN, range and ORDER BY fails with an unknown collation (Case sensitivity).

SQL Server #

No collation setup for filters: the statement carries COLLATE Latin1_General_CI_AS (or Latin1_General_CS_AS for a field you declared case-sensitive) inline, so neither direction depends on the database's own collation.

Filters on that column still compare case-insensitively, because they state their own collation inline. The price is speed: a comparison that names a collation different from the column's usually cannot seek on it, so measure a case-insensitive filter on a column you also group by.

MySQL and MariaDB #

Case sensitivity there belongs to the column's collation, which a statement cannot override portably.

A column has one collation, so a groupable column made binary also makes the case-insensitive filters and prefixes on that same column case-sensitive, silently (GRP-2's accepted divergence #4). If you need both on one field, decide which matters more; the compiler cannot give you both from one column.

SQLite #

Oracle #

MongoDB #

OpenSearch and Elasticsearch #

One compiler serves both. The index mapping is yours, and the compiled queries name the sub-fields your schema declares.

What stays out of this page #

Per-engine tuning (partitions, covering indexes, shard counts) depends on your data and workload. The compiled statements are in the conformance fixtures, one folder per case, with the exact text each database receives; run EXPLAIN on those against your own tables.