@quereus/quereus 4.22.0 → 4.24.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.
Files changed (153) hide show
  1. package/dist/src/core/database-cardinality-feedback.d.ts +133 -20
  2. package/dist/src/core/database-cardinality-feedback.d.ts.map +1 -1
  3. package/dist/src/core/database-cardinality-feedback.js +312 -39
  4. package/dist/src/core/database-cardinality-feedback.js.map +1 -1
  5. package/dist/src/core/database.d.ts +1 -0
  6. package/dist/src/core/database.d.ts.map +1 -1
  7. package/dist/src/core/database.js +14 -6
  8. package/dist/src/core/database.js.map +1 -1
  9. package/dist/src/core/statement.d.ts +6 -1
  10. package/dist/src/core/statement.d.ts.map +1 -1
  11. package/dist/src/core/statement.js +11 -2
  12. package/dist/src/core/statement.js.map +1 -1
  13. package/dist/src/func/builtins/cardinality-feedback.d.ts +6 -0
  14. package/dist/src/func/builtins/cardinality-feedback.d.ts.map +1 -1
  15. package/dist/src/func/builtins/cardinality-feedback.js +55 -3
  16. package/dist/src/func/builtins/cardinality-feedback.js.map +1 -1
  17. package/dist/src/func/builtins/explain.d.ts.map +1 -1
  18. package/dist/src/func/builtins/explain.js +3 -1
  19. package/dist/src/func/builtins/explain.js.map +1 -1
  20. package/dist/src/func/builtins/index.d.ts.map +1 -1
  21. package/dist/src/func/builtins/index.js +2 -1
  22. package/dist/src/func/builtins/index.js.map +1 -1
  23. package/dist/src/index.d.ts +3 -1
  24. package/dist/src/index.d.ts.map +1 -1
  25. package/dist/src/index.js +1 -0
  26. package/dist/src/index.js.map +1 -1
  27. package/dist/src/planner/cost/index.d.ts +27 -19
  28. package/dist/src/planner/cost/index.d.ts.map +1 -1
  29. package/dist/src/planner/cost/index.js +30 -21
  30. package/dist/src/planner/cost/index.js.map +1 -1
  31. package/dist/src/planner/framework/trace.js +2 -2
  32. package/dist/src/planner/framework/trace.js.map +1 -1
  33. package/dist/src/planner/nodes/aggregate-node.d.ts +2 -1
  34. package/dist/src/planner/nodes/aggregate-node.d.ts.map +1 -1
  35. package/dist/src/planner/nodes/aggregate-node.js +1 -0
  36. package/dist/src/planner/nodes/aggregate-node.js.map +1 -1
  37. package/dist/src/planner/nodes/filter.d.ts.map +1 -1
  38. package/dist/src/planner/nodes/filter.js +5 -10
  39. package/dist/src/planner/nodes/filter.js.map +1 -1
  40. package/dist/src/planner/nodes/hash-aggregate.d.ts +2 -1
  41. package/dist/src/planner/nodes/hash-aggregate.d.ts.map +1 -1
  42. package/dist/src/planner/nodes/hash-aggregate.js +1 -0
  43. package/dist/src/planner/nodes/hash-aggregate.js.map +1 -1
  44. package/dist/src/planner/nodes/plan-node.d.ts +16 -3
  45. package/dist/src/planner/nodes/plan-node.d.ts.map +1 -1
  46. package/dist/src/planner/nodes/plan-node.js +3 -0
  47. package/dist/src/planner/nodes/plan-node.js.map +1 -1
  48. package/dist/src/planner/nodes/reference.d.ts +3 -3
  49. package/dist/src/planner/nodes/reference.d.ts.map +1 -1
  50. package/dist/src/planner/nodes/reference.js +16 -12
  51. package/dist/src/planner/nodes/reference.js.map +1 -1
  52. package/dist/src/planner/nodes/stream-aggregate.d.ts +2 -1
  53. package/dist/src/planner/nodes/stream-aggregate.d.ts.map +1 -1
  54. package/dist/src/planner/nodes/stream-aggregate.js +1 -0
  55. package/dist/src/planner/nodes/stream-aggregate.js.map +1 -1
  56. package/dist/src/planner/nodes/table-access-nodes.d.ts +14 -1
  57. package/dist/src/planner/nodes/table-access-nodes.d.ts.map +1 -1
  58. package/dist/src/planner/nodes/table-access-nodes.js +52 -20
  59. package/dist/src/planner/nodes/table-access-nodes.js.map +1 -1
  60. package/dist/src/planner/optimizer-tuning.d.ts +42 -9
  61. package/dist/src/planner/optimizer-tuning.d.ts.map +1 -1
  62. package/dist/src/planner/optimizer-tuning.js +9 -4
  63. package/dist/src/planner/optimizer-tuning.js.map +1 -1
  64. package/dist/src/planner/rules/access/rule-key-set-seek.d.ts +9 -0
  65. package/dist/src/planner/rules/access/rule-key-set-seek.d.ts.map +1 -1
  66. package/dist/src/planner/rules/access/rule-key-set-seek.js +18 -12
  67. package/dist/src/planner/rules/access/rule-key-set-seek.js.map +1 -1
  68. package/dist/src/planner/rules/access/rule-select-access-path.d.ts.map +1 -1
  69. package/dist/src/planner/rules/access/rule-select-access-path.js +7 -8
  70. package/dist/src/planner/rules/access/rule-select-access-path.js.map +1 -1
  71. package/dist/src/planner/rules/aggregate/rule-aggregate-streaming.js +1 -1
  72. package/dist/src/planner/rules/aggregate/rule-aggregate-streaming.js.map +1 -1
  73. package/dist/src/planner/rules/cache/rule-nested-loop-right-cache.d.ts.map +1 -1
  74. package/dist/src/planner/rules/cache/rule-nested-loop-right-cache.js +7 -0
  75. package/dist/src/planner/rules/cache/rule-nested-loop-right-cache.js.map +1 -1
  76. package/dist/src/planner/rules/join/index-nested-loop.d.ts +6 -2
  77. package/dist/src/planner/rules/join/index-nested-loop.d.ts.map +1 -1
  78. package/dist/src/planner/rules/join/index-nested-loop.js +20 -14
  79. package/dist/src/planner/rules/join/index-nested-loop.js.map +1 -1
  80. package/dist/src/planner/rules/join/rule-fanout-batched-outer.d.ts.map +1 -1
  81. package/dist/src/planner/rules/join/rule-fanout-batched-outer.js +5 -0
  82. package/dist/src/planner/rules/join/rule-fanout-batched-outer.js.map +1 -1
  83. package/dist/src/planner/rules/join/rule-fanout-lookup-join.d.ts +6 -4
  84. package/dist/src/planner/rules/join/rule-fanout-lookup-join.d.ts.map +1 -1
  85. package/dist/src/planner/rules/join/rule-fanout-lookup-join.js +10 -7
  86. package/dist/src/planner/rules/join/rule-fanout-lookup-join.js.map +1 -1
  87. package/dist/src/planner/rules/join/rule-join-physical-selection.d.ts.map +1 -1
  88. package/dist/src/planner/rules/join/rule-join-physical-selection.js +108 -53
  89. package/dist/src/planner/rules/join/rule-join-physical-selection.js.map +1 -1
  90. package/dist/src/planner/rules/join/rule-monotonic-merge-join.d.ts +1 -1
  91. package/dist/src/planner/rules/join/rule-monotonic-merge-join.d.ts.map +1 -1
  92. package/dist/src/planner/rules/join/rule-monotonic-merge-join.js +15 -6
  93. package/dist/src/planner/rules/join/rule-monotonic-merge-join.js.map +1 -1
  94. package/dist/src/planner/rules/join/rule-quickpick-enumeration.d.ts.map +1 -1
  95. package/dist/src/planner/rules/join/rule-quickpick-enumeration.js +9 -1
  96. package/dist/src/planner/rules/join/rule-quickpick-enumeration.js.map +1 -1
  97. package/dist/src/planner/rules/parallel/rule-async-gather-union-all.d.ts +2 -1
  98. package/dist/src/planner/rules/parallel/rule-async-gather-union-all.d.ts.map +1 -1
  99. package/dist/src/planner/rules/parallel/rule-async-gather-union-all.js +6 -5
  100. package/dist/src/planner/rules/parallel/rule-async-gather-union-all.js.map +1 -1
  101. package/dist/src/planner/rules/parallel/rule-async-gather-zip-by-key.d.ts +4 -3
  102. package/dist/src/planner/rules/parallel/rule-async-gather-zip-by-key.d.ts.map +1 -1
  103. package/dist/src/planner/rules/parallel/rule-async-gather-zip-by-key.js +4 -3
  104. package/dist/src/planner/rules/parallel/rule-async-gather-zip-by-key.js.map +1 -1
  105. package/dist/src/planner/rules/parallel/rule-eager-prefetch-probe.d.ts +4 -3
  106. package/dist/src/planner/rules/parallel/rule-eager-prefetch-probe.d.ts.map +1 -1
  107. package/dist/src/planner/rules/parallel/rule-eager-prefetch-probe.js +5 -4
  108. package/dist/src/planner/rules/parallel/rule-eager-prefetch-probe.js.map +1 -1
  109. package/dist/src/planner/rules/retrieve/rule-grow-retrieve.d.ts.map +1 -1
  110. package/dist/src/planner/rules/retrieve/rule-grow-retrieve.js +4 -3
  111. package/dist/src/planner/rules/retrieve/rule-grow-retrieve.js.map +1 -1
  112. package/dist/src/planner/stats/catalog-stats.d.ts +8 -8
  113. package/dist/src/planner/stats/catalog-stats.d.ts.map +1 -1
  114. package/dist/src/planner/stats/catalog-stats.js +10 -10
  115. package/dist/src/planner/stats/catalog-stats.js.map +1 -1
  116. package/dist/src/planner/stats/table-cardinality.d.ts +119 -30
  117. package/dist/src/planner/stats/table-cardinality.d.ts.map +1 -1
  118. package/dist/src/planner/stats/table-cardinality.js +137 -29
  119. package/dist/src/planner/stats/table-cardinality.js.map +1 -1
  120. package/dist/src/planner/util/relative-rows.d.ts +29 -0
  121. package/dist/src/planner/util/relative-rows.d.ts.map +1 -0
  122. package/dist/src/planner/util/relative-rows.js +67 -0
  123. package/dist/src/planner/util/relative-rows.js.map +1 -0
  124. package/dist/src/planner/util/row-estimates.d.ts +23 -0
  125. package/dist/src/planner/util/row-estimates.d.ts.map +1 -1
  126. package/dist/src/planner/util/row-estimates.js +29 -0
  127. package/dist/src/planner/util/row-estimates.js.map +1 -1
  128. package/dist/src/runtime/cardinality-observations.d.ts +62 -7
  129. package/dist/src/runtime/cardinality-observations.d.ts.map +1 -1
  130. package/dist/src/runtime/cardinality-observations.js +74 -8
  131. package/dist/src/runtime/cardinality-observations.js.map +1 -1
  132. package/dist/src/runtime/emit/scan.d.ts +1 -1
  133. package/dist/src/runtime/emit/scan.d.ts.map +1 -1
  134. package/dist/src/runtime/emit/scan.js +78 -10
  135. package/dist/src/runtime/emit/scan.js.map +1 -1
  136. package/dist/src/schema/manager.d.ts +5 -5
  137. package/dist/src/schema/manager.d.ts.map +1 -1
  138. package/dist/src/schema/manager.js +9 -5
  139. package/dist/src/schema/manager.js.map +1 -1
  140. package/dist/src/vtab/cost-profile.d.ts +61 -0
  141. package/dist/src/vtab/cost-profile.d.ts.map +1 -0
  142. package/dist/src/vtab/cost-profile.js +52 -0
  143. package/dist/src/vtab/cost-profile.js.map +1 -0
  144. package/dist/src/vtab/filter-info.d.ts +16 -0
  145. package/dist/src/vtab/filter-info.d.ts.map +1 -1
  146. package/dist/src/vtab/filter-info.js +29 -0
  147. package/dist/src/vtab/filter-info.js.map +1 -1
  148. package/dist/src/vtab/memory/module.d.ts.map +1 -1
  149. package/dist/src/vtab/memory/module.js +5 -3
  150. package/dist/src/vtab/memory/module.js.map +1 -1
  151. package/dist/src/vtab/module.d.ts +53 -9
  152. package/dist/src/vtab/module.d.ts.map +1 -1
  153. package/package.json +3 -3
@@ -3,31 +3,42 @@
3
3
  *
4
4
  * One per `Database`. The planner reads it through `plannedRowCount`
5
5
  * (`planner/stats/table-cardinality.ts`), where an answering entry outranks the
6
- * catalog's `ANALYZE` count. This module owns the record policy — which
7
- * observations are worth keeping, and when one has moved far enough from what
8
- * plans were costed against to call it a *shift* — and the entries' lifetime.
6
+ * catalog's `ANALYZE` count and a module's approximate count, but not a module's
7
+ * exact one, and through `plannedRowsPerKey`, where an entry's rows per key answers
8
+ * unless the catalog's statistics cover the column set. This module owns the record
9
+ * policy — which observations are worth keeping, and when one has moved far enough
10
+ * from what plans were costed against to call it a *shift* — and the entries' lifetime.
9
11
  *
10
12
  * Validity is schema identity: an entry answers only for the exact `TableSchema`
11
13
  * object it was observed under. Any swap (`ANALYZE`, `ALTER TABLE`, drop and
12
14
  * re-create) silences it, and a schema-change listener evicts it. The identity
13
15
  * check is the correctness guard; the listener is memory hygiene.
14
16
  *
17
+ * An entry holds an exact count from a complete read, a floor ("at least N rows") from a
18
+ * partial one, or both; a floor only ever raises an estimate, and an exact count clears it.
19
+ * Beside them it keeps, per equality column set the table is seeked on through a
20
+ * non-unique index, a running mean of the rows one key matched ({@link PerKeyEntry}).
21
+ *
15
22
  * Execution feeds it through {@link CardinalityFeedbackManager.publish}, which admits
16
- * only counts of committed state: a count taken inside a transaction is held until
23
+ * only observations of committed state: one made inside a transaction is held until
17
24
  * that transaction commits ({@link CardinalityFeedbackManager.onCommitted}) and
18
25
  * dropped if it rolls back ({@link CardinalityFeedbackManager.onRolledBack}).
19
26
  *
20
27
  * A shift reaches prepared statements through `onShift`; each statement paces its
21
- * re-plans with a {@link FeedbackReplanState}.
28
+ * re-plans with a {@link FeedbackReplanState}. A module-reported size, which moves with
29
+ * no observation at all, is re-checked by each statement at execution start against the
30
+ * size its plan was costed with ({@link ReportedSizeSnapshot}).
22
31
  *
23
32
  * Nothing here is persisted: a new `Database` starts empty. See
24
33
  * docs/progressive-optimizer.md §3.2–3.6.
25
34
  */
26
35
  import type { OptimizerTuning } from '../planner/optimizer-tuning.js';
27
- import { CardinalityObservations } from '../runtime/cardinality-observations.js';
28
- import { type ObservedRowCounts } from '../planner/stats/table-cardinality.js';
36
+ import { CardinalityObservations, type RowsPerKeySpec } from '../runtime/cardinality-observations.js';
37
+ import { type ObservedKeyCardinalities, type ObservedRowCount, type ObservedRowCounts } from '../planner/stats/table-cardinality.js';
38
+ import type { SchemaDependency } from '../planner/planning-context.js';
29
39
  import type { TableSchema } from '../schema/table.js';
30
40
  import type { Database } from './database.js';
41
+ import type { ModuleRowCount } from '../vtab/module.js';
31
42
  /** Database internals the manager needs — keeps it constructible without the full `Database`. */
32
43
  export interface CardinalityFeedbackManagerContext {
33
44
  readonly schemaManager: Database['schemaManager'];
@@ -35,23 +46,38 @@ export interface CardinalityFeedbackManagerContext {
35
46
  getTuning(): OptimizerTuning;
36
47
  /** True when no transaction (explicit or implicit) is open. */
37
48
  getAutocommit(): boolean;
49
+ /** The table's module's own count (`RowCountSources.reportedRows`), ranked with this overlay's entry. */
50
+ reportedRows(table: TableSchema): ModuleRowCount | undefined;
38
51
  /**
39
- * A recorded count moved at least `cardinalityFeedback.shiftFactor` away from the
40
- * entry's baseline: plans costed against the old number may be wrong. `key` is the
41
- * lowercased `schema.table`.
52
+ * A recorded count, floor or rows-per-key mean moved at least
53
+ * `cardinalityFeedback.shiftFactor` away from its baseline: plans costed against the
54
+ * old number may be wrong. `key` is the lowercased `schema.table` — one key for every
55
+ * kind, so a per-key shift re-plans every statement reading the table, seeking or not.
42
56
  */
43
57
  onShift(key: string): void;
44
58
  }
59
+ /** By-value view of one column set's rows per key, for tests and diagnostics. */
60
+ export interface ObservedRowsPerKeySnapshot {
61
+ /** Column names, in the order of their sorted indexes. */
62
+ readonly keyColumns: readonly string[];
63
+ readonly rowsPerKey: number;
64
+ readonly samples: number;
65
+ readonly baselineRowsPerKey: number;
66
+ readonly shifts: number;
67
+ }
45
68
  /** By-value view of one valid entry, for tests and diagnostics. */
46
69
  export interface ObservedRowCountSnapshot {
47
70
  readonly schemaName: string;
48
71
  readonly tableName: string;
49
- readonly rows: number;
72
+ readonly rows: number | undefined;
73
+ readonly atLeast: number | undefined;
50
74
  /** What the catalog (`ANALYZE`) says for the same table; `undefined` when never analyzed. */
51
75
  readonly catalogRows: number | undefined;
52
76
  readonly baselineRows: number;
53
77
  readonly observations: number;
54
78
  readonly shifts: number;
79
+ /** Least recently recorded first. */
80
+ readonly perKey: readonly ObservedRowsPerKeySnapshot[];
55
81
  }
56
82
  /** The overlay's key for a table: lowercased `schema.table`. Shifts are reported under it. */
57
83
  export declare function overlayTableKey(schemaName: string, tableName: string): string;
@@ -76,7 +102,35 @@ export declare class FeedbackReplanState {
76
102
  onExecutionStart(cooldown: number): boolean;
77
103
  private requiredExecutions;
78
104
  }
79
- export declare class CardinalityFeedbackManager implements ObservedRowCounts {
105
+ /**
106
+ * The planned sizes, as of one compile, of the tables the plan reads whose module reports
107
+ * its own count (docs/progressive-optimizer.md §3.6). Such a count moves on every write
108
+ * with no event the planner hears, and a plan that no longer reads the table in full
109
+ * never produces an observation, so nothing else notices that a table planned at 10 rows
110
+ * now holds a million. A prepared statement compares its snapshot with the current
111
+ * planned sizes at each execution start and treats a drift like an overlay shift.
112
+ *
113
+ * Planned sizes, not raw module answers, are compared, so an approximate count the
114
+ * overlay outranks drifts only when what planning would use drifts.
115
+ */
116
+ export declare class ReportedSizeSnapshot {
117
+ private readonly sizes;
118
+ static readonly empty: ReportedSizeSnapshot;
119
+ private constructor();
120
+ /**
121
+ * Called right after a compile, in the same synchronous turn, so each size is the one
122
+ * the plan's table references were costed with. Tables whose module has no
123
+ * `getRowCount` are left out: overlay shifts and schema changes already cover them.
124
+ */
125
+ static capture(db: Database, dependencies: readonly SchemaDependency[]): ReportedSizeSnapshot;
126
+ /**
127
+ * True when some table's planned size has moved `shiftFactor` from the captured one
128
+ * with the larger side above `minRows` — the overlay's shift rule (§3.4). A table whose
129
+ * catalog object was replaced is skipped: that schema change already dropped the plan.
130
+ */
131
+ drifted(db: Database): boolean;
132
+ }
133
+ export declare class CardinalityFeedbackManager implements ObservedRowCounts, ObservedKeyCardinalities {
80
134
  private readonly ctx;
81
135
  /**
82
136
  * Lowercased `schema.table` → entry, the change-log / work-counter key convention.
@@ -86,23 +140,50 @@ export declare class CardinalityFeedbackManager implements ObservedRowCounts {
86
140
  private readonly entries;
87
141
  /**
88
142
  * Observations made inside the open transaction, held until it ends; same key as
89
- * `entries`, last count per table wins. Bounded by the distinct tables one
90
- * transaction observes.
143
+ * `entries`, last count and largest floor per table win. Bounded by the distinct
144
+ * tables one transaction observes.
91
145
  */
92
146
  private readonly pending;
93
147
  /** {@link onRolledBack} calls so far; each execution's sink records it at start. */
94
148
  private rollbacks;
95
149
  private unsubscribeSchemaChanges;
96
150
  constructor(ctx: CardinalityFeedbackManagerContext);
97
- observedRows(table: TableSchema): number | undefined;
151
+ observedRows(table: TableSchema): ObservedRowCount | undefined;
152
+ /** The running mean for `columns` on `table`, under the same identity rule as {@link observedRows}; a hit refreshes the table's recency. */
153
+ observedRowsPerKey(table: TableSchema, columns: readonly number[]): number | undefined;
98
154
  /**
99
155
  * Offer one exact row count of `table`, observed by a complete enumeration of
100
156
  * committed state. Applies the record policy (docs/progressive-optimizer.md §3.4):
101
157
  * ignored when the schema object is superseded or when both the observation and the
102
- * current estimate are small; otherwise recorded, and reported through `onShift`
103
- * when it has moved `shiftFactor` from the entry's baseline.
158
+ * current estimate are small; otherwise recorded — clearing any floor, which the newer
159
+ * complete count supersedes — and reported through `onShift` when it has moved
160
+ * `shiftFactor` from the entry's baseline.
104
161
  */
105
162
  record(table: TableSchema, rows: number): void;
163
+ /**
164
+ * Offer one floor for `table`: a read of committed state yielded `rows` distinct rows of
165
+ * it, so it holds at least that many (docs/progressive-optimizer.md §3.4). Recorded only
166
+ * when it exceeds both what planning would use now and `minRows`, so a floor never
167
+ * lowers an estimate and never makes an unknown table look smaller than the default it
168
+ * plans at today. Shifts like a count; floors only raise, so they cannot oscillate.
169
+ */
170
+ recordAtLeast(table: TableSchema, rows: number): void;
171
+ /**
172
+ * Offer `count` samples of rows per key for `spec`'s column set on `table`, summing to
173
+ * `sum` rows — one sample per exhausted equality seek with non-NULL keys
174
+ * (docs/progressive-optimizer.md §3.4). Ignored under a superseded schema, and unless
175
+ * the table's planned size exceeds `minRows`: below that every plan finishes fast, and
176
+ * the gate keeps small-table plans unchanged exactly as the count gate does. So a table
177
+ * of unknown size learns rows per key only once its size is learned (a complete scan,
178
+ * a floor, or a module count above the gate); publication applies per-key batches
179
+ * after the same execution's counts and floors, so one execution can open the gate for
180
+ * itself. A new column-set entry's baseline is the rows per key the plan was priced
181
+ * with; the table remembers at most `maxKeySetsPerTable` sets, least recently recorded
182
+ * evicted. Accepted bias: frequently probed keys weigh more than a uniform sample would.
183
+ * Reported through `onShift` under the table's key when the folded mean has moved
184
+ * `shiftFactor` from the set's baseline — the count rule, applied to the mean.
185
+ */
186
+ recordRowsPerKey(table: TableSchema, spec: RowsPerKeySpec, sum: number, count: number): void;
106
187
  /**
107
188
  * Offer one finished execution's observations (docs/progressive-optimizer.md §3.5).
108
189
  * A committed read (`readCommitted`) or an execution that ended with no transaction
@@ -115,12 +196,15 @@ export declare class CardinalityFeedbackManager implements ObservedRowCounts {
115
196
  publish(observations: CardinalityObservations, options: {
116
197
  readCommitted: boolean;
117
198
  }): void;
118
- /** A fresh per-execution sink, stamped so {@link publish} can tell whether a rollback ran under it. */
199
+ /**
200
+ * A fresh per-execution sink, stamped so {@link publish} can tell whether a rollback ran
201
+ * under it, and carrying the record floor so it can drop floors that could never record.
202
+ */
119
203
  beginObservations(): CardinalityObservations;
120
204
  /**
121
205
  * The open transaction committed: record what it held, except tables it wrote.
122
- * Such a count was taken mid-transaction, possibly before later writes in the same
123
- * transaction, and the change log cannot say which came first. `changedCounts` is
206
+ * Such an observation was made mid-transaction, possibly before later writes in the
207
+ * same transaction, and the change log cannot say which came first. `changedCounts` is
124
208
  * the change log keyed like `entries` — every table the transaction wrote, even one
125
209
  * whose writes cancelled out — and is not built when nothing is held.
126
210
  */
@@ -133,7 +217,36 @@ export declare class CardinalityFeedbackManager implements ObservedRowCounts {
133
217
  snapshot(): ObservedRowCountSnapshot[];
134
218
  dispose(): void;
135
219
  private subscribeToSchemaChanges;
220
+ /**
221
+ * Exact counts first: a floor at or below the count just recorded is then ignored.
222
+ * Rows per key last, so a count or floor from the same execution can open its table-size gate.
223
+ */
136
224
  private recordAll;
225
+ private holdAll;
226
+ /** What is held for `table`; anything held under an older schema object for its name is superseded. */
227
+ private held;
228
+ /** As {@link recordAll}: the count first, so a floor it already covers is ignored, and rows per key last. */
229
+ private recordHeld;
230
+ private isSuperseded;
231
+ /**
232
+ * What planning would use for `table` right now — `existing` ranked with the module's
233
+ * count and the catalog's (§3.3), else the default — so an exactly module-sized table
234
+ * compares against the module and a scan agreeing with it shifts nothing.
235
+ */
236
+ private plannedBefore;
237
+ /** Counts one recorded observation on `entry`, makes it the most recent, and enforces the cap. */
238
+ private upsert;
239
+ /** Reports a shift through `onShift` when `rows` has moved `shiftFactor` from the entry's baseline. */
240
+ private shiftIfMoved;
241
+ /**
242
+ * Reports a shift through `onShift` when a column set's mean has moved `shiftFactor`
243
+ * from its baseline. The table key is reported, not the set: a statement that reads the
244
+ * table re-plans and every seek node in it re-snapshots the overlay (§3.6). A set's first
245
+ * record cannot shift when its plan was already priced from the mean (the baseline is what
246
+ * the plan used); a set re-created after eviction carries the module's estimate again and
247
+ * may shift once, landing the same plan.
248
+ */
249
+ private shiftIfRowsPerKeyMoved;
137
250
  /** The entry under `key` if it was observed against `table`; a stale one is replaced on record. */
138
251
  private validEntry;
139
252
  private touch;
@@ -1 +1 @@
1
- {"version":3,"file":"database-cardinality-feedback.d.ts","sourceRoot":"","sources":["../../../src/core/database-cardinality-feedback.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAG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