From 0f3613042ba01f2e3242ae91971219d93cfd691f Mon Sep 17 00:00:00 2001 From: Faizan Qazi Date: Mon, 13 Mar 2023 15:31:41 -0400 Subject: [PATCH] sql/schemachanger: constraint name is not populated in errors Previously, the declarative schema changer set, the constraint name causing errors to have place holders. To address this, this patch will set the constraint name when the constraint becomes visible and impacts DML statements. Release note: None Epic: None --- pkg/cli/testdata/declarative-rules/deprules | 147 ++++++++- .../rules/current/dep_add_constraint.go | 18 +- .../rules/current/dep_drop_constraint.go | 37 ++- .../scplan/internal/rules/current/helpers.go | 8 + .../internal/rules/current/testdata/deprules | 294 ++++++++++++++++-- .../scplan/testdata/alter_table_add_check | 28 +- .../scplan/testdata/alter_table_add_check_udf | 28 +- .../schemachanger/scplan/testdata/drop_index | 32 +- .../schemachanger/scplan/testdata/drop_table | 48 +-- .../end_to_end/alter_table_add_check_udf | 16 +- .../end_to_end/alter_table_add_check_vanilla | 34 +- .../alter_table_add_check_with_seq_and_udt | 16 +- .../end_to_end/alter_table_add_foreign_key | 49 ++- .../alter_table_add_unique_without_index | 34 +- .../alter_table_alter_primary_key_using_hash | 18 +- .../alter_table_drop_constraint_check | 16 +- .../end_to_end/alter_table_drop_constraint_fk | 30 +- .../alter_table_drop_constraint_uwi | 14 +- .../alter_table_validate_constraint | 18 +- .../end_to_end/drop_index_hash_sharded_index | 14 +- .../explain/alter_table_add_check_udf | 31 +- .../alter_table_add_check_udf.rollback_1_of_2 | 8 +- .../alter_table_add_check_udf.rollback_2_of_2 | 8 +- .../explain/alter_table_add_check_vanilla | 31 +- ...er_table_add_check_vanilla.rollback_1_of_2 | 8 +- ...er_table_add_check_vanilla.rollback_2_of_2 | 8 +- .../alter_table_add_check_with_seq_and_udt | 31 +- ...add_check_with_seq_and_udt.rollback_1_of_2 | 8 +- ...add_check_with_seq_and_udt.rollback_2_of_2 | 8 +- .../explain/alter_table_add_foreign_key | 34 +- ...lter_table_add_foreign_key.rollback_1_of_2 | 11 +- ...lter_table_add_foreign_key.rollback_2_of_2 | 11 +- .../alter_table_add_unique_without_index | 34 +- ...e_add_unique_without_index.rollback_1_of_2 | 11 +- ...e_add_unique_without_index.rollback_2_of_2 | 11 +- .../alter_table_alter_primary_key_using_hash | 23 +- ...ter_primary_key_using_hash.rollback_1_of_7 | 6 +- ...ter_primary_key_using_hash.rollback_2_of_7 | 6 +- ...ter_primary_key_using_hash.rollback_3_of_7 | 6 +- ...ter_primary_key_using_hash.rollback_4_of_7 | 6 +- ...ter_primary_key_using_hash.rollback_5_of_7 | 6 +- ...ter_primary_key_using_hash.rollback_6_of_7 | 6 +- ...ter_primary_key_using_hash.rollback_7_of_7 | 6 +- .../explain/alter_table_drop_constraint_check | 31 +- .../explain/alter_table_drop_constraint_fk | 31 +- .../explain/alter_table_drop_constraint_uwi | 31 +- .../explain/alter_table_validate_constraint | 29 +- ..._table_validate_constraint.rollback_1_of_2 | 8 +- ..._table_validate_constraint.rollback_2_of_2 | 8 +- .../explain/drop_index_hash_sharded_index | 31 +- .../explain_verbose/alter_table_add_check_udf | 90 +++--- .../alter_table_add_check_udf.rollback_1_of_2 | 29 +- .../alter_table_add_check_udf.rollback_2_of_2 | 29 +- .../alter_table_add_check_vanilla | 90 +++--- ...er_table_add_check_vanilla.rollback_1_of_2 | 29 +- ...er_table_add_check_vanilla.rollback_2_of_2 | 29 +- .../alter_table_add_check_with_seq_and_udt | 88 +++--- ...add_check_with_seq_and_udt.rollback_1_of_2 | 29 +- ...add_check_with_seq_and_udt.rollback_2_of_2 | 29 +- .../alter_table_add_foreign_key | 97 +++--- ...lter_table_add_foreign_key.rollback_1_of_2 | 32 +- ...lter_table_add_foreign_key.rollback_2_of_2 | 32 +- .../alter_table_add_unique_without_index | 91 +++--- ...e_add_unique_without_index.rollback_1_of_2 | 32 +- ...e_add_unique_without_index.rollback_2_of_2 | 32 +- .../alter_table_alter_primary_key_using_hash | 56 ++-- ...ter_primary_key_using_hash.rollback_1_of_7 | 19 +- ...ter_primary_key_using_hash.rollback_2_of_7 | 19 +- ...ter_primary_key_using_hash.rollback_3_of_7 | 19 +- ...ter_primary_key_using_hash.rollback_4_of_7 | 19 +- ...ter_primary_key_using_hash.rollback_5_of_7 | 19 +- ...ter_primary_key_using_hash.rollback_6_of_7 | 19 +- ...ter_primary_key_using_hash.rollback_7_of_7 | 19 +- .../alter_table_drop_constraint_check | 88 +++--- .../alter_table_drop_constraint_fk | 88 +++--- .../alter_table_drop_constraint_uwi | 88 +++--- .../alter_table_validate_constraint | 84 ++--- ..._table_validate_constraint.rollback_1_of_2 | 29 +- ..._table_validate_constraint.rollback_2_of_2 | 29 +- .../drop_index_hash_sharded_index | 88 +++--- 80 files changed, 1791 insertions(+), 1036 deletions(-) diff --git a/pkg/cli/testdata/declarative-rules/deprules b/pkg/cli/testdata/declarative-rules/deprules index 121c11cdbda6..226639517e1b 100644 --- a/pkg/cli/testdata/declarative-rules/deprules +++ b/pkg/cli/testdata/declarative-rules/deprules @@ -293,6 +293,114 @@ deprules - descriptorIsNotBeingDropped-23.1($prev) - joinTargetNode($prev, $prev-Target, $prev-Node) - joinTargetNode($next, $next-Target, $next-Node) +- name: Constraint should be hidden before name + from: constraint-name-Node + kind: SameStagePrecedence + to: constraint-Node + query: + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - joinOnConstraintID($constraint-name, $constraint, $table-id, $constraint-id) + - toAbsent($constraint-name-Target, $constraint-Target) + - $constraint-name-Node[CurrentStatus] = ABSENT + - $constraint-Node[CurrentStatus] = ABSENT + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) + - joinTargetNode($constraint, $constraint-Target, $constraint-Node) +- name: Constraint should be hidden before name + from: constraint-name-Node + kind: SameStagePrecedence + to: constraint-Node + query: + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - joinOnConstraintID($constraint-name, $constraint, $table-id, $constraint-id) + - transient($constraint-name-Target, $constraint-Target) + - $constraint-name-Node[CurrentStatus] = TRANSIENT_ABSENT + - $constraint-Node[CurrentStatus] = TRANSIENT_ABSENT + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) + - joinTargetNode($constraint, $constraint-Target, $constraint-Node) +- name: Constraint should be hidden before name + from: constraint-name-Node + kind: SameStagePrecedence + to: constraint-Node + query: + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - joinOnConstraintID($constraint-name, $constraint, $table-id, $constraint-id) + - $constraint-name-Target[TargetStatus] = TRANSIENT_ABSENT + - $constraint-name-Node[CurrentStatus] = TRANSIENT_ABSENT + - $constraint-Target[TargetStatus] = ABSENT + - $constraint-Node[CurrentStatus] = ABSENT + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) + - joinTargetNode($constraint, $constraint-Target, $constraint-Node) +- name: Constraint should be hidden before name + from: constraint-name-Node + kind: SameStagePrecedence + to: constraint-Node + query: + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - joinOnConstraintID($constraint-name, $constraint, $table-id, $constraint-id) + - $constraint-name-Target[TargetStatus] = ABSENT + - $constraint-name-Node[CurrentStatus] = ABSENT + - $constraint-Target[TargetStatus] = TRANSIENT_ABSENT + - $constraint-Node[CurrentStatus] = TRANSIENT_ABSENT + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) + - joinTargetNode($constraint, $constraint-Target, $constraint-Node) +- name: Constraint should be hidden before name + from: constraint-Node + kind: Precedence + to: constraint-name-Node + query: + - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - joinOnConstraintID($constraint, $constraint-name, $table-id, $constraint-id) + - toAbsent($constraint-Target, $constraint-name-Target) + - $constraint-Node[CurrentStatus] = VALIDATED + - $constraint-name-Node[CurrentStatus] = ABSENT + - joinTargetNode($constraint, $constraint-Target, $constraint-Node) + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) +- name: Constraint should be hidden before name + from: constraint-Node + kind: Precedence + to: constraint-name-Node + query: + - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - joinOnConstraintID($constraint, $constraint-name, $table-id, $constraint-id) + - transient($constraint-Target, $constraint-name-Target) + - $constraint-Node[CurrentStatus] = TRANSIENT_VALIDATED + - $constraint-name-Node[CurrentStatus] = TRANSIENT_ABSENT + - joinTargetNode($constraint, $constraint-Target, $constraint-Node) + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) +- name: Constraint should be hidden before name + from: constraint-Node + kind: Precedence + to: constraint-name-Node + query: + - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - joinOnConstraintID($constraint, $constraint-name, $table-id, $constraint-id) + - $constraint-Target[TargetStatus] = TRANSIENT_ABSENT + - $constraint-Node[CurrentStatus] = TRANSIENT_VALIDATED + - $constraint-name-Target[TargetStatus] = ABSENT + - $constraint-name-Node[CurrentStatus] = ABSENT + - joinTargetNode($constraint, $constraint-Target, $constraint-Node) + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) +- name: Constraint should be hidden before name + from: constraint-Node + kind: Precedence + to: constraint-name-Node + query: + - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - joinOnConstraintID($constraint, $constraint-name, $table-id, $constraint-id) + - $constraint-Target[TargetStatus] = ABSENT + - $constraint-Node[CurrentStatus] = VALIDATED + - $constraint-name-Target[TargetStatus] = TRANSIENT_ABSENT + - $constraint-name-Node[CurrentStatus] = TRANSIENT_ABSENT + - joinTargetNode($constraint, $constraint-Target, $constraint-Node) + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) - name: DEFAULT or ON UPDATE existence precedes writes to column from: expr-Node kind: Precedence @@ -1779,7 +1887,7 @@ deprules kind: SameStagePrecedence to: complex-constraint-Node query: - - $dependent[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependent[Type] = '*scpb.ConstraintComment' - $complex-constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - joinOnConstraintID($dependent, $complex-constraint, $table-id, $constraint-id) - ToPublicOrTransient($dependent-Target, $complex-constraint-Target) @@ -1793,7 +1901,7 @@ deprules to: dependent-Node query: - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - - $dependent[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependent[Type] = '*scpb.ConstraintComment' - joinOnConstraintID($constraint, $dependent, $table-id, $constraint-id) - toAbsent($constraint-Target, $dependent-Target) - $constraint-Node[CurrentStatus] = VALIDATED @@ -1806,7 +1914,7 @@ deprules to: dependent-Node query: - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - - $dependent[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependent[Type] = '*scpb.ConstraintComment' - joinOnConstraintID($constraint, $dependent, $table-id, $constraint-id) - transient($constraint-Target, $dependent-Target) - $constraint-Node[CurrentStatus] = TRANSIENT_VALIDATED @@ -1819,7 +1927,7 @@ deprules to: dependent-Node query: - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - - $dependent[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependent[Type] = '*scpb.ConstraintComment' - joinOnConstraintID($constraint, $dependent, $table-id, $constraint-id) - $constraint-Target[TargetStatus] = TRANSIENT_ABSENT - $constraint-Node[CurrentStatus] = TRANSIENT_VALIDATED @@ -1833,7 +1941,7 @@ deprules to: dependent-Node query: - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - - $dependent[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependent[Type] = '*scpb.ConstraintComment' - joinOnConstraintID($constraint, $dependent, $table-id, $constraint-id) - $constraint-Target[TargetStatus] = ABSENT - $constraint-Node[CurrentStatus] = VALIDATED @@ -2047,7 +2155,7 @@ deprules kind: Precedence to: constraint-Node query: - - $dependents[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependents[Type] = '*scpb.ConstraintComment' - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - joinOnConstraintID($dependents, $constraint, $table-id, $constraint-id) - toAbsent($dependents-Target, $constraint-Target) @@ -2060,7 +2168,7 @@ deprules kind: Precedence to: constraint-Node query: - - $dependents[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependents[Type] = '*scpb.ConstraintComment' - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - joinOnConstraintID($dependents, $constraint, $table-id, $constraint-id) - transient($dependents-Target, $constraint-Target) @@ -2073,7 +2181,7 @@ deprules kind: Precedence to: constraint-Node query: - - $dependents[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependents[Type] = '*scpb.ConstraintComment' - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - joinOnConstraintID($dependents, $constraint, $table-id, $constraint-id) - $dependents-Target[TargetStatus] = TRANSIENT_ABSENT @@ -2087,7 +2195,7 @@ deprules kind: Precedence to: constraint-Node query: - - $dependents[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependents[Type] = '*scpb.ConstraintComment' - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - joinOnConstraintID($dependents, $constraint, $table-id, $constraint-id) - $dependents-Target[TargetStatus] = ABSENT @@ -2155,7 +2263,7 @@ deprules kind: SameStagePrecedence to: constraint-Node query: - - $dependents[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependents[Type] = '*scpb.ConstraintComment' - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraintUnvalidated'] - joinOnConstraintID($dependents, $constraint, $table-id, $constraint-id) - toAbsent($dependents-Target, $constraint-Target) @@ -2168,7 +2276,7 @@ deprules kind: SameStagePrecedence to: constraint-Node query: - - $dependents[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependents[Type] = '*scpb.ConstraintComment' - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraintUnvalidated'] - joinOnConstraintID($dependents, $constraint, $table-id, $constraint-id) - transient($dependents-Target, $constraint-Target) @@ -2181,7 +2289,7 @@ deprules kind: SameStagePrecedence to: constraint-Node query: - - $dependents[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependents[Type] = '*scpb.ConstraintComment' - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraintUnvalidated'] - joinOnConstraintID($dependents, $constraint, $table-id, $constraint-id) - $dependents-Target[TargetStatus] = TRANSIENT_ABSENT @@ -2195,7 +2303,7 @@ deprules kind: SameStagePrecedence to: constraint-Node query: - - $dependents[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependents[Type] = '*scpb.ConstraintComment' - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraintUnvalidated'] - joinOnConstraintID($dependents, $constraint, $table-id, $constraint-id) - $dependents-Target[TargetStatus] = ABSENT @@ -3279,6 +3387,19 @@ deprules - $dependent-Node[CurrentStatus] = PUBLIC - joinTargetNode($simple-constraint, $simple-constraint-Target, $simple-constraint-Node) - joinTargetNode($dependent, $dependent-Target, $dependent-Node) +- name: simple constraint visible before name + from: simple-constraint-Node + kind: SameStagePrecedence + to: constraint-name-Node + query: + - $simple-constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - joinOnConstraintID($simple-constraint, $constraint-name, $table-id, $constraint-id) + - ToPublicOrTransient($simple-constraint-Target, $constraint-name-Target) + - $simple-constraint-Node[CurrentStatus] = WRITE_ONLY + - $constraint-name-Node[CurrentStatus] = PUBLIC + - joinTargetNode($simple-constraint, $simple-constraint-Target, $simple-constraint-Node) + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) - name: swapped primary index public before column from: index-Node kind: Precedence diff --git a/pkg/sql/schemachanger/scplan/internal/rules/current/dep_add_constraint.go b/pkg/sql/schemachanger/scplan/internal/rules/current/dep_add_constraint.go index 5936f5d333fa..035f2891531a 100644 --- a/pkg/sql/schemachanger/scplan/internal/rules/current/dep_add_constraint.go +++ b/pkg/sql/schemachanger/scplan/internal/rules/current/dep_add_constraint.go @@ -26,7 +26,7 @@ func init() { "dependent", "complex-constraint", func(from, to NodeVars) rel.Clauses { return rel.Clauses{ - from.TypeFilter(rulesVersionKey, isConstraintDependent), + from.TypeFilter(rulesVersionKey, isConstraintDependent, Not(isConstraintWithIndexName)), to.TypeFilter(rulesVersionKey, isNonIndexBackedConstraint, isSubjectTo2VersionInvariant), JoinOnConstraintID(from, to, "table-id", "constraint-id"), StatusesToPublicOrTransient(from, scpb.Status_PUBLIC, to, scpb.Status_PUBLIC), @@ -47,4 +47,20 @@ func init() { } }, ) + + // Constraint name should be assigned right before it becomes visible, otherwise + // we won't have the correct message inside errors. + registerDepRule( + "simple constraint visible before name", + scgraph.SameStagePrecedence, + "simple-constraint", "constraint-name", + func(from, to NodeVars) rel.Clauses { + return rel.Clauses{ + from.TypeFilter(rulesVersionKey, isNonIndexBackedConstraint), + to.Type((*scpb.ConstraintWithoutIndexName)(nil)), + JoinOnConstraintID(from, to, "table-id", "constraint-id"), + StatusesToPublicOrTransient(from, scpb.Status_WRITE_ONLY, to, scpb.Status_PUBLIC), + } + }, + ) } diff --git a/pkg/sql/schemachanger/scplan/internal/rules/current/dep_drop_constraint.go b/pkg/sql/schemachanger/scplan/internal/rules/current/dep_drop_constraint.go index 24f003668b43..9f243daf35bb 100644 --- a/pkg/sql/schemachanger/scplan/internal/rules/current/dep_drop_constraint.go +++ b/pkg/sql/schemachanger/scplan/internal/rules/current/dep_drop_constraint.go @@ -29,7 +29,7 @@ func init() { func(from, to NodeVars) rel.Clauses { return rel.Clauses{ from.TypeFilter(rulesVersionKey, isNonIndexBackedConstraint, isSubjectTo2VersionInvariant), - to.TypeFilter(rulesVersionKey, isConstraintDependent), + to.TypeFilter(rulesVersionKey, isConstraintDependent, Not(isConstraintWithIndexName)), JoinOnConstraintID(from, to, "table-id", "constraint-id"), } }, @@ -42,7 +42,7 @@ func init() { scpb.Status_ABSENT, scpb.Status_ABSENT, func(from, to NodeVars) rel.Clauses { return rel.Clauses{ - from.TypeFilter(rulesVersionKey, isConstraintDependent), + from.TypeFilter(rulesVersionKey, isConstraintDependent, Not(isConstraintWithIndexName)), to.TypeFilter(rulesVersionKey, isNonIndexBackedConstraint, isSubjectTo2VersionInvariant), JoinOnConstraintID(from, to, "table-id", "constraint-id"), } @@ -61,10 +61,41 @@ func init() { scpb.Status_ABSENT, scpb.Status_ABSENT, func(from, to NodeVars) rel.Clauses { return rel.Clauses{ - from.TypeFilter(rulesVersionKey, isConstraintDependent), + from.TypeFilter(rulesVersionKey, isConstraintDependent, Not(isConstraintWithIndexName)), to.TypeFilter(rulesVersionKey, isNonIndexBackedConstraint, Not(isSubjectTo2VersionInvariant)), JoinOnConstraintID(from, to, "table-id", "constraint-id"), } }, ) + + // Constraint name should be cleared right before the constraint is no + // longer visible. + registerDepRuleForDrop( + "Constraint should be hidden before name", + scgraph.SameStagePrecedence, + "constraint-name", "constraint", + scpb.Status_ABSENT, scpb.Status_ABSENT, + func(from, to NodeVars) rel.Clauses { + return rel.Clauses{ + from.Type((*scpb.ConstraintWithoutIndexName)(nil)), + to.TypeFilter(rulesVersionKey, isNonIndexBackedConstraint), + JoinOnConstraintID(from, to, "table-id", "constraint-id"), + } + }, + ) + // Constraint should be validated before the constraint name is attempted + // to be cleaned. + registerDepRuleForDrop( + "Constraint should be hidden before name", + scgraph.Precedence, + "constraint", "constraint-name", + scpb.Status_VALIDATED, scpb.Status_ABSENT, + func(from, to NodeVars) rel.Clauses { + return rel.Clauses{ + from.TypeFilter(rulesVersionKey, isNonIndexBackedConstraint), + to.Type((*scpb.ConstraintWithoutIndexName)(nil)), + JoinOnConstraintID(from, to, "table-id", "constraint-id"), + } + }, + ) } diff --git a/pkg/sql/schemachanger/scplan/internal/rules/current/helpers.go b/pkg/sql/schemachanger/scplan/internal/rules/current/helpers.go index 0ec8c63a07f2..8fb6ea182591 100644 --- a/pkg/sql/schemachanger/scplan/internal/rules/current/helpers.go +++ b/pkg/sql/schemachanger/scplan/internal/rules/current/helpers.go @@ -264,6 +264,14 @@ func isConstraintDependent(e scpb.Element) bool { return false } +func isConstraintWithIndexName(e scpb.Element) bool { + switch e.(type) { + case *scpb.ConstraintWithoutIndexName: + return true + } + return false +} + func isData(e scpb.Element) bool { switch e.(type) { case *scpb.DatabaseData: diff --git a/pkg/sql/schemachanger/scplan/internal/rules/current/testdata/deprules b/pkg/sql/schemachanger/scplan/internal/rules/current/testdata/deprules index 4c23e43216aa..a50201787ab6 100644 --- a/pkg/sql/schemachanger/scplan/internal/rules/current/testdata/deprules +++ b/pkg/sql/schemachanger/scplan/internal/rules/current/testdata/deprules @@ -290,6 +290,114 @@ deprules - descriptorIsNotBeingDropped-23.1($prev) - joinTargetNode($prev, $prev-Target, $prev-Node) - joinTargetNode($next, $next-Target, $next-Node) +- name: Constraint should be hidden before name + from: constraint-name-Node + kind: SameStagePrecedence + to: constraint-Node + query: + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - joinOnConstraintID($constraint-name, $constraint, $table-id, $constraint-id) + - toAbsent($constraint-name-Target, $constraint-Target) + - $constraint-name-Node[CurrentStatus] = ABSENT + - $constraint-Node[CurrentStatus] = ABSENT + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) + - joinTargetNode($constraint, $constraint-Target, $constraint-Node) +- name: Constraint should be hidden before name + from: constraint-name-Node + kind: SameStagePrecedence + to: constraint-Node + query: + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - joinOnConstraintID($constraint-name, $constraint, $table-id, $constraint-id) + - transient($constraint-name-Target, $constraint-Target) + - $constraint-name-Node[CurrentStatus] = TRANSIENT_ABSENT + - $constraint-Node[CurrentStatus] = TRANSIENT_ABSENT + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) + - joinTargetNode($constraint, $constraint-Target, $constraint-Node) +- name: Constraint should be hidden before name + from: constraint-name-Node + kind: SameStagePrecedence + to: constraint-Node + query: + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - joinOnConstraintID($constraint-name, $constraint, $table-id, $constraint-id) + - $constraint-name-Target[TargetStatus] = TRANSIENT_ABSENT + - $constraint-name-Node[CurrentStatus] = TRANSIENT_ABSENT + - $constraint-Target[TargetStatus] = ABSENT + - $constraint-Node[CurrentStatus] = ABSENT + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) + - joinTargetNode($constraint, $constraint-Target, $constraint-Node) +- name: Constraint should be hidden before name + from: constraint-name-Node + kind: SameStagePrecedence + to: constraint-Node + query: + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - joinOnConstraintID($constraint-name, $constraint, $table-id, $constraint-id) + - $constraint-name-Target[TargetStatus] = ABSENT + - $constraint-name-Node[CurrentStatus] = ABSENT + - $constraint-Target[TargetStatus] = TRANSIENT_ABSENT + - $constraint-Node[CurrentStatus] = TRANSIENT_ABSENT + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) + - joinTargetNode($constraint, $constraint-Target, $constraint-Node) +- name: Constraint should be hidden before name + from: constraint-Node + kind: Precedence + to: constraint-name-Node + query: + - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - joinOnConstraintID($constraint, $constraint-name, $table-id, $constraint-id) + - toAbsent($constraint-Target, $constraint-name-Target) + - $constraint-Node[CurrentStatus] = VALIDATED + - $constraint-name-Node[CurrentStatus] = ABSENT + - joinTargetNode($constraint, $constraint-Target, $constraint-Node) + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) +- name: Constraint should be hidden before name + from: constraint-Node + kind: Precedence + to: constraint-name-Node + query: + - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - joinOnConstraintID($constraint, $constraint-name, $table-id, $constraint-id) + - transient($constraint-Target, $constraint-name-Target) + - $constraint-Node[CurrentStatus] = TRANSIENT_VALIDATED + - $constraint-name-Node[CurrentStatus] = TRANSIENT_ABSENT + - joinTargetNode($constraint, $constraint-Target, $constraint-Node) + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) +- name: Constraint should be hidden before name + from: constraint-Node + kind: Precedence + to: constraint-name-Node + query: + - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - joinOnConstraintID($constraint, $constraint-name, $table-id, $constraint-id) + - $constraint-Target[TargetStatus] = TRANSIENT_ABSENT + - $constraint-Node[CurrentStatus] = TRANSIENT_VALIDATED + - $constraint-name-Target[TargetStatus] = ABSENT + - $constraint-name-Node[CurrentStatus] = ABSENT + - joinTargetNode($constraint, $constraint-Target, $constraint-Node) + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) +- name: Constraint should be hidden before name + from: constraint-Node + kind: Precedence + to: constraint-name-Node + query: + - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - joinOnConstraintID($constraint, $constraint-name, $table-id, $constraint-id) + - $constraint-Target[TargetStatus] = ABSENT + - $constraint-Node[CurrentStatus] = VALIDATED + - $constraint-name-Target[TargetStatus] = TRANSIENT_ABSENT + - $constraint-name-Node[CurrentStatus] = TRANSIENT_ABSENT + - joinTargetNode($constraint, $constraint-Target, $constraint-Node) + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) - name: DEFAULT or ON UPDATE existence precedes writes to column from: expr-Node kind: Precedence @@ -1776,7 +1884,7 @@ deprules kind: SameStagePrecedence to: complex-constraint-Node query: - - $dependent[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependent[Type] = '*scpb.ConstraintComment' - $complex-constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - joinOnConstraintID($dependent, $complex-constraint, $table-id, $constraint-id) - ToPublicOrTransient($dependent-Target, $complex-constraint-Target) @@ -1790,7 +1898,7 @@ deprules to: dependent-Node query: - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - - $dependent[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependent[Type] = '*scpb.ConstraintComment' - joinOnConstraintID($constraint, $dependent, $table-id, $constraint-id) - toAbsent($constraint-Target, $dependent-Target) - $constraint-Node[CurrentStatus] = VALIDATED @@ -1803,7 +1911,7 @@ deprules to: dependent-Node query: - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - - $dependent[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependent[Type] = '*scpb.ConstraintComment' - joinOnConstraintID($constraint, $dependent, $table-id, $constraint-id) - transient($constraint-Target, $dependent-Target) - $constraint-Node[CurrentStatus] = TRANSIENT_VALIDATED @@ -1816,7 +1924,7 @@ deprules to: dependent-Node query: - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - - $dependent[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependent[Type] = '*scpb.ConstraintComment' - joinOnConstraintID($constraint, $dependent, $table-id, $constraint-id) - $constraint-Target[TargetStatus] = TRANSIENT_ABSENT - $constraint-Node[CurrentStatus] = TRANSIENT_VALIDATED @@ -1830,7 +1938,7 @@ deprules to: dependent-Node query: - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - - $dependent[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependent[Type] = '*scpb.ConstraintComment' - joinOnConstraintID($constraint, $dependent, $table-id, $constraint-id) - $constraint-Target[TargetStatus] = ABSENT - $constraint-Node[CurrentStatus] = VALIDATED @@ -2044,7 +2152,7 @@ deprules kind: Precedence to: constraint-Node query: - - $dependents[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependents[Type] = '*scpb.ConstraintComment' - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - joinOnConstraintID($dependents, $constraint, $table-id, $constraint-id) - toAbsent($dependents-Target, $constraint-Target) @@ -2057,7 +2165,7 @@ deprules kind: Precedence to: constraint-Node query: - - $dependents[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependents[Type] = '*scpb.ConstraintComment' - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - joinOnConstraintID($dependents, $constraint, $table-id, $constraint-id) - transient($dependents-Target, $constraint-Target) @@ -2070,7 +2178,7 @@ deprules kind: Precedence to: constraint-Node query: - - $dependents[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependents[Type] = '*scpb.ConstraintComment' - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - joinOnConstraintID($dependents, $constraint, $table-id, $constraint-id) - $dependents-Target[TargetStatus] = TRANSIENT_ABSENT @@ -2084,7 +2192,7 @@ deprules kind: Precedence to: constraint-Node query: - - $dependents[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependents[Type] = '*scpb.ConstraintComment' - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - joinOnConstraintID($dependents, $constraint, $table-id, $constraint-id) - $dependents-Target[TargetStatus] = ABSENT @@ -2152,7 +2260,7 @@ deprules kind: SameStagePrecedence to: constraint-Node query: - - $dependents[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependents[Type] = '*scpb.ConstraintComment' - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraintUnvalidated'] - joinOnConstraintID($dependents, $constraint, $table-id, $constraint-id) - toAbsent($dependents-Target, $constraint-Target) @@ -2165,7 +2273,7 @@ deprules kind: SameStagePrecedence to: constraint-Node query: - - $dependents[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependents[Type] = '*scpb.ConstraintComment' - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraintUnvalidated'] - joinOnConstraintID($dependents, $constraint, $table-id, $constraint-id) - transient($dependents-Target, $constraint-Target) @@ -2178,7 +2286,7 @@ deprules kind: SameStagePrecedence to: constraint-Node query: - - $dependents[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependents[Type] = '*scpb.ConstraintComment' - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraintUnvalidated'] - joinOnConstraintID($dependents, $constraint, $table-id, $constraint-id) - $dependents-Target[TargetStatus] = TRANSIENT_ABSENT @@ -2192,7 +2300,7 @@ deprules kind: SameStagePrecedence to: constraint-Node query: - - $dependents[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependents[Type] = '*scpb.ConstraintComment' - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraintUnvalidated'] - joinOnConstraintID($dependents, $constraint, $table-id, $constraint-id) - $dependents-Target[TargetStatus] = ABSENT @@ -3276,6 +3384,19 @@ deprules - $dependent-Node[CurrentStatus] = PUBLIC - joinTargetNode($simple-constraint, $simple-constraint-Target, $simple-constraint-Node) - joinTargetNode($dependent, $dependent-Target, $dependent-Node) +- name: simple constraint visible before name + from: simple-constraint-Node + kind: SameStagePrecedence + to: constraint-name-Node + query: + - $simple-constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - joinOnConstraintID($simple-constraint, $constraint-name, $table-id, $constraint-id) + - ToPublicOrTransient($simple-constraint-Target, $constraint-name-Target) + - $simple-constraint-Node[CurrentStatus] = WRITE_ONLY + - $constraint-name-Node[CurrentStatus] = PUBLIC + - joinTargetNode($simple-constraint, $simple-constraint-Target, $simple-constraint-Node) + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) - name: swapped primary index public before column from: index-Node kind: Precedence @@ -3638,6 +3759,114 @@ deprules - descriptorIsNotBeingDropped-23.1($prev) - joinTargetNode($prev, $prev-Target, $prev-Node) - joinTargetNode($next, $next-Target, $next-Node) +- name: Constraint should be hidden before name + from: constraint-name-Node + kind: SameStagePrecedence + to: constraint-Node + query: + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - joinOnConstraintID($constraint-name, $constraint, $table-id, $constraint-id) + - toAbsent($constraint-name-Target, $constraint-Target) + - $constraint-name-Node[CurrentStatus] = ABSENT + - $constraint-Node[CurrentStatus] = ABSENT + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) + - joinTargetNode($constraint, $constraint-Target, $constraint-Node) +- name: Constraint should be hidden before name + from: constraint-name-Node + kind: SameStagePrecedence + to: constraint-Node + query: + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - joinOnConstraintID($constraint-name, $constraint, $table-id, $constraint-id) + - transient($constraint-name-Target, $constraint-Target) + - $constraint-name-Node[CurrentStatus] = TRANSIENT_ABSENT + - $constraint-Node[CurrentStatus] = TRANSIENT_ABSENT + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) + - joinTargetNode($constraint, $constraint-Target, $constraint-Node) +- name: Constraint should be hidden before name + from: constraint-name-Node + kind: SameStagePrecedence + to: constraint-Node + query: + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - joinOnConstraintID($constraint-name, $constraint, $table-id, $constraint-id) + - $constraint-name-Target[TargetStatus] = TRANSIENT_ABSENT + - $constraint-name-Node[CurrentStatus] = TRANSIENT_ABSENT + - $constraint-Target[TargetStatus] = ABSENT + - $constraint-Node[CurrentStatus] = ABSENT + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) + - joinTargetNode($constraint, $constraint-Target, $constraint-Node) +- name: Constraint should be hidden before name + from: constraint-name-Node + kind: SameStagePrecedence + to: constraint-Node + query: + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - joinOnConstraintID($constraint-name, $constraint, $table-id, $constraint-id) + - $constraint-name-Target[TargetStatus] = ABSENT + - $constraint-name-Node[CurrentStatus] = ABSENT + - $constraint-Target[TargetStatus] = TRANSIENT_ABSENT + - $constraint-Node[CurrentStatus] = TRANSIENT_ABSENT + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) + - joinTargetNode($constraint, $constraint-Target, $constraint-Node) +- name: Constraint should be hidden before name + from: constraint-Node + kind: Precedence + to: constraint-name-Node + query: + - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - joinOnConstraintID($constraint, $constraint-name, $table-id, $constraint-id) + - toAbsent($constraint-Target, $constraint-name-Target) + - $constraint-Node[CurrentStatus] = VALIDATED + - $constraint-name-Node[CurrentStatus] = ABSENT + - joinTargetNode($constraint, $constraint-Target, $constraint-Node) + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) +- name: Constraint should be hidden before name + from: constraint-Node + kind: Precedence + to: constraint-name-Node + query: + - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - joinOnConstraintID($constraint, $constraint-name, $table-id, $constraint-id) + - transient($constraint-Target, $constraint-name-Target) + - $constraint-Node[CurrentStatus] = TRANSIENT_VALIDATED + - $constraint-name-Node[CurrentStatus] = TRANSIENT_ABSENT + - joinTargetNode($constraint, $constraint-Target, $constraint-Node) + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) +- name: Constraint should be hidden before name + from: constraint-Node + kind: Precedence + to: constraint-name-Node + query: + - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - joinOnConstraintID($constraint, $constraint-name, $table-id, $constraint-id) + - $constraint-Target[TargetStatus] = TRANSIENT_ABSENT + - $constraint-Node[CurrentStatus] = TRANSIENT_VALIDATED + - $constraint-name-Target[TargetStatus] = ABSENT + - $constraint-name-Node[CurrentStatus] = ABSENT + - joinTargetNode($constraint, $constraint-Target, $constraint-Node) + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) +- name: Constraint should be hidden before name + from: constraint-Node + kind: Precedence + to: constraint-name-Node + query: + - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - joinOnConstraintID($constraint, $constraint-name, $table-id, $constraint-id) + - $constraint-Target[TargetStatus] = ABSENT + - $constraint-Node[CurrentStatus] = VALIDATED + - $constraint-name-Target[TargetStatus] = TRANSIENT_ABSENT + - $constraint-name-Node[CurrentStatus] = TRANSIENT_ABSENT + - joinTargetNode($constraint, $constraint-Target, $constraint-Node) + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) - name: DEFAULT or ON UPDATE existence precedes writes to column from: expr-Node kind: Precedence @@ -5124,7 +5353,7 @@ deprules kind: SameStagePrecedence to: complex-constraint-Node query: - - $dependent[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependent[Type] = '*scpb.ConstraintComment' - $complex-constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - joinOnConstraintID($dependent, $complex-constraint, $table-id, $constraint-id) - ToPublicOrTransient($dependent-Target, $complex-constraint-Target) @@ -5138,7 +5367,7 @@ deprules to: dependent-Node query: - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - - $dependent[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependent[Type] = '*scpb.ConstraintComment' - joinOnConstraintID($constraint, $dependent, $table-id, $constraint-id) - toAbsent($constraint-Target, $dependent-Target) - $constraint-Node[CurrentStatus] = VALIDATED @@ -5151,7 +5380,7 @@ deprules to: dependent-Node query: - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - - $dependent[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependent[Type] = '*scpb.ConstraintComment' - joinOnConstraintID($constraint, $dependent, $table-id, $constraint-id) - transient($constraint-Target, $dependent-Target) - $constraint-Node[CurrentStatus] = TRANSIENT_VALIDATED @@ -5164,7 +5393,7 @@ deprules to: dependent-Node query: - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - - $dependent[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependent[Type] = '*scpb.ConstraintComment' - joinOnConstraintID($constraint, $dependent, $table-id, $constraint-id) - $constraint-Target[TargetStatus] = TRANSIENT_ABSENT - $constraint-Node[CurrentStatus] = TRANSIENT_VALIDATED @@ -5178,7 +5407,7 @@ deprules to: dependent-Node query: - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - - $dependent[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependent[Type] = '*scpb.ConstraintComment' - joinOnConstraintID($constraint, $dependent, $table-id, $constraint-id) - $constraint-Target[TargetStatus] = ABSENT - $constraint-Node[CurrentStatus] = VALIDATED @@ -5392,7 +5621,7 @@ deprules kind: Precedence to: constraint-Node query: - - $dependents[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependents[Type] = '*scpb.ConstraintComment' - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - joinOnConstraintID($dependents, $constraint, $table-id, $constraint-id) - toAbsent($dependents-Target, $constraint-Target) @@ -5405,7 +5634,7 @@ deprules kind: Precedence to: constraint-Node query: - - $dependents[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependents[Type] = '*scpb.ConstraintComment' - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - joinOnConstraintID($dependents, $constraint, $table-id, $constraint-id) - transient($dependents-Target, $constraint-Target) @@ -5418,7 +5647,7 @@ deprules kind: Precedence to: constraint-Node query: - - $dependents[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependents[Type] = '*scpb.ConstraintComment' - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - joinOnConstraintID($dependents, $constraint, $table-id, $constraint-id) - $dependents-Target[TargetStatus] = TRANSIENT_ABSENT @@ -5432,7 +5661,7 @@ deprules kind: Precedence to: constraint-Node query: - - $dependents[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependents[Type] = '*scpb.ConstraintComment' - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.CheckConstraint', '*scpb.ForeignKeyConstraint', '*scpb.ColumnNotNull'] - joinOnConstraintID($dependents, $constraint, $table-id, $constraint-id) - $dependents-Target[TargetStatus] = ABSENT @@ -5500,7 +5729,7 @@ deprules kind: SameStagePrecedence to: constraint-Node query: - - $dependents[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependents[Type] = '*scpb.ConstraintComment' - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraintUnvalidated'] - joinOnConstraintID($dependents, $constraint, $table-id, $constraint-id) - toAbsent($dependents-Target, $constraint-Target) @@ -5513,7 +5742,7 @@ deprules kind: SameStagePrecedence to: constraint-Node query: - - $dependents[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependents[Type] = '*scpb.ConstraintComment' - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraintUnvalidated'] - joinOnConstraintID($dependents, $constraint, $table-id, $constraint-id) - transient($dependents-Target, $constraint-Target) @@ -5526,7 +5755,7 @@ deprules kind: SameStagePrecedence to: constraint-Node query: - - $dependents[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependents[Type] = '*scpb.ConstraintComment' - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraintUnvalidated'] - joinOnConstraintID($dependents, $constraint, $table-id, $constraint-id) - $dependents-Target[TargetStatus] = TRANSIENT_ABSENT @@ -5540,7 +5769,7 @@ deprules kind: SameStagePrecedence to: constraint-Node query: - - $dependents[Type] IN ['*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment'] + - $dependents[Type] = '*scpb.ConstraintComment' - $constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraintUnvalidated'] - joinOnConstraintID($dependents, $constraint, $table-id, $constraint-id) - $dependents-Target[TargetStatus] = ABSENT @@ -6624,6 +6853,19 @@ deprules - $dependent-Node[CurrentStatus] = PUBLIC - joinTargetNode($simple-constraint, $simple-constraint-Target, $simple-constraint-Node) - joinTargetNode($dependent, $dependent-Target, $dependent-Node) +- name: simple constraint visible before name + from: simple-constraint-Node + kind: SameStagePrecedence + to: constraint-name-Node + query: + - $simple-constraint[Type] IN ['*scpb.UniqueWithoutIndexConstraint', '*scpb.UniqueWithoutIndexConstraintUnvalidated', '*scpb.CheckConstraint', '*scpb.CheckConstraintUnvalidated', '*scpb.ForeignKeyConstraint', '*scpb.ForeignKeyConstraintUnvalidated', '*scpb.ColumnNotNull'] + - $constraint-name[Type] = '*scpb.ConstraintWithoutIndexName' + - joinOnConstraintID($simple-constraint, $constraint-name, $table-id, $constraint-id) + - ToPublicOrTransient($simple-constraint-Target, $constraint-name-Target) + - $simple-constraint-Node[CurrentStatus] = WRITE_ONLY + - $constraint-name-Node[CurrentStatus] = PUBLIC + - joinTargetNode($simple-constraint, $simple-constraint-Target, $simple-constraint-Node) + - joinTargetNode($constraint-name, $constraint-name-Target, $constraint-name-Node) - name: swapped primary index public before column from: index-Node kind: Precedence diff --git a/pkg/sql/schemachanger/scplan/testdata/alter_table_add_check b/pkg/sql/schemachanger/scplan/testdata/alter_table_add_check index 39424720aedd..6c646832419e 100644 --- a/pkg/sql/schemachanger/scplan/testdata/alter_table_add_check +++ b/pkg/sql/schemachanger/scplan/testdata/alter_table_add_check @@ -5,9 +5,10 @@ CREATE TABLE t (i INT PRIMARY KEY) ops ALTER TABLE t ADD CHECK (i > 0) ---- -StatementPhase stage 1 of 1 with 1 MutationType op +StatementPhase stage 1 of 1 with 2 MutationType ops transitions: [[CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2}, PUBLIC], ABSENT] -> WRITE_ONLY + [[ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2}, PUBLIC], ABSENT] -> PUBLIC ops: *scop.AddCheckConstraint CheckExpr: i > 0:::INT8 @@ -16,15 +17,21 @@ StatementPhase stage 1 of 1 with 1 MutationType op ConstraintID: 2 TableID: 104 Validity: 2 + *scop.SetConstraintName + ConstraintID: 2 + Name: check_i + TableID: 104 PreCommitPhase stage 1 of 2 with 1 MutationType op transitions: [[CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2}, PUBLIC], WRITE_ONLY] -> ABSENT + [[ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2}, PUBLIC], PUBLIC] -> ABSENT ops: *scop.UndoAllInTxnImmediateMutationOpSideEffects {} -PreCommitPhase stage 2 of 2 with 3 MutationType ops +PreCommitPhase stage 2 of 2 with 4 MutationType ops transitions: [[CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2}, PUBLIC], ABSENT] -> WRITE_ONLY + [[ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2}, PUBLIC], ABSENT] -> PUBLIC ops: *scop.AddCheckConstraint CheckExpr: i > 0:::INT8 @@ -33,6 +40,10 @@ PreCommitPhase stage 2 of 2 with 3 MutationType ops ConstraintID: 2 TableID: 104 Validity: 2 + *scop.SetConstraintName + ConstraintID: 2 + Name: check_i + TableID: 104 *scop.SetJobStateOnDescriptor DescriptorID: 104 Initialize: true @@ -54,15 +65,10 @@ PostCommitPhase stage 1 of 2 with 1 ValidationType op *scop.ValidateConstraint ConstraintID: 2 TableID: 104 -PostCommitPhase stage 2 of 2 with 4 MutationType ops +PostCommitPhase stage 2 of 2 with 3 MutationType ops transitions: [[CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2}, PUBLIC], VALIDATED] -> PUBLIC - [[ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2}, PUBLIC], ABSENT] -> PUBLIC ops: - *scop.SetConstraintName - ConstraintID: 2 - Name: check_i - TableID: 104 *scop.MakeValidatedCheckConstraintPublic ConstraintID: 2 TableID: 104 @@ -90,7 +96,7 @@ ALTER TABLE t ADD CHECK (i > 0) to: [CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2}, VALIDATED] kind: PreviousStagePrecedence rule: CheckConstraint transitions to PUBLIC uphold 2-version invariant: WRITE_ONLY->VALIDATED -- from: [ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2}, PUBLIC] - to: [CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2}, PUBLIC] +- from: [CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2}, WRITE_ONLY] + to: [ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2}, PUBLIC] kind: SameStagePrecedence - rule: constraint dependent public right before complex constraint + rule: simple constraint visible before name diff --git a/pkg/sql/schemachanger/scplan/testdata/alter_table_add_check_udf b/pkg/sql/schemachanger/scplan/testdata/alter_table_add_check_udf index 04cff41b7294..3562b2481376 100644 --- a/pkg/sql/schemachanger/scplan/testdata/alter_table_add_check_udf +++ b/pkg/sql/schemachanger/scplan/testdata/alter_table_add_check_udf @@ -6,9 +6,10 @@ CREATE FUNCTION f(b INT) RETURNS INT LANGUAGE SQL AS $$ SELECT b + 1 $$; ops ALTER TABLE t ADD CONSTRAINT check_b CHECK (f(b) > 1); ---- -StatementPhase stage 1 of 1 with 2 MutationType ops +StatementPhase stage 1 of 1 with 3 MutationType ops transitions: [[CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2}, PUBLIC], ABSENT] -> WRITE_ONLY + [[ConstraintWithoutIndexName:{DescID: 104, Name: check_b, ConstraintID: 2}, PUBLIC], ABSENT] -> PUBLIC ops: *scop.AddCheckConstraint CheckExpr: '[FUNCTION 100105](b) > 1:::INT8' @@ -22,15 +23,21 @@ StatementPhase stage 1 of 1 with 2 MutationType ops BackReferencedTableID: 104 FunctionIDs: - 105 + *scop.SetConstraintName + ConstraintID: 2 + Name: check_b + TableID: 104 PreCommitPhase stage 1 of 2 with 1 MutationType op transitions: [[CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2}, PUBLIC], WRITE_ONLY] -> ABSENT + [[ConstraintWithoutIndexName:{DescID: 104, Name: check_b, ConstraintID: 2}, PUBLIC], PUBLIC] -> ABSENT ops: *scop.UndoAllInTxnImmediateMutationOpSideEffects {} -PreCommitPhase stage 2 of 2 with 5 MutationType ops +PreCommitPhase stage 2 of 2 with 6 MutationType ops transitions: [[CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2}, PUBLIC], ABSENT] -> WRITE_ONLY + [[ConstraintWithoutIndexName:{DescID: 104, Name: check_b, ConstraintID: 2}, PUBLIC], ABSENT] -> PUBLIC ops: *scop.AddCheckConstraint CheckExpr: '[FUNCTION 100105](b) > 1:::INT8' @@ -44,6 +51,10 @@ PreCommitPhase stage 2 of 2 with 5 MutationType ops BackReferencedTableID: 104 FunctionIDs: - 105 + *scop.SetConstraintName + ConstraintID: 2 + Name: check_b + TableID: 104 *scop.SetJobStateOnDescriptor DescriptorID: 104 Initialize: true @@ -70,15 +81,10 @@ PostCommitPhase stage 1 of 2 with 1 ValidationType op *scop.ValidateConstraint ConstraintID: 2 TableID: 104 -PostCommitPhase stage 2 of 2 with 5 MutationType ops +PostCommitPhase stage 2 of 2 with 4 MutationType ops transitions: [[CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2}, PUBLIC], VALIDATED] -> PUBLIC - [[ConstraintWithoutIndexName:{DescID: 104, Name: check_b, ConstraintID: 2}, PUBLIC], ABSENT] -> PUBLIC ops: - *scop.SetConstraintName - ConstraintID: 2 - Name: check_b - TableID: 104 *scop.MakeValidatedCheckConstraintPublic ConstraintID: 2 TableID: 104 @@ -110,7 +116,7 @@ ALTER TABLE t ADD CONSTRAINT check_b CHECK (f(b) > 1); to: [CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2}, VALIDATED] kind: PreviousStagePrecedence rule: CheckConstraint transitions to PUBLIC uphold 2-version invariant: WRITE_ONLY->VALIDATED -- from: [ConstraintWithoutIndexName:{DescID: 104, Name: check_b, ConstraintID: 2}, PUBLIC] - to: [CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2}, PUBLIC] +- from: [CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2}, WRITE_ONLY] + to: [ConstraintWithoutIndexName:{DescID: 104, Name: check_b, ConstraintID: 2}, PUBLIC] kind: SameStagePrecedence - rule: constraint dependent public right before complex constraint + rule: simple constraint visible before name diff --git a/pkg/sql/schemachanger/scplan/testdata/drop_index b/pkg/sql/schemachanger/scplan/testdata/drop_index index cfb29f080268..5e47c43dd5e8 100644 --- a/pkg/sql/schemachanger/scplan/testdata/drop_index +++ b/pkg/sql/schemachanger/scplan/testdata/drop_index @@ -366,14 +366,13 @@ DROP INDEX idx2 CASCADE ops DROP INDEX idx3 CASCADE ---- -StatementPhase stage 1 of 1 with 6 MutationType ops +StatementPhase stage 1 of 1 with 5 MutationType ops transitions: [[Column:{DescID: 104, ColumnID: 5}, ABSENT], PUBLIC] -> WRITE_ONLY [[ColumnName:{DescID: 104, Name: crdb_internal_i_shard_16, ColumnID: 5}, ABSENT], PUBLIC] -> ABSENT [[ColumnNotNull:{DescID: 104, ColumnID: 5, IndexID: 0}, ABSENT], PUBLIC] -> VALIDATED [[SecondaryIndex:{DescID: 104, IndexID: 6, ConstraintID: 0}, ABSENT], PUBLIC] -> VALIDATED [[CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2}, ABSENT], PUBLIC] -> VALIDATED - [[ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_i_shard_16, ConstraintID: 2}, ABSENT], PUBLIC] -> ABSENT ops: *scop.MakePublicColumnNotNullValidated ColumnID: 5 @@ -384,10 +383,6 @@ StatementPhase stage 1 of 1 with 6 MutationType ops *scop.MakePublicCheckConstraintValidated ConstraintID: 2 TableID: 104 - *scop.SetConstraintName - ConstraintID: 2 - Name: crdb_internal_constraint_2_name_placeholder - TableID: 104 *scop.MakePublicColumnWriteOnly ColumnID: 5 TableID: 104 @@ -402,18 +397,16 @@ PreCommitPhase stage 1 of 2 with 1 MutationType op [[ColumnNotNull:{DescID: 104, ColumnID: 5, IndexID: 0}, ABSENT], VALIDATED] -> PUBLIC [[SecondaryIndex:{DescID: 104, IndexID: 6, ConstraintID: 0}, ABSENT], VALIDATED] -> PUBLIC [[CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2}, ABSENT], VALIDATED] -> PUBLIC - [[ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_i_shard_16, ConstraintID: 2}, ABSENT], ABSENT] -> PUBLIC ops: *scop.UndoAllInTxnImmediateMutationOpSideEffects {} -PreCommitPhase stage 2 of 2 with 8 MutationType ops +PreCommitPhase stage 2 of 2 with 7 MutationType ops transitions: [[Column:{DescID: 104, ColumnID: 5}, ABSENT], PUBLIC] -> WRITE_ONLY [[ColumnName:{DescID: 104, Name: crdb_internal_i_shard_16, ColumnID: 5}, ABSENT], PUBLIC] -> ABSENT [[ColumnNotNull:{DescID: 104, ColumnID: 5, IndexID: 0}, ABSENT], PUBLIC] -> VALIDATED [[SecondaryIndex:{DescID: 104, IndexID: 6, ConstraintID: 0}, ABSENT], PUBLIC] -> VALIDATED [[CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2}, ABSENT], PUBLIC] -> VALIDATED - [[ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_i_shard_16, ConstraintID: 2}, ABSENT], PUBLIC] -> ABSENT ops: *scop.MakePublicColumnNotNullValidated ColumnID: 5 @@ -424,10 +417,6 @@ PreCommitPhase stage 2 of 2 with 8 MutationType ops *scop.MakePublicCheckConstraintValidated ConstraintID: 2 TableID: 104 - *scop.SetConstraintName - ConstraintID: 2 - Name: crdb_internal_constraint_2_name_placeholder - TableID: 104 *scop.MakePublicColumnWriteOnly ColumnID: 5 TableID: 104 @@ -445,12 +434,12 @@ PreCommitPhase stage 2 of 2 with 8 MutationType ops - 104 JobID: 1 NonCancelable: true - RunningStatus: PostCommitNonRevertiblePhase stage 1 of 2 with 8 MutationType ops pending + RunningStatus: PostCommitNonRevertiblePhase stage 1 of 2 with 9 MutationType ops pending Statements: - statement: DROP INDEX idx3 CASCADE redactedstatement: DROP INDEX ‹defaultdb›.public.‹t1›@‹idx3› CASCADE statementtag: DROP INDEX -PostCommitNonRevertiblePhase stage 1 of 2 with 10 MutationType ops +PostCommitNonRevertiblePhase stage 1 of 2 with 11 MutationType ops transitions: [[Column:{DescID: 104, ColumnID: 5}, ABSENT], WRITE_ONLY] -> DELETE_ONLY [[ColumnNotNull:{DescID: 104, ColumnID: 5, IndexID: 0}, ABSENT], VALIDATED] -> ABSENT @@ -460,12 +449,14 @@ PostCommitNonRevertiblePhase stage 1 of 2 with 10 MutationType ops [[SecondaryIndex:{DescID: 104, IndexID: 6, ConstraintID: 0}, ABSENT], VALIDATED] -> DELETE_ONLY [[IndexName:{DescID: 104, Name: idx3, IndexID: 6}, ABSENT], PUBLIC] -> ABSENT [[CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2}, ABSENT], VALIDATED] -> ABSENT + [[ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_i_shard_16, ConstraintID: 2}, ABSENT], PUBLIC] -> ABSENT ops: *scop.RemoveColumnNotNull ColumnID: 5 TableID: 104 - *scop.RemoveCheckConstraint + *scop.SetConstraintName ConstraintID: 2 + Name: crdb_internal_constraint_2_name_placeholder TableID: 104 *scop.MakeWriteOnlyColumnDeleteOnly ColumnID: 5 @@ -477,6 +468,9 @@ PostCommitNonRevertiblePhase stage 1 of 2 with 10 MutationType ops IndexID: 6 Name: crdb_internal_index_6_name_placeholder TableID: 104 + *scop.RemoveCheckConstraint + ConstraintID: 2 + TableID: 104 *scop.RemoveColumnFromIndex ColumnID: 5 IndexID: 6 @@ -537,7 +531,7 @@ DROP INDEX idx3 CASCADE - from: [CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2}, VALIDATED] to: [ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_i_shard_16, ConstraintID: 2}, ABSENT] kind: Precedence - rule: constraint no longer public before dependents + rule: Constraint should be hidden before name - from: [Column:{DescID: 104, ColumnID: 5}, DELETE_ONLY] to: [Column:{DescID: 104, ColumnID: 5}, ABSENT] kind: PreviousStagePrecedence @@ -592,8 +586,8 @@ DROP INDEX idx3 CASCADE rules: [dependents removed before column; column type removed right before column when not dropping relation] - from: [ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_i_shard_16, ConstraintID: 2}, ABSENT] to: [CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2}, ABSENT] - kind: Precedence - rule: dependents removed before constraint + kind: SameStagePrecedence + rule: Constraint should be hidden before name - from: [IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 6}, ABSENT] to: [SecondaryIndex:{DescID: 104, IndexID: 6, ConstraintID: 0}, ABSENT] kind: Precedence diff --git a/pkg/sql/schemachanger/scplan/testdata/drop_table b/pkg/sql/schemachanger/scplan/testdata/drop_table index f5fa677d89b5..9da50c5359e6 100644 --- a/pkg/sql/schemachanger/scplan/testdata/drop_table +++ b/pkg/sql/schemachanger/scplan/testdata/drop_table @@ -35,15 +35,12 @@ ALTER TABLE shipments ALTER COLUMN udfcol SET DEFAULT f1(); ops DROP TABLE defaultdb.shipments CASCADE; ---- -StatementPhase stage 1 of 1 with 22 MutationType ops +StatementPhase stage 1 of 1 with 19 MutationType ops transitions: [[ForeignKeyConstraint:{DescID: 109, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104}, ABSENT], PUBLIC] -> VALIDATED - [[ConstraintWithoutIndexName:{DescID: 109, Name: fk_customers, ConstraintID: 2}, ABSENT], PUBLIC] -> ABSENT [[ConstraintComment:{DescID: 109, ConstraintID: 2, Comment: customer is not god}, ABSENT], PUBLIC] -> ABSENT [[ForeignKeyConstraint:{DescID: 109, IndexID: 0, ConstraintID: 3, ReferencedDescID: 105}, ABSENT], PUBLIC] -> VALIDATED - [[ConstraintWithoutIndexName:{DescID: 109, Name: fk_orders, ConstraintID: 3}, ABSENT], PUBLIC] -> ABSENT [[ForeignKeyConstraint:{DescID: 109, IndexID: 0, ConstraintID: 4, ReferencedDescID: 104}, ABSENT], PUBLIC] -> VALIDATED - [[ConstraintWithoutIndexName:{DescID: 109, Name: fk_customers2, ConstraintID: 4}, ABSENT], PUBLIC] -> ABSENT [[Namespace:{DescID: 111, Name: v1, ReferencedDescID: 100}, ABSENT], PUBLIC] -> ABSENT [[Owner:{DescID: 111}, ABSENT], PUBLIC] -> ABSENT [[UserPrivileges:{DescID: 111, Name: admin}, ABSENT], PUBLIC] -> ABSENT @@ -66,27 +63,15 @@ StatementPhase stage 1 of 1 with 22 MutationType ops *scop.MakePublicForeignKeyConstraintValidated ConstraintID: 2 TableID: 109 - *scop.SetConstraintName - ConstraintID: 2 - Name: crdb_internal_constraint_2_name_placeholder - TableID: 109 *scop.RemoveConstraintComment ConstraintID: 2 TableID: 109 *scop.MakePublicForeignKeyConstraintValidated ConstraintID: 3 TableID: 109 - *scop.SetConstraintName - ConstraintID: 3 - Name: crdb_internal_constraint_3_name_placeholder - TableID: 109 *scop.MakePublicForeignKeyConstraintValidated ConstraintID: 4 TableID: 109 - *scop.SetConstraintName - ConstraintID: 4 - Name: crdb_internal_constraint_4_name_placeholder - TableID: 109 *scop.MarkDescriptorAsDropped DescriptorID: 111 *scop.RemoveBackReferencesInRelations @@ -142,12 +127,9 @@ StatementPhase stage 1 of 1 with 22 MutationType ops PreCommitPhase stage 1 of 2 with 1 MutationType op transitions: [[ForeignKeyConstraint:{DescID: 109, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104}, ABSENT], VALIDATED] -> PUBLIC - [[ConstraintWithoutIndexName:{DescID: 109, Name: fk_customers, ConstraintID: 2}, ABSENT], ABSENT] -> PUBLIC [[ConstraintComment:{DescID: 109, ConstraintID: 2, Comment: customer is not god}, ABSENT], ABSENT] -> PUBLIC [[ForeignKeyConstraint:{DescID: 109, IndexID: 0, ConstraintID: 3, ReferencedDescID: 105}, ABSENT], VALIDATED] -> PUBLIC - [[ConstraintWithoutIndexName:{DescID: 109, Name: fk_orders, ConstraintID: 3}, ABSENT], ABSENT] -> PUBLIC [[ForeignKeyConstraint:{DescID: 109, IndexID: 0, ConstraintID: 4, ReferencedDescID: 104}, ABSENT], VALIDATED] -> PUBLIC - [[ConstraintWithoutIndexName:{DescID: 109, Name: fk_customers2, ConstraintID: 4}, ABSENT], ABSENT] -> PUBLIC [[Namespace:{DescID: 111, Name: v1, ReferencedDescID: 100}, ABSENT], ABSENT] -> PUBLIC [[Owner:{DescID: 111}, ABSENT], ABSENT] -> PUBLIC [[UserPrivileges:{DescID: 111, Name: admin}, ABSENT], ABSENT] -> PUBLIC @@ -1259,31 +1241,31 @@ DROP TABLE defaultdb.shipments CASCADE; - from: [ConstraintWithoutIndexName:{DescID: 109, Name: check, ConstraintID: 5}, ABSENT] to: [CheckConstraintUnvalidated:{DescID: 109, ConstraintID: 5, ReferencedSequenceIDs: [106]}, ABSENT] kind: SameStagePrecedence - rule: dependents removed right before simple constraint + rule: Constraint should be hidden before name - from: [ConstraintWithoutIndexName:{DescID: 109, Name: check, ConstraintID: 5}, ABSENT] to: [Table:{DescID: 109}, ABSENT] kind: Precedence rule: non-data dependents removed before descriptor - from: [ConstraintWithoutIndexName:{DescID: 109, Name: fk_customers, ConstraintID: 2}, ABSENT] to: [ForeignKeyConstraint:{DescID: 109, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104}, ABSENT] - kind: Precedence - rule: dependents removed before constraint + kind: SameStagePrecedence + rule: Constraint should be hidden before name - from: [ConstraintWithoutIndexName:{DescID: 109, Name: fk_customers, ConstraintID: 2}, ABSENT] to: [Table:{DescID: 109}, ABSENT] kind: Precedence rule: non-data dependents removed before descriptor - from: [ConstraintWithoutIndexName:{DescID: 109, Name: fk_customers2, ConstraintID: 4}, ABSENT] to: [ForeignKeyConstraint:{DescID: 109, IndexID: 0, ConstraintID: 4, ReferencedDescID: 104}, ABSENT] - kind: Precedence - rule: dependents removed before constraint + kind: SameStagePrecedence + rule: Constraint should be hidden before name - from: [ConstraintWithoutIndexName:{DescID: 109, Name: fk_customers2, ConstraintID: 4}, ABSENT] to: [Table:{DescID: 109}, ABSENT] kind: Precedence rule: non-data dependents removed before descriptor - from: [ConstraintWithoutIndexName:{DescID: 109, Name: fk_orders, ConstraintID: 3}, ABSENT] to: [ForeignKeyConstraint:{DescID: 109, IndexID: 0, ConstraintID: 3, ReferencedDescID: 105}, ABSENT] - kind: Precedence - rule: dependents removed before constraint + kind: SameStagePrecedence + rule: Constraint should be hidden before name - from: [ConstraintWithoutIndexName:{DescID: 109, Name: fk_orders, ConstraintID: 3}, ABSENT] to: [Table:{DescID: 109}, ABSENT] kind: Precedence @@ -1303,7 +1285,7 @@ DROP TABLE defaultdb.shipments CASCADE; - from: [ForeignKeyConstraint:{DescID: 109, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104}, VALIDATED] to: [ConstraintWithoutIndexName:{DescID: 109, Name: fk_customers, ConstraintID: 2}, ABSENT] kind: Precedence - rule: constraint no longer public before dependents + rule: Constraint should be hidden before name - from: [ForeignKeyConstraint:{DescID: 109, IndexID: 0, ConstraintID: 3, ReferencedDescID: 105}, ABSENT] to: [Table:{DescID: 109}, ABSENT] kind: Precedence @@ -1315,7 +1297,7 @@ DROP TABLE defaultdb.shipments CASCADE; - from: [ForeignKeyConstraint:{DescID: 109, IndexID: 0, ConstraintID: 3, ReferencedDescID: 105}, VALIDATED] to: [ConstraintWithoutIndexName:{DescID: 109, Name: fk_orders, ConstraintID: 3}, ABSENT] kind: Precedence - rule: constraint no longer public before dependents + rule: Constraint should be hidden before name - from: [ForeignKeyConstraint:{DescID: 109, IndexID: 0, ConstraintID: 4, ReferencedDescID: 104}, ABSENT] to: [Table:{DescID: 109}, ABSENT] kind: Precedence @@ -1327,7 +1309,7 @@ DROP TABLE defaultdb.shipments CASCADE; - from: [ForeignKeyConstraint:{DescID: 109, IndexID: 0, ConstraintID: 4, ReferencedDescID: 104}, VALIDATED] to: [ConstraintWithoutIndexName:{DescID: 109, Name: fk_customers2, ConstraintID: 4}, ABSENT] kind: Precedence - rule: constraint no longer public before dependents + rule: Constraint should be hidden before name - from: [IndexColumn:{DescID: 109, ColumnID: 1, IndexID: 1}, ABSENT] to: [Column:{DescID: 109, ColumnID: 1}, ABSENT] kind: Precedence @@ -2687,22 +2669,16 @@ CREATE TABLE defaultdb.greeter ( ops DROP TABLE defaultdb.greeter ---- -StatementPhase stage 1 of 1 with 2 MutationType ops +StatementPhase stage 1 of 1 with 1 MutationType op transitions: [[CheckConstraint:{DescID: 115, ReferencedTypeIDs: [113 114], IndexID: 0, ConstraintID: 2}, ABSENT], PUBLIC] -> VALIDATED - [[ConstraintWithoutIndexName:{DescID: 115, Name: check, ConstraintID: 2}, ABSENT], PUBLIC] -> ABSENT ops: *scop.MakePublicCheckConstraintValidated ConstraintID: 2 TableID: 115 - *scop.SetConstraintName - ConstraintID: 2 - Name: crdb_internal_constraint_2_name_placeholder - TableID: 115 PreCommitPhase stage 1 of 2 with 1 MutationType op transitions: [[CheckConstraint:{DescID: 115, ReferencedTypeIDs: [113 114], IndexID: 0, ConstraintID: 2}, ABSENT], VALIDATED] -> PUBLIC - [[ConstraintWithoutIndexName:{DescID: 115, Name: check, ConstraintID: 2}, ABSENT], ABSENT] -> PUBLIC ops: *scop.UndoAllInTxnImmediateMutationOpSideEffects {} diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_check_udf b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_check_udf index 4ef18114c913..40107ff7c6d4 100644 --- a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_check_udf +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_check_udf @@ -22,7 +22,7 @@ write *eventpb.AlterTable to event log: tag: ALTER TABLE user: root tableName: defaultdb.public.t -## StatementPhase stage 1 of 1 with 2 MutationType ops +## StatementPhase stage 1 of 1 with 3 MutationType ops upsert descriptor #104 table: + checks: @@ -30,7 +30,7 @@ upsert descriptor #104 + - 2 + constraintId: 2 + expr: '[FUNCTION 100105](b) > 1:::INT8' - + name: crdb_internal_constraint_2_name_placeholder + + name: check_b + validity: Validating columns: - id: 1 @@ -82,7 +82,7 @@ upsert descriptor #105 ## PreCommitPhase stage 1 of 2 with 1 MutationType op undo all catalog changes within txn #1 persist all catalog changes to storage -## PreCommitPhase stage 2 of 2 with 5 MutationType ops +## PreCommitPhase stage 2 of 2 with 6 MutationType ops upsert descriptor #104 table: + checks: @@ -90,7 +90,7 @@ upsert descriptor #104 + - 2 + constraintId: 2 + expr: '[FUNCTION 100105](b) > 1:::INT8' - + name: crdb_internal_constraint_2_name_placeholder + + name: check_b + validity: Validating columns: - id: 1 @@ -172,17 +172,15 @@ begin transaction #2 commit transaction #2 begin transaction #3 ## PostCommitPhase stage 1 of 2 with 1 ValidationType op -validate CHECK constraint crdb_internal_constraint_2_name_placeholder in table #104 +validate CHECK constraint check_b in table #104 commit transaction #3 begin transaction #4 -## PostCommitPhase stage 2 of 2 with 5 MutationType ops +## PostCommitPhase stage 2 of 2 with 4 MutationType ops upsert descriptor #104 ... - constraintId: 2 expr: '[FUNCTION 100105](b) > 1:::INT8' - - name: crdb_internal_constraint_2_name_placeholder + name: check_b - validity: Validating - + name: check_b columns: - id: 1 ... diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_check_vanilla b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_check_vanilla index 610950205dec..c039d1e56a54 100644 --- a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_check_vanilla +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_check_vanilla @@ -4,6 +4,24 @@ CREATE TABLE t (i INT PRIMARY KEY) ... +object {100 101 t} -> 104 + +stage-exec phase=PostCommitPhase stage=: +INSERT INTO t (i) VALUES($stageKey); +INSERT INTO t (i) VALUES($stageKey + 1); +---- + +stage-exec phase=PostCommitPhase stage=: +INSERT INTO t (i) VALUES(-1) +---- +pq: failed to satisfy CHECK constraint .* + +# Each insert will be injected twice per stage, so we should always, +# see a count of 2. +stage-query phase=PostCommitPhase stage=: +SELECT count(*)=($successfulStageCount*2) FROM t; +---- +true + test ALTER TABLE t ADD CHECK (i > 0) --- @@ -21,7 +39,7 @@ write *eventpb.AlterTable to event log: tag: ALTER TABLE user: root tableName: defaultdb.public.t -## StatementPhase stage 1 of 1 with 1 MutationType op +## StatementPhase stage 1 of 1 with 2 MutationType ops upsert descriptor #104 table: + checks: @@ -29,7 +47,7 @@ upsert descriptor #104 + - 1 + constraintId: 2 + expr: i > 0:::INT8 - + name: crdb_internal_constraint_2_name_placeholder + + name: check_i + validity: Validating columns: - id: 1 @@ -67,7 +85,7 @@ upsert descriptor #104 ## PreCommitPhase stage 1 of 2 with 1 MutationType op undo all catalog changes within txn #1 persist all catalog changes to storage -## PreCommitPhase stage 2 of 2 with 3 MutationType ops +## PreCommitPhase stage 2 of 2 with 4 MutationType ops upsert descriptor #104 table: + checks: @@ -75,7 +93,7 @@ upsert descriptor #104 + - 1 + constraintId: 2 + expr: i > 0:::INT8 - + name: crdb_internal_constraint_2_name_placeholder + + name: check_i + validity: Validating columns: - id: 1 @@ -137,17 +155,15 @@ begin transaction #2 commit transaction #2 begin transaction #3 ## PostCommitPhase stage 1 of 2 with 1 ValidationType op -validate CHECK constraint crdb_internal_constraint_2_name_placeholder in table #104 +validate CHECK constraint check_i in table #104 commit transaction #3 begin transaction #4 -## PostCommitPhase stage 2 of 2 with 4 MutationType ops +## PostCommitPhase stage 2 of 2 with 3 MutationType ops upsert descriptor #104 ... - constraintId: 2 expr: i > 0:::INT8 - - name: crdb_internal_constraint_2_name_placeholder + name: check_i - validity: Validating - + name: check_i columns: - id: 1 ... diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_check_with_seq_and_udt b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_check_with_seq_and_udt index ae18aa9c6445..baf9ef8e3a79 100644 --- a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_check_with_seq_and_udt +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_check_with_seq_and_udt @@ -26,7 +26,7 @@ write *eventpb.AlterTable to event log: tag: ALTER TABLE user: root tableName: defaultdb.public.t -## StatementPhase stage 1 of 1 with 3 MutationType ops +## StatementPhase stage 1 of 1 with 4 MutationType ops upsert descriptor #104 ... createAsOfTime: @@ -65,7 +65,7 @@ upsert descriptor #107 + - 2 + constraintId: 2 + expr: (i > nextval(104:::REGCLASS)) OR (j::@100105 = b'@':::@100105) - + name: crdb_internal_constraint_2_name_placeholder + + name: check_i_j + validity: Validating columns: - id: 1 @@ -104,7 +104,7 @@ upsert descriptor #107 ## PreCommitPhase stage 1 of 2 with 1 MutationType op undo all catalog changes within txn #1 persist all catalog changes to storage -## PreCommitPhase stage 2 of 2 with 8 MutationType ops +## PreCommitPhase stage 2 of 2 with 9 MutationType ops upsert descriptor #104 ... createAsOfTime: @@ -167,7 +167,7 @@ upsert descriptor #107 + - 2 + constraintId: 2 + expr: (i > nextval(104:::REGCLASS)) OR (j::@100105 = b'@':::@100105) - + name: crdb_internal_constraint_2_name_placeholder + + name: check_i_j + validity: Validating columns: - id: 1 @@ -231,10 +231,10 @@ begin transaction #2 commit transaction #2 begin transaction #3 ## PostCommitPhase stage 1 of 2 with 1 ValidationType op -validate CHECK constraint crdb_internal_constraint_2_name_placeholder in table #107 +validate CHECK constraint check_i_j in table #107 commit transaction #3 begin transaction #4 -## PostCommitPhase stage 2 of 2 with 7 MutationType ops +## PostCommitPhase stage 2 of 2 with 6 MutationType ops upsert descriptor #104 ... createAsOfTime: @@ -284,11 +284,9 @@ upsert descriptor #106 + version: "3" upsert descriptor #107 ... - constraintId: 2 expr: (i > nextval(104:::REGCLASS)) OR (j::@100105 = b'@':::@100105) - - name: crdb_internal_constraint_2_name_placeholder + name: check_i_j - validity: Validating - + name: check_i_j columns: - id: 1 ... diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_foreign_key b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_foreign_key index 454a593d8b72..213e482fcba6 100644 --- a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_foreign_key +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_foreign_key @@ -1,11 +1,33 @@ setup CREATE TABLE t1 (i INT PRIMARY KEY); -CREATE TABLE t2 (i INT PRIMARY KEY) +CREATE TABLE t2 (i INT PRIMARY KEY); +INSERT INTO t2 VALUES(-1); +INSERT INTO t2 VALUES(-2); +INSERT INTO t2 VALUES(-3); ---- ... +object {100 101 t1} -> 104 +object {100 101 t2} -> 105 +stage-exec phase=PostCommitPhase stage=: +INSERT INTO t2 (i) VALUES($stageKey); +INSERT INTO t2 (i) VALUES($stageKey + 1); +INSERT INTO t1 (i) VALUES($stageKey); +INSERT INTO t1 (i) VALUES($stageKey + 1); +---- + +stage-exec phase=PostCommitPhase stage=: +INSERT INTO t1 (i) VALUES($stageKey+3) +---- +insert on table "t1" violates foreign key constraint "t1_i_fkey" + +# Each insert will be injected twice per stage, so we should always, +# see a count of 2. +stage-query phase=PostCommitPhase stage=: +SELECT count(*)=($successfulStageCount*2)+3 FROM t2; +---- +true + test ALTER TABLE t1 ADD FOREIGN KEY (i) REFERENCES t2(i) ---- @@ -23,7 +45,7 @@ write *eventpb.AlterTable to event log: tag: ALTER TABLE user: root tableName: defaultdb.public.t1 -## StatementPhase stage 1 of 1 with 1 MutationType op +## StatementPhase stage 1 of 1 with 2 MutationType ops upsert descriptor #104 ... id: 104 @@ -34,7 +56,7 @@ upsert descriptor #104 + constraintType: FOREIGN_KEY + foreignKey: + constraintId: 2 - + name: crdb_internal_constraint_2_name_placeholder + + name: t1_i_fkey + originColumnIds: + - 1 + originTableId: 104 @@ -64,7 +86,7 @@ upsert descriptor #105 id: 105 + inboundFks: + - constraintId: 2 - + name: crdb_internal_constraint_2_name_placeholder + + name: t1_i_fkey + originColumnIds: + - 1 + originTableId: 104 @@ -84,7 +106,7 @@ upsert descriptor #105 ## PreCommitPhase stage 1 of 2 with 1 MutationType op undo all catalog changes within txn #1 persist all catalog changes to storage -## PreCommitPhase stage 2 of 2 with 4 MutationType ops +## PreCommitPhase stage 2 of 2 with 5 MutationType ops upsert descriptor #104 ... createAsOfTime: @@ -114,7 +136,7 @@ upsert descriptor #104 + constraintType: FOREIGN_KEY + foreignKey: + constraintId: 2 - + name: crdb_internal_constraint_2_name_placeholder + + name: t1_i_fkey + originColumnIds: + - 1 + originTableId: 104 @@ -154,7 +176,7 @@ upsert descriptor #105 id: 105 + inboundFks: + - constraintId: 2 - + name: crdb_internal_constraint_2_name_placeholder + + name: t1_i_fkey + originColumnIds: + - 1 + originTableId: 104 @@ -180,10 +202,10 @@ begin transaction #2 commit transaction #2 begin transaction #3 ## PostCommitPhase stage 1 of 2 with 1 ValidationType op -validate FOREIGN KEY constraint crdb_internal_constraint_2_name_placeholder in table #104 +validate FOREIGN KEY constraint t1_i_fkey in table #104 commit transaction #3 begin transaction #4 -## PostCommitPhase stage 2 of 2 with 5 MutationType ops +## PostCommitPhase stage 2 of 2 with 4 MutationType ops upsert descriptor #104 ... createAsOfTime: @@ -213,7 +235,7 @@ upsert descriptor #104 - constraintType: FOREIGN_KEY - foreignKey: - constraintId: 2 - - name: crdb_internal_constraint_2_name_placeholder + - name: t1_i_fkey - originColumnIds: - - 1 - originTableId: 104 @@ -258,13 +280,6 @@ upsert descriptor #105 - revertible: true families: - columnIds: - ... - inboundFks: - - constraintId: 2 - - name: crdb_internal_constraint_2_name_placeholder - + name: t1_i_fkey - originColumnIds: - - 1 ... - 1 referencedTableId: 105 diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_unique_without_index b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_unique_without_index index e58a83a6ec3d..04f6ba9ccaa0 100644 --- a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_unique_without_index +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_add_unique_without_index @@ -1,10 +1,30 @@ setup CREATE TABLE t (i INT PRIMARY KEY, j INT); SET experimental_enable_unique_without_index_constraints = true; +INSERT INTO t VALUES(-1, -1); +INSERT INTO t VALUES(-2, -2); +INSERT INTO t VALUES(-3, -3); ---- ... +object {100 101 t} -> 104 +stage-exec phase=PostCommitPhase stage=: +INSERT INTO t (i, j) VALUES($stageKey, $stageKey); +INSERT INTO t (i, j) VALUES($stageKey + 1, $stageKey +1); +---- + +stage-exec phase=PostCommitPhase stage=: +INSERT INTO t (i, j) VALUES($stageKey +2, $stageKey) +---- +duplicate key value violates unique constraint "unique_j" + +# Each insert will be injected twice per stage, so we should always, +# see a count of 2. +stage-query phase=PostCommitPhase stage=: +SELECT count(*)=($successfulStageCount*2)+3 FROM t; +---- +true + test ALTER TABLE t ADD UNIQUE WITHOUT INDEX (j); ---- @@ -22,7 +42,7 @@ write *eventpb.AlterTable to event log: tag: ALTER TABLE user: root tableName: defaultdb.public.t -## StatementPhase stage 1 of 1 with 1 MutationType op +## StatementPhase stage 1 of 1 with 2 MutationType ops upsert descriptor #104 ... id: 104 @@ -37,7 +57,7 @@ upsert descriptor #104 + columnIds: + - 2 + constraintId: 2 - + name: crdb_internal_constraint_2_name_placeholder + + name: unique_j + tableId: 104 + validity: Validating + direction: ADD @@ -59,7 +79,7 @@ upsert descriptor #104 ## PreCommitPhase stage 1 of 2 with 1 MutationType op undo all catalog changes within txn #1 persist all catalog changes to storage -## PreCommitPhase stage 2 of 2 with 3 MutationType ops +## PreCommitPhase stage 2 of 2 with 4 MutationType ops upsert descriptor #104 ... createAsOfTime: @@ -93,7 +113,7 @@ upsert descriptor #104 + columnIds: + - 2 + constraintId: 2 - + name: crdb_internal_constraint_2_name_placeholder + + name: unique_j + tableId: 104 + validity: Validating + direction: ADD @@ -121,10 +141,10 @@ begin transaction #2 commit transaction #2 begin transaction #3 ## PostCommitPhase stage 1 of 2 with 1 ValidationType op -validate UNIQUE WITHOUT INDEX constraint crdb_internal_constraint_2_name_placeholder in table #104 +validate UNIQUE WITHOUT INDEX constraint unique_j in table #104 commit transaction #3 begin transaction #4 -## PostCommitPhase stage 2 of 2 with 4 MutationType ops +## PostCommitPhase stage 2 of 2 with 3 MutationType ops upsert descriptor #104 ... createAsOfTime: @@ -158,7 +178,7 @@ upsert descriptor #104 - columnIds: - - 2 - constraintId: 2 - - name: crdb_internal_constraint_2_name_placeholder + - name: unique_j - tableId: 104 - validity: Validating - direction: ADD diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_alter_primary_key_using_hash b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_alter_primary_key_using_hash index 93b11de2a81b..312fed1b8927 100644 --- a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_alter_primary_key_using_hash +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_alter_primary_key_using_hash @@ -21,14 +21,14 @@ write *eventpb.AlterTable to event log: tag: ALTER TABLE user: root tableName: defaultdb.public.t -## StatementPhase stage 1 of 1 with 21 MutationType ops +## StatementPhase stage 1 of 1 with 22 MutationType ops upsert descriptor #104 table: + checks: + - constraintId: 2 + expr: '"crdb_internal_j_shard_3" IN (0,1,2)' + fromHashShardedColumn: true - + name: crdb_internal_constraint_2_name_placeholder + + name: check_crdb_internal_j_shard_3 + validity: Validating columns: - id: 1 @@ -205,14 +205,14 @@ upsert descriptor #104 ## PreCommitPhase stage 1 of 2 with 1 MutationType op undo all catalog changes within txn #1 persist all catalog changes to storage -## PreCommitPhase stage 2 of 2 with 27 MutationType ops +## PreCommitPhase stage 2 of 2 with 28 MutationType ops upsert descriptor #104 table: + checks: + - constraintId: 2 + expr: '"crdb_internal_j_shard_3" IN (0,1,2)' + fromHashShardedColumn: true - + name: crdb_internal_constraint_2_name_placeholder + + name: check_crdb_internal_j_shard_3 + validity: Validating columns: - id: 1 @@ -417,7 +417,7 @@ begin transaction #3 ## PostCommitPhase stage 1 of 7 with 6 MutationType ops upsert descriptor #104 ... - name: crdb_internal_constraint_2_name_placeholder + name: check_crdb_internal_j_shard_3 validity: Validating + - columnIds: + - 3 @@ -560,15 +560,14 @@ begin transaction #9 validate forward indexes [2] in table #104 validate forward indexes [4] in table #104 validate CHECK constraint crdb_internal_j_shard_3_auto_not_null in table #104 -validate CHECK constraint crdb_internal_constraint_2_name_placeholder in table #104 +validate CHECK constraint check_crdb_internal_j_shard_3 in table #104 commit transaction #9 begin transaction #10 -## PostCommitNonRevertiblePhase stage 1 of 3 with 18 MutationType ops +## PostCommitNonRevertiblePhase stage 1 of 3 with 17 MutationType ops upsert descriptor #104 ... - expr: '"crdb_internal_j_shard_3" IN (0,1,2)' fromHashShardedColumn: true - - name: crdb_internal_constraint_2_name_placeholder + name: check_crdb_internal_j_shard_3 - validity: Validating - - columnIds: - - 3 @@ -576,7 +575,6 @@ upsert descriptor #104 - isNonNullConstraint: true - name: crdb_internal_j_shard_3_auto_not_null - validity: Validating - + name: check_crdb_internal_j_shard_3 columns: - id: 1 ... diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_drop_constraint_check b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_drop_constraint_check index 7df6e7e990f3..261d1ad43fb0 100644 --- a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_drop_constraint_check +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_drop_constraint_check @@ -23,13 +23,11 @@ begin transaction #1 checking for feature: ALTER TABLE increment telemetry for sql.schema.alter_table increment telemetry for sql.schema.alter_table.drop_constraint -## StatementPhase stage 1 of 1 with 2 MutationType ops +## StatementPhase stage 1 of 1 with 1 MutationType op upsert descriptor #104 ... - constraintId: 2 expr: i > 0:::INT8 - - name: check_i - + name: crdb_internal_constraint_2_name_placeholder + name: check_i + validity: Dropping columns: - id: 1 @@ -63,13 +61,11 @@ upsert descriptor #104 ## PreCommitPhase stage 1 of 2 with 1 MutationType op undo all catalog changes within txn #1 persist all catalog changes to storage -## PreCommitPhase stage 2 of 2 with 4 MutationType ops +## PreCommitPhase stage 2 of 2 with 3 MutationType ops upsert descriptor #104 ... - constraintId: 2 expr: i > 0:::INT8 - - name: check_i - + name: crdb_internal_constraint_2_name_placeholder + name: check_i + validity: Dropping columns: - id: 1 @@ -125,7 +121,7 @@ notified job registry to adopt jobs: [1] begin transaction #2 commit transaction #2 begin transaction #3 -## PostCommitNonRevertiblePhase stage 1 of 1 with 3 MutationType ops +## PostCommitNonRevertiblePhase stage 1 of 1 with 4 MutationType ops upsert descriptor #104 table: - checks: @@ -133,7 +129,7 @@ upsert descriptor #104 - - 1 - constraintId: 2 - expr: i > 0:::INT8 - - name: crdb_internal_constraint_2_name_placeholder + - name: check_i - validity: Dropping + checks: [] columns: diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_drop_constraint_fk b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_drop_constraint_fk index c5929edc2df4..f4eb03eb816d 100644 --- a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_drop_constraint_fk +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_drop_constraint_fk @@ -11,7 +11,7 @@ CREATE TABLE t1 (i INT PRIMARY KEY REFERENCES t2(i)); stage-exec phase=PostCommitNonRevertiblePhase stage=1 INSERT INTO t1 VALUES (0); ---- -pq: insert on table "t1" violates foreign key constraint "crdb_internal_constraint_2_name_placeholder" +pq: insert on table "t1" violates foreign key constraint "t1_i_fkey" stage-query phase=PostCommitNonRevertiblePhase stage=1 SELECT count(*) FROM t1; @@ -52,15 +52,8 @@ begin transaction #1 checking for feature: ALTER TABLE increment telemetry for sql.schema.alter_table increment telemetry for sql.schema.alter_table.drop_constraint -## StatementPhase stage 1 of 1 with 2 MutationType ops +## StatementPhase stage 1 of 1 with 1 MutationType op upsert descriptor #104 - ... - inboundFks: - - constraintId: 2 - - name: t1_i_fkey - + name: crdb_internal_constraint_2_name_placeholder - originColumnIds: - - 1 ... - 1 referencedTableId: 104 @@ -82,7 +75,7 @@ upsert descriptor #105 + constraintType: FOREIGN_KEY + foreignKey: + constraintId: 2 - + name: crdb_internal_constraint_2_name_placeholder + + name: t1_i_fkey + originColumnIds: + - 1 + originTableId: 105 @@ -121,7 +114,7 @@ upsert descriptor #105 ## PreCommitPhase stage 1 of 2 with 1 MutationType op undo all catalog changes within txn #1 persist all catalog changes to storage -## PreCommitPhase stage 2 of 2 with 5 MutationType ops +## PreCommitPhase stage 2 of 2 with 4 MutationType ops upsert descriptor #104 ... createAsOfTime: @@ -132,13 +125,6 @@ upsert descriptor #104 + jobId: "1" families: - columnIds: - ... - inboundFks: - - constraintId: 2 - - name: t1_i_fkey - + name: crdb_internal_constraint_2_name_placeholder - originColumnIds: - - 1 ... - 1 referencedTableId: 104 @@ -177,7 +163,7 @@ upsert descriptor #105 + constraintType: FOREIGN_KEY + foreignKey: + constraintId: 2 - + name: crdb_internal_constraint_2_name_placeholder + + name: t1_i_fkey + originColumnIds: + - 1 + originTableId: 105 @@ -221,7 +207,7 @@ notified job registry to adopt jobs: [1] begin transaction #2 commit transaction #2 begin transaction #3 -## PostCommitNonRevertiblePhase stage 1 of 1 with 5 MutationType ops +## PostCommitNonRevertiblePhase stage 1 of 1 with 6 MutationType ops upsert descriptor #104 ... createAsOfTime: @@ -237,7 +223,7 @@ upsert descriptor #104 id: 104 - inboundFks: - - constraintId: 2 - - name: crdb_internal_constraint_2_name_placeholder + - name: t1_i_fkey - originColumnIds: - - 1 - originTableId: 105 @@ -279,7 +265,7 @@ upsert descriptor #105 - constraintType: FOREIGN_KEY - foreignKey: - constraintId: 2 - - name: crdb_internal_constraint_2_name_placeholder + - name: t1_i_fkey - originColumnIds: - - 1 - originTableId: 105 diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_drop_constraint_uwi b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_drop_constraint_uwi index f5ab34ac633b..dd2a55f126a7 100644 --- a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_drop_constraint_uwi +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_drop_constraint_uwi @@ -12,7 +12,7 @@ stage-exec phase=PostCommitNonRevertiblePhase stage=1 INSERT INTO t VALUES ($stageKey, $stageKey); INSERT INTO t VALUES ($stageKey+1, $stageKey); ---- -pq: duplicate key value violates unique constraint "crdb_internal_constraint_2_name_placeholder" +pq: duplicate key value violates unique constraint "unique_j" stage-query phase=PostCommitNonRevertiblePhase stage=1 SELECT count(*) FROM t; @@ -28,7 +28,7 @@ begin transaction #1 checking for feature: ALTER TABLE increment telemetry for sql.schema.alter_table increment telemetry for sql.schema.alter_table.drop_constraint -## StatementPhase stage 1 of 1 with 2 MutationType ops +## StatementPhase stage 1 of 1 with 1 MutationType op upsert descriptor #104 ... id: 104 @@ -43,7 +43,7 @@ upsert descriptor #104 + columnIds: + - 2 + constraintId: 2 - + name: crdb_internal_constraint_2_name_placeholder + + name: unique_j + tableId: 104 + validity: Dropping + direction: DROP @@ -67,7 +67,7 @@ upsert descriptor #104 ## PreCommitPhase stage 1 of 2 with 1 MutationType op undo all catalog changes within txn #1 persist all catalog changes to storage -## PreCommitPhase stage 2 of 2 with 4 MutationType ops +## PreCommitPhase stage 2 of 2 with 3 MutationType ops upsert descriptor #104 ... createAsOfTime: @@ -99,7 +99,7 @@ upsert descriptor #104 + columnIds: + - 2 + constraintId: 2 - + name: crdb_internal_constraint_2_name_placeholder + + name: unique_j + tableId: 104 + validity: Dropping + direction: DROP @@ -128,7 +128,7 @@ notified job registry to adopt jobs: [1] begin transaction #2 commit transaction #2 begin transaction #3 -## PostCommitNonRevertiblePhase stage 1 of 1 with 3 MutationType ops +## PostCommitNonRevertiblePhase stage 1 of 1 with 4 MutationType ops upsert descriptor #104 ... createAsOfTime: @@ -160,7 +160,7 @@ upsert descriptor #104 - columnIds: - - 2 - constraintId: 2 - - name: crdb_internal_constraint_2_name_placeholder + - name: unique_j - tableId: 104 - validity: Dropping - direction: DROP diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_validate_constraint b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_validate_constraint index c87f8c3e3cde..f466a47af52e 100644 --- a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_validate_constraint +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_validate_constraint @@ -13,7 +13,7 @@ begin transaction #1 checking for feature: ALTER TABLE increment telemetry for sql.schema.alter_table increment telemetry for sql.schema.alter_table.validate_constraint -## StatementPhase stage 1 of 1 with 3 MutationType ops +## StatementPhase stage 1 of 1 with 4 MutationType ops upsert descriptor #104 ... - columnIds: @@ -21,9 +21,8 @@ upsert descriptor #104 - constraintId: 2 + constraintId: 3 expr: i > 0:::INT8 - - name: check_i + name: check_i - validity: Unvalidated - + name: crdb_internal_constraint_3_name_placeholder + validity: Validating columns: - id: 1 @@ -61,7 +60,7 @@ upsert descriptor #104 ## PreCommitPhase stage 1 of 2 with 1 MutationType op undo all catalog changes within txn #1 persist all catalog changes to storage -## PreCommitPhase stage 2 of 2 with 5 MutationType ops +## PreCommitPhase stage 2 of 2 with 6 MutationType ops upsert descriptor #104 ... - columnIds: @@ -69,9 +68,8 @@ upsert descriptor #104 - constraintId: 2 + constraintId: 3 expr: i > 0:::INT8 - - name: check_i + name: check_i - validity: Unvalidated - + name: crdb_internal_constraint_3_name_placeholder + validity: Validating columns: - id: 1 @@ -134,17 +132,15 @@ begin transaction #2 commit transaction #2 begin transaction #3 ## PostCommitPhase stage 1 of 2 with 1 ValidationType op -validate CHECK constraint crdb_internal_constraint_3_name_placeholder in table #104 +validate CHECK constraint check_i in table #104 commit transaction #3 begin transaction #4 -## PostCommitPhase stage 2 of 2 with 4 MutationType ops +## PostCommitPhase stage 2 of 2 with 3 MutationType ops upsert descriptor #104 ... - constraintId: 3 expr: i > 0:::INT8 - - name: crdb_internal_constraint_3_name_placeholder + name: check_i - validity: Validating - + name: check_i columns: - id: 1 ... diff --git a/pkg/sql/schemachanger/testdata/end_to_end/drop_index_hash_sharded_index b/pkg/sql/schemachanger/testdata/end_to_end/drop_index_hash_sharded_index index 84af4ae1e177..b93ab9b660f1 100644 --- a/pkg/sql/schemachanger/testdata/end_to_end/drop_index_hash_sharded_index +++ b/pkg/sql/schemachanger/testdata/end_to_end/drop_index_hash_sharded_index @@ -34,7 +34,7 @@ write *eventpb.DropIndex to event log: tag: DROP INDEX user: root tableName: defaultdb.public.t -## StatementPhase stage 1 of 1 with 6 MutationType ops +## StatementPhase stage 1 of 1 with 5 MutationType ops upsert descriptor #104 ... - 3 @@ -43,8 +43,7 @@ upsert descriptor #104 + expr: crdb_internal_column_3_name_placeholder IN (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15) fromHashShardedColumn: true - - name: check_crdb_internal_j_shard_16 - + name: crdb_internal_constraint_2_name_placeholder + name: check_crdb_internal_j_shard_16 + validity: Dropping + - columnIds: + - 3 @@ -191,7 +190,7 @@ upsert descriptor #104 ## PreCommitPhase stage 1 of 2 with 1 MutationType op undo all catalog changes within txn #1 persist all catalog changes to storage -## PreCommitPhase stage 2 of 2 with 8 MutationType ops +## PreCommitPhase stage 2 of 2 with 7 MutationType ops upsert descriptor #104 ... - 3 @@ -200,8 +199,7 @@ upsert descriptor #104 + expr: crdb_internal_column_3_name_placeholder IN (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15) fromHashShardedColumn: true - - name: check_crdb_internal_j_shard_16 - + name: crdb_internal_constraint_2_name_placeholder + name: check_crdb_internal_j_shard_16 + validity: Dropping + - columnIds: + - 3 @@ -367,7 +365,7 @@ notified job registry to adopt jobs: [1] begin transaction #2 commit transaction #2 begin transaction #3 -## PostCommitNonRevertiblePhase stage 1 of 2 with 10 MutationType ops +## PostCommitNonRevertiblePhase stage 1 of 2 with 11 MutationType ops upsert descriptor #104 table: - checks: @@ -377,7 +375,7 @@ upsert descriptor #104 - expr: crdb_internal_column_3_name_placeholder IN (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 10, 11, 12, 13, 14, 15) - fromHashShardedColumn: true - - name: crdb_internal_constraint_2_name_placeholder + - name: check_crdb_internal_j_shard_16 - validity: Dropping - - columnIds: - - 3 diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_udf b/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_udf index 21470cea85a3..994415e2c776 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_udf +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_udf @@ -8,23 +8,28 @@ EXPLAIN (ddl) ALTER TABLE t ADD CONSTRAINT check_b CHECK (f(b) > 1); Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› ADD CONSTRAINT ‹check_b› CHECK (f(‹b›) > ‹1›); ├── StatementPhase │ └── Stage 1 of 1 in StatementPhase - │ ├── 1 element transitioning toward PUBLIC - │ │ └── ABSENT → WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ └── 2 Mutation operations + │ ├── 2 elements transitioning toward PUBLIC + │ │ ├── ABSENT → WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ │ └── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: check_b, ConstraintID: 2} + │ └── 3 Mutation operations │ ├── AddCheckConstraint {"CheckExpr":"[FUNCTION 100105...","ConstraintID":2,"TableID":104,"Validity":2} - │ └── AddTableConstraintBackReferencesInFunctions {"BackReferencedConstraintID":2,"BackReferencedTableID":104} + │ ├── AddTableConstraintBackReferencesInFunctions {"BackReferencedConstraintID":2,"BackReferencedTableID":104} + │ └── SetConstraintName {"ConstraintID":2,"Name":"check_b","TableID":104} ├── PreCommitPhase │ ├── Stage 1 of 2 in PreCommitPhase - │ │ ├── 1 element transitioning toward PUBLIC - │ │ │ └── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ │ ├── 2 elements transitioning toward PUBLIC + │ │ │ ├── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ │ │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_b, ConstraintID: 2} │ │ └── 1 Mutation operation │ │ └── UndoAllInTxnImmediateMutationOpSideEffects │ └── Stage 2 of 2 in PreCommitPhase - │ ├── 1 element transitioning toward PUBLIC - │ │ └── ABSENT → WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ └── 5 Mutation operations + │ ├── 2 elements transitioning toward PUBLIC + │ │ ├── ABSENT → WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ │ └── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: check_b, ConstraintID: 2} + │ └── 6 Mutation operations │ ├── AddCheckConstraint {"CheckExpr":"[FUNCTION 100105...","ConstraintID":2,"TableID":104,"Validity":2} │ ├── AddTableConstraintBackReferencesInFunctions {"BackReferencedConstraintID":2,"BackReferencedTableID":104} + │ ├── SetConstraintName {"ConstraintID":2,"Name":"check_b","TableID":104} │ ├── SetJobStateOnDescriptor {"DescriptorID":104,"Initialize":true} │ ├── SetJobStateOnDescriptor {"DescriptorID":105,"Initialize":true} │ └── CreateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} @@ -35,11 +40,9 @@ Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› ADD CONS │ └── 1 Validation operation │ └── ValidateConstraint {"ConstraintID":2,"TableID":104} └── Stage 2 of 2 in PostCommitPhase - ├── 2 elements transitioning toward PUBLIC - │ ├── VALIDATED → PUBLIC CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ └── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: check_b, ConstraintID: 2} - └── 5 Mutation operations - ├── SetConstraintName {"ConstraintID":2,"Name":"check_b","TableID":104} + ├── 1 element transitioning toward PUBLIC + │ └── VALIDATED → PUBLIC CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + └── 4 Mutation operations ├── MakeValidatedCheckConstraintPublic {"ConstraintID":2,"TableID":104} ├── RemoveJobStateFromDescriptor {"DescriptorID":104} ├── RemoveJobStateFromDescriptor {"DescriptorID":105} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_udf.rollback_1_of_2 b/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_udf.rollback_1_of_2 index f947e929a7bf..1424cf399d24 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_udf.rollback_1_of_2 +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_udf.rollback_1_of_2 @@ -9,9 +9,11 @@ EXPLAIN (ddl) rollback at post-commit stage 1 of 2; Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t› ADD CONSTRAINT ‹check_b› CHECK (f(‹b›) > ‹1›); └── PostCommitNonRevertiblePhase └── Stage 1 of 1 in PostCommitNonRevertiblePhase - ├── 1 element transitioning toward ABSENT - │ └── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - └── 5 Mutation operations + ├── 2 elements transitioning toward ABSENT + │ ├── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_b, ConstraintID: 2} + └── 6 Mutation operations + ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":104} ├── RemoveCheckConstraint {"ConstraintID":2,"TableID":104} ├── RemoveTableConstraintBackReferencesFromFunctions {"BackReferencedConstraintID":2,"BackReferencedTableID":104} ├── RemoveJobStateFromDescriptor {"DescriptorID":104} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_udf.rollback_2_of_2 b/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_udf.rollback_2_of_2 index bd24189aa9c9..b3e7c6e68a0f 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_udf.rollback_2_of_2 +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_udf.rollback_2_of_2 @@ -9,9 +9,11 @@ EXPLAIN (ddl) rollback at post-commit stage 2 of 2; Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t› ADD CONSTRAINT ‹check_b› CHECK (f(‹b›) > ‹1›); └── PostCommitNonRevertiblePhase └── Stage 1 of 1 in PostCommitNonRevertiblePhase - ├── 1 element transitioning toward ABSENT - │ └── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - └── 5 Mutation operations + ├── 2 elements transitioning toward ABSENT + │ ├── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_b, ConstraintID: 2} + └── 6 Mutation operations + ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":104} ├── RemoveCheckConstraint {"ConstraintID":2,"TableID":104} ├── RemoveTableConstraintBackReferencesFromFunctions {"BackReferencedConstraintID":2,"BackReferencedTableID":104} ├── RemoveJobStateFromDescriptor {"DescriptorID":104} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_vanilla b/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_vanilla index fc4103302277..cc14bddaf9fb 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_vanilla +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_vanilla @@ -8,21 +8,26 @@ EXPLAIN (ddl) ALTER TABLE t ADD CHECK (i > 0) Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› ADD CHECK (‹i› > ‹0›); ├── StatementPhase │ └── Stage 1 of 1 in StatementPhase - │ ├── 1 element transitioning toward PUBLIC - │ │ └── ABSENT → WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ └── 1 Mutation operation - │ └── AddCheckConstraint {"CheckExpr":"i \u003e 0:::INT8","ConstraintID":2,"TableID":104,"Validity":2} + │ ├── 2 elements transitioning toward PUBLIC + │ │ ├── ABSENT → WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ │ └── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} + │ └── 2 Mutation operations + │ ├── AddCheckConstraint {"CheckExpr":"i \u003e 0:::INT8","ConstraintID":2,"TableID":104,"Validity":2} + │ └── SetConstraintName {"ConstraintID":2,"Name":"check_i","TableID":104} ├── PreCommitPhase │ ├── Stage 1 of 2 in PreCommitPhase - │ │ ├── 1 element transitioning toward PUBLIC - │ │ │ └── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ │ ├── 2 elements transitioning toward PUBLIC + │ │ │ ├── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ │ │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} │ │ └── 1 Mutation operation │ │ └── UndoAllInTxnImmediateMutationOpSideEffects │ └── Stage 2 of 2 in PreCommitPhase - │ ├── 1 element transitioning toward PUBLIC - │ │ └── ABSENT → WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ └── 3 Mutation operations + │ ├── 2 elements transitioning toward PUBLIC + │ │ ├── ABSENT → WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ │ └── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} + │ └── 4 Mutation operations │ ├── AddCheckConstraint {"CheckExpr":"i \u003e 0:::INT8","ConstraintID":2,"TableID":104,"Validity":2} + │ ├── SetConstraintName {"ConstraintID":2,"Name":"check_i","TableID":104} │ ├── SetJobStateOnDescriptor {"DescriptorID":104,"Initialize":true} │ └── CreateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} └── PostCommitPhase @@ -32,11 +37,9 @@ Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› ADD CHEC │ └── 1 Validation operation │ └── ValidateConstraint {"ConstraintID":2,"TableID":104} └── Stage 2 of 2 in PostCommitPhase - ├── 2 elements transitioning toward PUBLIC - │ ├── VALIDATED → PUBLIC CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ └── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} - └── 4 Mutation operations - ├── SetConstraintName {"ConstraintID":2,"Name":"check_i","TableID":104} + ├── 1 element transitioning toward PUBLIC + │ └── VALIDATED → PUBLIC CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + └── 3 Mutation operations ├── MakeValidatedCheckConstraintPublic {"ConstraintID":2,"TableID":104} ├── RemoveJobStateFromDescriptor {"DescriptorID":104} └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"all stages compl..."} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_vanilla.rollback_1_of_2 b/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_vanilla.rollback_1_of_2 index 6efdcf37e6e2..7d565e07de0a 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_vanilla.rollback_1_of_2 +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_vanilla.rollback_1_of_2 @@ -9,9 +9,11 @@ EXPLAIN (ddl) rollback at post-commit stage 1 of 2; Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t› ADD CHECK (‹i› > ‹0›); └── PostCommitNonRevertiblePhase └── Stage 1 of 1 in PostCommitNonRevertiblePhase - ├── 1 element transitioning toward ABSENT - │ └── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - └── 3 Mutation operations + ├── 2 elements transitioning toward ABSENT + │ ├── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} + └── 4 Mutation operations + ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":104} ├── RemoveCheckConstraint {"ConstraintID":2,"TableID":104} ├── RemoveJobStateFromDescriptor {"DescriptorID":104} └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"all stages compl..."} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_vanilla.rollback_2_of_2 b/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_vanilla.rollback_2_of_2 index e6abbc38bbe0..3e121399201c 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_vanilla.rollback_2_of_2 +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_vanilla.rollback_2_of_2 @@ -9,9 +9,11 @@ EXPLAIN (ddl) rollback at post-commit stage 2 of 2; Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t› ADD CHECK (‹i› > ‹0›); └── PostCommitNonRevertiblePhase └── Stage 1 of 1 in PostCommitNonRevertiblePhase - ├── 1 element transitioning toward ABSENT - │ └── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - └── 3 Mutation operations + ├── 2 elements transitioning toward ABSENT + │ ├── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} + └── 4 Mutation operations + ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":104} ├── RemoveCheckConstraint {"ConstraintID":2,"TableID":104} ├── RemoveJobStateFromDescriptor {"DescriptorID":104} └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"all stages compl..."} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_with_seq_and_udt b/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_with_seq_and_udt index b772bfb84161..49016482ba22 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_with_seq_and_udt +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_with_seq_and_udt @@ -9,25 +9,30 @@ EXPLAIN (ddl) ALTER TABLE t ADD CHECK (i > nextval('s') OR j::typ = 'a'); Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› ADD CHECK ((‹i› > nextval(‹'s'›)) OR (‹j›::‹typ› = ‹'a'›)); ├── StatementPhase │ └── Stage 1 of 1 in StatementPhase - │ ├── 1 element transitioning toward PUBLIC - │ │ └── ABSENT → WRITE_ONLY CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} - │ └── 3 Mutation operations + │ ├── 2 elements transitioning toward PUBLIC + │ │ ├── ABSENT → WRITE_ONLY CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} + │ │ └── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 107, Name: check_i_j, ConstraintID: 2} + │ └── 4 Mutation operations │ ├── AddCheckConstraint {"CheckExpr":"(i \u003e nextval(104...","ConstraintID":2,"TableID":107,"Validity":2} │ ├── UpdateTableBackReferencesInTypes {"BackReferencedTableID":107} - │ └── UpdateTableBackReferencesInSequences {"BackReferencedTableID":107} + │ ├── UpdateTableBackReferencesInSequences {"BackReferencedTableID":107} + │ └── SetConstraintName {"ConstraintID":2,"Name":"check_i_j","TableID":107} ├── PreCommitPhase │ ├── Stage 1 of 2 in PreCommitPhase - │ │ ├── 1 element transitioning toward PUBLIC - │ │ │ └── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} + │ │ ├── 2 elements transitioning toward PUBLIC + │ │ │ ├── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} + │ │ │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 107, Name: check_i_j, ConstraintID: 2} │ │ └── 1 Mutation operation │ │ └── UndoAllInTxnImmediateMutationOpSideEffects │ └── Stage 2 of 2 in PreCommitPhase - │ ├── 1 element transitioning toward PUBLIC - │ │ └── ABSENT → WRITE_ONLY CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} - │ └── 8 Mutation operations + │ ├── 2 elements transitioning toward PUBLIC + │ │ ├── ABSENT → WRITE_ONLY CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} + │ │ └── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 107, Name: check_i_j, ConstraintID: 2} + │ └── 9 Mutation operations │ ├── AddCheckConstraint {"CheckExpr":"(i \u003e nextval(104...","ConstraintID":2,"TableID":107,"Validity":2} │ ├── UpdateTableBackReferencesInTypes {"BackReferencedTableID":107} │ ├── UpdateTableBackReferencesInSequences {"BackReferencedTableID":107} + │ ├── SetConstraintName {"ConstraintID":2,"Name":"check_i_j","TableID":107} │ ├── SetJobStateOnDescriptor {"DescriptorID":104,"Initialize":true} │ ├── SetJobStateOnDescriptor {"DescriptorID":105,"Initialize":true} │ ├── SetJobStateOnDescriptor {"DescriptorID":106,"Initialize":true} @@ -40,11 +45,9 @@ Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› ADD CHEC │ └── 1 Validation operation │ └── ValidateConstraint {"ConstraintID":2,"TableID":107} └── Stage 2 of 2 in PostCommitPhase - ├── 2 elements transitioning toward PUBLIC - │ ├── VALIDATED → PUBLIC CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} - │ └── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 107, Name: check_i_j, ConstraintID: 2} - └── 7 Mutation operations - ├── SetConstraintName {"ConstraintID":2,"Name":"check_i_j","TableID":107} + ├── 1 element transitioning toward PUBLIC + │ └── VALIDATED → PUBLIC CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} + └── 6 Mutation operations ├── MakeValidatedCheckConstraintPublic {"ConstraintID":2,"TableID":107} ├── RemoveJobStateFromDescriptor {"DescriptorID":104} ├── RemoveJobStateFromDescriptor {"DescriptorID":105} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_with_seq_and_udt.rollback_1_of_2 b/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_with_seq_and_udt.rollback_1_of_2 index 90117e8eaf53..9d845a48293c 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_with_seq_and_udt.rollback_1_of_2 +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_with_seq_and_udt.rollback_1_of_2 @@ -10,9 +10,11 @@ EXPLAIN (ddl) rollback at post-commit stage 1 of 2; Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t› ADD CHECK ((‹i› > nextval(‹'s'›)) OR (‹j›::‹typ› = ‹'a'›)); └── PostCommitNonRevertiblePhase └── Stage 1 of 1 in PostCommitNonRevertiblePhase - ├── 1 element transitioning toward ABSENT - │ └── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} - └── 8 Mutation operations + ├── 2 elements transitioning toward ABSENT + │ ├── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} + │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 107, Name: check_i_j, ConstraintID: 2} + └── 9 Mutation operations + ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":107} ├── RemoveCheckConstraint {"ConstraintID":2,"TableID":107} ├── UpdateTableBackReferencesInTypes {"BackReferencedTableID":107} ├── UpdateTableBackReferencesInSequences {"BackReferencedTableID":107} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_with_seq_and_udt.rollback_2_of_2 b/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_with_seq_and_udt.rollback_2_of_2 index cb0015648427..d3469905bc64 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_with_seq_and_udt.rollback_2_of_2 +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_add_check_with_seq_and_udt.rollback_2_of_2 @@ -10,9 +10,11 @@ EXPLAIN (ddl) rollback at post-commit stage 2 of 2; Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t› ADD CHECK ((‹i› > nextval(‹'s'›)) OR (‹j›::‹typ› = ‹'a'›)); └── PostCommitNonRevertiblePhase └── Stage 1 of 1 in PostCommitNonRevertiblePhase - ├── 1 element transitioning toward ABSENT - │ └── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} - └── 8 Mutation operations + ├── 2 elements transitioning toward ABSENT + │ ├── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} + │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 107, Name: check_i_j, ConstraintID: 2} + └── 9 Mutation operations + ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":107} ├── RemoveCheckConstraint {"ConstraintID":2,"TableID":107} ├── UpdateTableBackReferencesInTypes {"BackReferencedTableID":107} ├── UpdateTableBackReferencesInSequences {"BackReferencedTableID":107} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_add_foreign_key b/pkg/sql/schemachanger/testdata/explain/alter_table_add_foreign_key index f01f6f97a85f..33b97a3d188d 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_add_foreign_key +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_add_foreign_key @@ -1,6 +1,9 @@ /* setup */ CREATE TABLE t1 (i INT PRIMARY KEY); CREATE TABLE t2 (i INT PRIMARY KEY); +INSERT INTO t2 VALUES(-1); +INSERT INTO t2 VALUES(-2); +INSERT INTO t2 VALUES(-3); /* test */ EXPLAIN (ddl) ALTER TABLE t1 ADD FOREIGN KEY (i) REFERENCES t2(i); @@ -8,21 +11,26 @@ EXPLAIN (ddl) ALTER TABLE t1 ADD FOREIGN KEY (i) REFERENCES t2(i); Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t1› ADD CONSTRAINT ‹t1_i_fkey› FOREIGN KEY (‹i›) REFERENCES ‹defaultdb›.‹public›.‹t2› (‹i›); ├── StatementPhase │ └── Stage 1 of 1 in StatementPhase - │ ├── 1 element transitioning toward PUBLIC - │ │ └── ABSENT → WRITE_ONLY ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} - │ └── 1 Mutation operation - │ └── AddForeignKeyConstraint {"ConstraintID":2,"ReferencedTableID":105,"TableID":104,"Validity":2} + │ ├── 2 elements transitioning toward PUBLIC + │ │ ├── ABSENT → WRITE_ONLY ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} + │ │ └── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: t1_i_fkey, ConstraintID: 2} + │ └── 2 Mutation operations + │ ├── AddForeignKeyConstraint {"ConstraintID":2,"ReferencedTableID":105,"TableID":104,"Validity":2} + │ └── SetConstraintName {"ConstraintID":2,"Name":"t1_i_fkey","TableID":104} ├── PreCommitPhase │ ├── Stage 1 of 2 in PreCommitPhase - │ │ ├── 1 element transitioning toward PUBLIC - │ │ │ └── WRITE_ONLY → ABSENT ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} + │ │ ├── 2 elements transitioning toward PUBLIC + │ │ │ ├── WRITE_ONLY → ABSENT ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} + │ │ │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: t1_i_fkey, ConstraintID: 2} │ │ └── 1 Mutation operation │ │ └── UndoAllInTxnImmediateMutationOpSideEffects │ └── Stage 2 of 2 in PreCommitPhase - │ ├── 1 element transitioning toward PUBLIC - │ │ └── ABSENT → WRITE_ONLY ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} - │ └── 4 Mutation operations + │ ├── 2 elements transitioning toward PUBLIC + │ │ ├── ABSENT → WRITE_ONLY ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} + │ │ └── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: t1_i_fkey, ConstraintID: 2} + │ └── 5 Mutation operations │ ├── AddForeignKeyConstraint {"ConstraintID":2,"ReferencedTableID":105,"TableID":104,"Validity":2} + │ ├── SetConstraintName {"ConstraintID":2,"Name":"t1_i_fkey","TableID":104} │ ├── SetJobStateOnDescriptor {"DescriptorID":104,"Initialize":true} │ ├── SetJobStateOnDescriptor {"DescriptorID":105,"Initialize":true} │ └── CreateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} @@ -33,11 +41,9 @@ Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t1› ADD CON │ └── 1 Validation operation │ └── ValidateConstraint {"ConstraintID":2,"TableID":104} └── Stage 2 of 2 in PostCommitPhase - ├── 2 elements transitioning toward PUBLIC - │ ├── VALIDATED → PUBLIC ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} - │ └── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: t1_i_fkey, ConstraintID: 2} - └── 5 Mutation operations - ├── SetConstraintName {"ConstraintID":2,"Name":"t1_i_fkey","TableID":104} + ├── 1 element transitioning toward PUBLIC + │ └── VALIDATED → PUBLIC ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} + └── 4 Mutation operations ├── MakeValidatedForeignKeyConstraintPublic {"ConstraintID":2,"ReferencedTableID":105,"TableID":104} ├── RemoveJobStateFromDescriptor {"DescriptorID":104} ├── RemoveJobStateFromDescriptor {"DescriptorID":105} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_add_foreign_key.rollback_1_of_2 b/pkg/sql/schemachanger/testdata/explain/alter_table_add_foreign_key.rollback_1_of_2 index ec1f54603731..797f3a302b28 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_add_foreign_key.rollback_1_of_2 +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_add_foreign_key.rollback_1_of_2 @@ -1,6 +1,9 @@ /* setup */ CREATE TABLE t1 (i INT PRIMARY KEY); CREATE TABLE t2 (i INT PRIMARY KEY); +INSERT INTO t2 VALUES(-1); +INSERT INTO t2 VALUES(-2); +INSERT INTO t2 VALUES(-3); /* test */ ALTER TABLE t1 ADD FOREIGN KEY (i) REFERENCES t2(i); @@ -9,9 +12,11 @@ EXPLAIN (ddl) rollback at post-commit stage 1 of 2; Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t1› ADD CONSTRAINT ‹t1_i_fkey› FOREIGN KEY (‹i›) REFERENCES ‹defaultdb›.public.‹t2› (‹i›); └── PostCommitNonRevertiblePhase └── Stage 1 of 1 in PostCommitNonRevertiblePhase - ├── 1 element transitioning toward ABSENT - │ └── WRITE_ONLY → ABSENT ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} - └── 5 Mutation operations + ├── 2 elements transitioning toward ABSENT + │ ├── WRITE_ONLY → ABSENT ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} + │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: t1_i_fkey, ConstraintID: 2} + └── 6 Mutation operations + ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":104} ├── RemoveForeignKeyBackReference {"OriginConstraintID":2,"OriginTableID":104,"ReferencedTableID":105} ├── RemoveForeignKeyConstraint {"ConstraintID":2,"TableID":104} ├── RemoveJobStateFromDescriptor {"DescriptorID":104} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_add_foreign_key.rollback_2_of_2 b/pkg/sql/schemachanger/testdata/explain/alter_table_add_foreign_key.rollback_2_of_2 index ed38dff2d1b2..f847de8e8417 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_add_foreign_key.rollback_2_of_2 +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_add_foreign_key.rollback_2_of_2 @@ -1,6 +1,9 @@ /* setup */ CREATE TABLE t1 (i INT PRIMARY KEY); CREATE TABLE t2 (i INT PRIMARY KEY); +INSERT INTO t2 VALUES(-1); +INSERT INTO t2 VALUES(-2); +INSERT INTO t2 VALUES(-3); /* test */ ALTER TABLE t1 ADD FOREIGN KEY (i) REFERENCES t2(i); @@ -9,9 +12,11 @@ EXPLAIN (ddl) rollback at post-commit stage 2 of 2; Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t1› ADD CONSTRAINT ‹t1_i_fkey› FOREIGN KEY (‹i›) REFERENCES ‹defaultdb›.public.‹t2› (‹i›); └── PostCommitNonRevertiblePhase └── Stage 1 of 1 in PostCommitNonRevertiblePhase - ├── 1 element transitioning toward ABSENT - │ └── WRITE_ONLY → ABSENT ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} - └── 5 Mutation operations + ├── 2 elements transitioning toward ABSENT + │ ├── WRITE_ONLY → ABSENT ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} + │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: t1_i_fkey, ConstraintID: 2} + └── 6 Mutation operations + ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":104} ├── RemoveForeignKeyBackReference {"OriginConstraintID":2,"OriginTableID":104,"ReferencedTableID":105} ├── RemoveForeignKeyConstraint {"ConstraintID":2,"TableID":104} ├── RemoveJobStateFromDescriptor {"DescriptorID":104} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_add_unique_without_index b/pkg/sql/schemachanger/testdata/explain/alter_table_add_unique_without_index index 886e161a8cbe..542c2e593053 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_add_unique_without_index +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_add_unique_without_index @@ -1,6 +1,9 @@ /* setup */ CREATE TABLE t (i INT PRIMARY KEY, j INT); SET experimental_enable_unique_without_index_constraints = true; +INSERT INTO t VALUES(-1, -1); +INSERT INTO t VALUES(-2, -2); +INSERT INTO t VALUES(-3, -3); /* test */ EXPLAIN (ddl) ALTER TABLE t ADD UNIQUE WITHOUT INDEX (j); @@ -8,21 +11,26 @@ EXPLAIN (ddl) ALTER TABLE t ADD UNIQUE WITHOUT INDEX (j); Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› ADD CONSTRAINT ‹unique_j› UNIQUE WITHOUT INDEX (‹j›); ├── StatementPhase │ └── Stage 1 of 1 in StatementPhase - │ ├── 1 element transitioning toward PUBLIC - │ │ └── ABSENT → WRITE_ONLY UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} - │ └── 1 Mutation operation - │ └── AddUniqueWithoutIndexConstraint {"ConstraintID":2,"TableID":104,"Validity":2} + │ ├── 2 elements transitioning toward PUBLIC + │ │ ├── ABSENT → WRITE_ONLY UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} + │ │ └── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} + │ └── 2 Mutation operations + │ ├── AddUniqueWithoutIndexConstraint {"ConstraintID":2,"TableID":104,"Validity":2} + │ └── SetConstraintName {"ConstraintID":2,"Name":"unique_j","TableID":104} ├── PreCommitPhase │ ├── Stage 1 of 2 in PreCommitPhase - │ │ ├── 1 element transitioning toward PUBLIC - │ │ │ └── WRITE_ONLY → ABSENT UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} + │ │ ├── 2 elements transitioning toward PUBLIC + │ │ │ ├── WRITE_ONLY → ABSENT UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} + │ │ │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} │ │ └── 1 Mutation operation │ │ └── UndoAllInTxnImmediateMutationOpSideEffects │ └── Stage 2 of 2 in PreCommitPhase - │ ├── 1 element transitioning toward PUBLIC - │ │ └── ABSENT → WRITE_ONLY UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} - │ └── 3 Mutation operations + │ ├── 2 elements transitioning toward PUBLIC + │ │ ├── ABSENT → WRITE_ONLY UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} + │ │ └── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} + │ └── 4 Mutation operations │ ├── AddUniqueWithoutIndexConstraint {"ConstraintID":2,"TableID":104,"Validity":2} + │ ├── SetConstraintName {"ConstraintID":2,"Name":"unique_j","TableID":104} │ ├── SetJobStateOnDescriptor {"DescriptorID":104,"Initialize":true} │ └── CreateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} └── PostCommitPhase @@ -32,11 +40,9 @@ Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› ADD CONS │ └── 1 Validation operation │ └── ValidateConstraint {"ConstraintID":2,"TableID":104} └── Stage 2 of 2 in PostCommitPhase - ├── 2 elements transitioning toward PUBLIC - │ ├── VALIDATED → PUBLIC UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} - │ └── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} - └── 4 Mutation operations - ├── SetConstraintName {"ConstraintID":2,"Name":"unique_j","TableID":104} + ├── 1 element transitioning toward PUBLIC + │ └── VALIDATED → PUBLIC UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} + └── 3 Mutation operations ├── MakeValidatedUniqueWithoutIndexConstraintPublic {"ConstraintID":2,"TableID":104} ├── RemoveJobStateFromDescriptor {"DescriptorID":104} └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"all stages compl..."} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_add_unique_without_index.rollback_1_of_2 b/pkg/sql/schemachanger/testdata/explain/alter_table_add_unique_without_index.rollback_1_of_2 index 50da00569aee..e8b15463de95 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_add_unique_without_index.rollback_1_of_2 +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_add_unique_without_index.rollback_1_of_2 @@ -1,6 +1,9 @@ /* setup */ CREATE TABLE t (i INT PRIMARY KEY, j INT); SET experimental_enable_unique_without_index_constraints = true; +INSERT INTO t VALUES(-1, -1); +INSERT INTO t VALUES(-2, -2); +INSERT INTO t VALUES(-3, -3); /* test */ ALTER TABLE t ADD UNIQUE WITHOUT INDEX (j); @@ -9,9 +12,11 @@ EXPLAIN (ddl) rollback at post-commit stage 1 of 2; Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t› ADD CONSTRAINT ‹unique_j› UNIQUE WITHOUT INDEX (‹j›); └── PostCommitNonRevertiblePhase └── Stage 1 of 1 in PostCommitNonRevertiblePhase - ├── 1 element transitioning toward ABSENT - │ └── WRITE_ONLY → ABSENT UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} - └── 3 Mutation operations + ├── 2 elements transitioning toward ABSENT + │ ├── WRITE_ONLY → ABSENT UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} + │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} + └── 4 Mutation operations + ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":104} ├── RemoveUniqueWithoutIndexConstraint {"ConstraintID":2,"TableID":104} ├── RemoveJobStateFromDescriptor {"DescriptorID":104} └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"all stages compl..."} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_add_unique_without_index.rollback_2_of_2 b/pkg/sql/schemachanger/testdata/explain/alter_table_add_unique_without_index.rollback_2_of_2 index 0d35284f8d81..2354732feabc 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_add_unique_without_index.rollback_2_of_2 +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_add_unique_without_index.rollback_2_of_2 @@ -1,6 +1,9 @@ /* setup */ CREATE TABLE t (i INT PRIMARY KEY, j INT); SET experimental_enable_unique_without_index_constraints = true; +INSERT INTO t VALUES(-1, -1); +INSERT INTO t VALUES(-2, -2); +INSERT INTO t VALUES(-3, -3); /* test */ ALTER TABLE t ADD UNIQUE WITHOUT INDEX (j); @@ -9,9 +12,11 @@ EXPLAIN (ddl) rollback at post-commit stage 2 of 2; Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t› ADD CONSTRAINT ‹unique_j› UNIQUE WITHOUT INDEX (‹j›); └── PostCommitNonRevertiblePhase └── Stage 1 of 1 in PostCommitNonRevertiblePhase - ├── 1 element transitioning toward ABSENT - │ └── WRITE_ONLY → ABSENT UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} - └── 3 Mutation operations + ├── 2 elements transitioning toward ABSENT + │ ├── WRITE_ONLY → ABSENT UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} + │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} + └── 4 Mutation operations + ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":104} ├── RemoveUniqueWithoutIndexConstraint {"ConstraintID":2,"TableID":104} ├── RemoveJobStateFromDescriptor {"DescriptorID":104} └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"all stages compl..."} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash b/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash index af401db76f82..2613d21d0e5f 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash @@ -7,11 +7,12 @@ EXPLAIN (ddl) ALTER TABLE t ALTER PRIMARY KEY USING COLUMNS (j) USING HASH WITH Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› ALTER PRIMARY KEY USING COLUMNS (‹j›) USING HASH WITH (‹bucket_count› = ‹3›); ├── StatementPhase │ └── Stage 1 of 1 in StatementPhase - │ ├── 18 elements transitioning toward PUBLIC + │ ├── 19 elements transitioning toward PUBLIC │ │ ├── ABSENT → DELETE_ONLY Column:{DescID: 104, ColumnID: 3} │ │ ├── ABSENT → PUBLIC ColumnName:{DescID: 104, Name: crdb_internal_j_shard_3, ColumnID: 3} │ │ ├── ABSENT → PUBLIC ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 3} │ │ ├── ABSENT → WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} + │ │ ├── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} │ │ ├── ABSENT → BACKFILL_ONLY PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 3, TemporaryIndexID: 3, SourceIndexID: 1} │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2} │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 2} @@ -32,11 +33,12 @@ Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› ALTER PR │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 3} │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3} │ │ └── ABSENT → DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 6, SourceIndexID: 1} - │ └── 21 Mutation operations + │ └── 22 Mutation operations │ ├── MakeAbsentColumnDeleteOnly {"Column":{"ColumnID":3,"IsHidden":true,"PgAttributeNum":3,"TableID":104}} │ ├── SetColumnName {"ColumnID":3,"Name":"crdb_internal_j_...","TableID":104} │ ├── SetAddedColumnType {"ColumnType":{"ColumnID":3,"IsVirtual":true,"TableID":104}} │ ├── AddCheckConstraint {"CheckExpr":"\"crdb_internal_j...","ConstraintID":2,"FromHashShardedColumn":true,"TableID":104,"Validity":2} + │ ├── SetConstraintName {"ConstraintID":2,"Name":"check_crdb_inter...","TableID":104} │ ├── MakeAbsentIndexBackfilling {"Index":{"ConstraintID":3,"IndexID":2,"IsUnique":true,"SourceIndexID":1,"TableID":104,"TemporaryIndexID":3}} │ ├── AddColumnToIndex {"ColumnID":3,"IndexID":2,"TableID":104} │ ├── AddColumnToIndex {"ColumnID":2,"IndexID":2,"Ordinal":1,"TableID":104} @@ -56,11 +58,12 @@ Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› ALTER PR │ └── SetIndexName {"IndexID":4,"Name":"t_i_key","TableID":104} ├── PreCommitPhase │ ├── Stage 1 of 2 in PreCommitPhase - │ │ ├── 18 elements transitioning toward PUBLIC + │ │ ├── 19 elements transitioning toward PUBLIC │ │ │ ├── DELETE_ONLY → ABSENT Column:{DescID: 104, ColumnID: 3} │ │ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 104, Name: crdb_internal_j_shard_3, ColumnID: 3} │ │ │ ├── PUBLIC → ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 3} │ │ │ ├── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} + │ │ │ ├── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} │ │ │ ├── BACKFILL_ONLY → ABSENT PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 3, TemporaryIndexID: 3, SourceIndexID: 1} │ │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2} │ │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 2} @@ -84,11 +87,12 @@ Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› ALTER PR │ │ └── 1 Mutation operation │ │ └── UndoAllInTxnImmediateMutationOpSideEffects │ └── Stage 2 of 2 in PreCommitPhase - │ ├── 18 elements transitioning toward PUBLIC + │ ├── 19 elements transitioning toward PUBLIC │ │ ├── ABSENT → DELETE_ONLY Column:{DescID: 104, ColumnID: 3} │ │ ├── ABSENT → PUBLIC ColumnName:{DescID: 104, Name: crdb_internal_j_shard_3, ColumnID: 3} │ │ ├── ABSENT → PUBLIC ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 3} │ │ ├── ABSENT → WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} + │ │ ├── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} │ │ ├── ABSENT → BACKFILL_ONLY PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 3, TemporaryIndexID: 3, SourceIndexID: 1} │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2} │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 2} @@ -109,11 +113,12 @@ Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› ALTER PR │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 3} │ │ ├── ABSENT → PUBLIC IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 3} │ │ └── ABSENT → DELETE_ONLY TemporaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 6, SourceIndexID: 1} - │ └── 27 Mutation operations + │ └── 28 Mutation operations │ ├── MakeAbsentColumnDeleteOnly {"Column":{"ColumnID":3,"IsHidden":true,"PgAttributeNum":3,"TableID":104}} │ ├── SetColumnName {"ColumnID":3,"Name":"crdb_internal_j_...","TableID":104} │ ├── SetAddedColumnType {"ColumnType":{"ColumnID":3,"IsVirtual":true,"TableID":104}} │ ├── AddCheckConstraint {"CheckExpr":"\"crdb_internal_j...","ConstraintID":2,"FromHashShardedColumn":true,"TableID":104,"Validity":2} + │ ├── SetConstraintName {"ConstraintID":2,"Name":"check_crdb_inter...","TableID":104} │ ├── MakeAbsentIndexBackfilling {"Index":{"ConstraintID":3,"IndexID":2,"IsUnique":true,"SourceIndexID":1,"TableID":104,"TemporaryIndexID":3}} │ ├── MaybeAddSplitForIndex {"IndexID":2,"TableID":104} │ ├── AddColumnToIndex {"ColumnID":3,"IndexID":2,"TableID":104} @@ -208,11 +213,10 @@ Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› ALTER PR │ └── ValidateConstraint {"ConstraintID":2,"IndexIDForValidation":2,"TableID":104} └── PostCommitNonRevertiblePhase ├── Stage 1 of 3 in PostCommitNonRevertiblePhase - │ ├── 7 elements transitioning toward PUBLIC + │ ├── 6 elements transitioning toward PUBLIC │ │ ├── WRITE_ONLY → PUBLIC Column:{DescID: 104, ColumnID: 3} │ │ ├── VALIDATED → PUBLIC ColumnNotNull:{DescID: 104, ColumnID: 3, IndexID: 2} │ │ ├── VALIDATED → PUBLIC CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} - │ │ ├── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} │ │ ├── VALIDATED → PUBLIC PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 3, TemporaryIndexID: 3, SourceIndexID: 1} │ │ ├── ABSENT → PUBLIC IndexName:{DescID: 104, Name: t_pkey, IndexID: 2} │ │ └── VALIDATED → PUBLIC SecondaryIndex:{DescID: 104, IndexID: 4, ConstraintID: 5, TemporaryIndexID: 5, SourceIndexID: 1} @@ -225,11 +229,11 @@ Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› ALTER PR │ ├── 2 elements transitioning toward ABSENT │ │ ├── PUBLIC → VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} │ │ └── PUBLIC → ABSENT IndexName:{DescID: 104, Name: t_pkey, IndexID: 1} - │ └── 18 Mutation operations + │ └── 17 Mutation operations │ ├── MakePublicPrimaryIndexWriteOnly {"IndexID":1,"TableID":104} │ ├── SetIndexName {"IndexID":1,"Name":"crdb_internal_in...","TableID":104} │ ├── MakeValidatedColumnNotNullPublic {"ColumnID":3,"TableID":104} - │ ├── SetConstraintName {"ConstraintID":2,"Name":"check_crdb_inter...","TableID":104} + │ ├── MakeValidatedCheckConstraintPublic {"ConstraintID":2,"TableID":104} │ ├── SetIndexName {"IndexID":2,"Name":"t_pkey","TableID":104} │ ├── MakeWriteOnlyIndexDeleteOnly {"IndexID":3,"TableID":104} │ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":3,"TableID":104} @@ -238,7 +242,6 @@ Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› ALTER PR │ ├── MakeValidatedSecondaryIndexPublic {"IndexID":4,"TableID":104} │ ├── RefreshStats {"TableID":104} │ ├── MakeWriteOnlyIndexDeleteOnly {"IndexID":5,"TableID":104} - │ ├── MakeValidatedCheckConstraintPublic {"ConstraintID":2,"TableID":104} │ ├── MakeValidatedPrimaryIndexPublic {"IndexID":2,"TableID":104} │ ├── MakeWriteOnlyColumnPublic {"ColumnID":3,"TableID":104} │ ├── RefreshStats {"TableID":104} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_1_of_7 b/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_1_of_7 index 33af1721e53e..13b44d367ed1 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_1_of_7 +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_1_of_7 @@ -8,11 +8,12 @@ EXPLAIN (ddl) rollback at post-commit stage 1 of 7; Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t› ALTER PRIMARY KEY USING COLUMNS (‹j›) USING HASH WITH (‹bucket_count› = ‹3›); └── PostCommitNonRevertiblePhase └── Stage 1 of 1 in PostCommitNonRevertiblePhase - ├── 23 elements transitioning toward ABSENT + ├── 24 elements transitioning toward ABSENT │ ├── DELETE_ONLY → ABSENT Column:{DescID: 104, ColumnID: 3} │ ├── PUBLIC → ABSENT ColumnName:{DescID: 104, Name: crdb_internal_j_shard_3, ColumnID: 3} │ ├── PUBLIC → ABSENT ColumnType:{DescID: 104, ColumnFamilyID: 0, ColumnID: 3} │ ├── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} + │ ├── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} │ ├── BACKFILL_ONLY → ABSENT PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 3, TemporaryIndexID: 3, SourceIndexID: 1} │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2} │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 2} @@ -32,8 +33,9 @@ Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t› A │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 4} │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 5} │ └── PUBLIC → ABSENT IndexName:{DescID: 104, Name: t_i_key, IndexID: 4} - └── 24 Mutation operations + └── 25 Mutation operations ├── SetColumnName {"ColumnID":3,"Name":"crdb_internal_co...","TableID":104} + ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":104} ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":2,"TableID":104} ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":2,"Ordinal":1,"TableID":104} ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":2,"Kind":2,"TableID":104} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_2_of_7 b/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_2_of_7 index 19adc81514a4..d5b8c6338494 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_2_of_7 +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_2_of_7 @@ -8,11 +8,12 @@ EXPLAIN (ddl) rollback at post-commit stage 2 of 7; Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t› ALTER PRIMARY KEY USING COLUMNS (‹j›) USING HASH WITH (‹bucket_count› = ‹3›); └── PostCommitNonRevertiblePhase ├── Stage 1 of 2 in PostCommitNonRevertiblePhase - │ ├── 21 elements transitioning toward ABSENT + │ ├── 22 elements transitioning toward ABSENT │ │ ├── WRITE_ONLY → DELETE_ONLY Column:{DescID: 104, ColumnID: 3} │ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 104, Name: crdb_internal_j_shard_3, ColumnID: 3} │ │ ├── WRITE_ONLY → ABSENT ColumnNotNull:{DescID: 104, ColumnID: 3, IndexID: 2} │ │ ├── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} + │ │ ├── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} │ │ ├── BACKFILL_ONLY → ABSENT PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 3, TemporaryIndexID: 3, SourceIndexID: 1} │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2} │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 2} @@ -30,8 +31,9 @@ Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t› A │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 4} │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 5} │ │ └── PUBLIC → ABSENT IndexName:{DescID: 104, Name: t_i_key, IndexID: 4} - │ └── 23 Mutation operations + │ └── 24 Mutation operations │ ├── SetColumnName {"ColumnID":3,"Name":"crdb_internal_co...","TableID":104} + │ ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":104} │ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":2,"TableID":104} │ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":2,"Ordinal":1,"TableID":104} │ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":2,"Kind":2,"TableID":104} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_3_of_7 b/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_3_of_7 index 1005b03a9f5f..6d918ca8b5e0 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_3_of_7 +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_3_of_7 @@ -8,11 +8,12 @@ EXPLAIN (ddl) rollback at post-commit stage 3 of 7; Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t› ALTER PRIMARY KEY USING COLUMNS (‹j›) USING HASH WITH (‹bucket_count› = ‹3›); └── PostCommitNonRevertiblePhase ├── Stage 1 of 2 in PostCommitNonRevertiblePhase - │ ├── 21 elements transitioning toward ABSENT + │ ├── 22 elements transitioning toward ABSENT │ │ ├── WRITE_ONLY → DELETE_ONLY Column:{DescID: 104, ColumnID: 3} │ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 104, Name: crdb_internal_j_shard_3, ColumnID: 3} │ │ ├── WRITE_ONLY → ABSENT ColumnNotNull:{DescID: 104, ColumnID: 3, IndexID: 2} │ │ ├── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} + │ │ ├── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} │ │ ├── BACKFILL_ONLY → ABSENT PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 3, TemporaryIndexID: 3, SourceIndexID: 1} │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2} │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 2} @@ -30,8 +31,9 @@ Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t› A │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 4} │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 5} │ │ └── PUBLIC → ABSENT IndexName:{DescID: 104, Name: t_i_key, IndexID: 4} - │ └── 23 Mutation operations + │ └── 24 Mutation operations │ ├── SetColumnName {"ColumnID":3,"Name":"crdb_internal_co...","TableID":104} + │ ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":104} │ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":2,"TableID":104} │ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":2,"Ordinal":1,"TableID":104} │ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":2,"Kind":2,"TableID":104} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_4_of_7 b/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_4_of_7 index 03d9150138ae..c959203e9750 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_4_of_7 +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_4_of_7 @@ -8,11 +8,12 @@ EXPLAIN (ddl) rollback at post-commit stage 4 of 7; Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t› ALTER PRIMARY KEY USING COLUMNS (‹j›) USING HASH WITH (‹bucket_count› = ‹3›); └── PostCommitNonRevertiblePhase ├── Stage 1 of 2 in PostCommitNonRevertiblePhase - │ ├── 21 elements transitioning toward ABSENT + │ ├── 22 elements transitioning toward ABSENT │ │ ├── WRITE_ONLY → DELETE_ONLY Column:{DescID: 104, ColumnID: 3} │ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 104, Name: crdb_internal_j_shard_3, ColumnID: 3} │ │ ├── WRITE_ONLY → ABSENT ColumnNotNull:{DescID: 104, ColumnID: 3, IndexID: 2} │ │ ├── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} + │ │ ├── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} │ │ ├── DELETE_ONLY → ABSENT PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 3, TemporaryIndexID: 3, SourceIndexID: 1} │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2} │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 2} @@ -30,8 +31,9 @@ Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t› A │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 4} │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 5} │ │ └── PUBLIC → ABSENT IndexName:{DescID: 104, Name: t_i_key, IndexID: 4} - │ └── 23 Mutation operations + │ └── 24 Mutation operations │ ├── SetColumnName {"ColumnID":3,"Name":"crdb_internal_co...","TableID":104} + │ ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":104} │ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":2,"TableID":104} │ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":2,"Ordinal":1,"TableID":104} │ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":2,"Kind":2,"TableID":104} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_5_of_7 b/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_5_of_7 index fc73936ddb36..fac5dabe563c 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_5_of_7 +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_5_of_7 @@ -8,11 +8,12 @@ EXPLAIN (ddl) rollback at post-commit stage 5 of 7; Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t› ALTER PRIMARY KEY USING COLUMNS (‹j›) USING HASH WITH (‹bucket_count› = ‹3›); └── PostCommitNonRevertiblePhase ├── Stage 1 of 2 in PostCommitNonRevertiblePhase - │ ├── 21 elements transitioning toward ABSENT + │ ├── 22 elements transitioning toward ABSENT │ │ ├── WRITE_ONLY → DELETE_ONLY Column:{DescID: 104, ColumnID: 3} │ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 104, Name: crdb_internal_j_shard_3, ColumnID: 3} │ │ ├── WRITE_ONLY → ABSENT ColumnNotNull:{DescID: 104, ColumnID: 3, IndexID: 2} │ │ ├── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} + │ │ ├── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} │ │ ├── MERGE_ONLY → DELETE_ONLY PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 3, TemporaryIndexID: 3, SourceIndexID: 1} │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2} │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 2} @@ -30,8 +31,9 @@ Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t› A │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 4} │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 5} │ │ └── PUBLIC → ABSENT IndexName:{DescID: 104, Name: t_i_key, IndexID: 4} - │ └── 23 Mutation operations + │ └── 24 Mutation operations │ ├── SetColumnName {"ColumnID":3,"Name":"crdb_internal_co...","TableID":104} + │ ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":104} │ ├── MakeWriteOnlyIndexDeleteOnly {"IndexID":3,"TableID":104} │ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":3,"TableID":104} │ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":3,"Ordinal":1,"TableID":104} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_6_of_7 b/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_6_of_7 index 159581ffa656..9c2d4f5dbd05 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_6_of_7 +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_6_of_7 @@ -8,11 +8,12 @@ EXPLAIN (ddl) rollback at post-commit stage 6 of 7; Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t› ALTER PRIMARY KEY USING COLUMNS (‹j›) USING HASH WITH (‹bucket_count› = ‹3›); └── PostCommitNonRevertiblePhase ├── Stage 1 of 2 in PostCommitNonRevertiblePhase - │ ├── 21 elements transitioning toward ABSENT + │ ├── 22 elements transitioning toward ABSENT │ │ ├── WRITE_ONLY → DELETE_ONLY Column:{DescID: 104, ColumnID: 3} │ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 104, Name: crdb_internal_j_shard_3, ColumnID: 3} │ │ ├── WRITE_ONLY → ABSENT ColumnNotNull:{DescID: 104, ColumnID: 3, IndexID: 2} │ │ ├── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} + │ │ ├── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} │ │ ├── MERGE_ONLY → DELETE_ONLY PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 3, TemporaryIndexID: 3, SourceIndexID: 1} │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2} │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 2} @@ -30,8 +31,9 @@ Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t› A │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 4} │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 5} │ │ └── PUBLIC → ABSENT IndexName:{DescID: 104, Name: t_i_key, IndexID: 4} - │ └── 23 Mutation operations + │ └── 24 Mutation operations │ ├── SetColumnName {"ColumnID":3,"Name":"crdb_internal_co...","TableID":104} + │ ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":104} │ ├── MakeWriteOnlyIndexDeleteOnly {"IndexID":3,"TableID":104} │ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":3,"TableID":104} │ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":3,"Ordinal":1,"TableID":104} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_7_of_7 b/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_7_of_7 index aa3cf2124b71..03cbe0433f77 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_7_of_7 +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_alter_primary_key_using_hash.rollback_7_of_7 @@ -8,11 +8,12 @@ EXPLAIN (ddl) rollback at post-commit stage 7 of 7; Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t› ALTER PRIMARY KEY USING COLUMNS (‹j›) USING HASH WITH (‹bucket_count› = ‹3›); └── PostCommitNonRevertiblePhase ├── Stage 1 of 2 in PostCommitNonRevertiblePhase - │ ├── 21 elements transitioning toward ABSENT + │ ├── 22 elements transitioning toward ABSENT │ │ ├── WRITE_ONLY → DELETE_ONLY Column:{DescID: 104, ColumnID: 3} │ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 104, Name: crdb_internal_j_shard_3, ColumnID: 3} │ │ ├── WRITE_ONLY → ABSENT ColumnNotNull:{DescID: 104, ColumnID: 3, IndexID: 2} │ │ ├── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} + │ │ ├── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} │ │ ├── WRITE_ONLY → DELETE_ONLY PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 3, TemporaryIndexID: 3, SourceIndexID: 1} │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2} │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 2} @@ -30,8 +31,9 @@ Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t› A │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 4} │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 5} │ │ └── PUBLIC → ABSENT IndexName:{DescID: 104, Name: t_i_key, IndexID: 4} - │ └── 23 Mutation operations + │ └── 24 Mutation operations │ ├── SetColumnName {"ColumnID":3,"Name":"crdb_internal_co...","TableID":104} + │ ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":104} │ ├── MakeWriteOnlyIndexDeleteOnly {"IndexID":2,"TableID":104} │ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":2,"TableID":104} │ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":2,"Ordinal":1,"TableID":104} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_drop_constraint_check b/pkg/sql/schemachanger/testdata/explain/alter_table_drop_constraint_check index eb3a1642db5b..e29dcb1777bd 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_drop_constraint_check +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_drop_constraint_check @@ -7,33 +7,30 @@ EXPLAIN (ddl) ALTER TABLE t DROP CONSTRAINT check_i; Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP CONSTRAINT ‹check_i›; ├── StatementPhase │ └── Stage 1 of 1 in StatementPhase - │ ├── 2 elements transitioning toward ABSENT - │ │ ├── PUBLIC → VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} - │ └── 2 Mutation operations - │ ├── MakePublicCheckConstraintValidated {"ConstraintID":2,"TableID":104} - │ └── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":104} + │ ├── 1 element transitioning toward ABSENT + │ │ └── PUBLIC → VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ └── 1 Mutation operation + │ └── MakePublicCheckConstraintValidated {"ConstraintID":2,"TableID":104} ├── PreCommitPhase │ ├── Stage 1 of 2 in PreCommitPhase - │ │ ├── 2 elements transitioning toward ABSENT - │ │ │ ├── VALIDATED → PUBLIC CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ │ │ └── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} + │ │ ├── 1 element transitioning toward ABSENT + │ │ │ └── VALIDATED → PUBLIC CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} │ │ └── 1 Mutation operation │ │ └── UndoAllInTxnImmediateMutationOpSideEffects │ └── Stage 2 of 2 in PreCommitPhase - │ ├── 2 elements transitioning toward ABSENT - │ │ ├── PUBLIC → VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} - │ └── 4 Mutation operations + │ ├── 1 element transitioning toward ABSENT + │ │ └── PUBLIC → VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ └── 3 Mutation operations │ ├── MakePublicCheckConstraintValidated {"ConstraintID":2,"TableID":104} - │ ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":104} │ ├── SetJobStateOnDescriptor {"DescriptorID":104,"Initialize":true} │ └── CreateSchemaChangerJob {"NonCancelable":true,"RunningStatus":"PostCommitNonRev..."} └── PostCommitNonRevertiblePhase └── Stage 1 of 1 in PostCommitNonRevertiblePhase - ├── 1 element transitioning toward ABSENT - │ └── VALIDATED → ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - └── 3 Mutation operations + ├── 2 elements transitioning toward ABSENT + │ ├── VALIDATED → ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} + └── 4 Mutation operations + ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":104} ├── RemoveCheckConstraint {"ConstraintID":2,"TableID":104} ├── RemoveJobStateFromDescriptor {"DescriptorID":104} └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"all stages compl..."} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_drop_constraint_fk b/pkg/sql/schemachanger/testdata/explain/alter_table_drop_constraint_fk index 5dd39fe0cd84..07445f6f1329 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_drop_constraint_fk +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_drop_constraint_fk @@ -8,34 +8,31 @@ EXPLAIN (ddl) ALTER TABLE t1 DROP CONSTRAINT t1_i_fkey; Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t1› DROP CONSTRAINT ‹t1_i_fkey›; ├── StatementPhase │ └── Stage 1 of 1 in StatementPhase - │ ├── 2 elements transitioning toward ABSENT - │ │ ├── PUBLIC → VALIDATED ForeignKeyConstraint:{DescID: 105, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104} - │ │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 105, Name: t1_i_fkey, ConstraintID: 2} - │ └── 2 Mutation operations - │ ├── MakePublicForeignKeyConstraintValidated {"ConstraintID":2,"TableID":105} - │ └── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":105} + │ ├── 1 element transitioning toward ABSENT + │ │ └── PUBLIC → VALIDATED ForeignKeyConstraint:{DescID: 105, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104} + │ └── 1 Mutation operation + │ └── MakePublicForeignKeyConstraintValidated {"ConstraintID":2,"TableID":105} ├── PreCommitPhase │ ├── Stage 1 of 2 in PreCommitPhase - │ │ ├── 2 elements transitioning toward ABSENT - │ │ │ ├── VALIDATED → PUBLIC ForeignKeyConstraint:{DescID: 105, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104} - │ │ │ └── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 105, Name: t1_i_fkey, ConstraintID: 2} + │ │ ├── 1 element transitioning toward ABSENT + │ │ │ └── VALIDATED → PUBLIC ForeignKeyConstraint:{DescID: 105, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104} │ │ └── 1 Mutation operation │ │ └── UndoAllInTxnImmediateMutationOpSideEffects │ └── Stage 2 of 2 in PreCommitPhase - │ ├── 2 elements transitioning toward ABSENT - │ │ ├── PUBLIC → VALIDATED ForeignKeyConstraint:{DescID: 105, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104} - │ │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 105, Name: t1_i_fkey, ConstraintID: 2} - │ └── 5 Mutation operations + │ ├── 1 element transitioning toward ABSENT + │ │ └── PUBLIC → VALIDATED ForeignKeyConstraint:{DescID: 105, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104} + │ └── 4 Mutation operations │ ├── MakePublicForeignKeyConstraintValidated {"ConstraintID":2,"TableID":105} - │ ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":105} │ ├── SetJobStateOnDescriptor {"DescriptorID":104,"Initialize":true} │ ├── SetJobStateOnDescriptor {"DescriptorID":105,"Initialize":true} │ └── CreateSchemaChangerJob {"NonCancelable":true,"RunningStatus":"PostCommitNonRev..."} └── PostCommitNonRevertiblePhase └── Stage 1 of 1 in PostCommitNonRevertiblePhase - ├── 1 element transitioning toward ABSENT - │ └── VALIDATED → ABSENT ForeignKeyConstraint:{DescID: 105, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104} - └── 5 Mutation operations + ├── 2 elements transitioning toward ABSENT + │ ├── VALIDATED → ABSENT ForeignKeyConstraint:{DescID: 105, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104} + │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 105, Name: t1_i_fkey, ConstraintID: 2} + └── 6 Mutation operations + ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":105} ├── RemoveForeignKeyBackReference {"OriginConstraintID":2,"OriginTableID":105,"ReferencedTableID":104} ├── RemoveForeignKeyConstraint {"ConstraintID":2,"TableID":105} ├── RemoveJobStateFromDescriptor {"DescriptorID":104} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_drop_constraint_uwi b/pkg/sql/schemachanger/testdata/explain/alter_table_drop_constraint_uwi index 75337219064a..32801b1713df 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_drop_constraint_uwi +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_drop_constraint_uwi @@ -9,33 +9,30 @@ EXPLAIN (ddl) ALTER TABLE t DROP CONSTRAINT unique_j; Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP CONSTRAINT ‹unique_j›; ├── StatementPhase │ └── Stage 1 of 1 in StatementPhase - │ ├── 2 elements transitioning toward ABSENT - │ │ ├── PUBLIC → VALIDATED UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} - │ │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} - │ └── 2 Mutation operations - │ ├── MakePublicUniqueWithoutIndexConstraintValidated {"ConstraintID":2,"TableID":104} - │ └── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":104} + │ ├── 1 element transitioning toward ABSENT + │ │ └── PUBLIC → VALIDATED UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} + │ └── 1 Mutation operation + │ └── MakePublicUniqueWithoutIndexConstraintValidated {"ConstraintID":2,"TableID":104} ├── PreCommitPhase │ ├── Stage 1 of 2 in PreCommitPhase - │ │ ├── 2 elements transitioning toward ABSENT - │ │ │ ├── VALIDATED → PUBLIC UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} - │ │ │ └── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} + │ │ ├── 1 element transitioning toward ABSENT + │ │ │ └── VALIDATED → PUBLIC UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} │ │ └── 1 Mutation operation │ │ └── UndoAllInTxnImmediateMutationOpSideEffects │ └── Stage 2 of 2 in PreCommitPhase - │ ├── 2 elements transitioning toward ABSENT - │ │ ├── PUBLIC → VALIDATED UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} - │ │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} - │ └── 4 Mutation operations + │ ├── 1 element transitioning toward ABSENT + │ │ └── PUBLIC → VALIDATED UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} + │ └── 3 Mutation operations │ ├── MakePublicUniqueWithoutIndexConstraintValidated {"ConstraintID":2,"TableID":104} - │ ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":104} │ ├── SetJobStateOnDescriptor {"DescriptorID":104,"Initialize":true} │ └── CreateSchemaChangerJob {"NonCancelable":true,"RunningStatus":"PostCommitNonRev..."} └── PostCommitNonRevertiblePhase └── Stage 1 of 1 in PostCommitNonRevertiblePhase - ├── 1 element transitioning toward ABSENT - │ └── VALIDATED → ABSENT UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} - └── 3 Mutation operations + ├── 2 elements transitioning toward ABSENT + │ ├── VALIDATED → ABSENT UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} + │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} + └── 4 Mutation operations + ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":104} ├── RemoveUniqueWithoutIndexConstraint {"ConstraintID":2,"TableID":104} ├── RemoveJobStateFromDescriptor {"DescriptorID":104} └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"all stages compl..."} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_validate_constraint b/pkg/sql/schemachanger/testdata/explain/alter_table_validate_constraint index fa068d983ab5..a354490dc257 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_validate_constraint +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_validate_constraint @@ -8,33 +8,38 @@ EXPLAIN (ddl) ALTER TABLE t VALIDATE CONSTRAINT check_i; Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› VALIDATE CONSTRAINT ‹check_i›; ├── StatementPhase │ └── Stage 1 of 1 in StatementPhase - │ ├── 1 element transitioning toward PUBLIC - │ │ └── ABSENT → WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} + │ ├── 2 elements transitioning toward PUBLIC + │ │ ├── ABSENT → WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} + │ │ └── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 3} │ ├── 2 elements transitioning toward ABSENT │ │ ├── PUBLIC → ABSENT CheckConstraintUnvalidated:{DescID: 104, ConstraintID: 2} │ │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} - │ └── 3 Mutation operations + │ └── 4 Mutation operations │ ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":104} │ ├── AddCheckConstraint {"CheckExpr":"i \u003e 0:::INT8","ConstraintID":3,"TableID":104,"Validity":2} + │ ├── SetConstraintName {"ConstraintID":3,"Name":"check_i","TableID":104} │ └── RemoveCheckConstraint {"ConstraintID":2,"TableID":104} ├── PreCommitPhase │ ├── Stage 1 of 2 in PreCommitPhase - │ │ ├── 1 element transitioning toward PUBLIC - │ │ │ └── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} + │ │ ├── 2 elements transitioning toward PUBLIC + │ │ │ ├── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} + │ │ │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 3} │ │ ├── 2 elements transitioning toward ABSENT │ │ │ ├── ABSENT → PUBLIC CheckConstraintUnvalidated:{DescID: 104, ConstraintID: 2} │ │ │ └── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} │ │ └── 1 Mutation operation │ │ └── UndoAllInTxnImmediateMutationOpSideEffects │ └── Stage 2 of 2 in PreCommitPhase - │ ├── 1 element transitioning toward PUBLIC - │ │ └── ABSENT → WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} + │ ├── 2 elements transitioning toward PUBLIC + │ │ ├── ABSENT → WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} + │ │ └── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 3} │ ├── 2 elements transitioning toward ABSENT │ │ ├── PUBLIC → ABSENT CheckConstraintUnvalidated:{DescID: 104, ConstraintID: 2} │ │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} - │ └── 5 Mutation operations + │ └── 6 Mutation operations │ ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":104} │ ├── AddCheckConstraint {"CheckExpr":"i \u003e 0:::INT8","ConstraintID":3,"TableID":104,"Validity":2} + │ ├── SetConstraintName {"ConstraintID":3,"Name":"check_i","TableID":104} │ ├── RemoveCheckConstraint {"ConstraintID":2,"TableID":104} │ ├── SetJobStateOnDescriptor {"DescriptorID":104,"Initialize":true} │ └── CreateSchemaChangerJob {"RunningStatus":"PostCommitPhase ..."} @@ -45,11 +50,9 @@ Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› VALIDATE │ └── 1 Validation operation │ └── ValidateConstraint {"ConstraintID":3,"TableID":104} └── Stage 2 of 2 in PostCommitPhase - ├── 2 elements transitioning toward PUBLIC - │ ├── VALIDATED → PUBLIC CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} - │ └── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 3} - └── 4 Mutation operations - ├── SetConstraintName {"ConstraintID":3,"Name":"check_i","TableID":104} + ├── 1 element transitioning toward PUBLIC + │ └── VALIDATED → PUBLIC CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} + └── 3 Mutation operations ├── MakeValidatedCheckConstraintPublic {"ConstraintID":3,"TableID":104} ├── RemoveJobStateFromDescriptor {"DescriptorID":104} └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"all stages compl..."} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_validate_constraint.rollback_1_of_2 b/pkg/sql/schemachanger/testdata/explain/alter_table_validate_constraint.rollback_1_of_2 index 427ec5f1f4f3..aac67a68f839 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_validate_constraint.rollback_1_of_2 +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_validate_constraint.rollback_1_of_2 @@ -12,11 +12,13 @@ Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t› V ├── 2 elements transitioning toward PUBLIC │ ├── ABSENT → PUBLIC CheckConstraintUnvalidated:{DescID: 104, ConstraintID: 2} │ └── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} - ├── 1 element transitioning toward ABSENT - │ └── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} - └── 5 Mutation operations + ├── 2 elements transitioning toward ABSENT + │ ├── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} + │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 3} + └── 6 Mutation operations ├── AddCheckConstraint {"CheckExpr":"i \u003e 0:::INT8","ConstraintID":2,"TableID":104,"Validity":1} ├── SetConstraintName {"ConstraintID":2,"Name":"check_i","TableID":104} + ├── SetConstraintName {"ConstraintID":3,"Name":"crdb_internal_co...","TableID":104} ├── RemoveCheckConstraint {"ConstraintID":3,"TableID":104} ├── RemoveJobStateFromDescriptor {"DescriptorID":104} └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"all stages compl..."} diff --git a/pkg/sql/schemachanger/testdata/explain/alter_table_validate_constraint.rollback_2_of_2 b/pkg/sql/schemachanger/testdata/explain/alter_table_validate_constraint.rollback_2_of_2 index ceae1353eff2..700c6900fe95 100644 --- a/pkg/sql/schemachanger/testdata/explain/alter_table_validate_constraint.rollback_2_of_2 +++ b/pkg/sql/schemachanger/testdata/explain/alter_table_validate_constraint.rollback_2_of_2 @@ -12,11 +12,13 @@ Schema change plan for rolling back ALTER TABLE ‹defaultdb›.public.‹t› V ├── 2 elements transitioning toward PUBLIC │ ├── ABSENT → PUBLIC CheckConstraintUnvalidated:{DescID: 104, ConstraintID: 2} │ └── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} - ├── 1 element transitioning toward ABSENT - │ └── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} - └── 5 Mutation operations + ├── 2 elements transitioning toward ABSENT + │ ├── WRITE_ONLY → ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} + │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 3} + └── 6 Mutation operations ├── AddCheckConstraint {"CheckExpr":"i \u003e 0:::INT8","ConstraintID":2,"TableID":104,"Validity":1} ├── SetConstraintName {"ConstraintID":2,"Name":"check_i","TableID":104} + ├── SetConstraintName {"ConstraintID":3,"Name":"crdb_internal_co...","TableID":104} ├── RemoveCheckConstraint {"ConstraintID":3,"TableID":104} ├── RemoveJobStateFromDescriptor {"DescriptorID":104} └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"all stages compl..."} diff --git a/pkg/sql/schemachanger/testdata/explain/drop_index_hash_sharded_index b/pkg/sql/schemachanger/testdata/explain/drop_index_hash_sharded_index index bcfe409474ec..c4c26171c835 100644 --- a/pkg/sql/schemachanger/testdata/explain/drop_index_hash_sharded_index +++ b/pkg/sql/schemachanger/testdata/explain/drop_index_hash_sharded_index @@ -8,51 +8,46 @@ EXPLAIN (ddl) DROP INDEX idx CASCADE; Schema change plan for DROP INDEX ‹defaultdb›.‹public›.‹t›@‹idx› CASCADE; ├── StatementPhase │ └── Stage 1 of 1 in StatementPhase - │ ├── 6 elements transitioning toward ABSENT + │ ├── 5 elements transitioning toward ABSENT │ │ ├── PUBLIC → WRITE_ONLY Column:{DescID: 104, ColumnID: 3} │ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 104, Name: crdb_internal_j_shard_16, ColumnID: 3} │ │ ├── PUBLIC → VALIDATED ColumnNotNull:{DescID: 104, ColumnID: 3, IndexID: 0} │ │ ├── PUBLIC → VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} - │ │ ├── PUBLIC → VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_16, ConstraintID: 2} - │ └── 6 Mutation operations + │ │ └── PUBLIC → VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ └── 5 Mutation operations │ ├── MakePublicColumnNotNullValidated {"ColumnID":3,"TableID":104} │ ├── MakePublicSecondaryIndexWriteOnly {"IndexID":2,"TableID":104} │ ├── MakePublicCheckConstraintValidated {"ConstraintID":2,"TableID":104} - │ ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":104} │ ├── MakePublicColumnWriteOnly {"ColumnID":3,"TableID":104} │ └── SetColumnName {"ColumnID":3,"Name":"crdb_internal_co...","TableID":104} ├── PreCommitPhase │ ├── Stage 1 of 2 in PreCommitPhase - │ │ ├── 6 elements transitioning toward ABSENT + │ │ ├── 5 elements transitioning toward ABSENT │ │ │ ├── WRITE_ONLY → PUBLIC Column:{DescID: 104, ColumnID: 3} │ │ │ ├── ABSENT → PUBLIC ColumnName:{DescID: 104, Name: crdb_internal_j_shard_16, ColumnID: 3} │ │ │ ├── VALIDATED → PUBLIC ColumnNotNull:{DescID: 104, ColumnID: 3, IndexID: 0} │ │ │ ├── VALIDATED → PUBLIC SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} - │ │ │ ├── VALIDATED → PUBLIC CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ │ │ └── ABSENT → PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_16, ConstraintID: 2} + │ │ │ └── VALIDATED → PUBLIC CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} │ │ └── 1 Mutation operation │ │ └── UndoAllInTxnImmediateMutationOpSideEffects │ └── Stage 2 of 2 in PreCommitPhase - │ ├── 6 elements transitioning toward ABSENT + │ ├── 5 elements transitioning toward ABSENT │ │ ├── PUBLIC → WRITE_ONLY Column:{DescID: 104, ColumnID: 3} │ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 104, Name: crdb_internal_j_shard_16, ColumnID: 3} │ │ ├── PUBLIC → VALIDATED ColumnNotNull:{DescID: 104, ColumnID: 3, IndexID: 0} │ │ ├── PUBLIC → VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} - │ │ ├── PUBLIC → VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_16, ConstraintID: 2} - │ └── 8 Mutation operations + │ │ └── PUBLIC → VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ └── 7 Mutation operations │ ├── MakePublicColumnNotNullValidated {"ColumnID":3,"TableID":104} │ ├── MakePublicSecondaryIndexWriteOnly {"IndexID":2,"TableID":104} │ ├── MakePublicCheckConstraintValidated {"ConstraintID":2,"TableID":104} - │ ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":104} │ ├── MakePublicColumnWriteOnly {"ColumnID":3,"TableID":104} │ ├── SetColumnName {"ColumnID":3,"Name":"crdb_internal_co...","TableID":104} │ ├── SetJobStateOnDescriptor {"DescriptorID":104,"Initialize":true} │ └── CreateSchemaChangerJob {"NonCancelable":true,"RunningStatus":"PostCommitNonRev..."} └── PostCommitNonRevertiblePhase ├── Stage 1 of 2 in PostCommitNonRevertiblePhase - │ ├── 8 elements transitioning toward ABSENT + │ ├── 9 elements transitioning toward ABSENT │ │ ├── WRITE_ONLY → DELETE_ONLY Column:{DescID: 104, ColumnID: 3} │ │ ├── VALIDATED → ABSENT ColumnNotNull:{DescID: 104, ColumnID: 3, IndexID: 0} │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 2} @@ -60,13 +55,15 @@ Schema change plan for DROP INDEX ‹defaultdb›.‹public›.‹t›@‹idx› │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 104, ColumnID: 1, IndexID: 2} │ │ ├── VALIDATED → DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} │ │ ├── PUBLIC → ABSENT IndexName:{DescID: 104, Name: idx, IndexID: 2} - │ │ └── VALIDATED → ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ └── 10 Mutation operations + │ │ ├── VALIDATED → ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ │ └── PUBLIC → ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_16, ConstraintID: 2} + │ └── 11 Mutation operations │ ├── RemoveColumnNotNull {"ColumnID":3,"TableID":104} - │ ├── RemoveCheckConstraint {"ConstraintID":2,"TableID":104} + │ ├── SetConstraintName {"ConstraintID":2,"Name":"crdb_internal_co...","TableID":104} │ ├── MakeWriteOnlyColumnDeleteOnly {"ColumnID":3,"TableID":104} │ ├── MakeWriteOnlyIndexDeleteOnly {"IndexID":2,"TableID":104} │ ├── SetIndexName {"IndexID":2,"Name":"crdb_internal_in...","TableID":104} + │ ├── RemoveCheckConstraint {"ConstraintID":2,"TableID":104} │ ├── RemoveColumnFromIndex {"ColumnID":3,"IndexID":2,"TableID":104} │ ├── RemoveColumnFromIndex {"ColumnID":2,"IndexID":2,"Ordinal":1,"TableID":104} │ ├── RemoveColumnFromIndex {"ColumnID":1,"IndexID":2,"Kind":1,"TableID":104} diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_udf b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_udf index 15f988e31dce..4bf9254bc419 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_udf +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_udf @@ -11,15 +11,21 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ADD CONSTRAINT check_b CHECK (f(b) > 1); │ │ │ └── • Stage 1 of 1 in StatementPhase │ │ -│ ├── • 1 element transitioning toward PUBLIC +│ ├── • 2 elements transitioning toward PUBLIC │ │ │ -│ │ └── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} -│ │ │ ABSENT → WRITE_ONLY +│ │ ├── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} +│ │ │ │ ABSENT → WRITE_ONLY +│ │ │ │ +│ │ │ └── • PreviousStagePrecedence dependency from ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} +│ │ │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: ABSENT->WRITE_ONLY" +│ │ │ +│ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_b, ConstraintID: 2} +│ │ │ ABSENT → PUBLIC │ │ │ -│ │ └── • PreviousStagePrecedence dependency from ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} -│ │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: ABSENT->WRITE_ONLY" +│ │ └── • SameStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} +│ │ rule: "simple constraint visible before name" │ │ -│ └── • 2 Mutation operations +│ └── • 3 Mutation operations │ │ │ ├── • AddCheckConstraint │ │ CheckExpr: '[FUNCTION 100105](b) > 1:::INT8' @@ -29,20 +35,28 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ADD CONSTRAINT check_b CHECK (f(b) > 1); │ │ TableID: 104 │ │ Validity: 2 │ │ -│ └── • AddTableConstraintBackReferencesInFunctions -│ BackReferencedConstraintID: 2 -│ BackReferencedTableID: 104 -│ FunctionIDs: -│ - 105 +│ ├── • AddTableConstraintBackReferencesInFunctions +│ │ BackReferencedConstraintID: 2 +│ │ BackReferencedTableID: 104 +│ │ FunctionIDs: +│ │ - 105 +│ │ +│ └── • SetConstraintName +│ ConstraintID: 2 +│ Name: check_b +│ TableID: 104 │ ├── • PreCommitPhase │ │ │ ├── • Stage 1 of 2 in PreCommitPhase │ │ │ -│ │ ├── • 1 element transitioning toward PUBLIC +│ │ ├── • 2 elements transitioning toward PUBLIC +│ │ │ │ +│ │ │ ├── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} +│ │ │ │ WRITE_ONLY → ABSENT │ │ │ │ -│ │ │ └── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} -│ │ │ WRITE_ONLY → ABSENT +│ │ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_b, ConstraintID: 2} +│ │ │ PUBLIC → ABSENT │ │ │ │ │ └── • 1 Mutation operation │ │ │ @@ -51,15 +65,21 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ADD CONSTRAINT check_b CHECK (f(b) > 1); │ │ │ └── • Stage 2 of 2 in PreCommitPhase │ │ -│ ├── • 1 element transitioning toward PUBLIC +│ ├── • 2 elements transitioning toward PUBLIC │ │ │ -│ │ └── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} -│ │ │ ABSENT → WRITE_ONLY +│ │ ├── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} +│ │ │ │ ABSENT → WRITE_ONLY +│ │ │ │ +│ │ │ └── • PreviousStagePrecedence dependency from ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} +│ │ │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: ABSENT->WRITE_ONLY" +│ │ │ +│ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_b, ConstraintID: 2} +│ │ │ ABSENT → PUBLIC │ │ │ -│ │ └── • PreviousStagePrecedence dependency from ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} -│ │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: ABSENT->WRITE_ONLY" +│ │ └── • SameStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} +│ │ rule: "simple constraint visible before name" │ │ -│ └── • 5 Mutation operations +│ └── • 6 Mutation operations │ │ │ ├── • AddCheckConstraint │ │ CheckExpr: '[FUNCTION 100105](b) > 1:::INT8' @@ -75,6 +95,11 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ADD CONSTRAINT check_b CHECK (f(b) > 1); │ │ FunctionIDs: │ │ - 105 │ │ +│ ├── • SetConstraintName +│ │ ConstraintID: 2 +│ │ Name: check_b +│ │ TableID: 104 +│ │ │ ├── • SetJobStateOnDescriptor │ │ DescriptorID: 104 │ │ Initialize: true @@ -117,26 +142,15 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ADD CONSTRAINT check_b CHECK (f(b) > 1); │ └── • Stage 2 of 2 in PostCommitPhase │ - ├── • 2 elements transitioning toward PUBLIC + ├── • 1 element transitioning toward PUBLIC │ │ - │ ├── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ │ │ VALIDATED → PUBLIC - │ │ │ - │ │ ├── • PreviousStagePrecedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ │ │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: VALIDATED->PUBLIC" - │ │ │ - │ │ └── • SameStagePrecedence dependency from PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: check_b, ConstraintID: 2} - │ │ rule: "constraint dependent public right before complex constraint" - │ │ - │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_b, ConstraintID: 2} - │ ABSENT → PUBLIC + │ └── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ │ VALIDATED → PUBLIC + │ │ + │ └── • PreviousStagePrecedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: VALIDATED->PUBLIC" │ - └── • 5 Mutation operations - │ - ├── • SetConstraintName - │ ConstraintID: 2 - │ Name: check_b - │ TableID: 104 + └── • 4 Mutation operations │ ├── • MakeValidatedCheckConstraintPublic │ ConstraintID: 2 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_udf.rollback_1_of_2 b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_udf.rollback_1_of_2 index 6afb36f8186d..42378e066a4c 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_udf.rollback_1_of_2 +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_udf.rollback_1_of_2 @@ -12,18 +12,29 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 1 of 2; │ └── • Stage 1 of 1 in PostCommitNonRevertiblePhase │ - ├── • 1 element transitioning toward ABSENT + ├── • 2 elements transitioning toward ABSENT │ │ - │ └── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ │ WRITE_ONLY → ABSENT - │ │ - │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" + │ ├── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ │ │ WRITE_ONLY → ABSENT + │ │ │ + │ │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" + │ │ │ + │ │ └── • SameStagePrecedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_b, ConstraintID: 2} + │ │ rule: "Constraint should be hidden before name" + │ │ + │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_b, ConstraintID: 2} + │ │ PUBLIC → ABSENT │ │ - │ └── • Precedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_b, ConstraintID: 2} - │ rule: "dependents removed before constraint" + │ └── • Precedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ rule: "Constraint should be hidden before name" │ - └── • 5 Mutation operations + └── • 6 Mutation operations + │ + ├── • SetConstraintName + │ ConstraintID: 2 + │ Name: crdb_internal_constraint_2_name_placeholder + │ TableID: 104 │ ├── • RemoveCheckConstraint │ ConstraintID: 2 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_udf.rollback_2_of_2 b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_udf.rollback_2_of_2 index 4cf121c7db02..33e268c66385 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_udf.rollback_2_of_2 +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_udf.rollback_2_of_2 @@ -12,18 +12,29 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 2 of 2; │ └── • Stage 1 of 1 in PostCommitNonRevertiblePhase │ - ├── • 1 element transitioning toward ABSENT + ├── • 2 elements transitioning toward ABSENT │ │ - │ └── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ │ WRITE_ONLY → ABSENT - │ │ - │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" + │ ├── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ │ │ WRITE_ONLY → ABSENT + │ │ │ + │ │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" + │ │ │ + │ │ └── • SameStagePrecedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_b, ConstraintID: 2} + │ │ rule: "Constraint should be hidden before name" + │ │ + │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_b, ConstraintID: 2} + │ │ PUBLIC → ABSENT │ │ - │ └── • Precedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_b, ConstraintID: 2} - │ rule: "dependents removed before constraint" + │ └── • Precedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ rule: "Constraint should be hidden before name" │ - └── • 5 Mutation operations + └── • 6 Mutation operations + │ + ├── • SetConstraintName + │ ConstraintID: 2 + │ Name: crdb_internal_constraint_2_name_placeholder + │ TableID: 104 │ ├── • RemoveCheckConstraint │ ConstraintID: 2 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_vanilla b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_vanilla index 101b147d5492..6fb38333f467 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_vanilla +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_vanilla @@ -11,32 +11,46 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ADD CHECK (i > 0) │ │ │ └── • Stage 1 of 1 in StatementPhase │ │ -│ ├── • 1 element transitioning toward PUBLIC +│ ├── • 2 elements transitioning toward PUBLIC │ │ │ -│ │ └── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} -│ │ │ ABSENT → WRITE_ONLY +│ │ ├── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} +│ │ │ │ ABSENT → WRITE_ONLY +│ │ │ │ +│ │ │ └── • PreviousStagePrecedence dependency from ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} +│ │ │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: ABSENT->WRITE_ONLY" +│ │ │ +│ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} +│ │ │ ABSENT → PUBLIC │ │ │ -│ │ └── • PreviousStagePrecedence dependency from ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} -│ │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: ABSENT->WRITE_ONLY" +│ │ └── • SameStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} +│ │ rule: "simple constraint visible before name" │ │ -│ └── • 1 Mutation operation +│ └── • 2 Mutation operations +│ │ +│ ├── • AddCheckConstraint +│ │ CheckExpr: i > 0:::INT8 +│ │ ColumnIDs: +│ │ - 1 +│ │ ConstraintID: 2 +│ │ TableID: 104 +│ │ Validity: 2 │ │ -│ └── • AddCheckConstraint -│ CheckExpr: i > 0:::INT8 -│ ColumnIDs: -│ - 1 +│ └── • SetConstraintName │ ConstraintID: 2 +│ Name: check_i │ TableID: 104 -│ Validity: 2 │ ├── • PreCommitPhase │ │ │ ├── • Stage 1 of 2 in PreCommitPhase │ │ │ -│ │ ├── • 1 element transitioning toward PUBLIC +│ │ ├── • 2 elements transitioning toward PUBLIC │ │ │ │ -│ │ │ └── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} -│ │ │ WRITE_ONLY → ABSENT +│ │ │ ├── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} +│ │ │ │ WRITE_ONLY → ABSENT +│ │ │ │ +│ │ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} +│ │ │ PUBLIC → ABSENT │ │ │ │ │ └── • 1 Mutation operation │ │ │ @@ -45,15 +59,21 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ADD CHECK (i > 0) │ │ │ └── • Stage 2 of 2 in PreCommitPhase │ │ -│ ├── • 1 element transitioning toward PUBLIC +│ ├── • 2 elements transitioning toward PUBLIC +│ │ │ +│ │ ├── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} +│ │ │ │ ABSENT → WRITE_ONLY +│ │ │ │ +│ │ │ └── • PreviousStagePrecedence dependency from ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} +│ │ │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: ABSENT->WRITE_ONLY" │ │ │ -│ │ └── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} -│ │ │ ABSENT → WRITE_ONLY +│ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} +│ │ │ ABSENT → PUBLIC │ │ │ -│ │ └── • PreviousStagePrecedence dependency from ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} -│ │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: ABSENT->WRITE_ONLY" +│ │ └── • SameStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} +│ │ rule: "simple constraint visible before name" │ │ -│ └── • 3 Mutation operations +│ └── • 4 Mutation operations │ │ │ ├── • AddCheckConstraint │ │ CheckExpr: i > 0:::INT8 @@ -63,6 +83,11 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ADD CHECK (i > 0) │ │ TableID: 104 │ │ Validity: 2 │ │ +│ ├── • SetConstraintName +│ │ ConstraintID: 2 +│ │ Name: check_i +│ │ TableID: 104 +│ │ │ ├── • SetJobStateOnDescriptor │ │ DescriptorID: 104 │ │ Initialize: true @@ -99,26 +124,15 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ADD CHECK (i > 0) │ └── • Stage 2 of 2 in PostCommitPhase │ - ├── • 2 elements transitioning toward PUBLIC + ├── • 1 element transitioning toward PUBLIC │ │ - │ ├── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ │ │ VALIDATED → PUBLIC - │ │ │ - │ │ ├── • PreviousStagePrecedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ │ │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: VALIDATED->PUBLIC" - │ │ │ - │ │ └── • SameStagePrecedence dependency from PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} - │ │ rule: "constraint dependent public right before complex constraint" - │ │ - │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} - │ ABSENT → PUBLIC + │ └── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ │ VALIDATED → PUBLIC + │ │ + │ └── • PreviousStagePrecedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: VALIDATED->PUBLIC" │ - └── • 4 Mutation operations - │ - ├── • SetConstraintName - │ ConstraintID: 2 - │ Name: check_i - │ TableID: 104 + └── • 3 Mutation operations │ ├── • MakeValidatedCheckConstraintPublic │ ConstraintID: 2 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_vanilla.rollback_1_of_2 b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_vanilla.rollback_1_of_2 index 2dcb3ed0557d..6172ca4907c7 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_vanilla.rollback_1_of_2 +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_vanilla.rollback_1_of_2 @@ -12,18 +12,29 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 1 of 2; │ └── • Stage 1 of 1 in PostCommitNonRevertiblePhase │ - ├── • 1 element transitioning toward ABSENT + ├── • 2 elements transitioning toward ABSENT │ │ - │ └── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ │ WRITE_ONLY → ABSENT - │ │ - │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" + │ ├── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ │ │ WRITE_ONLY → ABSENT + │ │ │ + │ │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" + │ │ │ + │ │ └── • SameStagePrecedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} + │ │ rule: "Constraint should be hidden before name" + │ │ + │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} + │ │ PUBLIC → ABSENT │ │ - │ └── • Precedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} - │ rule: "dependents removed before constraint" + │ └── • Precedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ rule: "Constraint should be hidden before name" │ - └── • 3 Mutation operations + └── • 4 Mutation operations + │ + ├── • SetConstraintName + │ ConstraintID: 2 + │ Name: crdb_internal_constraint_2_name_placeholder + │ TableID: 104 │ ├── • RemoveCheckConstraint │ ConstraintID: 2 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_vanilla.rollback_2_of_2 b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_vanilla.rollback_2_of_2 index 6093f8900a35..3eecd9749dae 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_vanilla.rollback_2_of_2 +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_vanilla.rollback_2_of_2 @@ -12,18 +12,29 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 2 of 2; │ └── • Stage 1 of 1 in PostCommitNonRevertiblePhase │ - ├── • 1 element transitioning toward ABSENT + ├── • 2 elements transitioning toward ABSENT │ │ - │ └── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ │ WRITE_ONLY → ABSENT - │ │ - │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" + │ ├── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ │ │ WRITE_ONLY → ABSENT + │ │ │ + │ │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" + │ │ │ + │ │ └── • SameStagePrecedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} + │ │ rule: "Constraint should be hidden before name" + │ │ + │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} + │ │ PUBLIC → ABSENT │ │ - │ └── • Precedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} - │ rule: "dependents removed before constraint" + │ └── • Precedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ rule: "Constraint should be hidden before name" │ - └── • 3 Mutation operations + └── • 4 Mutation operations + │ + ├── • SetConstraintName + │ ConstraintID: 2 + │ Name: crdb_internal_constraint_2_name_placeholder + │ TableID: 104 │ ├── • RemoveCheckConstraint │ ConstraintID: 2 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_with_seq_and_udt b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_with_seq_and_udt index d9ed6731285c..fbb52df9bd87 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_with_seq_and_udt +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_with_seq_and_udt @@ -12,15 +12,21 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ADD CHECK (i > nextval('s') OR j::typ = 'a' │ │ │ └── • Stage 1 of 1 in StatementPhase │ │ -│ ├── • 1 element transitioning toward PUBLIC +│ ├── • 2 elements transitioning toward PUBLIC │ │ │ -│ │ └── • CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} -│ │ │ ABSENT → WRITE_ONLY +│ │ ├── • CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} +│ │ │ │ ABSENT → WRITE_ONLY +│ │ │ │ +│ │ │ └── • PreviousStagePrecedence dependency from ABSENT CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} +│ │ │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: ABSENT->WRITE_ONLY" +│ │ │ +│ │ └── • ConstraintWithoutIndexName:{DescID: 107, Name: check_i_j, ConstraintID: 2} +│ │ │ ABSENT → PUBLIC │ │ │ -│ │ └── • PreviousStagePrecedence dependency from ABSENT CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} -│ │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: ABSENT->WRITE_ONLY" +│ │ └── • SameStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} +│ │ rule: "simple constraint visible before name" │ │ -│ └── • 3 Mutation operations +│ └── • 4 Mutation operations │ │ │ ├── • AddCheckConstraint │ │ CheckExpr: (i > nextval(104:::REGCLASS)) OR (j::@100105 = b'@':::@100105) @@ -37,19 +43,27 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ADD CHECK (i > nextval('s') OR j::typ = 'a' │ │ - 105 │ │ - 106 │ │ -│ └── • UpdateTableBackReferencesInSequences -│ BackReferencedTableID: 107 -│ SequenceIDs: -│ - 104 +│ ├── • UpdateTableBackReferencesInSequences +│ │ BackReferencedTableID: 107 +│ │ SequenceIDs: +│ │ - 104 +│ │ +│ └── • SetConstraintName +│ ConstraintID: 2 +│ Name: check_i_j +│ TableID: 107 │ ├── • PreCommitPhase │ │ │ ├── • Stage 1 of 2 in PreCommitPhase │ │ │ -│ │ ├── • 1 element transitioning toward PUBLIC +│ │ ├── • 2 elements transitioning toward PUBLIC +│ │ │ │ +│ │ │ ├── • CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} +│ │ │ │ WRITE_ONLY → ABSENT │ │ │ │ -│ │ │ └── • CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} -│ │ │ WRITE_ONLY → ABSENT +│ │ │ └── • ConstraintWithoutIndexName:{DescID: 107, Name: check_i_j, ConstraintID: 2} +│ │ │ PUBLIC → ABSENT │ │ │ │ │ └── • 1 Mutation operation │ │ │ @@ -58,15 +72,21 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ADD CHECK (i > nextval('s') OR j::typ = 'a' │ │ │ └── • Stage 2 of 2 in PreCommitPhase │ │ -│ ├── • 1 element transitioning toward PUBLIC +│ ├── • 2 elements transitioning toward PUBLIC │ │ │ -│ │ └── • CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} -│ │ │ ABSENT → WRITE_ONLY +│ │ ├── • CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} +│ │ │ │ ABSENT → WRITE_ONLY +│ │ │ │ +│ │ │ └── • PreviousStagePrecedence dependency from ABSENT CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} +│ │ │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: ABSENT->WRITE_ONLY" +│ │ │ +│ │ └── • ConstraintWithoutIndexName:{DescID: 107, Name: check_i_j, ConstraintID: 2} +│ │ │ ABSENT → PUBLIC │ │ │ -│ │ └── • PreviousStagePrecedence dependency from ABSENT CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} -│ │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: ABSENT->WRITE_ONLY" +│ │ └── • SameStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} +│ │ rule: "simple constraint visible before name" │ │ -│ └── • 8 Mutation operations +│ └── • 9 Mutation operations │ │ │ ├── • AddCheckConstraint │ │ CheckExpr: (i > nextval(104:::REGCLASS)) OR (j::@100105 = b'@':::@100105) @@ -88,6 +108,11 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ADD CHECK (i > nextval('s') OR j::typ = 'a' │ │ SequenceIDs: │ │ - 104 │ │ +│ ├── • SetConstraintName +│ │ ConstraintID: 2 +│ │ Name: check_i_j +│ │ TableID: 107 +│ │ │ ├── • SetJobStateOnDescriptor │ │ DescriptorID: 104 │ │ Initialize: true @@ -140,26 +165,15 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ADD CHECK (i > nextval('s') OR j::typ = 'a' │ └── • Stage 2 of 2 in PostCommitPhase │ - ├── • 2 elements transitioning toward PUBLIC + ├── • 1 element transitioning toward PUBLIC │ │ - │ ├── • CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} - │ │ │ VALIDATED → PUBLIC - │ │ │ - │ │ ├── • PreviousStagePrecedence dependency from VALIDATED CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} - │ │ │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: VALIDATED->PUBLIC" - │ │ │ - │ │ └── • SameStagePrecedence dependency from PUBLIC ConstraintWithoutIndexName:{DescID: 107, Name: check_i_j, ConstraintID: 2} - │ │ rule: "constraint dependent public right before complex constraint" - │ │ - │ └── • ConstraintWithoutIndexName:{DescID: 107, Name: check_i_j, ConstraintID: 2} - │ ABSENT → PUBLIC + │ └── • CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} + │ │ VALIDATED → PUBLIC + │ │ + │ └── • PreviousStagePrecedence dependency from VALIDATED CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} + │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: VALIDATED->PUBLIC" │ - └── • 7 Mutation operations - │ - ├── • SetConstraintName - │ ConstraintID: 2 - │ Name: check_i_j - │ TableID: 107 + └── • 6 Mutation operations │ ├── • MakeValidatedCheckConstraintPublic │ ConstraintID: 2 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_with_seq_and_udt.rollback_1_of_2 b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_with_seq_and_udt.rollback_1_of_2 index 838f720d23f9..7e3eb9858570 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_with_seq_and_udt.rollback_1_of_2 +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_with_seq_and_udt.rollback_1_of_2 @@ -13,18 +13,29 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 1 of 2; │ └── • Stage 1 of 1 in PostCommitNonRevertiblePhase │ - ├── • 1 element transitioning toward ABSENT + ├── • 2 elements transitioning toward ABSENT │ │ - │ └── • CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} - │ │ WRITE_ONLY → ABSENT - │ │ - │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} - │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" + │ ├── • CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} + │ │ │ WRITE_ONLY → ABSENT + │ │ │ + │ │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} + │ │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" + │ │ │ + │ │ └── • SameStagePrecedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 107, Name: check_i_j, ConstraintID: 2} + │ │ rule: "Constraint should be hidden before name" + │ │ + │ └── • ConstraintWithoutIndexName:{DescID: 107, Name: check_i_j, ConstraintID: 2} + │ │ PUBLIC → ABSENT │ │ - │ └── • Precedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 107, Name: check_i_j, ConstraintID: 2} - │ rule: "dependents removed before constraint" + │ └── • Precedence dependency from VALIDATED CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} + │ rule: "Constraint should be hidden before name" │ - └── • 8 Mutation operations + └── • 9 Mutation operations + │ + ├── • SetConstraintName + │ ConstraintID: 2 + │ Name: crdb_internal_constraint_2_name_placeholder + │ TableID: 107 │ ├── • RemoveCheckConstraint │ ConstraintID: 2 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_with_seq_and_udt.rollback_2_of_2 b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_with_seq_and_udt.rollback_2_of_2 index 04c66098dcf7..efa5a115ed23 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_with_seq_and_udt.rollback_2_of_2 +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_check_with_seq_and_udt.rollback_2_of_2 @@ -13,18 +13,29 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 2 of 2; │ └── • Stage 1 of 1 in PostCommitNonRevertiblePhase │ - ├── • 1 element transitioning toward ABSENT + ├── • 2 elements transitioning toward ABSENT │ │ - │ └── • CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} - │ │ WRITE_ONLY → ABSENT - │ │ - │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} - │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" + │ ├── • CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} + │ │ │ WRITE_ONLY → ABSENT + │ │ │ + │ │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} + │ │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" + │ │ │ + │ │ └── • SameStagePrecedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 107, Name: check_i_j, ConstraintID: 2} + │ │ rule: "Constraint should be hidden before name" + │ │ + │ └── • ConstraintWithoutIndexName:{DescID: 107, Name: check_i_j, ConstraintID: 2} + │ │ PUBLIC → ABSENT │ │ - │ └── • Precedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 107, Name: check_i_j, ConstraintID: 2} - │ rule: "dependents removed before constraint" + │ └── • Precedence dependency from VALIDATED CheckConstraint:{DescID: 107, ReferencedTypeIDs: [105 106], IndexID: 0, ConstraintID: 2, ReferencedSequenceIDs: [104]} + │ rule: "Constraint should be hidden before name" │ - └── • 8 Mutation operations + └── • 9 Mutation operations + │ + ├── • SetConstraintName + │ ConstraintID: 2 + │ Name: crdb_internal_constraint_2_name_placeholder + │ TableID: 107 │ ├── • RemoveCheckConstraint │ ConstraintID: 2 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_foreign_key b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_foreign_key index b3941af0a06e..1d8cbcfeaca4 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_foreign_key +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_foreign_key @@ -1,6 +1,9 @@ /* setup */ CREATE TABLE t1 (i INT PRIMARY KEY); CREATE TABLE t2 (i INT PRIMARY KEY); +INSERT INTO t2 VALUES(-1); +INSERT INTO t2 VALUES(-2); +INSERT INTO t2 VALUES(-3); /* test */ EXPLAIN (ddl, verbose) ALTER TABLE t1 ADD FOREIGN KEY (i) REFERENCES t2(i); @@ -11,34 +14,48 @@ EXPLAIN (ddl, verbose) ALTER TABLE t1 ADD FOREIGN KEY (i) REFERENCES t2(i); │ │ │ └── • Stage 1 of 1 in StatementPhase │ │ -│ ├── • 1 element transitioning toward PUBLIC +│ ├── • 2 elements transitioning toward PUBLIC │ │ │ -│ │ └── • ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} -│ │ │ ABSENT → WRITE_ONLY +│ │ ├── • ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} +│ │ │ │ ABSENT → WRITE_ONLY +│ │ │ │ +│ │ │ └── • PreviousStagePrecedence dependency from ABSENT ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} +│ │ │ rule: "ForeignKeyConstraint transitions to PUBLIC uphold 2-version invariant: ABSENT->WRITE_ONLY" +│ │ │ +│ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: t1_i_fkey, ConstraintID: 2} +│ │ │ ABSENT → PUBLIC │ │ │ -│ │ └── • PreviousStagePrecedence dependency from ABSENT ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} -│ │ rule: "ForeignKeyConstraint transitions to PUBLIC uphold 2-version invariant: ABSENT->WRITE_ONLY" +│ │ └── • SameStagePrecedence dependency from WRITE_ONLY ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} +│ │ rule: "simple constraint visible before name" │ │ -│ └── • 1 Mutation operation +│ └── • 2 Mutation operations +│ │ +│ ├── • AddForeignKeyConstraint +│ │ ColumnIDs: +│ │ - 1 +│ │ ConstraintID: 2 +│ │ ReferencedColumnIDs: +│ │ - 1 +│ │ ReferencedTableID: 105 +│ │ TableID: 104 +│ │ Validity: 2 │ │ -│ └── • AddForeignKeyConstraint -│ ColumnIDs: -│ - 1 +│ └── • SetConstraintName │ ConstraintID: 2 -│ ReferencedColumnIDs: -│ - 1 -│ ReferencedTableID: 105 +│ Name: t1_i_fkey │ TableID: 104 -│ Validity: 2 │ ├── • PreCommitPhase │ │ │ ├── • Stage 1 of 2 in PreCommitPhase │ │ │ -│ │ ├── • 1 element transitioning toward PUBLIC +│ │ ├── • 2 elements transitioning toward PUBLIC +│ │ │ │ +│ │ │ ├── • ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} +│ │ │ │ WRITE_ONLY → ABSENT │ │ │ │ -│ │ │ └── • ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} -│ │ │ WRITE_ONLY → ABSENT +│ │ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: t1_i_fkey, ConstraintID: 2} +│ │ │ PUBLIC → ABSENT │ │ │ │ │ └── • 1 Mutation operation │ │ │ @@ -47,15 +64,21 @@ EXPLAIN (ddl, verbose) ALTER TABLE t1 ADD FOREIGN KEY (i) REFERENCES t2(i); │ │ │ └── • Stage 2 of 2 in PreCommitPhase │ │ -│ ├── • 1 element transitioning toward PUBLIC +│ ├── • 2 elements transitioning toward PUBLIC +│ │ │ +│ │ ├── • ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} +│ │ │ │ ABSENT → WRITE_ONLY +│ │ │ │ +│ │ │ └── • PreviousStagePrecedence dependency from ABSENT ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} +│ │ │ rule: "ForeignKeyConstraint transitions to PUBLIC uphold 2-version invariant: ABSENT->WRITE_ONLY" │ │ │ -│ │ └── • ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} -│ │ │ ABSENT → WRITE_ONLY +│ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: t1_i_fkey, ConstraintID: 2} +│ │ │ ABSENT → PUBLIC │ │ │ -│ │ └── • PreviousStagePrecedence dependency from ABSENT ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} -│ │ rule: "ForeignKeyConstraint transitions to PUBLIC uphold 2-version invariant: ABSENT->WRITE_ONLY" +│ │ └── • SameStagePrecedence dependency from WRITE_ONLY ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} +│ │ rule: "simple constraint visible before name" │ │ -│ └── • 4 Mutation operations +│ └── • 5 Mutation operations │ │ │ ├── • AddForeignKeyConstraint │ │ ColumnIDs: @@ -67,6 +90,11 @@ EXPLAIN (ddl, verbose) ALTER TABLE t1 ADD FOREIGN KEY (i) REFERENCES t2(i); │ │ TableID: 104 │ │ Validity: 2 │ │ +│ ├── • SetConstraintName +│ │ ConstraintID: 2 +│ │ Name: t1_i_fkey +│ │ TableID: 104 +│ │ │ ├── • SetJobStateOnDescriptor │ │ DescriptorID: 104 │ │ Initialize: true @@ -109,26 +137,15 @@ EXPLAIN (ddl, verbose) ALTER TABLE t1 ADD FOREIGN KEY (i) REFERENCES t2(i); │ └── • Stage 2 of 2 in PostCommitPhase │ - ├── • 2 elements transitioning toward PUBLIC - │ │ - │ ├── • ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} - │ │ │ VALIDATED → PUBLIC - │ │ │ - │ │ ├── • PreviousStagePrecedence dependency from VALIDATED ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} - │ │ │ rule: "ForeignKeyConstraint transitions to PUBLIC uphold 2-version invariant: VALIDATED->PUBLIC" - │ │ │ - │ │ └── • SameStagePrecedence dependency from PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: t1_i_fkey, ConstraintID: 2} - │ │ rule: "constraint dependent public right before complex constraint" + ├── • 1 element transitioning toward PUBLIC │ │ - │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: t1_i_fkey, ConstraintID: 2} - │ ABSENT → PUBLIC + │ └── • ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} + │ │ VALIDATED → PUBLIC + │ │ + │ └── • PreviousStagePrecedence dependency from VALIDATED ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} + │ rule: "ForeignKeyConstraint transitions to PUBLIC uphold 2-version invariant: VALIDATED->PUBLIC" │ - └── • 5 Mutation operations - │ - ├── • SetConstraintName - │ ConstraintID: 2 - │ Name: t1_i_fkey - │ TableID: 104 + └── • 4 Mutation operations │ ├── • MakeValidatedForeignKeyConstraintPublic │ ConstraintID: 2 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_foreign_key.rollback_1_of_2 b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_foreign_key.rollback_1_of_2 index 38f7c097f67f..5eae243a8623 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_foreign_key.rollback_1_of_2 +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_foreign_key.rollback_1_of_2 @@ -1,6 +1,9 @@ /* setup */ CREATE TABLE t1 (i INT PRIMARY KEY); CREATE TABLE t2 (i INT PRIMARY KEY); +INSERT INTO t2 VALUES(-1); +INSERT INTO t2 VALUES(-2); +INSERT INTO t2 VALUES(-3); /* test */ ALTER TABLE t1 ADD FOREIGN KEY (i) REFERENCES t2(i); @@ -12,18 +15,29 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 1 of 2; │ └── • Stage 1 of 1 in PostCommitNonRevertiblePhase │ - ├── • 1 element transitioning toward ABSENT + ├── • 2 elements transitioning toward ABSENT │ │ - │ └── • ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} - │ │ WRITE_ONLY → ABSENT - │ │ - │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} - │ │ rule: "ForeignKeyConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" + │ ├── • ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} + │ │ │ WRITE_ONLY → ABSENT + │ │ │ + │ │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} + │ │ │ rule: "ForeignKeyConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" + │ │ │ + │ │ └── • SameStagePrecedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: t1_i_fkey, ConstraintID: 2} + │ │ rule: "Constraint should be hidden before name" + │ │ + │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: t1_i_fkey, ConstraintID: 2} + │ │ PUBLIC → ABSENT │ │ - │ └── • Precedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: t1_i_fkey, ConstraintID: 2} - │ rule: "dependents removed before constraint" + │ └── • Precedence dependency from VALIDATED ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} + │ rule: "Constraint should be hidden before name" │ - └── • 5 Mutation operations + └── • 6 Mutation operations + │ + ├── • SetConstraintName + │ ConstraintID: 2 + │ Name: crdb_internal_constraint_2_name_placeholder + │ TableID: 104 │ ├── • RemoveForeignKeyBackReference │ OriginConstraintID: 2 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_foreign_key.rollback_2_of_2 b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_foreign_key.rollback_2_of_2 index ccd6764e709b..a6144fee798d 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_foreign_key.rollback_2_of_2 +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_foreign_key.rollback_2_of_2 @@ -1,6 +1,9 @@ /* setup */ CREATE TABLE t1 (i INT PRIMARY KEY); CREATE TABLE t2 (i INT PRIMARY KEY); +INSERT INTO t2 VALUES(-1); +INSERT INTO t2 VALUES(-2); +INSERT INTO t2 VALUES(-3); /* test */ ALTER TABLE t1 ADD FOREIGN KEY (i) REFERENCES t2(i); @@ -12,18 +15,29 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 2 of 2; │ └── • Stage 1 of 1 in PostCommitNonRevertiblePhase │ - ├── • 1 element transitioning toward ABSENT + ├── • 2 elements transitioning toward ABSENT │ │ - │ └── • ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} - │ │ WRITE_ONLY → ABSENT - │ │ - │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} - │ │ rule: "ForeignKeyConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" + │ ├── • ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} + │ │ │ WRITE_ONLY → ABSENT + │ │ │ + │ │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} + │ │ │ rule: "ForeignKeyConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" + │ │ │ + │ │ └── • SameStagePrecedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: t1_i_fkey, ConstraintID: 2} + │ │ rule: "Constraint should be hidden before name" + │ │ + │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: t1_i_fkey, ConstraintID: 2} + │ │ PUBLIC → ABSENT │ │ - │ └── • Precedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: t1_i_fkey, ConstraintID: 2} - │ rule: "dependents removed before constraint" + │ └── • Precedence dependency from VALIDATED ForeignKeyConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2, ReferencedDescID: 105} + │ rule: "Constraint should be hidden before name" │ - └── • 5 Mutation operations + └── • 6 Mutation operations + │ + ├── • SetConstraintName + │ ConstraintID: 2 + │ Name: crdb_internal_constraint_2_name_placeholder + │ TableID: 104 │ ├── • RemoveForeignKeyBackReference │ OriginConstraintID: 2 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_unique_without_index b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_unique_without_index index 6d113045ede4..b52e9ec46a99 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_unique_without_index +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_unique_without_index @@ -1,6 +1,9 @@ /* setup */ CREATE TABLE t (i INT PRIMARY KEY, j INT); SET experimental_enable_unique_without_index_constraints = true; +INSERT INTO t VALUES(-1, -1); +INSERT INTO t VALUES(-2, -2); +INSERT INTO t VALUES(-3, -3); /* test */ EXPLAIN (ddl, verbose) ALTER TABLE t ADD UNIQUE WITHOUT INDEX (j); @@ -11,31 +14,45 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ADD UNIQUE WITHOUT INDEX (j); │ │ │ └── • Stage 1 of 1 in StatementPhase │ │ -│ ├── • 1 element transitioning toward PUBLIC +│ ├── • 2 elements transitioning toward PUBLIC │ │ │ -│ │ └── • UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} -│ │ │ ABSENT → WRITE_ONLY +│ │ ├── • UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} +│ │ │ │ ABSENT → WRITE_ONLY +│ │ │ │ +│ │ │ └── • PreviousStagePrecedence dependency from ABSENT UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} +│ │ │ rule: "UniqueWithoutIndexConstraint transitions to PUBLIC uphold 2-version invariant: ABSENT->WRITE_ONLY" +│ │ │ +│ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} +│ │ │ ABSENT → PUBLIC │ │ │ -│ │ └── • PreviousStagePrecedence dependency from ABSENT UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} -│ │ rule: "UniqueWithoutIndexConstraint transitions to PUBLIC uphold 2-version invariant: ABSENT->WRITE_ONLY" +│ │ └── • SameStagePrecedence dependency from WRITE_ONLY UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} +│ │ rule: "simple constraint visible before name" │ │ -│ └── • 1 Mutation operation +│ └── • 2 Mutation operations │ │ -│ └── • AddUniqueWithoutIndexConstraint -│ ColumnIDs: -│ - 2 +│ ├── • AddUniqueWithoutIndexConstraint +│ │ ColumnIDs: +│ │ - 2 +│ │ ConstraintID: 2 +│ │ TableID: 104 +│ │ Validity: 2 +│ │ +│ └── • SetConstraintName │ ConstraintID: 2 +│ Name: unique_j │ TableID: 104 -│ Validity: 2 │ ├── • PreCommitPhase │ │ │ ├── • Stage 1 of 2 in PreCommitPhase │ │ │ -│ │ ├── • 1 element transitioning toward PUBLIC +│ │ ├── • 2 elements transitioning toward PUBLIC +│ │ │ │ +│ │ │ ├── • UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} +│ │ │ │ WRITE_ONLY → ABSENT │ │ │ │ -│ │ │ └── • UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} -│ │ │ WRITE_ONLY → ABSENT +│ │ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} +│ │ │ PUBLIC → ABSENT │ │ │ │ │ └── • 1 Mutation operation │ │ │ @@ -44,15 +61,21 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ADD UNIQUE WITHOUT INDEX (j); │ │ │ └── • Stage 2 of 2 in PreCommitPhase │ │ -│ ├── • 1 element transitioning toward PUBLIC +│ ├── • 2 elements transitioning toward PUBLIC │ │ │ -│ │ └── • UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} -│ │ │ ABSENT → WRITE_ONLY +│ │ ├── • UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} +│ │ │ │ ABSENT → WRITE_ONLY +│ │ │ │ +│ │ │ └── • PreviousStagePrecedence dependency from ABSENT UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} +│ │ │ rule: "UniqueWithoutIndexConstraint transitions to PUBLIC uphold 2-version invariant: ABSENT->WRITE_ONLY" +│ │ │ +│ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} +│ │ │ ABSENT → PUBLIC │ │ │ -│ │ └── • PreviousStagePrecedence dependency from ABSENT UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} -│ │ rule: "UniqueWithoutIndexConstraint transitions to PUBLIC uphold 2-version invariant: ABSENT->WRITE_ONLY" +│ │ └── • SameStagePrecedence dependency from WRITE_ONLY UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} +│ │ rule: "simple constraint visible before name" │ │ -│ └── • 3 Mutation operations +│ └── • 4 Mutation operations │ │ │ ├── • AddUniqueWithoutIndexConstraint │ │ ColumnIDs: @@ -61,6 +84,11 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ADD UNIQUE WITHOUT INDEX (j); │ │ TableID: 104 │ │ Validity: 2 │ │ +│ ├── • SetConstraintName +│ │ ConstraintID: 2 +│ │ Name: unique_j +│ │ TableID: 104 +│ │ │ ├── • SetJobStateOnDescriptor │ │ DescriptorID: 104 │ │ Initialize: true @@ -98,26 +126,15 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ADD UNIQUE WITHOUT INDEX (j); │ └── • Stage 2 of 2 in PostCommitPhase │ - ├── • 2 elements transitioning toward PUBLIC + ├── • 1 element transitioning toward PUBLIC │ │ - │ ├── • UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} - │ │ │ VALIDATED → PUBLIC - │ │ │ - │ │ ├── • PreviousStagePrecedence dependency from VALIDATED UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} - │ │ │ rule: "UniqueWithoutIndexConstraint transitions to PUBLIC uphold 2-version invariant: VALIDATED->PUBLIC" - │ │ │ - │ │ └── • SameStagePrecedence dependency from PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} - │ │ rule: "constraint dependent public right before complex constraint" - │ │ - │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} - │ ABSENT → PUBLIC + │ └── • UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} + │ │ VALIDATED → PUBLIC + │ │ + │ └── • PreviousStagePrecedence dependency from VALIDATED UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} + │ rule: "UniqueWithoutIndexConstraint transitions to PUBLIC uphold 2-version invariant: VALIDATED->PUBLIC" │ - └── • 4 Mutation operations - │ - ├── • SetConstraintName - │ ConstraintID: 2 - │ Name: unique_j - │ TableID: 104 + └── • 3 Mutation operations │ ├── • MakeValidatedUniqueWithoutIndexConstraintPublic │ ConstraintID: 2 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_unique_without_index.rollback_1_of_2 b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_unique_without_index.rollback_1_of_2 index 8008a747a702..0cc1348215fd 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_unique_without_index.rollback_1_of_2 +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_unique_without_index.rollback_1_of_2 @@ -1,6 +1,9 @@ /* setup */ CREATE TABLE t (i INT PRIMARY KEY, j INT); SET experimental_enable_unique_without_index_constraints = true; +INSERT INTO t VALUES(-1, -1); +INSERT INTO t VALUES(-2, -2); +INSERT INTO t VALUES(-3, -3); /* test */ ALTER TABLE t ADD UNIQUE WITHOUT INDEX (j); @@ -12,18 +15,29 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 1 of 2; │ └── • Stage 1 of 1 in PostCommitNonRevertiblePhase │ - ├── • 1 element transitioning toward ABSENT + ├── • 2 elements transitioning toward ABSENT │ │ - │ └── • UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} - │ │ WRITE_ONLY → ABSENT - │ │ - │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} - │ │ rule: "UniqueWithoutIndexConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" + │ ├── • UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} + │ │ │ WRITE_ONLY → ABSENT + │ │ │ + │ │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} + │ │ │ rule: "UniqueWithoutIndexConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" + │ │ │ + │ │ └── • SameStagePrecedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} + │ │ rule: "Constraint should be hidden before name" + │ │ + │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} + │ │ PUBLIC → ABSENT │ │ - │ └── • Precedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} - │ rule: "dependents removed before constraint" + │ └── • Precedence dependency from VALIDATED UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} + │ rule: "Constraint should be hidden before name" │ - └── • 3 Mutation operations + └── • 4 Mutation operations + │ + ├── • SetConstraintName + │ ConstraintID: 2 + │ Name: crdb_internal_constraint_2_name_placeholder + │ TableID: 104 │ ├── • RemoveUniqueWithoutIndexConstraint │ ConstraintID: 2 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_unique_without_index.rollback_2_of_2 b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_unique_without_index.rollback_2_of_2 index a670c1049e4d..563c4229bd57 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_unique_without_index.rollback_2_of_2 +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_add_unique_without_index.rollback_2_of_2 @@ -1,6 +1,9 @@ /* setup */ CREATE TABLE t (i INT PRIMARY KEY, j INT); SET experimental_enable_unique_without_index_constraints = true; +INSERT INTO t VALUES(-1, -1); +INSERT INTO t VALUES(-2, -2); +INSERT INTO t VALUES(-3, -3); /* test */ ALTER TABLE t ADD UNIQUE WITHOUT INDEX (j); @@ -12,18 +15,29 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 2 of 2; │ └── • Stage 1 of 1 in PostCommitNonRevertiblePhase │ - ├── • 1 element transitioning toward ABSENT + ├── • 2 elements transitioning toward ABSENT │ │ - │ └── • UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} - │ │ WRITE_ONLY → ABSENT - │ │ - │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} - │ │ rule: "UniqueWithoutIndexConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" + │ ├── • UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} + │ │ │ WRITE_ONLY → ABSENT + │ │ │ + │ │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} + │ │ │ rule: "UniqueWithoutIndexConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" + │ │ │ + │ │ └── • SameStagePrecedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} + │ │ rule: "Constraint should be hidden before name" + │ │ + │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} + │ │ PUBLIC → ABSENT │ │ - │ └── • Precedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} - │ rule: "dependents removed before constraint" + │ └── • Precedence dependency from VALIDATED UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} + │ rule: "Constraint should be hidden before name" │ - └── • 3 Mutation operations + └── • 4 Mutation operations + │ + ├── • SetConstraintName + │ ConstraintID: 2 + │ Name: crdb_internal_constraint_2_name_placeholder + │ TableID: 104 │ ├── • RemoveUniqueWithoutIndexConstraint │ ConstraintID: 2 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash index 7a56e58ff3a0..5bdb55c86ae0 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash @@ -10,7 +10,7 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ALTER PRIMARY KEY USING COLUMNS (j) USING H │ │ │ └── • Stage 1 of 1 in StatementPhase │ │ -│ ├── • 18 elements transitioning toward PUBLIC +│ ├── • 19 elements transitioning toward PUBLIC │ │ │ │ │ ├── • Column:{DescID: 104, ColumnID: 3} │ │ │ │ ABSENT → DELETE_ONLY @@ -38,6 +38,12 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ALTER PRIMARY KEY USING COLUMNS (j) USING H │ │ │ └── • PreviousStagePrecedence dependency from ABSENT CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} │ │ │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: ABSENT->WRITE_ONLY" │ │ │ +│ │ ├── • ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} +│ │ │ │ ABSENT → PUBLIC +│ │ │ │ +│ │ │ └── • SameStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} +│ │ │ rule: "simple constraint visible before name" +│ │ │ │ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 3, TemporaryIndexID: 3, SourceIndexID: 1} │ │ │ │ ABSENT → BACKFILL_ONLY │ │ │ │ @@ -178,7 +184,7 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ALTER PRIMARY KEY USING COLUMNS (j) USING H │ │ └── • PreviousStagePrecedence dependency from ABSENT TemporaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 6, SourceIndexID: 1} │ │ rule: "TemporaryIndex transitions to TRANSIENT_ABSENT uphold 2-version invariant: ABSENT->DELETE_ONLY" │ │ -│ └── • 21 Mutation operations +│ └── • 22 Mutation operations │ │ │ ├── • MakeAbsentColumnDeleteOnly │ │ Column: @@ -216,6 +222,11 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ALTER PRIMARY KEY USING COLUMNS (j) USING H │ │ TableID: 104 │ │ Validity: 2 │ │ +│ ├── • SetConstraintName +│ │ ConstraintID: 2 +│ │ Name: check_crdb_internal_j_shard_3 +│ │ TableID: 104 +│ │ │ ├── • MakeAbsentIndexBackfilling │ │ Index: │ │ ConstraintID: 3 @@ -343,7 +354,7 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ALTER PRIMARY KEY USING COLUMNS (j) USING H │ │ │ ├── • Stage 1 of 2 in PreCommitPhase │ │ │ -│ │ ├── • 18 elements transitioning toward PUBLIC +│ │ ├── • 19 elements transitioning toward PUBLIC │ │ │ │ │ │ │ ├── • Column:{DescID: 104, ColumnID: 3} │ │ │ │ DELETE_ONLY → ABSENT @@ -357,6 +368,9 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ALTER PRIMARY KEY USING COLUMNS (j) USING H │ │ │ ├── • CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} │ │ │ │ WRITE_ONLY → ABSENT │ │ │ │ +│ │ │ ├── • ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ │ │ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 3, TemporaryIndexID: 3, SourceIndexID: 1} │ │ │ │ BACKFILL_ONLY → ABSENT │ │ │ │ @@ -423,7 +437,7 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ALTER PRIMARY KEY USING COLUMNS (j) USING H │ │ │ └── • Stage 2 of 2 in PreCommitPhase │ │ -│ ├── • 18 elements transitioning toward PUBLIC +│ ├── • 19 elements transitioning toward PUBLIC │ │ │ │ │ ├── • Column:{DescID: 104, ColumnID: 3} │ │ │ │ ABSENT → DELETE_ONLY @@ -451,6 +465,12 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ALTER PRIMARY KEY USING COLUMNS (j) USING H │ │ │ └── • PreviousStagePrecedence dependency from ABSENT CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} │ │ │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: ABSENT->WRITE_ONLY" │ │ │ +│ │ ├── • ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} +│ │ │ │ ABSENT → PUBLIC +│ │ │ │ +│ │ │ └── • SameStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} +│ │ │ rule: "simple constraint visible before name" +│ │ │ │ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 3, TemporaryIndexID: 3, SourceIndexID: 1} │ │ │ │ ABSENT → BACKFILL_ONLY │ │ │ │ @@ -591,7 +611,7 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ALTER PRIMARY KEY USING COLUMNS (j) USING H │ │ └── • PreviousStagePrecedence dependency from ABSENT TemporaryIndex:{DescID: 104, IndexID: 5, ConstraintID: 6, SourceIndexID: 1} │ │ rule: "TemporaryIndex transitions to TRANSIENT_ABSENT uphold 2-version invariant: ABSENT->DELETE_ONLY" │ │ -│ └── • 27 Mutation operations +│ └── • 28 Mutation operations │ │ │ ├── • MakeAbsentColumnDeleteOnly │ │ Column: @@ -629,6 +649,11 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ALTER PRIMARY KEY USING COLUMNS (j) USING H │ │ TableID: 104 │ │ Validity: 2 │ │ +│ ├── • SetConstraintName +│ │ ConstraintID: 2 +│ │ Name: check_crdb_internal_j_shard_3 +│ │ TableID: 104 +│ │ │ ├── • MakeAbsentIndexBackfilling │ │ Index: │ │ ConstraintID: 3 @@ -1113,7 +1138,7 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ALTER PRIMARY KEY USING COLUMNS (j) USING H │ ├── • Stage 1 of 3 in PostCommitNonRevertiblePhase │ │ - │ ├── • 7 elements transitioning toward PUBLIC + │ ├── • 6 elements transitioning toward PUBLIC │ │ │ │ │ ├── • Column:{DescID: 104, ColumnID: 3} │ │ │ │ WRITE_ONLY → PUBLIC @@ -1157,14 +1182,8 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ALTER PRIMARY KEY USING COLUMNS (j) USING H │ │ ├── • CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} │ │ │ │ VALIDATED → PUBLIC │ │ │ │ - │ │ │ ├── • PreviousStagePrecedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} - │ │ │ │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: VALIDATED->PUBLIC" - │ │ │ │ - │ │ │ └── • SameStagePrecedence dependency from PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} - │ │ │ rule: "constraint dependent public right before complex constraint" - │ │ │ - │ │ ├── • ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} - │ │ │ ABSENT → PUBLIC + │ │ │ └── • PreviousStagePrecedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} + │ │ │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: VALIDATED->PUBLIC" │ │ │ │ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 3, TemporaryIndexID: 3, SourceIndexID: 1} │ │ │ │ VALIDATED → PUBLIC @@ -1258,7 +1277,7 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ALTER PRIMARY KEY USING COLUMNS (j) USING H │ │ └── • Precedence dependency from VALIDATED PrimaryIndex:{DescID: 104, IndexID: 1, ConstraintID: 1} │ │ rule: "index no longer public before dependents, excluding columns" │ │ - │ └── • 18 Mutation operations + │ └── • 17 Mutation operations │ │ │ ├── • MakePublicPrimaryIndexWriteOnly │ │ IndexID: 1 @@ -1273,9 +1292,8 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ALTER PRIMARY KEY USING COLUMNS (j) USING H │ │ ColumnID: 3 │ │ TableID: 104 │ │ - │ ├── • SetConstraintName + │ ├── • MakeValidatedCheckConstraintPublic │ │ ConstraintID: 2 - │ │ Name: check_crdb_internal_j_shard_3 │ │ TableID: 104 │ │ │ ├── • SetIndexName @@ -1315,10 +1333,6 @@ EXPLAIN (ddl, verbose) ALTER TABLE t ALTER PRIMARY KEY USING COLUMNS (j) USING H │ │ IndexID: 5 │ │ TableID: 104 │ │ - │ ├── • MakeValidatedCheckConstraintPublic - │ │ ConstraintID: 2 - │ │ TableID: 104 - │ │ │ ├── • MakeValidatedPrimaryIndexPublic │ │ IndexID: 2 │ │ TableID: 104 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_1_of_7 b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_1_of_7 index 9e020ff1a32c..8d5acf6af3a1 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_1_of_7 +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_1_of_7 @@ -11,7 +11,7 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 1 of 7; │ └── • Stage 1 of 1 in PostCommitNonRevertiblePhase │ - ├── • 23 elements transitioning toward ABSENT + ├── • 24 elements transitioning toward ABSENT │ │ │ ├── • Column:{DescID: 104, ColumnID: 3} │ │ │ DELETE_ONLY → ABSENT @@ -59,8 +59,14 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 1 of 7; │ │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} │ │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" │ │ │ - │ │ └── • Precedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} - │ │ rule: "dependents removed before constraint" + │ │ └── • SameStagePrecedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} + │ │ rule: "Constraint should be hidden before name" + │ │ + │ ├── • ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} + │ │ │ PUBLIC → ABSENT + │ │ │ + │ │ └── • Precedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} + │ │ rule: "Constraint should be hidden before name" │ │ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 3, TemporaryIndexID: 3, SourceIndexID: 1} │ │ │ BACKFILL_ONLY → ABSENT @@ -221,13 +227,18 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 1 of 7; │ └── • Precedence dependency from DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 4, ConstraintID: 5, TemporaryIndexID: 5, SourceIndexID: 1} │ rule: "index no longer public before index name" │ - └── • 24 Mutation operations + └── • 25 Mutation operations │ ├── • SetColumnName │ ColumnID: 3 │ Name: crdb_internal_column_3_name_placeholder │ TableID: 104 │ + ├── • SetConstraintName + │ ConstraintID: 2 + │ Name: crdb_internal_constraint_2_name_placeholder + │ TableID: 104 + │ ├── • RemoveColumnFromIndex │ ColumnID: 3 │ IndexID: 2 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_2_of_7 b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_2_of_7 index 655f374aa23d..e71be83e155c 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_2_of_7 +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_2_of_7 @@ -11,7 +11,7 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 2 of 7; │ ├── • Stage 1 of 2 in PostCommitNonRevertiblePhase │ │ - │ ├── • 21 elements transitioning toward ABSENT + │ ├── • 22 elements transitioning toward ABSENT │ │ │ │ │ ├── • Column:{DescID: 104, ColumnID: 3} │ │ │ │ WRITE_ONLY → DELETE_ONLY @@ -43,8 +43,14 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 2 of 7; │ │ │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} │ │ │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" │ │ │ │ - │ │ │ └── • Precedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} - │ │ │ rule: "dependents removed before constraint" + │ │ │ └── • SameStagePrecedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} + │ │ │ rule: "Constraint should be hidden before name" + │ │ │ + │ │ ├── • ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} + │ │ │ rule: "Constraint should be hidden before name" │ │ │ │ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 3, TemporaryIndexID: 3, SourceIndexID: 1} │ │ │ │ BACKFILL_ONLY → ABSENT @@ -184,13 +190,18 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 2 of 7; │ │ └── • Precedence dependency from DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 4, ConstraintID: 5, TemporaryIndexID: 5, SourceIndexID: 1} │ │ rule: "index no longer public before index name" │ │ - │ └── • 23 Mutation operations + │ └── • 24 Mutation operations │ │ │ ├── • SetColumnName │ │ ColumnID: 3 │ │ Name: crdb_internal_column_3_name_placeholder │ │ TableID: 104 │ │ + │ ├── • SetConstraintName + │ │ ConstraintID: 2 + │ │ Name: crdb_internal_constraint_2_name_placeholder + │ │ TableID: 104 + │ │ │ ├── • RemoveColumnFromIndex │ │ ColumnID: 3 │ │ IndexID: 2 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_3_of_7 b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_3_of_7 index 55eebf434227..2da6b7a266d1 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_3_of_7 +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_3_of_7 @@ -11,7 +11,7 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 3 of 7; │ ├── • Stage 1 of 2 in PostCommitNonRevertiblePhase │ │ - │ ├── • 21 elements transitioning toward ABSENT + │ ├── • 22 elements transitioning toward ABSENT │ │ │ │ │ ├── • Column:{DescID: 104, ColumnID: 3} │ │ │ │ WRITE_ONLY → DELETE_ONLY @@ -43,8 +43,14 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 3 of 7; │ │ │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} │ │ │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" │ │ │ │ - │ │ │ └── • Precedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} - │ │ │ rule: "dependents removed before constraint" + │ │ │ └── • SameStagePrecedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} + │ │ │ rule: "Constraint should be hidden before name" + │ │ │ + │ │ ├── • ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} + │ │ │ rule: "Constraint should be hidden before name" │ │ │ │ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 3, TemporaryIndexID: 3, SourceIndexID: 1} │ │ │ │ BACKFILL_ONLY → ABSENT @@ -184,13 +190,18 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 3 of 7; │ │ └── • Precedence dependency from DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 4, ConstraintID: 5, TemporaryIndexID: 5, SourceIndexID: 1} │ │ rule: "index no longer public before index name" │ │ - │ └── • 23 Mutation operations + │ └── • 24 Mutation operations │ │ │ ├── • SetColumnName │ │ ColumnID: 3 │ │ Name: crdb_internal_column_3_name_placeholder │ │ TableID: 104 │ │ + │ ├── • SetConstraintName + │ │ ConstraintID: 2 + │ │ Name: crdb_internal_constraint_2_name_placeholder + │ │ TableID: 104 + │ │ │ ├── • RemoveColumnFromIndex │ │ ColumnID: 3 │ │ IndexID: 2 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_4_of_7 b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_4_of_7 index c94b83bbbba9..df3a76ff50ec 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_4_of_7 +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_4_of_7 @@ -11,7 +11,7 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 4 of 7; │ ├── • Stage 1 of 2 in PostCommitNonRevertiblePhase │ │ - │ ├── • 21 elements transitioning toward ABSENT + │ ├── • 22 elements transitioning toward ABSENT │ │ │ │ │ ├── • Column:{DescID: 104, ColumnID: 3} │ │ │ │ WRITE_ONLY → DELETE_ONLY @@ -43,8 +43,14 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 4 of 7; │ │ │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} │ │ │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" │ │ │ │ - │ │ │ └── • Precedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} - │ │ │ rule: "dependents removed before constraint" + │ │ │ └── • SameStagePrecedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} + │ │ │ rule: "Constraint should be hidden before name" + │ │ │ + │ │ ├── • ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} + │ │ │ rule: "Constraint should be hidden before name" │ │ │ │ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 3, TemporaryIndexID: 3, SourceIndexID: 1} │ │ │ │ DELETE_ONLY → ABSENT @@ -184,13 +190,18 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 4 of 7; │ │ └── • Precedence dependency from DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 4, ConstraintID: 5, TemporaryIndexID: 5, SourceIndexID: 1} │ │ rule: "index no longer public before index name" │ │ - │ └── • 23 Mutation operations + │ └── • 24 Mutation operations │ │ │ ├── • SetColumnName │ │ ColumnID: 3 │ │ Name: crdb_internal_column_3_name_placeholder │ │ TableID: 104 │ │ + │ ├── • SetConstraintName + │ │ ConstraintID: 2 + │ │ Name: crdb_internal_constraint_2_name_placeholder + │ │ TableID: 104 + │ │ │ ├── • RemoveColumnFromIndex │ │ ColumnID: 3 │ │ IndexID: 2 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_5_of_7 b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_5_of_7 index e56d36b512d4..ad58cdf47128 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_5_of_7 +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_5_of_7 @@ -11,7 +11,7 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 5 of 7; │ ├── • Stage 1 of 2 in PostCommitNonRevertiblePhase │ │ - │ ├── • 21 elements transitioning toward ABSENT + │ ├── • 22 elements transitioning toward ABSENT │ │ │ │ │ ├── • Column:{DescID: 104, ColumnID: 3} │ │ │ │ WRITE_ONLY → DELETE_ONLY @@ -43,8 +43,14 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 5 of 7; │ │ │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} │ │ │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" │ │ │ │ - │ │ │ └── • Precedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} - │ │ │ rule: "dependents removed before constraint" + │ │ │ └── • SameStagePrecedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} + │ │ │ rule: "Constraint should be hidden before name" + │ │ │ + │ │ ├── • ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} + │ │ │ rule: "Constraint should be hidden before name" │ │ │ │ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 3, TemporaryIndexID: 3, SourceIndexID: 1} │ │ │ │ MERGE_ONLY → DELETE_ONLY @@ -160,13 +166,18 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 5 of 7; │ │ └── • Precedence dependency from DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 4, ConstraintID: 5, TemporaryIndexID: 5, SourceIndexID: 1} │ │ rule: "index no longer public before index name" │ │ - │ └── • 23 Mutation operations + │ └── • 24 Mutation operations │ │ │ ├── • SetColumnName │ │ ColumnID: 3 │ │ Name: crdb_internal_column_3_name_placeholder │ │ TableID: 104 │ │ + │ ├── • SetConstraintName + │ │ ConstraintID: 2 + │ │ Name: crdb_internal_constraint_2_name_placeholder + │ │ TableID: 104 + │ │ │ ├── • MakeWriteOnlyIndexDeleteOnly │ │ IndexID: 3 │ │ TableID: 104 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_6_of_7 b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_6_of_7 index fc5fb6d2f74a..dc4d28e5fcd7 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_6_of_7 +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_6_of_7 @@ -11,7 +11,7 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 6 of 7; │ ├── • Stage 1 of 2 in PostCommitNonRevertiblePhase │ │ - │ ├── • 21 elements transitioning toward ABSENT + │ ├── • 22 elements transitioning toward ABSENT │ │ │ │ │ ├── • Column:{DescID: 104, ColumnID: 3} │ │ │ │ WRITE_ONLY → DELETE_ONLY @@ -43,8 +43,14 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 6 of 7; │ │ │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} │ │ │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" │ │ │ │ - │ │ │ └── • Precedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} - │ │ │ rule: "dependents removed before constraint" + │ │ │ └── • SameStagePrecedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} + │ │ │ rule: "Constraint should be hidden before name" + │ │ │ + │ │ ├── • ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} + │ │ │ rule: "Constraint should be hidden before name" │ │ │ │ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 3, TemporaryIndexID: 3, SourceIndexID: 1} │ │ │ │ MERGE_ONLY → DELETE_ONLY @@ -160,13 +166,18 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 6 of 7; │ │ └── • Precedence dependency from DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 4, ConstraintID: 5, TemporaryIndexID: 5, SourceIndexID: 1} │ │ rule: "index no longer public before index name" │ │ - │ └── • 23 Mutation operations + │ └── • 24 Mutation operations │ │ │ ├── • SetColumnName │ │ ColumnID: 3 │ │ Name: crdb_internal_column_3_name_placeholder │ │ TableID: 104 │ │ + │ ├── • SetConstraintName + │ │ ConstraintID: 2 + │ │ Name: crdb_internal_constraint_2_name_placeholder + │ │ TableID: 104 + │ │ │ ├── • MakeWriteOnlyIndexDeleteOnly │ │ IndexID: 3 │ │ TableID: 104 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_7_of_7 b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_7_of_7 index 837b5eae1dc8..dd83caf5a0bb 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_7_of_7 +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_alter_primary_key_using_hash.rollback_7_of_7 @@ -11,7 +11,7 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 7 of 7; │ ├── • Stage 1 of 2 in PostCommitNonRevertiblePhase │ │ - │ ├── • 21 elements transitioning toward ABSENT + │ ├── • 22 elements transitioning toward ABSENT │ │ │ │ │ ├── • Column:{DescID: 104, ColumnID: 3} │ │ │ │ WRITE_ONLY → DELETE_ONLY @@ -43,8 +43,14 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 7 of 7; │ │ │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} │ │ │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" │ │ │ │ - │ │ │ └── • Precedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} - │ │ │ rule: "dependents removed before constraint" + │ │ │ └── • SameStagePrecedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} + │ │ │ rule: "Constraint should be hidden before name" + │ │ │ + │ │ ├── • ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_3, ConstraintID: 2} + │ │ │ │ PUBLIC → ABSENT + │ │ │ │ + │ │ │ └── • Precedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 2, ConstraintID: 2} + │ │ │ rule: "Constraint should be hidden before name" │ │ │ │ │ ├── • PrimaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 3, TemporaryIndexID: 3, SourceIndexID: 1} │ │ │ │ WRITE_ONLY → DELETE_ONLY @@ -160,13 +166,18 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 7 of 7; │ │ └── • Precedence dependency from DELETE_ONLY SecondaryIndex:{DescID: 104, IndexID: 4, ConstraintID: 5, TemporaryIndexID: 5, SourceIndexID: 1} │ │ rule: "index no longer public before index name" │ │ - │ └── • 23 Mutation operations + │ └── • 24 Mutation operations │ │ │ ├── • SetColumnName │ │ ColumnID: 3 │ │ Name: crdb_internal_column_3_name_placeholder │ │ TableID: 104 │ │ + │ ├── • SetConstraintName + │ │ ConstraintID: 2 + │ │ Name: crdb_internal_constraint_2_name_placeholder + │ │ TableID: 104 + │ │ │ ├── • MakeWriteOnlyIndexDeleteOnly │ │ IndexID: 2 │ │ TableID: 104 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_drop_constraint_check b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_drop_constraint_check index 8748983ea01f..a18c01da39b4 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_drop_constraint_check +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_drop_constraint_check @@ -10,42 +10,28 @@ EXPLAIN (ddl, verbose) ALTER TABLE t DROP CONSTRAINT check_i; │ │ │ └── • Stage 1 of 1 in StatementPhase │ │ -│ ├── • 2 elements transitioning toward ABSENT +│ ├── • 1 element transitioning toward ABSENT │ │ │ -│ │ ├── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} -│ │ │ │ PUBLIC → VALIDATED -│ │ │ │ -│ │ │ └── • PreviousStagePrecedence dependency from PUBLIC CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} -│ │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: PUBLIC->VALIDATED" -│ │ │ -│ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} -│ │ │ PUBLIC → ABSENT +│ │ └── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} +│ │ │ PUBLIC → VALIDATED │ │ │ -│ │ └── • Precedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} -│ │ rule: "constraint no longer public before dependents" +│ │ └── • PreviousStagePrecedence dependency from PUBLIC CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} +│ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: PUBLIC->VALIDATED" │ │ -│ └── • 2 Mutation operations -│ │ -│ ├── • MakePublicCheckConstraintValidated -│ │ ConstraintID: 2 -│ │ TableID: 104 +│ └── • 1 Mutation operation │ │ -│ └── • SetConstraintName +│ └── • MakePublicCheckConstraintValidated │ ConstraintID: 2 -│ Name: crdb_internal_constraint_2_name_placeholder │ TableID: 104 │ ├── • PreCommitPhase │ │ │ ├── • Stage 1 of 2 in PreCommitPhase │ │ │ -│ │ ├── • 2 elements transitioning toward ABSENT -│ │ │ │ -│ │ │ ├── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} -│ │ │ │ VALIDATED → PUBLIC +│ │ ├── • 1 element transitioning toward ABSENT │ │ │ │ -│ │ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} -│ │ │ ABSENT → PUBLIC +│ │ │ └── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} +│ │ │ VALIDATED → PUBLIC │ │ │ │ │ └── • 1 Mutation operation │ │ │ @@ -54,31 +40,20 @@ EXPLAIN (ddl, verbose) ALTER TABLE t DROP CONSTRAINT check_i; │ │ │ └── • Stage 2 of 2 in PreCommitPhase │ │ -│ ├── • 2 elements transitioning toward ABSENT +│ ├── • 1 element transitioning toward ABSENT │ │ │ -│ │ ├── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} -│ │ │ │ PUBLIC → VALIDATED -│ │ │ │ -│ │ │ └── • PreviousStagePrecedence dependency from PUBLIC CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} -│ │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: PUBLIC->VALIDATED" -│ │ │ -│ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} -│ │ │ PUBLIC → ABSENT +│ │ └── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} +│ │ │ PUBLIC → VALIDATED │ │ │ -│ │ └── • Precedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} -│ │ rule: "constraint no longer public before dependents" +│ │ └── • PreviousStagePrecedence dependency from PUBLIC CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} +│ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: PUBLIC->VALIDATED" │ │ -│ └── • 4 Mutation operations +│ └── • 3 Mutation operations │ │ │ ├── • MakePublicCheckConstraintValidated │ │ ConstraintID: 2 │ │ TableID: 104 │ │ -│ ├── • SetConstraintName -│ │ ConstraintID: 2 -│ │ Name: crdb_internal_constraint_2_name_placeholder -│ │ TableID: 104 -│ │ │ ├── • SetJobStateOnDescriptor │ │ DescriptorID: 104 │ │ Initialize: true @@ -90,7 +65,7 @@ EXPLAIN (ddl, verbose) ALTER TABLE t DROP CONSTRAINT check_i; │ - 104 │ JobID: 1 │ NonCancelable: true -│ RunningStatus: PostCommitNonRevertiblePhase stage 1 of 1 with 1 MutationType op pending +│ RunningStatus: PostCommitNonRevertiblePhase stage 1 of 1 with 2 MutationType ops pending │ Statements: │ - statement: ALTER TABLE t DROP CONSTRAINT check_i │ redactedstatement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP CONSTRAINT ‹check_i› @@ -100,18 +75,29 @@ EXPLAIN (ddl, verbose) ALTER TABLE t DROP CONSTRAINT check_i; │ └── • Stage 1 of 1 in PostCommitNonRevertiblePhase │ - ├── • 1 element transitioning toward ABSENT + ├── • 2 elements transitioning toward ABSENT │ │ - │ └── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ │ VALIDATED → ABSENT - │ │ - │ ├── • PreviousStagePrecedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: VALIDATED->ABSENT" + │ ├── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ │ │ VALIDATED → ABSENT + │ │ │ + │ │ ├── • PreviousStagePrecedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: VALIDATED->ABSENT" + │ │ │ + │ │ └── • SameStagePrecedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} + │ │ rule: "Constraint should be hidden before name" + │ │ + │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} + │ │ PUBLIC → ABSENT │ │ - │ └── • Precedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} - │ rule: "dependents removed before constraint" + │ └── • Precedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ rule: "Constraint should be hidden before name" │ - └── • 3 Mutation operations + └── • 4 Mutation operations + │ + ├── • SetConstraintName + │ ConstraintID: 2 + │ Name: crdb_internal_constraint_2_name_placeholder + │ TableID: 104 │ ├── • RemoveCheckConstraint │ ConstraintID: 2 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_drop_constraint_fk b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_drop_constraint_fk index f8f619de15bd..92ec21c121c9 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_drop_constraint_fk +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_drop_constraint_fk @@ -11,42 +11,28 @@ EXPLAIN (ddl, verbose) ALTER TABLE t1 DROP CONSTRAINT t1_i_fkey; │ │ │ └── • Stage 1 of 1 in StatementPhase │ │ -│ ├── • 2 elements transitioning toward ABSENT +│ ├── • 1 element transitioning toward ABSENT │ │ │ -│ │ ├── • ForeignKeyConstraint:{DescID: 105, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104} -│ │ │ │ PUBLIC → VALIDATED -│ │ │ │ -│ │ │ └── • PreviousStagePrecedence dependency from PUBLIC ForeignKeyConstraint:{DescID: 105, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104} -│ │ │ rule: "ForeignKeyConstraint transitions to ABSENT uphold 2-version invariant: PUBLIC->VALIDATED" -│ │ │ -│ │ └── • ConstraintWithoutIndexName:{DescID: 105, Name: t1_i_fkey, ConstraintID: 2} -│ │ │ PUBLIC → ABSENT +│ │ └── • ForeignKeyConstraint:{DescID: 105, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104} +│ │ │ PUBLIC → VALIDATED │ │ │ -│ │ └── • Precedence dependency from VALIDATED ForeignKeyConstraint:{DescID: 105, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104} -│ │ rule: "constraint no longer public before dependents" +│ │ └── • PreviousStagePrecedence dependency from PUBLIC ForeignKeyConstraint:{DescID: 105, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104} +│ │ rule: "ForeignKeyConstraint transitions to ABSENT uphold 2-version invariant: PUBLIC->VALIDATED" │ │ -│ └── • 2 Mutation operations -│ │ -│ ├── • MakePublicForeignKeyConstraintValidated -│ │ ConstraintID: 2 -│ │ TableID: 105 +│ └── • 1 Mutation operation │ │ -│ └── • SetConstraintName +│ └── • MakePublicForeignKeyConstraintValidated │ ConstraintID: 2 -│ Name: crdb_internal_constraint_2_name_placeholder │ TableID: 105 │ ├── • PreCommitPhase │ │ │ ├── • Stage 1 of 2 in PreCommitPhase │ │ │ -│ │ ├── • 2 elements transitioning toward ABSENT -│ │ │ │ -│ │ │ ├── • ForeignKeyConstraint:{DescID: 105, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104} -│ │ │ │ VALIDATED → PUBLIC +│ │ ├── • 1 element transitioning toward ABSENT │ │ │ │ -│ │ │ └── • ConstraintWithoutIndexName:{DescID: 105, Name: t1_i_fkey, ConstraintID: 2} -│ │ │ ABSENT → PUBLIC +│ │ │ └── • ForeignKeyConstraint:{DescID: 105, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104} +│ │ │ VALIDATED → PUBLIC │ │ │ │ │ └── • 1 Mutation operation │ │ │ @@ -55,31 +41,20 @@ EXPLAIN (ddl, verbose) ALTER TABLE t1 DROP CONSTRAINT t1_i_fkey; │ │ │ └── • Stage 2 of 2 in PreCommitPhase │ │ -│ ├── • 2 elements transitioning toward ABSENT +│ ├── • 1 element transitioning toward ABSENT │ │ │ -│ │ ├── • ForeignKeyConstraint:{DescID: 105, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104} -│ │ │ │ PUBLIC → VALIDATED -│ │ │ │ -│ │ │ └── • PreviousStagePrecedence dependency from PUBLIC ForeignKeyConstraint:{DescID: 105, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104} -│ │ │ rule: "ForeignKeyConstraint transitions to ABSENT uphold 2-version invariant: PUBLIC->VALIDATED" -│ │ │ -│ │ └── • ConstraintWithoutIndexName:{DescID: 105, Name: t1_i_fkey, ConstraintID: 2} -│ │ │ PUBLIC → ABSENT +│ │ └── • ForeignKeyConstraint:{DescID: 105, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104} +│ │ │ PUBLIC → VALIDATED │ │ │ -│ │ └── • Precedence dependency from VALIDATED ForeignKeyConstraint:{DescID: 105, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104} -│ │ rule: "constraint no longer public before dependents" +│ │ └── • PreviousStagePrecedence dependency from PUBLIC ForeignKeyConstraint:{DescID: 105, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104} +│ │ rule: "ForeignKeyConstraint transitions to ABSENT uphold 2-version invariant: PUBLIC->VALIDATED" │ │ -│ └── • 5 Mutation operations +│ └── • 4 Mutation operations │ │ │ ├── • MakePublicForeignKeyConstraintValidated │ │ ConstraintID: 2 │ │ TableID: 105 │ │ -│ ├── • SetConstraintName -│ │ ConstraintID: 2 -│ │ Name: crdb_internal_constraint_2_name_placeholder -│ │ TableID: 105 -│ │ │ ├── • SetJobStateOnDescriptor │ │ DescriptorID: 104 │ │ Initialize: true @@ -96,7 +71,7 @@ EXPLAIN (ddl, verbose) ALTER TABLE t1 DROP CONSTRAINT t1_i_fkey; │ - 105 │ JobID: 1 │ NonCancelable: true -│ RunningStatus: PostCommitNonRevertiblePhase stage 1 of 1 with 2 MutationType ops pending +│ RunningStatus: PostCommitNonRevertiblePhase stage 1 of 1 with 3 MutationType ops pending │ Statements: │ - statement: ALTER TABLE t1 DROP CONSTRAINT t1_i_fkey │ redactedstatement: ALTER TABLE ‹defaultdb›.‹public›.‹t1› DROP CONSTRAINT ‹t1_i_fkey› @@ -106,18 +81,29 @@ EXPLAIN (ddl, verbose) ALTER TABLE t1 DROP CONSTRAINT t1_i_fkey; │ └── • Stage 1 of 1 in PostCommitNonRevertiblePhase │ - ├── • 1 element transitioning toward ABSENT + ├── • 2 elements transitioning toward ABSENT │ │ - │ └── • ForeignKeyConstraint:{DescID: 105, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104} - │ │ VALIDATED → ABSENT - │ │ - │ ├── • PreviousStagePrecedence dependency from VALIDATED ForeignKeyConstraint:{DescID: 105, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104} - │ │ rule: "ForeignKeyConstraint transitions to ABSENT uphold 2-version invariant: VALIDATED->ABSENT" + │ ├── • ForeignKeyConstraint:{DescID: 105, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104} + │ │ │ VALIDATED → ABSENT + │ │ │ + │ │ ├── • PreviousStagePrecedence dependency from VALIDATED ForeignKeyConstraint:{DescID: 105, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104} + │ │ │ rule: "ForeignKeyConstraint transitions to ABSENT uphold 2-version invariant: VALIDATED->ABSENT" + │ │ │ + │ │ └── • SameStagePrecedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 105, Name: t1_i_fkey, ConstraintID: 2} + │ │ rule: "Constraint should be hidden before name" + │ │ + │ └── • ConstraintWithoutIndexName:{DescID: 105, Name: t1_i_fkey, ConstraintID: 2} + │ │ PUBLIC → ABSENT │ │ - │ └── • Precedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 105, Name: t1_i_fkey, ConstraintID: 2} - │ rule: "dependents removed before constraint" + │ └── • Precedence dependency from VALIDATED ForeignKeyConstraint:{DescID: 105, IndexID: 0, ConstraintID: 2, ReferencedDescID: 104} + │ rule: "Constraint should be hidden before name" │ - └── • 5 Mutation operations + └── • 6 Mutation operations + │ + ├── • SetConstraintName + │ ConstraintID: 2 + │ Name: crdb_internal_constraint_2_name_placeholder + │ TableID: 105 │ ├── • RemoveForeignKeyBackReference │ OriginConstraintID: 2 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_drop_constraint_uwi b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_drop_constraint_uwi index a9992361cc03..8b248863898c 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_drop_constraint_uwi +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_drop_constraint_uwi @@ -12,42 +12,28 @@ EXPLAIN (ddl, verbose) ALTER TABLE t DROP CONSTRAINT unique_j; │ │ │ └── • Stage 1 of 1 in StatementPhase │ │ -│ ├── • 2 elements transitioning toward ABSENT +│ ├── • 1 element transitioning toward ABSENT │ │ │ -│ │ ├── • UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} -│ │ │ │ PUBLIC → VALIDATED -│ │ │ │ -│ │ │ └── • PreviousStagePrecedence dependency from PUBLIC UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} -│ │ │ rule: "UniqueWithoutIndexConstraint transitions to ABSENT uphold 2-version invariant: PUBLIC->VALIDATED" -│ │ │ -│ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} -│ │ │ PUBLIC → ABSENT +│ │ └── • UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} +│ │ │ PUBLIC → VALIDATED │ │ │ -│ │ └── • Precedence dependency from VALIDATED UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} -│ │ rule: "constraint no longer public before dependents" +│ │ └── • PreviousStagePrecedence dependency from PUBLIC UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} +│ │ rule: "UniqueWithoutIndexConstraint transitions to ABSENT uphold 2-version invariant: PUBLIC->VALIDATED" │ │ -│ └── • 2 Mutation operations -│ │ -│ ├── • MakePublicUniqueWithoutIndexConstraintValidated -│ │ ConstraintID: 2 -│ │ TableID: 104 +│ └── • 1 Mutation operation │ │ -│ └── • SetConstraintName +│ └── • MakePublicUniqueWithoutIndexConstraintValidated │ ConstraintID: 2 -│ Name: crdb_internal_constraint_2_name_placeholder │ TableID: 104 │ ├── • PreCommitPhase │ │ │ ├── • Stage 1 of 2 in PreCommitPhase │ │ │ -│ │ ├── • 2 elements transitioning toward ABSENT -│ │ │ │ -│ │ │ ├── • UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} -│ │ │ │ VALIDATED → PUBLIC +│ │ ├── • 1 element transitioning toward ABSENT │ │ │ │ -│ │ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} -│ │ │ ABSENT → PUBLIC +│ │ │ └── • UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} +│ │ │ VALIDATED → PUBLIC │ │ │ │ │ └── • 1 Mutation operation │ │ │ @@ -56,31 +42,20 @@ EXPLAIN (ddl, verbose) ALTER TABLE t DROP CONSTRAINT unique_j; │ │ │ └── • Stage 2 of 2 in PreCommitPhase │ │ -│ ├── • 2 elements transitioning toward ABSENT +│ ├── • 1 element transitioning toward ABSENT │ │ │ -│ │ ├── • UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} -│ │ │ │ PUBLIC → VALIDATED -│ │ │ │ -│ │ │ └── • PreviousStagePrecedence dependency from PUBLIC UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} -│ │ │ rule: "UniqueWithoutIndexConstraint transitions to ABSENT uphold 2-version invariant: PUBLIC->VALIDATED" -│ │ │ -│ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} -│ │ │ PUBLIC → ABSENT +│ │ └── • UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} +│ │ │ PUBLIC → VALIDATED │ │ │ -│ │ └── • Precedence dependency from VALIDATED UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} -│ │ rule: "constraint no longer public before dependents" +│ │ └── • PreviousStagePrecedence dependency from PUBLIC UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} +│ │ rule: "UniqueWithoutIndexConstraint transitions to ABSENT uphold 2-version invariant: PUBLIC->VALIDATED" │ │ -│ └── • 4 Mutation operations +│ └── • 3 Mutation operations │ │ │ ├── • MakePublicUniqueWithoutIndexConstraintValidated │ │ ConstraintID: 2 │ │ TableID: 104 │ │ -│ ├── • SetConstraintName -│ │ ConstraintID: 2 -│ │ Name: crdb_internal_constraint_2_name_placeholder -│ │ TableID: 104 -│ │ │ ├── • SetJobStateOnDescriptor │ │ DescriptorID: 104 │ │ Initialize: true @@ -92,7 +67,7 @@ EXPLAIN (ddl, verbose) ALTER TABLE t DROP CONSTRAINT unique_j; │ - 104 │ JobID: 1 │ NonCancelable: true -│ RunningStatus: PostCommitNonRevertiblePhase stage 1 of 1 with 1 MutationType op pending +│ RunningStatus: PostCommitNonRevertiblePhase stage 1 of 1 with 2 MutationType ops pending │ Statements: │ - statement: ALTER TABLE t DROP CONSTRAINT unique_j │ redactedstatement: ALTER TABLE ‹defaultdb›.‹public›.‹t› DROP CONSTRAINT ‹unique_j› @@ -102,18 +77,29 @@ EXPLAIN (ddl, verbose) ALTER TABLE t DROP CONSTRAINT unique_j; │ └── • Stage 1 of 1 in PostCommitNonRevertiblePhase │ - ├── • 1 element transitioning toward ABSENT + ├── • 2 elements transitioning toward ABSENT │ │ - │ └── • UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} - │ │ VALIDATED → ABSENT - │ │ - │ ├── • PreviousStagePrecedence dependency from VALIDATED UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} - │ │ rule: "UniqueWithoutIndexConstraint transitions to ABSENT uphold 2-version invariant: VALIDATED->ABSENT" + │ ├── • UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} + │ │ │ VALIDATED → ABSENT + │ │ │ + │ │ ├── • PreviousStagePrecedence dependency from VALIDATED UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} + │ │ │ rule: "UniqueWithoutIndexConstraint transitions to ABSENT uphold 2-version invariant: VALIDATED->ABSENT" + │ │ │ + │ │ └── • SameStagePrecedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} + │ │ rule: "Constraint should be hidden before name" + │ │ + │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} + │ │ PUBLIC → ABSENT │ │ - │ └── • Precedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: unique_j, ConstraintID: 2} - │ rule: "dependents removed before constraint" + │ └── • Precedence dependency from VALIDATED UniqueWithoutIndexConstraint:{DescID: 104, ConstraintID: 2} + │ rule: "Constraint should be hidden before name" │ - └── • 3 Mutation operations + └── • 4 Mutation operations + │ + ├── • SetConstraintName + │ ConstraintID: 2 + │ Name: crdb_internal_constraint_2_name_placeholder + │ TableID: 104 │ ├── • RemoveUniqueWithoutIndexConstraint │ ConstraintID: 2 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_validate_constraint b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_validate_constraint index 07f2abc40479..a25dab8c8350 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_validate_constraint +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_validate_constraint @@ -11,13 +11,19 @@ EXPLAIN (ddl, verbose) ALTER TABLE t VALIDATE CONSTRAINT check_i; │ │ │ └── • Stage 1 of 1 in StatementPhase │ │ -│ ├── • 1 element transitioning toward PUBLIC +│ ├── • 2 elements transitioning toward PUBLIC │ │ │ -│ │ └── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} -│ │ │ ABSENT → WRITE_ONLY +│ │ ├── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} +│ │ │ │ ABSENT → WRITE_ONLY +│ │ │ │ +│ │ │ └── • PreviousStagePrecedence dependency from ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} +│ │ │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: ABSENT->WRITE_ONLY" +│ │ │ +│ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 3} +│ │ │ ABSENT → PUBLIC │ │ │ -│ │ └── • PreviousStagePrecedence dependency from ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} -│ │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: ABSENT->WRITE_ONLY" +│ │ └── • SameStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} +│ │ rule: "simple constraint visible before name" │ │ │ ├── • 2 elements transitioning toward ABSENT │ │ │ @@ -25,12 +31,12 @@ EXPLAIN (ddl, verbose) ALTER TABLE t VALIDATE CONSTRAINT check_i; │ │ │ │ PUBLIC → ABSENT │ │ │ │ │ │ │ └── • SameStagePrecedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} -│ │ │ rule: "dependents removed right before simple constraint" +│ │ │ rule: "Constraint should be hidden before name" │ │ │ │ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} │ │ PUBLIC → ABSENT │ │ -│ └── • 3 Mutation operations +│ └── • 4 Mutation operations │ │ │ ├── • SetConstraintName │ │ ConstraintID: 2 @@ -45,6 +51,11 @@ EXPLAIN (ddl, verbose) ALTER TABLE t VALIDATE CONSTRAINT check_i; │ │ TableID: 104 │ │ Validity: 2 │ │ +│ ├── • SetConstraintName +│ │ ConstraintID: 3 +│ │ Name: check_i +│ │ TableID: 104 +│ │ │ └── • RemoveCheckConstraint │ ConstraintID: 2 │ TableID: 104 @@ -53,10 +64,13 @@ EXPLAIN (ddl, verbose) ALTER TABLE t VALIDATE CONSTRAINT check_i; │ │ │ ├── • Stage 1 of 2 in PreCommitPhase │ │ │ -│ │ ├── • 1 element transitioning toward PUBLIC +│ │ ├── • 2 elements transitioning toward PUBLIC +│ │ │ │ +│ │ │ ├── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} +│ │ │ │ WRITE_ONLY → ABSENT │ │ │ │ -│ │ │ └── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} -│ │ │ WRITE_ONLY → ABSENT +│ │ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 3} +│ │ │ PUBLIC → ABSENT │ │ │ │ │ ├── • 2 elements transitioning toward ABSENT │ │ │ │ @@ -73,13 +87,19 @@ EXPLAIN (ddl, verbose) ALTER TABLE t VALIDATE CONSTRAINT check_i; │ │ │ └── • Stage 2 of 2 in PreCommitPhase │ │ -│ ├── • 1 element transitioning toward PUBLIC +│ ├── • 2 elements transitioning toward PUBLIC +│ │ │ +│ │ ├── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} +│ │ │ │ ABSENT → WRITE_ONLY +│ │ │ │ +│ │ │ └── • PreviousStagePrecedence dependency from ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} +│ │ │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: ABSENT->WRITE_ONLY" │ │ │ -│ │ └── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} -│ │ │ ABSENT → WRITE_ONLY +│ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 3} +│ │ │ ABSENT → PUBLIC │ │ │ -│ │ └── • PreviousStagePrecedence dependency from ABSENT CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} -│ │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: ABSENT->WRITE_ONLY" +│ │ └── • SameStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} +│ │ rule: "simple constraint visible before name" │ │ │ ├── • 2 elements transitioning toward ABSENT │ │ │ @@ -87,12 +107,12 @@ EXPLAIN (ddl, verbose) ALTER TABLE t VALIDATE CONSTRAINT check_i; │ │ │ │ PUBLIC → ABSENT │ │ │ │ │ │ │ └── • SameStagePrecedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} -│ │ │ rule: "dependents removed right before simple constraint" +│ │ │ rule: "Constraint should be hidden before name" │ │ │ │ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} │ │ PUBLIC → ABSENT │ │ -│ └── • 5 Mutation operations +│ └── • 6 Mutation operations │ │ │ ├── • SetConstraintName │ │ ConstraintID: 2 @@ -107,6 +127,11 @@ EXPLAIN (ddl, verbose) ALTER TABLE t VALIDATE CONSTRAINT check_i; │ │ TableID: 104 │ │ Validity: 2 │ │ +│ ├── • SetConstraintName +│ │ ConstraintID: 3 +│ │ Name: check_i +│ │ TableID: 104 +│ │ │ ├── • RemoveCheckConstraint │ │ ConstraintID: 2 │ │ TableID: 104 @@ -147,26 +172,15 @@ EXPLAIN (ddl, verbose) ALTER TABLE t VALIDATE CONSTRAINT check_i; │ └── • Stage 2 of 2 in PostCommitPhase │ - ├── • 2 elements transitioning toward PUBLIC + ├── • 1 element transitioning toward PUBLIC │ │ - │ ├── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} - │ │ │ VALIDATED → PUBLIC - │ │ │ - │ │ ├── • PreviousStagePrecedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} - │ │ │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: VALIDATED->PUBLIC" - │ │ │ - │ │ └── • SameStagePrecedence dependency from PUBLIC ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 3} - │ │ rule: "constraint dependent public right before complex constraint" - │ │ - │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 3} - │ ABSENT → PUBLIC + │ └── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} + │ │ VALIDATED → PUBLIC + │ │ + │ └── • PreviousStagePrecedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} + │ rule: "CheckConstraint transitions to PUBLIC uphold 2-version invariant: VALIDATED->PUBLIC" │ - └── • 4 Mutation operations - │ - ├── • SetConstraintName - │ ConstraintID: 3 - │ Name: check_i - │ TableID: 104 + └── • 3 Mutation operations │ ├── • MakeValidatedCheckConstraintPublic │ ConstraintID: 3 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_validate_constraint.rollback_1_of_2 b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_validate_constraint.rollback_1_of_2 index 1f9f16c80b04..bd1217205b54 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_validate_constraint.rollback_1_of_2 +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_validate_constraint.rollback_1_of_2 @@ -20,18 +20,24 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 1 of 2; │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} │ ABSENT → PUBLIC │ - ├── • 1 element transitioning toward ABSENT + ├── • 2 elements transitioning toward ABSENT │ │ - │ └── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} - │ │ WRITE_ONLY → ABSENT - │ │ - │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} - │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" + │ ├── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} + │ │ │ WRITE_ONLY → ABSENT + │ │ │ + │ │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} + │ │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" + │ │ │ + │ │ └── • SameStagePrecedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 3} + │ │ rule: "Constraint should be hidden before name" + │ │ + │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 3} + │ │ PUBLIC → ABSENT │ │ - │ └── • Precedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 3} - │ rule: "dependents removed before constraint" + │ └── • Precedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} + │ rule: "Constraint should be hidden before name" │ - └── • 5 Mutation operations + └── • 6 Mutation operations │ ├── • AddCheckConstraint │ CheckExpr: i > 0:::INT8 @@ -46,6 +52,11 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 1 of 2; │ Name: check_i │ TableID: 104 │ + ├── • SetConstraintName + │ ConstraintID: 3 + │ Name: crdb_internal_constraint_3_name_placeholder + │ TableID: 104 + │ ├── • RemoveCheckConstraint │ ConstraintID: 3 │ TableID: 104 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_validate_constraint.rollback_2_of_2 b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_validate_constraint.rollback_2_of_2 index 17f1561ec451..6b955cc2a058 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_validate_constraint.rollback_2_of_2 +++ b/pkg/sql/schemachanger/testdata/explain_verbose/alter_table_validate_constraint.rollback_2_of_2 @@ -20,18 +20,24 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 2 of 2; │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 2} │ ABSENT → PUBLIC │ - ├── • 1 element transitioning toward ABSENT + ├── • 2 elements transitioning toward ABSENT │ │ - │ └── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} - │ │ WRITE_ONLY → ABSENT - │ │ - │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} - │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" + │ ├── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} + │ │ │ WRITE_ONLY → ABSENT + │ │ │ + │ │ ├── • PreviousStagePrecedence dependency from WRITE_ONLY CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} + │ │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: WRITE_ONLY->VALIDATED" + │ │ │ + │ │ └── • SameStagePrecedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 3} + │ │ rule: "Constraint should be hidden before name" + │ │ + │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 3} + │ │ PUBLIC → ABSENT │ │ - │ └── • Precedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_i, ConstraintID: 3} - │ rule: "dependents removed before constraint" + │ └── • Precedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 3} + │ rule: "Constraint should be hidden before name" │ - └── • 5 Mutation operations + └── • 6 Mutation operations │ ├── • AddCheckConstraint │ CheckExpr: i > 0:::INT8 @@ -46,6 +52,11 @@ EXPLAIN (ddl, verbose) rollback at post-commit stage 2 of 2; │ Name: check_i │ TableID: 104 │ + ├── • SetConstraintName + │ ConstraintID: 3 + │ Name: crdb_internal_constraint_3_name_placeholder + │ TableID: 104 + │ ├── • RemoveCheckConstraint │ ConstraintID: 3 │ TableID: 104 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/drop_index_hash_sharded_index b/pkg/sql/schemachanger/testdata/explain_verbose/drop_index_hash_sharded_index index 9e1eac9ba309..e30d4943ba2b 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/drop_index_hash_sharded_index +++ b/pkg/sql/schemachanger/testdata/explain_verbose/drop_index_hash_sharded_index @@ -11,7 +11,7 @@ EXPLAIN (ddl, verbose) DROP INDEX idx CASCADE; │ │ │ └── • Stage 1 of 1 in StatementPhase │ │ -│ ├── • 6 elements transitioning toward ABSENT +│ ├── • 5 elements transitioning toward ABSENT │ │ │ │ │ ├── • Column:{DescID: 104, ColumnID: 3} │ │ │ │ PUBLIC → WRITE_ONLY @@ -40,19 +40,13 @@ EXPLAIN (ddl, verbose) DROP INDEX idx CASCADE; │ │ │ └── • PreviousStagePrecedence dependency from PUBLIC SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} │ │ │ rule: "SecondaryIndex transitions to ABSENT uphold 2-version invariant: PUBLIC->VALIDATED" │ │ │ -│ │ ├── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} -│ │ │ │ PUBLIC → VALIDATED -│ │ │ │ -│ │ │ └── • PreviousStagePrecedence dependency from PUBLIC CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} -│ │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: PUBLIC->VALIDATED" -│ │ │ -│ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_16, ConstraintID: 2} -│ │ │ PUBLIC → ABSENT +│ │ └── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} +│ │ │ PUBLIC → VALIDATED │ │ │ -│ │ └── • Precedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} -│ │ rule: "constraint no longer public before dependents" +│ │ └── • PreviousStagePrecedence dependency from PUBLIC CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} +│ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: PUBLIC->VALIDATED" │ │ -│ └── • 6 Mutation operations +│ └── • 5 Mutation operations │ │ │ ├── • MakePublicColumnNotNullValidated │ │ ColumnID: 3 @@ -66,11 +60,6 @@ EXPLAIN (ddl, verbose) DROP INDEX idx CASCADE; │ │ ConstraintID: 2 │ │ TableID: 104 │ │ -│ ├── • SetConstraintName -│ │ ConstraintID: 2 -│ │ Name: crdb_internal_constraint_2_name_placeholder -│ │ TableID: 104 -│ │ │ ├── • MakePublicColumnWriteOnly │ │ ColumnID: 3 │ │ TableID: 104 @@ -84,7 +73,7 @@ EXPLAIN (ddl, verbose) DROP INDEX idx CASCADE; │ │ │ ├── • Stage 1 of 2 in PreCommitPhase │ │ │ -│ │ ├── • 6 elements transitioning toward ABSENT +│ │ ├── • 5 elements transitioning toward ABSENT │ │ │ │ │ │ │ ├── • Column:{DescID: 104, ColumnID: 3} │ │ │ │ WRITE_ONLY → PUBLIC @@ -98,11 +87,8 @@ EXPLAIN (ddl, verbose) DROP INDEX idx CASCADE; │ │ │ ├── • SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} │ │ │ │ VALIDATED → PUBLIC │ │ │ │ -│ │ │ ├── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} -│ │ │ │ VALIDATED → PUBLIC -│ │ │ │ -│ │ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_16, ConstraintID: 2} -│ │ │ ABSENT → PUBLIC +│ │ │ └── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} +│ │ │ VALIDATED → PUBLIC │ │ │ │ │ └── • 1 Mutation operation │ │ │ @@ -111,7 +97,7 @@ EXPLAIN (ddl, verbose) DROP INDEX idx CASCADE; │ │ │ └── • Stage 2 of 2 in PreCommitPhase │ │ -│ ├── • 6 elements transitioning toward ABSENT +│ ├── • 5 elements transitioning toward ABSENT │ │ │ │ │ ├── • Column:{DescID: 104, ColumnID: 3} │ │ │ │ PUBLIC → WRITE_ONLY @@ -140,19 +126,13 @@ EXPLAIN (ddl, verbose) DROP INDEX idx CASCADE; │ │ │ └── • PreviousStagePrecedence dependency from PUBLIC SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} │ │ │ rule: "SecondaryIndex transitions to ABSENT uphold 2-version invariant: PUBLIC->VALIDATED" │ │ │ -│ │ ├── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} -│ │ │ │ PUBLIC → VALIDATED -│ │ │ │ -│ │ │ └── • PreviousStagePrecedence dependency from PUBLIC CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} -│ │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: PUBLIC->VALIDATED" -│ │ │ -│ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_16, ConstraintID: 2} -│ │ │ PUBLIC → ABSENT +│ │ └── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} +│ │ │ PUBLIC → VALIDATED │ │ │ -│ │ └── • Precedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} -│ │ rule: "constraint no longer public before dependents" +│ │ └── • PreviousStagePrecedence dependency from PUBLIC CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} +│ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: PUBLIC->VALIDATED" │ │ -│ └── • 8 Mutation operations +│ └── • 7 Mutation operations │ │ │ ├── • MakePublicColumnNotNullValidated │ │ ColumnID: 3 @@ -166,11 +146,6 @@ EXPLAIN (ddl, verbose) DROP INDEX idx CASCADE; │ │ ConstraintID: 2 │ │ TableID: 104 │ │ -│ ├── • SetConstraintName -│ │ ConstraintID: 2 -│ │ Name: crdb_internal_constraint_2_name_placeholder -│ │ TableID: 104 -│ │ │ ├── • MakePublicColumnWriteOnly │ │ ColumnID: 3 │ │ TableID: 104 @@ -191,7 +166,7 @@ EXPLAIN (ddl, verbose) DROP INDEX idx CASCADE; │ - 104 │ JobID: 1 │ NonCancelable: true -│ RunningStatus: PostCommitNonRevertiblePhase stage 1 of 2 with 8 MutationType ops pending +│ RunningStatus: PostCommitNonRevertiblePhase stage 1 of 2 with 9 MutationType ops pending │ Statements: │ - statement: DROP INDEX idx CASCADE │ redactedstatement: DROP INDEX ‹defaultdb›.‹public›.‹t›@‹idx› CASCADE @@ -201,7 +176,7 @@ EXPLAIN (ddl, verbose) DROP INDEX idx CASCADE; │ ├── • Stage 1 of 2 in PostCommitNonRevertiblePhase │ │ - │ ├── • 8 elements transitioning toward ABSENT + │ ├── • 9 elements transitioning toward ABSENT │ │ │ │ │ ├── • Column:{DescID: 104, ColumnID: 3} │ │ │ │ WRITE_ONLY → DELETE_ONLY @@ -257,23 +232,30 @@ EXPLAIN (ddl, verbose) DROP INDEX idx CASCADE; │ │ │ └── • Precedence dependency from VALIDATED SecondaryIndex:{DescID: 104, IndexID: 2, ConstraintID: 0} │ │ │ rule: "index no longer public before dependents, excluding columns" │ │ │ - │ │ └── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ │ │ VALIDATED → ABSENT - │ │ │ - │ │ ├── • PreviousStagePrecedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} - │ │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: VALIDATED->ABSENT" + │ │ ├── • CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ │ │ │ VALIDATED → ABSENT + │ │ │ │ + │ │ │ ├── • PreviousStagePrecedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ │ │ │ rule: "CheckConstraint transitions to ABSENT uphold 2-version invariant: VALIDATED->ABSENT" + │ │ │ │ + │ │ │ └── • SameStagePrecedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_16, ConstraintID: 2} + │ │ │ rule: "Constraint should be hidden before name" + │ │ │ + │ │ └── • ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_16, ConstraintID: 2} + │ │ │ PUBLIC → ABSENT │ │ │ - │ │ └── • Precedence dependency from ABSENT ConstraintWithoutIndexName:{DescID: 104, Name: check_crdb_internal_j_shard_16, ConstraintID: 2} - │ │ rule: "dependents removed before constraint" + │ │ └── • Precedence dependency from VALIDATED CheckConstraint:{DescID: 104, IndexID: 0, ConstraintID: 2} + │ │ rule: "Constraint should be hidden before name" │ │ - │ └── • 10 Mutation operations + │ └── • 11 Mutation operations │ │ │ ├── • RemoveColumnNotNull │ │ ColumnID: 3 │ │ TableID: 104 │ │ - │ ├── • RemoveCheckConstraint + │ ├── • SetConstraintName │ │ ConstraintID: 2 + │ │ Name: crdb_internal_constraint_2_name_placeholder │ │ TableID: 104 │ │ │ ├── • MakeWriteOnlyColumnDeleteOnly @@ -289,6 +271,10 @@ EXPLAIN (ddl, verbose) DROP INDEX idx CASCADE; │ │ Name: crdb_internal_index_2_name_placeholder │ │ TableID: 104 │ │ + │ ├── • RemoveCheckConstraint + │ │ ConstraintID: 2 + │ │ TableID: 104 + │ │ │ ├── • RemoveColumnFromIndex │ │ ColumnID: 3 │ │ IndexID: 2