@quereus/quereus 0.2.1 → 0.4.5
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 +12 -1
- package/dist/src/common/errors.js.map +1 -1
- package/dist/src/common/json-types.d.ts +11 -0
- package/dist/src/common/json-types.d.ts.map +1 -0
- package/dist/src/common/json-types.js +3 -0
- package/dist/src/common/json-types.js.map +1 -0
- package/dist/src/common/types.d.ts +1 -0
- package/dist/src/common/types.d.ts.map +1 -1
- package/dist/src/core/database-options.d.ts +2 -2
- package/dist/src/core/database-options.d.ts.map +1 -1
- package/dist/src/core/database-options.js.map +1 -1
- package/dist/src/core/database.d.ts +61 -14
- package/dist/src/core/database.d.ts.map +1 -1
- package/dist/src/core/database.js +481 -54
- package/dist/src/core/database.js.map +1 -1
- package/dist/src/core/statement.d.ts.map +1 -1
- package/dist/src/core/statement.js +3 -1
- package/dist/src/core/statement.js.map +1 -1
- package/dist/src/func/builtins/builtin-window-functions.d.ts.map +1 -1
- package/dist/src/func/builtins/builtin-window-functions.js.map +1 -1
- package/dist/src/func/builtins/datetime.d.ts +2 -0
- package/dist/src/func/builtins/datetime.d.ts.map +1 -1
- package/dist/src/func/builtins/datetime.js +39 -0
- package/dist/src/func/builtins/datetime.js.map +1 -1
- package/dist/src/func/builtins/explain.d.ts +1 -0
- package/dist/src/func/builtins/explain.d.ts.map +1 -1
- package/dist/src/func/builtins/explain.js +159 -36
- package/dist/src/func/builtins/explain.js.map +1 -1
- package/dist/src/func/builtins/index.d.ts.map +1 -1
- package/dist/src/func/builtins/index.js +5 -2
- package/dist/src/func/builtins/index.js.map +1 -1
- package/dist/src/func/builtins/json-helpers.d.ts +8 -8
- package/dist/src/func/builtins/json-helpers.d.ts.map +1 -1
- package/dist/src/func/builtins/json-helpers.js +3 -3
- package/dist/src/func/builtins/json-helpers.js.map +1 -1
- package/dist/src/func/builtins/json-tvf.d.ts.map +1 -1
- package/dist/src/func/builtins/json-tvf.js +1 -1
- package/dist/src/func/builtins/json-tvf.js.map +1 -1
- package/dist/src/func/builtins/json.d.ts.map +1 -1
- package/dist/src/func/builtins/json.js +3 -2
- package/dist/src/func/builtins/json.js.map +1 -1
- package/dist/src/func/builtins/schema.d.ts.map +1 -1
- package/dist/src/func/builtins/schema.js +22 -1
- package/dist/src/func/builtins/schema.js.map +1 -1
- package/dist/src/func/context.d.ts.map +1 -1
- package/dist/src/func/context.js +5 -0
- package/dist/src/func/context.js.map +1 -1
- package/dist/src/func/registration.d.ts +2 -1
- package/dist/src/func/registration.d.ts.map +1 -1
- package/dist/src/func/registration.js.map +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/parser/ast.d.ts +83 -4
- package/dist/src/parser/ast.d.ts.map +1 -1
- package/dist/src/parser/lexer.d.ts +11 -0
- package/dist/src/parser/lexer.d.ts.map +1 -1
- package/dist/src/parser/lexer.js +29 -21
- package/dist/src/parser/lexer.js.map +1 -1
- package/dist/src/parser/parser.d.ts +16 -0
- package/dist/src/parser/parser.d.ts.map +1 -1
- package/dist/src/parser/parser.js +542 -26
- package/dist/src/parser/parser.js.map +1 -1
- package/dist/src/parser/visitor.d.ts.map +1 -1
- package/dist/src/parser/visitor.js +1 -0
- package/dist/src/parser/visitor.js.map +1 -1
- package/dist/src/planner/analysis/binding-collector.d.ts +5 -0
- package/dist/src/planner/analysis/binding-collector.d.ts.map +1 -0
- package/dist/src/planner/analysis/binding-collector.js +73 -0
- package/dist/src/planner/analysis/binding-collector.js.map +1 -0
- package/dist/src/planner/analysis/const-evaluator.js +1 -1
- package/dist/src/planner/analysis/const-evaluator.js.map +1 -1
- package/dist/src/planner/analysis/const-pass.d.ts.map +1 -1
- package/dist/src/planner/analysis/const-pass.js +1 -1
- package/dist/src/planner/analysis/const-pass.js.map +1 -1
- package/dist/src/planner/analysis/constraint-extractor.d.ts +67 -31
- package/dist/src/planner/analysis/constraint-extractor.d.ts.map +1 -1
- package/dist/src/planner/analysis/constraint-extractor.js +513 -84
- package/dist/src/planner/analysis/constraint-extractor.js.map +1 -1
- package/dist/src/planner/analysis/predicate-normalizer.d.ts +17 -0
- package/dist/src/planner/analysis/predicate-normalizer.d.ts.map +1 -0
- package/dist/src/planner/analysis/predicate-normalizer.js +222 -0
- package/dist/src/planner/analysis/predicate-normalizer.js.map +1 -0
- package/dist/src/planner/building/alter-table.d.ts.map +1 -1
- package/dist/src/planner/building/alter-table.js +5 -2
- package/dist/src/planner/building/alter-table.js.map +1 -1
- package/dist/src/planner/building/block.d.ts.map +1 -1
- package/dist/src/planner/building/block.js +16 -0
- package/dist/src/planner/building/block.js.map +1 -1
- package/dist/src/planner/building/constraint-builder.d.ts +1 -1
- package/dist/src/planner/building/constraint-builder.d.ts.map +1 -1
- package/dist/src/planner/building/constraint-builder.js +52 -3
- package/dist/src/planner/building/constraint-builder.js.map +1 -1
- package/dist/src/planner/building/create-assertion.d.ts +5 -0
- package/dist/src/planner/building/create-assertion.d.ts.map +1 -0
- package/dist/src/planner/building/create-assertion.js +5 -0
- package/dist/src/planner/building/create-assertion.js.map +1 -0
- package/dist/src/planner/building/declare-schema.d.ts +8 -0
- package/dist/src/planner/building/declare-schema.d.ts.map +1 -0
- package/dist/src/planner/building/declare-schema.js +14 -0
- package/dist/src/planner/building/declare-schema.js.map +1 -0
- package/dist/src/planner/building/delete.d.ts.map +1 -1
- package/dist/src/planner/building/delete.js +37 -5
- package/dist/src/planner/building/delete.js.map +1 -1
- package/dist/src/planner/building/drop-assertion.d.ts +5 -0
- package/dist/src/planner/building/drop-assertion.d.ts.map +1 -0
- package/dist/src/planner/building/drop-assertion.js +8 -0
- package/dist/src/planner/building/drop-assertion.js.map +1 -0
- package/dist/src/planner/building/expression.d.ts.map +1 -1
- package/dist/src/planner/building/expression.js +1 -0
- package/dist/src/planner/building/expression.js.map +1 -1
- package/dist/src/planner/building/function-call.d.ts.map +1 -1
- package/dist/src/planner/building/function-call.js +2 -1
- package/dist/src/planner/building/function-call.js.map +1 -1
- package/dist/src/planner/building/insert.d.ts.map +1 -1
- package/dist/src/planner/building/insert.js +67 -10
- package/dist/src/planner/building/insert.js.map +1 -1
- package/dist/src/planner/building/pragma.d.ts.map +1 -1
- package/dist/src/planner/building/pragma.js +1 -0
- package/dist/src/planner/building/pragma.js.map +1 -1
- package/dist/src/planner/building/schema-resolution.d.ts +2 -2
- package/dist/src/planner/building/schema-resolution.d.ts.map +1 -1
- package/dist/src/planner/building/select-aggregates.d.ts.map +1 -1
- package/dist/src/planner/building/select-aggregates.js +3 -2
- package/dist/src/planner/building/select-aggregates.js.map +1 -1
- package/dist/src/planner/building/select-compound.d.ts +2 -2
- package/dist/src/planner/building/select-compound.d.ts.map +1 -1
- package/dist/src/planner/building/select-compound.js +10 -1
- package/dist/src/planner/building/select-compound.js.map +1 -1
- package/dist/src/planner/building/select-context.d.ts +3 -3
- package/dist/src/planner/building/select-context.d.ts.map +1 -1
- package/dist/src/planner/building/select-context.js.map +1 -1
- package/dist/src/planner/building/select-modifiers.d.ts +6 -5
- package/dist/src/planner/building/select-modifiers.d.ts.map +1 -1
- package/dist/src/planner/building/select-modifiers.js +5 -4
- package/dist/src/planner/building/select-modifiers.js.map +1 -1
- package/dist/src/planner/building/select-projections.d.ts.map +1 -1
- package/dist/src/planner/building/select-projections.js +4 -5
- 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 +3 -3
- package/dist/src/planner/building/select.d.ts.map +1 -1
- package/dist/src/planner/building/select.js +18 -8
- package/dist/src/planner/building/select.js.map +1 -1
- package/dist/src/planner/building/table-function.d.ts.map +1 -1
- package/dist/src/planner/building/table-function.js +1 -1
- package/dist/src/planner/building/table-function.js.map +1 -1
- package/dist/src/planner/building/table.d.ts +5 -3
- package/dist/src/planner/building/table.d.ts.map +1 -1
- package/dist/src/planner/building/table.js +7 -2
- 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 +38 -6
- package/dist/src/planner/building/update.js.map +1 -1
- package/dist/src/planner/building/with.d.ts +3 -3
- package/dist/src/planner/building/with.d.ts.map +1 -1
- package/dist/src/planner/building/with.js.map +1 -1
- package/dist/src/planner/debug.d.ts.map +1 -1
- package/dist/src/planner/debug.js.map +1 -1
- package/dist/src/planner/framework/characteristics.d.ts +235 -0
- package/dist/src/planner/framework/characteristics.d.ts.map +1 -0
- package/dist/src/planner/framework/characteristics.js +299 -0
- package/dist/src/planner/framework/characteristics.js.map +1 -0
- package/dist/src/planner/framework/context.d.ts +16 -5
- package/dist/src/planner/framework/context.d.ts.map +1 -1
- package/dist/src/planner/framework/context.js +2 -0
- package/dist/src/planner/framework/context.js.map +1 -1
- package/dist/src/planner/framework/pass.d.ts +116 -0
- package/dist/src/planner/framework/pass.d.ts.map +1 -0
- package/dist/src/planner/framework/pass.js +236 -0
- package/dist/src/planner/framework/pass.js.map +1 -0
- package/dist/src/planner/nodes/aggregate-node.d.ts +16 -6
- package/dist/src/planner/nodes/aggregate-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/aggregate-node.js +40 -4
- package/dist/src/planner/nodes/aggregate-node.js.map +1 -1
- package/dist/src/planner/nodes/array-index-node.js.map +1 -1
- package/dist/src/planner/nodes/cache-node.d.ts +5 -2
- package/dist/src/planner/nodes/cache-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/cache-node.js +6 -0
- package/dist/src/planner/nodes/cache-node.js.map +1 -1
- package/dist/src/planner/nodes/constraint-check-node.d.ts +10 -2
- package/dist/src/planner/nodes/constraint-check-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/constraint-check-node.js +12 -4
- package/dist/src/planner/nodes/constraint-check-node.js.map +1 -1
- package/dist/src/planner/nodes/create-assertion-node.d.ts +22 -0
- package/dist/src/planner/nodes/create-assertion-node.d.ts.map +1 -0
- package/dist/src/planner/nodes/create-assertion-node.js +41 -0
- package/dist/src/planner/nodes/create-assertion-node.js.map +1 -0
- package/dist/src/planner/nodes/create-index-node.js +2 -2
- package/dist/src/planner/nodes/create-index-node.js.map +1 -1
- package/dist/src/planner/nodes/create-table-node.js +2 -2
- package/dist/src/planner/nodes/create-table-node.js.map +1 -1
- package/dist/src/planner/nodes/cte-node.d.ts +17 -2
- package/dist/src/planner/nodes/cte-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/cte-node.js +9 -1
- package/dist/src/planner/nodes/cte-node.js.map +1 -1
- package/dist/src/planner/nodes/cte-reference-node.js +1 -1
- package/dist/src/planner/nodes/cte-reference-node.js.map +1 -1
- package/dist/src/planner/nodes/declarative-schema.d.ts +62 -0
- package/dist/src/planner/nodes/declarative-schema.d.ts.map +1 -0
- package/dist/src/planner/nodes/declarative-schema.js +181 -0
- package/dist/src/planner/nodes/declarative-schema.js.map +1 -0
- package/dist/src/planner/nodes/delete-node.d.ts +8 -3
- package/dist/src/planner/nodes/delete-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/delete-node.js +10 -2
- package/dist/src/planner/nodes/delete-node.js.map +1 -1
- package/dist/src/planner/nodes/distinct-node.d.ts +3 -2
- package/dist/src/planner/nodes/distinct-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/distinct-node.js +17 -4
- package/dist/src/planner/nodes/distinct-node.js.map +1 -1
- package/dist/src/planner/nodes/dml-executor-node.d.ts +1 -1
- package/dist/src/planner/nodes/dml-executor-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/drop-assertion-node.d.ts +21 -0
- package/dist/src/planner/nodes/drop-assertion-node.d.ts.map +1 -0
- package/dist/src/planner/nodes/drop-assertion-node.js +41 -0
- package/dist/src/planner/nodes/drop-assertion-node.js.map +1 -0
- package/dist/src/planner/nodes/drop-table-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/drop-table-node.js +1 -0
- package/dist/src/planner/nodes/drop-table-node.js.map +1 -1
- package/dist/src/planner/nodes/filter.d.ts +8 -3
- package/dist/src/planner/nodes/filter.d.ts.map +1 -1
- package/dist/src/planner/nodes/filter.js +44 -0
- package/dist/src/planner/nodes/filter.js.map +1 -1
- package/dist/src/planner/nodes/insert-node.d.ts +9 -3
- package/dist/src/planner/nodes/insert-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/insert-node.js +11 -2
- package/dist/src/planner/nodes/insert-node.js.map +1 -1
- package/dist/src/planner/nodes/internal-recursive-cte-ref-node.d.ts +3 -4
- package/dist/src/planner/nodes/internal-recursive-cte-ref-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/internal-recursive-cte-ref-node.js +1 -16
- package/dist/src/planner/nodes/internal-recursive-cte-ref-node.js.map +1 -1
- package/dist/src/planner/nodes/join-node.d.ts +12 -3
- package/dist/src/planner/nodes/join-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/join-node.js +111 -2
- package/dist/src/planner/nodes/join-node.js.map +1 -1
- package/dist/src/planner/nodes/limit-offset.d.ts +7 -3
- package/dist/src/planner/nodes/limit-offset.d.ts.map +1 -1
- package/dist/src/planner/nodes/limit-offset.js +15 -0
- package/dist/src/planner/nodes/limit-offset.js.map +1 -1
- package/dist/src/planner/nodes/plan-node-type.d.ts +8 -0
- package/dist/src/planner/nodes/plan-node-type.d.ts.map +1 -1
- package/dist/src/planner/nodes/plan-node-type.js +8 -0
- package/dist/src/planner/nodes/plan-node-type.js.map +1 -1
- package/dist/src/planner/nodes/plan-node.d.ts +9 -9
- package/dist/src/planner/nodes/plan-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/plan-node.js +3 -3
- package/dist/src/planner/nodes/plan-node.js.map +1 -1
- package/dist/src/planner/nodes/pragma.d.ts +2 -1
- package/dist/src/planner/nodes/pragma.d.ts.map +1 -1
- package/dist/src/planner/nodes/pragma.js +3 -1
- package/dist/src/planner/nodes/pragma.js.map +1 -1
- package/dist/src/planner/nodes/project-node.d.ts +16 -3
- package/dist/src/planner/nodes/project-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/project-node.js +82 -2
- 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 +1 -1
- package/dist/src/planner/nodes/recursive-cte-node.js.map +1 -1
- package/dist/src/planner/nodes/reference.d.ts +13 -4
- package/dist/src/planner/nodes/reference.d.ts.map +1 -1
- package/dist/src/planner/nodes/reference.js +16 -0
- package/dist/src/planner/nodes/reference.js.map +1 -1
- package/dist/src/planner/nodes/remote-query-node.d.ts +37 -0
- package/dist/src/planner/nodes/remote-query-node.d.ts.map +1 -0
- package/dist/src/planner/nodes/remote-query-node.js +63 -0
- package/dist/src/planner/nodes/remote-query-node.js.map +1 -0
- package/dist/src/planner/nodes/retrieve-node.d.ts +46 -0
- package/dist/src/planner/nodes/retrieve-node.d.ts.map +1 -0
- package/dist/src/planner/nodes/retrieve-node.js +77 -0
- package/dist/src/planner/nodes/retrieve-node.js.map +1 -0
- package/dist/src/planner/nodes/returning-node.d.ts +4 -3
- package/dist/src/planner/nodes/returning-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/returning-node.js +44 -3
- package/dist/src/planner/nodes/returning-node.js.map +1 -1
- package/dist/src/planner/nodes/sequencing-node.d.ts +1 -1
- package/dist/src/planner/nodes/sequencing-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/sequencing-node.js.map +1 -1
- package/dist/src/planner/nodes/set-operation-node.d.ts +1 -1
- package/dist/src/planner/nodes/set-operation-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/set-operation-node.js.map +1 -1
- package/dist/src/planner/nodes/sort.d.ts +11 -2
- package/dist/src/planner/nodes/sort.d.ts.map +1 -1
- package/dist/src/planner/nodes/sort.js +23 -2
- package/dist/src/planner/nodes/sort.js.map +1 -1
- package/dist/src/planner/nodes/stream-aggregate.d.ts.map +1 -1
- package/dist/src/planner/nodes/stream-aggregate.js +4 -1
- package/dist/src/planner/nodes/stream-aggregate.js.map +1 -1
- package/dist/src/planner/nodes/table-access-nodes.d.ts +7 -1
- package/dist/src/planner/nodes/table-access-nodes.d.ts.map +1 -1
- package/dist/src/planner/nodes/table-access-nodes.js +22 -4
- package/dist/src/planner/nodes/table-access-nodes.js.map +1 -1
- package/dist/src/planner/nodes/table-function-call.d.ts +2 -1
- package/dist/src/planner/nodes/table-function-call.d.ts.map +1 -1
- package/dist/src/planner/nodes/table-function-call.js +12 -5
- package/dist/src/planner/nodes/table-function-call.js.map +1 -1
- package/dist/src/planner/nodes/transaction-node.js +2 -2
- package/dist/src/planner/nodes/transaction-node.js.map +1 -1
- package/dist/src/planner/nodes/update-node.d.ts +7 -1
- package/dist/src/planner/nodes/update-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/update-node.js +11 -2
- package/dist/src/planner/nodes/update-node.js.map +1 -1
- package/dist/src/planner/nodes/view-reference-node.js.map +1 -1
- package/dist/src/planner/nodes/window-function.js.map +1 -1
- package/dist/src/planner/nodes/window-node.js.map +1 -1
- package/dist/src/planner/optimizer-tuning.d.ts +11 -0
- package/dist/src/planner/optimizer-tuning.d.ts.map +1 -1
- package/dist/src/planner/optimizer-tuning.js +6 -0
- package/dist/src/planner/optimizer-tuning.js.map +1 -1
- package/dist/src/planner/optimizer.d.ts +17 -3
- package/dist/src/planner/optimizer.d.ts.map +1 -1
- package/dist/src/planner/optimizer.js +159 -67
- package/dist/src/planner/optimizer.js.map +1 -1
- package/dist/src/planner/planning-context.d.ts +5 -3
- package/dist/src/planner/planning-context.d.ts.map +1 -1
- package/dist/src/planner/planning-context.js +2 -0
- package/dist/src/planner/planning-context.js.map +1 -1
- package/dist/src/planner/resolve.d.ts +3 -2
- package/dist/src/planner/resolve.d.ts.map +1 -1
- package/dist/src/planner/resolve.js +6 -5
- package/dist/src/planner/resolve.js.map +1 -1
- package/dist/src/planner/rules/access/rule-select-access-path.d.ts +8 -3
- 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 +206 -47
- 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 +10 -3
- package/dist/src/planner/rules/aggregate/rule-aggregate-streaming.d.ts.map +1 -1
- package/dist/src/planner/rules/aggregate/rule-aggregate-streaming.js +95 -87
- package/dist/src/planner/rules/aggregate/rule-aggregate-streaming.js.map +1 -1
- package/dist/src/planner/rules/cache/rule-cte-optimization.d.ts +8 -2
- package/dist/src/planner/rules/cache/rule-cte-optimization.d.ts.map +1 -1
- package/dist/src/planner/rules/cache/rule-cte-optimization.js +24 -13
- package/dist/src/planner/rules/cache/rule-cte-optimization.js.map +1 -1
- package/dist/src/planner/rules/cache/rule-materialization-advisory.d.ts +9 -2
- package/dist/src/planner/rules/cache/rule-materialization-advisory.d.ts.map +1 -1
- package/dist/src/planner/rules/cache/rule-materialization-advisory.js +14 -7
- package/dist/src/planner/rules/cache/rule-materialization-advisory.js.map +1 -1
- package/dist/src/planner/rules/cache/rule-mutating-subquery-cache.d.ts +9 -3
- package/dist/src/planner/rules/cache/rule-mutating-subquery-cache.d.ts.map +1 -1
- package/dist/src/planner/rules/cache/rule-mutating-subquery-cache.js +34 -37
- package/dist/src/planner/rules/cache/rule-mutating-subquery-cache.js.map +1 -1
- package/dist/src/planner/rules/join/rule-join-greedy-commute.d.ts +14 -0
- package/dist/src/planner/rules/join/rule-join-greedy-commute.d.ts.map +1 -0
- package/dist/src/planner/rules/join/rule-join-greedy-commute.js +33 -0
- package/dist/src/planner/rules/join/rule-join-greedy-commute.js.map +1 -0
- package/dist/src/planner/rules/join/rule-join-key-inference.d.ts +11 -0
- package/dist/src/planner/rules/join/rule-join-key-inference.d.ts.map +1 -0
- package/dist/src/planner/rules/join/rule-join-key-inference.js +32 -0
- package/dist/src/planner/rules/join/rule-join-key-inference.js.map +1 -0
- package/dist/src/planner/rules/join/rule-quickpick-enumeration.d.ts +4 -0
- package/dist/src/planner/rules/join/rule-quickpick-enumeration.d.ts.map +1 -0
- package/dist/src/planner/rules/join/rule-quickpick-enumeration.js +233 -0
- package/dist/src/planner/rules/join/rule-quickpick-enumeration.js.map +1 -0
- package/dist/src/planner/rules/predicate/rule-predicate-pushdown.d.ts +21 -0
- package/dist/src/planner/rules/predicate/rule-predicate-pushdown.d.ts.map +1 -0
- package/dist/src/planner/rules/predicate/rule-predicate-pushdown.js +125 -0
- package/dist/src/planner/rules/predicate/rule-predicate-pushdown.js.map +1 -0
- package/dist/src/planner/rules/retrieve/rule-grow-retrieve.d.ts +21 -0
- package/dist/src/planner/rules/retrieve/rule-grow-retrieve.d.ts.map +1 -0
- package/dist/src/planner/rules/retrieve/rule-grow-retrieve.js +261 -0
- package/dist/src/planner/rules/retrieve/rule-grow-retrieve.js.map +1 -0
- package/dist/src/planner/scopes/registered.d.ts +1 -0
- package/dist/src/planner/scopes/registered.d.ts.map +1 -1
- package/dist/src/planner/scopes/registered.js +7 -0
- package/dist/src/planner/scopes/registered.js.map +1 -1
- package/dist/src/planner/stats/index.d.ts +0 -17
- package/dist/src/planner/stats/index.d.ts.map +1 -1
- package/dist/src/planner/stats/index.js +0 -58
- package/dist/src/planner/stats/index.js.map +1 -1
- package/dist/src/planner/util/deferred-constraint.d.ts +14 -0
- package/dist/src/planner/util/deferred-constraint.d.ts.map +1 -0
- package/dist/src/planner/util/deferred-constraint.js +85 -0
- package/dist/src/planner/util/deferred-constraint.js.map +1 -0
- package/dist/src/planner/util/key-utils.d.ts +15 -0
- package/dist/src/planner/util/key-utils.d.ts.map +1 -0
- package/dist/src/planner/util/key-utils.js +43 -0
- package/dist/src/planner/util/key-utils.js.map +1 -0
- package/dist/src/planner/validation/plan-validator.d.ts.map +1 -1
- package/dist/src/planner/validation/plan-validator.js +1 -0
- package/dist/src/planner/validation/plan-validator.js.map +1 -1
- package/dist/src/runtime/deferred-constraint-queue.d.ts +33 -0
- package/dist/src/runtime/deferred-constraint-queue.d.ts.map +1 -0
- package/dist/src/runtime/deferred-constraint-queue.js +172 -0
- package/dist/src/runtime/deferred-constraint-queue.js.map +1 -0
- package/dist/src/runtime/emission-context.d.ts +9 -3
- package/dist/src/runtime/emission-context.d.ts.map +1 -1
- package/dist/src/runtime/emission-context.js +5 -1
- package/dist/src/runtime/emission-context.js.map +1 -1
- package/dist/src/runtime/emit/add-constraint.d.ts.map +1 -1
- package/dist/src/runtime/emit/add-constraint.js +22 -4
- package/dist/src/runtime/emit/add-constraint.js.map +1 -1
- package/dist/src/runtime/emit/aggregate.d.ts.map +1 -1
- package/dist/src/runtime/emit/aggregate.js +3 -2
- package/dist/src/runtime/emit/aggregate.js.map +1 -1
- package/dist/src/runtime/emit/array-index.js.map +1 -1
- package/dist/src/runtime/emit/binary.d.ts.map +1 -1
- package/dist/src/runtime/emit/binary.js +9 -2
- package/dist/src/runtime/emit/binary.js.map +1 -1
- package/dist/src/runtime/emit/cache.d.ts.map +1 -1
- package/dist/src/runtime/emit/cache.js +1 -1
- package/dist/src/runtime/emit/cache.js.map +1 -1
- package/dist/src/runtime/emit/cast.d.ts.map +1 -1
- package/dist/src/runtime/emit/cast.js.map +1 -1
- package/dist/src/runtime/emit/constraint-check.d.ts.map +1 -1
- package/dist/src/runtime/emit/constraint-check.js +110 -23
- package/dist/src/runtime/emit/constraint-check.js.map +1 -1
- package/dist/src/runtime/emit/create-assertion.d.ts +5 -0
- package/dist/src/runtime/emit/create-assertion.d.ts.map +1 -0
- package/dist/src/runtime/emit/create-assertion.js +70 -0
- package/dist/src/runtime/emit/create-assertion.js.map +1 -0
- package/dist/src/runtime/emit/cte-reference.d.ts.map +1 -1
- package/dist/src/runtime/emit/cte-reference.js.map +1 -1
- package/dist/src/runtime/emit/cte.d.ts.map +1 -1
- package/dist/src/runtime/emit/cte.js.map +1 -1
- package/dist/src/runtime/emit/distinct.d.ts.map +1 -1
- package/dist/src/runtime/emit/distinct.js.map +1 -1
- package/dist/src/runtime/emit/dml-executor.d.ts.map +1 -1
- package/dist/src/runtime/emit/dml-executor.js +17 -9
- package/dist/src/runtime/emit/dml-executor.js.map +1 -1
- package/dist/src/runtime/emit/drop-assertion.d.ts +5 -0
- package/dist/src/runtime/emit/drop-assertion.d.ts.map +1 -0
- package/dist/src/runtime/emit/drop-assertion.js +30 -0
- package/dist/src/runtime/emit/drop-assertion.js.map +1 -0
- package/dist/src/runtime/emit/filter.d.ts.map +1 -1
- package/dist/src/runtime/emit/filter.js.map +1 -1
- package/dist/src/runtime/emit/join.d.ts.map +1 -1
- package/dist/src/runtime/emit/join.js.map +1 -1
- package/dist/src/runtime/emit/limit-offset.d.ts.map +1 -1
- package/dist/src/runtime/emit/limit-offset.js.map +1 -1
- package/dist/src/runtime/emit/pragma.js.map +1 -1
- package/dist/src/runtime/emit/project.d.ts.map +1 -1
- 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 +1 -1
- package/dist/src/runtime/emit/recursive-cte.js.map +1 -1
- package/dist/src/runtime/emit/remote-query.d.ts +9 -0
- package/dist/src/runtime/emit/remote-query.d.ts.map +1 -0
- package/dist/src/runtime/emit/remote-query.js +30 -0
- package/dist/src/runtime/emit/remote-query.js.map +1 -0
- package/dist/src/runtime/emit/retrieve.d.ts +5 -0
- package/dist/src/runtime/emit/retrieve.d.ts.map +1 -0
- package/dist/src/runtime/emit/retrieve.js +9 -0
- package/dist/src/runtime/emit/retrieve.js.map +1 -0
- package/dist/src/runtime/emit/returning.d.ts.map +1 -1
- package/dist/src/runtime/emit/returning.js +1 -1
- package/dist/src/runtime/emit/returning.js.map +1 -1
- package/dist/src/runtime/emit/scalar-function.d.ts.map +1 -1
- package/dist/src/runtime/emit/scalar-function.js.map +1 -1
- package/dist/src/runtime/emit/scan.d.ts.map +1 -1
- package/dist/src/runtime/emit/scan.js +20 -5
- package/dist/src/runtime/emit/scan.js.map +1 -1
- package/dist/src/runtime/emit/schema-declarative.d.ts +8 -0
- package/dist/src/runtime/emit/schema-declarative.d.ts.map +1 -0
- package/dist/src/runtime/emit/schema-declarative.js +163 -0
- package/dist/src/runtime/emit/schema-declarative.js.map +1 -0
- package/dist/src/runtime/emit/sequencing.d.ts.map +1 -1
- package/dist/src/runtime/emit/sequencing.js.map +1 -1
- package/dist/src/runtime/emit/set-operation.d.ts.map +1 -1
- package/dist/src/runtime/emit/set-operation.js +6 -6
- package/dist/src/runtime/emit/set-operation.js.map +1 -1
- package/dist/src/runtime/emit/sort.d.ts.map +1 -1
- package/dist/src/runtime/emit/sort.js.map +1 -1
- package/dist/src/runtime/emit/subquery.d.ts +1 -1
- package/dist/src/runtime/emit/subquery.d.ts.map +1 -1
- package/dist/src/runtime/emit/subquery.js +6 -6
- package/dist/src/runtime/emit/subquery.js.map +1 -1
- package/dist/src/runtime/emit/transaction.d.ts.map +1 -1
- package/dist/src/runtime/emit/transaction.js +48 -8
- package/dist/src/runtime/emit/transaction.js.map +1 -1
- package/dist/src/runtime/emit/values.d.ts.map +1 -1
- package/dist/src/runtime/emit/values.js.map +1 -1
- package/dist/src/runtime/emit/window.d.ts.map +1 -1
- 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 +1 -0
- 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 +16 -2
- package/dist/src/runtime/register.js.map +1 -1
- package/dist/src/runtime/scheduler.js.map +1 -1
- package/dist/src/runtime/types.d.ts +2 -2
- package/dist/src/runtime/types.d.ts.map +1 -1
- package/dist/src/runtime/types.js +4 -1
- package/dist/src/runtime/types.js.map +1 -1
- package/dist/src/runtime/utils.d.ts +2 -2
- package/dist/src/runtime/utils.d.ts.map +1 -1
- package/dist/src/runtime/utils.js +1 -0
- package/dist/src/runtime/utils.js.map +1 -1
- package/dist/src/schema/assertion.d.ts +19 -0
- package/dist/src/schema/assertion.d.ts.map +1 -0
- package/dist/src/schema/assertion.js +2 -0
- package/dist/src/schema/assertion.js.map +1 -0
- package/dist/src/schema/catalog.d.ts +44 -0
- package/dist/src/schema/catalog.d.ts.map +1 -0
- package/dist/src/schema/catalog.js +148 -0
- package/dist/src/schema/catalog.js.map +1 -0
- package/dist/src/schema/change-events.d.ts +2 -2
- package/dist/src/schema/change-events.d.ts.map +1 -1
- package/dist/src/schema/column.d.ts +2 -0
- package/dist/src/schema/column.d.ts.map +1 -1
- package/dist/src/schema/column.js.map +1 -1
- package/dist/src/schema/declared-schema-manager.d.ts +42 -0
- package/dist/src/schema/declared-schema-manager.d.ts.map +1 -0
- package/dist/src/schema/declared-schema-manager.js +71 -0
- package/dist/src/schema/declared-schema-manager.js.map +1 -0
- package/dist/src/schema/function.d.ts +3 -2
- package/dist/src/schema/function.d.ts.map +1 -1
- package/dist/src/schema/function.js.map +1 -1
- package/dist/src/schema/manager.d.ts +8 -3
- package/dist/src/schema/manager.d.ts.map +1 -1
- package/dist/src/schema/manager.js +32 -3
- package/dist/src/schema/manager.js.map +1 -1
- package/dist/src/schema/schema-differ.d.ts +34 -0
- package/dist/src/schema/schema-differ.d.ts.map +1 -0
- package/dist/src/schema/schema-differ.js +157 -0
- package/dist/src/schema/schema-differ.js.map +1 -0
- package/dist/src/schema/schema-hasher.d.ts +10 -0
- package/dist/src/schema/schema-hasher.d.ts.map +1 -0
- package/dist/src/schema/schema-hasher.js +39 -0
- package/dist/src/schema/schema-hasher.js.map +1 -0
- package/dist/src/schema/schema.d.ts +7 -0
- package/dist/src/schema/schema.d.ts.map +1 -1
- package/dist/src/schema/schema.js +19 -0
- package/dist/src/schema/schema.js.map +1 -1
- package/dist/src/schema/table.d.ts +28 -3
- package/dist/src/schema/table.d.ts.map +1 -1
- package/dist/src/schema/table.js +17 -2
- package/dist/src/schema/table.js.map +1 -1
- package/dist/src/schema/window-function.d.ts.map +1 -1
- package/dist/src/schema/window-function.js.map +1 -1
- package/dist/src/util/ast-stringify.d.ts.map +1 -1
- package/dist/src/util/ast-stringify.js +116 -3
- package/dist/src/util/ast-stringify.js.map +1 -1
- package/dist/src/util/environment.js.map +1 -1
- package/dist/src/util/plugin-loader.d.ts +25 -2
- package/dist/src/util/plugin-loader.d.ts.map +1 -1
- package/dist/src/util/plugin-loader.js +180 -2
- package/dist/src/util/plugin-loader.js.map +1 -1
- package/dist/src/util/row-descriptor.d.ts +1 -1
- package/dist/src/util/row-descriptor.d.ts.map +1 -1
- package/dist/src/util/row-descriptor.js.map +1 -1
- package/dist/src/util/serialization.d.ts +3 -0
- package/dist/src/util/serialization.d.ts.map +1 -1
- package/dist/src/util/serialization.js +1 -0
- package/dist/src/util/serialization.js.map +1 -1
- package/dist/src/vtab/best-access-plan.d.ts +1 -1
- package/dist/src/vtab/best-access-plan.d.ts.map +1 -1
- package/dist/src/vtab/best-access-plan.js +1 -0
- package/dist/src/vtab/best-access-plan.js.map +1 -1
- package/dist/src/vtab/manifest.d.ts.map +1 -1
- package/dist/src/vtab/memory/layer/base.d.ts.map +1 -1
- package/dist/src/vtab/memory/layer/base.js +2 -0
- package/dist/src/vtab/memory/layer/base.js.map +1 -1
- package/dist/src/vtab/memory/layer/manager.d.ts +2 -1
- package/dist/src/vtab/memory/layer/manager.d.ts.map +1 -1
- package/dist/src/vtab/memory/layer/manager.js +24 -6
- package/dist/src/vtab/memory/layer/manager.js.map +1 -1
- package/dist/src/vtab/memory/layer/safe-iterate.d.ts.map +1 -1
- package/dist/src/vtab/memory/layer/safe-iterate.js.map +1 -1
- package/dist/src/vtab/memory/module.d.ts.map +1 -1
- package/dist/src/vtab/memory/module.js +5 -0
- package/dist/src/vtab/memory/module.js.map +1 -1
- package/dist/src/vtab/memory/table.d.ts +2 -1
- package/dist/src/vtab/memory/table.d.ts.map +1 -1
- package/dist/src/vtab/memory/table.js +3 -2
- package/dist/src/vtab/memory/table.js.map +1 -1
- package/dist/src/vtab/memory/utils/logging.d.ts +2 -2
- package/dist/src/vtab/memory/utils/logging.d.ts.map +1 -1
- package/dist/src/vtab/memory/utils/logging.js +6 -3
- package/dist/src/vtab/memory/utils/logging.js.map +1 -1
- package/dist/src/vtab/module.d.ts +25 -0
- package/dist/src/vtab/module.d.ts.map +1 -1
- package/dist/src/vtab/table.d.ts +17 -4
- package/dist/src/vtab/table.d.ts.map +1 -1
- package/dist/src/vtab/table.js.map +1 -1
- package/package.json +4 -2
- package/src/common/errors.ts +1 -1
- package/src/common/json-types.ts +16 -0
- package/src/common/types.ts +2 -0
- package/src/core/database-options.ts +8 -8
- package/src/core/database.ts +537 -71
- package/src/core/statement.ts +3 -1
- package/src/func/builtins/builtin-window-functions.ts +11 -10
- package/src/func/builtins/datetime.ts +42 -0
- package/src/func/builtins/explain.ts +186 -44
- package/src/func/builtins/index.ts +5 -2
- package/src/func/builtins/json-helpers.ts +21 -21
- package/src/func/builtins/json-tvf.ts +8 -9
- package/src/func/builtins/json.ts +10 -9
- package/src/func/builtins/schema.ts +24 -4
- package/src/func/context.ts +7 -0
- package/src/func/registration.ts +5 -1
- package/src/index.ts +2 -2
- package/src/parser/ast.ts +582 -481
- package/src/parser/lexer.ts +27 -21
- package/src/parser/parser.ts +3336 -2776
- package/src/parser/visitor.ts +1 -0
- package/src/planner/analysis/binding-collector.ts +83 -0
- package/src/planner/analysis/const-evaluator.ts +1 -1
- package/src/planner/analysis/const-pass.ts +3 -2
- package/src/planner/analysis/constraint-extractor.ts +610 -123
- package/src/planner/analysis/predicate-normalizer.ts +237 -0
- package/src/planner/building/alter-table.ts +3 -1
- package/src/planner/building/block.ts +93 -78
- package/src/planner/building/constraint-builder.ts +173 -114
- package/src/planner/building/create-assertion.ts +7 -0
- package/src/planner/building/declare-schema.ts +22 -0
- package/src/planner/building/delete.ts +214 -171
- package/src/planner/building/drop-assertion.ts +11 -0
- package/src/planner/building/expression.ts +1 -0
- package/src/planner/building/function-call.ts +6 -5
- package/src/planner/building/insert.ts +428 -349
- package/src/planner/building/pragma.ts +1 -0
- package/src/planner/building/schema-resolution.ts +176 -176
- package/src/planner/building/select-aggregates.ts +5 -3
- package/src/planner/building/select-compound.ts +22 -13
- package/src/planner/building/select-context.ts +6 -6
- package/src/planner/building/select-modifiers.ts +8 -7
- package/src/planner/building/select-projections.ts +177 -176
- package/src/planner/building/select-window.ts +259 -253
- package/src/planner/building/select.ts +531 -520
- package/src/planner/building/table-function.ts +49 -48
- package/src/planner/building/table.ts +9 -3
- package/src/planner/building/update.ts +319 -270
- package/src/planner/building/with.ts +7 -7
- package/src/planner/debug.ts +1 -0
- package/src/planner/framework/characteristics.ts +503 -0
- package/src/planner/framework/context.ts +23 -6
- package/src/planner/framework/pass.ts +354 -0
- package/src/planner/nodes/aggregate-node.ts +52 -7
- package/src/planner/nodes/array-index-node.ts +1 -1
- package/src/planner/nodes/cache-node.ts +11 -2
- package/src/planner/nodes/constraint-check-node.ts +14 -5
- package/src/planner/nodes/create-assertion-node.ts +51 -0
- package/src/planner/nodes/create-index-node.ts +2 -2
- package/src/planner/nodes/create-table-node.ts +2 -2
- package/src/planner/nodes/cte-node.ts +30 -4
- package/src/planner/nodes/cte-reference-node.ts +2 -2
- package/src/planner/nodes/declarative-schema.ts +221 -0
- package/src/planner/nodes/delete-node.ts +102 -96
- package/src/planner/nodes/distinct-node.ts +20 -6
- package/src/planner/nodes/dml-executor-node.ts +1 -1
- package/src/planner/nodes/drop-assertion-node.ts +50 -0
- package/src/planner/nodes/drop-table-node.ts +1 -0
- package/src/planner/nodes/filter.ts +56 -3
- package/src/planner/nodes/insert-node.ts +126 -120
- package/src/planner/nodes/internal-recursive-cte-ref-node.ts +5 -20
- package/src/planner/nodes/join-node.ts +122 -4
- package/src/planner/nodes/limit-offset.ts +132 -113
- package/src/planner/nodes/plan-node-type.ts +95 -87
- package/src/planner/nodes/plan-node.ts +8 -8
- package/src/planner/nodes/pragma.ts +6 -3
- package/src/planner/nodes/project-node.ts +101 -7
- package/src/planner/nodes/recursive-cte-node.ts +6 -6
- package/src/planner/nodes/reference.ts +334 -312
- package/src/planner/nodes/remote-query-node.ts +73 -0
- package/src/planner/nodes/retrieve-node.ts +86 -0
- package/src/planner/nodes/returning-node.ts +52 -10
- package/src/planner/nodes/sequencing-node.ts +2 -2
- package/src/planner/nodes/set-operation-node.ts +3 -3
- package/src/planner/nodes/sort.ts +33 -4
- package/src/planner/nodes/stream-aggregate.ts +5 -1
- package/src/planner/nodes/table-access-nodes.ts +31 -6
- package/src/planner/nodes/table-function-call.ts +134 -127
- package/src/planner/nodes/transaction-node.ts +2 -2
- package/src/planner/nodes/update-node.ts +138 -132
- package/src/planner/nodes/view-reference-node.ts +1 -1
- package/src/planner/nodes/window-function.ts +2 -2
- package/src/planner/nodes/window-node.ts +1 -1
- package/src/planner/optimizer-tuning.ts +18 -0
- package/src/planner/optimizer.ts +171 -96
- package/src/planner/planning-context.ts +10 -3
- package/src/planner/resolve.ts +10 -9
- package/src/planner/rules/README.md +96 -96
- package/src/planner/rules/access/rule-select-access-path.ts +384 -184
- package/src/planner/rules/aggregate/rule-aggregate-streaming.ts +118 -104
- package/src/planner/rules/cache/rule-cte-optimization.ts +29 -16
- package/src/planner/rules/cache/rule-materialization-advisory.ts +14 -7
- package/src/planner/rules/cache/rule-mutating-subquery-cache.ts +38 -44
- package/src/planner/rules/join/rule-join-greedy-commute.ts +48 -0
- package/src/planner/rules/join/rule-join-key-inference.ts +35 -0
- package/src/planner/rules/join/rule-quickpick-enumeration.ts +267 -0
- package/src/planner/rules/predicate/rule-predicate-pushdown.ts +144 -0
- package/src/planner/rules/retrieve/rule-grow-retrieve.ts +337 -0
- package/src/planner/scopes/registered.ts +8 -0
- package/src/planner/stats/index.ts +0 -65
- package/src/planner/util/key-utils.ts +46 -0
- package/src/planner/validation/plan-validator.ts +5 -3
- package/src/runtime/deferred-constraint-queue.ts +196 -0
- package/src/runtime/emission-context.ts +11 -5
- package/src/runtime/emit/add-constraint.ts +26 -5
- package/src/runtime/emit/aggregate.ts +9 -7
- package/src/runtime/emit/array-index.ts +2 -2
- package/src/runtime/emit/binary.ts +26 -8
- package/src/runtime/emit/cache.ts +2 -2
- package/src/runtime/emit/cast.ts +2 -2
- package/src/runtime/emit/constraint-check.ts +148 -26
- package/src/runtime/emit/create-assertion.ts +82 -0
- package/src/runtime/emit/cte-reference.ts +2 -2
- package/src/runtime/emit/cte.ts +2 -2
- package/src/runtime/emit/distinct.ts +2 -2
- package/src/runtime/emit/dml-executor.ts +20 -12
- package/src/runtime/emit/drop-assertion.ts +45 -0
- package/src/runtime/emit/filter.ts +4 -4
- package/src/runtime/emit/join.ts +8 -7
- package/src/runtime/emit/limit-offset.ts +2 -2
- package/src/runtime/emit/pragma.ts +2 -2
- package/src/runtime/emit/project.ts +2 -2
- package/src/runtime/emit/recursive-cte.ts +2 -2
- package/src/runtime/emit/remote-query.ts +47 -0
- package/src/runtime/emit/retrieve.ts +15 -0
- package/src/runtime/emit/returning.ts +4 -4
- package/src/runtime/emit/scalar-function.ts +2 -2
- package/src/runtime/emit/scan.ts +29 -13
- package/src/runtime/emit/schema-declarative.ts +205 -0
- package/src/runtime/emit/sequencing.ts +3 -3
- package/src/runtime/emit/set-operation.ts +7 -7
- package/src/runtime/emit/sort.ts +2 -2
- package/src/runtime/emit/subquery.ts +10 -10
- package/src/runtime/emit/transaction.ts +46 -8
- package/src/runtime/emit/values.ts +2 -2
- package/src/runtime/emit/window.ts +3 -3
- package/src/runtime/emitters.ts +1 -0
- package/src/runtime/register.ts +150 -135
- package/src/runtime/scheduler.ts +2 -2
- package/src/runtime/types.ts +10 -7
- package/src/runtime/utils.ts +3 -2
- package/src/schema/assertion.ts +21 -0
- package/src/schema/catalog.ts +208 -0
- package/src/schema/change-events.ts +2 -2
- package/src/schema/column.ts +2 -0
- package/src/schema/declared-schema-manager.ts +82 -0
- package/src/schema/function.ts +5 -2
- package/src/schema/manager.ts +742 -709
- package/src/schema/schema-differ.ts +214 -0
- package/src/schema/schema-hasher.ts +44 -0
- package/src/schema/schema.ts +23 -0
- package/src/schema/table.ts +398 -364
- package/src/schema/window-function.ts +2 -0
- package/src/util/ast-stringify.ts +869 -764
- package/src/util/environment.ts +2 -2
- package/src/util/plugin-loader.ts +232 -7
- package/src/util/row-descriptor.ts +1 -1
- package/src/util/serialization.ts +2 -0
- package/src/vtab/best-access-plan.ts +2 -1
- package/src/vtab/manifest.ts +1 -0
- package/src/vtab/memory/index.ts +178 -178
- package/src/vtab/memory/layer/base.ts +275 -273
- package/src/vtab/memory/layer/interface.ts +47 -47
- package/src/vtab/memory/layer/manager.ts +33 -11
- package/src/vtab/memory/layer/safe-iterate.ts +3 -3
- package/src/vtab/memory/layer/transaction.ts +229 -229
- package/src/vtab/memory/module.ts +24 -18
- package/src/vtab/memory/table.ts +256 -253
- package/src/vtab/memory/utils/logging.ts +6 -3
- package/src/vtab/module.ts +170 -140
- package/src/vtab/table.ts +162 -143
|
@@ -1,349 +1,428 @@
|
|
|
1
|
-
import type * as AST from '../../parser/ast.js';
|
|
2
|
-
import type { PlanningContext } from '../planning-context.js';
|
|
3
|
-
import { InsertNode } from '../nodes/insert-node.js';
|
|
4
|
-
import { buildTableReference } from './table.js';
|
|
5
|
-
import { QuereusError } from '../../common/errors.js';
|
|
6
|
-
import { StatusCode } from '../../common/types.js';
|
|
7
|
-
import { buildSelectStmt } from './select.js';
|
|
8
|
-
import { buildWithClause } from './with.js';
|
|
9
|
-
import { ValuesNode } from '../nodes/values-node.js';
|
|
10
|
-
import { PlanNode, type RelationalPlanNode, type ScalarPlanNode } from '../nodes/plan-node.js';
|
|
11
|
-
import { buildExpression } from './expression.js';
|
|
12
|
-
import { checkColumnsAssignable, columnSchemaToDef } from '../type-utils.js';
|
|
13
|
-
import type { ColumnDef } from '../../common/datatype.js';
|
|
14
|
-
import type {
|
|
15
|
-
import { RegisteredScope } from '../scopes/registered.js';
|
|
16
|
-
import { ColumnReferenceNode } from '../nodes/reference.js';
|
|
17
|
-
import { SinkNode } from '../nodes/sink-node.js';
|
|
18
|
-
import { ConstraintCheckNode } from '../nodes/constraint-check-node.js';
|
|
19
|
-
import { RowOpFlag } from '../../schema/table.js';
|
|
20
|
-
import { ReturningNode } from '../nodes/returning-node.js';
|
|
21
|
-
import { ProjectNode, type Projection } from '../nodes/project-node.js';
|
|
22
|
-
import { buildOldNewRowDescriptors } from '../../util/row-descriptor.js';
|
|
23
|
-
import { DmlExecutorNode } from '../nodes/dml-executor-node.js';
|
|
24
|
-
import { buildConstraintChecks } from './constraint-builder.js';
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Creates a uniform row expansion projection that maps any relational source
|
|
28
|
-
* to the target table's column structure, filling in defaults for omitted columns.
|
|
29
|
-
* This ensures INSERT works orthogonally with any relational source.
|
|
30
|
-
*/
|
|
31
|
-
function createRowExpansionProjection(
|
|
32
|
-
ctx: PlanningContext,
|
|
33
|
-
sourceNode: RelationalPlanNode,
|
|
34
|
-
targetColumns: ColumnDef[],
|
|
35
|
-
tableReference:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
)
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
//
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
// Create
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
const
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
1
|
+
import type * as AST from '../../parser/ast.js';
|
|
2
|
+
import type { PlanningContext } from '../planning-context.js';
|
|
3
|
+
import { InsertNode } from '../nodes/insert-node.js';
|
|
4
|
+
import { buildTableReference } from './table.js';
|
|
5
|
+
import { QuereusError } from '../../common/errors.js';
|
|
6
|
+
import { StatusCode } from '../../common/types.js';
|
|
7
|
+
import { buildSelectStmt } from './select.js';
|
|
8
|
+
import { buildWithClause } from './with.js';
|
|
9
|
+
import { ValuesNode } from '../nodes/values-node.js';
|
|
10
|
+
import { PlanNode, type RelationalPlanNode, type ScalarPlanNode, type Attribute, type RowDescriptor } from '../nodes/plan-node.js';
|
|
11
|
+
import { buildExpression } from './expression.js';
|
|
12
|
+
import { checkColumnsAssignable, columnSchemaToDef } from '../type-utils.js';
|
|
13
|
+
import type { ColumnDef } from '../../common/datatype.js';
|
|
14
|
+
import type { CTEScopeNode } from '../nodes/cte-node.js';
|
|
15
|
+
import { RegisteredScope } from '../scopes/registered.js';
|
|
16
|
+
import { ColumnReferenceNode, TableReferenceNode } from '../nodes/reference.js';
|
|
17
|
+
import { SinkNode } from '../nodes/sink-node.js';
|
|
18
|
+
import { ConstraintCheckNode } from '../nodes/constraint-check-node.js';
|
|
19
|
+
import { RowOpFlag } from '../../schema/table.js';
|
|
20
|
+
import { ReturningNode } from '../nodes/returning-node.js';
|
|
21
|
+
import { ProjectNode, type Projection } from '../nodes/project-node.js';
|
|
22
|
+
import { buildOldNewRowDescriptors } from '../../util/row-descriptor.js';
|
|
23
|
+
import { DmlExecutorNode } from '../nodes/dml-executor-node.js';
|
|
24
|
+
import { buildConstraintChecks } from './constraint-builder.js';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Creates a uniform row expansion projection that maps any relational source
|
|
28
|
+
* to the target table's column structure, filling in defaults for omitted columns.
|
|
29
|
+
* This ensures INSERT works orthogonally with any relational source.
|
|
30
|
+
*/
|
|
31
|
+
function createRowExpansionProjection(
|
|
32
|
+
ctx: PlanningContext,
|
|
33
|
+
sourceNode: RelationalPlanNode,
|
|
34
|
+
targetColumns: ColumnDef[],
|
|
35
|
+
tableReference: TableReferenceNode,
|
|
36
|
+
contextScope?: RegisteredScope
|
|
37
|
+
): RelationalPlanNode {
|
|
38
|
+
const tableSchema = tableReference.tableSchema;
|
|
39
|
+
|
|
40
|
+
// If we're inserting into all columns in table order, no expansion needed
|
|
41
|
+
if (targetColumns.length === tableSchema.columns.length) {
|
|
42
|
+
const allColumnsMatch = targetColumns.every((tc, i) =>
|
|
43
|
+
tc.name.toLowerCase() === tableSchema.columns[i].name.toLowerCase()
|
|
44
|
+
);
|
|
45
|
+
if (allColumnsMatch) {
|
|
46
|
+
return sourceNode; // Source already matches table structure
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Create projection expressions for each table column
|
|
51
|
+
const projections: Projection[] = [];
|
|
52
|
+
const sourceAttributes = sourceNode.getAttributes();
|
|
53
|
+
|
|
54
|
+
// If we have a context scope, we need to also register source columns in it
|
|
55
|
+
// so that defaults can reference them (e.g., DEFAULT base_price + markup)
|
|
56
|
+
if (contextScope) {
|
|
57
|
+
targetColumns.forEach((targetCol, index) => {
|
|
58
|
+
if (index < sourceAttributes.length) {
|
|
59
|
+
const sourceAttr = sourceAttributes[index];
|
|
60
|
+
const colNameLower = targetCol.name.toLowerCase();
|
|
61
|
+
contextScope.registerSymbol(colNameLower, (exp, s) =>
|
|
62
|
+
new ColumnReferenceNode(s, exp as AST.ColumnExpr, sourceAttr.type, sourceAttr.id, index)
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
tableSchema.columns.forEach((tableColumn) => {
|
|
69
|
+
// Find if this table column is in the target columns
|
|
70
|
+
const targetColIndex = targetColumns.findIndex(tc =>
|
|
71
|
+
tc.name.toLowerCase() === tableColumn.name.toLowerCase()
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
if (targetColIndex >= 0) {
|
|
75
|
+
// This column is provided by the source - reference the source column
|
|
76
|
+
if (targetColIndex < sourceAttributes.length) {
|
|
77
|
+
const sourceAttr = sourceAttributes[targetColIndex];
|
|
78
|
+
// Create a column reference to the source attribute
|
|
79
|
+
const columnRef = new ColumnReferenceNode(
|
|
80
|
+
ctx.scope,
|
|
81
|
+
{ type: 'column', name: sourceAttr.name } satisfies AST.ColumnExpr,
|
|
82
|
+
sourceAttr.type,
|
|
83
|
+
sourceAttr.id,
|
|
84
|
+
targetColIndex
|
|
85
|
+
);
|
|
86
|
+
projections.push({
|
|
87
|
+
node: columnRef,
|
|
88
|
+
alias: tableColumn.name
|
|
89
|
+
});
|
|
90
|
+
} else {
|
|
91
|
+
throw new QuereusError(
|
|
92
|
+
`Source has fewer columns than expected for INSERT target columns`,
|
|
93
|
+
StatusCode.ERROR
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
// This column is omitted - use default value or NULL
|
|
98
|
+
let defaultNode: ScalarPlanNode;
|
|
99
|
+
// Use context scope for default evaluation if available
|
|
100
|
+
const defaultCtx = contextScope ? { ...ctx, scope: contextScope } : ctx;
|
|
101
|
+
if (tableColumn.defaultValue !== undefined) {
|
|
102
|
+
// Use default value
|
|
103
|
+
if (typeof tableColumn.defaultValue === 'object' && tableColumn.defaultValue !== null && 'type' in tableColumn.defaultValue) {
|
|
104
|
+
// It's an AST.Expression - build it into a plan node with context scope
|
|
105
|
+
defaultNode = buildExpression(defaultCtx, tableColumn.defaultValue as AST.Expression) as ScalarPlanNode;
|
|
106
|
+
} else {
|
|
107
|
+
// Literal default value
|
|
108
|
+
defaultNode = buildExpression(defaultCtx, { type: 'literal', value: tableColumn.defaultValue }) as ScalarPlanNode;
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
// No default value - use NULL
|
|
112
|
+
defaultNode = buildExpression(defaultCtx, { type: 'literal', value: null }) as ScalarPlanNode;
|
|
113
|
+
}
|
|
114
|
+
projections.push({
|
|
115
|
+
node: defaultNode,
|
|
116
|
+
alias: tableColumn.name
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// Create projection node that expands source to table structure
|
|
122
|
+
return new ProjectNode(ctx.scope, sourceNode, projections);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Validates that RETURNING expressions use appropriate NEW/OLD qualifiers for the operation type
|
|
127
|
+
*/
|
|
128
|
+
function validateReturningExpression(expr: AST.Expression, operationType: 'INSERT' | 'UPDATE' | 'DELETE'): void {
|
|
129
|
+
function checkExpression(e: AST.Expression): void {
|
|
130
|
+
if (e.type === 'column') {
|
|
131
|
+
if (e.table?.toLowerCase() === 'old' && operationType === 'INSERT') {
|
|
132
|
+
throw new QuereusError(
|
|
133
|
+
'OLD qualifier cannot be used in INSERT RETURNING clause',
|
|
134
|
+
StatusCode.ERROR
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
if (e.table?.toLowerCase() === 'new' && operationType === 'DELETE') {
|
|
138
|
+
throw new QuereusError(
|
|
139
|
+
'NEW qualifier cannot be used in DELETE RETURNING clause',
|
|
140
|
+
StatusCode.ERROR
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
} else if (e.type === 'binary') {
|
|
144
|
+
checkExpression(e.left);
|
|
145
|
+
checkExpression(e.right);
|
|
146
|
+
} else if (e.type === 'unary') {
|
|
147
|
+
checkExpression(e.expr);
|
|
148
|
+
} else if (e.type === 'function') {
|
|
149
|
+
e.args.forEach(checkExpression);
|
|
150
|
+
} else if (e.type === 'case') {
|
|
151
|
+
if (e.baseExpr) checkExpression(e.baseExpr);
|
|
152
|
+
e.whenThenClauses.forEach(clause => {
|
|
153
|
+
checkExpression(clause.when);
|
|
154
|
+
checkExpression(clause.then);
|
|
155
|
+
});
|
|
156
|
+
if (e.elseExpr) checkExpression(e.elseExpr);
|
|
157
|
+
} else if (e.type === 'cast') {
|
|
158
|
+
checkExpression(e.expr);
|
|
159
|
+
} else if (e.type === 'collate') {
|
|
160
|
+
checkExpression(e.expr);
|
|
161
|
+
} else if (e.type === 'subquery') {
|
|
162
|
+
// Subqueries in RETURNING are complex - for now, we'll skip validation
|
|
163
|
+
// A full implementation would need to traverse the subquery's AST
|
|
164
|
+
} else if (e.type === 'in') {
|
|
165
|
+
checkExpression(e.expr);
|
|
166
|
+
if (e.values) {
|
|
167
|
+
e.values.forEach(checkExpression);
|
|
168
|
+
}
|
|
169
|
+
} else if (e.type === 'exists') {
|
|
170
|
+
// EXISTS subqueries are complex - skip validation for now
|
|
171
|
+
} else if (e.type === 'windowFunction') {
|
|
172
|
+
checkExpression(e.function);
|
|
173
|
+
}
|
|
174
|
+
// Other expression types (literal, parameter) don't need validation
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
checkExpression(expr);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function buildInsertStmt(
|
|
181
|
+
ctx: PlanningContext,
|
|
182
|
+
stmt: AST.InsertStmt,
|
|
183
|
+
): PlanNode {
|
|
184
|
+
const tableRetrieve = buildTableReference({ type: 'table', table: stmt.table }, ctx);
|
|
185
|
+
const tableReference = tableRetrieve.tableRef; // Extract the actual TableReferenceNode
|
|
186
|
+
|
|
187
|
+
// Process mutation context assignments if present
|
|
188
|
+
const mutationContextValues = new Map<string, ScalarPlanNode>();
|
|
189
|
+
const contextAttributes: Attribute[] = [];
|
|
190
|
+
let contextScope: RegisteredScope | undefined;
|
|
191
|
+
|
|
192
|
+
if (stmt.contextValues && tableReference.tableSchema.mutationContext) {
|
|
193
|
+
// Create context attributes
|
|
194
|
+
tableReference.tableSchema.mutationContext.forEach((contextVar) => {
|
|
195
|
+
contextAttributes.push({
|
|
196
|
+
id: PlanNode.nextAttrId(),
|
|
197
|
+
name: contextVar.name,
|
|
198
|
+
type: {
|
|
199
|
+
typeClass: 'scalar' as const,
|
|
200
|
+
affinity: contextVar.affinity,
|
|
201
|
+
nullable: !contextVar.notNull,
|
|
202
|
+
isReadOnly: true
|
|
203
|
+
},
|
|
204
|
+
sourceRelation: `context.${tableReference.tableSchema.name}`
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
// Create a new scope for mutation context
|
|
209
|
+
contextScope = new RegisteredScope(ctx.scope);
|
|
210
|
+
|
|
211
|
+
// Register mutation context variables in the scope (before evaluating expressions)
|
|
212
|
+
contextAttributes.forEach((attr, index) => {
|
|
213
|
+
const contextVar = tableReference.tableSchema.mutationContext![index];
|
|
214
|
+
const varNameLower = contextVar.name.toLowerCase();
|
|
215
|
+
|
|
216
|
+
// Register both unqualified and qualified names
|
|
217
|
+
contextScope!.subscribeFactory(varNameLower, (exp, s) =>
|
|
218
|
+
new ColumnReferenceNode(s, exp as AST.ColumnExpr, attr.type, attr.id, index)
|
|
219
|
+
);
|
|
220
|
+
contextScope!.subscribeFactory(`context.${varNameLower}`, (exp, s) =>
|
|
221
|
+
new ColumnReferenceNode(s, exp as AST.ColumnExpr, attr.type, attr.id, index)
|
|
222
|
+
);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
// Build context value expressions using the context scope
|
|
226
|
+
const contextWithScope = { ...ctx, scope: contextScope };
|
|
227
|
+
stmt.contextValues.forEach((assignment) => {
|
|
228
|
+
const valueExpr = buildExpression(contextWithScope, assignment.value) as ScalarPlanNode;
|
|
229
|
+
mutationContextValues.set(assignment.name, valueExpr);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
let targetColumns: ColumnDef[] = [];
|
|
234
|
+
if (stmt.columns && stmt.columns.length > 0) {
|
|
235
|
+
// Explicit columns specified
|
|
236
|
+
targetColumns = stmt.columns.map((colName, index) => columnSchemaToDef(colName, tableReference.tableSchema.columns[index]));
|
|
237
|
+
} else {
|
|
238
|
+
// No explicit columns - default to all table columns in order
|
|
239
|
+
targetColumns = tableReference.tableSchema.columns.map(col => columnSchemaToDef(col.name, col));
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
let sourceNode: RelationalPlanNode;
|
|
243
|
+
|
|
244
|
+
if (stmt.values) {
|
|
245
|
+
// VALUES clause - build the VALUES node
|
|
246
|
+
const rows = stmt.values.map(rowExprs =>
|
|
247
|
+
rowExprs.map(expr => buildExpression(ctx, expr) as PlanNode as ScalarPlanNode)
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
// Check that there are the right number of columns in each row
|
|
251
|
+
rows.forEach(row => {
|
|
252
|
+
if (row.length !== targetColumns.length) {
|
|
253
|
+
throw new QuereusError(`Column count mismatch in VALUES clause. Expected ${targetColumns.length} columns, got ${row.length}.`, StatusCode.ERROR, undefined, stmt.loc?.start.line, stmt.loc?.start.column);
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
// Create VALUES node with target column names
|
|
258
|
+
const targetColumnNames = targetColumns.map(col => col.name);
|
|
259
|
+
sourceNode = new ValuesNode(ctx.scope, rows, targetColumnNames);
|
|
260
|
+
|
|
261
|
+
} else if (stmt.select) {
|
|
262
|
+
// SELECT clause - build the SELECT statement
|
|
263
|
+
let parentCtes: Map<string, CTEScopeNode> = new Map();
|
|
264
|
+
if (stmt.withClause) {
|
|
265
|
+
parentCtes = buildWithClause(ctx, stmt.withClause);
|
|
266
|
+
}
|
|
267
|
+
const selectPlan = buildSelectStmt(ctx, stmt.select, parentCtes);
|
|
268
|
+
if (selectPlan.getType().typeClass !== 'relation') {
|
|
269
|
+
throw new QuereusError('SELECT statement in INSERT did not produce a relational plan.', StatusCode.INTERNAL, undefined, stmt.loc?.start.line, stmt.loc?.start.column);
|
|
270
|
+
}
|
|
271
|
+
sourceNode = selectPlan as RelationalPlanNode;
|
|
272
|
+
checkColumnsAssignable(sourceNode.getType().columns, targetColumns, stmt);
|
|
273
|
+
|
|
274
|
+
} else {
|
|
275
|
+
throw new QuereusError('INSERT statement must have a VALUES clause or a SELECT query.', StatusCode.ERROR);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// ORTHOGONAL ROW EXPANSION: Apply uniform row expansion to map any source to table structure with defaults
|
|
279
|
+
const expandedSourceNode = createRowExpansionProjection(ctx, sourceNode, targetColumns, tableReference, contextScope);
|
|
280
|
+
|
|
281
|
+
// Update targetColumns to reflect all table columns since we've expanded the source
|
|
282
|
+
const finalTargetColumns = tableReference.tableSchema.columns.map(col => columnSchemaToDef(col.name, col));
|
|
283
|
+
|
|
284
|
+
// Create OLD/NEW attributes for INSERT (OLD = all NULL, NEW = actual values)
|
|
285
|
+
const oldAttributes = tableReference.tableSchema.columns.map((col) => ({
|
|
286
|
+
id: PlanNode.nextAttrId(),
|
|
287
|
+
name: col.name,
|
|
288
|
+
type: {
|
|
289
|
+
typeClass: 'scalar' as const,
|
|
290
|
+
affinity: col.affinity,
|
|
291
|
+
nullable: true, // OLD values are always NULL for INSERT
|
|
292
|
+
isReadOnly: false
|
|
293
|
+
},
|
|
294
|
+
sourceRelation: `OLD.${tableReference.tableSchema.name}`
|
|
295
|
+
}));
|
|
296
|
+
|
|
297
|
+
const newAttributes = tableReference.tableSchema.columns.map((col) => ({
|
|
298
|
+
id: PlanNode.nextAttrId(),
|
|
299
|
+
name: col.name,
|
|
300
|
+
type: {
|
|
301
|
+
typeClass: 'scalar' as const,
|
|
302
|
+
affinity: col.affinity,
|
|
303
|
+
nullable: !col.notNull,
|
|
304
|
+
isReadOnly: false
|
|
305
|
+
},
|
|
306
|
+
sourceRelation: `NEW.${tableReference.tableSchema.name}`
|
|
307
|
+
}));
|
|
308
|
+
|
|
309
|
+
const { oldRowDescriptor, newRowDescriptor, flatRowDescriptor } = buildOldNewRowDescriptors(oldAttributes, newAttributes);
|
|
310
|
+
|
|
311
|
+
// Build context descriptor if we have context attributes
|
|
312
|
+
const contextDescriptor: RowDescriptor = contextAttributes.length > 0 ? [] : undefined as any;
|
|
313
|
+
if (contextDescriptor) {
|
|
314
|
+
contextAttributes.forEach((attr, index) => {
|
|
315
|
+
contextDescriptor[attr.id] = index;
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// Build constraint checks at plan time
|
|
320
|
+
const constraintChecks = buildConstraintChecks(
|
|
321
|
+
ctx,
|
|
322
|
+
tableReference.tableSchema,
|
|
323
|
+
RowOpFlag.INSERT,
|
|
324
|
+
oldAttributes,
|
|
325
|
+
newAttributes,
|
|
326
|
+
flatRowDescriptor,
|
|
327
|
+
contextAttributes
|
|
328
|
+
);
|
|
329
|
+
|
|
330
|
+
const insertNode = new InsertNode(
|
|
331
|
+
ctx.scope,
|
|
332
|
+
tableReference,
|
|
333
|
+
finalTargetColumns,
|
|
334
|
+
expandedSourceNode,
|
|
335
|
+
flatRowDescriptor,
|
|
336
|
+
mutationContextValues.size > 0 ? mutationContextValues : undefined,
|
|
337
|
+
contextAttributes.length > 0 ? contextAttributes : undefined,
|
|
338
|
+
contextDescriptor
|
|
339
|
+
);
|
|
340
|
+
|
|
341
|
+
const constraintCheckNode = new ConstraintCheckNode(
|
|
342
|
+
ctx.scope,
|
|
343
|
+
insertNode,
|
|
344
|
+
tableReference,
|
|
345
|
+
RowOpFlag.INSERT,
|
|
346
|
+
oldRowDescriptor,
|
|
347
|
+
newRowDescriptor,
|
|
348
|
+
flatRowDescriptor,
|
|
349
|
+
constraintChecks,
|
|
350
|
+
mutationContextValues.size > 0 ? mutationContextValues : undefined,
|
|
351
|
+
contextAttributes.length > 0 ? contextAttributes : undefined,
|
|
352
|
+
contextDescriptor
|
|
353
|
+
);
|
|
354
|
+
|
|
355
|
+
// Add DML executor node to perform the actual database insert operations
|
|
356
|
+
const dmlExecutorNode = new DmlExecutorNode(
|
|
357
|
+
ctx.scope,
|
|
358
|
+
constraintCheckNode,
|
|
359
|
+
tableReference,
|
|
360
|
+
'insert',
|
|
361
|
+
stmt.onConflict
|
|
362
|
+
);
|
|
363
|
+
|
|
364
|
+
const resultNode: RelationalPlanNode = dmlExecutorNode;
|
|
365
|
+
|
|
366
|
+
if (stmt.returning && stmt.returning.length > 0) {
|
|
367
|
+
// Create returning scope with OLD/NEW attribute access
|
|
368
|
+
const returningScope = new RegisteredScope(ctx.scope);
|
|
369
|
+
|
|
370
|
+
// Register OLD.* symbols (always NULL for INSERT)
|
|
371
|
+
oldAttributes.forEach((attr, columnIndex) => {
|
|
372
|
+
const tableColumn = tableReference.tableSchema.columns[columnIndex];
|
|
373
|
+
returningScope.registerSymbol(`old.${tableColumn.name.toLowerCase()}`, (exp, s) =>
|
|
374
|
+
new ColumnReferenceNode(s, exp as AST.ColumnExpr, attr.type, attr.id, columnIndex)
|
|
375
|
+
);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
// Register NEW.* symbols and unqualified column names (default to NEW)
|
|
379
|
+
newAttributes.forEach((attr, columnIndex) => {
|
|
380
|
+
const tableColumn = tableReference.tableSchema.columns[columnIndex];
|
|
381
|
+
|
|
382
|
+
// NEW.column
|
|
383
|
+
returningScope.registerSymbol(`new.${tableColumn.name.toLowerCase()}`, (exp, s) =>
|
|
384
|
+
new ColumnReferenceNode(s, exp as AST.ColumnExpr, attr.type, attr.id, columnIndex)
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
// Unqualified column (defaults to NEW)
|
|
388
|
+
returningScope.registerSymbol(tableColumn.name.toLowerCase(), (exp, s) =>
|
|
389
|
+
new ColumnReferenceNode(s, exp as AST.ColumnExpr, attr.type, attr.id, columnIndex)
|
|
390
|
+
);
|
|
391
|
+
|
|
392
|
+
// Table-qualified form (table.column -> NEW)
|
|
393
|
+
const tblQualified = `${tableReference.tableSchema.name.toLowerCase()}.${tableColumn.name.toLowerCase()}`;
|
|
394
|
+
returningScope.registerSymbol(tblQualified, (exp, s) =>
|
|
395
|
+
new ColumnReferenceNode(s, exp as AST.ColumnExpr, attr.type, attr.id, columnIndex)
|
|
396
|
+
);
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
// Build RETURNING projections in the OLD/NEW context
|
|
400
|
+
const returningProjections = stmt.returning.map(rc => {
|
|
401
|
+
// TODO: Support RETURNING *
|
|
402
|
+
if (rc.type === 'all') throw new QuereusError('RETURNING * not yet supported', StatusCode.UNSUPPORTED);
|
|
403
|
+
|
|
404
|
+
// Infer alias from column name if not explicitly provided
|
|
405
|
+
let alias = rc.alias;
|
|
406
|
+
if (!alias && rc.expr.type === 'column') {
|
|
407
|
+
// For qualified column references like NEW.id, normalize to lowercase
|
|
408
|
+
if (rc.expr.table) {
|
|
409
|
+
alias = `${rc.expr.table.toLowerCase()}.${rc.expr.name.toLowerCase()}`;
|
|
410
|
+
} else {
|
|
411
|
+
alias = rc.expr.name.toLowerCase();
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// Validate that OLD references are not used in INSERT RETURNING
|
|
416
|
+
validateReturningExpression(rc.expr, 'INSERT');
|
|
417
|
+
|
|
418
|
+
return {
|
|
419
|
+
node: buildExpression({ ...ctx, scope: returningScope }, rc.expr) as ScalarPlanNode,
|
|
420
|
+
alias: alias
|
|
421
|
+
};
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
return new ReturningNode(ctx.scope, dmlExecutorNode, returningProjections);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
return new SinkNode(ctx.scope, resultNode, 'insert');
|
|
428
|
+
}
|