@ultimat3/testing 31.8.0 → 31.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +22 -22
- package/src/auth-adapter-conformance-sessions.ts +19 -0
- package/src/entity-conformance-chain-writes.ts +350 -0
- package/src/entity-conformance-checks.ts +22 -0
- package/src/entity-conformance-contains.ts +145 -0
- package/src/entity-conformance-counted-in.ts +229 -0
- package/src/entity-conformance-latest-by.ts +242 -0
- package/src/entity-conformance-lock-keys.ts +206 -0
- package/src/entity-conformance-matrix-writes.ts +75 -0
- package/src/entity-conformance-matrix.ts +5 -5
- package/src/entity-conformance-measures.ts +166 -0
- package/src/entity-conformance-page-bytes.ts +57 -0
- package/src/entity-conformance-tenancy.ts +46 -1
- package/src/entity-conformance-unreturned.ts +355 -0
- package/src/entity-conformance-update-many.ts +359 -0
- package/src/entity-conformance-version-lock.ts +204 -0
- package/src/entity-conformance-write-entities.ts +71 -0
- package/src/entity-conformance-write-support.ts +40 -0
- package/src/entity-driver-conformance.ts +10 -0
- package/src/plan-sweep-fix.ts +18 -0
- package/src/plan-sweep-report.ts +5 -2
- package/src/plan-trigram.ts +21 -0
|
@@ -30,6 +30,13 @@ export interface EntityDriverSubject {
|
|
|
30
30
|
* nothing: absent here, the history check is not run against it (there is no refusal to assert).
|
|
31
31
|
*/
|
|
32
32
|
readonly history?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Whether the store keeps a `references(…, { countedIn })` counter — Postgres by trigger, memory
|
|
35
|
+
* in its repository. A `defineDriver` store has no lifecycle hook, so it refuses a counted child's
|
|
36
|
+
* repository (`X_DRIVER_UNSUPPORTED`, capability `countedIn`): absent here, that refusal is
|
|
37
|
+
* asserted and the counter checks themselves are not run (there is no handle to run them on).
|
|
38
|
+
*/
|
|
39
|
+
readonly counters?: boolean;
|
|
33
40
|
/**
|
|
34
41
|
* How many lock requests are blocked behind a holder right now — `memoryLockWaiters` from
|
|
35
42
|
* `@ultimat3/entity/adapter`, or `pg_stat_activity`'s `wait_event_type = 'Lock'` on a pool. What
|
|
@@ -45,6 +52,8 @@ export interface EntityDriverRun {
|
|
|
45
52
|
readonly foreignKeys: boolean;
|
|
46
53
|
/** The subject's `history`, `false` when it declared none. */
|
|
47
54
|
readonly history: boolean;
|
|
55
|
+
/** The subject's `counters`, `false` when it declared none. */
|
|
56
|
+
readonly counters: boolean;
|
|
48
57
|
/** The subject's `lockWaiters`, when it can see one. */
|
|
49
58
|
readonly lockWaiters: (() => number | Promise<number>) | undefined;
|
|
50
59
|
}
|
|
@@ -103,6 +112,7 @@ export const runEntityDriverCheck = async (
|
|
|
103
112
|
driver,
|
|
104
113
|
foreignKeys: subject.foreignKeys,
|
|
105
114
|
history: subject.history === true,
|
|
115
|
+
counters: subject.counters === true,
|
|
106
116
|
lockWaiters: subject.lockWaiters,
|
|
107
117
|
});
|
|
108
118
|
};
|
package/src/plan-sweep-fix.ts
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
// lookup that pins a unique key reads one row whatever the planner walked to find it, and a whole
|
|
4
4
|
// read a keyed join side could probe by a declared index is one the planner declined on cost.
|
|
5
5
|
|
|
6
|
+
import { trigramDeclaration } from '@ultimat3/entity';
|
|
6
7
|
import type { PlanVerdict, PlanVerdictCode } from './plan-oracle';
|
|
7
8
|
import type { PlanUnservable } from './plan-sort-key';
|
|
8
9
|
import { sortKeyPart } from './plan-sort-key';
|
|
10
|
+
import { trigramColumns, trigramServed } from './plan-trigram';
|
|
9
11
|
import type { SeedEntity } from './seed-graph-shape';
|
|
10
12
|
|
|
11
13
|
export interface PlanFinding {
|
|
@@ -24,6 +26,11 @@ export interface PlanFinding {
|
|
|
24
26
|
* empty with it.
|
|
25
27
|
*/
|
|
26
28
|
readonly unserved?: PlanUnservable | 'declared';
|
|
29
|
+
/**
|
|
30
|
+
* The whole `indexes:` entry when a bare `on:` would not serve the statement: an `ilike` (a text
|
|
31
|
+
* `contains`) is served by a `gin_trgm_ops` index only (`plan-trigram.ts`).
|
|
32
|
+
*/
|
|
33
|
+
readonly declaration?: string;
|
|
27
34
|
}
|
|
28
35
|
|
|
29
36
|
/** Every column set the table holds unique: the primary key, unique columns, total unique rules. */
|
|
@@ -225,6 +232,17 @@ export function planFindings(
|
|
|
225
232
|
}
|
|
226
233
|
const description = entity.$describe();
|
|
227
234
|
const byColumn = new Map(description.columns.map((c) => [c.column, c.property]));
|
|
235
|
+
// BEFORE the btree rules: no btree serves an `ilike`, so a declared one argues nothing away.
|
|
236
|
+
const searched =
|
|
237
|
+
verdict.code === 'X_QUERY_UNINDEXED' ? trigramColumns(statement, verdict.range) : [];
|
|
238
|
+
if (searched.length > 0) {
|
|
239
|
+
return searched
|
|
240
|
+
.filter((column) => !trigramServed(entity, column))
|
|
241
|
+
.map((column) => {
|
|
242
|
+
const property = byColumn.get(column) ?? column;
|
|
243
|
+
return { ...finding, index: [property], declaration: trigramDeclaration(property) };
|
|
244
|
+
});
|
|
245
|
+
}
|
|
228
246
|
const walked = verdict.code === 'X_QUERY_UNINDEXED' && verdict.node !== 'Seq Scan';
|
|
229
247
|
// A walk filtered by a range already has its order: what it lacks is the bound. A btree serves
|
|
230
248
|
// no order after a range column, so the index is the equality columns, then the range.
|
package/src/plan-sweep-report.ts
CHANGED
|
@@ -21,9 +21,12 @@ const STATEMENT_CHARS = 160;
|
|
|
21
21
|
const excerpt = (statement: string): string =>
|
|
22
22
|
statement.length <= STATEMENT_CHARS ? statement : `${statement.slice(0, STATEMENT_CHARS)}…`;
|
|
23
23
|
|
|
24
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* `indexes: [{ on: ['orgId', 'authorId'] }]` — the line to paste into the entity; the finding's
|
|
26
|
+
* own `declaration` when a bare `on:` would not serve it (an `ilike` needs `gin_trgm_ops`).
|
|
27
|
+
*/
|
|
25
28
|
const indexLine = (finding: PlanFinding): string =>
|
|
26
|
-
`indexes: [{ on: [${finding.index.map((p) => `'${p}'`).join(', ')}] }]`;
|
|
29
|
+
finding.declaration ?? `indexes: [{ on: [${finding.index.map((p) => `'${p}'`).join(', ')}] }]`;
|
|
27
30
|
|
|
28
31
|
/**
|
|
29
32
|
* A read that compares no column of the table — a whole-table count, an unfiltered export — is
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// A text `contains` in a red statement: `ilike` as sent, `~~*` as a plan prints it. Only a
|
|
2
|
+
// `gin_trgm_ops` index serves it — a btree on the same column does not — so the finding names that
|
|
3
|
+
// declaration (`@ultimat3/entity`'s spelling) and only a declared trigram index argues it away.
|
|
4
|
+
|
|
5
|
+
import type { SeedEntity } from './seed-graph-shape';
|
|
6
|
+
|
|
7
|
+
const escaped = (name: string): string => name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
8
|
+
|
|
9
|
+
/** `"title" ilike $1`, `title ~~* $1`, `p.title ILIKE …`: the column, then the operator. */
|
|
10
|
+
const searches = (statement: string, column: string): boolean =>
|
|
11
|
+
new RegExp(`(?:^|[\\s(.,])"?${escaped(column)}"?\\s+(?:ilike|~~\\*)\\s`, 'i').test(statement);
|
|
12
|
+
|
|
13
|
+
/** The physical columns among `range` the statement compares with `ilike`. */
|
|
14
|
+
export const trigramColumns = (statement: string, range: readonly string[]): readonly string[] =>
|
|
15
|
+
range.filter((column) => searches(statement, column));
|
|
16
|
+
|
|
17
|
+
/** A declared `gin_trgm_ops` index leading with this physical column, total or partial. */
|
|
18
|
+
export const trigramServed = (entity: SeedEntity, column: string): boolean =>
|
|
19
|
+
entity
|
|
20
|
+
.$describe()
|
|
21
|
+
.indexes.some((index) => index.operatorClass === 'gin_trgm_ops' && index.columns[0] === column);
|