@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
|
@@ -9,6 +9,32 @@ import type * as AST from '../parser/ast.js';
|
|
|
9
9
|
*/
|
|
10
10
|
export type ResolveColumnInSource = (schemaName: string, tableName: string, columnName: string) => boolean;
|
|
11
11
|
export declare function renameTableInAst(node: AST.AstNode | undefined, oldName: string, newName: string, defaultSchemaName: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Whether `node` refers to the table/view `name` in schema `defaultSchemaName` —
|
|
14
|
+
* read-only, nothing is mutated.
|
|
15
|
+
*
|
|
16
|
+
* Deliberately the SAME traversal {@link renameTableInAst} uses, run with
|
|
17
|
+
* `dryRun`, so "refers to" can never drift from "would have been rewritten by a
|
|
18
|
+
* rename". That equivalence is the whole point: the DROP guard refuses exactly
|
|
19
|
+
* the cases `ALTER TABLE … RENAME` would have followed. A second traversal — or
|
|
20
|
+
* a `renameTableInAst(clone, name, name, …)` trick, which would silently
|
|
21
|
+
* re-case identifiers — would both break it.
|
|
22
|
+
*
|
|
23
|
+
* `name` is passed as both old and new name; under `dryRun` the new name is
|
|
24
|
+
* never read.
|
|
25
|
+
*
|
|
26
|
+
* The column-level probes ({@link columnReferencedInAst},
|
|
27
|
+
* {@link columnReferencedInCheckExpression}) reach the same equivalence a
|
|
28
|
+
* different way — a real rename, to a sentinel name, over a throwaway
|
|
29
|
+
* {@link spineCloneAst} copy — because the column walker has ~8 mutation points
|
|
30
|
+
* and a CTE-re-exposure branch that reads the new name, so threading `dryRun`
|
|
31
|
+
* through it is the riskier of the two. Neither flaw of the identity-rename
|
|
32
|
+
* trick warned against above applies there: the mutated node is a discarded
|
|
33
|
+
* clone (nothing user-visible is re-cased), and the target is a fresh name no
|
|
34
|
+
* column can hold, so `newCol !== oldCol` and the re-exposure branch answers
|
|
35
|
+
* exactly as it would for a real rename to an unused name.
|
|
36
|
+
*/
|
|
37
|
+
export declare function tableReferencedInAst(node: AST.AstNode | undefined, name: string, defaultSchemaName: string): boolean;
|
|
12
38
|
/**
|
|
13
39
|
* Rewrite the renamed table inside every partial-index predicate of `indexes`,
|
|
14
40
|
* in place. A predicate may carry a table-qualified self-reference
|
|
@@ -35,6 +61,31 @@ export declare function renameTableInIndexPredicates(indexes: ReadonlyArray<{
|
|
|
35
61
|
export declare function renameTableInCheckConstraints(checks: ReadonlyArray<{
|
|
36
62
|
readonly expr: AST.Expression;
|
|
37
63
|
}> | undefined, oldName: string, newName: string, defaultSchemaName: string): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Rewrite the renamed table inside the two expressions a `ColumnSchema` can carry —
|
|
66
|
+
* a column DEFAULT (`w integer default ((select min(v) from u))`, however authored:
|
|
67
|
+
* inline, or via `ALTER TABLE … ALTER COLUMN … SET DEFAULT`, which writes the same
|
|
68
|
+
* field) and a generated column's body (`g integer generated always as ((select
|
|
69
|
+
* min(u.v) from u) + id)`) — in place.
|
|
70
|
+
*
|
|
71
|
+
* Unlike the column-rename counterpart ({@link renameColumnInColumnExpressions}) there
|
|
72
|
+
* is no seeded/unseeded split: {@link renameTableInAst} resolves nothing against an
|
|
73
|
+
* implicit owning table, so the SAME entry point is correct for the renamed table's own
|
|
74
|
+
* columns (a self-referencing default, `default ((select count(*) from t))`) and for
|
|
75
|
+
* every other table's.
|
|
76
|
+
*
|
|
77
|
+
* Same sharing and idempotence story as {@link renameTableInCheckConstraints}: the
|
|
78
|
+
* `Expression` is the very AST the catalog's `TableSchema` holds, so one in-place
|
|
79
|
+
* rewrite reaches every holder and a second call with the same pair finds nothing
|
|
80
|
+
* naming `oldName` and returns false.
|
|
81
|
+
*
|
|
82
|
+
* The parameter is structurally typed rather than `ColumnSchema[]` so this module stays
|
|
83
|
+
* free of catalog imports; `ColumnSchema` satisfies it.
|
|
84
|
+
*/
|
|
85
|
+
export declare function renameTableInColumnExpressions(columns: ReadonlyArray<{
|
|
86
|
+
readonly defaultValue?: AST.Expression | null;
|
|
87
|
+
readonly generatedExpr?: AST.Expression;
|
|
88
|
+
}> | undefined, oldName: string, newName: string, defaultSchemaName: string): boolean;
|
|
38
89
|
/**
|
|
39
90
|
* Rewrite column references inside a full statement/expression AST, resolving
|
|
40
91
|
* unqualified refs against the FROM scopes the walk descends (no implicit seed,
|
|
@@ -72,8 +123,54 @@ export declare function renameColumnInAst(node: AST.AstNode | undefined, tableNa
|
|
|
72
123
|
* sources are not asked (the rewriter would need recursive column-set
|
|
73
124
|
* inference on their bodies). `renameColumnInAst` shares the same callback
|
|
74
125
|
* (passed by the view-body callers) and the same limitation.
|
|
126
|
+
*
|
|
127
|
+
* The seed also makes this walk the owner of the `new.` / `old.` **row-image**
|
|
128
|
+
* namespace: a CHECK may name the row being written explicitly
|
|
129
|
+
* (`check (new.a > 0)`, `check on delete (old.a > 0)` — `docs/sql-ddl.md`
|
|
130
|
+
* § CHECK Constraints), and those qualifiers name the owning table's row, not
|
|
131
|
+
* anything a FROM clause binds. So the qualified-ref case matches them too —
|
|
132
|
+
* but only here, never through `renameColumnInAst`, where a `new.` ref belongs
|
|
133
|
+
* to some other table's row image.
|
|
134
|
+
*
|
|
135
|
+
* That match is scope-**aware**, not depth-blind, because `new` and `old` are
|
|
136
|
+
* not reserved words in this parser: `create table "new" (…)` is legal, so a
|
|
137
|
+
* CHECK may legitimately contain `(select max("new".a) from "new")`. The match
|
|
138
|
+
* therefore requires that no FROM/WITH frame above the seed rebind the
|
|
139
|
+
* qualifier — see `matchesRowImage`.
|
|
75
140
|
*/
|
|
76
141
|
export declare function renameColumnInCheckExpression(expr: AST.AstNode | undefined, tableName: string, oldColName: string, newColName: string, defaultSchemaName: string, resolveColumnInSource?: ResolveColumnInSource): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Whether `node` refers to `tableName`.`columnName` — read-only with respect to
|
|
144
|
+
* the caller's AST; a throwaway {@link spineCloneAst} copy is what gets
|
|
145
|
+
* rewritten.
|
|
146
|
+
*
|
|
147
|
+
* Same equivalence {@link tableReferencedInAst} establishes for the table verb,
|
|
148
|
+
* and for the same reason: "refers to" must mean "would have been rewritten by
|
|
149
|
+
* `ALTER TABLE … RENAME COLUMN`", or a DROP guard built on it refuses a
|
|
150
|
+
* different set of cases than the rename follows. See that function's comment
|
|
151
|
+
* for why the column verb reaches it by clone+sentinel rather than by `dryRun`.
|
|
152
|
+
*
|
|
153
|
+
* `resolveColumnInSource` is **not optional in practice**: without it the walk
|
|
154
|
+
* has no way to tell that an unqualified ref inside a subquery binds to a
|
|
155
|
+
* like-named column on the subquery's own FROM source, and a caller asking
|
|
156
|
+
* "does this body name `t.v`?" gets `true` for a body whose only `v` is
|
|
157
|
+
* another table's. Every caller should pass the catalog-backed resolver
|
|
158
|
+
* (`buildColumnSourceResolver`).
|
|
159
|
+
*
|
|
160
|
+
* NOTE: one spine clone plus one walk per probe, and the DROP COLUMN guard probes every
|
|
161
|
+
* live assertion. Trivial at the handful-of-assertions scale schemas have today, and it
|
|
162
|
+
* only runs on DDL; if a schema ever carries assertions by the hundred, filter by
|
|
163
|
+
* `tableReferencedInAst` (no clone) before paying for the column probe.
|
|
164
|
+
*/
|
|
165
|
+
export declare function columnReferencedInAst(node: AST.AstNode | undefined, tableName: string, columnName: string, defaultSchemaName: string, resolveColumnInSource?: ResolveColumnInSource): boolean;
|
|
166
|
+
/**
|
|
167
|
+
* {@link columnReferencedInAst} for an expression that resolves unqualified refs
|
|
168
|
+
* against an implicit binding to `tableName` — a CHECK expression or a
|
|
169
|
+
* partial-index predicate. Uses {@link renameColumnInCheckExpression}'s seeded
|
|
170
|
+
* entry point so the probe answers for exactly the scope that expression is
|
|
171
|
+
* planned in.
|
|
172
|
+
*/
|
|
173
|
+
export declare function columnReferencedInCheckExpression(expr: AST.AstNode | undefined, tableName: string, columnName: string, defaultSchemaName: string, resolveColumnInSource?: ResolveColumnInSource): boolean;
|
|
77
174
|
/**
|
|
78
175
|
* Rewrite the renamed column inside every partial-index predicate of `indexes`,
|
|
79
176
|
* in place. A predicate resolves unqualified refs against the indexed table
|
|
@@ -92,6 +189,12 @@ export declare function renameColumnInCheckExpression(expr: AST.AstNode | undefi
|
|
|
92
189
|
*
|
|
93
190
|
* The parameter is structurally typed rather than `IndexSchema[]` so this module
|
|
94
191
|
* stays free of catalog imports; `IndexSchema` satisfies it.
|
|
192
|
+
*
|
|
193
|
+
* Sharing the seeded entry point also brings its `new.` / `old.` row-image match
|
|
194
|
+
* along, which is inert here: a partial-index predicate describes rows already
|
|
195
|
+
* stored, has no written-row context, and a predicate naming one would not plan
|
|
196
|
+
* in the first place. Nothing to suppress — noted so the shared entry point does
|
|
197
|
+
* not read as an oversight.
|
|
95
198
|
*/
|
|
96
199
|
export declare function renameColumnInIndexPredicates(indexes: ReadonlyArray<{
|
|
97
200
|
readonly predicate?: AST.Expression;
|
|
@@ -109,6 +212,45 @@ export declare function renameColumnInIndexPredicates(indexes: ReadonlyArray<{
|
|
|
109
212
|
export declare function renameColumnInCheckConstraints(checks: ReadonlyArray<{
|
|
110
213
|
readonly expr: AST.Expression;
|
|
111
214
|
}> | undefined, tableName: string, oldColName: string, newColName: string, defaultSchemaName: string, resolveColumnInSource?: ResolveColumnInSource): boolean;
|
|
215
|
+
/**
|
|
216
|
+
* Rewrite the renamed column inside the two expressions a `ColumnSchema` can carry —
|
|
217
|
+
* a column DEFAULT (`b integer default (new.a + 1)`, however authored: inline, or via
|
|
218
|
+
* `ALTER TABLE … ALTER COLUMN … SET DEFAULT`, which writes the same field) and a
|
|
219
|
+
* generated column's body (`g integer generated always as (a + 1)`) — in place, for
|
|
220
|
+
* every column of the renamed table itself.
|
|
221
|
+
*
|
|
222
|
+
* The seeded {@link renameColumnInCheckExpression} entry point is correct for both, for
|
|
223
|
+
* the two halves of what the seed provides:
|
|
224
|
+
*
|
|
225
|
+
* - The implicit unaliased binding to the owning table is what makes a generated
|
|
226
|
+
* column's **bare** `a` resolve — it has no FROM clause to bind against, exactly like
|
|
227
|
+
* a CHECK.
|
|
228
|
+
* - The seed also owns the `new.` / `old.` **row-image** namespace, which is what makes a
|
|
229
|
+
* default's `new.a` resolve. A default is evaluated against the row being written, so
|
|
230
|
+
* that qualifier names this table's row image, not anything a FROM binds.
|
|
231
|
+
*
|
|
232
|
+
* Case folding (`NEW.A`) and the shadowing edge (a real table literally named `new`,
|
|
233
|
+
* reached from a subquery inside the expression) therefore behave exactly as they do for
|
|
234
|
+
* a CHECK, because the same walk decides all three.
|
|
235
|
+
*
|
|
236
|
+
* Only pass the renamed table's OWN columns. A default on a *different* table can reach
|
|
237
|
+
* this table only through a subquery, so an unqualified ref there must bind inside that
|
|
238
|
+
* subquery's FROM — that caller wants {@link renameColumnInAst}, whose walk has no seed.
|
|
239
|
+
*
|
|
240
|
+
* Same sharing and idempotence story as {@link renameColumnInCheckConstraints}: a
|
|
241
|
+
* module's rename hook rebuilds only the renamed column's `ColumnSchema` and keeps every
|
|
242
|
+
* other one by reference, and even the rebuilt one carries the SAME expression nodes
|
|
243
|
+
* (`buildConstraintsFromColumn` passes them into the reconstructed `ColumnDef` by
|
|
244
|
+
* reference and `columnDefToSchema` assigns them straight back), so one in-place rewrite
|
|
245
|
+
* reaches every holder and a second call with the same pair is a no-op.
|
|
246
|
+
*
|
|
247
|
+
* The parameter is structurally typed rather than `ColumnSchema[]` so this module stays
|
|
248
|
+
* free of catalog imports; `ColumnSchema` satisfies it.
|
|
249
|
+
*/
|
|
250
|
+
export declare function renameColumnInColumnExpressions(columns: ReadonlyArray<{
|
|
251
|
+
readonly defaultValue?: AST.Expression | null;
|
|
252
|
+
readonly generatedExpr?: AST.Expression;
|
|
253
|
+
}> | undefined, tableName: string, oldColName: string, newColName: string, defaultSchemaName: string, resolveColumnInSource?: ResolveColumnInSource): boolean;
|
|
112
254
|
/**
|
|
113
255
|
* Strip table-qualified self-references in a CHECK expression down to the
|
|
114
256
|
* unqualified form: `check (t.qty > 0)` (or `main.t.qty`) becomes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rename-rewriter.d.ts","sourceRoot":"","sources":["../../../src/schema/rename-rewriter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"rename-rewriter.d.ts","sourceRoot":"","sources":["../../../src/schema/rename-rewriter.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
+
import { spineCloneAst } from '../util/ast-spine-clone.js';
|
|
1
2
|
const eq = (a, b) => (a ?? '').toLowerCase() === (b ?? '').toLowerCase();
|
|
2
3
|
const schemaMatches = (nodeSchema, defaultSchema) => nodeSchema === undefined || eq(nodeSchema, defaultSchema);
|
|
3
|
-
// ──────────────────────────────────────────────────────────────────────
|
|
4
|
-
// Table rename
|
|
5
|
-
// ──────────────────────────────────────────────────────────────────────
|
|
6
4
|
export function renameTableInAst(node, oldName, newName, defaultSchemaName) {
|
|
7
5
|
if (!node)
|
|
8
6
|
return false;
|
|
@@ -10,9 +8,44 @@ export function renameTableInAst(node, oldName, newName, defaultSchemaName) {
|
|
|
10
8
|
visitTableRename(node, oldName, newName, defaultSchemaName, ctx);
|
|
11
9
|
return ctx.changed;
|
|
12
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Whether `node` refers to the table/view `name` in schema `defaultSchemaName` —
|
|
13
|
+
* read-only, nothing is mutated.
|
|
14
|
+
*
|
|
15
|
+
* Deliberately the SAME traversal {@link renameTableInAst} uses, run with
|
|
16
|
+
* `dryRun`, so "refers to" can never drift from "would have been rewritten by a
|
|
17
|
+
* rename". That equivalence is the whole point: the DROP guard refuses exactly
|
|
18
|
+
* the cases `ALTER TABLE … RENAME` would have followed. A second traversal — or
|
|
19
|
+
* a `renameTableInAst(clone, name, name, …)` trick, which would silently
|
|
20
|
+
* re-case identifiers — would both break it.
|
|
21
|
+
*
|
|
22
|
+
* `name` is passed as both old and new name; under `dryRun` the new name is
|
|
23
|
+
* never read.
|
|
24
|
+
*
|
|
25
|
+
* The column-level probes ({@link columnReferencedInAst},
|
|
26
|
+
* {@link columnReferencedInCheckExpression}) reach the same equivalence a
|
|
27
|
+
* different way — a real rename, to a sentinel name, over a throwaway
|
|
28
|
+
* {@link spineCloneAst} copy — because the column walker has ~8 mutation points
|
|
29
|
+
* and a CTE-re-exposure branch that reads the new name, so threading `dryRun`
|
|
30
|
+
* through it is the riskier of the two. Neither flaw of the identity-rename
|
|
31
|
+
* trick warned against above applies there: the mutated node is a discarded
|
|
32
|
+
* clone (nothing user-visible is re-cased), and the target is a fresh name no
|
|
33
|
+
* column can hold, so `newCol !== oldCol` and the re-exposure branch answers
|
|
34
|
+
* exactly as it would for a real rename to an unused name.
|
|
35
|
+
*/
|
|
36
|
+
export function tableReferencedInAst(node, name, defaultSchemaName) {
|
|
37
|
+
if (!node)
|
|
38
|
+
return false;
|
|
39
|
+
const ctx = { changed: false, dryRun: true };
|
|
40
|
+
visitTableRename(node, name, name, defaultSchemaName, ctx);
|
|
41
|
+
return ctx.changed;
|
|
42
|
+
}
|
|
13
43
|
function visitTableRename(node, oldName, newName, defaultSchemaName, ctx) {
|
|
14
44
|
if (!node)
|
|
15
45
|
return;
|
|
46
|
+
// A dry run only answers yes/no — stop as soon as the answer is known.
|
|
47
|
+
if (ctx.dryRun && ctx.changed)
|
|
48
|
+
return;
|
|
16
49
|
switch (node.type) {
|
|
17
50
|
case 'select': {
|
|
18
51
|
const stmt = node;
|
|
@@ -91,7 +124,8 @@ function visitTableRename(node, oldName, newName, defaultSchemaName, ctx) {
|
|
|
91
124
|
case 'table': {
|
|
92
125
|
const ts = node;
|
|
93
126
|
if (eq(ts.table.name, oldName) && schemaMatches(ts.table.schema, defaultSchemaName)) {
|
|
94
|
-
|
|
127
|
+
if (!ctx.dryRun)
|
|
128
|
+
ts.table.name = newName;
|
|
95
129
|
ctx.changed = true;
|
|
96
130
|
}
|
|
97
131
|
break;
|
|
@@ -176,7 +210,8 @@ function visitTableRename(node, oldName, newName, defaultSchemaName, ctx) {
|
|
|
176
210
|
case 'column': {
|
|
177
211
|
const col = node;
|
|
178
212
|
if (col.table && eq(col.table, oldName) && schemaMatches(col.schema, defaultSchemaName)) {
|
|
179
|
-
|
|
213
|
+
if (!ctx.dryRun)
|
|
214
|
+
col.table = newName;
|
|
180
215
|
ctx.changed = true;
|
|
181
216
|
}
|
|
182
217
|
break;
|
|
@@ -190,8 +225,9 @@ function visitTableRename(node, oldName, newName, defaultSchemaName, ctx) {
|
|
|
190
225
|
* Apply an in-place expression rewrite across a schema-object collection,
|
|
191
226
|
* skipping items whose expression is absent. Returns whether any item changed.
|
|
192
227
|
*
|
|
193
|
-
* Backs the
|
|
194
|
-
* below, which differ only in which field they pluck and which walker they
|
|
228
|
+
* Backs the `rename{Column,Table}In{IndexPredicates,CheckConstraints,ColumnExpressions}`
|
|
229
|
+
* entry points below, which differ only in which field they pluck and which walker they
|
|
230
|
+
* run.
|
|
195
231
|
*/
|
|
196
232
|
function rewriteEach(items, pick, rewrite) {
|
|
197
233
|
let changed = false;
|
|
@@ -228,11 +264,40 @@ export function renameTableInIndexPredicates(indexes, oldName, newName, defaultS
|
|
|
228
264
|
export function renameTableInCheckConstraints(checks, oldName, newName, defaultSchemaName) {
|
|
229
265
|
return rewriteEach(checks, cc => cc.expr, expr => renameTableInAst(expr, oldName, newName, defaultSchemaName));
|
|
230
266
|
}
|
|
267
|
+
/**
|
|
268
|
+
* Rewrite the renamed table inside the two expressions a `ColumnSchema` can carry —
|
|
269
|
+
* a column DEFAULT (`w integer default ((select min(v) from u))`, however authored:
|
|
270
|
+
* inline, or via `ALTER TABLE … ALTER COLUMN … SET DEFAULT`, which writes the same
|
|
271
|
+
* field) and a generated column's body (`g integer generated always as ((select
|
|
272
|
+
* min(u.v) from u) + id)`) — in place.
|
|
273
|
+
*
|
|
274
|
+
* Unlike the column-rename counterpart ({@link renameColumnInColumnExpressions}) there
|
|
275
|
+
* is no seeded/unseeded split: {@link renameTableInAst} resolves nothing against an
|
|
276
|
+
* implicit owning table, so the SAME entry point is correct for the renamed table's own
|
|
277
|
+
* columns (a self-referencing default, `default ((select count(*) from t))`) and for
|
|
278
|
+
* every other table's.
|
|
279
|
+
*
|
|
280
|
+
* Same sharing and idempotence story as {@link renameTableInCheckConstraints}: the
|
|
281
|
+
* `Expression` is the very AST the catalog's `TableSchema` holds, so one in-place
|
|
282
|
+
* rewrite reaches every holder and a second call with the same pair finds nothing
|
|
283
|
+
* naming `oldName` and returns false.
|
|
284
|
+
*
|
|
285
|
+
* The parameter is structurally typed rather than `ColumnSchema[]` so this module stays
|
|
286
|
+
* free of catalog imports; `ColumnSchema` satisfies it.
|
|
287
|
+
*/
|
|
288
|
+
export function renameTableInColumnExpressions(columns, oldName, newName, defaultSchemaName) {
|
|
289
|
+
const rewrite = (expr) => renameTableInAst(expr, oldName, newName, defaultSchemaName);
|
|
290
|
+
// Both walks always run — `||` on the results, not short-circuited between them.
|
|
291
|
+
const defaultsChanged = rewriteEach(columns, c => c.defaultValue ?? undefined, rewrite);
|
|
292
|
+
const generatedChanged = rewriteEach(columns, c => c.generatedExpr, rewrite);
|
|
293
|
+
return defaultsChanged || generatedChanged;
|
|
294
|
+
}
|
|
231
295
|
function rewriteIdentifierIfTable(id, oldName, newName, defaultSchemaName, ctx) {
|
|
232
296
|
if (!id)
|
|
233
297
|
return;
|
|
234
298
|
if (eq(id.name, oldName) && schemaMatches(id.schema, defaultSchemaName)) {
|
|
235
|
-
|
|
299
|
+
if (!ctx.dryRun)
|
|
300
|
+
id.name = newName;
|
|
236
301
|
ctx.changed = true;
|
|
237
302
|
}
|
|
238
303
|
}
|
|
@@ -266,6 +331,7 @@ export function renameColumnInAst(node, tableName, oldColName, newColName, defau
|
|
|
266
331
|
scopeStack: [],
|
|
267
332
|
changed: false,
|
|
268
333
|
resolveColumnInSource,
|
|
334
|
+
matchRowImageQualifier: false,
|
|
269
335
|
};
|
|
270
336
|
visitColumnRename(node, state);
|
|
271
337
|
return state.changed;
|
|
@@ -290,6 +356,20 @@ export function renameColumnInAst(node, tableName, oldColName, newColName, defau
|
|
|
290
356
|
* sources are not asked (the rewriter would need recursive column-set
|
|
291
357
|
* inference on their bodies). `renameColumnInAst` shares the same callback
|
|
292
358
|
* (passed by the view-body callers) and the same limitation.
|
|
359
|
+
*
|
|
360
|
+
* The seed also makes this walk the owner of the `new.` / `old.` **row-image**
|
|
361
|
+
* namespace: a CHECK may name the row being written explicitly
|
|
362
|
+
* (`check (new.a > 0)`, `check on delete (old.a > 0)` — `docs/sql-ddl.md`
|
|
363
|
+
* § CHECK Constraints), and those qualifiers name the owning table's row, not
|
|
364
|
+
* anything a FROM clause binds. So the qualified-ref case matches them too —
|
|
365
|
+
* but only here, never through `renameColumnInAst`, where a `new.` ref belongs
|
|
366
|
+
* to some other table's row image.
|
|
367
|
+
*
|
|
368
|
+
* That match is scope-**aware**, not depth-blind, because `new` and `old` are
|
|
369
|
+
* not reserved words in this parser: `create table "new" (…)` is legal, so a
|
|
370
|
+
* CHECK may legitimately contain `(select max("new".a) from "new")`. The match
|
|
371
|
+
* therefore requires that no FROM/WITH frame above the seed rebind the
|
|
372
|
+
* qualifier — see `matchesRowImage`.
|
|
293
373
|
*/
|
|
294
374
|
export function renameColumnInCheckExpression(expr, tableName, oldColName, newColName, defaultSchemaName, resolveColumnInSource) {
|
|
295
375
|
if (!expr)
|
|
@@ -302,6 +382,7 @@ export function renameColumnInCheckExpression(expr, tableName, oldColName, newCo
|
|
|
302
382
|
scopeStack: [],
|
|
303
383
|
changed: false,
|
|
304
384
|
resolveColumnInSource,
|
|
385
|
+
matchRowImageQualifier: true,
|
|
305
386
|
};
|
|
306
387
|
const frame = emptyFrame();
|
|
307
388
|
frame.unaliased.add(state.tableName);
|
|
@@ -314,6 +395,52 @@ export function renameColumnInCheckExpression(expr, tableName, oldColName, newCo
|
|
|
314
395
|
}
|
|
315
396
|
return state.changed;
|
|
316
397
|
}
|
|
398
|
+
/**
|
|
399
|
+
* Sentinel rename target for the two read-only column probes below. No user
|
|
400
|
+
* column can hold this name, and the probe rewrites *to* it, so it can never
|
|
401
|
+
* collide with anything the walk is looking for.
|
|
402
|
+
*/
|
|
403
|
+
const PROBE_COLUMN_NAME = '__quereus_column_probe__';
|
|
404
|
+
/**
|
|
405
|
+
* Whether `node` refers to `tableName`.`columnName` — read-only with respect to
|
|
406
|
+
* the caller's AST; a throwaway {@link spineCloneAst} copy is what gets
|
|
407
|
+
* rewritten.
|
|
408
|
+
*
|
|
409
|
+
* Same equivalence {@link tableReferencedInAst} establishes for the table verb,
|
|
410
|
+
* and for the same reason: "refers to" must mean "would have been rewritten by
|
|
411
|
+
* `ALTER TABLE … RENAME COLUMN`", or a DROP guard built on it refuses a
|
|
412
|
+
* different set of cases than the rename follows. See that function's comment
|
|
413
|
+
* for why the column verb reaches it by clone+sentinel rather than by `dryRun`.
|
|
414
|
+
*
|
|
415
|
+
* `resolveColumnInSource` is **not optional in practice**: without it the walk
|
|
416
|
+
* has no way to tell that an unqualified ref inside a subquery binds to a
|
|
417
|
+
* like-named column on the subquery's own FROM source, and a caller asking
|
|
418
|
+
* "does this body name `t.v`?" gets `true` for a body whose only `v` is
|
|
419
|
+
* another table's. Every caller should pass the catalog-backed resolver
|
|
420
|
+
* (`buildColumnSourceResolver`).
|
|
421
|
+
*
|
|
422
|
+
* NOTE: one spine clone plus one walk per probe, and the DROP COLUMN guard probes every
|
|
423
|
+
* live assertion. Trivial at the handful-of-assertions scale schemas have today, and it
|
|
424
|
+
* only runs on DDL; if a schema ever carries assertions by the hundred, filter by
|
|
425
|
+
* `tableReferencedInAst` (no clone) before paying for the column probe.
|
|
426
|
+
*/
|
|
427
|
+
export function columnReferencedInAst(node, tableName, columnName, defaultSchemaName, resolveColumnInSource) {
|
|
428
|
+
if (!node)
|
|
429
|
+
return false;
|
|
430
|
+
return renameColumnInAst(spineCloneAst(node), tableName, columnName, PROBE_COLUMN_NAME, defaultSchemaName, resolveColumnInSource);
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* {@link columnReferencedInAst} for an expression that resolves unqualified refs
|
|
434
|
+
* against an implicit binding to `tableName` — a CHECK expression or a
|
|
435
|
+
* partial-index predicate. Uses {@link renameColumnInCheckExpression}'s seeded
|
|
436
|
+
* entry point so the probe answers for exactly the scope that expression is
|
|
437
|
+
* planned in.
|
|
438
|
+
*/
|
|
439
|
+
export function columnReferencedInCheckExpression(expr, tableName, columnName, defaultSchemaName, resolveColumnInSource) {
|
|
440
|
+
if (!expr)
|
|
441
|
+
return false;
|
|
442
|
+
return renameColumnInCheckExpression(spineCloneAst(expr), tableName, columnName, PROBE_COLUMN_NAME, defaultSchemaName, resolveColumnInSource);
|
|
443
|
+
}
|
|
317
444
|
/**
|
|
318
445
|
* Rewrite the renamed column inside every partial-index predicate of `indexes`,
|
|
319
446
|
* in place. A predicate resolves unqualified refs against the indexed table
|
|
@@ -332,6 +459,12 @@ export function renameColumnInCheckExpression(expr, tableName, oldColName, newCo
|
|
|
332
459
|
*
|
|
333
460
|
* The parameter is structurally typed rather than `IndexSchema[]` so this module
|
|
334
461
|
* stays free of catalog imports; `IndexSchema` satisfies it.
|
|
462
|
+
*
|
|
463
|
+
* Sharing the seeded entry point also brings its `new.` / `old.` row-image match
|
|
464
|
+
* along, which is inert here: a partial-index predicate describes rows already
|
|
465
|
+
* stored, has no written-row context, and a predicate naming one would not plan
|
|
466
|
+
* in the first place. Nothing to suppress — noted so the shared entry point does
|
|
467
|
+
* not read as an oversight.
|
|
335
468
|
*/
|
|
336
469
|
export function renameColumnInIndexPredicates(indexes, tableName, oldColName, newColName, defaultSchemaName, resolveColumnInSource) {
|
|
337
470
|
return rewriteEach(indexes, idx => idx.predicate, expr => renameColumnInCheckExpression(expr, tableName, oldColName, newColName, defaultSchemaName, resolveColumnInSource));
|
|
@@ -349,6 +482,48 @@ export function renameColumnInIndexPredicates(indexes, tableName, oldColName, ne
|
|
|
349
482
|
export function renameColumnInCheckConstraints(checks, tableName, oldColName, newColName, defaultSchemaName, resolveColumnInSource) {
|
|
350
483
|
return rewriteEach(checks, cc => cc.expr, expr => renameColumnInCheckExpression(expr, tableName, oldColName, newColName, defaultSchemaName, resolveColumnInSource));
|
|
351
484
|
}
|
|
485
|
+
/**
|
|
486
|
+
* Rewrite the renamed column inside the two expressions a `ColumnSchema` can carry —
|
|
487
|
+
* a column DEFAULT (`b integer default (new.a + 1)`, however authored: inline, or via
|
|
488
|
+
* `ALTER TABLE … ALTER COLUMN … SET DEFAULT`, which writes the same field) and a
|
|
489
|
+
* generated column's body (`g integer generated always as (a + 1)`) — in place, for
|
|
490
|
+
* every column of the renamed table itself.
|
|
491
|
+
*
|
|
492
|
+
* The seeded {@link renameColumnInCheckExpression} entry point is correct for both, for
|
|
493
|
+
* the two halves of what the seed provides:
|
|
494
|
+
*
|
|
495
|
+
* - The implicit unaliased binding to the owning table is what makes a generated
|
|
496
|
+
* column's **bare** `a` resolve — it has no FROM clause to bind against, exactly like
|
|
497
|
+
* a CHECK.
|
|
498
|
+
* - The seed also owns the `new.` / `old.` **row-image** namespace, which is what makes a
|
|
499
|
+
* default's `new.a` resolve. A default is evaluated against the row being written, so
|
|
500
|
+
* that qualifier names this table's row image, not anything a FROM binds.
|
|
501
|
+
*
|
|
502
|
+
* Case folding (`NEW.A`) and the shadowing edge (a real table literally named `new`,
|
|
503
|
+
* reached from a subquery inside the expression) therefore behave exactly as they do for
|
|
504
|
+
* a CHECK, because the same walk decides all three.
|
|
505
|
+
*
|
|
506
|
+
* Only pass the renamed table's OWN columns. A default on a *different* table can reach
|
|
507
|
+
* this table only through a subquery, so an unqualified ref there must bind inside that
|
|
508
|
+
* subquery's FROM — that caller wants {@link renameColumnInAst}, whose walk has no seed.
|
|
509
|
+
*
|
|
510
|
+
* Same sharing and idempotence story as {@link renameColumnInCheckConstraints}: a
|
|
511
|
+
* module's rename hook rebuilds only the renamed column's `ColumnSchema` and keeps every
|
|
512
|
+
* other one by reference, and even the rebuilt one carries the SAME expression nodes
|
|
513
|
+
* (`buildConstraintsFromColumn` passes them into the reconstructed `ColumnDef` by
|
|
514
|
+
* reference and `columnDefToSchema` assigns them straight back), so one in-place rewrite
|
|
515
|
+
* reaches every holder and a second call with the same pair is a no-op.
|
|
516
|
+
*
|
|
517
|
+
* The parameter is structurally typed rather than `ColumnSchema[]` so this module stays
|
|
518
|
+
* free of catalog imports; `ColumnSchema` satisfies it.
|
|
519
|
+
*/
|
|
520
|
+
export function renameColumnInColumnExpressions(columns, tableName, oldColName, newColName, defaultSchemaName, resolveColumnInSource) {
|
|
521
|
+
const rewrite = (expr) => renameColumnInCheckExpression(expr, tableName, oldColName, newColName, defaultSchemaName, resolveColumnInSource);
|
|
522
|
+
// Both walks always run — `||` on the results, not short-circuited between them.
|
|
523
|
+
const defaultsChanged = rewriteEach(columns, c => c.defaultValue ?? undefined, rewrite);
|
|
524
|
+
const generatedChanged = rewriteEach(columns, c => c.generatedExpr, rewrite);
|
|
525
|
+
return defaultsChanged || generatedChanged;
|
|
526
|
+
}
|
|
352
527
|
function emptyFrame() {
|
|
353
528
|
return {
|
|
354
529
|
unaliased: new Set(),
|
|
@@ -509,6 +684,66 @@ function isQualifierShadowedInScope(state, qualifier) {
|
|
|
509
684
|
}
|
|
510
685
|
return false;
|
|
511
686
|
}
|
|
687
|
+
/**
|
|
688
|
+
* Whether a qualified column ref names the **row image** of the table this
|
|
689
|
+
* seeded walk was entered for — `new.<col>` / `old.<col>` inside one of its own
|
|
690
|
+
* CHECK expressions. Only the seeded entry point sets
|
|
691
|
+
* `matchRowImageQualifier`; see {@link renameColumnInCheckExpression} for why
|
|
692
|
+
* that scoping is what keeps another table's `new.` ref out of this match.
|
|
693
|
+
*
|
|
694
|
+
* A schema-qualified `main.new.a` is a real three-part table reference, never a
|
|
695
|
+
* row image, so it is excluded outright.
|
|
696
|
+
*
|
|
697
|
+
* `qualifierLower` is `col.table` already lowercased by the caller.
|
|
698
|
+
*/
|
|
699
|
+
function matchesRowImage(state, col, qualifierLower) {
|
|
700
|
+
if (!state.matchRowImageQualifier)
|
|
701
|
+
return false;
|
|
702
|
+
if (col.schema !== undefined)
|
|
703
|
+
return false;
|
|
704
|
+
if (qualifierLower !== 'new' && qualifierLower !== 'old')
|
|
705
|
+
return false;
|
|
706
|
+
return !isQualifierReboundAboveSeed(state, qualifierLower);
|
|
707
|
+
}
|
|
708
|
+
/**
|
|
709
|
+
* Whether any real FROM / WITH frame rebinds `qualifier` to a row source of its
|
|
710
|
+
* own, which would make a `new.` / `old.` ref name that source rather than the
|
|
711
|
+
* row image. `new` and `old` are not reserved words here — `create table "new"`
|
|
712
|
+
* is legal — so this scan is what stops the row-image match from false-firing
|
|
713
|
+
* inside `check ((select max("new".a) from "new") >= 0)`.
|
|
714
|
+
*
|
|
715
|
+
* The scan starts at index 1: frame 0 is the implicit seed
|
|
716
|
+
* {@link renameColumnInCheckExpression} pushes for the owning table, which is
|
|
717
|
+
* not a FROM binding and must not count as a rebind. All four ways a frame can
|
|
718
|
+
* bind a qualifier are checked — an unaliased source, an alias, a CTE name in
|
|
719
|
+
* scope, and a shadowing-but-not-exposing CTE source.
|
|
720
|
+
*
|
|
721
|
+
* Deliberately "any enclosing frame wins" rather than innermost-first: a frame
|
|
722
|
+
* only sits above index 0 while the walk is *inside* the subquery that pushed
|
|
723
|
+
* it, so every such frame really does enclose the reference. A top-level
|
|
724
|
+
* `new.a` in `check (new.a > 0 and (select count(*) from "new") >= 0)` is
|
|
725
|
+
* visited with only the seed on the stack and still matches.
|
|
726
|
+
*
|
|
727
|
+
* NOTE: the residual is a *correlated* `new.<col>` written inside a subquery
|
|
728
|
+
* that selects from a real table named `new` — left alone by both the rewrite
|
|
729
|
+
* and the drop refusal, since the qualifier is ambiguous there anyway. If that
|
|
730
|
+
* ever needs to resolve to the row image, it needs a spelling that distinguishes
|
|
731
|
+
* the two (the SQL standard has none), not a change to this scan.
|
|
732
|
+
*/
|
|
733
|
+
function isQualifierReboundAboveSeed(state, qualifier) {
|
|
734
|
+
for (let i = 1; i < state.scopeStack.length; i++) {
|
|
735
|
+
const frame = state.scopeStack[i];
|
|
736
|
+
if (frame.unaliased.has(qualifier))
|
|
737
|
+
return true;
|
|
738
|
+
if (frame.aliasMap.has(qualifier))
|
|
739
|
+
return true;
|
|
740
|
+
if (frame.ctesInScope.has(qualifier))
|
|
741
|
+
return true;
|
|
742
|
+
if (frame.ctesShadowingSource.has(qualifier))
|
|
743
|
+
return true;
|
|
744
|
+
}
|
|
745
|
+
return false;
|
|
746
|
+
}
|
|
512
747
|
function visitColumnRename(node, state) {
|
|
513
748
|
if (!node)
|
|
514
749
|
return;
|
|
@@ -830,7 +1065,11 @@ function visitColumnRename(node, state) {
|
|
|
830
1065
|
(col.schema === undefined || eq(col.schema, state.defaultSchema)) &&
|
|
831
1066
|
!isQualifierShadowedInScope(state, qualifierLower);
|
|
832
1067
|
const viaAlias = aliasResolvesToTable(state, col.table);
|
|
833
|
-
|
|
1068
|
+
// Row-image match is tried LAST so a table genuinely named `new` or
|
|
1069
|
+
// `old` that is itself the renamed table keeps resolving through
|
|
1070
|
+
// `directHit` exactly as it did before this path existed.
|
|
1071
|
+
const rowImageHit = !directHit && !viaAlias && matchesRowImage(state, col, qualifierLower);
|
|
1072
|
+
if (directHit || viaAlias || rowImageHit) {
|
|
834
1073
|
col.name = state.newCol;
|
|
835
1074
|
state.changed = true;
|
|
836
1075
|
}
|
|
@@ -971,6 +1210,12 @@ function isResultColumnExposure(col, bodyFrame, state) {
|
|
|
971
1210
|
* is the reserved written-row namespace no FROM source legitimately shadows), so
|
|
972
1211
|
* no scope tracking applies — narrower and simpler than the scope-aware walkers
|
|
973
1212
|
* above. Returns whether any reference was rewritten.
|
|
1213
|
+
*
|
|
1214
|
+
* Depth-blind **on purpose**, unlike the row-image match in `matchesRowImage`.
|
|
1215
|
+
* The two look alike but answer different questions: this one rewrites by view
|
|
1216
|
+
* *output* name inside a `with inverse` expr, whose grammar admits no FROM
|
|
1217
|
+
* clause that could rebind `new`, whereas a CHECK body may contain a subquery
|
|
1218
|
+
* selecting from a real table named `"new"` and so must consult the scope stack.
|
|
974
1219
|
*/
|
|
975
1220
|
function renameNewQualifiedRefs(expr, renames) {
|
|
976
1221
|
let changed = false;
|