@quereus/quereus 3.1.2 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/core/database-assertions.js +3 -3
- package/dist/src/core/database-assertions.js.map +1 -1
- package/dist/src/core/database.js +3 -3
- package/dist/src/core/database.js.map +1 -1
- package/dist/src/core/statement.js +3 -3
- package/dist/src/core/statement.js.map +1 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/parser/visitor.js +1 -1
- package/dist/src/parser/visitor.js.map +1 -1
- package/dist/src/planner/analysis/attribute-provenance.d.ts +45 -0
- package/dist/src/planner/analysis/attribute-provenance.d.ts.map +1 -0
- package/dist/src/planner/analysis/attribute-provenance.js +81 -0
- package/dist/src/planner/analysis/attribute-provenance.js.map +1 -0
- package/dist/src/planner/analysis/const-evaluator.js +5 -5
- package/dist/src/planner/analysis/const-evaluator.js.map +1 -1
- package/dist/src/planner/building/select-window.d.ts.map +1 -1
- package/dist/src/planner/building/select-window.js +54 -21
- package/dist/src/planner/building/select-window.js.map +1 -1
- package/dist/src/planner/cache/correlation-detector.d.ts +7 -0
- package/dist/src/planner/cache/correlation-detector.d.ts.map +1 -1
- package/dist/src/planner/cache/correlation-detector.js +34 -2
- package/dist/src/planner/cache/correlation-detector.js.map +1 -1
- package/dist/src/planner/nodes/async-gather-node.d.ts +169 -0
- package/dist/src/planner/nodes/async-gather-node.d.ts.map +1 -0
- package/dist/src/planner/nodes/async-gather-node.js +488 -0
- package/dist/src/planner/nodes/async-gather-node.js.map +1 -0
- package/dist/src/planner/nodes/bloom-join-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/bloom-join-node.js +8 -7
- package/dist/src/planner/nodes/bloom-join-node.js.map +1 -1
- package/dist/src/planner/nodes/eager-prefetch-node.d.ts +47 -0
- package/dist/src/planner/nodes/eager-prefetch-node.d.ts.map +1 -0
- package/dist/src/planner/nodes/eager-prefetch-node.js +96 -0
- package/dist/src/planner/nodes/eager-prefetch-node.js.map +1 -0
- package/dist/src/planner/nodes/fanout-lookup-join-node.d.ts +150 -0
- package/dist/src/planner/nodes/fanout-lookup-join-node.d.ts.map +1 -0
- package/dist/src/planner/nodes/fanout-lookup-join-node.js +265 -0
- package/dist/src/planner/nodes/fanout-lookup-join-node.js.map +1 -0
- package/dist/src/planner/nodes/merge-join-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/merge-join-node.js +8 -7
- package/dist/src/planner/nodes/merge-join-node.js.map +1 -1
- package/dist/src/planner/nodes/plan-node-type.d.ts +3 -0
- package/dist/src/planner/nodes/plan-node-type.d.ts.map +1 -1
- package/dist/src/planner/nodes/plan-node-type.js +3 -0
- package/dist/src/planner/nodes/plan-node-type.js.map +1 -1
- package/dist/src/planner/nodes/plan-node.d.ts +36 -0
- package/dist/src/planner/nodes/plan-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/plan-node.js +26 -0
- package/dist/src/planner/nodes/plan-node.js.map +1 -1
- package/dist/src/planner/nodes/reference.d.ts.map +1 -1
- package/dist/src/planner/nodes/reference.js +13 -0
- package/dist/src/planner/nodes/reference.js.map +1 -1
- package/dist/src/planner/optimizer-tuning.d.ts +107 -0
- package/dist/src/planner/optimizer-tuning.d.ts.map +1 -1
- package/dist/src/planner/optimizer-tuning.js +43 -0
- 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 +91 -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 +1 -6
- package/dist/src/planner/rules/access/rule-monotonic-range-access.js.map +1 -1
- package/dist/src/planner/rules/join/rule-fanout-batched-outer.d.ts +74 -0
- package/dist/src/planner/rules/join/rule-fanout-batched-outer.d.ts.map +1 -0
- package/dist/src/planner/rules/join/rule-fanout-batched-outer.js +139 -0
- package/dist/src/planner/rules/join/rule-fanout-batched-outer.js.map +1 -0
- package/dist/src/planner/rules/join/rule-fanout-lookup-join.d.ts +58 -0
- package/dist/src/planner/rules/join/rule-fanout-lookup-join.d.ts.map +1 -0
- package/dist/src/planner/rules/join/rule-fanout-lookup-join.js +592 -0
- package/dist/src/planner/rules/join/rule-fanout-lookup-join.js.map +1 -0
- package/dist/src/planner/rules/parallel/rule-async-gather-union-all.d.ts +43 -0
- package/dist/src/planner/rules/parallel/rule-async-gather-union-all.d.ts.map +1 -0
- package/dist/src/planner/rules/parallel/rule-async-gather-union-all.js +115 -0
- package/dist/src/planner/rules/parallel/rule-async-gather-union-all.js.map +1 -0
- package/dist/src/planner/rules/parallel/rule-async-gather-zip-by-key.d.ts +102 -0
- package/dist/src/planner/rules/parallel/rule-async-gather-zip-by-key.d.ts.map +1 -0
- package/dist/src/planner/rules/parallel/rule-async-gather-zip-by-key.js +545 -0
- package/dist/src/planner/rules/parallel/rule-async-gather-zip-by-key.js.map +1 -0
- package/dist/src/planner/rules/parallel/rule-eager-prefetch-probe.d.ts +45 -0
- package/dist/src/planner/rules/parallel/rule-eager-prefetch-probe.d.ts.map +1 -0
- package/dist/src/planner/rules/parallel/rule-eager-prefetch-probe.js +78 -0
- package/dist/src/planner/rules/parallel/rule-eager-prefetch-probe.js.map +1 -0
- package/dist/src/planner/scopes/param.d.ts.map +1 -1
- package/dist/src/planner/scopes/param.js +13 -11
- package/dist/src/planner/scopes/param.js.map +1 -1
- package/dist/src/planner/type-utils.js +1 -1
- package/dist/src/planner/type-utils.js.map +1 -1
- package/dist/src/planner/validation/plan-validator.d.ts.map +1 -1
- package/dist/src/planner/validation/plan-validator.js +17 -19
- package/dist/src/planner/validation/plan-validator.js.map +1 -1
- package/dist/src/runtime/async-semaphore.d.ts +36 -0
- package/dist/src/runtime/async-semaphore.d.ts.map +1 -0
- package/dist/src/runtime/async-semaphore.js +72 -0
- package/dist/src/runtime/async-semaphore.js.map +1 -0
- package/dist/src/runtime/deferred-constraint-queue.d.ts.map +1 -1
- package/dist/src/runtime/deferred-constraint-queue.js +4 -3
- package/dist/src/runtime/deferred-constraint-queue.js.map +1 -1
- package/dist/src/runtime/emit/async-gather.d.ts +77 -0
- package/dist/src/runtime/emit/async-gather.d.ts.map +1 -0
- package/dist/src/runtime/emit/async-gather.js +234 -0
- package/dist/src/runtime/emit/async-gather.js.map +1 -0
- package/dist/src/runtime/emit/bloom-join.d.ts.map +1 -1
- package/dist/src/runtime/emit/bloom-join.js +38 -17
- package/dist/src/runtime/emit/bloom-join.js.map +1 -1
- package/dist/src/runtime/emit/eager-prefetch.d.ts +77 -0
- package/dist/src/runtime/emit/eager-prefetch.d.ts.map +1 -0
- package/dist/src/runtime/emit/eager-prefetch.js +223 -0
- package/dist/src/runtime/emit/eager-prefetch.js.map +1 -0
- package/dist/src/runtime/emit/fanout-lookup-join.d.ts +130 -0
- package/dist/src/runtime/emit/fanout-lookup-join.d.ts.map +1 -0
- package/dist/src/runtime/emit/fanout-lookup-join.js +521 -0
- package/dist/src/runtime/emit/fanout-lookup-join.js.map +1 -0
- package/dist/src/runtime/parallel-driver.d.ts +68 -0
- package/dist/src/runtime/parallel-driver.d.ts.map +1 -0
- package/dist/src/runtime/parallel-driver.js +233 -0
- package/dist/src/runtime/parallel-driver.js.map +1 -0
- package/dist/src/runtime/register.d.ts.map +1 -1
- package/dist/src/runtime/register.js +9 -0
- package/dist/src/runtime/register.js.map +1 -1
- package/dist/src/runtime/strict-fork.d.ts +36 -0
- package/dist/src/runtime/strict-fork.d.ts.map +1 -0
- package/dist/src/runtime/strict-fork.js +125 -0
- package/dist/src/runtime/strict-fork.js.map +1 -0
- package/dist/src/util/comparison.d.ts.map +1 -1
- package/dist/src/util/comparison.js +11 -1
- package/dist/src/util/comparison.js.map +1 -1
- package/dist/src/vtab/concurrency.d.ts +29 -0
- package/dist/src/vtab/concurrency.d.ts.map +1 -0
- package/dist/src/vtab/concurrency.js +47 -0
- package/dist/src/vtab/concurrency.js.map +1 -0
- package/dist/src/vtab/memory/layer/scan-layer.d.ts.map +1 -1
- package/dist/src/vtab/memory/layer/scan-layer.js +67 -29
- package/dist/src/vtab/memory/layer/scan-layer.js.map +1 -1
- package/dist/src/vtab/memory/module.d.ts +21 -0
- package/dist/src/vtab/memory/module.d.ts.map +1 -1
- package/dist/src/vtab/memory/module.js +21 -0
- package/dist/src/vtab/memory/module.js.map +1 -1
- package/dist/src/vtab/module.d.ts +47 -0
- package/dist/src/vtab/module.d.ts.map +1 -1
- package/package.json +4 -3
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attribute provenance: a derived map from attribute id to the relational node
|
|
3
|
+
* that *originated* (minted) it.
|
|
4
|
+
*
|
|
5
|
+
* Attribute ids have two distinct lifecycle operations that `getAttributes()`
|
|
6
|
+
* smears together:
|
|
7
|
+
*
|
|
8
|
+
* - **Origination** — a node mints a fresh id via `PlanNode.nextAttrId()`
|
|
9
|
+
* (scans, computed projections, aggregate outputs, VALUES rows).
|
|
10
|
+
* - **Forwarding** — a node re-publishes an id one of its children already
|
|
11
|
+
* produced (SetOperation, Join concatenation, EagerPrefetch, AsyncGather,
|
|
12
|
+
* simple column-ref projections, ...).
|
|
13
|
+
*
|
|
14
|
+
* The real invariant of the attribute model is "each id is *originated* exactly
|
|
15
|
+
* once", NOT "each id appears at most once in the tree" — forwarding the same id
|
|
16
|
+
* up through N ancestors is the whole point of stable ids.
|
|
17
|
+
*
|
|
18
|
+
* Origination is derivable structurally with no per-node declaration: an id is
|
|
19
|
+
* originated at the deepest relational node that outputs it and whose direct
|
|
20
|
+
* relational children do **not**. A single post-order walk over the existing
|
|
21
|
+
* `getAttributes()` surface yields the complete provenance map.
|
|
22
|
+
*/
|
|
23
|
+
import { isRelationalNode } from '../nodes/plan-node.js';
|
|
24
|
+
import { QuereusError } from '../../common/errors.js';
|
|
25
|
+
import { StatusCode } from '../../common/types.js';
|
|
26
|
+
/**
|
|
27
|
+
* Compute the attribute-provenance surface for a plan tree in one post-order
|
|
28
|
+
* walk. An attribute id is *originated* at the deepest relational node that
|
|
29
|
+
* outputs it and whose direct relational children do not; ancestors that
|
|
30
|
+
* re-publish the id are forwards, not new origins.
|
|
31
|
+
*
|
|
32
|
+
* The returned map contains an entry for every id that appears anywhere in the
|
|
33
|
+
* tree (forwarded ids resolve to their origin), so membership answers "is this
|
|
34
|
+
* id in scope?" exactly as the old global-set check did.
|
|
35
|
+
*
|
|
36
|
+
* @throws QuereusError(INTERNAL) when two distinct relational nodes originate
|
|
37
|
+
* the same id (the genuine-bug case the old validator caught) or when a single
|
|
38
|
+
* node lists the same id more than once. Forwarding never throws.
|
|
39
|
+
*/
|
|
40
|
+
export function computeAttributeProvenance(root) {
|
|
41
|
+
const provenance = new Map();
|
|
42
|
+
const visited = new Set();
|
|
43
|
+
const walk = (node, path) => {
|
|
44
|
+
// Dedupe by node identity: plan trees are DAGs (shared CTE/common
|
|
45
|
+
// subexpression instances). Visiting a shared instance once keeps the
|
|
46
|
+
// walk linear and avoids treating its single origin as a collision.
|
|
47
|
+
if (visited.has(node))
|
|
48
|
+
return;
|
|
49
|
+
visited.add(node);
|
|
50
|
+
const nodeChain = [...path, node.nodeType];
|
|
51
|
+
// Post-order: process children before deciding what this node originates.
|
|
52
|
+
for (const child of node.getChildren()) {
|
|
53
|
+
walk(child, nodeChain);
|
|
54
|
+
}
|
|
55
|
+
if (!isRelationalNode(node))
|
|
56
|
+
return;
|
|
57
|
+
// Ids output by direct relational children are forwarded, not originated here.
|
|
58
|
+
const childIds = new Set();
|
|
59
|
+
for (const rel of node.getRelations()) {
|
|
60
|
+
for (const attr of rel.getAttributes()) {
|
|
61
|
+
childIds.add(attr.id);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const nodePath = nodeChain.join(' > ');
|
|
65
|
+
for (const attr of node.getAttributes()) {
|
|
66
|
+
if (childIds.has(attr.id))
|
|
67
|
+
continue; // forwarded — not an origin
|
|
68
|
+
const existing = provenance.get(attr.id);
|
|
69
|
+
if (existing) {
|
|
70
|
+
if (existing.originNode === node) {
|
|
71
|
+
throw new QuereusError(`Duplicate attribute ID ${attr.id} within the output of ${nodePath}`, StatusCode.INTERNAL);
|
|
72
|
+
}
|
|
73
|
+
throw new QuereusError(`Attribute ID ${attr.id} originated at two distinct nodes (${existing.path} and ${nodePath})`, StatusCode.INTERNAL);
|
|
74
|
+
}
|
|
75
|
+
provenance.set(attr.id, { originNode: node, path: nodePath });
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
walk(root, []);
|
|
79
|
+
return provenance;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=attribute-provenance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attribute-provenance.js","sourceRoot":"","sources":["../../../../src/planner/analysis/attribute-provenance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,gBAAgB,EAA0C,MAAM,uBAAuB,CAAC;AACjG,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AASnD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,0BAA0B,CAAC,IAAc;IACxD,MAAM,UAAU,GAAG,IAAI,GAAG,EAA2B,CAAC;IACtD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAY,CAAC;IAEpC,MAAM,IAAI,GAAG,CAAC,IAAc,EAAE,IAAuB,EAAQ,EAAE;QAC9D,kEAAkE;QAClE,sEAAsE;QACtE,oEAAoE;QACpE,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,OAAO;QAC9B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAElB,MAAM,SAAS,GAAG,CAAC,GAAG,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC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IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC/D,CAAC;IACF,CAAC,CAAC;IAEF,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACf,OAAO,UAAU,CAAC;AACnB,CAAC"}
|
|
@@ -9,7 +9,7 @@ import { StatusCode } from '../../common/types.js';
|
|
|
9
9
|
import { emitPlanNode } from '../../runtime/emitters.js';
|
|
10
10
|
import { EmissionContext } from '../../runtime/emission-context.js';
|
|
11
11
|
import { Scheduler } from '../../runtime/scheduler.js';
|
|
12
|
-
import {
|
|
12
|
+
import { createStrictRowContextMap, wrapTableContextsStrict } from '../../runtime/strict-fork.js';
|
|
13
13
|
import { isAsyncIterable } from '../../runtime/utils.js';
|
|
14
14
|
import { createLogger } from '../../common/logger.js';
|
|
15
15
|
import { TableLiteralNode } from '../nodes/values-node.js';
|
|
@@ -33,8 +33,8 @@ export function createRuntimeExpressionEvaluator(db) {
|
|
|
33
33
|
db,
|
|
34
34
|
stmt: undefined,
|
|
35
35
|
params: {}, // No parameters needed for constants
|
|
36
|
-
context:
|
|
37
|
-
tableContexts: new Map(), // No table contexts needed for constants
|
|
36
|
+
context: createStrictRowContextMap(), // No row context needed
|
|
37
|
+
tableContexts: wrapTableContextsStrict(new Map()), // No table contexts needed for constants
|
|
38
38
|
enableMetrics: false
|
|
39
39
|
};
|
|
40
40
|
// Execute and get the result
|
|
@@ -136,8 +136,8 @@ export function createRuntimeRelationalEvaluator(db) {
|
|
|
136
136
|
db,
|
|
137
137
|
stmt: undefined,
|
|
138
138
|
params: {},
|
|
139
|
-
context:
|
|
140
|
-
tableContexts: new Map(),
|
|
139
|
+
context: createStrictRowContextMap(),
|
|
140
|
+
tableContexts: wrapTableContextsStrict(new Map()),
|
|
141
141
|
enableMetrics: false
|
|
142
142
|
};
|
|
143
143
|
return scheduler.run(runtimeCtx);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"const-evaluator.js","sourceRoot":"","sources":["../../../../src/planner/analysis/const-evaluator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAEvD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"const-evaluator.js","sourceRoot":"","sources":["../../../../src/planner/analysis/const-evaluator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAEvD,OAAO,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAClG,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAG3D,MAAM,GAAG,GAAG,YAAY,CAAC,wBAAwB,CAAC,CAAC;AAEnD;;GAEG;AACH,MAAM,UAAU,gCAAgC,CAAC,EAAY;IAC5D,OAAO,SAAS,kBAAkB,CAAC,IAAc;QAChD,GAAG,CAAC,oCAAoC,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEzD,IAAI,CAAC;YACJ,oCAAoC;YACpC,MAAM,WAAW,GAAG,IAAI,eAAe,CAAC,EAAE,CAAC,CAAC;YAE5C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C,CAAC,CAAC;YAEH,mDAAmD;YACnD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAkB,CAAC;YAC/C,MAAM,OAAO,GAAG,IAAoF,CAAC;YACrG,MAAM,aAAa,GAAgB,CAAC,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;YAEhE,MAAM,WAAW,GAAG,IAAI,gBAAgB,CACvC,IAAI,CAAC,KAAK,EACV,QAAQ,EACR,OAAO,CAAC,aAAa,EACrB,OAAO,EACP,aAAa,CACb,CAAC;YAEF,GAAG,CAAC,mDAAmD,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;YAClE,OAAO,WAAW,CAAC;QAEpB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,GAAG,CAAC,2CAA2C,EAAE,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;YACvE,MAAM,IAAI,YAAY,CAAC,8BAA8B,EAAE,UAAU,CAAC,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QACtH,CAAC;IACF,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-window.d.ts","sourceRoot":"","sources":["../../../../src/planner/building/select-window.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"select-window.d.ts","sourceRoot":"","sources":["../../../../src/planner/building/select-window.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,kBAAkB,EAAkB,MAAM,uBAAuB,CAAC;AAC1F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAI9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAMrE,OAAO,KAAK,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAGhD;;GAEG;AACH,wBAAgB,gBAAgB,CAC/B,KAAK,EAAE,kBAAkB,EACzB,eAAe,EAAE;IAAE,IAAI,EAAE,sBAAsB,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,EACnE,aAAa,EAAE,eAAe,EAC9B,IAAI,EAAE,GAAG,CAAC,UAAU,GAClB,kBAAkB,CAqEpB"}
|
|
@@ -105,16 +105,17 @@ function buildWindowProjections(stmt, windowNode, selectContext, windowFunctions
|
|
|
105
105
|
// Build each column expression once and reuse for both classification and projection
|
|
106
106
|
const builtExpr = buildExpression(selectContext, column.expr, true);
|
|
107
107
|
if (isWindowExpression(builtExpr)) {
|
|
108
|
-
//
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
108
|
+
// Rewrite each window-function descendant into an ArrayIndexNode pointing
|
|
109
|
+
// at its computed window-output column, preserving any surrounding
|
|
110
|
+
// arithmetic / scalar wrapper (e.g. `1000 - row_number() over (...)`).
|
|
111
|
+
// The top-level case (`row_number() over (...) as rn`) falls out naturally:
|
|
112
|
+
// the whole tree is the window node, so the rewrite returns a bare
|
|
113
|
+
// ArrayIndexNode, matching the prior behavior.
|
|
114
|
+
const rewritten = rewriteWindowFunctions(builtExpr, windowFunctions, sourceColumnCount, windowType, selectContext.scope);
|
|
115
|
+
windowProjections.push({
|
|
116
|
+
node: rewritten,
|
|
117
|
+
alias: column.alias
|
|
118
|
+
});
|
|
118
119
|
}
|
|
119
120
|
else {
|
|
120
121
|
// For regular columns, use the already-built expression
|
|
@@ -128,21 +129,53 @@ function buildWindowProjections(stmt, windowNode, selectContext, windowFunctions
|
|
|
128
129
|
return windowProjections;
|
|
129
130
|
}
|
|
130
131
|
/**
|
|
131
|
-
*
|
|
132
|
+
* Recursively rewrites every WindowFunctionCallNode descendant of a scalar
|
|
133
|
+
* expression into an ArrayIndexNode referencing that function's window-output
|
|
134
|
+
* column, leaving the surrounding expression structure intact.
|
|
135
|
+
*
|
|
136
|
+
* Mirrors the aggregate path (collectInnerAggregates): the whole outer
|
|
137
|
+
* expression is preserved and the inner window results are substituted back in.
|
|
138
|
+
* Does NOT recurse into a window function's own arguments — its result is a
|
|
139
|
+
* single output column already materialized by the WindowNode.
|
|
140
|
+
*/
|
|
141
|
+
function rewriteWindowFunctions(node, windowFunctions, sourceColumnCount, windowType, scope) {
|
|
142
|
+
if (CapabilityDetectors.isWindowFunction(node)) {
|
|
143
|
+
const index = findWindowColumnIndex(node, windowFunctions, sourceColumnCount);
|
|
144
|
+
if (index >= 0) {
|
|
145
|
+
return new ArrayIndexNode(scope, index, windowType.columns[index].type);
|
|
146
|
+
}
|
|
147
|
+
// No match (shouldn't happen for a window node we collected) — leave as-is.
|
|
148
|
+
return node;
|
|
149
|
+
}
|
|
150
|
+
const children = node.getChildren();
|
|
151
|
+
const newChildren = [];
|
|
152
|
+
let changed = false;
|
|
153
|
+
for (const child of children) {
|
|
154
|
+
// Only scalar children participate in window rewriting; pass others through.
|
|
155
|
+
if ('expression' in child) {
|
|
156
|
+
const rewrittenChild = rewriteWindowFunctions(child, windowFunctions, sourceColumnCount, windowType, scope);
|
|
157
|
+
if (rewrittenChild !== child) {
|
|
158
|
+
changed = true;
|
|
159
|
+
}
|
|
160
|
+
newChildren.push(rewrittenChild);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
newChildren.push(child);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return changed ? node.withChildren(newChildren) : node;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Finds the window-output column index for a single window-function node by
|
|
170
|
+
* matching it (name + window spec) against the collected window functions.
|
|
132
171
|
*/
|
|
133
|
-
function
|
|
172
|
+
function findWindowColumnIndex(windowNode, windowFunctions, sourceColumnCount) {
|
|
134
173
|
const matchingWindowFuncIndex = windowFunctions.findIndex(({ func }) => {
|
|
135
|
-
// Match based on function name
|
|
136
|
-
if (
|
|
137
|
-
func.functionName.toLowerCase() !== originalExpr.functionName.toLowerCase()) {
|
|
174
|
+
// Match based on function name and window specification
|
|
175
|
+
if (func.functionName.toLowerCase() !== windowNode.functionName.toLowerCase()) {
|
|
138
176
|
return false;
|
|
139
177
|
}
|
|
140
|
-
|
|
141
|
-
const windowFunc = originalExpr;
|
|
142
|
-
// Also compare window specifications to distinguish between functions with same name
|
|
143
|
-
const originalWindow = windowFunc.expression.window;
|
|
144
|
-
const funcWindow = func.expression.window;
|
|
145
|
-
return compareWindowSpecs(originalWindow, funcWindow);
|
|
178
|
+
return compareWindowSpecs(windowNode.expression.window, func.expression.window);
|
|
146
179
|
});
|
|
147
180
|
return matchingWindowFuncIndex >= 0 ? sourceColumnCount + matchingWindowFuncIndex : -1;
|
|
148
181
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-window.js","sourceRoot":"","sources":["../../../../src/planner/building/select-window.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"select-window.js","sourceRoot":"","sources":["../../../../src/planner/building/select-window.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAmB,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,WAAW,EAAmB,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAEtE;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC/B,KAAyB,EACzB,eAAmE,EACnE,aAA8B,EAC9B,IAAoB;IAEpB,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClC,OAAO,KAAK,CA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AAkB,CAAC,UAAU,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IACjF,CAAC,CAAC,CAAC;IAEH,OAAO,uBAAuB,IAAI,CAAC,CAAC,CAAC,CAAC,iBAAiB,GAAG,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACxF,CAAC;AAED;;GAEG;AACH,SAAS,kBAAkB,CAAC,cAAqC,EAAE,UAAiC;IACnG,gCAAgC;IAChC,MAAM,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,WAAW,IAAI,EAAE,CAAC,CAAC;IAC5E,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,WAAW,IAAI,EAAE,CAAC,CAAC;IAEpE,4BAA4B;IAC5B,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC;IACpE,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC;IAE5D,+BAA+B;IAC/B,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,KAAK,IAAI,IAAI,CAAC,CAAC;IACpE,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,KAAK,IAAI,IAAI,CAAC,CAAC;IAE5D,OAAO,iBAAiB,KAAK,aAAa;QACtC,aAAa,KAAK,SAAS;QAC3B,aAAa,KAAK,SAAS,CAAC;AACjC,CAAC"}
|
|
@@ -8,4 +8,11 @@ import { type RelationalPlanNode } from '../nodes/plan-node.js';
|
|
|
8
8
|
* that are not defined within its own scope.
|
|
9
9
|
*/
|
|
10
10
|
export declare function isCorrelatedSubquery(subqueryNode: RelationalPlanNode): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Collect the attribute IDs the subquery references from *outer* scopes (i.e.
|
|
13
|
+
* not defined within its own subtree). An empty set means the subquery is not
|
|
14
|
+
* correlated. Used by rules that need to know *which* outer attributes a
|
|
15
|
+
* correlation depends on, not merely that it is correlated.
|
|
16
|
+
*/
|
|
17
|
+
export declare function collectExternalReferences(subqueryNode: RelationalPlanNode): Set<number>;
|
|
11
18
|
//# sourceMappingURL=correlation-detector.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"correlation-detector.d.ts","sourceRoot":"","sources":["../../../../src/planner/cache/correlation-detector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAmC,KAAK,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAIjG;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,kBAAkB,GAAG,OAAO,
|
|
1
|
+
{"version":3,"file":"correlation-detector.d.ts","sourceRoot":"","sources":["../../../../src/planner/cache/correlation-detector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAmC,KAAK,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAIjG;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,kBAAkB,GAAG,OAAO,CAK9E;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,YAAY,EAAE,kBAAkB,GAAG,GAAG,CAAC,MAAM,CAAC,CAMvF"}
|
|
@@ -9,12 +9,24 @@ import { PlanNodeType } from '../nodes/plan-node-type.js';
|
|
|
9
9
|
* that are not defined within its own scope.
|
|
10
10
|
*/
|
|
11
11
|
export function isCorrelatedSubquery(subqueryNode) {
|
|
12
|
-
//
|
|
12
|
+
// Short-circuit: stop at the first external reference rather than collecting all.
|
|
13
13
|
const definedAttributes = new Set();
|
|
14
14
|
collectDefinedAttributes(subqueryNode, definedAttributes);
|
|
15
|
-
// Check if any column references use attributes not defined within the subquery
|
|
16
15
|
return hasExternalReferences(subqueryNode, definedAttributes);
|
|
17
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Collect the attribute IDs the subquery references from *outer* scopes (i.e.
|
|
19
|
+
* not defined within its own subtree). An empty set means the subquery is not
|
|
20
|
+
* correlated. Used by rules that need to know *which* outer attributes a
|
|
21
|
+
* correlation depends on, not merely that it is correlated.
|
|
22
|
+
*/
|
|
23
|
+
export function collectExternalReferences(subqueryNode) {
|
|
24
|
+
const definedAttributes = new Set();
|
|
25
|
+
collectDefinedAttributes(subqueryNode, definedAttributes);
|
|
26
|
+
const external = new Set();
|
|
27
|
+
collectExternalAttributeIds(subqueryNode, definedAttributes, external);
|
|
28
|
+
return external;
|
|
29
|
+
}
|
|
18
30
|
/**
|
|
19
31
|
* Recursively collect all attributes defined by relational nodes within a subtree
|
|
20
32
|
*/
|
|
@@ -70,4 +82,24 @@ function hasExternalReferences(node, definedAttributes) {
|
|
|
70
82
|
}
|
|
71
83
|
return false;
|
|
72
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Like {@link hasExternalReferences}, but accumulates every external attribute
|
|
87
|
+
* ID into `external` instead of short-circuiting at the first one.
|
|
88
|
+
*/
|
|
89
|
+
function collectExternalAttributeIds(node, definedAttributes, external) {
|
|
90
|
+
if (node.nodeType === PlanNodeType.ColumnReference) {
|
|
91
|
+
const colRef = node;
|
|
92
|
+
if (!definedAttributes.has(colRef.attributeId)) {
|
|
93
|
+
external.add(colRef.attributeId);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
for (const child of node.getChildren()) {
|
|
97
|
+
collectExternalAttributeIds(child, definedAttributes, external);
|
|
98
|
+
}
|
|
99
|
+
if (isRelationalNode(node)) {
|
|
100
|
+
for (const relation of node.getRelations()) {
|
|
101
|
+
collectExternalAttributeIds(relation, definedAttributes, external);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
73
105
|
//# sourceMappingURL=correlation-detector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"correlation-detector.js","sourceRoot":"","sources":["../../../../src/planner/cache/correlation-detector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAA0C,MAAM,uBAAuB,CAAC;AACjG,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG1D;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,YAAgC;IACpE,
|
|
1
|
+
{"version":3,"file":"correlation-detector.js","sourceRoot":"","sources":["../../../../src/planner/cache/correlation-detector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAA0C,MAAM,uBAAuB,CAAC;AACjG,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG1D;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,YAAgC;IACpE,kFAAkF;IAClF,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAU,CAAC;IAC5C,wBAAwB,CAAC,YAAY,EAAE,iBAAiB,CAAC,CAAC;IAC1D,OAAO,qBAAqB,CAAC,YAAY,EAAE,iBAAiB,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CAAC,YAAgC;IACzE,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAU,CAAC;IAC5C,wBAAwB,CAAC,YAAY,EAAE,iBAAiB,CAAC,CAAC;IAC1D,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IACnC,2BAA2B,CAAC,YAAY,EAAE,iBAAiB,EAAE,QAAQ,CAAC,CAAC;IACvE,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,SAAS,wBAAwB,CAAC,IAAc,EAAE,iBAA8B;IAC/E,mDAAmD;IACnD,MAAM,YAAY,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAC5C,IAAI,YAAY,EAAE,CAAC;QAClB,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QACxC,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;YAC/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CAAC;YAClC,IAAI,qBAAqB,CAAC,QAAQ,EAAE,iBAAiB,CAAC,EAAE,CAAC;gBACxD,OAAO,IAAI,CAAC;YACb,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,SAAS,2BAA2B,CACnC,IAAc,EACd,iBAA8B,EAC9B,QAAqB;IAErB,IAAI,IAAI,CAAC,QAAQ,KAAK,YAAY,CAAC,eAAe,EAAE,CAAC;QACpD,MAAM,MAAM,GAAG,IAA2B,CAAC;QAC3C,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;YAChD,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QAClC,CAAC;IACF,CAAC;IAED,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;QACxC,2BAA2B,CAAC,KAAK,EAAE,iBAAiB,EAAE,QAAQ,CAAC,CAAC;IACjE,CAAC;IAED,IAAI,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5B,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,YAAY,EAAE,EAAE,CAAC;YAC5C,2BAA2B,CAAC,QAAQ,EAAE,iBAAiB,EAAE,QAAQ,CAAC,CAAC;QACpE,CAAC;IACF,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { PlanNode } from './plan-node.js';
|
|
2
|
+
import type { RelationalPlanNode, Attribute, PhysicalProperties } from './plan-node.js';
|
|
3
|
+
import type { RelationType } from '../../common/datatype.js';
|
|
4
|
+
import { PlanNodeType } from './plan-node-type.js';
|
|
5
|
+
import type { Scope } from '../scopes/scope.js';
|
|
6
|
+
/**
|
|
7
|
+
* How {@link AsyncGatherNode} combines rows from its N independent child relations.
|
|
8
|
+
*
|
|
9
|
+
* - `unionAll`: yield every row from every branch in arrival order — multiset
|
|
10
|
+
* union (no dedup). All children must have matching column counts.
|
|
11
|
+
*
|
|
12
|
+
* - `crossProduct`: drain every branch fully, then yield the full Cartesian
|
|
13
|
+
* product. The output attributes are the concatenation of all children's
|
|
14
|
+
* attributes. **Materialises every branch in memory before yielding the
|
|
15
|
+
* first row** — see emitter docs in `runtime/emit/async-gather.ts`.
|
|
16
|
+
*
|
|
17
|
+
* - `zipByKey`: full N-way outer join on the key columns named **per branch** by
|
|
18
|
+
* `branchKeyAttrs`. For each distinct key value present in any branch, emit
|
|
19
|
+
* exactly one composed row: the K merged key columns once (carrying the
|
|
20
|
+
* gather-minted `outputKeyAttrs` ids), then each branch's non-key columns
|
|
21
|
+
* (NULL when that branch has no row for that key). Implemented as an **eager
|
|
22
|
+
* hash-merge** over a `BTree` keyed by the key tuple — **drains every branch
|
|
23
|
+
* in memory before yielding the first row** (see emitter docs). It is *not*
|
|
24
|
+
* a chained binary full-outer-join lowering.
|
|
25
|
+
*
|
|
26
|
+
* The gather genuinely **originates** the K merged key columns (their ids,
|
|
27
|
+
* `outputKeyAttrs`, appear in no child — "branch0's key, or branch1's key, …,
|
|
28
|
+
* whichever row is present") and **forwards** each branch's non-key ids (each
|
|
29
|
+
* appears in exactly one child). This is provenance-clean by construction:
|
|
30
|
+
* no id is output by two branches, so `validatePhysicalTree` passes.
|
|
31
|
+
*
|
|
32
|
+
* The discriminated-union shape is deliberate: future variants (e.g.
|
|
33
|
+
* `mergeOrdered`) will attach per-combinator config without breaking the
|
|
34
|
+
* constructor.
|
|
35
|
+
*/
|
|
36
|
+
export type AsyncGatherCombinator = {
|
|
37
|
+
readonly kind: 'unionAll';
|
|
38
|
+
} | {
|
|
39
|
+
readonly kind: 'crossProduct';
|
|
40
|
+
} | {
|
|
41
|
+
readonly kind: 'zipByKey';
|
|
42
|
+
/**
|
|
43
|
+
* Per branch b, the attribute IDs of that branch's K key columns, in
|
|
44
|
+
* key-position order. Distinct per branch (provenance-clean — each branch
|
|
45
|
+
* originates its own key id). `length === children.length`; every inner
|
|
46
|
+
* list has the same length K.
|
|
47
|
+
*/
|
|
48
|
+
readonly branchKeyAttrs: readonly (readonly number[])[];
|
|
49
|
+
/**
|
|
50
|
+
* The K output key attribute IDs the gather mints (originates). One per
|
|
51
|
+
* key position. Pairwise distinct and disjoint from every child's
|
|
52
|
+
* attribute IDs. Output key columns sit at index 0..K-1, in this order.
|
|
53
|
+
*/
|
|
54
|
+
readonly outputKeyAttrs: readonly number[];
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Per-branch column-index mapping for a `zipByKey` gather, resolved from the
|
|
58
|
+
* per-branch {@link AsyncGatherCombinator.branchKeyAttrs} lists against each
|
|
59
|
+
* child's attribute layout. Consumed by the node's type inference and by the
|
|
60
|
+
* runtime emitter (via {@link AsyncGatherNode.getZipByKeyIndices}).
|
|
61
|
+
*/
|
|
62
|
+
export interface ZipByKeyIndices {
|
|
63
|
+
/** Per branch, the column index of each key attribute, in `branchKeyAttrs[b]` order. */
|
|
64
|
+
readonly branchKeyIndices: readonly (readonly number[])[];
|
|
65
|
+
/** Per branch, the column indices of non-key columns, in declared order. */
|
|
66
|
+
readonly branchNonKeyIndices: readonly (readonly number[])[];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Physical N-ary relational node that drives ≥ 2 independent (uncorrelated)
|
|
70
|
+
* child relations concurrently via {@link ParallelDriver.drive} and combines
|
|
71
|
+
* their outputs with the configured {@link AsyncGatherCombinator}.
|
|
72
|
+
*
|
|
73
|
+
* Properties:
|
|
74
|
+
*
|
|
75
|
+
* - `unionAll`: ordering is dropped (arrival-order interleave is
|
|
76
|
+
* non-deterministic); FDs / ECs / constant bindings / domain constraints
|
|
77
|
+
* are dropped (same conservatism `SetOperationNode.computePhysical` already
|
|
78
|
+
* applies); attribute IDs mirror `children[0]` to preserve downstream
|
|
79
|
+
* `ORDER BY` references; `isSet` is `false` (duplicates allowed); per-column
|
|
80
|
+
* nullability is the OR across children.
|
|
81
|
+
*
|
|
82
|
+
* - `crossProduct`: ordering is dropped; FDs / ECs / bindings / domain
|
|
83
|
+
* constraints are the pairwise N-ary fold of the children (the same fold
|
|
84
|
+
* `JoinNode(cross)` does, repeated); attribute IDs are the verbatim
|
|
85
|
+
* concatenation of children; per-column nullability flows through
|
|
86
|
+
* unchanged. Cartesian product order is deterministic-but-unspecified
|
|
87
|
+
* (a function of the per-branch arrival order). **Buffers all branches
|
|
88
|
+
* before yielding** — not suitable for large branches.
|
|
89
|
+
*
|
|
90
|
+
* `concurrencySafe` and `expectedLatencyMs` are NOT propagated by this node:
|
|
91
|
+
* those fields are not yet defined on {@link PhysicalProperties} (the parallel
|
|
92
|
+
* track has not landed them). Once a successor ticket (5.5 or later) adds
|
|
93
|
+
* them, the intended merge is `AND` across children for `concurrencySafe` and
|
|
94
|
+
* `max` across children for `expectedLatencyMs`; update this node's
|
|
95
|
+
* `computePhysical` at that time. The fields currently inherited from
|
|
96
|
+
* `PlanNode.physical`'s default child-merge are `deterministic`,
|
|
97
|
+
* `idempotent`, and `readonly` (AND across children).
|
|
98
|
+
*/
|
|
99
|
+
export declare class AsyncGatherNode extends PlanNode implements RelationalPlanNode {
|
|
100
|
+
readonly children: readonly RelationalPlanNode[];
|
|
101
|
+
readonly combinator: AsyncGatherCombinator;
|
|
102
|
+
readonly concurrencyCap: number;
|
|
103
|
+
readonly preserveAttributeIds?: readonly Attribute[] | undefined;
|
|
104
|
+
readonly nodeType = PlanNodeType.AsyncGather;
|
|
105
|
+
private attributesCache;
|
|
106
|
+
private zipIndicesCache;
|
|
107
|
+
constructor(scope: Scope, children: readonly RelationalPlanNode[], combinator: AsyncGatherCombinator, concurrencyCap: number, preserveAttributeIds?: readonly Attribute[] | undefined);
|
|
108
|
+
private static validateConstruction;
|
|
109
|
+
/**
|
|
110
|
+
* Validate a `zipByKey` combinator under the per-branch-refs representation:
|
|
111
|
+
*
|
|
112
|
+
* - `branchKeyAttrs` has one list per branch, all of the same non-empty
|
|
113
|
+
* length K.
|
|
114
|
+
* - `outputKeyAttrs` has length K, its ids are pairwise distinct AND disjoint
|
|
115
|
+
* from every child attribute id (load-bearing: a collision would let the
|
|
116
|
+
* provenance walk treat an output key id as forwarded, breaking the
|
|
117
|
+
* origination contract this design relies on).
|
|
118
|
+
* - each `branchKeyAttrs[b][k]` resolves in branch b.
|
|
119
|
+
* - per key position, affinity (physical storage class) agrees across all
|
|
120
|
+
* branches (the codebase has no distinct affinity field). Nullability may
|
|
121
|
+
* differ between branches; it gets OR'd in {@link getType}.
|
|
122
|
+
* - per key position, the declared collation agrees across all branches. The
|
|
123
|
+
* runtime key comparator derives solely from branch 0's key-column
|
|
124
|
+
* collations, so a disagreement would let branch 0 win silently and merge
|
|
125
|
+
* (or fail to merge) rows under the wrong collation. Guarding it here means
|
|
126
|
+
* both the recognition rule and manual construction are protected. An
|
|
127
|
+
* absent `collationName` normalizes to the binary collation.
|
|
128
|
+
*/
|
|
129
|
+
private static validateZipByKey;
|
|
130
|
+
/**
|
|
131
|
+
* Resolve each branch's own `branchKeyAttrs[b]` list against that branch's
|
|
132
|
+
* attribute layout, yielding per-branch key/non-key column indices. Memoised;
|
|
133
|
+
* only valid for a `zipByKey` combinator.
|
|
134
|
+
*/
|
|
135
|
+
private computeZipByKeyIndices;
|
|
136
|
+
/** Public accessor for the resolved zipByKey index mapping (used by the emitter). */
|
|
137
|
+
getZipByKeyIndices(): ZipByKeyIndices;
|
|
138
|
+
private buildAttributes;
|
|
139
|
+
/**
|
|
140
|
+
* Build the `zipByKey` output attribute layout: the K merged key attributes
|
|
141
|
+
* first (type/nullability/collation derived from branch 0's key column at
|
|
142
|
+
* position k, nullability OR'd across branches because a NULL-keyed row can
|
|
143
|
+
* surface — but **carrying the gather-minted `outputKeyAttrs[k]` id**, since
|
|
144
|
+
* the gather originates these merged columns), then each branch's non-key
|
|
145
|
+
* attributes in declared order, each forced nullable (NULL when the branch is
|
|
146
|
+
* absent for a key). Non-key attribute IDs are unique across branches and the
|
|
147
|
+
* minted key ids are disjoint from all of them, so there is no ID collision.
|
|
148
|
+
*/
|
|
149
|
+
private buildZipByKeyAttributes;
|
|
150
|
+
getAttributes(): readonly Attribute[];
|
|
151
|
+
getType(): RelationType;
|
|
152
|
+
/**
|
|
153
|
+
* Build the `zipByKey` output relation type. Column layout mirrors
|
|
154
|
+
* {@link buildZipByKeyAttributes}: deduped key columns (nullability OR'd),
|
|
155
|
+
* then each branch's non-key columns forced nullable. The key columns
|
|
156
|
+
* `[0..K-1]` form the output's unique key — multiple NULL-keyed rows do not
|
|
157
|
+
* violate this (SQL UNIQUE permits multiple NULLs). `isSet` is false because
|
|
158
|
+
* NULL-keyed standalone rows can repeat.
|
|
159
|
+
*/
|
|
160
|
+
private getZipByKeyType;
|
|
161
|
+
computePhysical(childrenPhysical: PhysicalProperties[]): Partial<PhysicalProperties>;
|
|
162
|
+
getChildren(): readonly PlanNode[];
|
|
163
|
+
getRelations(): readonly RelationalPlanNode[];
|
|
164
|
+
withChildren(newChildren: readonly PlanNode[]): PlanNode;
|
|
165
|
+
get estimatedRows(): number | undefined;
|
|
166
|
+
toString(): string;
|
|
167
|
+
getLogicalAttributes(): Record<string, unknown>;
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=async-gather-node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-gather-node.d.ts","sourceRoot":"","sources":["../../../../src/planner/nodes/async-gather-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,KAAK,EACX,kBAAkB,EAClB,SAAS,EACT,kBAAkB,EAIlB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,YAAY,EAAU,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAgBhD;;;;;;;;;;;;;;;;;;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