@quereus/quereus 4.3.2 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/dist/src/core/database-external-changes.d.ts +2 -2
  2. package/dist/src/core/database-external-changes.d.ts.map +1 -1
  3. package/dist/src/core/database-external-changes.js +12 -9
  4. package/dist/src/core/database-external-changes.js.map +1 -1
  5. package/dist/src/core/database-materialized-views-apply.d.ts +156 -14
  6. package/dist/src/core/database-materialized-views-apply.d.ts.map +1 -1
  7. package/dist/src/core/database-materialized-views-apply.js +370 -65
  8. package/dist/src/core/database-materialized-views-apply.js.map +1 -1
  9. package/dist/src/core/database-materialized-views-plan-builders.d.ts +65 -1
  10. package/dist/src/core/database-materialized-views-plan-builders.d.ts.map +1 -1
  11. package/dist/src/core/database-materialized-views-plan-builders.js +347 -8
  12. package/dist/src/core/database-materialized-views-plan-builders.js.map +1 -1
  13. package/dist/src/core/database-materialized-views-plans.d.ts +254 -30
  14. package/dist/src/core/database-materialized-views-plans.d.ts.map +1 -1
  15. package/dist/src/core/database-materialized-views.d.ts +96 -40
  16. package/dist/src/core/database-materialized-views.d.ts.map +1 -1
  17. package/dist/src/core/database-materialized-views.js +172 -116
  18. package/dist/src/core/database-materialized-views.js.map +1 -1
  19. package/dist/src/core/database.d.ts.map +1 -1
  20. package/dist/src/core/database.js +20 -17
  21. package/dist/src/core/database.js.map +1 -1
  22. package/dist/src/func/builtins/aggregate.d.ts.map +1 -1
  23. package/dist/src/func/builtins/aggregate.js +127 -21
  24. package/dist/src/func/builtins/aggregate.js.map +1 -1
  25. package/dist/src/func/registration.d.ts +6 -1
  26. package/dist/src/func/registration.d.ts.map +1 -1
  27. package/dist/src/func/registration.js +16 -0
  28. package/dist/src/func/registration.js.map +1 -1
  29. package/dist/src/planner/analysis/equi-correlation.d.ts +26 -0
  30. package/dist/src/planner/analysis/equi-correlation.d.ts.map +1 -0
  31. package/dist/src/planner/analysis/equi-correlation.js +62 -0
  32. package/dist/src/planner/analysis/equi-correlation.js.map +1 -0
  33. package/dist/src/planner/analysis/query-rewrite-matcher.d.ts +54 -18
  34. package/dist/src/planner/analysis/query-rewrite-matcher.d.ts.map +1 -1
  35. package/dist/src/planner/analysis/query-rewrite-matcher.js +86 -42
  36. package/dist/src/planner/analysis/query-rewrite-matcher.js.map +1 -1
  37. package/dist/src/planner/analysis/scalar-subqueries.d.ts +28 -0
  38. package/dist/src/planner/analysis/scalar-subqueries.d.ts.map +1 -0
  39. package/dist/src/planner/analysis/scalar-subqueries.js +60 -0
  40. package/dist/src/planner/analysis/scalar-subqueries.js.map +1 -0
  41. package/dist/src/planner/building/select.d.ts.map +1 -1
  42. package/dist/src/planner/building/select.js +15 -1
  43. package/dist/src/planner/building/select.js.map +1 -1
  44. package/dist/src/planner/building/with.d.ts.map +1 -1
  45. package/dist/src/planner/building/with.js +5 -8
  46. package/dist/src/planner/building/with.js.map +1 -1
  47. package/dist/src/planner/cache/materialization-advisory.d.ts +33 -0
  48. package/dist/src/planner/cache/materialization-advisory.d.ts.map +1 -1
  49. package/dist/src/planner/cache/materialization-advisory.js +164 -28
  50. package/dist/src/planner/cache/materialization-advisory.js.map +1 -1
  51. package/dist/src/planner/cache/reference-graph.d.ts +0 -4
  52. package/dist/src/planner/cache/reference-graph.d.ts.map +1 -1
  53. package/dist/src/planner/cache/reference-graph.js +5 -13
  54. package/dist/src/planner/cache/reference-graph.js.map +1 -1
  55. package/dist/src/planner/cost/index.d.ts +28 -7
  56. package/dist/src/planner/cost/index.d.ts.map +1 -1
  57. package/dist/src/planner/cost/index.js +26 -0
  58. package/dist/src/planner/cost/index.js.map +1 -1
  59. package/dist/src/planner/nodes/cache-node.d.ts +18 -2
  60. package/dist/src/planner/nodes/cache-node.d.ts.map +1 -1
  61. package/dist/src/planner/nodes/cache-node.js +42 -3
  62. package/dist/src/planner/nodes/cache-node.js.map +1 -1
  63. package/dist/src/planner/nodes/cte-node.d.ts +15 -1
  64. package/dist/src/planner/nodes/cte-node.d.ts.map +1 -1
  65. package/dist/src/planner/nodes/cte-node.js +12 -2
  66. package/dist/src/planner/nodes/cte-node.js.map +1 -1
  67. package/dist/src/planner/nodes/recursive-cte-node.d.ts +30 -1
  68. package/dist/src/planner/nodes/recursive-cte-node.d.ts.map +1 -1
  69. package/dist/src/planner/nodes/recursive-cte-node.js +30 -3
  70. package/dist/src/planner/nodes/recursive-cte-node.js.map +1 -1
  71. package/dist/src/planner/optimizer.d.ts.map +1 -1
  72. package/dist/src/planner/optimizer.js +129 -1
  73. package/dist/src/planner/optimizer.js.map +1 -1
  74. package/dist/src/planner/rules/cache/rule-cte-optimization.d.ts.map +1 -1
  75. package/dist/src/planner/rules/cache/rule-cte-optimization.js +8 -1
  76. package/dist/src/planner/rules/cache/rule-cte-optimization.js.map +1 -1
  77. package/dist/src/planner/rules/cache/rule-in-subquery-cache.d.ts +7 -0
  78. package/dist/src/planner/rules/cache/rule-in-subquery-cache.d.ts.map +1 -1
  79. package/dist/src/planner/rules/cache/rule-in-subquery-cache.js +14 -1
  80. package/dist/src/planner/rules/cache/rule-in-subquery-cache.js.map +1 -1
  81. package/dist/src/planner/rules/cache/rule-materialized-view-rewrite.d.ts.map +1 -1
  82. package/dist/src/planner/rules/cache/rule-materialized-view-rewrite.js +53 -54
  83. package/dist/src/planner/rules/cache/rule-materialized-view-rewrite.js.map +1 -1
  84. package/dist/src/planner/rules/cache/rule-mutating-subquery-cache.d.ts.map +1 -1
  85. package/dist/src/planner/rules/cache/rule-mutating-subquery-cache.js +6 -0
  86. package/dist/src/planner/rules/cache/rule-mutating-subquery-cache.js.map +1 -1
  87. package/dist/src/planner/rules/cache/rule-nested-loop-right-cache.d.ts +25 -0
  88. package/dist/src/planner/rules/cache/rule-nested-loop-right-cache.d.ts.map +1 -0
  89. package/dist/src/planner/rules/cache/rule-nested-loop-right-cache.js +176 -0
  90. package/dist/src/planner/rules/cache/rule-nested-loop-right-cache.js.map +1 -0
  91. package/dist/src/planner/rules/cache/rule-scalar-subquery-cache.d.ts +29 -0
  92. package/dist/src/planner/rules/cache/rule-scalar-subquery-cache.d.ts.map +1 -0
  93. package/dist/src/planner/rules/cache/rule-scalar-subquery-cache.js +66 -0
  94. package/dist/src/planner/rules/cache/rule-scalar-subquery-cache.js.map +1 -0
  95. package/dist/src/planner/rules/join/rule-fanout-lookup-join.d.ts.map +1 -1
  96. package/dist/src/planner/rules/join/rule-fanout-lookup-join.js +1 -54
  97. package/dist/src/planner/rules/join/rule-fanout-lookup-join.js.map +1 -1
  98. package/dist/src/planner/rules/subquery/rule-scalar-agg-decorrelation.d.ts +191 -0
  99. package/dist/src/planner/rules/subquery/rule-scalar-agg-decorrelation.d.ts.map +1 -0
  100. package/dist/src/planner/rules/subquery/rule-scalar-agg-decorrelation.js +623 -0
  101. package/dist/src/planner/rules/subquery/rule-scalar-agg-decorrelation.js.map +1 -0
  102. package/dist/src/planner/rules/subquery/rule-subquery-decorrelation.d.ts +10 -1
  103. package/dist/src/planner/rules/subquery/rule-subquery-decorrelation.d.ts.map +1 -1
  104. package/dist/src/planner/rules/subquery/rule-subquery-decorrelation.js +242 -51
  105. package/dist/src/planner/rules/subquery/rule-subquery-decorrelation.js.map +1 -1
  106. package/dist/src/runtime/cache/shared-cache.d.ts +7 -0
  107. package/dist/src/runtime/cache/shared-cache.d.ts.map +1 -1
  108. package/dist/src/runtime/cache/shared-cache.js +34 -1
  109. package/dist/src/runtime/cache/shared-cache.js.map +1 -1
  110. package/dist/src/runtime/emit/aggregate.d.ts +2 -3
  111. package/dist/src/runtime/emit/aggregate.d.ts.map +1 -1
  112. package/dist/src/runtime/emit/aggregate.js +6 -15
  113. package/dist/src/runtime/emit/aggregate.js.map +1 -1
  114. package/dist/src/runtime/emit/cache.d.ts +7 -3
  115. package/dist/src/runtime/emit/cache.d.ts.map +1 -1
  116. package/dist/src/runtime/emit/cache.js +23 -6
  117. package/dist/src/runtime/emit/cache.js.map +1 -1
  118. package/dist/src/runtime/emit/cte.d.ts.map +1 -1
  119. package/dist/src/runtime/emit/cte.js +43 -20
  120. package/dist/src/runtime/emit/cte.js.map +1 -1
  121. package/dist/src/runtime/emit/dml-executor.d.ts.map +1 -1
  122. package/dist/src/runtime/emit/dml-executor.js +68 -43
  123. package/dist/src/runtime/emit/dml-executor.js.map +1 -1
  124. package/dist/src/runtime/emit/materialized-view-helpers.d.ts.map +1 -1
  125. package/dist/src/runtime/emit/materialized-view-helpers.js +5 -4
  126. package/dist/src/runtime/emit/materialized-view-helpers.js.map +1 -1
  127. package/dist/src/runtime/emit/recursive-cte.d.ts.map +1 -1
  128. package/dist/src/runtime/emit/recursive-cte.js +59 -1
  129. package/dist/src/runtime/emit/recursive-cte.js.map +1 -1
  130. package/dist/src/runtime/parallel-driver.d.ts +15 -1
  131. package/dist/src/runtime/parallel-driver.d.ts.map +1 -1
  132. package/dist/src/runtime/parallel-driver.js +17 -1
  133. package/dist/src/runtime/parallel-driver.js.map +1 -1
  134. package/dist/src/runtime/types.d.ts +36 -0
  135. package/dist/src/runtime/types.d.ts.map +1 -1
  136. package/dist/src/runtime/types.js.map +1 -1
  137. package/dist/src/schema/function.d.ts +79 -0
  138. package/dist/src/schema/function.d.ts.map +1 -1
  139. package/dist/src/schema/function.js.map +1 -1
  140. package/dist/src/vtab/memory/layer/scan-layer.js +21 -2
  141. package/dist/src/vtab/memory/layer/scan-layer.js.map +1 -1
  142. package/package.json +3 -3
@@ -0,0 +1,176 @@
1
+ /**
2
+ * Rule: Nested-Loop Right-Side Cache Injection
3
+ *
4
+ * Required Characteristics:
5
+ * - Node is a logical JoinNode that survived physical selection — i.e. a
6
+ * nested-loop join (equi-joins were already lowered to hash/merge, which
7
+ * materialize their build side on their own).
8
+ * - Join type is left-driven (`inner` / `left` / `cross` / `semi` / `anti`):
9
+ * the runtime re-opens the right pipeline once per left row
10
+ * (`emitLoopJoin.driveFromLeft`). `right` / `full` drive from the right and
11
+ * scan each side once, so caching their right side only wastes memory.
12
+ * - Right side is pure (no side effects — that is the mutating-subquery-cache
13
+ * rule's job), deterministic, uncorrelated, and small enough to materialize.
14
+ *
15
+ * Applied When:
16
+ * - A pure right side would otherwise be re-scanned N times, one full scan per
17
+ * left row. Wrapping it in a run-once CacheNode replays the buffer instead.
18
+ *
19
+ * Benefits: Turns N full right-side scans into one scan + N buffer replays —
20
+ * decisive on a high-per-read-latency vtab where each reopen costs I/O.
21
+ */
22
+ import { createLogger } from '../../../common/logger.js';
23
+ import { PlanNodeType } from '../../nodes/plan-node-type.js';
24
+ import { CacheNode } from '../../nodes/cache-node.js';
25
+ import { JoinNode } from '../../nodes/join-node.js';
26
+ import { TableAccessNode } from '../../nodes/table-access-nodes.js';
27
+ import { PlanNodeCharacteristics, CapabilityDetectors, CachingAnalysis } from '../../framework/characteristics.js';
28
+ import { isCorrelatedSubquery } from '../../cache/correlation-detector.js';
29
+ const log = createLogger('optimizer:rule:nested-loop-right-cache');
30
+ /**
31
+ * A CTE reference (NOT_MATERIALIZED CTEs re-emit an inlined sub-plan; recursive
32
+ * refs stream from a working table) manages its own row-context lifetime as it
33
+ * iterates. Eagerly materializing such a right side via a CacheNode drains and
34
+ * tears that context down before the join's ON-condition reads it, producing a
35
+ * runtime "no row context" error (and, for shared inlined scans, corrupting the
36
+ * outer loop's own context). Caching a CTE-backed right side is also low value:
37
+ * a materialized CTE is already a buffer, and a NOT_MATERIALIZED one re-scans
38
+ * cheap local state. So skip any right side whose subtree touches CTE machinery.
39
+ *
40
+ * NOTE: this is a CacheNode/CTEReference runtime-emit interaction, not a
41
+ * planner-only limitation — the sibling mutating-subquery-cache rule shares it
42
+ * but rarely fires on CTE right sides. See the ticket handoff for the follow-up.
43
+ */
44
+ const CTE_NODE_TYPES = new Set([
45
+ PlanNodeType.CTEReference,
46
+ PlanNodeType.CTE,
47
+ PlanNodeType.RecursiveCTE,
48
+ PlanNodeType.InternalRecursiveCTERef,
49
+ ]);
50
+ /** True iff `node` or any descendant is a CTE-machinery node (see above). */
51
+ function subtreeTouchesCte(node) {
52
+ const stack = [node];
53
+ while (stack.length > 0) {
54
+ const current = stack.pop();
55
+ if (CTE_NODE_TYPES.has(current.nodeType))
56
+ return true;
57
+ for (const child of current.getChildren()) {
58
+ stack.push(child);
59
+ }
60
+ }
61
+ return false;
62
+ }
63
+ /**
64
+ * Best available row estimate for the buffer the CacheNode would hold: the
65
+ * LARGEST estimate anywhere in the right subtree.
66
+ *
67
+ * We can't just read `right.physical.estimatedRows`. Two gaps make the top of
68
+ * the subtree read too low:
69
+ * - Pass-through nodes (e.g. AliasNode) don't propagate the physical estimate,
70
+ * so the subtree top can be `undefined` while the leaf underneath has it.
71
+ * - An access leaf's `physical.estimatedRows` is the *table* row count, but the
72
+ * module's own access-plan estimate (getBestAccessPlan `rows`, the true "how
73
+ * many rows will this scan hand back" — e.g. a high-latency vtab reporting
74
+ * 60000) lives only in `filterInfo.indexInfoOutput.estimatedRows`.
75
+ * Taking the subtree max over both signals is a conservative upper bound that
76
+ * keeps the memory gate sound (never under-counts a large source into a cache).
77
+ *
78
+ * NOTE: this over-estimates a large base scan that a selective Filter shrinks —
79
+ * output rows may be few, yet the max reflects the pre-filter scan. That biases
80
+ * toward NOT caching such a right side (a missed optimization, never a memory
81
+ * hazard). If a real workload wants those cached, propagate physical
82
+ * estimatedRows through the pass-through nodes and read the top estimate instead.
83
+ */
84
+ function estimateRightRows(node) {
85
+ let max;
86
+ const consider = (rows) => {
87
+ if (rows !== undefined && Number.isFinite(rows)) {
88
+ max = max === undefined ? rows : Math.max(max, rows);
89
+ }
90
+ };
91
+ const stack = [node];
92
+ while (stack.length > 0) {
93
+ const current = stack.pop();
94
+ consider(current.physical?.estimatedRows);
95
+ if (current instanceof TableAccessNode) {
96
+ consider(Number(current.filterInfo.indexInfoOutput.estimatedRows));
97
+ }
98
+ for (const child of current.getChildren()) {
99
+ stack.push(child);
100
+ }
101
+ }
102
+ return max;
103
+ }
104
+ export function ruleNestedLoopRightCache(node, context) {
105
+ // Only logical JoinNodes reach here uncached. By PostOptimization,
106
+ // join-physical-selection has already converted every equi-join it wanted to
107
+ // hash/merge (those materialize their build side), so any surviving logical
108
+ // JoinNode IS a nested loop — the exact structural signal we need.
109
+ if (!(node instanceof JoinNode)) {
110
+ return null;
111
+ }
112
+ // Driver gate: only the left-driven join types re-scan the right side.
113
+ // `right` / `full` buffer the left side once and scan the right side once
114
+ // (`emitLoopJoin.driveFromRight`), so caching their right side is pure waste.
115
+ // NOTE: inner/left/cross fully drain the right per left row, so the run-once
116
+ // cache (streamWithCache only retains its buffer once a consumer drains the
117
+ // source to completion — see shared-cache.ts) fills on the first left row and
118
+ // replays thereafter. Semi/anti `break` on the first match (emitLoopJoin
119
+ // driveFromLeft), so a matched left row abandons the partial buffer and the
120
+ // next row re-scans; their buffer only lands after the first *unmatched* left
121
+ // row drains the right in full. Caching them is still never a regression
122
+ // (same reopen count until the buffer fills, a win after), just data-dependent
123
+ // rather than the guaranteed replay inner/cross/left get.
124
+ if (node.joinType === 'right' || node.joinType === 'full') {
125
+ return null;
126
+ }
127
+ const right = node.right;
128
+ // Already cached (e.g. by cte / in-subquery / mutating-subquery cache).
129
+ if (CapabilityDetectors.isCached(right) && right.isCached()) {
130
+ return null;
131
+ }
132
+ // Purity gate: side effects are the mutating-subquery-cache rule's job.
133
+ // Double-wrapping a write would change nothing and only burn memory.
134
+ if (PlanNodeCharacteristics.subtreeHasSideEffects(right)) {
135
+ return null;
136
+ }
137
+ // Determinism gate: a non-deterministic right side (e.g. `random()`) must be
138
+ // re-evaluated per left row to preserve today's observable behavior; caching
139
+ // would freeze the first scan's values across every subsequent left row.
140
+ if (!PlanNodeCharacteristics.isDeterministic(right)) {
141
+ return null;
142
+ }
143
+ // Correlation gate: a right subtree that references left attributes (a
144
+ // parameterized/lateral seek produced by predicate pushdown) is
145
+ // re-parameterized per left row and MUST NOT be cached. Note the plain
146
+ // `a JOIN b ON a.x > b.y` case is *uncorrelated*: the ON predicate is a
147
+ // separate JoinNode.condition child, not inside the right subtree — so the
148
+ // bare right access has no external refs and is cacheable.
149
+ if (isCorrelatedSubquery(right)) {
150
+ return null;
151
+ }
152
+ // CTE-safety gate: eagerly materializing a CTE-backed right side breaks the
153
+ // join's row-context at runtime (see subtreeTouchesCte above).
154
+ if (subtreeTouchesCte(right)) {
155
+ return null;
156
+ }
157
+ // Size gate (memory safety): materializing an unbounded right side trades I/O
158
+ // for memory. Respect the existing nested-loop caching threshold.
159
+ const estimatedRows = estimateRightRows(right) ?? context.tuning.defaultRowEstimate;
160
+ if (estimatedRows > context.tuning.join.maxRightRowsForCaching) {
161
+ log('Right side too large to cache (%d rows > %d), skipping', estimatedRows, context.tuning.join.maxRightRowsForCaching);
162
+ return null;
163
+ }
164
+ log('Caching pure nested-loop right side (%s, %d rows)', node.joinType, estimatedRows);
165
+ // Memory strategy + a CacheNode threshold (which degrades to pass-through
166
+ // past its limit) mirrors the sibling mutating-subquery-cache rule. Spill is
167
+ // unreachable under the size gate above (maxRightRowsForCaching <
168
+ // cache.spillThreshold), so 'memory' is the only live choice here.
169
+ const threshold = CachingAnalysis.getCacheThreshold(right);
170
+ const cached = new CacheNode(right.scope, right, 'memory', threshold);
171
+ // Reconstruct via withChildren, NOT the raw JoinNode constructor: withChildren
172
+ // threads usingColumns AND existence through verbatim, so existence match-flag
173
+ // columns survive the rebuild (the manual constructor drops `existence`).
174
+ return node.withChildren(node.condition ? [node.left, cached, node.condition] : [node.left, cached]);
175
+ }
176
+ //# sourceMappingURL=rule-nested-loop-right-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rule-nested-loop-right-cache.js","sourceRoot":"","sources":["../../../../../src/planner/rules/cache/rule-nested-loop-right-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,OAAO,EAAE,SAAS,EAAE,MA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C,KAAK,CAAC,CAAC;IAC3D,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;IAEtE,+EAA+E;IAC/E,+EAA+E;IAC/E,0EAA0E;IAC1E,OAAO,IAAI,CAAC,YAAY,CACvB,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAC1E,CAAC;AACH,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Rule: Scalar-Subquery Cache
3
+ *
4
+ * Required Characteristics:
5
+ * - Node must be a ScalarSubqueryNode
6
+ * - Inner subquery must be uncorrelated (no outer attribute references)
7
+ * - Inner subquery must be deterministic and read-only (functional)
8
+ * - Inner subquery must not already be cached
9
+ *
10
+ * Applied When:
11
+ * - A scalar subquery embedded in a WHERE / projection / ORDER BY / HAVING
12
+ * expression would re-execute its full pipeline for every outer row.
13
+ *
14
+ * Benefits: Materializes the inner result once and replays from cache on
15
+ * subsequent evaluations, reducing O(N) inner scans to O(1) per execution.
16
+ *
17
+ * EAGER vs. NON-EAGER — this rule uses NON-eager, the key contrast with
18
+ * `rule-in-subquery-cache`. `ruleInSubqueryCache` needs eager mode because
19
+ * `emitIn`'s pure consumer returns on the first matching row, which would abort
20
+ * a streaming cache build mid-drain and leave it uncommitted. `emitScalarSubquery`
21
+ * has NO such short-circuit: it iterates the entire input on every evaluation
22
+ * (it must read every row to detect the ">1 row" error). So a streaming
23
+ * (non-eager) CacheNode is fully drained and committed on the first evaluation,
24
+ * and subsequent evaluations replay from the buffer. Do NOT "fix" this to eager.
25
+ */
26
+ import type { PlanNode } from '../../nodes/plan-node.js';
27
+ import type { OptContext } from '../../framework/context.js';
28
+ export declare function ruleScalarSubqueryCache(node: PlanNode, context: OptContext): PlanNode | null;
29
+ //# sourceMappingURL=rule-scalar-subquery-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rule-scalar-subquery-cache.d.ts","sourceRoot":"","sources":["../../../../../src/planner/rules/cache/rule-scalar-subquery-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAS7D,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,GAAG,QAAQ,GAAG,IAAI,CAiD5F"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Rule: Scalar-Subquery Cache
3
+ *
4
+ * Required Characteristics:
5
+ * - Node must be a ScalarSubqueryNode
6
+ * - Inner subquery must be uncorrelated (no outer attribute references)
7
+ * - Inner subquery must be deterministic and read-only (functional)
8
+ * - Inner subquery must not already be cached
9
+ *
10
+ * Applied When:
11
+ * - A scalar subquery embedded in a WHERE / projection / ORDER BY / HAVING
12
+ * expression would re-execute its full pipeline for every outer row.
13
+ *
14
+ * Benefits: Materializes the inner result once and replays from cache on
15
+ * subsequent evaluations, reducing O(N) inner scans to O(1) per execution.
16
+ *
17
+ * EAGER vs. NON-EAGER — this rule uses NON-eager, the key contrast with
18
+ * `rule-in-subquery-cache`. `ruleInSubqueryCache` needs eager mode because
19
+ * `emitIn`'s pure consumer returns on the first matching row, which would abort
20
+ * a streaming cache build mid-drain and leave it uncommitted. `emitScalarSubquery`
21
+ * has NO such short-circuit: it iterates the entire input on every evaluation
22
+ * (it must read every row to detect the ">1 row" error). So a streaming
23
+ * (non-eager) CacheNode is fully drained and committed on the first evaluation,
24
+ * and subsequent evaluations replay from the buffer. Do NOT "fix" this to eager.
25
+ */
26
+ import { createLogger } from '../../../common/logger.js';
27
+ import { CacheNode } from '../../nodes/cache-node.js';
28
+ import { CapabilityDetectors, CachingAnalysis, PlanNodeCharacteristics } from '../../framework/characteristics.js';
29
+ import { isCorrelatedSubquery } from '../../cache/correlation-detector.js';
30
+ import { PlanNodeType } from '../../nodes/plan-node-type.js';
31
+ const log = createLogger('optimizer:rule:scalar-subquery-cache');
32
+ export function ruleScalarSubqueryCache(node, context) {
33
+ // Guard: must be a ScalarSubqueryNode
34
+ if (node.nodeType !== PlanNodeType.ScalarSubquery) {
35
+ return null;
36
+ }
37
+ const scalarNode = node;
38
+ const inner = scalarNode.subquery;
39
+ // Gate: inner must not already be cached (idempotent under the fixpoint pass)
40
+ if (CapabilityDetectors.isCached(inner) && inner.isCached()) {
41
+ log('scalar-subquery inner already cached, skipping');
42
+ return null;
43
+ }
44
+ // Gate: inner must be uncorrelated. A correlated inner's result depends on
45
+ // the outer row and must NOT be cached.
46
+ if (isCorrelatedSubquery(inner)) {
47
+ log('scalar-subquery is correlated, skipping cache wrapping');
48
+ return null;
49
+ }
50
+ // Gate: inner must be deterministic and read-only. This also excludes the
51
+ // impure DML-bearing inner, which keeps its run-once memo in emitScalarSubquery.
52
+ if (!PlanNodeCharacteristics.isFunctional(inner)) {
53
+ log('scalar-subquery inner is not functional, skipping cache wrapping');
54
+ return null;
55
+ }
56
+ log('Wrapping uncorrelated scalar-subquery inner in CacheNode');
57
+ const cacheThreshold = Math.min(CachingAnalysis.getCacheThreshold(inner), context.tuning.cte.maxCacheThreshold);
58
+ // Non-eager (streaming): the scalar consumer drains the whole input on the
59
+ // first evaluation, committing the buffer, so later evaluations replay. See
60
+ // the eager-vs-non-eager note in the module header.
61
+ const cachedInner = new CacheNode(inner.scope, inner, 'memory', cacheThreshold, false // non-eager: scalar consumer already fully drains on first eval
62
+ );
63
+ // Rebuild via withChildren so future constructor fields can't be dropped.
64
+ return scalarNode.withChildren([cachedInner]);
65
+ }
66
+ //# sourceMappingURL=rule-scalar-subquery-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rule-scal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AC;IAED,GAAG,CAAC,0DAA0D,CAAC,CAAC;IAEhE,MAAM,cAAc,GAAG,IAAI,CAAC,GAAG,CAC9B,eAAe,CAAC,iBAAiB,CAAC,KAAK,CAAC,EACxC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,iBAAiB,CACpC,CAAC;IAEF,2EAA2E;IAC3E,4EAA4E;IAC5E,oDAAoD;IACpD,MAAM,WAAW,GAAG,IAAI,SAAS,CAChC,KAAK,CAAC,KAAK,EACX,KAAK,EACL,QAAQ,EACR,cAAc,EACd,KAAK,CAAE,gEAAgE;KACvE,CAAC;IAEF,0EAA0E;IAC1E,OAAO,UAAU,CAAC,YAAY,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC;AAC/C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"rule-fanout-lookup-join.d.ts","sourceRoot":"","sources":["../../../../../src/planner/rules/join/rule-fanout-lookup-join.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAGN,KAAK,QAAQ,EAGb,MAAM,0BAA0B,CAAC;AA4DlC,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,GAAG,QAAQ,GAAG,IAAI,CA4OzF"}
1
+ {"version":3,"file":"rule-fanout-lookup-join.d.ts","sourceRoot":"","sources":["../../../../../src/planner/rules/join/rule-fanout-lookup-join.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAGN,KAAK,QAAQ,EAGb,MAAM,0BAA0B,CAAC;AA6DlC,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,GAAG,QAAQ,GAAG,IAAI,CA4OzF"}
@@ -61,12 +61,12 @@ import { LimitOffsetNode } from '../../nodes/limit-offset.js';
61
61
  import { DistinctNode } from '../../nodes/distinct-node.js';
62
62
  import { AliasNode } from '../../nodes/alias-node.js';
63
63
  import { JoinNode, extractEquiPairsFromCondition } from '../../nodes/join-node.js';
64
- import { ScalarSubqueryNode } from '../../nodes/subquery.js';
65
64
  import { ColumnReferenceNode } from '../../nodes/reference.js';
66
65
  import { normalizePredicate } from '../../analysis/predicate-normalizer.js';
67
66
  import { checkFkPkAlignment, extractTableSchema } from '../../util/key-utils.js';
68
67
  import { lookupCoveringFK, isRowPreservingPathToTable } from '../../util/ind-utils.js';
69
68
  import { collectExternalReferences } from '../../cache/correlation-detector.js';
69
+ import { collectScalarSubqueries, substituteSubqueries } from '../../analysis/scalar-subqueries.js';
70
70
  import { CapabilityDetectors, PlanNodeCharacteristics } from '../../framework/characteristics.js';
71
71
  import { isAndOfColumnEqualities } from './rule-join-elimination.js';
72
72
  import { FanOutLookupJoinNode, isCrossBranchMode, isLeftBranchMode } from '../../nodes/fanout-lookup-join-node.js';
@@ -298,59 +298,6 @@ export function ruleFanOutLookupJoin(node, context) {
298
298
  function columnExprFor(name) {
299
299
  return { type: 'column', name };
300
300
  }
301
- /**
302
- * Collect every `ScalarSubqueryNode` reachable in a projection's scalar
303
- * expression tree, in deterministic pre-order. A recognized subquery is a leaf
304
- * for this walk: we push it and do NOT descend into its relational body, so a
305
- * subquery nested *inside* another subquery's correlation predicate remains part
306
- * of its enclosing branch child rather than being clustered as its own branch.
307
- * (The relational body is filtered out by the `typeClass === 'scalar'` guard
308
- * regardless, but stopping early keeps the intent explicit.)
309
- */
310
- function collectScalarSubqueries(expr, out) {
311
- if (expr instanceof ScalarSubqueryNode) {
312
- out.push(expr);
313
- return;
314
- }
315
- for (const child of expr.getChildren()) {
316
- if (child.getType().typeClass === 'scalar') {
317
- collectScalarSubqueries(child, out);
318
- }
319
- }
320
- }
321
- /**
322
- * Rebuild a projection's scalar expression with each recognized
323
- * `ScalarSubqueryNode` replaced by its `ColumnReferenceNode` into the fan-out's
324
- * wide row, leaving the wrapping expression (`coalesce(<colref>, 0)`) intact.
325
- * For a bare-subquery projection the root itself is in the map and is returned
326
- * directly; for a wrapped subquery the tree is rebuilt via `withChildren` with
327
- * only the matched inner node substituted. Returns the input unchanged when no
328
- * descendant is a recognized subquery.
329
- */
330
- function substituteSubqueries(expr, replacements) {
331
- if (expr instanceof ScalarSubqueryNode) {
332
- return replacements.get(expr) ?? expr;
333
- }
334
- const children = expr.getChildren();
335
- if (children.length === 0)
336
- return expr;
337
- const newChildren = [];
338
- let changed = false;
339
- for (const child of children) {
340
- if (child.getType().typeClass === 'scalar') {
341
- const replaced = substituteSubqueries(child, replacements);
342
- newChildren.push(replaced);
343
- if (replaced !== child)
344
- changed = true;
345
- }
346
- else {
347
- newChildren.push(child);
348
- }
349
- }
350
- if (!changed)
351
- return expr;
352
- return expr.withChildren(newChildren);
353
- }
354
301
  /**
355
302
  * Recognize a correlated scalar-aggregate subquery as an `atMostOne-left`
356
303
  * fan-out branch. Returns null when the subquery is not correlated, correlates
@@ -1 +1 @@
1
- {"version":3,"file":"rule-fanout-lookup-join.js","sourceRoot":"","sources":["../../../../../src/planner/rules/join/rule-fanout-lookup-join.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EACN,gBAAgB,GAKhB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM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@
1
+ /**
2
+ * Rule: Scalar-Aggregate Subquery Decorrelation
3
+ *
4
+ * Rewrites a correlated scalar-aggregate subquery in a SELECT projection into a
5
+ * grouped LEFT JOIN, so the inner table is scanned/aggregated ONCE instead of
6
+ * once per outer row:
7
+ *
8
+ * Project[..., ScalarSubquery(Agg(Filter(corr ∧ rest, inner))) ...](outer)
9
+ * becomes
10
+ * Project[..., <guarded value read> ...]
11
+ * LeftJoin[corr] -- outer.a = inner.k, verbatim
12
+ * outer
13
+ * Aggregate(groupBy=[inner.k...], aggregates=[orig agg])
14
+ * Filter(rest, inner) -- residual inner-only predicates
15
+ *
16
+ * In SQL terms: `(select agg(x) from c where c.fk = o.k)` →
17
+ * `left join (select fk, agg(x) as val from c group by fk) g on g.fk = o.k`.
18
+ *
19
+ * The grouped aggregate PRESERVES the inner correlation attribute ids as its
20
+ * group-by output attribute ids (the same id-preservation ProjectNode applies
21
+ * to bare column-reference projections), so the original correlation conjuncts
22
+ * serve verbatim as the join condition and hash-join equi-pair extraction sees
23
+ * plain `colref = colref` pairs.
24
+ *
25
+ * Empty-group semantics ("the count bug"): a scalar aggregate over zero rows
26
+ * still yields one row (`count(*)` → 0, `sum(x)` → NULL), but the grouped join
27
+ * produces NO group for an outer row with no matches. The aggregate's
28
+ * empty-input value is computed at plan time via the exact runtime path
29
+ * (`finalizeFunction(cloneInitialValue(initialValue))`):
30
+ * - empty value NULL (sum/min/max/avg/json_group_array/…): the join miss
31
+ * already yields NULL — the replacement is a bare column reference;
32
+ * - otherwise (count/total): the replacement is
33
+ * `CASE WHEN <group key> IS NULL THEN <empty literal> ELSE <value> END`.
34
+ * A matched row always has a non-NULL group key (the equality matched), and
35
+ * an inner group with a NULL key can never match any outer row, so
36
+ * `key IS NULL` holds exactly on join misses — a separate `1 AS __present`
37
+ * marker column is unnecessary. This is a marker, not `coalesce(...)`, so
38
+ * an aggregate legitimately returning NULL on non-empty input stays NULL.
39
+ *
40
+ * Outer references OUTSIDE the correlation conjuncts (e.g. in aggregate
41
+ * arguments: `json_object('entryId', e.id, …)`) are remapped to the inner
42
+ * column they are equated with — justified by the equality predicate — but only
43
+ * when the equality is value-faithful (value-discriminating collation AND same
44
+ * logical type); otherwise the rule bails and the subquery stays correlated.
45
+ *
46
+ * Bail (leave the subquery correlated) when:
47
+ * - the subquery is uncorrelated, or correlates beyond the immediate outer;
48
+ * - the inner subtree carries a side effect (per-row firing is observable);
49
+ * - the subquery root is not a bare zero-group single-aggregate beneath
50
+ * bare pass-through Project/Alias wrappers (a Sort/LimitOffset wrapper, a
51
+ * GROUP BY, a composite expression over aggregates, or a non-aggregate
52
+ * `... limit 1` shape all keep today's behavior, including the >1-row
53
+ * scalar-subquery runtime error);
54
+ * - the aggregate's source is not a Filter whose predicate splits into
55
+ * `outer.col = inner.col` equi-conjuncts plus inner-only residuals
56
+ * (non-equi correlation such as `inner.ts < outer.ts` bails);
57
+ * - the aggregate's empty-input value cannot be folded to a plan-time
58
+ * literal (finalize throws, is async, non-deterministic, or yields a
59
+ * non-primitive);
60
+ * - an outer reference outside the conjuncts is not value-faithfully
61
+ * remappable.
62
+ *
63
+ * Registered unconditionally (no cost gate) after `fanout-lookup-join`, so the
64
+ * remote-latency fan-out path keeps first claim on the branches it is tuned
65
+ * for; the tiny-outer/huge-inner cost tradeoff is tracked in
66
+ * `backlog/feat-decorrelation-cost-model`.
67
+ *
68
+ * FOUR MATCH SITES share the identical per-subquery rewrite (`decorrelateOne`):
69
+ * - `ruleScalarAggDecorrelation` — subqueries in a ProjectNode's projection
70
+ * expressions; the join stack lands between the Project and its source.
71
+ * - `ruleScalarAggDecorrelationAggregate` — subqueries inside an
72
+ * AggregateNode's aggregate-argument (and group-by) expressions; the join
73
+ * stack lands BELOW the aggregate, between it and its source. Cardinality
74
+ * safety: the grouped subtree's GROUP BY keys are a unique key on its
75
+ * output, so the LEFT join matches at most one row per source row — the
76
+ * aggregate's input row count and multiplicity are preserved exactly, and
77
+ * every existing group-by/aggregate reference resolves unchanged by
78
+ * attribute id (left-side attributes stay visible through the join).
79
+ * - `ruleScalarAggDecorrelationFilter` — subqueries anywhere in a FilterNode's
80
+ * predicate (WHERE, and HAVING — a HAVING clause plans as a FilterNode whose
81
+ * source is an AggregateNode); the join stack lands between the Filter and
82
+ * its source, and the subquery reference in the predicate is substituted with
83
+ * the guarded value read. A FilterNode publishes its source's attributes
84
+ * verbatim, so the LEFT join's appended grouped-aggregate columns would leak
85
+ * to whatever consumes the filter — and a HAVING filter is frequently the
86
+ * query's output node itself (the SELECT projection is fused into the
87
+ * Aggregate below it, leaving no capping Project). The rule therefore caps its
88
+ * own result with a bare pass-through Project that re-exposes exactly the
89
+ * Filter's original attributes; the outer columns keep their original indices
90
+ * (the LEFT join places the outer on the left), so that projection's column
91
+ * references — and everything above — resolve unchanged.
92
+ * - `ruleScalarAggDecorrelationSort` — subqueries in a SortNode's sort-key
93
+ * expressions (`order by (select count(*) from c where c.fk = o.k)`); the
94
+ * join stack lands BELOW the Sort so the sort key can read the grouped
95
+ * value column. A SortNode publishes its source's attributes VERBATIM (it
96
+ * never consumes/hides columns the way a Project does), so the LEFT join's
97
+ * appended grouped-aggregate columns would otherwise leak upward and change
98
+ * the row shape every ancestor (a capping Project, a view body, a compound
99
+ * arm, LIMIT/OFFSET) sees. Like the Filter site, the rule caps its result
100
+ * with the same bare pass-through Project (`capToAttributes`) that
101
+ * re-exposes exactly the Sort's original attributes; the outer columns keep
102
+ * their original indices (the LEFT join places the outer on the left), so
103
+ * that projection — and everything above — resolves unchanged.
104
+ *
105
+ * SCOPE: like every site, `decorrelateOne` requires the correlation columns
106
+ * to be attributes of the Sort's OWN source. That holds for identity
107
+ * projections (`select o.* … order by (select … where c.fk = o.k)`) and
108
+ * for any query that also selects the correlation column. When the SELECT
109
+ * list projects the correlation column AWAY (`select o.id from o order by
110
+ * (select … where c.fk = o.k)`), the Sort sits above a stripping Project
111
+ * whose output no longer carries `o.k`, so the rule BAILS and the subquery
112
+ * stays correlated — still correct, because the runtime resolves `o.k` from
113
+ * the still-live base-scan row context below the Project; it is merely not
114
+ * decorrelated. Threading the grouped value column up through a stripping
115
+ * Project is tracked in
116
+ * `backlog/feat-decorrelate-order-by-subquery-nonselected-column`.
117
+ *
118
+ * NESTED subqueries converge level by level: the Structural pass is top-down
119
+ * with rules firing BEFORE descent, so the grouped aggregate built by one
120
+ * level's rewrite (whose aggregate argument carries the next level's subquery,
121
+ * outer references already remapped to the enclosing inner columns) is itself
122
+ * visited later in the same pass, where the Aggregate-site rule fires on it.
123
+ */
124
+ import type { PlanNode } from '../../nodes/plan-node.js';
125
+ import type { OptContext } from '../../framework/context.js';
126
+ export declare function ruleScalarAggDecorrelation(node: PlanNode, _context: OptContext): PlanNode | null;
127
+ /**
128
+ * Aggregate-argument match site: the same rewrite for subqueries embedded in
129
+ * an AggregateNode's aggregate-argument (or group-by) expressions — the shape
130
+ * a nested aggregate subquery takes after the Project-site rewrite of its
131
+ * enclosing level (the enclosing rewrite's outer-reference remap makes a
132
+ * two-level correlation local to the new grouped aggregate's source). The join
133
+ * stack lands below the aggregate; see the module header for cardinality
134
+ * safety and multi-level convergence.
135
+ *
136
+ * NOTE: this site can also fire on an aggregate INSIDE a still-correlated
137
+ * subquery (e.g. when the enclosing level's remap bailed but the nested
138
+ * correlation is local). That is correct but the grouped subtree then
139
+ * re-executes per outer row — whether it beats the per-inner-row correlated
140
+ * plan is data-dependent; if a workload regresses here, gate this site on the
141
+ * enclosing subtree being decorrelated (part of
142
+ * `backlog/feat-decorrelation-cost-model`).
143
+ */
144
+ export declare function ruleScalarAggDecorrelationAggregate(node: PlanNode, _context: OptContext): PlanNode | null;
145
+ /**
146
+ * Filter match site (WHERE and HAVING): the same rewrite for a correlated
147
+ * scalar-aggregate subquery used anywhere in a FilterNode's predicate —
148
+ * `where o.total > (select avg(c.amount) from c where c.fk = o.k)`. The join
149
+ * stack lands between the Filter and its source, and the subquery reference in
150
+ * the predicate is substituted with the guarded value read; the result is
151
+ * `Filter[pred'](LeftJoin(outer, groupedAgg))`.
152
+ *
153
+ * HAVING needs no special-casing: `... group by o.k having sum(o.v) > (select …)`
154
+ * plans as a FilterNode whose source is an AggregateNode, so the aggregate's
155
+ * group-key / aggregate-result attributes are exactly the outer attributes the
156
+ * subquery correlates to — `decorrelateAll` treats the AggregateNode as the outer
157
+ * like any other relation.
158
+ *
159
+ * The LEFT join is load-bearing (an outer row with no inner match survives
160
+ * carrying the aggregate's empty-input value, which the replacement reproduces
161
+ * byte-for-byte), so three-valued predicate logic is preserved with no new code.
162
+ *
163
+ * The rewritten Filter's source gains the grouped join's columns; a FilterNode
164
+ * publishes its source's attributes verbatim, so the result is capped with a bare
165
+ * pass-through Project (see `capToAttributes`) that re-exposes exactly the
166
+ * original Filter attributes — without it the extra columns leak to the query
167
+ * output whenever the Filter is not already under a projection (the common HAVING
168
+ * shape, where the SELECT list is fused into the Aggregate below the filter).
169
+ */
170
+ export declare function ruleScalarAggDecorrelationFilter(node: PlanNode, _context: OptContext): PlanNode | null;
171
+ /**
172
+ * Sort match site: a correlated scalar-aggregate subquery in a SortNode's
173
+ * sort-key expression — `order by (select count(*) from c where c.fk = o.k)`.
174
+ * The join stack lands BELOW the Sort (so the sort key can read the grouped
175
+ * value column), and each recognized subquery reference in the keys is
176
+ * substituted with the guarded value read; direction/nulls are copied verbatim.
177
+ *
178
+ * A SortNode publishes its source's attributes verbatim, so the LEFT join's
179
+ * appended columns would leak upward and change the row shape every ancestor
180
+ * sees. The result is therefore capped with the same bare pass-through Project
181
+ * as the Filter site (`capToAttributes`), re-exposing exactly the Sort's
182
+ * original attributes — invariant output shape regardless of whether an
183
+ * enclosing Project exists (view body / compound arm / bare top-level Sort).
184
+ *
185
+ * Ordering is stable: the substituted value is byte-identical to the scalar the
186
+ * subquery would return (same empty-input replacement as the other sites), and
187
+ * the LEFT join matches at most one row per outer row (unique group keys), so
188
+ * row count, multiplicity, and per-row sort-key values are all unchanged.
189
+ */
190
+ export declare function ruleScalarAggDecorrelationSort(node: PlanNode, _context: OptContext): PlanNode | null;
191
+ //# sourceMappingURL=rule-scalar-agg-decorrelation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rule-scalar-agg-decorrelation.d.ts","sourceRoot":"","sources":["../../../../../src/planner/rules/subquery/rule-scalar-agg-decorrelation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0HG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAiD,MAAM,0BAA0B,CAAC;AAExG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAgC7D,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,GAAG,QAAQ,GAAG,IAAI,CAahG;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mCAAmC,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,GAAG,QAAQ,GAAG,IAAI,CAgBzG;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,gCAAgC,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,GAAG,QAAQ,GAAG,IAAI,CAoBtG;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,GAAG,QAAQ,GAAG,IAAI,CA0BpG"}