@quereus/quereus 0.1.0 → 0.2.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 (477) hide show
  1. package/README.md +47 -23
  2. package/dist/src/common/types.d.ts +1 -0
  3. package/dist/src/common/types.d.ts.map +1 -1
  4. package/dist/src/core/database.d.ts +22 -4
  5. package/dist/src/core/database.d.ts.map +1 -1
  6. package/dist/src/core/database.js +44 -6
  7. package/dist/src/core/database.js.map +1 -1
  8. package/dist/src/core/statement.d.ts +0 -7
  9. package/dist/src/core/statement.d.ts.map +1 -1
  10. package/dist/src/core/statement.js +1 -51
  11. package/dist/src/core/statement.js.map +1 -1
  12. package/dist/src/func/builtins/explain.d.ts.map +1 -1
  13. package/dist/src/func/builtins/explain.js +0 -11
  14. package/dist/src/func/builtins/explain.js.map +1 -1
  15. package/dist/src/index.d.ts +13 -5
  16. package/dist/src/index.d.ts.map +1 -1
  17. package/dist/src/index.js +5 -2
  18. package/dist/src/index.js.map +1 -1
  19. package/dist/src/parser/ast.d.ts +10 -4
  20. package/dist/src/parser/ast.d.ts.map +1 -1
  21. package/dist/src/parser/parser.d.ts.map +1 -1
  22. package/dist/src/parser/parser.js +40 -44
  23. package/dist/src/parser/parser.js.map +1 -1
  24. package/dist/src/planner/analysis/const-pass.d.ts.map +1 -1
  25. package/dist/src/planner/analysis/const-pass.js +12 -6
  26. package/dist/src/planner/analysis/const-pass.js.map +1 -1
  27. package/dist/src/planner/building/constraint-builder.d.ts +11 -0
  28. package/dist/src/planner/building/constraint-builder.d.ts.map +1 -0
  29. package/dist/src/planner/building/constraint-builder.js +79 -0
  30. package/dist/src/planner/building/constraint-builder.js.map +1 -0
  31. package/dist/src/planner/building/delete.d.ts.map +1 -1
  32. package/dist/src/planner/building/delete.js +7 -4
  33. package/dist/src/planner/building/delete.js.map +1 -1
  34. package/dist/src/planner/building/expression.d.ts +3 -0
  35. package/dist/src/planner/building/expression.d.ts.map +1 -1
  36. package/dist/src/planner/building/expression.js +33 -7
  37. package/dist/src/planner/building/expression.js.map +1 -1
  38. package/dist/src/planner/building/insert.d.ts.map +1 -1
  39. package/dist/src/planner/building/insert.js +5 -2
  40. package/dist/src/planner/building/insert.js.map +1 -1
  41. package/dist/src/planner/building/select-aggregates.d.ts.map +1 -1
  42. package/dist/src/planner/building/select-aggregates.js +46 -9
  43. package/dist/src/planner/building/select-aggregates.js.map +1 -1
  44. package/dist/src/planner/building/select-context.js +20 -11
  45. package/dist/src/planner/building/select-context.js.map +1 -1
  46. package/dist/src/planner/building/select-modifiers.d.ts +5 -3
  47. package/dist/src/planner/building/select-modifiers.d.ts.map +1 -1
  48. package/dist/src/planner/building/select-modifiers.js +29 -20
  49. package/dist/src/planner/building/select-modifiers.js.map +1 -1
  50. package/dist/src/planner/building/select-projections.d.ts +3 -1
  51. package/dist/src/planner/building/select-projections.d.ts.map +1 -1
  52. package/dist/src/planner/building/select-projections.js +15 -20
  53. package/dist/src/planner/building/select-projections.js.map +1 -1
  54. package/dist/src/planner/building/select-window.d.ts.map +1 -1
  55. package/dist/src/planner/building/select-window.js +6 -3
  56. package/dist/src/planner/building/select-window.js.map +1 -1
  57. package/dist/src/planner/building/select.d.ts +25 -2
  58. package/dist/src/planner/building/select.d.ts.map +1 -1
  59. package/dist/src/planner/building/select.js +147 -24
  60. package/dist/src/planner/building/select.js.map +1 -1
  61. package/dist/src/planner/building/table.d.ts +0 -10
  62. package/dist/src/planner/building/table.d.ts.map +1 -1
  63. package/dist/src/planner/building/table.js +1 -35
  64. package/dist/src/planner/building/table.js.map +1 -1
  65. package/dist/src/planner/building/update.d.ts.map +1 -1
  66. package/dist/src/planner/building/update.js +8 -5
  67. package/dist/src/planner/building/update.js.map +1 -1
  68. package/dist/src/planner/building/with.d.ts.map +1 -1
  69. package/dist/src/planner/building/with.js +7 -8
  70. package/dist/src/planner/building/with.js.map +1 -1
  71. package/dist/src/planner/cache/correlation-detector.d.ts +11 -0
  72. package/dist/src/planner/cache/correlation-detector.d.ts.map +1 -0
  73. package/dist/src/planner/cache/correlation-detector.js +73 -0
  74. package/dist/src/planner/cache/correlation-detector.js.map +1 -0
  75. package/dist/src/planner/cache/materialization-advisory.d.ts +12 -18
  76. package/dist/src/planner/cache/materialization-advisory.d.ts.map +1 -1
  77. package/dist/src/planner/cache/materialization-advisory.js +65 -46
  78. package/dist/src/planner/cache/materialization-advisory.js.map +1 -1
  79. package/dist/src/planner/cache/reference-graph.d.ts +14 -9
  80. package/dist/src/planner/cache/reference-graph.d.ts.map +1 -1
  81. package/dist/src/planner/cache/reference-graph.js +93 -84
  82. package/dist/src/planner/cache/reference-graph.js.map +1 -1
  83. package/dist/src/planner/debug.d.ts +25 -0
  84. package/dist/src/planner/debug.d.ts.map +1 -1
  85. package/dist/src/planner/debug.js +127 -0
  86. package/dist/src/planner/debug.js.map +1 -1
  87. package/dist/src/planner/framework/context.d.ts +11 -0
  88. package/dist/src/planner/framework/context.d.ts.map +1 -1
  89. package/dist/src/planner/framework/context.js +25 -2
  90. package/dist/src/planner/framework/context.js.map +1 -1
  91. package/dist/src/planner/framework/registry.d.ts +3 -7
  92. package/dist/src/planner/framework/registry.d.ts.map +1 -1
  93. package/dist/src/planner/framework/registry.js +20 -31
  94. package/dist/src/planner/framework/registry.js.map +1 -1
  95. package/dist/src/planner/nodes/add-constraint-node.d.ts +2 -1
  96. package/dist/src/planner/nodes/add-constraint-node.d.ts.map +1 -1
  97. package/dist/src/planner/nodes/add-constraint-node.js +3 -0
  98. package/dist/src/planner/nodes/add-constraint-node.js.map +1 -1
  99. package/dist/src/planner/nodes/aggregate-node.d.ts.map +1 -1
  100. package/dist/src/planner/nodes/aggregate-node.js +6 -4
  101. package/dist/src/planner/nodes/aggregate-node.js.map +1 -1
  102. package/dist/src/planner/nodes/cache-node.d.ts.map +1 -1
  103. package/dist/src/planner/nodes/cache-node.js +2 -2
  104. package/dist/src/planner/nodes/cache-node.js.map +1 -1
  105. package/dist/src/planner/nodes/constraint-check-node.d.ts +13 -6
  106. package/dist/src/planner/nodes/constraint-check-node.d.ts.map +1 -1
  107. package/dist/src/planner/nodes/constraint-check-node.js +38 -12
  108. package/dist/src/planner/nodes/constraint-check-node.js.map +1 -1
  109. package/dist/src/planner/nodes/create-index-node.d.ts +2 -1
  110. package/dist/src/planner/nodes/create-index-node.d.ts.map +1 -1
  111. package/dist/src/planner/nodes/create-index-node.js +3 -0
  112. package/dist/src/planner/nodes/create-index-node.js.map +1 -1
  113. package/dist/src/planner/nodes/create-table-node.d.ts +2 -1
  114. package/dist/src/planner/nodes/create-table-node.d.ts.map +1 -1
  115. package/dist/src/planner/nodes/create-table-node.js +3 -0
  116. package/dist/src/planner/nodes/create-table-node.js.map +1 -1
  117. package/dist/src/planner/nodes/create-view-node.d.ts +2 -1
  118. package/dist/src/planner/nodes/create-view-node.d.ts.map +1 -1
  119. package/dist/src/planner/nodes/create-view-node.js +3 -0
  120. package/dist/src/planner/nodes/create-view-node.js.map +1 -1
  121. package/dist/src/planner/nodes/cte-node.d.ts +1 -1
  122. package/dist/src/planner/nodes/cte-node.d.ts.map +1 -1
  123. package/dist/src/planner/nodes/cte-node.js +33 -12
  124. package/dist/src/planner/nodes/cte-node.js.map +1 -1
  125. package/dist/src/planner/nodes/cte-reference-node.d.ts +18 -4
  126. package/dist/src/planner/nodes/cte-reference-node.d.ts.map +1 -1
  127. package/dist/src/planner/nodes/cte-reference-node.js +40 -10
  128. package/dist/src/planner/nodes/cte-reference-node.js.map +1 -1
  129. package/dist/src/planner/nodes/delete-node.d.ts +4 -3
  130. package/dist/src/planner/nodes/delete-node.d.ts.map +1 -1
  131. package/dist/src/planner/nodes/delete-node.js +20 -6
  132. package/dist/src/planner/nodes/delete-node.js.map +1 -1
  133. package/dist/src/planner/nodes/distinct-node.d.ts.map +1 -1
  134. package/dist/src/planner/nodes/distinct-node.js +2 -2
  135. package/dist/src/planner/nodes/distinct-node.js.map +1 -1
  136. package/dist/src/planner/nodes/dml-executor-node.d.ts +1 -1
  137. package/dist/src/planner/nodes/dml-executor-node.d.ts.map +1 -1
  138. package/dist/src/planner/nodes/dml-executor-node.js +2 -2
  139. package/dist/src/planner/nodes/dml-executor-node.js.map +1 -1
  140. package/dist/src/planner/nodes/drop-table-node.d.ts +2 -1
  141. package/dist/src/planner/nodes/drop-table-node.d.ts.map +1 -1
  142. package/dist/src/planner/nodes/drop-table-node.js +3 -0
  143. package/dist/src/planner/nodes/drop-table-node.js.map +1 -1
  144. package/dist/src/planner/nodes/drop-view-node.d.ts +2 -1
  145. package/dist/src/planner/nodes/drop-view-node.d.ts.map +1 -1
  146. package/dist/src/planner/nodes/drop-view-node.js +3 -0
  147. package/dist/src/planner/nodes/drop-view-node.js.map +1 -1
  148. package/dist/src/planner/nodes/filter.d.ts.map +1 -1
  149. package/dist/src/planner/nodes/filter.js +3 -3
  150. package/dist/src/planner/nodes/filter.js.map +1 -1
  151. package/dist/src/planner/nodes/insert-node.d.ts +2 -1
  152. package/dist/src/planner/nodes/insert-node.d.ts.map +1 -1
  153. package/dist/src/planner/nodes/insert-node.js +18 -5
  154. package/dist/src/planner/nodes/insert-node.js.map +1 -1
  155. package/dist/src/planner/nodes/internal-recursive-cte-ref-node.d.ts +28 -0
  156. package/dist/src/planner/nodes/internal-recursive-cte-ref-node.d.ts.map +1 -0
  157. package/dist/src/planner/nodes/internal-recursive-cte-ref-node.js +69 -0
  158. package/dist/src/planner/nodes/internal-recursive-cte-ref-node.js.map +1 -0
  159. package/dist/src/planner/nodes/join-node.d.ts.map +1 -1
  160. package/dist/src/planner/nodes/join-node.js +3 -3
  161. package/dist/src/planner/nodes/join-node.js.map +1 -1
  162. package/dist/src/planner/nodes/limit-offset.d.ts.map +1 -1
  163. package/dist/src/planner/nodes/limit-offset.js +2 -2
  164. package/dist/src/planner/nodes/limit-offset.js.map +1 -1
  165. package/dist/src/planner/nodes/plan-node-type.d.ts +1 -1
  166. package/dist/src/planner/nodes/plan-node-type.d.ts.map +1 -1
  167. package/dist/src/planner/nodes/plan-node-type.js +1 -1
  168. package/dist/src/planner/nodes/plan-node-type.js.map +1 -1
  169. package/dist/src/planner/nodes/plan-node.d.ts +23 -0
  170. package/dist/src/planner/nodes/plan-node.d.ts.map +1 -1
  171. package/dist/src/planner/nodes/plan-node.js +25 -2
  172. package/dist/src/planner/nodes/plan-node.js.map +1 -1
  173. package/dist/src/planner/nodes/project-node.d.ts +5 -1
  174. package/dist/src/planner/nodes/project-node.d.ts.map +1 -1
  175. package/dist/src/planner/nodes/project-node.js +39 -20
  176. package/dist/src/planner/nodes/project-node.js.map +1 -1
  177. package/dist/src/planner/nodes/recursive-cte-node.d.ts +2 -2
  178. package/dist/src/planner/nodes/recursive-cte-node.d.ts.map +1 -1
  179. package/dist/src/planner/nodes/recursive-cte-node.js +20 -8
  180. package/dist/src/planner/nodes/recursive-cte-node.js.map +1 -1
  181. package/dist/src/planner/nodes/reference.d.ts.map +1 -1
  182. package/dist/src/planner/nodes/reference.js +4 -2
  183. package/dist/src/planner/nodes/reference.js.map +1 -1
  184. package/dist/src/planner/nodes/returning-node.d.ts +1 -1
  185. package/dist/src/planner/nodes/returning-node.d.ts.map +1 -1
  186. package/dist/src/planner/nodes/returning-node.js +21 -13
  187. package/dist/src/planner/nodes/returning-node.js.map +1 -1
  188. package/dist/src/planner/nodes/scalar.d.ts +26 -2
  189. package/dist/src/planner/nodes/scalar.d.ts.map +1 -1
  190. package/dist/src/planner/nodes/scalar.js +82 -10
  191. package/dist/src/planner/nodes/scalar.js.map +1 -1
  192. package/dist/src/planner/nodes/sequencing-node.d.ts.map +1 -1
  193. package/dist/src/planner/nodes/sequencing-node.js +2 -2
  194. package/dist/src/planner/nodes/sequencing-node.js.map +1 -1
  195. package/dist/src/planner/nodes/set-operation-node.d.ts.map +1 -1
  196. package/dist/src/planner/nodes/set-operation-node.js +3 -3
  197. package/dist/src/planner/nodes/set-operation-node.js.map +1 -1
  198. package/dist/src/planner/nodes/single-row.d.ts +4 -2
  199. package/dist/src/planner/nodes/single-row.d.ts.map +1 -1
  200. package/dist/src/planner/nodes/single-row.js +3 -0
  201. package/dist/src/planner/nodes/single-row.js.map +1 -1
  202. package/dist/src/planner/nodes/sink-node.d.ts +1 -1
  203. package/dist/src/planner/nodes/sink-node.d.ts.map +1 -1
  204. package/dist/src/planner/nodes/sink-node.js +4 -4
  205. package/dist/src/planner/nodes/sink-node.js.map +1 -1
  206. package/dist/src/planner/nodes/sort.d.ts.map +1 -1
  207. package/dist/src/planner/nodes/sort.js +2 -2
  208. package/dist/src/planner/nodes/sort.js.map +1 -1
  209. package/dist/src/planner/nodes/stream-aggregate.d.ts +1 -0
  210. package/dist/src/planner/nodes/stream-aggregate.d.ts.map +1 -1
  211. package/dist/src/planner/nodes/stream-aggregate.js +64 -11
  212. package/dist/src/planner/nodes/stream-aggregate.js.map +1 -1
  213. package/dist/src/planner/nodes/subquery.d.ts +4 -4
  214. package/dist/src/planner/nodes/subquery.d.ts.map +1 -1
  215. package/dist/src/planner/nodes/subquery.js +68 -23
  216. package/dist/src/planner/nodes/subquery.js.map +1 -1
  217. package/dist/src/planner/nodes/table-access-nodes.d.ts +83 -0
  218. package/dist/src/planner/nodes/table-access-nodes.d.ts.map +1 -0
  219. package/dist/src/planner/nodes/table-access-nodes.js +226 -0
  220. package/dist/src/planner/nodes/table-access-nodes.js.map +1 -0
  221. package/dist/src/planner/nodes/update-node.d.ts +4 -2
  222. package/dist/src/planner/nodes/update-node.d.ts.map +1 -1
  223. package/dist/src/planner/nodes/update-node.js +26 -13
  224. package/dist/src/planner/nodes/update-node.js.map +1 -1
  225. package/dist/src/planner/nodes/window-node.d.ts.map +1 -1
  226. package/dist/src/planner/nodes/window-node.js +25 -23
  227. package/dist/src/planner/nodes/window-node.js.map +1 -1
  228. package/dist/src/planner/optimizer.d.ts.map +1 -1
  229. package/dist/src/planner/optimizer.js +46 -50
  230. package/dist/src/planner/optimizer.js.map +1 -1
  231. package/dist/src/planner/planning-context.d.ts +13 -0
  232. package/dist/src/planner/planning-context.d.ts.map +1 -1
  233. package/dist/src/planner/planning-context.js.map +1 -1
  234. package/dist/src/planner/rules/access/rule-select-access-path.d.ts +1 -1
  235. package/dist/src/planner/rules/access/rule-select-access-path.d.ts.map +1 -1
  236. package/dist/src/planner/rules/access/rule-select-access-path.js +59 -53
  237. package/dist/src/planner/rules/access/rule-select-access-path.js.map +1 -1
  238. package/dist/src/planner/rules/aggregate/rule-aggregate-streaming.d.ts.map +1 -1
  239. package/dist/src/planner/rules/aggregate/rule-aggregate-streaming.js +62 -2
  240. package/dist/src/planner/rules/aggregate/rule-aggregate-streaming.js.map +1 -1
  241. package/dist/src/planner/rules/cache/rule-materialization-advisory.d.ts.map +1 -1
  242. package/dist/src/planner/rules/cache/rule-materialization-advisory.js +31 -24
  243. package/dist/src/planner/rules/cache/rule-materialization-advisory.js.map +1 -1
  244. package/dist/src/planner/scopes/base.d.ts +0 -10
  245. package/dist/src/planner/scopes/base.d.ts.map +1 -1
  246. package/dist/src/planner/scopes/base.js +0 -14
  247. package/dist/src/planner/scopes/base.js.map +1 -1
  248. package/dist/src/planner/scopes/empty.d.ts +0 -2
  249. package/dist/src/planner/scopes/empty.d.ts.map +1 -1
  250. package/dist/src/planner/scopes/empty.js +0 -8
  251. package/dist/src/planner/scopes/empty.js.map +1 -1
  252. package/dist/src/planner/scopes/multi.d.ts.map +1 -1
  253. package/dist/src/planner/scopes/multi.js +0 -1
  254. package/dist/src/planner/scopes/multi.js.map +1 -1
  255. package/dist/src/planner/scopes/param.d.ts.map +1 -1
  256. package/dist/src/planner/scopes/param.js +0 -1
  257. package/dist/src/planner/scopes/param.js.map +1 -1
  258. package/dist/src/planner/scopes/registered.d.ts +0 -10
  259. package/dist/src/planner/scopes/registered.d.ts.map +1 -1
  260. package/dist/src/planner/scopes/registered.js +1 -17
  261. package/dist/src/planner/scopes/registered.js.map +1 -1
  262. package/dist/src/planner/scopes/scope.d.ts +0 -8
  263. package/dist/src/planner/scopes/scope.d.ts.map +1 -1
  264. package/dist/src/planner/validation/plan-validator.d.ts.map +1 -1
  265. package/dist/src/planner/validation/plan-validator.js +1 -7
  266. package/dist/src/planner/validation/plan-validator.js.map +1 -1
  267. package/dist/src/runtime/context-helpers.d.ts +45 -0
  268. package/dist/src/runtime/context-helpers.d.ts.map +1 -0
  269. package/dist/src/runtime/context-helpers.js +139 -0
  270. package/dist/src/runtime/context-helpers.js.map +1 -0
  271. package/dist/src/runtime/emission-context.d.ts +1 -0
  272. package/dist/src/runtime/emission-context.d.ts.map +1 -1
  273. package/dist/src/runtime/emission-context.js +2 -1
  274. package/dist/src/runtime/emission-context.js.map +1 -1
  275. package/dist/src/runtime/emit/aggregate.d.ts.map +1 -1
  276. package/dist/src/runtime/emit/aggregate.js +119 -86
  277. package/dist/src/runtime/emit/aggregate.js.map +1 -1
  278. package/dist/src/runtime/emit/between.d.ts +5 -0
  279. package/dist/src/runtime/emit/between.d.ts.map +1 -0
  280. package/dist/src/runtime/emit/between.js +38 -0
  281. package/dist/src/runtime/emit/between.js.map +1 -0
  282. package/dist/src/runtime/emit/binary.d.ts +0 -1
  283. package/dist/src/runtime/emit/binary.d.ts.map +1 -1
  284. package/dist/src/runtime/emit/binary.js +0 -36
  285. package/dist/src/runtime/emit/binary.js.map +1 -1
  286. package/dist/src/runtime/emit/column-reference.d.ts.map +1 -1
  287. package/dist/src/runtime/emit/column-reference.js +2 -26
  288. package/dist/src/runtime/emit/column-reference.js.map +1 -1
  289. package/dist/src/runtime/emit/constraint-check.d.ts.map +1 -1
  290. package/dist/src/runtime/emit/constraint-check.js +16 -123
  291. package/dist/src/runtime/emit/constraint-check.js.map +1 -1
  292. package/dist/src/runtime/emit/cte-reference.d.ts.map +1 -1
  293. package/dist/src/runtime/emit/cte-reference.js +16 -48
  294. package/dist/src/runtime/emit/cte-reference.js.map +1 -1
  295. package/dist/src/runtime/emit/distinct.d.ts.map +1 -1
  296. package/dist/src/runtime/emit/distinct.js +2 -8
  297. package/dist/src/runtime/emit/distinct.js.map +1 -1
  298. package/dist/src/runtime/emit/filter.d.ts.map +1 -1
  299. package/dist/src/runtime/emit/filter.js +6 -13
  300. package/dist/src/runtime/emit/filter.js.map +1 -1
  301. package/dist/src/runtime/emit/internal-recursive-cte-ref.d.ts +5 -0
  302. package/dist/src/runtime/emit/internal-recursive-cte-ref.d.ts.map +1 -0
  303. package/dist/src/runtime/emit/internal-recursive-cte-ref.js +23 -0
  304. package/dist/src/runtime/emit/internal-recursive-cte-ref.js.map +1 -0
  305. package/dist/src/runtime/emit/join.d.ts.map +1 -1
  306. package/dist/src/runtime/emit/join.js +40 -40
  307. package/dist/src/runtime/emit/join.js.map +1 -1
  308. package/dist/src/runtime/emit/project.d.ts.map +1 -1
  309. package/dist/src/runtime/emit/project.js +13 -13
  310. package/dist/src/runtime/emit/project.js.map +1 -1
  311. package/dist/src/runtime/emit/recursive-cte.d.ts.map +1 -1
  312. package/dist/src/runtime/emit/recursive-cte.js +3 -14
  313. package/dist/src/runtime/emit/recursive-cte.js.map +1 -1
  314. package/dist/src/runtime/emit/returning.d.ts.map +1 -1
  315. package/dist/src/runtime/emit/returning.js +7 -14
  316. package/dist/src/runtime/emit/returning.js.map +1 -1
  317. package/dist/src/runtime/emit/scan.d.ts +5 -2
  318. package/dist/src/runtime/emit/scan.d.ts.map +1 -1
  319. package/dist/src/runtime/emit/scan.js +21 -17
  320. package/dist/src/runtime/emit/scan.js.map +1 -1
  321. package/dist/src/runtime/emit/sort.d.ts.map +1 -1
  322. package/dist/src/runtime/emit/sort.js +8 -11
  323. package/dist/src/runtime/emit/sort.js.map +1 -1
  324. package/dist/src/runtime/emit/subquery.d.ts.map +1 -1
  325. package/dist/src/runtime/emit/subquery.js +95 -40
  326. package/dist/src/runtime/emit/subquery.js.map +1 -1
  327. package/dist/src/runtime/emit/table-valued-function.d.ts.map +1 -1
  328. package/dist/src/runtime/emit/table-valued-function.js +7 -22
  329. package/dist/src/runtime/emit/table-valued-function.js.map +1 -1
  330. package/dist/src/runtime/emit/update.d.ts.map +1 -1
  331. package/dist/src/runtime/emit/update.js +20 -27
  332. package/dist/src/runtime/emit/update.js.map +1 -1
  333. package/dist/src/runtime/emit/window.d.ts.map +1 -1
  334. package/dist/src/runtime/emit/window.js +55 -83
  335. package/dist/src/runtime/emit/window.js.map +1 -1
  336. package/dist/src/runtime/emitters.d.ts.map +1 -1
  337. package/dist/src/runtime/emitters.js +49 -1
  338. package/dist/src/runtime/emitters.js.map +1 -1
  339. package/dist/src/runtime/register.d.ts.map +1 -1
  340. package/dist/src/runtime/register.js +5 -4
  341. package/dist/src/runtime/register.js.map +1 -1
  342. package/dist/src/runtime/scheduler.d.ts.map +1 -1
  343. package/dist/src/runtime/scheduler.js +47 -42
  344. package/dist/src/runtime/scheduler.js.map +1 -1
  345. package/dist/src/runtime/types.d.ts +34 -0
  346. package/dist/src/runtime/types.d.ts.map +1 -1
  347. package/dist/src/runtime/types.js +21 -0
  348. package/dist/src/runtime/types.js.map +1 -1
  349. package/dist/src/schema/manager.d.ts.map +1 -1
  350. package/dist/src/schema/manager.js +29 -16
  351. package/dist/src/schema/manager.js.map +1 -1
  352. package/dist/src/schema/table.d.ts +4 -4
  353. package/dist/src/schema/table.d.ts.map +1 -1
  354. package/dist/src/schema/table.js +10 -10
  355. package/dist/src/schema/table.js.map +1 -1
  356. package/dist/src/util/plugin-loader.d.ts +10 -1
  357. package/dist/src/util/plugin-loader.d.ts.map +1 -1
  358. package/dist/src/util/plugin-loader.js +56 -1
  359. package/dist/src/util/plugin-loader.js.map +1 -1
  360. package/dist/src/util/working-table-iterable.d.ts.map +1 -1
  361. package/dist/src/util/working-table-iterable.js +8 -8
  362. package/dist/src/util/working-table-iterable.js.map +1 -1
  363. package/dist/src/vtab/manifest.d.ts +36 -0
  364. package/dist/src/vtab/manifest.d.ts.map +1 -1
  365. package/dist/src/vtab/table.d.ts +1 -1
  366. package/dist/src/vtab/table.d.ts.map +1 -1
  367. package/package.json +8 -3
  368. package/src/common/types.ts +1 -0
  369. package/src/core/database.ts +48 -6
  370. package/src/core/statement.ts +1 -49
  371. package/src/func/builtins/explain.ts +0 -11
  372. package/src/index.ts +39 -5
  373. package/src/parser/ast.ts +12 -6
  374. package/src/parser/parser.ts +45 -52
  375. package/src/planner/analysis/const-pass.ts +281 -270
  376. package/src/planner/building/constraint-builder.ts +114 -0
  377. package/src/planner/building/delete.ts +18 -5
  378. package/src/planner/building/expression.ts +35 -7
  379. package/src/planner/building/insert.ts +16 -3
  380. package/src/planner/building/select-aggregates.ts +57 -11
  381. package/src/planner/building/select-context.ts +22 -12
  382. package/src/planner/building/select-modifiers.ts +35 -21
  383. package/src/planner/building/select-projections.ts +25 -26
  384. package/src/planner/building/select-window.ts +14 -9
  385. package/src/planner/building/select.ts +163 -31
  386. package/src/planner/building/table.ts +1 -40
  387. package/src/planner/building/update.ts +22 -7
  388. package/src/planner/building/with.ts +12 -13
  389. package/src/planner/cache/correlation-detector.ts +83 -0
  390. package/src/planner/cache/materialization-advisory.ts +71 -50
  391. package/src/planner/cache/reference-graph.ts +115 -91
  392. package/src/planner/debug.ts +163 -0
  393. package/src/planner/framework/context.ts +36 -2
  394. package/src/planner/framework/registry.ts +261 -274
  395. package/src/planner/nodes/add-constraint-node.ts +5 -1
  396. package/src/planner/nodes/aggregate-node.ts +6 -4
  397. package/src/planner/nodes/cache-node.ts +2 -2
  398. package/src/planner/nodes/constraint-check-node.ts +49 -15
  399. package/src/planner/nodes/create-index-node.ts +5 -1
  400. package/src/planner/nodes/create-table-node.ts +5 -1
  401. package/src/planner/nodes/create-view-node.ts +5 -1
  402. package/src/planner/nodes/cte-node.ts +45 -14
  403. package/src/planner/nodes/cte-reference-node.ts +49 -13
  404. package/src/planner/nodes/delete-node.ts +31 -7
  405. package/src/planner/nodes/distinct-node.ts +2 -2
  406. package/src/planner/nodes/dml-executor-node.ts +3 -3
  407. package/src/planner/nodes/drop-table-node.ts +5 -1
  408. package/src/planner/nodes/drop-view-node.ts +5 -1
  409. package/src/planner/nodes/filter.ts +3 -3
  410. package/src/planner/nodes/function.ts +93 -93
  411. package/src/planner/nodes/insert-node.ts +28 -5
  412. package/src/planner/nodes/internal-recursive-cte-ref-node.ts +76 -0
  413. package/src/planner/nodes/join-node.ts +3 -3
  414. package/src/planner/nodes/limit-offset.ts +2 -2
  415. package/src/planner/nodes/plan-node-type.ts +1 -1
  416. package/src/planner/nodes/plan-node.ts +39 -2
  417. package/src/planner/nodes/project-node.ts +39 -19
  418. package/src/planner/nodes/recursive-cte-node.ts +37 -9
  419. package/src/planner/nodes/reference.ts +4 -2
  420. package/src/planner/nodes/returning-node.ts +25 -13
  421. package/src/planner/nodes/scalar.ts +95 -11
  422. package/src/planner/nodes/sequencing-node.ts +2 -2
  423. package/src/planner/nodes/set-operation-node.ts +3 -3
  424. package/src/planner/nodes/single-row.ts +7 -2
  425. package/src/planner/nodes/sink-node.ts +5 -5
  426. package/src/planner/nodes/sort.ts +2 -2
  427. package/src/planner/nodes/stream-aggregate.ts +76 -12
  428. package/src/planner/nodes/subquery.ts +90 -27
  429. package/src/planner/nodes/{physical-access-nodes.ts → table-access-nodes.ts} +6 -6
  430. package/src/planner/nodes/update-node.ts +31 -13
  431. package/src/planner/nodes/window-node.ts +28 -22
  432. package/src/planner/optimizer.ts +257 -263
  433. package/src/planner/planning-context.ts +15 -0
  434. package/src/planner/rules/access/rule-select-access-path.ts +68 -64
  435. package/src/planner/rules/aggregate/rule-aggregate-streaming.ts +74 -2
  436. package/src/planner/rules/cache/rule-materialization-advisory.ts +31 -27
  437. package/src/planner/scopes/base.ts +0 -17
  438. package/src/planner/scopes/empty.ts +0 -10
  439. package/src/planner/scopes/multi.ts +0 -1
  440. package/src/planner/scopes/param.ts +0 -1
  441. package/src/planner/scopes/registered.ts +1 -20
  442. package/src/planner/scopes/scope.ts +0 -12
  443. package/src/planner/validation/plan-validator.ts +1 -8
  444. package/src/runtime/context-helpers.ts +191 -0
  445. package/src/runtime/emission-context.ts +5 -2
  446. package/src/runtime/emit/aggregate.ts +131 -85
  447. package/src/runtime/emit/between.ts +51 -0
  448. package/src/runtime/emit/binary.ts +0 -46
  449. package/src/runtime/emit/column-reference.ts +3 -36
  450. package/src/runtime/emit/constraint-check.ts +19 -144
  451. package/src/runtime/emit/cte-reference.ts +23 -60
  452. package/src/runtime/emit/distinct.ts +2 -7
  453. package/src/runtime/emit/filter.ts +6 -13
  454. package/src/runtime/emit/internal-recursive-cte-ref.ts +37 -0
  455. package/src/runtime/emit/join.ts +45 -43
  456. package/src/runtime/emit/project.ts +18 -12
  457. package/src/runtime/emit/recursive-cte.ts +3 -12
  458. package/src/runtime/emit/returning.ts +7 -14
  459. package/src/runtime/emit/scan.ts +25 -23
  460. package/src/runtime/emit/sort.ts +8 -11
  461. package/src/runtime/emit/subquery.ts +108 -48
  462. package/src/runtime/emit/table-valued-function.ts +7 -20
  463. package/src/runtime/emit/update.ts +22 -29
  464. package/src/runtime/emit/window.ts +74 -88
  465. package/src/runtime/emitters.ts +52 -1
  466. package/src/runtime/register.ts +5 -4
  467. package/src/runtime/scheduler.ts +54 -54
  468. package/src/runtime/types.ts +45 -0
  469. package/src/schema/manager.ts +34 -19
  470. package/src/schema/table.ts +8 -8
  471. package/src/util/plugin-loader.ts +78 -4
  472. package/src/util/working-table-iterable.ts +15 -7
  473. package/src/vtab/manifest.ts +42 -0
  474. package/src/vtab/table.ts +1 -1
  475. package/src/planner/nodes/scan.ts +0 -103
  476. package/src/planner/rules/physical/rule-mark-physical.ts +0 -37
  477. package/src/runtime/emit/table-reference.ts +0 -92
@@ -1,18 +1,21 @@
1
1
  import { emitPlanNode } from '../emitters.js';
2
- import { compareSqlValuesFast, BINARY_COLLATION } from '../../util/comparison.js';
2
+ import { compareSqlValuesFast, resolveCollation } from '../../util/comparison.js';
3
3
  import { QuereusError } from '../../common/errors.js';
4
4
  import { StatusCode } from '../../common/types.js';
5
5
  import { BTree } from 'inheritree';
6
6
  export function emitScalarSubquery(plan, ctx) {
7
- async function run(ctx, input) {
7
+ async function run(rctx, input) {
8
8
  let result = null;
9
9
  let seen = false;
10
10
  for await (const row of input) {
11
11
  if (seen) {
12
12
  throw new QuereusError('Scalar subquery returned more than one row', StatusCode.ERROR, undefined, plan.expression.loc?.start.line, plan.expression.loc?.start.column);
13
13
  }
14
+ if (row.length > 1) {
15
+ throw new QuereusError('Subquery should return at most one column', StatusCode.ERROR);
16
+ }
17
+ result = row.length === 0 ? null : row[0];
14
18
  seen = true;
15
- result = row[0];
16
19
  }
17
20
  return result;
18
21
  }
@@ -20,19 +23,22 @@ export function emitScalarSubquery(plan, ctx) {
20
23
  return {
21
24
  params: [innerInstruction],
22
25
  run,
23
- note: 'scalar subquery'
26
+ note: 'SCALAR_SUBQUERY'
24
27
  };
25
28
  }
26
29
  export function emitIn(plan, ctx) {
30
+ // Extract collation from the condition expression
31
+ const conditionType = plan.condition.getType();
32
+ const collationName = conditionType.collationName || 'BINARY';
33
+ const collation = resolveCollation(collationName);
27
34
  if (plan.source) {
28
35
  // IN subquery: expr IN (SELECT ...)
29
- async function runSubquery(ctx, input, condition) {
36
+ // Use streaming approach - check each row as we read it, return early on match
37
+ async function runSubqueryStreaming(_rctx, input, condition) {
30
38
  // If condition is NULL, result is NULL
31
39
  if (condition === null) {
32
40
  return null;
33
41
  }
34
- // Build BTree of all values from subquery
35
- const tree = new BTree((val) => val, (a, b) => compareSqlValuesFast(a, b, BINARY_COLLATION));
36
42
  let hasNull = false;
37
43
  for await (const row of input) {
38
44
  if (row.length > 0) {
@@ -41,14 +47,12 @@ export function emitIn(plan, ctx) {
41
47
  hasNull = true;
42
48
  continue;
43
49
  }
44
- tree.insert(rowValue);
50
+ // Check for match immediately - no need to materialize
51
+ if (compareSqlValuesFast(condition, rowValue, collation) === 0) {
52
+ return 1; // Found a match
53
+ }
45
54
  }
46
55
  }
47
- // Check if condition exists in tree
48
- const value = tree.get(condition);
49
- if (value !== undefined) {
50
- return 1; // Found a match
51
- }
52
56
  // No match found - if any value was NULL, result is NULL
53
57
  return hasNull ? null : 0;
54
58
  }
@@ -56,49 +60,100 @@ export function emitIn(plan, ctx) {
56
60
  const conditionExpr = emitPlanNode(plan.condition, ctx);
57
61
  return {
58
62
  params: [sourceInstruction, conditionExpr],
59
- run: runSubquery,
63
+ run: runSubqueryStreaming,
60
64
  note: `IN (subquery)`
61
65
  };
62
66
  }
63
67
  else if (plan.values) {
64
68
  // IN value list: expr IN (value1, value2, ...)
65
- function runValues(ctx, condition, ...values) {
66
- // If condition is NULL, result is NULL
67
- if (condition === null) {
68
- return null;
69
- }
70
- // Build BTree of all values
71
- const tree = new BTree((val) => val, (a, b) => compareSqlValuesFast(a, b, BINARY_COLLATION));
69
+ // Check if all values are truly constant (can be evaluated at emit time)
70
+ const allConstant = plan.values.every(val => val.physical.constant);
71
+ if (allConstant) {
72
+ // Pre-build BTree at emit time for constant values
73
+ const tree = new BTree((val) => val, (a, b) => compareSqlValuesFast(a, b, collation));
72
74
  let hasNull = false;
73
- for (const value of values) {
74
- if (value === null) {
75
- hasNull = true;
76
- continue;
75
+ function innerConstantRun(_rctx, condition) {
76
+ // If condition is NULL, result is NULL
77
+ if (condition === null) {
78
+ return null;
77
79
  }
78
- tree.insert(value);
80
+ // Check if condition exists in pre-built tree
81
+ const path = tree.find(condition);
82
+ if (path.on) {
83
+ return 1; // Found a match
84
+ }
85
+ // No match found - if any value was NULL, result is NULL
86
+ return hasNull ? null : 0;
79
87
  }
80
- // Check if condition exists in tree
81
- const path = tree.find(condition);
82
- if (path.on) {
83
- return 1; // Found a match
88
+ const values = plan.values.map(val => val.getValue());
89
+ let runFunc;
90
+ if (values.some(val => val instanceof Promise)) {
91
+ // Must resolve promises at runtime
92
+ runFunc = async (rctx, condition) => {
93
+ const resolved = await Promise.all(values);
94
+ for (const value of resolved) {
95
+ if (value === null) {
96
+ hasNull = true;
97
+ continue;
98
+ }
99
+ tree.insert(value);
100
+ }
101
+ return innerConstantRun(rctx, condition);
102
+ };
84
103
  }
85
- // No match found - if any value was NULL, result is NULL
86
- return hasNull ? null : 0;
104
+ else {
105
+ for (const value of values) {
106
+ if (value === null) {
107
+ hasNull = true;
108
+ continue;
109
+ }
110
+ tree.insert(value);
111
+ }
112
+ runFunc = innerConstantRun;
113
+ }
114
+ const conditionExpr = emitPlanNode(plan.condition, ctx);
115
+ return {
116
+ params: [conditionExpr],
117
+ run: runFunc,
118
+ note: `IN (${plan.values.length} constant values)`
119
+ };
120
+ }
121
+ else {
122
+ // Some values are expressions - build tree at runtime
123
+ function runDynamicValues(_rctx, condition, ...values) {
124
+ // If condition is NULL, result is NULL
125
+ if (condition === null) {
126
+ return null;
127
+ }
128
+ // Linear scan is optimal since we're only doing one lookup per execution
129
+ let hasNull = false;
130
+ for (const value of values) {
131
+ if (value === null) {
132
+ hasNull = true;
133
+ continue;
134
+ }
135
+ if (compareSqlValuesFast(condition, value, collation) === 0) {
136
+ return 1; // Found a match
137
+ }
138
+ }
139
+ // No match found - if any value was NULL, result is NULL
140
+ return hasNull ? null : 0;
141
+ }
142
+ const conditionExpr = emitPlanNode(plan.condition, ctx);
143
+ const valueExprs = plan.values.map(val => emitPlanNode(val, ctx));
144
+ return {
145
+ params: [conditionExpr, ...valueExprs],
146
+ run: runDynamicValues,
147
+ note: `IN (${plan.values.length} dynamic values)`
148
+ };
87
149
  }
88
- const conditionExpr = emitPlanNode(plan.condition, ctx);
89
- const valueExprs = plan.values.map(val => emitPlanNode(val, ctx));
90
- return {
91
- params: [conditionExpr, ...valueExprs],
92
- run: runValues,
93
- note: `IN (${plan.values.length} values)`
94
- };
95
150
  }
96
151
  else {
97
152
  throw new QuereusError('IN node must have either source or values', StatusCode.INTERNAL);
98
153
  }
99
154
  }
100
155
  export function emitExists(plan, ctx) {
101
- async function run(ctx, input) {
156
+ async function run(_rctx, input) {
102
157
  for await (const _row of input) {
103
158
  return 1; // First row => TRUE
104
159
  }
@@ -1 +1 @@
1
- {"version":3,"file":"subquery.js","sourceRoot":"","sources":["../../../../src/runtime/emit/subquery.ts"],"names":[],"mappings":"A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ED,MAAM,aAAa,GAAG,YAAY,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;YACxD,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;YAElE,OAAO;gBACN,MAAM,EAAE,CAAC,aAAa,EAAE,GAAG,UAAU,CAAC;gBACtC,GAAG,EAAE,gBAAuB;gBAC5B,IAAI,EAAE,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,kBAAkB;aACjD,CAAC;QACH,CAAC;IACF,CAAC;SAAM,CAAC;QACP,MAAM,IAAI,YAAY,CAAC,2CAA2C,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IAC1F,CAAC;AACF,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAAgB,EAAE,GAAoB;IAChE,KAAK,UAAU,GAAG,CAAC,KAAqB,EAAE,KAAyB;QAClE,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YAChC,OAAO,CAAC,CAAC,CAAC,oBAAoB;QAC/B,CAAC;QACD,OAAO,CAAC,CAAC,CAAC,iBAAiB;IAC5B,CAAC;IAED,MAAM,gBAAgB,GAAG,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAE1D,OAAO;QACN,MAAM,EAAE,CAAC,gBAAgB,CAAC;QAC1B,GAAG;QACH,IAAI,EAAE,QAAQ;KACd,CAAC;AACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"table-valued-function.d.ts","sourceRoot":"","sources":["../../../../src/runtime/emit/table-valued-function.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAkC,MAAM,aAAa,CAAC;AAM/E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4CAA4C,CAAC;AAGxF,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,qBAAqB,EAAE,GAAG,EAAE,eAAe,GAAG,WAAW,CA4G1G"}
1
+ {"version":3,"file":"table-valued-function.d.ts","sourceRoot":"","sources":["../../../../src/runtime/emit/table-valued-function.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAkC,MAAM,aAAa,CAAC;AAM/E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4CAA4C,CAAC;AAIxF,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,qBAAqB,EAAE,GAAG,EAAE,eAAe,GAAG,WAAW,CA8F1G"}
@@ -3,6 +3,7 @@ import { QuereusError } from '../../common/errors.js';
3
3
  import { StatusCode } from '../../common/types.js';
4
4
  import { isTableValuedFunctionSchema } from '../../schema/function.js';
5
5
  import { buildRowDescriptor } from '../../util/row-descriptor.js';
6
+ import { withRowContextGenerator } from '../context-helpers.js';
6
7
  export function emitTableValuedFunctionCall(plan, ctx) {
7
8
  const functionName = plan.functionName.toLowerCase();
8
9
  const numArgs = plan.operands.length;
@@ -36,17 +37,9 @@ export function emitTableValuedFunctionCall(plan, ctx) {
36
37
  const result = capturedFunction.implementation(innerCtx.db, ...args);
37
38
  // Handle both direct AsyncIterable and Promise<AsyncIterable>
38
39
  const iterable = result instanceof Promise ? await result : result;
39
- for await (const row of iterable) {
40
- // Set up row context for column references
41
- innerCtx.context.set(rowDescriptor, () => row);
42
- try {
43
- yield row;
44
- }
45
- finally {
46
- // Clean up row context
47
- innerCtx.context.delete(rowDescriptor);
48
- }
49
- }
40
+ yield* withRowContextGenerator(innerCtx, rowDescriptor, iterable, async function* (row) {
41
+ yield row;
42
+ });
50
43
  }
51
44
  catch (error) {
52
45
  throw new QuereusError(`Table-valued function ${functionName} failed: ${error.message}`, StatusCode.ERROR, error);
@@ -75,17 +68,9 @@ export function emitTableValuedFunctionCall(plan, ctx) {
75
68
  const result = capturedFunction.implementation(...args);
76
69
  // Handle both direct AsyncIterable and Promise<AsyncIterable>
77
70
  const iterable = result instanceof Promise ? await result : result;
78
- for await (const row of iterable) {
79
- // Set up row context for column references
80
- innerCtx.context.set(rowDescriptor, () => row);
81
- try {
82
- yield row;
83
- }
84
- finally {
85
- // Clean up row context
86
- innerCtx.context.delete(rowDescriptor);
87
- }
88
- }
71
+ yield* withRowContextGenerator(innerCtx, rowDescriptor, iterable, async function* (row) {
72
+ yield row;
73
+ });
89
74
  }
90
75
  catch (error) {
91
76
  throw new QuereusError(`Table-valued function ${functionName} failed: ${error.message}`, StatusCode.ERROR, error);
@@ -1 +1 @@
1
- {"version":3,"file":"table-valued-function.js","sourceRoot":"","sources":["../../../../src/runtime/emit/table-valued-function.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,UAAU,EAA2B,MAAM,uBAAuB,CAAC;AAE5E,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAGvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,MAAM,UAAU,2BAA2B,CAAC,IAA2B,EAAE,GAAoB;IAC5F,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;IACrD,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAErC,uDAAuD;IACvD,MAAM,aAAa,GAAG,kBAAkB,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC;IAE/D,iEAAiE;IACjE,sEAAsE;IACtE,IAAI,cAAc,GAAG,GAAG,CAAC,YAAY,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAC7D,IAAI,CAAC,cAAc,EAAE,CAAC;QACrB,cAAc,GAAG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,GAAG,CAAC;YACX,CAAC,CAAC,CAAC;QACJ,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACrB,MAAM,IAAI,YAAY,CAAC,yBAAyB,YAAY,YAAY,KAAK,CAAC,OAAO,EAAE,EAAE,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QACnH,CAAC;IACF,CAAC;IAED,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;IAC9E,MAAM,WAAW,GAAG,cAAc,CAAC,YAAY,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC;IAEtE,OAAO,0BAA0B,CAChC,CAAC,GAAG,YAAY,CAAC,EACjB,WAA6B,EAC7B,GAAG,EACH,OAAO,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CACnD,CAAC;AACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/runtime/emit/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,KAAK,EAAE,WAAW,EAAkC,MAAM,aAAa,CAAC;AAI/E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAG9D,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,eAAe,GAAG,WAAW,CAgE9E"}
1
+ {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/runtime/emit/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,KAAK,EAAE,WAAW,EAAkC,MAAM,aAAa,CAAC;AAI/E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAI9D,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,eAAe,GAAG,WAAW,CAwD9E"}
@@ -2,6 +2,7 @@ import { emitPlanNode, emitCallFromPlan } from '../emitters.js';
2
2
  import { QuereusError } from '../../common/errors.js';
3
3
  import { StatusCode } from '../../common/types.js';
4
4
  import { buildRowDescriptor, composeOldNewRow } from '../../util/row-descriptor.js';
5
+ import { withRowContextGenerator } from '../context-helpers.js';
5
6
  export function emitUpdate(plan, ctx) {
6
7
  const tableSchema = plan.table.tableSchema;
7
8
  // Create row descriptor for the source rows (needed for assignment expression evaluation)
@@ -18,35 +19,27 @@ export function emitUpdate(plan, ctx) {
18
19
  // Emit assignment value expressions as callbacks
19
20
  const assignmentEvaluators = plan.assignments.map(assign => emitCallFromPlan(assign.value, ctx));
20
21
  async function* run(rctx, sourceRowsIterable, ...assignmentEvaluators) {
21
- for await (const sourceRow of sourceRowsIterable) {
22
- // Set up row context for evaluating assignment expressions
23
- rctx.context.set(sourceRowDescriptor, () => sourceRow);
24
- try {
25
- // Evaluate assignment expressions in the context of this row
26
- const assignmentValues = [];
27
- for (const evaluator of assignmentEvaluators) {
28
- const value = evaluator(rctx);
29
- assignmentValues.push(value);
30
- }
31
- // Create a new row with updated values
32
- const updatedRow = [...sourceRow]; // Copy the original row
33
- // Apply assignment values to the row
34
- for (let i = 0; i < assignmentValues.length; i++) {
35
- const targetColIdx = assignmentTargetIndices[i];
36
- updatedRow[targetColIdx] = assignmentValues[i];
37
- }
38
- // Create flat row with OLD (source) and NEW (updated) values for constraint checking
39
- const flatRow = composeOldNewRow(sourceRow, updatedRow, tableSchema.columns.length);
40
- // Yield the flat row for constraint checking
41
- // NOTE: UpdateNode only transforms rows - it does NOT execute the actual update
42
- // The UpdateExecutorNode is responsible for calling vtab.xUpdate
43
- yield flatRow;
22
+ yield* withRowContextGenerator(rctx, sourceRowDescriptor, sourceRowsIterable, async function* (sourceRow) {
23
+ // Evaluate assignment expressions in the context of this row
24
+ const assignmentValues = [];
25
+ for (const evaluator of assignmentEvaluators) {
26
+ const value = evaluator(rctx);
27
+ assignmentValues.push(value);
44
28
  }
45
- finally {
46
- // Clean up row context
47
- rctx.context.delete(sourceRowDescriptor);
29
+ // Create a new row with updated values
30
+ const updatedRow = [...sourceRow]; // Copy the original row
31
+ // Apply assignment values to the row
32
+ for (let i = 0; i < assignmentValues.length; i++) {
33
+ const targetColIdx = assignmentTargetIndices[i];
34
+ updatedRow[targetColIdx] = assignmentValues[i];
48
35
  }
49
- }
36
+ // Create flat row with OLD (source) and NEW (updated) values for constraint checking
37
+ const flatRow = composeOldNewRow(sourceRow, updatedRow, tableSchema.columns.length);
38
+ // Yield the flat row for constraint checking
39
+ // NOTE: UpdateNode only transforms rows - it does NOT execute the actual update
40
+ // The UpdateExecutorNode is responsible for calling vtab.xUpdate
41
+ yield flatRow;
42
+ });
50
43
  }
51
44
  const sourceInstruction = emitPlanNode(plan.source, ctx);
52
45
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"update.js","sourceRoot":"","sources":["../../../../src/runtime/emit/update.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,UAAU,EAA2B,MAAM,uBAAuB,CAAC;AAE5E,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEpF,MAAM,UAAU,UAAU,CAAC,IAAgB,EAAE,GAAoB;IAChE,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC;IAE3C,0FAA0F;IAC1F,MAAM,mBAAmB,GAAG,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC,CAAC;IAE5E,0CAA0C;IAC1C,MAAM,uBAAuB,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,C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,EAAE,GAAG,EAAE,eAAe,GAAG,WAAW,CAyF9E"}
1
+ {"version":3,"file":"window.d.ts","sourceRoot":"","sources":["../../../../src/runtime/emit/window.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,aAAa,CAAC;AAE/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAa9D,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,eAAe,GAAG,WAAW,CAyF9E"}
@@ -5,6 +5,7 @@ import { StatusCode } from '../../common/types.js';
5
5
  import { compareSqlValues, createOrderByComparatorFast, resolveCollation } from '../../util/comparison.js';
6
6
  import { createLogger } from '../../common/logger.js';
7
7
  import { buildRowDescriptor } from '../../util/row-descriptor.js';
8
+ import { withRowContext, withAsyncRowContext } from '../context-helpers.js';
8
9
  const log = createLogger('runtime:emit:window');
9
10
  export function emitWindow(plan, ctx) {
10
11
  // Get schemas for all window functions in this node
@@ -63,20 +64,16 @@ export function emitWindow(plan, ctx) {
63
64
  async function groupByPartitions(rows, partitionCallbacks, rctx, sourceRowDescriptor) {
64
65
  const partitions = new Map();
65
66
  for (const row of rows) {
66
- rctx.context.set(sourceRowDescriptor, () => row);
67
- try {
67
+ const partitionKey = await withAsyncRowContext(rctx, sourceRowDescriptor, () => row, async () => {
68
68
  // Evaluate partition expressions
69
- const partitionValues = partitionCallbacks.map(callback => callback(rctx));
69
+ const partitionValues = await Promise.all(partitionCallbacks.map(callback => callback(rctx)));
70
70
  // Create partition key
71
- const partitionKey = partitionValues.map(val => val === null ? 'NULL' : String(val)).join('|');
72
- if (!partitions.has(partitionKey)) {
73
- partitions.set(partitionKey, []);
74
- }
75
- partitions.get(partitionKey).push(row);
76
- }
77
- finally {
78
- rctx.context.delete(sourceRowDescriptor);
71
+ return partitionValues.map(val => val === null ? 'NULL' : String(val)).join('|');
72
+ });
73
+ if (!partitions.has(partitionKey)) {
74
+ partitions.set(partitionKey, []);
79
75
  }
76
+ partitions.get(partitionKey).push(row);
80
77
  }
81
78
  return partitions;
82
79
  }
@@ -88,8 +85,8 @@ async function* processPartition(partitionRows, plan, functionSchemas, rctx, sou
88
85
  const currentRow = sortedRows[currentIndex];
89
86
  const outputRow = [...currentRow];
90
87
  // Set up context for current row
91
- rctx.context.set(sourceRowDescriptor, () => currentRow);
92
- try {
88
+ const outputValues = await withRowContext(rctx, sourceRowDescriptor, () => currentRow, async () => {
89
+ const values = [];
93
90
  // Compute each window function
94
91
  for (let funcIndex = 0; funcIndex < plan.functions.length; funcIndex++) {
95
92
  const func = plan.functions[funcIndex];
@@ -97,7 +94,7 @@ async function* processPartition(partitionRows, plan, functionSchemas, rctx, sou
97
94
  const argCallback = funcArgCallbacks[funcIndex];
98
95
  let value;
99
96
  if (schema.kind === 'ranking') {
100
- value = computeRankingFunction(func.functionName, sortedRows, currentIndex, orderByCallbacks, rctx, sourceRowDescriptor);
97
+ value = await computeRankingFunction(func.functionName, sortedRows, currentIndex, orderByCallbacks, rctx, sourceRowDescriptor);
101
98
  }
102
99
  else if (schema.kind === 'aggregate') {
103
100
  value = await computeAggregateFunction(schema, argCallback, sortedRows, currentIndex, plan.windowSpec.frame, plan.windowSpec.orderBy.length > 0, rctx, sourceRowDescriptor);
@@ -105,20 +102,14 @@ async function* processPartition(partitionRows, plan, functionSchemas, rctx, sou
105
102
  else {
106
103
  throw new QuereusError(`Window function type ${schema.kind} not yet implemented`, StatusCode.UNSUPPORTED);
107
104
  }
108
- outputRow.push(value);
105
+ values.push(value);
109
106
  }
110
- }
111
- finally {
112
- rctx.context.delete(sourceRowDescriptor);
113
- }
107
+ return values;
108
+ });
109
+ // Add computed values to output row
110
+ outputRow.push(...outputValues);
114
111
  // Yield the output row
115
- rctx.context.set(outputRowDescriptor, () => outputRow);
116
- try {
117
- yield outputRow;
118
- }
119
- finally {
120
- rctx.context.delete(outputRowDescriptor);
121
- }
112
+ yield await withRowContext(rctx, outputRowDescriptor, () => outputRow, () => outputRow);
122
113
  }
123
114
  }
124
115
  async function sortRows(rows, orderBy, orderByCallbacks, rctx, sourceRowDescriptor) {
@@ -130,31 +121,25 @@ async function sortRows(rows, orderBy, orderByCallbacks, rctx, sourceRowDescript
130
121
  // TODO: Extract actual collation from order clause expression
131
122
  // For now, use BINARY collation (most common case)
132
123
  const collationFunc = resolveCollation('BINARY');
133
- return createOrderByComparatorFast(orderClause.direction, orderClause.nullsOrdering, collationFunc);
124
+ return createOrderByComparatorFast(orderClause.direction, orderClause.nulls, collationFunc);
134
125
  });
135
- return [...rows].sort((a, b) => {
126
+ // Pre-evaluate ORDER BY values for all rows to avoid async in sort
127
+ const rowsWithValues = await Promise.all(rows.map(async (row) => {
128
+ const values = await Promise.all(orderByCallbacks.map(async (callback) => {
129
+ return await withAsyncRowContext(rctx, sourceRowDescriptor, () => row, async () => {
130
+ const result = callback(rctx);
131
+ return await Promise.resolve(result);
132
+ });
133
+ }));
134
+ return { row, values };
135
+ }));
136
+ // Now sort using the pre-evaluated values
137
+ rowsWithValues.sort((a, b) => {
136
138
  // Compare each ORDER BY expression in sequence
137
139
  for (let i = 0; i < orderBy.length; i++) {
138
- const callback = orderByCallbacks[i];
139
140
  const comparator = orderByComparators[i];
140
- // Evaluate expression for row A
141
- rctx.context.set(sourceRowDescriptor, () => a);
142
- let valueA;
143
- try {
144
- valueA = callback(rctx);
145
- }
146
- finally {
147
- rctx.context.delete(sourceRowDescriptor);
148
- }
149
- // Evaluate expression for row B
150
- rctx.context.set(sourceRowDescriptor, () => b);
151
- let valueB;
152
- try {
153
- valueB = callback(rctx);
154
- }
155
- finally {
156
- rctx.context.delete(sourceRowDescriptor);
157
- }
141
+ const valueA = a.values[i];
142
+ const valueB = b.values[i];
158
143
  // Use pre-created optimized comparator
159
144
  const comparison = comparator(valueA, valueB);
160
145
  // If not equal, return comparison result
@@ -165,8 +150,10 @@ async function sortRows(rows, orderBy, orderByCallbacks, rctx, sourceRowDescript
165
150
  }
166
151
  return 0; // All ORDER BY expressions are equal
167
152
  });
153
+ // Extract just the rows in sorted order
154
+ return rowsWithValues.map(item => item.row);
168
155
  }
169
- function computeRankingFunction(functionName, sortedRows, currentIndex, orderByCallbacks, rctx, sourceRowDescriptor) {
156
+ async function computeRankingFunction(functionName, sortedRows, currentIndex, orderByCallbacks, rctx, sourceRowDescriptor) {
170
157
  switch (functionName.toLowerCase()) {
171
158
  case 'row_number':
172
159
  return currentIndex + 1;
@@ -176,7 +163,7 @@ function computeRankingFunction(functionName, sortedRows, currentIndex, orderByC
176
163
  const currentRow = sortedRows[currentIndex];
177
164
  for (let i = 0; i < currentIndex; i++) {
178
165
  const prevRow = sortedRows[i];
179
- if (!areRowsEqualInOrderBy(prevRow, currentRow, orderByCallbacks, rctx, sourceRowDescriptor)) {
166
+ if (!(await areRowsEqualInOrderBy(prevRow, currentRow, orderByCallbacks, rctx, sourceRowDescriptor))) {
180
167
  rank = i + 2; // Rank is 1-based and accounts for ties
181
168
  }
182
169
  }
@@ -189,9 +176,9 @@ function computeRankingFunction(functionName, sortedRows, currentIndex, orderByC
189
176
  const seenValues = new Set();
190
177
  for (let i = 0; i < currentIndex; i++) {
191
178
  const prevRow = sortedRows[i];
192
- if (!areRowsEqualInOrderBy(prevRow, currentRow, orderByCallbacks, rctx, sourceRowDescriptor)) {
179
+ if (!(await areRowsEqualInOrderBy(prevRow, currentRow, orderByCallbacks, rctx, sourceRowDescriptor))) {
193
180
  // Create a key for this distinct set of ORDER BY values
194
- const key = getOrderByKey(prevRow, orderByCallbacks, rctx, sourceRowDescriptor);
181
+ const key = await getOrderByKey(prevRow, orderByCallbacks, rctx, sourceRowDescriptor);
195
182
  if (!seenValues.has(key)) {
196
183
  seenValues.add(key);
197
184
  denseRank++;
@@ -212,22 +199,19 @@ async function computeAggregateFunction(schema, argCallback, sortedRows, current
212
199
  // Process rows within the frame
213
200
  for (let i = frameBounds.start; i <= frameBounds.end; i++) {
214
201
  const frameRow = sortedRows[i];
215
- rctx.context.set(sourceRowDescriptor, () => frameRow);
216
- try {
202
+ await withAsyncRowContext(rctx, sourceRowDescriptor, () => frameRow, async () => {
217
203
  let argValue = null;
218
204
  // Get argument value if callback exists
219
205
  if (argCallback) {
220
- argValue = argCallback(rctx);
206
+ const result = argCallback(rctx);
207
+ argValue = await Promise.resolve(result);
221
208
  }
222
209
  // Apply aggregate step function
223
210
  if (schema.step) {
224
211
  accumulator = schema.step(accumulator, argValue);
225
212
  rowCount++;
226
213
  }
227
- }
228
- finally {
229
- rctx.context.delete(sourceRowDescriptor);
230
- }
214
+ });
231
215
  }
232
216
  // Apply final function
233
217
  return schema.final ? schema.final(accumulator, rowCount) : accumulator;
@@ -288,26 +272,18 @@ function getFrameBounds(frame, totalRows, currentIndex, hasOrderBy = true) {
288
272
  }
289
273
  return { start, end };
290
274
  }
291
- function areRowsEqualInOrderBy(rowA, rowB, orderByCallbacks, rctx, sourceRowDescriptor) {
275
+ async function areRowsEqualInOrderBy(rowA, rowB, orderByCallbacks, rctx, sourceRowDescriptor) {
292
276
  for (const callback of orderByCallbacks) {
293
277
  // Get value for row A
294
- rctx.context.set(sourceRowDescriptor, () => rowA);
295
- let valueA;
296
- try {
297
- valueA = callback(rctx);
298
- }
299
- finally {
300
- rctx.context.delete(sourceRowDescriptor);
301
- }
278
+ const valueA = await withAsyncRowContext(rctx, sourceRowDescriptor, () => rowA, async () => {
279
+ const result = callback(rctx);
280
+ return await Promise.resolve(result);
281
+ });
302
282
  // Get value for row B
303
- rctx.context.set(sourceRowDescriptor, () => rowB);
304
- let valueB;
305
- try {
306
- valueB = callback(rctx);
307
- }
308
- finally {
309
- rctx.context.delete(sourceRowDescriptor);
310
- }
283
+ const valueB = await withAsyncRowContext(rctx, sourceRowDescriptor, () => rowB, async () => {
284
+ const result = callback(rctx);
285
+ return await Promise.resolve(result);
286
+ });
311
287
  // If any ORDER BY expression differs, rows are not equal
312
288
  if (compareSqlValues(valueA, valueB) !== 0) {
313
289
  return false;
@@ -315,14 +291,10 @@ function areRowsEqualInOrderBy(rowA, rowB, orderByCallbacks, rctx, sourceRowDesc
315
291
  }
316
292
  return true; // All ORDER BY expressions are equal
317
293
  }
318
- function getOrderByKey(row, orderByCallbacks, rctx, sourceRowDescriptor) {
319
- rctx.context.set(sourceRowDescriptor, () => row);
320
- try {
321
- const values = orderByCallbacks.map(callback => callback(rctx));
294
+ async function getOrderByKey(row, orderByCallbacks, rctx, sourceRowDescriptor) {
295
+ return await withAsyncRowContext(rctx, sourceRowDescriptor, () => row, async () => {
296
+ const values = await Promise.all(orderByCallbacks.map(callback => Promise.resolve(callback(rctx))));
322
297
  return values.map(val => val === null ? 'NULL' : String(val)).join('|');
323
- }
324
- finally {
325
- rctx.context.delete(sourceRowDescriptor);
326
- }
298
+ });
327
299
  }
328
300
  //# sourceMappingURL=window.js.map