@quereus/quereus 0.7.3 → 0.7.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/dist/src/schema/manager.d.ts.map +1 -1
- package/dist/src/schema/manager.js +19 -18
- 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,581 +0,0 @@
|
|
|
1
|
-
import type { StreamAggregateNode } from '../../planner/nodes/stream-aggregate.js';
|
|
2
|
-
import type { Instruction, InstructionRun, RuntimeContext } from '../types.js';
|
|
3
|
-
import { emitPlanNode, emitCallFromPlan } from '../emitters.js';
|
|
4
|
-
import { type SqlValue, type Row, type MaybePromise } from '../../common/types.js';
|
|
5
|
-
import type { EmissionContext } from '../emission-context.js';
|
|
6
|
-
import type { FunctionSchema } from '../../schema/function.js';
|
|
7
|
-
import { isAggregateFunctionSchema } from '../../schema/function.js';
|
|
8
|
-
import { AggregateFunctionCallNode } from '../../planner/nodes/aggregate-function.js';
|
|
9
|
-
import type { PlanNode, RowDescriptor } from '../../planner/nodes/plan-node.js';
|
|
10
|
-
import { isRelationalNode } from '../../planner/nodes/plan-node.js';
|
|
11
|
-
import { compareSqlValues } from '../../util/comparison.js';
|
|
12
|
-
import { BTree } from 'inheritree';
|
|
13
|
-
import { createLogger } from '../../common/logger.js';
|
|
14
|
-
import { logContextPush, logContextPop } from '../utils.js';
|
|
15
|
-
import { coerceForAggregate } from '../../util/coercion.js';
|
|
16
|
-
import { quereusError } from '../../common/errors.js';
|
|
17
|
-
import { StatusCode } from '../../common/types.js';
|
|
18
|
-
import { buildRowDescriptor } from '../../util/row-descriptor.js';
|
|
19
|
-
import { AggValue } from '../../func/registration.js';
|
|
20
|
-
|
|
21
|
-
export const ctxLog = createLogger('runtime:context');
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Compare two arrays of SQL values for equality
|
|
25
|
-
*/
|
|
26
|
-
function compareGroupKeys(a: SqlValue[], b: SqlValue[]): number {
|
|
27
|
-
if (a.length !== b.length) {
|
|
28
|
-
return a.length - b.length;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
for (let i = 0; i < a.length; i++) {
|
|
32
|
-
const comparison = compareSqlValues(a[i], b[i]);
|
|
33
|
-
if (comparison !== 0) {
|
|
34
|
-
return comparison;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return 0;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Compare SQL values for DISTINCT tracking (single value or array)
|
|
42
|
-
*/
|
|
43
|
-
function compareDistinctValues(a: SqlValue | SqlValue[], b: SqlValue | SqlValue[]): number {
|
|
44
|
-
// Handle arrays (for multi-argument aggregates)
|
|
45
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
|
46
|
-
return compareGroupKeys(a, b);
|
|
47
|
-
}
|
|
48
|
-
// Handle single values
|
|
49
|
-
if (!Array.isArray(a) && !Array.isArray(b)) {
|
|
50
|
-
return compareSqlValues(a, b);
|
|
51
|
-
}
|
|
52
|
-
// Mixed types shouldn't happen, but handle gracefully
|
|
53
|
-
return Array.isArray(a) ? 1 : -1;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Find the source relation node that column references should use as their context key.
|
|
58
|
-
* This traverses up the tree to find the original table scan or similar node.
|
|
59
|
-
*/
|
|
60
|
-
function findSourceRelation(node: PlanNode): PlanNode {
|
|
61
|
-
// Keep going up until we find a values node
|
|
62
|
-
let current = node;
|
|
63
|
-
while (current) {
|
|
64
|
-
if (current.nodeType === 'Values' || current.nodeType === 'SingleRow') {
|
|
65
|
-
return current;
|
|
66
|
-
}
|
|
67
|
-
// Get the first relational source
|
|
68
|
-
const relations = current.getRelations();
|
|
69
|
-
if (relations.length > 0) {
|
|
70
|
-
current = relations[0];
|
|
71
|
-
} else {
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return node; // Fallback to the original node
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function emitStreamAggregate(plan: StreamAggregateNode, ctx: EmissionContext): Instruction {
|
|
79
|
-
// Find the actual source relation for column references
|
|
80
|
-
const sourceRelation = findSourceRelation(plan.source);
|
|
81
|
-
|
|
82
|
-
// Create row descriptors for context
|
|
83
|
-
const sourceAttributes = plan.source.getAttributes();
|
|
84
|
-
|
|
85
|
-
// Create separate descriptors for group yielding to avoid conflicts with source row processing
|
|
86
|
-
const groupSourceRowDescriptor = buildRowDescriptor(sourceAttributes);
|
|
87
|
-
const groupSourceRelationRowDescriptor = sourceRelation !== plan.source
|
|
88
|
-
? buildRowDescriptor(isRelationalNode(sourceRelation) ? sourceRelation.getAttributes() : sourceAttributes)
|
|
89
|
-
: groupSourceRowDescriptor;
|
|
90
|
-
|
|
91
|
-
ctxLog('StreamAggregate setup: source=%s, sourceRelation=%s', plan.source.nodeType, sourceRelation.nodeType);
|
|
92
|
-
ctxLog('Source attributes: %O', sourceAttributes.map(attr => `${attr.name}(#${attr.id})`));
|
|
93
|
-
if (sourceRelation !== plan.source) {
|
|
94
|
-
const sourceRelationAttributes = isRelationalNode(sourceRelation) ? sourceRelation.getAttributes() : sourceAttributes;
|
|
95
|
-
ctxLog('Source relation attributes: %O', sourceRelationAttributes.map((attr) => `${attr.name}(#${attr.id})`));
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Create output row descriptor for the StreamAggregate's output
|
|
99
|
-
const outputRowDescriptor = buildRowDescriptor(plan.getAttributes());
|
|
100
|
-
|
|
101
|
-
// Create scan row descriptor for source relation attributes (for Filter evaluation)
|
|
102
|
-
const scanRowDescriptor = buildRowDescriptor(sourceAttributes);
|
|
103
|
-
|
|
104
|
-
// CRITICAL FIX: Create a combined descriptor that includes BOTH output and source attributes
|
|
105
|
-
// This allows correlated subqueries to access original table attributes
|
|
106
|
-
const combinedRowDescriptor: RowDescriptor = {...outputRowDescriptor};
|
|
107
|
-
sourceAttributes.forEach((attr, index) => {
|
|
108
|
-
// Only add if not already present in output (avoid conflicts)
|
|
109
|
-
if (combinedRowDescriptor[attr.id] === undefined) {
|
|
110
|
-
combinedRowDescriptor[attr.id] = Object.keys(outputRowDescriptor).length + index;
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
async function* run(
|
|
115
|
-
ctx: RuntimeContext,
|
|
116
|
-
sourceRows: AsyncIterable<Row>,
|
|
117
|
-
...groupByAndAggregateArgs: Array<(ctx: RuntimeContext) => MaybePromise<SqlValue>>
|
|
118
|
-
): AsyncIterable<Row> {
|
|
119
|
-
|
|
120
|
-
// Split the arguments: first N are GROUP BY expressions, rest are aggregate args
|
|
121
|
-
const numGroupBy = plan.groupBy.length;
|
|
122
|
-
const groupByFunctions = groupByAndAggregateArgs.slice(0, numGroupBy);
|
|
123
|
-
|
|
124
|
-
// For aggregate arguments, we need to properly index them based on each aggregate's argument count
|
|
125
|
-
let aggregateArgOffset = numGroupBy;
|
|
126
|
-
const aggregateArgFunctions: Array<Array<(ctx: RuntimeContext) => MaybePromise<SqlValue>>> = [];
|
|
127
|
-
|
|
128
|
-
for (const agg of plan.aggregates) {
|
|
129
|
-
const funcNode = agg.expression;
|
|
130
|
-
if (!(funcNode instanceof AggregateFunctionCallNode)) {
|
|
131
|
-
quereusError(
|
|
132
|
-
`Expected AggregateFunctionCallNode but got ${funcNode.constructor.name}`,
|
|
133
|
-
StatusCode.INTERNAL
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
const args = funcNode.args || [];
|
|
137
|
-
const aggregateArgs = groupByAndAggregateArgs.slice(aggregateArgOffset, aggregateArgOffset + args.length);
|
|
138
|
-
aggregateArgFunctions.push(aggregateArgs);
|
|
139
|
-
aggregateArgOffset += args.length;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Get the function schemas for each aggregate
|
|
143
|
-
const aggregateSchemas: FunctionSchema[] = [];
|
|
144
|
-
const aggregateDistinctFlags: boolean[] = [];
|
|
145
|
-
for (const agg of plan.aggregates) {
|
|
146
|
-
const funcNode = agg.expression;
|
|
147
|
-
if (!(funcNode instanceof AggregateFunctionCallNode)) {
|
|
148
|
-
quereusError(
|
|
149
|
-
`Expected AggregateFunctionCallNode but got ${funcNode.constructor.name}`,
|
|
150
|
-
StatusCode.INTERNAL
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const funcSchema = funcNode.functionSchema;
|
|
155
|
-
if (!isAggregateFunctionSchema(funcSchema)) {
|
|
156
|
-
quereusError(
|
|
157
|
-
`Function ${funcNode.functionName || 'unknown'} is not an aggregate function`,
|
|
158
|
-
StatusCode.INTERNAL
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
aggregateSchemas.push(funcSchema);
|
|
163
|
-
aggregateDistinctFlags.push(funcNode.isDistinct);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// Handle the case with no GROUP BY - aggregate everything into a single group
|
|
167
|
-
if (plan.groupBy.length === 0) {
|
|
168
|
-
// Initialize accumulators for each aggregate
|
|
169
|
-
const accumulators: SqlValue[] = aggregateSchemas.map(schema => {
|
|
170
|
-
// Get fresh initial value - if it's a function, call it; if it's an object/array, copy it
|
|
171
|
-
const initialValue = isAggregateFunctionSchema(schema) ? schema.initialValue : undefined;
|
|
172
|
-
if (typeof initialValue === 'function') {
|
|
173
|
-
return initialValue();
|
|
174
|
-
} else if (Array.isArray(initialValue)) {
|
|
175
|
-
return [...initialValue];
|
|
176
|
-
} else if (initialValue && typeof initialValue === 'object') {
|
|
177
|
-
return { ...initialValue };
|
|
178
|
-
} else {
|
|
179
|
-
return initialValue;
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
// For DISTINCT aggregates, track unique values using BTree for proper SQL comparison
|
|
184
|
-
const distinctTrees: BTree<SqlValue | SqlValue[], SqlValue | SqlValue[]>[] = aggregateDistinctFlags.map(isDistinct =>
|
|
185
|
-
isDistinct ? new BTree<SqlValue | SqlValue[], SqlValue | SqlValue[]>(
|
|
186
|
-
(val: SqlValue | SqlValue[]) => val,
|
|
187
|
-
compareDistinctValues
|
|
188
|
-
) : new BTree<SqlValue | SqlValue[], SqlValue | SqlValue[]>((val: SqlValue | SqlValue[]) => val, compareDistinctValues) // Empty tree for non-distinct
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
// Track the last source row for representative row in combined descriptor
|
|
192
|
-
let lastSourceRow: Row | null = null;
|
|
193
|
-
|
|
194
|
-
// Process all rows
|
|
195
|
-
for await (const row of sourceRows) {
|
|
196
|
-
lastSourceRow = row;
|
|
197
|
-
|
|
198
|
-
// Set the current row in the runtime context for Filter and aggregate evaluation
|
|
199
|
-
ctx.context.set(scanRowDescriptor, () => row);
|
|
200
|
-
logContextPush(scanRowDescriptor, 'scan-row', sourceAttributes);
|
|
201
|
-
|
|
202
|
-
try {
|
|
203
|
-
// For each aggregate, call its step function
|
|
204
|
-
for (let i = 0; i < plan.aggregates.length; i++) {
|
|
205
|
-
const schema = aggregateSchemas[i];
|
|
206
|
-
const isDistinct = aggregateDistinctFlags[i];
|
|
207
|
-
|
|
208
|
-
// Evaluate the aggregate arguments in the context of the current row
|
|
209
|
-
const argValues: SqlValue[] = [];
|
|
210
|
-
const funcNode = plan.aggregates[i].expression;
|
|
211
|
-
if (!(funcNode instanceof AggregateFunctionCallNode)) {
|
|
212
|
-
quereusError(`Expected AggregateFunctionCallNode but got ${funcNode.constructor.name}`, StatusCode.INTERNAL);
|
|
213
|
-
}
|
|
214
|
-
const args = funcNode.args || [];
|
|
215
|
-
const argFunctions = aggregateArgFunctions[i] || []; // Add defensive check
|
|
216
|
-
|
|
217
|
-
for (let j = 0; j < args.length; j++) {
|
|
218
|
-
if (j < argFunctions.length) {
|
|
219
|
-
const rawValue = await argFunctions[j](ctx);
|
|
220
|
-
// Apply coercion based on the function type
|
|
221
|
-
const coercedValue = coerceForAggregate(rawValue, funcNode.functionName || 'unknown');
|
|
222
|
-
argValues.push(coercedValue);
|
|
223
|
-
} else {
|
|
224
|
-
argValues.push(null);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// Handle DISTINCT logic using BTree for proper SQL value comparison
|
|
229
|
-
if (isDistinct) {
|
|
230
|
-
const distinctValue = argValues.length === 1 ? argValues[0] : argValues;
|
|
231
|
-
const existingPath = distinctTrees[i].insert(distinctValue);
|
|
232
|
-
if (!existingPath.on) {
|
|
233
|
-
// Value already exists, skip this occurrence
|
|
234
|
-
continue;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// Call the step function
|
|
239
|
-
if (isAggregateFunctionSchema(schema)) {
|
|
240
|
-
accumulators[i] = schema.stepFunction(accumulators[i], ...argValues);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
} finally {
|
|
244
|
-
// Clean up scan context for this row
|
|
245
|
-
logContextPop(scanRowDescriptor, 'scan-row');
|
|
246
|
-
ctx.context.delete(scanRowDescriptor);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// Finalize and yield the result
|
|
251
|
-
const aggregateRow: SqlValue[] = [];
|
|
252
|
-
for (let i = 0; i < plan.aggregates.length; i++) {
|
|
253
|
-
const schema = aggregateSchemas[i];
|
|
254
|
-
|
|
255
|
-
let finalValue: SqlValue;
|
|
256
|
-
if (isAggregateFunctionSchema(schema)) {
|
|
257
|
-
finalValue = schema.finalizeFunction(accumulators[i]);
|
|
258
|
-
} else {
|
|
259
|
-
finalValue = accumulators[i];
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
aggregateRow.push(finalValue);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// Build combined row with aggregate results + representative source row
|
|
266
|
-
const fullRow = lastSourceRow ? [...aggregateRow, ...lastSourceRow] : aggregateRow;
|
|
267
|
-
|
|
268
|
-
// Set up combined context for the result row (includes both output and source attributes)
|
|
269
|
-
if (lastSourceRow) {
|
|
270
|
-
ctx.context.set(scanRowDescriptor, () => lastSourceRow);
|
|
271
|
-
logContextPush(scanRowDescriptor, 'aggregate-rep-row');
|
|
272
|
-
}
|
|
273
|
-
ctx.context.set(combinedRowDescriptor, () => fullRow);
|
|
274
|
-
logContextPush(combinedRowDescriptor, 'aggregate-full-row');
|
|
275
|
-
try {
|
|
276
|
-
yield aggregateRow;
|
|
277
|
-
} finally {
|
|
278
|
-
logContextPop(combinedRowDescriptor, 'aggregate-full-row');
|
|
279
|
-
ctx.context.delete(combinedRowDescriptor);
|
|
280
|
-
if (lastSourceRow) {
|
|
281
|
-
logContextPop(scanRowDescriptor, 'aggregate-rep-row');
|
|
282
|
-
ctx.context.delete(scanRowDescriptor);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
} else {
|
|
286
|
-
// Handle GROUP BY case with streaming aggregation
|
|
287
|
-
// Since input is ordered by grouping columns, we can process groups sequentially
|
|
288
|
-
|
|
289
|
-
let currentGroupKey: SqlValue[] | null = null;
|
|
290
|
-
let currentGroupValues: SqlValue[] = [];
|
|
291
|
-
let currentSourceRow: Row | null = null; // Track the current group's representative row
|
|
292
|
-
let currentAccumulators: AggValue[] = [];
|
|
293
|
-
let currentDistinctTrees: BTree<SqlValue | SqlValue[], SqlValue | SqlValue[]>[] = [];
|
|
294
|
-
let cleanupPreviousGroupContext: (() => void) | null = null;
|
|
295
|
-
|
|
296
|
-
// Process all rows
|
|
297
|
-
for await (const row of sourceRows) {
|
|
298
|
-
if (cleanupPreviousGroupContext) {
|
|
299
|
-
cleanupPreviousGroupContext();
|
|
300
|
-
cleanupPreviousGroupContext = null;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
// Set the current row in the runtime context for Filter and GROUP BY evaluation
|
|
304
|
-
ctx.context.set(scanRowDescriptor, () => row);
|
|
305
|
-
logContextPush(scanRowDescriptor, 'scan-row', sourceAttributes);
|
|
306
|
-
|
|
307
|
-
try {
|
|
308
|
-
// Evaluate GROUP BY expressions to determine the group
|
|
309
|
-
const groupValues: SqlValue[] = [];
|
|
310
|
-
for (const groupByFunc of groupByFunctions) {
|
|
311
|
-
groupValues.push(await groupByFunc(ctx));
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// Evaluate aggregate function arguments BEFORE checking for group changes
|
|
315
|
-
// This ensures we have the values we need even if we're about to yield the previous group
|
|
316
|
-
const currentRowArgValues: SqlValue[][] = [];
|
|
317
|
-
for (let i = 0; i < plan.aggregates.length; i++) {
|
|
318
|
-
const funcNode = plan.aggregates[i].expression;
|
|
319
|
-
if (!(funcNode instanceof AggregateFunctionCallNode)) {
|
|
320
|
-
quereusError(`Expected AggregateFunctionCallNode but got ${funcNode.constructor.name}`, StatusCode.INTERNAL);
|
|
321
|
-
}
|
|
322
|
-
const args = funcNode.args || [];
|
|
323
|
-
const argFunctions = aggregateArgFunctions[i] || [];
|
|
324
|
-
|
|
325
|
-
const argValues: SqlValue[] = [];
|
|
326
|
-
for (let j = 0; j < args.length; j++) {
|
|
327
|
-
if (j < argFunctions.length) {
|
|
328
|
-
const rawValue = await argFunctions[j](ctx);
|
|
329
|
-
// Apply coercion based on the function type
|
|
330
|
-
const coercedValue = coerceForAggregate(rawValue, funcNode.functionName || 'unknown');
|
|
331
|
-
argValues.push(coercedValue);
|
|
332
|
-
} else {
|
|
333
|
-
argValues.push(null);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
currentRowArgValues.push(argValues);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
// Check if we've moved to a new group using proper SQL value comparison
|
|
340
|
-
if (currentGroupKey !== null && compareGroupKeys(currentGroupKey, groupValues) !== 0) {
|
|
341
|
-
// CRITICAL: Save the previous group's representative row before yielding
|
|
342
|
-
const previousGroupSourceRow = currentSourceRow;
|
|
343
|
-
|
|
344
|
-
// Yield the previous group's results
|
|
345
|
-
const aggregateRow: SqlValue[] = [];
|
|
346
|
-
|
|
347
|
-
// First, add the GROUP BY values
|
|
348
|
-
aggregateRow.push(...currentGroupValues);
|
|
349
|
-
|
|
350
|
-
// Then, add the finalized aggregate values
|
|
351
|
-
for (let i = 0; i < plan.aggregates.length; i++) {
|
|
352
|
-
const schema = aggregateSchemas[i];
|
|
353
|
-
|
|
354
|
-
let finalValue: SqlValue;
|
|
355
|
-
if (isAggregateFunctionSchema(schema)) {
|
|
356
|
-
finalValue = schema.finalizeFunction(currentAccumulators[i]);
|
|
357
|
-
} else {
|
|
358
|
-
finalValue = currentAccumulators[i];
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
aggregateRow.push(finalValue);
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
// Build combined row with aggregate results + representative source row
|
|
365
|
-
const fullRow = previousGroupSourceRow ? [...aggregateRow, ...previousGroupSourceRow] : aggregateRow;
|
|
366
|
-
|
|
367
|
-
// Set up context with the PREVIOUS group's representative row (not the current row)
|
|
368
|
-
if (previousGroupSourceRow) {
|
|
369
|
-
ctx.context.set(scanRowDescriptor, () => previousGroupSourceRow);
|
|
370
|
-
logContextPush(scanRowDescriptor, 'group-rep-row');
|
|
371
|
-
}
|
|
372
|
-
ctx.context.set(combinedRowDescriptor, () => fullRow);
|
|
373
|
-
logContextPush(combinedRowDescriptor, 'output-row-groupby');
|
|
374
|
-
if (previousGroupSourceRow) {
|
|
375
|
-
// Use the previous group's representative row for HAVING evaluation
|
|
376
|
-
// Use separate descriptors to avoid conflicts with source row processing
|
|
377
|
-
ctx.context.set(groupSourceRowDescriptor, () => previousGroupSourceRow!);
|
|
378
|
-
logContextPush(groupSourceRowDescriptor, 'source-row-groupby', sourceAttributes);
|
|
379
|
-
if (sourceRelation !== plan.source) {
|
|
380
|
-
ctx.context.set(groupSourceRelationRowDescriptor, () => previousGroupSourceRow!);
|
|
381
|
-
logContextPush(groupSourceRelationRowDescriptor, 'source-relation-row-groupby');
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
// Defer context cleanup
|
|
386
|
-
cleanupPreviousGroupContext = () => {
|
|
387
|
-
logContextPop(combinedRowDescriptor, 'output-row-groupby');
|
|
388
|
-
ctx.context.delete(combinedRowDescriptor);
|
|
389
|
-
if (previousGroupSourceRow) {
|
|
390
|
-
logContextPop(scanRowDescriptor, 'group-rep-row');
|
|
391
|
-
ctx.context.delete(scanRowDescriptor);
|
|
392
|
-
}
|
|
393
|
-
if (previousGroupSourceRow) {
|
|
394
|
-
logContextPop(groupSourceRowDescriptor, 'source-row-groupby');
|
|
395
|
-
ctx.context.delete(groupSourceRowDescriptor);
|
|
396
|
-
if (sourceRelation !== plan.source) {
|
|
397
|
-
logContextPop(groupSourceRelationRowDescriptor, 'source-relation-row-groupby');
|
|
398
|
-
ctx.context.delete(groupSourceRelationRowDescriptor);
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
};
|
|
402
|
-
|
|
403
|
-
yield aggregateRow;
|
|
404
|
-
|
|
405
|
-
// Reset for new group
|
|
406
|
-
currentAccumulators = aggregateSchemas.map(schema => {
|
|
407
|
-
// Get fresh initial value - if it's a function, call it; if it's an object/array, copy it
|
|
408
|
-
const initialValue = isAggregateFunctionSchema(schema) ? schema.initialValue : undefined;
|
|
409
|
-
if (typeof initialValue === 'function') {
|
|
410
|
-
return initialValue();
|
|
411
|
-
} else if (Array.isArray(initialValue)) {
|
|
412
|
-
return [...initialValue];
|
|
413
|
-
} else if (initialValue && typeof initialValue === 'object') {
|
|
414
|
-
return { ...initialValue };
|
|
415
|
-
} else {
|
|
416
|
-
return initialValue;
|
|
417
|
-
}
|
|
418
|
-
});
|
|
419
|
-
currentDistinctTrees = aggregateDistinctFlags.map(isDistinct =>
|
|
420
|
-
isDistinct ? new BTree<SqlValue | SqlValue[], SqlValue | SqlValue[]>(
|
|
421
|
-
(val: SqlValue | SqlValue[]) => val,
|
|
422
|
-
compareDistinctValues
|
|
423
|
-
) : new BTree<SqlValue | SqlValue[], SqlValue | SqlValue[]>((val: SqlValue | SqlValue[]) => val, compareDistinctValues)
|
|
424
|
-
);
|
|
425
|
-
// Set representative row for the new group (which is the current row)
|
|
426
|
-
currentSourceRow = row;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
// Initialize if first group
|
|
430
|
-
if (currentGroupKey === null) {
|
|
431
|
-
currentAccumulators = aggregateSchemas.map(schema => {
|
|
432
|
-
// Get fresh initial value - if it's a function, call it; if it's an object/array, copy it
|
|
433
|
-
const initialValue = isAggregateFunctionSchema(schema) ? schema.initialValue : undefined;
|
|
434
|
-
if (typeof initialValue === 'function') {
|
|
435
|
-
return initialValue();
|
|
436
|
-
} else if (Array.isArray(initialValue)) {
|
|
437
|
-
return [...initialValue];
|
|
438
|
-
} else if (initialValue && typeof initialValue === 'object') {
|
|
439
|
-
return { ...initialValue };
|
|
440
|
-
} else {
|
|
441
|
-
return initialValue;
|
|
442
|
-
}
|
|
443
|
-
});
|
|
444
|
-
currentDistinctTrees = aggregateDistinctFlags.map(isDistinct =>
|
|
445
|
-
isDistinct ? new BTree<SqlValue | SqlValue[], SqlValue | SqlValue[]>(
|
|
446
|
-
(val: SqlValue | SqlValue[]) => val,
|
|
447
|
-
compareDistinctValues
|
|
448
|
-
) : new BTree<SqlValue | SqlValue[], SqlValue | SqlValue[]>((val: SqlValue | SqlValue[]) => val, compareDistinctValues)
|
|
449
|
-
);
|
|
450
|
-
// Set representative row for the first group
|
|
451
|
-
currentSourceRow = row;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
// Update current group
|
|
455
|
-
currentGroupKey = groupValues;
|
|
456
|
-
currentGroupValues = groupValues;
|
|
457
|
-
|
|
458
|
-
// For each aggregate, call its step function using the pre-evaluated arguments
|
|
459
|
-
for (let i = 0; i < plan.aggregates.length; i++) {
|
|
460
|
-
const schema = aggregateSchemas[i];
|
|
461
|
-
const isDistinct = aggregateDistinctFlags[i];
|
|
462
|
-
const argValues = currentRowArgValues[i];
|
|
463
|
-
|
|
464
|
-
// Handle DISTINCT logic using BTree for proper SQL value comparison
|
|
465
|
-
if (isDistinct) {
|
|
466
|
-
const distinctValue = argValues.length === 1 ? argValues[0] : argValues;
|
|
467
|
-
const existingPath = currentDistinctTrees[i].insert(distinctValue);
|
|
468
|
-
if (!existingPath.on) {
|
|
469
|
-
// Value already exists, skip this occurrence
|
|
470
|
-
continue;
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
// Call the step function
|
|
475
|
-
if (isAggregateFunctionSchema(schema)) {
|
|
476
|
-
currentAccumulators[i] = schema.stepFunction(currentAccumulators[i], ...argValues);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
} finally {
|
|
480
|
-
// Clean up scan context for this row
|
|
481
|
-
logContextPop(scanRowDescriptor, 'scan-row');
|
|
482
|
-
ctx.context.delete(scanRowDescriptor);
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
if (cleanupPreviousGroupContext) {
|
|
487
|
-
cleanupPreviousGroupContext();
|
|
488
|
-
cleanupPreviousGroupContext = null;
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
// Yield the final group if any rows were processed
|
|
492
|
-
if (currentGroupKey !== null) {
|
|
493
|
-
const aggregateRow: SqlValue[] = [];
|
|
494
|
-
|
|
495
|
-
// First, add the GROUP BY values
|
|
496
|
-
aggregateRow.push(...currentGroupValues);
|
|
497
|
-
|
|
498
|
-
// Then, add the finalized aggregate values
|
|
499
|
-
for (let i = 0; i < plan.aggregates.length; i++) {
|
|
500
|
-
const schema = aggregateSchemas[i];
|
|
501
|
-
|
|
502
|
-
let finalValue: SqlValue;
|
|
503
|
-
if (isAggregateFunctionSchema(schema)) {
|
|
504
|
-
finalValue = schema.finalizeFunction(currentAccumulators[i]);
|
|
505
|
-
} else {
|
|
506
|
-
finalValue = currentAccumulators[i];
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
aggregateRow.push(finalValue);
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
// Build combined row with aggregate results + representative source row
|
|
513
|
-
const fullRow = currentSourceRow ? [...aggregateRow, ...currentSourceRow] : aggregateRow;
|
|
514
|
-
|
|
515
|
-
// Set up context for final group with correct source row
|
|
516
|
-
if (currentSourceRow) {
|
|
517
|
-
ctx.context.set(scanRowDescriptor, () => currentSourceRow);
|
|
518
|
-
logContextPush(scanRowDescriptor, 'final-group-rep-row');
|
|
519
|
-
}
|
|
520
|
-
ctx.context.set(combinedRowDescriptor, () => fullRow);
|
|
521
|
-
logContextPush(combinedRowDescriptor, 'final-output-row');
|
|
522
|
-
if (currentSourceRow) {
|
|
523
|
-
// Use the final group's representative row for HAVING evaluation
|
|
524
|
-
// Use separate descriptors to avoid conflicts with source row processing
|
|
525
|
-
ctx.context.set(groupSourceRowDescriptor, () => currentSourceRow!);
|
|
526
|
-
logContextPush(groupSourceRowDescriptor, 'final-source-row', sourceAttributes);
|
|
527
|
-
if (sourceRelation !== plan.source) {
|
|
528
|
-
ctx.context.set(groupSourceRelationRowDescriptor, () => currentSourceRow!);
|
|
529
|
-
logContextPush(groupSourceRelationRowDescriptor, 'final-source-relation-row');
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
try {
|
|
534
|
-
yield aggregateRow;
|
|
535
|
-
} finally {
|
|
536
|
-
logContextPop(combinedRowDescriptor, 'final-output-row');
|
|
537
|
-
ctx.context.delete(combinedRowDescriptor);
|
|
538
|
-
if (currentSourceRow) {
|
|
539
|
-
logContextPop(scanRowDescriptor, 'final-group-rep-row');
|
|
540
|
-
ctx.context.delete(scanRowDescriptor);
|
|
541
|
-
}
|
|
542
|
-
if (currentSourceRow) {
|
|
543
|
-
logContextPop(groupSourceRowDescriptor, 'final-source-row');
|
|
544
|
-
ctx.context.delete(groupSourceRowDescriptor);
|
|
545
|
-
if (sourceRelation !== plan.source) {
|
|
546
|
-
logContextPop(groupSourceRelationRowDescriptor, 'final-source-relation-row');
|
|
547
|
-
ctx.context.delete(groupSourceRelationRowDescriptor);
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
const sourceInstruction = emitPlanNode(plan.source, ctx);
|
|
556
|
-
|
|
557
|
-
// Emit GROUP BY expressions
|
|
558
|
-
const groupByInstructions = plan.groupBy.map(expr => emitCallFromPlan(expr, ctx));
|
|
559
|
-
|
|
560
|
-
// Emit aggregate argument expressions
|
|
561
|
-
const aggregateArgInstructions: Instruction[] = [];
|
|
562
|
-
for (const agg of plan.aggregates) {
|
|
563
|
-
const funcNode = agg.expression;
|
|
564
|
-
if (!(funcNode instanceof AggregateFunctionCallNode)) {
|
|
565
|
-
quereusError(`Expected AggregateFunctionCallNode but got ${funcNode.constructor.name}`, StatusCode.INTERNAL);
|
|
566
|
-
}
|
|
567
|
-
const args = funcNode.args || [];
|
|
568
|
-
for (const arg of args) {
|
|
569
|
-
if (!arg) {
|
|
570
|
-
quereusError(`Aggregate argument is undefined for function ${funcNode.functionName}`, StatusCode.INTERNAL);
|
|
571
|
-
}
|
|
572
|
-
aggregateArgInstructions.push(emitCallFromPlan(arg, ctx));
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
return {
|
|
577
|
-
params: [sourceInstruction, ...groupByInstructions, ...aggregateArgInstructions],
|
|
578
|
-
run: run as InstructionRun,
|
|
579
|
-
note: `stream_aggregate(${plan.groupBy.length > 0 ? `GROUP BY ${plan.groupBy.length}` : 'no grouping'}, ${plan.aggregates.length} aggs)`
|
|
580
|
-
};
|
|
581
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { ArrayIndexNode } from '../../planner/nodes/array-index-node.js';
|
|
2
|
-
import type { Instruction, RuntimeContext } from '../types.js';
|
|
3
|
-
import type { EmissionContext } from '../emission-context.js';
|
|
4
|
-
import { quereusError } from '../../common/errors.js';
|
|
5
|
-
import { StatusCode, type OutputValue } from '../../common/types.js';
|
|
6
|
-
|
|
7
|
-
export function emitArrayIndex(plan: ArrayIndexNode, _ctx: EmissionContext): Instruction {
|
|
8
|
-
function run(ctx: RuntimeContext): OutputValue {
|
|
9
|
-
// Look through the context to find a row that has the index we need
|
|
10
|
-
for (const [_descriptor, rowGetter] of ctx.context.entries()) {
|
|
11
|
-
const row = rowGetter();
|
|
12
|
-
if (Array.isArray(row) && plan.index < row.length) {
|
|
13
|
-
return row[plan.index];
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
quereusError(`No row context found for array index ${plan.index}`, StatusCode.INTERNAL);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
params: [],
|
|
22
|
-
run: run,
|
|
23
|
-
note: `array[${plan.index}]`
|
|
24
|
-
};
|
|
25
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { SqlValue } from "../../common/types.js";
|
|
2
|
-
import type { Instruction, InstructionRun, RuntimeContext } from "../types.js";
|
|
3
|
-
import type { BetweenNode } from "../../planner/nodes/scalar.js";
|
|
4
|
-
import { emitPlanNode } from "../emitters.js";
|
|
5
|
-
import { compareSqlValuesFast, resolveCollation } from "../../util/comparison.js";
|
|
6
|
-
import { coerceForComparison } from "../../util/coercion.js";
|
|
7
|
-
import type { EmissionContext } from "../emission-context.js";
|
|
8
|
-
|
|
9
|
-
export function emitBetween(plan: BetweenNode, ctx: EmissionContext): Instruction {
|
|
10
|
-
// Pre-resolve collation function for optimal performance (using BINARY as default for BETWEEN)
|
|
11
|
-
const collationFunc = resolveCollation('BINARY');
|
|
12
|
-
|
|
13
|
-
function run(ctx: RuntimeContext, value: SqlValue, lowerBound: SqlValue, upperBound: SqlValue): SqlValue {
|
|
14
|
-
// SQL BETWEEN logic: value BETWEEN lower AND upper
|
|
15
|
-
// Equivalent to: value >= lower AND value <= upper
|
|
16
|
-
// NULL handling: if any operand is NULL, result is NULL
|
|
17
|
-
if (value === null || lowerBound === null || upperBound === null) {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Apply type coercion before comparison
|
|
22
|
-
const [coercedValue1, coercedLower] = coerceForComparison(value, lowerBound);
|
|
23
|
-
const [coercedValue2, coercedUpper] = coerceForComparison(value, upperBound);
|
|
24
|
-
|
|
25
|
-
// Use pre-resolved collation function for optimal performance
|
|
26
|
-
const lowerResult = compareSqlValuesFast(coercedValue1, coercedLower, collationFunc);
|
|
27
|
-
const upperResult = compareSqlValuesFast(coercedValue2, coercedUpper, collationFunc);
|
|
28
|
-
|
|
29
|
-
// value >= lowerBound AND value <= upperBound
|
|
30
|
-
const betweenResult = (lowerResult >= 0 && upperResult <= 0);
|
|
31
|
-
|
|
32
|
-
// Handle NOT BETWEEN
|
|
33
|
-
if (plan.expression.not) {
|
|
34
|
-
return !betweenResult;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return betweenResult;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const valueExpr = emitPlanNode(plan.expr, ctx);
|
|
41
|
-
const lowerExpr = emitPlanNode(plan.lower, ctx);
|
|
42
|
-
const upperExpr = emitPlanNode(plan.upper, ctx);
|
|
43
|
-
|
|
44
|
-
const notPrefix = plan.expression.not ? 'NOT ' : '';
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
params: [valueExpr, lowerExpr, upperExpr],
|
|
48
|
-
run: run as InstructionRun,
|
|
49
|
-
note: `${notPrefix}BETWEEN`
|
|
50
|
-
};
|
|
51
|
-
}
|