@quereus/quereus 4.6.0 → 4.8.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 (584) hide show
  1. package/README.md +2 -2
  2. package/dist/src/common/errors.d.ts +17 -0
  3. package/dist/src/common/errors.d.ts.map +1 -1
  4. package/dist/src/common/errors.js +21 -0
  5. package/dist/src/common/errors.js.map +1 -1
  6. package/dist/src/common/types.d.ts +19 -0
  7. package/dist/src/common/types.d.ts.map +1 -1
  8. package/dist/src/common/types.js.map +1 -1
  9. package/dist/src/core/database-assertions.d.ts +4 -3
  10. package/dist/src/core/database-assertions.d.ts.map +1 -1
  11. package/dist/src/core/database-assertions.js +44 -14
  12. package/dist/src/core/database-assertions.js.map +1 -1
  13. package/dist/src/core/database-events.d.ts +62 -0
  14. package/dist/src/core/database-events.d.ts.map +1 -1
  15. package/dist/src/core/database-events.js +88 -2
  16. package/dist/src/core/database-events.js.map +1 -1
  17. package/dist/src/core/database-internal.d.ts +5 -2
  18. package/dist/src/core/database-internal.d.ts.map +1 -1
  19. package/dist/src/core/database-materialized-views-plan-builders.d.ts.map +1 -1
  20. package/dist/src/core/database-materialized-views-plan-builders.js +4 -2
  21. package/dist/src/core/database-materialized-views-plan-builders.js.map +1 -1
  22. package/dist/src/core/database-materialized-views-plans.d.ts +12 -2
  23. package/dist/src/core/database-materialized-views-plans.d.ts.map +1 -1
  24. package/dist/src/core/database-materialized-views.d.ts +46 -0
  25. package/dist/src/core/database-materialized-views.d.ts.map +1 -1
  26. package/dist/src/core/database-materialized-views.js +75 -4
  27. package/dist/src/core/database-materialized-views.js.map +1 -1
  28. package/dist/src/core/database.d.ts +48 -2
  29. package/dist/src/core/database.d.ts.map +1 -1
  30. package/dist/src/core/database.js +222 -11
  31. package/dist/src/core/database.js.map +1 -1
  32. package/dist/src/core/derived-row-validator.d.ts.map +1 -1
  33. package/dist/src/core/derived-row-validator.js +7 -1
  34. package/dist/src/core/derived-row-validator.js.map +1 -1
  35. package/dist/src/core/statement.d.ts.map +1 -1
  36. package/dist/src/core/statement.js +101 -5
  37. package/dist/src/core/statement.js.map +1 -1
  38. package/dist/src/emit/ast-stringify.d.ts +18 -2
  39. package/dist/src/emit/ast-stringify.d.ts.map +1 -1
  40. package/dist/src/emit/ast-stringify.js +22 -4
  41. package/dist/src/emit/ast-stringify.js.map +1 -1
  42. package/dist/src/func/builtins/explain.d.ts.map +1 -1
  43. package/dist/src/func/builtins/explain.js +19 -5
  44. package/dist/src/func/builtins/explain.js.map +1 -1
  45. package/dist/src/func/builtins/scalar.d.ts.map +1 -1
  46. package/dist/src/func/builtins/scalar.js +24 -20
  47. package/dist/src/func/builtins/scalar.js.map +1 -1
  48. package/dist/src/func/builtins/schema.d.ts.map +1 -1
  49. package/dist/src/func/builtins/schema.js +32 -5
  50. package/dist/src/func/builtins/schema.js.map +1 -1
  51. package/dist/src/index.d.ts +9 -5
  52. package/dist/src/index.d.ts.map +1 -1
  53. package/dist/src/index.js +7 -5
  54. package/dist/src/index.js.map +1 -1
  55. package/dist/src/parser/ast.d.ts +58 -1
  56. package/dist/src/parser/ast.d.ts.map +1 -1
  57. package/dist/src/parser/parser.js +1 -1
  58. package/dist/src/parser/parser.js.map +1 -1
  59. package/dist/src/parser/utils.d.ts +13 -1
  60. package/dist/src/parser/utils.d.ts.map +1 -1
  61. package/dist/src/parser/utils.js +14 -0
  62. package/dist/src/parser/utils.js.map +1 -1
  63. package/dist/src/planner/analysis/assertion-classifier.d.ts.map +1 -1
  64. package/dist/src/planner/analysis/assertion-classifier.js +7 -2
  65. package/dist/src/planner/analysis/assertion-classifier.js.map +1 -1
  66. package/dist/src/planner/analysis/assertion-hoist-cache.d.ts.map +1 -1
  67. package/dist/src/planner/analysis/assertion-hoist-cache.js +5 -0
  68. package/dist/src/planner/analysis/assertion-hoist-cache.js.map +1 -1
  69. package/dist/src/planner/analysis/change-scope.d.ts +11 -3
  70. package/dist/src/planner/analysis/change-scope.d.ts.map +1 -1
  71. package/dist/src/planner/analysis/change-scope.js +5 -4
  72. package/dist/src/planner/analysis/change-scope.js.map +1 -1
  73. package/dist/src/planner/analysis/coverage-prover.d.ts.map +1 -1
  74. package/dist/src/planner/analysis/coverage-prover.js +13 -5
  75. package/dist/src/planner/analysis/coverage-prover.js.map +1 -1
  76. package/dist/src/planner/analysis/equi-correlation.d.ts +6 -1
  77. package/dist/src/planner/analysis/equi-correlation.d.ts.map +1 -1
  78. package/dist/src/planner/analysis/equi-correlation.js +8 -1
  79. package/dist/src/planner/analysis/equi-correlation.js.map +1 -1
  80. package/dist/src/planner/analysis/predicate-dependencies.d.ts +34 -0
  81. package/dist/src/planner/analysis/predicate-dependencies.d.ts.map +1 -0
  82. package/dist/src/planner/analysis/predicate-dependencies.js +60 -0
  83. package/dist/src/planner/analysis/predicate-dependencies.js.map +1 -0
  84. package/dist/src/planner/analysis/query-rewrite-matcher.d.ts +1 -1
  85. package/dist/src/planner/analysis/query-rewrite-matcher.d.ts.map +1 -1
  86. package/dist/src/planner/analysis/query-rewrite-matcher.js +0 -26
  87. package/dist/src/planner/analysis/query-rewrite-matcher.js.map +1 -1
  88. package/dist/src/planner/building/alter-table.d.ts.map +1 -1
  89. package/dist/src/planner/building/alter-table.js +53 -17
  90. package/dist/src/planner/building/alter-table.js.map +1 -1
  91. package/dist/src/planner/building/constraint-builder.d.ts.map +1 -1
  92. package/dist/src/planner/building/constraint-builder.js +9 -5
  93. package/dist/src/planner/building/constraint-builder.js.map +1 -1
  94. package/dist/src/planner/building/create-assertion.d.ts.map +1 -1
  95. package/dist/src/planner/building/create-assertion.js +72 -1
  96. package/dist/src/planner/building/create-assertion.js.map +1 -1
  97. package/dist/src/planner/building/create-view.d.ts +6 -1
  98. package/dist/src/planner/building/create-view.d.ts.map +1 -1
  99. package/dist/src/planner/building/create-view.js +12 -3
  100. package/dist/src/planner/building/create-view.js.map +1 -1
  101. package/dist/src/planner/building/ddl.d.ts.map +1 -1
  102. package/dist/src/planner/building/ddl.js +6 -2
  103. package/dist/src/planner/building/ddl.js.map +1 -1
  104. package/dist/src/planner/building/delete.d.ts.map +1 -1
  105. package/dist/src/planner/building/delete.js +23 -10
  106. package/dist/src/planner/building/delete.js.map +1 -1
  107. package/dist/src/planner/building/dml-target.d.ts.map +1 -1
  108. package/dist/src/planner/building/dml-target.js +4 -0
  109. package/dist/src/planner/building/dml-target.js.map +1 -1
  110. package/dist/src/planner/building/drop-assertion.d.ts.map +1 -1
  111. package/dist/src/planner/building/drop-assertion.js +3 -1
  112. package/dist/src/planner/building/drop-assertion.js.map +1 -1
  113. package/dist/src/planner/building/foreign-key-builder.d.ts.map +1 -1
  114. package/dist/src/planner/building/foreign-key-builder.js +7 -5
  115. package/dist/src/planner/building/foreign-key-builder.js.map +1 -1
  116. package/dist/src/planner/building/function-call.d.ts +35 -0
  117. package/dist/src/planner/building/function-call.d.ts.map +1 -1
  118. package/dist/src/planner/building/function-call.js +53 -40
  119. package/dist/src/planner/building/function-call.js.map +1 -1
  120. package/dist/src/planner/building/insert.d.ts.map +1 -1
  121. package/dist/src/planner/building/insert.js +185 -48
  122. package/dist/src/planner/building/insert.js.map +1 -1
  123. package/dist/src/planner/building/materialized-view.d.ts.map +1 -1
  124. package/dist/src/planner/building/materialized-view.js +3 -1
  125. package/dist/src/planner/building/materialized-view.js.map +1 -1
  126. package/dist/src/planner/building/schema-authored-context.d.ts +69 -0
  127. package/dist/src/planner/building/schema-authored-context.d.ts.map +1 -0
  128. package/dist/src/planner/building/schema-authored-context.js +75 -0
  129. package/dist/src/planner/building/schema-authored-context.js.map +1 -0
  130. package/dist/src/planner/building/schema-resolution.d.ts.map +1 -1
  131. package/dist/src/planner/building/schema-resolution.js +7 -4
  132. package/dist/src/planner/building/schema-resolution.js.map +1 -1
  133. package/dist/src/planner/building/select-aggregates.d.ts +187 -2
  134. package/dist/src/planner/building/select-aggregates.d.ts.map +1 -1
  135. package/dist/src/planner/building/select-aggregates.js +414 -81
  136. package/dist/src/planner/building/select-aggregates.js.map +1 -1
  137. package/dist/src/planner/building/select-compound.js +2 -2
  138. package/dist/src/planner/building/select-compound.js.map +1 -1
  139. package/dist/src/planner/building/select-context.d.ts +91 -0
  140. package/dist/src/planner/building/select-context.d.ts.map +1 -1
  141. package/dist/src/planner/building/select-context.js +113 -0
  142. package/dist/src/planner/building/select-context.js.map +1 -1
  143. package/dist/src/planner/building/select-modifiers.d.ts +10 -3
  144. package/dist/src/planner/building/select-modifiers.d.ts.map +1 -1
  145. package/dist/src/planner/building/select-modifiers.js +29 -8
  146. package/dist/src/planner/building/select-modifiers.js.map +1 -1
  147. package/dist/src/planner/building/select-ordinal.d.ts +64 -19
  148. package/dist/src/planner/building/select-ordinal.d.ts.map +1 -1
  149. package/dist/src/planner/building/select-ordinal.js +79 -30
  150. package/dist/src/planner/building/select-ordinal.js.map +1 -1
  151. package/dist/src/planner/building/select-projections.d.ts +1 -1
  152. package/dist/src/planner/building/select-projections.d.ts.map +1 -1
  153. package/dist/src/planner/building/select-projections.js +18 -11
  154. package/dist/src/planner/building/select-projections.js.map +1 -1
  155. package/dist/src/planner/building/select-window.d.ts +13 -3
  156. package/dist/src/planner/building/select-window.d.ts.map +1 -1
  157. package/dist/src/planner/building/select-window.js +142 -37
  158. package/dist/src/planner/building/select-window.js.map +1 -1
  159. package/dist/src/planner/building/select.d.ts.map +1 -1
  160. package/dist/src/planner/building/select.js +129 -59
  161. package/dist/src/planner/building/select.js.map +1 -1
  162. package/dist/src/planner/building/update.d.ts.map +1 -1
  163. package/dist/src/planner/building/update.js +27 -13
  164. package/dist/src/planner/building/update.js.map +1 -1
  165. package/dist/src/planner/building/view-mutation-builder.d.ts +1 -1
  166. package/dist/src/planner/building/view-mutation-builder.d.ts.map +1 -1
  167. package/dist/src/planner/building/view-mutation-builder.js +102 -8
  168. package/dist/src/planner/building/view-mutation-builder.js.map +1 -1
  169. package/dist/src/planner/building/with.d.ts.map +1 -1
  170. package/dist/src/planner/building/with.js +34 -4
  171. package/dist/src/planner/building/with.js.map +1 -1
  172. package/dist/src/planner/cache/correlation-detector.d.ts +15 -0
  173. package/dist/src/planner/cache/correlation-detector.d.ts.map +1 -1
  174. package/dist/src/planner/cache/correlation-detector.js +26 -0
  175. package/dist/src/planner/cache/correlation-detector.js.map +1 -1
  176. package/dist/src/planner/cache/materialization-advisory.d.ts +7 -0
  177. package/dist/src/planner/cache/materialization-advisory.d.ts.map +1 -1
  178. package/dist/src/planner/cache/materialization-advisory.js +12 -3
  179. package/dist/src/planner/cache/materialization-advisory.js.map +1 -1
  180. package/dist/src/planner/framework/characteristics.d.ts +9 -0
  181. package/dist/src/planner/framework/characteristics.d.ts.map +1 -1
  182. package/dist/src/planner/framework/characteristics.js.map +1 -1
  183. package/dist/src/planner/framework/pass.d.ts +2 -0
  184. package/dist/src/planner/framework/pass.d.ts.map +1 -1
  185. package/dist/src/planner/framework/pass.js +15 -0
  186. package/dist/src/planner/framework/pass.js.map +1 -1
  187. package/dist/src/planner/mutation/backward-body.d.ts.map +1 -1
  188. package/dist/src/planner/mutation/backward-body.js +4 -1
  189. package/dist/src/planner/mutation/backward-body.js.map +1 -1
  190. package/dist/src/planner/mutation/body-context.d.ts +23 -0
  191. package/dist/src/planner/mutation/body-context.d.ts.map +1 -0
  192. package/dist/src/planner/mutation/body-context.js +26 -0
  193. package/dist/src/planner/mutation/body-context.js.map +1 -0
  194. package/dist/src/planner/mutation/cte-flatten.js +15 -2
  195. package/dist/src/planner/mutation/cte-flatten.js.map +1 -1
  196. package/dist/src/planner/mutation/decomposition.d.ts +8 -0
  197. package/dist/src/planner/mutation/decomposition.d.ts.map +1 -1
  198. package/dist/src/planner/mutation/decomposition.js +8 -3
  199. package/dist/src/planner/mutation/decomposition.js.map +1 -1
  200. package/dist/src/planner/mutation/lens-enforcement.js +1 -1
  201. package/dist/src/planner/mutation/multi-source.d.ts +7 -0
  202. package/dist/src/planner/mutation/multi-source.d.ts.map +1 -1
  203. package/dist/src/planner/mutation/multi-source.js +5 -0
  204. package/dist/src/planner/mutation/multi-source.js.map +1 -1
  205. package/dist/src/planner/mutation/mutation-diagnostic.d.ts +1 -1
  206. package/dist/src/planner/mutation/mutation-diagnostic.d.ts.map +1 -1
  207. package/dist/src/planner/mutation/mutation-diagnostic.js.map +1 -1
  208. package/dist/src/planner/mutation/scope-transform.d.ts +32 -0
  209. package/dist/src/planner/mutation/scope-transform.d.ts.map +1 -1
  210. package/dist/src/planner/mutation/scope-transform.js +181 -33
  211. package/dist/src/planner/mutation/scope-transform.js.map +1 -1
  212. package/dist/src/planner/mutation/set-op.d.ts.map +1 -1
  213. package/dist/src/planner/mutation/set-op.js +66 -16
  214. package/dist/src/planner/mutation/set-op.js.map +1 -1
  215. package/dist/src/planner/mutation/single-source.d.ts.map +1 -1
  216. package/dist/src/planner/mutation/single-source.js +100 -24
  217. package/dist/src/planner/mutation/single-source.js.map +1 -1
  218. package/dist/src/planner/nodes/add-constraint-node.d.ts +15 -1
  219. package/dist/src/planner/nodes/add-constraint-node.d.ts.map +1 -1
  220. package/dist/src/planner/nodes/add-constraint-node.js +10 -1
  221. package/dist/src/planner/nodes/add-constraint-node.js.map +1 -1
  222. package/dist/src/planner/nodes/aggregate-node.d.ts +14 -5
  223. package/dist/src/planner/nodes/aggregate-node.d.ts.map +1 -1
  224. package/dist/src/planner/nodes/aggregate-node.js +28 -21
  225. package/dist/src/planner/nodes/aggregate-node.js.map +1 -1
  226. package/dist/src/planner/nodes/alter-table-node.d.ts +27 -2
  227. package/dist/src/planner/nodes/alter-table-node.d.ts.map +1 -1
  228. package/dist/src/planner/nodes/alter-table-node.js +49 -2
  229. package/dist/src/planner/nodes/alter-table-node.js.map +1 -1
  230. package/dist/src/planner/nodes/constraint-check-node.d.ts.map +1 -1
  231. package/dist/src/planner/nodes/constraint-check-node.js +17 -19
  232. package/dist/src/planner/nodes/constraint-check-node.js.map +1 -1
  233. package/dist/src/planner/nodes/create-assertion-node.d.ts +2 -1
  234. package/dist/src/planner/nodes/create-assertion-node.d.ts.map +1 -1
  235. package/dist/src/planner/nodes/create-assertion-node.js +5 -2
  236. package/dist/src/planner/nodes/create-assertion-node.js.map +1 -1
  237. package/dist/src/planner/nodes/cte-node.d.ts +19 -9
  238. package/dist/src/planner/nodes/cte-node.d.ts.map +1 -1
  239. package/dist/src/planner/nodes/cte-node.js +25 -9
  240. package/dist/src/planner/nodes/cte-node.js.map +1 -1
  241. package/dist/src/planner/nodes/delete-node.d.ts +20 -2
  242. package/dist/src/planner/nodes/delete-node.d.ts.map +1 -1
  243. package/dist/src/planner/nodes/delete-node.js +11 -2
  244. package/dist/src/planner/nodes/delete-node.js.map +1 -1
  245. package/dist/src/planner/nodes/dml-executor-node.d.ts +58 -1
  246. package/dist/src/planner/nodes/dml-executor-node.d.ts.map +1 -1
  247. package/dist/src/planner/nodes/dml-executor-node.js +107 -15
  248. package/dist/src/planner/nodes/dml-executor-node.js.map +1 -1
  249. package/dist/src/planner/nodes/drop-assertion-node.d.ts +2 -1
  250. package/dist/src/planner/nodes/drop-assertion-node.d.ts.map +1 -1
  251. package/dist/src/planner/nodes/drop-assertion-node.js +5 -2
  252. package/dist/src/planner/nodes/drop-assertion-node.js.map +1 -1
  253. package/dist/src/planner/nodes/filter.d.ts.map +1 -1
  254. package/dist/src/planner/nodes/filter.js +12 -6
  255. package/dist/src/planner/nodes/filter.js.map +1 -1
  256. package/dist/src/planner/nodes/hash-aggregate.d.ts +0 -5
  257. package/dist/src/planner/nodes/hash-aggregate.d.ts.map +1 -1
  258. package/dist/src/planner/nodes/hash-aggregate.js +17 -20
  259. package/dist/src/planner/nodes/hash-aggregate.js.map +1 -1
  260. package/dist/src/planner/nodes/insert-node.d.ts +19 -2
  261. package/dist/src/planner/nodes/insert-node.d.ts.map +1 -1
  262. package/dist/src/planner/nodes/insert-node.js +10 -2
  263. package/dist/src/planner/nodes/insert-node.js.map +1 -1
  264. package/dist/src/planner/nodes/key-set-semi-join-node.d.ts +42 -10
  265. package/dist/src/planner/nodes/key-set-semi-join-node.d.ts.map +1 -1
  266. package/dist/src/planner/nodes/key-set-semi-join-node.js +85 -16
  267. package/dist/src/planner/nodes/key-set-semi-join-node.js.map +1 -1
  268. package/dist/src/planner/nodes/lens-auxiliary-access-node.d.ts +5 -0
  269. package/dist/src/planner/nodes/lens-auxiliary-access-node.d.ts.map +1 -1
  270. package/dist/src/planner/nodes/lens-auxiliary-access-node.js.map +1 -1
  271. package/dist/src/planner/nodes/plan-node.d.ts +5 -0
  272. package/dist/src/planner/nodes/plan-node.d.ts.map +1 -1
  273. package/dist/src/planner/nodes/plan-node.js +12 -0
  274. package/dist/src/planner/nodes/plan-node.js.map +1 -1
  275. package/dist/src/planner/nodes/project-node.d.ts.map +1 -1
  276. package/dist/src/planner/nodes/project-node.js +16 -35
  277. package/dist/src/planner/nodes/project-node.js.map +1 -1
  278. package/dist/src/planner/nodes/retrieve-node.d.ts +16 -2
  279. package/dist/src/planner/nodes/retrieve-node.d.ts.map +1 -1
  280. package/dist/src/planner/nodes/retrieve-node.js +8 -1
  281. package/dist/src/planner/nodes/retrieve-node.js.map +1 -1
  282. package/dist/src/planner/nodes/returning-node.d.ts.map +1 -1
  283. package/dist/src/planner/nodes/returning-node.js +13 -32
  284. package/dist/src/planner/nodes/returning-node.js.map +1 -1
  285. package/dist/src/planner/nodes/stream-aggregate.d.ts +0 -5
  286. package/dist/src/planner/nodes/stream-aggregate.d.ts.map +1 -1
  287. package/dist/src/planner/nodes/stream-aggregate.js +18 -24
  288. package/dist/src/planner/nodes/stream-aggregate.js.map +1 -1
  289. package/dist/src/planner/nodes/table-access-nodes.d.ts +89 -1
  290. package/dist/src/planner/nodes/table-access-nodes.d.ts.map +1 -1
  291. package/dist/src/planner/nodes/table-access-nodes.js +64 -2
  292. package/dist/src/planner/nodes/table-access-nodes.js.map +1 -1
  293. package/dist/src/planner/nodes/update-node.d.ts +19 -2
  294. package/dist/src/planner/nodes/update-node.d.ts.map +1 -1
  295. package/dist/src/planner/nodes/update-node.js +10 -2
  296. package/dist/src/planner/nodes/update-node.js.map +1 -1
  297. package/dist/src/planner/optimizer.d.ts +18 -0
  298. package/dist/src/planner/optimizer.d.ts.map +1 -1
  299. package/dist/src/planner/optimizer.js +59 -10
  300. package/dist/src/planner/optimizer.js.map +1 -1
  301. package/dist/src/planner/planning-context.d.ts +24 -0
  302. package/dist/src/planner/planning-context.d.ts.map +1 -1
  303. package/dist/src/planner/planning-context.js.map +1 -1
  304. package/dist/src/planner/rules/access/rule-key-set-seek.d.ts +78 -20
  305. package/dist/src/planner/rules/access/rule-key-set-seek.d.ts.map +1 -1
  306. package/dist/src/planner/rules/access/rule-key-set-seek.js +297 -71
  307. package/dist/src/planner/rules/access/rule-key-set-seek.js.map +1 -1
  308. package/dist/src/planner/rules/access/rule-monotonic-range-access.d.ts.map +1 -1
  309. package/dist/src/planner/rules/access/rule-monotonic-range-access.js +2 -2
  310. package/dist/src/planner/rules/access/rule-monotonic-range-access.js.map +1 -1
  311. package/dist/src/planner/rules/access/rule-select-access-path.d.ts +11 -1
  312. package/dist/src/planner/rules/access/rule-select-access-path.d.ts.map +1 -1
  313. package/dist/src/planner/rules/access/rule-select-access-path.js +46 -2
  314. package/dist/src/planner/rules/access/rule-select-access-path.js.map +1 -1
  315. package/dist/src/planner/rules/aggregate/rule-groupby-fd-simplification.d.ts +7 -4
  316. package/dist/src/planner/rules/aggregate/rule-groupby-fd-simplification.d.ts.map +1 -1
  317. package/dist/src/planner/rules/aggregate/rule-groupby-fd-simplification.js +39 -5
  318. package/dist/src/planner/rules/aggregate/rule-groupby-fd-simplification.js.map +1 -1
  319. package/dist/src/planner/rules/cache/rule-cte-optimization.d.ts.map +1 -1
  320. package/dist/src/planner/rules/cache/rule-cte-optimization.js +6 -2
  321. package/dist/src/planner/rules/cache/rule-cte-optimization.js.map +1 -1
  322. package/dist/src/planner/rules/cache/rule-materialized-view-rewrite.js +10 -3
  323. package/dist/src/planner/rules/cache/rule-materialized-view-rewrite.js.map +1 -1
  324. package/dist/src/planner/rules/join/index-nested-loop.d.ts.map +1 -1
  325. package/dist/src/planner/rules/join/index-nested-loop.js +13 -7
  326. package/dist/src/planner/rules/join/index-nested-loop.js.map +1 -1
  327. package/dist/src/planner/rules/join/rule-fanout-lookup-join.d.ts +4 -0
  328. package/dist/src/planner/rules/join/rule-fanout-lookup-join.d.ts.map +1 -1
  329. package/dist/src/planner/rules/join/rule-fanout-lookup-join.js +50 -15
  330. package/dist/src/planner/rules/join/rule-fanout-lookup-join.js.map +1 -1
  331. package/dist/src/planner/rules/join/rule-join-elimination.d.ts +6 -0
  332. package/dist/src/planner/rules/join/rule-join-elimination.d.ts.map +1 -1
  333. package/dist/src/planner/rules/join/rule-join-elimination.js +25 -9
  334. package/dist/src/planner/rules/join/rule-join-elimination.js.map +1 -1
  335. package/dist/src/planner/rules/join/rule-join-key-inference.d.ts +7 -0
  336. package/dist/src/planner/rules/join/rule-join-key-inference.d.ts.map +1 -1
  337. package/dist/src/planner/rules/join/rule-join-key-inference.js +23 -11
  338. package/dist/src/planner/rules/join/rule-join-key-inference.js.map +1 -1
  339. package/dist/src/planner/rules/join/rule-join-physical-selection.d.ts +2 -2
  340. package/dist/src/planner/rules/join/rule-join-physical-selection.d.ts.map +1 -1
  341. package/dist/src/planner/rules/join/rule-join-physical-selection.js +46 -16
  342. package/dist/src/planner/rules/join/rule-join-physical-selection.js.map +1 -1
  343. package/dist/src/planner/rules/join/rule-monotonic-merge-join.d.ts +2 -0
  344. package/dist/src/planner/rules/join/rule-monotonic-merge-join.d.ts.map +1 -1
  345. package/dist/src/planner/rules/join/rule-monotonic-merge-join.js +14 -0
  346. package/dist/src/planner/rules/join/rule-monotonic-merge-join.js.map +1 -1
  347. package/dist/src/planner/rules/predicate/rule-aggregate-predicate-pushdown.d.ts +2 -2
  348. package/dist/src/planner/rules/predicate/rule-aggregate-predicate-pushdown.d.ts.map +1 -1
  349. package/dist/src/planner/rules/predicate/rule-aggregate-predicate-pushdown.js +19 -22
  350. package/dist/src/planner/rules/predicate/rule-aggregate-predicate-pushdown.js.map +1 -1
  351. package/dist/src/planner/rules/predicate/rule-filter-selectivity.d.ts +33 -19
  352. package/dist/src/planner/rules/predicate/rule-filter-selectivity.d.ts.map +1 -1
  353. package/dist/src/planner/rules/predicate/rule-filter-selectivity.js +37 -18
  354. package/dist/src/planner/rules/predicate/rule-filter-selectivity.js.map +1 -1
  355. package/dist/src/planner/rules/predicate/rule-join-predicate-pushdown.d.ts +6 -3
  356. package/dist/src/planner/rules/predicate/rule-join-predicate-pushdown.d.ts.map +1 -1
  357. package/dist/src/planner/rules/predicate/rule-join-predicate-pushdown.js +6 -3
  358. package/dist/src/planner/rules/predicate/rule-join-predicate-pushdown.js.map +1 -1
  359. package/dist/src/planner/rules/predicate/rule-predicate-pushdown.d.ts.map +1 -1
  360. package/dist/src/planner/rules/predicate/rule-predicate-pushdown.js +11 -21
  361. package/dist/src/planner/rules/predicate/rule-predicate-pushdown.js.map +1 -1
  362. package/dist/src/planner/rules/shared/access-leaf.d.ts +16 -3
  363. package/dist/src/planner/rules/shared/access-leaf.d.ts.map +1 -1
  364. package/dist/src/planner/rules/shared/access-leaf.js +21 -5
  365. package/dist/src/planner/rules/shared/access-leaf.js.map +1 -1
  366. package/dist/src/planner/rules/subquery/rule-anti-join-fk-empty.js +1 -1
  367. package/dist/src/planner/rules/subquery/rule-anti-join-fk-empty.js.map +1 -1
  368. package/dist/src/planner/rules/subquery/rule-semi-join-fk-trivial.js +1 -1
  369. package/dist/src/planner/rules/subquery/rule-semi-join-fk-trivial.js.map +1 -1
  370. package/dist/src/planner/stored-body-context.d.ts +57 -0
  371. package/dist/src/planner/stored-body-context.d.ts.map +1 -0
  372. package/dist/src/planner/stored-body-context.js +64 -0
  373. package/dist/src/planner/stored-body-context.js.map +1 -0
  374. package/dist/src/planner/util/ind-utils.d.ts +28 -20
  375. package/dist/src/planner/util/ind-utils.d.ts.map +1 -1
  376. package/dist/src/planner/util/ind-utils.js +36 -27
  377. package/dist/src/planner/util/ind-utils.js.map +1 -1
  378. package/dist/src/planner/util/key-utils.d.ts +19 -4
  379. package/dist/src/planner/util/key-utils.d.ts.map +1 -1
  380. package/dist/src/planner/util/key-utils.js +23 -7
  381. package/dist/src/planner/util/key-utils.js.map +1 -1
  382. package/dist/src/planner/util/output-names.d.ts +12 -0
  383. package/dist/src/planner/util/output-names.d.ts.map +1 -0
  384. package/dist/src/planner/util/output-names.js +20 -0
  385. package/dist/src/planner/util/output-names.js.map +1 -0
  386. package/dist/src/planner/util/row-estimates.d.ts +11 -0
  387. package/dist/src/planner/util/row-estimates.d.ts.map +1 -1
  388. package/dist/src/planner/util/row-estimates.js +28 -0
  389. package/dist/src/planner/util/row-estimates.js.map +1 -1
  390. package/dist/src/runtime/deferred-constraint-queue.d.ts.map +1 -1
  391. package/dist/src/runtime/deferred-constraint-queue.js +3 -2
  392. package/dist/src/runtime/deferred-constraint-queue.js.map +1 -1
  393. package/dist/src/runtime/emit/add-constraint.d.ts.map +1 -1
  394. package/dist/src/runtime/emit/add-constraint.js +22 -6
  395. package/dist/src/runtime/emit/add-constraint.js.map +1 -1
  396. package/dist/src/runtime/emit/alter-schema-event.d.ts +59 -4
  397. package/dist/src/runtime/emit/alter-schema-event.d.ts.map +1 -1
  398. package/dist/src/runtime/emit/alter-schema-event.js +63 -4
  399. package/dist/src/runtime/emit/alter-schema-event.js.map +1 -1
  400. package/dist/src/runtime/emit/alter-table.d.ts.map +1 -1
  401. package/dist/src/runtime/emit/alter-table.js +212 -92
  402. package/dist/src/runtime/emit/alter-table.js.map +1 -1
  403. package/dist/src/runtime/emit/analyze.d.ts.map +1 -1
  404. package/dist/src/runtime/emit/analyze.js +15 -4
  405. package/dist/src/runtime/emit/analyze.js.map +1 -1
  406. package/dist/src/runtime/emit/assertion-drop-guard.d.ts +37 -0
  407. package/dist/src/runtime/emit/assertion-drop-guard.d.ts.map +1 -0
  408. package/dist/src/runtime/emit/assertion-drop-guard.js +59 -0
  409. package/dist/src/runtime/emit/assertion-drop-guard.js.map +1 -0
  410. package/dist/src/runtime/emit/assertion-rename-helpers.d.ts +33 -0
  411. package/dist/src/runtime/emit/assertion-rename-helpers.d.ts.map +1 -0
  412. package/dist/src/runtime/emit/assertion-rename-helpers.js +124 -0
  413. package/dist/src/runtime/emit/assertion-rename-helpers.js.map +1 -0
  414. package/dist/src/runtime/emit/constraint-check.d.ts.map +1 -1
  415. package/dist/src/runtime/emit/constraint-check.js +10 -227
  416. package/dist/src/runtime/emit/constraint-check.js.map +1 -1
  417. package/dist/src/runtime/emit/create-assertion.d.ts.map +1 -1
  418. package/dist/src/runtime/emit/create-assertion.js +31 -14
  419. package/dist/src/runtime/emit/create-assertion.js.map +1 -1
  420. package/dist/src/runtime/emit/cte.d.ts.map +1 -1
  421. package/dist/src/runtime/emit/cte.js +11 -6
  422. package/dist/src/runtime/emit/cte.js.map +1 -1
  423. package/dist/src/runtime/emit/dml-executor.d.ts.map +1 -1
  424. package/dist/src/runtime/emit/dml-executor.js +169 -1
  425. package/dist/src/runtime/emit/dml-executor.js.map +1 -1
  426. package/dist/src/runtime/emit/drop-assertion.js +8 -8
  427. package/dist/src/runtime/emit/drop-assertion.js.map +1 -1
  428. package/dist/src/runtime/emit/drop-column-guards.d.ts +151 -0
  429. package/dist/src/runtime/emit/drop-column-guards.d.ts.map +1 -0
  430. package/dist/src/runtime/emit/drop-column-guards.js +230 -0
  431. package/dist/src/runtime/emit/drop-column-guards.js.map +1 -0
  432. package/dist/src/runtime/emit/drop-table.d.ts.map +1 -1
  433. package/dist/src/runtime/emit/drop-table.js +6 -0
  434. package/dist/src/runtime/emit/drop-table.js.map +1 -1
  435. package/dist/src/runtime/emit/drop-view.d.ts.map +1 -1
  436. package/dist/src/runtime/emit/drop-view.js +4 -0
  437. package/dist/src/runtime/emit/drop-view.js.map +1 -1
  438. package/dist/src/runtime/emit/key-set-semi-join.d.ts.map +1 -1
  439. package/dist/src/runtime/emit/key-set-semi-join.js +5 -3
  440. package/dist/src/runtime/emit/key-set-semi-join.js.map +1 -1
  441. package/dist/src/runtime/emit/materialized-view-helpers.d.ts +4 -4
  442. package/dist/src/runtime/emit/materialized-view-helpers.d.ts.map +1 -1
  443. package/dist/src/runtime/emit/materialized-view-helpers.js +34 -22
  444. package/dist/src/runtime/emit/materialized-view-helpers.js.map +1 -1
  445. package/dist/src/runtime/emit/materialized-view.d.ts.map +1 -1
  446. package/dist/src/runtime/emit/materialized-view.js +7 -2
  447. package/dist/src/runtime/emit/materialized-view.js.map +1 -1
  448. package/dist/src/runtime/emit/recursive-cte.d.ts.map +1 -1
  449. package/dist/src/runtime/emit/recursive-cte.js +4 -5
  450. package/dist/src/runtime/emit/recursive-cte.js.map +1 -1
  451. package/dist/src/runtime/emit/remote-query.d.ts.map +1 -1
  452. package/dist/src/runtime/emit/remote-query.js +8 -3
  453. package/dist/src/runtime/emit/remote-query.js.map +1 -1
  454. package/dist/src/runtime/emit/scan.d.ts.map +1 -1
  455. package/dist/src/runtime/emit/scan.js +4 -1
  456. package/dist/src/runtime/emit/scan.js.map +1 -1
  457. package/dist/src/runtime/emit/schema-declarative.js +2 -2
  458. package/dist/src/runtime/emit/schema-declarative.js.map +1 -1
  459. package/dist/src/runtime/emit/update.d.ts.map +1 -1
  460. package/dist/src/runtime/emit/update.js +18 -6
  461. package/dist/src/runtime/emit/update.js.map +1 -1
  462. package/dist/src/runtime/parallel-driver.d.ts +4 -3
  463. package/dist/src/runtime/parallel-driver.d.ts.map +1 -1
  464. package/dist/src/runtime/parallel-driver.js +8 -3
  465. package/dist/src/runtime/parallel-driver.js.map +1 -1
  466. package/dist/src/runtime/row-constraints.d.ts +85 -0
  467. package/dist/src/runtime/row-constraints.d.ts.map +1 -0
  468. package/dist/src/runtime/row-constraints.js +239 -0
  469. package/dist/src/runtime/row-constraints.js.map +1 -0
  470. package/dist/src/runtime/types.d.ts +18 -11
  471. package/dist/src/runtime/types.d.ts.map +1 -1
  472. package/dist/src/runtime/types.js.map +1 -1
  473. package/dist/src/runtime/utils.d.ts.map +1 -1
  474. package/dist/src/runtime/utils.js +11 -0
  475. package/dist/src/runtime/utils.js.map +1 -1
  476. package/dist/src/schema/assertion.d.ts +14 -1
  477. package/dist/src/schema/assertion.d.ts.map +1 -1
  478. package/dist/src/schema/assertion.js +14 -1
  479. package/dist/src/schema/assertion.js.map +1 -1
  480. package/dist/src/schema/catalog-persistability.js +19 -3
  481. package/dist/src/schema/catalog-persistability.js.map +1 -1
  482. package/dist/src/schema/catalog.d.ts +6 -0
  483. package/dist/src/schema/catalog.d.ts.map +1 -1
  484. package/dist/src/schema/catalog.js +26 -36
  485. package/dist/src/schema/catalog.js.map +1 -1
  486. package/dist/src/schema/column-source-resolver.d.ts +18 -0
  487. package/dist/src/schema/column-source-resolver.d.ts.map +1 -0
  488. package/dist/src/schema/column-source-resolver.js +22 -0
  489. package/dist/src/schema/column-source-resolver.js.map +1 -0
  490. package/dist/src/schema/constraint-builder.d.ts.map +1 -1
  491. package/dist/src/schema/constraint-builder.js +7 -1
  492. package/dist/src/schema/constraint-builder.js.map +1 -1
  493. package/dist/src/schema/ddl-generator.js +8 -0
  494. package/dist/src/schema/ddl-generator.js.map +1 -1
  495. package/dist/src/schema/lens-compiler.d.ts.map +1 -1
  496. package/dist/src/schema/lens-compiler.js +203 -51
  497. package/dist/src/schema/lens-compiler.js.map +1 -1
  498. package/dist/src/schema/lens-prover.d.ts +2 -3
  499. package/dist/src/schema/lens-prover.d.ts.map +1 -1
  500. package/dist/src/schema/lens-prover.js +19 -11
  501. package/dist/src/schema/lens-prover.js.map +1 -1
  502. package/dist/src/schema/manager.d.ts +30 -12
  503. package/dist/src/schema/manager.d.ts.map +1 -1
  504. package/dist/src/schema/manager.js +49 -17
  505. package/dist/src/schema/manager.js.map +1 -1
  506. package/dist/src/schema/rename-rewriter.d.ts +142 -0
  507. package/dist/src/schema/rename-rewriter.d.ts.map +1 -1
  508. package/dist/src/schema/rename-rewriter.js +254 -9
  509. package/dist/src/schema/rename-rewriter.js.map +1 -1
  510. package/dist/src/schema/reserved-tags.d.ts +1 -1
  511. package/dist/src/schema/reserved-tags.d.ts.map +1 -1
  512. package/dist/src/schema/reserved-tags.js +4 -3
  513. package/dist/src/schema/reserved-tags.js.map +1 -1
  514. package/dist/src/schema/schema-differ.d.ts +16 -0
  515. package/dist/src/schema/schema-differ.d.ts.map +1 -1
  516. package/dist/src/schema/schema-differ.js +122 -11
  517. package/dist/src/schema/schema-differ.js.map +1 -1
  518. package/dist/src/schema/view.d.ts +11 -0
  519. package/dist/src/schema/view.d.ts.map +1 -1
  520. package/dist/src/schema/view.js +12 -0
  521. package/dist/src/schema/view.js.map +1 -1
  522. package/dist/src/types/builtin-types.d.ts +38 -0
  523. package/dist/src/types/builtin-types.d.ts.map +1 -1
  524. package/dist/src/types/builtin-types.js +77 -26
  525. package/dist/src/types/builtin-types.js.map +1 -1
  526. package/dist/src/types/index.d.ts +1 -1
  527. package/dist/src/types/index.d.ts.map +1 -1
  528. package/dist/src/types/index.js +1 -1
  529. package/dist/src/types/index.js.map +1 -1
  530. package/dist/src/util/abort-signal.d.ts +25 -0
  531. package/dist/src/util/abort-signal.d.ts.map +1 -0
  532. package/dist/src/util/abort-signal.js +40 -0
  533. package/dist/src/util/abort-signal.js.map +1 -0
  534. package/dist/src/util/{working-table-iterable.d.ts → array-row-iterable.d.ts} +6 -6
  535. package/dist/src/util/array-row-iterable.d.ts.map +1 -0
  536. package/dist/src/util/{working-table-iterable.js → array-row-iterable.js} +6 -6
  537. package/dist/src/util/array-row-iterable.js.map +1 -0
  538. package/dist/src/vtab/concurrency.d.ts +15 -0
  539. package/dist/src/vtab/concurrency.d.ts.map +1 -1
  540. package/dist/src/vtab/concurrency.js +17 -0
  541. package/dist/src/vtab/concurrency.js.map +1 -1
  542. package/dist/src/vtab/events.d.ts +3 -0
  543. package/dist/src/vtab/events.d.ts.map +1 -1
  544. package/dist/src/vtab/events.js.map +1 -1
  545. package/dist/src/vtab/manifest.d.ts +15 -0
  546. package/dist/src/vtab/manifest.d.ts.map +1 -1
  547. package/dist/src/vtab/memory/layer/base.d.ts +10 -0
  548. package/dist/src/vtab/memory/layer/base.d.ts.map +1 -1
  549. package/dist/src/vtab/memory/layer/base.js +10 -0
  550. package/dist/src/vtab/memory/layer/base.js.map +1 -1
  551. package/dist/src/vtab/memory/layer/interface.d.ts +24 -0
  552. package/dist/src/vtab/memory/layer/interface.d.ts.map +1 -1
  553. package/dist/src/vtab/memory/layer/manager.d.ts +21 -3
  554. package/dist/src/vtab/memory/layer/manager.d.ts.map +1 -1
  555. package/dist/src/vtab/memory/layer/manager.js +107 -157
  556. package/dist/src/vtab/memory/layer/manager.js.map +1 -1
  557. package/dist/src/vtab/memory/layer/transaction.d.ts +11 -0
  558. package/dist/src/vtab/memory/layer/transaction.d.ts.map +1 -1
  559. package/dist/src/vtab/memory/layer/transaction.js +19 -0
  560. package/dist/src/vtab/memory/layer/transaction.js.map +1 -1
  561. package/dist/src/vtab/memory/module.d.ts +57 -1
  562. package/dist/src/vtab/memory/module.d.ts.map +1 -1
  563. package/dist/src/vtab/memory/module.js +103 -2
  564. package/dist/src/vtab/memory/module.js.map +1 -1
  565. package/dist/src/vtab/memory/table.d.ts +12 -1
  566. package/dist/src/vtab/memory/table.d.ts.map +1 -1
  567. package/dist/src/vtab/memory/table.js +12 -1
  568. package/dist/src/vtab/memory/table.js.map +1 -1
  569. package/dist/src/vtab/module.d.ts +59 -2
  570. package/dist/src/vtab/module.d.ts.map +1 -1
  571. package/dist/src/vtab/table.d.ts +8 -1
  572. package/dist/src/vtab/table.d.ts.map +1 -1
  573. package/dist/src/vtab/table.js.map +1 -1
  574. package/dist/src/vtab/test-support/commit-stall.d.ts +53 -0
  575. package/dist/src/vtab/test-support/commit-stall.d.ts.map +1 -0
  576. package/dist/src/vtab/test-support/commit-stall.js +73 -0
  577. package/dist/src/vtab/test-support/commit-stall.js.map +1 -0
  578. package/dist/src/vtab/test-support/committed-read-conformance.d.ts +96 -0
  579. package/dist/src/vtab/test-support/committed-read-conformance.d.ts.map +1 -0
  580. package/dist/src/vtab/test-support/committed-read-conformance.js +364 -0
  581. package/dist/src/vtab/test-support/committed-read-conformance.js.map +1 -0
  582. package/package.json +3 -3
  583. package/dist/src/util/working-table-iterable.d.ts.map +0 -1
  584. package/dist/src/util/working-table-iterable.js.map +0 -1
@@ -0,0 +1,69 @@
1
+ import type { PlanningContext } from '../planning-context.js';
2
+ /**
3
+ * The planning context any SCHEMA-AUTHORED expression must be built on — a column
4
+ * `DEFAULT`, a generated-column expression, a `CHECK` constraint, or a synthesized
5
+ * foreign-key probe. All four are written in the TABLE's definition, not in the
6
+ * statement doing the write, so their unqualified relation names must always mean
7
+ * real schema objects, and must mean the SAME ones no matter where the writing
8
+ * statement happens to be pointed. `schemaName` is the OWNING table's schema (for the
9
+ * anchor key default on a view write-through, the anchor BASE table's schema — not
10
+ * the view's).
11
+ *
12
+ * Clears the two CTE-related fields so no statement's common table expressions — the
13
+ * writing statement's own leading `with` clause, or ones it inherited from an enclosing
14
+ * statement — can shadow a real table out from under someone else's DDL:
15
+ *
16
+ * - `cteNodes` → cleared, so `default (select count(*) from c)` keeps meaning the
17
+ * real table `c` even under `with c as (…) insert into t …`. Clearing on the
18
+ * CONTEXT is what closes it: `buildWithContext` seeds its map from `ctx.cteNodes`
19
+ * and prefers a non-empty explicit `parentCTEs` argument over it, so handing an
20
+ * empty map downstream is not sufficient.
21
+ * - `cteReferenceCache` → cleared for the same reason
22
+ * {@link import('../stored-body-context.js').storedBodyContext} clears it: the cache
23
+ * is keyed on bare `cteName:alias`, so a caller definition and one declared inside a
24
+ * `check` subquery's own `with` clause would collide on a single entry and the
25
+ * schema-authored SQL would read the caller's relation.
26
+ *
27
+ * And narrows the schema search path:
28
+ *
29
+ * - `schemaPath` → `[schemaName]` exactly, the owning schema ONLY with no fallback to
30
+ * the session default path. So `default (select count(*) from c)` on a `temp` table
31
+ * means `temp.c` whatever schema path the writing statement carries (the session
32
+ * `pragma schema_path`, or a per-statement `insert … with schema …`). This is the
33
+ * single place that decides it, for all four expression kinds — the constraint and
34
+ * foreign-key builders used to narrow themselves, which is exactly why a table's
35
+ * `check` and its column `default` could disagree about the same bare name. It is
36
+ * deliberately stricter than a stored view body's `Database._homeSchemaPath()` (home
37
+ * schema first, then the session default path): a schema-authored expression that
38
+ * names a relation in another schema must qualify it. See docs/schema.md.
39
+ *
40
+ * It deliberately does NOT touch:
41
+ *
42
+ * - `scope` — `buildWithContext` contributes CTE *definitions* only, never scope
43
+ * symbols, so the scope is not a leak channel. `building/update.ts` and
44
+ * `building/delete.ts` must keep their table scope for `new.` / `old.` resolution,
45
+ * so this is applied ON TOP of those contexts rather than instead of them.
46
+ * - `storedBodyOf` — these expressions are built INLINE in the caller's statement,
47
+ * not as a re-entered stored body. Setting it would wrongly make a
48
+ * {@link import('../../parser/ast.js').StoredBodyEnv} marker inert.
49
+ *
50
+ * Sibling of {@link import('../stored-body-context.js').storedBodyContext}, which does
51
+ * the same job for the other kind of stored, schema-authored SQL: view and
52
+ * materialized-view bodies. That one isolates the WHOLE naming environment (home
53
+ * schema path, stored-body marker) because a body is re-entered as its own plan; this
54
+ * one keeps the caller's scope because these expressions stay inline.
55
+ *
56
+ * NOTE: this helper covers every schema-authored expression that is BUILT — but two
57
+ * CHECK-enforcement paths re-prepare the constraint's own SQL text as a whole statement
58
+ * instead, so they never reach a planning context and pin the same `[schemaName]` path on
59
+ * the {@link import('../../core/statement.js').Statement} directly:
60
+ * `validateBackfillAgainstChecks` (`runtime/emit/alter-table.ts`, ADD COLUMN over existing
61
+ * rows) and `validateChecksOverExistingRows` (`schema/constraint-builder.ts`, maintained
62
+ * tables). Two spellings of one rule is tolerable at two sites; if a third appears, give
63
+ * the statement seam its own helper rather than a fourth copy.
64
+ *
65
+ * @param schemaName the owning table's schema name — REQUIRED, so no call site can
66
+ * silently inherit the writing statement's path.
67
+ */
68
+ export declare function schemaAuthoredContext(ctx: PlanningContext, schemaName: string): PlanningContext;
69
+ //# sourceMappingURL=schema-authored-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-authored-context.d.ts","sourceRoot":"","sources":["../../../../src/planner/building/schema-authored-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,GAAG,eAAe,CAM/F"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * The planning context any SCHEMA-AUTHORED expression must be built on — a column
3
+ * `DEFAULT`, a generated-column expression, a `CHECK` constraint, or a synthesized
4
+ * foreign-key probe. All four are written in the TABLE's definition, not in the
5
+ * statement doing the write, so their unqualified relation names must always mean
6
+ * real schema objects, and must mean the SAME ones no matter where the writing
7
+ * statement happens to be pointed. `schemaName` is the OWNING table's schema (for the
8
+ * anchor key default on a view write-through, the anchor BASE table's schema — not
9
+ * the view's).
10
+ *
11
+ * Clears the two CTE-related fields so no statement's common table expressions — the
12
+ * writing statement's own leading `with` clause, or ones it inherited from an enclosing
13
+ * statement — can shadow a real table out from under someone else's DDL:
14
+ *
15
+ * - `cteNodes` → cleared, so `default (select count(*) from c)` keeps meaning the
16
+ * real table `c` even under `with c as (…) insert into t …`. Clearing on the
17
+ * CONTEXT is what closes it: `buildWithContext` seeds its map from `ctx.cteNodes`
18
+ * and prefers a non-empty explicit `parentCTEs` argument over it, so handing an
19
+ * empty map downstream is not sufficient.
20
+ * - `cteReferenceCache` → cleared for the same reason
21
+ * {@link import('../stored-body-context.js').storedBodyContext} clears it: the cache
22
+ * is keyed on bare `cteName:alias`, so a caller definition and one declared inside a
23
+ * `check` subquery's own `with` clause would collide on a single entry and the
24
+ * schema-authored SQL would read the caller's relation.
25
+ *
26
+ * And narrows the schema search path:
27
+ *
28
+ * - `schemaPath` → `[schemaName]` exactly, the owning schema ONLY with no fallback to
29
+ * the session default path. So `default (select count(*) from c)` on a `temp` table
30
+ * means `temp.c` whatever schema path the writing statement carries (the session
31
+ * `pragma schema_path`, or a per-statement `insert … with schema …`). This is the
32
+ * single place that decides it, for all four expression kinds — the constraint and
33
+ * foreign-key builders used to narrow themselves, which is exactly why a table's
34
+ * `check` and its column `default` could disagree about the same bare name. It is
35
+ * deliberately stricter than a stored view body's `Database._homeSchemaPath()` (home
36
+ * schema first, then the session default path): a schema-authored expression that
37
+ * names a relation in another schema must qualify it. See docs/schema.md.
38
+ *
39
+ * It deliberately does NOT touch:
40
+ *
41
+ * - `scope` — `buildWithContext` contributes CTE *definitions* only, never scope
42
+ * symbols, so the scope is not a leak channel. `building/update.ts` and
43
+ * `building/delete.ts` must keep their table scope for `new.` / `old.` resolution,
44
+ * so this is applied ON TOP of those contexts rather than instead of them.
45
+ * - `storedBodyOf` — these expressions are built INLINE in the caller's statement,
46
+ * not as a re-entered stored body. Setting it would wrongly make a
47
+ * {@link import('../../parser/ast.js').StoredBodyEnv} marker inert.
48
+ *
49
+ * Sibling of {@link import('../stored-body-context.js').storedBodyContext}, which does
50
+ * the same job for the other kind of stored, schema-authored SQL: view and
51
+ * materialized-view bodies. That one isolates the WHOLE naming environment (home
52
+ * schema path, stored-body marker) because a body is re-entered as its own plan; this
53
+ * one keeps the caller's scope because these expressions stay inline.
54
+ *
55
+ * NOTE: this helper covers every schema-authored expression that is BUILT — but two
56
+ * CHECK-enforcement paths re-prepare the constraint's own SQL text as a whole statement
57
+ * instead, so they never reach a planning context and pin the same `[schemaName]` path on
58
+ * the {@link import('../../core/statement.js').Statement} directly:
59
+ * `validateBackfillAgainstChecks` (`runtime/emit/alter-table.ts`, ADD COLUMN over existing
60
+ * rows) and `validateChecksOverExistingRows` (`schema/constraint-builder.ts`, maintained
61
+ * tables). Two spellings of one rule is tolerable at two sites; if a third appears, give
62
+ * the statement seam its own helper rather than a fourth copy.
63
+ *
64
+ * @param schemaName the owning table's schema name — REQUIRED, so no call site can
65
+ * silently inherit the writing statement's path.
66
+ */
67
+ export function schemaAuthoredContext(ctx, schemaName) {
68
+ // Identity fast-path only when nothing would actually change: the CTE namespace is
69
+ // already empty AND the path is already exactly the owning schema.
70
+ if (!ctx.cteNodes && !ctx.cteReferenceCache
71
+ && ctx.schemaPath?.length === 1 && ctx.schemaPath[0] === schemaName)
72
+ return ctx;
73
+ return { ...ctx, cteNodes: undefined, cteReferenceCache: undefined, schemaPath: [schemaName] };
74
+ }
75
+ //# sourceMappingURL=schema-authored-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-authored-context.js","sourceRoot":"","sources":["../../../../src/planner/building/schema-authored-context.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAoB,EAAE,UAAkB;IAC7E,mFAAmF;IACnF,mEAAmE;IACnE,IAAI,CAAC,GAAG,CAAC,QAAQ,IAAI,CAAC,GAAG,CAAC,iBAAiB;WACvC,GAAG,CAAC,UAAU,EAAE,MAAM,KAAK,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,UAAU;QAAE,OAAO,GAAG,CAAC;IACjF,OAAO,EAAE,GAAG,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,iBAAiB,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC;AAChG,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"schema-resolution.d.ts","sourceRoot":"","sources":["../../../../src/planner/building/schema-resolution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAoB,MAAM,wBAAwB,CAAC;AAChF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAOlE,8EAA8E;AAC9E,eAAO,MAAM,gBAAgB,cAAc,CAAC;AAE5C,mEAAmE;AACnE,wBAAgB,oBAAoB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAEjE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CACjC,GAAG,EAAE,eAAe,EACpB,SAAS,EAAE,MAAM,EACjB,UAAU,CAAC,EAAE,MAAM,GACjB,WAAW,CA6Fb;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACpC,GAAG,EAAE,eAAe,EACpB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACb,cAAc,CAqChB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAChC,GAAG,EAAE,eAAe,EACpB,UAAU,EAAE,MAAM,GAChB;IAAE,MAAM,EAAE,qBAAqB,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CA+BtD;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC/B,GAAG,EAAE,eAAe,EACpB,aAAa,EAAE,MAAM,GACnB,iBAAiB,CAwBnB"}
1
+ {"version":3,"file":"schema-resolution.d.ts","sourceRoot":"","sources":["../../../../src/planner/building/schema-resolution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAoB,MAAM,wBAAwB,CAAC;AAChF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAOlE,8EAA8E;AAC9E,eAAO,MAAM,gBAAgB,cAAc,CAAC;AAE5C,mEAAmE;AACnE,wBAAgB,oBAAoB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAEjE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CACjC,GAAG,EAAE,eAAe,EACpB,SAAS,EAAE,MAAM,EACjB,UAAU,CAAC,EAAE,MAAM,GACjB,WAAW,CA+Fb;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACpC,GAAG,EAAE,eAAe,EACpB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACb,cAAc,CAqChB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAChC,GAAG,EAAE,eAAe,EACpB,UAAU,EAAE,MAAM,GAChB;IAAE,MAAM,EAAE,qBAAqB,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CA+BtD;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC/B,GAAG,EAAE,eAAe,EACpB,aAAa,EAAE,MAAM,GACnB,iBAAiB,CAwBnB"}
@@ -1,4 +1,4 @@
1
- import { QuereusError } from '../../common/errors.js';
1
+ import { QuereusError, RelationNotFoundError } from '../../common/errors.js';
2
2
  import { StatusCode } from '../../common/types.js';
3
3
  import { createLogger } from '../../common/logger.js';
4
4
  const log = createLogger('planner:schema-resolution');
@@ -29,7 +29,8 @@ export function resolveTableSchema(ctx, tableName, schemaName) {
29
29
  // Resolve table schema with explicit schema name
30
30
  const tableSchema = ctx.schemaManager.findTable(tableName, resolvedSchemaName);
31
31
  if (!tableSchema) {
32
- throw new QuereusError(`Table not found: ${resolvedSchemaName}.${tableName}`, StatusCode.ERROR);
32
+ // Message text is asserted on by the sqllogic suites — keep it byte-identical.
33
+ throw new RelationNotFoundError(`Table not found: ${resolvedSchemaName}.${tableName}`);
33
34
  }
34
35
  // Record dependency
35
36
  const dependency = {
@@ -60,7 +61,9 @@ export function resolveTableSchema(ctx, tableName, schemaName) {
60
61
  if (!tableSchema) {
61
62
  // Generate helpful error message
62
63
  const searchedSchemas = schemaPath || ['main', 'temp'];
63
- const existsIn = ctx.schemaManager.findSchemasContainingTable(tableName);
64
+ // Views count here: an unqualified name resolves through the path across
65
+ // tables and views alike, so an off-path VIEW is exactly as suggestible.
66
+ const existsIn = ctx.schemaManager.findSchemasContainingRelation(tableName);
64
67
  let errorMsg = `Table '${tableName}' not found in schema path: ${searchedSchemas.join(', ')}`;
65
68
  if (existsIn.length > 0) {
66
69
  // Table exists in other schemas - suggest qualified name
@@ -74,7 +77,7 @@ export function resolveTableSchema(ctx, tableName, schemaName) {
74
77
  errorMsg += `\n Or add '${existsIn[0]}' to your WITH SCHEMA clause`;
75
78
  }
76
79
  }
77
- throw new QuereusError(errorMsg, StatusCode.ERROR);
80
+ throw new RelationNotFoundError(errorMsg);
78
81
  }
79
82
  // Record dependency
80
83
  const dependency = {
@@ -1 +1 @@
1
- {"version":3,"file":"schema-resolution.js","sourceRoot":"","sources":["../../../../src/planner/building/schema-resolution.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,MAAM,GAAG,GAAG,YAAY,CAAC,2BAA2B,CAAC,CAAC;AAEtD,8EAA8E;AAC9E,MAAM,CAAC,MAAM,gBAAgB,GAAG,WAAW,CAAC;AAE5C,mEAAmE;AACnE,MAAM,UAAU,oBAAoB,CAAC,UAAmB;IACvD,OAAO,UAAU,EAAE,WAAW,EAAE,KAAK,gBAAgB,CAAC;AACvD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CACjC,GAAoB,EACpB,SAAiB,EACjB,UAAmB;IAEnB,uFAAuF;IACvF,IAAI,oBAAoB,CAAC,UAAU,CAAC,EAAE,CAAC;QACtC,OAAO,kBAAkB,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC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,CAAC;IAED,oBAAoB;IACpB,MAAM,UAAU,GAAqB;QACpC,IAAI,EAAE,aAAa;QACnB,UAAU,EAAE,UAAU;KACtB,CAAC;IACF,GAAG,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAEhE,eAAe;IACf,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IAE1C,GAAG,CAAC,0BAA0B,EAAE,UAAU,CAAC,CAAC;IAC5C,OAAO,UAAU,CAAC;AACnB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC/B,GAAoB,EACpB,aAAqB;IAErB,MAAM,QAAQ,GAAG,aAAa,aAAa,EAAE,CAAC;IAE9C,oBAAoB;IACpB,MAAM,MAAM,GAAG,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC7C,IAAI,MAAM,EAAE,CAAC;QACZ,GAAG,CAAC,4BAA4B,EAAE,aAAa,CAAC,CAAC;QACjD,OAAO,MAA2B,CAAC;IACpC,CAAC;IAED,MAAM,SAAS,GAAG,GAAG,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,aAAa,CAAC,CAAC;IAE/D,oBAAoB;IACpB,MAAM,UAAU,GAAqB;QACpC,IAAI,EAAE,WAAW;QACjB,UAAU,EAAE,aAAa;KACzB,CAAC;IACF,GAAG,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;IAE/D,eAAe;IACf,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAEzC,GAAG,CAAC,wBAAwB,EAAE,aAAa,CAAC,CAAC;IAC7C,OAAO,SAAS,CAAC;AAClB,CAAC"}
1
+ {"version":3,"file":"schema-resolution.js","sourceRoot":"","sources":["../../../../src/planner/building/schema-resolution.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAA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4B,EAAE,aAAa,CAAC,CAAC;QACjD,OAAO,MAA2B,CAAC;IACpC,CAAC;IAED,MAAM,SAAS,GAAG,GAAG,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,aAAa,CAAC,CAAC;IAE/D,oBAAoB;IACpB,MAAM,UAAU,GAAqB;QACpC,IAAI,EAAE,WAAW;QACjB,UAAU,EAAE,aAAa;KACzB,CAAC;IACF,GAAG,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;IAE/D,eAAe;IACf,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAEzC,GAAG,CAAC,wBAAwB,EAAE,aAAa,CAAC,CAAC;IAC7C,OAAO,SAAS,CAAC;AAClB,CAAC"}
@@ -1,15 +1,17 @@
1
1
  import type * as AST from '../../parser/ast.js';
2
- import { type RelationalPlanNode, type ScalarPlanNode } from '../nodes/plan-node.js';
2
+ import { type Attribute, type PlanNode, type RelationalPlanNode, type ScalarPlanNode } from '../nodes/plan-node.js';
3
3
  import type { PlanningContext } from '../planning-context.js';
4
4
  import { type Projection } from '../nodes/project-node.js';
5
5
  import { RegisteredScope } from '../scopes/registered.js';
6
+ import type { Scope } from '../scopes/scope.js';
7
+ import { type SelectListEntry } from './select-ordinal.js';
6
8
  /**
7
9
  * Processes GROUP BY, aggregates, and HAVING clauses
8
10
  */
9
11
  export declare function buildAggregatePhase(input: RelationalPlanNode, stmt: AST.SelectStmt, selectContext: PlanningContext, aggregates: {
10
12
  expression: ScalarPlanNode;
11
13
  alias: string;
12
- }[], hasAggregates: boolean, projections: Projection[], hasWrappedAggregates?: boolean, selectListAsts?: AST.Expression[]): {
14
+ }[], hasAggregates: boolean, projections: Projection[], hasWrappedAggregates?: boolean, selectList?: readonly SelectListEntry[], starProjectionsByColumn?: ReadonlyMap<AST.ResultColumn, readonly Projection[]>): {
13
15
  output: RelationalPlanNode;
14
16
  aggregateScope?: RegisteredScope;
15
17
  needsFinalProjection: boolean;
@@ -21,6 +23,189 @@ export declare function buildAggregatePhase(input: RelationalPlanNode, stmt: AST
21
23
  orderByHasAggregates?: boolean;
22
24
  aggregatesContext?: PlanningContext['aggregates'];
23
25
  };
26
+ /**
27
+ * What a grouped query's rows are allowed to expose: the attribute ids reachable
28
+ * after aggregation, plus the canonical AST strings of the GROUP BY expressions
29
+ * themselves.
30
+ *
31
+ * Two flavours of attribute id are legal, and both matter depending on where the
32
+ * expression being checked was built. An expression built against the
33
+ * *pre-aggregate* scope (the SELECT list, before the final projection) names base
34
+ * source attributes, so the ids of the GROUP BY key expressions cover it. A HAVING
35
+ * predicate resolves through a hybrid scope and may name either the AggregateNode's
36
+ * own output attributes or, via the source-column fallback, base ones — so the
37
+ * output ids must be admitted too, passed in `groupedOutputAttributes`.
38
+ *
39
+ * The window phase of a grouped query has its own check
40
+ * ({@link assertGroupedWindowCoverage}); it needs to descend into subqueries and to
41
+ * tell a correlated reference from an ungrouped local one, neither of which this
42
+ * coverage set can express.
43
+ *
44
+ * The fingerprint set covers whole grouped subtrees (`select id+1 … group by
45
+ * id+1`) and, incidentally, the qualifier mismatch between `group by t.a` and a
46
+ * later bare `a`. Fingerprints fold identifier case (see
47
+ * {@link expressionToIdentityString}), so `group by A || '!'` covers a later
48
+ * `a || '!'`; quoted literals stay byte-exact, so `a || 'X'` does not.
49
+ */
50
+ export interface GroupByCoverage {
51
+ readonly attrIds: ReadonlySet<number>;
52
+ readonly fingerprints: ReadonlySet<string>;
53
+ }
54
+ /**
55
+ * Builds the coverage test for a grouped query. `groupedOutputAttributes` is the
56
+ * AggregateNode's output attributes (group keys followed by aggregate results),
57
+ * needed only when the expressions to be checked were built against the aggregate
58
+ * output scope.
59
+ */
60
+ export declare function buildGroupByCoverage(groupByExpressions: readonly ScalarPlanNode[], groupedOutputAttributes?: readonly Attribute[]): GroupByCoverage;
61
+ /**
62
+ * Raises the standard GROUP BY coverage error when `node` reads a column the
63
+ * grouped rows do not carry. Used by the SELECT-list check below; the window
64
+ * phase raises the same message from {@link assertGroupedWindowCoverage}.
65
+ */
66
+ export declare function assertGroupByCoverage(node: PlanNode, coverage: GroupByCoverage): void;
67
+ /**
68
+ * What the window phase of a GROUPED query needs in order to run its window
69
+ * specifications and function arguments over the AggregateNode's own rows.
70
+ *
71
+ * The WindowNode sits ABOVE the AggregateNode, so it can read only what the
72
+ * aggregate's output row carries: the grouping keys and the aggregate results.
73
+ * But the scope those expressions are built against falls through to the
74
+ * pre-aggregate select scope, so several perfectly legal spellings of a grouping
75
+ * key (`wg.a` against `group by a`, or the whole `a || '!'` against `group by a
76
+ * || '!'`) bind to a *base-table* attribute the aggregate row never had. This
77
+ * context supplies both halves of the answer: the two maps let
78
+ * {@link redirectToGroupKeys} rewrite such a subtree onto the aggregate's own
79
+ * output column, and the two attribute-id sets let
80
+ * {@link assertGroupedWindowCoverage} reject what survives.
81
+ */
82
+ export interface GroupedWindowContext {
83
+ /** Where each GROUP BY key lives on the AggregateNode's output row. */
84
+ readonly groupKeys: GroupKeyIndex;
85
+ /** AggregateNode output attributes: group keys in GROUP BY order, then aggregate results. */
86
+ readonly outputAttributes: readonly Attribute[];
87
+ /**
88
+ * Every attribute id the AggregateNode's input subtree produces and this query can
89
+ * name — exactly "the columns this grouped query could have read before it grouped".
90
+ * CTE definition bodies are excluded; see {@link isCteDefinition}.
91
+ *
92
+ * This is what tells a reference belonging to THIS query apart from one that does
93
+ * not, at any nesting depth. A window specification may contain a subquery, and
94
+ * inside it live two unrelated kinds of column reference: the subquery's own
95
+ * columns and correlated references pointing back out. Attribute ids are minted
96
+ * per relation instance, so a subquery's own `wg t` scan and the outer `wg` scan
97
+ * never share one — membership here separates them exactly. A reference NOT in
98
+ * this set is the subquery's own column or a reference to an ENCLOSING query, and
99
+ * is none of the window phase's business either way.
100
+ */
101
+ readonly aggregateInputAttrIds: ReadonlySet<number>;
102
+ /**
103
+ * Legal AFTER redirection: AggregateNode output attribute ids ONLY. Once
104
+ * {@link redirectToGroupKeys} has run, an aggregate-input attribute id still
105
+ * present anywhere in a window expression is an ungrouped reference.
106
+ */
107
+ readonly outputAttrIds: ReadonlySet<number>;
108
+ }
109
+ /**
110
+ * Locates each GROUP BY key on the AggregateNode's output row, under both spellings a
111
+ * later expression may reach it by: the whole grouped expression written out again, or
112
+ * (for a bare-column key) the base column under any qualifier.
113
+ *
114
+ * Shared by the window phase's {@link redirectToGroupKeys} and by the select list's
115
+ * {@link buildFinalAggregateProjections}, which resolve the same question about
116
+ * different expressions.
117
+ */
118
+ export interface GroupKeyIndex {
119
+ /** Identity fingerprint of each GROUP BY expression → its output column index. */
120
+ readonly byFingerprint: ReadonlyMap<string, number>;
121
+ /** Base attribute id of each bare-column GROUP BY key → its output column index. */
122
+ readonly byBaseAttrId: ReadonlyMap<number, number>;
123
+ }
124
+ /**
125
+ * Builds the {@link GroupKeyIndex} for a grouped query's GROUP BY list. The output
126
+ * column index is the key's position in that list, which is its position on the
127
+ * AggregateNode's output row.
128
+ */
129
+ export declare function indexGroupKeys(groupByExpressions: readonly ScalarPlanNode[]): GroupKeyIndex;
130
+ /**
131
+ * Builds the {@link GroupedWindowContext} for a grouped, windowed query.
132
+ * `outputAttributes` is the AggregateNode's attribute list (group keys in GROUP BY
133
+ * order, then the aggregate results); `aggregateInput` is the AggregateNode's
134
+ * source relation, whose whole subtree defines
135
+ * {@link GroupedWindowContext.aggregateInputAttrIds}.
136
+ */
137
+ export declare function buildGroupedWindowContext(groupByExpressions: readonly ScalarPlanNode[], outputAttributes: readonly Attribute[], aggregateInput: PlanNode): GroupedWindowContext;
138
+ /**
139
+ * Rewrites every subtree of a window specification / window-function argument that
140
+ * IS a grouping key into a reference to the AggregateNode's output column for that
141
+ * key, so the expression reads the grouped row instead of a base-table column that
142
+ * row does not carry.
143
+ *
144
+ * Two match rules, in order at each node:
145
+ *
146
+ * 1. The whole subtree's identity fingerprint equals a GROUP BY expression's — covers
147
+ * `group by a || '!'` + `over (order by a || '!')`, and nested occurrences such
148
+ * as `over (order by upper(a || '!'))` because the walk recurses. Identifier case
149
+ * is folded, so `group by A || '!'` matches too; quoted literals are byte-exact,
150
+ * so `a || 'X'` and `a || 'x'` remain different keys.
151
+ *
152
+ * Unconditional above any subquery, where the expression is written in this query's
153
+ * own scope. INSIDE a subquery it is guarded by {@link readsOnlyAggregateInput} —
154
+ * every column reference in the subtree must be a pre-grouping column of THIS query
155
+ * — because there the same text can name something else entirely: under `group by
156
+ * a`, a bare `a` written inside `over (order by (select … where t.a = a))` names the
157
+ * subquery's own `t.a` and yet fingerprints as `a`, so an unguarded rule 1 would
158
+ * silently rewrite it into the outer group column and change what the query means.
159
+ * The guard cannot replace the top-level case: `group by (select max(t.b) from wg t
160
+ * where t.a = wg.a)` repeated verbatim in the specification is a legal grouping key
161
+ * whose subtree also reads the subquery's own columns.
162
+ * 2. The node is a column reference whose attribute id is the *base* attribute id of
163
+ * a bare-column grouping key — covers `group by a` + `over (order by wg.a)` and
164
+ * `over (order by w.a)`. Both spellings fall through to the same base attribute
165
+ * the group key was built from, so the match is qualifier-independent. It needs no
166
+ * guard at any depth: attribute ids are minted per relation instance, so only a
167
+ * reference that genuinely resolves to this query's grouping column can match.
168
+ *
169
+ * Otherwise recurse into every child, relational ones included, rebuilding through
170
+ * `withChildren` — a correlated reference to a grouping key can live arbitrarily deep
171
+ * inside a subquery in the window specification, and it must be redirected there too
172
+ * or it reaches the runtime as a base-table attribute the grouped row never carried.
173
+ *
174
+ * NOTE: rule 1 matches by AST text, so a subtree that *reads* like a grouping key but
175
+ * resolves to something else could be redirected wrongly. Within one query the guard
176
+ * above closes that off; the residue is a subtree of ENCLOSING-query references that
177
+ * happens to spell a grouping key (`group by a` in an inner query whose window spec
178
+ * says `outer_alias.a`… only when that fingerprints identically). This is the same
179
+ * limitation the select list already carries through the shared {@link GroupKeyIndex};
180
+ * fixing it means comparing resolved attribute identity rather than text, for both
181
+ * callers at once.
182
+ */
183
+ export declare function redirectToGroupKeys(node: ScalarPlanNode, context: GroupedWindowContext, scope: Scope): ScalarPlanNode;
184
+ /**
185
+ * Raises the GROUP BY coverage error for a window specification / window-function
186
+ * argument of a GROUPED query that still reads a pre-grouping column after
187
+ * {@link redirectToGroupKeys} has run.
188
+ *
189
+ * Distinct from {@link assertGroupByCoverage} in exactly two ways, both required by
190
+ * the fact that a window expression may contain a subquery:
191
+ *
192
+ * - it descends into relational children, so a correlated reference buried in a
193
+ * subquery is checked rather than skipped;
194
+ * - it flags a column reference only when the attribute id is one of THIS query's
195
+ * pre-grouping columns. A reference to anything else — the subquery's own columns,
196
+ * or a correlated reference to an enclosing query — is legal here and is left alone.
197
+ *
198
+ * The aggregate exemption is likewise narrowed to this query's OWN aggregates; see
199
+ * {@link findUngroupedWindowColumnRef}.
200
+ */
201
+ export declare function assertGroupedWindowCoverage(node: PlanNode, context: GroupedWindowContext): void;
202
+ /**
203
+ * Every aggregate function call inside an AST expression, in source order.
204
+ * Does not descend into an aggregate's own arguments (nested aggregates are
205
+ * invalid SQL). Exported for callers that need to *inspect* the aggregates in a
206
+ * clause rather than collect them into the AggregateNode.
207
+ */
208
+ export declare function collectAggregateFunctionExprs(expr: AST.Expression, ctx: PlanningContext): AST.FunctionExpr[];
24
209
  /**
25
210
  * Builds final projections for the complete SELECT list in aggregate context
26
211
  */
@@ -1 +1 @@
1
- {"version":3,"file":"select-aggregates.d.ts","sourceRoot":"","sources":["../../../../src/planner/building/select-aggregates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAmD,KAAK,kBAAkB,EAAE,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACtI,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAI9D,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAc1D;;GAEG;AACH,wBAAgB,mBAAmB,CAClC,KAAK,EAAE,kBAAkB,EACzB,IAAI,EAAE,GAAG,CAAC,UAAU,EACpB,aAAa,EAAE,eAAe,EAC9B,UAAU,EAAE;IAAE,UAAU,EAAE,cAAc,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAAE,EAC3D,aAAa,EAAE,OAAO,EACtB,WAAW,EAAE,UAAU,EAAE,EACzB,oBAAoB,GAAE,OAAe,EACrC,cAAc,GAAE,GAAG,CAAC,UAAU,EAAO,GACnC;IACF,MAAM,EAAE,kBAAkB,CAAC;IAC3B,cAAc,CAAC,EAAE,eAAe,CAAC;IACjC,oBAAoB,EAAE,OAAO,CAAC;IAC9B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,aAAa,CAAC,EAAE,kBAAkB,CAAC;IACnC,kBAAkB,CAAC,EAAE,cAAc,EAAE,CAAC;IACtC,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,iBAAiB,CAAC,EAAE,eAAe,CAAC,YAAY,CAAC,CAAC;CAClD,CA6IA;AAueD;;GAEG;AACH,wBAAgB,8BAA8B,CAC7C,IAAI,EAAE,GAAG,CAAC,UAAU,EACpB,aAAa,EAAE,eAAe,EAC9B,oBAAoB,EAAE,eAAe,EACrC,aAAa,EAAE,kBAAkB,EACjC,UAAU,EAAE;IAAE,UAAU,EAAE,cAAc,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAAE,EAC3D,kBAAkB,EAAE,cAAc,EAAE,EACpC,uBAAuB,GAAE,WAAW,CAAC,GAAG,CAAC,YAAY,EAAE,SAAS,UAAU,EAAE,CAAa,GACvF,UAAU,EAAE,CAyGd"}
1
+ {"version":3,"file":"select-aggregates.d.ts","sourceRoot":"","sources":["../../../../src/planner/building/select-aggregates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,qBA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