@quereus/quereus 4.4.0 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (491) hide show
  1. package/README.md +6 -1
  2. package/dist/src/common/types.d.ts +9 -0
  3. package/dist/src/common/types.d.ts.map +1 -1
  4. package/dist/src/common/types.js.map +1 -1
  5. package/dist/src/core/database-events.d.ts +49 -0
  6. package/dist/src/core/database-events.d.ts.map +1 -1
  7. package/dist/src/core/database-events.js +148 -0
  8. package/dist/src/core/database-events.js.map +1 -1
  9. package/dist/src/core/database-materialized-views-analysis.d.ts.map +1 -1
  10. package/dist/src/core/database-materialized-views-analysis.js +1 -0
  11. package/dist/src/core/database-materialized-views-analysis.js.map +1 -1
  12. package/dist/src/core/database-materialized-views-plan-builders.d.ts +2 -1
  13. package/dist/src/core/database-materialized-views-plan-builders.d.ts.map +1 -1
  14. package/dist/src/core/database-materialized-views-plan-builders.js +26 -5
  15. package/dist/src/core/database-materialized-views-plan-builders.js.map +1 -1
  16. package/dist/src/core/database-materialized-views-plans.d.ts +6 -3
  17. package/dist/src/core/database-materialized-views-plans.d.ts.map +1 -1
  18. package/dist/src/core/database-materialized-views.d.ts +3 -2
  19. package/dist/src/core/database-materialized-views.d.ts.map +1 -1
  20. package/dist/src/core/database-materialized-views.js +26 -5
  21. package/dist/src/core/database-materialized-views.js.map +1 -1
  22. package/dist/src/core/database.d.ts +5 -0
  23. package/dist/src/core/database.d.ts.map +1 -1
  24. package/dist/src/core/database.js +21 -1
  25. package/dist/src/core/database.js.map +1 -1
  26. package/dist/src/core/internal-statement-cache.d.ts +18 -0
  27. package/dist/src/core/internal-statement-cache.d.ts.map +1 -0
  28. package/dist/src/core/internal-statement-cache.js +211 -0
  29. package/dist/src/core/internal-statement-cache.js.map +1 -0
  30. package/dist/src/func/builtins/aggregate.d.ts +13 -12
  31. package/dist/src/func/builtins/aggregate.d.ts.map +1 -1
  32. package/dist/src/func/builtins/aggregate.js +45 -67
  33. package/dist/src/func/builtins/aggregate.js.map +1 -1
  34. package/dist/src/func/builtins/builtin-window-functions.d.ts.map +1 -1
  35. package/dist/src/func/builtins/builtin-window-functions.js +63 -48
  36. package/dist/src/func/builtins/builtin-window-functions.js.map +1 -1
  37. package/dist/src/func/builtins/scalar.d.ts.map +1 -1
  38. package/dist/src/func/builtins/scalar.js +92 -3
  39. package/dist/src/func/builtins/scalar.js.map +1 -1
  40. package/dist/src/func/registration.d.ts +18 -1
  41. package/dist/src/func/registration.d.ts.map +1 -1
  42. package/dist/src/func/registration.js +26 -0
  43. package/dist/src/func/registration.js.map +1 -1
  44. package/dist/src/index.d.ts +10 -10
  45. package/dist/src/index.d.ts.map +1 -1
  46. package/dist/src/index.js +13 -12
  47. package/dist/src/index.js.map +1 -1
  48. package/dist/src/parser/parser.d.ts +6 -0
  49. package/dist/src/parser/parser.d.ts.map +1 -1
  50. package/dist/src/parser/parser.js +45 -34
  51. package/dist/src/parser/parser.js.map +1 -1
  52. package/dist/src/planner/analysis/coarsened-key.d.ts +4 -3
  53. package/dist/src/planner/analysis/coarsened-key.d.ts.map +1 -1
  54. package/dist/src/planner/analysis/coarsened-key.js +37 -3
  55. package/dist/src/planner/analysis/coarsened-key.js.map +1 -1
  56. package/dist/src/planner/analysis/comparison-collation.d.ts +35 -3
  57. package/dist/src/planner/analysis/comparison-collation.d.ts.map +1 -1
  58. package/dist/src/planner/analysis/comparison-collation.js +37 -3
  59. package/dist/src/planner/analysis/comparison-collation.js.map +1 -1
  60. package/dist/src/planner/analysis/coverage-prover.d.ts +13 -2
  61. package/dist/src/planner/analysis/coverage-prover.d.ts.map +1 -1
  62. package/dist/src/planner/analysis/coverage-prover.js +10 -14
  63. package/dist/src/planner/analysis/coverage-prover.js.map +1 -1
  64. package/dist/src/planner/analysis/expression-fingerprint.d.ts.map +1 -1
  65. package/dist/src/planner/analysis/expression-fingerprint.js +29 -0
  66. package/dist/src/planner/analysis/expression-fingerprint.js.map +1 -1
  67. package/dist/src/planner/analysis/predicate-conjuncts.d.ts +10 -4
  68. package/dist/src/planner/analysis/predicate-conjuncts.d.ts.map +1 -1
  69. package/dist/src/planner/analysis/predicate-conjuncts.js +28 -7
  70. package/dist/src/planner/analysis/predicate-conjuncts.js.map +1 -1
  71. package/dist/src/planner/analysis/query-rewrite-matcher.d.ts +6 -0
  72. package/dist/src/planner/analysis/query-rewrite-matcher.d.ts.map +1 -1
  73. package/dist/src/planner/analysis/query-rewrite-matcher.js +19 -29
  74. package/dist/src/planner/analysis/query-rewrite-matcher.js.map +1 -1
  75. package/dist/src/planner/analysis/sat-checker.d.ts.map +1 -1
  76. package/dist/src/planner/analysis/sat-checker.js +43 -4
  77. package/dist/src/planner/analysis/sat-checker.js.map +1 -1
  78. package/dist/src/planner/analysis/scalar-subqueries.d.ts +22 -3
  79. package/dist/src/planner/analysis/scalar-subqueries.d.ts.map +1 -1
  80. package/dist/src/planner/analysis/scalar-subqueries.js +32 -3
  81. package/dist/src/planner/analysis/scalar-subqueries.js.map +1 -1
  82. package/dist/src/planner/analysis/set-op-type-merge.d.ts +64 -0
  83. package/dist/src/planner/analysis/set-op-type-merge.d.ts.map +1 -0
  84. package/dist/src/planner/analysis/set-op-type-merge.js +97 -0
  85. package/dist/src/planner/analysis/set-op-type-merge.js.map +1 -0
  86. package/dist/src/planner/building/coercion.d.ts +78 -0
  87. package/dist/src/planner/building/coercion.d.ts.map +1 -0
  88. package/dist/src/planner/building/coercion.js +137 -0
  89. package/dist/src/planner/building/coercion.js.map +1 -0
  90. package/dist/src/planner/building/constraint-builder.d.ts.map +1 -1
  91. package/dist/src/planner/building/constraint-builder.js +5 -18
  92. package/dist/src/planner/building/constraint-builder.js.map +1 -1
  93. package/dist/src/planner/building/delete.d.ts.map +1 -1
  94. package/dist/src/planner/building/delete.js +10 -3
  95. package/dist/src/planner/building/delete.js.map +1 -1
  96. package/dist/src/planner/building/expression.d.ts.map +1 -1
  97. package/dist/src/planner/building/expression.js +13 -35
  98. package/dist/src/planner/building/expression.js.map +1 -1
  99. package/dist/src/planner/building/foreign-key-builder.d.ts +44 -1
  100. package/dist/src/planner/building/foreign-key-builder.d.ts.map +1 -1
  101. package/dist/src/planner/building/foreign-key-builder.js +54 -0
  102. package/dist/src/planner/building/foreign-key-builder.js.map +1 -1
  103. package/dist/src/planner/building/function-call.d.ts.map +1 -1
  104. package/dist/src/planner/building/function-call.js +8 -0
  105. package/dist/src/planner/building/function-call.js.map +1 -1
  106. package/dist/src/planner/building/insert.d.ts.map +1 -1
  107. package/dist/src/planner/building/insert.js +9 -12
  108. package/dist/src/planner/building/insert.js.map +1 -1
  109. package/dist/src/planner/building/select-compound.d.ts.map +1 -1
  110. package/dist/src/planner/building/select-compound.js +10 -6
  111. package/dist/src/planner/building/select-compound.js.map +1 -1
  112. package/dist/src/planner/building/update.d.ts.map +1 -1
  113. package/dist/src/planner/building/update.js +13 -4
  114. package/dist/src/planner/building/update.js.map +1 -1
  115. package/dist/src/planner/cost/conjunct-cost.d.ts +42 -0
  116. package/dist/src/planner/cost/conjunct-cost.d.ts.map +1 -0
  117. package/dist/src/planner/cost/conjunct-cost.js +62 -0
  118. package/dist/src/planner/cost/conjunct-cost.js.map +1 -0
  119. package/dist/src/planner/framework/pass.js +3 -3
  120. package/dist/src/planner/mutation/propagate.d.ts.map +1 -1
  121. package/dist/src/planner/mutation/propagate.js +1 -0
  122. package/dist/src/planner/mutation/propagate.js.map +1 -1
  123. package/dist/src/planner/nodes/async-gather-node.d.ts.map +1 -1
  124. package/dist/src/planner/nodes/async-gather-node.js +19 -8
  125. package/dist/src/planner/nodes/async-gather-node.js.map +1 -1
  126. package/dist/src/planner/nodes/bloom-join-node.d.ts +2 -0
  127. package/dist/src/planner/nodes/bloom-join-node.d.ts.map +1 -1
  128. package/dist/src/planner/nodes/bloom-join-node.js +10 -5
  129. package/dist/src/planner/nodes/bloom-join-node.js.map +1 -1
  130. package/dist/src/planner/nodes/dml-executor-node.d.ts +0 -9
  131. package/dist/src/planner/nodes/dml-executor-node.d.ts.map +1 -1
  132. package/dist/src/planner/nodes/dml-executor-node.js.map +1 -1
  133. package/dist/src/planner/nodes/join-node.d.ts +5 -0
  134. package/dist/src/planner/nodes/join-node.d.ts.map +1 -1
  135. package/dist/src/planner/nodes/join-node.js +8 -1
  136. package/dist/src/planner/nodes/join-node.js.map +1 -1
  137. package/dist/src/planner/nodes/join-utils.d.ts +57 -0
  138. package/dist/src/planner/nodes/join-utils.d.ts.map +1 -1
  139. package/dist/src/planner/nodes/join-utils.js +47 -0
  140. package/dist/src/planner/nodes/join-utils.js.map +1 -1
  141. package/dist/src/planner/nodes/key-set-semi-join-node.d.ts +87 -0
  142. package/dist/src/planner/nodes/key-set-semi-join-node.d.ts.map +1 -0
  143. package/dist/src/planner/nodes/key-set-semi-join-node.js +137 -0
  144. package/dist/src/planner/nodes/key-set-semi-join-node.js.map +1 -0
  145. package/dist/src/planner/nodes/merge-join-node.d.ts +2 -0
  146. package/dist/src/planner/nodes/merge-join-node.d.ts.map +1 -1
  147. package/dist/src/planner/nodes/merge-join-node.js +14 -6
  148. package/dist/src/planner/nodes/merge-join-node.js.map +1 -1
  149. package/dist/src/planner/nodes/plan-node-type.d.ts +1 -0
  150. package/dist/src/planner/nodes/plan-node-type.d.ts.map +1 -1
  151. package/dist/src/planner/nodes/plan-node-type.js +1 -0
  152. package/dist/src/planner/nodes/plan-node-type.js.map +1 -1
  153. package/dist/src/planner/nodes/scalar.d.ts.map +1 -1
  154. package/dist/src/planner/nodes/scalar.js +26 -3
  155. package/dist/src/planner/nodes/scalar.js.map +1 -1
  156. package/dist/src/planner/nodes/set-operation-node.d.ts +68 -16
  157. package/dist/src/planner/nodes/set-operation-node.d.ts.map +1 -1
  158. package/dist/src/planner/nodes/set-operation-node.js +147 -26
  159. package/dist/src/planner/nodes/set-operation-node.js.map +1 -1
  160. package/dist/src/planner/nodes/table-access-nodes.d.ts +19 -1
  161. package/dist/src/planner/nodes/table-access-nodes.d.ts.map +1 -1
  162. package/dist/src/planner/nodes/table-access-nodes.js +13 -2
  163. package/dist/src/planner/nodes/table-access-nodes.js.map +1 -1
  164. package/dist/src/planner/optimizer.d.ts.map +1 -1
  165. package/dist/src/planner/optimizer.js +54 -12
  166. package/dist/src/planner/optimizer.js.map +1 -1
  167. package/dist/src/planner/rules/access/rule-key-set-seek.d.ts +68 -0
  168. package/dist/src/planner/rules/access/rule-key-set-seek.d.ts.map +1 -0
  169. package/dist/src/planner/rules/access/rule-key-set-seek.js +408 -0
  170. package/dist/src/planner/rules/access/rule-key-set-seek.js.map +1 -0
  171. package/dist/src/planner/rules/access/rule-monotonic-range-access.d.ts.map +1 -1
  172. package/dist/src/planner/rules/access/rule-monotonic-range-access.js +2 -2
  173. package/dist/src/planner/rules/access/rule-monotonic-range-access.js.map +1 -1
  174. package/dist/src/planner/rules/access/rule-select-access-path.d.ts +27 -0
  175. package/dist/src/planner/rules/access/rule-select-access-path.d.ts.map +1 -1
  176. package/dist/src/planner/rules/access/rule-select-access-path.js +74 -29
  177. package/dist/src/planner/rules/access/rule-select-access-path.js.map +1 -1
  178. package/dist/src/planner/rules/cache/rule-materialized-view-rewrite.d.ts.map +1 -1
  179. package/dist/src/planner/rules/cache/rule-materialized-view-rewrite.js +23 -4
  180. package/dist/src/planner/rules/cache/rule-materialized-view-rewrite.js.map +1 -1
  181. package/dist/src/planner/rules/cache/rule-scalar-subquery-cache.d.ts +10 -8
  182. package/dist/src/planner/rules/cache/rule-scalar-subquery-cache.d.ts.map +1 -1
  183. package/dist/src/planner/rules/cache/rule-scalar-subquery-cache.js +10 -8
  184. package/dist/src/planner/rules/cache/rule-scalar-subquery-cache.js.map +1 -1
  185. package/dist/src/planner/rules/join/equi-pair-extractor.d.ts +67 -41
  186. package/dist/src/planner/rules/join/equi-pair-extractor.d.ts.map +1 -1
  187. package/dist/src/planner/rules/join/equi-pair-extractor.js +72 -36
  188. package/dist/src/planner/rules/join/equi-pair-extractor.js.map +1 -1
  189. package/dist/src/planner/rules/join/rule-join-physical-selection.d.ts.map +1 -1
  190. package/dist/src/planner/rules/join/rule-join-physical-selection.js +14 -2
  191. package/dist/src/planner/rules/join/rule-join-physical-selection.js.map +1 -1
  192. package/dist/src/planner/rules/join/rule-monotonic-merge-join.d.ts.map +1 -1
  193. package/dist/src/planner/rules/join/rule-monotonic-merge-join.js +11 -1
  194. package/dist/src/planner/rules/join/rule-monotonic-merge-join.js.map +1 -1
  195. package/dist/src/planner/rules/predicate/rule-empty-relation-folding.d.ts +1 -1
  196. package/dist/src/planner/rules/predicate/rule-empty-relation-folding.js +1 -1
  197. package/dist/src/planner/rules/predicate/rule-filter-conjunct-ordering.d.ts +30 -0
  198. package/dist/src/planner/rules/predicate/rule-filter-conjunct-ordering.d.ts.map +1 -0
  199. package/dist/src/planner/rules/predicate/rule-filter-conjunct-ordering.js +63 -0
  200. package/dist/src/planner/rules/predicate/rule-filter-conjunct-ordering.js.map +1 -0
  201. package/dist/src/planner/rules/predicate/rule-filter-selectivity.d.ts +17 -1
  202. package/dist/src/planner/rules/predicate/rule-filter-selectivity.d.ts.map +1 -1
  203. package/dist/src/planner/rules/predicate/rule-filter-selectivity.js +206 -12
  204. package/dist/src/planner/rules/predicate/rule-filter-selectivity.js.map +1 -1
  205. package/dist/src/planner/rules/predicate/rule-predicate-inference-equivalence.js +8 -1
  206. package/dist/src/planner/rules/predicate/rule-predicate-inference-equivalence.js.map +1 -1
  207. package/dist/src/planner/rules/predicate/rule-predicate-pushdown.d.ts +3 -1
  208. package/dist/src/planner/rules/predicate/rule-predicate-pushdown.d.ts.map +1 -1
  209. package/dist/src/planner/rules/predicate/rule-predicate-pushdown.js +13 -1
  210. package/dist/src/planner/rules/predicate/rule-predicate-pushdown.js.map +1 -1
  211. package/dist/src/planner/rules/retrieve/rule-grow-retrieve.d.ts.map +1 -1
  212. package/dist/src/planner/rules/retrieve/rule-grow-retrieve.js +18 -3
  213. package/dist/src/planner/rules/retrieve/rule-grow-retrieve.js.map +1 -1
  214. package/dist/src/planner/rules/shared/index-style-context.d.ts +17 -0
  215. package/dist/src/planner/rules/shared/index-style-context.d.ts.map +1 -1
  216. package/dist/src/planner/rules/shared/index-style-context.js +7 -0
  217. package/dist/src/planner/rules/shared/index-style-context.js.map +1 -1
  218. package/dist/src/planner/rules/subquery/rule-scalar-agg-decorrelation.js +4 -0
  219. package/dist/src/planner/rules/subquery/rule-scalar-agg-decorrelation.js.map +1 -1
  220. package/dist/src/planner/rules/subquery/rule-subquery-decorrelation.d.ts +24 -6
  221. package/dist/src/planner/rules/subquery/rule-subquery-decorrelation.d.ts.map +1 -1
  222. package/dist/src/planner/rules/subquery/rule-subquery-decorrelation.js +175 -60
  223. package/dist/src/planner/rules/subquery/rule-subquery-decorrelation.js.map +1 -1
  224. package/dist/src/planner/stats/catalog-stats.d.ts +52 -0
  225. package/dist/src/planner/stats/catalog-stats.d.ts.map +1 -1
  226. package/dist/src/planner/stats/catalog-stats.js +151 -5
  227. package/dist/src/planner/stats/catalog-stats.js.map +1 -1
  228. package/dist/src/planner/stats/index.d.ts +15 -0
  229. package/dist/src/planner/stats/index.d.ts.map +1 -1
  230. package/dist/src/planner/stats/index.js.map +1 -1
  231. package/dist/src/planner/stats/selectivity-combine.d.ts +53 -0
  232. package/dist/src/planner/stats/selectivity-combine.d.ts.map +1 -0
  233. package/dist/src/planner/stats/selectivity-combine.js +75 -0
  234. package/dist/src/planner/stats/selectivity-combine.js.map +1 -0
  235. package/dist/src/planner/util/column-origins.d.ts +58 -0
  236. package/dist/src/planner/util/column-origins.d.ts.map +1 -0
  237. package/dist/src/planner/util/column-origins.js +90 -0
  238. package/dist/src/planner/util/column-origins.js.map +1 -0
  239. package/dist/src/runtime/deferred-constraint-queue.d.ts +40 -0
  240. package/dist/src/runtime/deferred-constraint-queue.d.ts.map +1 -1
  241. package/dist/src/runtime/deferred-constraint-queue.js +91 -0
  242. package/dist/src/runtime/deferred-constraint-queue.js.map +1 -1
  243. package/dist/src/runtime/emit/aggregate-setup.d.ts +49 -0
  244. package/dist/src/runtime/emit/aggregate-setup.d.ts.map +1 -0
  245. package/dist/src/runtime/emit/aggregate-setup.js +99 -0
  246. package/dist/src/runtime/emit/aggregate-setup.js.map +1 -0
  247. package/dist/src/runtime/emit/aggregate.d.ts.map +1 -1
  248. package/dist/src/runtime/emit/aggregate.js +4 -69
  249. package/dist/src/runtime/emit/aggregate.js.map +1 -1
  250. package/dist/src/runtime/emit/alter-table.d.ts.map +1 -1
  251. package/dist/src/runtime/emit/alter-table.js +354 -165
  252. package/dist/src/runtime/emit/alter-table.js.map +1 -1
  253. package/dist/src/runtime/emit/asof-scan.d.ts.map +1 -1
  254. package/dist/src/runtime/emit/asof-scan.js +11 -0
  255. package/dist/src/runtime/emit/asof-scan.js.map +1 -1
  256. package/dist/src/runtime/emit/between.d.ts.map +1 -1
  257. package/dist/src/runtime/emit/between.js +7 -12
  258. package/dist/src/runtime/emit/between.js.map +1 -1
  259. package/dist/src/runtime/emit/binary.d.ts.map +1 -1
  260. package/dist/src/runtime/emit/binary.js +24 -25
  261. package/dist/src/runtime/emit/binary.js.map +1 -1
  262. package/dist/src/runtime/emit/bloom-join.d.ts.map +1 -1
  263. package/dist/src/runtime/emit/bloom-join.js +8 -16
  264. package/dist/src/runtime/emit/bloom-join.js.map +1 -1
  265. package/dist/src/runtime/emit/case.d.ts.map +1 -1
  266. package/dist/src/runtime/emit/case.js +40 -6
  267. package/dist/src/runtime/emit/case.js.map +1 -1
  268. package/dist/src/runtime/emit/cast.d.ts.map +1 -1
  269. package/dist/src/runtime/emit/cast.js +10 -23
  270. package/dist/src/runtime/emit/cast.js.map +1 -1
  271. package/dist/src/runtime/emit/constraint-check.d.ts.map +1 -1
  272. package/dist/src/runtime/emit/constraint-check.js +72 -51
  273. package/dist/src/runtime/emit/constraint-check.js.map +1 -1
  274. package/dist/src/runtime/emit/create-view.d.ts.map +1 -1
  275. package/dist/src/runtime/emit/create-view.js +6 -0
  276. package/dist/src/runtime/emit/create-view.js.map +1 -1
  277. package/dist/src/runtime/emit/distinct.d.ts.map +1 -1
  278. package/dist/src/runtime/emit/distinct.js +6 -3
  279. package/dist/src/runtime/emit/distinct.js.map +1 -1
  280. package/dist/src/runtime/emit/dml-executor.d.ts.map +1 -1
  281. package/dist/src/runtime/emit/dml-executor.js +188 -84
  282. package/dist/src/runtime/emit/dml-executor.js.map +1 -1
  283. package/dist/src/runtime/emit/filter.d.ts +18 -0
  284. package/dist/src/runtime/emit/filter.d.ts.map +1 -1
  285. package/dist/src/runtime/emit/filter.js +52 -10
  286. package/dist/src/runtime/emit/filter.js.map +1 -1
  287. package/dist/src/runtime/emit/hash-aggregate.d.ts.map +1 -1
  288. package/dist/src/runtime/emit/hash-aggregate.js +16 -65
  289. package/dist/src/runtime/emit/hash-aggregate.js.map +1 -1
  290. package/dist/src/runtime/emit/insert.d.ts.map +1 -1
  291. package/dist/src/runtime/emit/insert.js +18 -7
  292. package/dist/src/runtime/emit/insert.js.map +1 -1
  293. package/dist/src/runtime/emit/join-key-extractor.d.ts +46 -0
  294. package/dist/src/runtime/emit/join-key-extractor.d.ts.map +1 -0
  295. package/dist/src/runtime/emit/join-key-extractor.js +60 -0
  296. package/dist/src/runtime/emit/join-key-extractor.js.map +1 -0
  297. package/dist/src/runtime/emit/join.d.ts.map +1 -1
  298. package/dist/src/runtime/emit/join.js +37 -11
  299. package/dist/src/runtime/emit/join.js.map +1 -1
  300. package/dist/src/runtime/emit/key-set-semi-join.d.ts +29 -0
  301. package/dist/src/runtime/emit/key-set-semi-join.d.ts.map +1 -0
  302. package/dist/src/runtime/emit/key-set-semi-join.js +143 -0
  303. package/dist/src/runtime/emit/key-set-semi-join.js.map +1 -0
  304. package/dist/src/runtime/emit/materialized-view-helpers.d.ts +14 -1
  305. package/dist/src/runtime/emit/materialized-view-helpers.d.ts.map +1 -1
  306. package/dist/src/runtime/emit/materialized-view-helpers.js +33 -3
  307. package/dist/src/runtime/emit/materialized-view-helpers.js.map +1 -1
  308. package/dist/src/runtime/emit/materialized-view.d.ts.map +1 -1
  309. package/dist/src/runtime/emit/materialized-view.js +47 -6
  310. package/dist/src/runtime/emit/materialized-view.js.map +1 -1
  311. package/dist/src/runtime/emit/merge-join.d.ts.map +1 -1
  312. package/dist/src/runtime/emit/merge-join.js +32 -15
  313. package/dist/src/runtime/emit/merge-join.js.map +1 -1
  314. package/dist/src/runtime/emit/operand-comparator.d.ts +40 -0
  315. package/dist/src/runtime/emit/operand-comparator.d.ts.map +1 -0
  316. package/dist/src/runtime/emit/operand-comparator.js +59 -0
  317. package/dist/src/runtime/emit/operand-comparator.js.map +1 -0
  318. package/dist/src/runtime/emit/scan.d.ts.map +1 -1
  319. package/dist/src/runtime/emit/scan.js +11 -2
  320. package/dist/src/runtime/emit/scan.js.map +1 -1
  321. package/dist/src/runtime/emit/set-object-tags.d.ts +8 -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 +8 -0
  324. package/dist/src/runtime/emit/set-object-tags.js.map +1 -1
  325. package/dist/src/runtime/emit/set-operation.d.ts.map +1 -1
  326. package/dist/src/runtime/emit/set-operation.js +7 -4
  327. package/dist/src/runtime/emit/set-operation.js.map +1 -1
  328. package/dist/src/runtime/emit/sort.d.ts.map +1 -1
  329. package/dist/src/runtime/emit/sort.js +5 -2
  330. package/dist/src/runtime/emit/sort.js.map +1 -1
  331. package/dist/src/runtime/emit/subquery.d.ts.map +1 -1
  332. package/dist/src/runtime/emit/subquery.js +113 -13
  333. package/dist/src/runtime/emit/subquery.js.map +1 -1
  334. package/dist/src/runtime/emit/temporal-arithmetic.d.ts +7 -0
  335. package/dist/src/runtime/emit/temporal-arithmetic.d.ts.map +1 -1
  336. package/dist/src/runtime/emit/temporal-arithmetic.js +15 -7
  337. package/dist/src/runtime/emit/temporal-arithmetic.js.map +1 -1
  338. package/dist/src/runtime/emit/update.d.ts.map +1 -1
  339. package/dist/src/runtime/emit/update.js +44 -3
  340. package/dist/src/runtime/emit/update.js.map +1 -1
  341. package/dist/src/runtime/emit/window.d.ts.map +1 -1
  342. package/dist/src/runtime/emit/window.js +72 -55
  343. package/dist/src/runtime/emit/window.js.map +1 -1
  344. package/dist/src/runtime/foreign-key-actions.d.ts +36 -1
  345. package/dist/src/runtime/foreign-key-actions.d.ts.map +1 -1
  346. package/dist/src/runtime/foreign-key-actions.js +238 -116
  347. package/dist/src/runtime/foreign-key-actions.js.map +1 -1
  348. package/dist/src/runtime/parallel-driver.d.ts +10 -2
  349. package/dist/src/runtime/parallel-driver.d.ts.map +1 -1
  350. package/dist/src/runtime/parallel-driver.js +12 -2
  351. package/dist/src/runtime/parallel-driver.js.map +1 -1
  352. package/dist/src/runtime/register.d.ts.map +1 -1
  353. package/dist/src/runtime/register.js +2 -0
  354. package/dist/src/runtime/register.js.map +1 -1
  355. package/dist/src/runtime/types.d.ts +25 -0
  356. package/dist/src/runtime/types.d.ts.map +1 -1
  357. package/dist/src/runtime/types.js.map +1 -1
  358. package/dist/src/schema/catalog-persistability.d.ts +58 -0
  359. package/dist/src/schema/catalog-persistability.d.ts.map +1 -0
  360. package/dist/src/schema/catalog-persistability.js +87 -0
  361. package/dist/src/schema/catalog-persistability.js.map +1 -0
  362. package/dist/src/schema/catalog.d.ts +17 -1
  363. package/dist/src/schema/catalog.d.ts.map +1 -1
  364. package/dist/src/schema/catalog.js +25 -3
  365. package/dist/src/schema/catalog.js.map +1 -1
  366. package/dist/src/schema/constraint-builder.d.ts +20 -22
  367. package/dist/src/schema/constraint-builder.d.ts.map +1 -1
  368. package/dist/src/schema/constraint-builder.js +43 -36
  369. package/dist/src/schema/constraint-builder.js.map +1 -1
  370. package/dist/src/schema/ddl-generator.d.ts +23 -0
  371. package/dist/src/schema/ddl-generator.d.ts.map +1 -1
  372. package/dist/src/schema/ddl-generator.js +27 -0
  373. package/dist/src/schema/ddl-generator.js.map +1 -1
  374. package/dist/src/schema/function.d.ts +39 -1
  375. package/dist/src/schema/function.d.ts.map +1 -1
  376. package/dist/src/schema/function.js.map +1 -1
  377. package/dist/src/schema/manager.d.ts +28 -0
  378. package/dist/src/schema/manager.d.ts.map +1 -1
  379. package/dist/src/schema/manager.js +82 -14
  380. package/dist/src/schema/manager.js.map +1 -1
  381. package/dist/src/schema/schema-differ.d.ts.map +1 -1
  382. package/dist/src/schema/schema-differ.js +51 -12
  383. package/dist/src/schema/schema-differ.js.map +1 -1
  384. package/dist/src/schema/unique-enforcement.d.ts +31 -0
  385. package/dist/src/schema/unique-enforcement.d.ts.map +1 -1
  386. package/dist/src/schema/unique-enforcement.js +37 -1
  387. package/dist/src/schema/unique-enforcement.js.map +1 -1
  388. package/dist/src/schema/window-function.d.ts +30 -10
  389. package/dist/src/schema/window-function.d.ts.map +1 -1
  390. package/dist/src/schema/window-function.js +20 -16
  391. package/dist/src/schema/window-function.js.map +1 -1
  392. package/dist/src/types/builtin-types.d.ts.map +1 -1
  393. package/dist/src/types/builtin-types.js +30 -4
  394. package/dist/src/types/builtin-types.js.map +1 -1
  395. package/dist/src/types/cast-semantics.d.ts +43 -0
  396. package/dist/src/types/cast-semantics.d.ts.map +1 -0
  397. package/dist/src/types/cast-semantics.js +59 -0
  398. package/dist/src/types/cast-semantics.js.map +1 -0
  399. package/dist/src/types/index.d.ts +1 -1
  400. package/dist/src/types/index.d.ts.map +1 -1
  401. package/dist/src/types/index.js +1 -1
  402. package/dist/src/types/index.js.map +1 -1
  403. package/dist/src/types/json-type.d.ts.map +1 -1
  404. package/dist/src/types/json-type.js +31 -10
  405. package/dist/src/types/json-type.js.map +1 -1
  406. package/dist/src/types/logical-type.d.ts +22 -0
  407. package/dist/src/types/logical-type.d.ts.map +1 -1
  408. package/dist/src/types/logical-type.js.map +1 -1
  409. package/dist/src/types/temporal-types.d.ts.map +1 -1
  410. package/dist/src/types/temporal-types.js +33 -11
  411. package/dist/src/types/temporal-types.js.map +1 -1
  412. package/dist/src/types/validation.d.ts +39 -1
  413. package/dist/src/types/validation.d.ts.map +1 -1
  414. package/dist/src/types/validation.js +60 -0
  415. package/dist/src/types/validation.js.map +1 -1
  416. package/dist/src/util/ast-spine-clone.d.ts +23 -0
  417. package/dist/src/util/ast-spine-clone.d.ts.map +1 -0
  418. package/dist/src/util/ast-spine-clone.js +41 -0
  419. package/dist/src/util/ast-spine-clone.js.map +1 -0
  420. package/dist/src/util/coercion.d.ts +13 -0
  421. package/dist/src/util/coercion.d.ts.map +1 -1
  422. package/dist/src/util/coercion.js +10 -1
  423. package/dist/src/util/coercion.js.map +1 -1
  424. package/dist/src/util/comparison.d.ts +114 -0
  425. package/dist/src/util/comparison.d.ts.map +1 -1
  426. package/dist/src/util/comparison.js +187 -27
  427. package/dist/src/util/comparison.js.map +1 -1
  428. package/dist/src/vtab/best-access-plan.d.ts +87 -0
  429. package/dist/src/vtab/best-access-plan.d.ts.map +1 -1
  430. package/dist/src/vtab/best-access-plan.js +87 -0
  431. package/dist/src/vtab/best-access-plan.js.map +1 -1
  432. package/dist/src/vtab/manifest.d.ts +7 -0
  433. package/dist/src/vtab/manifest.d.ts.map +1 -1
  434. package/dist/src/vtab/memory/connection.d.ts +14 -1
  435. package/dist/src/vtab/memory/connection.d.ts.map +1 -1
  436. package/dist/src/vtab/memory/connection.js +20 -2
  437. package/dist/src/vtab/memory/connection.js.map +1 -1
  438. package/dist/src/vtab/memory/layer/base.d.ts +12 -5
  439. package/dist/src/vtab/memory/layer/base.d.ts.map +1 -1
  440. package/dist/src/vtab/memory/layer/base.js +20 -9
  441. package/dist/src/vtab/memory/layer/base.js.map +1 -1
  442. package/dist/src/vtab/memory/layer/connection.d.ts +17 -0
  443. package/dist/src/vtab/memory/layer/connection.d.ts.map +1 -1
  444. package/dist/src/vtab/memory/layer/connection.js +26 -0
  445. package/dist/src/vtab/memory/layer/connection.js.map +1 -1
  446. package/dist/src/vtab/memory/layer/manager.d.ts +156 -31
  447. package/dist/src/vtab/memory/layer/manager.d.ts.map +1 -1
  448. package/dist/src/vtab/memory/layer/manager.js +695 -158
  449. package/dist/src/vtab/memory/layer/manager.js.map +1 -1
  450. package/dist/src/vtab/memory/layer/plan-filter.d.ts +41 -20
  451. package/dist/src/vtab/memory/layer/plan-filter.d.ts.map +1 -1
  452. package/dist/src/vtab/memory/layer/plan-filter.js +57 -27
  453. package/dist/src/vtab/memory/layer/plan-filter.js.map +1 -1
  454. package/dist/src/vtab/memory/layer/row-convert.d.ts +21 -0
  455. package/dist/src/vtab/memory/layer/row-convert.d.ts.map +1 -0
  456. package/dist/src/vtab/memory/layer/row-convert.js +30 -0
  457. package/dist/src/vtab/memory/layer/row-convert.js.map +1 -0
  458. package/dist/src/vtab/memory/layer/scan-layer.d.ts +6 -3
  459. package/dist/src/vtab/memory/layer/scan-layer.d.ts.map +1 -1
  460. package/dist/src/vtab/memory/layer/scan-layer.js +48 -34
  461. package/dist/src/vtab/memory/layer/scan-layer.js.map +1 -1
  462. package/dist/src/vtab/memory/layer/transaction.d.ts +142 -19
  463. package/dist/src/vtab/memory/layer/transaction.d.ts.map +1 -1
  464. package/dist/src/vtab/memory/layer/transaction.js +237 -73
  465. package/dist/src/vtab/memory/layer/transaction.js.map +1 -1
  466. package/dist/src/vtab/memory/module.d.ts +14 -2
  467. package/dist/src/vtab/memory/module.d.ts.map +1 -1
  468. package/dist/src/vtab/memory/module.js +60 -41
  469. package/dist/src/vtab/memory/module.js.map +1 -1
  470. package/dist/src/vtab/memory/table.d.ts +1 -1
  471. package/dist/src/vtab/memory/table.d.ts.map +1 -1
  472. package/dist/src/vtab/memory/table.js +12 -4
  473. package/dist/src/vtab/memory/table.js.map +1 -1
  474. package/dist/src/vtab/memory/types.d.ts +27 -1
  475. package/dist/src/vtab/memory/types.d.ts.map +1 -1
  476. package/dist/src/vtab/memory/types.js +16 -1
  477. package/dist/src/vtab/memory/types.js.map +1 -1
  478. package/dist/src/vtab/memory/utils/primary-key.d.ts +9 -0
  479. package/dist/src/vtab/memory/utils/primary-key.d.ts.map +1 -1
  480. package/dist/src/vtab/memory/utils/primary-key.js +11 -0
  481. package/dist/src/vtab/memory/utils/primary-key.js.map +1 -1
  482. package/dist/src/vtab/module.d.ts +63 -0
  483. package/dist/src/vtab/module.d.ts.map +1 -1
  484. package/dist/src/vtab/table.d.ts +33 -7
  485. package/dist/src/vtab/table.d.ts.map +1 -1
  486. package/dist/src/vtab/table.js.map +1 -1
  487. package/package.json +3 -3
  488. package/dist/src/planner/rules/cache/rule-in-subquery-cache.d.ts +0 -26
  489. package/dist/src/planner/rules/cache/rule-in-subquery-cache.d.ts.map +0 -1
  490. package/dist/src/planner/rules/cache/rule-in-subquery-cache.js +0 -66
  491. package/dist/src/planner/rules/cache/rule-in-subquery-cache.js.map +0 -1
@@ -64,6 +64,66 @@ export function validateAndParse(value, type, columnName) {
64
64
  // Then validate the parsed result
65
65
  return validateValue(parsed, type, columnName);
66
66
  }
67
+ /**
68
+ * Coerce each cell in `row` to its declared column's logical type via
69
+ * {@link validateAndParse} (INTEGER/REAL affinity, JSON parsing, etc.) — the
70
+ * shared step every write path (memory tables, the KV store backend, the
71
+ * isolation overlay) applies before PK extraction, serialization, and index-key
72
+ * construction. `label` identifies the target for the "too many values" error
73
+ * (e.g. `` `${schemaName}.${tableName}` `` or `` `INSERT into ${tableName}` ``)
74
+ * so each call site keeps its own wording.
75
+ *
76
+ * @throws QuereusError if `row` has more cells than `columns`, or a cell fails validation/parsing
77
+ */
78
+ export function coerceRowToSchema(row, columns, label) {
79
+ if (row.length > columns.length) {
80
+ throw new QuereusError(`Too many values for ${label}: expected ${columns.length}, got ${row.length}`, StatusCode.ERROR);
81
+ }
82
+ return row.map((value, i) => validateAndParse(value, columns[i].logicalType, columns[i].name));
83
+ }
84
+ /**
85
+ * Build the per-statement conversion step for a DML write. Given the static
86
+ * logical type of the expression producing each cell (index-aligned with
87
+ * `columns`) and the target columns, returns a closure that converts exactly
88
+ * the cells whose producing type is not already the target column's logical
89
+ * type — or `undefined` when no cell needs converting, so the caller can skip
90
+ * the per-row work entirely.
91
+ *
92
+ * Types are compared by object identity: the type registry hands out one
93
+ * shared `LogicalType` instance per type, so an expression whose static type
94
+ * IS the column's type (a reference to a same-typed column — an unassigned
95
+ * column in an UPDATE, or `insert into b select j from a`) produces values
96
+ * already in declared form, and those MUST be left alone: conversion is not
97
+ * repeatable for every type. JSON's `parse` reads a plain JS string as JSON
98
+ * source, so re-converting a stored JSON text value either changes it (the
99
+ * text `9` becomes the number 9) or throws (`abc` is not valid JSON source).
100
+ * An unknown source type (`undefined` entry) converts — the safe historical
101
+ * behavior for values of unproven provenance.
102
+ *
103
+ * The returned closure copies the row and converts via {@link validateAndParse},
104
+ * so conversion failures carry the same message text the storage layer used to
105
+ * produce. Cells at or beyond the row's length are left for the storage width
106
+ * guard, mirroring {@link coerceRowToSchema}'s map-over-present-cells behavior.
107
+ */
108
+ export function buildRowCoercion(sourceTypes, columns) {
109
+ const convertIndices = [];
110
+ for (let i = 0; i < columns.length; i++) {
111
+ if (sourceTypes[i] !== columns[i].logicalType) {
112
+ convertIndices.push(i);
113
+ }
114
+ }
115
+ if (convertIndices.length === 0)
116
+ return undefined;
117
+ return (row) => {
118
+ const out = row.slice();
119
+ for (const i of convertIndices) {
120
+ if (i >= out.length)
121
+ break;
122
+ out[i] = validateAndParse(out[i], columns[i].logicalType, columns[i].name);
123
+ }
124
+ return out;
125
+ };
126
+ }
67
127
  /**
68
128
  * Check if a value is compatible with a logical type without throwing.
69
129
  *
@@ -1 +1 @@
1
- {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../../src/types/validation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAC5B,KAAe,EACf,IAAiB,EACjB,UAAmB;IAEnB,uBAAuB;IACvB,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAEhC,2BAA2B;IAC3B,IAAI,IAA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AAE,IAAiB;IAChE,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,IAAI,CAAC,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAChC,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC7B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAe,EAAE,IAAiB;IAC1D,IAAI,CAAC;QACJ,OAAO,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAChC,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,IAAI,CAAC;IACb,CAAC;AACF,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Structural ("spine") clone of an AST subtree: plain objects and arrays are
3
+ * deep-copied, everything else is passed through **by reference**.
4
+ *
5
+ * Exists for the in-place AST rewriters (`schema/rename-rewriter.ts`), which
6
+ * mutate the node graph they are handed and report whether anything changed. A
7
+ * caller that wants to compute what a rewrite *would* produce — without touching
8
+ * the live catalog AST — must rewrite a copy instead.
9
+ *
10
+ * Why not `structuredClone`: `AST.LiteralExpr.value` is typed
11
+ * `MaybePromise<SqlValue>`, and a Promise is not structured-cloneable — a live
12
+ * body carrying one would throw `DataCloneError`. The rewriters only ever assign
13
+ * to string fields (`.name`, `.schema`, `.table`, `.column`) and replace string
14
+ * arrays on plain AST nodes, so copying the plain-object/array spine is enough:
15
+ * every leaf they mutate is freshly owned, and every leaf they do not touch
16
+ * (primitives, `Uint8Array`, `bigint`, class instances, Promises) can safely stay
17
+ * shared.
18
+ *
19
+ * Frozen inputs are fine — the copy is unfrozen. Assumes a tree (the parser emits
20
+ * no cycles); a cyclic graph would recurse without bound.
21
+ */
22
+ export declare function spineCloneAst<T>(node: T): T;
23
+ //# sourceMappingURL=ast-spine-clone.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast-spine-clone.d.ts","sourceRoot":"","sources":["../../../src/util/ast-spine-clone.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAE3C"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Structural ("spine") clone of an AST subtree: plain objects and arrays are
3
+ * deep-copied, everything else is passed through **by reference**.
4
+ *
5
+ * Exists for the in-place AST rewriters (`schema/rename-rewriter.ts`), which
6
+ * mutate the node graph they are handed and report whether anything changed. A
7
+ * caller that wants to compute what a rewrite *would* produce — without touching
8
+ * the live catalog AST — must rewrite a copy instead.
9
+ *
10
+ * Why not `structuredClone`: `AST.LiteralExpr.value` is typed
11
+ * `MaybePromise<SqlValue>`, and a Promise is not structured-cloneable — a live
12
+ * body carrying one would throw `DataCloneError`. The rewriters only ever assign
13
+ * to string fields (`.name`, `.schema`, `.table`, `.column`) and replace string
14
+ * arrays on plain AST nodes, so copying the plain-object/array spine is enough:
15
+ * every leaf they mutate is freshly owned, and every leaf they do not touch
16
+ * (primitives, `Uint8Array`, `bigint`, class instances, Promises) can safely stay
17
+ * shared.
18
+ *
19
+ * Frozen inputs are fine — the copy is unfrozen. Assumes a tree (the parser emits
20
+ * no cycles); a cyclic graph would recurse without bound.
21
+ */
22
+ export function spineCloneAst(node) {
23
+ return spineClone(node);
24
+ }
25
+ function spineClone(value) {
26
+ if (Array.isArray(value))
27
+ return value.map(spineClone);
28
+ if (value === null || typeof value !== 'object')
29
+ return value;
30
+ // Anything with a non-plain prototype (Uint8Array, Date, Map, Promise, any
31
+ // class instance) is a leaf the rewriters never write into — share it.
32
+ const proto = Object.getPrototypeOf(value);
33
+ if (proto !== Object.prototype && proto !== null)
34
+ return value;
35
+ const out = {};
36
+ for (const [key, v] of Object.entries(value)) {
37
+ out[key] = spineClone(v);
38
+ }
39
+ return out;
40
+ }
41
+ //# sourceMappingURL=ast-spine-clone.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast-spine-clone.js","sourceRoot":"","sources":["../../../src/util/ast-spine-clone.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,aAAa,CAAI,IAAO;IACvC,OAAO,UAAU,CAAC,IAAI,CAAM,CAAC;AAC9B,CAAC;AAED,SAAS,UAAU,CAAC,KAAc;IACjC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACvD,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC9D,2EAA2E;IAC3E,uEAAuE;IACvE,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC3C,IAAI,KAAK,KAAK,MAAM,CAAC,SAAS,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC/D,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,KAAK,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9C,GAAG,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;IAC1B,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC"}
@@ -25,6 +25,19 @@ export declare function coerceToNumberForArithmetic(value: SqlValue): number;
25
25
  * BETWEEN emission and will be removed in a future release.
26
26
  */
27
27
  export declare function coerceForComparison(v1: SqlValue, v2: SqlValue): [SqlValue, SqlValue];
28
+ /**
29
+ * Coerces a value for aggregate function arguments.
30
+ * Most aggregate functions should accept numeric strings as numbers.
31
+ * For COUNT, no coercion needed. For SUM/AVG, numeric strings should be converted.
32
+ *
33
+ * NOTE: this converts a numeric-looking string for min/max too, so `min('5','10')`
34
+ * over a plain TEXT column returns the NUMBER 5 — disagreeing with
35
+ * `order by … limit 1`, which keeps text order. Predates the semantic-ordering
36
+ * min/max binding and is unchanged by it (the emitters skip this call entirely
37
+ * when every argument type is numeric or carries semantic ordering — see
38
+ * `computeAggregateSkipCoercion` in runtime/emit/aggregate-setup.ts). Tracked as
39
+ * backlog `bug-text-minmax-numeric-coercion`.
40
+ */
28
41
  export declare function coerceForAggregate(value: SqlValue, functionName: string): SqlValue;
29
42
  /**
30
43
  * Determines if a value should be treated as numeric in the given context.
@@ -1 +1 @@
1
- {"version":3,"file":"coercion.d.ts","sourceRoot":"","sources":["../../../src/util/coercion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;GAGG;AAEH;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,QAAQ,GAAG,QAAQ,CAU3D;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,CAWnE;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAyBpF;AASD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,GAAG,QAAQ,CAWlF;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CASvD"}
1
+ {"version":3,"file":"coercion.d.ts","sourceRoot":"","sources":["../../../src/util/coercion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;GAGG;AAEH;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,QAAQ,GAAG,QAAQ,CAU3D;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,CAWnE;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAyBpF;AAKD;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,GAAG,QAAQ,CAWlF;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CASvD"}
@@ -69,12 +69,21 @@ export function coerceForComparison(v1, v2) {
69
69
  // No coercion needed or possible
70
70
  return [v1, v2];
71
71
  }
72
+ /** Aggregates that never want their argument read as a number. */
73
+ const NON_NUMERIC_AGGREGATES = new Set(['COUNT', 'GROUP_CONCAT']);
72
74
  /**
73
75
  * Coerces a value for aggregate function arguments.
74
76
  * Most aggregate functions should accept numeric strings as numbers.
75
77
  * For COUNT, no coercion needed. For SUM/AVG, numeric strings should be converted.
78
+ *
79
+ * NOTE: this converts a numeric-looking string for min/max too, so `min('5','10')`
80
+ * over a plain TEXT column returns the NUMBER 5 — disagreeing with
81
+ * `order by … limit 1`, which keeps text order. Predates the semantic-ordering
82
+ * min/max binding and is unchanged by it (the emitters skip this call entirely
83
+ * when every argument type is numeric or carries semantic ordering — see
84
+ * `computeAggregateSkipCoercion` in runtime/emit/aggregate-setup.ts). Tracked as
85
+ * backlog `bug-text-minmax-numeric-coercion`.
76
86
  */
77
- const NON_NUMERIC_AGGREGATES = new Set(['COUNT', 'GROUP_CONCAT']);
78
87
  export function coerceForAggregate(value, functionName) {
79
88
  const upperName = functionName.toUpperCase();
80
89
  if (NON_NUMERIC_AGGREGATES.has(upperName) || upperName.startsWith('JSON_')) {
@@ -1 +1 @@
1
- {"version":3,"file":"coercion.js","sourceRoot":"","sources":["../../../src/util/coercion.ts"],"names":[],"mappings":"AAEA;;;GAGG;AAEH;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAe;IAChD,IAAI,OAAO,KAAK,KAAK,Q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jB,CAAC;AAED,kEAAkE;AAClE,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC;AAElE;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAe,EAAE,YAAoB;IACvE,MAAM,SAAS,GAAG,YAAY,CAAC,WAAW,EAAE,CAAC;IAC7C,IAAI,sBAAsB,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5E,OAAO,KAAK,CAAC;IACd,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACtD,OAAO,iBAAiB,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,KAAe;IAC7C,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IACjC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1F,OAAO,IAAI,CAAC;IACb,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,iBAAiB,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC;IAC3C,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC"}
@@ -173,6 +173,120 @@ export declare function compareWithOrderByFast(a: SqlValue, b: SqlValue, directi
173
173
  * @returns An optimized comparison function
174
174
  */
175
175
  export declare function createOrderByComparatorFast(direction?: 'asc' | 'desc', nullsOrdering?: 'first' | 'last', collationFunc?: CollationFunction): (a: SqlValue, b: SqlValue) => number;
176
+ /**
177
+ * True when a logical type's `compare` defines an order that observably differs from
178
+ * storage-class + collation ordering (see {@link LogicalType.semanticOrdering}). This
179
+ * is the routing predicate for user-visible ordering/identity sites: ORDER BY,
180
+ * comparison operators, range-scan bound filters, and DISTINCT/GROUP BY identity use
181
+ * the type's `compare` exactly when this returns true.
182
+ */
183
+ export declare function hasSemanticOrdering(type: LogicalType | undefined): type is LogicalType;
184
+ /**
185
+ * True when two logical types order values differently — i.e. the comparators
186
+ * {@link createTypedComparator} builds for them are not interchangeable, so any structure
187
+ * keyed by one has to be re-sorted (and its uniqueness re-judged) to move to the other.
188
+ *
189
+ * `createTypedComparator(type, coll)` is fully determined by `type.compare`: present → the
190
+ * type's own `compare`; absent → `compareSqlValuesFast` under the collation. So comparing
191
+ * the two `compare` identities is exactly the question, and it catches more than a
192
+ * {@link hasSemanticOrdering} check would:
193
+ *
194
+ * - TEXT ↔ TIMESPAN — TIMESPAN's `compare` ranks by elapsed time, so 'PT1H', 'PT60M' and
195
+ * 'PT3600S' are one value where text sees three.
196
+ * - TEXT ↔ JSON — JSON's `compare` ranks by canonical structure, so '{"a":1}' and
197
+ * '{ "a" : 1 }' are one value.
198
+ * - TEXT ↔ DATE / TIME / DATETIME — these carry their own `compare` hard-wired to
199
+ * BINARY_COLLATION, ignoring the column's declared collation, so `text collate nocase →
200
+ * date` really does re-order even though both orderings are "textual".
201
+ *
202
+ * A retype that flattens to the SAME logical type object (`text → varchar(50)`,
203
+ * `integer → bigint`) shares one `compare` and is correctly reported as no change.
204
+ *
205
+ * NOTE: deliberately conservative — it answers "may the order move", not "does it". The
206
+ * DATE / TIME / DATETIME family compares exactly as BINARY text does, so under the only
207
+ * collation those types legally accept (BINARY — `supportedCollations: []`) a `text → date`
208
+ * retype re-sorts every structure into the order it was already in. Harmless but O(rows);
209
+ * if a retype on a large table ever shows up as slow, narrow the predicate to a probe of the
210
+ * two comparators over a representative value set, or special-case the BINARY-equivalent
211
+ * comparators by identity.
212
+ */
213
+ export declare function comparisonSemanticsDiffer(a: LogicalType, b: LogicalType): boolean;
214
+ /**
215
+ * True when two declared logical types may share ONE physical equi-join key — i.e. when
216
+ * comparing their values with a single type-blind comparator (a serialized hash key, a
217
+ * merge co-walk) reproduces what `=` says about them.
218
+ *
219
+ * The admissible shapes are "neither side declares a semantic-ordering type" or "both
220
+ * declare the SAME one". A **mixed** pair (`timespan` ↔ `text`) is the defect this gates:
221
+ * `=` runs the generic comparison path, which applies a runtime duration check whenever
222
+ * either side is temporal, so 'PT1H' = 'PT60M'; a hash or merge join comparing raw text
223
+ * disagrees and silently drops the row. Merge join cannot be rescued by canonicalizing
224
+ * the key either — it needs both inputs physically sorted in its comparator's order, and
225
+ * a `timespan` side is sorted by elapsed time while a `text` side is sorted by text, so
226
+ * no single comparator merges the two. Declining is the only sound answer; the pair
227
+ * demotes to the residual / generic join, where `=`'s own semantics apply.
228
+ *
229
+ * NOT {@link comparisonSemanticsDiffer}, which asks a different question (may an ordered
230
+ * structure keyed under `a` be reused under `b`) by comparing `compare` identity. EVERY
231
+ * builtin type carries its own `compare`, so that predicate reports "differ" for an
232
+ * ordinary `integer` ↔ `real` join key and would cost a hash join for no correctness
233
+ * gain. This one keys on the `semanticOrdering` flag, which is exactly the set of types
234
+ * whose order is not reproducible from storage class + collation.
235
+ *
236
+ * See `docs/types.md` § "Semantic ordering".
237
+ */
238
+ export declare function semanticOrderingsAgree(a: LogicalType | undefined, b: LogicalType | undefined): boolean;
239
+ /**
240
+ * Canonical key-identity transform for a declared logical type, or undefined when raw
241
+ * values already key faithfully. Defined exactly when the type carries semantic ordering
242
+ * AND a `groupKey` hook (TIMESPAN — its stored text is not canonical for equality:
243
+ * 'PT1H' ≡ 'PT60M'); JSON has semantic ordering but its canonical text is already
244
+ * identity-faithful, so it takes no transform. Every hash-, set-, or byte-keyed identity
245
+ * site (GROUP BY, hash joins, IN membership, the persistent store's PK/index key encoding,
246
+ * the isolation overlay's shadowing keys) must run values through this before serializing, or two
247
+ * values the type's `compare` calls equal land on distinct keys.
248
+ */
249
+ export declare function semanticKeyTransform(type: LogicalType | undefined): ((value: SqlValue) => SqlValue) | undefined;
250
+ /**
251
+ * ORDER BY comparator for one sort key of a declared logical type. When the type
252
+ * carries semantic ordering (see {@link hasSemanticOrdering}), non-NULL pairs are
253
+ * ranked by the type's `compare` (via {@link createTypedComparator}, which keeps the
254
+ * storage-class-mismatch fallback so a probe of a different storage class never
255
+ * falsely equals); otherwise this is exactly {@link createOrderByComparatorFast}.
256
+ *
257
+ * NULL placement is handled HERE, never delegated to `type.compare` — the type
258
+ * convention (NULL smallest, always) differs from ORDER BY's NULLS FIRST/LAST and
259
+ * default rules, which {@link orderByNullResult} implements.
260
+ */
261
+ export declare function createTypedOrderByComparator(type: LogicalType | undefined, direction?: 'asc' | 'desc', nullsOrdering?: 'first' | 'last', collationFunc?: CollationFunction): (a: SqlValue, b: SqlValue) => number;
262
+ /**
263
+ * The comparator an ordering site uses for a single value of `type` under
264
+ * `collation`: the type's own `compare` when it carries semantic ordering
265
+ * ({@link hasSemanticOrdering}), else storage-class + collation ordering. The
266
+ * scalar form of {@link createSemanticRowComparator}'s per-column routing — one
267
+ * copy of the routing rule, shared by row identity (DISTINCT/set operations) and
268
+ * the min/max aggregate binding (`bindArgs` in func/builtins/aggregate.ts).
269
+ *
270
+ * `type` may be undefined (untyped/ANY) — such values use the collation
271
+ * comparator, byte-identical to the historical BINARY default when no collation
272
+ * is passed. Safe for runtime type drift: the typed path's
273
+ * storage-class-mismatch guard (see {@link createTypedComparator}) falls back to
274
+ * storage-class ordering rather than mis-parsing.
275
+ */
276
+ export declare function createSemanticValueComparator(type: LogicalType | undefined, collation?: CollationFunction): (a: SqlValue, b: SqlValue) => number;
277
+ /**
278
+ * Row comparator for identity checks (DISTINCT, set operations) that routes each
279
+ * column through its declared logical type's `compare` when — and only when — that
280
+ * type carries semantic ordering ({@link hasSemanticOrdering}); all other columns
281
+ * keep the storage-class + collation comparison of
282
+ * {@link createCollationRowComparator}. This makes row identity agree with `=`
283
+ * (e.g. TIMESPAN 'PT1H' ≡ 'PT60M' collapses) without perturbing collation-aware
284
+ * text identity on ANY/TEXT columns, whose declared `compare` is not
285
+ * collation-aware and must not be consulted here.
286
+ *
287
+ * Per-column routing is {@link createSemanticValueComparator}.
288
+ */
289
+ export declare function createSemanticRowComparator(types: readonly (LogicalType | undefined)[], collations: readonly CollationFunction[]): (a: Row, b: Row) => number;
176
290
  /**
177
291
  * Determines if a SqlValue is truthy for filter purposes.
178
292
  * In SQL semantics (numeric truthiness):
@@ -1 +1 @@
1
- {"version":3,"file":"comparison.d.ts","sourceRoot":"","sources":["../../../src/util/comparison.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAGxD,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAKlG,YAAY,EAAE,iBAAiB,EAAE,CAAC;AASlC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAkB9D;AAsBD;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,iBAE9B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAE,iBAE9B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,iBAQ7B,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAOpF;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE3D;AAgCD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CActG;AAoGD;;;;;;;;;;;;GAYG;AACH,wBAAg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AAC,EAAE,iBAAiB,GAC3B,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,KAAK,MAAM,CA0BtC;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACvC,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,UAAU,CAAC,EAAE,SAAS,CAAC,iBAAiB,GAAG,SAAS,CAAC,EAAE,GACrD,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,KAAK,MAAM,CAa5B;AAED;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAC3C,UAAU,EAAE,SAAS,iBAAiB,EAAE,GACtC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,KAAK,MAAM,CAU5B"}
@@ -221,8 +221,14 @@ function compareNumbers(a, b) {
221
221
  *
222
222
  * Their ORDERINGS are unrelated and always have been: this branch compares canonical JSON
223
223
  * *syntax* (braces, quotes, commas included), while `deepCompareJson` ranks by JSON type,
224
- * then key list, then values. Only this branch's order is load-bearing it is what the
225
- * store's `encodeObject` writes as UTF-8 and physically sorts by.
224
+ * then key list, then values. This branch's order is what the store's `encodeObject`
225
+ * writes as UTF-8 and physically sorts by.
226
+ *
227
+ * This branch is reached only where an OBJECT value is ordered WITHOUT a declared JSON
228
+ * logical type to route it. A declared JSON column is compared through
229
+ * `createTypedComparator(JSON_TYPE, …)` everywhere it is ordered — the memory BTree's key
230
+ * comparator, `<`/`>`/BETWEEN at runtime, and ORDER BY — so an indexed JSON range seek
231
+ * walks exactly the window the operators evaluate.
226
232
  *
227
233
  * NOTE: assumes OBJECT-class values are treated as immutable — the string is cached on
228
234
  * first serialization and never invalidated, so mutating a value in place after it has
@@ -407,34 +413,27 @@ export var NullsOrdering;
407
413
  * @returns -1 if a < b, 0 if a === b, 1 if a > b (after applying direction and null ordering)
408
414
  */
409
415
  export function compareWithOrderByFast(a, b, direction, nullsOrdering, collationFunc) {
410
- let comparison;
411
416
  // Fast path: both values are non-NULL (most common case)
412
417
  if (a !== null && b !== null) {
413
- comparison = compareSqlValuesFast(a, b, collationFunc);
414
- }
415
- else if (a === null && b === null) {
416
- comparison = 0;
417
- }
418
- else if (a === null) {
419
- // Explicit NULLS ordering is absolute — not affected by ASC/DESC
420
- if (nullsOrdering === NullsOrdering.FIRST)
421
- return -1;
422
- if (nullsOrdering === NullsOrdering.LAST)
423
- return 1;
424
- // Default behavior: nulls always first (both ASC and DESC)
425
- comparison = direction === SortDirection.DESC ? 1 : -1;
426
- }
427
- else { // b === null
428
- // Explicit NULLS ordering is absolute — not affected by ASC/DESC
429
- if (nullsOrdering === NullsOrdering.FIRST)
430
- return 1;
431
- if (nullsOrdering === NullsOrdering.LAST)
432
- return -1;
433
- // Default behavior: nulls always first (both ASC and DESC)
434
- comparison = direction === SortDirection.DESC ? -1 : 1;
418
+ const comparison = compareSqlValuesFast(a, b, collationFunc);
419
+ // Apply DESC direction (branchless when direction is ASC)
420
+ return direction === SortDirection.DESC ? -comparison : comparison;
435
421
  }
436
- // Apply DESC direction (branchless when direction is ASC)
437
- return direction === SortDirection.DESC ? -comparison : comparison;
422
+ return orderByNullResult(a, b, nullsOrdering);
423
+ }
424
+ /**
425
+ * Final ORDER BY verdict for a pair with at least one NULL. NULL placement is
426
+ * absolute — never affected by ASC/DESC: explicit NULLS FIRST/LAST pin the ends,
427
+ * and the default places NULLs first for both directions (SQLite-compatible; the
428
+ * historical direction-conditioned form in {@link compareWithOrderByFast} negated
429
+ * itself back to the same result).
430
+ */
431
+ function orderByNullResult(a, b, nullsOrdering) {
432
+ if (a === null && b === null)
433
+ return 0;
434
+ if (a === null)
435
+ return nullsOrdering === NullsOrdering.LAST ? 1 : -1;
436
+ return nullsOrdering === NullsOrdering.LAST ? -1 : 1;
438
437
  }
439
438
  /**
440
439
  * Factory function that takes a pre-resolved collation function.
@@ -457,6 +456,167 @@ export function createOrderByComparatorFast(direction = 'asc', nullsOrdering, co
457
456
  return compareWithOrderByFast(a, b, directionFlag, nullsFlag, collationFunc);
458
457
  };
459
458
  }
459
+ /**
460
+ * True when a logical type's `compare` defines an order that observably differs from
461
+ * storage-class + collation ordering (see {@link LogicalType.semanticOrdering}). This
462
+ * is the routing predicate for user-visible ordering/identity sites: ORDER BY,
463
+ * comparison operators, range-scan bound filters, and DISTINCT/GROUP BY identity use
464
+ * the type's `compare` exactly when this returns true.
465
+ */
466
+ export function hasSemanticOrdering(type) {
467
+ return type?.semanticOrdering === true && typeof type.compare === 'function';
468
+ }
469
+ /**
470
+ * True when two logical types order values differently — i.e. the comparators
471
+ * {@link createTypedComparator} builds for them are not interchangeable, so any structure
472
+ * keyed by one has to be re-sorted (and its uniqueness re-judged) to move to the other.
473
+ *
474
+ * `createTypedComparator(type, coll)` is fully determined by `type.compare`: present → the
475
+ * type's own `compare`; absent → `compareSqlValuesFast` under the collation. So comparing
476
+ * the two `compare` identities is exactly the question, and it catches more than a
477
+ * {@link hasSemanticOrdering} check would:
478
+ *
479
+ * - TEXT ↔ TIMESPAN — TIMESPAN's `compare` ranks by elapsed time, so 'PT1H', 'PT60M' and
480
+ * 'PT3600S' are one value where text sees three.
481
+ * - TEXT ↔ JSON — JSON's `compare` ranks by canonical structure, so '{"a":1}' and
482
+ * '{ "a" : 1 }' are one value.
483
+ * - TEXT ↔ DATE / TIME / DATETIME — these carry their own `compare` hard-wired to
484
+ * BINARY_COLLATION, ignoring the column's declared collation, so `text collate nocase →
485
+ * date` really does re-order even though both orderings are "textual".
486
+ *
487
+ * A retype that flattens to the SAME logical type object (`text → varchar(50)`,
488
+ * `integer → bigint`) shares one `compare` and is correctly reported as no change.
489
+ *
490
+ * NOTE: deliberately conservative — it answers "may the order move", not "does it". The
491
+ * DATE / TIME / DATETIME family compares exactly as BINARY text does, so under the only
492
+ * collation those types legally accept (BINARY — `supportedCollations: []`) a `text → date`
493
+ * retype re-sorts every structure into the order it was already in. Harmless but O(rows);
494
+ * if a retype on a large table ever shows up as slow, narrow the predicate to a probe of the
495
+ * two comparators over a representative value set, or special-case the BINARY-equivalent
496
+ * comparators by identity.
497
+ */
498
+ export function comparisonSemanticsDiffer(a, b) {
499
+ return a.compare !== b.compare;
500
+ }
501
+ /**
502
+ * True when two declared logical types may share ONE physical equi-join key — i.e. when
503
+ * comparing their values with a single type-blind comparator (a serialized hash key, a
504
+ * merge co-walk) reproduces what `=` says about them.
505
+ *
506
+ * The admissible shapes are "neither side declares a semantic-ordering type" or "both
507
+ * declare the SAME one". A **mixed** pair (`timespan` ↔ `text`) is the defect this gates:
508
+ * `=` runs the generic comparison path, which applies a runtime duration check whenever
509
+ * either side is temporal, so 'PT1H' = 'PT60M'; a hash or merge join comparing raw text
510
+ * disagrees and silently drops the row. Merge join cannot be rescued by canonicalizing
511
+ * the key either — it needs both inputs physically sorted in its comparator's order, and
512
+ * a `timespan` side is sorted by elapsed time while a `text` side is sorted by text, so
513
+ * no single comparator merges the two. Declining is the only sound answer; the pair
514
+ * demotes to the residual / generic join, where `=`'s own semantics apply.
515
+ *
516
+ * NOT {@link comparisonSemanticsDiffer}, which asks a different question (may an ordered
517
+ * structure keyed under `a` be reused under `b`) by comparing `compare` identity. EVERY
518
+ * builtin type carries its own `compare`, so that predicate reports "differ" for an
519
+ * ordinary `integer` ↔ `real` join key and would cost a hash join for no correctness
520
+ * gain. This one keys on the `semanticOrdering` flag, which is exactly the set of types
521
+ * whose order is not reproducible from storage class + collation.
522
+ *
523
+ * See `docs/types.md` § "Semantic ordering".
524
+ */
525
+ export function semanticOrderingsAgree(a, b) {
526
+ const semA = hasSemanticOrdering(a);
527
+ const semB = hasSemanticOrdering(b);
528
+ if (!semA && !semB)
529
+ return true;
530
+ return semA && semB && a === b;
531
+ }
532
+ /**
533
+ * Canonical key-identity transform for a declared logical type, or undefined when raw
534
+ * values already key faithfully. Defined exactly when the type carries semantic ordering
535
+ * AND a `groupKey` hook (TIMESPAN — its stored text is not canonical for equality:
536
+ * 'PT1H' ≡ 'PT60M'); JSON has semantic ordering but its canonical text is already
537
+ * identity-faithful, so it takes no transform. Every hash-, set-, or byte-keyed identity
538
+ * site (GROUP BY, hash joins, IN membership, the persistent store's PK/index key encoding,
539
+ * the isolation overlay's shadowing keys) must run values through this before serializing, or two
540
+ * values the type's `compare` calls equal land on distinct keys.
541
+ */
542
+ export function semanticKeyTransform(type) {
543
+ return hasSemanticOrdering(type) && type.groupKey
544
+ ? (value) => type.groupKey(value)
545
+ : undefined;
546
+ }
547
+ /**
548
+ * ORDER BY comparator for one sort key of a declared logical type. When the type
549
+ * carries semantic ordering (see {@link hasSemanticOrdering}), non-NULL pairs are
550
+ * ranked by the type's `compare` (via {@link createTypedComparator}, which keeps the
551
+ * storage-class-mismatch fallback so a probe of a different storage class never
552
+ * falsely equals); otherwise this is exactly {@link createOrderByComparatorFast}.
553
+ *
554
+ * NULL placement is handled HERE, never delegated to `type.compare` — the type
555
+ * convention (NULL smallest, always) differs from ORDER BY's NULLS FIRST/LAST and
556
+ * default rules, which {@link orderByNullResult} implements.
557
+ */
558
+ export function createTypedOrderByComparator(type, direction = 'asc', nullsOrdering, collationFunc = BINARY_COLLATION) {
559
+ if (!hasSemanticOrdering(type)) {
560
+ return createOrderByComparatorFast(direction, nullsOrdering, collationFunc);
561
+ }
562
+ const negate = direction === 'desc';
563
+ const nullsFlag = nullsOrdering === 'first'
564
+ ? NullsOrdering.FIRST
565
+ : nullsOrdering === 'last'
566
+ ? NullsOrdering.LAST
567
+ : NullsOrdering.DEFAULT;
568
+ const typedCompare = createTypedComparator(type, collationFunc);
569
+ return (a, b) => {
570
+ if (a !== null && b !== null) {
571
+ const comparison = typedCompare(a, b);
572
+ return negate ? -comparison : comparison;
573
+ }
574
+ return orderByNullResult(a, b, nullsFlag);
575
+ };
576
+ }
577
+ /**
578
+ * The comparator an ordering site uses for a single value of `type` under
579
+ * `collation`: the type's own `compare` when it carries semantic ordering
580
+ * ({@link hasSemanticOrdering}), else storage-class + collation ordering. The
581
+ * scalar form of {@link createSemanticRowComparator}'s per-column routing — one
582
+ * copy of the routing rule, shared by row identity (DISTINCT/set operations) and
583
+ * the min/max aggregate binding (`bindArgs` in func/builtins/aggregate.ts).
584
+ *
585
+ * `type` may be undefined (untyped/ANY) — such values use the collation
586
+ * comparator, byte-identical to the historical BINARY default when no collation
587
+ * is passed. Safe for runtime type drift: the typed path's
588
+ * storage-class-mismatch guard (see {@link createTypedComparator}) falls back to
589
+ * storage-class ordering rather than mis-parsing.
590
+ */
591
+ export function createSemanticValueComparator(type, collation = BINARY_COLLATION) {
592
+ return hasSemanticOrdering(type)
593
+ ? createTypedComparator(type, collation)
594
+ : (a, b) => compareSqlValuesFast(a, b, collation);
595
+ }
596
+ /**
597
+ * Row comparator for identity checks (DISTINCT, set operations) that routes each
598
+ * column through its declared logical type's `compare` when — and only when — that
599
+ * type carries semantic ordering ({@link hasSemanticOrdering}); all other columns
600
+ * keep the storage-class + collation comparison of
601
+ * {@link createCollationRowComparator}. This makes row identity agree with `=`
602
+ * (e.g. TIMESPAN 'PT1H' ≡ 'PT60M' collapses) without perturbing collation-aware
603
+ * text identity on ANY/TEXT columns, whose declared `compare` is not
604
+ * collation-aware and must not be consulted here.
605
+ *
606
+ * Per-column routing is {@link createSemanticValueComparator}.
607
+ */
608
+ export function createSemanticRowComparator(types, collations) {
609
+ const comparators = types.map((type, i) => createSemanticValueComparator(type, collations[i] ?? BINARY_COLLATION));
610
+ const len = comparators.length;
611
+ return (a, b) => {
612
+ for (let i = 0; i < len; i++) {
613
+ const cmp = comparators[i](a[i], b[i]);
614
+ if (cmp !== 0)
615
+ return cmp;
616
+ }
617
+ return 0;
618
+ };
619
+ }
460
620
  /**
461
621
  * Determines if a SqlValue is truthy for filter purposes.
462
622
  * In SQL semantics (numeric truthiness):