@quereus/quereus 4.16.0 → 4.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/core/database-auto-analyze.d.ts +258 -0
- package/dist/src/core/database-auto-analyze.d.ts.map +1 -0
- package/dist/src/core/database-auto-analyze.js +616 -0
- package/dist/src/core/database-auto-analyze.js.map +1 -0
- package/dist/src/core/database-materialized-views.d.ts +42 -1
- package/dist/src/core/database-materialized-views.d.ts.map +1 -1
- package/dist/src/core/database-materialized-views.js +76 -3
- package/dist/src/core/database-materialized-views.js.map +1 -1
- package/dist/src/core/database-transaction.d.ts +17 -0
- package/dist/src/core/database-transaction.d.ts.map +1 -1
- package/dist/src/core/database-transaction.js +37 -0
- package/dist/src/core/database-transaction.js.map +1 -1
- package/dist/src/core/database.d.ts +8 -1
- package/dist/src/core/database.d.ts.map +1 -1
- package/dist/src/core/database.js +135 -5
- package/dist/src/core/database.js.map +1 -1
- package/dist/src/planner/analysis/change-scope.d.ts.map +1 -1
- package/dist/src/planner/analysis/change-scope.js +8 -8
- package/dist/src/planner/analysis/change-scope.js.map +1 -1
- package/dist/src/planner/analysis/constraint-extractor.d.ts.map +1 -1
- package/dist/src/planner/analysis/constraint-extractor.js +27 -14
- package/dist/src/planner/analysis/constraint-extractor.js.map +1 -1
- package/dist/src/planner/analysis/expression-fingerprint.d.ts.map +1 -1
- package/dist/src/planner/analysis/expression-fingerprint.js +23 -2
- package/dist/src/planner/analysis/expression-fingerprint.js.map +1 -1
- package/dist/src/planner/analysis/mv-body-functions.d.ts +46 -0
- package/dist/src/planner/analysis/mv-body-functions.d.ts.map +1 -0
- package/dist/src/planner/analysis/mv-body-functions.js +65 -0
- package/dist/src/planner/analysis/mv-body-functions.js.map +1 -0
- package/dist/src/planner/analysis/predicate-shape.d.ts +32 -4
- package/dist/src/planner/analysis/predicate-shape.d.ts.map +1 -1
- package/dist/src/planner/analysis/predicate-shape.js +37 -5
- package/dist/src/planner/analysis/predicate-shape.js.map +1 -1
- package/dist/src/planner/analysis/query-rewrite-matcher.d.ts +2 -2
- package/dist/src/planner/analysis/query-rewrite-matcher.d.ts.map +1 -1
- package/dist/src/planner/analysis/query-rewrite-matcher.js +46 -6
- package/dist/src/planner/analysis/query-rewrite-matcher.js.map +1 -1
- package/dist/src/planner/analysis/sat-checker.js +2 -5
- package/dist/src/planner/analysis/sat-checker.js.map +1 -1
- package/dist/src/planner/building/select-aggregates.d.ts +17 -5
- package/dist/src/planner/building/select-aggregates.d.ts.map +1 -1
- package/dist/src/planner/building/select-aggregates.js +122 -79
- package/dist/src/planner/building/select-aggregates.js.map +1 -1
- package/dist/src/planner/building/select-modifiers.d.ts +1 -1
- package/dist/src/planner/building/select.d.ts.map +1 -1
- package/dist/src/planner/building/select.js +73 -55
- package/dist/src/planner/building/select.js.map +1 -1
- package/dist/src/planner/cost/index.d.ts +28 -0
- package/dist/src/planner/cost/index.d.ts.map +1 -1
- package/dist/src/planner/cost/index.js +33 -0
- package/dist/src/planner/cost/index.js.map +1 -1
- package/dist/src/planner/nodes/limit-offset.d.ts.map +1 -1
- package/dist/src/planner/nodes/limit-offset.js +3 -2
- package/dist/src/planner/nodes/limit-offset.js.map +1 -1
- package/dist/src/planner/optimizer-tuning.d.ts +10 -6
- package/dist/src/planner/optimizer-tuning.d.ts.map +1 -1
- package/dist/src/planner/optimizer-tuning.js.map +1 -1
- package/dist/src/planner/optimizer.d.ts.map +1 -1
- package/dist/src/planner/optimizer.js +49 -0
- package/dist/src/planner/optimizer.js.map +1 -1
- package/dist/src/planner/rules/access/rule-monotonic-range-access.d.ts.map +1 -1
- package/dist/src/planner/rules/access/rule-monotonic-range-access.js +8 -4
- package/dist/src/planner/rules/access/rule-monotonic-range-access.js.map +1 -1
- package/dist/src/planner/rules/access/rule-select-access-path.d.ts +14 -0
- package/dist/src/planner/rules/access/rule-select-access-path.d.ts.map +1 -1
- package/dist/src/planner/rules/access/rule-select-access-path.js +5 -1
- package/dist/src/planner/rules/access/rule-select-access-path.js.map +1 -1
- package/dist/src/planner/rules/aggregate/rule-groupby-fd-simplification.d.ts +3 -1
- package/dist/src/planner/rules/aggregate/rule-groupby-fd-simplification.d.ts.map +1 -1
- package/dist/src/planner/rules/aggregate/rule-groupby-fd-simplification.js +8 -3
- package/dist/src/planner/rules/aggregate/rule-groupby-fd-simplification.js.map +1 -1
- package/dist/src/planner/rules/aggregate/rule-minmax-index-boundary.d.ts +47 -0
- package/dist/src/planner/rules/aggregate/rule-minmax-index-boundary.d.ts.map +1 -0
- package/dist/src/planner/rules/aggregate/rule-minmax-index-boundary.js +200 -0
- package/dist/src/planner/rules/aggregate/rule-minmax-index-boundary.js.map +1 -0
- package/dist/src/planner/rules/cache/rule-nested-loop-right-cache.d.ts +29 -0
- package/dist/src/planner/rules/cache/rule-nested-loop-right-cache.d.ts.map +1 -1
- package/dist/src/planner/rules/cache/rule-nested-loop-right-cache.js +55 -16
- package/dist/src/planner/rules/cache/rule-nested-loop-right-cache.js.map +1 -1
- package/dist/src/planner/rules/join/index-nested-loop.d.ts +96 -22
- package/dist/src/planner/rules/join/index-nested-loop.d.ts.map +1 -1
- package/dist/src/planner/rules/join/index-nested-loop.js +401 -82
- package/dist/src/planner/rules/join/index-nested-loop.js.map +1 -1
- package/dist/src/planner/rules/join/rule-fanout-batched-outer.d.ts +20 -0
- package/dist/src/planner/rules/join/rule-fanout-batched-outer.d.ts.map +1 -1
- package/dist/src/planner/rules/join/rule-fanout-batched-outer.js +23 -4
- package/dist/src/planner/rules/join/rule-fanout-batched-outer.js.map +1 -1
- package/dist/src/planner/rules/join/rule-join-greedy-commute.d.ts.map +1 -1
- package/dist/src/planner/rules/join/rule-join-greedy-commute.js +7 -0
- package/dist/src/planner/rules/join/rule-join-greedy-commute.js.map +1 -1
- package/dist/src/planner/rules/join/rule-join-physical-selection.d.ts +19 -2
- package/dist/src/planner/rules/join/rule-join-physical-selection.d.ts.map +1 -1
- package/dist/src/planner/rules/join/rule-join-physical-selection.js +262 -40
- package/dist/src/planner/rules/join/rule-join-physical-selection.js.map +1 -1
- package/dist/src/planner/rules/join/rule-quickpick-enumeration.d.ts.map +1 -1
- package/dist/src/planner/rules/join/rule-quickpick-enumeration.js +24 -4
- package/dist/src/planner/rules/join/rule-quickpick-enumeration.js.map +1 -1
- package/dist/src/planner/rules/join/rule-semi-join-pushdown.d.ts +107 -0
- package/dist/src/planner/rules/join/rule-semi-join-pushdown.d.ts.map +1 -0
- package/dist/src/planner/rules/join/rule-semi-join-pushdown.js +214 -0
- package/dist/src/planner/rules/join/rule-semi-join-pushdown.js.map +1 -0
- package/dist/src/planner/rules/predicate/rule-sargable-range-rewrite.d.ts.map +1 -1
- package/dist/src/planner/rules/predicate/rule-sargable-range-rewrite.js +2 -1
- package/dist/src/planner/rules/predicate/rule-sargable-range-rewrite.js.map +1 -1
- package/dist/src/planner/rules/retrieve/rule-grow-retrieve.d.ts +21 -0
- package/dist/src/planner/rules/retrieve/rule-grow-retrieve.d.ts.map +1 -1
- package/dist/src/planner/rules/retrieve/rule-grow-retrieve.js +24 -6
- package/dist/src/planner/rules/retrieve/rule-grow-retrieve.js.map +1 -1
- package/dist/src/planner/rules/shared/access-leaf.d.ts +12 -12
- package/dist/src/planner/rules/shared/access-leaf.d.ts.map +1 -1
- package/dist/src/planner/rules/shared/access-leaf.js +3 -14
- package/dist/src/planner/rules/shared/access-leaf.js.map +1 -1
- package/dist/src/planner/stats/catalog-stats.d.ts.map +1 -1
- package/dist/src/planner/stats/catalog-stats.js +6 -10
- package/dist/src/planner/stats/catalog-stats.js.map +1 -1
- package/dist/src/planner/type-utils.d.ts.map +1 -1
- package/dist/src/planner/type-utils.js +3 -5
- package/dist/src/planner/type-utils.js.map +1 -1
- package/dist/src/planner/util/fd-utils.d.ts.map +1 -1
- package/dist/src/planner/util/fd-utils.js +4 -7
- package/dist/src/planner/util/fd-utils.js.map +1 -1
- package/dist/src/runtime/emit/alter-table.d.ts.map +1 -1
- package/dist/src/runtime/emit/alter-table.js +58 -4
- package/dist/src/runtime/emit/alter-table.js.map +1 -1
- package/dist/src/runtime/emit/binary.d.ts.map +1 -1
- package/dist/src/runtime/emit/binary.js +5 -3
- package/dist/src/runtime/emit/binary.js.map +1 -1
- package/dist/src/runtime/emit/fanout-lookup-join.d.ts.map +1 -1
- package/dist/src/runtime/emit/fanout-lookup-join.js +9 -1
- package/dist/src/runtime/emit/fanout-lookup-join.js.map +1 -1
- package/dist/src/runtime/emit/limit-offset.d.ts.map +1 -1
- package/dist/src/runtime/emit/limit-offset.js +50 -24
- package/dist/src/runtime/emit/limit-offset.js.map +1 -1
- package/dist/src/runtime/emit/materialized-view-helpers.d.ts +33 -2
- package/dist/src/runtime/emit/materialized-view-helpers.d.ts.map +1 -1
- package/dist/src/runtime/emit/materialized-view-helpers.js +61 -5
- package/dist/src/runtime/emit/materialized-view-helpers.js.map +1 -1
- package/dist/src/runtime/emit/materialized-view.d.ts.map +1 -1
- package/dist/src/runtime/emit/materialized-view.js +6 -1
- package/dist/src/runtime/emit/materialized-view.js.map +1 -1
- package/dist/src/runtime/emit/ordinal-slice.d.ts.map +1 -1
- package/dist/src/runtime/emit/ordinal-slice.js +8 -0
- package/dist/src/runtime/emit/ordinal-slice.js.map +1 -1
- package/dist/src/schema/derivation.d.ts +15 -1
- package/dist/src/schema/derivation.d.ts.map +1 -1
- package/dist/src/schema/derivation.js.map +1 -1
- package/dist/src/schema/function.d.ts +9 -4
- package/dist/src/schema/function.d.ts.map +1 -1
- package/dist/src/schema/function.js +11 -9
- package/dist/src/schema/function.js.map +1 -1
- package/dist/src/schema/schema.d.ts +14 -3
- package/dist/src/schema/schema.d.ts.map +1 -1
- package/dist/src/schema/schema.js +20 -2
- package/dist/src/schema/schema.js.map +1 -1
- package/dist/src/schema/table.d.ts +27 -0
- package/dist/src/schema/table.d.ts.map +1 -1
- package/dist/src/schema/table.js +55 -0
- package/dist/src/schema/table.js.map +1 -1
- package/dist/src/schema/unique-enforcement.d.ts +6 -13
- package/dist/src/schema/unique-enforcement.d.ts.map +1 -1
- package/dist/src/schema/unique-enforcement.js +8 -17
- package/dist/src/schema/unique-enforcement.js.map +1 -1
- package/dist/src/util/comparison.d.ts +19 -0
- package/dist/src/util/comparison.d.ts.map +1 -1
- package/dist/src/util/comparison.js +22 -0
- package/dist/src/util/comparison.js.map +1 -1
- package/dist/src/vtab/memory/module.d.ts.map +1 -1
- package/dist/src/vtab/memory/module.js +10 -0
- package/dist/src/vtab/memory/module.js.map +1 -1
- package/package.json +3 -3
|
@@ -103,14 +103,18 @@ function estimateRightRows(node) {
|
|
|
103
103
|
}
|
|
104
104
|
return max;
|
|
105
105
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Would this join's right side be wrapped in a `CacheNode` by
|
|
108
|
+
* {@link ruleNestedLoopRightCache}? The single source of truth for that
|
|
109
|
+
* question: the rule below calls it and then builds the node, and
|
|
110
|
+
* `rule-join-physical-selection` calls it to decide whether a plain nested loop
|
|
111
|
+
* pays its inner side's first-row latency ONCE (cached: one open plus N buffer
|
|
112
|
+
* replays) or once per outer row (uncached: N re-opens). Neither caller may
|
|
113
|
+
* restate any of the gates.
|
|
114
|
+
*
|
|
115
|
+
* Every gate is a decline; the comments on each explain what it protects.
|
|
116
|
+
*/
|
|
117
|
+
export function canCacheNestedLoopRight(node, context) {
|
|
114
118
|
// Driver gate: only the left-driven join types re-scan the right side.
|
|
115
119
|
// `right` / `full` buffer the left side once and scan the right side once
|
|
116
120
|
// (`emitLoopJoin.driveFromRight`), so caching their right side is pure waste.
|
|
@@ -124,23 +128,23 @@ export function ruleNestedLoopRightCache(node, context) {
|
|
|
124
128
|
// (same reopen count until the buffer fills, a win after), just data-dependent
|
|
125
129
|
// rather than the guaranteed replay inner/cross/left get.
|
|
126
130
|
if (node.joinType === 'right' || node.joinType === 'full') {
|
|
127
|
-
return
|
|
131
|
+
return false;
|
|
128
132
|
}
|
|
129
133
|
const right = node.right;
|
|
130
134
|
// Already cached (e.g. by cte / in-subquery / mutating-subquery cache).
|
|
131
135
|
if (CapabilityDetectors.isCached(right) && right.isCached()) {
|
|
132
|
-
return
|
|
136
|
+
return false;
|
|
133
137
|
}
|
|
134
138
|
// Purity gate: side effects are the mutating-subquery-cache rule's job.
|
|
135
139
|
// Double-wrapping a write would change nothing and only burn memory.
|
|
136
140
|
if (PlanNodeCharacteristics.subtreeHasSideEffects(right)) {
|
|
137
|
-
return
|
|
141
|
+
return false;
|
|
138
142
|
}
|
|
139
143
|
// Determinism gate: a non-deterministic right side (e.g. `random()`) must be
|
|
140
144
|
// re-evaluated per left row to preserve today's observable behavior; caching
|
|
141
145
|
// would freeze the first scan's values across every subsequent left row.
|
|
142
146
|
if (!PlanNodeCharacteristics.isDeterministic(right)) {
|
|
143
|
-
return
|
|
147
|
+
return false;
|
|
144
148
|
}
|
|
145
149
|
// Correlation gate: a right subtree that references left attributes (a
|
|
146
150
|
// parameterized/lateral seek produced by predicate pushdown) is
|
|
@@ -149,24 +153,59 @@ export function ruleNestedLoopRightCache(node, context) {
|
|
|
149
153
|
// separate JoinNode.condition child, not inside the right subtree — so the
|
|
150
154
|
// bare right access has no external refs and is cacheable.
|
|
151
155
|
if (isCorrelatedSubquery(right)) {
|
|
152
|
-
return
|
|
156
|
+
return false;
|
|
153
157
|
}
|
|
154
158
|
// CTE-safety gate: eagerly materializing a CTE-backed right side breaks the
|
|
155
159
|
// join's row-context at runtime (see subtreeTouchesCte above).
|
|
156
160
|
if (subtreeTouchesCte(right)) {
|
|
157
|
-
return
|
|
161
|
+
return false;
|
|
158
162
|
}
|
|
159
163
|
// Size gate (memory safety): materializing an unbounded right side trades I/O
|
|
160
164
|
// for memory. Respect the existing nested-loop caching threshold.
|
|
161
165
|
const estimatedRows = estimateRightRows(right) ?? context.tuning.defaultRowEstimate;
|
|
162
166
|
if (estimatedRows > context.tuning.join.maxRightRowsForCaching) {
|
|
163
167
|
log('Right side too large to cache (%d rows > %d), skipping', estimatedRows, context.tuning.join.maxRightRowsForCaching);
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Is this join's right side opened ONCE per join rather than once per outer row?
|
|
174
|
+
* True two ways: it is already materialized (a `CacheNode` from this rule on an
|
|
175
|
+
* earlier visit, or from the cte / in-subquery / mutating-subquery caches — all
|
|
176
|
+
* of which scan once and replay a buffer), or {@link canCacheNestedLoopRight}
|
|
177
|
+
* says this rule is about to make it so.
|
|
178
|
+
*
|
|
179
|
+
* `rule-join-physical-selection` asks THIS question, not the cacheability one:
|
|
180
|
+
* the two differ exactly on an already-cached right side, which
|
|
181
|
+
* `canCacheNestedLoopRight` declines (nothing left to do) but which pays its
|
|
182
|
+
* first-row latency once, not per outer row. Pricing that side per outer row
|
|
183
|
+
* made the selection rule re-visit a join this rule had just improved, re-price
|
|
184
|
+
* its nested loop as if the cache were not there, and convert it to a hash join
|
|
185
|
+
* — discarding the cache and landing on the costlier plan.
|
|
186
|
+
*/
|
|
187
|
+
export function nestedLoopRightOpensOnce(node, context) {
|
|
188
|
+
const right = node.right;
|
|
189
|
+
if (CapabilityDetectors.isCached(right) && right.isCached())
|
|
190
|
+
return true;
|
|
191
|
+
return canCacheNestedLoopRight(node, context);
|
|
192
|
+
}
|
|
193
|
+
export function ruleNestedLoopRightCache(node, context) {
|
|
194
|
+
// Only logical JoinNodes reach here uncached. By PostOptimization,
|
|
195
|
+
// join-physical-selection has already converted every equi-join it wanted to
|
|
196
|
+
// hash/merge (those materialize their build side), so any surviving logical
|
|
197
|
+
// JoinNode IS a nested loop — the exact structural signal we need.
|
|
198
|
+
if (!(node instanceof JoinNode)) {
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
if (!canCacheNestedLoopRight(node, context)) {
|
|
164
202
|
return null;
|
|
165
203
|
}
|
|
166
|
-
|
|
204
|
+
const right = node.right;
|
|
205
|
+
log('Caching pure nested-loop right side (%s)', node.joinType);
|
|
167
206
|
// Memory strategy + a CacheNode threshold (which degrades to pass-through
|
|
168
207
|
// past its limit) mirrors the sibling mutating-subquery-cache rule. Spill is
|
|
169
|
-
// unreachable under
|
|
208
|
+
// unreachable under `canCacheNestedLoopRight`'s size gate (maxRightRowsForCaching <
|
|
170
209
|
// cache.spillThreshold), so 'memory' is the only live choice here.
|
|
171
210
|
const threshold = CachingAnalysis.getCacheThreshold(right);
|
|
172
211
|
const cached = new CacheNode(right.scope, right, 'memory', threshold);
|
|
@@ -1 +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,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACnH,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAE3E,MAAM,GAAG,GAAG,YAAY,CAAC,wCAAwC,CAAC,CAAC;AAEnE;;;;;;;;;;;;;GAaG;AACH,MAAM,cAAc,GAA8B,IAAI,GAAG,CAAC;IACzD,YAAY,CAAC,YAAY;IACzB,YAAY,CAAC,GAAG;IAChB,YAAY,CAAC,YAAY;IACzB,YAAY,CAAC,uBAAuB;CACpC,CAAC,CAAC;AAEH,6EAA6E;AAC7E,SAAS,iBAAiB,CAAC,IAAc;I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CAAC;YAC3C,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnB,CAAC;IACF,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,
|
|
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,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACnH,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAE3E,MAAM,GAAG,GAAG,YAAY,CAAC,wCAAwC,CAAC,CAAC;AAEnE;;;;;;;;;;;;;GAaG;AACH,MAAM,cAAc,GAA8B,IAAI,GAAG,CAAC;IACzD,YAAY,CAAC,YAAY;IACzB,YAAY,CAAC,GAAG;IAChB,YAAY,CAAC,YAAY;IACzB,YAAY,CAAC,uBAAuB;CACpC,CAAC,CAAC;AAEH,6EAA6E;AAC7E,SAAS,iBAAiB,CAAC,IAAc;IACxC,MAAM,KAAK,GAAe,CAAC,IAAI,CAAC,CAAC;IACjC,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,EAAG,CAAC;QAC7B,IAAI,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC;YAAE,OAAO,IAAI,CAAC;QACtD,KAAK,MAAM,KAAK,IAA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I,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAC1E,CAAC;AACH,CAAC"}
|
|
@@ -1,49 +1,123 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Index-nested-loop candidate construction for `rule-join-physical-selection`.
|
|
3
3
|
*
|
|
4
|
-
* When a join's inner
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
4
|
+
* When a join's inner side bottoms out in a table-access leaf whose module can
|
|
5
|
+
* answer an equality seek on the join key, the leaf is replaced by an
|
|
6
|
+
* `IndexSeekNode` whose seek keys are column references into the OUTER row.
|
|
7
|
+
* The node above stays the logical `JoinNode`, so the existing nested-loop
|
|
8
|
+
* emitter drives it: for each outer row it installs the outer row slot and
|
|
9
|
+
* re-opens the inner pipeline, and the seek-key expressions resolve through
|
|
10
|
+
* the runtime context by attribute id — the same machinery correlated
|
|
11
11
|
* subqueries already exercise.
|
|
12
12
|
*
|
|
13
13
|
* Join(inner, s, SeqScan(big)) Join(inner, s, IndexSeek(big, keys=[s.k]))
|
|
14
14
|
* ON big.id = s.k ──▶ ON big.id = s.k
|
|
15
15
|
* reads every row of big one seek per row of s
|
|
16
16
|
*
|
|
17
|
+
* Two admission arms for the inner leaf. A WALK leaf (plain full scan, or an
|
|
18
|
+
* ordering-only index walk) enforces nothing, so its `FilterInfo` may be
|
|
19
|
+
* replaced wholesale. A SEEK leaf (`IndexSeekNode`) already enforces the
|
|
20
|
+
* predicates the module claimed — `status = 'x'` below is nowhere else in the
|
|
21
|
+
* tree — so it is admitted by re-OFFERING those predicates to the module
|
|
22
|
+
* alongside the join key and re-applying whatever the module declines:
|
|
23
|
+
*
|
|
24
|
+
* Join(inner, s, IndexSeek(big, [status='x']))
|
|
25
|
+
* ON big.id = s.k
|
|
26
|
+
* ──▶ Join(inner, s, Filter[status='x'](IndexSeek(big, keys=[s.k])))
|
|
27
|
+
* or Join(inner, s, IndexSeek(big, keys=[status='x', s.k])) (composite index)
|
|
28
|
+
*
|
|
29
|
+
* The function takes `outer` / `inner` explicitly rather than reading a
|
|
30
|
+
* JoinNode's `left` / `right`: the caller asks for BOTH orientations of an
|
|
31
|
+
* inner join (seek the right driven by the left, and the mirror) and elects
|
|
32
|
+
* the cheaper — see `ruleJoinPhysicalSelection`. Here "outer" always means the
|
|
33
|
+
* side that will drive, and "inner" the side whose leaf becomes the seek,
|
|
34
|
+
* whichever JoinNode slot each came from.
|
|
35
|
+
*
|
|
17
36
|
* This module only CONSTRUCTS the candidate (recognize the shape, probe the
|
|
18
|
-
* module, cost it); the
|
|
19
|
-
*
|
|
37
|
+
* module, cost it); the cost comparison and the join rebuild live in the
|
|
38
|
+
* caller. Every gate below declines by returning null, which leaves the
|
|
20
39
|
* nested-loop / hash / merge competition unchanged.
|
|
21
40
|
*
|
|
22
41
|
* NOTE: one extra pair of `getBestAccessPlan` probes runs per qualifying
|
|
23
|
-
* equi-join, uncached (see `probeModule`)
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
42
|
+
* equi-join on the walk arm, uncached (see `probeModule`); the seek arm runs
|
|
43
|
+
* ONE probe — its baseline is the displaced seek's recorded cost, a field read
|
|
44
|
+
* rather than a second probe. Cheap for both shipped modules; memoize by
|
|
45
|
+
* (table, offered constraints) only if a third-party module with an expensive
|
|
46
|
+
* planner shows up in optimization profiles — mirrors the rule-key-set-seek
|
|
47
|
+
* tripwire.
|
|
27
48
|
*/
|
|
28
49
|
import type { RelationalPlanNode } from '../../nodes/plan-node.js';
|
|
29
50
|
import type { OptContext } from '../../framework/context.js';
|
|
30
|
-
import {
|
|
51
|
+
import type { JoinType } from '../../nodes/join-node.js';
|
|
31
52
|
import type { EquiJoinPair } from '../../nodes/join-utils.js';
|
|
53
|
+
import { type PredicateConstraint } from '../../analysis/constraint-extractor.js';
|
|
54
|
+
import type { TableSchema } from '../../../schema/table.js';
|
|
32
55
|
export interface IndexNestedLoopCandidate {
|
|
33
|
-
/**
|
|
34
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Rebuilt INNER subtree with the access leaf replaced by the correlated seek.
|
|
58
|
+
* Which JoinNode slot it belongs in is the caller's business — it is the
|
|
59
|
+
* `inner` argument's slot, which is the right one only in the un-mirrored case.
|
|
60
|
+
*/
|
|
61
|
+
readonly newInner: RelationalPlanNode;
|
|
35
62
|
/** Engine-currency cost, comparable with nestedLoop/hash/merge in the caller. */
|
|
36
63
|
readonly cost: number;
|
|
64
|
+
/**
|
|
65
|
+
* The two inputs `cost` was derived from, so the caller can re-price the same
|
|
66
|
+
* seek under a different driver (`batchedIndexNestedLoopJoinCost`) without
|
|
67
|
+
* re-probing: the module's row estimate for one seek, and the inner
|
|
68
|
+
* subtree's first-row latency.
|
|
69
|
+
*/
|
|
70
|
+
readonly rowsPerSeek: number;
|
|
71
|
+
readonly perSeekLatencyMs: number;
|
|
72
|
+
/**
|
|
73
|
+
* True when the rebuilt inner PROVABLY yields at most one row per outer row —
|
|
74
|
+
* see {@link provesAtMostOne}. What lets the caller drive this candidate as a
|
|
75
|
+
* one-branch `FanOutLookupJoinNode` (`atMostOne-*` branch), whose runtime
|
|
76
|
+
* throws on a second row.
|
|
77
|
+
*/
|
|
78
|
+
readonly atMostOne: boolean;
|
|
37
79
|
}
|
|
38
80
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
81
|
+
* PROOF — not an estimate — that the inner rebuilt from `combined` yields at
|
|
82
|
+
* most one row per outer row. `FanOutLookupJoinNode`'s `atMostOne-*` branch
|
|
83
|
+
* modes throw `QuereusError(CONSTRAINT)` at runtime on a second row, so the
|
|
84
|
+
* module's `rows: 1` estimate must not stand in: a module that estimates 1 and
|
|
85
|
+
* returns 2 would turn a working query into an error.
|
|
86
|
+
*
|
|
87
|
+
* Premise: every constraint in `combined` is enforced somewhere inside the
|
|
88
|
+
* rebuilt inner. That is total for the `=` constraints this proof reads, by
|
|
89
|
+
* construction rather than by argument — each one is either module-DECLINED, and
|
|
90
|
+
* `reapplyDeclinedPushed` re-applies every declined pushed constraint as a Filter
|
|
91
|
+
* (join-key leftovers need none: the ON condition the caller keeps above the seek
|
|
92
|
+
* covers them), or module-HANDLED, and a handled constraint is either consumed
|
|
93
|
+
* into the seek's bounds or recovered by `selectPhysicalNode`'s
|
|
94
|
+
* `reattachUnconsumedConstraints` — whose `RECLAIMABLE_OPS` set contains `'='`,
|
|
95
|
+
* so no equality can fall through it. A Filter only removes rows, so a constraint
|
|
96
|
+
* enforced by a filter rather than by the index counts just the same. Then: if
|
|
97
|
+
* some enforced key has EVERY column pinned by an equality whose collation
|
|
98
|
+
* refines the key's ({@link equalityRefinesKey}), any two surviving rows agree
|
|
99
|
+
* on the whole key and uniqueness forbids the second. Ranges, IN and OR_RANGE
|
|
100
|
+
* admit many values and never contribute. Over-fetch is harmless — a
|
|
101
|
+
* `COARSER_SAFE` seek's residual Filter re-applies the exact comparison above
|
|
102
|
+
* it — and the finer-index case (`MISMATCH_UNSAFE`) never reaches here: it
|
|
103
|
+
* degrades to a scan in `selectPhysicalNode` and `rebuiltSeek` declines the
|
|
104
|
+
* candidate first. NULL keys need no case: `col = NULL` matches nothing.
|
|
105
|
+
*
|
|
106
|
+
* Exported for direct unit coverage; it is the correctness core of the batched
|
|
107
|
+
* candidate.
|
|
108
|
+
*/
|
|
109
|
+
export declare function provesAtMostOne(tableSchema: TableSchema, combined: readonly PredicateConstraint[]): boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Try to build an index-nested-loop candidate: the `inner` subtree rebuilt with
|
|
112
|
+
* its access leaf replaced by an `IndexSeekNode` correlated to `outer`, plus
|
|
41
113
|
* its engine-currency cost. Returns null when any gate declines; the caller's
|
|
42
114
|
* nested-loop / hash / merge competition is then unchanged.
|
|
43
115
|
*
|
|
44
|
-
* `
|
|
45
|
-
*
|
|
46
|
-
* left
|
|
116
|
+
* `joinType` is the type the REBUILT join will have with `outer` on the left
|
|
117
|
+
* (so a mirrored inner join passes 'inner'). `equiPairs` must be non-empty and
|
|
118
|
+
* oriented left=outer / right=inner — the caller flips them for the mirror.
|
|
119
|
+
* `outerRows` is the outer side's row estimate, the same input hash and merge
|
|
120
|
+
* selection use for that side.
|
|
47
121
|
*/
|
|
48
|
-
export declare function tryIndexNestedLoop(
|
|
122
|
+
export declare function tryIndexNestedLoop(joinType: JoinType, outer: RelationalPlanNode, inner: RelationalPlanNode, equiPairs: readonly EquiJoinPair[], outerRows: number, context: OptContext): IndexNestedLoopCandidate | null;
|
|
49
123
|
//# sourceMappingURL=index-nested-loop.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-nested-loop.d.ts","sourceRoot":"","sources":["../../../../../src/planner/rules/join/index-nested-loop.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index-nested-loop.d.ts","sourceRoot":"","sources":["../../../../../src/planner/rules/join/index-nested-loop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAGH,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,0BAA0B,CAAC;AACnF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAS9D,OAAO,EAA+C,KAAK,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAgB/H,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAM5D,MAAM,WAAW,wBAAwB;IACxC;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,CAAC;IACtC,iFAAiF;IACjF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;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