@quereus/quereus 0.1.0 → 0.2.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.
- package/README.md +47 -23
- package/dist/src/core/database.d.ts +22 -4
- package/dist/src/core/database.d.ts.map +1 -1
- package/dist/src/core/database.js +44 -6
- package/dist/src/core/database.js.map +1 -1
- package/dist/src/core/statement.d.ts +0 -7
- package/dist/src/core/statement.d.ts.map +1 -1
- package/dist/src/core/statement.js +1 -51
- package/dist/src/core/statement.js.map +1 -1
- package/dist/src/func/builtins/explain.d.ts.map +1 -1
- package/dist/src/func/builtins/explain.js +0 -11
- package/dist/src/func/builtins/explain.js.map +1 -1
- package/dist/src/index.d.ts +13 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +5 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/parser/ast.d.ts +9 -2
- package/dist/src/parser/ast.d.ts.map +1 -1
- package/dist/src/parser/parser.d.ts.map +1 -1
- package/dist/src/parser/parser.js +40 -44
- package/dist/src/parser/parser.js.map +1 -1
- package/dist/src/planner/analysis/const-pass.d.ts.map +1 -1
- package/dist/src/planner/analysis/const-pass.js +12 -6
- package/dist/src/planner/analysis/const-pass.js.map +1 -1
- package/dist/src/planner/building/constraint-builder.d.ts +11 -0
- package/dist/src/planner/building/constraint-builder.d.ts.map +1 -0
- package/dist/src/planner/building/constraint-builder.js +79 -0
- package/dist/src/planner/building/constraint-builder.js.map +1 -0
- package/dist/src/planner/building/delete.d.ts.map +1 -1
- package/dist/src/planner/building/delete.js +6 -3
- package/dist/src/planner/building/delete.js.map +1 -1
- package/dist/src/planner/building/expression.d.ts +3 -0
- package/dist/src/planner/building/expression.d.ts.map +1 -1
- package/dist/src/planner/building/expression.js +33 -7
- package/dist/src/planner/building/expression.js.map +1 -1
- package/dist/src/planner/building/insert.d.ts.map +1 -1
- package/dist/src/planner/building/insert.js +4 -1
- package/dist/src/planner/building/insert.js.map +1 -1
- package/dist/src/planner/building/select-aggregates.d.ts.map +1 -1
- package/dist/src/planner/building/select-aggregates.js +46 -9
- package/dist/src/planner/building/select-aggregates.js.map +1 -1
- package/dist/src/planner/building/select-context.js +20 -11
- package/dist/src/planner/building/select-context.js.map +1 -1
- package/dist/src/planner/building/select-modifiers.d.ts +5 -3
- package/dist/src/planner/building/select-modifiers.d.ts.map +1 -1
- package/dist/src/planner/building/select-modifiers.js +29 -20
- package/dist/src/planner/building/select-modifiers.js.map +1 -1
- package/dist/src/planner/building/select-projections.d.ts +3 -1
- package/dist/src/planner/building/select-projections.d.ts.map +1 -1
- package/dist/src/planner/building/select-projections.js +15 -20
- package/dist/src/planner/building/select-projections.js.map +1 -1
- package/dist/src/planner/building/select-window.d.ts.map +1 -1
- package/dist/src/planner/building/select-window.js +6 -3
- package/dist/src/planner/building/select-window.js.map +1 -1
- package/dist/src/planner/building/select.d.ts +25 -2
- package/dist/src/planner/building/select.d.ts.map +1 -1
- package/dist/src/planner/building/select.js +147 -24
- package/dist/src/planner/building/select.js.map +1 -1
- package/dist/src/planner/building/table.d.ts +0 -10
- package/dist/src/planner/building/table.d.ts.map +1 -1
- package/dist/src/planner/building/table.js +1 -35
- package/dist/src/planner/building/table.js.map +1 -1
- package/dist/src/planner/building/update.d.ts.map +1 -1
- package/dist/src/planner/building/update.js +7 -4
- package/dist/src/planner/building/update.js.map +1 -1
- package/dist/src/planner/building/with.d.ts.map +1 -1
- package/dist/src/planner/building/with.js +7 -8
- package/dist/src/planner/building/with.js.map +1 -1
- package/dist/src/planner/cache/correlation-detector.d.ts +11 -0
- package/dist/src/planner/cache/correlation-detector.d.ts.map +1 -0
- package/dist/src/planner/cache/correlation-detector.js +73 -0
- package/dist/src/planner/cache/correlation-detector.js.map +1 -0
- package/dist/src/planner/cache/materialization-advisory.d.ts +12 -18
- package/dist/src/planner/cache/materialization-advisory.d.ts.map +1 -1
- package/dist/src/planner/cache/materialization-advisory.js +65 -46
- package/dist/src/planner/cache/materialization-advisory.js.map +1 -1
- package/dist/src/planner/cache/reference-graph.d.ts +14 -9
- package/dist/src/planner/cache/reference-graph.d.ts.map +1 -1
- package/dist/src/planner/cache/reference-graph.js +93 -84
- package/dist/src/planner/cache/reference-graph.js.map +1 -1
- package/dist/src/planner/debug.d.ts +25 -0
- package/dist/src/planner/debug.d.ts.map +1 -1
- package/dist/src/planner/debug.js +127 -0
- package/dist/src/planner/debug.js.map +1 -1
- package/dist/src/planner/framework/context.d.ts +11 -0
- package/dist/src/planner/framework/context.d.ts.map +1 -1
- package/dist/src/planner/framework/context.js +25 -2
- package/dist/src/planner/framework/context.js.map +1 -1
- package/dist/src/planner/framework/registry.d.ts +3 -7
- package/dist/src/planner/framework/registry.d.ts.map +1 -1
- package/dist/src/planner/framework/registry.js +20 -31
- package/dist/src/planner/framework/registry.js.map +1 -1
- package/dist/src/planner/nodes/add-constraint-node.d.ts +2 -1
- package/dist/src/planner/nodes/add-constraint-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/add-constraint-node.js +3 -0
- package/dist/src/planner/nodes/add-constraint-node.js.map +1 -1
- package/dist/src/planner/nodes/aggregate-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/aggregate-node.js +6 -4
- package/dist/src/planner/nodes/aggregate-node.js.map +1 -1
- package/dist/src/planner/nodes/cache-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/cache-node.js +2 -2
- package/dist/src/planner/nodes/cache-node.js.map +1 -1
- package/dist/src/planner/nodes/constraint-check-node.d.ts +11 -4
- package/dist/src/planner/nodes/constraint-check-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/constraint-check-node.js +38 -12
- package/dist/src/planner/nodes/constraint-check-node.js.map +1 -1
- package/dist/src/planner/nodes/create-index-node.d.ts +2 -1
- package/dist/src/planner/nodes/create-index-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/create-index-node.js +3 -0
- package/dist/src/planner/nodes/create-index-node.js.map +1 -1
- package/dist/src/planner/nodes/create-table-node.d.ts +2 -1
- package/dist/src/planner/nodes/create-table-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/create-table-node.js +3 -0
- package/dist/src/planner/nodes/create-table-node.js.map +1 -1
- package/dist/src/planner/nodes/create-view-node.d.ts +2 -1
- package/dist/src/planner/nodes/create-view-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/create-view-node.js +3 -0
- package/dist/src/planner/nodes/create-view-node.js.map +1 -1
- package/dist/src/planner/nodes/cte-node.d.ts +1 -1
- package/dist/src/planner/nodes/cte-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/cte-node.js +33 -12
- package/dist/src/planner/nodes/cte-node.js.map +1 -1
- package/dist/src/planner/nodes/cte-reference-node.d.ts +18 -4
- package/dist/src/planner/nodes/cte-reference-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/cte-reference-node.js +40 -10
- package/dist/src/planner/nodes/cte-reference-node.js.map +1 -1
- package/dist/src/planner/nodes/delete-node.d.ts +4 -3
- package/dist/src/planner/nodes/delete-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/delete-node.js +20 -6
- package/dist/src/planner/nodes/delete-node.js.map +1 -1
- package/dist/src/planner/nodes/distinct-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/distinct-node.js +2 -2
- package/dist/src/planner/nodes/distinct-node.js.map +1 -1
- package/dist/src/planner/nodes/dml-executor-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/dml-executor-node.js +2 -2
- package/dist/src/planner/nodes/dml-executor-node.js.map +1 -1
- package/dist/src/planner/nodes/drop-table-node.d.ts +2 -1
- package/dist/src/planner/nodes/drop-table-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/drop-table-node.js +3 -0
- package/dist/src/planner/nodes/drop-table-node.js.map +1 -1
- package/dist/src/planner/nodes/drop-view-node.d.ts +2 -1
- package/dist/src/planner/nodes/drop-view-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/drop-view-node.js +3 -0
- package/dist/src/planner/nodes/drop-view-node.js.map +1 -1
- package/dist/src/planner/nodes/filter.d.ts.map +1 -1
- package/dist/src/planner/nodes/filter.js +3 -3
- package/dist/src/planner/nodes/filter.js.map +1 -1
- package/dist/src/planner/nodes/insert-node.d.ts +2 -1
- package/dist/src/planner/nodes/insert-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/insert-node.js +18 -5
- package/dist/src/planner/nodes/insert-node.js.map +1 -1
- package/dist/src/planner/nodes/internal-recursive-cte-ref-node.d.ts +28 -0
- package/dist/src/planner/nodes/internal-recursive-cte-ref-node.d.ts.map +1 -0
- package/dist/src/planner/nodes/internal-recursive-cte-ref-node.js +69 -0
- package/dist/src/planner/nodes/internal-recursive-cte-ref-node.js.map +1 -0
- package/dist/src/planner/nodes/join-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/join-node.js +3 -3
- package/dist/src/planner/nodes/join-node.js.map +1 -1
- package/dist/src/planner/nodes/limit-offset.d.ts.map +1 -1
- package/dist/src/planner/nodes/limit-offset.js +2 -2
- package/dist/src/planner/nodes/limit-offset.js.map +1 -1
- package/dist/src/planner/nodes/plan-node-type.d.ts +1 -1
- package/dist/src/planner/nodes/plan-node-type.d.ts.map +1 -1
- package/dist/src/planner/nodes/plan-node-type.js +1 -1
- package/dist/src/planner/nodes/plan-node-type.js.map +1 -1
- package/dist/src/planner/nodes/plan-node.d.ts +23 -0
- package/dist/src/planner/nodes/plan-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/plan-node.js +25 -2
- package/dist/src/planner/nodes/plan-node.js.map +1 -1
- package/dist/src/planner/nodes/project-node.d.ts +5 -1
- package/dist/src/planner/nodes/project-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/project-node.js +39 -20
- package/dist/src/planner/nodes/project-node.js.map +1 -1
- package/dist/src/planner/nodes/recursive-cte-node.d.ts +2 -2
- package/dist/src/planner/nodes/recursive-cte-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/recursive-cte-node.js +20 -8
- package/dist/src/planner/nodes/recursive-cte-node.js.map +1 -1
- package/dist/src/planner/nodes/reference.d.ts.map +1 -1
- package/dist/src/planner/nodes/reference.js +4 -2
- package/dist/src/planner/nodes/reference.js.map +1 -1
- package/dist/src/planner/nodes/returning-node.d.ts +1 -1
- package/dist/src/planner/nodes/returning-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/returning-node.js +21 -13
- package/dist/src/planner/nodes/returning-node.js.map +1 -1
- package/dist/src/planner/nodes/scalar.d.ts +26 -2
- package/dist/src/planner/nodes/scalar.d.ts.map +1 -1
- package/dist/src/planner/nodes/scalar.js +82 -10
- package/dist/src/planner/nodes/scalar.js.map +1 -1
- package/dist/src/planner/nodes/sequencing-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/sequencing-node.js +2 -2
- package/dist/src/planner/nodes/sequencing-node.js.map +1 -1
- package/dist/src/planner/nodes/set-operation-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/set-operation-node.js +3 -3
- package/dist/src/planner/nodes/set-operation-node.js.map +1 -1
- package/dist/src/planner/nodes/single-row.d.ts +4 -2
- package/dist/src/planner/nodes/single-row.d.ts.map +1 -1
- package/dist/src/planner/nodes/single-row.js +3 -0
- package/dist/src/planner/nodes/single-row.js.map +1 -1
- package/dist/src/planner/nodes/sink-node.d.ts +1 -1
- package/dist/src/planner/nodes/sink-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/sink-node.js +4 -4
- package/dist/src/planner/nodes/sink-node.js.map +1 -1
- package/dist/src/planner/nodes/sort.d.ts.map +1 -1
- package/dist/src/planner/nodes/sort.js +2 -2
- package/dist/src/planner/nodes/sort.js.map +1 -1
- package/dist/src/planner/nodes/stream-aggregate.d.ts +1 -0
- package/dist/src/planner/nodes/stream-aggregate.d.ts.map +1 -1
- package/dist/src/planner/nodes/stream-aggregate.js +64 -11
- package/dist/src/planner/nodes/stream-aggregate.js.map +1 -1
- package/dist/src/planner/nodes/subquery.d.ts +4 -4
- package/dist/src/planner/nodes/subquery.d.ts.map +1 -1
- package/dist/src/planner/nodes/subquery.js +68 -23
- package/dist/src/planner/nodes/subquery.js.map +1 -1
- package/dist/src/planner/nodes/table-access-nodes.d.ts +83 -0
- package/dist/src/planner/nodes/table-access-nodes.d.ts.map +1 -0
- package/dist/src/planner/nodes/table-access-nodes.js +226 -0
- package/dist/src/planner/nodes/table-access-nodes.js.map +1 -0
- package/dist/src/planner/nodes/update-node.d.ts +4 -2
- package/dist/src/planner/nodes/update-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/update-node.js +26 -13
- package/dist/src/planner/nodes/update-node.js.map +1 -1
- package/dist/src/planner/nodes/window-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/window-node.js +25 -23
- package/dist/src/planner/nodes/window-node.js.map +1 -1
- package/dist/src/planner/optimizer.d.ts.map +1 -1
- package/dist/src/planner/optimizer.js +46 -50
- package/dist/src/planner/optimizer.js.map +1 -1
- package/dist/src/planner/planning-context.d.ts +13 -0
- package/dist/src/planner/planning-context.d.ts.map +1 -1
- package/dist/src/planner/planning-context.js.map +1 -1
- package/dist/src/planner/rules/access/rule-select-access-path.d.ts +1 -1
- 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 +59 -53
- package/dist/src/planner/rules/access/rule-select-access-path.js.map +1 -1
- package/dist/src/planner/rules/aggregate/rule-aggregate-streaming.d.ts.map +1 -1
- package/dist/src/planner/rules/aggregate/rule-aggregate-streaming.js +62 -2
- package/dist/src/planner/rules/aggregate/rule-aggregate-streaming.js.map +1 -1
- package/dist/src/planner/rules/cache/rule-materialization-advisory.d.ts.map +1 -1
- package/dist/src/planner/rules/cache/rule-materialization-advisory.js +31 -24
- package/dist/src/planner/rules/cache/rule-materialization-advisory.js.map +1 -1
- package/dist/src/planner/scopes/base.d.ts +0 -10
- package/dist/src/planner/scopes/base.d.ts.map +1 -1
- package/dist/src/planner/scopes/base.js +0 -14
- package/dist/src/planner/scopes/base.js.map +1 -1
- package/dist/src/planner/scopes/empty.d.ts +0 -2
- package/dist/src/planner/scopes/empty.d.ts.map +1 -1
- package/dist/src/planner/scopes/empty.js +0 -8
- package/dist/src/planner/scopes/empty.js.map +1 -1
- package/dist/src/planner/scopes/multi.d.ts.map +1 -1
- package/dist/src/planner/scopes/multi.js +0 -1
- package/dist/src/planner/scopes/multi.js.map +1 -1
- package/dist/src/planner/scopes/param.d.ts.map +1 -1
- package/dist/src/planner/scopes/param.js +0 -1
- package/dist/src/planner/scopes/param.js.map +1 -1
- package/dist/src/planner/scopes/registered.d.ts +0 -10
- package/dist/src/planner/scopes/registered.d.ts.map +1 -1
- package/dist/src/planner/scopes/registered.js +1 -17
- package/dist/src/planner/scopes/registered.js.map +1 -1
- package/dist/src/planner/scopes/scope.d.ts +0 -8
- package/dist/src/planner/scopes/scope.d.ts.map +1 -1
- package/dist/src/planner/validation/plan-validator.d.ts.map +1 -1
- package/dist/src/planner/validation/plan-validator.js +1 -7
- package/dist/src/planner/validation/plan-validator.js.map +1 -1
- package/dist/src/runtime/context-helpers.d.ts +45 -0
- package/dist/src/runtime/context-helpers.d.ts.map +1 -0
- package/dist/src/runtime/context-helpers.js +139 -0
- package/dist/src/runtime/context-helpers.js.map +1 -0
- package/dist/src/runtime/emission-context.d.ts +1 -0
- package/dist/src/runtime/emission-context.d.ts.map +1 -1
- package/dist/src/runtime/emission-context.js +2 -1
- package/dist/src/runtime/emission-context.js.map +1 -1
- package/dist/src/runtime/emit/aggregate.d.ts.map +1 -1
- package/dist/src/runtime/emit/aggregate.js +119 -86
- package/dist/src/runtime/emit/aggregate.js.map +1 -1
- package/dist/src/runtime/emit/between.d.ts +5 -0
- package/dist/src/runtime/emit/between.d.ts.map +1 -0
- package/dist/src/runtime/emit/between.js +38 -0
- package/dist/src/runtime/emit/between.js.map +1 -0
- package/dist/src/runtime/emit/binary.d.ts +0 -1
- package/dist/src/runtime/emit/binary.d.ts.map +1 -1
- package/dist/src/runtime/emit/binary.js +0 -36
- package/dist/src/runtime/emit/binary.js.map +1 -1
- package/dist/src/runtime/emit/column-reference.d.ts.map +1 -1
- package/dist/src/runtime/emit/column-reference.js +2 -26
- package/dist/src/runtime/emit/column-reference.js.map +1 -1
- package/dist/src/runtime/emit/constraint-check.d.ts.map +1 -1
- package/dist/src/runtime/emit/constraint-check.js +14 -121
- package/dist/src/runtime/emit/constraint-check.js.map +1 -1
- package/dist/src/runtime/emit/cte-reference.d.ts.map +1 -1
- package/dist/src/runtime/emit/cte-reference.js +16 -48
- package/dist/src/runtime/emit/cte-reference.js.map +1 -1
- package/dist/src/runtime/emit/distinct.d.ts.map +1 -1
- package/dist/src/runtime/emit/distinct.js +2 -8
- package/dist/src/runtime/emit/distinct.js.map +1 -1
- package/dist/src/runtime/emit/filter.d.ts.map +1 -1
- package/dist/src/runtime/emit/filter.js +6 -13
- package/dist/src/runtime/emit/filter.js.map +1 -1
- package/dist/src/runtime/emit/internal-recursive-cte-ref.d.ts +5 -0
- package/dist/src/runtime/emit/internal-recursive-cte-ref.d.ts.map +1 -0
- package/dist/src/runtime/emit/internal-recursive-cte-ref.js +23 -0
- package/dist/src/runtime/emit/internal-recursive-cte-ref.js.map +1 -0
- package/dist/src/runtime/emit/join.d.ts.map +1 -1
- package/dist/src/runtime/emit/join.js +40 -40
- package/dist/src/runtime/emit/join.js.map +1 -1
- package/dist/src/runtime/emit/project.d.ts.map +1 -1
- package/dist/src/runtime/emit/project.js +13 -13
- package/dist/src/runtime/emit/project.js.map +1 -1
- package/dist/src/runtime/emit/recursive-cte.d.ts.map +1 -1
- package/dist/src/runtime/emit/recursive-cte.js +3 -14
- package/dist/src/runtime/emit/recursive-cte.js.map +1 -1
- package/dist/src/runtime/emit/returning.d.ts.map +1 -1
- package/dist/src/runtime/emit/returning.js +7 -14
- package/dist/src/runtime/emit/returning.js.map +1 -1
- package/dist/src/runtime/emit/scan.d.ts +5 -2
- package/dist/src/runtime/emit/scan.d.ts.map +1 -1
- package/dist/src/runtime/emit/scan.js +21 -17
- package/dist/src/runtime/emit/scan.js.map +1 -1
- package/dist/src/runtime/emit/sort.d.ts.map +1 -1
- package/dist/src/runtime/emit/sort.js +8 -11
- package/dist/src/runtime/emit/sort.js.map +1 -1
- package/dist/src/runtime/emit/subquery.d.ts.map +1 -1
- package/dist/src/runtime/emit/subquery.js +95 -40
- package/dist/src/runtime/emit/subquery.js.map +1 -1
- package/dist/src/runtime/emit/table-valued-function.d.ts.map +1 -1
- package/dist/src/runtime/emit/table-valued-function.js +7 -22
- package/dist/src/runtime/emit/table-valued-function.js.map +1 -1
- package/dist/src/runtime/emit/update.d.ts.map +1 -1
- package/dist/src/runtime/emit/update.js +20 -27
- package/dist/src/runtime/emit/update.js.map +1 -1
- package/dist/src/runtime/emit/window.d.ts.map +1 -1
- package/dist/src/runtime/emit/window.js +55 -83
- package/dist/src/runtime/emit/window.js.map +1 -1
- package/dist/src/runtime/emitters.d.ts.map +1 -1
- package/dist/src/runtime/emitters.js +49 -1
- package/dist/src/runtime/emitters.js.map +1 -1
- package/dist/src/runtime/register.d.ts.map +1 -1
- package/dist/src/runtime/register.js +5 -4
- package/dist/src/runtime/register.js.map +1 -1
- package/dist/src/runtime/scheduler.d.ts.map +1 -1
- package/dist/src/runtime/scheduler.js +47 -42
- package/dist/src/runtime/scheduler.js.map +1 -1
- package/dist/src/runtime/types.d.ts +34 -0
- package/dist/src/runtime/types.d.ts.map +1 -1
- package/dist/src/runtime/types.js +21 -0
- package/dist/src/runtime/types.js.map +1 -1
- package/dist/src/schema/manager.d.ts.map +1 -1
- package/dist/src/schema/manager.js +29 -16
- package/dist/src/schema/manager.js.map +1 -1
- package/dist/src/util/plugin-loader.d.ts +10 -1
- package/dist/src/util/plugin-loader.d.ts.map +1 -1
- package/dist/src/util/plugin-loader.js +56 -1
- package/dist/src/util/plugin-loader.js.map +1 -1
- package/dist/src/util/working-table-iterable.d.ts.map +1 -1
- package/dist/src/util/working-table-iterable.js +8 -8
- package/dist/src/util/working-table-iterable.js.map +1 -1
- package/dist/src/vtab/manifest.d.ts +36 -0
- package/dist/src/vtab/manifest.d.ts.map +1 -1
- package/package.json +8 -3
- package/src/core/database.ts +48 -6
- package/src/core/statement.ts +1 -49
- package/src/func/builtins/explain.ts +0 -11
- package/src/index.ts +39 -5
- package/src/parser/ast.ts +11 -2
- package/src/parser/parser.ts +40 -47
- package/src/planner/analysis/const-pass.ts +281 -270
- package/src/planner/building/constraint-builder.ts +114 -0
- package/src/planner/building/delete.ts +16 -3
- package/src/planner/building/expression.ts +35 -7
- package/src/planner/building/insert.ts +14 -1
- package/src/planner/building/select-aggregates.ts +57 -11
- package/src/planner/building/select-context.ts +22 -12
- package/src/planner/building/select-modifiers.ts +35 -21
- package/src/planner/building/select-projections.ts +25 -26
- package/src/planner/building/select-window.ts +14 -9
- package/src/planner/building/select.ts +163 -31
- package/src/planner/building/table.ts +1 -40
- package/src/planner/building/update.ts +19 -4
- package/src/planner/building/with.ts +12 -13
- package/src/planner/cache/correlation-detector.ts +83 -0
- package/src/planner/cache/materialization-advisory.ts +71 -50
- package/src/planner/cache/reference-graph.ts +115 -91
- package/src/planner/debug.ts +163 -0
- package/src/planner/framework/context.ts +36 -2
- package/src/planner/framework/registry.ts +261 -274
- package/src/planner/nodes/add-constraint-node.ts +5 -1
- package/src/planner/nodes/aggregate-node.ts +6 -4
- package/src/planner/nodes/cache-node.ts +2 -2
- package/src/planner/nodes/constraint-check-node.ts +47 -13
- package/src/planner/nodes/create-index-node.ts +5 -1
- package/src/planner/nodes/create-table-node.ts +5 -1
- package/src/planner/nodes/create-view-node.ts +5 -1
- package/src/planner/nodes/cte-node.ts +45 -14
- package/src/planner/nodes/cte-reference-node.ts +49 -13
- package/src/planner/nodes/delete-node.ts +31 -7
- package/src/planner/nodes/distinct-node.ts +2 -2
- package/src/planner/nodes/dml-executor-node.ts +2 -2
- package/src/planner/nodes/drop-table-node.ts +5 -1
- package/src/planner/nodes/drop-view-node.ts +5 -1
- package/src/planner/nodes/filter.ts +3 -3
- package/src/planner/nodes/function.ts +93 -93
- package/src/planner/nodes/insert-node.ts +28 -5
- package/src/planner/nodes/internal-recursive-cte-ref-node.ts +76 -0
- package/src/planner/nodes/join-node.ts +3 -3
- package/src/planner/nodes/limit-offset.ts +2 -2
- package/src/planner/nodes/plan-node-type.ts +1 -1
- package/src/planner/nodes/plan-node.ts +39 -2
- package/src/planner/nodes/project-node.ts +39 -19
- package/src/planner/nodes/recursive-cte-node.ts +37 -9
- package/src/planner/nodes/reference.ts +4 -2
- package/src/planner/nodes/returning-node.ts +25 -13
- package/src/planner/nodes/scalar.ts +95 -11
- package/src/planner/nodes/sequencing-node.ts +2 -2
- package/src/planner/nodes/set-operation-node.ts +3 -3
- package/src/planner/nodes/single-row.ts +7 -2
- package/src/planner/nodes/sink-node.ts +5 -5
- package/src/planner/nodes/sort.ts +2 -2
- package/src/planner/nodes/stream-aggregate.ts +76 -12
- package/src/planner/nodes/subquery.ts +90 -27
- package/src/planner/nodes/{physical-access-nodes.ts → table-access-nodes.ts} +6 -6
- package/src/planner/nodes/update-node.ts +31 -13
- package/src/planner/nodes/window-node.ts +28 -22
- package/src/planner/optimizer.ts +257 -263
- package/src/planner/planning-context.ts +15 -0
- package/src/planner/rules/access/rule-select-access-path.ts +68 -64
- package/src/planner/rules/aggregate/rule-aggregate-streaming.ts +74 -2
- package/src/planner/rules/cache/rule-materialization-advisory.ts +31 -27
- package/src/planner/scopes/base.ts +0 -17
- package/src/planner/scopes/empty.ts +0 -10
- package/src/planner/scopes/multi.ts +0 -1
- package/src/planner/scopes/param.ts +0 -1
- package/src/planner/scopes/registered.ts +1 -20
- package/src/planner/scopes/scope.ts +0 -12
- package/src/planner/validation/plan-validator.ts +1 -8
- package/src/runtime/context-helpers.ts +191 -0
- package/src/runtime/emission-context.ts +5 -2
- package/src/runtime/emit/aggregate.ts +131 -85
- package/src/runtime/emit/between.ts +51 -0
- package/src/runtime/emit/binary.ts +0 -46
- package/src/runtime/emit/column-reference.ts +3 -36
- package/src/runtime/emit/constraint-check.ts +17 -142
- package/src/runtime/emit/cte-reference.ts +23 -60
- package/src/runtime/emit/distinct.ts +2 -7
- package/src/runtime/emit/filter.ts +6 -13
- package/src/runtime/emit/internal-recursive-cte-ref.ts +37 -0
- package/src/runtime/emit/join.ts +45 -43
- package/src/runtime/emit/project.ts +18 -12
- package/src/runtime/emit/recursive-cte.ts +3 -12
- package/src/runtime/emit/returning.ts +7 -14
- package/src/runtime/emit/scan.ts +25 -23
- package/src/runtime/emit/sort.ts +8 -11
- package/src/runtime/emit/subquery.ts +108 -48
- package/src/runtime/emit/table-valued-function.ts +7 -20
- package/src/runtime/emit/update.ts +22 -29
- package/src/runtime/emit/window.ts +74 -88
- package/src/runtime/emitters.ts +52 -1
- package/src/runtime/register.ts +5 -4
- package/src/runtime/scheduler.ts +54 -54
- package/src/runtime/types.ts +45 -0
- package/src/schema/manager.ts +34 -19
- package/src/util/plugin-loader.ts +78 -4
- package/src/util/working-table-iterable.ts +15 -7
- package/src/vtab/manifest.ts +42 -0
- package/src/planner/nodes/scan.ts +0 -103
- package/src/planner/rules/physical/rule-mark-physical.ts +0 -37
- package/src/runtime/emit/table-reference.ts +0 -92
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PlanNodeType } from './plan-node-type.js';
|
|
2
|
-
import { PlanNode, type RelationalPlanNode, type ScalarPlanNode, type UnaryRelationalNode, type Attribute } from './plan-node.js';
|
|
2
|
+
import { PlanNode, type RelationalPlanNode, type ScalarPlanNode, type UnaryRelationalNode, type Attribute, isRelationalNode } from './plan-node.js';
|
|
3
3
|
import type { RelationType } from '../../common/datatype.js';
|
|
4
4
|
import type { Scope } from '../scopes/scope.js';
|
|
5
5
|
import { Cached } from '../../util/cached.js';
|
|
@@ -95,7 +95,8 @@ export class AggregateNode extends PlanNode implements UnaryRelationalNode {
|
|
|
95
95
|
id: PlanNode.nextAttrId(),
|
|
96
96
|
name,
|
|
97
97
|
type: expr.getType(),
|
|
98
|
-
sourceRelation: `${this.nodeType}:${this.id}
|
|
98
|
+
sourceRelation: `${this.nodeType}:${this.id}`,
|
|
99
|
+
relationName: 'aggregate' // AggregateNode creates new relation context
|
|
99
100
|
});
|
|
100
101
|
});
|
|
101
102
|
|
|
@@ -105,7 +106,8 @@ export class AggregateNode extends PlanNode implements UnaryRelationalNode {
|
|
|
105
106
|
id: PlanNode.nextAttrId(),
|
|
106
107
|
name: agg.alias,
|
|
107
108
|
type: agg.expression.getType(),
|
|
108
|
-
sourceRelation: `${this.nodeType}:${this.id}
|
|
109
|
+
sourceRelation: `${this.nodeType}:${this.id}`,
|
|
110
|
+
relationName: 'aggregate' // AggregateNode creates new relation context
|
|
109
111
|
});
|
|
110
112
|
});
|
|
111
113
|
|
|
@@ -139,7 +141,7 @@ export class AggregateNode extends PlanNode implements UnaryRelationalNode {
|
|
|
139
141
|
const newAggregateExpressions = restChildren.slice(this.groupBy.length);
|
|
140
142
|
|
|
141
143
|
// Type check
|
|
142
|
-
if (!(
|
|
144
|
+
if (!isRelationalNode(newSource)) {
|
|
143
145
|
quereusError('AggregateNode: first child must be a RelationalPlanNode', StatusCode.INTERNAL);
|
|
144
146
|
}
|
|
145
147
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PlanNodeType } from './plan-node-type.js';
|
|
2
|
-
import { PlanNode, type RelationalPlanNode, type UnaryRelationalNode, type Attribute } from './plan-node.js';
|
|
2
|
+
import { PlanNode, type RelationalPlanNode, type UnaryRelationalNode, type Attribute, isRelationalNode } from './plan-node.js';
|
|
3
3
|
import type { RelationType } from '../../common/datatype.js';
|
|
4
4
|
import type { Scope } from '../scopes/scope.js';
|
|
5
5
|
import { StatusCode } from '../../common/types.js';
|
|
@@ -58,7 +58,7 @@ export class CacheNode extends PlanNode implements UnaryRelationalNode {
|
|
|
58
58
|
const [newSource] = newChildren;
|
|
59
59
|
|
|
60
60
|
// Type check
|
|
61
|
-
if (!(
|
|
61
|
+
if (!isRelationalNode(newSource)) {
|
|
62
62
|
quereusError('CacheNode: child must be a RelationalPlanNode', StatusCode.INTERNAL);
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import type { Scope } from '../scopes/scope.js';
|
|
2
|
-
import { PlanNode, type RelationalPlanNode, type Attribute, type RowDescriptor } from './plan-node.js';
|
|
2
|
+
import { PlanNode, type RelationalPlanNode, type Attribute, type RowDescriptor, type ScalarPlanNode, isRelationalNode } from './plan-node.js';
|
|
3
3
|
import { PlanNodeType } from './plan-node-type.js';
|
|
4
4
|
import type { TableReferenceNode } from './reference.js';
|
|
5
5
|
import type { RelationType } from '../../common/datatype.js';
|
|
6
6
|
import type { RowOp } from '../../schema/table.js';
|
|
7
|
+
import type { RowConstraintSchema } from '../../schema/table.js';
|
|
8
|
+
|
|
9
|
+
export interface ConstraintCheck {
|
|
10
|
+
constraint: RowConstraintSchema; // The constraint metadata
|
|
11
|
+
expression: ScalarPlanNode; // Pre-built expression node
|
|
12
|
+
}
|
|
7
13
|
|
|
8
14
|
/**
|
|
9
15
|
* Represents constraint checking for DML operations.
|
|
@@ -17,8 +23,10 @@ export class ConstraintCheckNode extends PlanNode implements RelationalPlanNode
|
|
|
17
23
|
public readonly source: RelationalPlanNode,
|
|
18
24
|
public readonly table: TableReferenceNode,
|
|
19
25
|
public readonly operation: RowOp,
|
|
20
|
-
public readonly oldRowDescriptor
|
|
21
|
-
public readonly newRowDescriptor
|
|
26
|
+
public readonly oldRowDescriptor: RowDescriptor | undefined,
|
|
27
|
+
public readonly newRowDescriptor: RowDescriptor | undefined,
|
|
28
|
+
public readonly flatRowDescriptor: RowDescriptor,
|
|
29
|
+
public readonly constraintChecks: ConstraintCheck[]
|
|
22
30
|
) {
|
|
23
31
|
super(scope);
|
|
24
32
|
}
|
|
@@ -37,26 +45,47 @@ export class ConstraintCheckNode extends PlanNode implements RelationalPlanNode
|
|
|
37
45
|
}
|
|
38
46
|
|
|
39
47
|
getChildren(): readonly PlanNode[] {
|
|
40
|
-
|
|
48
|
+
const children: PlanNode[] = [this.source];
|
|
49
|
+
// Add all constraint expression nodes as children so optimizer can see them
|
|
50
|
+
this.constraintChecks.forEach(check => {
|
|
51
|
+
children.push(check.expression);
|
|
52
|
+
});
|
|
53
|
+
return children;
|
|
41
54
|
}
|
|
42
55
|
|
|
43
56
|
withChildren(newChildren: readonly PlanNode[]): PlanNode {
|
|
44
|
-
|
|
45
|
-
|
|
57
|
+
const expectedChildren = 1 + this.constraintChecks.length;
|
|
58
|
+
if (newChildren.length !== expectedChildren) {
|
|
59
|
+
throw new Error(`ConstraintCheckNode expects ${expectedChildren} children, got ${newChildren.length}`);
|
|
46
60
|
}
|
|
47
61
|
|
|
48
|
-
const [newSource] = newChildren;
|
|
62
|
+
const [newSource, ...newConstraintExprs] = newChildren;
|
|
49
63
|
|
|
50
|
-
// Type check
|
|
51
|
-
if (!(
|
|
52
|
-
throw new Error('ConstraintCheckNode: child must be a RelationalPlanNode');
|
|
64
|
+
// Type check the source
|
|
65
|
+
if (!isRelationalNode(newSource)) {
|
|
66
|
+
throw new Error('ConstraintCheckNode: first child must be a RelationalPlanNode');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Type check constraint expressions
|
|
70
|
+
for (let i = 0; i < newConstraintExprs.length; i++) {
|
|
71
|
+
const expr = newConstraintExprs[i];
|
|
72
|
+
if (!('getType' in expr) || typeof (expr as any).getType !== 'function') {
|
|
73
|
+
throw new Error(`ConstraintCheckNode: constraint child ${i + 1} must be a ScalarPlanNode`);
|
|
74
|
+
}
|
|
53
75
|
}
|
|
54
76
|
|
|
55
77
|
// Return same instance if nothing changed
|
|
56
|
-
if (newSource === this.source
|
|
78
|
+
if (newSource === this.source &&
|
|
79
|
+
newConstraintExprs.every((expr, i) => expr === this.constraintChecks[i].expression)) {
|
|
57
80
|
return this;
|
|
58
81
|
}
|
|
59
82
|
|
|
83
|
+
// Rebuild constraint checks with new expressions
|
|
84
|
+
const newConstraintChecks = this.constraintChecks.map((check, i) => ({
|
|
85
|
+
...check,
|
|
86
|
+
expression: newConstraintExprs[i] as ScalarPlanNode
|
|
87
|
+
}));
|
|
88
|
+
|
|
60
89
|
// Create new instance
|
|
61
90
|
return new ConstraintCheckNode(
|
|
62
91
|
this.scope,
|
|
@@ -64,7 +93,9 @@ export class ConstraintCheckNode extends PlanNode implements RelationalPlanNode
|
|
|
64
93
|
this.table,
|
|
65
94
|
this.operation,
|
|
66
95
|
this.oldRowDescriptor,
|
|
67
|
-
this.newRowDescriptor
|
|
96
|
+
this.newRowDescriptor,
|
|
97
|
+
this.flatRowDescriptor,
|
|
98
|
+
newConstraintChecks
|
|
68
99
|
);
|
|
69
100
|
}
|
|
70
101
|
|
|
@@ -76,7 +107,8 @@ export class ConstraintCheckNode extends PlanNode implements RelationalPlanNode
|
|
|
76
107
|
const opName = this.operation === 1 ? 'INSERT' :
|
|
77
108
|
this.operation === 2 ? 'UPDATE' :
|
|
78
109
|
this.operation === 4 ? 'DELETE' : 'UNKNOWN';
|
|
79
|
-
|
|
110
|
+
const constraintCount = this.constraintChecks.length;
|
|
111
|
+
return `CHECK ${constraintCount} CONSTRAINTS ON ${opName}`;
|
|
80
112
|
}
|
|
81
113
|
|
|
82
114
|
override getLogicalAttributes(): Record<string, unknown> {
|
|
@@ -88,6 +120,8 @@ export class ConstraintCheckNode extends PlanNode implements RelationalPlanNode
|
|
|
88
120
|
table: this.table.tableSchema.name,
|
|
89
121
|
schema: this.table.tableSchema.schemaName,
|
|
90
122
|
operation: opName,
|
|
123
|
+
constraintCount: this.constraintChecks.length,
|
|
124
|
+
constraintNames: this.constraintChecks.map(c => c.constraint.name || '_unnamed'),
|
|
91
125
|
hasOldDescriptor: !!this.oldRowDescriptor,
|
|
92
126
|
hasNewDescriptor: !!this.newRowDescriptor,
|
|
93
127
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type * as AST from '../../parser/ast.js';
|
|
2
2
|
import type { Scope } from '../scopes/scope.js';
|
|
3
|
-
import { VoidNode } from './plan-node.js';
|
|
3
|
+
import { PhysicalProperties, VoidNode } from './plan-node.js';
|
|
4
4
|
import { PlanNodeType } from './plan-node-type.js';
|
|
5
5
|
import { expressionToString } from '../../util/ast-stringify.js';
|
|
6
6
|
|
|
@@ -34,4 +34,8 @@ export class CreateIndexNode extends VoidNode {
|
|
|
34
34
|
statement: expressionToString(this.statementAst as any) // Convert AST to string
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
+
|
|
38
|
+
override computePhysical(_children: readonly PhysicalProperties[]): Partial<PhysicalProperties> {
|
|
39
|
+
return { readonly: false };
|
|
40
|
+
}
|
|
37
41
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type * as AST from '../../parser/ast.js';
|
|
2
2
|
import type { Scope } from '../scopes/scope.js';
|
|
3
|
-
import { VoidNode } from './plan-node.js';
|
|
3
|
+
import { PhysicalProperties, VoidNode } from './plan-node.js';
|
|
4
4
|
import { PlanNodeType } from './plan-node-type.js';
|
|
5
5
|
import { expressionToString } from '../../util/ast-stringify.js';
|
|
6
6
|
|
|
@@ -28,4 +28,8 @@ export class CreateTableNode extends VoidNode {
|
|
|
28
28
|
statement: expressionToString(this.statementAst as any) // Convert AST to string
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
+
|
|
32
|
+
override computePhysical(_children: readonly PhysicalProperties[]): Partial<PhysicalProperties> {
|
|
33
|
+
return { readonly: false };
|
|
34
|
+
}
|
|
31
35
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as AST from '../../parser/ast.js';
|
|
2
|
-
import { VoidNode } from './plan-node.js';
|
|
2
|
+
import { PhysicalProperties, VoidNode } from './plan-node.js';
|
|
3
3
|
import { PlanNodeType } from './plan-node-type.js';
|
|
4
4
|
import type { Scope } from '../scopes/scope.js';
|
|
5
5
|
|
|
@@ -37,4 +37,8 @@ export class CreateViewNode extends VoidNode {
|
|
|
37
37
|
selectSql: this.sql
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
+
|
|
41
|
+
override computePhysical(_children: readonly PhysicalProperties[]): Partial<PhysicalProperties> {
|
|
42
|
+
return { readonly: false };
|
|
43
|
+
}
|
|
40
44
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PlanNode, type UnaryRelationalNode, type RelationalPlanNode, type Attribute, type TableDescriptor } from './plan-node.js';
|
|
1
|
+
import { PlanNode, type UnaryRelationalNode, type RelationalPlanNode, type Attribute, type TableDescriptor, isRelationalNode } from './plan-node.js';
|
|
2
2
|
import type { RelationType } from '../../common/datatype.js';
|
|
3
3
|
import { PlanNodeType } from './plan-node-type.js';
|
|
4
4
|
import type { Scope } from '../scopes/scope.js';
|
|
@@ -41,17 +41,27 @@ export class CTENode extends PlanNode implements CTEPlanNode {
|
|
|
41
41
|
|
|
42
42
|
private buildAttributes(): Attribute[] {
|
|
43
43
|
const queryAttributes = this.source.getAttributes();
|
|
44
|
-
|
|
45
|
-
// Use explicit column names if provided, otherwise use query output column names
|
|
46
44
|
const queryType = this.source.getType();
|
|
47
45
|
const columnNames = this.columns || queryType.columns.map((c: any) => c.name);
|
|
48
46
|
|
|
49
|
-
return
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
return columnNames.map((name: string) => {
|
|
48
|
+
const srcAttr = queryAttributes.find(a => a.name.toLowerCase() === name.toLowerCase());
|
|
49
|
+
let resolvedType: any = srcAttr?.type;
|
|
50
|
+
if (!resolvedType) {
|
|
51
|
+
const colMeta = queryType.columns.find((c: any) => c.name.toLowerCase() === name.toLowerCase());
|
|
52
|
+
resolvedType = colMeta?.type;
|
|
53
|
+
}
|
|
54
|
+
// Fallback: generic TEXT scalar if nothing else is available (should not normally happen)
|
|
55
|
+
if (!resolvedType) {
|
|
56
|
+
resolvedType = { typeClass: 'scalar', affinity: 'TEXT', nullable: true, isReadOnly: false } as any;
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
id: srcAttr?.id ?? PlanNode.nextAttrId(),
|
|
60
|
+
name,
|
|
61
|
+
type: resolvedType,
|
|
62
|
+
sourceRelation: `cte:${this.cteName}`
|
|
63
|
+
};
|
|
64
|
+
});
|
|
55
65
|
}
|
|
56
66
|
|
|
57
67
|
private buildType(): RelationType {
|
|
@@ -77,8 +87,8 @@ export class CTENode extends PlanNode implements CTEPlanNode {
|
|
|
77
87
|
return this.typeCache.value;
|
|
78
88
|
}
|
|
79
89
|
|
|
80
|
-
getChildren(): readonly [] {
|
|
81
|
-
return [];
|
|
90
|
+
getChildren(): readonly [RelationalPlanNode] {
|
|
91
|
+
return [this.source];
|
|
82
92
|
}
|
|
83
93
|
|
|
84
94
|
getRelations(): readonly [RelationalPlanNode] {
|
|
@@ -86,10 +96,31 @@ export class CTENode extends PlanNode implements CTEPlanNode {
|
|
|
86
96
|
}
|
|
87
97
|
|
|
88
98
|
withChildren(newChildren: readonly PlanNode[]): PlanNode {
|
|
89
|
-
if (newChildren.length !==
|
|
90
|
-
throw new Error(`CTENode expects
|
|
99
|
+
if (newChildren.length !== 1) {
|
|
100
|
+
throw new Error(`CTENode expects 1 child, got ${newChildren.length}`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const [newSource] = newChildren;
|
|
104
|
+
|
|
105
|
+
// Type check
|
|
106
|
+
if (!isRelationalNode(newSource)) {
|
|
107
|
+
throw new Error('CTENode: child must be a RelationalPlanNode');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Return same instance if nothing changed
|
|
111
|
+
if (newSource === this.source) {
|
|
112
|
+
return this;
|
|
91
113
|
}
|
|
92
|
-
|
|
114
|
+
|
|
115
|
+
// Create new instance with updated source
|
|
116
|
+
return new CTENode(
|
|
117
|
+
this.scope,
|
|
118
|
+
this.cteName,
|
|
119
|
+
this.columns,
|
|
120
|
+
newSource as RelationalPlanNode,
|
|
121
|
+
this.materializationHint,
|
|
122
|
+
this.isRecursive
|
|
123
|
+
);
|
|
93
124
|
}
|
|
94
125
|
|
|
95
126
|
override toString(): string {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PlanNode, type
|
|
1
|
+
import { PlanNode, type RelationalPlanNode, type Attribute } from './plan-node.js';
|
|
2
2
|
import type { RelationType } from '../../common/datatype.js';
|
|
3
3
|
import { PlanNodeType } from './plan-node-type.js';
|
|
4
4
|
import type { Scope } from '../scopes/scope.js';
|
|
@@ -9,30 +9,46 @@ import { Cached } from '../../util/cached.js';
|
|
|
9
9
|
* Plan node for referencing a CTE in a FROM clause.
|
|
10
10
|
* This points to a materialized CTE result.
|
|
11
11
|
*/
|
|
12
|
-
export class CTEReferenceNode extends PlanNode implements
|
|
12
|
+
export class CTEReferenceNode extends PlanNode implements RelationalPlanNode {
|
|
13
13
|
readonly nodeType = PlanNodeType.CTEReference;
|
|
14
|
+
private static nextRefId = 1;
|
|
15
|
+
public readonly referenceId: number;
|
|
14
16
|
|
|
17
|
+
// Cache of attributes to avoid regenerating new IDs on each plan rewrite
|
|
15
18
|
private attributesCache: Cached<Attribute[]>;
|
|
16
19
|
private typeCache: Cached<RelationType>;
|
|
17
20
|
|
|
18
21
|
constructor(
|
|
19
22
|
scope: Scope,
|
|
20
23
|
public readonly source: CTEPlanNode,
|
|
21
|
-
public readonly alias?: string
|
|
24
|
+
public readonly alias?: string,
|
|
25
|
+
/**
|
|
26
|
+
* Optionally provide an attribute list to preserve attribute IDs across
|
|
27
|
+
* plan rewrites (e.g. when `withChildren` creates a new instance). When
|
|
28
|
+
* omitted, a fresh list will be generated the first time it is requested.
|
|
29
|
+
*/
|
|
30
|
+
private readonly existingAttributes?: Attribute[]
|
|
22
31
|
) {
|
|
23
32
|
super(scope, 5); // Low cost since CTEs are materialized
|
|
24
|
-
this.
|
|
33
|
+
this.referenceId = CTEReferenceNode.nextRefId++;
|
|
34
|
+
this.attributesCache = new Cached(() => this.existingAttributes ?? this.buildAttributes());
|
|
25
35
|
this.typeCache = new Cached(() => this.buildType());
|
|
26
36
|
}
|
|
27
37
|
|
|
28
38
|
private buildAttributes(): Attribute[] {
|
|
29
|
-
//
|
|
30
|
-
//
|
|
39
|
+
// CRITICAL: Always create fresh attribute IDs for each CTE reference instance.
|
|
40
|
+
// Since we now cache CTEReferenceNode instances per alias in buildFrom(),
|
|
41
|
+
// each alias gets its own unique set of attribute IDs that remain consistent
|
|
42
|
+
// throughout the planning and execution phases.
|
|
43
|
+
const relationName = this.alias || this.source.cteName;
|
|
44
|
+
// Only use fresh IDs when we have an alias that differs from the CTE name
|
|
45
|
+
const useFreshIds = this.alias !== undefined && this.alias.toLowerCase() !== this.source.cteName.toLowerCase();
|
|
31
46
|
return this.source.getAttributes().map((attr: any) => ({
|
|
32
|
-
id: attr.id,
|
|
47
|
+
id: useFreshIds ? PlanNode.nextAttrId() : attr.id,
|
|
33
48
|
name: attr.name,
|
|
34
49
|
type: attr.type,
|
|
35
|
-
sourceRelation: `cte_ref:${this.source.cteName}
|
|
50
|
+
sourceRelation: `cte_ref:${this.source.cteName}`,
|
|
51
|
+
relationName
|
|
36
52
|
}));
|
|
37
53
|
}
|
|
38
54
|
|
|
@@ -59,8 +75,8 @@ export class CTEReferenceNode extends PlanNode implements UnaryRelationalNode {
|
|
|
59
75
|
return this.typeCache.value;
|
|
60
76
|
}
|
|
61
77
|
|
|
62
|
-
getChildren(): readonly [] {
|
|
63
|
-
return [];
|
|
78
|
+
getChildren(): readonly [CTEPlanNode] {
|
|
79
|
+
return [this.source];
|
|
64
80
|
}
|
|
65
81
|
|
|
66
82
|
getRelations(): readonly [RelationalPlanNode] {
|
|
@@ -68,10 +84,30 @@ export class CTEReferenceNode extends PlanNode implements UnaryRelationalNode {
|
|
|
68
84
|
}
|
|
69
85
|
|
|
70
86
|
withChildren(newChildren: readonly PlanNode[]): PlanNode {
|
|
71
|
-
if (newChildren.length !==
|
|
72
|
-
throw new Error(`CTEReferenceNode expects
|
|
87
|
+
if (newChildren.length !== 1) {
|
|
88
|
+
throw new Error(`CTEReferenceNode expects 1 child, got ${newChildren.length}`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const [newSource] = newChildren;
|
|
92
|
+
|
|
93
|
+
// Type check
|
|
94
|
+
if (newSource.nodeType !== PlanNodeType.CTE && newSource.nodeType !== PlanNodeType.RecursiveCTE) {
|
|
95
|
+
throw new Error(`CTEReferenceNode: child (${newSource.nodeType}) must be a CTEPlanNode`);
|
|
73
96
|
}
|
|
74
|
-
|
|
97
|
+
|
|
98
|
+
// Return same instance if nothing changed
|
|
99
|
+
if (newSource === this.source) {
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Create new instance with updated source
|
|
104
|
+
return new CTEReferenceNode(
|
|
105
|
+
this.scope,
|
|
106
|
+
newSource as CTEPlanNode,
|
|
107
|
+
this.alias,
|
|
108
|
+
// Preserve the original attribute list so IDs remain stable across rewrites
|
|
109
|
+
this.getAttributes()
|
|
110
|
+
);
|
|
75
111
|
}
|
|
76
112
|
|
|
77
113
|
override toString(): string {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Scope } from '../scopes/scope.js';
|
|
2
|
-
import { PlanNode, type RelationalPlanNode, type Attribute, type RowDescriptor } from './plan-node.js';
|
|
2
|
+
import { PlanNode, type RelationalPlanNode, type Attribute, type RowDescriptor, type PhysicalProperties, isRelationalNode } from './plan-node.js';
|
|
3
3
|
import { PlanNodeType } from './plan-node-type.js';
|
|
4
4
|
import type { TableReferenceNode } from './reference.js';
|
|
5
5
|
import type { RelationType } from '../../common/datatype.js';
|
|
@@ -14,7 +14,7 @@ export class DeleteNode extends PlanNode implements RelationalPlanNode {
|
|
|
14
14
|
constructor(
|
|
15
15
|
scope: Scope,
|
|
16
16
|
public readonly table: TableReferenceNode,
|
|
17
|
-
public readonly source: RelationalPlanNode, // Typically a FilterNode wrapping a
|
|
17
|
+
public readonly source: RelationalPlanNode, // Typically a FilterNode wrapping a TableReferenceNode
|
|
18
18
|
public readonly oldRowDescriptor?: RowDescriptor, // For constraint checking
|
|
19
19
|
public readonly flatRowDescriptor?: RowDescriptor,
|
|
20
20
|
) {
|
|
@@ -38,15 +38,39 @@ export class DeleteNode extends PlanNode implements RelationalPlanNode {
|
|
|
38
38
|
return [this.source, this.table];
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
getChildren(): readonly [] {
|
|
42
|
-
|
|
41
|
+
getChildren(): readonly PlanNode[] {
|
|
42
|
+
// Return the source relation as a child so optimizer can traverse it
|
|
43
|
+
return [this.source];
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
withChildren(newChildren: readonly PlanNode[]): PlanNode {
|
|
46
|
-
if (newChildren.length !==
|
|
47
|
-
throw new Error(`DeleteNode expects
|
|
47
|
+
if (newChildren.length !== 1) {
|
|
48
|
+
throw new Error(`DeleteNode expects 1 child (source), got ${newChildren.length}`);
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
+
|
|
51
|
+
const newSource = newChildren[0] as RelationalPlanNode;
|
|
52
|
+
if (!isRelationalNode(newSource)) {
|
|
53
|
+
throw new Error('DeleteNode: child must be a RelationalPlanNode');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (newSource === this.source) {
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return new DeleteNode(
|
|
61
|
+
this.scope,
|
|
62
|
+
this.table,
|
|
63
|
+
newSource,
|
|
64
|
+
this.oldRowDescriptor,
|
|
65
|
+
this.flatRowDescriptor
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
computePhysical(): Partial<PhysicalProperties> {
|
|
70
|
+
return {
|
|
71
|
+
readonly: false, // DELETE has side effects
|
|
72
|
+
estimatedRows: this.source.estimatedRows
|
|
73
|
+
};
|
|
50
74
|
}
|
|
51
75
|
|
|
52
76
|
get estimatedRows(): number | undefined {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PlanNodeType } from './plan-node-type.js';
|
|
2
|
-
import { PlanNode, type RelationalPlanNode, type UnaryRelationalNode, type Attribute } from './plan-node.js';
|
|
2
|
+
import { PlanNode, type RelationalPlanNode, type UnaryRelationalNode, type Attribute, isRelationalNode } from './plan-node.js';
|
|
3
3
|
import type { RelationType } from '../../common/datatype.js';
|
|
4
4
|
import type { Scope } from '../scopes/scope.js';
|
|
5
5
|
import { quereusError } from '../../common/errors.js';
|
|
@@ -75,7 +75,7 @@ export class DistinctNode extends PlanNode implements UnaryRelationalNode {
|
|
|
75
75
|
const [newSource] = newChildren;
|
|
76
76
|
|
|
77
77
|
// Type check
|
|
78
|
-
if (!(
|
|
78
|
+
if (!isRelationalNode(newSource)) {
|
|
79
79
|
quereusError('DistinctNode: child must be a RelationalPlanNode', StatusCode.INTERNAL);
|
|
80
80
|
}
|
|
81
81
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Scope } from '../scopes/scope.js';
|
|
2
|
-
import { PlanNode, type RelationalPlanNode, type Attribute, type PhysicalProperties } from './plan-node.js';
|
|
2
|
+
import { PlanNode, type RelationalPlanNode, type Attribute, type PhysicalProperties, isRelationalNode } from './plan-node.js';
|
|
3
3
|
import { PlanNodeType } from './plan-node-type.js';
|
|
4
4
|
import type { TableReferenceNode } from './reference.js';
|
|
5
5
|
import type { RelationType } from '../../common/datatype.js';
|
|
@@ -48,7 +48,7 @@ export class DmlExecutorNode extends PlanNode implements RelationalPlanNode {
|
|
|
48
48
|
const [newSource] = newChildren;
|
|
49
49
|
|
|
50
50
|
// Type check
|
|
51
|
-
if (!(
|
|
51
|
+
if (!isRelationalNode(newSource)) {
|
|
52
52
|
throw new Error('UpdateExecutorNode: child must be a RelationalPlanNode');
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Scope } from '../scopes/scope.js';
|
|
2
|
-
import { VoidNode } from './plan-node.js';
|
|
2
|
+
import { PhysicalProperties, VoidNode } from './plan-node.js';
|
|
3
3
|
import { PlanNodeType } from './plan-node-type.js';
|
|
4
4
|
import type * as AST from '../../parser/ast.js';
|
|
5
5
|
import { expressionToString } from '../../util/ast-stringify.js';
|
|
@@ -28,4 +28,8 @@ export class DropTableNode extends VoidNode {
|
|
|
28
28
|
statement: expressionToString(this.statementAst as any)
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
+
|
|
32
|
+
override computePhysical(_children: readonly PhysicalProperties[]): Partial<PhysicalProperties> {
|
|
33
|
+
return { readonly: false };
|
|
34
|
+
}
|
|
31
35
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VoidNode } from './plan-node.js';
|
|
1
|
+
import { PhysicalProperties, VoidNode } from './plan-node.js';
|
|
2
2
|
import { PlanNodeType } from './plan-node-type.js';
|
|
3
3
|
import type { Scope } from '../scopes/scope.js';
|
|
4
4
|
|
|
@@ -30,4 +30,8 @@ export class DropViewNode extends VoidNode {
|
|
|
30
30
|
ifExists: this.ifExists
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
|
+
|
|
34
|
+
override computePhysical(_children: readonly PhysicalProperties[]): Partial<PhysicalProperties> {
|
|
35
|
+
return { readonly: false };
|
|
36
|
+
}
|
|
33
37
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PlanNodeType } from './plan-node-type.js';
|
|
2
|
-
import { PlanNode, type RelationalPlanNode, type ScalarPlanNode, type UnaryRelationalNode, type Attribute } from './plan-node.js';
|
|
2
|
+
import { PlanNode, type RelationalPlanNode, type ScalarPlanNode, type UnaryRelationalNode, type Attribute, isRelationalNode, isScalarNode } from './plan-node.js';
|
|
3
3
|
import type { RelationType } from '../../common/datatype.js';
|
|
4
4
|
import type { Scope } from '../scopes/scope.js';
|
|
5
5
|
import { formatExpression } from '../../util/plan-formatter.js';
|
|
@@ -69,10 +69,10 @@ export class FilterNode extends PlanNode implements UnaryRelationalNode {
|
|
|
69
69
|
const [newSource, newPredicate] = newChildren;
|
|
70
70
|
|
|
71
71
|
// Type check
|
|
72
|
-
if (!(
|
|
72
|
+
if (!isRelationalNode(newSource)) {
|
|
73
73
|
quereusError('FilterNode: first child must be a RelationalPlanNode', StatusCode.INTERNAL);
|
|
74
74
|
}
|
|
75
|
-
if (!(
|
|
75
|
+
if (!isScalarNode(newPredicate)) {
|
|
76
76
|
quereusError('FilterNode: second child must be a ScalarPlanNode', StatusCode.INTERNAL);
|
|
77
77
|
}
|
|
78
78
|
|