@quereus/quereus 4.3.1 → 4.4.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 (788) hide show
  1. package/README.md +25 -7
  2. package/dist/src/common/types.d.ts +9 -59
  3. package/dist/src/common/types.d.ts.map +1 -1
  4. package/dist/src/common/types.js.map +1 -1
  5. package/dist/src/core/database-assertions.d.ts +2 -2
  6. package/dist/src/core/database-assertions.d.ts.map +1 -1
  7. package/dist/src/core/database-assertions.js +4 -3
  8. package/dist/src/core/database-assertions.js.map +1 -1
  9. package/dist/src/core/database-external-changes.d.ts +3 -3
  10. package/dist/src/core/database-external-changes.d.ts.map +1 -1
  11. package/dist/src/core/database-external-changes.js +13 -10
  12. package/dist/src/core/database-external-changes.js.map +1 -1
  13. package/dist/src/core/database-internal.d.ts.map +1 -1
  14. package/dist/src/core/database-materialized-views-analysis.d.ts +199 -0
  15. package/dist/src/core/database-materialized-views-analysis.d.ts.map +1 -0
  16. package/dist/src/core/database-materialized-views-analysis.js +502 -0
  17. package/dist/src/core/database-materialized-views-analysis.js.map +1 -0
  18. package/dist/src/core/database-materialized-views-apply.d.ts +422 -0
  19. package/dist/src/core/database-materialized-views-apply.d.ts.map +1 -0
  20. package/dist/src/core/database-materialized-views-apply.js +929 -0
  21. package/dist/src/core/database-materialized-views-apply.js.map +1 -0
  22. package/dist/src/core/database-materialized-views-plan-builders.d.ts +267 -0
  23. package/dist/src/core/database-materialized-views-plan-builders.d.ts.map +1 -0
  24. package/dist/src/core/database-materialized-views-plan-builders.js +1423 -0
  25. package/dist/src/core/database-materialized-views-plan-builders.js.map +1 -0
  26. package/dist/src/core/database-materialized-views-plans.d.ts +641 -0
  27. package/dist/src/core/database-materialized-views-plans.d.ts.map +1 -0
  28. package/dist/src/core/database-materialized-views-plans.js +13 -0
  29. package/dist/src/core/database-materialized-views-plans.js.map +1 -0
  30. package/dist/src/core/database-materialized-views.d.ts +108 -860
  31. package/dist/src/core/database-materialized-views.d.ts.map +1 -1
  32. package/dist/src/core/database-materialized-views.js +212 -2165
  33. package/dist/src/core/database-materialized-views.js.map +1 -1
  34. package/dist/src/core/database-transaction.d.ts +10 -1
  35. package/dist/src/core/database-transaction.d.ts.map +1 -1
  36. package/dist/src/core/database-transaction.js +16 -4
  37. package/dist/src/core/database-transaction.js.map +1 -1
  38. package/dist/src/core/database-watchers.d.ts.map +1 -1
  39. package/dist/src/core/database-watchers.js +2 -1
  40. package/dist/src/core/database-watchers.js.map +1 -1
  41. package/dist/src/core/database.d.ts +99 -13
  42. package/dist/src/core/database.d.ts.map +1 -1
  43. package/dist/src/core/database.js +270 -50
  44. package/dist/src/core/database.js.map +1 -1
  45. package/dist/src/core/derived-row-validator.d.ts +1 -1
  46. package/dist/src/core/derived-row-validator.d.ts.map +1 -1
  47. package/dist/src/core/derived-row-validator.js +5 -3
  48. package/dist/src/core/derived-row-validator.js.map +1 -1
  49. package/dist/src/core/statement.d.ts +8 -0
  50. package/dist/src/core/statement.d.ts.map +1 -1
  51. package/dist/src/core/statement.js +98 -18
  52. package/dist/src/core/statement.js.map +1 -1
  53. package/dist/src/emit/ast-stringify.d.ts.map +1 -1
  54. package/dist/src/emit/ast-stringify.js +24 -13
  55. package/dist/src/emit/ast-stringify.js.map +1 -1
  56. package/dist/src/func/builtins/aggregate.d.ts.map +1 -1
  57. package/dist/src/func/builtins/aggregate.js +127 -21
  58. package/dist/src/func/builtins/aggregate.js.map +1 -1
  59. package/dist/src/func/builtins/explain.d.ts.map +1 -1
  60. package/dist/src/func/builtins/explain.js +2 -1
  61. package/dist/src/func/builtins/explain.js.map +1 -1
  62. package/dist/src/func/builtins/json.d.ts.map +1 -1
  63. package/dist/src/func/builtins/json.js +2 -1
  64. package/dist/src/func/builtins/json.js.map +1 -1
  65. package/dist/src/func/builtins/mutation.d.ts.map +1 -1
  66. package/dist/src/func/builtins/mutation.js +3 -2
  67. package/dist/src/func/builtins/mutation.js.map +1 -1
  68. package/dist/src/func/registration.d.ts +6 -1
  69. package/dist/src/func/registration.d.ts.map +1 -1
  70. package/dist/src/func/registration.js +16 -0
  71. package/dist/src/func/registration.js.map +1 -1
  72. package/dist/src/index.d.ts +16 -6
  73. package/dist/src/index.d.ts.map +1 -1
  74. package/dist/src/index.js +33 -7
  75. package/dist/src/index.js.map +1 -1
  76. package/dist/src/parser/ast.d.ts +2 -2
  77. package/dist/src/parser/lexer.d.ts +11 -1
  78. package/dist/src/parser/lexer.d.ts.map +1 -1
  79. package/dist/src/parser/lexer.js +40 -34
  80. package/dist/src/parser/lexer.js.map +1 -1
  81. package/dist/src/parser/parser.d.ts.map +1 -1
  82. package/dist/src/parser/parser.js +16 -9
  83. package/dist/src/parser/parser.js.map +1 -1
  84. package/dist/src/planner/analysis/authored-inverse.js +1 -1
  85. package/dist/src/planner/analysis/comparison-collation.d.ts +52 -0
  86. package/dist/src/planner/analysis/comparison-collation.d.ts.map +1 -1
  87. package/dist/src/planner/analysis/comparison-collation.js +84 -7
  88. package/dist/src/planner/analysis/comparison-collation.js.map +1 -1
  89. package/dist/src/planner/analysis/constraint-extractor.d.ts.map +1 -1
  90. package/dist/src/planner/analysis/constraint-extractor.js +64 -17
  91. package/dist/src/planner/analysis/constraint-extractor.js.map +1 -1
  92. package/dist/src/planner/analysis/coverage-prover.d.ts +1 -1
  93. package/dist/src/planner/analysis/coverage-prover.js +1 -1
  94. package/dist/src/planner/analysis/equi-correlation.d.ts +26 -0
  95. package/dist/src/planner/analysis/equi-correlation.d.ts.map +1 -0
  96. package/dist/src/planner/analysis/equi-correlation.js +62 -0
  97. package/dist/src/planner/analysis/equi-correlation.js.map +1 -0
  98. package/dist/src/planner/analysis/query-rewrite-matcher.d.ts +54 -18
  99. package/dist/src/planner/analysis/query-rewrite-matcher.d.ts.map +1 -1
  100. package/dist/src/planner/analysis/query-rewrite-matcher.js +86 -42
  101. package/dist/src/planner/analysis/query-rewrite-matcher.js.map +1 -1
  102. package/dist/src/planner/analysis/sat-checker.d.ts +8 -1
  103. package/dist/src/planner/analysis/sat-checker.d.ts.map +1 -1
  104. package/dist/src/planner/analysis/sat-checker.js +117 -22
  105. package/dist/src/planner/analysis/sat-checker.js.map +1 -1
  106. package/dist/src/planner/analysis/scalar-invertibility.d.ts +13 -4
  107. package/dist/src/planner/analysis/scalar-invertibility.d.ts.map +1 -1
  108. package/dist/src/planner/analysis/scalar-invertibility.js +12 -3
  109. package/dist/src/planner/analysis/scalar-invertibility.js.map +1 -1
  110. package/dist/src/planner/analysis/scalar-subqueries.d.ts +28 -0
  111. package/dist/src/planner/analysis/scalar-subqueries.d.ts.map +1 -0
  112. package/dist/src/planner/analysis/scalar-subqueries.js +60 -0
  113. package/dist/src/planner/analysis/scalar-subqueries.js.map +1 -0
  114. package/dist/src/planner/analysis/update-lineage.d.ts +1 -1
  115. package/dist/src/planner/analysis/update-lineage.js +1 -1
  116. package/dist/src/planner/analysis/update-lineage.js.map +1 -1
  117. package/dist/src/planner/analysis/view-complement.d.ts +2 -2
  118. package/dist/src/planner/building/delete.js +2 -2
  119. package/dist/src/planner/building/delete.js.map +1 -1
  120. package/dist/src/planner/building/dml-target.d.ts +2 -2
  121. package/dist/src/planner/building/dml-target.js +2 -2
  122. package/dist/src/planner/building/insert.d.ts.map +1 -1
  123. package/dist/src/planner/building/insert.js +53 -2
  124. package/dist/src/planner/building/insert.js.map +1 -1
  125. package/dist/src/planner/building/schema-resolution.d.ts +3 -0
  126. package/dist/src/planner/building/schema-resolution.d.ts.map +1 -1
  127. package/dist/src/planner/building/schema-resolution.js +4 -5
  128. package/dist/src/planner/building/schema-resolution.js.map +1 -1
  129. package/dist/src/planner/building/select.d.ts.map +1 -1
  130. package/dist/src/planner/building/select.js +18 -4
  131. package/dist/src/planner/building/select.js.map +1 -1
  132. package/dist/src/planner/building/update.js +2 -2
  133. package/dist/src/planner/building/update.js.map +1 -1
  134. package/dist/src/planner/building/view-mutation-builder.js +7 -7
  135. package/dist/src/planner/building/view-mutation-builder.js.map +1 -1
  136. package/dist/src/planner/building/with.d.ts.map +1 -1
  137. package/dist/src/planner/building/with.js +5 -8
  138. package/dist/src/planner/building/with.js.map +1 -1
  139. package/dist/src/planner/cache/materialization-advisory.d.ts +34 -2
  140. package/dist/src/planner/cache/materialization-advisory.d.ts.map +1 -1
  141. package/dist/src/planner/cache/materialization-advisory.js +185 -42
  142. package/dist/src/planner/cache/materialization-advisory.js.map +1 -1
  143. package/dist/src/planner/cache/reference-graph.d.ts +14 -5
  144. package/dist/src/planner/cache/reference-graph.d.ts.map +1 -1
  145. package/dist/src/planner/cache/reference-graph.js +31 -39
  146. package/dist/src/planner/cache/reference-graph.js.map +1 -1
  147. package/dist/src/planner/cost/index.d.ts +30 -5
  148. package/dist/src/planner/cost/index.d.ts.map +1 -1
  149. package/dist/src/planner/cost/index.js +26 -0
  150. package/dist/src/planner/cost/index.js.map +1 -1
  151. package/dist/src/planner/debug.d.ts +3 -2
  152. package/dist/src/planner/debug.d.ts.map +1 -1
  153. package/dist/src/planner/debug.js +9 -3
  154. package/dist/src/planner/debug.js.map +1 -1
  155. package/dist/src/planner/framework/characteristics.d.ts +46 -19
  156. package/dist/src/planner/framework/characteristics.d.ts.map +1 -1
  157. package/dist/src/planner/framework/characteristics.js +50 -134
  158. package/dist/src/planner/framework/characteristics.js.map +1 -1
  159. package/dist/src/planner/framework/context.d.ts +8 -44
  160. package/dist/src/planner/framework/context.d.ts.map +1 -1
  161. package/dist/src/planner/framework/context.js +0 -91
  162. package/dist/src/planner/framework/context.js.map +1 -1
  163. package/dist/src/planner/framework/pass.d.ts +7 -0
  164. package/dist/src/planner/framework/pass.d.ts.map +1 -1
  165. package/dist/src/planner/framework/pass.js +84 -0
  166. package/dist/src/planner/framework/pass.js.map +1 -1
  167. package/dist/src/planner/framework/registry.d.ts +13 -42
  168. package/dist/src/planner/framework/registry.d.ts.map +1 -1
  169. package/dist/src/planner/framework/registry.js +14 -182
  170. package/dist/src/planner/framework/registry.js.map +1 -1
  171. package/dist/src/planner/mutation/backward-body.d.ts +2 -2
  172. package/dist/src/planner/mutation/cte-flatten.js +1 -1
  173. package/dist/src/planner/mutation/decomposition.d.ts +2 -2
  174. package/dist/src/planner/mutation/decomposition.js +1 -1
  175. package/dist/src/planner/mutation/lens-enforcement.d.ts.map +1 -1
  176. package/dist/src/planner/mutation/lens-enforcement.js +2 -1
  177. package/dist/src/planner/mutation/lens-enforcement.js.map +1 -1
  178. package/dist/src/planner/mutation/multi-source.d.ts +8 -8
  179. package/dist/src/planner/mutation/multi-source.js +11 -11
  180. package/dist/src/planner/mutation/multi-source.js.map +1 -1
  181. package/dist/src/planner/mutation/propagate.d.ts +1 -1
  182. package/dist/src/planner/mutation/propagate.js +1 -1
  183. package/dist/src/planner/mutation/scope-transform.d.ts +2 -2
  184. package/dist/src/planner/mutation/scope-transform.js +3 -3
  185. package/dist/src/planner/mutation/scope-transform.js.map +1 -1
  186. package/dist/src/planner/mutation/set-op.d.ts +1 -1
  187. package/dist/src/planner/mutation/set-op.d.ts.map +1 -1
  188. package/dist/src/planner/mutation/set-op.js +3 -2
  189. package/dist/src/planner/mutation/set-op.js.map +1 -1
  190. package/dist/src/planner/mutation/single-source.d.ts +3 -3
  191. package/dist/src/planner/mutation/single-source.js +9 -9
  192. package/dist/src/planner/mutation/single-source.js.map +1 -1
  193. package/dist/src/planner/nodes/aggregate-function.d.ts +3 -1
  194. package/dist/src/planner/nodes/aggregate-function.d.ts.map +1 -1
  195. package/dist/src/planner/nodes/aggregate-function.js +1 -0
  196. package/dist/src/planner/nodes/aggregate-function.js.map +1 -1
  197. package/dist/src/planner/nodes/aggregate-node.d.ts +1 -0
  198. package/dist/src/planner/nodes/aggregate-node.d.ts.map +1 -1
  199. package/dist/src/planner/nodes/aggregate-node.js +8 -1
  200. package/dist/src/planner/nodes/aggregate-node.js.map +1 -1
  201. package/dist/src/planner/nodes/alias-node.d.ts.map +1 -1
  202. package/dist/src/planner/nodes/alias-node.js +3 -1
  203. package/dist/src/planner/nodes/alias-node.js.map +1 -1
  204. package/dist/src/planner/nodes/asof-scan-node.d.ts.map +1 -1
  205. package/dist/src/planner/nodes/asof-scan-node.js +3 -2
  206. package/dist/src/planner/nodes/asof-scan-node.js.map +1 -1
  207. package/dist/src/planner/nodes/asserted-keys-node.d.ts +1 -1
  208. package/dist/src/planner/nodes/asserted-keys-node.d.ts.map +1 -1
  209. package/dist/src/planner/nodes/asserted-keys-node.js +5 -2
  210. package/dist/src/planner/nodes/asserted-keys-node.js.map +1 -1
  211. package/dist/src/planner/nodes/async-gather-node.d.ts.map +1 -1
  212. package/dist/src/planner/nodes/async-gather-node.js +3 -1
  213. package/dist/src/planner/nodes/async-gather-node.js.map +1 -1
  214. package/dist/src/planner/nodes/block.js +3 -3
  215. package/dist/src/planner/nodes/block.js.map +1 -1
  216. package/dist/src/planner/nodes/bloom-join-node.d.ts +2 -0
  217. package/dist/src/planner/nodes/bloom-join-node.d.ts.map +1 -1
  218. package/dist/src/planner/nodes/bloom-join-node.js +5 -1
  219. package/dist/src/planner/nodes/bloom-join-node.js.map +1 -1
  220. package/dist/src/planner/nodes/cache-node.d.ts +19 -2
  221. package/dist/src/planner/nodes/cache-node.d.ts.map +1 -1
  222. package/dist/src/planner/nodes/cache-node.js +43 -3
  223. package/dist/src/planner/nodes/cache-node.js.map +1 -1
  224. package/dist/src/planner/nodes/cte-node.d.ts +16 -1
  225. package/dist/src/planner/nodes/cte-node.d.ts.map +1 -1
  226. package/dist/src/planner/nodes/cte-node.js +16 -3
  227. package/dist/src/planner/nodes/cte-node.js.map +1 -1
  228. package/dist/src/planner/nodes/distinct-node.js +3 -3
  229. package/dist/src/planner/nodes/distinct-node.js.map +1 -1
  230. package/dist/src/planner/nodes/dml-executor-node.d.ts +21 -0
  231. package/dist/src/planner/nodes/dml-executor-node.d.ts.map +1 -1
  232. package/dist/src/planner/nodes/dml-executor-node.js.map +1 -1
  233. package/dist/src/planner/nodes/envelope-scan-node.d.ts +1 -1
  234. package/dist/src/planner/nodes/envelope-scan-node.js +1 -1
  235. package/dist/src/planner/nodes/fanout-lookup-join-node.d.ts.map +1 -1
  236. package/dist/src/planner/nodes/fanout-lookup-join-node.js +4 -2
  237. package/dist/src/planner/nodes/fanout-lookup-join-node.js.map +1 -1
  238. package/dist/src/planner/nodes/filter.d.ts +10 -2
  239. package/dist/src/planner/nodes/filter.d.ts.map +1 -1
  240. package/dist/src/planner/nodes/filter.js +81 -14
  241. package/dist/src/planner/nodes/filter.js.map +1 -1
  242. package/dist/src/planner/nodes/hash-aggregate.d.ts +12 -1
  243. package/dist/src/planner/nodes/hash-aggregate.d.ts.map +1 -1
  244. package/dist/src/planner/nodes/hash-aggregate.js +28 -1
  245. package/dist/src/planner/nodes/hash-aggregate.js.map +1 -1
  246. package/dist/src/planner/nodes/internal-recursive-cte-ref-node.d.ts +3 -1
  247. package/dist/src/planner/nodes/internal-recursive-cte-ref-node.d.ts.map +1 -1
  248. package/dist/src/planner/nodes/internal-recursive-cte-ref-node.js +1 -0
  249. package/dist/src/planner/nodes/internal-recursive-cte-ref-node.js.map +1 -1
  250. package/dist/src/planner/nodes/join-node.d.ts +3 -1
  251. package/dist/src/planner/nodes/join-node.d.ts.map +1 -1
  252. package/dist/src/planner/nodes/join-node.js +5 -5
  253. package/dist/src/planner/nodes/join-node.js.map +1 -1
  254. package/dist/src/planner/nodes/lens-auxiliary-access-node.d.ts.map +1 -1
  255. package/dist/src/planner/nodes/lens-auxiliary-access-node.js +4 -1
  256. package/dist/src/planner/nodes/lens-auxiliary-access-node.js.map +1 -1
  257. package/dist/src/planner/nodes/limit-offset.d.ts +1 -0
  258. package/dist/src/planner/nodes/limit-offset.d.ts.map +1 -1
  259. package/dist/src/planner/nodes/limit-offset.js +4 -3
  260. package/dist/src/planner/nodes/limit-offset.js.map +1 -1
  261. package/dist/src/planner/nodes/merge-join-node.d.ts +2 -0
  262. package/dist/src/planner/nodes/merge-join-node.d.ts.map +1 -1
  263. package/dist/src/planner/nodes/merge-join-node.js +6 -1
  264. package/dist/src/planner/nodes/merge-join-node.js.map +1 -1
  265. package/dist/src/planner/nodes/ordinal-slice-node.d.ts.map +1 -1
  266. package/dist/src/planner/nodes/ordinal-slice-node.js +3 -1
  267. package/dist/src/planner/nodes/ordinal-slice-node.js.map +1 -1
  268. package/dist/src/planner/nodes/plan-node.d.ts +68 -5
  269. package/dist/src/planner/nodes/plan-node.d.ts.map +1 -1
  270. package/dist/src/planner/nodes/plan-node.js +137 -24
  271. package/dist/src/planner/nodes/plan-node.js.map +1 -1
  272. package/dist/src/planner/nodes/project-node.d.ts +3 -2
  273. package/dist/src/planner/nodes/project-node.d.ts.map +1 -1
  274. package/dist/src/planner/nodes/project-node.js +1 -0
  275. package/dist/src/planner/nodes/project-node.js.map +1 -1
  276. package/dist/src/planner/nodes/recursive-cte-node.d.ts +30 -1
  277. package/dist/src/planner/nodes/recursive-cte-node.d.ts.map +1 -1
  278. package/dist/src/planner/nodes/recursive-cte-node.js +38 -5
  279. package/dist/src/planner/nodes/recursive-cte-node.js.map +1 -1
  280. package/dist/src/planner/nodes/reference.d.ts +5 -1
  281. package/dist/src/planner/nodes/reference.d.ts.map +1 -1
  282. package/dist/src/planner/nodes/reference.js +3 -0
  283. package/dist/src/planner/nodes/reference.js.map +1 -1
  284. package/dist/src/planner/nodes/remote-query-node.d.ts.map +1 -1
  285. package/dist/src/planner/nodes/remote-query-node.js +3 -1
  286. package/dist/src/planner/nodes/remote-query-node.js.map +1 -1
  287. package/dist/src/planner/nodes/retrieve-node.d.ts.map +1 -1
  288. package/dist/src/planner/nodes/retrieve-node.js +3 -1
  289. package/dist/src/planner/nodes/retrieve-node.js.map +1 -1
  290. package/dist/src/planner/nodes/set-operation-node.d.ts.map +1 -1
  291. package/dist/src/planner/nodes/set-operation-node.js +3 -1
  292. package/dist/src/planner/nodes/set-operation-node.js.map +1 -1
  293. package/dist/src/planner/nodes/sink-node.d.ts.map +1 -1
  294. package/dist/src/planner/nodes/sink-node.js +3 -1
  295. package/dist/src/planner/nodes/sink-node.js.map +1 -1
  296. package/dist/src/planner/nodes/sort.d.ts +2 -1
  297. package/dist/src/planner/nodes/sort.d.ts.map +1 -1
  298. package/dist/src/planner/nodes/sort.js +9 -5
  299. package/dist/src/planner/nodes/sort.js.map +1 -1
  300. package/dist/src/planner/nodes/stream-aggregate.d.ts +12 -1
  301. package/dist/src/planner/nodes/stream-aggregate.d.ts.map +1 -1
  302. package/dist/src/planner/nodes/stream-aggregate.js +32 -3
  303. package/dist/src/planner/nodes/stream-aggregate.js.map +1 -1
  304. package/dist/src/planner/nodes/table-access-nodes.d.ts +2 -1
  305. package/dist/src/planner/nodes/table-access-nodes.d.ts.map +1 -1
  306. package/dist/src/planner/nodes/table-access-nodes.js +2 -0
  307. package/dist/src/planner/nodes/table-access-nodes.js.map +1 -1
  308. package/dist/src/planner/nodes/view-mutation-node.d.ts +2 -2
  309. package/dist/src/planner/nodes/view-mutation-node.d.ts.map +1 -1
  310. package/dist/src/planner/nodes/view-mutation-node.js +5 -1
  311. package/dist/src/planner/nodes/view-mutation-node.js.map +1 -1
  312. package/dist/src/planner/nodes/window-function.d.ts +3 -1
  313. package/dist/src/planner/nodes/window-function.d.ts.map +1 -1
  314. package/dist/src/planner/nodes/window-function.js +1 -0
  315. package/dist/src/planner/nodes/window-function.js.map +1 -1
  316. package/dist/src/planner/optimizer.d.ts +52 -8
  317. package/dist/src/planner/optimizer.d.ts.map +1 -1
  318. package/dist/src/planner/optimizer.js +1014 -895
  319. package/dist/src/planner/optimizer.js.map +1 -1
  320. package/dist/src/planner/rules/access/rule-select-access-path.d.ts.map +1 -1
  321. package/dist/src/planner/rules/access/rule-select-access-path.js +235 -202
  322. package/dist/src/planner/rules/access/rule-select-access-path.js.map +1 -1
  323. package/dist/src/planner/rules/cache/rule-cte-optimization.d.ts.map +1 -1
  324. package/dist/src/planner/rules/cache/rule-cte-optimization.js +8 -1
  325. package/dist/src/planner/rules/cache/rule-cte-optimization.js.map +1 -1
  326. package/dist/src/planner/rules/cache/rule-in-subquery-cache.d.ts +7 -0
  327. package/dist/src/planner/rules/cache/rule-in-subquery-cache.d.ts.map +1 -1
  328. package/dist/src/planner/rules/cache/rule-in-subquery-cache.js +14 -1
  329. package/dist/src/planner/rules/cache/rule-in-subquery-cache.js.map +1 -1
  330. package/dist/src/planner/rules/cache/rule-materialized-view-rewrite.d.ts +2 -2
  331. package/dist/src/planner/rules/cache/rule-materialized-view-rewrite.d.ts.map +1 -1
  332. package/dist/src/planner/rules/cache/rule-materialized-view-rewrite.js +55 -56
  333. package/dist/src/planner/rules/cache/rule-materialized-view-rewrite.js.map +1 -1
  334. package/dist/src/planner/rules/cache/rule-mutating-subquery-cache.d.ts.map +1 -1
  335. package/dist/src/planner/rules/cache/rule-mutating-subquery-cache.js +6 -0
  336. package/dist/src/planner/rules/cache/rule-mutating-subquery-cache.js.map +1 -1
  337. package/dist/src/planner/rules/cache/rule-nested-loop-right-cache.d.ts +25 -0
  338. package/dist/src/planner/rules/cache/rule-nested-loop-right-cache.d.ts.map +1 -0
  339. package/dist/src/planner/rules/cache/rule-nested-loop-right-cache.js +176 -0
  340. package/dist/src/planner/rules/cache/rule-nested-loop-right-cache.js.map +1 -0
  341. package/dist/src/planner/rules/cache/rule-scalar-cse.d.ts +1 -1
  342. package/dist/src/planner/rules/cache/rule-scalar-cse.js +1 -1
  343. package/dist/src/planner/rules/cache/rule-scalar-subquery-cache.d.ts +29 -0
  344. package/dist/src/planner/rules/cache/rule-scalar-subquery-cache.d.ts.map +1 -0
  345. package/dist/src/planner/rules/cache/rule-scalar-subquery-cache.js +66 -0
  346. package/dist/src/planner/rules/cache/rule-scalar-subquery-cache.js.map +1 -0
  347. package/dist/src/planner/rules/join/rule-fanout-batched-outer.d.ts +1 -1
  348. package/dist/src/planner/rules/join/rule-fanout-batched-outer.js +1 -1
  349. package/dist/src/planner/rules/join/rule-fanout-lookup-join.d.ts.map +1 -1
  350. package/dist/src/planner/rules/join/rule-fanout-lookup-join.js +1 -54
  351. package/dist/src/planner/rules/join/rule-fanout-lookup-join.js.map +1 -1
  352. package/dist/src/planner/rules/join/rule-inner-join-existence-recovery.d.ts +1 -1
  353. package/dist/src/planner/rules/join/rule-inner-join-existence-recovery.js +1 -1
  354. package/dist/src/planner/rules/join/rule-join-elimination.d.ts +1 -1
  355. package/dist/src/planner/rules/join/rule-join-elimination.js +1 -1
  356. package/dist/src/planner/rules/parallel/rule-async-gather-zip-by-key.js +5 -6
  357. package/dist/src/planner/rules/parallel/rule-async-gather-zip-by-key.js.map +1 -1
  358. package/dist/src/planner/rules/predicate/rule-empty-relation-folding.d.ts +1 -1
  359. package/dist/src/planner/rules/predicate/rule-empty-relation-folding.js +1 -1
  360. package/dist/src/planner/rules/predicate/rule-filter-contradiction.d.ts +2 -2
  361. package/dist/src/planner/rules/predicate/rule-filter-contradiction.d.ts.map +1 -1
  362. package/dist/src/planner/rules/predicate/rule-filter-contradiction.js +4 -3
  363. package/dist/src/planner/rules/predicate/rule-filter-contradiction.js.map +1 -1
  364. package/dist/src/planner/rules/predicate/rule-filter-selectivity.d.ts +19 -0
  365. package/dist/src/planner/rules/predicate/rule-filter-selectivity.d.ts.map +1 -0
  366. package/dist/src/planner/rules/predicate/rule-filter-selectivity.js +48 -0
  367. package/dist/src/planner/rules/predicate/rule-filter-selectivity.js.map +1 -0
  368. package/dist/src/planner/rules/predicate/rule-sargable-range-rewrite.js +12 -1
  369. package/dist/src/planner/rules/predicate/rule-sargable-range-rewrite.js.map +1 -1
  370. package/dist/src/planner/rules/retrieve/rule-grow-retrieve.d.ts.map +1 -1
  371. package/dist/src/planner/rules/retrieve/rule-grow-retrieve.js +22 -20
  372. package/dist/src/planner/rules/retrieve/rule-grow-retrieve.js.map +1 -1
  373. package/dist/src/planner/rules/shared/index-style-context.d.ts +39 -0
  374. package/dist/src/planner/rules/shared/index-style-context.d.ts.map +1 -0
  375. package/dist/src/planner/rules/shared/index-style-context.js +26 -0
  376. package/dist/src/planner/rules/shared/index-style-context.js.map +1 -0
  377. package/dist/src/planner/rules/sort/rule-orderby-fd-pruning.d.ts +1 -1
  378. package/dist/src/planner/rules/sort/rule-orderby-fd-pruning.js +1 -1
  379. package/dist/src/planner/rules/subquery/rule-anti-join-fk-empty.d.ts +1 -1
  380. package/dist/src/planner/rules/subquery/rule-anti-join-fk-empty.js +1 -1
  381. package/dist/src/planner/rules/subquery/rule-scalar-agg-decorrelation.d.ts +191 -0
  382. package/dist/src/planner/rules/subquery/rule-scalar-agg-decorrelation.d.ts.map +1 -0
  383. package/dist/src/planner/rules/subquery/rule-scalar-agg-decorrelation.js +623 -0
  384. package/dist/src/planner/rules/subquery/rule-scalar-agg-decorrelation.js.map +1 -0
  385. package/dist/src/planner/rules/subquery/rule-subquery-decorrelation.d.ts +10 -1
  386. package/dist/src/planner/rules/subquery/rule-subquery-decorrelation.d.ts.map +1 -1
  387. package/dist/src/planner/rules/subquery/rule-subquery-decorrelation.js +242 -51
  388. package/dist/src/planner/rules/subquery/rule-subquery-decorrelation.js.map +1 -1
  389. package/dist/src/planner/stats/analyze.d.ts.map +1 -1
  390. package/dist/src/planner/stats/analyze.js +2 -20
  391. package/dist/src/planner/stats/analyze.js.map +1 -1
  392. package/dist/src/planner/stats/histogram.d.ts.map +1 -1
  393. package/dist/src/planner/stats/histogram.js +4 -0
  394. package/dist/src/planner/stats/histogram.js.map +1 -1
  395. package/dist/src/planner/util/fd-utils.d.ts +2 -3
  396. package/dist/src/planner/util/fd-utils.d.ts.map +1 -1
  397. package/dist/src/planner/util/fd-utils.js +2 -3
  398. package/dist/src/planner/util/fd-utils.js.map +1 -1
  399. package/dist/src/planner/validation/plan-validator.d.ts +16 -0
  400. package/dist/src/planner/validation/plan-validator.d.ts.map +1 -1
  401. package/dist/src/planner/validation/plan-validator.js +36 -0
  402. package/dist/src/planner/validation/plan-validator.js.map +1 -1
  403. package/dist/src/runtime/async-util.d.ts +26 -0
  404. package/dist/src/runtime/async-util.d.ts.map +1 -1
  405. package/dist/src/runtime/async-util.js +139 -55
  406. package/dist/src/runtime/async-util.js.map +1 -1
  407. package/dist/src/runtime/cache/shared-cache.d.ts +7 -0
  408. package/dist/src/runtime/cache/shared-cache.d.ts.map +1 -1
  409. package/dist/src/runtime/cache/shared-cache.js +34 -1
  410. package/dist/src/runtime/cache/shared-cache.js.map +1 -1
  411. package/dist/src/runtime/context-helpers.d.ts +32 -4
  412. package/dist/src/runtime/context-helpers.d.ts.map +1 -1
  413. package/dist/src/runtime/context-helpers.js +26 -9
  414. package/dist/src/runtime/context-helpers.js.map +1 -1
  415. package/dist/src/runtime/deferred-constraint-queue.d.ts.map +1 -1
  416. package/dist/src/runtime/deferred-constraint-queue.js +2 -1
  417. package/dist/src/runtime/deferred-constraint-queue.js.map +1 -1
  418. package/dist/src/runtime/emission-context.d.ts +27 -3
  419. package/dist/src/runtime/emission-context.d.ts.map +1 -1
  420. package/dist/src/runtime/emission-context.js +38 -7
  421. package/dist/src/runtime/emission-context.js.map +1 -1
  422. package/dist/src/runtime/emit/add-constraint.d.ts.map +1 -1
  423. package/dist/src/runtime/emit/add-constraint.js +7 -1
  424. package/dist/src/runtime/emit/add-constraint.js.map +1 -1
  425. package/dist/src/runtime/emit/aggregate.d.ts +2 -3
  426. package/dist/src/runtime/emit/aggregate.d.ts.map +1 -1
  427. package/dist/src/runtime/emit/aggregate.js +23 -28
  428. package/dist/src/runtime/emit/aggregate.js.map +1 -1
  429. package/dist/src/runtime/emit/alter-table.d.ts.map +1 -1
  430. package/dist/src/runtime/emit/alter-table.js +98 -9
  431. package/dist/src/runtime/emit/alter-table.js.map +1 -1
  432. package/dist/src/runtime/emit/analyze.d.ts.map +1 -1
  433. package/dist/src/runtime/emit/analyze.js +2 -1
  434. package/dist/src/runtime/emit/analyze.js.map +1 -1
  435. package/dist/src/runtime/emit/asof-scan.d.ts.map +1 -1
  436. package/dist/src/runtime/emit/asof-scan.js +13 -10
  437. package/dist/src/runtime/emit/asof-scan.js.map +1 -1
  438. package/dist/src/runtime/emit/async-gather.d.ts.map +1 -1
  439. package/dist/src/runtime/emit/async-gather.js +4 -3
  440. package/dist/src/runtime/emit/async-gather.js.map +1 -1
  441. package/dist/src/runtime/emit/between.d.ts.map +1 -1
  442. package/dist/src/runtime/emit/between.js +2 -1
  443. package/dist/src/runtime/emit/between.js.map +1 -1
  444. package/dist/src/runtime/emit/binary.d.ts.map +1 -1
  445. package/dist/src/runtime/emit/binary.js +122 -14
  446. package/dist/src/runtime/emit/binary.js.map +1 -1
  447. package/dist/src/runtime/emit/block.d.ts.map +1 -1
  448. package/dist/src/runtime/emit/block.js +2 -1
  449. package/dist/src/runtime/emit/block.js.map +1 -1
  450. package/dist/src/runtime/emit/bloom-join.d.ts.map +1 -1
  451. package/dist/src/runtime/emit/bloom-join.js +20 -8
  452. package/dist/src/runtime/emit/bloom-join.js.map +1 -1
  453. package/dist/src/runtime/emit/cache.d.ts +7 -3
  454. package/dist/src/runtime/emit/cache.d.ts.map +1 -1
  455. package/dist/src/runtime/emit/cache.js +25 -7
  456. package/dist/src/runtime/emit/cache.js.map +1 -1
  457. package/dist/src/runtime/emit/case.d.ts.map +1 -1
  458. package/dist/src/runtime/emit/case.js +66 -45
  459. package/dist/src/runtime/emit/case.js.map +1 -1
  460. package/dist/src/runtime/emit/cast.d.ts.map +1 -1
  461. package/dist/src/runtime/emit/cast.js +2 -1
  462. package/dist/src/runtime/emit/cast.js.map +1 -1
  463. package/dist/src/runtime/emit/constraint-check.d.ts.map +1 -1
  464. package/dist/src/runtime/emit/constraint-check.js +13 -7
  465. package/dist/src/runtime/emit/constraint-check.js.map +1 -1
  466. package/dist/src/runtime/emit/create-assertion.d.ts.map +1 -1
  467. package/dist/src/runtime/emit/create-assertion.js +2 -1
  468. package/dist/src/runtime/emit/create-assertion.js.map +1 -1
  469. package/dist/src/runtime/emit/create-index.d.ts.map +1 -1
  470. package/dist/src/runtime/emit/create-index.js +12 -1
  471. package/dist/src/runtime/emit/create-index.js.map +1 -1
  472. package/dist/src/runtime/emit/create-table.d.ts.map +1 -1
  473. package/dist/src/runtime/emit/create-table.js +12 -1
  474. package/dist/src/runtime/emit/create-table.js.map +1 -1
  475. package/dist/src/runtime/emit/cte-reference.d.ts.map +1 -1
  476. package/dist/src/runtime/emit/cte-reference.js +2 -1
  477. package/dist/src/runtime/emit/cte-reference.js.map +1 -1
  478. package/dist/src/runtime/emit/cte.d.ts.map +1 -1
  479. package/dist/src/runtime/emit/cte.js +45 -21
  480. package/dist/src/runtime/emit/cte.js.map +1 -1
  481. package/dist/src/runtime/emit/ddl-transaction-policy.d.ts +50 -0
  482. package/dist/src/runtime/emit/ddl-transaction-policy.d.ts.map +1 -0
  483. package/dist/src/runtime/emit/ddl-transaction-policy.js +69 -0
  484. package/dist/src/runtime/emit/ddl-transaction-policy.js.map +1 -0
  485. package/dist/src/runtime/emit/delete.d.ts.map +1 -1
  486. package/dist/src/runtime/emit/delete.js +2 -1
  487. package/dist/src/runtime/emit/delete.js.map +1 -1
  488. package/dist/src/runtime/emit/distinct.d.ts.map +1 -1
  489. package/dist/src/runtime/emit/distinct.js +2 -1
  490. package/dist/src/runtime/emit/distinct.js.map +1 -1
  491. package/dist/src/runtime/emit/dml-executor.d.ts.map +1 -1
  492. package/dist/src/runtime/emit/dml-executor.js +138 -74
  493. package/dist/src/runtime/emit/dml-executor.js.map +1 -1
  494. package/dist/src/runtime/emit/drop-assertion.d.ts.map +1 -1
  495. package/dist/src/runtime/emit/drop-assertion.js +2 -1
  496. package/dist/src/runtime/emit/drop-assertion.js.map +1 -1
  497. package/dist/src/runtime/emit/drop-index.d.ts.map +1 -1
  498. package/dist/src/runtime/emit/drop-index.js +17 -1
  499. package/dist/src/runtime/emit/drop-index.js.map +1 -1
  500. package/dist/src/runtime/emit/drop-table.d.ts.map +1 -1
  501. package/dist/src/runtime/emit/drop-table.js +11 -1
  502. package/dist/src/runtime/emit/drop-table.js.map +1 -1
  503. package/dist/src/runtime/emit/eager-prefetch.d.ts.map +1 -1
  504. package/dist/src/runtime/emit/eager-prefetch.js +2 -1
  505. package/dist/src/runtime/emit/eager-prefetch.js.map +1 -1
  506. package/dist/src/runtime/emit/envelope-scan.d.ts.map +1 -1
  507. package/dist/src/runtime/emit/envelope-scan.js +2 -1
  508. package/dist/src/runtime/emit/envelope-scan.js.map +1 -1
  509. package/dist/src/runtime/emit/fanout-lookup-join.d.ts.map +1 -1
  510. package/dist/src/runtime/emit/fanout-lookup-join.js +3 -2
  511. package/dist/src/runtime/emit/fanout-lookup-join.js.map +1 -1
  512. package/dist/src/runtime/emit/filter.d.ts.map +1 -1
  513. package/dist/src/runtime/emit/filter.js +8 -3
  514. package/dist/src/runtime/emit/filter.js.map +1 -1
  515. package/dist/src/runtime/emit/hash-aggregate.d.ts.map +1 -1
  516. package/dist/src/runtime/emit/hash-aggregate.js +16 -11
  517. package/dist/src/runtime/emit/hash-aggregate.js.map +1 -1
  518. package/dist/src/runtime/emit/insert.d.ts.map +1 -1
  519. package/dist/src/runtime/emit/insert.js +2 -1
  520. package/dist/src/runtime/emit/insert.js.map +1 -1
  521. package/dist/src/runtime/emit/join.d.ts.map +1 -1
  522. package/dist/src/runtime/emit/join.js +20 -6
  523. package/dist/src/runtime/emit/join.js.map +1 -1
  524. package/dist/src/runtime/emit/limit-offset.d.ts.map +1 -1
  525. package/dist/src/runtime/emit/limit-offset.js +2 -1
  526. package/dist/src/runtime/emit/limit-offset.js.map +1 -1
  527. package/dist/src/runtime/emit/literal.d.ts.map +1 -1
  528. package/dist/src/runtime/emit/literal.js +2 -1
  529. package/dist/src/runtime/emit/literal.js.map +1 -1
  530. package/dist/src/runtime/emit/materialized-view-helpers.d.ts +22 -0
  531. package/dist/src/runtime/emit/materialized-view-helpers.d.ts.map +1 -1
  532. package/dist/src/runtime/emit/materialized-view-helpers.js +128 -16
  533. package/dist/src/runtime/emit/materialized-view-helpers.js.map +1 -1
  534. package/dist/src/runtime/emit/materialized-view.d.ts.map +1 -1
  535. package/dist/src/runtime/emit/materialized-view.js +6 -0
  536. package/dist/src/runtime/emit/materialized-view.js.map +1 -1
  537. package/dist/src/runtime/emit/merge-join.d.ts.map +1 -1
  538. package/dist/src/runtime/emit/merge-join.js +14 -4
  539. package/dist/src/runtime/emit/merge-join.js.map +1 -1
  540. package/dist/src/runtime/emit/ordinal-slice.d.ts.map +1 -1
  541. package/dist/src/runtime/emit/ordinal-slice.js +2 -1
  542. package/dist/src/runtime/emit/ordinal-slice.js.map +1 -1
  543. package/dist/src/runtime/emit/pragma.d.ts.map +1 -1
  544. package/dist/src/runtime/emit/pragma.js +2 -1
  545. package/dist/src/runtime/emit/pragma.js.map +1 -1
  546. package/dist/src/runtime/emit/project.d.ts.map +1 -1
  547. package/dist/src/runtime/emit/project.js +7 -2
  548. package/dist/src/runtime/emit/project.js.map +1 -1
  549. package/dist/src/runtime/emit/recursive-cte.d.ts.map +1 -1
  550. package/dist/src/runtime/emit/recursive-cte.js +61 -2
  551. package/dist/src/runtime/emit/recursive-cte.js.map +1 -1
  552. package/dist/src/runtime/emit/returning.d.ts.map +1 -1
  553. package/dist/src/runtime/emit/returning.js +7 -2
  554. package/dist/src/runtime/emit/returning.js.map +1 -1
  555. package/dist/src/runtime/emit/scalar-function.d.ts.map +1 -1
  556. package/dist/src/runtime/emit/scalar-function.js +2 -1
  557. package/dist/src/runtime/emit/scalar-function.js.map +1 -1
  558. package/dist/src/runtime/emit/scan.d.ts.map +1 -1
  559. package/dist/src/runtime/emit/scan.js +55 -17
  560. package/dist/src/runtime/emit/scan.js.map +1 -1
  561. package/dist/src/runtime/emit/schema-declarative.d.ts.map +1 -1
  562. package/dist/src/runtime/emit/schema-declarative.js +6 -5
  563. package/dist/src/runtime/emit/schema-declarative.js.map +1 -1
  564. package/dist/src/runtime/emit/sequencing.d.ts.map +1 -1
  565. package/dist/src/runtime/emit/sequencing.js +2 -1
  566. package/dist/src/runtime/emit/sequencing.js.map +1 -1
  567. package/dist/src/runtime/emit/set-operation.d.ts.map +1 -1
  568. package/dist/src/runtime/emit/set-operation.js +6 -5
  569. package/dist/src/runtime/emit/set-operation.js.map +1 -1
  570. package/dist/src/runtime/emit/sink.d.ts.map +1 -1
  571. package/dist/src/runtime/emit/sink.js +2 -1
  572. package/dist/src/runtime/emit/sink.js.map +1 -1
  573. package/dist/src/runtime/emit/sort.d.ts.map +1 -1
  574. package/dist/src/runtime/emit/sort.js +2 -1
  575. package/dist/src/runtime/emit/sort.js.map +1 -1
  576. package/dist/src/runtime/emit/subquery.d.ts.map +1 -1
  577. package/dist/src/runtime/emit/subquery.js +42 -23
  578. package/dist/src/runtime/emit/subquery.js.map +1 -1
  579. package/dist/src/runtime/emit/table-valued-function.d.ts.map +1 -1
  580. package/dist/src/runtime/emit/table-valued-function.js +2 -1
  581. package/dist/src/runtime/emit/table-valued-function.js.map +1 -1
  582. package/dist/src/runtime/emit/temporal-arithmetic.d.ts.map +1 -1
  583. package/dist/src/runtime/emit/temporal-arithmetic.js +2 -1
  584. package/dist/src/runtime/emit/temporal-arithmetic.js.map +1 -1
  585. package/dist/src/runtime/emit/transaction.d.ts.map +1 -1
  586. package/dist/src/runtime/emit/transaction.js +2 -1
  587. package/dist/src/runtime/emit/transaction.js.map +1 -1
  588. package/dist/src/runtime/emit/unary.d.ts.map +1 -1
  589. package/dist/src/runtime/emit/unary.js +2 -1
  590. package/dist/src/runtime/emit/unary.js.map +1 -1
  591. package/dist/src/runtime/emit/update.d.ts.map +1 -1
  592. package/dist/src/runtime/emit/update.js +2 -1
  593. package/dist/src/runtime/emit/update.js.map +1 -1
  594. package/dist/src/runtime/emit/values.d.ts.map +1 -1
  595. package/dist/src/runtime/emit/values.js +2 -1
  596. package/dist/src/runtime/emit/values.js.map +1 -1
  597. package/dist/src/runtime/emit/view-mutation.d.ts +1 -1
  598. package/dist/src/runtime/emit/view-mutation.d.ts.map +1 -1
  599. package/dist/src/runtime/emit/view-mutation.js +6 -3
  600. package/dist/src/runtime/emit/view-mutation.js.map +1 -1
  601. package/dist/src/runtime/emit/window.d.ts.map +1 -1
  602. package/dist/src/runtime/emit/window.js +26 -9
  603. package/dist/src/runtime/emit/window.js.map +1 -1
  604. package/dist/src/runtime/emitters.d.ts +11 -3
  605. package/dist/src/runtime/emitters.d.ts.map +1 -1
  606. package/dist/src/runtime/emitters.js +13 -22
  607. package/dist/src/runtime/emitters.js.map +1 -1
  608. package/dist/src/runtime/foreign-key-actions.d.ts.map +1 -1
  609. package/dist/src/runtime/foreign-key-actions.js +39 -13
  610. package/dist/src/runtime/foreign-key-actions.js.map +1 -1
  611. package/dist/src/runtime/parallel-driver.d.ts +32 -4
  612. package/dist/src/runtime/parallel-driver.d.ts.map +1 -1
  613. package/dist/src/runtime/parallel-driver.js +88 -18
  614. package/dist/src/runtime/parallel-driver.js.map +1 -1
  615. package/dist/src/runtime/scheduler.d.ts +56 -7
  616. package/dist/src/runtime/scheduler.d.ts.map +1 -1
  617. package/dist/src/runtime/scheduler.js +223 -200
  618. package/dist/src/runtime/scheduler.js.map +1 -1
  619. package/dist/src/runtime/strict-flags.d.ts +22 -0
  620. package/dist/src/runtime/strict-flags.d.ts.map +1 -0
  621. package/dist/src/runtime/strict-flags.js +26 -0
  622. package/dist/src/runtime/strict-flags.js.map +1 -0
  623. package/dist/src/runtime/strict-fork.d.ts +4 -4
  624. package/dist/src/runtime/strict-fork.d.ts.map +1 -1
  625. package/dist/src/runtime/strict-fork.js +175 -31
  626. package/dist/src/runtime/strict-fork.js.map +1 -1
  627. package/dist/src/runtime/types.d.ts +102 -4
  628. package/dist/src/runtime/types.d.ts.map +1 -1
  629. package/dist/src/runtime/types.js +37 -0
  630. package/dist/src/runtime/types.js.map +1 -1
  631. package/dist/src/runtime/utils.d.ts.map +1 -1
  632. package/dist/src/runtime/utils.js +8 -17
  633. package/dist/src/runtime/utils.js.map +1 -1
  634. package/dist/src/schema/column.d.ts +8 -0
  635. package/dist/src/schema/column.d.ts.map +1 -1
  636. package/dist/src/schema/column.js.map +1 -1
  637. package/dist/src/schema/ddl-generator.js +5 -0
  638. package/dist/src/schema/ddl-generator.js.map +1 -1
  639. package/dist/src/schema/function.d.ts +79 -0
  640. package/dist/src/schema/function.d.ts.map +1 -1
  641. package/dist/src/schema/function.js.map +1 -1
  642. package/dist/src/schema/lens-compiler.js +2 -2
  643. package/dist/src/schema/lens-compiler.js.map +1 -1
  644. package/dist/src/schema/lens-prover.d.ts.map +1 -1
  645. package/dist/src/schema/lens-prover.js +2 -3
  646. package/dist/src/schema/lens-prover.js.map +1 -1
  647. package/dist/src/schema/lens.d.ts +1 -1
  648. package/dist/src/schema/manager.d.ts.map +1 -1
  649. package/dist/src/schema/manager.js +7 -2
  650. package/dist/src/schema/manager.js.map +1 -1
  651. package/dist/src/schema/rename-rewriter.d.ts +61 -0
  652. package/dist/src/schema/rename-rewriter.d.ts.map +1 -1
  653. package/dist/src/schema/rename-rewriter.js +77 -0
  654. package/dist/src/schema/rename-rewriter.js.map +1 -1
  655. package/dist/src/schema/table.d.ts +36 -8
  656. package/dist/src/schema/table.d.ts.map +1 -1
  657. package/dist/src/schema/table.js +61 -11
  658. package/dist/src/schema/table.js.map +1 -1
  659. package/dist/src/schema/unique-enforcement.d.ts +28 -5
  660. package/dist/src/schema/unique-enforcement.d.ts.map +1 -1
  661. package/dist/src/schema/unique-enforcement.js +37 -5
  662. package/dist/src/schema/unique-enforcement.js.map +1 -1
  663. package/dist/src/schema/view.d.ts +1 -1
  664. package/dist/src/schema/view.js +1 -1
  665. package/dist/src/types/json-type.d.ts.map +1 -1
  666. package/dist/src/types/json-type.js +18 -8
  667. package/dist/src/types/json-type.js.map +1 -1
  668. package/dist/src/types/logical-type.d.ts +26 -0
  669. package/dist/src/types/logical-type.d.ts.map +1 -1
  670. package/dist/src/types/logical-type.js.map +1 -1
  671. package/dist/src/util/comparison.d.ts +83 -59
  672. package/dist/src/util/comparison.d.ts.map +1 -1
  673. package/dist/src/util/comparison.js +191 -131
  674. package/dist/src/util/comparison.js.map +1 -1
  675. package/dist/src/util/json-canonical.d.ts +34 -0
  676. package/dist/src/util/json-canonical.d.ts.map +1 -0
  677. package/dist/src/util/json-canonical.js +32 -0
  678. package/dist/src/util/json-canonical.js.map +1 -0
  679. package/dist/src/util/key-serializer.d.ts +10 -3
  680. package/dist/src/util/key-serializer.d.ts.map +1 -1
  681. package/dist/src/util/key-serializer.js +43 -17
  682. package/dist/src/util/key-serializer.js.map +1 -1
  683. package/dist/src/util/key-tuple-codec.d.ts +37 -0
  684. package/dist/src/util/key-tuple-codec.d.ts.map +1 -0
  685. package/dist/src/util/key-tuple-codec.js +65 -0
  686. package/dist/src/util/key-tuple-codec.js.map +1 -0
  687. package/dist/src/util/latches.d.ts +29 -3
  688. package/dist/src/util/latches.d.ts.map +1 -1
  689. package/dist/src/util/latches.js +60 -6
  690. package/dist/src/util/latches.js.map +1 -1
  691. package/dist/src/util/patterns.d.ts +22 -8
  692. package/dist/src/util/patterns.d.ts.map +1 -1
  693. package/dist/src/util/patterns.js +87 -16
  694. package/dist/src/util/patterns.js.map +1 -1
  695. package/dist/src/util/qualified-name.d.ts +10 -0
  696. package/dist/src/util/qualified-name.d.ts.map +1 -0
  697. package/dist/src/util/qualified-name.js +15 -0
  698. package/dist/src/util/qualified-name.js.map +1 -0
  699. package/dist/src/vtab/backing-host.d.ts +8 -1
  700. package/dist/src/vtab/backing-host.d.ts.map +1 -1
  701. package/dist/src/vtab/backing-host.js +7 -0
  702. package/dist/src/vtab/backing-host.js.map +1 -1
  703. package/dist/src/vtab/best-access-plan.d.ts +18 -0
  704. package/dist/src/vtab/best-access-plan.d.ts.map +1 -1
  705. package/dist/src/vtab/best-access-plan.js +15 -0
  706. package/dist/src/vtab/best-access-plan.js.map +1 -1
  707. package/dist/src/vtab/capabilities.d.ts +44 -0
  708. package/dist/src/vtab/capabilities.d.ts.map +1 -1
  709. package/dist/src/vtab/filter-info.d.ts +42 -0
  710. package/dist/src/vtab/filter-info.d.ts.map +1 -1
  711. package/dist/src/vtab/filter-info.js +137 -1
  712. package/dist/src/vtab/filter-info.js.map +1 -1
  713. package/dist/src/vtab/idx-str.d.ts +62 -0
  714. package/dist/src/vtab/idx-str.d.ts.map +1 -0
  715. package/dist/src/vtab/idx-str.js +130 -0
  716. package/dist/src/vtab/idx-str.js.map +1 -0
  717. package/dist/src/vtab/index-descriptor.d.ts +122 -0
  718. package/dist/src/vtab/index-descriptor.d.ts.map +1 -0
  719. package/dist/src/vtab/index-descriptor.js +104 -0
  720. package/dist/src/vtab/index-descriptor.js.map +1 -0
  721. package/dist/src/vtab/mapping-advertisement.d.ts +1 -1
  722. package/dist/src/vtab/memory/index.d.ts +12 -4
  723. package/dist/src/vtab/memory/index.d.ts.map +1 -1
  724. package/dist/src/vtab/memory/index.js +17 -9
  725. package/dist/src/vtab/memory/index.js.map +1 -1
  726. package/dist/src/vtab/memory/layer/base.d.ts +85 -31
  727. package/dist/src/vtab/memory/layer/base.d.ts.map +1 -1
  728. package/dist/src/vtab/memory/layer/base.js +127 -86
  729. package/dist/src/vtab/memory/layer/base.js.map +1 -1
  730. package/dist/src/vtab/memory/layer/connection.d.ts +27 -0
  731. package/dist/src/vtab/memory/layer/connection.d.ts.map +1 -1
  732. package/dist/src/vtab/memory/layer/connection.js +36 -1
  733. package/dist/src/vtab/memory/layer/connection.js.map +1 -1
  734. package/dist/src/vtab/memory/layer/interface.d.ts +24 -4
  735. package/dist/src/vtab/memory/layer/interface.d.ts.map +1 -1
  736. package/dist/src/vtab/memory/layer/manager.d.ts +212 -16
  737. package/dist/src/vtab/memory/layer/manager.d.ts.map +1 -1
  738. package/dist/src/vtab/memory/layer/manager.js +754 -170
  739. package/dist/src/vtab/memory/layer/manager.js.map +1 -1
  740. package/dist/src/vtab/memory/layer/plan-filter.d.ts +26 -1
  741. package/dist/src/vtab/memory/layer/plan-filter.d.ts.map +1 -1
  742. package/dist/src/vtab/memory/layer/plan-filter.js +29 -11
  743. package/dist/src/vtab/memory/layer/plan-filter.js.map +1 -1
  744. package/dist/src/vtab/memory/layer/safe-iterate.d.ts +2 -2
  745. package/dist/src/vtab/memory/layer/safe-iterate.d.ts.map +1 -1
  746. package/dist/src/vtab/memory/layer/safe-iterate.js +2 -2
  747. package/dist/src/vtab/memory/layer/safe-iterate.js.map +1 -1
  748. package/dist/src/vtab/memory/layer/scan-layer.d.ts +5 -1
  749. package/dist/src/vtab/memory/layer/scan-layer.d.ts.map +1 -1
  750. package/dist/src/vtab/memory/layer/scan-layer.js +59 -24
  751. package/dist/src/vtab/memory/layer/scan-layer.js.map +1 -1
  752. package/dist/src/vtab/memory/layer/scan-plan.d.ts.map +1 -1
  753. package/dist/src/vtab/memory/layer/scan-plan.js +13 -21
  754. package/dist/src/vtab/memory/layer/scan-plan.js.map +1 -1
  755. package/dist/src/vtab/memory/layer/transaction.d.ts +169 -7
  756. package/dist/src/vtab/memory/layer/transaction.d.ts.map +1 -1
  757. package/dist/src/vtab/memory/layer/transaction.js +334 -9
  758. package/dist/src/vtab/memory/layer/transaction.js.map +1 -1
  759. package/dist/src/vtab/memory/module.d.ts +11 -4
  760. package/dist/src/vtab/memory/module.d.ts.map +1 -1
  761. package/dist/src/vtab/memory/module.js +35 -16
  762. package/dist/src/vtab/memory/module.js.map +1 -1
  763. package/dist/src/vtab/memory/table.d.ts +30 -4
  764. package/dist/src/vtab/memory/table.d.ts.map +1 -1
  765. package/dist/src/vtab/memory/table.js +63 -15
  766. package/dist/src/vtab/memory/table.js.map +1 -1
  767. package/dist/src/vtab/memory/utils/predicate.d.ts +9 -1
  768. package/dist/src/vtab/memory/utils/predicate.d.ts.map +1 -1
  769. package/dist/src/vtab/memory/utils/predicate.js +35 -14
  770. package/dist/src/vtab/memory/utils/predicate.js.map +1 -1
  771. package/dist/src/vtab/memory/utils/primary-key-encode.d.ts.map +1 -1
  772. package/dist/src/vtab/memory/utils/primary-key-encode.js +12 -6
  773. package/dist/src/vtab/memory/utils/primary-key-encode.js.map +1 -1
  774. package/dist/src/vtab/memory/utils/primary-key.d.ts +6 -1
  775. package/dist/src/vtab/memory/utils/primary-key.d.ts.map +1 -1
  776. package/dist/src/vtab/memory/utils/primary-key.js +12 -8
  777. package/dist/src/vtab/memory/utils/primary-key.js.map +1 -1
  778. package/dist/src/vtab/module.d.ts +38 -14
  779. package/dist/src/vtab/module.d.ts.map +1 -1
  780. package/dist/src/vtab/table.d.ts +41 -2
  781. package/dist/src/vtab/table.d.ts.map +1 -1
  782. package/dist/src/vtab/table.js +19 -0
  783. package/dist/src/vtab/table.js.map +1 -1
  784. package/package.json +5 -4
  785. package/dist/src/planner/rules/cache/rule-materialization-advisory.d.ts +0 -18
  786. package/dist/src/planner/rules/cache/rule-materialization-advisory.d.ts.map +0 -1
  787. package/dist/src/planner/rules/cache/rule-materialization-advisory.js +0 -65
  788. package/dist/src/planner/rules/cache/rule-materialization-advisory.js.map +0 -1
@@ -0,0 +1,641 @@
1
+ /**
2
+ * Materialized-view maintenance — plan types and the manager's decoupling context.
3
+ *
4
+ * The tagged {@link MaintenancePlan} union (one arm per maintenance strategy) plus the
5
+ * shared plan shapes, the per-column {@link BackingProjector}, the coarsening-collision
6
+ * watch column, the per-statement {@link BackingConnectionCache}, and the
7
+ * {@link MaterializedViewManagerContext} the manager runs against. Split out of
8
+ * `database-materialized-views.ts` (its class + orchestration) so the type surface reads
9
+ * on its own; see that file and `docs/mv-maintenance.md` for how each arm is built and
10
+ * applied.
11
+ */
12
+ import type { SchemaManager } from '../schema/manager.js';
13
+ import type { SqlValue, Row } from '../common/types.js';
14
+ import type { CollationFunction, CollationResolver } from '../types/logical-type.js';
15
+ import type { PrimaryKeyColumnDefinition } from '../schema/table.js';
16
+ import type { BTreeKeyForPrimary } from '../vtab/memory/types.js';
17
+ import { Scheduler } from '../runtime/scheduler.js';
18
+ import type { BindingMode } from '../planner/analysis/binding-extractor.js';
19
+ import type { MaintenanceSourceStats, MaintenanceStrategy } from '../planner/cost/index.js';
20
+ import type { AggregateAlgebra, AggregateFunctionSchema } from '../schema/function.js';
21
+ import type { AggValue } from '../func/registration.js';
22
+ import type { DerivedRowConstraintValidator } from './derived-row-validator.js';
23
+ import type { MaintainedTableSchema } from '../schema/derivation.js';
24
+ import type { VirtualTableConnection } from '../vtab/connection.js';
25
+ import type { CompiledPredicate } from '../vtab/memory/utils/predicate.js';
26
+ import type { Database } from './database.js';
27
+ import type { DatabaseEventEmitter } from './database-events.js';
28
+ import type * as AST from '../parser/ast.js';
29
+ /**
30
+ * Database internals the materialized-view manager needs. Mirrors
31
+ * `AssertionEvaluatorContext` / `WatcherManagerContext` — keeps the manager
32
+ * decoupled from the full `Database`.
33
+ */
34
+ export interface MaterializedViewManagerContext {
35
+ readonly schemaManager: SchemaManager;
36
+ readonly optimizer: Database['optimizer'];
37
+ /** Database event emitter — the row-time collision telemetry channel
38
+ * ({@link MaterializedViewManager.detectAndReportCoarseningCollisions}) queues
39
+ * {@link MaintenanceCollisionEvent}s here. Already exposed for the transaction
40
+ * manager; reused narrowly. */
41
+ getEventEmitter(): DatabaseEventEmitter;
42
+ /** Name→function collation lookup against the owning database's registry (throws on an
43
+ * unregistered name). Every collation-aware comparison the manager makes — key identity,
44
+ * UNIQUE self-conflict, coarsening-collision divergence — resolves through this, so a
45
+ * collation registered with `db.registerCollation(...)` is honored instead of silently
46
+ * degrading to byte comparison. */
47
+ getCollationResolver(): CollationResolver;
48
+ _buildPlan(statements: AST.Statement[]): import('./database.js').BuildPlanResult;
49
+ _findTable(tableName: string, schemaName?: string): ReturnType<Database['_findTable']>;
50
+ /** Backing-connection resolution for row-time write-through (see {@link MaterializedViewManager.getBackingConnection}). */
51
+ getConnectionsForTable(tableName: string): VirtualTableConnection[];
52
+ registerConnection(connection: VirtualTableConnection): Promise<void>;
53
+ }
54
+ /**
55
+ * A compiled per-MV maintenance plan — how {@link MaterializedViewManager.applyMaintenancePlan}
56
+ * keeps an MV's backing table consistent with a source row-write. A tagged union over
57
+ * the maintenance strategies the incremental substrate names (the spike's
58
+ * `incremental-maintenance-substrate-spike` design). The builder
59
+ * ({@link MaterializedViewManager.buildMaintenancePlan}) produces four bounded-delta arms:
60
+ * `'inverse-projection'` (the covering-index shape), `'residual-recompute'` (single-source
61
+ * aggregates), `'prefix-delete'` (single-source lateral-TVF fan-out), and `'join-residual'`
62
+ * (the provably-1:1 inner join). Only `'inverse-projection'` is applied **per source row,
63
+ * immediately** — its backing is read mid-statement by covering-UNIQUE enforcement, and its
64
+ * delta is a cheap pure projection. The three **residual** arms accumulate their affected
65
+ * binding keys into the per-statement {@link ResidualKeyBatch} (deduped across the
66
+ * statement's changes) and recompute once per distinct key at the end-of-statement flush.
67
+ * The `'full-rebuild'` floor (the always-correct convergence point for bodies no
68
+ * bounded-delta arm fits) is likewise deferred — marked dirty per row and rebuilt once per
69
+ * statement. Both deferred kinds drain at
70
+ * {@link MaterializedViewManager.flushDeferredMaintenance}.
71
+ */
72
+ export type MaintenancePlan = InverseProjectionPlan | FullRebuildPlan | ResidualRecomputePlan | PrefixDeletePlan | JoinResidualPlan;
73
+ /**
74
+ * One backing primary-key column as a {@link MaintenancePlan} sees it: the btree's declared
75
+ * `(index, direction, collation-name)` triple plus the collation *function* the name resolves
76
+ * to, resolved once when the plan is built (`resolveBackingPkColumns`).
77
+ *
78
+ * The name stays for logging and plan equality; the function is what the per-row key
79
+ * comparisons in `database-materialized-views-apply.ts` call, so they never pay a registry
80
+ * lookup — nor silently fall back to byte comparison — per row.
81
+ */
82
+ export interface BackingPkColumn extends PrimaryKeyColumnDefinition {
83
+ /** Resolved comparator for {@link collation}; BINARY when the column declares no COLLATE. */
84
+ readonly collationFn: CollationFunction;
85
+ }
86
+ /**
87
+ * The three **residual** (key-filtered recompute) arms — every {@link MaintenancePlan}
88
+ * kind except `'inverse-projection'` and `'full-rebuild'`. These are the arms the
89
+ * per-statement {@link ResidualKeyBatch} defers: their affected binding keys accumulate
90
+ * (deduped) during the statement's row loop and each distinct key's residual runs once
91
+ * at the end-of-statement flush ({@link MaterializedViewManager.flushDeferredMaintenance}).
92
+ */
93
+ export type ResidualMaintenancePlan = ResidualRecomputePlan | PrefixDeletePlan | JoinResidualPlan;
94
+ /**
95
+ * Fields shared by the three residual arms. `fullRebuildScheduler` is the per-statement
96
+ * **degrade-to-rebuild escape**: when the statement's distinct affected-key count makes
97
+ * k residual runs cost more than one whole-body rebuild (`shouldDegradeToRebuild` against
98
+ * {@link MaintenancePlanCommon.sourceStats}), the flush runs this scheduler to completion
99
+ * and applies a single `'replace-all'` diff instead — the stored `chosenStrategy` is
100
+ * unchanged, so a later low-cardinality statement naturally reverts to per-key residuals.
101
+ * Compiled once at registration ({@link buildMaintenancePlan}) exactly like the floor's
102
+ * own `bodyScheduler`; optional defensively (an absent scheduler just skips the demotion).
103
+ */
104
+ export interface ResidualArmCommon {
105
+ fullRebuildScheduler?: Scheduler;
106
+ }
107
+ /**
108
+ * Structural subset of the fields the forward (driving-source) residual-recompute
109
+ * apply path reads — shared by the aggregate {@link ResidualRecomputePlan} and the
110
+ * 1:1-join {@link JoinResidualPlan} so both drive {@link applyForwardResidual}
111
+ * unchanged. For an aggregate the forward key is the group key (`'gk'`); for a join
112
+ * it is the driving table `T`'s PK (`'pk'`).
113
+ */
114
+ export interface ForwardResidualPlan {
115
+ mv: MaintainedTableSchema;
116
+ backingSchema: string;
117
+ backingTableName: string;
118
+ /** Cached scheduler for the key-filtered residual (the body with `injectKeyFilter`
119
+ * applied on the driving source). Re-run per affected key, bound through the live txn. */
120
+ residualScheduler: Scheduler;
121
+ bindParamPrefix: 'gk' | 'pk';
122
+ /** Source-column indices of the forward binding key (group columns / `T`'s PK columns). */
123
+ bindColumns: number[];
124
+ backingPkDefinition: ReadonlyArray<BackingPkColumn>;
125
+ backingPkSourceCols: number[];
126
+ }
127
+ /**
128
+ * How a single backing output column is derived from the changed source row — a pure
129
+ * per-row (per-statement) function. `'passthrough'` copies a source column (the column
130
+ * permutation that *every* PK / UNIQUE-covered column must use, so the backing key and
131
+ * the inverse-projection conflict map are recoverable); `'expr'` evaluates a
132
+ * deterministic scalar expression over the source row (a non-key derived column —
133
+ * `materialized-view-rowtime-expression-projections`). `eval` is the runtime-compiled
134
+ * evaluator (see {@link compileSourceRowEvaluator}), so a computed backing value is
135
+ * exactly what `select <body>` would produce.
136
+ */
137
+ export type BackingProjector = {
138
+ readonly kind: 'passthrough';
139
+ readonly sourceCol: number;
140
+ } | {
141
+ readonly kind: 'expr';
142
+ readonly eval: (sourceRow: Row) => SqlValue;
143
+ };
144
+ /**
145
+ * One **weakened** column of a coarsened backing key K′, precomputed once at
146
+ * registration for the row-time collision telemetry
147
+ * ({@link MaterializedViewManager.detectAndReportCoarseningCollisions}). Carries the
148
+ * backing column index to read from each {@link BackingRowChange} image, the
149
+ * **source** (pre-coarsening, stricter) collation the divergence test compares
150
+ * under, the **output** (coarsened) collation the backing key enforces, and the
151
+ * column name for the {@link MaintenanceCollisionEvent} payload. Derived from
152
+ * `mv.derivation.coarsenedKey.weakened` (column names) via `mv.columnIndexMap`.
153
+ */
154
+ export interface CoarseningWatchColumn {
155
+ /** Backing column index (= body output column index) the weakened K′ column lands at. */
156
+ readonly index: number;
157
+ /** Source key enforcement collation (pre-coarsening); the divergence test compares under it. */
158
+ readonly sourceCollation: string;
159
+ /** {@link sourceCollation} resolved against the database registry, once at registration. */
160
+ readonly sourceCollationFn: CollationFunction;
161
+ /** Output (coarsened) collation the backing key enforces. */
162
+ readonly outputCollation: string;
163
+ /** Backing/output column name (for the event payload's `weakenedColumns`). */
164
+ readonly column: string;
165
+ }
166
+ /**
167
+ * Common identity + cost-gate fields shared by every {@link MaintenancePlan} arm.
168
+ * `chosenStrategy` / `sourceStats` are set once by the create-time cost gate
169
+ * ({@link buildMaintenancePlan}, via `selectMaintenanceStrategy`) and are not
170
+ * re-evaluated per write, except for the per-statement residual → rebuild demotion
171
+ * (`shouldDegradeToRebuild` against the statement's actual distinct-key count, at
172
+ * the end-of-statement flush).
173
+ */
174
+ export interface MaintenancePlanCommon {
175
+ /** The MV this plan maintains. */
176
+ mv: MaintainedTableSchema;
177
+ /** Lowercased `schema.table` of the single source `T`. */
178
+ sourceBase: string;
179
+ backingSchema: string;
180
+ backingTableName: string;
181
+ /** Strategy the cost gate chose: argmin `maintenanceCost` over the body's sound strategies. */
182
+ chosenStrategy: MaintenanceStrategy;
183
+ /** Create-time cost inputs (StatsProvider + forward optimizer), retained so the DML
184
+ * boundary can re-cost residual vs. rebuild against the actual changeCardinality. */
185
+ sourceStats: MaintenanceSourceStats;
186
+ /** Compiled declared-CHECK/FK validator over derived row images — present ONLY
187
+ * when the maintained table declares ≥1 applicable CHECK or ≥1 FK (the
188
+ * zero-overhead gate: MV-sugar backings and constraint-less maintained tables
189
+ * carry `undefined` and pay nothing per write). Built once at registration
190
+ * ({@link MaterializedViewManager.registerMaterializedView}); applied to each
191
+ * insert/update {@link BackingRowChange} before the cascade. */
192
+ derivedRowValidator?: DerivedRowConstraintValidator;
193
+ /** Precomputed weakened-K′-column watch list for row-time collision telemetry —
194
+ * present ONLY when `mv.derivation.coarsenedKey` is stamped (the zero-overhead
195
+ * gate: a provable-key / refining-lineage-key MV carries `undefined` and pays
196
+ * nothing per write — detection short-circuits on this field). Built once at
197
+ * registration ({@link MaterializedViewManager.registerMaterializedView} →
198
+ * {@link MaterializedViewManager.buildCoarseningWatch}); read by
199
+ * {@link MaterializedViewManager.detectAndReportCoarseningCollisions} from both
200
+ * the bounded-delta and full-rebuild maintenance arms. */
201
+ coarseningWatch?: ReadonlyArray<CoarseningWatchColumn>;
202
+ /** Backing columns that are BOTH declared NOT NULL AND physical-PK members AND whose
203
+ * re-derived body output column is nullable — the exact reachable "NOT-NULL
204
+ * ordering-seeded PK over a loosened source" skew. Present ONLY when non-empty (the
205
+ * zero-overhead gate: nearly every MV carries `undefined` and pays a single boolean
206
+ * check per maintained write — the NOT-NULL/physical-PK set alone is non-empty for
207
+ * almost every MV, so the discriminator is the body-nullability term). Precomputed once
208
+ * at plan build ({@link MaterializedViewManager.buildMaintenancePlan}). Read by the
209
+ * row-time guard in {@link MaterializedViewManager.maintainRowTime} /
210
+ * {@link MaterializedViewManager.flushDeferredMaintenance}. The refresh path has its own
211
+ * materialized-row equivalent (`assertNoNullInNotNullSeededPk` in
212
+ * runtime/emit/materialized-view-helpers.ts). See
213
+ * fix/bug-mv-rowtime-null-into-notnull-seeded-pk. */
214
+ nullGuardColumns?: ReadonlyArray<{
215
+ readonly index: number;
216
+ readonly name: string;
217
+ }>;
218
+ }
219
+ export interface InverseProjectionPlan extends MaintenancePlanCommon {
220
+ readonly kind: 'inverse-projection';
221
+ /** Backing-table physical primary-key definition (the column order the btree keys on). */
222
+ backingPkDefinition: ReadonlyArray<BackingPkColumn>;
223
+ /** `projectors[j]` derives backing output column `j` from the changed source row —
224
+ * either a passthrough copy of a source column or a deterministic scalar expression
225
+ * over the source row. Every PK / backing-key column is `'passthrough'` (eligibility
226
+ * rejects a computed column that lands in the backing key); non-key columns may be
227
+ * `'expr'`. {@link MaterializedViewManager.lookupCoveringConflicts} reads only the
228
+ * passthrough projectors for its inverse (source↔backing) map. */
229
+ projectors: BackingProjector[];
230
+ /** Partial-WHERE predicate evaluated on a single source row; absent ⇒ every row
231
+ * is in scope. A source row contributes a backing row only when this is
232
+ * unambiguously TRUE (mirrors partial-UNIQUE / partial-index semantics). */
233
+ predicate?: CompiledPredicate;
234
+ }
235
+ /**
236
+ * The always-correct **floor**: a body for which no bounded-delta arm is sound is
237
+ * maintained by re-evaluating it in full per writing statement and replacing the backing
238
+ * transactionally (a single `'replace-all'` {@link MaintenanceOp} — a keyed diff against
239
+ * the backing's pending layer, so the delta still commits/rolls-back with the source
240
+ * write and still drives the MV-over-MV cascade). The whole optimized body is compiled
241
+ * once at registration into {@link bodyScheduler}; {@link MaterializedViewManager.applyFullRebuild}
242
+ * runs it to completion against live source state and diffs the result into the backing.
243
+ *
244
+ * Reachability: `buildMaintenancePlan` routes a body here whenever no bounded-delta arm
245
+ * fits ({@link MaterializedViewManager.tryBuildBoundedDeltaArm} returns `null`). It is the
246
+ * one **deferred** arm — marked dirty per source row and rebuilt exactly once at the
247
+ * end-of-statement flush ({@link MaterializedViewManager.flushDeferredMaintenance}), so a bulk
248
+ * write is O(body) not O(rows × body). See `docs/mv-maintenance.md` § Full-rebuild floor.
249
+ */
250
+ export interface FullRebuildPlan extends MaintenancePlanCommon {
251
+ readonly kind: 'full-rebuild';
252
+ /** The optimized body compiled once at registration — the **whole** body (no
253
+ * `injectKeyFilter`), with the read-side MV rewrite suppressed so it reads its sources,
254
+ * not the backing it populates. Re-run to completion per writing statement, bound
255
+ * through the live transaction (reads-own-writes), to recompute every backing row. */
256
+ bodyScheduler: Scheduler;
257
+ /** Every source base (lowercased `schema.table`) the body reads — set-op legs, every
258
+ * join source, etc. The plan is indexed under each in `rowTimeBySource` (via
259
+ * {@link planSourceBases}), so a write to **any** of them triggers a rebuild; missing
260
+ * one would leave the MV stale on that source's writes. `sourceBase` (the
261
+ * {@link MaintenancePlanCommon} field) holds the first of these for parity. */
262
+ sourceBases: string[];
263
+ }
264
+ /**
265
+ * The general-body residual-recompute arm: per source change, derive the affected
266
+ * binding key(s) from the changed row, run a key-filtered residual of the body against
267
+ * **live mid-transaction source state**, and apply the keyed diff — upsert the recomputed
268
+ * slice (replacing the old row at the same backing key; a value-identical recompute is
269
+ * suppressed by the host, see vtab/backing-host.ts) or, when the residual returns
270
+ * nothing, delete the emptied key. Wired for the **single-source aggregate** shape
271
+ * (`select g1,… , agg(…) from T [where P] group by g1,…` over bare group columns) by
272
+ * `materialized-view-rowtime-residual-recompute`; the 1:1 row-preserving join shape
273
+ * (`'row'` binding) reuses the same kernel in a follow-on ticket.
274
+ *
275
+ * The residual is the body with a key-equality filter injected on `T`'s
276
+ * `TableReferenceNode` via {@link injectKeyFilter} (parameterized `gk0…` for a group
277
+ * binding, `pk0…` for a row binding), compiled + cached once at registration and run
278
+ * synchronously through the live transaction so the source read is reads-own-writes —
279
+ * the synchronous analogue of `database-assertions.ts`'s residual path.
280
+ *
281
+ * It carries the {@link BindingMode} the spike names as the convergence point (built
282
+ * directly from the body's shape — for an aggregate, the bare GROUP BY columns; NOT
283
+ * via `extractBindings`, whose `'group'` classification additionally requires the group
284
+ * key to cover a source unique key and so reports `'global'` for the common
285
+ * `group by <non-key>` body). The per-statement rebuild demotion rides
286
+ * {@link ResidualArmCommon.fullRebuildScheduler}.
287
+ */
288
+ export interface ResidualRecomputePlan extends MaintenancePlanCommon, ResidualArmCommon {
289
+ readonly kind: 'residual-recompute';
290
+ binding: BindingMode;
291
+ /** Delta-aggregate fast path descriptor — present iff EVERY stored aggregate column
292
+ * passed the create-time delta eligibility gate ({@link buildDeltaAggregateDescriptor}
293
+ * in database-materialized-views-plan-builders.ts). When present, the statement
294
+ * accumulation folds per-column accumulator deltas alongside the residual keys and
295
+ * the flush maintains each affected group by pure arithmetic on the stored backing
296
+ * row (`merge` on insert, `merge(negate(…))` on delete) with zero source reads —
297
+ * falling back to the residual per group only where the declared algebra cannot
298
+ * prove a retraction observational (see {@link DeltaAggregateColumn.retractionSafe}).
299
+ * Absent ⇒ the arm behaves exactly as before (key-filtered residual re-execution).
300
+ * The plan `kind` stays `'residual-recompute'` either way; `chosenStrategy` records
301
+ * `'delta-aggregate'` when the descriptor is active (cost-strategy decoupling, the
302
+ * same pattern as `'prefix-delete'`). */
303
+ delta?: DeltaAggregateDescriptor;
304
+ /** Cached scheduler for the key-filtered residual (the body with `injectKeyFilter`
305
+ * applied on `T`). Re-run per affected key tuple, bound through the live transaction. */
306
+ residualScheduler: Scheduler;
307
+ /** Bind-parameter prefix the residual was compiled with: `'gk'` (group) / `'pk'` (row). */
308
+ bindParamPrefix: 'gk' | 'pk';
309
+ /** Source-column indices of the binding key (group columns / row key columns). The
310
+ * affected key tuple is `bindColumns.map(c => changedRow[c])`, bound to `${prefix}{i}`. */
311
+ bindColumns: number[];
312
+ /** Backing-table physical primary-key definition (the column order the btree keys on). */
313
+ backingPkDefinition: ReadonlyArray<BackingPkColumn>;
314
+ /** Source column projected (passthrough) into each backing-PK column, in
315
+ * `backingPkDefinition` order. The old backing slice's delete key for a changed row
316
+ * `R` is `buildPrimaryKeyFromValues(backingPkSourceCols.map(sc => R[sc]), backingPkDefinition)`. */
317
+ backingPkSourceCols: number[];
318
+ }
319
+ /**
320
+ * The single-source lateral-TVF fan-out arm: a body of the shape
321
+ * `select T.pk…, …, f.* from T cross join lateral tvf(<args over T>) f`, where each base
322
+ * row of `T` fans out to **N** backing rows (one per row the TVF emits for it). The
323
+ * backing PK is the **composite product key** `(T.pk ∪ tvf-key)` that
324
+ * `optimizer-keyed-cross-product-join-keys` advertises through `keysOf` over the lateral
325
+ * join, with the base PK as its **leading prefix** (asserted at build).
326
+ *
327
+ * Per changed base row, maintenance is a **keyed diff of the recomputed fan-out against
328
+ * the existing effective slice for the base-PK prefix** (read via the host's
329
+ * `scanEffective`, since one base row owns many backing rows sharing the prefix): re-run
330
+ * the TVF fan-out **residual** for that base row, delete only the existing keys the
331
+ * recompute no longer produces, and **upsert** each recomputed row (value-identical
332
+ * upserts are suppressed by the host). An UPDATE diffs both the OLD and NEW base keys
333
+ * (the base PK may move); a DELETE diffs the old slice to all-deletes; an INSERT diffs
334
+ * against an empty slice. This reuses the residual kernel of {@link ResidualRecomputePlan}
335
+ * unchanged — the affected-key derivation, the `injectKeyFilter` residual (pinned to the
336
+ * base `TableReferenceNode` with the `'pk'` prefix), reads-own-writes execution, the cost
337
+ * gate — and differs only in the **prefix-slice** diff (vs point-key) and the **N-row**
338
+ * residual (vs ≤1). The body's WHERE, if any, is part of the residual (so an out-of-scope
339
+ * base row fans out to zero rows), exactly as in the aggregate arm.
340
+ *
341
+ * `chosenStrategy` is `'residual-recompute'` (the shared key-filtered re-execution cost
342
+ * shape — the fan-out factor is unknown at create); `kind` is `'prefix-delete'` (the
343
+ * apply-arm dispatcher).
344
+ */
345
+ export interface PrefixDeletePlan extends MaintenancePlanCommon, ResidualArmCommon {
346
+ readonly kind: 'prefix-delete';
347
+ /** Substrate parity (the base-PK 'row' binding); unread by the apply path, which uses
348
+ * `bindColumns` / `backingPrefixSourceCols`. */
349
+ binding: BindingMode;
350
+ /** Cached scheduler for the base-PK-keyed residual (the body with `injectKeyFilter`
351
+ * applied on `T`, `'pk'` prefix). Re-run per affected base key; fans out to N rows. */
352
+ residualScheduler: Scheduler;
353
+ bindParamPrefix: 'pk';
354
+ /** Source-`T` PK column indices (the base key). The affected key tuple is
355
+ * `bindColumns.map(c => changedRow[c])`, bound to `pk{i}`. */
356
+ bindColumns: number[];
357
+ /** Full backing-table physical primary key (base-PK prefix ++ TVF-key tail). */
358
+ backingPkDefinition: ReadonlyArray<BackingPkColumn>;
359
+ /** Number of leading backing-PK columns that form the base-PK prefix (= `bindColumns.length`). */
360
+ basePrefixLength: number;
361
+ /** Source-`T` column projected into each leading (base-prefix) backing-PK column, in
362
+ * backing-PK order. The by-prefix delete key for a changed row `R` is
363
+ * `backingPrefixSourceCols.map(sc => R[sc])`. */
364
+ backingPrefixSourceCols: number[];
365
+ }
366
+ /**
367
+ * The 1:1 row-preserving **inner/cross join** arm: a body
368
+ * `select … from T join P on T.fk = P.id` where `T` contributes **exactly one** MV row
369
+ * per governed `T` row (proven by {@link proveOneToOneJoin} — no row loss via NOT-NULL
370
+ * FK→PK referential integrity, no fan-out via `isUnique(T.pk)` at the join frame). The
371
+ * backing is keyed on `T`'s PK (the composite product key `keysOf` advertises across the
372
+ * 1:1 join collapses to `T`'s PK), so each changed `T` row maps to one backing row.
373
+ *
374
+ * Reuses the residual kernel of {@link ResidualRecomputePlan} on its **driving (`T`)**
375
+ * side via {@link ForwardResidualPlan}: a `T`-keyed (`'pk'`) residual recomputes the one
376
+ * joined row for a changed `T` row (run residual → upsert the recomputed row, or delete
377
+ * the key when it returns nothing), identical to a `'row'`-binding aggregate of size 1.
378
+ * `applyForwardResidual` drives it.
379
+ *
380
+ * The **lookup (`P`)** side is the join arm's distinct problem: the MV's `sourceTables`
381
+ * includes `P`, so a write to `P` also fires maintenance, but the forward residual is
382
+ * keyed on `T`'s PK and a `P` row joins *many* `T` rows. This plan therefore carries a
383
+ * **second residual keyed on `P`'s PK** (`lookupResidualScheduler`): for a `P` change it
384
+ * runs `… where P.pk = :pk0` (the body **including** its WHERE) against live state,
385
+ * returning every currently in-scope joined row (each carrying its `T.pk` backing key), and
386
+ * **upserts** each.
387
+ *
388
+ * **WHERE handling — bounded-delta over a partial-WHERE 1:1 join.** A body WHERE is
389
+ * classified at build by which base table(s) its columns reference
390
+ * ({@link MaterializedViewManager.buildJoinResidualPlan}):
391
+ * - **`T`-only predicate** — no extra machinery. The forward (`T`) residual already injects
392
+ * + applies the WHERE (an out-of-scope `T` row recomputes to zero residual rows ⇒ its
393
+ * delete-without-upsert removes the backing row), and a `T`-column predicate cannot move
394
+ * the membership set `{ T : T.fk = P.pk }`, so the lookup side stays **upsert-only**
395
+ * (`lookupMembershipResidualScheduler` absent) — sound for the same reason the no-WHERE
396
+ * arm is.
397
+ * - **`P`-referencing predicate** (or both sides) — a `P` write can flip a row's WHERE truth
398
+ * and so add/remove a backing row, which upsert-only could never delete. The lookup side
399
+ * becomes **delete-capable**: `lookupMembershipResidualScheduler` is the body with
400
+ * `injectKeyFilter` on `P` but the WHERE **stripped** (membership only). Per affected `P`
401
+ * key {@link MaterializedViewManager.applyLookupResidual} diffs it against the in-scope
402
+ * `lookupResidualScheduler` (WHERE retained): membership keys the in-scope recompute no
403
+ * longer produces are deleted, the in-scope rows are upserted — a keyed diff that converges
404
+ * the membership both ways without churning the unchanged rows.
405
+ *
406
+ * Still inner/cross only; outer joins and **fanning** (non-1:1) joins continue to fall to the
407
+ * full-rebuild floor. See `docs/incremental-maintenance.md` § join-residual and the soundness
408
+ * note in {@link MaterializedViewManager.applyLookupResidual}.
409
+ */
410
+ export interface JoinResidualPlan extends MaintenancePlanCommon, ForwardResidualPlan, ResidualArmCommon {
411
+ readonly kind: 'join-residual';
412
+ /** Substrate parity: the driving `T`'s `'row'`/PK binding. */
413
+ binding: BindingMode;
414
+ bindParamPrefix: 'pk';
415
+ /** Lowercased `schema.table` of the lookup source `P` (distinct from `sourceBase` = `T`). */
416
+ lookupBase: string;
417
+ /** Cached scheduler for the in-scope lookup-keyed residual (the body — WHERE **retained** —
418
+ * with `injectKeyFilter` applied on `P`, `'pk'` prefix). Re-run per affected `P` key;
419
+ * returns the currently in-scope joined rows to upsert. */
420
+ lookupResidualScheduler: Scheduler;
421
+ /** Delete-capable lookup membership residual (the body with the WHERE **stripped** and
422
+ * `injectKeyFilter` on `P`). Present **iff** the body WHERE references `P`: the lookup side
423
+ * must then delete the backing key of every currently-referencing `T` row (regardless of
424
+ * scope) before re-upserting the in-scope survivors, so a `P` write that flips a row's WHERE
425
+ * membership adds/removes its backing row. Absent for a no-WHERE or `T`-only-WHERE body
426
+ * (the lookup side is sound upsert-only — membership cannot move on a `P` write). */
427
+ lookupMembershipResidualScheduler?: Scheduler;
428
+ /** Source-`P` PK column indices (the lookup key). The affected key tuple for a `P`
429
+ * change is `lookupBindColumns.map(c => changedRow[c])`, bound to `pk{i}`. */
430
+ lookupBindColumns: number[];
431
+ lookupBindParamPrefix: 'pk';
432
+ }
433
+ /**
434
+ * Per-statement cache of resolved backing {@link VirtualTableConnection}s, keyed by the
435
+ * lowercased backing `schema.table`. Created **once per DML generator run** (one
436
+ * statement) and threaded through the maintenance path so the backing-connection
437
+ * resolution — a scan over *all* the Database's active connections in
438
+ * {@link MaterializedViewManager.getBackingConnection} — is paid once per
439
+ * (statement, backing) instead of once per source row. This amortizes the dominant
440
+ * per-row overhead of a bulk `insert`/`update`/`delete` over a covered table.
441
+ *
442
+ * It is purely a resolution cache: the `'inverse-projection'` arm's per-row ops are still
443
+ * applied **immediately** to the cached connection's pending transaction layer, so a later
444
+ * same-statement row's enforcement scan (`lookupCoveringConflicts`) still observes every
445
+ * earlier row's backing write. The **residual** arms and the **full-rebuild** floor are
446
+ * instead deferred to a single end-of-statement
447
+ * {@link MaterializedViewManager.flushDeferredMaintenance} (tracked in the per-statement
448
+ * {@link ResidualKeyBatch} / dirty set, not this cache) — sound because only an
449
+ * inverse-projection MV can serve as a covering structure, so no enforcement scan depends
450
+ * on a deferred arm's per-row visibility. See `docs/mv-maintenance.md` § Synchronous,
451
+ * transactional, per-statement. Because the cache is scoped to one generator run, the
452
+ * connection it holds cannot be torn down mid-statement; the cold enforcement/eviction
453
+ * paths that omit the cache re-resolve the *same* connection deterministically, so
454
+ * reads-own-writes is unaffected.
455
+ */
456
+ export type BackingConnectionCache = Map<string, VirtualTableConnection>;
457
+ /**
458
+ * One deduped **forward** (driving-source) affected binding key, as
459
+ * `applyForwardResidual` derives it from a changed source row: `keyTuple` binds the
460
+ * key-filtered residual's parameters, `keyVals` are the backing-PK values (in
461
+ * `backingPkDefinition` order) the recomputed slice is matched on, and `deleteKey` is the
462
+ * prebuilt point-delete key for an emptied slice. Deduped on `canonKeyValues(keyVals)`.
463
+ */
464
+ export interface ForwardResidualKey {
465
+ keyTuple: SqlValue[];
466
+ keyVals: SqlValue[];
467
+ deleteKey: BTreeKeyForPrimary;
468
+ }
469
+ /**
470
+ * One deduped affected **base** key of a `'prefix-delete'` fan-out plan: `keyTuple` binds
471
+ * the base-PK-keyed residual, `prefix` is the slice's leading-backing-PK equality key.
472
+ * Deduped on `canonKeyValues(keyTuple)`.
473
+ */
474
+ export interface PrefixDeleteKey {
475
+ keyTuple: SqlValue[];
476
+ prefix: SqlValue[];
477
+ }
478
+ /**
479
+ * One stored aggregate output column of a delta-maintained aggregate MV, resolved once
480
+ * at plan build from the aggregate call node's registry-resolved function schema. The
481
+ * engine consumes ONLY the declared {@link AggregateAlgebra} plus the schema's
482
+ * step/finalize/initialValue — never an aggregate-name list (docs/invariants.md).
483
+ */
484
+ export interface DeltaAggregateColumn {
485
+ /** Backing column index (= body output column index) this aggregate lands at. */
486
+ readonly backingCol: number;
487
+ /** The registry-resolved aggregate schema — carries step/finalize/initialValue. */
488
+ readonly schema: AggregateFunctionSchema;
489
+ /** `schema.algebra`, narrowed: `merge` + `decode` always; `negate` for a `'group'`
490
+ * column (absent for a `'tighten'` column). */
491
+ readonly algebra: AggregateAlgebra;
492
+ /** Delta maintenance class this column belongs to:
493
+ * - `'group'`: an abelian-group aggregate (count/sum — `merge` + `negate` + `decode`).
494
+ * Inserts and deletes both fold arithmetically (`merge` / `merge(negate(…))`).
495
+ * - `'tighten'`: a join-semilattice aggregate (min/max, `bit_or`/`bool_or` — `merge`,
496
+ * `decode`, but **no** `negate`). An insert `merge`s the new value in cheaply
497
+ * (min/max tighten toward the new extreme); a retraction cannot be undone
498
+ * arithmetically, so a retracted group falls back to the residual (its
499
+ * {@link retractionSafe} is always false, and {@link DeltaAggregateDescriptor.hasTighten}
500
+ * routes the whole group to the residual whether or not a row is stored). */
501
+ readonly deltaClass: 'group' | 'tighten';
502
+ /** Source column feeding `step()`; `undefined` for a zero-arg (count(*)-shaped) call. */
503
+ readonly argSourceCol: number | undefined;
504
+ /** True iff this is the zero-arg multiplicity witness (count(*)): its finalized value
505
+ * counts the group's rows, so 0 ⇔ the group emptied (delete the backing row). */
506
+ readonly isMultiplicity: boolean;
507
+ /** True when a RETRACTION may be applied through `decode` of the stored value:
508
+ * either the algebra declares `decodeExact` (decode is a full inverse), or the
509
+ * argument column is declared NOT NULL — then every surviving row contributes, so
510
+ * the true contribution count equals the multiplicity and stays positive while the
511
+ * backing row exists (sum's absorbing decode witness never spuriously empties).
512
+ * A group that accumulated a retraction while ANY column is not retraction-safe is
513
+ * re-derived by the residual at flush instead of trusting the arithmetic. A
514
+ * `'tighten'` column is never retraction-safe. */
515
+ readonly retractionSafe: boolean;
516
+ }
517
+ /**
518
+ * The **decomposition-maintained** class of stored aggregate column (the `avg` class):
519
+ * a column whose value is a scalar `combine` over sibling partial aggregates that are
520
+ * THEMSELVES stored, delta-maintained columns of the same MV body — `avg(x) ≡
521
+ * sum(x)/count(x)`, and any UDAF declaring {@link AggregateAlgebra.decompose}. It carries
522
+ * NO independent accumulator (it is derived): at flush its value is
523
+ * `combine([finalized(partial) …])` over its partials' freshly finalized values. Resolved
524
+ * once at plan build (`buildDeltaAggregateDescriptor` — the create-time gate that binds
525
+ * each partial to a stored sibling) and evaluated per affected group at flush
526
+ * ({@link computeDeltaAggregateOps}). `avg` is the first client, not a special case.
527
+ */
528
+ export interface DeltaDecomposeColumn {
529
+ /** Backing column index (= body output column index) this decomposed aggregate lands at. */
530
+ readonly backingCol: number;
531
+ /** Index into {@link DeltaAggregateDescriptor.aggColumns} of each partial, in
532
+ * `decompose.partials` order — the finalized partial values `combine` consumes. Two
533
+ * decompose columns sharing a partial name the same index (the partial is maintained
534
+ * once, read by both). */
535
+ readonly partialIndices: readonly number[];
536
+ /** `algebra.decompose.combine`: builds this column's finalized value from its partials'
537
+ * finalized values, in `partialIndices` order. Reproduces the aggregate's own finalize
538
+ * incl. the empty-group / divide-by-zero case (avg → count 0/NULL ⇒ NULL). */
539
+ readonly combine: (partialValues: readonly SqlValue[]) => SqlValue;
540
+ }
541
+ /**
542
+ * Create-time descriptor for the delta-aggregate fast path inside a
543
+ * `'residual-recompute'` plan — see {@link ResidualRecomputePlan.delta}. Built by
544
+ * `buildDeltaAggregateDescriptor` only when every stored column qualifies; any gate
545
+ * failure leaves the plan on the plain residual (never an error).
546
+ */
547
+ export interface DeltaAggregateDescriptor {
548
+ /** The stored, independently-accumulated aggregate output columns (one per delta-
549
+ * maintainable aggregate the body projects). A {@link DeltaDecomposeColumn}'s partials
550
+ * are entries here; the decompose column itself is not (it accumulates nothing). */
551
+ readonly aggColumns: readonly DeltaAggregateColumn[];
552
+ /** Decomposition-maintained columns (the `avg` class): each derived at flush from its
553
+ * sibling stored partials via `combine`, contributing no independent accumulation.
554
+ * Empty for a body with no decompose column. See {@link DeltaDecomposeColumn}. */
555
+ readonly decomposeColumns: readonly DeltaDecomposeColumn[];
556
+ /** Non-aggregate (group-key passthrough) backing columns: each copies the group's
557
+ * backing-PK value at position `pkPos` (in `backingPkDefinition` order) into
558
+ * backing column `backingCol` — covers a group column projected outside the PK
559
+ * (e.g. a duplicate projection of a group column). */
560
+ readonly groupColumns: ReadonlyArray<{
561
+ readonly backingCol: number;
562
+ readonly pkPos: number;
563
+ }>;
564
+ /** Index into {@link aggColumns} of the count(*) multiplicity witness. */
565
+ readonly multiplicityIndex: number;
566
+ /** Total backing column count (the upsert row width). */
567
+ readonly backingColumnCount: number;
568
+ /** True iff every {@link DeltaAggregateColumn.retractionSafe}; when false, a group
569
+ * whose statement delta contains any retraction falls back to the residual. */
570
+ readonly retractionSafe: boolean;
571
+ /** True iff any {@link DeltaAggregateColumn} is `'tighten'` (min/max — `merge`, no
572
+ * `negate`). Such a column cannot retract arithmetically, so a group that accumulated
573
+ * ANY retraction re-derives from the residual whether or not a row is stored (unlike a
574
+ * merely not-retraction-safe abelian column, whose no-stored net-fold stays exact). A
575
+ * purely group-column descriptor (`false`) never takes the tighten fallback branch. */
576
+ readonly hasTighten: boolean;
577
+ /** Compiled single-source-row body WHERE; a row whose predicate is not
578
+ * unambiguously TRUE contributes nothing (mirrors the inverse-projection arm).
579
+ * Absent ⇒ every row is in scope. */
580
+ readonly predicate?: CompiledPredicate;
581
+ }
582
+ /**
583
+ * Per-group accumulated statement delta for a delta-aggregate MV — the value side of
584
+ * {@link ResidualKeyBatchEntry.delta}, keyed (like `forward`) on
585
+ * `canonKeyValues(keyVals)` so the two maps pair up at flush.
586
+ */
587
+ export interface DeltaGroupState {
588
+ /** Backing-PK (group key) values, in `backingPkDefinition` order. */
589
+ readonly keyVals: SqlValue[];
590
+ /** Prebuilt point-delete key for an emptied group. */
591
+ readonly deleteKey: BTreeKeyForPrimary;
592
+ /** Net accumulator delta per aggregate column (descriptor `aggColumns` order),
593
+ * folded across the statement: `merge`d `step` contributions for inserts,
594
+ * `merge`d `negate(step(…))` contributions for deletes. */
595
+ readonly accs: AggValue[];
596
+ /** True once any retraction (delete / update-old-image) contributed — the flush
597
+ * falls back to the residual for this group when the descriptor is not
598
+ * retraction-safe and a stored row exists. */
599
+ retracted: boolean;
600
+ }
601
+ /**
602
+ * The per-statement key accumulation for one residual-arm MV — which distinct binding
603
+ * keys this statement's source changes affected, per residual variant. `forward` holds
604
+ * driving-source keys (`'residual-recompute'` group keys; `'join-residual'` `T`-PK keys),
605
+ * `lookup` holds a `'join-residual'` plan's lookup-side (`P`-PK) keys (which run the
606
+ * reverse residual variant at flush), and `prefix` holds a `'prefix-delete'` plan's base
607
+ * keys. Exactly one map is populated for the single-variant arms; a `'join-residual'` MV
608
+ * may accumulate `forward` and `lookup` in one statement (e.g. an FK cascade writing both
609
+ * sides). Each map is keyed on the canonical key bytes (`canonKeyValues`) — the same
610
+ * dedup the per-row appliers do within one change, extended across the whole statement.
611
+ */
612
+ export interface ResidualKeyBatchEntry {
613
+ forward: Map<string, ForwardResidualKey>;
614
+ lookup: Map<string, SqlValue[]>;
615
+ prefix: Map<string, PrefixDeleteKey>;
616
+ /** Delta-aggregate accumulation, keyed like `forward` on the canonical group-key
617
+ * bytes. Populated ONLY alongside `forward` (the residual keys are always
618
+ * accumulated too), so dropping it — {@link deltaPoisoned} — degrades the flush to
619
+ * the plain residual with zero information loss. */
620
+ delta?: Map<string, DeltaGroupState>;
621
+ /** Set when a per-row savepoint revert (OR FAIL) invalidated the accumulated
622
+ * deltas: the savepoint undid the failing row's source/backing writes, but a JS
623
+ * accumulation cannot be unwound, so the net deltas may include a reverted row's
624
+ * contribution. The residual keys stay valid (a reverted key recomputes to a
625
+ * value-identical row, suppressed), so the flush routes through them instead.
626
+ * See `poisonResidualDeltaAccumulations`. */
627
+ deltaPoisoned?: boolean;
628
+ }
629
+ /**
630
+ * Per-statement deferred-residual key batch, keyed by MV key (lowercased
631
+ * `schema.name`). Created once per DML generator run alongside the
632
+ * {@link BackingConnectionCache} and the deferred full-rebuild set; the residual arms
633
+ * accumulate their affected keys here during the row loop
634
+ * ({@link MaterializedViewManager.maintainRowTime}) and each MV's distinct keys are
635
+ * recomputed exactly once at the end-of-statement
636
+ * {@link MaterializedViewManager.flushDeferredMaintenance}. Owned by the statement:
637
+ * discarded with the statement-savepoint unwind on failure, never carried across
638
+ * statements.
639
+ */
640
+ export type ResidualKeyBatch = Map<string, ResidualKeyBatchEntry>;
641
+ //# sourceMappingURL=database-materialized-views-plans.d.ts.map