turbine-orm 0.56.0 → 0.58.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/README.md CHANGED
@@ -454,7 +454,7 @@ const db = turbine({
454
454
 
455
455
  Where a pg-style alias exists (`max`, `idleTimeoutMillis`, `connectionTimeoutMillis`), the explicit Turbine field wins when both are set.
456
456
 
457
- > **`planCacheMode` (Postgres only, opt-in).** PostgreSQL may promote a **named** prepared statement to a generic plan from its sixth execution onward, and a generic plan is costed blind to the bound values. On a predicate whose selectivity swings per value (a `tenant_id` equality on a shared table, where one value matches a handful of rows and another matches most of them), the statement can be locked onto a plan chosen for the average value, and it never reverts. `planCacheMode: 'auto' | 'force_custom_plan' | 'force_generic_plan'` pins the backend's choice; `'force_custom_plan'` re-plans every execution and removes the cliff. It is applied as a connection parameter (`options=-c plan_cache_mode=...`) when Turbine opens a connection, so it is in force for that connection's first statement and for every checkout, `$transaction`, stream and pipeline on it, and it cannot race your first query. Leave it unset (the default) and Turbine sends nothing at all. Reach for it when you have measured a statement getting slower after its fifth execution. **Correction to the 0.54 text, which said `findMany` / `findFirst` bind `LIMIT $n` and are "much less exposed":** that was false. PostgreSQL does not deny the planner a limit fraction for a bound limit, it substitutes a default of 10% of the child node's own row estimate (clamped at one row), and an unknown `OFFSET` triggers the same substitution even when the limit is a constant, which a paginated Turbine read always has. Two things also need saying about the sentence that opens this note. The sixth execution is a ceiling, not a trigger: `auto` promotes only when the generic plan's **estimated** cost is not worse than the average custom cost, so many statements are never promoted at all, and `pg_prepared_statements.generic_plans` is how you tell. And the shape that gets promoted unprompted is the one with **no limit**, not the limited one: measured on a skewed join predicate, an unlimited `count()`-shaped statement promoted under the default `auto` and ran a nested loop at 430x the buffers of the custom plan, while the same predicate under `LIMIT $n` was never promoted across eight executions (its substituted row count made the generic plan look more expensive). A limited `findMany` gives the planner two unknowns instead of one, which is not the same as more damage. `implicitPkOrdering` is **off by default in core**, so a default `findMany` emits no `ORDER BY`; switching it on adds an ordering a generic plan can walk the whole table in. Measure with `plan_cache_mode = force_generic_plan` against `force_custom_plan` rather than reasoning about which shapes ought to be safe; the fixtures and numbers are on the [relations page](https://turbineorm.dev/relations) and in the 0.55.0 changelog. **Two 0.56 corrections to the paragraph above.** First, "neither an ORDER BY nor a limit is required" is true, but it read as if ordering did not matter: on a real multi-tenant schema swept table by table, every divergent shape had an `ORDER BY` and every shape without one measured 1.00x, so it is not necessary in general and is still the strongest single predictor in practice. Second, a custom plan is not automatically the better one: on a reproducible fixture where one dense value's rows are packed at the end of the heap, `LIMIT 20` with no ordering reads 4,262 buffers custom against 71 generic (the default `auto` never promotes there, so it produces the 4,262-buffer plan too). Since 0.56 the per-query read arg **`forceCustomPlan: true`** covers the case a connection-wide setting cannot express, custom on one query and `auto` everywhere else, and `turbine doctor` detects the distribution that admits the flip. Three scope limits: it does nothing on an **external pool** (Turbine never opens those connections, so set the GUC in the driver's own setup; Turbine-owned string `replicas` on that same client DO get it); a Postgres wire-compatible engine without the setting (CockroachDB, YugabyteDB, pre-12 PostgreSQL) refuses the connection parameter itself; and a **connection pooler** may filter startup parameters (PgBouncer's `ignore_startup_parameters`), where `ALTER ROLE ... SET plan_cache_mode = ...` is the way in. Any value outside the three throws `ValidationError` at construction, and a non-Postgres engine throws `UnsupportedFeatureError` (`TURBINE_E017`).
457
+ > **`planCacheMode` (Postgres only, opt-in).** PostgreSQL may promote a **named** prepared statement to a generic plan from its sixth execution onward, and a generic plan is costed blind to the bound values. On a predicate whose selectivity swings per value (a `tenant_id` equality on a shared table, where one value matches a handful of rows and another matches most of them), the statement can be locked onto a plan chosen for the average value, and it never reverts. `planCacheMode: 'auto' | 'force_custom_plan' | 'force_generic_plan'` pins the backend's choice; `'force_custom_plan'` re-plans every execution and removes the cliff. It is applied as a connection parameter (`options=-c plan_cache_mode=...`) when Turbine opens a connection, so it is in force for that connection's first statement and for every checkout, `$transaction`, stream and pipeline on it, and it cannot race your first query. Leave it unset (the default) and Turbine sends nothing at all. Reach for it when you have measured a statement getting slower after its fifth execution. **Correction to the 0.54 text, which said `findMany` / `findFirst` bind `LIMIT $n` and are "much less exposed":** that was false. PostgreSQL does not deny the planner a limit fraction for a bound limit, it substitutes a default of 10% of the child node's own row estimate (clamped at one row), and an unknown `OFFSET` triggers the same substitution even when the limit is a constant, which a paginated Turbine read always has. Two things also need saying about the sentence that opens this note. The sixth execution is a ceiling, not a trigger: `auto` promotes only when the generic plan's **estimated** cost is not worse than the average custom cost, so many statements are never promoted at all, and `pg_prepared_statements.generic_plans` is how you tell. And the shape that gets promoted unprompted is the one with **no limit**, not the limited one: measured on a skewed join predicate, an unlimited `count()`-shaped statement promoted under the default `auto` and ran a nested loop at 430x the buffers of the custom plan, while the same predicate under `LIMIT $n` was never promoted across eight executions (its substituted row count made the generic plan look more expensive). A limited `findMany` gives the planner two unknowns instead of one, which is not the same as more damage. `implicitPkOrdering` is **off by default in core**, so a default `findMany` emits no `ORDER BY`; switching it on adds an ordering a generic plan can walk the whole table in. Measure with `plan_cache_mode = force_generic_plan` against `force_custom_plan` rather than reasoning about which shapes ought to be safe; the fixtures and numbers are on the [relations page](https://turbineorm.dev/relations) and in the 0.55.0 changelog. **Two 0.56 corrections to the paragraph above.** First, "neither an ORDER BY nor a limit is required" is true, but it read as if ordering did not matter: on a real multi-tenant schema swept table by table, every divergent shape had an `ORDER BY` and every shape without one measured 1.00x, so it is not necessary in general and is still the strongest single predictor in practice. Second, a custom plan is not automatically the better one: on a reproducible fixture where one dense value's rows are packed at the end of the heap, `LIMIT 20` with no ordering reads 4,262 buffers custom against 71 generic (the default `auto` never promotes there, so it produces the 4,262-buffer plan too). Since 0.56 the per-query read arg **`forceCustomPlan: true`** covers the case a connection-wide setting cannot express, custom on one query and `auto` everywhere else, and `turbine doctor` detects the distribution that admits the flip. **0.57 correction:** that read arg reached the core client only. Through `turbine-orm/prisma-compat` it was accepted and silently dropped until 0.57.0, so a compat integration that followed this advice got a no-op; confirm at the wire with `pg_prepared_statements` rather than assuming. 0.57 also adds a third divergence mechanism to `doctor`: an **unindexed** filter column, where the good plan is a sequential scan the generic plan will not choose (measured 250 buffers against 20,074 on a 20,000-row / 247-page fixture). Three scope limits: it does nothing on an **external pool** (Turbine never opens those connections, so set the GUC in the driver's own setup; Turbine-owned string `replicas` on that same client DO get it); a Postgres wire-compatible engine without the setting (CockroachDB, YugabyteDB, pre-12 PostgreSQL) refuses the connection parameter itself; and a **connection pooler** may filter startup parameters (PgBouncer's `ignore_startup_parameters`), where `ALTER ROLE ... SET plan_cache_mode = ...` is the way in. Any value outside the three throws `ValidationError` at construction, and a non-Postgres engine throws `UnsupportedFeatureError` (`TURBINE_E017`).
458
458
 
459
459
  > **`preparedStatements` and connection poolers.** With prepared statements on, Turbine submits queries as `{ name, text, values }` so Postgres caches the parse and plan **per backend connection**. That is a real win against a database you connect to directly, and a hazard behind a transaction-pooling proxy (PgBouncer in `transaction` mode, Supabase's pooler port, some serverless poolers): the named statement is prepared on one backend and your next query may land on another, which fails with `prepared statement "..." does not exist`. Turbine defaults it to `true` only for pools it creates itself and `false` for external pools passed via `pool` / `turbineHttp()`, because serverless drivers are the common case there. If you are pointing a Turbine-owned pool at a transaction pooler, set `preparedStatements: false`. The environment variable `TURBINE_DISABLE_PREPARED=1` turns it off globally without a code change.
460
460
 
@@ -1038,6 +1038,21 @@ const prisma = createPrismaCompatClient(db, PRISMA_MAP);
1038
1038
  const users = await prisma.User.findMany({ include: { posts: { take: 5 } } });
1039
1039
  ```
1040
1040
 
1041
+ Turbine-only query options (`forceCustomPlan`, `skipGlobalFilters`, `allowFullTableScan`,
1042
+ `warnOnUnlimited`, `timeout`, `optimisticLock`, `distinctOn`, …) pass through the compat
1043
+ delegates, and an unrecognized query-level key logs a one-time dev warning naming the
1044
+ nearest real option instead of being dropped.
1045
+
1046
+ > **Correction, 0.57.0.** Before that release the adapter copied a hand-written allowlist
1047
+ > of keys, so those options were accepted by the type-checker and silently dropped. That
1048
+ > includes `forceCustomPlan`, which 0.56.0 shipped and `turbine doctor` recommended: on
1049
+ > prisma-compat it did nothing at all, while working exactly as documented on the core
1050
+ > client. Two changes are visible on upgrade even if you change nothing: `skipGlobalFilters`
1051
+ > now takes effect where it was inert, and `relationLoadStrategy: 'query'` now maps to
1052
+ > Turbine's `'batched'` instead of silently using the join plan. The option surface is now
1053
+ > compiler-checked against the core argument interfaces, so a newly added core option fails
1054
+ > the build in the adapter rather than being stranded in silence.
1055
+
1041
1056
  ### Capability matrix
1042
1057
 
1043
1058
  Everything is honest about what ports and what doesn't. Features marked **PG-only** throw a typed `UnsupportedFeatureError` (`TURBINE_E017`) on other engines rather than silently degrading.
@@ -83,6 +83,8 @@ const index_advisor_js_1 = require("../index-advisor.js");
83
83
  const index_stats_js_1 = require("../index-stats.js");
84
84
  const introspect_js_1 = require("../introspect.js");
85
85
  const plan_divergence_js_1 = require("../plan-divergence.js");
86
+ const plan_flip_probe_js_1 = require("../plan-flip-probe.js");
87
+ const schema_js_1 = require("../schema.js");
86
88
  const schema_sql_js_1 = require("../schema-sql.js");
87
89
  const config_js_1 = require("./config.js");
88
90
  const destructive_js_1 = require("./destructive.js");
@@ -2324,8 +2326,14 @@ async function cmdDoctor(args, config) {
2324
2326
  // one-connection snapshot rather than opening a second read.
2325
2327
  const divergenceOn = args.noPlanDivergence !== true;
2326
2328
  const divergenceColumns = divergenceOn ? (0, plan_divergence_js_1.collectDivergenceCandidateColumns)(schema) : [];
2329
+ // The columns a finding could ORDER BY, read alongside the candidates: the
2330
+ // size of an unindexed-filter flip turns on the ORDER column's correlation,
2331
+ // not the filter column's, and reading only the latter is how an earlier
2332
+ // revision printed a statistic about the wrong column.
2333
+ const divergenceOrderColumns = divergenceOn ? (0, plan_divergence_js_1.collectDivergenceOrderColumns)(schema) : [];
2327
2334
  const probedTables = [...new Set(missing.map((m) => m.table))];
2328
2335
  const statsTables = [...new Set([...probedTables, ...divergenceColumns.map((c) => c.table)])];
2336
+ const distributionColumns = [...divergenceColumns, ...divergenceOrderColumns];
2329
2337
  let snapshot;
2330
2338
  try {
2331
2339
  snapshot = await (0, index_stats_js_1.collectStatsSnapshot)({
@@ -2333,7 +2341,7 @@ async function cmdDoctor(args, config) {
2333
2341
  schema: config.schema,
2334
2342
  tables: statsTables,
2335
2343
  columns: probedColumns,
2336
- distributionColumns: divergenceColumns,
2344
+ distributionColumns,
2337
2345
  });
2338
2346
  }
2339
2347
  catch (err) {
@@ -2376,9 +2384,18 @@ async function cmdDoctor(args, config) {
2376
2384
  // trustworthy stats_reset age because they normalize write counters by it;
2377
2385
  // this check reads no counter, only pg_stats, whose freshness is ANALYZE. A
2378
2386
  // cluster with a NULL stats_reset (the default) must still get the check.
2379
- const divergence = divergenceOn && snapshot.available
2387
+ const scored = divergenceOn && snapshot.available
2380
2388
  ? (0, plan_divergence_js_1.findPlanDivergence)(schema, snapshot)
2381
- : { findings: [], notices: [], candidatesConsidered: 0 };
2389
+ : { findings: [], notices: [], candidatesConsidered: 0, consideredIndexed: 0, consideredUnindexed: 0 };
2390
+ // Statistics can say how bad a flip WOULD be; only the planner can say whether
2391
+ // it is reachable. The `unindexed-filter` branch shipped in 0.57 without that
2392
+ // question answered and was right 6 times in 13 on a real schema, so every one
2393
+ // of its findings is now put to a plan-only EXPLAIN. Nothing is executed, and a
2394
+ // probe that fails keeps its finding rather than dropping it.
2395
+ const flipProbe = divergenceOn && scored.findings.some(plan_flip_probe_js_1.needsFlipProbe)
2396
+ ? await (0, plan_flip_probe_js_1.probePlanFlips)({ connectionString: url, schema: config.schema, findings: scored.findings })
2397
+ : (0, plan_flip_probe_js_1.emptyFlipProbeResult)();
2398
+ const divergence = (0, plan_flip_probe_js_1.applyFlipVerdicts)(scored, flipProbe);
2382
2399
  if (jsonMode) {
2383
2400
  spinner?.stop();
2384
2401
  console.log(JSON.stringify(buildDoctorJson({ schema, findings, invalid, snapshot, usable, heat, subtract, divergence, args }), null, 2));
@@ -2465,6 +2482,20 @@ function buildDoctorJson(ctx) {
2465
2482
  // just because the section was skipped or found nothing.
2466
2483
  out.planDivergence = ctx.divergence.findings;
2467
2484
  out.planDivergenceNotices = ctx.divergence.notices;
2485
+ // How large the scored population was, and how it split. A consumer counting
2486
+ // findings alone cannot tell "considered and clean" from "never looked", and
2487
+ // the unindexed half of that population did not exist before.
2488
+ out.planDivergenceScored = {
2489
+ considered: ctx.divergence.candidatesConsidered,
2490
+ indexed: ctx.divergence.consideredIndexed,
2491
+ unindexed: ctx.divergence.consideredUnindexed,
2492
+ // Whether the unindexed findings above were put to the planner, and how many
2493
+ // it refuted. `flipProbed: false` means they are statistics-only and carry
2494
+ // 0.57's precision, so a consumer can tell a verified list from an unverified
2495
+ // one instead of inferring it from the count.
2496
+ flipProbed: ctx.divergence.flipProbed === true,
2497
+ flipRefuted: ctx.divergence.flipRefuted ?? 0,
2498
+ };
2468
2499
  return out;
2469
2500
  }
2470
2501
  async function renderDoctorHuman(ctx) {
@@ -2483,6 +2514,11 @@ async function renderDoctorHuman(ctx) {
2483
2514
  (0, ui_js_1.newline)();
2484
2515
  return;
2485
2516
  }
2517
+ // One column, one place. An unindexed filter column that ALSO diverges is one
2518
+ // problem with one remedy (the index), so the divergence evidence renders as
2519
+ // an extra block on the missing-index finding rather than as a second,
2520
+ // unrelated-looking entry in the cached-plan section.
2521
+ const attached = attachDivergenceToMissingIndexes(findings, divergence);
2486
2522
  if (findings.length > 0) {
2487
2523
  (0, ui_js_1.warn)(`Found ${(0, ui_js_1.bold)(String(findings.length))} unindexed relation probe(s)`);
2488
2524
  (0, ui_js_1.newline)();
@@ -2490,10 +2526,10 @@ async function renderDoctorHuman(ctx) {
2490
2526
  console.log(` ${(0, ui_js_1.dim)('once per parent row, so an unindexed FK costs a full table scan PER PARENT.')}`);
2491
2527
  (0, ui_js_1.newline)();
2492
2528
  if (usable) {
2493
- renderTiers(findings, snapshot, args);
2529
+ renderTiers(findings, snapshot, args, attached);
2494
2530
  }
2495
2531
  else {
2496
- renderTopologyFallback(findings, snapshot);
2532
+ renderTopologyFallback(findings, snapshot, attached);
2497
2533
  }
2498
2534
  // Heat honesty: one line when the workload-heat boost could not be sourced.
2499
2535
  if (!heat.available && heat.notice) {
@@ -2502,7 +2538,7 @@ async function renderDoctorHuman(ctx) {
2502
2538
  }
2503
2539
  }
2504
2540
  renderInvalidIndexes(invalid);
2505
- renderPlanDivergence(divergence);
2541
+ renderPlanDivergence(divergence, attached);
2506
2542
  if (subtract.unusedRan) {
2507
2543
  renderUnusedIndexes(subtract.unused, subtract.minScans, snapshot);
2508
2544
  renderRedundantIndexes(subtract.redundant);
@@ -2599,8 +2635,96 @@ function renderDoctorAudit(audit, minScans, snapshot) {
2599
2635
  console.log(` ${(0, ui_js_1.dim)('Consider dropping the ones you confirm are unused. Nothing here is auto-dropped.')}`);
2600
2636
  (0, ui_js_1.newline)();
2601
2637
  }
2638
+ function attachDivergenceToMissingIndexes(findings, divergence) {
2639
+ const byColumn = new Map();
2640
+ for (const d of divergence.findings) {
2641
+ if (d.branch !== 'unindexed-filter')
2642
+ continue;
2643
+ byColumn.set(`${d.table}\u0000${d.column}`, d);
2644
+ }
2645
+ const attached = new Map();
2646
+ for (const f of findings) {
2647
+ // Single-column probes only: a composite probe's index is not the thing the
2648
+ // single-column divergence model reasons about.
2649
+ if (f.missing.columns.length !== 1 || f.missing.columns[0] === undefined)
2650
+ continue;
2651
+ const key = `${f.missing.table}\u0000${f.missing.columns[0]}`;
2652
+ const d = byColumn.get(key);
2653
+ if (d)
2654
+ attached.set(key, d);
2655
+ }
2656
+ return attached;
2657
+ }
2658
+ /** The key a missing-index finding is looked up by in {@link AttachedDivergence}. */
2659
+ function attachKey(f) {
2660
+ return `${f.missing.table}\u0000${f.missing.columns[0] ?? ''}`;
2661
+ }
2662
+ /**
2663
+ * The cached-plan evidence block printed UNDER a missing-index finding.
2664
+ *
2665
+ * It never recommends `forceCustomPlan`: the remedy is the index the same
2666
+ * finding already prints, and recommending a per-query plan-cache override for a
2667
+ * missing index would be advice to paper over a table scan.
2668
+ */
2669
+ /**
2670
+ * How big an `unindexed-filter` flip is, and under what condition, as plain
2671
+ * lines both branch-B renderers print.
2672
+ *
2673
+ * The condition is not decoration. The generic plan's cost is one heap fetch per
2674
+ * index entry, so the ratio is the table's rows-per-page when the heap is not in
2675
+ * `orderColumn` order and ~1x when it is: 80x and 1.2x on two fixtures identical
2676
+ * in every scored input. An earlier revision printed the ratio unconditionally
2677
+ * and quoted the FILTER column's correlation next to a sentence about the ORDER
2678
+ * column's physical order, so the one field offered as the reader's escape hatch
2679
+ * was measured on the wrong column.
2680
+ */
2681
+ function divergenceAmplificationLines(d) {
2682
+ const amp = divInt(d.worstCaseAmplification ?? 0);
2683
+ const corr = d.orderColumnCorrelation;
2684
+ const corrLabel = corr === null || corr === undefined
2685
+ ? `no pg_stats correlation available for "${d.orderColumn}"`
2686
+ : `correlation ${corr.toFixed(5)} on "${d.orderColumn}"`;
2687
+ if (d.heapNearlyOrdered === true) {
2688
+ return [
2689
+ `The size of that flip turns on the heap's physical order, and THIS heap is in near-exact`,
2690
+ `"${d.orderColumn}" order (${corrLabel}), so consecutive index entries hit the`,
2691
+ `same pinned page: measured ~1x, not the ~${amp}x an unordered heap reads. Most likely this`,
2692
+ `one is not costing you anything today. It is also one sampled statistic away from the`,
2693
+ `much worse reading, so measure rather than assume in either direction.`,
2694
+ ];
2695
+ }
2696
+ return [
2697
+ `That costs ~${amp}x the buffers of the seq scan, because each index entry is its own heap`,
2698
+ `fetch (${corrLabel}). The one shape that reads ~1x instead is a heap`,
2699
+ `in near-exact "${d.orderColumn}" order; two pages of local disorder already reads ~41x.`,
2700
+ ];
2701
+ }
2702
+ function renderDivergenceEvidence(d) {
2703
+ const tuples = divInt(d.tuplesWalked ?? d.rows);
2704
+ console.log(` ${(0, ui_js_1.dim)(ui_js_1.symbols.tee)} ${(0, ui_js_1.yellow)('cached-plan risk:')} this unindexed filter column can also flip a cached plan.`);
2705
+ console.log(` ${(0, ui_js_1.dim)(`${divInt(d.rows)} rows in ${divInt(d.pages)} pages, rarest value ~${divInt(d.rarestBucket)} rows, below the assumed LIMIT ${d.assumedLimit}.`)}`);
2706
+ console.log(` ${(0, ui_js_1.dim)(`Without the index the good plan is a seq scan (${divInt(d.pages)} pages); a promoted generic`)}`);
2707
+ console.log(` ${(0, ui_js_1.dim)(`plan cannot see the value is rare, keeps the ordered "${d.orderColumn}" walk, and reads`)}`);
2708
+ console.log(` ${(0, ui_js_1.dim)(`up to ~${tuples} tuples before it fills the LIMIT.`)}`);
2709
+ console.log(` ${(0, ui_js_1.dim)('Postgres promotes this shape exactly when the workload keeps asking for the rare')}`);
2710
+ console.log(` ${(0, ui_js_1.dim)('value: that is the case where the custom plan is expensive enough for the generic')}`);
2711
+ console.log(` ${(0, ui_js_1.dim)('estimate to look cheaper.')}`);
2712
+ for (const line of divergenceAmplificationLines(d))
2713
+ console.log(` ${(0, ui_js_1.dim)(line)}`);
2714
+ console.log(` ${(0, ui_js_1.dim)('Adding the index above is the fix. Confirm first if you want to:')}`);
2715
+ for (const line of d.diagnosticSql.split('\n')) {
2716
+ console.log(` ${(0, ui_js_1.green)(line)}`);
2717
+ }
2718
+ console.log(` ${(0, ui_js_1.dim)('After adding this index, re-run doctor. This column is expected to reappear as a')}`);
2719
+ console.log(` ${(0, ui_js_1.dim)('sparse-value finding in the cached-plan section. That later finding is exposure, not')}`);
2720
+ console.log(` ${(0, ui_js_1.dim)('a regression: the index makes the good plan much cheaper, which is why the ratio it')}`);
2721
+ console.log(` ${(0, ui_js_1.dim)('quotes is larger, and on a measured fixture it is also what stops Postgres from')}`);
2722
+ console.log(` ${(0, ui_js_1.dim)('promoting the generic plan at all. Treat the reappearance as the normal end state;')}`);
2723
+ console.log(` ${(0, ui_js_1.dim)("use the diagnostic block's generic_plans counter to decide whether anything more is")}`);
2724
+ console.log(` ${(0, ui_js_1.dim)('warranted.')}`);
2725
+ }
2602
2726
  /** Cost-aware tiered output: three sections, each finding annotated with its numbers. */
2603
- function renderTiers(findings, snapshot, _args) {
2727
+ function renderTiers(findings, snapshot, _args, attached) {
2604
2728
  const ageLabel = snapshot.statsAgeDays !== null ? `${Math.round(snapshot.statsAgeDays)}d` : 'unknown';
2605
2729
  console.log(` ${(0, ui_js_1.dim)(`Cost triage based on live statistics (stats reset ${ageLabel} ago). Thresholds: tiny < ${index_stats_js_1.STATS_THRESHOLDS.tinyTableRows.toLocaleString()} rows,`)}`);
2606
2730
  console.log(` ${(0, ui_js_1.dim)(`"real" write rate >= ${index_stats_js_1.STATS_THRESHOLDS.highWritesPerDay.toLocaleString()}/day, "many" indexes >= ${index_stats_js_1.STATS_THRESHOLDS.manyIndexes}.`)}`);
@@ -2619,12 +2743,12 @@ function renderTiers(findings, snapshot, _args) {
2619
2743
  console.log(` ${(0, ui_js_1.bold)(tierColor[tier](`${TIER_LABEL[tier]} (${inTier.length})`))}`);
2620
2744
  (0, ui_js_1.newline)();
2621
2745
  for (const f of inTier) {
2622
- renderFinding(f, { concurrently: true, withReasons: true });
2746
+ renderFinding(f, { concurrently: true, withReasons: true, divergence: attached.get(attachKey(f)) });
2623
2747
  }
2624
2748
  }
2625
2749
  }
2626
2750
  /** Degraded output: today's size-sorted topology report when stats are absent/young. */
2627
- function renderTopologyFallback(findings, snapshot) {
2751
+ function renderTopologyFallback(findings, snapshot, attached) {
2628
2752
  (0, ui_js_1.warn)('Statistics unavailable or too young to score cost: showing size-sorted topology only.');
2629
2753
  for (const notice of snapshot.notices)
2630
2754
  console.log(` ${(0, ui_js_1.dim)(`- ${notice}`)}`);
@@ -2634,7 +2758,7 @@ function renderTopologyFallback(findings, snapshot) {
2634
2758
  (0, ui_js_1.newline)();
2635
2759
  const sorted = [...findings].sort((a, b) => (b.score.metrics.rows ?? 0) - (a.score.metrics.rows ?? 0));
2636
2760
  for (const f of sorted) {
2637
- renderFinding(f, { concurrently: false, withReasons: false });
2761
+ renderFinding(f, { concurrently: false, withReasons: false, divergence: attached.get(attachKey(f)) });
2638
2762
  }
2639
2763
  }
2640
2764
  /** Render one finding: table + columns, probing relations, reasons, and the create SQL. */
@@ -2652,7 +2776,10 @@ function renderFinding(f, opts) {
2652
2776
  console.log(` ${(0, ui_js_1.dim)(ui_js_1.symbols.tee)} ${(0, ui_js_1.dim)(reason)}`);
2653
2777
  }
2654
2778
  }
2655
- console.log(` ${(0, ui_js_1.dim)(ui_js_1.symbols.teeEnd)} ${(0, ui_js_1.green)(doctorCreateSql(f, { concurrently: opts.concurrently }))}`);
2779
+ const last = opts.divergence ? ui_js_1.symbols.tee : ui_js_1.symbols.teeEnd;
2780
+ console.log(` ${(0, ui_js_1.dim)(last)} ${(0, ui_js_1.green)(doctorCreateSql(f, { concurrently: opts.concurrently }))}`);
2781
+ if (opts.divergence)
2782
+ renderDivergenceEvidence(opts.divergence);
2656
2783
  (0, ui_js_1.newline)();
2657
2784
  }
2658
2785
  /** The invalid-index report section (a failed CONCURRENTLY build leaves these behind). */
@@ -2668,6 +2795,42 @@ function renderInvalidIndexes(invalid) {
2668
2795
  (0, ui_js_1.newline)();
2669
2796
  }
2670
2797
  }
2798
+ /**
2799
+ * The release in which `turbine-orm/prisma-compat` began forwarding Turbine-only
2800
+ * query options (`forceCustomPlan` among them) to the core client.
2801
+ *
2802
+ * Printed rather than assumed, and the sentence stays even after that release:
2803
+ * doctor's audience routinely runs a CLI newer than the library pinned in the
2804
+ * app, and on an older library the option is accepted and silently ignored.
2805
+ */
2806
+ const COMPAT_PASSTHROUGH_VERSION = '0.57.0';
2807
+ /**
2808
+ * The gates + scored-population footer. Split out because it is printed from two
2809
+ * places: the normal section, and the case where every finding was attached to a
2810
+ * missing-index finding instead.
2811
+ */
2812
+ function renderDivergenceGates(divergence) {
2813
+ const t = plan_divergence_js_1.PLAN_DIVERGENCE_THRESHOLDS;
2814
+ console.log(` ${(0, ui_js_1.dim)(`Gates, indexed column: the wrong plan must walk >= ${t.minWalkPages} pages and >= ${Math.round(t.minWalkFraction * 100)}% of the table.`)}`);
2815
+ console.log(` ${(0, ui_js_1.dim)(`Gates, unindexed column: the rarest value must hold fewer rows than the limit, and the wrong`)}`);
2816
+ console.log(` ${(0, ui_js_1.dim)(`plan must walk >= ${t.minGenericTupleWalk.toLocaleString('en-US')} tuples. Assumed LIMIT ${t.assumedLimit} throughout.`)}`);
2817
+ console.log(` ${(0, ui_js_1.dim)(`${divergence.candidatesConsidered} column(s) were scored (${divergence.consideredIndexed} indexed, ${divergence.consideredUnindexed} unindexed). That population is relation-probe`)}`);
2818
+ console.log(` ${(0, ui_js_1.dim)('and leading-index columns only: a filter column that is neither is not covered. Skip this')}`);
2819
+ console.log(` ${(0, ui_js_1.dim)('section with --no-plan-divergence.')}`);
2820
+ // Say whether the unindexed findings were verified, and what verification
2821
+ // removed. Statistics can only say how bad a flip would be; a plan-only EXPLAIN
2822
+ // says whether the planner can reach it at all.
2823
+ if (divergence.flipProbed === true) {
2824
+ const refuted = divergence.flipRefuted ?? 0;
2825
+ const wereRefuted = refuted === 1 ? '1 was refuted' : `${refuted} were refuted`;
2826
+ console.log(` ${(0, ui_js_1.dim)(`Every unindexed finding was put to the planner (EXPLAIN, nothing executed); ${wereRefuted}`)}`);
2827
+ console.log(` ${(0, ui_js_1.dim)('because the generic plan keeps the same sequential scan, so no flip is reachable.')}`);
2828
+ }
2829
+ else if (divergence.consideredUnindexed > 0) {
2830
+ console.log(` ${(0, ui_js_1.dim)('Unindexed findings are UNVERIFIED here: the planner probe did not run, so some may name a')}`);
2831
+ console.log(` ${(0, ui_js_1.dim)('divergence the planner would never choose.')}`);
2832
+ }
2833
+ }
2671
2834
  /** Round to a whole number and group it, for the divergence report's estimates. */
2672
2835
  function divInt(n) {
2673
2836
  if (!Number.isFinite(n))
@@ -2680,8 +2843,26 @@ function divInt(n) {
2680
2843
  * application code (scope the plan-cache mode to the affected reads), and the
2681
2844
  * index that looks like a fix is measured NOT to be one.
2682
2845
  */
2683
- function renderPlanDivergence(divergence) {
2684
- const { findings, notices } = divergence;
2846
+ function renderPlanDivergence(divergence, attached) {
2847
+ const { notices } = divergence;
2848
+ // Anything already rendered as evidence on a missing-index finding is NOT
2849
+ // repeated here: one column, one problem, one remedy.
2850
+ const rendered = new Set(attached.values());
2851
+ const findings = divergence.findings.filter((f) => !rendered.has(f));
2852
+ // Every divergence finding was attached above, so this section has no entries
2853
+ // of its own. The pointer, the gates and the scored population still belong in
2854
+ // the report: they are output of THIS check, and a reader must be able to tell
2855
+ // "considered and clean" from "never looked".
2856
+ //
2857
+ // Printed BEFORE the notices rather than inside an early return: an early
2858
+ // return that also required `notices.length === 0` dropped both blocks
2859
+ // whenever any candidate lacked a pg_stats row, which is the normal reason a
2860
+ // notice exists.
2861
+ if (findings.length === 0 && rendered.size > 0) {
2862
+ console.log(` ${(0, ui_js_1.dim)(`Cached-plan divergence: ${rendered.size} finding(s), shown with the index findings above.`)}`);
2863
+ renderDivergenceGates(divergence);
2864
+ (0, ui_js_1.newline)();
2865
+ }
2685
2866
  if (findings.length === 0 && notices.length === 0)
2686
2867
  return;
2687
2868
  if (findings.length > 0) {
@@ -2694,16 +2875,39 @@ function renderPlanDivergence(divergence) {
2694
2875
  console.log(` ${(0, ui_js_1.dim)('land on the other side of a plan boundary from the real value, the plan flips.')}`);
2695
2876
  (0, ui_js_1.newline)();
2696
2877
  }
2878
+ const analyzedLabel = (f) => f.lastAnalyze === null
2879
+ ? 'last ANALYZE unknown'
2880
+ : `last analyzed ${Math.max(0, Math.round((Date.now() - f.lastAnalyze.getTime()) / 86_400_000))}d ago`;
2697
2881
  for (const f of findings) {
2882
+ if (f.branch === 'unindexed-filter') {
2883
+ // Only reached when the column has no missing-index finding to hang this
2884
+ // on (an index that exists but cannot serve the equality: partial,
2885
+ // expression, or non-btree). The remedy is still an index, not a
2886
+ // plan-cache setting, so this entry never suggests forceCustomPlan.
2887
+ console.log(` ${(0, ui_js_1.yellow)(ui_js_1.symbols.warning)} ${(0, ui_js_1.bold)((0, ui_js_1.cyan)(`${f.table}.${f.column}`))} ${(0, ui_js_1.gray)('UNINDEXED-FILTER FLIP')}`);
2888
+ console.log(` ${(0, ui_js_1.dim)(ui_js_1.symbols.tee)} ${divInt(f.rows)} rows in ${divInt(f.pages)} pages, rarest value ~${(0, ui_js_1.bold)(divInt(f.rarestBucket))} rows, below the assumed LIMIT ${f.assumedLimit}`);
2889
+ console.log(` ${(0, ui_js_1.dim)(ui_js_1.symbols.tee)} no index serves ${f.column} = $1, so the good plan is a seq scan (${divInt(f.pages)} pages);`);
2890
+ console.log(` ${(0, ui_js_1.dim)(`a promoted generic plan keeps the ordered "${f.orderColumn}" walk and reads up to ~${divInt(f.tuplesWalked ?? f.rows)} tuples`)}`);
2891
+ console.log(` ${(0, ui_js_1.dim)('before it fills the LIMIT.')}`);
2892
+ for (const line of divergenceAmplificationLines(f))
2893
+ console.log(` ${(0, ui_js_1.dim)(line)}`);
2894
+ console.log(` ${(0, ui_js_1.dim)(ui_js_1.symbols.tee)} ${(0, ui_js_1.dim)(`filter-column correlation ${f.correlation.toFixed(2)}, ${analyzedLabel(f)}`)}`);
2895
+ console.log(` ${(0, ui_js_1.dim)(ui_js_1.symbols.tee)} ${(0, ui_js_1.dim)('the fix is an index that can serve this equality. A partial or expression index')}`);
2896
+ console.log(` ${(0, ui_js_1.dim)('on the column does not: the planner has no path for the bare predicate. A hash')}`);
2897
+ console.log(` ${(0, ui_js_1.dim)('index does, and a column served by one is scored by the other rule instead.')}`);
2898
+ console.log(` ${(0, ui_js_1.dim)(ui_js_1.symbols.teeEnd)} ${(0, ui_js_1.dim)('confirm with YOUR values before changing anything:')}`);
2899
+ for (const line of f.diagnosticSql.split('\n')) {
2900
+ console.log(` ${(0, ui_js_1.green)(line)}`);
2901
+ }
2902
+ (0, ui_js_1.newline)();
2903
+ continue;
2904
+ }
2698
2905
  console.log(` ${(0, ui_js_1.yellow)(ui_js_1.symbols.warning)} ${(0, ui_js_1.bold)((0, ui_js_1.cyan)(`${f.table}.${f.column}`))} ${(0, ui_js_1.gray)('SPARSE-VALUE FLIP')}`);
2699
2906
  console.log(` ${(0, ui_js_1.dim)(ui_js_1.symbols.tee)} generic estimate ${(0, ui_js_1.bold)(divInt(f.genericEstimate))} rows ${(0, ui_js_1.dim)(`(${divInt(f.rows)} rows / ${divInt(f.distinctValues)} distinct values)`)}`);
2700
2907
  console.log(` ${(0, ui_js_1.dim)(ui_js_1.symbols.tee)} rarest value bucket ${(0, ui_js_1.bold)(divInt(f.rarestBucket))} rows ${(0, ui_js_1.dim)('(pg_stats most_common_freqs / residual bucket)')}`);
2701
- console.log(` ${(0, ui_js_1.dim)(ui_js_1.symbols.tee)} crossover ${(0, ui_js_1.bold)(divInt(f.crossoverRows))} rows ${(0, ui_js_1.dim)(`(sqrt(limit ${f.assumedLimit} x ${divInt(f.pages)} pages); ${divInt(f.crossoverRowsWide)} at limit ${f.thresholds.wideLimit})`)}`);
2702
- const analyzed = f.lastAnalyze === null
2703
- ? 'last ANALYZE unknown'
2704
- : `last analyzed ${Math.max(0, Math.round((Date.now() - f.lastAnalyze.getTime()) / 86_400_000))}d ago`;
2705
- console.log(` ${(0, ui_js_1.dim)(ui_js_1.symbols.tee)} ${(0, ui_js_1.dim)(`values below the crossover: ${divInt(f.valuesBelowCrossover)} of ${divInt(f.distinctValues)}, correlation ${f.correlation.toFixed(2)}, ${analyzed}`)}`);
2706
- console.log(` ${(0, ui_js_1.dim)(ui_js_1.symbols.tee)} for such a value the generic plan walks ~${(0, ui_js_1.bold)(divInt(f.walkPages))} of ${divInt(f.pages)} pages ${(0, ui_js_1.dim)(`(${Math.round(f.walkFraction * 100)}% of the table)`)}`);
2908
+ console.log(` ${(0, ui_js_1.dim)(ui_js_1.symbols.tee)} crossover ${(0, ui_js_1.bold)(divInt(f.crossoverRows ?? 0))} rows ${(0, ui_js_1.dim)(`(sqrt(limit ${f.assumedLimit} x ${divInt(f.pages)} pages); ${divInt(f.crossoverRowsWide ?? 0)} at limit ${f.thresholds.wideLimit})`)}`);
2909
+ console.log(` ${(0, ui_js_1.dim)(ui_js_1.symbols.tee)} ${(0, ui_js_1.dim)(`values below the crossover: ${divInt(f.valuesBelowCrossover ?? 0)} of ${divInt(f.distinctValues)}, filter-column correlation ${f.correlation.toFixed(2)}, ${analyzedLabel(f)}`)}`);
2910
+ console.log(` ${(0, ui_js_1.dim)(ui_js_1.symbols.tee)} for such a value the generic plan walks ~${(0, ui_js_1.bold)(divInt(f.walkPages ?? 0))} of ${divInt(f.pages)} pages ${(0, ui_js_1.dim)(`(${Math.round((f.walkFraction ?? 0) * 100)}% of the table)`)}`);
2707
2911
  console.log(` ${(0, ui_js_1.dim)(`for reads shaped WHERE ${f.column} = $1 ORDER BY ${f.orderColumn} LIMIT $n,`)}`);
2708
2912
  console.log(` ${(0, ui_js_1.dim)("where the custom plan reads only that value's own rows.")}`);
2709
2913
  console.log(` ${(0, ui_js_1.dim)(ui_js_1.symbols.tee)} ${(0, ui_js_1.dim)('No amplification figure is printed, deliberately. This models how many rows a')}`);
@@ -2716,6 +2920,7 @@ function renderPlanDivergence(divergence) {
2716
2920
  (0, ui_js_1.newline)();
2717
2921
  }
2718
2922
  if (findings.length > 0) {
2923
+ const first = findings.find((f) => f.branch === 'sparse-value');
2719
2924
  console.log(` ${(0, ui_js_1.bold)('What to do, in order:')}`);
2720
2925
  console.log(` 1. Check that this shape is promoted AT ALL. Step 1 of the block above: while`);
2721
2926
  console.log(` ${(0, ui_js_1.dim)('generic_plans is 0, Postgres is planning with your real values and there is nothing')}`);
@@ -2723,27 +2928,68 @@ function renderPlanDivergence(divergence) {
2723
2928
  console.log(` 2. If it does promote, compare the two plans. Both SETs matter: without them a`);
2724
2929
  console.log(` ${(0, ui_js_1.dim)('repeated seq scan resumes where the last one stopped and a catastrophic case reads')}`);
2725
2930
  console.log(` ${(0, ui_js_1.dim)('as harmless.')}`);
2726
- console.log(` 3. If the flip is real, scope the fix to those reads:`);
2727
- const first = findings[0];
2728
- console.log(` ${(0, ui_js_1.cyan)(`db.${first.table}.findMany({ where: { ${first.columnField}: value }, orderBy: { ${first.orderColumnField}: 'asc' },`)}`);
2729
- console.log(` ${(0, ui_js_1.cyan)(` limit: 20, forceCustomPlan: true })`)}`);
2730
- console.log(` ${(0, ui_js_1.dim)('That withholds the prepared-statement NAME for that one query, so the driver')}`);
2731
- console.log(` ${(0, ui_js_1.dim)('re-parses it every execution and it is always planned with the real values. No')}`);
2732
- console.log(` ${(0, ui_js_1.dim)('GUC, no SET LOCAL, no transaction, no extra round trip.')}`);
2733
- console.log(` 4. Do NOT set planCacheMode on the client to fix this. There are measured shapes`);
2734
- console.log(` ${(0, ui_js_1.dim)('where a generic plan is dramatically better (an unordered LIMIT over a value whose')}`);
2735
- console.log(` ${(0, ui_js_1.dim)('rows are packed at the end of the heap: 4,262 buffers custom vs 71 generic on a')}`);
2736
- console.log(` ${(0, ui_js_1.dim)('reproducible fixture). A custom plan is not automatically the better plan.')}`);
2737
- console.log(` 5. A composite index on (${first.column}, ${first.orderColumn}) makes the GOOD plan better. It`);
2738
- console.log(` ${(0, ui_js_1.dim)('does NOT stop the generic plan from choosing the other one, and it can widen the gap.')}`);
2739
- console.log(` ${(0, ui_js_1.dim)('Add it for the custom-plan win, not as a fix for this finding.')}`);
2931
+ if (first) {
2932
+ // The OPTION is named first and both call shapes follow, so no step
2933
+ // assumes which client the reader is holding. The compat example uses
2934
+ // Prisma's `take`: printing `limit` there would be a second wrong
2935
+ // instruction, since `limit` is a Turbine spelling compat does not read.
2936
+ console.log(` 3. If the flip is real, scope the fix to those reads with ${(0, ui_js_1.cyan)('forceCustomPlan')}. It`);
2937
+ console.log(` ${(0, ui_js_1.dim)('withholds the prepared-statement NAME for that one query, so the driver re-parses')}`);
2938
+ console.log(` ${(0, ui_js_1.dim)('it every execution and it is always planned with the real values. No GUC, no SET')}`);
2939
+ console.log(` ${(0, ui_js_1.dim)('LOCAL, no transaction, no extra round trip.')}`);
2940
+ // Hanging indent rather than an alignment that pretends to line up: the
2941
+ // call's own width depends on the table name, so a fixed padding column
2942
+ // misaligns on every schema but the one it was written against.
2943
+ const args = `where: { ${first.columnField}: value }, orderBy: { ${first.orderColumnField}: 'asc' },`;
2944
+ // The accessor is the camelCase FIELD spelling, not the raw table name:
2945
+ // TurbineClient and the code generator both define table accessors through
2946
+ // snakeToCamel, so `db.inventory_location` is undefined on every
2947
+ // snake_case schema. The finding's own `columnField` / `orderColumnField`
2948
+ // are already field-space for the same reason.
2949
+ console.log(` ${(0, ui_js_1.dim)('On the core client:')}`);
2950
+ console.log(` ${(0, ui_js_1.cyan)(`db.${(0, schema_js_1.snakeToCamel)(first.table)}.findMany({`)}`);
2951
+ console.log(` ${(0, ui_js_1.cyan)(args)}`);
2952
+ console.log(` ${(0, ui_js_1.cyan)('limit: 20, forceCustomPlan: true,')}`);
2953
+ console.log(` ${(0, ui_js_1.cyan)('})')}`);
2954
+ console.log(` ${(0, ui_js_1.dim)("Through turbine-orm/prisma-compat, the same option on the delegate call (Prisma's")}`);
2955
+ console.log(` ${(0, ui_js_1.dim)('`take`, not `limit`). The Prisma MODEL name is not knowable from the schema side,')}`);
2956
+ console.log(` ${(0, ui_js_1.dim)('so substitute your own:')}`);
2957
+ console.log(` ${(0, ui_js_1.cyan)('compat.<Model>.findMany({')}`);
2958
+ console.log(` ${(0, ui_js_1.cyan)(args)}`);
2959
+ console.log(` ${(0, ui_js_1.cyan)('take: 20, forceCustomPlan: true,')}`);
2960
+ console.log(` ${(0, ui_js_1.cyan)('})')}`);
2961
+ console.log(` ${(0, ui_js_1.dim)(`The compat passthrough requires turbine >= ${COMPAT_PASSTHROUGH_VERSION}. On an older version the option`)}`);
2962
+ console.log(` ${(0, ui_js_1.dim)('is accepted and ignored there, so confirm at the wire with the same')}`);
2963
+ console.log(` ${(0, ui_js_1.dim)('pg_prepared_statements check in step 1 rather than assuming it took effect.')}`);
2964
+ console.log(` 4. Reaching for a database-wide plan_cache_mode is not the fix, whichever client you`);
2965
+ console.log(` ${(0, ui_js_1.dim)('use. There are measured shapes where a generic plan is dramatically better: an')}`);
2966
+ console.log(` ${(0, ui_js_1.dim)('unordered LIMIT over a value whose rows are packed at the end of the heap reads')}`);
2967
+ console.log(` ${(0, ui_js_1.dim)('4,262 buffers under a custom plan against 71 under a generic one. That fixture is')}`);
2968
+ console.log(` ${(0, ui_js_1.dim)('printed in full at turbineorm.dev/relations, so the number is checkable rather')}`);
2969
+ console.log(` ${(0, ui_js_1.dim)('than asserted. Pinning every statement')}`);
2970
+ console.log(` ${(0, ui_js_1.dim)('in one direction trades this finding for its mirror image. That applies equally to')}`);
2971
+ console.log(` ${(0, ui_js_1.dim)("Turbine's client-level `planCacheMode` and to a SET or ALTER ROLE applied outside")}`);
2972
+ console.log(` ${(0, ui_js_1.dim)('Turbine.')}`);
2973
+ console.log(` 5. A composite index on (${first.column}, ${first.orderColumn}) makes the GOOD plan better. It`);
2974
+ console.log(` ${(0, ui_js_1.dim)('does NOT stop the generic plan from choosing the other one, and it can widen the gap.')}`);
2975
+ console.log(` ${(0, ui_js_1.dim)('Add it for the custom-plan win, not as a fix for this finding.')}`);
2976
+ }
2977
+ // Stated separately because the first remedy genuinely differs by branch: an
2978
+ // UNINDEXED column's flip is fixed by the index, and a per-query plan-cache
2979
+ // override there would only paper over a table scan.
2980
+ if (findings.some((f) => f.branch === 'unindexed-filter')) {
2981
+ console.log(` ${first ? 6 : 3}. A finding on an UNINDEXED column has a different FIRST remedy: add an index that`);
2982
+ console.log(` ${(0, ui_js_1.dim)('serves the equality, then re-run doctor and re-score. The index moves the')}`);
2983
+ console.log(` ${(0, ui_js_1.dim)('divergence in both directions at once (it makes the good plan much cheaper, which')}`);
2984
+ console.log(` ${(0, ui_js_1.dim)('widens the ratio, and on a measured fixture it also stopped Postgres promoting the')}`);
2985
+ console.log(` ${(0, ui_js_1.dim)('generic plan at all), so do not assume the finding is closed by adding it.')}`);
2986
+ }
2740
2987
  (0, ui_js_1.newline)();
2741
2988
  console.log(` ${(0, ui_js_1.dim)('This finding is derived from statistics, not from your traffic: it says the DISTRIBUTION')}`);
2742
- console.log(` ${(0, ui_js_1.dim)('admits a damaging flip, not that a query is running one today. It models ONE shape,')}`);
2743
- console.log(` ${(0, ui_js_1.dim)('the rare value that loses its bitmap plan. It cannot see where a value physically')}`);
2744
- console.log(` ${(0, ui_js_1.dim)('sits in the heap, so a clean report is not evidence of immunity.')}`);
2745
- console.log(` ${(0, ui_js_1.dim)(`Gates: the wrong plan must walk >= ${plan_divergence_js_1.PLAN_DIVERGENCE_THRESHOLDS.minWalkPages} pages and >= ${Math.round(plan_divergence_js_1.PLAN_DIVERGENCE_THRESHOLDS.minWalkFraction * 100)}% of the table, at an assumed`)}`);
2746
- console.log(` ${(0, ui_js_1.dim)(`LIMIT ${plan_divergence_js_1.PLAN_DIVERGENCE_THRESHOLDS.assumedLimit}. ${divergence.candidatesConsidered} column(s) were scored. Skip this section with --no-plan-divergence.`)}`);
2989
+ console.log(` ${(0, ui_js_1.dim)('admits a damaging flip, not that a query is running one today. It cannot see where a')}`);
2990
+ console.log(` ${(0, ui_js_1.dim)('value physically sits in the heap, so a clean report is not evidence of immunity, and')}`);
2991
+ console.log(` ${(0, ui_js_1.dim)('a column that is neither an FK nor indexed is not in the scored population at all.')}`);
2992
+ renderDivergenceGates(divergence);
2747
2993
  (0, ui_js_1.newline)();
2748
2994
  }
2749
2995
  if (notices.length > 0) {
@@ -148,50 +148,14 @@ const CONFIG_KEY_SET = new Set(Object.keys(TURBINE_CONFIG_KEYS));
148
148
  * engine factories' first argument. Same story as `schema`.
149
149
  */
150
150
  const NON_CONFIG_KEYS = new Set(['queryInterfaceFactory', 'schema', 'url']);
151
- /** camelCase name → its lowercased words (`logQueryParams` → log, query, params). */
152
- function camelWords(name) {
153
- return name
154
- .split(/(?=[A-Z])/)
155
- .map((w) => w.toLowerCase())
156
- .filter(Boolean);
157
- }
158
151
  /**
159
152
  * The real config key `key` most likely meant, or null when nothing is close.
160
153
  *
161
- * {@link closestName} (the same helper the unknown-COLUMN message uses) decides
162
- * first, so both diagnostics rank near-misses identically. It is bounded by edit
163
- * distance, which covers typos but not the miss this warning exists for: a
164
- * guessed name that omits a whole word. `logParams` is five edits from
165
- * `logQueryParams`, past the bound, yet it names the same words in the same
166
- * order, so a second pass accepts a candidate whose camelCase words CONTAIN the
167
- * guess's words in order, preferring the one that adds fewest words.
154
+ * {@link suggestKey} is shared with the prisma-compat query-option warner, so
155
+ * both diagnostics rank near-misses identically.
168
156
  */
169
157
  function suggestConfigKey(key) {
170
- const direct = (0, utils_js_1.closestName)(key, CONFIG_KEY_SET);
171
- if (direct)
172
- return direct;
173
- const wanted = camelWords(key);
174
- if (wanted.length < 2)
175
- return null;
176
- let best = null;
177
- let bestExtra = Number.POSITIVE_INFINITY;
178
- for (const candidate of CONFIG_KEY_SET) {
179
- const words = camelWords(candidate);
180
- if (words.length <= wanted.length)
181
- continue;
182
- let i = 0;
183
- for (const w of words)
184
- if (w === wanted[i])
185
- i++;
186
- if (i !== wanted.length)
187
- continue;
188
- const extra = words.length - wanted.length;
189
- if (extra < bestExtra) {
190
- bestExtra = extra;
191
- best = candidate;
192
- }
193
- }
194
- return best;
158
+ return (0, utils_js_1.suggestKey)(key, CONFIG_KEY_SET);
195
159
  }
196
160
  /**
197
161
  * Dev-mode notice for a key on the config object that is not part of the config