Skip to content

Commit 8e48947

Browse files
committed
docs(spec, driver-sql): state that text in a measure filter compares by the backend collation
The aggregationFilter bit promised the in-memory answer on every operator but text ordering, which was measured on SQLite and PostgreSQL 16 only. Text equality and membership also follow a case- or accent-insensitive collation, as the same datasource's where does; the TSDoc, the describe and the changeset now say so and name MySQL and SQL Server as not measured. The changeset's kind line becomes semantic: a stored having or measure filter keeps validating and now matches other rows under the NULL rule. The query syntax page drops a row that listed the per-measure filter as not enforced. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5nSNBMzF8jj9quUkjf
1 parent 4775f3f commit 8e48947

7 files changed

Lines changed: 32 additions & 18 deletions

File tree

‎.changeset/33698-measure-filter-pushdown.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
feat(spec, objectql, driver-sql, driver-turso): a per-measure aggregation filter runs in SQL on driver-sql, behind one declared driver capability (#33698)
99

1010
Clause-②: yes (widening: one optional DriverCapabilities bit)
11-
Metadata-protocol: added
11+
Metadata-protocol: semantic
1212

13-
**The capability.** `DriverCapabilities` (`@objectstack/spec/data`) gains one optional boolean, `aggregationFilter`: the driver's `aggregate()` evaluates a per-measure `aggregations[].filter` itself, with the answers the engine's in-memory aggregation gives. Absence means `false`. A driver that declares nothing keeps exactly the path it had.
13+
**The capability.** `DriverCapabilities` (`@objectstack/spec/data`) gains one optional boolean, `aggregationFilter`: the driver's `aggregate()` evaluates a per-measure `aggregations[].filter` itself, with the answers the engine's in-memory aggregation gives, except that text compares by the database collation (see the last paragraph). Absence means `false`. A driver that declares nothing keeps exactly the path it had.
1414

1515
**What runs where.**
1616

@@ -23,4 +23,4 @@ Metadata-protocol: added
2323

2424
**A measure filter the `where` compiler refuses now refuses on driver-sql.** Because driver-sql compiles a measure filter with the same where compiler, a filter that compiler refuses answers the same `400 INVALID_FILTER` its `where` twin answers. The recorded case is a `{ $field }` comparison between columns of different classes on an object with no audit fields (`created_at` against an image field): before, the engine evaluated it in memory and answered `200`; on driver-sql it now answers `400 INVALID_FILTER`, as `where` always did. A driver without the bit still evaluates it in memory and answers `200`.
2525

26-
**Declared latitude.** Ordering a non-temporal text column (`$gt` / `$lt` / `$between` on text) follows the database collation, as it always has for a `where`. On a database whose collation is not code-point order (measured: PostgreSQL with an ICU `en-US` collation), such a measure filter can select other rows in SQL than in memory. Every other operator agreed on SQLite and PostgreSQL 16. MySQL was not measured.
26+
**Declared latitude: text compares by the database collation.** On driver-sql a measure filter now answers what the `where` of the same datasource answers, so text comparison in it follows the database collation, where the in-memory path compares text exactly. Ordering a non-temporal text column (`$gt` / `$lt` / `$between` on text) follows the collation everywhere; on a case- or accent-insensitive collation, equality and membership do too, so `stage $eq 'won'` also counts `Won` rows, as `where` already does. Measured: SQLite and PostgreSQL 16 agree with the in-memory path on every operator with a `C.UTF-8` collation; PostgreSQL 16 with an ICU `en-US` collation differs only in text ordering. MySQL and SQL Server were not measured; their default collations are case-insensitive.

‎content/docs/protocol/objectql/query-syntax.mdx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ on the `find()` path:
9090

9191
| Member | Status |
9292
|:-------|:-------|
93-
| `aggregations[].filter` | `[EXPERIMENTAL — not enforced]` — a SQL `FILTER (WHERE …)` affordance neither the SQL builders nor the in-memory fallback applies |
9493
| `search.fuzzy` / `boost` / `operator` / `minScore` / `language` / `highlight` | `[EXPERIMENTAL — not enforced]` — only `query` and `fields` drive the expansion |
9594

9695
`top` is the exception that *is* honored — the engine normalises it to `limit`.

‎content/docs/references/data/driver-nosql.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ const result = AggregationPipelineSchema.parse(data);
165165
| **autonumber** | `boolean` | optional | Driver natively generates persistent autonumber/sequence values |
166166
| **batchSchemaSync** | `boolean` | optional | Supports batched schema sync to reduce schema DDL round-trips (absence = false) |
167167
| **transactionsUnsupported** | `boolean` | optional | Transport cannot honour transactions even though `beginTransaction` is inherited (absence = false) |
168-
| **aggregationFilter** | `boolean` | optional | `aggregate()` evaluates a per-measure `aggregations[].filter` itself, with the engine's in-memory answer (absence = false: the engine aggregates filtered measures in memory) |
168+
| **aggregationFilter** | `boolean` | optional | `aggregate()` evaluates a per-measure `aggregations[].filter` itself, with the engine's in-memory answer, except that text compares by the backend collation as in `where` (absence = false: the engine aggregates filtered measures in memory) |
169169
| **create** | `never` | optional | [REMOVED] `DriverCapabilities.create` was removed in @objectstack/spec 17.0.0 (ADR-0049 enforce-or-remove) — no code in any repository ever read it, so its value never changed which code path ran. CRUD is not optional for a driver: `create`/`find`/`findOne`/`update`/`delete` are REQUIRED `IDataDriver` methods and the engine calls them unconditionally. Delete the key. |
170170
| **read** | `never` | optional | [REMOVED] `DriverCapabilities.read` was removed in @objectstack/spec 17.0.0 (ADR-0049 enforce-or-remove) — no code in any repository ever read it, so its value never changed which code path ran. CRUD is not optional for a driver: reads go through the REQUIRED `find`/`findOne`/`count` methods, called unconditionally. Delete the key. |
171171
| **update** | `never` | optional | [REMOVED] `DriverCapabilities.update` was removed in @objectstack/spec 17.0.0 (ADR-0049 enforce-or-remove) — no code in any repository ever read it, so its value never changed which code path ran. CRUD is not optional for a driver: `update`/`upsert` are REQUIRED `IDataDriver` methods, called unconditionally. Delete the key. |

‎content/docs/references/data/driver-sql.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const result = DataTypeMappingSchema.parse(data);
7878
| **autonumber** | `boolean` | optional | Driver natively generates persistent autonumber/sequence values |
7979
| **batchSchemaSync** | `boolean` | optional | Supports batched schema sync to reduce schema DDL round-trips (absence = false) |
8080
| **transactionsUnsupported** | `boolean` | optional | Transport cannot honour transactions even though `beginTransaction` is inherited (absence = false) |
81-
| **aggregationFilter** | `boolean` | optional | `aggregate()` evaluates a per-measure `aggregations[].filter` itself, with the engine's in-memory answer (absence = false: the engine aggregates filtered measures in memory) |
81+
| **aggregationFilter** | `boolean` | optional | `aggregate()` evaluates a per-measure `aggregations[].filter` itself, with the engine's in-memory answer, except that text compares by the backend collation as in `where` (absence = false: the engine aggregates filtered measures in memory) |
8282
| **create** | `never` | optional | [REMOVED] `DriverCapabilities.create` was removed in @objectstack/spec 17.0.0 (ADR-0049 enforce-or-remove) — no code in any repository ever read it, so its value never changed which code path ran. CRUD is not optional for a driver: `create`/`find`/`findOne`/`update`/`delete` are REQUIRED `IDataDriver` methods and the engine calls them unconditionally. Delete the key. |
8383
| **read** | `never` | optional | [REMOVED] `DriverCapabilities.read` was removed in @objectstack/spec 17.0.0 (ADR-0049 enforce-or-remove) — no code in any repository ever read it, so its value never changed which code path ran. CRUD is not optional for a driver: reads go through the REQUIRED `find`/`findOne`/`count` methods, called unconditionally. Delete the key. |
8484
| **update** | `never` | optional | [REMOVED] `DriverCapabilities.update` was removed in @objectstack/spec 17.0.0 (ADR-0049 enforce-or-remove) — no code in any repository ever read it, so its value never changed which code path ran. CRUD is not optional for a driver: `update`/`upsert` are REQUIRED `IDataDriver` methods, called unconditionally. Delete the key. |

‎content/docs/references/data/driver.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const result = DriverCapabilitiesSchema.parse(data);
3232
| **autonumber** | `boolean` | optional | Driver natively generates persistent autonumber/sequence values |
3333
| **batchSchemaSync** | `boolean` | optional | Supports batched schema sync to reduce schema DDL round-trips (absence = false) |
3434
| **transactionsUnsupported** | `boolean` | optional | Transport cannot honour transactions even though `beginTransaction` is inherited (absence = false) |
35-
| **aggregationFilter** | `boolean` | optional | `aggregate()` evaluates a per-measure `aggregations[].filter` itself, with the engine's in-memory answer (absence = false: the engine aggregates filtered measures in memory) |
35+
| **aggregationFilter** | `boolean` | optional | `aggregate()` evaluates a per-measure `aggregations[].filter` itself, with the engine's in-memory answer, except that text compares by the backend collation as in `where` (absence = false: the engine aggregates filtered measures in memory) |
3636
| **create** | `never` | optional | [REMOVED] `DriverCapabilities.create` was removed in @objectstack/spec 17.0.0 (ADR-0049 enforce-or-remove) — no code in any repository ever read it, so its value never changed which code path ran. CRUD is not optional for a driver: `create`/`find`/`findOne`/`update`/`delete` are REQUIRED `IDataDriver` methods and the engine calls them unconditionally. Delete the key. |
3737
| **read** | `never` | optional | [REMOVED] `DriverCapabilities.read` was removed in @objectstack/spec 17.0.0 (ADR-0049 enforce-or-remove) — no code in any repository ever read it, so its value never changed which code path ran. CRUD is not optional for a driver: reads go through the REQUIRED `find`/`findOne`/`count` methods, called unconditionally. Delete the key. |
3838
| **update** | `never` | optional | [REMOVED] `DriverCapabilities.update` was removed in @objectstack/spec 17.0.0 (ADR-0049 enforce-or-remove) — no code in any repository ever read it, so its value never changed which code path ran. CRUD is not optional for a driver: `update`/`upsert` are REQUIRED `IDataDriver` methods, called unconditionally. Delete the key. |
@@ -88,7 +88,7 @@ const result = DriverCapabilitiesSchema.parse(data);
8888
| **autonumber** | `boolean` | optional | Driver natively generates persistent autonumber/sequence values |
8989
| **batchSchemaSync** | `boolean` | optional | Supports batched schema sync to reduce schema DDL round-trips (absence = false) |
9090
| **transactionsUnsupported** | `boolean` | optional | Transport cannot honour transactions even though `beginTransaction` is inherited (absence = false) |
91-
| **aggregationFilter** | `boolean` | optional | `aggregate()` evaluates a per-measure `aggregations[].filter` itself, with the engine's in-memory answer (absence = false: the engine aggregates filtered measures in memory) |
91+
| **aggregationFilter** | `boolean` | optional | `aggregate()` evaluates a per-measure `aggregations[].filter` itself, with the engine's in-memory answer, except that text compares by the backend collation as in `where` (absence = false: the engine aggregates filtered measures in memory) |
9292
| **create** | `never` | optional | [REMOVED] `DriverCapabilities.create` was removed in @objectstack/spec 17.0.0 (ADR-0049 enforce-or-remove) — no code in any repository ever read it, so its value never changed which code path ran. CRUD is not optional for a driver: `create`/`find`/`findOne`/`update`/`delete` are REQUIRED `IDataDriver` methods and the engine calls them unconditionally. Delete the key. |
9393
| **read** | `never` | optional | [REMOVED] `DriverCapabilities.read` was removed in @objectstack/spec 17.0.0 (ADR-0049 enforce-or-remove) — no code in any repository ever read it, so its value never changed which code path ran. CRUD is not optional for a driver: reads go through the REQUIRED `find`/`findOne`/`count` methods, called unconditionally. Delete the key. |
9494
| **update** | `never` | optional | [REMOVED] `DriverCapabilities.update` was removed in @objectstack/spec 17.0.0 (ADR-0049 enforce-or-remove) — no code in any repository ever read it, so its value never changed which code path ran. CRUD is not optional for a driver: `update`/`upsert` are REQUIRED `IDataDriver` methods, called unconditionally. Delete the key. |

‎packages/drivers/driver-sql/src/sql-driver.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,9 @@ export class SqlDriver implements IDataDriver {
389389
// engine sends filtered measures here instead of reading every row into
390390
// memory. A subclass whose transport cannot run the compile (TursoDriver's
391391
// remote mode answers `aggregate()` with 501) spreads this and turns it off.
392+
// Declared on every dialect: text comparison in the filter is then the
393+
// collation's, as for this datasource's `where` (the latitude the bit's
394+
// TSDoc in `data/driver.zod.ts` states, measured dialects named there).
392395
aggregationFilter: true,
393396
};
394397
}

‎packages/spec/src/data/driver.zod.ts‎

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,27 @@ export const DriverCapabilitiesSchema = lazySchema(() => z.object({
293293
* statement's `where` and stay on the whole statement; the measure filter
294294
* only narrows inside it.
295295
*
296-
* The one latitude the promise inherits rather than closes: ordering a
297-
* NON-temporal text column (`$gt` / `$lt` / `$between` on text) is the
298-
* backend collation's, not promised (the comparison-operator text in
299-
* `filter.zod.ts`), exactly as it is for a `where`. On a backend whose
300-
* collation is not code-point order — measured: PostgreSQL with an ICU
301-
* `en-US` database collation — such a measure filter can select other rows
302-
* than the in-memory path, which orders by UTF-16 code units. Every other
303-
* operator, and ordering on numbers, dates, datetimes and times, answers
304-
* alike.
296+
* The latitude the promise inherits rather than closes: TEXT comparison in
297+
* a measure filter is the backend collation's, as it is for a `where` on the
298+
* same datasource. A measure filter answers what its `where` twin answers
299+
* there, not what the in-memory path answers, which compares text exactly,
300+
* by UTF-16 code units. Concretely:
301+
*
302+
* - ordering a NON-temporal text column (`$gt` / `$gte` / `$lt` / `$lte` /
303+
* `$between` on text) follows the collation on every backend; it is not
304+
* promised in any case (the comparison-operator text in `filter.zod.ts`);
305+
* - equality and membership on text (`$eq`, implicit equality, `$ne`, `$in`,
306+
* `$nin`) follow the collation too, so on a case- or accent-insensitive
307+
* collation `stage $eq 'won'` also selects `Won`, exactly as the `where`
308+
* of the same datasource does.
309+
*
310+
* Measured (in-memory path against driver-sql's where compiler, 119
311+
* filters): SQLite, and PostgreSQL 16 with a `C.UTF-8` database collation,
312+
* answer alike on every operator; PostgreSQL 16 with an ICU `en-US` database
313+
* collation differs only in text ordering. NOT measured: MySQL and SQL
314+
* Server, whose default collations are case-insensitive, so equality and
315+
* membership on text are expected to fold case there. Numbers, booleans,
316+
* dates, datetimes and times answer alike wherever measured.
305317
*
306318
* What the engine does with it: `engine.aggregate` sends an aggregate whose
307319
* measures carry a filter to `driver.aggregate` only when this bit is `true`
@@ -323,7 +335,7 @@ export const DriverCapabilitiesSchema = lazySchema(() => z.object({
323335
*
324336
* Optional; absence means `false`, like `batchSchemaSync`.
325337
*/
326-
aggregationFilter: z.boolean().optional().describe('`aggregate()` evaluates a per-measure `aggregations[].filter` itself, with the engine\'s in-memory answer (absence = false: the engine aggregates filtered measures in memory)'),
338+
aggregationFilter: z.boolean().optional().describe('`aggregate()` evaluates a per-measure `aggregations[].filter` itself, with the engine\'s in-memory answer, except that text compares by the backend collation as in `where` (absence = false: the engine aggregates filtered measures in memory)'),
327339

328340
// ============================================================================
329341
// Retired capability bits (#4634, ADR-0049 enforce-or-remove) — 17.0.0

0 commit comments

Comments
 (0)