@quereus/quereus 0.7.3 → 0.7.4
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/package.json +3 -3
- package/dist/src/common/constants.js.map +0 -1
- package/dist/src/common/datatype.js.map +0 -1
- package/dist/src/common/errors.js.map +0 -1
- package/dist/src/common/json-types.js.map +0 -1
- package/dist/src/common/logger.js.map +0 -1
- package/dist/src/common/type-inference.js.map +0 -1
- package/dist/src/common/types.js.map +0 -1
- package/dist/src/core/database-options.js.map +0 -1
- package/dist/src/core/database.js.map +0 -1
- package/dist/src/core/param.js.map +0 -1
- package/dist/src/core/statement.js.map +0 -1
- package/dist/src/func/builtins/aggregate.js.map +0 -1
- package/dist/src/func/builtins/builtin-window-functions.js.map +0 -1
- package/dist/src/func/builtins/conversion.js.map +0 -1
- package/dist/src/func/builtins/datetime.js.map +0 -1
- package/dist/src/func/builtins/explain.js.map +0 -1
- package/dist/src/func/builtins/generation.js.map +0 -1
- package/dist/src/func/builtins/index.js.map +0 -1
- package/dist/src/func/builtins/json-helpers.js.map +0 -1
- package/dist/src/func/builtins/json-tvf.js.map +0 -1
- package/dist/src/func/builtins/json.js.map +0 -1
- package/dist/src/func/builtins/scalar.js.map +0 -1
- package/dist/src/func/builtins/schema.js.map +0 -1
- package/dist/src/func/builtins/string.js.map +0 -1
- package/dist/src/func/builtins/timespan.js.map +0 -1
- package/dist/src/func/context.js.map +0 -1
- package/dist/src/func/registration.js.map +0 -1
- package/dist/src/index.js.map +0 -1
- package/dist/src/parser/ast.js.map +0 -1
- package/dist/src/parser/index.js.map +0 -1
- package/dist/src/parser/lexer.js.map +0 -1
- package/dist/src/parser/parser.js.map +0 -1
- package/dist/src/parser/utils.js.map +0 -1
- package/dist/src/parser/visitor.js.map +0 -1
- package/dist/src/planner/analysis/binding-collector.js.map +0 -1
- package/dist/src/planner/analysis/const-evaluator.js.map +0 -1
- package/dist/src/planner/analysis/const-pass.js.map +0 -1
- package/dist/src/planner/analysis/constraint-extractor.js.map +0 -1
- package/dist/src/planner/analysis/predicate-normalizer.js.map +0 -1
- package/dist/src/planner/building/alter-table.js.map +0 -1
- package/dist/src/planner/building/block.js.map +0 -1
- package/dist/src/planner/building/constraint-builder.js.map +0 -1
- package/dist/src/planner/building/create-assertion.js.map +0 -1
- package/dist/src/planner/building/create-view.js.map +0 -1
- package/dist/src/planner/building/ddl.js.map +0 -1
- package/dist/src/planner/building/declare-schema.js.map +0 -1
- package/dist/src/planner/building/delete.js.map +0 -1
- package/dist/src/planner/building/drop-assertion.js.map +0 -1
- package/dist/src/planner/building/drop-table.js.map +0 -1
- package/dist/src/planner/building/drop-view.js.map +0 -1
- package/dist/src/planner/building/expression.js.map +0 -1
- package/dist/src/planner/building/function-call.js.map +0 -1
- package/dist/src/planner/building/insert.js.map +0 -1
- package/dist/src/planner/building/pragma.js.map +0 -1
- package/dist/src/planner/building/schema-resolution.js.map +0 -1
- package/dist/src/planner/building/select-aggregates.js.map +0 -1
- package/dist/src/planner/building/select-compound.js.map +0 -1
- package/dist/src/planner/building/select-context.js.map +0 -1
- package/dist/src/planner/building/select-modifiers.js.map +0 -1
- package/dist/src/planner/building/select-projections.js.map +0 -1
- package/dist/src/planner/building/select-window.js.map +0 -1
- package/dist/src/planner/building/select.js.map +0 -1
- package/dist/src/planner/building/table-function.js.map +0 -1
- package/dist/src/planner/building/table.js.map +0 -1
- package/dist/src/planner/building/transaction.js.map +0 -1
- package/dist/src/planner/building/update.js.map +0 -1
- package/dist/src/planner/building/with.js.map +0 -1
- package/dist/src/planner/cache/correlation-detector.js.map +0 -1
- package/dist/src/planner/cache/materialization-advisory.js.map +0 -1
- package/dist/src/planner/cache/reference-graph.js.map +0 -1
- package/dist/src/planner/cost/index.js.map +0 -1
- package/dist/src/planner/debug/logger-utils.js.map +0 -1
- package/dist/src/planner/debug.js.map +0 -1
- package/dist/src/planner/framework/characteristics.js.map +0 -1
- package/dist/src/planner/framework/context.js.map +0 -1
- package/dist/src/planner/framework/pass.js.map +0 -1
- package/dist/src/planner/framework/physical-utils.js.map +0 -1
- package/dist/src/planner/framework/registry.js.map +0 -1
- package/dist/src/planner/framework/trace.js.map +0 -1
- package/dist/src/planner/nodes/add-constraint-node.js.map +0 -1
- package/dist/src/planner/nodes/aggregate-function.js.map +0 -1
- package/dist/src/planner/nodes/aggregate-node.js.map +0 -1
- package/dist/src/planner/nodes/array-index-node.js.map +0 -1
- package/dist/src/planner/nodes/block.js.map +0 -1
- package/dist/src/planner/nodes/cache-node.js.map +0 -1
- package/dist/src/planner/nodes/constraint-check-node.js.map +0 -1
- package/dist/src/planner/nodes/create-assertion-node.js.map +0 -1
- package/dist/src/planner/nodes/create-index-node.js.map +0 -1
- package/dist/src/planner/nodes/create-table-node.js.map +0 -1
- package/dist/src/planner/nodes/create-view-node.js.map +0 -1
- package/dist/src/planner/nodes/cte-node.js.map +0 -1
- package/dist/src/planner/nodes/cte-reference-node.js.map +0 -1
- package/dist/src/planner/nodes/declarative-schema.js.map +0 -1
- package/dist/src/planner/nodes/delete-node.js.map +0 -1
- package/dist/src/planner/nodes/distinct-node.js.map +0 -1
- package/dist/src/planner/nodes/dml-executor-node.js.map +0 -1
- package/dist/src/planner/nodes/drop-assertion-node.js.map +0 -1
- package/dist/src/planner/nodes/drop-table-node.js.map +0 -1
- package/dist/src/planner/nodes/drop-view-node.js.map +0 -1
- package/dist/src/planner/nodes/filter.js.map +0 -1
- package/dist/src/planner/nodes/function.js.map +0 -1
- package/dist/src/planner/nodes/insert-node.js.map +0 -1
- package/dist/src/planner/nodes/internal-recursive-cte-ref-node.js.map +0 -1
- package/dist/src/planner/nodes/join-node.js.map +0 -1
- package/dist/src/planner/nodes/limit-offset.js.map +0 -1
- package/dist/src/planner/nodes/plan-node-type.js.map +0 -1
- package/dist/src/planner/nodes/plan-node.js.map +0 -1
- package/dist/src/planner/nodes/pragma.js.map +0 -1
- package/dist/src/planner/nodes/project-node.js.map +0 -1
- package/dist/src/planner/nodes/recursive-cte-node.js.map +0 -1
- package/dist/src/planner/nodes/reference.js.map +0 -1
- package/dist/src/planner/nodes/remote-query-node.js.map +0 -1
- package/dist/src/planner/nodes/retrieve-node.js.map +0 -1
- package/dist/src/planner/nodes/returning-node.js.map +0 -1
- package/dist/src/planner/nodes/scalar.js.map +0 -1
- package/dist/src/planner/nodes/sequencing-node.js.map +0 -1
- package/dist/src/planner/nodes/set-operation-node.js.map +0 -1
- package/dist/src/planner/nodes/single-row.js.map +0 -1
- package/dist/src/planner/nodes/sink-node.js.map +0 -1
- package/dist/src/planner/nodes/sort.js.map +0 -1
- package/dist/src/planner/nodes/stream-aggregate.js.map +0 -1
- package/dist/src/planner/nodes/subquery.js.map +0 -1
- package/dist/src/planner/nodes/table-access-nodes.js.map +0 -1
- package/dist/src/planner/nodes/table-function-call.js.map +0 -1
- package/dist/src/planner/nodes/transaction-node.js.map +0 -1
- package/dist/src/planner/nodes/update-node.js.map +0 -1
- package/dist/src/planner/nodes/values-node.js.map +0 -1
- package/dist/src/planner/nodes/view-reference-node.js.map +0 -1
- package/dist/src/planner/nodes/window-function.js.map +0 -1
- package/dist/src/planner/nodes/window-node.js.map +0 -1
- package/dist/src/planner/optimizer-tuning.js.map +0 -1
- package/dist/src/planner/optimizer.js.map +0 -1
- package/dist/src/planner/planning-context.js.map +0 -1
- package/dist/src/planner/resolve.js.map +0 -1
- package/dist/src/planner/rules/access/rule-select-access-path.js.map +0 -1
- package/dist/src/planner/rules/aggregate/rule-aggregate-streaming.js.map +0 -1
- package/dist/src/planner/rules/cache/rule-cte-optimization.js.map +0 -1
- package/dist/src/planner/rules/cache/rule-materialization-advisory.js.map +0 -1
- package/dist/src/planner/rules/cache/rule-mutating-subquery-cache.js.map +0 -1
- package/dist/src/planner/rules/join/rule-join-greedy-commute.js.map +0 -1
- package/dist/src/planner/rules/join/rule-join-key-inference.js.map +0 -1
- package/dist/src/planner/rules/join/rule-quickpick-enumeration.js.map +0 -1
- package/dist/src/planner/rules/predicate/rule-predicate-pushdown.js.map +0 -1
- package/dist/src/planner/rules/retrieve/rule-grow-retrieve.js.map +0 -1
- package/dist/src/planner/scopes/aliased.js.map +0 -1
- package/dist/src/planner/scopes/base.js.map +0 -1
- package/dist/src/planner/scopes/empty.js.map +0 -1
- package/dist/src/planner/scopes/global.js.map +0 -1
- package/dist/src/planner/scopes/multi.js.map +0 -1
- package/dist/src/planner/scopes/param.js.map +0 -1
- package/dist/src/planner/scopes/registered.js.map +0 -1
- package/dist/src/planner/scopes/scope.js.map +0 -1
- package/dist/src/planner/stats/basic-estimates.js.map +0 -1
- package/dist/src/planner/stats/index.js.map +0 -1
- package/dist/src/planner/type-utils.js.map +0 -1
- package/dist/src/planner/util/key-utils.js.map +0 -1
- package/dist/src/planner/validation/determinism-validator.js.map +0 -1
- package/dist/src/planner/validation/plan-validator.js.map +0 -1
- package/dist/src/runtime/async-util.js.map +0 -1
- package/dist/src/runtime/cache/shared-cache.js.map +0 -1
- package/dist/src/runtime/context-helpers.js.map +0 -1
- package/dist/src/runtime/deferred-constraint-queue.js.map +0 -1
- package/dist/src/runtime/emission-context.js.map +0 -1
- package/dist/src/runtime/emit/add-constraint.js.map +0 -1
- package/dist/src/runtime/emit/aggregate.js.map +0 -1
- package/dist/src/runtime/emit/array-index.js.map +0 -1
- package/dist/src/runtime/emit/between.js.map +0 -1
- package/dist/src/runtime/emit/binary.js.map +0 -1
- package/dist/src/runtime/emit/block.js.map +0 -1
- package/dist/src/runtime/emit/cache.js.map +0 -1
- package/dist/src/runtime/emit/case.js.map +0 -1
- package/dist/src/runtime/emit/cast.js.map +0 -1
- package/dist/src/runtime/emit/collate.js.map +0 -1
- package/dist/src/runtime/emit/column-reference.js.map +0 -1
- package/dist/src/runtime/emit/constraint-check.js.map +0 -1
- package/dist/src/runtime/emit/create-assertion.js.map +0 -1
- package/dist/src/runtime/emit/create-index.js.map +0 -1
- package/dist/src/runtime/emit/create-table.js.map +0 -1
- package/dist/src/runtime/emit/create-view.js.map +0 -1
- package/dist/src/runtime/emit/cte-reference.js.map +0 -1
- package/dist/src/runtime/emit/cte.js.map +0 -1
- package/dist/src/runtime/emit/delete.js.map +0 -1
- package/dist/src/runtime/emit/distinct.js.map +0 -1
- package/dist/src/runtime/emit/dml-executor.js.map +0 -1
- package/dist/src/runtime/emit/drop-assertion.js.map +0 -1
- package/dist/src/runtime/emit/drop-table.js.map +0 -1
- package/dist/src/runtime/emit/drop-view.js.map +0 -1
- package/dist/src/runtime/emit/filter.js.map +0 -1
- package/dist/src/runtime/emit/insert.js.map +0 -1
- package/dist/src/runtime/emit/internal-recursive-cte-ref.js.map +0 -1
- package/dist/src/runtime/emit/join.js.map +0 -1
- package/dist/src/runtime/emit/limit-offset.js.map +0 -1
- package/dist/src/runtime/emit/literal.js.map +0 -1
- package/dist/src/runtime/emit/parameter.js.map +0 -1
- package/dist/src/runtime/emit/pragma.js.map +0 -1
- package/dist/src/runtime/emit/project.js.map +0 -1
- package/dist/src/runtime/emit/recursive-cte.js.map +0 -1
- package/dist/src/runtime/emit/remote-query.js.map +0 -1
- package/dist/src/runtime/emit/retrieve.js.map +0 -1
- package/dist/src/runtime/emit/returning.js.map +0 -1
- package/dist/src/runtime/emit/scalar-function.js.map +0 -1
- package/dist/src/runtime/emit/scan.js.map +0 -1
- package/dist/src/runtime/emit/schema-declarative.js.map +0 -1
- package/dist/src/runtime/emit/sequencing.js.map +0 -1
- package/dist/src/runtime/emit/set-operation.js.map +0 -1
- package/dist/src/runtime/emit/sink.js.map +0 -1
- package/dist/src/runtime/emit/sort.js.map +0 -1
- package/dist/src/runtime/emit/subquery.js.map +0 -1
- package/dist/src/runtime/emit/table-valued-function.js.map +0 -1
- package/dist/src/runtime/emit/temporal-arithmetic.js.map +0 -1
- package/dist/src/runtime/emit/transaction.js.map +0 -1
- package/dist/src/runtime/emit/unary.js.map +0 -1
- package/dist/src/runtime/emit/update.js.map +0 -1
- package/dist/src/runtime/emit/values.js.map +0 -1
- package/dist/src/runtime/emit/window-function.js.map +0 -1
- package/dist/src/runtime/emit/window.js.map +0 -1
- package/dist/src/runtime/emitters.js.map +0 -1
- package/dist/src/runtime/register.js.map +0 -1
- package/dist/src/runtime/scheduler.js.map +0 -1
- package/dist/src/runtime/types.js.map +0 -1
- package/dist/src/runtime/utils.js.map +0 -1
- package/dist/src/schema/assertion.js.map +0 -1
- package/dist/src/schema/catalog.js.map +0 -1
- package/dist/src/schema/change-events.js.map +0 -1
- package/dist/src/schema/column.js.map +0 -1
- package/dist/src/schema/declared-schema-manager.js.map +0 -1
- package/dist/src/schema/function.js.map +0 -1
- package/dist/src/schema/manager.js.map +0 -1
- package/dist/src/schema/schema-differ.js.map +0 -1
- package/dist/src/schema/schema-hasher.js.map +0 -1
- package/dist/src/schema/schema.js.map +0 -1
- package/dist/src/schema/table.js.map +0 -1
- package/dist/src/schema/view.js.map +0 -1
- package/dist/src/schema/window-function.js.map +0 -1
- package/dist/src/types/builtin-types.js.map +0 -1
- package/dist/src/types/index.js.map +0 -1
- package/dist/src/types/json-type.js.map +0 -1
- package/dist/src/types/logical-type.js.map +0 -1
- package/dist/src/types/plugin-interface.js.map +0 -1
- package/dist/src/types/registry.js.map +0 -1
- package/dist/src/types/temporal-types.js.map +0 -1
- package/dist/src/types/validation.js.map +0 -1
- package/dist/src/util/affinity.js.map +0 -1
- package/dist/src/util/ast-stringify.js.map +0 -1
- package/dist/src/util/cached.js.map +0 -1
- package/dist/src/util/coercion.js.map +0 -1
- package/dist/src/util/comparison.js.map +0 -1
- package/dist/src/util/environment.js.map +0 -1
- package/dist/src/util/hash.js.map +0 -1
- package/dist/src/util/latches.js.map +0 -1
- package/dist/src/util/mutation-statement.js.map +0 -1
- package/dist/src/util/patterns.js.map +0 -1
- package/dist/src/util/plan-formatter.js.map +0 -1
- package/dist/src/util/plugin-helper.js.map +0 -1
- package/dist/src/util/row-descriptor.js.map +0 -1
- package/dist/src/util/serialization.js.map +0 -1
- package/dist/src/util/sql-literal.js.map +0 -1
- package/dist/src/util/working-table-iterable.js.map +0 -1
- package/dist/src/vtab/best-access-plan.js.map +0 -1
- package/dist/src/vtab/connection.js.map +0 -1
- package/dist/src/vtab/filter-info.js.map +0 -1
- package/dist/src/vtab/index-info.js.map +0 -1
- package/dist/src/vtab/manifest.js.map +0 -1
- package/dist/src/vtab/memory/connection.js.map +0 -1
- package/dist/src/vtab/memory/index.js.map +0 -1
- package/dist/src/vtab/memory/layer/base-cursor.js.map +0 -1
- package/dist/src/vtab/memory/layer/base.js.map +0 -1
- package/dist/src/vtab/memory/layer/connection.js.map +0 -1
- package/dist/src/vtab/memory/layer/interface.js.map +0 -1
- package/dist/src/vtab/memory/layer/manager.js.map +0 -1
- package/dist/src/vtab/memory/layer/safe-iterate.js.map +0 -1
- package/dist/src/vtab/memory/layer/scan-plan.js.map +0 -1
- package/dist/src/vtab/memory/layer/transaction-cursor.js.map +0 -1
- package/dist/src/vtab/memory/layer/transaction.js.map +0 -1
- package/dist/src/vtab/memory/module.js.map +0 -1
- package/dist/src/vtab/memory/table.js.map +0 -1
- package/dist/src/vtab/memory/types.js.map +0 -1
- package/dist/src/vtab/memory/utils/logging.js.map +0 -1
- package/dist/src/vtab/memory/utils/primary-key.js.map +0 -1
- package/dist/src/vtab/module.js.map +0 -1
- package/dist/src/vtab/table.js.map +0 -1
- package/src/common/constants.ts +0 -60
- package/src/common/datatype.ts +0 -85
- package/src/common/errors.ts +0 -189
- package/src/common/json-types.ts +0 -16
- package/src/common/logger.ts +0 -97
- package/src/common/type-inference.ts +0 -39
- package/src/common/types.ts +0 -151
- package/src/core/database-options.ts +0 -258
- package/src/core/database.ts +0 -1461
- package/src/core/param.ts +0 -56
- package/src/core/statement.ts +0 -528
- package/src/func/builtins/aggregate.ts +0 -269
- package/src/func/builtins/builtin-window-functions.ts +0 -166
- package/src/func/builtins/conversion.ts +0 -226
- package/src/func/builtins/datetime.ts +0 -500
- package/src/func/builtins/explain.ts +0 -779
- package/src/func/builtins/generation.ts +0 -43
- package/src/func/builtins/index.ts +0 -167
- package/src/func/builtins/json-helpers.ts +0 -237
- package/src/func/builtins/json-tvf.ts +0 -224
- package/src/func/builtins/json.ts +0 -588
- package/src/func/builtins/scalar.ts +0 -423
- package/src/func/builtins/schema.ts +0 -213
- package/src/func/builtins/string.ts +0 -306
- package/src/func/builtins/timespan.ts +0 -179
- package/src/func/context.ts +0 -258
- package/src/func/registration.ts +0 -201
- package/src/index.ts +0 -172
- package/src/parser/ast.ts +0 -581
- package/src/parser/index.ts +0 -65
- package/src/parser/lexer.ts +0 -806
- package/src/parser/parser.ts +0 -3352
- package/src/parser/utils.ts +0 -10
- package/src/parser/visitor.ts +0 -188
- package/src/planner/analysis/README.md +0 -93
- package/src/planner/analysis/binding-collector.ts +0 -83
- package/src/planner/analysis/const-evaluator.ts +0 -63
- package/src/planner/analysis/const-pass.ts +0 -282
- package/src/planner/analysis/constraint-extractor.ts +0 -764
- package/src/planner/analysis/predicate-normalizer.ts +0 -237
- package/src/planner/building/alter-table.ts +0 -49
- package/src/planner/building/block.ts +0 -93
- package/src/planner/building/constraint-builder.ts +0 -178
- package/src/planner/building/create-assertion.ts +0 -7
- package/src/planner/building/create-view.ts +0 -29
- package/src/planner/building/ddl.ts +0 -24
- package/src/planner/building/declare-schema.ts +0 -22
- package/src/planner/building/delete.ts +0 -218
- package/src/planner/building/drop-assertion.ts +0 -11
- package/src/planner/building/drop-table.ts +0 -13
- package/src/planner/building/drop-view.ts +0 -19
- package/src/planner/building/expression.ts +0 -205
- package/src/planner/building/function-call.ts +0 -129
- package/src/planner/building/insert.ts +0 -435
- package/src/planner/building/pragma.ts +0 -34
- package/src/planner/building/schema-resolution.ts +0 -176
- package/src/planner/building/select-aggregates.ts +0 -318
- package/src/planner/building/select-compound.ts +0 -119
- package/src/planner/building/select-context.ts +0 -85
- package/src/planner/building/select-modifiers.ts +0 -236
- package/src/planner/building/select-projections.ts +0 -177
- package/src/planner/building/select-window.ts +0 -259
- package/src/planner/building/select.ts +0 -567
- package/src/planner/building/table-function.ts +0 -49
- package/src/planner/building/table.ts +0 -40
- package/src/planner/building/transaction.ts +0 -23
- package/src/planner/building/update.ts +0 -331
- package/src/planner/building/with.ts +0 -180
- package/src/planner/cache/correlation-detector.ts +0 -83
- package/src/planner/cache/materialization-advisory.ts +0 -265
- package/src/planner/cache/reference-graph.ts +0 -196
- package/src/planner/cost/index.ts +0 -169
- package/src/planner/debug/logger-utils.ts +0 -68
- package/src/planner/debug.ts +0 -480
- package/src/planner/framework/README.md +0 -132
- package/src/planner/framework/characteristics.ts +0 -503
- package/src/planner/framework/context.ts +0 -239
- package/src/planner/framework/pass.ts +0 -354
- package/src/planner/framework/physical-utils.ts +0 -210
- package/src/planner/framework/registry.ts +0 -261
- package/src/planner/framework/trace.ts +0 -259
- package/src/planner/nodes/add-constraint-node.ts +0 -62
- package/src/planner/nodes/aggregate-function.ts +0 -155
- package/src/planner/nodes/aggregate-node.ts +0 -267
- package/src/planner/nodes/array-index-node.ts +0 -50
- package/src/planner/nodes/block.ts +0 -80
- package/src/planner/nodes/cache-node.ts +0 -103
- package/src/planner/nodes/constraint-check-node.ts +0 -138
- package/src/planner/nodes/create-assertion-node.ts +0 -51
- package/src/planner/nodes/create-index-node.ts +0 -41
- package/src/planner/nodes/create-table-node.ts +0 -35
- package/src/planner/nodes/create-view-node.ts +0 -44
- package/src/planner/nodes/cte-node.ts +0 -168
- package/src/planner/nodes/cte-reference-node.ts +0 -125
- package/src/planner/nodes/declarative-schema.ts +0 -221
- package/src/planner/nodes/delete-node.ts +0 -102
- package/src/planner/nodes/distinct-node.ts +0 -107
- package/src/planner/nodes/dml-executor-node.ts +0 -104
- package/src/planner/nodes/drop-assertion-node.ts +0 -50
- package/src/planner/nodes/drop-table-node.ts +0 -36
- package/src/planner/nodes/drop-view-node.ts +0 -37
- package/src/planner/nodes/filter.ts +0 -144
- package/src/planner/nodes/function.ts +0 -98
- package/src/planner/nodes/insert-node.ts +0 -126
- package/src/planner/nodes/internal-recursive-cte-ref-node.ts +0 -61
- package/src/planner/nodes/join-node.ts +0 -336
- package/src/planner/nodes/limit-offset.ts +0 -144
- package/src/planner/nodes/plan-node-type.ts +0 -95
- package/src/planner/nodes/plan-node.ts +0 -503
- package/src/planner/nodes/pragma.ts +0 -98
- package/src/planner/nodes/project-node.ts +0 -337
- package/src/planner/nodes/recursive-cte-node.ts +0 -158
- package/src/planner/nodes/reference.ts +0 -334
- package/src/planner/nodes/remote-query-node.ts +0 -73
- package/src/planner/nodes/retrieve-node.ts +0 -86
- package/src/planner/nodes/returning-node.ts +0 -269
- package/src/planner/nodes/scalar.ts +0 -772
- package/src/planner/nodes/sequencing-node.ts +0 -113
- package/src/planner/nodes/set-operation-node.ts +0 -87
- package/src/planner/nodes/single-row.ts +0 -85
- package/src/planner/nodes/sink-node.ts +0 -61
- package/src/planner/nodes/sort.ts +0 -166
- package/src/planner/nodes/stream-aggregate.ts +0 -293
- package/src/planner/nodes/subquery.ts +0 -268
- package/src/planner/nodes/table-access-nodes.ts +0 -323
- package/src/planner/nodes/table-function-call.ts +0 -134
- package/src/planner/nodes/transaction-node.ts +0 -55
- package/src/planner/nodes/update-node.ts +0 -138
- package/src/planner/nodes/values-node.ts +0 -244
- package/src/planner/nodes/view-reference-node.ts +0 -97
- package/src/planner/nodes/window-function.ts +0 -73
- package/src/planner/nodes/window-node.ts +0 -199
- package/src/planner/optimizer-tuning.ts +0 -105
- package/src/planner/optimizer.ts +0 -332
- package/src/planner/planning-context.ts +0 -190
- package/src/planner/resolve.ts +0 -101
- package/src/planner/rules/README.md +0 -96
- package/src/planner/rules/access/rule-select-access-path.ts +0 -399
- package/src/planner/rules/aggregate/rule-aggregate-streaming.ts +0 -162
- package/src/planner/rules/cache/rule-cte-optimization.ts +0 -79
- package/src/planner/rules/cache/rule-materialization-advisory.ts +0 -77
- package/src/planner/rules/cache/rule-mutating-subquery-cache.ts +0 -104
- package/src/planner/rules/join/rule-join-greedy-commute.ts +0 -48
- package/src/planner/rules/join/rule-join-key-inference.ts +0 -35
- package/src/planner/rules/join/rule-quickpick-enumeration.ts +0 -267
- package/src/planner/rules/predicate/rule-predicate-pushdown.ts +0 -144
- package/src/planner/rules/retrieve/rule-grow-retrieve.ts +0 -337
- package/src/planner/scopes/aliased.ts +0 -50
- package/src/planner/scopes/base.ts +0 -10
- package/src/planner/scopes/empty.ts +0 -12
- package/src/planner/scopes/global.ts +0 -73
- package/src/planner/scopes/multi.ts +0 -40
- package/src/planner/scopes/param.ts +0 -95
- package/src/planner/scopes/registered.ts +0 -67
- package/src/planner/scopes/scope.ts +0 -16
- package/src/planner/stats/basic-estimates.ts +0 -107
- package/src/planner/stats/index.ts +0 -158
- package/src/planner/type-utils.ts +0 -87
- package/src/planner/util/key-utils.ts +0 -46
- package/src/planner/validation/determinism-validator.ts +0 -104
- package/src/planner/validation/plan-validator.ts +0 -335
- package/src/runtime/async-util.ts +0 -283
- package/src/runtime/cache/shared-cache.ts +0 -169
- package/src/runtime/context-helpers.ts +0 -191
- package/src/runtime/deferred-constraint-queue.ts +0 -196
- package/src/runtime/emission-context.ts +0 -319
- package/src/runtime/emit/add-constraint.ts +0 -78
- package/src/runtime/emit/aggregate.ts +0 -581
- package/src/runtime/emit/array-index.ts +0 -25
- package/src/runtime/emit/between.ts +0 -51
- package/src/runtime/emit/binary.ts +0 -357
- package/src/runtime/emit/block.ts +0 -23
- package/src/runtime/emit/cache.ts +0 -64
- package/src/runtime/emit/case.ts +0 -87
- package/src/runtime/emit/cast.ts +0 -151
- package/src/runtime/emit/collate.ts +0 -9
- package/src/runtime/emit/column-reference.ts +0 -17
- package/src/runtime/emit/constraint-check.ts +0 -290
- package/src/runtime/emit/create-assertion.ts +0 -82
- package/src/runtime/emit/create-index.ts +0 -15
- package/src/runtime/emit/create-table.ts +0 -15
- package/src/runtime/emit/create-view.ts +0 -52
- package/src/runtime/emit/cte-reference.ts +0 -38
- package/src/runtime/emit/cte.ts +0 -39
- package/src/runtime/emit/delete.ts +0 -24
- package/src/runtime/emit/distinct.ts +0 -40
- package/src/runtime/emit/dml-executor.ts +0 -198
- package/src/runtime/emit/drop-assertion.ts +0 -45
- package/src/runtime/emit/drop-table.ts +0 -27
- package/src/runtime/emit/drop-view.ts +0 -49
- package/src/runtime/emit/filter.ts +0 -30
- package/src/runtime/emit/insert.ts +0 -42
- package/src/runtime/emit/internal-recursive-cte-ref.ts +0 -37
- package/src/runtime/emit/join.ts +0 -148
- package/src/runtime/emit/limit-offset.ts +0 -73
- package/src/runtime/emit/literal.ts +0 -17
- package/src/runtime/emit/parameter.ts +0 -59
- package/src/runtime/emit/pragma.ts +0 -56
- package/src/runtime/emit/project.ts +0 -46
- package/src/runtime/emit/recursive-cte.ts +0 -111
- package/src/runtime/emit/remote-query.ts +0 -47
- package/src/runtime/emit/retrieve.ts +0 -15
- package/src/runtime/emit/returning.ts +0 -41
- package/src/runtime/emit/scalar-function.ts +0 -69
- package/src/runtime/emit/scan.ts +0 -106
- package/src/runtime/emit/schema-declarative.ts +0 -215
- package/src/runtime/emit/sequencing.ts +0 -24
- package/src/runtime/emit/set-operation.ts +0 -141
- package/src/runtime/emit/sink.ts +0 -27
- package/src/runtime/emit/sort.ts +0 -75
- package/src/runtime/emit/subquery.ts +0 -203
- package/src/runtime/emit/table-valued-function.ts +0 -106
- package/src/runtime/emit/temporal-arithmetic.ts +0 -302
- package/src/runtime/emit/transaction.ts +0 -205
- package/src/runtime/emit/unary.ts +0 -101
- package/src/runtime/emit/update.ts +0 -66
- package/src/runtime/emit/values.ts +0 -66
- package/src/runtime/emit/window-function.ts +0 -42
- package/src/runtime/emit/window.ts +0 -458
- package/src/runtime/emitters.ts +0 -183
- package/src/runtime/register.ts +0 -150
- package/src/runtime/scheduler.ts +0 -488
- package/src/runtime/types.ts +0 -242
- package/src/runtime/utils.ts +0 -177
- package/src/schema/assertion.ts +0 -21
- package/src/schema/catalog.ts +0 -269
- package/src/schema/change-events.ts +0 -80
- package/src/schema/column.ts +0 -51
- package/src/schema/declared-schema-manager.ts +0 -82
- package/src/schema/function.ts +0 -188
- package/src/schema/manager.ts +0 -1034
- package/src/schema/schema-differ.ts +0 -214
- package/src/schema/schema-hasher.ts +0 -26
- package/src/schema/schema.ts +0 -222
- package/src/schema/table.ts +0 -409
- package/src/schema/view.ts +0 -19
- package/src/schema/window-function.ts +0 -56
- package/src/types/builtin-types.ts +0 -350
- package/src/types/index.ts +0 -17
- package/src/types/json-type.ts +0 -152
- package/src/types/logical-type.ts +0 -91
- package/src/types/plugin-interface.ts +0 -10
- package/src/types/registry.ts +0 -204
- package/src/types/temporal-types.ts +0 -290
- package/src/types/validation.ts +0 -120
- package/src/util/affinity.ts +0 -151
- package/src/util/ast-stringify.ts +0 -887
- package/src/util/cached.ts +0 -25
- package/src/util/coercion.ts +0 -113
- package/src/util/comparison.ts +0 -510
- package/src/util/environment.ts +0 -52
- package/src/util/hash.ts +0 -90
- package/src/util/latches.ts +0 -47
- package/src/util/mutation-statement.ts +0 -135
- package/src/util/patterns.ts +0 -56
- package/src/util/plan-formatter.ts +0 -48
- package/src/util/plugin-helper.ts +0 -110
- package/src/util/row-descriptor.ts +0 -105
- package/src/util/serialization.ts +0 -47
- package/src/util/sql-literal.ts +0 -22
- package/src/util/working-table-iterable.ts +0 -38
- package/src/vtab/best-access-plan.ts +0 -244
- package/src/vtab/connection.ts +0 -36
- package/src/vtab/filter-info.ts +0 -23
- package/src/vtab/index-info.ts +0 -84
- package/src/vtab/manifest.ts +0 -86
- package/src/vtab/memory/connection.ts +0 -73
- package/src/vtab/memory/index.ts +0 -191
- package/src/vtab/memory/layer/base-cursor.ts +0 -124
- package/src/vtab/memory/layer/base.ts +0 -275
- package/src/vtab/memory/layer/connection.ts +0 -203
- package/src/vtab/memory/layer/interface.ts +0 -47
- package/src/vtab/memory/layer/manager.ts +0 -909
- package/src/vtab/memory/layer/safe-iterate.ts +0 -49
- package/src/vtab/memory/layer/scan-plan.ts +0 -84
- package/src/vtab/memory/layer/transaction-cursor.ts +0 -162
- package/src/vtab/memory/layer/transaction.ts +0 -229
- package/src/vtab/memory/module.ts +0 -667
- package/src/vtab/memory/table.ts +0 -251
- package/src/vtab/memory/types.ts +0 -23
- package/src/vtab/memory/utils/logging.ts +0 -36
- package/src/vtab/memory/utils/primary-key.ts +0 -163
- package/src/vtab/module.ts +0 -162
- package/src/vtab/table.ts +0 -177
|
@@ -1,567 +0,0 @@
|
|
|
1
|
-
import type * as AST from '../../parser/ast.js';
|
|
2
|
-
import { PlanNode, type RelationalPlanNode, type ScalarPlanNode } from '../nodes/plan-node.js';
|
|
3
|
-
import { QuereusError } from '../../common/errors.js';
|
|
4
|
-
import { StatusCode } from '../../common/types.js';
|
|
5
|
-
import type { PlanningContext } from '../planning-context.js';
|
|
6
|
-
import { SingleRowNode } from '../nodes/single-row.js';
|
|
7
|
-
import { buildTableReference } from './table.js';
|
|
8
|
-
import { AliasedScope } from '../scopes/aliased.js';
|
|
9
|
-
import { RegisteredScope } from '../scopes/registered.js';
|
|
10
|
-
import type { Scope } from '../scopes/scope.js';
|
|
11
|
-
import { MultiScope } from '../scopes/multi.js';
|
|
12
|
-
import { ProjectNode, type Projection } from '../nodes/project-node.js';
|
|
13
|
-
import { buildExpression } from './expression.js';
|
|
14
|
-
import { FilterNode } from '../nodes/filter.js';
|
|
15
|
-
import { buildTableFunctionCall } from './table-function.js';
|
|
16
|
-
import { CTEReferenceNode } from '../nodes/cte-reference-node.js';
|
|
17
|
-
import { InternalRecursiveCTERefNode as _InternalRecursiveCTERefNode } from '../nodes/internal-recursive-cte-ref-node.js';
|
|
18
|
-
import type { CTEScopeNode, CTEPlanNode } from '../nodes/cte-node.js';
|
|
19
|
-
import { JoinNode } from '../nodes/join-node.js';
|
|
20
|
-
import { ColumnReferenceNode } from '../nodes/reference.js';
|
|
21
|
-
import { TEXT_TYPE } from '../../types/builtin-types.js';
|
|
22
|
-
import { ValuesNode } from '../nodes/values-node.js';
|
|
23
|
-
import { createLogger } from '../../common/logger.js';
|
|
24
|
-
|
|
25
|
-
// Import decomposed functionality
|
|
26
|
-
import { buildWithContext } from './select-context.js';
|
|
27
|
-
import { buildCompoundSelect } from './select-compound.js';
|
|
28
|
-
import { analyzeSelectColumns, buildStarProjections } from './select-projections.js';
|
|
29
|
-
import { buildAggregatePhase, buildFinalAggregateProjections } from './select-aggregates.js';
|
|
30
|
-
import { buildWindowPhase } from './select-window.js';
|
|
31
|
-
import { buildFinalProjections, applyDistinct, applyOrderBy, applyLimitOffset } from './select-modifiers.js';
|
|
32
|
-
import { SortNode, type SortKey } from '../nodes/sort.js';
|
|
33
|
-
|
|
34
|
-
import { buildInsertStmt } from './insert.js';
|
|
35
|
-
import { buildUpdateStmt } from './update.js';
|
|
36
|
-
import { buildDeleteStmt } from './delete.js';
|
|
37
|
-
import { CapabilityDetectors } from '../framework/characteristics.js';
|
|
38
|
-
|
|
39
|
-
const logger = createLogger('planner:cte');
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Creates an initial logical query plan for a SELECT statement.
|
|
43
|
-
*
|
|
44
|
-
* For this initial version, it only supports simple "SELECT ... FROM one_table" queries,
|
|
45
|
-
* effectively returning a TableReferenceNode for that table.
|
|
46
|
-
*
|
|
47
|
-
* @param stmt The AST.SelectStmt to plan.
|
|
48
|
-
* @param ctx The parent planning context for this SELECT statement.
|
|
49
|
-
* @param parentCTEs A map of parent CTEs for compound statements.
|
|
50
|
-
* @returns A BatchNode representing the plan for the SELECT statement.
|
|
51
|
-
* @throws {QuereusError} If the FROM clause is missing, empty, or contains more than one source.
|
|
52
|
-
*/
|
|
53
|
-
export function buildSelectStmt(
|
|
54
|
-
ctx: PlanningContext,
|
|
55
|
-
stmt: AST.SelectStmt,
|
|
56
|
-
parentCTEs: Map<string, CTEScopeNode> = new Map(),
|
|
57
|
-
/**
|
|
58
|
-
* Whether ProjectNodes inside this SELECT should forward all input columns that are not explicitly
|
|
59
|
-
* listed in the projection list. This is desirable for top-level queries (helps ORDER BY, window
|
|
60
|
-
* functions, etc.) but must be switched off for scalar/IN/EXISTS sub-queries which are required to
|
|
61
|
-
* expose only their declared columns.
|
|
62
|
-
*/
|
|
63
|
-
preserveInputColumns: boolean = true
|
|
64
|
-
): PlanNode {
|
|
65
|
-
|
|
66
|
-
// Phase 0: Handle WITH clause if present
|
|
67
|
-
const { contextWithCTEs, cteNodes } = buildWithContext(ctx, stmt, parentCTEs);
|
|
68
|
-
|
|
69
|
-
// Handle compound set operations (UNION / INTERSECT / EXCEPT)
|
|
70
|
-
if (stmt.compound) {
|
|
71
|
-
return buildCompoundSelect(stmt, contextWithCTEs, cteNodes,
|
|
72
|
-
(ctx, stmt, parentCTEs) => buildSelectStmt(ctx, stmt, parentCTEs) as RelationalPlanNode);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Phase 1: Plan FROM clause and determine local input relations for the current select scope
|
|
76
|
-
// Use the context that includes CTEs as well as the merged CTE map so that table references
|
|
77
|
-
// inside the FROM clause can correctly resolve to CTE definitions created by the WITH clause.
|
|
78
|
-
const fromTables = !stmt.from || stmt.from.length === 0
|
|
79
|
-
? [SingleRowNode.instance]
|
|
80
|
-
: stmt.from.map(from => buildFrom(from, contextWithCTEs, cteNodes));
|
|
81
|
-
|
|
82
|
-
// Multiple FROM sources (from joins) are not supported - maybe never will be
|
|
83
|
-
if (fromTables.length > 1) {
|
|
84
|
-
throw new QuereusError(
|
|
85
|
-
'SELECT with multiple FROM sources (joins) not supported.',
|
|
86
|
-
StatusCode.UNSUPPORTED, undefined, stmt.from![1].loc?.start.line, stmt.from![1].loc?.start.column
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Phase 2: Create the main scope for this SELECT statement
|
|
91
|
-
const columnScopes = fromTables.map(ft => ctx.outputScopes.get(ft) || ft.scope).filter(Boolean);
|
|
92
|
-
const selectScope = new MultiScope([...columnScopes, contextWithCTEs.scope]);
|
|
93
|
-
let selectContext: PlanningContext = { ...contextWithCTEs, scope: selectScope };
|
|
94
|
-
|
|
95
|
-
let input: RelationalPlanNode = fromTables[0];
|
|
96
|
-
|
|
97
|
-
// Plan WHERE clause
|
|
98
|
-
if (stmt.where) {
|
|
99
|
-
const whereExpression = buildExpression(selectContext, stmt.where);
|
|
100
|
-
input = new FilterNode(selectScope, input, whereExpression);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Build projections based on the SELECT list
|
|
104
|
-
const projections: Projection[] = [];
|
|
105
|
-
|
|
106
|
-
// Analyze SELECT columns
|
|
107
|
-
const {
|
|
108
|
-
projections: columnProjections,
|
|
109
|
-
aggregates,
|
|
110
|
-
windowFunctions,
|
|
111
|
-
hasAggregates,
|
|
112
|
-
hasWindowFunctions
|
|
113
|
-
} = analyzeSelectColumns(stmt.columns, selectContext);
|
|
114
|
-
|
|
115
|
-
// Handle SELECT * separately
|
|
116
|
-
for (const column of stmt.columns) {
|
|
117
|
-
if (column.type === 'all') {
|
|
118
|
-
const starProjections = buildStarProjections(column, input, selectScope);
|
|
119
|
-
projections.push(...starProjections);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Add non-star projections
|
|
124
|
-
projections.push(...columnProjections);
|
|
125
|
-
|
|
126
|
-
// Process aggregates if present
|
|
127
|
-
const aggregateResult = buildAggregatePhase(input, stmt, selectContext, aggregates, hasAggregates, projections);
|
|
128
|
-
input = aggregateResult.output;
|
|
129
|
-
let preAggregateSort = aggregateResult.preAggregateSort;
|
|
130
|
-
|
|
131
|
-
// Update context if we have aggregates
|
|
132
|
-
if (aggregateResult.aggregateScope) {
|
|
133
|
-
selectContext = { ...selectContext, scope: aggregateResult.aggregateScope };
|
|
134
|
-
|
|
135
|
-
// Build final projections if needed
|
|
136
|
-
if (aggregateResult.needsFinalProjection && aggregateResult.aggregateNode && aggregateResult.groupByExpressions) {
|
|
137
|
-
const finalProjections = buildFinalAggregateProjections(
|
|
138
|
-
stmt,
|
|
139
|
-
selectContext,
|
|
140
|
-
aggregateResult.aggregateScope,
|
|
141
|
-
aggregateResult.aggregateNode,
|
|
142
|
-
aggregates,
|
|
143
|
-
aggregateResult.groupByExpressions
|
|
144
|
-
);
|
|
145
|
-
input = new ProjectNode(selectScope, input, finalProjections, undefined, undefined, preserveInputColumns);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Handle window functions if present
|
|
150
|
-
if (hasWindowFunctions) {
|
|
151
|
-
// Check if ORDER BY references columns not in SELECT before applying window functions
|
|
152
|
-
let preWindowSort = false;
|
|
153
|
-
if (stmt.orderBy) {
|
|
154
|
-
const selectedColumns = new Set<string>();
|
|
155
|
-
for (const column of stmt.columns) {
|
|
156
|
-
if (column.type === 'column' && column.expr.type === 'column') {
|
|
157
|
-
selectedColumns.add(column.expr.name.toLowerCase());
|
|
158
|
-
}
|
|
159
|
-
if (column.type === 'column' && column.alias) {
|
|
160
|
-
selectedColumns.add(column.alias.toLowerCase());
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// Check if ORDER BY references columns not in SELECT
|
|
165
|
-
for (const orderByClause of stmt.orderBy) {
|
|
166
|
-
if (orderByClause.expr.type === 'column') {
|
|
167
|
-
const orderColumn = orderByClause.expr.name.toLowerCase();
|
|
168
|
-
if (!selectedColumns.has(orderColumn)) {
|
|
169
|
-
// Apply ORDER BY before window projections
|
|
170
|
-
const sortKeys: SortKey[] = stmt.orderBy.map(orderBy => ({
|
|
171
|
-
expression: buildExpression(selectContext, orderBy.expr),
|
|
172
|
-
direction: orderBy.direction,
|
|
173
|
-
nulls: orderBy.nulls
|
|
174
|
-
}));
|
|
175
|
-
input = new SortNode(selectContext.scope, input, sortKeys);
|
|
176
|
-
preWindowSort = true;
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
input = buildWindowPhase(input, windowFunctions, selectContext, stmt);
|
|
184
|
-
|
|
185
|
-
// Update context to include window output columns
|
|
186
|
-
const windowOutputScope = new RegisteredScope(selectContext.scope);
|
|
187
|
-
const windowAttributes = input.getAttributes();
|
|
188
|
-
input.getType().columns.forEach((col, index) => {
|
|
189
|
-
const attr = windowAttributes[index];
|
|
190
|
-
windowOutputScope.registerSymbol(col.name.toLowerCase(), (exp, s) =>
|
|
191
|
-
new ColumnReferenceNode(s, exp as AST.ColumnExpr, col.type, attr.id, index));
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
// Create combined scope that includes both original columns and window output
|
|
195
|
-
const combinedScope = new MultiScope([windowOutputScope, selectScope]);
|
|
196
|
-
selectContext = { ...selectContext, scope: combinedScope };
|
|
197
|
-
|
|
198
|
-
// Don't apply ORDER BY again if we already did it
|
|
199
|
-
if (preWindowSort) {
|
|
200
|
-
preAggregateSort = true;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// Handle final projections for non-aggregate, non-window cases
|
|
205
|
-
if (!hasAggregates && !hasWindowFunctions) {
|
|
206
|
-
const finalResult = buildFinalProjections(input, projections, selectScope, stmt, selectContext, preserveInputColumns);
|
|
207
|
-
input = finalResult.output;
|
|
208
|
-
selectContext = finalResult.finalContext;
|
|
209
|
-
preAggregateSort = finalResult.preAggregateSort;
|
|
210
|
-
|
|
211
|
-
// Apply final modifiers with projection scope for column alias resolution
|
|
212
|
-
input = applyDistinct(input, stmt, selectScope);
|
|
213
|
-
input = applyOrderBy(input, stmt, selectContext, preAggregateSort, finalResult.projectionScope);
|
|
214
|
-
input = applyLimitOffset(input, stmt, selectContext, finalResult.projectionScope);
|
|
215
|
-
} else {
|
|
216
|
-
// Apply final modifiers without projection scope for aggregate/window cases
|
|
217
|
-
input = applyDistinct(input, stmt, selectScope);
|
|
218
|
-
input = applyOrderBy(input, stmt, selectContext, preAggregateSort);
|
|
219
|
-
input = applyLimitOffset(input, stmt, selectContext);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return input;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Creates a plan for a VALUES statement.
|
|
227
|
-
*
|
|
228
|
-
* @param ctx The planning context
|
|
229
|
-
* @param stmt The AST.ValuesStmt to plan
|
|
230
|
-
* @returns A ValuesNode representing the VALUES clause
|
|
231
|
-
*/
|
|
232
|
-
export function buildValuesStmt(
|
|
233
|
-
ctx: PlanningContext,
|
|
234
|
-
stmt: AST.ValuesStmt
|
|
235
|
-
): ValuesNode {
|
|
236
|
-
// Build each row of values
|
|
237
|
-
const rows: ScalarPlanNode[][] = stmt.values.map(rowValues =>
|
|
238
|
-
rowValues.map(valueExpr => buildExpression(ctx, valueExpr))
|
|
239
|
-
);
|
|
240
|
-
|
|
241
|
-
// Create the VALUES node
|
|
242
|
-
return new ValuesNode(ctx.scope, rows);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Processes a FROM clause item into a relational plan node.
|
|
247
|
-
*
|
|
248
|
-
* Handles different types of FROM items:
|
|
249
|
-
* - Table references - creates a TableReferenceNode
|
|
250
|
-
* - Subqueries - plans the subquery
|
|
251
|
-
* - Joins - builds the join structure
|
|
252
|
-
* - Table functions - creates a table function call node
|
|
253
|
-
*
|
|
254
|
-
* For a simple table reference, this calls buildTableReference which
|
|
255
|
-
* returns a TableReferenceNode for that table.
|
|
256
|
-
*
|
|
257
|
-
* @param fromClause The FROM clause AST node to process
|
|
258
|
-
* @param ctx The planning context
|
|
259
|
-
* @returns A relational plan node representing the FROM clause
|
|
260
|
-
*/
|
|
261
|
-
export function buildFrom(fromClause: AST.FromClause, parentContext: PlanningContext, cteNodes: Map<string, CTEScopeNode> = new Map()): RelationalPlanNode {
|
|
262
|
-
let fromTable: RelationalPlanNode;
|
|
263
|
-
let columnScope: Scope;
|
|
264
|
-
|
|
265
|
-
if (fromClause.type === 'table') {
|
|
266
|
-
const tableName = fromClause.table.name.toLowerCase();
|
|
267
|
-
|
|
268
|
-
// Check if this is a CTE reference
|
|
269
|
-
if (cteNodes.has(tableName)) {
|
|
270
|
-
const cteNode = cteNodes.get(tableName)!;
|
|
271
|
-
|
|
272
|
-
// Check if this is an internal recursive CTE reference
|
|
273
|
-
if (CapabilityDetectors.isRecursiveCTERef(cteNode)) {
|
|
274
|
-
// For internal recursive references, use the node directly
|
|
275
|
-
fromTable = cteNode;
|
|
276
|
-
|
|
277
|
-
// Create scope for internal recursive CTE columns
|
|
278
|
-
const internalScope = new RegisteredScope(parentContext.scope);
|
|
279
|
-
const internalAttributes = cteNode.getAttributes();
|
|
280
|
-
cteNode.getType().columns.forEach((c, i) => {
|
|
281
|
-
const attr = internalAttributes[i];
|
|
282
|
-
internalScope.registerSymbol(c.name.toLowerCase(), (exp, s) =>
|
|
283
|
-
new ColumnReferenceNode(s, exp as AST.ColumnExpr, c.type, attr.id, i));
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
if (fromClause.alias) {
|
|
287
|
-
columnScope = new AliasedScope(internalScope, tableName, fromClause.alias.toLowerCase());
|
|
288
|
-
} else {
|
|
289
|
-
columnScope = new AliasedScope(internalScope, tableName, tableName);
|
|
290
|
-
}
|
|
291
|
-
} else {
|
|
292
|
-
// Regular CTE reference - cache by CTE name + alias to ensure consistent attribute IDs
|
|
293
|
-
const cacheKey = `${tableName}:${fromClause.alias || tableName}`;
|
|
294
|
-
|
|
295
|
-
// Initialize cache if not exists
|
|
296
|
-
if (!parentContext.cteReferenceCache) {
|
|
297
|
-
parentContext.cteReferenceCache = new Map();
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
let cteRefNode: CTEReferenceNode;
|
|
301
|
-
if (parentContext.cteReferenceCache.has(cacheKey)) {
|
|
302
|
-
cteRefNode = parentContext.cteReferenceCache.get(cacheKey)!;
|
|
303
|
-
const attrs = cteRefNode.getAttributes();
|
|
304
|
-
logger(`Using cached CTE reference ${cacheKey}, attrs=[${attrs.map(a => a.id).join(',')}]`);
|
|
305
|
-
} else {
|
|
306
|
-
cteRefNode = new CTEReferenceNode(parentContext.scope, cteNode as CTEPlanNode, fromClause.alias);
|
|
307
|
-
parentContext.cteReferenceCache.set(cacheKey, cteRefNode);
|
|
308
|
-
const attrs = cteRefNode.getAttributes();
|
|
309
|
-
logger(`Created new CTE reference ${cacheKey}, attrs=[${attrs.map(a => a.id).join(',')}]`);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
// Create scope for CTE columns using attributes from the reference node
|
|
313
|
-
// CRITICAL: Use a closure to capture the reference node's attributes
|
|
314
|
-
// This ensures all column references use the same attribute IDs
|
|
315
|
-
const cteScope = new RegisteredScope(parentContext.scope);
|
|
316
|
-
const refAttrs = cteRefNode.getAttributes();
|
|
317
|
-
cteRefNode.getType().columns.forEach((c, i) => {
|
|
318
|
-
const attr = refAttrs[i];
|
|
319
|
-
cteScope.registerSymbol(c.name.toLowerCase(), (exp, s) => {
|
|
320
|
-
// Always use the cached reference node's attribute ID
|
|
321
|
-
return new ColumnReferenceNode(s, exp as AST.ColumnExpr, c.type, attr.id, i);
|
|
322
|
-
});
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
if (fromClause.alias) {
|
|
326
|
-
columnScope = new AliasedScope(cteScope, tableName, fromClause.alias.toLowerCase());
|
|
327
|
-
} else {
|
|
328
|
-
columnScope = new AliasedScope(cteScope, tableName, tableName);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
// CRITICAL: Cache the reference node so later expression compilation uses the same attribute IDs
|
|
332
|
-
// TODO: replace this monkey patching with a proper interface
|
|
333
|
-
(columnScope as any).referenceNode = cteRefNode;
|
|
334
|
-
|
|
335
|
-
fromTable = cteRefNode;
|
|
336
|
-
}
|
|
337
|
-
} else {
|
|
338
|
-
// Check if this is a view
|
|
339
|
-
const schemaName = fromClause.table.schema || parentContext.db.schemaManager.getCurrentSchemaName();
|
|
340
|
-
const viewSchema = parentContext.db.schemaManager.getView(schemaName, fromClause.table.name);
|
|
341
|
-
|
|
342
|
-
if (viewSchema) {
|
|
343
|
-
// Build the view's SELECT statement
|
|
344
|
-
let viewSelectNode = buildSelectStmt(parentContext, viewSchema.selectAst, cteNodes) as RelationalPlanNode;
|
|
345
|
-
|
|
346
|
-
// If the view has explicit column names, wrap with a projection to rename columns
|
|
347
|
-
if (viewSchema.columns && viewSchema.columns.length > 0) {
|
|
348
|
-
const viewAttributes = viewSelectNode.getAttributes();
|
|
349
|
-
const projections = viewSchema.columns.map((columnName, i) => {
|
|
350
|
-
if (i >= viewAttributes.length) {
|
|
351
|
-
throw new QuereusError(
|
|
352
|
-
`View '${viewSchema.name}' has more explicit column names than SELECT columns`,
|
|
353
|
-
StatusCode.ERROR
|
|
354
|
-
);
|
|
355
|
-
}
|
|
356
|
-
const attr = viewAttributes[i];
|
|
357
|
-
const columnRef = new ColumnReferenceNode(
|
|
358
|
-
parentContext.scope,
|
|
359
|
-
{ type: 'column', name: attr.name } as AST.ColumnExpr,
|
|
360
|
-
attr.type,
|
|
361
|
-
attr.id,
|
|
362
|
-
i
|
|
363
|
-
);
|
|
364
|
-
return {
|
|
365
|
-
node: columnRef,
|
|
366
|
-
alias: columnName
|
|
367
|
-
};
|
|
368
|
-
});
|
|
369
|
-
fromTable = new ProjectNode(parentContext.scope, viewSelectNode, projections);
|
|
370
|
-
} else {
|
|
371
|
-
fromTable = viewSelectNode;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// Create scope for view columns
|
|
375
|
-
const viewScope = new RegisteredScope(parentContext.scope);
|
|
376
|
-
const viewAttributes = fromTable.getAttributes();
|
|
377
|
-
fromTable.getType().columns.forEach((c, i) => {
|
|
378
|
-
const attr = viewAttributes[i];
|
|
379
|
-
viewScope.registerSymbol(c.name.toLowerCase(), (exp, s) =>
|
|
380
|
-
new ColumnReferenceNode(s, exp as AST.ColumnExpr, c.type, attr.id, i));
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
if (fromClause.alias) {
|
|
384
|
-
columnScope = new AliasedScope(viewScope, fromClause.table.name.toLowerCase(), fromClause.alias.toLowerCase());
|
|
385
|
-
} else {
|
|
386
|
-
columnScope = new AliasedScope(viewScope, fromClause.table.name.toLowerCase(), fromClause.table.name.toLowerCase());
|
|
387
|
-
}
|
|
388
|
-
} else {
|
|
389
|
-
// Regular table
|
|
390
|
-
fromTable = buildTableReference(fromClause, parentContext);
|
|
391
|
-
|
|
392
|
-
// Create scope for table columns
|
|
393
|
-
const tableScope = new RegisteredScope(parentContext.scope);
|
|
394
|
-
const tableAttributes = fromTable.getAttributes();
|
|
395
|
-
fromTable.getType().columns.forEach((c, i) => {
|
|
396
|
-
const attr = tableAttributes[i];
|
|
397
|
-
tableScope.registerSymbol(c.name.toLowerCase(), (exp, s) =>
|
|
398
|
-
new ColumnReferenceNode(s, exp as AST.ColumnExpr, c.type, attr.id, i));
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
if (fromClause.alias) {
|
|
402
|
-
columnScope = new AliasedScope(tableScope, fromClause.table.name.toLowerCase(), fromClause.alias.toLowerCase());
|
|
403
|
-
} else {
|
|
404
|
-
columnScope = new AliasedScope(tableScope, fromClause.table.name.toLowerCase(), fromClause.table.name.toLowerCase());
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
} else if (fromClause.type === 'functionSource') {
|
|
410
|
-
fromTable = buildTableFunctionCall(fromClause, parentContext);
|
|
411
|
-
|
|
412
|
-
// Create scope for function columns
|
|
413
|
-
const functionScope = new RegisteredScope(parentContext.scope);
|
|
414
|
-
const functionAttributes = fromTable.getAttributes();
|
|
415
|
-
fromTable.getType().columns.forEach((c, i) => {
|
|
416
|
-
const attr = functionAttributes[i];
|
|
417
|
-
functionScope.registerSymbol(c.name.toLowerCase(), (exp, s) =>
|
|
418
|
-
new ColumnReferenceNode(s, exp as AST.ColumnExpr, c.type, attr.id, i));
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
if (fromClause.alias) {
|
|
422
|
-
// Use the alias as the table name
|
|
423
|
-
columnScope = new AliasedScope(functionScope, '', fromClause.alias.toLowerCase());
|
|
424
|
-
} else {
|
|
425
|
-
// Use the function name as the table name
|
|
426
|
-
columnScope = new AliasedScope(functionScope, '', fromClause.name.name.toLowerCase());
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
} else if (fromClause.type === 'subquerySource') {
|
|
430
|
-
// Build the subquery
|
|
431
|
-
if (fromClause.subquery.type === 'select') {
|
|
432
|
-
fromTable = buildSelectStmt(parentContext, fromClause.subquery, cteNodes) as RelationalPlanNode;
|
|
433
|
-
} else if (fromClause.subquery.type === 'values') {
|
|
434
|
-
fromTable = buildValuesStmt(parentContext, fromClause.subquery);
|
|
435
|
-
} else {
|
|
436
|
-
const exhaustiveCheck: never = fromClause.subquery;
|
|
437
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
438
|
-
throw new QuereusError(`Unsupported subquery type: ${(exhaustiveCheck as any).type}`, StatusCode.INTERNAL);
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
// Create scope for subquery columns
|
|
442
|
-
const subqueryScope = new RegisteredScope(parentContext.scope);
|
|
443
|
-
const subqueryAttributes = fromTable.getAttributes();
|
|
444
|
-
|
|
445
|
-
// Use provided column names or infer from subquery
|
|
446
|
-
const columnNames = fromClause.columns || fromTable.getType().columns.map(c => c.name);
|
|
447
|
-
|
|
448
|
-
columnNames.forEach((colName, i) => {
|
|
449
|
-
if (i < subqueryAttributes.length) {
|
|
450
|
-
const attr = subqueryAttributes[i];
|
|
451
|
-
const columnType = fromTable.getType().columns[i]?.type || { typeClass: 'scalar', logicalType: TEXT_TYPE, nullable: true, isReadOnly: true };
|
|
452
|
-
subqueryScope.registerSymbol(colName.toLowerCase(), (exp, s) =>
|
|
453
|
-
new ColumnReferenceNode(s, exp as AST.ColumnExpr, columnType, attr.id, i));
|
|
454
|
-
}
|
|
455
|
-
});
|
|
456
|
-
|
|
457
|
-
columnScope = new AliasedScope(subqueryScope, '', fromClause.alias.toLowerCase());
|
|
458
|
-
|
|
459
|
-
} else if (fromClause.type === 'mutatingSubquerySource') {
|
|
460
|
-
// Build the mutating subquery (DML with RETURNING)
|
|
461
|
-
let dmlNode: RelationalPlanNode;
|
|
462
|
-
|
|
463
|
-
if (fromClause.stmt.type === 'insert') {
|
|
464
|
-
// Build INSERT without SinkNode wrapper since we need the RETURNING results
|
|
465
|
-
dmlNode = buildInsertStmt(parentContext, fromClause.stmt) as RelationalPlanNode;
|
|
466
|
-
} else if (fromClause.stmt.type === 'update') {
|
|
467
|
-
// Build UPDATE without SinkNode wrapper since we need the RETURNING results
|
|
468
|
-
dmlNode = buildUpdateStmt(parentContext, fromClause.stmt) as RelationalPlanNode;
|
|
469
|
-
} else if (fromClause.stmt.type === 'delete') {
|
|
470
|
-
// Build DELETE without SinkNode wrapper since we need the RETURNING results
|
|
471
|
-
dmlNode = buildDeleteStmt(parentContext, fromClause.stmt) as RelationalPlanNode;
|
|
472
|
-
} else {
|
|
473
|
-
const exhaustiveCheck: never = fromClause.stmt;
|
|
474
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
475
|
-
throw new QuereusError(`Unsupported mutating subquery type: ${(exhaustiveCheck as any).type}`, StatusCode.INTERNAL);
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
fromTable = dmlNode;
|
|
479
|
-
|
|
480
|
-
// Create scope for mutating subquery columns
|
|
481
|
-
const mutatingScope = new RegisteredScope(parentContext.scope);
|
|
482
|
-
const mutatingAttributes = fromTable.getAttributes();
|
|
483
|
-
|
|
484
|
-
// Use provided column names or infer from RETURNING clause
|
|
485
|
-
const columnNames = fromClause.columns || fromTable.getType().columns.map(c => c.name);
|
|
486
|
-
|
|
487
|
-
columnNames.forEach((colName, i) => {
|
|
488
|
-
if (i < mutatingAttributes.length) {
|
|
489
|
-
const attr = mutatingAttributes[i];
|
|
490
|
-
const columnType = fromTable.getType().columns[i]?.type || { typeClass: 'scalar', logicalType: TEXT_TYPE, nullable: true, isReadOnly: false };
|
|
491
|
-
mutatingScope.registerSymbol(colName.toLowerCase(), (exp, s) =>
|
|
492
|
-
new ColumnReferenceNode(s, exp as AST.ColumnExpr, columnType, attr.id, i));
|
|
493
|
-
}
|
|
494
|
-
});
|
|
495
|
-
|
|
496
|
-
columnScope = new AliasedScope(mutatingScope, '', fromClause.alias.toLowerCase());
|
|
497
|
-
|
|
498
|
-
} else if (fromClause.type === 'join') {
|
|
499
|
-
// Handle JOIN clauses
|
|
500
|
-
return buildJoin(fromClause, parentContext, cteNodes);
|
|
501
|
-
} else {
|
|
502
|
-
// Handle the case where fromClause.type is not recognized
|
|
503
|
-
const exhaustiveCheck: never = fromClause;
|
|
504
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
505
|
-
throw new QuereusError(`Unsupported FROM clause type: ${(exhaustiveCheck as any).type}`, StatusCode.INTERNAL);
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
parentContext.outputScopes.set(fromTable, columnScope);
|
|
509
|
-
return fromTable;
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
/**
|
|
513
|
-
* Builds a join plan node from an AST join clause
|
|
514
|
-
*/
|
|
515
|
-
function buildJoin(joinClause: AST.JoinClause, parentContext: PlanningContext, cteNodes: Map<string, CTEScopeNode>): JoinNode {
|
|
516
|
-
// Build left and right sides recursively
|
|
517
|
-
const leftNode = buildFrom(joinClause.left, parentContext, cteNodes);
|
|
518
|
-
const rightNode = buildFrom(joinClause.right, parentContext, cteNodes);
|
|
519
|
-
|
|
520
|
-
// Create a combined scope for join expressions
|
|
521
|
-
const leftScope = parentContext.outputScopes.get(leftNode);
|
|
522
|
-
const rightScope = parentContext.outputScopes.get(rightNode);
|
|
523
|
-
if (!leftScope || !rightScope) {
|
|
524
|
-
// This should not happen if buildFrom correctly populates the scopes
|
|
525
|
-
throw new QuereusError('Could not find output scope for join source', StatusCode.INTERNAL);
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
// Create a combined scope for the join that includes both left and right columns
|
|
529
|
-
const combinedScope = new MultiScope([leftScope, rightScope]);
|
|
530
|
-
|
|
531
|
-
// Create a new planning context with the combined scope for condition evaluation
|
|
532
|
-
const joinContext: PlanningContext = {
|
|
533
|
-
...parentContext,
|
|
534
|
-
scope: combinedScope
|
|
535
|
-
};
|
|
536
|
-
|
|
537
|
-
let condition: ScalarPlanNode | undefined;
|
|
538
|
-
let usingColumns: string[] | undefined;
|
|
539
|
-
|
|
540
|
-
// Handle ON condition
|
|
541
|
-
if (joinClause.condition) {
|
|
542
|
-
condition = buildExpression(joinContext, joinClause.condition);
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
// Handle USING columns
|
|
546
|
-
if (joinClause.columns) {
|
|
547
|
-
usingColumns = joinClause.columns;
|
|
548
|
-
// Convert USING to ON condition: table1.col1 = table2.col1 AND table1.col2 = table2.col2 ...
|
|
549
|
-
// For now, store the column names and let the emitter handle the condition
|
|
550
|
-
// TODO: This could be improved by synthesizing the equality conditions here
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
const joinNode = new JoinNode(
|
|
554
|
-
parentContext.scope,
|
|
555
|
-
leftNode,
|
|
556
|
-
rightNode,
|
|
557
|
-
joinClause.joinType,
|
|
558
|
-
condition,
|
|
559
|
-
usingColumns
|
|
560
|
-
);
|
|
561
|
-
|
|
562
|
-
// Use the combined scope as the column scope for the join
|
|
563
|
-
// This allows both qualified and unqualified column references to resolve properly
|
|
564
|
-
parentContext.outputScopes.set(joinNode, combinedScope);
|
|
565
|
-
|
|
566
|
-
return joinNode;
|
|
567
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type * as AST from '../../parser/ast.js';
|
|
2
|
-
import type { PlanningContext } from '../planning-context.js';
|
|
3
|
-
import { TableFunctionCallNode } from '../nodes/table-function-call.js';
|
|
4
|
-
import { buildExpression } from './expression.js';
|
|
5
|
-
import { QuereusError } from '../../common/errors.js';
|
|
6
|
-
import { StatusCode } from '../../common/types.js';
|
|
7
|
-
import { isTableValuedFunctionSchema } from '../../schema/function.js';
|
|
8
|
-
import { resolveFunctionSchema } from './schema-resolution.js';
|
|
9
|
-
|
|
10
|
-
export function buildTableFunctionCall(
|
|
11
|
-
functionSource: AST.FunctionSource,
|
|
12
|
-
ctx: PlanningContext
|
|
13
|
-
): TableFunctionCallNode {
|
|
14
|
-
const functionName = functionSource.name.name;
|
|
15
|
-
const args = functionSource.args.map(arg => buildExpression(ctx, arg));
|
|
16
|
-
|
|
17
|
-
// Resolve function schema at build time
|
|
18
|
-
const functionSchema = resolveFunctionSchema(ctx, functionName, args.length);
|
|
19
|
-
|
|
20
|
-
if (!isTableValuedFunctionSchema(functionSchema)) {
|
|
21
|
-
throw new QuereusError(
|
|
22
|
-
`Function ${functionName}/${args.length} is not a table-valued function`,
|
|
23
|
-
StatusCode.ERROR,
|
|
24
|
-
undefined,
|
|
25
|
-
functionSource.loc?.start.line,
|
|
26
|
-
functionSource.loc?.start.column
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Validate argument count
|
|
31
|
-
if (functionSchema.numArgs >= 0 && args.length !== functionSchema.numArgs) {
|
|
32
|
-
throw new QuereusError(
|
|
33
|
-
`Function ${functionName} called with ${args.length} arguments, expected ${functionSchema.numArgs}`,
|
|
34
|
-
StatusCode.ERROR,
|
|
35
|
-
undefined,
|
|
36
|
-
functionSource.loc?.start.line,
|
|
37
|
-
functionSource.loc?.start.column
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return new TableFunctionCallNode(
|
|
42
|
-
ctx.scope,
|
|
43
|
-
functionName,
|
|
44
|
-
functionSchema,
|
|
45
|
-
args,
|
|
46
|
-
functionSource.alias,
|
|
47
|
-
functionSource.columns
|
|
48
|
-
);
|
|
49
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { QuereusError } from '../../common/errors.js';
|
|
2
|
-
import { StatusCode } from '../../common/types.js';
|
|
3
|
-
import type * as AST from '../../parser/ast.js';
|
|
4
|
-
import { TableReferenceNode } from '../nodes/reference.js';
|
|
5
|
-
import { RetrieveNode } from '../nodes/retrieve-node.js';
|
|
6
|
-
import type { PlanningContext } from '../planning-context.js';
|
|
7
|
-
import { resolveTableSchema, resolveVtabModule } from './schema-resolution.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Plans a table reference operation based on a FROM clause item.
|
|
11
|
-
* Creates a TableReferenceNode and wraps it in a RetrieveNode to establish
|
|
12
|
-
* the boundary between virtual table module execution and Quereus execution.
|
|
13
|
-
*
|
|
14
|
-
* @param fromClause The AST node representing a table in the FROM clause.
|
|
15
|
-
* @param context The planning context to resolve table definitions.
|
|
16
|
-
* @returns A RetrieveNode wrapping the TableReferenceNode for the specified table.
|
|
17
|
-
* @throws {QuereusError} If the table is not found, the reference is ambiguous, or fromClause is not a simple table.
|
|
18
|
-
*/
|
|
19
|
-
export function buildTableReference(fromClause: AST.FromClause, context: PlanningContext): RetrieveNode {
|
|
20
|
-
if (fromClause.type !== 'table') {
|
|
21
|
-
throw new QuereusError('buildTableReference currently only supports simple table references.', StatusCode.INTERNAL);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Resolve table schema at build time
|
|
25
|
-
const tableSchema = resolveTableSchema(context, fromClause.table.name, fromClause.table.schema);
|
|
26
|
-
|
|
27
|
-
// Resolve vtab module at build time
|
|
28
|
-
const vtabModuleInfo = resolveVtabModule(context, tableSchema.vtabModuleName);
|
|
29
|
-
|
|
30
|
-
const tableRef = new TableReferenceNode(
|
|
31
|
-
context.scope,
|
|
32
|
-
tableSchema,
|
|
33
|
-
vtabModuleInfo.module,
|
|
34
|
-
vtabModuleInfo.auxData
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
// Wrap in RetrieveNode to establish vtab/Quereus boundary
|
|
38
|
-
return new RetrieveNode(context.scope, tableRef, tableRef);
|
|
39
|
-
}
|
|
40
|
-
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import * as AST from '../../parser/ast.js';
|
|
2
|
-
import type { PlanningContext } from '../planning-context.js';
|
|
3
|
-
import { TransactionPlanNode } from '../nodes/transaction-node.js';
|
|
4
|
-
|
|
5
|
-
export function buildBeginStmt(ctx: PlanningContext, stmt: AST.BeginStmt): TransactionPlanNode {
|
|
6
|
-
return new TransactionPlanNode(ctx.scope, 'begin', stmt);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function buildCommitStmt(ctx: PlanningContext, stmt: AST.CommitStmt): TransactionPlanNode {
|
|
10
|
-
return new TransactionPlanNode(ctx.scope, 'commit', stmt);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function buildRollbackStmt(ctx: PlanningContext, stmt: AST.RollbackStmt): TransactionPlanNode {
|
|
14
|
-
return new TransactionPlanNode(ctx.scope, 'rollback', stmt, stmt.savepoint);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function buildSavepointStmt(ctx: PlanningContext, stmt: AST.SavepointStmt): TransactionPlanNode {
|
|
18
|
-
return new TransactionPlanNode(ctx.scope, 'savepoint', stmt, stmt.name);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function buildReleaseStmt(ctx: PlanningContext, stmt: AST.ReleaseStmt): TransactionPlanNode {
|
|
22
|
-
return new TransactionPlanNode(ctx.scope, 'release', stmt, stmt.savepoint);
|
|
23
|
-
}
|