@quereus/quereus 4.11.0 → 4.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (451) hide show
  1. package/dist/src/common/type-inference.d.ts +12 -6
  2. package/dist/src/common/type-inference.d.ts.map +1 -1
  3. package/dist/src/common/type-inference.js +12 -24
  4. package/dist/src/common/type-inference.js.map +1 -1
  5. package/dist/src/core/database-assertions.d.ts.map +1 -1
  6. package/dist/src/core/database-assertions.js +7 -5
  7. package/dist/src/core/database-assertions.js.map +1 -1
  8. package/dist/src/core/database-events.d.ts +4 -3
  9. package/dist/src/core/database-events.d.ts.map +1 -1
  10. package/dist/src/core/database-events.js +4 -3
  11. package/dist/src/core/database-events.js.map +1 -1
  12. package/dist/src/core/database-materialized-views-analysis.d.ts +1 -3
  13. package/dist/src/core/database-materialized-views-analysis.d.ts.map +1 -1
  14. package/dist/src/core/database-materialized-views-analysis.js +1 -11
  15. package/dist/src/core/database-materialized-views-analysis.js.map +1 -1
  16. package/dist/src/core/database-materialized-views-plan-builders.d.ts.map +1 -1
  17. package/dist/src/core/database-materialized-views-plan-builders.js +12 -10
  18. package/dist/src/core/database-materialized-views-plan-builders.js.map +1 -1
  19. package/dist/src/core/database.d.ts.map +1 -1
  20. package/dist/src/core/database.js +13 -2
  21. package/dist/src/core/database.js.map +1 -1
  22. package/dist/src/core/derived-row-validator.d.ts.map +1 -1
  23. package/dist/src/core/derived-row-validator.js +14 -2
  24. package/dist/src/core/derived-row-validator.js.map +1 -1
  25. package/dist/src/core/param.d.ts +9 -0
  26. package/dist/src/core/param.d.ts.map +1 -1
  27. package/dist/src/core/param.js +21 -1
  28. package/dist/src/core/param.js.map +1 -1
  29. package/dist/src/core/statement.d.ts.map +1 -1
  30. package/dist/src/core/statement.js +38 -15
  31. package/dist/src/core/statement.js.map +1 -1
  32. package/dist/src/func/builtins/aggregate.d.ts.map +1 -1
  33. package/dist/src/func/builtins/aggregate.js +7 -2
  34. package/dist/src/func/builtins/aggregate.js.map +1 -1
  35. package/dist/src/func/builtins/builtin-window-functions.d.ts.map +1 -1
  36. package/dist/src/func/builtins/builtin-window-functions.js +27 -11
  37. package/dist/src/func/builtins/builtin-window-functions.js.map +1 -1
  38. package/dist/src/func/builtins/datetime.d.ts.map +1 -1
  39. package/dist/src/func/builtins/datetime.js +8 -3
  40. package/dist/src/func/builtins/datetime.js.map +1 -1
  41. package/dist/src/func/builtins/explain.d.ts.map +1 -1
  42. package/dist/src/func/builtins/explain.js +9 -29
  43. package/dist/src/func/builtins/explain.js.map +1 -1
  44. package/dist/src/func/builtins/json-tvf.d.ts.map +1 -1
  45. package/dist/src/func/builtins/json-tvf.js +14 -7
  46. package/dist/src/func/builtins/json-tvf.js.map +1 -1
  47. package/dist/src/func/builtins/return-types.d.ts +29 -0
  48. package/dist/src/func/builtins/return-types.d.ts.map +1 -1
  49. package/dist/src/func/builtins/return-types.js +4 -1
  50. package/dist/src/func/builtins/return-types.js.map +1 -1
  51. package/dist/src/func/builtins/scalar.d.ts.map +1 -1
  52. package/dist/src/func/builtins/scalar.js +22 -67
  53. package/dist/src/func/builtins/scalar.js.map +1 -1
  54. package/dist/src/func/builtins/schema.d.ts.map +1 -1
  55. package/dist/src/func/builtins/schema.js +26 -16
  56. package/dist/src/func/builtins/schema.js.map +1 -1
  57. package/dist/src/index.d.ts +1 -1
  58. package/dist/src/index.d.ts.map +1 -1
  59. package/dist/src/index.js +6 -1
  60. package/dist/src/index.js.map +1 -1
  61. package/dist/src/parser/parser.d.ts.map +1 -1
  62. package/dist/src/parser/parser.js +8 -5
  63. package/dist/src/parser/parser.js.map +1 -1
  64. package/dist/src/parser/visitor.d.ts +16 -0
  65. package/dist/src/parser/visitor.d.ts.map +1 -1
  66. package/dist/src/parser/visitor.js +16 -0
  67. package/dist/src/parser/visitor.js.map +1 -1
  68. package/dist/src/planner/analysis/assertion-plan.d.ts +33 -0
  69. package/dist/src/planner/analysis/assertion-plan.d.ts.map +1 -0
  70. package/dist/src/planner/analysis/assertion-plan.js +39 -0
  71. package/dist/src/planner/analysis/assertion-plan.js.map +1 -0
  72. package/dist/src/planner/analysis/binary-operator-class.d.ts +55 -0
  73. package/dist/src/planner/analysis/binary-operator-class.d.ts.map +1 -0
  74. package/dist/src/planner/analysis/binary-operator-class.js +57 -0
  75. package/dist/src/planner/analysis/binary-operator-class.js.map +1 -0
  76. package/dist/src/planner/analysis/binding-extractor.d.ts +9 -3
  77. package/dist/src/planner/analysis/binding-extractor.d.ts.map +1 -1
  78. package/dist/src/planner/analysis/binding-extractor.js +11 -16
  79. package/dist/src/planner/analysis/binding-extractor.js.map +1 -1
  80. package/dist/src/planner/analysis/change-scope.d.ts.map +1 -1
  81. package/dist/src/planner/analysis/change-scope.js +19 -6
  82. package/dist/src/planner/analysis/change-scope.js.map +1 -1
  83. package/dist/src/planner/analysis/check-extraction.d.ts +1 -7
  84. package/dist/src/planner/analysis/check-extraction.d.ts.map +1 -1
  85. package/dist/src/planner/analysis/check-extraction.js.map +1 -1
  86. package/dist/src/planner/analysis/comparison-collation.d.ts +17 -0
  87. package/dist/src/planner/analysis/comparison-collation.d.ts.map +1 -1
  88. package/dist/src/planner/analysis/comparison-collation.js +17 -5
  89. package/dist/src/planner/analysis/comparison-collation.js.map +1 -1
  90. package/dist/src/planner/analysis/constraint-extractor.d.ts.map +1 -1
  91. package/dist/src/planner/analysis/constraint-extractor.js +18 -18
  92. package/dist/src/planner/analysis/constraint-extractor.js.map +1 -1
  93. package/dist/src/planner/analysis/coverage-prover.d.ts +11 -7
  94. package/dist/src/planner/analysis/coverage-prover.d.ts.map +1 -1
  95. package/dist/src/planner/analysis/coverage-prover.js +11 -7
  96. package/dist/src/planner/analysis/coverage-prover.js.map +1 -1
  97. package/dist/src/planner/analysis/equi-correlation.d.ts +1 -1
  98. package/dist/src/planner/analysis/equi-correlation.js +1 -1
  99. package/dist/src/planner/analysis/expression-fingerprint.d.ts.map +1 -1
  100. package/dist/src/planner/analysis/expression-fingerprint.js +0 -2
  101. package/dist/src/planner/analysis/expression-fingerprint.js.map +1 -1
  102. package/dist/src/planner/analysis/key-filter.d.ts.map +1 -1
  103. package/dist/src/planner/analysis/key-filter.js +2 -3
  104. package/dist/src/planner/analysis/key-filter.js.map +1 -1
  105. package/dist/src/planner/analysis/relation-key.d.ts +104 -0
  106. package/dist/src/planner/analysis/relation-key.d.ts.map +1 -0
  107. package/dist/src/planner/analysis/relation-key.js +121 -0
  108. package/dist/src/planner/analysis/relation-key.js.map +1 -0
  109. package/dist/src/planner/analysis/scalar-param-usage.d.ts.map +1 -1
  110. package/dist/src/planner/analysis/scalar-param-usage.js +12 -4
  111. package/dist/src/planner/analysis/scalar-param-usage.js.map +1 -1
  112. package/dist/src/planner/analysis/set-op-type-merge.d.ts +9 -3
  113. package/dist/src/planner/analysis/set-op-type-merge.d.ts.map +1 -1
  114. package/dist/src/planner/analysis/set-op-type-merge.js +22 -8
  115. package/dist/src/planner/analysis/set-op-type-merge.js.map +1 -1
  116. package/dist/src/planner/building/alter-table.d.ts.map +1 -1
  117. package/dist/src/planner/building/alter-table.js +31 -23
  118. package/dist/src/planner/building/alter-table.js.map +1 -1
  119. package/dist/src/planner/building/analyze.d.ts.map +1 -1
  120. package/dist/src/planner/building/analyze.js +21 -0
  121. package/dist/src/planner/building/analyze.js.map +1 -1
  122. package/dist/src/planner/building/block.d.ts.map +1 -1
  123. package/dist/src/planner/building/block.js +222 -82
  124. package/dist/src/planner/building/block.js.map +1 -1
  125. package/dist/src/planner/building/constraint-builder.d.ts.map +1 -1
  126. package/dist/src/planner/building/constraint-builder.js +5 -3
  127. package/dist/src/planner/building/constraint-builder.js.map +1 -1
  128. package/dist/src/planner/building/delete.js +1 -1
  129. package/dist/src/planner/building/delete.js.map +1 -1
  130. package/dist/src/planner/building/expression.d.ts.map +1 -1
  131. package/dist/src/planner/building/expression.js +11 -3
  132. package/dist/src/planner/building/expression.js.map +1 -1
  133. package/dist/src/planner/building/foreign-key-builder.d.ts +16 -6
  134. package/dist/src/planner/building/foreign-key-builder.d.ts.map +1 -1
  135. package/dist/src/planner/building/foreign-key-builder.js +43 -20
  136. package/dist/src/planner/building/foreign-key-builder.js.map +1 -1
  137. package/dist/src/planner/building/generated-column-scope.d.ts +58 -0
  138. package/dist/src/planner/building/generated-column-scope.d.ts.map +1 -0
  139. package/dist/src/planner/building/generated-column-scope.js +117 -0
  140. package/dist/src/planner/building/generated-column-scope.js.map +1 -0
  141. package/dist/src/planner/building/insert.d.ts.map +1 -1
  142. package/dist/src/planner/building/insert.js +20 -28
  143. package/dist/src/planner/building/insert.js.map +1 -1
  144. package/dist/src/planner/building/select-aggregates.d.ts +73 -132
  145. package/dist/src/planner/building/select-aggregates.d.ts.map +1 -1
  146. package/dist/src/planner/building/select-aggregates.js +405 -81
  147. package/dist/src/planner/building/select-aggregates.js.map +1 -1
  148. package/dist/src/planner/building/select-modifiers.d.ts +37 -8
  149. package/dist/src/planner/building/select-modifiers.d.ts.map +1 -1
  150. package/dist/src/planner/building/select-modifiers.js +8 -9
  151. package/dist/src/planner/building/select-modifiers.js.map +1 -1
  152. package/dist/src/planner/building/select-ordinal.d.ts +6 -0
  153. package/dist/src/planner/building/select-ordinal.d.ts.map +1 -1
  154. package/dist/src/planner/building/select-ordinal.js +1 -1
  155. package/dist/src/planner/building/select-ordinal.js.map +1 -1
  156. package/dist/src/planner/building/select-window.d.ts +2 -2
  157. package/dist/src/planner/building/select-window.d.ts.map +1 -1
  158. package/dist/src/planner/building/select-window.js +82 -101
  159. package/dist/src/planner/building/select-window.js.map +1 -1
  160. package/dist/src/planner/building/select.d.ts.map +1 -1
  161. package/dist/src/planner/building/select.js +78 -33
  162. package/dist/src/planner/building/select.js.map +1 -1
  163. package/dist/src/planner/building/update.d.ts.map +1 -1
  164. package/dist/src/planner/building/update.js +14 -8
  165. package/dist/src/planner/building/update.js.map +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 +329 -14
  168. package/dist/src/planner/building/view-mutation-builder.js.map +1 -1
  169. package/dist/src/planner/building/with.d.ts +6 -0
  170. package/dist/src/planner/building/with.d.ts.map +1 -1
  171. package/dist/src/planner/building/with.js +52 -3
  172. package/dist/src/planner/building/with.js.map +1 -1
  173. package/dist/src/planner/cache/correlation-detector.d.ts.map +1 -1
  174. package/dist/src/planner/cache/correlation-detector.js +44 -17
  175. package/dist/src/planner/cache/correlation-detector.js.map +1 -1
  176. package/dist/src/planner/framework/physical-utils.d.ts +6 -0
  177. package/dist/src/planner/framework/physical-utils.d.ts.map +1 -1
  178. package/dist/src/planner/framework/physical-utils.js +6 -0
  179. package/dist/src/planner/framework/physical-utils.js.map +1 -1
  180. package/dist/src/planner/mutation/lens-enforcement.d.ts +123 -0
  181. package/dist/src/planner/mutation/lens-enforcement.d.ts.map +1 -1
  182. package/dist/src/planner/mutation/lens-enforcement.js +362 -5
  183. package/dist/src/planner/mutation/lens-enforcement.js.map +1 -1
  184. package/dist/src/planner/mutation/mutation-diagnostic.d.ts +1 -1
  185. package/dist/src/planner/mutation/mutation-diagnostic.d.ts.map +1 -1
  186. package/dist/src/planner/mutation/mutation-diagnostic.js.map +1 -1
  187. package/dist/src/planner/nodes/alter-table-node.d.ts +15 -11
  188. package/dist/src/planner/nodes/alter-table-node.d.ts.map +1 -1
  189. package/dist/src/planner/nodes/alter-table-node.js +5 -0
  190. package/dist/src/planner/nodes/alter-table-node.js.map +1 -1
  191. package/dist/src/planner/nodes/bloom-join-node.d.ts.map +1 -1
  192. package/dist/src/planner/nodes/bloom-join-node.js +7 -0
  193. package/dist/src/planner/nodes/bloom-join-node.js.map +1 -1
  194. package/dist/src/planner/nodes/constraint-check-node.d.ts +16 -0
  195. package/dist/src/planner/nodes/constraint-check-node.d.ts.map +1 -1
  196. package/dist/src/planner/nodes/constraint-check-node.js.map +1 -1
  197. package/dist/src/planner/nodes/plan-node-type.d.ts +1 -1
  198. package/dist/src/planner/nodes/plan-node-type.d.ts.map +1 -1
  199. package/dist/src/planner/nodes/plan-node-type.js +1 -1
  200. package/dist/src/planner/nodes/plan-node-type.js.map +1 -1
  201. package/dist/src/planner/nodes/pragma.d.ts.map +1 -1
  202. package/dist/src/planner/nodes/pragma.js +5 -2
  203. package/dist/src/planner/nodes/pragma.js.map +1 -1
  204. package/dist/src/planner/nodes/reference.d.ts.map +1 -1
  205. package/dist/src/planner/nodes/reference.js +9 -1
  206. package/dist/src/planner/nodes/reference.js.map +1 -1
  207. package/dist/src/planner/nodes/scalar.d.ts.map +1 -1
  208. package/dist/src/planner/nodes/scalar.js +117 -91
  209. package/dist/src/planner/nodes/scalar.js.map +1 -1
  210. package/dist/src/planner/nodes/sequence-node.d.ts +50 -0
  211. package/dist/src/planner/nodes/sequence-node.d.ts.map +1 -0
  212. package/dist/src/planner/nodes/sequence-node.js +96 -0
  213. package/dist/src/planner/nodes/sequence-node.js.map +1 -0
  214. package/dist/src/planner/nodes/values-node.d.ts +8 -0
  215. package/dist/src/planner/nodes/values-node.d.ts.map +1 -1
  216. package/dist/src/planner/nodes/values-node.js +29 -6
  217. package/dist/src/planner/nodes/values-node.js.map +1 -1
  218. package/dist/src/planner/nodes/view-mutation-node.d.ts +43 -1
  219. package/dist/src/planner/nodes/view-mutation-node.d.ts.map +1 -1
  220. package/dist/src/planner/nodes/view-mutation-node.js +27 -6
  221. package/dist/src/planner/nodes/view-mutation-node.js.map +1 -1
  222. package/dist/src/planner/nodes/window-node.d.ts +33 -4
  223. package/dist/src/planner/nodes/window-node.d.ts.map +1 -1
  224. package/dist/src/planner/nodes/window-node.js +80 -36
  225. package/dist/src/planner/nodes/window-node.js.map +1 -1
  226. package/dist/src/planner/planning-context.d.ts +38 -1
  227. package/dist/src/planner/planning-context.d.ts.map +1 -1
  228. package/dist/src/planner/rules/access/rule-key-set-seek.d.ts.map +1 -1
  229. package/dist/src/planner/rules/access/rule-key-set-seek.js +8 -3
  230. package/dist/src/planner/rules/access/rule-key-set-seek.js.map +1 -1
  231. package/dist/src/planner/rules/join/rule-fanout-lookup-join.js +18 -12
  232. package/dist/src/planner/rules/join/rule-fanout-lookup-join.js.map +1 -1
  233. package/dist/src/planner/rules/retrieve/rule-grow-retrieve.js +4 -3
  234. package/dist/src/planner/rules/retrieve/rule-grow-retrieve.js.map +1 -1
  235. package/dist/src/planner/rules/window/rule-monotonic-window.d.ts.map +1 -1
  236. package/dist/src/planner/rules/window/rule-monotonic-window.js +6 -0
  237. package/dist/src/planner/rules/window/rule-monotonic-window.js.map +1 -1
  238. package/dist/src/planner/scopes/param.d.ts.map +1 -1
  239. package/dist/src/planner/scopes/param.js +10 -5
  240. package/dist/src/planner/scopes/param.js.map +1 -1
  241. package/dist/src/planner/util/ind-utils.d.ts +25 -8
  242. package/dist/src/planner/util/ind-utils.d.ts.map +1 -1
  243. package/dist/src/planner/util/ind-utils.js +53 -10
  244. package/dist/src/planner/util/ind-utils.js.map +1 -1
  245. package/dist/src/planner/util/key-utils.d.ts +7 -7
  246. package/dist/src/planner/util/key-utils.js +9 -9
  247. package/dist/src/planner/util/key-utils.js.map +1 -1
  248. package/dist/src/runtime/delta-executor.d.ts.map +1 -1
  249. package/dist/src/runtime/delta-executor.js +7 -2
  250. package/dist/src/runtime/delta-executor.js.map +1 -1
  251. package/dist/src/runtime/emit/add-constraint.d.ts.map +1 -1
  252. package/dist/src/runtime/emit/add-constraint.js +50 -15
  253. package/dist/src/runtime/emit/add-constraint.js.map +1 -1
  254. package/dist/src/runtime/emit/alter-schema-event.d.ts +2 -43
  255. package/dist/src/runtime/emit/alter-schema-event.d.ts.map +1 -1
  256. package/dist/src/runtime/emit/alter-schema-event.js +2 -53
  257. package/dist/src/runtime/emit/alter-schema-event.js.map +1 -1
  258. package/dist/src/runtime/emit/alter-table.d.ts.map +1 -1
  259. package/dist/src/runtime/emit/alter-table.js +59 -24
  260. package/dist/src/runtime/emit/alter-table.js.map +1 -1
  261. package/dist/src/runtime/emit/analyze.d.ts.map +1 -1
  262. package/dist/src/runtime/emit/analyze.js +7 -0
  263. package/dist/src/runtime/emit/analyze.js.map +1 -1
  264. package/dist/src/runtime/emit/assertion-rename-helpers.d.ts.map +1 -1
  265. package/dist/src/runtime/emit/assertion-rename-helpers.js +2 -3
  266. package/dist/src/runtime/emit/assertion-rename-helpers.js.map +1 -1
  267. package/dist/src/runtime/emit/binary.d.ts +5 -0
  268. package/dist/src/runtime/emit/binary.d.ts.map +1 -1
  269. package/dist/src/runtime/emit/binary.js +22 -22
  270. package/dist/src/runtime/emit/binary.js.map +1 -1
  271. package/dist/src/runtime/emit/block.d.ts.map +1 -1
  272. package/dist/src/runtime/emit/block.js +9 -3
  273. package/dist/src/runtime/emit/block.js.map +1 -1
  274. package/dist/src/runtime/emit/constraint-check.d.ts.map +1 -1
  275. package/dist/src/runtime/emit/constraint-check.js +5 -6
  276. package/dist/src/runtime/emit/constraint-check.js.map +1 -1
  277. package/dist/src/runtime/emit/create-assertion.d.ts.map +1 -1
  278. package/dist/src/runtime/emit/create-assertion.js +71 -70
  279. package/dist/src/runtime/emit/create-assertion.js.map +1 -1
  280. package/dist/src/runtime/emit/create-index.d.ts.map +1 -1
  281. package/dist/src/runtime/emit/create-index.js +8 -3
  282. package/dist/src/runtime/emit/create-index.js.map +1 -1
  283. package/dist/src/runtime/emit/create-table.d.ts.map +1 -1
  284. package/dist/src/runtime/emit/create-table.js +20 -10
  285. package/dist/src/runtime/emit/create-table.js.map +1 -1
  286. package/dist/src/runtime/emit/create-view.d.ts.map +1 -1
  287. package/dist/src/runtime/emit/create-view.js +51 -44
  288. package/dist/src/runtime/emit/create-view.js.map +1 -1
  289. package/dist/src/runtime/emit/ddl-event-scope.d.ts +71 -0
  290. package/dist/src/runtime/emit/ddl-event-scope.d.ts.map +1 -0
  291. package/dist/src/runtime/emit/ddl-event-scope.js +80 -0
  292. package/dist/src/runtime/emit/ddl-event-scope.js.map +1 -0
  293. package/dist/src/runtime/emit/dml-executor.d.ts.map +1 -1
  294. package/dist/src/runtime/emit/dml-executor.js +23 -23
  295. package/dist/src/runtime/emit/dml-executor.js.map +1 -1
  296. package/dist/src/runtime/emit/drop-assertion.d.ts.map +1 -1
  297. package/dist/src/runtime/emit/drop-assertion.js +23 -17
  298. package/dist/src/runtime/emit/drop-assertion.js.map +1 -1
  299. package/dist/src/runtime/emit/drop-index.d.ts.map +1 -1
  300. package/dist/src/runtime/emit/drop-index.js +7 -2
  301. package/dist/src/runtime/emit/drop-index.js.map +1 -1
  302. package/dist/src/runtime/emit/drop-table.d.ts.map +1 -1
  303. package/dist/src/runtime/emit/drop-table.js +16 -10
  304. package/dist/src/runtime/emit/drop-table.js.map +1 -1
  305. package/dist/src/runtime/emit/drop-view.d.ts.map +1 -1
  306. package/dist/src/runtime/emit/drop-view.js +50 -43
  307. package/dist/src/runtime/emit/drop-view.js.map +1 -1
  308. package/dist/src/runtime/emit/insert.d.ts.map +1 -1
  309. package/dist/src/runtime/emit/insert.js +2 -1
  310. package/dist/src/runtime/emit/insert.js.map +1 -1
  311. package/dist/src/runtime/emit/materialized-view.d.ts.map +1 -1
  312. package/dist/src/runtime/emit/materialized-view.js +87 -67
  313. package/dist/src/runtime/emit/materialized-view.js.map +1 -1
  314. package/dist/src/runtime/emit/schema-declarative.d.ts +8 -0
  315. package/dist/src/runtime/emit/schema-declarative.d.ts.map +1 -1
  316. package/dist/src/runtime/emit/schema-declarative.js +128 -25
  317. package/dist/src/runtime/emit/schema-declarative.js.map +1 -1
  318. package/dist/src/runtime/emit/sequence.d.ts +17 -0
  319. package/dist/src/runtime/emit/sequence.d.ts.map +1 -0
  320. package/dist/src/runtime/emit/sequence.js +40 -0
  321. package/dist/src/runtime/emit/sequence.js.map +1 -0
  322. package/dist/src/runtime/emit/set-object-tags.d.ts.map +1 -1
  323. package/dist/src/runtime/emit/set-object-tags.js +40 -32
  324. package/dist/src/runtime/emit/set-object-tags.js.map +1 -1
  325. package/dist/src/runtime/emit/table-valued-function.d.ts.map +1 -1
  326. package/dist/src/runtime/emit/table-valued-function.js +3 -2
  327. package/dist/src/runtime/emit/table-valued-function.js.map +1 -1
  328. package/dist/src/runtime/emit/update.js +3 -3
  329. package/dist/src/runtime/emit/update.js.map +1 -1
  330. package/dist/src/runtime/emit/view-mutation.d.ts.map +1 -1
  331. package/dist/src/runtime/emit/view-mutation.js +45 -3
  332. package/dist/src/runtime/emit/view-mutation.js.map +1 -1
  333. package/dist/src/runtime/foreign-key-actions.d.ts.map +1 -1
  334. package/dist/src/runtime/foreign-key-actions.js +9 -10
  335. package/dist/src/runtime/foreign-key-actions.js.map +1 -1
  336. package/dist/src/runtime/register.d.ts.map +1 -1
  337. package/dist/src/runtime/register.js +3 -2
  338. package/dist/src/runtime/register.js.map +1 -1
  339. package/dist/src/runtime/row-constraints.d.ts +14 -8
  340. package/dist/src/runtime/row-constraints.d.ts.map +1 -1
  341. package/dist/src/runtime/row-constraints.js +41 -15
  342. package/dist/src/runtime/row-constraints.js.map +1 -1
  343. package/dist/src/runtime/strict-representation.d.ts +11 -6
  344. package/dist/src/runtime/strict-representation.d.ts.map +1 -1
  345. package/dist/src/runtime/strict-representation.js +1 -44
  346. package/dist/src/runtime/strict-representation.js.map +1 -1
  347. package/dist/src/schema/assertion.d.ts +25 -2
  348. package/dist/src/schema/assertion.d.ts.map +1 -1
  349. package/dist/src/schema/assertion.js.map +1 -1
  350. package/dist/src/schema/catalog-rendering.d.ts +38 -0
  351. package/dist/src/schema/catalog-rendering.d.ts.map +1 -0
  352. package/dist/src/schema/catalog-rendering.js +171 -0
  353. package/dist/src/schema/catalog-rendering.js.map +1 -0
  354. package/dist/src/schema/catalog.d.ts +69 -3
  355. package/dist/src/schema/catalog.d.ts.map +1 -1
  356. package/dist/src/schema/catalog.js +124 -19
  357. package/dist/src/schema/catalog.js.map +1 -1
  358. package/dist/src/schema/column-source-resolver.d.ts +9 -5
  359. package/dist/src/schema/column-source-resolver.d.ts.map +1 -1
  360. package/dist/src/schema/column-source-resolver.js +9 -5
  361. package/dist/src/schema/column-source-resolver.js.map +1 -1
  362. package/dist/src/schema/constraint-builder.d.ts +13 -10
  363. package/dist/src/schema/constraint-builder.d.ts.map +1 -1
  364. package/dist/src/schema/constraint-builder.js +45 -17
  365. package/dist/src/schema/constraint-builder.js.map +1 -1
  366. package/dist/src/schema/declared-schema-manager.d.ts +50 -0
  367. package/dist/src/schema/declared-schema-manager.d.ts.map +1 -1
  368. package/dist/src/schema/declared-schema-manager.js +52 -0
  369. package/dist/src/schema/declared-schema-manager.js.map +1 -1
  370. package/dist/src/schema/expr-scope/frame.d.ts +65 -0
  371. package/dist/src/schema/expr-scope/frame.d.ts.map +1 -0
  372. package/dist/src/schema/expr-scope/frame.js +104 -0
  373. package/dist/src/schema/expr-scope/frame.js.map +1 -0
  374. package/dist/src/schema/expr-scope/walk.d.ts +40 -0
  375. package/dist/src/schema/expr-scope/walk.d.ts.map +1 -0
  376. package/dist/src/schema/expr-scope/walk.js +260 -0
  377. package/dist/src/schema/expr-scope/walk.js.map +1 -0
  378. package/dist/src/schema/generated-column-refs.d.ts +41 -0
  379. package/dist/src/schema/generated-column-refs.d.ts.map +1 -0
  380. package/dist/src/schema/generated-column-refs.js +124 -0
  381. package/dist/src/schema/generated-column-refs.js.map +1 -0
  382. package/dist/src/schema/lens-ack.d.ts.map +1 -1
  383. package/dist/src/schema/lens-ack.js +5 -2
  384. package/dist/src/schema/lens-ack.js.map +1 -1
  385. package/dist/src/schema/lens-compiler.d.ts.map +1 -1
  386. package/dist/src/schema/lens-compiler.js +9 -1
  387. package/dist/src/schema/lens-compiler.js.map +1 -1
  388. package/dist/src/schema/lens-prover.d.ts +7 -2
  389. package/dist/src/schema/lens-prover.d.ts.map +1 -1
  390. package/dist/src/schema/lens-prover.js +105 -11
  391. package/dist/src/schema/lens-prover.js.map +1 -1
  392. package/dist/src/schema/lens.d.ts +12 -0
  393. package/dist/src/schema/lens.d.ts.map +1 -1
  394. package/dist/src/schema/lens.js +10 -0
  395. package/dist/src/schema/lens.js.map +1 -1
  396. package/dist/src/schema/manager.d.ts +35 -1
  397. package/dist/src/schema/manager.d.ts.map +1 -1
  398. package/dist/src/schema/manager.js +125 -26
  399. package/dist/src/schema/manager.js.map +1 -1
  400. package/dist/src/schema/rename/self-qualifier-strip.d.ts +16 -10
  401. package/dist/src/schema/rename/self-qualifier-strip.d.ts.map +1 -1
  402. package/dist/src/schema/rename/self-qualifier-strip.js +30 -213
  403. package/dist/src/schema/rename/self-qualifier-strip.js.map +1 -1
  404. package/dist/src/schema/rename-rewriter.d.ts +4 -3
  405. package/dist/src/schema/rename-rewriter.d.ts.map +1 -1
  406. package/dist/src/schema/rename-rewriter.js +4 -3
  407. package/dist/src/schema/rename-rewriter.js.map +1 -1
  408. package/dist/src/schema/schema-differ.d.ts +54 -6
  409. package/dist/src/schema/schema-differ.d.ts.map +1 -1
  410. package/dist/src/schema/schema-differ.js +108 -42
  411. package/dist/src/schema/schema-differ.js.map +1 -1
  412. package/dist/src/schema/schema-hasher.d.ts +12 -0
  413. package/dist/src/schema/schema-hasher.d.ts.map +1 -1
  414. package/dist/src/schema/schema-hasher.js +28 -10
  415. package/dist/src/schema/schema-hasher.js.map +1 -1
  416. package/dist/src/schema/table.d.ts +74 -19
  417. package/dist/src/schema/table.d.ts.map +1 -1
  418. package/dist/src/schema/table.js +133 -71
  419. package/dist/src/schema/table.js.map +1 -1
  420. package/dist/src/types/comparison-coercion.d.ts +5 -1
  421. package/dist/src/types/comparison-coercion.d.ts.map +1 -1
  422. package/dist/src/types/comparison-coercion.js +21 -5
  423. package/dist/src/types/comparison-coercion.js.map +1 -1
  424. package/dist/src/types/representation.d.ts +65 -0
  425. package/dist/src/types/representation.d.ts.map +1 -0
  426. package/dist/src/types/representation.js +63 -0
  427. package/dist/src/types/representation.js.map +1 -0
  428. package/dist/src/types/validation.d.ts +76 -22
  429. package/dist/src/types/validation.d.ts.map +1 -1
  430. package/dist/src/types/validation.js +110 -31
  431. package/dist/src/types/validation.js.map +1 -1
  432. package/dist/src/vtab/best-access-plan.d.ts +10 -0
  433. package/dist/src/vtab/best-access-plan.d.ts.map +1 -1
  434. package/dist/src/vtab/best-access-plan.js +16 -0
  435. package/dist/src/vtab/best-access-plan.js.map +1 -1
  436. package/dist/src/vtab/capabilities.d.ts +72 -4
  437. package/dist/src/vtab/capabilities.d.ts.map +1 -1
  438. package/dist/src/vtab/memory/layer/manager.d.ts.map +1 -1
  439. package/dist/src/vtab/memory/layer/manager.js +17 -13
  440. package/dist/src/vtab/memory/layer/manager.js.map +1 -1
  441. package/dist/src/vtab/module.d.ts +13 -7
  442. package/dist/src/vtab/module.d.ts.map +1 -1
  443. package/package.json +3 -3
  444. package/dist/src/planner/nodes/array-index-node.d.ts +0 -22
  445. package/dist/src/planner/nodes/array-index-node.d.ts.map +0 -1
  446. package/dist/src/planner/nodes/array-index-node.js +0 -41
  447. package/dist/src/planner/nodes/array-index-node.js.map +0 -1
  448. package/dist/src/runtime/emit/array-index.d.ts +0 -5
  449. package/dist/src/runtime/emit/array-index.d.ts.map +0 -1
  450. package/dist/src/runtime/emit/array-index.js +0 -22
  451. package/dist/src/runtime/emit/array-index.js.map +0 -1
@@ -1,12 +1,12 @@
1
1
  import { WindowNode } from '../nodes/window-node.js';
2
2
  import { WindowFunctionCallNode } from '../nodes/window-function.js';
3
3
  import { ProjectNode } from '../nodes/project-node.js';
4
- import { ArrayIndexNode } from '../nodes/array-index-node.js';
4
+ import { ColumnReferenceNode } from '../nodes/reference.js';
5
5
  import { LiteralNode } from '../nodes/scalar.js';
6
6
  import { buildExpression } from './expression.js';
7
- import { assertGroupedWindowCoverage, collectAggregateFunctionExprs, redirectToGroupKeys } from './select-aggregates.js';
7
+ import { collectAggregateFunctionExprs, redirectPostAggregate } from './select-aggregates.js';
8
8
  import { findMatchingAggregate } from './function-call.js';
9
- import { QuereusError } from '../../common/errors.js';
9
+ import { QuereusError, quereusError } from '../../common/errors.js';
10
10
  import { StatusCode } from '../../common/types.js';
11
11
  import { expressionToString } from '../../emit/ast-stringify.js';
12
12
  import { CapabilityDetectors } from '../framework/characteristics.js';
@@ -29,6 +29,9 @@ export function buildWindowPhase(input, windowFunctions, selectContext, selectLi
29
29
  let currentInput = input;
30
30
  // Group window functions by their window specification
31
31
  const windowGroups = groupWindowFunctionsBySpec(windowFunctions);
32
+ // Each collected function's window-output attribute, recorded as its node is
33
+ // built; resolved to a WindowColumnEntry against the outermost node below.
34
+ const windowAttributes = new Map();
32
35
  // Create WindowNode for each unique window specification
33
36
  for (const [_windowSpecKey, functions] of windowGroups) {
34
37
  const firstFunc = functions[0];
@@ -52,10 +55,10 @@ export function buildWindowPhase(input, windowFunctions, selectContext, selectLi
52
55
  // nonetheless bind to a base-table attribute, because the scope these are built
53
56
  // against falls through to the pre-aggregate select scope: a qualified `wg.a`
54
57
  // against `group by a`, or the whole expression against `group by a || '!'`.
55
- // Redirect every such subtree onto the aggregate's own output column.
56
- const redirect = (expr) => groupedWindowContext
57
- ? redirectToGroupKeys(expr, groupedWindowContext, selectContext.scope)
58
- : expr;
58
+ // Redirect every such subtree onto the aggregate's own output column. Anything a
59
+ // redirect leaves on a pre-grouping attribute is a genuinely ungrouped reference,
60
+ // rejected over the finished plan by `assertGroupedPlanCoverage` (select.ts).
61
+ const redirect = (expr) => redirectPostAggregate(expr, groupedWindowContext, selectContext.scope);
59
62
  // CRITICAL: Build window specification expressions using the INPUT scope
60
63
  // This ensures expressions reference the correct input attribute IDs,
61
64
  // not premature output attribute IDs that don't exist in the runtime context
@@ -65,30 +68,33 @@ export function buildWindowPhase(input, windowFunctions, selectContext, selectLi
65
68
  // so each re-created WindowFunctionCallNode can be handed its argument
66
69
  // logical types for faithful return-type inference (window MIN/MAX).
67
70
  const functionArguments = buildWindowFunctionArguments(functions.map(({ func }) => func), selectContext).map(args => args.map(redirect));
68
- // After redirection, anything still naming one of this query's pre-grouping
69
- // columns is a genuinely ungrouped reference, illegal for exactly the reason a
70
- // bare column in the select list is, and must say so at plan time — otherwise it
71
- // reaches the runtime as an attribute the aggregate row never had, and the query
72
- // dies with an internal "no row context" error instead. A reference belonging to
73
- // a subquery inside the specification, or correlated out to an ENCLOSING query,
74
- // is not this query's business and passes through.
75
- if (groupedWindowContext) {
76
- for (const expr of partitionExpressions)
77
- assertGroupedWindowCoverage(expr, groupedWindowContext);
78
- for (const expr of orderByExpressions)
79
- assertGroupedWindowCoverage(expr, groupedWindowContext);
80
- for (const args of functionArguments) {
81
- for (const arg of args)
82
- assertGroupedWindowCoverage(arg, groupedWindowContext);
83
- }
84
- }
85
71
  // Create new WindowFunctionCallNode instances with alias + argument-type info
86
72
  const windowFuncsWithAlias = functions.map(({ func, alias }, i) => new WindowFunctionCallNode(func.scope, func.expression, func.functionName, func.isDistinct, alias, functionArguments[i].map(a => a.getType().logicalType)));
87
73
  // Now create the WindowNode with pre-compiled expressions
88
- currentInput = new WindowNode(selectContext.scope, currentInput, windowSpec, windowFuncsWithAlias, partitionExpressions, orderByExpressions, functionArguments);
74
+ const windowNode = new WindowNode(selectContext.scope, currentInput, windowSpec, windowFuncsWithAlias, partitionExpressions, orderByExpressions, functionArguments);
75
+ // Record each function's freshly minted window-output attribute under the
76
+ // AST identity the select-list rewrite will look it up by.
77
+ const windowAttrs = windowNode.getWindowAttributes();
78
+ functions.forEach(({ func }, i) => {
79
+ windowAttributes.set(func.expression, windowAttrs[i]);
80
+ });
81
+ currentInput = windowNode;
82
+ }
83
+ // Resolve each window attribute's position against the OUTERMOST window node —
84
+ // stacked WindowNodes pass inner window columns through, so one lookup covers
85
+ // every group without index arithmetic.
86
+ const outerAttrIndex = currentInput.getAttributeIndex();
87
+ const windowColumns = new Map();
88
+ for (const [expr, attr] of windowAttributes) {
89
+ windowColumns.set(expr, {
90
+ attr,
91
+ // Present by construction: every window attribute is on the outermost node's row.
92
+ columnIndex: outerAttrIndex.get(attr.id),
93
+ });
89
94
  }
90
- // Create projections that select only the requested columns using direct array indexing
91
- const windowProjections = buildWindowProjections(selectListProjections, currentInput, selectContext, windowFunctions);
95
+ // Rewrite the select list into the projection above the WindowNode(s), with each
96
+ // window function replaced by a reference to its window-output column.
97
+ const windowProjections = buildWindowProjections(selectListProjections, windowColumns, selectContext.scope);
92
98
  if (windowProjections.length > 0) {
93
99
  currentInput = new ProjectNode(selectContext.scope, currentInput, windowProjections);
94
100
  }
@@ -142,28 +148,29 @@ function rejectUncollectedAggregates(func, selectContext) {
142
148
  check(arg, 'arguments');
143
149
  }
144
150
  /**
145
- * Groups window functions by their window specification
151
+ * Groups window functions by their window specification, so functions sharing a
152
+ * specification share one WindowNode — one sort and one buffering/streaming pass
153
+ * per unique specification.
146
154
  *
147
- * NOTE: the key is `JSON.stringify` over raw AST fragments, which include each
148
- * fragment's source-location (`loc`) data — so two textually identical `over (…)`
149
- * clauses at different source positions never key equal and this never actually
150
- * groups anything; every window function gets its own WindowNode. That accident is
151
- * currently load-bearing: {@link findWindowColumnIndex} matches a window function by
152
- * name + spec only, so two same-named functions genuinely sharing one WindowNode
153
- * would both resolve to the first one's output column. Stripping `loc` here (or
154
- * comparing structurally) makes the grouping work and breaks the column matching —
155
- * that change has to teach `findWindowColumnIndex` to match by node identity or
156
- * position first.
155
+ * The key is `JSON.stringify` over the raw AST spec fragments with every
156
+ * source-location (`loc`) field stripped, so two textually identical `over (…)`
157
+ * clauses key equal wherever they were written. Spelling differences that the
158
+ * scope would resolve identically (a different identifier case, an unused
159
+ * qualifier) still key apart — that only costs a duplicate WindowNode, never a
160
+ * wrong merge, because within one select list the same spelling always resolves
161
+ * to the same thing. Matching a function to its output COLUMN is independent of
162
+ * this grouping: each function's window attribute is recorded under its
163
+ * `AST.WindowFunctionExpr` identity as its node is built (see buildWindowPhase).
157
164
  */
158
165
  function groupWindowFunctionsBySpec(windowFunctions) {
159
166
  const windowGroups = new Map();
160
167
  for (const { func, alias } of windowFunctions) {
161
- // Create a key based on the window specification
168
+ // Structural key: the spec fragments minus source locations.
162
169
  const windowSpecKey = JSON.stringify({
163
170
  partitionBy: func.expression.window?.partitionBy || [],
164
171
  orderBy: func.expression.window?.orderBy || [],
165
- frame: func.expression.window?.frame
166
- });
172
+ frame: func.expression.window?.frame ?? null
173
+ }, (key, value) => (key === 'loc' ? undefined : value));
167
174
  if (!windowGroups.has(windowSpecKey)) {
168
175
  windowGroups.set(windowSpecKey, []);
169
176
  }
@@ -205,20 +212,19 @@ function buildWindowFunctionArguments(windowFuncs, selectContext) {
205
212
  * expressions, which are left exactly as built. Only entries containing a window
206
213
  * function are rebuilt, and only by substituting each window result in place.
207
214
  */
208
- function buildWindowProjections(selectListProjections, windowNode, selectContext, windowFunctions) {
209
- const windowType = windowNode.getType();
210
- const sourceColumnCount = windowType.columns.length - windowFunctions.length;
215
+ function buildWindowProjections(selectListProjections, windowColumns, scope) {
211
216
  return selectListProjections.map(projection => {
212
- // Rewrite each window-function descendant into an ArrayIndexNode pointing
213
- // at its computed window-output column, preserving any surrounding
214
- // arithmetic / scalar wrapper (e.g. `1000 - row_number() over (...)`).
215
- const rewritten = rewriteWindowFunctions(projection.node, windowFunctions, sourceColumnCount, windowType, selectContext.scope);
217
+ // Rewrite each window-function descendant into a column reference to its
218
+ // computed window-output column, preserving any surrounding arithmetic /
219
+ // scalar wrapper (e.g. `1000 - row_number() over (...)`).
220
+ const rewritten = rewriteWindowFunctions(projection.node, windowColumns, scope);
216
221
  if (rewritten === projection.node)
217
222
  return projection;
218
- // The rewrite replaces the authored expression with an ArrayIndexNode, whose
219
- // own name is a bare index (`[2]`). An unaliased window column must keep the
220
- // expression the user wrote as its output name, like every other unaliased
221
- // select-list column (`select count(*) from t group by g` yields `count(*)`).
223
+ // The rewrite replaces the authored expression with a column reference whose
224
+ // own name is the window column's synthetic name. An unaliased window column
225
+ // must keep the expression the user wrote as its output name, like every
226
+ // other unaliased select-list column (`select count(*) from t group by g`
227
+ // yields `count(*)`).
222
228
  return {
223
229
  ...projection,
224
230
  node: rewritten,
@@ -229,22 +235,37 @@ function buildWindowProjections(selectListProjections, windowNode, selectContext
229
235
  }
230
236
  /**
231
237
  * Recursively rewrites every WindowFunctionCallNode descendant of a scalar
232
- * expression into an ArrayIndexNode referencing that function's window-output
233
- * column, leaving the surrounding expression structure intact.
238
+ * expression into a ColumnReferenceNode bound to that function's window-output
239
+ * attribute, leaving the surrounding expression structure intact.
240
+ *
241
+ * The reference resolves by attribute id at runtime (`resolveAttribute`), exactly
242
+ * like every other column read — so it stays correct no matter what operators the
243
+ * optimizer later places between the WindowNode and this projection.
234
244
  *
235
245
  * Mirrors the aggregate path (collectInnerAggregates): the whole outer
236
246
  * expression is preserved and the inner window results are substituted back in.
237
247
  * Does NOT recurse into a window function's own arguments — its result is a
238
248
  * single output column already materialized by the WindowNode.
239
249
  */
240
- function rewriteWindowFunctions(node, windowFunctions, sourceColumnCount, windowType, scope) {
250
+ function rewriteWindowFunctions(node, windowColumns, scope) {
241
251
  if (CapabilityDetectors.isWindowFunction(node)) {
242
- const index = findWindowColumnIndex(node, windowFunctions, sourceColumnCount);
243
- if (index >= 0) {
244
- return new ArrayIndexNode(scope, index, windowType.columns[index].type);
252
+ const windowFunc = node;
253
+ const entry = windowColumns.get(windowFunc.expression);
254
+ if (!entry) {
255
+ // Every window function in the select list was collected by
256
+ // analyzeSelectColumns and keyed here by its AST node; a miss means the
257
+ // two walks diverged, and silently keeping the raw node would reach the
258
+ // runtime as an unevaluable call.
259
+ quereusError(`Window function ${windowFunc.functionName} was not collected into any WindowNode`, StatusCode.INTERNAL);
245
260
  }
246
- // No match (shouldn't happen for a window node we collected) — leave as-is.
247
- return node;
261
+ // Synthetic column expression; only plan display and error text read it
262
+ // (ColumnReferenceNode.toString() / getLogicalAttributes()).
263
+ const columnExpr = {
264
+ type: 'column',
265
+ name: entry.attr.name,
266
+ loc: windowFunc.expression.loc,
267
+ };
268
+ return new ColumnReferenceNode(scope, columnExpr, entry.attr.type, entry.attr.id, entry.columnIndex);
248
269
  }
249
270
  const children = node.getChildren();
250
271
  const newChildren = [];
@@ -252,7 +273,7 @@ function rewriteWindowFunctions(node, windowFunctions, sourceColumnCount, window
252
273
  for (const child of children) {
253
274
  // Only scalar children participate in window rewriting; pass others through.
254
275
  if ('expression' in child) {
255
- const rewrittenChild = rewriteWindowFunctions(child, windowFunctions, sourceColumnCount, windowType, scope);
276
+ const rewrittenChild = rewriteWindowFunctions(child, windowColumns, scope);
256
277
  if (rewrittenChild !== child) {
257
278
  changed = true;
258
279
  }
@@ -264,44 +285,4 @@ function rewriteWindowFunctions(node, windowFunctions, sourceColumnCount, window
264
285
  }
265
286
  return changed ? node.withChildren(newChildren) : node;
266
287
  }
267
- /**
268
- * Finds the window-output column index for a single window-function node by
269
- * matching it (name + window spec) against the collected window functions.
270
- */
271
- function findWindowColumnIndex(windowNode, windowFunctions, sourceColumnCount) {
272
- const matchingWindowFuncIndex = windowFunctions.findIndex(({ func }) => {
273
- // Match based on function name and window specification
274
- if (func.functionName.toLowerCase() !== windowNode.functionName.toLowerCase()) {
275
- return false;
276
- }
277
- return compareWindowSpecs(windowNode.expression.window, func.expression.window);
278
- });
279
- return matchingWindowFuncIndex >= 0 ? sourceColumnCount + matchingWindowFuncIndex : -1;
280
- }
281
- /**
282
- * Compares two window specifications for equality
283
- *
284
- * NOTE: like {@link groupWindowFunctionsBySpec}, this compares `JSON.stringify` of
285
- * raw AST fragments including their source-location (`loc`) data, so two textually
286
- * identical `over (…)` clauses written at different positions never compare equal.
287
- * That is what keeps `sum(v) over (order by v) a, sum(v*10) over (order by v) b`
288
- * resolving to two different window columns despite matching on function name.
289
- * Making this comparison structural without also teaching
290
- * {@link findWindowColumnIndex} to match by node identity or position collapses
291
- * both onto the first function's column.
292
- */
293
- function compareWindowSpecs(originalWindow, funcWindow) {
294
- // Compare partition expressions
295
- const originalPartition = JSON.stringify(originalWindow?.partitionBy || []);
296
- const funcPartition = JSON.stringify(funcWindow?.partitionBy || []);
297
- // Compare order expressions
298
- const originalOrder = JSON.stringify(originalWindow?.orderBy || []);
299
- const funcOrder = JSON.stringify(funcWindow?.orderBy || []);
300
- // Compare frame specifications
301
- const originalFrame = JSON.stringify(originalWindow?.frame || null);
302
- const funcFrame = JSON.stringify(funcWindow?.frame || null);
303
- return originalPartition === funcPartition &&
304
- originalOrder === funcOrder &&
305
- originalFrame === funcFrame;
306
- }
307
288
  //# sourceMappingURL=select-window.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"select-window.js","sourceRoot":"","sources":["../../../../src/planner/building/select-window.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAmB,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,WAAW,EAAmB,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,2BAA2B,EAAE,6BAA6B,EAAE,mBAAmB,EAA6B,MAAM,wBAAwB,CAAC;AACpJ,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAEtE;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAC/B,KAAyB,EACzB,eAAmE,EACnE,aAA8B,EAC9B,qBAA4C,EAC5C,oBAA2C;IAE3C,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClC,OAAO,KAAK,CAAC;IACd,CAAC;IAED,IAAI,YAAY,GAAG,KAAK,CAAC;IAEzB,uDAAuD;IACvD,MAAM,YAAY,GAAG,0BAA0B,CAAC,eAAe,CAAC,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AAG,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,KAAK,SAAS,EAAE,KAAK,kBAAkB,EAAE,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAG/G,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAO9D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAUhD,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,sBAAsB,CAAC;AAMtE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAyBrD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,eAAe,EACpB,IAAI,EAAE,GAAG,CAAC,UAAU,EACpB,UAAU,GAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAa;AACjD;;;;;GAKG;AACH,oBAAoB,GAAE,OAAc,GACnC,QAAQ,CAyWV;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC9B,GAAG,EAAE,eAAe,EACpB,IAAI,EAAE,GAAG,CAAC,UAAU,GAClB,UAAU,CAQZ;AA6BD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE,aAAa,EAAE,eAAe,EAAE,QAAQ,GAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAa,GAAG,kBAAkB,CA0RzJ;AA6FD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,mBAAmB,CAClC,YAAY,EAAE,SAAS,MAAM,EAAE,EAC/B,SAAS,EAAE,SAAS,SAAS,EAAE,EAC/B,UAAU,EAAE,SAAS,SAAS,EAAE,EAChC,KAAK,EAAE,KAAK,GACV,cAAc,CAchB"}
@@ -31,7 +31,7 @@ import { buildWithContext, enterStoredBodyEnv } from './select-context.js';
31
31
  import { storedBodyContext } from '../stored-body-context.js';
32
32
  import { buildCompoundSelect } from './select-compound.js';
33
33
  import { analyzeSelectColumns, buildStarProjections } from './select-projections.js';
34
- import { buildAggregatePhase, buildFinalAggregateProjections, buildGroupedWindowContext } from './select-aggregates.js';
34
+ import { buildAggregatePhase, buildFinalAggregateProjections, assertGroupedPlanCoverage, redirectPostAggregate } from './select-aggregates.js';
35
35
  import { buildWindowPhase } from './select-window.js';
36
36
  import { buildFinalProjections, applyDistinct, applyOrderBy, applyLimitOffset, createProjectionOutputScope } from './select-modifiers.js';
37
37
  import { SortNode } from '../nodes/sort.js';
@@ -155,10 +155,13 @@ preserveInputColumns = true) {
155
155
  // Set when the query is BOTH grouped and windowed: the grouped select-list
156
156
  // projection list, to be projected above the window phase's WindowNode.
157
157
  let windowSelectProjections;
158
- // Also set only for a grouped, windowed query: what the aggregate's rows carry,
159
- // so the window phase can redirect a window specification onto them and reject
160
- // one that reads anything else.
161
- let windowGroupedContext;
158
+ // Set for every GROUPED query (built by buildAggregatePhase the moment the
159
+ // AggregateNode exists, so no post-aggregate site here can run before it): what
160
+ // the aggregate's rows carry, so every post-aggregate expression built below —
161
+ // sort keys, the rebuilt select list, the window phase's specifications and
162
+ // arguments — reaches the grouping-key redirect through redirectPostAggregate,
163
+ // and so the finished plan can be boundary-checked once at the bottom.
164
+ const groupedRedirectContext = aggregateResult.groupedRedirectContext;
162
165
  // The node whose output attributes ARE this SELECT's result columns, once one
163
166
  // exists. A positional ORDER BY binds to its Nth attribute (see applyOrderBy).
164
167
  let orderByOutputRelation;
@@ -174,40 +177,39 @@ preserveInputColumns = true) {
174
177
  scope: aggregateResult.aggregateScope,
175
178
  aggregates: aggregateResult.aggregatesContext,
176
179
  };
177
- // When ORDER BY references aggregate functions, apply it now — *before*
178
- // any stripping final projection — so it can resolve against the full
179
- // AggregateNode output (which still includes ORDER-BY-only aggregates).
180
- // Skipped when window functions are present (window output isn't
180
+ // Applying ORDER BY here — *before* any stripping final projection — is the
181
+ // EXCEPTION, taken only when ORDER BY introduced aggregates the select list
182
+ // does not have. Those exist solely for the sort and the final projection
183
+ // strips them, so the sort must see the full AggregateNode output while they
184
+ // are still there. Every other aggregate ORDER BY falls through to the
185
+ // applyOrderBy at the bottom of this function, which gets the final
186
+ // projection's output scope — the only place an alias of a *wrapped* aggregate
187
+ // (`count(*) + 1 as c`, whose aggregate entry is aliased `count(*)`) is named.
188
+ // Also skipped when window functions are present (window output isn't
181
189
  // available yet) or when pre-aggregate sort already handled ordering.
182
- if (aggregateResult.orderByHasAggregates &&
190
+ //
191
+ // The two scopes are mutually exclusive, so an ORDER BY that needs BOTH loses:
192
+ // `select count(*) + 1 as c from t order by max(a), c` takes this branch for
193
+ // `max(a)` and then cannot see `c`. Tracked as
194
+ // backlog/bug-order-by-alias-lost-when-order-by-adds-its-own-aggregate.
195
+ if (aggregateResult.orderByNeedsPostAggregateSort &&
196
+ aggregateResult.hasOrderByOnlyAggregates &&
183
197
  !preAggregateSort &&
184
198
  !hasWindowFunctions &&
185
199
  stmt.orderBy && stmt.orderBy.length > 0) {
186
- input = applyOrderBy(input, stmt, selectContext, preAggregateSort, undefined, true, selectListEntries);
200
+ input = applyOrderBy(input, stmt, selectContext, {
201
+ allowAggregates: true,
202
+ selectList: selectListEntries,
203
+ groupedRedirect: groupedRedirectContext,
204
+ });
187
205
  orderByAppliedEarly = true;
188
206
  }
189
- // A grouped, windowed query's window specifications and function arguments are
190
- // built against the aggregate-output scope but fall through to the pre-aggregate
191
- // select scope for anything the aggregate does not carry. Some of what falls
192
- // through is a legal grouping key under another spelling and some is a genuinely
193
- // ungrouped column, so hand the window phase both halves: the maps that redirect
194
- // the former onto the aggregate's own output columns, and the strict coverage
195
- // test that rejects the latter at plan time. The aggregate's source relation goes
196
- // along so both halves can tell which references belong to THIS query — a window
197
- // specification may contain a subquery, whose own columns and whose correlated
198
- // references to an enclosing query are neither redirected nor rejected.
199
- if (hasWindowFunctions &&
200
- aggregateResult.aggregateNode &&
201
- aggregateResult.groupByExpressions &&
202
- aggregateResult.groupByExpressions.length > 0) {
203
- windowGroupedContext = buildGroupedWindowContext(aggregateResult.groupByExpressions, aggregateResult.aggregateNode.getAttributes(), aggregateResult.aggregateNode.getRelations()[0]);
204
- }
205
207
  // Build final projections if needed. A window function in the select list also
206
208
  // forces one: the window phase projects the select list ABOVE its WindowNode, so
207
209
  // the grouped select list must be materialized as a projection list here even when
208
210
  // the AggregateNode's own output would otherwise have been the result shape.
209
211
  if ((aggregateResult.needsFinalProjection || hasWindowFunctions) && aggregateResult.aggregateNode && aggregateResult.groupByExpressions) {
210
- const finalProjections = buildFinalAggregateProjections(stmt, selectContext, aggregateResult.aggregateScope, aggregateResult.aggregateNode, aggregates, aggregateResult.groupByExpressions, starProjectionsByColumn);
212
+ const finalProjections = buildFinalAggregateProjections(stmt, selectContext, aggregateResult.aggregateScope, aggregateResult.aggregateNode, aggregates, aggregateResult.groupByExpressions, starProjectionsByColumn, groupedRedirectContext);
211
213
  if (hasWindowFunctions) {
212
214
  // Hand the grouped select list to the window phase instead of projecting it
213
215
  // here: the WindowNode must sit between the aggregate output and the final
@@ -250,9 +252,12 @@ preserveInputColumns = true) {
250
252
  if (!selectedColumns.has(orderColumn)) {
251
253
  // Apply ORDER BY before window projections. This sort sits BELOW the
252
254
  // window projection, so a positional reference resolves through the
253
- // select list (no output attributes exist yet to bind to).
255
+ // select list (no output attributes exist yet to bind to). In a
256
+ // grouped query this SortNode sits ABOVE the AggregateNode, so a key
257
+ // naming a grouping key by a spelling the aggregate output scope does
258
+ // not publish must land on the aggregate's own output column.
254
259
  const sortKeys = stmt.orderBy.map(orderBy => ({
255
- expression: buildOrdinalAwareExpression(selectContext, orderBy.expr, selectListEntries, 'ORDER BY'),
260
+ expression: redirectPostAggregate(buildOrdinalAwareExpression(selectContext, orderBy.expr, selectListEntries, 'ORDER BY'), groupedRedirectContext, selectContext.scope),
256
261
  direction: orderBy.direction,
257
262
  nulls: orderBy.nulls
258
263
  }));
@@ -263,7 +268,7 @@ preserveInputColumns = true) {
263
268
  }
264
269
  }
265
270
  }
266
- input = buildWindowPhase(input, windowFunctions, selectContext, windowSelectProjections ?? projections, windowGroupedContext);
271
+ input = buildWindowPhase(input, windowFunctions, selectContext, windowSelectProjections ?? projections, groupedRedirectContext);
267
272
  // The window phase ends in a ProjectNode over the SELECT list, so that node's
268
273
  // attributes are this query's result columns.
269
274
  orderByOutputRelation = input;
@@ -299,7 +304,12 @@ preserveInputColumns = true) {
299
304
  orderByOutputRelation = finalResult.output;
300
305
  // Apply final modifiers with projection scope for column alias resolution
301
306
  input = applyDistinct(input, stmt, selectScope);
302
- input = applyOrderBy(input, stmt, selectContext, preAggregateSort, finalResult.projectionScope, false, selectListEntries, orderByOutputRelation);
307
+ input = applyOrderBy(input, stmt, selectContext, {
308
+ preAggregateSort,
309
+ projectionScope: finalResult.projectionScope,
310
+ selectList: selectListEntries,
311
+ outputRelation: orderByOutputRelation,
312
+ });
303
313
  input = applyLimitOffset(input, stmt, selectContext, finalResult.projectionScope);
304
314
  }
305
315
  else {
@@ -311,10 +321,45 @@ preserveInputColumns = true) {
311
321
  if (!orderByAppliedEarly) {
312
322
  // In the aggregate path, ORDER BY may legally reference aggregates; in the
313
323
  // window path it may reference window outputs. Both are now in selectContext.
314
- input = applyOrderBy(input, stmt, selectContext, preAggregateSort, aggregateProjectionScope, hasAggregates, selectListEntries, orderByOutputRelation);
324
+ // `groupedRedirect` makes a sort key naming a grouping key by a spelling the
325
+ // output scopes do not publish (`order by wg.a`, `order by upper(wg.a)`, a
326
+ // repeated computed key) land on the AggregateNode's own output column.
327
+ // Without it the key binds to a base-table attribute and the sort dies at run
328
+ // time whenever a buffering operator — a WindowNode — sits between the
329
+ // aggregate and this sort.
330
+ input = applyOrderBy(input, stmt, selectContext, {
331
+ preAggregateSort,
332
+ projectionScope: aggregateProjectionScope,
333
+ allowAggregates: hasAggregates,
334
+ selectList: selectListEntries,
335
+ outputRelation: orderByOutputRelation,
336
+ groupedRedirect: groupedRedirectContext,
337
+ });
315
338
  }
316
339
  input = applyLimitOffset(input, stmt, selectContext, aggregateProjectionScope);
317
340
  }
341
+ // Boundary check over the finished plan of a GROUPED query: nothing above the
342
+ // AggregateNode may still reference a pre-grouping column, which is the invariant
343
+ // docs/runtime.md § "Corollary: a published source row reaches only the adjacent
344
+ // consumer" states. A post-aggregate builder that skipped redirectPostAggregate now
345
+ // fails here, at plan time, with the user-facing GROUP BY message — instead of
346
+ // shipping a plan that dies at run time with an internal "No row context found"
347
+ // error once a buffering operator separates it from the aggregate (how both the
348
+ // SELECT-list and ORDER BY escapes shipped).
349
+ //
350
+ // NOTE: deliberately STRICT — this also rejects a query that genuinely reads an
351
+ // ungrouped column above the aggregate (`select a from wg group by a order by b`,
352
+ // or a correlated subquery reading an ungrouped column), which previously ran and
353
+ // read an arbitrary representative row of each group. That was a wrong-result bug,
354
+ // no test asserted it (measured across the full engine suite: zero hand-written
355
+ // occurrences; 18 fuzz-generated sort keys, all in error-tolerant harnesses), and
356
+ // rejecting it matches what the SELECT list and HAVING already do. Revisit only if
357
+ // SQLite-style bare-column ORDER BY tolerance becomes a compatibility requirement;
358
+ // the weaker alternative is checking only above buffering operators (WindowNode),
359
+ // where the representative source row genuinely dies.
360
+ if (groupedRedirectContext && aggregateResult.aggregateNode) {
361
+ assertGroupedPlanCoverage(input, aggregateResult.aggregateNode, groupedRedirectContext);
362
+ }
318
363
  return input;
319
364
  }
320
365
  /**