@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
|
@@ -2,12 +2,14 @@ import type * as AST from '../../parser/ast.js';
|
|
|
2
2
|
import type { RelationalPlanNode } from '../nodes/plan-node.js';
|
|
3
3
|
import type { PlanningContext } from '../planning-context.js';
|
|
4
4
|
import type { Projection } from '../nodes/project-node.js';
|
|
5
|
+
import { RegisteredScope } from '../scopes/registered.js';
|
|
5
6
|
/**
|
|
6
7
|
* Builds final projections for non-aggregate cases
|
|
7
8
|
*/
|
|
8
|
-
export declare function buildFinalProjections(input: RelationalPlanNode, projections: Projection[], selectScope: any, stmt: AST.SelectStmt, selectContext: PlanningContext): {
|
|
9
|
+
export declare function buildFinalProjections(input: RelationalPlanNode, projections: Projection[], selectScope: any, stmt: AST.SelectStmt, selectContext: PlanningContext, preserveInputColumns?: boolean): {
|
|
9
10
|
output: RelationalPlanNode;
|
|
10
11
|
finalContext: PlanningContext;
|
|
12
|
+
projectionScope?: RegisteredScope;
|
|
11
13
|
preAggregateSort: boolean;
|
|
12
14
|
};
|
|
13
15
|
/**
|
|
@@ -17,9 +19,9 @@ export declare function applyDistinct(input: RelationalPlanNode, stmt: AST.Selec
|
|
|
17
19
|
/**
|
|
18
20
|
* Applies ORDER BY clause if not already applied
|
|
19
21
|
*/
|
|
20
|
-
export declare function applyOrderBy(input: RelationalPlanNode, stmt: AST.SelectStmt, selectContext: PlanningContext, preAggregateSort: boolean): RelationalPlanNode;
|
|
22
|
+
export declare function applyOrderBy(input: RelationalPlanNode, stmt: AST.SelectStmt, selectContext: PlanningContext, preAggregateSort: boolean, projectionScope?: RegisteredScope): RelationalPlanNode;
|
|
21
23
|
/**
|
|
22
24
|
* Applies LIMIT and OFFSET clauses
|
|
23
25
|
*/
|
|
24
|
-
export declare function applyLimitOffset(input: RelationalPlanNode, stmt: AST.SelectStmt, selectContext: PlanningContext): RelationalPlanNode;
|
|
26
|
+
export declare function applyLimitOffset(input: RelationalPlanNode, stmt: AST.SelectStmt, selectContext: PlanningContext, projectionScope?: RegisteredScope): RelationalPlanNode;
|
|
25
27
|
//# sourceMappingURL=select-modifiers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-modifiers.d.ts","sourceRoot":"","sources":["../../../../src/planner/building/select-modifiers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAChD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"select-modifiers.d.ts","sourceRoot":"","sources":["../../../../src/planner/building/select-modifiers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAChD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAO3D,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAI1D;;GAEG;AACH,wBAAgB,qBAAqB,CACpC,KAAK,EAAE,kBAAkB,EACzB,WAAW,EAAE,UAAU,EAAE,EACzB,WAAW,EAAE,GAAG,EAChB,IAAI,EAAE,GAAG,CAAC,UAAU,EACpB,aAAa,EAAE,eAAe,EAC9B,oBAAoB,GAAE,OAAc,GAClC;IACF,MAAM,EAAE,kBAAkB,CAAC;IAC3B,YAAY,EAAE,eAAe,CAAC;IAC9B,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,gBAAgB,EAAE,OAAO,CAAC;CAC1B,CAsCA;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC5B,KAAK,EAAE,kBAAkB,EACzB,IAAI,EAAE,GAAG,CAAC,UAAU,EACpB,WAAW,EAAE,GAAG,GACd,kBAAkB,CAKpB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC3B,KAAK,EAAE,kBAAkB,EACzB,IAAI,EAAE,GAAG,CAAC,UAAU,EACpB,aAAa,EAAE,eAAe,EAC9B,gBAAgB,EAAE,OAAO,EACzB,eAAe,CAAC,EAAE,eAAe,GAC/B,kBAAkB,CAqBpB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC/B,KAAK,EAAE,kBAAkB,EACzB,IAAI,EAAE,GAAG,CAAC,UAAU,EACpB,aAAa,EAAE,eAAe,EAC9B,eAAe,CAAC,EAAE,eAAe,GAC/B,kBAAkB,CAepB"}
|
|
@@ -10,15 +10,15 @@ import { buildExpression } from './expression.js';
|
|
|
10
10
|
/**
|
|
11
11
|
* Builds final projections for non-aggregate cases
|
|
12
12
|
*/
|
|
13
|
-
export function buildFinalProjections(input, projections, selectScope, stmt, selectContext) {
|
|
13
|
+
export function buildFinalProjections(input, projections, selectScope, stmt, selectContext, preserveInputColumns = true) {
|
|
14
14
|
if (projections.length === 0) {
|
|
15
15
|
return { output: input, finalContext: selectContext, preAggregateSort: false };
|
|
16
16
|
}
|
|
17
|
-
// Check if ORDER BY should be applied before projection
|
|
17
|
+
// Check if ORDER BY should be applied before projection (using input scope only)
|
|
18
18
|
const needsPreProjectionSort = shouldApplyOrderByBeforeProjection(stmt, projections);
|
|
19
19
|
let preAggregateSort = false;
|
|
20
20
|
let currentInput = input;
|
|
21
|
-
// Apply ORDER BY before projection if needed
|
|
21
|
+
// Apply ORDER BY before projection if needed (compile expressions against input scope)
|
|
22
22
|
if (needsPreProjectionSort && stmt.orderBy && stmt.orderBy.length > 0) {
|
|
23
23
|
const sortKeys = stmt.orderBy.map(orderByClause => {
|
|
24
24
|
const expression = buildExpression(selectContext, orderByClause.expr);
|
|
@@ -31,18 +31,15 @@ export function buildFinalProjections(input, projections, selectScope, stmt, sel
|
|
|
31
31
|
currentInput = new SortNode(selectScope, currentInput, sortKeys);
|
|
32
32
|
preAggregateSort = true;
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
// Create the ProjectNode only after all expressions are compiled against input scope
|
|
35
|
+
currentInput = new ProjectNode(selectScope, currentInput, projections, undefined, undefined, preserveInputColumns);
|
|
36
|
+
// Create projection output scope but DON'T merge it into finalContext yet
|
|
37
|
+
// Let the caller decide when to make these output attributes visible
|
|
36
38
|
const projectionOutputScope = createProjectionOutputScope(currentInput);
|
|
37
|
-
// Update selectContext to use BOTH the projection output scope AND the original scope
|
|
38
|
-
let finalContext = selectContext;
|
|
39
|
-
if (!needsPreProjectionSort) {
|
|
40
|
-
const combinedScope = new MultiScope([projectionOutputScope, selectScope]);
|
|
41
|
-
finalContext = { ...selectContext, scope: combinedScope };
|
|
42
|
-
}
|
|
43
39
|
return {
|
|
44
40
|
output: currentInput,
|
|
45
|
-
finalContext,
|
|
41
|
+
finalContext: selectContext, // Keep unchanged - no premature scope pollution
|
|
42
|
+
projectionScope: projectionOutputScope,
|
|
46
43
|
preAggregateSort
|
|
47
44
|
};
|
|
48
45
|
}
|
|
@@ -58,29 +55,41 @@ export function applyDistinct(input, stmt, selectScope) {
|
|
|
58
55
|
/**
|
|
59
56
|
* Applies ORDER BY clause if not already applied
|
|
60
57
|
*/
|
|
61
|
-
export function applyOrderBy(input, stmt, selectContext, preAggregateSort) {
|
|
58
|
+
export function applyOrderBy(input, stmt, selectContext, preAggregateSort, projectionScope) {
|
|
62
59
|
if (stmt.orderBy && stmt.orderBy.length > 0 && !preAggregateSort) {
|
|
60
|
+
// Merge projection scope if available so ORDER BY can reference output column aliases
|
|
61
|
+
let orderByContext = selectContext;
|
|
62
|
+
if (projectionScope) {
|
|
63
|
+
const combinedScope = new MultiScope([projectionScope, selectContext.scope]);
|
|
64
|
+
orderByContext = { ...selectContext, scope: combinedScope };
|
|
65
|
+
}
|
|
63
66
|
const sortKeys = stmt.orderBy.map(orderByClause => {
|
|
64
|
-
const expression = buildExpression(
|
|
67
|
+
const expression = buildExpression(orderByContext, orderByClause.expr);
|
|
65
68
|
return {
|
|
66
69
|
expression,
|
|
67
70
|
direction: orderByClause.direction,
|
|
68
71
|
nulls: orderByClause.nulls
|
|
69
72
|
};
|
|
70
73
|
});
|
|
71
|
-
return new SortNode(
|
|
74
|
+
return new SortNode(orderByContext.scope, input, sortKeys);
|
|
72
75
|
}
|
|
73
76
|
return input;
|
|
74
77
|
}
|
|
75
78
|
/**
|
|
76
79
|
* Applies LIMIT and OFFSET clauses
|
|
77
80
|
*/
|
|
78
|
-
export function applyLimitOffset(input, stmt, selectContext) {
|
|
81
|
+
export function applyLimitOffset(input, stmt, selectContext, projectionScope) {
|
|
79
82
|
if (stmt.limit || stmt.offset) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
// Merge projection scope if available so LIMIT/OFFSET can reference output column aliases
|
|
84
|
+
let limitContext = selectContext;
|
|
85
|
+
if (projectionScope) {
|
|
86
|
+
const combinedScope = new MultiScope([projectionScope, selectContext.scope]);
|
|
87
|
+
limitContext = { ...selectContext, scope: combinedScope };
|
|
88
|
+
}
|
|
89
|
+
const literalNull = new LiteralNode(limitContext.scope, { type: 'literal', value: null });
|
|
90
|
+
const limitExpression = stmt.limit ? buildExpression(limitContext, stmt.limit) : literalNull;
|
|
91
|
+
const offsetExpression = stmt.offset ? buildExpression(limitContext, stmt.offset) : literalNull;
|
|
92
|
+
return new LimitOffsetNode(limitContext.scope, input, limitExpression, offsetExpression);
|
|
84
93
|
}
|
|
85
94
|
return input;
|
|
86
95
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-modifiers.js","sourceRoot":"","sources":["../../../../src/planner/building/select-modifiers.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAgB,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACpC,KAAyB,EACzB,WAAyB,EACzB,WAAgB,EAChB,IAAoB,EACpB,aAA8B;
|
|
1
|
+
{"version":3,"file":"select-modifiers.js","sourceRoot":"","sources":["../../../../src/planner/building/select-modifiers.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CA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AAC,GAAG,EAAE,KAAK,EAAE,EAAE;QACvD,MAAM,IAAI,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;QACzC,qBAAqB,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CACvE,IAAI,mBAAmB,CAAC,CAAC,EAAE,GAAqB,EAAE,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;IAC/E,CAAC,CAAC,CAAC;IAEH,OAAO,qBAAqB,CAAC;AAC9B,CAAC"}
|
|
@@ -3,6 +3,8 @@ import { type ScalarPlanNode } from '../nodes/plan-node.js';
|
|
|
3
3
|
import type { PlanningContext } from '../planning-context.js';
|
|
4
4
|
import type { Projection } from '../nodes/project-node.js';
|
|
5
5
|
import { WindowFunctionCallNode } from '../nodes/window-function.js';
|
|
6
|
+
import { type RelationalPlanNode } from '../nodes/plan-node.js';
|
|
7
|
+
import type { Scope } from '../scopes/scope.js';
|
|
6
8
|
/**
|
|
7
9
|
* Checks if an expression contains aggregate functions
|
|
8
10
|
*/
|
|
@@ -17,7 +19,7 @@ export declare function isWindowExpression(node: ScalarPlanNode): boolean;
|
|
|
17
19
|
export declare function buildStarProjections(column: {
|
|
18
20
|
type: 'all';
|
|
19
21
|
table?: string;
|
|
20
|
-
},
|
|
22
|
+
}, source: RelationalPlanNode, selectScope: Scope): Projection[];
|
|
21
23
|
/**
|
|
22
24
|
* Analyzes SELECT columns and categorizes them into different types
|
|
23
25
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-projections.d.ts","sourceRoot":"","sources":["../../../../src/planner/building/select-projections.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAO3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"select-projections.d.ts","sourceRoot":"","sources":["../../../../src/planner/building/select-projections.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAO3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAcnE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAchE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CACnC,MAAM,EAAE;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,EACvC,MAAM,EAAE,kBAAkB,EAC1B,WAAW,EAAE,KAAK,GAChB,UAAU,EAAE,CAqCd;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CACnC,OAAO,EAAE,GAAG,CAAC,YAAY,EAAE,EAC3B,aAAa,EAAE,eAAe,GAC5B;IACF,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,UAAU,EAAE;QAAE,UAAU,EAAE,cAAc,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC5D,eAAe,EAAE;QAAE,IAAI,EAAE,sBAAsB,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACpE,aAAa,EAAE,OAAO,CAAC;IACvB,kBAAkB,EAAE,OAAO,CAAC;CAC5B,CA2CA"}
|
|
@@ -40,32 +40,27 @@ export function isWindowExpression(node) {
|
|
|
40
40
|
/**
|
|
41
41
|
* Builds projections for SELECT * or table.*
|
|
42
42
|
*/
|
|
43
|
-
export function buildStarProjections(column,
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (!tableMatches) {
|
|
52
|
-
throw new QuereusError(`Table '${column.table}' not found in FROM clause for qualified SELECT *`, StatusCode.ERROR);
|
|
53
|
-
}
|
|
43
|
+
export function buildStarProjections(column, source, selectScope) {
|
|
44
|
+
const allAttributes = source.getAttributes();
|
|
45
|
+
// Filter by relation name if qualified (e.g., SELECT t1.*)
|
|
46
|
+
const matchingAttributes = column.table
|
|
47
|
+
? allAttributes.filter(attr => attr.relationName && attr.relationName.toLowerCase() === column.table.toLowerCase())
|
|
48
|
+
: allAttributes;
|
|
49
|
+
if (column.table && matchingAttributes.length === 0) {
|
|
50
|
+
throw new QuereusError(`Table '${column.table}' not found in FROM clause for qualified SELECT *`, StatusCode.ERROR);
|
|
54
51
|
}
|
|
55
|
-
//
|
|
56
|
-
|
|
52
|
+
// Convert to projections
|
|
53
|
+
return matchingAttributes.map((attr, index) => {
|
|
57
54
|
const columnExpr = {
|
|
58
55
|
type: 'column',
|
|
59
|
-
name:
|
|
56
|
+
name: attr.name,
|
|
60
57
|
};
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
projections.push({
|
|
58
|
+
const columnRef = new ColumnReferenceNode(selectScope, columnExpr, attr.type, attr.id, index);
|
|
59
|
+
return {
|
|
64
60
|
node: columnRef,
|
|
65
|
-
alias:
|
|
66
|
-
}
|
|
61
|
+
alias: attr.name
|
|
62
|
+
};
|
|
67
63
|
});
|
|
68
|
-
return projections;
|
|
69
64
|
}
|
|
70
65
|
/**
|
|
71
66
|
* Analyzes SELECT columns and categorizes them into different types
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-projections.js","sourceRoot":"","sources":["../../../../src/planner/building/select-projections.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"select-projections.js","sourceRoot":"","sources":["../../../../src/planner/building/select-projections.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAIrE;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAoB;IACzD,IAAI,IAAI,YAAY,yBAAyB,EAAE,CAAC;QAC/C,OAAO,IAAI,CAAC;IACb,CAAC;IAED,oDAAoD;IACpD,KAAK,MAAM,KAAK,IAAI,IAAI,CA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AU,CAAC,EAAE,CAAC;gBAC9C,aAAa,GAAG,IAAI,CAAC;gBACrB,UAAU,CAAC,IAAI,CAAC;oBACf,UAAU,EAAE,UAAU;oBACtB,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,kBAAkB,CAAC,MAAM,CAAC,IAAI,CAAC;iBACtD,CAAC,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACP,WAAW,CAAC,IAAI,CAAC;oBAChB,IAAI,EAAE,UAAU;oBAChB,KAAK,EAAE,MAAM,CAAC,KAAK;iBACnB,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO;QACN,WAAW;QACX,UAAU;QACV,eAAe;QACf,aAAa;QACb,kBAAkB;KAClB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,sBAAsB,CAC9B,IAAoB,EACpB,KAAc,EACd,kBAAsE,EAAE;IAExE,IAAI,IAAI,YAAY,sBAAsB,EAAE,CAAC;QAC5C,eAAe,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED,oDAAoD;IACpD,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;QACxC,IAAI,YAAY,IAAI,KAAK,EAAE,CAAC;YAC3B,sBAAsB,CAAC,KAAuB,EAAE,SAAS,EAAE,eAAe,CAAC,CAAC;QAC7E,CAAC;IACF,CAAC;IAED,OAAO,eAAe,CAAC;AACxB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-window.d.ts","sourceRoot":"","sources":["../../../../src/planner/building/select-window.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,uBAAuB,CAAC;AAChF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAG9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAMrE,OAAO,KAAK,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAEhD;;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,
|
|
1
|
+
{"version":3,"file":"select-window.d.ts","sourceRoot":"","sources":["../../../../src/planner/building/select-window.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,uBAAuB,CAAC;AAChF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAG9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAMrE,OAAO,KAAK,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAEhD;;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"}
|
|
@@ -28,12 +28,15 @@ export function buildWindowPhase(input, windowFunctions, selectContext, stmt) {
|
|
|
28
28
|
// TODO: Replace with SequencingNode for optimal performance
|
|
29
29
|
// For now, proceed with WindowNode
|
|
30
30
|
}
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
//
|
|
31
|
+
// CRITICAL: Build window specification expressions using the INPUT scope
|
|
32
|
+
// This ensures expressions reference the correct input attribute IDs,
|
|
33
|
+
// not premature output attribute IDs that don't exist in the runtime context
|
|
34
34
|
const partitionExpressions = windowSpec.partitionBy.map(expr => buildExpression(selectContext, expr, false));
|
|
35
35
|
const orderByExpressions = windowSpec.orderBy.map(orderClause => buildExpression(selectContext, orderClause.expr, false));
|
|
36
|
+
// Create new WindowFunctionCallNode instances with alias information
|
|
37
|
+
const windowFuncsWithAlias = functions.map(({ func, alias }) => new WindowFunctionCallNode(func.scope, func.expression, func.functionName, func.isDistinct, alias));
|
|
36
38
|
const functionArguments = buildWindowFunctionArguments(windowFuncsWithAlias, selectContext);
|
|
39
|
+
// Now create the WindowNode with pre-compiled expressions
|
|
37
40
|
currentInput = new WindowNode(selectContext.scope, currentInput, windowSpec, windowFuncsWithAlias, partitionExpressions, orderByExpressions, functionArguments);
|
|
38
41
|
}
|
|
39
42
|
// Create projections that select only the requested columns using direct array indexing
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-window.js","sourceRoot":"","sources":["../../../../src/planner/building/select-window.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAmB,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7D;;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,CAAC;IACd,CAAC;IAED,IAAI,YAAY,GAAG,KAAK,CAAC;IAEzB,uDAAuD;IACvD,MAAM,YAAY,GAAG,0BAA0B,CAAC,eAAe,CAAC,CAAC;IAEjE,yDAAyD;IACzD,KAAK,MAAM,CAAC,cAAc,EAAE,SAAS,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S,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"}
|
|
@@ -7,7 +7,7 @@ import { ValuesNode } from '../nodes/values-node.js';
|
|
|
7
7
|
* Creates an initial logical query plan for a SELECT statement.
|
|
8
8
|
*
|
|
9
9
|
* For this initial version, it only supports simple "SELECT ... FROM one_table" queries,
|
|
10
|
-
* effectively returning a
|
|
10
|
+
* effectively returning a TableReferenceNode for that table.
|
|
11
11
|
*
|
|
12
12
|
* @param stmt The AST.SelectStmt to plan.
|
|
13
13
|
* @param ctx The parent planning context for this SELECT statement.
|
|
@@ -15,7 +15,14 @@ import { ValuesNode } from '../nodes/values-node.js';
|
|
|
15
15
|
* @returns A BatchNode representing the plan for the SELECT statement.
|
|
16
16
|
* @throws {QuereusError} If the FROM clause is missing, empty, or contains more than one source.
|
|
17
17
|
*/
|
|
18
|
-
export declare function buildSelectStmt(ctx: PlanningContext, stmt: AST.SelectStmt, parentCTEs?: Map<string, CTEPlanNode
|
|
18
|
+
export declare function buildSelectStmt(ctx: PlanningContext, stmt: AST.SelectStmt, parentCTEs?: Map<string, CTEPlanNode>,
|
|
19
|
+
/**
|
|
20
|
+
* Whether ProjectNodes inside this SELECT should forward all input columns that are not explicitly
|
|
21
|
+
* listed in the projection list. This is desirable for top-level queries (helps ORDER BY, window
|
|
22
|
+
* functions, etc.) but must be switched off for scalar/IN/EXISTS sub-queries which are required to
|
|
23
|
+
* expose only their declared columns.
|
|
24
|
+
*/
|
|
25
|
+
preserveInputColumns?: boolean): PlanNode;
|
|
19
26
|
/**
|
|
20
27
|
* Creates a plan for a VALUES statement.
|
|
21
28
|
*
|
|
@@ -24,5 +31,21 @@ export declare function buildSelectStmt(ctx: PlanningContext, stmt: AST.SelectSt
|
|
|
24
31
|
* @returns A ValuesNode representing the VALUES clause
|
|
25
32
|
*/
|
|
26
33
|
export declare function buildValuesStmt(ctx: PlanningContext, stmt: AST.ValuesStmt): ValuesNode;
|
|
34
|
+
/**
|
|
35
|
+
* Processes a FROM clause item into a relational plan node.
|
|
36
|
+
*
|
|
37
|
+
* Handles different types of FROM items:
|
|
38
|
+
* - Table references - creates a TableReferenceNode
|
|
39
|
+
* - Subqueries - plans the subquery
|
|
40
|
+
* - Joins - builds the join structure
|
|
41
|
+
* - Table functions - creates a table function call node
|
|
42
|
+
*
|
|
43
|
+
* For a simple table reference, this calls buildTableReference which
|
|
44
|
+
* returns a TableReferenceNode for that table.
|
|
45
|
+
*
|
|
46
|
+
* @param fromClause The FROM clause AST node to process
|
|
47
|
+
* @param ctx The planning context
|
|
48
|
+
* @returns A relational plan node representing the FROM clause
|
|
49
|
+
*/
|
|
27
50
|
export declare function buildFrom(fromClause: AST.FromClause, parentContext: PlanningContext, cteNodes?: Map<string, CTEPlanNode>): RelationalPlanNode;
|
|
28
51
|
//# sourceMappingURL=select.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../../../src/planner/building/select.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,KAAK,kBAAkB,EAAuB,MAAM,uBAAuB,CAAC;AAG/F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../../../src/planner/building/select.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,KAAK,kBAAkB,EAAuB,MAAM,uBAAuB,CAAC;AAG/F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAa9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGxD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAkBrD;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,eAAe,EACpB,IAAI,EAAE,GAAG,CAAC,UAAU,EACpB,UAAU,GAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAa;AAChD;;;;;GAKG;AACH,oBAAoB,GAAE,OAAc,GACnC,QAAQ,CAsJV;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC9B,GAAG,EAAE,eAAe,EACpB,IAAI,EAAE,GAAG,CAAC,UAAU,GAClB,UAAU,CAQZ;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE,aAAa,EAAE,eAAe,EAAE,QAAQ,GAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAa,GAAG,kBAAkB,CAyNxJ"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { QuereusError } from '../../common/errors.js';
|
|
2
2
|
import { StatusCode } from '../../common/types.js';
|
|
3
3
|
import { SingleRowNode } from '../nodes/single-row.js';
|
|
4
|
-
import {
|
|
4
|
+
import { buildTableReference } from './table.js';
|
|
5
5
|
import { AliasedScope } from '../scopes/aliased.js';
|
|
6
6
|
import { RegisteredScope } from '../scopes/registered.js';
|
|
7
7
|
import { MultiScope } from '../scopes/multi.js';
|
|
@@ -10,9 +10,11 @@ import { buildExpression } from './expression.js';
|
|
|
10
10
|
import { FilterNode } from '../nodes/filter.js';
|
|
11
11
|
import { buildTableFunctionCall } from './table-function.js';
|
|
12
12
|
import { CTEReferenceNode } from '../nodes/cte-reference-node.js';
|
|
13
|
+
import { InternalRecursiveCTERefNode } from '../nodes/internal-recursive-cte-ref-node.js';
|
|
13
14
|
import { JoinNode } from '../nodes/join-node.js';
|
|
14
15
|
import { ColumnReferenceNode } from '../nodes/reference.js';
|
|
15
16
|
import { ValuesNode } from '../nodes/values-node.js';
|
|
17
|
+
import { createLogger } from '../../common/logger.js';
|
|
16
18
|
// Import decomposed functionality
|
|
17
19
|
import { buildWithContext } from './select-context.js';
|
|
18
20
|
import { buildCompoundSelect } from './select-compound.js';
|
|
@@ -20,14 +22,16 @@ import { analyzeSelectColumns, buildStarProjections } from './select-projections
|
|
|
20
22
|
import { buildAggregatePhase, buildFinalAggregateProjections } from './select-aggregates.js';
|
|
21
23
|
import { buildWindowPhase } from './select-window.js';
|
|
22
24
|
import { buildFinalProjections, applyDistinct, applyOrderBy, applyLimitOffset } from './select-modifiers.js';
|
|
25
|
+
import { SortNode } from '../nodes/sort.js';
|
|
23
26
|
import { buildInsertStmt } from './insert.js';
|
|
24
27
|
import { buildUpdateStmt } from './update.js';
|
|
25
28
|
import { buildDeleteStmt } from './delete.js';
|
|
29
|
+
const logger = createLogger('planner:cte');
|
|
26
30
|
/**
|
|
27
31
|
* Creates an initial logical query plan for a SELECT statement.
|
|
28
32
|
*
|
|
29
33
|
* For this initial version, it only supports simple "SELECT ... FROM one_table" queries,
|
|
30
|
-
* effectively returning a
|
|
34
|
+
* effectively returning a TableReferenceNode for that table.
|
|
31
35
|
*
|
|
32
36
|
* @param stmt The AST.SelectStmt to plan.
|
|
33
37
|
* @param ctx The parent planning context for this SELECT statement.
|
|
@@ -35,7 +39,14 @@ import { buildDeleteStmt } from './delete.js';
|
|
|
35
39
|
* @returns A BatchNode representing the plan for the SELECT statement.
|
|
36
40
|
* @throws {QuereusError} If the FROM clause is missing, empty, or contains more than one source.
|
|
37
41
|
*/
|
|
38
|
-
export function buildSelectStmt(ctx, stmt, parentCTEs = new Map()
|
|
42
|
+
export function buildSelectStmt(ctx, stmt, parentCTEs = new Map(),
|
|
43
|
+
/**
|
|
44
|
+
* Whether ProjectNodes inside this SELECT should forward all input columns that are not explicitly
|
|
45
|
+
* listed in the projection list. This is desirable for top-level queries (helps ORDER BY, window
|
|
46
|
+
* functions, etc.) but must be switched off for scalar/IN/EXISTS sub-queries which are required to
|
|
47
|
+
* expose only their declared columns.
|
|
48
|
+
*/
|
|
49
|
+
preserveInputColumns = true) {
|
|
39
50
|
// Phase 0: Handle WITH clause if present
|
|
40
51
|
const { contextWithCTEs, cteNodes } = buildWithContext(ctx, stmt, parentCTEs);
|
|
41
52
|
// Handle compound set operations (UNION / INTERSECT / EXCEPT)
|
|
@@ -83,22 +94,74 @@ export function buildSelectStmt(ctx, stmt, parentCTEs = new Map()) {
|
|
|
83
94
|
// Build final projections if needed
|
|
84
95
|
if (aggregateResult.needsFinalProjection) {
|
|
85
96
|
const finalProjections = buildFinalAggregateProjections(stmt, selectContext, aggregateResult.aggregateScope);
|
|
86
|
-
input = new ProjectNode(selectScope, input, finalProjections);
|
|
97
|
+
input = new ProjectNode(selectScope, input, finalProjections, undefined, undefined, preserveInputColumns);
|
|
87
98
|
}
|
|
88
99
|
}
|
|
89
100
|
// Handle window functions if present
|
|
90
|
-
|
|
91
|
-
|
|
101
|
+
if (hasWindowFunctions) {
|
|
102
|
+
// Check if ORDER BY references columns not in SELECT before applying window functions
|
|
103
|
+
let preWindowSort = false;
|
|
104
|
+
if (stmt.orderBy) {
|
|
105
|
+
const selectedColumns = new Set();
|
|
106
|
+
for (const column of stmt.columns) {
|
|
107
|
+
if (column.type === 'column' && column.expr.type === 'column') {
|
|
108
|
+
selectedColumns.add(column.expr.name.toLowerCase());
|
|
109
|
+
}
|
|
110
|
+
if (column.type === 'column' && column.alias) {
|
|
111
|
+
selectedColumns.add(column.alias.toLowerCase());
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Check if ORDER BY references columns not in SELECT
|
|
115
|
+
for (const orderByClause of stmt.orderBy) {
|
|
116
|
+
if (orderByClause.expr.type === 'column') {
|
|
117
|
+
const orderColumn = orderByClause.expr.name.toLowerCase();
|
|
118
|
+
if (!selectedColumns.has(orderColumn)) {
|
|
119
|
+
// Apply ORDER BY before window projections
|
|
120
|
+
const sortKeys = stmt.orderBy.map(orderBy => ({
|
|
121
|
+
expression: buildExpression(selectContext, orderBy.expr),
|
|
122
|
+
direction: orderBy.direction,
|
|
123
|
+
nulls: orderBy.nulls
|
|
124
|
+
}));
|
|
125
|
+
input = new SortNode(selectContext.scope, input, sortKeys);
|
|
126
|
+
preWindowSort = true;
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
input = buildWindowPhase(input, windowFunctions, selectContext, stmt);
|
|
133
|
+
// Update context to include window output columns
|
|
134
|
+
const windowOutputScope = new RegisteredScope(selectContext.scope);
|
|
135
|
+
const windowAttributes = input.getAttributes();
|
|
136
|
+
input.getType().columns.forEach((col, index) => {
|
|
137
|
+
const attr = windowAttributes[index];
|
|
138
|
+
windowOutputScope.registerSymbol(col.name.toLowerCase(), (exp, s) => new ColumnReferenceNode(s, exp, col.type, attr.id, index));
|
|
139
|
+
});
|
|
140
|
+
// Create combined scope that includes both original columns and window output
|
|
141
|
+
const combinedScope = new MultiScope([windowOutputScope, selectScope]);
|
|
142
|
+
selectContext = { ...selectContext, scope: combinedScope };
|
|
143
|
+
// Don't apply ORDER BY again if we already did it
|
|
144
|
+
if (preWindowSort) {
|
|
145
|
+
preAggregateSort = true;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// Handle final projections for non-aggregate, non-window cases
|
|
92
149
|
if (!hasAggregates && !hasWindowFunctions) {
|
|
93
|
-
const finalResult = buildFinalProjections(input, projections, selectScope, stmt, selectContext);
|
|
150
|
+
const finalResult = buildFinalProjections(input, projections, selectScope, stmt, selectContext, preserveInputColumns);
|
|
94
151
|
input = finalResult.output;
|
|
95
152
|
selectContext = finalResult.finalContext;
|
|
96
153
|
preAggregateSort = finalResult.preAggregateSort;
|
|
154
|
+
// Apply final modifiers with projection scope for column alias resolution
|
|
155
|
+
input = applyDistinct(input, stmt, selectScope);
|
|
156
|
+
input = applyOrderBy(input, stmt, selectContext, preAggregateSort, finalResult.projectionScope);
|
|
157
|
+
input = applyLimitOffset(input, stmt, selectContext, finalResult.projectionScope);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
// Apply final modifiers without projection scope for aggregate/window cases
|
|
161
|
+
input = applyDistinct(input, stmt, selectScope);
|
|
162
|
+
input = applyOrderBy(input, stmt, selectContext, preAggregateSort);
|
|
163
|
+
input = applyLimitOffset(input, stmt, selectContext);
|
|
97
164
|
}
|
|
98
|
-
// Apply final modifiers
|
|
99
|
-
input = applyDistinct(input, stmt, selectScope);
|
|
100
|
-
input = applyOrderBy(input, stmt, selectContext, preAggregateSort);
|
|
101
|
-
input = applyLimitOffset(input, stmt, selectContext);
|
|
102
165
|
return input;
|
|
103
166
|
}
|
|
104
167
|
/**
|
|
@@ -114,6 +177,22 @@ export function buildValuesStmt(ctx, stmt) {
|
|
|
114
177
|
// Create the VALUES node
|
|
115
178
|
return new ValuesNode(ctx.scope, rows);
|
|
116
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* Processes a FROM clause item into a relational plan node.
|
|
182
|
+
*
|
|
183
|
+
* Handles different types of FROM items:
|
|
184
|
+
* - Table references - creates a TableReferenceNode
|
|
185
|
+
* - Subqueries - plans the subquery
|
|
186
|
+
* - Joins - builds the join structure
|
|
187
|
+
* - Table functions - creates a table function call node
|
|
188
|
+
*
|
|
189
|
+
* For a simple table reference, this calls buildTableReference which
|
|
190
|
+
* returns a TableReferenceNode for that table.
|
|
191
|
+
*
|
|
192
|
+
* @param fromClause The FROM clause AST node to process
|
|
193
|
+
* @param ctx The planning context
|
|
194
|
+
* @returns A relational plan node representing the FROM clause
|
|
195
|
+
*/
|
|
117
196
|
export function buildFrom(fromClause, parentContext, cteNodes = new Map()) {
|
|
118
197
|
let fromTable;
|
|
119
198
|
let columnScope;
|
|
@@ -122,21 +201,65 @@ export function buildFrom(fromClause, parentContext, cteNodes = new Map()) {
|
|
|
122
201
|
// Check if this is a CTE reference
|
|
123
202
|
if (cteNodes.has(tableName)) {
|
|
124
203
|
const cteNode = cteNodes.get(tableName);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
204
|
+
// Check if this is an internal recursive CTE reference
|
|
205
|
+
if (cteNode instanceof InternalRecursiveCTERefNode) {
|
|
206
|
+
// For internal recursive references, use the node directly
|
|
207
|
+
fromTable = cteNode;
|
|
208
|
+
// Create scope for internal recursive CTE columns
|
|
209
|
+
const internalScope = new RegisteredScope(parentContext.scope);
|
|
210
|
+
const internalAttributes = cteNode.getAttributes();
|
|
211
|
+
cteNode.getType().columns.forEach((c, i) => {
|
|
212
|
+
const attr = internalAttributes[i];
|
|
213
|
+
internalScope.registerSymbol(c.name.toLowerCase(), (exp, s) => new ColumnReferenceNode(s, exp, c.type, attr.id, i));
|
|
214
|
+
});
|
|
215
|
+
if (fromClause.alias) {
|
|
216
|
+
columnScope = new AliasedScope(internalScope, tableName, fromClause.alias.toLowerCase());
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
columnScope = new AliasedScope(internalScope, tableName, tableName);
|
|
220
|
+
}
|
|
135
221
|
}
|
|
136
222
|
else {
|
|
137
|
-
|
|
223
|
+
// Regular CTE reference - cache by CTE name + alias to ensure consistent attribute IDs
|
|
224
|
+
const cacheKey = `${tableName}:${fromClause.alias || tableName}`;
|
|
225
|
+
// Initialize cache if not exists
|
|
226
|
+
if (!parentContext.cteReferenceCache) {
|
|
227
|
+
parentContext.cteReferenceCache = new Map();
|
|
228
|
+
}
|
|
229
|
+
let cteRefNode;
|
|
230
|
+
if (parentContext.cteReferenceCache.has(cacheKey)) {
|
|
231
|
+
cteRefNode = parentContext.cteReferenceCache.get(cacheKey);
|
|
232
|
+
const attrs = cteRefNode.getAttributes();
|
|
233
|
+
logger(`Using cached CTE reference ${cacheKey}, attrs=[${attrs.map(a => a.id).join(',')}]`);
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
cteRefNode = new CTEReferenceNode(parentContext.scope, cteNode, fromClause.alias);
|
|
237
|
+
parentContext.cteReferenceCache.set(cacheKey, cteRefNode);
|
|
238
|
+
const attrs = cteRefNode.getAttributes();
|
|
239
|
+
logger(`Created new CTE reference ${cacheKey}, attrs=[${attrs.map(a => a.id).join(',')}]`);
|
|
240
|
+
}
|
|
241
|
+
// Create scope for CTE columns using attributes from the reference node
|
|
242
|
+
// CRITICAL: Use a closure to capture the reference node's attributes
|
|
243
|
+
// This ensures all column references use the same attribute IDs
|
|
244
|
+
const cteScope = new RegisteredScope(parentContext.scope);
|
|
245
|
+
const refAttrs = cteRefNode.getAttributes();
|
|
246
|
+
cteRefNode.getType().columns.forEach((c, i) => {
|
|
247
|
+
const attr = refAttrs[i];
|
|
248
|
+
cteScope.registerSymbol(c.name.toLowerCase(), (exp, s) => {
|
|
249
|
+
// Always use the cached reference node's attribute ID
|
|
250
|
+
return new ColumnReferenceNode(s, exp, c.type, attr.id, i);
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
if (fromClause.alias) {
|
|
254
|
+
columnScope = new AliasedScope(cteScope, tableName, fromClause.alias.toLowerCase());
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
columnScope = new AliasedScope(cteScope, tableName, tableName);
|
|
258
|
+
}
|
|
259
|
+
// CRITICAL: Cache the reference node so later expression compilation uses the same attribute IDs
|
|
260
|
+
columnScope.referenceNode = cteRefNode;
|
|
261
|
+
fromTable = cteRefNode;
|
|
138
262
|
}
|
|
139
|
-
fromTable = cteRefNode;
|
|
140
263
|
}
|
|
141
264
|
else {
|
|
142
265
|
// Check if this is a view
|
|
@@ -161,7 +284,7 @@ export function buildFrom(fromClause, parentContext, cteNodes = new Map()) {
|
|
|
161
284
|
}
|
|
162
285
|
else {
|
|
163
286
|
// Regular table
|
|
164
|
-
fromTable =
|
|
287
|
+
fromTable = buildTableReference(fromClause, parentContext);
|
|
165
288
|
// Create scope for table columns
|
|
166
289
|
const tableScope = new RegisteredScope(parentContext.scope);
|
|
167
290
|
const tableAttributes = fromTable.getAttributes();
|