@quereus/quereus 4.6.0 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/src/common/errors.d.ts +17 -0
- package/dist/src/common/errors.d.ts.map +1 -1
- package/dist/src/common/errors.js +21 -0
- package/dist/src/common/errors.js.map +1 -1
- package/dist/src/common/types.d.ts +19 -0
- package/dist/src/common/types.d.ts.map +1 -1
- package/dist/src/common/types.js.map +1 -1
- package/dist/src/core/database-assertions.d.ts +4 -3
- package/dist/src/core/database-assertions.d.ts.map +1 -1
- package/dist/src/core/database-assertions.js +44 -14
- package/dist/src/core/database-assertions.js.map +1 -1
- package/dist/src/core/database-events.d.ts +62 -0
- package/dist/src/core/database-events.d.ts.map +1 -1
- package/dist/src/core/database-events.js +88 -2
- package/dist/src/core/database-events.js.map +1 -1
- package/dist/src/core/database-internal.d.ts +5 -2
- package/dist/src/core/database-internal.d.ts.map +1 -1
- package/dist/src/core/database-materialized-views-plan-builders.d.ts.map +1 -1
- package/dist/src/core/database-materialized-views-plan-builders.js +4 -2
- package/dist/src/core/database-materialized-views-plan-builders.js.map +1 -1
- package/dist/src/core/database-materialized-views-plans.d.ts +12 -2
- package/dist/src/core/database-materialized-views-plans.d.ts.map +1 -1
- package/dist/src/core/database-materialized-views.d.ts +46 -0
- package/dist/src/core/database-materialized-views.d.ts.map +1 -1
- package/dist/src/core/database-materialized-views.js +75 -4
- package/dist/src/core/database-materialized-views.js.map +1 -1
- package/dist/src/core/database.d.ts +48 -2
- package/dist/src/core/database.d.ts.map +1 -1
- package/dist/src/core/database.js +222 -11
- package/dist/src/core/database.js.map +1 -1
- package/dist/src/core/derived-row-validator.d.ts.map +1 -1
- package/dist/src/core/derived-row-validator.js +7 -1
- package/dist/src/core/derived-row-validator.js.map +1 -1
- package/dist/src/core/statement.d.ts.map +1 -1
- package/dist/src/core/statement.js +101 -5
- package/dist/src/core/statement.js.map +1 -1
- package/dist/src/emit/ast-stringify.d.ts +18 -2
- package/dist/src/emit/ast-stringify.d.ts.map +1 -1
- package/dist/src/emit/ast-stringify.js +22 -4
- package/dist/src/emit/ast-stringify.js.map +1 -1
- package/dist/src/func/builtins/explain.d.ts.map +1 -1
- package/dist/src/func/builtins/explain.js +19 -5
- package/dist/src/func/builtins/explain.js.map +1 -1
- package/dist/src/func/builtins/scalar.d.ts.map +1 -1
- package/dist/src/func/builtins/scalar.js +24 -20
- package/dist/src/func/builtins/scalar.js.map +1 -1
- package/dist/src/func/builtins/schema.d.ts.map +1 -1
- package/dist/src/func/builtins/schema.js +32 -5
- package/dist/src/func/builtins/schema.js.map +1 -1
- package/dist/src/index.d.ts +9 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +7 -5
- package/dist/src/index.js.map +1 -1
- package/dist/src/parser/ast.d.ts +58 -1
- package/dist/src/parser/ast.d.ts.map +1 -1
- package/dist/src/parser/parser.js +1 -1
- package/dist/src/parser/parser.js.map +1 -1
- package/dist/src/parser/utils.d.ts +13 -1
- package/dist/src/parser/utils.d.ts.map +1 -1
- package/dist/src/parser/utils.js +14 -0
- package/dist/src/parser/utils.js.map +1 -1
- package/dist/src/planner/analysis/assertion-classifier.d.ts.map +1 -1
- package/dist/src/planner/analysis/assertion-classifier.js +7 -2
- package/dist/src/planner/analysis/assertion-classifier.js.map +1 -1
- package/dist/src/planner/analysis/assertion-hoist-cache.d.ts.map +1 -1
- package/dist/src/planner/analysis/assertion-hoist-cache.js +5 -0
- package/dist/src/planner/analysis/assertion-hoist-cache.js.map +1 -1
- package/dist/src/planner/analysis/change-scope.d.ts +11 -3
- package/dist/src/planner/analysis/change-scope.d.ts.map +1 -1
- package/dist/src/planner/analysis/change-scope.js +5 -4
- package/dist/src/planner/analysis/change-scope.js.map +1 -1
- package/dist/src/planner/analysis/coverage-prover.d.ts.map +1 -1
- package/dist/src/planner/analysis/coverage-prover.js +13 -5
- package/dist/src/planner/analysis/coverage-prover.js.map +1 -1
- package/dist/src/planner/analysis/equi-correlation.d.ts +6 -1
- package/dist/src/planner/analysis/equi-correlation.d.ts.map +1 -1
- package/dist/src/planner/analysis/equi-correlation.js +8 -1
- package/dist/src/planner/analysis/equi-correlation.js.map +1 -1
- package/dist/src/planner/analysis/predicate-dependencies.d.ts +34 -0
- package/dist/src/planner/analysis/predicate-dependencies.d.ts.map +1 -0
- package/dist/src/planner/analysis/predicate-dependencies.js +60 -0
- package/dist/src/planner/analysis/predicate-dependencies.js.map +1 -0
- package/dist/src/planner/analysis/query-rewrite-matcher.d.ts +1 -1
- package/dist/src/planner/analysis/query-rewrite-matcher.d.ts.map +1 -1
- package/dist/src/planner/analysis/query-rewrite-matcher.js +0 -26
- package/dist/src/planner/analysis/query-rewrite-matcher.js.map +1 -1
- package/dist/src/planner/building/alter-table.d.ts.map +1 -1
- package/dist/src/planner/building/alter-table.js +53 -17
- package/dist/src/planner/building/alter-table.js.map +1 -1
- package/dist/src/planner/building/constraint-builder.d.ts.map +1 -1
- package/dist/src/planner/building/constraint-builder.js +9 -5
- package/dist/src/planner/building/constraint-builder.js.map +1 -1
- package/dist/src/planner/building/create-assertion.d.ts.map +1 -1
- package/dist/src/planner/building/create-assertion.js +72 -1
- package/dist/src/planner/building/create-assertion.js.map +1 -1
- package/dist/src/planner/building/create-view.d.ts +6 -1
- package/dist/src/planner/building/create-view.d.ts.map +1 -1
- package/dist/src/planner/building/create-view.js +12 -3
- package/dist/src/planner/building/create-view.js.map +1 -1
- package/dist/src/planner/building/ddl.d.ts.map +1 -1
- package/dist/src/planner/building/ddl.js +6 -2
- package/dist/src/planner/building/ddl.js.map +1 -1
- package/dist/src/planner/building/delete.d.ts.map +1 -1
- package/dist/src/planner/building/delete.js +23 -10
- package/dist/src/planner/building/delete.js.map +1 -1
- package/dist/src/planner/building/dml-target.d.ts.map +1 -1
- package/dist/src/planner/building/dml-target.js +4 -0
- package/dist/src/planner/building/dml-target.js.map +1 -1
- package/dist/src/planner/building/drop-assertion.d.ts.map +1 -1
- package/dist/src/planner/building/drop-assertion.js +3 -1
- package/dist/src/planner/building/drop-assertion.js.map +1 -1
- package/dist/src/planner/building/foreign-key-builder.d.ts.map +1 -1
- package/dist/src/planner/building/foreign-key-builder.js +7 -5
- package/dist/src/planner/building/foreign-key-builder.js.map +1 -1
- package/dist/src/planner/building/function-call.d.ts +35 -0
- package/dist/src/planner/building/function-call.d.ts.map +1 -1
- package/dist/src/planner/building/function-call.js +53 -40
- package/dist/src/planner/building/function-call.js.map +1 -1
- package/dist/src/planner/building/insert.d.ts.map +1 -1
- package/dist/src/planner/building/insert.js +185 -48
- package/dist/src/planner/building/insert.js.map +1 -1
- package/dist/src/planner/building/materialized-view.d.ts.map +1 -1
- package/dist/src/planner/building/materialized-view.js +3 -1
- package/dist/src/planner/building/materialized-view.js.map +1 -1
- package/dist/src/planner/building/schema-authored-context.d.ts +69 -0
- package/dist/src/planner/building/schema-authored-context.d.ts.map +1 -0
- package/dist/src/planner/building/schema-authored-context.js +75 -0
- package/dist/src/planner/building/schema-authored-context.js.map +1 -0
- package/dist/src/planner/building/schema-resolution.d.ts.map +1 -1
- package/dist/src/planner/building/schema-resolution.js +7 -4
- package/dist/src/planner/building/schema-resolution.js.map +1 -1
- package/dist/src/planner/building/select-aggregates.d.ts +187 -2
- package/dist/src/planner/building/select-aggregates.d.ts.map +1 -1
- package/dist/src/planner/building/select-aggregates.js +414 -81
- package/dist/src/planner/building/select-aggregates.js.map +1 -1
- package/dist/src/planner/building/select-compound.js +2 -2
- package/dist/src/planner/building/select-compound.js.map +1 -1
- package/dist/src/planner/building/select-context.d.ts +91 -0
- package/dist/src/planner/building/select-context.d.ts.map +1 -1
- package/dist/src/planner/building/select-context.js +113 -0
- package/dist/src/planner/building/select-context.js.map +1 -1
- package/dist/src/planner/building/select-modifiers.d.ts +10 -3
- package/dist/src/planner/building/select-modifiers.d.ts.map +1 -1
- package/dist/src/planner/building/select-modifiers.js +29 -8
- package/dist/src/planner/building/select-modifiers.js.map +1 -1
- package/dist/src/planner/building/select-ordinal.d.ts +64 -19
- package/dist/src/planner/building/select-ordinal.d.ts.map +1 -1
- package/dist/src/planner/building/select-ordinal.js +79 -30
- package/dist/src/planner/building/select-ordinal.js.map +1 -1
- package/dist/src/planner/building/select-projections.d.ts +1 -1
- package/dist/src/planner/building/select-projections.d.ts.map +1 -1
- package/dist/src/planner/building/select-projections.js +18 -11
- package/dist/src/planner/building/select-projections.js.map +1 -1
- package/dist/src/planner/building/select-window.d.ts +13 -3
- package/dist/src/planner/building/select-window.d.ts.map +1 -1
- package/dist/src/planner/building/select-window.js +142 -37
- package/dist/src/planner/building/select-window.js.map +1 -1
- package/dist/src/planner/building/select.d.ts.map +1 -1
- package/dist/src/planner/building/select.js +129 -59
- package/dist/src/planner/building/select.js.map +1 -1
- package/dist/src/planner/building/update.d.ts.map +1 -1
- package/dist/src/planner/building/update.js +27 -13
- package/dist/src/planner/building/update.js.map +1 -1
- package/dist/src/planner/building/view-mutation-builder.d.ts +1 -1
- package/dist/src/planner/building/view-mutation-builder.d.ts.map +1 -1
- package/dist/src/planner/building/view-mutation-builder.js +102 -8
- package/dist/src/planner/building/view-mutation-builder.js.map +1 -1
- package/dist/src/planner/building/with.d.ts.map +1 -1
- package/dist/src/planner/building/with.js +34 -4
- package/dist/src/planner/building/with.js.map +1 -1
- package/dist/src/planner/cache/correlation-detector.d.ts +15 -0
- package/dist/src/planner/cache/correlation-detector.d.ts.map +1 -1
- package/dist/src/planner/cache/correlation-detector.js +26 -0
- package/dist/src/planner/cache/correlation-detector.js.map +1 -1
- package/dist/src/planner/cache/materialization-advisory.d.ts +7 -0
- package/dist/src/planner/cache/materialization-advisory.d.ts.map +1 -1
- package/dist/src/planner/cache/materialization-advisory.js +12 -3
- package/dist/src/planner/cache/materialization-advisory.js.map +1 -1
- package/dist/src/planner/framework/characteristics.d.ts +9 -0
- package/dist/src/planner/framework/characteristics.d.ts.map +1 -1
- package/dist/src/planner/framework/characteristics.js.map +1 -1
- package/dist/src/planner/framework/pass.d.ts +2 -0
- package/dist/src/planner/framework/pass.d.ts.map +1 -1
- package/dist/src/planner/framework/pass.js +15 -0
- package/dist/src/planner/framework/pass.js.map +1 -1
- package/dist/src/planner/mutation/backward-body.d.ts.map +1 -1
- package/dist/src/planner/mutation/backward-body.js +4 -1
- package/dist/src/planner/mutation/backward-body.js.map +1 -1
- package/dist/src/planner/mutation/body-context.d.ts +23 -0
- package/dist/src/planner/mutation/body-context.d.ts.map +1 -0
- package/dist/src/planner/mutation/body-context.js +26 -0
- package/dist/src/planner/mutation/body-context.js.map +1 -0
- package/dist/src/planner/mutation/cte-flatten.js +15 -2
- package/dist/src/planner/mutation/cte-flatten.js.map +1 -1
- package/dist/src/planner/mutation/decomposition.d.ts +8 -0
- package/dist/src/planner/mutation/decomposition.d.ts.map +1 -1
- package/dist/src/planner/mutation/decomposition.js +8 -3
- package/dist/src/planner/mutation/decomposition.js.map +1 -1
- package/dist/src/planner/mutation/lens-enforcement.js +1 -1
- package/dist/src/planner/mutation/multi-source.d.ts +7 -0
- package/dist/src/planner/mutation/multi-source.d.ts.map +1 -1
- package/dist/src/planner/mutation/multi-source.js +5 -0
- package/dist/src/planner/mutation/multi-source.js.map +1 -1
- package/dist/src/planner/mutation/mutation-diagnostic.d.ts +1 -1
- package/dist/src/planner/mutation/mutation-diagnostic.d.ts.map +1 -1
- package/dist/src/planner/mutation/mutation-diagnostic.js.map +1 -1
- package/dist/src/planner/mutation/scope-transform.d.ts +32 -0
- package/dist/src/planner/mutation/scope-transform.d.ts.map +1 -1
- package/dist/src/planner/mutation/scope-transform.js +181 -33
- package/dist/src/planner/mutation/scope-transform.js.map +1 -1
- package/dist/src/planner/mutation/set-op.d.ts.map +1 -1
- package/dist/src/planner/mutation/set-op.js +66 -16
- package/dist/src/planner/mutation/set-op.js.map +1 -1
- package/dist/src/planner/mutation/single-source.d.ts.map +1 -1
- package/dist/src/planner/mutation/single-source.js +100 -24
- package/dist/src/planner/mutation/single-source.js.map +1 -1
- package/dist/src/planner/nodes/add-constraint-node.d.ts +15 -1
- package/dist/src/planner/nodes/add-constraint-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/add-constraint-node.js +10 -1
- package/dist/src/planner/nodes/add-constraint-node.js.map +1 -1
- package/dist/src/planner/nodes/aggregate-node.d.ts +14 -5
- package/dist/src/planner/nodes/aggregate-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/aggregate-node.js +28 -21
- package/dist/src/planner/nodes/aggregate-node.js.map +1 -1
- package/dist/src/planner/nodes/alter-table-node.d.ts +27 -2
- package/dist/src/planner/nodes/alter-table-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/alter-table-node.js +49 -2
- package/dist/src/planner/nodes/alter-table-node.js.map +1 -1
- package/dist/src/planner/nodes/constraint-check-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/constraint-check-node.js +17 -19
- package/dist/src/planner/nodes/constraint-check-node.js.map +1 -1
- package/dist/src/planner/nodes/create-assertion-node.d.ts +2 -1
- package/dist/src/planner/nodes/create-assertion-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/create-assertion-node.js +5 -2
- package/dist/src/planner/nodes/create-assertion-node.js.map +1 -1
- package/dist/src/planner/nodes/cte-node.d.ts +19 -9
- package/dist/src/planner/nodes/cte-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/cte-node.js +25 -9
- package/dist/src/planner/nodes/cte-node.js.map +1 -1
- package/dist/src/planner/nodes/delete-node.d.ts +20 -2
- package/dist/src/planner/nodes/delete-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/delete-node.js +11 -2
- package/dist/src/planner/nodes/delete-node.js.map +1 -1
- package/dist/src/planner/nodes/dml-executor-node.d.ts +58 -1
- package/dist/src/planner/nodes/dml-executor-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/dml-executor-node.js +107 -15
- package/dist/src/planner/nodes/dml-executor-node.js.map +1 -1
- package/dist/src/planner/nodes/drop-assertion-node.d.ts +2 -1
- package/dist/src/planner/nodes/drop-assertion-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/drop-assertion-node.js +5 -2
- package/dist/src/planner/nodes/drop-assertion-node.js.map +1 -1
- package/dist/src/planner/nodes/filter.d.ts.map +1 -1
- package/dist/src/planner/nodes/filter.js +12 -6
- package/dist/src/planner/nodes/filter.js.map +1 -1
- package/dist/src/planner/nodes/hash-aggregate.d.ts +0 -5
- package/dist/src/planner/nodes/hash-aggregate.d.ts.map +1 -1
- package/dist/src/planner/nodes/hash-aggregate.js +17 -20
- package/dist/src/planner/nodes/hash-aggregate.js.map +1 -1
- package/dist/src/planner/nodes/insert-node.d.ts +19 -2
- package/dist/src/planner/nodes/insert-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/insert-node.js +10 -2
- package/dist/src/planner/nodes/insert-node.js.map +1 -1
- package/dist/src/planner/nodes/key-set-semi-join-node.d.ts +42 -10
- package/dist/src/planner/nodes/key-set-semi-join-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/key-set-semi-join-node.js +85 -16
- package/dist/src/planner/nodes/key-set-semi-join-node.js.map +1 -1
- package/dist/src/planner/nodes/lens-auxiliary-access-node.d.ts +5 -0
- package/dist/src/planner/nodes/lens-auxiliary-access-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/lens-auxiliary-access-node.js.map +1 -1
- package/dist/src/planner/nodes/plan-node.d.ts +5 -0
- package/dist/src/planner/nodes/plan-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/plan-node.js +12 -0
- package/dist/src/planner/nodes/plan-node.js.map +1 -1
- package/dist/src/planner/nodes/project-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/project-node.js +16 -35
- package/dist/src/planner/nodes/project-node.js.map +1 -1
- package/dist/src/planner/nodes/retrieve-node.d.ts +16 -2
- package/dist/src/planner/nodes/retrieve-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/retrieve-node.js +8 -1
- package/dist/src/planner/nodes/retrieve-node.js.map +1 -1
- package/dist/src/planner/nodes/returning-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/returning-node.js +13 -32
- package/dist/src/planner/nodes/returning-node.js.map +1 -1
- package/dist/src/planner/nodes/stream-aggregate.d.ts +0 -5
- package/dist/src/planner/nodes/stream-aggregate.d.ts.map +1 -1
- package/dist/src/planner/nodes/stream-aggregate.js +18 -24
- package/dist/src/planner/nodes/stream-aggregate.js.map +1 -1
- package/dist/src/planner/nodes/table-access-nodes.d.ts +89 -1
- package/dist/src/planner/nodes/table-access-nodes.d.ts.map +1 -1
- package/dist/src/planner/nodes/table-access-nodes.js +64 -2
- package/dist/src/planner/nodes/table-access-nodes.js.map +1 -1
- package/dist/src/planner/nodes/update-node.d.ts +19 -2
- package/dist/src/planner/nodes/update-node.d.ts.map +1 -1
- package/dist/src/planner/nodes/update-node.js +10 -2
- package/dist/src/planner/nodes/update-node.js.map +1 -1
- package/dist/src/planner/optimizer.d.ts +18 -0
- package/dist/src/planner/optimizer.d.ts.map +1 -1
- package/dist/src/planner/optimizer.js +59 -10
- package/dist/src/planner/optimizer.js.map +1 -1
- package/dist/src/planner/planning-context.d.ts +24 -0
- package/dist/src/planner/planning-context.d.ts.map +1 -1
- package/dist/src/planner/planning-context.js.map +1 -1
- package/dist/src/planner/rules/access/rule-key-set-seek.d.ts +78 -20
- package/dist/src/planner/rules/access/rule-key-set-seek.d.ts.map +1 -1
- package/dist/src/planner/rules/access/rule-key-set-seek.js +297 -71
- package/dist/src/planner/rules/access/rule-key-set-seek.js.map +1 -1
- package/dist/src/planner/rules/access/rule-monotonic-range-access.d.ts.map +1 -1
- package/dist/src/planner/rules/access/rule-monotonic-range-access.js +2 -2
- package/dist/src/planner/rules/access/rule-monotonic-range-access.js.map +1 -1
- package/dist/src/planner/rules/access/rule-select-access-path.d.ts +11 -1
- package/dist/src/planner/rules/access/rule-select-access-path.d.ts.map +1 -1
- package/dist/src/planner/rules/access/rule-select-access-path.js +46 -2
- package/dist/src/planner/rules/access/rule-select-access-path.js.map +1 -1
- package/dist/src/planner/rules/aggregate/rule-groupby-fd-simplification.d.ts +7 -4
- package/dist/src/planner/rules/aggregate/rule-groupby-fd-simplification.d.ts.map +1 -1
- package/dist/src/planner/rules/aggregate/rule-groupby-fd-simplification.js +39 -5
- package/dist/src/planner/rules/aggregate/rule-groupby-fd-simplification.js.map +1 -1
- package/dist/src/planner/rules/cache/rule-cte-optimization.d.ts.map +1 -1
- package/dist/src/planner/rules/cache/rule-cte-optimization.js +6 -2
- package/dist/src/planner/rules/cache/rule-cte-optimization.js.map +1 -1
- package/dist/src/planner/rules/cache/rule-materialized-view-rewrite.js +10 -3
- package/dist/src/planner/rules/cache/rule-materialized-view-rewrite.js.map +1 -1
- package/dist/src/planner/rules/join/index-nested-loop.d.ts.map +1 -1
- package/dist/src/planner/rules/join/index-nested-loop.js +13 -7
- package/dist/src/planner/rules/join/index-nested-loop.js.map +1 -1
- package/dist/src/planner/rules/join/rule-fanout-lookup-join.d.ts +4 -0
- package/dist/src/planner/rules/join/rule-fanout-lookup-join.d.ts.map +1 -1
- package/dist/src/planner/rules/join/rule-fanout-lookup-join.js +50 -15
- package/dist/src/planner/rules/join/rule-fanout-lookup-join.js.map +1 -1
- package/dist/src/planner/rules/join/rule-join-elimination.d.ts +6 -0
- package/dist/src/planner/rules/join/rule-join-elimination.d.ts.map +1 -1
- package/dist/src/planner/rules/join/rule-join-elimination.js +25 -9
- package/dist/src/planner/rules/join/rule-join-elimination.js.map +1 -1
- package/dist/src/planner/rules/join/rule-join-key-inference.d.ts +7 -0
- package/dist/src/planner/rules/join/rule-join-key-inference.d.ts.map +1 -1
- package/dist/src/planner/rules/join/rule-join-key-inference.js +23 -11
- package/dist/src/planner/rules/join/rule-join-key-inference.js.map +1 -1
- package/dist/src/planner/rules/join/rule-join-physical-selection.d.ts +2 -2
- package/dist/src/planner/rules/join/rule-join-physical-selection.d.ts.map +1 -1
- package/dist/src/planner/rules/join/rule-join-physical-selection.js +46 -16
- package/dist/src/planner/rules/join/rule-join-physical-selection.js.map +1 -1
- package/dist/src/planner/rules/join/rule-monotonic-merge-join.d.ts +2 -0
- package/dist/src/planner/rules/join/rule-monotonic-merge-join.d.ts.map +1 -1
- package/dist/src/planner/rules/join/rule-monotonic-merge-join.js +14 -0
- package/dist/src/planner/rules/join/rule-monotonic-merge-join.js.map +1 -1
- package/dist/src/planner/rules/predicate/rule-aggregate-predicate-pushdown.d.ts +2 -2
- package/dist/src/planner/rules/predicate/rule-aggregate-predicate-pushdown.d.ts.map +1 -1
- package/dist/src/planner/rules/predicate/rule-aggregate-predicate-pushdown.js +19 -22
- package/dist/src/planner/rules/predicate/rule-aggregate-predicate-pushdown.js.map +1 -1
- package/dist/src/planner/rules/predicate/rule-filter-selectivity.d.ts +33 -19
- package/dist/src/planner/rules/predicate/rule-filter-selectivity.d.ts.map +1 -1
- package/dist/src/planner/rules/predicate/rule-filter-selectivity.js +37 -18
- package/dist/src/planner/rules/predicate/rule-filter-selectivity.js.map +1 -1
- package/dist/src/planner/rules/predicate/rule-join-predicate-pushdown.d.ts +6 -3
- package/dist/src/planner/rules/predicate/rule-join-predicate-pushdown.d.ts.map +1 -1
- package/dist/src/planner/rules/predicate/rule-join-predicate-pushdown.js +6 -3
- package/dist/src/planner/rules/predicate/rule-join-predicate-pushdown.js.map +1 -1
- package/dist/src/planner/rules/predicate/rule-predicate-pushdown.d.ts.map +1 -1
- package/dist/src/planner/rules/predicate/rule-predicate-pushdown.js +11 -21
- package/dist/src/planner/rules/predicate/rule-predicate-pushdown.js.map +1 -1
- package/dist/src/planner/rules/shared/access-leaf.d.ts +16 -3
- package/dist/src/planner/rules/shared/access-leaf.d.ts.map +1 -1
- package/dist/src/planner/rules/shared/access-leaf.js +21 -5
- package/dist/src/planner/rules/shared/access-leaf.js.map +1 -1
- package/dist/src/planner/rules/subquery/rule-anti-join-fk-empty.js +1 -1
- package/dist/src/planner/rules/subquery/rule-anti-join-fk-empty.js.map +1 -1
- package/dist/src/planner/rules/subquery/rule-semi-join-fk-trivial.js +1 -1
- package/dist/src/planner/rules/subquery/rule-semi-join-fk-trivial.js.map +1 -1
- package/dist/src/planner/stored-body-context.d.ts +57 -0
- package/dist/src/planner/stored-body-context.d.ts.map +1 -0
- package/dist/src/planner/stored-body-context.js +64 -0
- package/dist/src/planner/stored-body-context.js.map +1 -0
- package/dist/src/planner/util/ind-utils.d.ts +28 -20
- package/dist/src/planner/util/ind-utils.d.ts.map +1 -1
- package/dist/src/planner/util/ind-utils.js +36 -27
- package/dist/src/planner/util/ind-utils.js.map +1 -1
- package/dist/src/planner/util/key-utils.d.ts +19 -4
- package/dist/src/planner/util/key-utils.d.ts.map +1 -1
- package/dist/src/planner/util/key-utils.js +23 -7
- package/dist/src/planner/util/key-utils.js.map +1 -1
- package/dist/src/planner/util/output-names.d.ts +12 -0
- package/dist/src/planner/util/output-names.d.ts.map +1 -0
- package/dist/src/planner/util/output-names.js +20 -0
- package/dist/src/planner/util/output-names.js.map +1 -0
- package/dist/src/planner/util/row-estimates.d.ts +11 -0
- package/dist/src/planner/util/row-estimates.d.ts.map +1 -1
- package/dist/src/planner/util/row-estimates.js +28 -0
- package/dist/src/planner/util/row-estimates.js.map +1 -1
- package/dist/src/runtime/deferred-constraint-queue.d.ts.map +1 -1
- package/dist/src/runtime/deferred-constraint-queue.js +3 -2
- package/dist/src/runtime/deferred-constraint-queue.js.map +1 -1
- package/dist/src/runtime/emit/add-constraint.d.ts.map +1 -1
- package/dist/src/runtime/emit/add-constraint.js +22 -6
- package/dist/src/runtime/emit/add-constraint.js.map +1 -1
- package/dist/src/runtime/emit/alter-schema-event.d.ts +59 -4
- package/dist/src/runtime/emit/alter-schema-event.d.ts.map +1 -1
- package/dist/src/runtime/emit/alter-schema-event.js +63 -4
- package/dist/src/runtime/emit/alter-schema-event.js.map +1 -1
- package/dist/src/runtime/emit/alter-table.d.ts.map +1 -1
- package/dist/src/runtime/emit/alter-table.js +212 -92
- package/dist/src/runtime/emit/alter-table.js.map +1 -1
- package/dist/src/runtime/emit/analyze.d.ts.map +1 -1
- package/dist/src/runtime/emit/analyze.js +15 -4
- package/dist/src/runtime/emit/analyze.js.map +1 -1
- package/dist/src/runtime/emit/assertion-drop-guard.d.ts +37 -0
- package/dist/src/runtime/emit/assertion-drop-guard.d.ts.map +1 -0
- package/dist/src/runtime/emit/assertion-drop-guard.js +59 -0
- package/dist/src/runtime/emit/assertion-drop-guard.js.map +1 -0
- package/dist/src/runtime/emit/assertion-rename-helpers.d.ts +33 -0
- package/dist/src/runtime/emit/assertion-rename-helpers.d.ts.map +1 -0
- package/dist/src/runtime/emit/assertion-rename-helpers.js +124 -0
- package/dist/src/runtime/emit/assertion-rename-helpers.js.map +1 -0
- package/dist/src/runtime/emit/constraint-check.d.ts.map +1 -1
- package/dist/src/runtime/emit/constraint-check.js +10 -227
- package/dist/src/runtime/emit/constraint-check.js.map +1 -1
- package/dist/src/runtime/emit/create-assertion.d.ts.map +1 -1
- package/dist/src/runtime/emit/create-assertion.js +31 -14
- package/dist/src/runtime/emit/create-assertion.js.map +1 -1
- package/dist/src/runtime/emit/cte.d.ts.map +1 -1
- package/dist/src/runtime/emit/cte.js +11 -6
- package/dist/src/runtime/emit/cte.js.map +1 -1
- package/dist/src/runtime/emit/dml-executor.d.ts.map +1 -1
- package/dist/src/runtime/emit/dml-executor.js +169 -1
- package/dist/src/runtime/emit/dml-executor.js.map +1 -1
- package/dist/src/runtime/emit/drop-assertion.js +8 -8
- package/dist/src/runtime/emit/drop-assertion.js.map +1 -1
- package/dist/src/runtime/emit/drop-column-guards.d.ts +151 -0
- package/dist/src/runtime/emit/drop-column-guards.d.ts.map +1 -0
- package/dist/src/runtime/emit/drop-column-guards.js +230 -0
- package/dist/src/runtime/emit/drop-column-guards.js.map +1 -0
- package/dist/src/runtime/emit/drop-table.d.ts.map +1 -1
- package/dist/src/runtime/emit/drop-table.js +6 -0
- package/dist/src/runtime/emit/drop-table.js.map +1 -1
- package/dist/src/runtime/emit/drop-view.d.ts.map +1 -1
- package/dist/src/runtime/emit/drop-view.js +4 -0
- package/dist/src/runtime/emit/drop-view.js.map +1 -1
- package/dist/src/runtime/emit/key-set-semi-join.d.ts.map +1 -1
- package/dist/src/runtime/emit/key-set-semi-join.js +5 -3
- package/dist/src/runtime/emit/key-set-semi-join.js.map +1 -1
- package/dist/src/runtime/emit/materialized-view-helpers.d.ts +4 -4
- package/dist/src/runtime/emit/materialized-view-helpers.d.ts.map +1 -1
- package/dist/src/runtime/emit/materialized-view-helpers.js +34 -22
- package/dist/src/runtime/emit/materialized-view-helpers.js.map +1 -1
- package/dist/src/runtime/emit/materialized-view.d.ts.map +1 -1
- package/dist/src/runtime/emit/materialized-view.js +7 -2
- package/dist/src/runtime/emit/materialized-view.js.map +1 -1
- package/dist/src/runtime/emit/recursive-cte.d.ts.map +1 -1
- package/dist/src/runtime/emit/recursive-cte.js +4 -5
- package/dist/src/runtime/emit/recursive-cte.js.map +1 -1
- package/dist/src/runtime/emit/remote-query.d.ts.map +1 -1
- package/dist/src/runtime/emit/remote-query.js +8 -3
- package/dist/src/runtime/emit/remote-query.js.map +1 -1
- package/dist/src/runtime/emit/scan.d.ts.map +1 -1
- package/dist/src/runtime/emit/scan.js +4 -1
- package/dist/src/runtime/emit/scan.js.map +1 -1
- package/dist/src/runtime/emit/schema-declarative.js +2 -2
- package/dist/src/runtime/emit/schema-declarative.js.map +1 -1
- package/dist/src/runtime/emit/update.d.ts.map +1 -1
- package/dist/src/runtime/emit/update.js +18 -6
- package/dist/src/runtime/emit/update.js.map +1 -1
- package/dist/src/runtime/parallel-driver.d.ts +4 -3
- package/dist/src/runtime/parallel-driver.d.ts.map +1 -1
- package/dist/src/runtime/parallel-driver.js +8 -3
- package/dist/src/runtime/parallel-driver.js.map +1 -1
- package/dist/src/runtime/row-constraints.d.ts +85 -0
- package/dist/src/runtime/row-constraints.d.ts.map +1 -0
- package/dist/src/runtime/row-constraints.js +239 -0
- package/dist/src/runtime/row-constraints.js.map +1 -0
- package/dist/src/runtime/types.d.ts +18 -11
- package/dist/src/runtime/types.d.ts.map +1 -1
- package/dist/src/runtime/types.js.map +1 -1
- package/dist/src/runtime/utils.d.ts.map +1 -1
- package/dist/src/runtime/utils.js +11 -0
- package/dist/src/runtime/utils.js.map +1 -1
- package/dist/src/schema/assertion.d.ts +14 -1
- package/dist/src/schema/assertion.d.ts.map +1 -1
- package/dist/src/schema/assertion.js +14 -1
- package/dist/src/schema/assertion.js.map +1 -1
- package/dist/src/schema/catalog-persistability.js +19 -3
- package/dist/src/schema/catalog-persistability.js.map +1 -1
- package/dist/src/schema/catalog.d.ts +6 -0
- package/dist/src/schema/catalog.d.ts.map +1 -1
- package/dist/src/schema/catalog.js +26 -36
- package/dist/src/schema/catalog.js.map +1 -1
- package/dist/src/schema/column-source-resolver.d.ts +18 -0
- package/dist/src/schema/column-source-resolver.d.ts.map +1 -0
- package/dist/src/schema/column-source-resolver.js +22 -0
- package/dist/src/schema/column-source-resolver.js.map +1 -0
- package/dist/src/schema/constraint-builder.d.ts.map +1 -1
- package/dist/src/schema/constraint-builder.js +7 -1
- package/dist/src/schema/constraint-builder.js.map +1 -1
- package/dist/src/schema/ddl-generator.js +8 -0
- package/dist/src/schema/ddl-generator.js.map +1 -1
- package/dist/src/schema/lens-compiler.d.ts.map +1 -1
- package/dist/src/schema/lens-compiler.js +203 -51
- package/dist/src/schema/lens-compiler.js.map +1 -1
- package/dist/src/schema/lens-prover.d.ts +2 -3
- package/dist/src/schema/lens-prover.d.ts.map +1 -1
- package/dist/src/schema/lens-prover.js +19 -11
- package/dist/src/schema/lens-prover.js.map +1 -1
- package/dist/src/schema/manager.d.ts +30 -12
- package/dist/src/schema/manager.d.ts.map +1 -1
- package/dist/src/schema/manager.js +49 -17
- package/dist/src/schema/manager.js.map +1 -1
- package/dist/src/schema/rename-rewriter.d.ts +142 -0
- package/dist/src/schema/rename-rewriter.d.ts.map +1 -1
- package/dist/src/schema/rename-rewriter.js +254 -9
- package/dist/src/schema/rename-rewriter.js.map +1 -1
- package/dist/src/schema/reserved-tags.d.ts +1 -1
- package/dist/src/schema/reserved-tags.d.ts.map +1 -1
- package/dist/src/schema/reserved-tags.js +4 -3
- package/dist/src/schema/reserved-tags.js.map +1 -1
- package/dist/src/schema/schema-differ.d.ts +16 -0
- package/dist/src/schema/schema-differ.d.ts.map +1 -1
- package/dist/src/schema/schema-differ.js +122 -11
- package/dist/src/schema/schema-differ.js.map +1 -1
- package/dist/src/schema/view.d.ts +11 -0
- package/dist/src/schema/view.d.ts.map +1 -1
- package/dist/src/schema/view.js +12 -0
- package/dist/src/schema/view.js.map +1 -1
- package/dist/src/types/builtin-types.d.ts +38 -0
- package/dist/src/types/builtin-types.d.ts.map +1 -1
- package/dist/src/types/builtin-types.js +77 -26
- package/dist/src/types/builtin-types.js.map +1 -1
- package/dist/src/types/index.d.ts +1 -1
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/types/index.js +1 -1
- package/dist/src/types/index.js.map +1 -1
- package/dist/src/util/abort-signal.d.ts +25 -0
- package/dist/src/util/abort-signal.d.ts.map +1 -0
- package/dist/src/util/abort-signal.js +40 -0
- package/dist/src/util/abort-signal.js.map +1 -0
- package/dist/src/util/{working-table-iterable.d.ts → array-row-iterable.d.ts} +6 -6
- package/dist/src/util/array-row-iterable.d.ts.map +1 -0
- package/dist/src/util/{working-table-iterable.js → array-row-iterable.js} +6 -6
- package/dist/src/util/array-row-iterable.js.map +1 -0
- package/dist/src/vtab/concurrency.d.ts +15 -0
- package/dist/src/vtab/concurrency.d.ts.map +1 -1
- package/dist/src/vtab/concurrency.js +17 -0
- package/dist/src/vtab/concurrency.js.map +1 -1
- package/dist/src/vtab/events.d.ts +3 -0
- package/dist/src/vtab/events.d.ts.map +1 -1
- package/dist/src/vtab/events.js.map +1 -1
- package/dist/src/vtab/manifest.d.ts +15 -0
- package/dist/src/vtab/manifest.d.ts.map +1 -1
- package/dist/src/vtab/memory/layer/base.d.ts +10 -0
- package/dist/src/vtab/memory/layer/base.d.ts.map +1 -1
- package/dist/src/vtab/memory/layer/base.js +10 -0
- package/dist/src/vtab/memory/layer/base.js.map +1 -1
- package/dist/src/vtab/memory/layer/interface.d.ts +24 -0
- package/dist/src/vtab/memory/layer/interface.d.ts.map +1 -1
- package/dist/src/vtab/memory/layer/manager.d.ts +21 -3
- package/dist/src/vtab/memory/layer/manager.d.ts.map +1 -1
- package/dist/src/vtab/memory/layer/manager.js +107 -157
- package/dist/src/vtab/memory/layer/manager.js.map +1 -1
- package/dist/src/vtab/memory/layer/transaction.d.ts +11 -0
- package/dist/src/vtab/memory/layer/transaction.d.ts.map +1 -1
- package/dist/src/vtab/memory/layer/transaction.js +19 -0
- package/dist/src/vtab/memory/layer/transaction.js.map +1 -1
- package/dist/src/vtab/memory/module.d.ts +57 -1
- package/dist/src/vtab/memory/module.d.ts.map +1 -1
- package/dist/src/vtab/memory/module.js +103 -2
- package/dist/src/vtab/memory/module.js.map +1 -1
- package/dist/src/vtab/memory/table.d.ts +12 -1
- package/dist/src/vtab/memory/table.d.ts.map +1 -1
- package/dist/src/vtab/memory/table.js +12 -1
- package/dist/src/vtab/memory/table.js.map +1 -1
- package/dist/src/vtab/module.d.ts +59 -2
- package/dist/src/vtab/module.d.ts.map +1 -1
- package/dist/src/vtab/table.d.ts +8 -1
- package/dist/src/vtab/table.d.ts.map +1 -1
- package/dist/src/vtab/table.js.map +1 -1
- package/dist/src/vtab/test-support/commit-stall.d.ts +53 -0
- package/dist/src/vtab/test-support/commit-stall.d.ts.map +1 -0
- package/dist/src/vtab/test-support/commit-stall.js +73 -0
- package/dist/src/vtab/test-support/commit-stall.js.map +1 -0
- package/dist/src/vtab/test-support/committed-read-conformance.d.ts +96 -0
- package/dist/src/vtab/test-support/committed-read-conformance.d.ts.map +1 -0
- package/dist/src/vtab/test-support/committed-read-conformance.js +364 -0
- package/dist/src/vtab/test-support/committed-read-conformance.js.map +1 -0
- package/package.json +3 -3
- package/dist/src/util/working-table-iterable.d.ts.map +0 -1
- package/dist/src/util/working-table-iterable.js.map +0 -1
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { buildAssertionViolationSql } from '../../schema/assertion.js';
|
|
2
|
+
import { renameTableInAst, renameColumnInAst } from '../../schema/rename-rewriter.js';
|
|
3
|
+
import { createLogger } from '../../common/logger.js';
|
|
4
|
+
const log = createLogger('runtime:emit:assertion-rename');
|
|
5
|
+
// NOTE: both passes walk only the renamed object's OWN schema — the same scope the
|
|
6
|
+
// plain-view and materialized-view loops in `alter-table.ts` use. An assertion's
|
|
7
|
+
// stored body resolves unqualified table names against the assertion's own schema
|
|
8
|
+
// first (`Database._homeSchemaPath`), so an unqualified `t` inside an assertion
|
|
9
|
+
// living in some other schema does not necessarily mean the renamed table, and
|
|
10
|
+
// rewriting it would be a false positive. The converse gap — an assertion that names
|
|
11
|
+
// the renamed table with an explicit `<other schema>.<table>` qualifier is NOT
|
|
12
|
+
// rewritten — is real, and shared verbatim with views and materialized views; it is
|
|
13
|
+
// tracked by `bug-rename-not-propagated-across-schemas`, which fixes all three object
|
|
14
|
+
// kinds with one "explicitly-qualified references only" rewriter mode.
|
|
15
|
+
/**
|
|
16
|
+
* Rewrites every assertion in `schema` after a source TABLE RENAME — the assertion
|
|
17
|
+
* mirror of the plain-view loop in `propagateTableRenameInSchema` (same same-schema
|
|
18
|
+
* gate at the caller, same in-place `renameTableInAst` walk over a body that owns its
|
|
19
|
+
* own FROM scopes).
|
|
20
|
+
*
|
|
21
|
+
* On a changed body the derived `violationSql` is regenerated from the rewritten
|
|
22
|
+
* expression (the commit-time evaluator re-parses that text, so it is the field that
|
|
23
|
+
* actually carries the rename into enforcement), `dependentTables` is string-mapped
|
|
24
|
+
* old base → new base, and the record is re-registered through
|
|
25
|
+
* {@link Database.schemaManager} so `assertion_modified` fires — which is what
|
|
26
|
+
* invalidates the optimizer's assertion-hoist cache.
|
|
27
|
+
*/
|
|
28
|
+
export function propagateTableRenameToAssertions(db, schema, renamedSchemaName, oldName, newName) {
|
|
29
|
+
const schemaLower = renamedSchemaName.toLowerCase();
|
|
30
|
+
const oldBase = `${schemaLower}.${oldName.toLowerCase()}`;
|
|
31
|
+
const newBase = `${schemaLower}.${newName.toLowerCase()}`;
|
|
32
|
+
for (const assertion of Array.from(schema.getAllAssertions())) {
|
|
33
|
+
const check = assertion.checkExpression;
|
|
34
|
+
if (!check)
|
|
35
|
+
continue;
|
|
36
|
+
if (!renameTableInAst(check, oldName, newName, renamedSchemaName))
|
|
37
|
+
continue;
|
|
38
|
+
reregisterRewrittenAssertion(db, schema, assertion, check, remapDependentTables(assertion.dependentTables, oldBase, newBase));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Rewrites every assertion in `schema` after a source COLUMN RENAME — the assertion
|
|
43
|
+
* mirror of the plain-view loop in `propagateColumnRenameInSchema`.
|
|
44
|
+
*
|
|
45
|
+
* `renameColumnInAst` (unseeded) is the correct entry point, not
|
|
46
|
+
* `renameColumnInCheckExpression`: an assertion body is a full expression that owns
|
|
47
|
+
* its own FROM scopes (`not exists (select … from t …)`), so there is no implicit
|
|
48
|
+
* binding to an owning table to seed. `resolveColumnInSource` keeps that scope walk
|
|
49
|
+
* catalog-aware for the same reason the view-body loop threads it — an unqualified
|
|
50
|
+
* ref binding to a like-named column on an inner subquery's own FROM must not be
|
|
51
|
+
* false-captured.
|
|
52
|
+
*
|
|
53
|
+
* `dependentTables` is keyed by base table, so a column rename leaves it untouched.
|
|
54
|
+
*/
|
|
55
|
+
export function propagateColumnRenameToAssertions(db, schema, renamedSchemaName, tableName, oldCol, newCol, resolveColumnInSource) {
|
|
56
|
+
for (const assertion of Array.from(schema.getAllAssertions())) {
|
|
57
|
+
const check = assertion.checkExpression;
|
|
58
|
+
if (!check)
|
|
59
|
+
continue;
|
|
60
|
+
if (!renameColumnInAst(check, tableName, oldCol, newCol, renamedSchemaName, resolveColumnInSource))
|
|
61
|
+
continue;
|
|
62
|
+
reregisterRewrittenAssertion(db, schema, assertion, check, assertion.dependentTables);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Swaps the rewritten assertion into the catalog. The CHECK expression AST was
|
|
67
|
+
* already mutated in place by the caller's walker, mirroring how the view loop
|
|
68
|
+
* treats `selectAst` — `oldObject` on the emitted event therefore shares the
|
|
69
|
+
* rewritten AST (only the derived fields differ), which no consumer reads.
|
|
70
|
+
*
|
|
71
|
+
* Registration goes through `SchemaManager.addAssertion` rather than
|
|
72
|
+
* `Schema.addAssertion` because only the former fires `assertion_modified`.
|
|
73
|
+
*
|
|
74
|
+
* NOTE: an assertion with no `checkExpression` (the schema field is optional, for
|
|
75
|
+
* assertions reconstructed from persisted `violationSql` alone) is skipped by both
|
|
76
|
+
* callers — there is no AST to walk. Unreachable today: nothing persists assertions
|
|
77
|
+
* (`CatalogObjectKind` is `'view' | 'materializedView' | 'table'` and no store module
|
|
78
|
+
* has an assertion catalog path), so every live assertion came from
|
|
79
|
+
* `CREATE ASSERTION` and carries its expression. If an assertion-reconstruction path
|
|
80
|
+
* is ever added, this pass needs a re-parse arm or those assertions break on rename.
|
|
81
|
+
*
|
|
82
|
+
* NOTE: no per-assertion try/catch, deliberately — the only plausible throw is
|
|
83
|
+
* `buildAssertionViolationSql` on an AST that already stringified at create time, and
|
|
84
|
+
* catching would leave `checkExpression` rewritten while `violationSql` still named
|
|
85
|
+
* the old table, which is silently the very breakage this pass exists to prevent. The
|
|
86
|
+
* cost is that a throw here leaves earlier assertions in the loop already rewritten
|
|
87
|
+
* against a rename the statement then reports as failed (the view loop above has the
|
|
88
|
+
* same exposure). If that ever becomes reachable, the fix is a dry-run probe before
|
|
89
|
+
* any mutation, like `assertRenameDependentsPersistable`'s — not a catch.
|
|
90
|
+
*/
|
|
91
|
+
function reregisterRewrittenAssertion(db, schema, assertion, check, dependentTables) {
|
|
92
|
+
const updated = {
|
|
93
|
+
...assertion,
|
|
94
|
+
violationSql: buildAssertionViolationSql(check),
|
|
95
|
+
dependentTables,
|
|
96
|
+
};
|
|
97
|
+
db.schemaManager.addAssertion(schema.name, updated);
|
|
98
|
+
log('Rewrote assertion %s.%s for rename: %s', schema.name, assertion.name, updated.violationSql);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Re-keys the informational `dependentTables` entries naming the renamed base.
|
|
102
|
+
* Purely cosmetic (it feeds `assertion_info().dependent_tables`) — the commit-time
|
|
103
|
+
* evaluator recomputes its own base set when it compiles the body. Deliberately a
|
|
104
|
+
* string map rather than a re-plan of the rewritten body: this runs mid-DDL, where a
|
|
105
|
+
* planning failure would be a new failure mode for no enforcement benefit.
|
|
106
|
+
*/
|
|
107
|
+
function remapDependentTables(deps, oldBase, newBase) {
|
|
108
|
+
if (!deps)
|
|
109
|
+
return deps;
|
|
110
|
+
let changed = false;
|
|
111
|
+
const mapped = deps.map(dep => {
|
|
112
|
+
if (dep.base !== oldBase)
|
|
113
|
+
return dep;
|
|
114
|
+
changed = true;
|
|
115
|
+
// relationKey is `<base>#<nodeId>`; a base never contains '#'.
|
|
116
|
+
const hash = dep.relationKey.indexOf('#');
|
|
117
|
+
return {
|
|
118
|
+
relationKey: hash >= 0 ? `${newBase}${dep.relationKey.slice(hash)}` : newBase,
|
|
119
|
+
base: newBase,
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
return changed ? mapped : deps;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=assertion-rename-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertion-rename-helpers.js","sourceRoot":"","sources":["../../../../src/runtime/emit/assertion-rename-helpers.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAEtF,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,MAAM,GAAG,GAAG,YAAY,CAAC,+BAA+B,CAAC,CAAC;AA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IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO;YAC7E,IAAI,EAAE,OAAO;SACb,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AAChC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constraint-check.d.ts","sourceRoot":"","sources":["../../../../src/runtime/emit/constraint-check.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,
|
|
1
|
+
{"version":3,"file":"constraint-check.d.ts","sourceRoot":"","sources":["../../../../src/runtime/emit/constraint-check.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAsB,MAAM,8CAA8C,CAAC;AAC5G,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,aAAa,CAAC;AAG/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAW9D,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,mBAAmB,EAAE,GAAG,EAAE,eAAe,GAAG,WAAW,CA0JhG"}
|
|
@@ -1,50 +1,8 @@
|
|
|
1
1
|
import { asRun } from '../types.js';
|
|
2
2
|
import { emitPlanNode, emitCallFromPlan } from '../emitters.js';
|
|
3
|
-
import { ConstraintError, FailConflictError, RollbackConflictError } from '../../common/errors.js';
|
|
4
|
-
import { RowOpFlag } from '../../schema/table.js';
|
|
5
|
-
import { ConflictResolution } from '../../common/constants.js';
|
|
6
3
|
import { withAsyncRowContext, createRowSlot } from '../context-helpers.js';
|
|
7
|
-
import { expressionToString } from '../../emit/ast-stringify.js';
|
|
8
4
|
import { composeCombinedDescriptor } from '../descriptor-helpers.js';
|
|
9
|
-
import {
|
|
10
|
-
import { validateAndParse } from '../../types/validation.js';
|
|
11
|
-
/**
|
|
12
|
-
* The violation message for a failing constraint — single source of truth for the
|
|
13
|
-
* immediate (row-time) and deferred (commit-time) paths, which must report a row
|
|
14
|
-
* identically no matter when the check happened to run.
|
|
15
|
-
*
|
|
16
|
-
* Engine-level CHECK and synthesized FK existence checks share the
|
|
17
|
-
* "CHECK constraint failed" prefix for backward compatibility with existing
|
|
18
|
-
* assertions; downstream consumers identify FK by name. The expression text is
|
|
19
|
-
* appended as a hint only when short enough to stay readable.
|
|
20
|
-
*/
|
|
21
|
-
function constraintViolationMessage(metadata) {
|
|
22
|
-
const exprHint = metadata.constraintExpr.length <= 60 ? ` (${metadata.constraintExpr})` : '';
|
|
23
|
-
return `CHECK constraint failed: ${metadata.constraintName}${exprHint}`;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Resolve the effective conflict action for a single failure.
|
|
27
|
-
*
|
|
28
|
-
* Precedence: statement-level OR clause > per-constraint default > ABORT.
|
|
29
|
-
*/
|
|
30
|
-
function pickAction(stmtOR, constraintDefault) {
|
|
31
|
-
return stmtOR ?? constraintDefault ?? ConflictResolution.ABORT;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Throws an appropriate ConstraintError subclass based on the effective
|
|
35
|
-
* conflict action. ABORT/REPLACE/IGNORE callers must not reach this — IGNORE
|
|
36
|
-
* is handled by skipping the row, REPLACE by substitution / passthrough, and
|
|
37
|
-
* ABORT throws a plain ConstraintError.
|
|
38
|
-
*/
|
|
39
|
-
function throwForAction(action, message) {
|
|
40
|
-
if (action === ConflictResolution.FAIL) {
|
|
41
|
-
throw new FailConflictError(message);
|
|
42
|
-
}
|
|
43
|
-
if (action === ConflictResolution.ROLLBACK) {
|
|
44
|
-
throw new RollbackConflictError(message);
|
|
45
|
-
}
|
|
46
|
-
throw new ConstraintError(message);
|
|
47
|
-
}
|
|
5
|
+
import { buildConstraintMetadata, evaluateRowConstraints, } from '../row-constraints.js';
|
|
48
6
|
export function emitConstraintCheck(plan, ctx) {
|
|
49
7
|
// Get the table schema to access constraints
|
|
50
8
|
const tableSchema = plan.table.tableSchema;
|
|
@@ -60,6 +18,11 @@ export function emitConstraintCheck(plan, ctx) {
|
|
|
60
18
|
if (mutationContextValues && contextAttributes) {
|
|
61
19
|
for (const attr of contextAttributes) {
|
|
62
20
|
const valueExpr = mutationContextValues.get(attr.name);
|
|
21
|
+
// NOTE: a declared context var with no supplied value is silently skipped here,
|
|
22
|
+
// which would shift every later value out of alignment with contextDescriptor.
|
|
23
|
+
// Unreachable today — emitDmlExecutor throws "Missing mutation context value for
|
|
24
|
+
// '<name>'" at prepare time first — but that's an external invariant, not one
|
|
25
|
+
// this loop enforces itself.
|
|
63
26
|
if (valueExpr) {
|
|
64
27
|
contextEvaluatorInstructions.push(emitCallFromPlan(valueExpr, ctx));
|
|
65
28
|
}
|
|
@@ -75,24 +38,8 @@ export function emitConstraintCheck(plan, ctx) {
|
|
|
75
38
|
const notNullDefaultCoercions = notNullDefaultPlans.map(d => d.defaultNode.getType().logicalType !== tableSchema.columns[d.columnIndex].logicalType
|
|
76
39
|
? tableSchema.columns[d.columnIndex]
|
|
77
40
|
: undefined);
|
|
78
|
-
const constraintMetadata = plan.constraintChecks.map(
|
|
79
|
-
|
|
80
|
-
const constraintName = check.constraint.name ?? generateDefaultConstraintName(tableSchema, check.constraint);
|
|
81
|
-
const constraintExpr = expressionToString(check.constraint.expr);
|
|
82
|
-
return {
|
|
83
|
-
schema: check.constraint,
|
|
84
|
-
flatRowDescriptor: plan.flatRowDescriptor,
|
|
85
|
-
evaluator: evaluatorInstruction.run,
|
|
86
|
-
constraintName,
|
|
87
|
-
constraintExpr,
|
|
88
|
-
shouldDefer: Boolean(check.deferrable || check.initiallyDeferred || check.needsDeferred),
|
|
89
|
-
baseTable: `${tableSchema.schemaName}.${tableSchema.name}`,
|
|
90
|
-
contextRow: undefined,
|
|
91
|
-
contextDescriptor,
|
|
92
|
-
kind: check.kind ?? 'check',
|
|
93
|
-
referencedColumnIndices: check.referencedColumnIndices,
|
|
94
|
-
};
|
|
95
|
-
});
|
|
41
|
+
const constraintMetadata = buildConstraintMetadata(plan.constraintChecks, tableSchema, flatRowDescriptor, contextDescriptor, checkEvaluators.map(instruction => instruction.run));
|
|
42
|
+
const scope = { operation: plan.operation, hasNewSection: Boolean(plan.newRowDescriptor) };
|
|
96
43
|
async function* run(rctx, inputRows, ...evaluatorFunctions) {
|
|
97
44
|
if (!inputRows) {
|
|
98
45
|
return;
|
|
@@ -113,9 +60,6 @@ export function emitConstraintCheck(plan, ctx) {
|
|
|
113
60
|
const value = (raw instanceof Promise ? await raw : raw);
|
|
114
61
|
contextRow.push(value);
|
|
115
62
|
}
|
|
116
|
-
constraintMetadata.forEach(meta => {
|
|
117
|
-
meta.contextRow = contextRow;
|
|
118
|
-
});
|
|
119
63
|
contextSlot = createRowSlot(rctx, contextDescriptor);
|
|
120
64
|
contextSlot.set(contextRow);
|
|
121
65
|
}
|
|
@@ -134,14 +78,14 @@ export function emitConstraintCheck(plan, ctx) {
|
|
|
134
78
|
for await (const inputRow of inputRows) {
|
|
135
79
|
let flatRow = inputRow;
|
|
136
80
|
// The row expressions see through `combinedDescriptor`. The getter is
|
|
137
|
-
// called lazily per lookup, so
|
|
81
|
+
// called lazily per lookup, so evaluateRowConstraints can swap it mid-row:
|
|
138
82
|
// after a REPLACE NOT NULL DEFAULT substitution, CHECK / FK must read
|
|
139
83
|
// the row AS SUBSTITUTED. The row arrives already converted to declared
|
|
140
84
|
// column types (the DML emitters convert the NEW section up front), so
|
|
141
85
|
// no separate coerced view exists — the substituted row IS what flows
|
|
142
86
|
// downstream.
|
|
143
87
|
let visibleRow = flatRow;
|
|
144
|
-
const evaluation = await withAsyncRowContext(rctx, combinedDescriptor, () => contextRow ? [...contextRow, ...visibleRow] : visibleRow, () =>
|
|
88
|
+
const evaluation = await withAsyncRowContext(rctx, combinedDescriptor, () => contextRow ? [...contextRow, ...visibleRow] : visibleRow, () => evaluateRowConstraints(rctx, scope, tableSchema, flatRow, constraintMetadata, constraintEvalFunctions, stmtOR, defaultsRuntime, contextRow, row => { visibleRow = row; }));
|
|
145
89
|
if (evaluation.skip)
|
|
146
90
|
continue;
|
|
147
91
|
if (evaluation.replacedRow) {
|
|
@@ -164,165 +108,4 @@ export function emitConstraintCheck(plan, ctx) {
|
|
|
164
108
|
note: `constraintCheck(${plan.operation}, ${contextEvaluatorInstructions.length} ctx, ${plan.constraintChecks.length} checks, ${notNullDefaultInstructions.length} defaults)`
|
|
165
109
|
};
|
|
166
110
|
}
|
|
167
|
-
async function checkConstraints(rctx, plan, tableSchema, row, constraintMetadata, evaluatorFunctions, stmtOR, notNullDefaults, showRow) {
|
|
168
|
-
// The row arrives with its NEW section already converted to declared column
|
|
169
|
-
// types (the DML emitters convert up front, driven by static types), so both
|
|
170
|
-
// passes read declared-form values. NOT NULL runs first: under OR REPLACE it
|
|
171
|
-
// may substitute a column's DEFAULT (converting that one injected value —
|
|
172
|
-
// see NotNullDefaultRuntime.coerceColumn), and CHECK / FK then read the row
|
|
173
|
-
// AS FINALLY SUBSTITUTED, which is also what flows on downstream.
|
|
174
|
-
const nnResult = await checkNotNullConstraints(rctx, plan, tableSchema, row, stmtOR, notNullDefaults);
|
|
175
|
-
if (nnResult.skip)
|
|
176
|
-
return { skip: true };
|
|
177
|
-
if (nnResult.replacedRow)
|
|
178
|
-
row = nnResult.replacedRow;
|
|
179
|
-
showRow(row);
|
|
180
|
-
// CHECK constraints (and synthetic FK existence checks built as RowConstraintSchema).
|
|
181
|
-
const ckResult = await checkCheckConstraints(rctx, plan, tableSchema, constraintMetadata, evaluatorFunctions, stmtOR, row);
|
|
182
|
-
if (ckResult.skip)
|
|
183
|
-
return { skip: true };
|
|
184
|
-
return { skip: false, replacedRow: nnResult.replacedRow };
|
|
185
|
-
}
|
|
186
|
-
async function checkNotNullConstraints(rctx, plan, tableSchema, flatRow, stmtOR, notNullDefaults) {
|
|
187
|
-
if (plan.operation === RowOpFlag.DELETE) {
|
|
188
|
-
return { skip: false };
|
|
189
|
-
}
|
|
190
|
-
if (!plan.newRowDescriptor) {
|
|
191
|
-
return { skip: false };
|
|
192
|
-
}
|
|
193
|
-
const numCols = tableSchema.columns.length;
|
|
194
|
-
let mutableRow;
|
|
195
|
-
// NOT NULL attribution: report the FIRST NOT-NULL column (in declaration
|
|
196
|
-
// order) whose effective NEW value is NULL, naming that column itself —
|
|
197
|
-
// independent of which column any DEFAULT references. A NULL sibling named by
|
|
198
|
-
// another column's `new.<col>` DEFAULT violates its OWN NOT NULL and is
|
|
199
|
-
// reported on its own merits, never threaded into the defaulted column's
|
|
200
|
-
// message. (See test/logic/03.4-defaults.sqllogic, the NOT NULL default section.)
|
|
201
|
-
for (let i = 0; i < numCols; i++) {
|
|
202
|
-
const column = tableSchema.columns[i];
|
|
203
|
-
if (!column.notNull)
|
|
204
|
-
continue;
|
|
205
|
-
const newValueIndex = numCols + i; // NEW section: n..2n-1
|
|
206
|
-
const value = (mutableRow ?? flatRow)[newValueIndex];
|
|
207
|
-
if (value !== null && value !== undefined)
|
|
208
|
-
continue;
|
|
209
|
-
const action = pickAction(stmtOR, column.defaultConflict);
|
|
210
|
-
const message = `NOT NULL constraint failed: ${tableSchema.name}.${column.name}`;
|
|
211
|
-
if (action === ConflictResolution.IGNORE) {
|
|
212
|
-
return { skip: true };
|
|
213
|
-
}
|
|
214
|
-
if (action === ConflictResolution.REPLACE) {
|
|
215
|
-
// Try to substitute the column's DEFAULT.
|
|
216
|
-
const defaultEntry = notNullDefaults.find(d => d.columnIndex === i);
|
|
217
|
-
if (!defaultEntry) {
|
|
218
|
-
// No DEFAULT available — REPLACE cannot recover.
|
|
219
|
-
throw new ConstraintError(message);
|
|
220
|
-
}
|
|
221
|
-
let defaultValue = await defaultEntry.evaluator(rctx);
|
|
222
|
-
if (defaultValue === null || defaultValue === undefined) {
|
|
223
|
-
// DEFAULT itself is NULL — substitution does not satisfy NOT NULL.
|
|
224
|
-
throw new ConstraintError(message);
|
|
225
|
-
}
|
|
226
|
-
if (defaultEntry.coerceColumn) {
|
|
227
|
-
// The substituted value is injected AFTER the emitters' conversion
|
|
228
|
-
// pass, so convert it here by the same static-type rule. Conversion
|
|
229
|
-
// itself can produce NULL (JSON's text 'null'), which still violates
|
|
230
|
-
// NOT NULL.
|
|
231
|
-
defaultValue = validateAndParse(defaultValue, defaultEntry.coerceColumn.logicalType, defaultEntry.coerceColumn.name);
|
|
232
|
-
if (defaultValue === null) {
|
|
233
|
-
throw new ConstraintError(message);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
if (!mutableRow)
|
|
237
|
-
mutableRow = [...flatRow];
|
|
238
|
-
mutableRow[newValueIndex] = defaultValue;
|
|
239
|
-
continue;
|
|
240
|
-
}
|
|
241
|
-
// ABORT / FAIL / ROLLBACK
|
|
242
|
-
throwForAction(action, message);
|
|
243
|
-
}
|
|
244
|
-
return { skip: false, replacedRow: mutableRow };
|
|
245
|
-
}
|
|
246
|
-
async function checkCheckConstraints(rctx, plan, tableSchema, constraintMetadata, evaluatorFunctions, stmtOR, flatRow) {
|
|
247
|
-
for (let i = 0; i < constraintMetadata.length; i++) {
|
|
248
|
-
const metadata = constraintMetadata[i];
|
|
249
|
-
const evaluator = evaluatorFunctions[i] ?? metadata.evaluator;
|
|
250
|
-
// Trust-the-origin apply path: the synthesized parent-side FK RESTRICT (NOT EXISTS)
|
|
251
|
-
// check is the plan-time dual of the runtime RESTRICT pre-checks. While applying
|
|
252
|
-
// external row changes the receiver skips it (the origin already enforced RESTRICT at
|
|
253
|
-
// its own commit) - otherwise a cascade DML re-entering this executor under the apply
|
|
254
|
-
// flag would throw here, wedging the sync stream. Only 'fk-parent' checks are gated;
|
|
255
|
-
// user CHECKs and child-side FK existence checks are untouched.
|
|
256
|
-
// (See database-external-changes.ts and runtime/foreign-key-actions.ts for the runtime dual.)
|
|
257
|
-
if (metadata.kind === 'fk-parent' && rctx.db._isFkRestrictSuppressed())
|
|
258
|
-
continue;
|
|
259
|
-
// Parent-side FK UPDATE: skip the NOT EXISTS subquery when none of the
|
|
260
|
-
// referenced parent columns actually changed.
|
|
261
|
-
if (plan.operation === RowOpFlag.UPDATE &&
|
|
262
|
-
metadata.kind === 'fk-parent' &&
|
|
263
|
-
metadata.referencedColumnIndices) {
|
|
264
|
-
// Both halves are in stored (declared) form: OLD comes from the scan, NEW
|
|
265
|
-
// was converted by the DML emitter — so plain identity is the right test.
|
|
266
|
-
const numCols = tableSchema.columns.length;
|
|
267
|
-
let anyChanged = false;
|
|
268
|
-
for (const colIdx of metadata.referencedColumnIndices) {
|
|
269
|
-
const oldVal = flatRow[colIdx]; // OLD section: 0..n-1
|
|
270
|
-
const newVal = flatRow[numCols + colIdx]; // NEW section: n..2n-1
|
|
271
|
-
if (!sqlValueIdentical(oldVal, newVal)) {
|
|
272
|
-
anyChanged = true;
|
|
273
|
-
break;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
if (!anyChanged)
|
|
277
|
-
continue;
|
|
278
|
-
}
|
|
279
|
-
// Resolve effective action up front; non-default actions (IGNORE/REPLACE/FAIL/ROLLBACK)
|
|
280
|
-
// must be applied at row time, so we cannot let those defer to commit.
|
|
281
|
-
const effectiveAction = pickAction(stmtOR, metadata.schema.defaultConflict);
|
|
282
|
-
const mustEvaluateNow = effectiveAction !== ConflictResolution.ABORT;
|
|
283
|
-
if (metadata.shouldDefer && !mustEvaluateNow) {
|
|
284
|
-
const activeConnectionId = rctx.activeConnection?.connectionId;
|
|
285
|
-
// Wrap so the deferred queue's evaluation at COMMIT throws the same
|
|
286
|
-
// attributed message as the immediate path below, instead of the queue's
|
|
287
|
-
// generic name-only fallback — matches the pattern derived-row-validator.ts
|
|
288
|
-
// already uses for maintained tables. The wrapper always throws before
|
|
289
|
-
// returning falsy, so the queue's own generic message never fires here.
|
|
290
|
-
// Only ABORT reaches this branch (see mustEvaluateNow), so throwing is the
|
|
291
|
-
// whole of the deferred failure contract — no IGNORE/REPLACE leg needed.
|
|
292
|
-
const message = constraintViolationMessage(metadata);
|
|
293
|
-
const deferredEvaluator = async (dctx) => {
|
|
294
|
-
const rawResult = evaluator(dctx);
|
|
295
|
-
const result = (rawResult instanceof Promise ? await rawResult : rawResult);
|
|
296
|
-
if (result !== null && !isTruthy(result)) {
|
|
297
|
-
throw new ConstraintError(message);
|
|
298
|
-
}
|
|
299
|
-
return result;
|
|
300
|
-
};
|
|
301
|
-
rctx.db._queueDeferredConstraintRow(metadata.baseTable, metadata.constraintName, flatRow, metadata.flatRowDescriptor, deferredEvaluator, activeConnectionId, metadata.contextRow, metadata.contextDescriptor);
|
|
302
|
-
continue;
|
|
303
|
-
}
|
|
304
|
-
// Resolve without a per-row microtask hop (see runtime/async-util.ts).
|
|
305
|
-
const rawResult = evaluator(rctx);
|
|
306
|
-
const result = (rawResult instanceof Promise ? await rawResult : rawResult);
|
|
307
|
-
// CHECK passes if truthy or NULL; fails otherwise (shared isTruthy semantics).
|
|
308
|
-
if (result !== null && !isTruthy(result)) {
|
|
309
|
-
const baseMessage = constraintViolationMessage(metadata);
|
|
310
|
-
if (effectiveAction === ConflictResolution.IGNORE) {
|
|
311
|
-
return { skip: true };
|
|
312
|
-
}
|
|
313
|
-
// REPLACE does NOT mask CHECK / FK violations — fall through to abort.
|
|
314
|
-
// (SQLite's OR REPLACE only relaxes UNIQUE/PK and NOT-NULL; CHECK still aborts.)
|
|
315
|
-
if (effectiveAction === ConflictResolution.REPLACE) {
|
|
316
|
-
throw new ConstraintError(baseMessage);
|
|
317
|
-
}
|
|
318
|
-
throwForAction(effectiveAction, baseMessage);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
return { skip: false };
|
|
322
|
-
}
|
|
323
|
-
function generateDefaultConstraintName(tableSchema, constraint) {
|
|
324
|
-
// Find the index of this constraint in the original array to get the correct constraint number
|
|
325
|
-
const originalIndex = tableSchema.checkConstraints.findIndex((c) => c === constraint);
|
|
326
|
-
return `_check_${originalIndex >= 0 ? originalIndex : 'unknown'}`;
|
|
327
|
-
}
|
|
328
111
|
//# sourceMappingURL=constraint-check.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"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,iBAAiB,EAAE,GAAG,4BAA4B,EAAE,GAAG,eAAe,EAAE,GAAG,0BAA0B,CAAC;QAC/G,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC;QACf,IAAI,EAAE,mBAAmB,IAAI,CAAC,SAAS,KAAK,4BAA4B,CAAC,MAAM,SAAS,IAAI,CAAC,gBAAgB,CAAC,MAAM,YAAY,0BAA0B,CAAC,MAAM,YAAY;KAC7K,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-assertion.d.ts","sourceRoot":"","sources":["../../../../src/runtime/emit/create-assertion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,aAAa,CAAC;AAE/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"create-assertion.d.ts","sourceRoot":"","sources":["../../../../src/runtime/emit/create-assertion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,aAAa,CAAC;AAE/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAU9D,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,eAAe,GAAG,WAAW,CAoGjG"}
|
|
@@ -2,19 +2,19 @@ import { asRun } from '../types.js';
|
|
|
2
2
|
import { QuereusError } from '../../common/errors.js';
|
|
3
3
|
import { StatusCode } from '../../common/types.js';
|
|
4
4
|
import { createLogger } from '../../common/logger.js';
|
|
5
|
-
import {
|
|
5
|
+
import { buildAssertionViolationSql } from '../../schema/assertion.js';
|
|
6
6
|
const log = createLogger('runtime:emit:create-assertion');
|
|
7
|
+
const warnLog = log.extend('warn');
|
|
7
8
|
export function emitCreateAssertion(plan, _ctx) {
|
|
8
9
|
async function run(rctx) {
|
|
9
10
|
// Ensure we're in a transaction before DDL (lazy/JIT transaction start)
|
|
10
11
|
await rctx.db._ensureTransaction();
|
|
11
|
-
// Convert the CHECK expression to SQL text for storage
|
|
12
|
-
//
|
|
13
|
-
//
|
|
12
|
+
// Convert the CHECK expression to SQL text for storage. Shared with the
|
|
13
|
+
// `ALTER TABLE … RENAME` propagation, which regenerates this same text from
|
|
14
|
+
// the rewritten expression (see `buildAssertionViolationSql`).
|
|
14
15
|
let violationSql;
|
|
15
16
|
try {
|
|
16
|
-
|
|
17
|
-
violationSql = `select 1 where not (${exprSql})`;
|
|
17
|
+
violationSql = buildAssertionViolationSql(plan.checkExpression);
|
|
18
18
|
}
|
|
19
19
|
catch (e) {
|
|
20
20
|
throw new QuereusError(`Cannot create assertion '${plan.name}': failed to convert check expression to SQL`, StatusCode.ERROR, e instanceof Error ? e : undefined);
|
|
@@ -22,15 +22,25 @@ export function emitCreateAssertion(plan, _ctx) {
|
|
|
22
22
|
// Create the assertion schema object
|
|
23
23
|
const assertionSchema = {
|
|
24
24
|
name: plan.name,
|
|
25
|
+
schemaName: plan.schemaName,
|
|
25
26
|
violationSql,
|
|
26
27
|
deferrable: true, // Auto-deferred for multi-table constraints
|
|
27
28
|
initiallyDeferred: true,
|
|
28
29
|
dependentTables: [],
|
|
29
30
|
checkExpression: plan.checkExpression,
|
|
30
31
|
};
|
|
31
|
-
// Discover dependent base tables (best-effort; conservative if any failure)
|
|
32
|
+
// Discover dependent base tables (best-effort; conservative if any failure).
|
|
33
|
+
// Plan under the assertion's home-schema path so unqualified table names in
|
|
34
|
+
// the body resolve against the assertion's own schema first, and under
|
|
35
|
+
// hoist suppression so another assertion's hoisted premises can't fold a
|
|
36
|
+
// base reference out of the plan — the commit-time evaluator derives its
|
|
37
|
+
// own base set the same way (see AssertionEvaluator.getOrCompilePlan).
|
|
38
|
+
// The builder (`planAssertionBody`) already proved this same violation SQL
|
|
39
|
+
// builds against the live catalog, so a failure below is a discovery-only
|
|
40
|
+
// failure (optimizer-stage, or the plan-shape walk) — never "the body names
|
|
41
|
+
// something that doesn't exist".
|
|
32
42
|
try {
|
|
33
|
-
const planNode = rctx.db.getPlan(violationSql);
|
|
43
|
+
const planNode = rctx.db.schemaManager.withSuppressedAssertionHoist(() => rctx.db.getPlan(violationSql, rctx.db._homeSchemaPath(plan.schemaName)));
|
|
34
44
|
const deps = new Map();
|
|
35
45
|
(function collect(node) {
|
|
36
46
|
const candidate = node;
|
|
@@ -49,24 +59,31 @@ export function emitCreateAssertion(plan, _ctx) {
|
|
|
49
59
|
log('Assertion %s dependencies discovered: %o', plan.name, assertionSchema.dependentTables);
|
|
50
60
|
}
|
|
51
61
|
catch (depErr) {
|
|
52
|
-
|
|
62
|
+
// Enforcement does NOT read `dependentTables` — the evaluator recomputes
|
|
63
|
+
// its base set when it compiles the body. A failure here only blanks the
|
|
64
|
+
// `dependent_tables` column of `assertion_info()`, and usually means the
|
|
65
|
+
// body will fail to plan at commit time too. Warn rather than swallow.
|
|
66
|
+
warnLog('Dependency discovery failed for assertion %s.%s; assertion_info().dependent_tables will be empty: %O', plan.schemaName, plan.name, depErr);
|
|
53
67
|
}
|
|
54
|
-
// Add to schema
|
|
68
|
+
// Add to the assertion's home schema
|
|
55
69
|
const schemaManager = rctx.db.schemaManager;
|
|
56
|
-
const schema = schemaManager.
|
|
57
|
-
|
|
70
|
+
const schema = schemaManager.getSchema(plan.schemaName);
|
|
71
|
+
if (!schema) {
|
|
72
|
+
throw new QuereusError(`Schema not found: ${plan.schemaName}`, StatusCode.ERROR);
|
|
73
|
+
}
|
|
74
|
+
// Check for existing assertion (names are unique per schema)
|
|
58
75
|
const existing = schema.getAssertion(plan.name);
|
|
59
76
|
if (existing) {
|
|
60
77
|
throw new QuereusError(`Assertion ${plan.name} already exists`, StatusCode.CONSTRAINT);
|
|
61
78
|
}
|
|
62
79
|
schemaManager.addAssertion(schema.name, assertionSchema);
|
|
63
|
-
log('Created assertion %s with violationSql: %s', plan.name, violationSql);
|
|
80
|
+
log('Created assertion %s.%s with violationSql: %s', plan.schemaName, plan.name, violationSql);
|
|
64
81
|
return null;
|
|
65
82
|
}
|
|
66
83
|
return {
|
|
67
84
|
params: [],
|
|
68
85
|
run: asRun(run),
|
|
69
|
-
note: `createAssertion(${plan.name})`
|
|
86
|
+
note: `createAssertion(${plan.schemaName}.${plan.name})`
|
|
70
87
|
};
|
|
71
88
|
}
|
|
72
89
|
//# sourceMappingURL=create-assertion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-assertion.js","sourceRoot":"","sources":["../../../../src/runtime/emit/create-assertion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAY,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"create-assertion.js","sourceRoot":"","sources":["../../../../src/runtime/emit/create-assertion.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAY,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AAEvE,MAAM,GAAG,GAAG,YAAY,CAAC,+BAA+B,CAAC,CAAC;AAC1D,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAEnC,MAAM,UAAU,mBAAmB,CAAC,IAAyB,EAAE,IAAqB;IAEnF,KAAK,UAAU,GAAG,CAAC,IAAoB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,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,IAAI,YAAY,CAAC,qBAAqB,IAAI,CAAC,UAAU,EAAE,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;QAClF,CAAC;QAED,6DAA6D;QAC7D,MAAM,QAAQ,GAAG,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChD,IAAI,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,YAAY,CACrB,aAAa,IAAI,CAAC,IAAI,iBAAiB,EACvC,UAAU,CAAC,UAAU,CACrB,CAAC;QACH,CAAC;QAED,aAAa,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;QAEzD,GAAG,CAAC,+CAA+C,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QAC/F,OAAO,IAAI,CAAC;IACb,CAAC;IAED,OAAO;QACN,MAAM,EAAE,EAAE;QACV,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC;QACf,IAAI,EAAE,mBAAmB,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,IAAI,GAAG;KACxD,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cte.d.ts","sourceRoot":"","sources":["../../../../src/runtime/emit/cte.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,aAAa,CAAC;AAE/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAI9D,wBAAgB,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,eAAe,GAAG,WAAW,
|
|
1
|
+
{"version":3,"file":"cte.d.ts","sourceRoot":"","sources":["../../../../src/runtime/emit/cte.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,aAAa,CAAC;AAE/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAI9D,wBAAgB,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,eAAe,GAAG,WAAW,CA+DxE"}
|
|
@@ -12,12 +12,17 @@ export function emitCTE(plan, ctx) {
|
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
14
|
// Shared materialization: every reference to this CTE shares one
|
|
15
|
-
// per-execution buffer keyed by the
|
|
16
|
-
// point at
|
|
17
|
-
//
|
|
18
|
-
//
|
|
15
|
+
// per-execution buffer keyed by the CTE's stable `tableDescriptor`.
|
|
16
|
+
// NOT the plan id: references usually point at one CTENode instance, but
|
|
17
|
+
// the optimizer may split it into several (the constant-folding pass
|
|
18
|
+
// rebuilds a two-parent node once per parent path), and each copy would
|
|
19
|
+
// then own a private buffer — re-driving the source, which for a
|
|
20
|
+
// data-modifying body means writing twice. The descriptor is threaded
|
|
21
|
+
// through every rebuild, so all copies agree on the key. Mirrors
|
|
22
|
+
// emitRecursiveCTE. Each reference emits its own copy of the source
|
|
23
|
+
// subtree; only the buffer owner ever iterates one.
|
|
19
24
|
const buffers = (rctx.cteMaterializations ??= new Map());
|
|
20
|
-
let bufferPromise = buffers.get(plan.
|
|
25
|
+
let bufferPromise = buffers.get(plan.tableDescriptor);
|
|
21
26
|
if (!bufferPromise) {
|
|
22
27
|
// First reference to run owns the single source drive. Create and
|
|
23
28
|
// store the promise SYNCHRONOUSLY (before any await) so a second
|
|
@@ -40,7 +45,7 @@ export function emitCTE(plan, ctx) {
|
|
|
40
45
|
// would otherwise surface an unhandled rejection. References that are
|
|
41
46
|
// still awaiting observe the rejection through their own await.
|
|
42
47
|
bufferPromise.catch(() => { });
|
|
43
|
-
buffers.set(plan.
|
|
48
|
+
buffers.set(plan.tableDescriptor, bufferPromise);
|
|
44
49
|
}
|
|
45
50
|
const rows = await bufferPromise;
|
|
46
51
|
for (const row of rows) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cte.js","sourceRoot":"","sources":["../../../../src/runtime/emit/cte.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,MAAM,UAAU,OAAO,CAAC,IAAa,EAAE,GAAoB;IAC1D,4BAA4B;IAC5B,MAAM,gBAAgB,GAAG,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAExD,KAAK,SAAS,CAAC,CAAC,GAAG,CAAC,IAAoB,EAAE,WAA+B;QACxE,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACvB,oEAAoE;YACpE,kEAAkE;YAClE,cAAc;YACd,KAAK,CAAC,CAAC,WAAW,CAAC;YACnB,OAAO;QACR,CAAC;QAED,iEAAiE;QACjE,
|
|
1
|
+
{"version":3,"file":"cte.js","sourceRoot":"","sources":["../../../../src/runtime/emit/cte.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,MAAM,UAAU,OAAO,CAAC,IAAa,EAAE,GAAoB;IAC1D,4BAA4B;IAC5B,MAAM,gBAAgB,GAAG,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAExD,KAAK,SAAS,CAAC,CAAC,GAAG,CAAC,IAAoB,EAAE,WAA+B;QACxE,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACvB,oEAAoE;YACpE,kEAAkE;YAClE,cAAc;YACd,KAAK,CAAC,CAAC,WAAW,CAAC;YACnB,OAAO;QACR,CAAC;QAED,iEAAiE;QACjE,oEAAoE;QACpE,yEAAyE;QACzE,qEAAqE;QAC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,CAAC,WAAW,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,GAAG;KACvE,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dml-executor.d.ts","sourceRoot":"","sources":["../../../../src/runtime/emit/dml-executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAChF,OAAO,KAAK,EAAE,WAAW,EAA+C,MAAM,aAAa,CAAC;AAO5F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAI9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"dml-executor.d.ts","sourceRoot":"","sources":["../../../../src/runtime/emit/dml-executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAChF,OAAO,KAAK,EAAE,WAAW,EAA+C,MAAM,aAAa,CAAC;AAO5F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAI9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AA+SzD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,8BAA8B,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAQ7E;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,eAAe,EAAE,GAAG,EAAE,eAAe,GAAG,WAAW,CAqvCxF"}
|