@quereus/quereus 4.16.0 → 4.17.1

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 (170) hide show
  1. package/dist/src/core/database-auto-analyze.d.ts +258 -0
  2. package/dist/src/core/database-auto-analyze.d.ts.map +1 -0
  3. package/dist/src/core/database-auto-analyze.js +616 -0
  4. package/dist/src/core/database-auto-analyze.js.map +1 -0
  5. package/dist/src/core/database-materialized-views.d.ts +42 -1
  6. package/dist/src/core/database-materialized-views.d.ts.map +1 -1
  7. package/dist/src/core/database-materialized-views.js +76 -3
  8. package/dist/src/core/database-materialized-views.js.map +1 -1
  9. package/dist/src/core/database-transaction.d.ts +17 -0
  10. package/dist/src/core/database-transaction.d.ts.map +1 -1
  11. package/dist/src/core/database-transaction.js +37 -0
  12. package/dist/src/core/database-transaction.js.map +1 -1
  13. package/dist/src/core/database.d.ts +8 -1
  14. package/dist/src/core/database.d.ts.map +1 -1
  15. package/dist/src/core/database.js +135 -5
  16. package/dist/src/core/database.js.map +1 -1
  17. package/dist/src/planner/analysis/change-scope.d.ts.map +1 -1
  18. package/dist/src/planner/analysis/change-scope.js +8 -8
  19. package/dist/src/planner/analysis/change-scope.js.map +1 -1
  20. package/dist/src/planner/analysis/constraint-extractor.d.ts.map +1 -1
  21. package/dist/src/planner/analysis/constraint-extractor.js +27 -14
  22. package/dist/src/planner/analysis/constraint-extractor.js.map +1 -1
  23. package/dist/src/planner/analysis/expression-fingerprint.d.ts.map +1 -1
  24. package/dist/src/planner/analysis/expression-fingerprint.js +23 -2
  25. package/dist/src/planner/analysis/expression-fingerprint.js.map +1 -1
  26. package/dist/src/planner/analysis/mv-body-functions.d.ts +46 -0
  27. package/dist/src/planner/analysis/mv-body-functions.d.ts.map +1 -0
  28. package/dist/src/planner/analysis/mv-body-functions.js +65 -0
  29. package/dist/src/planner/analysis/mv-body-functions.js.map +1 -0
  30. package/dist/src/planner/analysis/predicate-shape.d.ts +32 -4
  31. package/dist/src/planner/analysis/predicate-shape.d.ts.map +1 -1
  32. package/dist/src/planner/analysis/predicate-shape.js +37 -5
  33. package/dist/src/planner/analysis/predicate-shape.js.map +1 -1
  34. package/dist/src/planner/analysis/query-rewrite-matcher.d.ts +2 -2
  35. package/dist/src/planner/analysis/query-rewrite-matcher.d.ts.map +1 -1
  36. package/dist/src/planner/analysis/query-rewrite-matcher.js +46 -6
  37. package/dist/src/planner/analysis/query-rewrite-matcher.js.map +1 -1
  38. package/dist/src/planner/analysis/sat-checker.js +2 -5
  39. package/dist/src/planner/analysis/sat-checker.js.map +1 -1
  40. package/dist/src/planner/building/select-aggregates.d.ts +17 -5
  41. package/dist/src/planner/building/select-aggregates.d.ts.map +1 -1
  42. package/dist/src/planner/building/select-aggregates.js +122 -79
  43. package/dist/src/planner/building/select-aggregates.js.map +1 -1
  44. package/dist/src/planner/building/select-modifiers.d.ts +1 -1
  45. package/dist/src/planner/building/select.d.ts.map +1 -1
  46. package/dist/src/planner/building/select.js +73 -55
  47. package/dist/src/planner/building/select.js.map +1 -1
  48. package/dist/src/planner/cost/index.d.ts +28 -0
  49. package/dist/src/planner/cost/index.d.ts.map +1 -1
  50. package/dist/src/planner/cost/index.js +33 -0
  51. package/dist/src/planner/cost/index.js.map +1 -1
  52. package/dist/src/planner/nodes/limit-offset.d.ts.map +1 -1
  53. package/dist/src/planner/nodes/limit-offset.js +3 -2
  54. package/dist/src/planner/nodes/limit-offset.js.map +1 -1
  55. package/dist/src/planner/optimizer-tuning.d.ts +10 -6
  56. package/dist/src/planner/optimizer-tuning.d.ts.map +1 -1
  57. package/dist/src/planner/optimizer-tuning.js.map +1 -1
  58. package/dist/src/planner/optimizer.d.ts.map +1 -1
  59. package/dist/src/planner/optimizer.js +49 -0
  60. package/dist/src/planner/optimizer.js.map +1 -1
  61. package/dist/src/planner/rules/access/rule-monotonic-range-access.d.ts.map +1 -1
  62. package/dist/src/planner/rules/access/rule-monotonic-range-access.js +8 -4
  63. package/dist/src/planner/rules/access/rule-monotonic-range-access.js.map +1 -1
  64. package/dist/src/planner/rules/access/rule-select-access-path.d.ts +14 -0
  65. package/dist/src/planner/rules/access/rule-select-access-path.d.ts.map +1 -1
  66. package/dist/src/planner/rules/access/rule-select-access-path.js +5 -1
  67. package/dist/src/planner/rules/access/rule-select-access-path.js.map +1 -1
  68. package/dist/src/planner/rules/aggregate/rule-groupby-fd-simplification.d.ts +3 -1
  69. package/dist/src/planner/rules/aggregate/rule-groupby-fd-simplification.d.ts.map +1 -1
  70. package/dist/src/planner/rules/aggregate/rule-groupby-fd-simplification.js +8 -3
  71. package/dist/src/planner/rules/aggregate/rule-groupby-fd-simplification.js.map +1 -1
  72. package/dist/src/planner/rules/aggregate/rule-minmax-index-boundary.d.ts +47 -0
  73. package/dist/src/planner/rules/aggregate/rule-minmax-index-boundary.d.ts.map +1 -0
  74. package/dist/src/planner/rules/aggregate/rule-minmax-index-boundary.js +200 -0
  75. package/dist/src/planner/rules/aggregate/rule-minmax-index-boundary.js.map +1 -0
  76. package/dist/src/planner/rules/cache/rule-nested-loop-right-cache.d.ts +29 -0
  77. package/dist/src/planner/rules/cache/rule-nested-loop-right-cache.d.ts.map +1 -1
  78. package/dist/src/planner/rules/cache/rule-nested-loop-right-cache.js +55 -16
  79. package/dist/src/planner/rules/cache/rule-nested-loop-right-cache.js.map +1 -1
  80. package/dist/src/planner/rules/join/index-nested-loop.d.ts +96 -22
  81. package/dist/src/planner/rules/join/index-nested-loop.d.ts.map +1 -1
  82. package/dist/src/planner/rules/join/index-nested-loop.js +401 -82
  83. package/dist/src/planner/rules/join/index-nested-loop.js.map +1 -1
  84. package/dist/src/planner/rules/join/rule-fanout-batched-outer.d.ts +20 -0
  85. package/dist/src/planner/rules/join/rule-fanout-batched-outer.d.ts.map +1 -1
  86. package/dist/src/planner/rules/join/rule-fanout-batched-outer.js +23 -4
  87. package/dist/src/planner/rules/join/rule-fanout-batched-outer.js.map +1 -1
  88. package/dist/src/planner/rules/join/rule-join-greedy-commute.d.ts.map +1 -1
  89. package/dist/src/planner/rules/join/rule-join-greedy-commute.js +7 -0
  90. package/dist/src/planner/rules/join/rule-join-greedy-commute.js.map +1 -1
  91. package/dist/src/planner/rules/join/rule-join-physical-selection.d.ts +19 -2
  92. package/dist/src/planner/rules/join/rule-join-physical-selection.d.ts.map +1 -1
  93. package/dist/src/planner/rules/join/rule-join-physical-selection.js +262 -40
  94. package/dist/src/planner/rules/join/rule-join-physical-selection.js.map +1 -1
  95. package/dist/src/planner/rules/join/rule-quickpick-enumeration.d.ts.map +1 -1
  96. package/dist/src/planner/rules/join/rule-quickpick-enumeration.js +24 -4
  97. package/dist/src/planner/rules/join/rule-quickpick-enumeration.js.map +1 -1
  98. package/dist/src/planner/rules/join/rule-semi-join-pushdown.d.ts +107 -0
  99. package/dist/src/planner/rules/join/rule-semi-join-pushdown.d.ts.map +1 -0
  100. package/dist/src/planner/rules/join/rule-semi-join-pushdown.js +214 -0
  101. package/dist/src/planner/rules/join/rule-semi-join-pushdown.js.map +1 -0
  102. package/dist/src/planner/rules/predicate/rule-sargable-range-rewrite.d.ts.map +1 -1
  103. package/dist/src/planner/rules/predicate/rule-sargable-range-rewrite.js +2 -1
  104. package/dist/src/planner/rules/predicate/rule-sargable-range-rewrite.js.map +1 -1
  105. package/dist/src/planner/rules/retrieve/rule-grow-retrieve.d.ts +21 -0
  106. package/dist/src/planner/rules/retrieve/rule-grow-retrieve.d.ts.map +1 -1
  107. package/dist/src/planner/rules/retrieve/rule-grow-retrieve.js +24 -6
  108. package/dist/src/planner/rules/retrieve/rule-grow-retrieve.js.map +1 -1
  109. package/dist/src/planner/rules/shared/access-leaf.d.ts +12 -12
  110. package/dist/src/planner/rules/shared/access-leaf.d.ts.map +1 -1
  111. package/dist/src/planner/rules/shared/access-leaf.js +3 -14
  112. package/dist/src/planner/rules/shared/access-leaf.js.map +1 -1
  113. package/dist/src/planner/stats/catalog-stats.d.ts.map +1 -1
  114. package/dist/src/planner/stats/catalog-stats.js +6 -10
  115. package/dist/src/planner/stats/catalog-stats.js.map +1 -1
  116. package/dist/src/planner/type-utils.d.ts.map +1 -1
  117. package/dist/src/planner/type-utils.js +3 -5
  118. package/dist/src/planner/type-utils.js.map +1 -1
  119. package/dist/src/planner/util/fd-utils.d.ts.map +1 -1
  120. package/dist/src/planner/util/fd-utils.js +4 -7
  121. package/dist/src/planner/util/fd-utils.js.map +1 -1
  122. package/dist/src/runtime/emit/alter-table.d.ts.map +1 -1
  123. package/dist/src/runtime/emit/alter-table.js +58 -4
  124. package/dist/src/runtime/emit/alter-table.js.map +1 -1
  125. package/dist/src/runtime/emit/binary.d.ts.map +1 -1
  126. package/dist/src/runtime/emit/binary.js +5 -3
  127. package/dist/src/runtime/emit/binary.js.map +1 -1
  128. package/dist/src/runtime/emit/fanout-lookup-join.d.ts.map +1 -1
  129. package/dist/src/runtime/emit/fanout-lookup-join.js +9 -1
  130. package/dist/src/runtime/emit/fanout-lookup-join.js.map +1 -1
  131. package/dist/src/runtime/emit/limit-offset.d.ts.map +1 -1
  132. package/dist/src/runtime/emit/limit-offset.js +50 -24
  133. package/dist/src/runtime/emit/limit-offset.js.map +1 -1
  134. package/dist/src/runtime/emit/materialized-view-helpers.d.ts +33 -2
  135. package/dist/src/runtime/emit/materialized-view-helpers.d.ts.map +1 -1
  136. package/dist/src/runtime/emit/materialized-view-helpers.js +61 -5
  137. package/dist/src/runtime/emit/materialized-view-helpers.js.map +1 -1
  138. package/dist/src/runtime/emit/materialized-view.d.ts.map +1 -1
  139. package/dist/src/runtime/emit/materialized-view.js +6 -1
  140. package/dist/src/runtime/emit/materialized-view.js.map +1 -1
  141. package/dist/src/runtime/emit/ordinal-slice.d.ts.map +1 -1
  142. package/dist/src/runtime/emit/ordinal-slice.js +8 -0
  143. package/dist/src/runtime/emit/ordinal-slice.js.map +1 -1
  144. package/dist/src/schema/derivation.d.ts +15 -1
  145. package/dist/src/schema/derivation.d.ts.map +1 -1
  146. package/dist/src/schema/derivation.js.map +1 -1
  147. package/dist/src/schema/function.d.ts +9 -4
  148. package/dist/src/schema/function.d.ts.map +1 -1
  149. package/dist/src/schema/function.js +11 -9
  150. package/dist/src/schema/function.js.map +1 -1
  151. package/dist/src/schema/schema.d.ts +14 -3
  152. package/dist/src/schema/schema.d.ts.map +1 -1
  153. package/dist/src/schema/schema.js +20 -2
  154. package/dist/src/schema/schema.js.map +1 -1
  155. package/dist/src/schema/table.d.ts +27 -0
  156. package/dist/src/schema/table.d.ts.map +1 -1
  157. package/dist/src/schema/table.js +55 -0
  158. package/dist/src/schema/table.js.map +1 -1
  159. package/dist/src/schema/unique-enforcement.d.ts +6 -13
  160. package/dist/src/schema/unique-enforcement.d.ts.map +1 -1
  161. package/dist/src/schema/unique-enforcement.js +8 -17
  162. package/dist/src/schema/unique-enforcement.js.map +1 -1
  163. package/dist/src/util/comparison.d.ts +19 -0
  164. package/dist/src/util/comparison.d.ts.map +1 -1
  165. package/dist/src/util/comparison.js +22 -0
  166. package/dist/src/util/comparison.js.map +1 -1
  167. package/dist/src/vtab/memory/module.d.ts.map +1 -1
  168. package/dist/src/vtab/memory/module.js +10 -0
  169. package/dist/src/vtab/memory/module.js.map +1 -1
  170. package/package.json +3 -3
@@ -0,0 +1,258 @@
1
+ /**
2
+ * Auto-analyze staleness bookkeeping and background statistics refresh.
3
+ *
4
+ * Tracks, per base table, how many distinct rows committed transactions have
5
+ * changed since statistics were last collected for that table, decides when that
6
+ * drift is large enough to call the table's statistics stale, and — off the write
7
+ * path, from a debounced timer — refreshes them by running the ordinary `ANALYZE`
8
+ * statement for that one table.
9
+ *
10
+ * The counts come from the transaction change log (`TransactionManager`), read
11
+ * post-commit while the log is still alive. That log is maintained
12
+ * unconditionally on every write path already, so counting costs one `Map.size`
13
+ * read per table per savepoint layer and nothing on the write path itself.
14
+ *
15
+ * The refresh goes through `db.exec('analyze …')` rather than reaching into the
16
+ * collection internals. Two things fall out of that:
17
+ *
18
+ * - `db.exec` acquires the database's execution mutex, which is what serializes
19
+ * all statement execution. A refresh driven from a timer therefore queues
20
+ * behind whatever is running instead of racing it. It cannot deadlock, because
21
+ * it is never started from inside a statement.
22
+ * - There is exactly one implementation of "collect and record statistics for a
23
+ * table" (`runtime/emit/analyze.ts`), including its per-table `try` that logs
24
+ * and continues.
25
+ *
26
+ * A refresh cannot trigger itself: `ANALYZE` performs no DML, and it publishes
27
+ * its result by swapping the `TableSchema` and firing the internal catalog
28
+ * notifier rather than the data-change channel. Its implicit transaction commits
29
+ * with an empty change log, so no counter advances.
30
+ */
31
+ import type { Database } from './database.js';
32
+ /**
33
+ * First delay before retrying a refresh that was deferred because a transaction
34
+ * was open, doubling on each further retry (250, 500, 1000, 2000 ms).
35
+ *
36
+ * NOT the debounce: the debounce exists to let a burst of commits collapse, and
37
+ * 50 ms is far too soon to expect a statement that was in flight a moment ago to
38
+ * have finished. Starting an order of magnitude higher means the common case — a
39
+ * timer landing inside one ordinary `UPDATE` — is served by the first retry
40
+ * instead of burning the whole budget on wakeups that all land inside the same
41
+ * statement.
42
+ *
43
+ * NOTE: 250 ms is reasoning, not measurement — nothing has measured how long a
44
+ * statement actually holds its implicit transaction, and a memory-backed one
45
+ * frequently never yields to the timer queue at all (a 400-row `insert … values`
46
+ * ran to completion without a single `setTimeout(0)` firing), so this mostly
47
+ * governs store-backed workloads and explicit `BEGIN`s. If the debug log shows
48
+ * crossings routinely spending the whole budget, measure a real workload before
49
+ * raising the retry count — a longer first delay is likelier to be the fix.
50
+ */
51
+ export declare const AUTO_ANALYZE_DEFER_RETRY_MS = 250;
52
+ /**
53
+ * How many times one crossing may reschedule itself after being deferred. The
54
+ * geometric backoff above makes that about 3.75 s of total patience.
55
+ *
56
+ * Bounded on purpose: a user may park an explicit transaction open indefinitely,
57
+ * and an unbounded retry would then cost a wakeup per stale table forever. Once
58
+ * the budget is spent the crossing is dropped exactly as it was before retries
59
+ * existed — the counter stays over threshold and the next commit that touches the
60
+ * table re-arms.
61
+ *
62
+ * Must stay at or below `AUTO_ANALYZE_IDLE_MAX_PASSES - 2`: {@link
63
+ * AutoAnalyzeManager.whenIdle} spends one settle pass per retry plus one for the
64
+ * initial attempt and one to observe that nothing is left armed.
65
+ */
66
+ export declare const AUTO_ANALYZE_MAX_DEFER_RETRIES = 4;
67
+ /**
68
+ * Safety bound on {@link AutoAnalyzeManager.whenIdle}'s settle loop. Exported so the
69
+ * inequality against {@link AUTO_ANALYZE_MAX_DEFER_RETRIES} is checked by a test
70
+ * rather than only implied by one failing if it were ever violated.
71
+ */
72
+ export declare const AUTO_ANALYZE_IDLE_MAX_PASSES = 10;
73
+ /**
74
+ * Why a scheduled refresh ended. Only `deferred` wants a retry — it is the one
75
+ * outcome where nothing about the table changed and the refusal was purely about
76
+ * *when* the timer happened to land.
77
+ *
78
+ * The union exists so that `declined` (a deliberate refusal — feature off, table
79
+ * oversize, table gone) and `deferred` (transient) cannot be spelled the same way.
80
+ * Before it, every early return in {@link AutoAnalyzeManager['refresh']} was a bare
81
+ * `return` and a transient refusal silently abandoned its crossing.
82
+ */
83
+ export type RefreshOutcome = 'analyzed' | 'declined' | 'deferred' | 'failed';
84
+ /**
85
+ * Delay for a debounce timer armed at `now` for a table not eligible until
86
+ * `nextEligibleAt`: the debounce, or the remaining duty-cycle cooldown when that
87
+ * is longer. Exported for the same reason {@link isStaleCount} is — the cooldown
88
+ * arithmetic is otherwise only observable through timing.
89
+ */
90
+ export declare function armDelayMs(nextEligibleAt: number, now: number): number;
91
+ /**
92
+ * Database internals the auto-analyze manager needs. Mirrors
93
+ * `WatcherManagerContext` — keeps the manager constructible without the full
94
+ * `Database`.
95
+ */
96
+ export interface AutoAnalyzeManagerContext {
97
+ readonly schemaManager: Database['schemaManager'];
98
+ readonly options: Database['options'];
99
+ _findTable(tableName: string, schemaName?: string): ReturnType<Database['_findTable']>;
100
+ /**
101
+ * False while a transaction is open — an explicit `BEGIN…COMMIT` **and also** the
102
+ * implicit transaction a *writing* statement runs inside. Only the DML and DDL
103
+ * emitters call `_ensureTransaction`, so a read-only statement leaves this `true`,
104
+ * while every `insert` (`values` included — `runInsert` opens the transaction before
105
+ * it consumes its first row), `update`, `delete` and any DDL make it `false` for the
106
+ * rest of that statement. Since the refresh fires from a timer, it can land inside
107
+ * one of those and read `false` in a database the user considers to be in autocommit.
108
+ */
109
+ getAutocommit(): boolean;
110
+ /** Runs the refresh statement. Acquires the execution mutex — see the module doc. */
111
+ exec(sql: string): Promise<void>;
112
+ }
113
+ /** Per-table staleness bookkeeping. Keyed by lowercased `schema.table`. */
114
+ export interface TableStalenessEntry {
115
+ /** Distinct rows changed by committed transactions since the last successful
116
+ * statistics refresh. */
117
+ changedSinceAnalyze: number;
118
+ /** rowCount recorded by the last refresh this process observed; undefined = never. */
119
+ analyzedRowCount: number | undefined;
120
+ /** True once this crossing has been logged; cleared when the counter resets. */
121
+ staleLogged: boolean;
122
+ /** Armed debounce timer, if any. */
123
+ timer: ReturnType<typeof setTimeout> | undefined;
124
+ /** Resolves when the in-flight refresh for this table settles; undefined when idle. */
125
+ running: Promise<void> | undefined;
126
+ /** Epoch ms before which no refresh may start (duty-cycle cooldown / failure backoff). */
127
+ nextEligibleAt: number;
128
+ /** True once the oversize skip has been logged; cleared on a successful refresh. */
129
+ oversizeLogged: boolean;
130
+ /**
131
+ * Retries already spent on the current crossing after being deferred by an open
132
+ * transaction, capped at `AUTO_ANALYZE_MAX_DEFER_RETRIES`. Zeroed by a successful
133
+ * refresh and by any commit that touches the table, so it bounds one crossing's
134
+ * patience rather than the table's lifetime.
135
+ */
136
+ deferRetries: number;
137
+ }
138
+ /**
139
+ * The staleness threshold in changed rows:
140
+ *
141
+ * ```
142
+ * stale ⟺ changedSinceAnalyze >= max(minMutations, ratio × knownRowCount)
143
+ * ```
144
+ *
145
+ * `knownRowCount` is 0 for a never-analyzed table (`SchemaManager` hardcodes
146
+ * `estimatedRows` to 0 at create), so the absolute floor governs exactly the
147
+ * case that matters most: bulk-loading rows into a fresh table trips
148
+ * `minMutations` long before any percentage of zero could.
149
+ *
150
+ * Precedent for the defaults: SQL Server's auto-update-stats uses 500 + 20% of
151
+ * rows; PostgreSQL's autoanalyze uses 50 + 10%.
152
+ */
153
+ export declare function stalenessThreshold(minMutations: number, ratio: number, knownRowCount: number): number;
154
+ /** Pure form of the staleness predicate — see {@link stalenessThreshold}. */
155
+ export declare function isStaleCount(changedSinceAnalyze: number, minMutations: number, ratio: number, knownRowCount: number): boolean;
156
+ /**
157
+ * Tracks committed-mutation drift per base table for a single `Database`, and
158
+ * schedules the background refresh that clears it.
159
+ */
160
+ export declare class AutoAnalyzeManager {
161
+ private readonly ctx;
162
+ /**
163
+ * Lowercased `schema.table` → staleness bookkeeping. Same key convention the
164
+ * change log uses, so no re-derivation and no second key convention.
165
+ *
166
+ * NOTE: nothing here is persisted. After a restart the store backend's saved
167
+ * statistics still exist, but staleness accumulation restarts from zero — a
168
+ * table that drifted while the process was down looks fresh until it drifts
169
+ * again. Accepted for v1 (a restart is rare relative to the mutation
170
+ * threshold). If it ever matters, persist `changedSinceAnalyze` beside the
171
+ * table's statistics entry and reload it when the catalog loads.
172
+ */
173
+ private readonly entries;
174
+ private unsubscribeSchemaChanges;
175
+ /** Set by {@link dispose}; every scheduled path checks it before doing work. */
176
+ private disposed;
177
+ /** Refreshes that actually reached the `ANALYZE` statement. Test instrumentation. */
178
+ private refreshes;
179
+ constructor(ctx: AutoAnalyzeManagerContext);
180
+ private subscribeToSchemaChanges;
181
+ /**
182
+ * Fold one committed transaction's per-table changed-row counts into the
183
+ * staleness map and re-evaluate the threshold for every table it touched.
184
+ * Entries are created lazily on first touch.
185
+ */
186
+ recordCommit(counts: Map<string, number>): void;
187
+ /**
188
+ * Whether the named table (lowercased `schema.table`) has drifted past the
189
+ * threshold. Not a pure predicate: a table that has since disappeared answers
190
+ * `false` and has its entry dropped — see {@link knownRowCountOrDrop}.
191
+ */
192
+ isStale(key: string): boolean;
193
+ dispose(): void;
194
+ /** Cancel any armed timer for `entry`. Safe to call when none is armed. */
195
+ private clearTimer;
196
+ /** Forget a table, cancelling any refresh armed for it. */
197
+ private dropEntry;
198
+ /**
199
+ * Row count the ratio arm of the threshold applies to: what the last refresh
200
+ * this process observed reported, else whatever the catalog knows.
201
+ *
202
+ * Named for its side effect: a table that is gone (dropped between the commit
203
+ * and this lookup, or carried in from a detached schema) answers `undefined`
204
+ * AND has its entry evicted here, so every consumer of a row count doubles as
205
+ * the eviction path for stale keys. That is why {@link isStale} mutates.
206
+ */
207
+ private knownRowCountOrDrop;
208
+ private findTable;
209
+ /**
210
+ * Re-evaluate the threshold for one table after its counter moved: log the first
211
+ * crossing (a busy table must not flood the log) and arm a refresh.
212
+ */
213
+ private evaluate;
214
+ /** Schedule the debounced refresh for a table that has just crossed the threshold. */
215
+ private arm;
216
+ /**
217
+ * Begin a refresh, publish its settle promise on the entry, and act on how it
218
+ * ended. This is the single place that turns a {@link RefreshOutcome} into a
219
+ * scheduling decision — `refresh` itself only reports.
220
+ */
221
+ private start;
222
+ /** Decide what a finished refresh means for scheduling. */
223
+ private applyOutcome;
224
+ /**
225
+ * Reschedule a refusal that was purely about timing, on a geometric backoff and
226
+ * within a fixed budget. Once the budget is spent the crossing is dropped and the
227
+ * next commit that touches the table is what revives it.
228
+ */
229
+ private armDeferRetry;
230
+ /**
231
+ * Refresh one table's statistics, reporting how it ended. Never throws: a failed
232
+ * automatic refresh must not surface as an error on an unrelated user statement,
233
+ * and nothing awaits this.
234
+ *
235
+ * It decides nothing about scheduling — every exit names a {@link RefreshOutcome}
236
+ * and {@link start} decides what that means. A new early return therefore has to
237
+ * say whether it is a refusal or a deferral, which is what keeps "abandoned
238
+ * crossing" from being writable by accident.
239
+ */
240
+ private refresh;
241
+ /** Catalog row count for a table, ignoring the entry's own record. */
242
+ private catalogRowCount;
243
+ private enabled;
244
+ private minMutations;
245
+ private ratio;
246
+ /**
247
+ * Largest table (in known rows) an automatic refresh will scan; 0 disables the cap.
248
+ *
249
+ * NOTE: the gate is purely on row count. An earlier design also exempted modules
250
+ * whose `getStatistics()` answers the whole question cheaply, but no shipped module
251
+ * does — both the store backend (`store-table-base.ts`) and the memory backend
252
+ * (`vtab/memory/table.ts`) deliberately return an EMPTY `columnStats`, which
253
+ * `ANALYZE` reads as "size answered, scan for the rest". The exemption would be dead
254
+ * code. If a module that reports complete statistics ever appears, exempt it here.
255
+ */
256
+ private rowLimit;
257
+ }
258
+ //# sourceMappingURL=database-auto-analyze.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database-auto-analyze.d.ts","sourceRoot":"","sources":["../../../src/core/database-auto-analyze.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAOH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAgC9C;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAE/C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,8BAA8B,IAAI,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,4BAA4B,KAAK,CAAC;AAE/C;;;;;;;;;GASG;AACH,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,UAAU,GAAG,UAAU,GAAG,QAAQ,CAAC;AAE7E;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,cAAc,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED;;;;GAIG;AACH,MAAM,WAAW,yBAAyB;IACzC,QAAQ,CAAC,aAAa,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC;IAClD,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IAEtC,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC;IACvF;;;;;;;;OAQG;IACH,aAAa,IAAI,OAAO,CAAC;IACzB,qFAAqF;IACrF,IAAI,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