From 09eedc5c2fea3f621242f305f7b9681c1cb4fefd Mon Sep 17 00:00:00 2001 From: Annie Pompa Date: Tue, 19 Nov 2024 17:26:29 -0500 Subject: [PATCH 1/2] schemachanger: fix discards for explicit txns Previously, discarding a zone config on an object in an explicit transaction would only discard the latest (categorized by highest seq num) element associated with it. This would mean for the following scenario: ``` BEGIN; ALTER TABLE t CONFIGURE ZONE USING num_replicas = 11; ALTER TABLE t CONFIGURE ZONE USING num_replicas = 12; ALTER TABLE t CONFIGURE ZONE DISCARD; COMMIT; ``` The discard would only discard the element with a replication factor of 12, leaving us with a table with a rep. factor of 11. This patch ensures we clean up all references of an element when discarding. Epic: none Release note: None --- .../backup_base_generated_test.go | 28 +++++++++ .../logictest/testdata/logic_test/event_log | 1 - .../internal/scbuildstmt/configure_zone.go | 42 ++++++++----- .../scbuildstmt/database_zone_config.go | 16 ++--- .../internal/scbuildstmt/index_zone_config.go | 6 +- .../scbuildstmt/named_range_zone_config.go | 16 ++--- .../scbuildstmt/partition_zone_config.go | 4 +- .../internal/scbuildstmt/table_zone_config.go | 17 +++--- .../scbuildstmt/zone_config_helpers.go | 11 ++-- .../scexec/exec_immediate_mutation.go | 12 ++-- .../scexec/scmutationexec/zone_config.go | 11 +++- .../schemachanger/scop/immediate_mutation.go | 13 +++- .../immediate_mutation_visitor_generated.go | 6 ++ .../scplan/internal/opgen/op_funcs.go | 13 ++++ .../opgen/opgen_database_zone_config.go | 11 +++- .../internal/opgen/opgen_table_zone_config.go | 6 +- .../schemachanger/sctest_generated_test.go | 42 +++++++++++++ ...database_configure_zone_discard.definition | 1 + ...tabase_configure_zone_discard.side_effects | 17 +++++- ...re_zone_discard__statement_1_of_3.explain} | 0 ...e_discard__statement_1_of_3.explain_shape} | 0 ...ure_zone_discard__statement_2_of_3.explain | 28 +++++++++ ...ne_discard__statement_2_of_3.explain_shape | 9 +++ ...re_zone_discard__statement_3_of_3.explain} | 11 ++-- ...e_discard__statement_3_of_3.explain_shape} | 3 +- ...er_table_configure_zone_discard.definition | 9 +++ ..._table_configure_zone_discard.side_effects | 60 +++++++++++++++++++ ...ure_zone_discard__statement_1_of_3.explain | 24 ++++++++ ...ne_discard__statement_1_of_3.explain_shape | 8 +++ ...ure_zone_discard__statement_2_of_3.explain | 28 +++++++++ ...ne_discard__statement_2_of_3.explain_shape | 9 +++ ...ure_zone_discard__statement_3_of_3.explain | 21 +++++++ ...ne_discard__statement_3_of_3.explain_shape | 10 ++++ 33 files changed, 423 insertions(+), 70 deletions(-) rename pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/{alter_database_configure_zone_discard__statement_1_of_2.explain => alter_database_configure_zone_discard__statement_1_of_3.explain} (100%) rename pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/{alter_database_configure_zone_discard__statement_1_of_2.explain_shape => alter_database_configure_zone_discard__statement_1_of_3.explain_shape} (100%) create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_2_of_3.explain create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_2_of_3.explain_shape rename pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/{alter_database_configure_zone_discard__statement_2_of_2.explain => alter_database_configure_zone_discard__statement_3_of_3.explain} (66%) rename pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/{alter_database_configure_zone_discard__statement_2_of_2.explain_shape => alter_database_configure_zone_discard__statement_3_of_3.explain_shape} (76%) create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard.definition create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard.side_effects create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard__statement_1_of_3.explain create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard__statement_1_of_3.explain_shape create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard__statement_2_of_3.explain create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard__statement_2_of_3.explain_shape create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard__statement_3_of_3.explain create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard__statement_3_of_3.explain_shape diff --git a/pkg/ccl/schemachangerccl/backup_base_generated_test.go b/pkg/ccl/schemachangerccl/backup_base_generated_test.go index f380ee39a922..dce4fa2c9803 100644 --- a/pkg/ccl/schemachangerccl/backup_base_generated_test.go +++ b/pkg/ccl/schemachangerccl/backup_base_generated_test.go @@ -253,6 +253,13 @@ func TestBackupRollbacks_base_alter_table_configure_zone(t *testing.T) { sctest.BackupRollbacks(t, path, sctest.SingleNodeTestClusterFactory{}) } +func TestBackupRollbacks_base_alter_table_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard" + sctest.BackupRollbacks(t, path, sctest.SingleNodeTestClusterFactory{}) +} + func TestBackupRollbacks_base_alter_table_configure_zone_multiple(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -806,6 +813,13 @@ func TestBackupRollbacksMixedVersion_base_alter_table_configure_zone(t *testing. sctest.BackupRollbacksMixedVersion(t, path, sctest.SingleNodeTestClusterFactory{}) } +func TestBackupRollbacksMixedVersion_base_alter_table_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard" + sctest.BackupRollbacksMixedVersion(t, path, sctest.SingleNodeTestClusterFactory{}) +} + func TestBackupRollbacksMixedVersion_base_alter_table_configure_zone_multiple(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -1359,6 +1373,13 @@ func TestBackupSuccess_base_alter_table_configure_zone(t *testing.T) { sctest.BackupSuccess(t, path, sctest.SingleNodeTestClusterFactory{}) } +func TestBackupSuccess_base_alter_table_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard" + sctest.BackupSuccess(t, path, sctest.SingleNodeTestClusterFactory{}) +} + func TestBackupSuccess_base_alter_table_configure_zone_multiple(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -1912,6 +1933,13 @@ func TestBackupSuccessMixedVersion_base_alter_table_configure_zone(t *testing.T) sctest.BackupSuccessMixedVersion(t, path, sctest.SingleNodeTestClusterFactory{}) } +func TestBackupSuccessMixedVersion_base_alter_table_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard" + sctest.BackupSuccessMixedVersion(t, path, sctest.SingleNodeTestClusterFactory{}) +} + func TestBackupSuccessMixedVersion_base_alter_table_configure_zone_multiple(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) diff --git a/pkg/sql/logictest/testdata/logic_test/event_log b/pkg/sql/logictest/testdata/logic_test/event_log index 04147e502f1e..042def573c34 100644 --- a/pkg/sql/logictest/testdata/logic_test/event_log +++ b/pkg/sql/logictest/testdata/logic_test/event_log @@ -548,7 +548,6 @@ ORDER BY "timestamp", info 1 {"EventType": "set_zone_config", "Options": ["range_max_bytes = 67108865", "range_min_bytes = 16777216"], "ResolvedOldConfig": "range_min_bytes:134217728 range_max_bytes:536870912 gc: num_replicas:3 inherited_constraints:false null_voter_constraints_is_empty:true inherited_lease_preferences:false ", "Tag": "CONFIGURE ZONE", "Target": "TABLE test.public.a", "User": "root"} 1 {"EventType": "set_zone_config", "Options": ["\"gc.ttlseconds\" = 13000"], "ResolvedOldConfig": "range_min_bytes:134217728 range_max_bytes:536870912 gc: num_replicas:3 inherited_constraints:false null_voter_constraints_is_empty:true inherited_lease_preferences:false ", "Tag": "CONFIGURE ZONE", "Target": "INDEX test.public.a@a_pkey", "User": "root"} 1 {"EventType": "set_zone_config", "Options": ["\"gc.ttlseconds\" = 15000"], "ResolvedOldConfig": "range_min_bytes:134217728 range_max_bytes:536870912 gc: num_replicas:3 inherited_constraints:false null_voter_constraints_is_empty:true inherited_lease_preferences:false ", "Tag": "CONFIGURE ZONE", "Target": "INDEX test.public.a@bar", "User": "root"} -1 {"EventType": "set_zone_config", "Options": ["\"gc.ttlseconds\" = 15000"], "ResolvedOldConfig": "range_min_bytes:134217728 range_max_bytes:536870912 gc: num_replicas:3 inherited_constraints:false null_voter_constraints_is_empty:true inherited_lease_preferences:false ", "Tag": "CONFIGURE ZONE", "Target": "INDEX test.public.a@bar", "User": "root"} skipif config 3node-tenant-default-configs query IT diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/configure_zone.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/configure_zone.go index 82a49dcd0265..4f3bdeb172cd 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/configure_zone.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/configure_zone.go @@ -94,14 +94,23 @@ func SetZoneConfig(b BuildCtx, n *tree.SetZoneConfig) { if zco.isNoOp() { return } - toDrop, affectedSubzoneConfigsToUpdate := zco.getZoneConfigElemForDrop(b) - dropZoneConfigElem(b, toDrop, eventDetails) - addZoneConfigElem(b, affectedSubzoneConfigsToUpdate, oldZone, eventDetails) + + toDropList, affectedSubzoneConfigsToUpdate := zco.getZoneConfigElemForDrop(b) + for i, e := range toDropList { + // Log the latest dropping element. + dropZoneConfigElem(b, e, eventDetails, i == len(toDropList)-1 /* isLoggingNeeded */) + } + for _, e := range affectedSubzoneConfigsToUpdate { + // No need to log the side effects. + addZoneConfigElem(b, e, oldZone, eventDetails, false /* isLoggingNeeded */) + } } else { toAdd, affectedSubzoneConfigsToUpdate := zco.getZoneConfigElemForAdd(b) - affectedSubzoneConfigsToUpdate = append([]scpb.Element{toAdd}, - affectedSubzoneConfigsToUpdate...) - addZoneConfigElem(b, affectedSubzoneConfigsToUpdate, oldZone, eventDetails) + addZoneConfigElem(b, toAdd, oldZone, eventDetails, true) + for _, e := range affectedSubzoneConfigsToUpdate { + // No need to log the side effects. + addZoneConfigElem(b, e, oldZone, eventDetails, false /* isLoggingNeeded */) + } } } @@ -203,23 +212,26 @@ func astToZoneConfigObject(b BuildCtx, n *tree.SetZoneConfig) (zoneConfigObject, } func dropZoneConfigElem( - b BuildCtx, elem scpb.Element, eventDetails eventpb.CommonZoneConfigDetails, + b BuildCtx, elem scpb.Element, eventDetails eventpb.CommonZoneConfigDetails, isLoggingNeeded bool, ) { - info := &eventpb.RemoveZoneConfig{CommonZoneConfigDetails: eventDetails} b.Drop(elem) - b.LogEventForExistingPayload(elem, info) + if isLoggingNeeded { + info := &eventpb.RemoveZoneConfig{CommonZoneConfigDetails: eventDetails} + b.LogEventForExistingPayload(elem, info) + } } func addZoneConfigElem( b BuildCtx, - elems []scpb.Element, + elem scpb.Element, oldZone *zonepb.ZoneConfig, eventDetails eventpb.CommonZoneConfigDetails, + isLoggingNeeded bool, ) { - info := &eventpb.SetZoneConfig{CommonZoneConfigDetails: eventDetails, - ResolvedOldConfig: oldZone.String()} - for _, e := range elems { - b.Add(e) - b.LogEventForExistingPayload(e, info) + b.Add(elem) + if isLoggingNeeded { + info := &eventpb.SetZoneConfig{CommonZoneConfigDetails: eventDetails, + ResolvedOldConfig: oldZone.String()} + b.LogEventForExistingPayload(elem, info) } } diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/database_zone_config.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/database_zone_config.go index d51fe04191bf..9d9ccad369b9 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/database_zone_config.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/database_zone_config.go @@ -43,14 +43,14 @@ func (dzo *databaseZoneConfigObj) getZoneConfigElemForAdd( } func (dzo *databaseZoneConfigObj) getZoneConfigElemForDrop( - _ BuildCtx, -) (scpb.Element, []scpb.Element) { - elem := &scpb.DatabaseZoneConfig{ - DatabaseID: dzo.databaseID, - ZoneConfig: dzo.zoneConfig, - SeqNum: dzo.seqNum, - } - return elem, nil + b BuildCtx, +) ([]scpb.Element, []scpb.Element) { + var elems []scpb.Element + b.QueryByID(dzo.getTargetID()).FilterDatabaseZoneConfig(). + ForEach(func(_ scpb.Status, _ scpb.TargetStatus, e *scpb.DatabaseZoneConfig) { + elems = append(elems, e) + }) + return elems, nil } func (dzo *databaseZoneConfigObj) checkPrivilegeForSetZoneConfig( diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/index_zone_config.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/index_zone_config.go index b225a4493c34..8300bad77649 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/index_zone_config.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/index_zone_config.go @@ -80,10 +80,12 @@ func (izo *indexZoneConfigObj) getZoneConfigElemForAdd(b BuildCtx) (scpb.Element return szCfg, szCfgsToUpdate } -func (izo *indexZoneConfigObj) getZoneConfigElemForDrop(b BuildCtx) (scpb.Element, []scpb.Element) { +func (izo *indexZoneConfigObj) getZoneConfigElemForDrop( + b BuildCtx, +) ([]scpb.Element, []scpb.Element) { // TODO(annie): this will need to be revised in order to implement subzone // discards. - return izo.getZoneConfigElemForAdd(b) + return nil, nil } func (izo *indexZoneConfigObj) retrievePartialZoneConfig(b BuildCtx) *zonepb.ZoneConfig { diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/named_range_zone_config.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/named_range_zone_config.go index 1e5a5f2f74c5..1322558680af 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/named_range_zone_config.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/named_range_zone_config.go @@ -42,14 +42,14 @@ func (rzo *namedRangeZoneConfigObj) getZoneConfigElemForAdd( } func (rzo *namedRangeZoneConfigObj) getZoneConfigElemForDrop( - _ BuildCtx, -) (scpb.Element, []scpb.Element) { - elem := &scpb.NamedRangeZoneConfig{ - RangeID: rzo.rangeID, - ZoneConfig: rzo.zoneConfig, - SeqNum: rzo.seqNum, - } - return elem, nil + b BuildCtx, +) ([]scpb.Element, []scpb.Element) { + var elems []scpb.Element + b.QueryByID(rzo.getTargetID()).FilterNamedRangeZoneConfig(). + ForEach(func(_ scpb.Status, _ scpb.TargetStatus, e *scpb.NamedRangeZoneConfig) { + elems = append(elems, e) + }) + return elems, nil } func (rzo *namedRangeZoneConfigObj) checkPrivilegeForSetZoneConfig( diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/partition_zone_config.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/partition_zone_config.go index e2552fcc2506..38adede38390 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/partition_zone_config.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/partition_zone_config.go @@ -91,10 +91,10 @@ func (pzo *partitionZoneConfigObj) getZoneConfigElemForAdd( func (pzo *partitionZoneConfigObj) getZoneConfigElemForDrop( b BuildCtx, -) (scpb.Element, []scpb.Element) { +) ([]scpb.Element, []scpb.Element) { // TODO(annie): this will need to be revised in order to implement subzone // discards. This is fine for now as we fallback before we can get here. - return pzo.getZoneConfigElemForAdd(b) + return nil, nil } func (pzo *partitionZoneConfigObj) retrievePartialZoneConfig(b BuildCtx) *zonepb.ZoneConfig { diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/table_zone_config.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/table_zone_config.go index ceaa475c2a63..95e958eb2bc1 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/table_zone_config.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/table_zone_config.go @@ -41,13 +41,16 @@ func (tzo *tableZoneConfigObj) getZoneConfigElemForAdd(_ BuildCtx) (scpb.Element return elem, nil } -func (tzo *tableZoneConfigObj) getZoneConfigElemForDrop(_ BuildCtx) (scpb.Element, []scpb.Element) { - elem := &scpb.TableZoneConfig{ - TableID: tzo.tableID, - ZoneConfig: tzo.zoneConfig, - SeqNum: tzo.seqNum, - } - return elem, nil +func (tzo *tableZoneConfigObj) getZoneConfigElemForDrop( + b BuildCtx, +) ([]scpb.Element, []scpb.Element) { + var elems []scpb.Element + b.QueryByID(tzo.getTargetID()).FilterTableZoneConfig(). + ForEach(func(_ scpb.Status, _ scpb.TargetStatus, e *scpb.TableZoneConfig) { + e.ZoneConfig.DeleteTableConfig() + elems = append(elems, e) + }) + return elems, nil } func (tzo *tableZoneConfigObj) checkPrivilegeForSetZoneConfig( diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/zone_config_helpers.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/zone_config_helpers.go index ee938c2dce00..d0ea47288489 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/zone_config_helpers.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/zone_config_helpers.go @@ -59,12 +59,14 @@ type zoneConfigObjBuilder interface { // elements around. getZoneConfigElemForAdd(b BuildCtx) (scpb.Element, []scpb.Element) - // getZoneConfigElemForDrop retrieves (scpb.Element, []scpb.Element) needed - // for dropping the zone config object. The slice of multiple elements + // getZoneConfigElemForDrop retrieves ([]scpb.Element, []scpb.Element) needed + // for dropping the zone config object. The second slice of multiple elements // to be modified becomes more relevant for subzone configs -- as configuring // the zone on indexes and partitions can shift the subzone spans for other - // elements around. - getZoneConfigElemForDrop(b BuildCtx) (scpb.Element, []scpb.Element) + // elements around. The first slice is used to ensure all references with + // varying `seqNum`s for the element are dropped (relevant only in explicit + // transactions). + getZoneConfigElemForDrop(b BuildCtx) ([]scpb.Element, []scpb.Element) // getTargetID returns the target ID of the zone config object. This is either // a database or a table ID. @@ -1132,7 +1134,6 @@ func prepareZoneConfig( } if n.Discard { - partialZone.DeleteTableConfig() return nil, partialZone, nil } diff --git a/pkg/sql/schemachanger/scexec/exec_immediate_mutation.go b/pkg/sql/schemachanger/scexec/exec_immediate_mutation.go index dd26b2542112..73c786e0c00a 100644 --- a/pkg/sql/schemachanger/scexec/exec_immediate_mutation.go +++ b/pkg/sql/schemachanger/scexec/exec_immediate_mutation.go @@ -240,6 +240,12 @@ func (s *immediateState) exec(ctx context.Context, c Catalog) error { c.InsertTemporarySchema(tempIdxToRegister.schemaName, tempIdxToRegister.parentID, tempIdxId) } + for _, zcToDelete := range s.zoneConfigsToDelete { + if err = c.DeleteZoneConfig(ctx, zcToDelete.id); err != nil { + return err + } + } + for _, zcToUpdate := range s.modifiedZoneConfigs { if err = c.UpdateZoneConfig(ctx, zcToUpdate.id, zcToUpdate.zc); err != nil { return err @@ -273,12 +279,6 @@ func (s *immediateState) exec(ctx context.Context, c Catalog) error { } } - for _, zcToDelete := range s.zoneConfigsToDelete { - if err = c.DeleteZoneConfig(ctx, zcToDelete.id); err != nil { - return err - } - } - return c.Validate(ctx) } diff --git a/pkg/sql/schemachanger/scexec/scmutationexec/zone_config.go b/pkg/sql/schemachanger/scexec/scmutationexec/zone_config.go index 1ee4e2abd0bd..47b58efb8247 100644 --- a/pkg/sql/schemachanger/scexec/scmutationexec/zone_config.go +++ b/pkg/sql/schemachanger/scexec/scmutationexec/zone_config.go @@ -12,11 +12,18 @@ import ( ) func (i *immediateVisitor) DiscardZoneConfig(ctx context.Context, op scop.DiscardZoneConfig) error { + i.ImmediateMutationStateUpdater.DeleteZoneConfig(op.DescID) + return nil +} + +func (i *immediateVisitor) DiscardTableZoneConfig( + ctx context.Context, op scop.DiscardTableZoneConfig, +) error { zc := op.ZoneConfig if zc.IsSubzonePlaceholder() && len(zc.Subzones) == 0 { - i.ImmediateMutationStateUpdater.DeleteZoneConfig(op.DescID) + i.ImmediateMutationStateUpdater.DeleteZoneConfig(op.TableID) } else { - i.ImmediateMutationStateUpdater.UpdateZoneConfig(op.DescID, zc) + i.ImmediateMutationStateUpdater.UpdateZoneConfig(op.TableID, zc) } return nil } diff --git a/pkg/sql/schemachanger/scop/immediate_mutation.go b/pkg/sql/schemachanger/scop/immediate_mutation.go index b06bdfe3ff3b..467bed436f34 100644 --- a/pkg/sql/schemachanger/scop/immediate_mutation.go +++ b/pkg/sql/schemachanger/scop/immediate_mutation.go @@ -1002,10 +1002,19 @@ type AddDatabaseZoneConfig struct { ZoneConfig zonepb.ZoneConfig } -// DiscardZoneConfig discards the zone config for the given descriptor ID. +// DiscardZoneConfig discards the zone config for the given ID. For table IDs, +// we use DiscardTableZoneConfig as some extra work is needed for subzones. type DiscardZoneConfig struct { immediateMutationOp - DescID descpb.ID + DescID descpb.ID +} + +// DiscardTableZoneConfig discards the zone config for the given table ID. If +// the table has subzones, we mark the table's zone config as a subzone +// placeholder. +type DiscardTableZoneConfig struct { + immediateMutationOp + TableID descpb.ID ZoneConfig *zonepb.ZoneConfig } diff --git a/pkg/sql/schemachanger/scop/immediate_mutation_visitor_generated.go b/pkg/sql/schemachanger/scop/immediate_mutation_visitor_generated.go index 2d1272a899bd..f238371ed885 100644 --- a/pkg/sql/schemachanger/scop/immediate_mutation_visitor_generated.go +++ b/pkg/sql/schemachanger/scop/immediate_mutation_visitor_generated.go @@ -148,6 +148,7 @@ type ImmediateMutationVisitor interface { AddNamedRangeZoneConfig(context.Context, AddNamedRangeZoneConfig) error AddDatabaseZoneConfig(context.Context, AddDatabaseZoneConfig) error DiscardZoneConfig(context.Context, DiscardZoneConfig) error + DiscardTableZoneConfig(context.Context, DiscardTableZoneConfig) error AddTableZoneConfig(context.Context, AddTableZoneConfig) error AddIndexZoneConfig(context.Context, AddIndexZoneConfig) error AddPartitionZoneConfig(context.Context, AddPartitionZoneConfig) error @@ -808,6 +809,11 @@ func (op DiscardZoneConfig) Visit(ctx context.Context, v ImmediateMutationVisito return v.DiscardZoneConfig(ctx, op) } +// Visit is part of the ImmediateMutationOp interface. +func (op DiscardTableZoneConfig) Visit(ctx context.Context, v ImmediateMutationVisitor) error { + return v.DiscardTableZoneConfig(ctx, op) +} + // Visit is part of the ImmediateMutationOp interface. func (op AddTableZoneConfig) Visit(ctx context.Context, v ImmediateMutationVisitor) error { return v.AddTableZoneConfig(ctx, op) diff --git a/pkg/sql/schemachanger/scplan/internal/opgen/op_funcs.go b/pkg/sql/schemachanger/scplan/internal/opgen/op_funcs.go index c461b8121389..b7a40d185774 100644 --- a/pkg/sql/schemachanger/scplan/internal/opgen/op_funcs.go +++ b/pkg/sql/schemachanger/scplan/internal/opgen/op_funcs.go @@ -188,3 +188,16 @@ func checkIfDescriptorIsWithoutData(id descpb.ID, md *opGenContext) bool { } return !doesDescriptorHaveData } + +// checkIfDescriptorHasGCDependents will determine if a descriptor has data +// dependencies it still needs to GC. This allows us to determine when we can +// need to skip certain operations like deleting a zone config. +func checkIfDescriptorHasGCDependents(_ descpb.ID, md *opGenContext) bool { + for _, t := range md.Targets { + switch t.Element().(type) { + case *scpb.IndexData, *scpb.TableData: + return true + } + } + return false +} diff --git a/pkg/sql/schemachanger/scplan/internal/opgen/opgen_database_zone_config.go b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_database_zone_config.go index 4a6cd5ad06bd..d2b7d5d61800 100644 --- a/pkg/sql/schemachanger/scplan/internal/opgen/opgen_database_zone_config.go +++ b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_database_zone_config.go @@ -26,10 +26,15 @@ func init() { toAbsent( scpb.Status_PUBLIC, to(scpb.Status_ABSENT, - emit(func(this *scpb.DatabaseZoneConfig) *scop.DiscardZoneConfig { + emit(func(this *scpb.DatabaseZoneConfig, md *opGenContext) *scop.DiscardZoneConfig { + // If we are dropping a database with table dependencies, let the GC + // job take care of dropping this zone config -- as its table + // dependencies need this zone config. + if checkIfDescriptorHasGCDependents(this.DatabaseID, md) { + return nil + } return &scop.DiscardZoneConfig{ - DescID: this.DatabaseID, - ZoneConfig: this.ZoneConfig, + DescID: this.DatabaseID, } }), ), diff --git a/pkg/sql/schemachanger/scplan/internal/opgen/opgen_table_zone_config.go b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_table_zone_config.go index f2fd5e80805e..a9fd32d50527 100644 --- a/pkg/sql/schemachanger/scplan/internal/opgen/opgen_table_zone_config.go +++ b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_table_zone_config.go @@ -26,9 +26,9 @@ func init() { toAbsent( scpb.Status_PUBLIC, to(scpb.Status_ABSENT, - emit(func(this *scpb.TableZoneConfig) *scop.DiscardZoneConfig { - return &scop.DiscardZoneConfig{ - DescID: this.TableID, + emit(func(this *scpb.TableZoneConfig, md *opGenContext) *scop.DiscardTableZoneConfig { + return &scop.DiscardTableZoneConfig{ + TableID: this.TableID, ZoneConfig: this.ZoneConfig, } }), diff --git a/pkg/sql/schemachanger/sctest_generated_test.go b/pkg/sql/schemachanger/sctest_generated_test.go index 92dfc28797b5..0a508aac9311 100644 --- a/pkg/sql/schemachanger/sctest_generated_test.go +++ b/pkg/sql/schemachanger/sctest_generated_test.go @@ -253,6 +253,13 @@ func TestEndToEndSideEffects_alter_table_configure_zone(t *testing.T) { sctest.EndToEndSideEffects(t, path, sctest.SingleNodeTestClusterFactory{}) } +func TestEndToEndSideEffects_alter_table_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard" + sctest.EndToEndSideEffects(t, path, sctest.SingleNodeTestClusterFactory{}) +} + func TestEndToEndSideEffects_alter_table_configure_zone_multiple(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -806,6 +813,13 @@ func TestExecuteWithDMLInjection_alter_table_configure_zone(t *testing.T) { sctest.ExecuteWithDMLInjection(t, path, sctest.SingleNodeTestClusterFactory{}) } +func TestExecuteWithDMLInjection_alter_table_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard" + sctest.ExecuteWithDMLInjection(t, path, sctest.SingleNodeTestClusterFactory{}) +} + func TestExecuteWithDMLInjection_alter_table_configure_zone_multiple(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -1359,6 +1373,13 @@ func TestGenerateSchemaChangeCorpus_alter_table_configure_zone(t *testing.T) { sctest.GenerateSchemaChangeCorpus(t, path, sctest.SingleNodeTestClusterFactory{}) } +func TestGenerateSchemaChangeCorpus_alter_table_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard" + sctest.GenerateSchemaChangeCorpus(t, path, sctest.SingleNodeTestClusterFactory{}) +} + func TestGenerateSchemaChangeCorpus_alter_table_configure_zone_multiple(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -1912,6 +1933,13 @@ func TestPause_alter_table_configure_zone(t *testing.T) { sctest.Pause(t, path, sctest.SingleNodeTestClusterFactory{}) } +func TestPause_alter_table_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard" + sctest.Pause(t, path, sctest.SingleNodeTestClusterFactory{}) +} + func TestPause_alter_table_configure_zone_multiple(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -2465,6 +2493,13 @@ func TestPauseMixedVersion_alter_table_configure_zone(t *testing.T) { sctest.PauseMixedVersion(t, path, sctest.SingleNodeTestClusterFactory{}) } +func TestPauseMixedVersion_alter_table_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard" + sctest.PauseMixedVersion(t, path, sctest.SingleNodeTestClusterFactory{}) +} + func TestPauseMixedVersion_alter_table_configure_zone_multiple(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -3018,6 +3053,13 @@ func TestRollback_alter_table_configure_zone(t *testing.T) { sctest.Rollback(t, path, sctest.SingleNodeTestClusterFactory{}) } +func TestRollback_alter_table_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard" + sctest.Rollback(t, path, sctest.SingleNodeTestClusterFactory{}) +} + func TestRollback_alter_table_configure_zone_multiple(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard.definition b/pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard.definition index 51e8a2e98bce..032ecd8f6090 100644 --- a/pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard.definition +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard.definition @@ -4,5 +4,6 @@ CREATE DATABASE db; test ALTER DATABASE db CONFIGURE ZONE USING num_replicas = 7, gc.ttlseconds = 10000; +ALTER DATABASE db CONFIGURE ZONE USING num_replicas = 8; ALTER DATABASE db CONFIGURE ZONE DISCARD; ---- diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard.side_effects b/pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard.side_effects index 3625db98357e..4232756c2b05 100644 --- a/pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard.side_effects +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard.side_effects @@ -7,6 +7,7 @@ CREATE DATABASE db; /* test */ ALTER DATABASE db CONFIGURE ZONE USING num_replicas = 7, gc.ttlseconds = 10000; +ALTER DATABASE db CONFIGURE ZONE USING num_replicas = 8; ALTER DATABASE db CONFIGURE ZONE DISCARD; ---- begin transaction #1 @@ -27,6 +28,20 @@ write *eventpb.SetZoneConfig to event log: ## StatementPhase stage 1 of 1 with 1 MutationType op upsert zone config for #104 checking for feature: CONFIGURE ZONE +write *eventpb.SetZoneConfig to event log: + config: + options: + - num_replicas = 8 + target: DATABASE db + resolvedOldConfig: 'gc: num_replicas:7 inherited_constraints:true null_voter_constraints_is_empty:false inherited_lease_preferences:true ' + sql: + descriptorId: 104 + statement: ALTER DATABASE ‹db› CONFIGURE ZONE USING ‹num_replicas› = ‹8› + tag: CONFIGURE ZONE + user: root +## StatementPhase stage 1 of 1 with 1 MutationType op +upsert zone config for #104 +checking for feature: CONFIGURE ZONE write *eventpb.RemoveZoneConfig to event log: config: target: DATABASE db @@ -35,7 +50,7 @@ write *eventpb.RemoveZoneConfig to event log: statement: ALTER DATABASE ‹db› CONFIGURE ZONE DISCARD tag: CONFIGURE ZONE user: root -## StatementPhase stage 1 of 1 with 1 MutationType op +## StatementPhase stage 1 of 1 with 2 MutationType ops deleting zone config for #104 # end StatementPhase # begin PreCommitPhase diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_1_of_2.explain b/pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_1_of_3.explain similarity index 100% rename from pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_1_of_2.explain rename to pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_1_of_3.explain diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_1_of_2.explain_shape b/pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_1_of_3.explain_shape similarity index 100% rename from pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_1_of_2.explain_shape rename to pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_1_of_3.explain_shape diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_2_of_3.explain b/pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_2_of_3.explain new file mode 100644 index 000000000000..0dcf09157958 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_2_of_3.explain @@ -0,0 +1,28 @@ +/* setup */ +CREATE DATABASE db; + +/* test */ +ALTER DATABASE db CONFIGURE ZONE USING num_replicas = 7, gc.ttlseconds = 10000; +EXPLAIN (DDL) ALTER DATABASE db CONFIGURE ZONE USING num_replicas = 8; +---- +Schema change plan for ALTER DATABASE ‹db› CONFIGURE ZONE USING ‹num_replicas› = ‹8›; following ALTER DATABASE ‹db› CONFIGURE ZONE USING ‹num_replicas› = ‹7›, ‹"gc.ttlseconds"› = ‹10000›; + ├── StatementPhase + │ └── Stage 1 of 1 in StatementPhase + │ ├── 1 element transitioning toward PUBLIC + │ │ └── ABSENT → PUBLIC DatabaseZoneConfig:{DescID: 104 (db), SeqNum: 2} + │ └── 1 Mutation operation + │ └── AddDatabaseZoneConfig {"DatabaseID":104} + └── PreCommitPhase + ├── Stage 1 of 2 in PreCommitPhase + │ ├── 2 elements transitioning toward PUBLIC + │ │ ├── PUBLIC → ABSENT DatabaseZoneConfig:{DescID: 104 (db), SeqNum: 1} + │ │ └── PUBLIC → ABSENT DatabaseZoneConfig:{DescID: 104 (db), SeqNum: 2} + │ └── 1 Mutation operation + │ └── UndoAllInTxnImmediateMutationOpSideEffects + └── Stage 2 of 2 in PreCommitPhase + ├── 2 elements transitioning toward PUBLIC + │ ├── ABSENT → PUBLIC DatabaseZoneConfig:{DescID: 104 (db), SeqNum: 1} + │ └── ABSENT → PUBLIC DatabaseZoneConfig:{DescID: 104 (db), SeqNum: 2} + └── 2 Mutation operations + ├── AddDatabaseZoneConfig {"DatabaseID":104} + └── AddDatabaseZoneConfig {"DatabaseID":104} diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_2_of_3.explain_shape b/pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_2_of_3.explain_shape new file mode 100644 index 000000000000..b8c6777406fc --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_2_of_3.explain_shape @@ -0,0 +1,9 @@ +/* setup */ +CREATE DATABASE db; + +/* test */ +ALTER DATABASE db CONFIGURE ZONE USING num_replicas = 7, gc.ttlseconds = 10000; +EXPLAIN (DDL, SHAPE) ALTER DATABASE db CONFIGURE ZONE USING num_replicas = 8; +---- +Schema change plan for ALTER DATABASE ‹db› CONFIGURE ZONE USING ‹num_replicas› = ‹8›; following ALTER DATABASE ‹db› CONFIGURE ZONE USING ‹num_replicas› = ‹7›, ‹"gc.ttlseconds"› = ‹10000›; + └── execute 1 system table mutations transaction diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_2_of_2.explain b/pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_3_of_3.explain similarity index 66% rename from pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_2_of_2.explain rename to pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_3_of_3.explain index 1b098706869f..9bc39d09c1df 100644 --- a/pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_2_of_2.explain +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_3_of_3.explain @@ -3,14 +3,17 @@ CREATE DATABASE db; /* test */ ALTER DATABASE db CONFIGURE ZONE USING num_replicas = 7, gc.ttlseconds = 10000; +ALTER DATABASE db CONFIGURE ZONE USING num_replicas = 8; EXPLAIN (DDL) ALTER DATABASE db CONFIGURE ZONE DISCARD; ---- -Schema change plan for ALTER DATABASE ‹db› CONFIGURE ZONE DISCARD; following ALTER DATABASE ‹db› CONFIGURE ZONE USING ‹num_replicas› = ‹7›, ‹"gc.ttlseconds"› = ‹10000›; +Schema change plan for ALTER DATABASE ‹db› CONFIGURE ZONE DISCARD; following ALTER DATABASE ‹db› CONFIGURE ZONE USING ‹num_replicas› = ‹7›, ‹"gc.ttlseconds"› = ‹10000›; ALTER DATABASE ‹db› CONFIGURE ZONE USING ‹num_replicas› = ‹8›; ├── StatementPhase │ └── Stage 1 of 1 in StatementPhase - │ ├── 1 element transitioning toward ABSENT - │ │ └── PUBLIC → ABSENT DatabaseZoneConfig:{DescID: 104 (db), SeqNum: 1} - │ └── 1 Mutation operation + │ ├── 2 elements transitioning toward ABSENT + │ │ ├── PUBLIC → ABSENT DatabaseZoneConfig:{DescID: 104 (db), SeqNum: 1} + │ │ └── PUBLIC → ABSENT DatabaseZoneConfig:{DescID: 104 (db), SeqNum: 2} + │ └── 2 Mutation operations + │ ├── DiscardZoneConfig {"DescID":104} │ └── DiscardZoneConfig {"DescID":104} └── PreCommitPhase └── Stage 1 of 1 in PreCommitPhase diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_2_of_2.explain_shape b/pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_3_of_3.explain_shape similarity index 76% rename from pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_2_of_2.explain_shape rename to pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_3_of_3.explain_shape index c3278d1288d1..15bbfcb3c6d8 100644 --- a/pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_2_of_2.explain_shape +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_database_configure_zone_discard/alter_database_configure_zone_discard__statement_3_of_3.explain_shape @@ -3,7 +3,8 @@ CREATE DATABASE db; /* test */ ALTER DATABASE db CONFIGURE ZONE USING num_replicas = 7, gc.ttlseconds = 10000; +ALTER DATABASE db CONFIGURE ZONE USING num_replicas = 8; EXPLAIN (DDL, SHAPE) ALTER DATABASE db CONFIGURE ZONE DISCARD; ---- -Schema change plan for ALTER DATABASE ‹db› CONFIGURE ZONE DISCARD; following ALTER DATABASE ‹db› CONFIGURE ZONE USING ‹num_replicas› = ‹7›, ‹"gc.ttlseconds"› = ‹10000›; +Schema change plan for ALTER DATABASE ‹db› CONFIGURE ZONE DISCARD; following ALTER DATABASE ‹db› CONFIGURE ZONE USING ‹num_replicas› = ‹7›, ‹"gc.ttlseconds"› = ‹10000›; ALTER DATABASE ‹db› CONFIGURE ZONE USING ‹num_replicas› = ‹8›; └── execute 1 system table mutations transaction diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard.definition b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard.definition new file mode 100644 index 000000000000..bfe3cf7a693a --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard.definition @@ -0,0 +1,9 @@ +setup +CREATE TABLE t(i int); +---- + +test +ALTER TABLE t CONFIGURE ZONE USING num_replicas = 7, gc.ttlseconds = 10000; +ALTER TABLE t CONFIGURE ZONE USING num_replicas = 8; +ALTER TABLE t CONFIGURE ZONE DISCARD; +---- diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard.side_effects b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard.side_effects new file mode 100644 index 000000000000..725539477fd1 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard.side_effects @@ -0,0 +1,60 @@ +/* setup */ +CREATE TABLE t(i int); +---- +... ++object {100 101 t} -> 104 + +/* test */ +ALTER TABLE t CONFIGURE ZONE USING num_replicas = 7, gc.ttlseconds = 10000; +ALTER TABLE t CONFIGURE ZONE USING num_replicas = 8; +ALTER TABLE t CONFIGURE ZONE DISCARD; +---- +begin transaction #1 +# begin StatementPhase +checking for feature: CONFIGURE ZONE +write *eventpb.SetZoneConfig to event log: + config: + options: + - '"gc.ttlseconds" = 10000' + - num_replicas = 7 + target: TABLE defaultdb.public.t + resolvedOldConfig: 'range_min_bytes:134217728 range_max_bytes:536870912 gc: num_replicas:5 inherited_constraints:false null_voter_constraints_is_empty:true inherited_lease_preferences:false ' + sql: + descriptorId: 104 + statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› CONFIGURE ZONE USING ‹num_replicas› = ‹7›, ‹"gc.ttlseconds"› = ‹10000› + tag: CONFIGURE ZONE + user: root +## StatementPhase stage 1 of 1 with 1 MutationType op +upsert zone config for #104 +checking for feature: CONFIGURE ZONE +write *eventpb.SetZoneConfig to event log: + config: + options: + - num_replicas = 8 + target: TABLE defaultdb.public.t + resolvedOldConfig: 'range_min_bytes:134217728 range_max_bytes:536870912 gc: num_replicas:5 inherited_constraints:false null_voter_constraints_is_empty:true inherited_lease_preferences:false ' + sql: + descriptorId: 104 + statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› CONFIGURE ZONE USING ‹num_replicas› = ‹8› + tag: CONFIGURE ZONE + user: root +## StatementPhase stage 1 of 1 with 1 MutationType op +upsert zone config for #104 +checking for feature: CONFIGURE ZONE +write *eventpb.RemoveZoneConfig to event log: + config: + target: TABLE defaultdb.public.t + sql: + descriptorId: 104 + statement: ALTER TABLE ‹defaultdb›.‹public›.‹t› CONFIGURE ZONE DISCARD + tag: CONFIGURE ZONE + user: root +## StatementPhase stage 1 of 1 with 2 MutationType ops +deleting zone config for #104 +# end StatementPhase +# begin PreCommitPhase +## PreCommitPhase stage 1 of 1 with 1 MutationType op +undo all catalog changes within txn #1 +persist all catalog changes to storage +# end PreCommitPhase +commit transaction #1 diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard__statement_1_of_3.explain b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard__statement_1_of_3.explain new file mode 100644 index 000000000000..bea03c14ef93 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard__statement_1_of_3.explain @@ -0,0 +1,24 @@ +/* setup */ +CREATE TABLE t(i int); + +/* test */ +EXPLAIN (DDL) ALTER TABLE t CONFIGURE ZONE USING num_replicas = 7, gc.ttlseconds = 10000; +---- +Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› CONFIGURE ZONE USING ‹num_replicas› = ‹7›, ‹"gc.ttlseconds"› = ‹10000›; + ├── StatementPhase + │ └── Stage 1 of 1 in StatementPhase + │ ├── 1 element transitioning toward PUBLIC + │ │ └── ABSENT → PUBLIC TableZoneConfig:{DescID: 104 (t), SeqNum: 1} + │ └── 1 Mutation operation + │ └── AddTableZoneConfig {"TableID":104} + └── PreCommitPhase + ├── Stage 1 of 2 in PreCommitPhase + │ ├── 1 element transitioning toward PUBLIC + │ │ └── PUBLIC → ABSENT TableZoneConfig:{DescID: 104 (t), SeqNum: 1} + │ └── 1 Mutation operation + │ └── UndoAllInTxnImmediateMutationOpSideEffects + └── Stage 2 of 2 in PreCommitPhase + ├── 1 element transitioning toward PUBLIC + │ └── ABSENT → PUBLIC TableZoneConfig:{DescID: 104 (t), SeqNum: 1} + └── 1 Mutation operation + └── AddTableZoneConfig {"TableID":104} diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard__statement_1_of_3.explain_shape b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard__statement_1_of_3.explain_shape new file mode 100644 index 000000000000..ab16093d7d00 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard__statement_1_of_3.explain_shape @@ -0,0 +1,8 @@ +/* setup */ +CREATE TABLE t(i int); + +/* test */ +EXPLAIN (DDL, SHAPE) ALTER TABLE t CONFIGURE ZONE USING num_replicas = 7, gc.ttlseconds = 10000; +---- +Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› CONFIGURE ZONE USING ‹num_replicas› = ‹7›, ‹"gc.ttlseconds"› = ‹10000›; + └── execute 1 system table mutations transaction diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard__statement_2_of_3.explain b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard__statement_2_of_3.explain new file mode 100644 index 000000000000..9e5216b87ba5 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard__statement_2_of_3.explain @@ -0,0 +1,28 @@ +/* setup */ +CREATE TABLE t(i int); + +/* test */ +ALTER TABLE t CONFIGURE ZONE USING num_replicas = 7, gc.ttlseconds = 10000; +EXPLAIN (DDL) ALTER TABLE t CONFIGURE ZONE USING num_replicas = 8; +---- +Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› CONFIGURE ZONE USING ‹num_replicas› = ‹8›; following ALTER TABLE ‹defaultdb›.‹public›.‹t› CONFIGURE ZONE USING ‹num_replicas› = ‹7›, ‹"gc.ttlseconds"› = ‹10000›; + ├── StatementPhase + │ └── Stage 1 of 1 in StatementPhase + │ ├── 1 element transitioning toward PUBLIC + │ │ └── ABSENT → PUBLIC TableZoneConfig:{DescID: 104 (t), SeqNum: 2} + │ └── 1 Mutation operation + │ └── AddTableZoneConfig {"TableID":104} + └── PreCommitPhase + ├── Stage 1 of 2 in PreCommitPhase + │ ├── 2 elements transitioning toward PUBLIC + │ │ ├── PUBLIC → ABSENT TableZoneConfig:{DescID: 104 (t), SeqNum: 1} + │ │ └── PUBLIC → ABSENT TableZoneConfig:{DescID: 104 (t), SeqNum: 2} + │ └── 1 Mutation operation + │ └── UndoAllInTxnImmediateMutationOpSideEffects + └── Stage 2 of 2 in PreCommitPhase + ├── 2 elements transitioning toward PUBLIC + │ ├── ABSENT → PUBLIC TableZoneConfig:{DescID: 104 (t), SeqNum: 1} + │ └── ABSENT → PUBLIC TableZoneConfig:{DescID: 104 (t), SeqNum: 2} + └── 2 Mutation operations + ├── AddTableZoneConfig {"TableID":104} + └── AddTableZoneConfig {"TableID":104} diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard__statement_2_of_3.explain_shape b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard__statement_2_of_3.explain_shape new file mode 100644 index 000000000000..246f82a23535 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard__statement_2_of_3.explain_shape @@ -0,0 +1,9 @@ +/* setup */ +CREATE TABLE t(i int); + +/* test */ +ALTER TABLE t CONFIGURE ZONE USING num_replicas = 7, gc.ttlseconds = 10000; +EXPLAIN (DDL, SHAPE) ALTER TABLE t CONFIGURE ZONE USING num_replicas = 8; +---- +Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› CONFIGURE ZONE USING ‹num_replicas› = ‹8›; following ALTER TABLE ‹defaultdb›.‹public›.‹t› CONFIGURE ZONE USING ‹num_replicas› = ‹7›, ‹"gc.ttlseconds"› = ‹10000›; + └── execute 1 system table mutations transaction diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard__statement_3_of_3.explain b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard__statement_3_of_3.explain new file mode 100644 index 000000000000..5acae968c2e8 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard__statement_3_of_3.explain @@ -0,0 +1,21 @@ +/* setup */ +CREATE TABLE t(i int); + +/* test */ +ALTER TABLE t CONFIGURE ZONE USING num_replicas = 7, gc.ttlseconds = 10000; +ALTER TABLE t CONFIGURE ZONE USING num_replicas = 8; +EXPLAIN (DDL) ALTER TABLE t CONFIGURE ZONE DISCARD; +---- +Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› CONFIGURE ZONE DISCARD; following ALTER TABLE ‹defaultdb›.‹public›.‹t› CONFIGURE ZONE USING ‹num_replicas› = ‹7›, ‹"gc.ttlseconds"› = ‹10000›; ALTER TABLE ‹defaultdb›.‹public›.‹t› CONFIGURE ZONE USING ‹num_replicas› = ‹8›; + ├── StatementPhase + │ └── Stage 1 of 1 in StatementPhase + │ ├── 2 elements transitioning toward ABSENT + │ │ ├── PUBLIC → ABSENT TableZoneConfig:{DescID: 104 (t), SeqNum: 1} + │ │ └── PUBLIC → ABSENT TableZoneConfig:{DescID: 104 (t), SeqNum: 2} + │ └── 2 Mutation operations + │ ├── DiscardTableZoneConfig {"TableID":104} + │ └── DiscardTableZoneConfig {"TableID":104} + └── PreCommitPhase + └── Stage 1 of 1 in PreCommitPhase + └── 1 Mutation operation + └── UndoAllInTxnImmediateMutationOpSideEffects diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard__statement_3_of_3.explain_shape b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard__statement_3_of_3.explain_shape new file mode 100644 index 000000000000..f2a9f9fb528a --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_table_configure_zone_discard/alter_table_configure_zone_discard__statement_3_of_3.explain_shape @@ -0,0 +1,10 @@ +/* setup */ +CREATE TABLE t(i int); + +/* test */ +ALTER TABLE t CONFIGURE ZONE USING num_replicas = 7, gc.ttlseconds = 10000; +ALTER TABLE t CONFIGURE ZONE USING num_replicas = 8; +EXPLAIN (DDL, SHAPE) ALTER TABLE t CONFIGURE ZONE DISCARD; +---- +Schema change plan for ALTER TABLE ‹defaultdb›.‹public›.‹t› CONFIGURE ZONE DISCARD; following ALTER TABLE ‹defaultdb›.‹public›.‹t› CONFIGURE ZONE USING ‹num_replicas› = ‹7›, ‹"gc.ttlseconds"› = ‹10000›; ALTER TABLE ‹defaultdb›.‹public›.‹t› CONFIGURE ZONE USING ‹num_replicas› = ‹8›; + └── execute 1 system table mutations transaction From bd1cf6df1d46805e2834d96bcbf43b8de3192c32 Mon Sep 17 00:00:00 2001 From: Annie Pompa Date: Thu, 24 Oct 2024 11:32:43 -0400 Subject: [PATCH 2/2] schemachanger: add support for discarding subzones This patch adds support for discarding a subzone config in the DSC. Fixes: #133158 Epic: none Release note: None --- .../backup_base_generated_test.go | 28 ++++++ .../schemachangerccl/ccl_generated_test.go | 70 ++++++++++++++ .../testdata/decomp/multiregion | 3 + .../alter_index_configure_zone.explain | 4 +- ...re_zone_multiple__statement_1_of_3.explain | 4 +- ...re_zone_multiple__statement_2_of_3.explain | 6 +- ...re_zone_multiple__statement_3_of_3.explain | 8 +- .../alter_partition_configure_zone.explain | 4 +- ...artition_configure_zone_discard.definition | 16 ++++ ...tition_configure_zone_discard.side_effects | 82 ++++++++++++++++ ...ure_zone_discard__statement_1_of_4.explain | 30 ++++++ ...ne_discard__statement_1_of_4.explain_shape | 14 +++ ...ure_zone_discard__statement_2_of_4.explain | 34 +++++++ ...ne_discard__statement_2_of_4.explain_shape | 15 +++ ...ure_zone_discard__statement_3_of_4.explain | 38 ++++++++ ...ne_discard__statement_3_of_4.explain_shape | 16 ++++ ...ure_zone_discard__statement_4_of_4.explain | 35 +++++++ ...ne_discard__statement_4_of_4.explain_shape | 17 ++++ ...re_zone_multiple__statement_1_of_4.explain | 4 +- ...re_zone_multiple__statement_2_of_4.explain | 6 +- ...re_zone_multiple__statement_3_of_4.explain | 8 +- ...re_zone_multiple__statement_4_of_4.explain | 10 +- ...ne_subpartitions__statement_1_of_4.explain | 4 +- ...ne_subpartitions__statement_2_of_4.explain | 6 +- ...ne_subpartitions__statement_3_of_4.explain | 8 +- ...ne_subpartitions__statement_4_of_4.explain | 10 +- pkg/config/zonepb/zone.go | 6 +- .../internal/scbuildstmt/configure_zone.go | 7 -- .../scbuildstmt/database_zone_config.go | 5 +- .../internal/scbuildstmt/index_zone_config.go | 91 +++++++++++++++++- .../scbuildstmt/named_range_zone_config.go | 4 + .../scbuildstmt/partition_zone_config.go | 94 ++++++++++++++++++- .../internal/scbuildstmt/table_zone_config.go | 5 +- .../scbuildstmt/zone_config_helpers.go | 40 ++++++-- pkg/sql/schemachanger/scdecomp/decomp.go | 7 +- pkg/sql/schemachanger/scdeps/exec_deps.go | 44 ++++++++- .../scdeps/sctestdeps/test_deps.go | 34 ++++++- pkg/sql/schemachanger/scexec/dependencies.go | 10 ++ .../scexec/exec_immediate_mutation.go | 92 ++++++++++++------ .../scexec/mocks_generated_test.go | 22 ++++- .../scexec/scmutationexec/dependencies.go | 10 +- .../scexec/scmutationexec/index.go | 6 +- .../scexec/scmutationexec/zone_config.go | 7 ++ .../schemachanger/scop/immediate_mutation.go | 25 +++-- .../immediate_mutation_visitor_generated.go | 6 ++ pkg/sql/schemachanger/scpb/elements.proto | 2 + pkg/sql/schemachanger/scpb/uml/table.puml | 2 + .../internal/opgen/opgen_index_zone_config.go | 15 ++- .../opgen/opgen_partition_zone_config.go | 15 ++- .../schemachanger/sctest_generated_test.go | 42 +++++++++ ...er_index_configure_zone_discard.definition | 14 +++ ..._index_configure_zone_discard.side_effects | 80 ++++++++++++++++ ...ure_zone_discard__statement_1_of_4.explain | 28 ++++++ ...ne_discard__statement_1_of_4.explain_shape | 12 +++ ...ure_zone_discard__statement_2_of_4.explain | 32 +++++++ ...ne_discard__statement_2_of_4.explain_shape | 13 +++ ...ure_zone_discard__statement_3_of_4.explain | 36 +++++++ ...ne_discard__statement_3_of_4.explain_shape | 14 +++ ...ure_zone_discard__statement_4_of_4.explain | 33 +++++++ ...ne_discard__statement_4_of_4.explain_shape | 15 +++ 60 files changed, 1209 insertions(+), 139 deletions(-) create mode 100644 pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard.definition create mode 100644 pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard.side_effects create mode 100644 pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_1_of_4.explain create mode 100644 pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_1_of_4.explain_shape create mode 100644 pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_2_of_4.explain create mode 100644 pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_2_of_4.explain_shape create mode 100644 pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_3_of_4.explain create mode 100644 pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_3_of_4.explain_shape create mode 100644 pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_4_of_4.explain create mode 100644 pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_4_of_4.explain_shape create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard.definition create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard.side_effects create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_1_of_4.explain create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_1_of_4.explain_shape create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_2_of_4.explain create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_2_of_4.explain_shape create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_3_of_4.explain create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_3_of_4.explain_shape create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_4_of_4.explain create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_4_of_4.explain_shape diff --git a/pkg/ccl/schemachangerccl/backup_base_generated_test.go b/pkg/ccl/schemachangerccl/backup_base_generated_test.go index dce4fa2c9803..d33b7a13ece8 100644 --- a/pkg/ccl/schemachangerccl/backup_base_generated_test.go +++ b/pkg/ccl/schemachangerccl/backup_base_generated_test.go @@ -99,6 +99,13 @@ func TestBackupRollbacks_base_alter_database_configure_zone_multiple(t *testing. sctest.BackupRollbacks(t, path, sctest.SingleNodeTestClusterFactory{}) } +func TestBackupRollbacks_base_alter_index_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard" + sctest.BackupRollbacks(t, path, sctest.SingleNodeTestClusterFactory{}) +} + func TestBackupRollbacks_base_alter_named_range_configure_zone(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -659,6 +666,13 @@ func TestBackupRollbacksMixedVersion_base_alter_database_configure_zone_multiple sctest.BackupRollbacksMixedVersion(t, path, sctest.SingleNodeTestClusterFactory{}) } +func TestBackupRollbacksMixedVersion_base_alter_index_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard" + sctest.BackupRollbacksMixedVersion(t, path, sctest.SingleNodeTestClusterFactory{}) +} + func TestBackupRollbacksMixedVersion_base_alter_named_range_configure_zone(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -1219,6 +1233,13 @@ func TestBackupSuccess_base_alter_database_configure_zone_multiple(t *testing.T) sctest.BackupSuccess(t, path, sctest.SingleNodeTestClusterFactory{}) } +func TestBackupSuccess_base_alter_index_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard" + sctest.BackupSuccess(t, path, sctest.SingleNodeTestClusterFactory{}) +} + func TestBackupSuccess_base_alter_named_range_configure_zone(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -1779,6 +1800,13 @@ func TestBackupSuccessMixedVersion_base_alter_database_configure_zone_multiple(t sctest.BackupSuccessMixedVersion(t, path, sctest.SingleNodeTestClusterFactory{}) } +func TestBackupSuccessMixedVersion_base_alter_index_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard" + sctest.BackupSuccessMixedVersion(t, path, sctest.SingleNodeTestClusterFactory{}) +} + func TestBackupSuccessMixedVersion_base_alter_named_range_configure_zone(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) diff --git a/pkg/ccl/schemachangerccl/ccl_generated_test.go b/pkg/ccl/schemachangerccl/ccl_generated_test.go index 2d765137ba24..d868a02d01b4 100644 --- a/pkg/ccl/schemachangerccl/ccl_generated_test.go +++ b/pkg/ccl/schemachangerccl/ccl_generated_test.go @@ -36,6 +36,13 @@ func TestBackupRollbacks_ccl_alter_partition_configure_zone(t *testing.T) { sctest.BackupRollbacks(t, path, MultiRegionTestClusterFactory{}) } +func TestBackupRollbacks_ccl_alter_partition_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard" + sctest.BackupRollbacks(t, path, MultiRegionTestClusterFactory{}) +} + func TestBackupRollbacks_ccl_alter_partition_configure_zone_multiple(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -120,6 +127,13 @@ func TestBackupRollbacksMixedVersion_ccl_alter_partition_configure_zone(t *testi sctest.BackupRollbacksMixedVersion(t, path, MultiRegionTestClusterFactory{}) } +func TestBackupRollbacksMixedVersion_ccl_alter_partition_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard" + sctest.BackupRollbacksMixedVersion(t, path, MultiRegionTestClusterFactory{}) +} + func TestBackupRollbacksMixedVersion_ccl_alter_partition_configure_zone_multiple(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -204,6 +218,13 @@ func TestBackupSuccess_ccl_alter_partition_configure_zone(t *testing.T) { sctest.BackupSuccess(t, path, MultiRegionTestClusterFactory{}) } +func TestBackupSuccess_ccl_alter_partition_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard" + sctest.BackupSuccess(t, path, MultiRegionTestClusterFactory{}) +} + func TestBackupSuccess_ccl_alter_partition_configure_zone_multiple(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -288,6 +309,13 @@ func TestBackupSuccessMixedVersion_ccl_alter_partition_configure_zone(t *testing sctest.BackupSuccessMixedVersion(t, path, MultiRegionTestClusterFactory{}) } +func TestBackupSuccessMixedVersion_ccl_alter_partition_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard" + sctest.BackupSuccessMixedVersion(t, path, MultiRegionTestClusterFactory{}) +} + func TestBackupSuccessMixedVersion_ccl_alter_partition_configure_zone_multiple(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -372,6 +400,13 @@ func TestEndToEndSideEffects_ccl_alter_partition_configure_zone(t *testing.T) { sctest.EndToEndSideEffects(t, path, MultiRegionTestClusterFactory{}) } +func TestEndToEndSideEffects_ccl_alter_partition_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard" + sctest.EndToEndSideEffects(t, path, MultiRegionTestClusterFactory{}) +} + func TestEndToEndSideEffects_ccl_alter_partition_configure_zone_multiple(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -456,6 +491,13 @@ func TestExecuteWithDMLInjection_ccl_alter_partition_configure_zone(t *testing.T sctest.ExecuteWithDMLInjection(t, path, MultiRegionTestClusterFactory{}) } +func TestExecuteWithDMLInjection_ccl_alter_partition_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard" + sctest.ExecuteWithDMLInjection(t, path, MultiRegionTestClusterFactory{}) +} + func TestExecuteWithDMLInjection_ccl_alter_partition_configure_zone_multiple(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -540,6 +582,13 @@ func TestGenerateSchemaChangeCorpus_ccl_alter_partition_configure_zone(t *testin sctest.GenerateSchemaChangeCorpus(t, path, MultiRegionTestClusterFactory{}) } +func TestGenerateSchemaChangeCorpus_ccl_alter_partition_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard" + sctest.GenerateSchemaChangeCorpus(t, path, MultiRegionTestClusterFactory{}) +} + func TestGenerateSchemaChangeCorpus_ccl_alter_partition_configure_zone_multiple(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -624,6 +673,13 @@ func TestPause_ccl_alter_partition_configure_zone(t *testing.T) { sctest.Pause(t, path, MultiRegionTestClusterFactory{}) } +func TestPause_ccl_alter_partition_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard" + sctest.Pause(t, path, MultiRegionTestClusterFactory{}) +} + func TestPause_ccl_alter_partition_configure_zone_multiple(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -708,6 +764,13 @@ func TestPauseMixedVersion_ccl_alter_partition_configure_zone(t *testing.T) { sctest.PauseMixedVersion(t, path, MultiRegionTestClusterFactory{}) } +func TestPauseMixedVersion_ccl_alter_partition_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard" + sctest.PauseMixedVersion(t, path, MultiRegionTestClusterFactory{}) +} + func TestPauseMixedVersion_ccl_alter_partition_configure_zone_multiple(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -792,6 +855,13 @@ func TestRollback_ccl_alter_partition_configure_zone(t *testing.T) { sctest.Rollback(t, path, MultiRegionTestClusterFactory{}) } +func TestRollback_ccl_alter_partition_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard" + sctest.Rollback(t, path, MultiRegionTestClusterFactory{}) +} + func TestRollback_ccl_alter_partition_configure_zone_multiple(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) diff --git a/pkg/ccl/schemachangerccl/testdata/decomp/multiregion b/pkg/ccl/schemachangerccl/testdata/decomp/multiregion index db268ec72ea1..200fd401ac90 100644 --- a/pkg/ccl/schemachangerccl/testdata/decomp/multiregion +++ b/pkg/ccl/schemachangerccl/testdata/decomp/multiregion @@ -1355,6 +1355,7 @@ ElementState: Status: PUBLIC - PartitionZoneConfig: indexId: 1 + oldIdxRef: -1 partitionName: us-east1 seqNum: 0 subzone: @@ -1392,6 +1393,7 @@ ElementState: Status: PUBLIC - PartitionZoneConfig: indexId: 1 + oldIdxRef: -1 partitionName: us-east2 seqNum: 0 subzone: @@ -1429,6 +1431,7 @@ ElementState: Status: PUBLIC - PartitionZoneConfig: indexId: 1 + oldIdxRef: -1 partitionName: us-east3 seqNum: 0 subzone: diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_index_configure_zone/alter_index_configure_zone.explain b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_index_configure_zone/alter_index_configure_zone.explain index 9b5959d75289..4ba92a6f4f4a 100644 --- a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_index_configure_zone/alter_index_configure_zone.explain +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_index_configure_zone/alter_index_configure_zone.explain @@ -11,7 +11,7 @@ Schema change plan for ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹foo │ ├── 1 element transitioning toward PUBLIC │ │ └── ABSENT → PUBLIC IndexZoneConfig:{DescID: 104 (t), IndexID: 2 (foo), SeqNum: 1} │ └── 1 Mutation operation - │ └── AddIndexZoneConfig {"TableID":104} + │ └── AddIndexZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} └── PreCommitPhase ├── Stage 1 of 2 in PreCommitPhase │ ├── 1 element transitioning toward PUBLIC @@ -22,4 +22,4 @@ Schema change plan for ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹foo ├── 1 element transitioning toward PUBLIC │ └── ABSENT → PUBLIC IndexZoneConfig:{DescID: 104 (t), IndexID: 2 (foo), SeqNum: 1} └── 1 Mutation operation - └── AddIndexZoneConfig {"TableID":104} + └── AddIndexZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_index_configure_zone_multiple/alter_index_configure_zone_multiple__statement_1_of_3.explain b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_index_configure_zone_multiple/alter_index_configure_zone_multiple__statement_1_of_3.explain index 6622d909fab2..02e76e698ebc 100644 --- a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_index_configure_zone_multiple/alter_index_configure_zone_multiple__statement_1_of_3.explain +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_index_configure_zone_multiple/alter_index_configure_zone_multiple__statement_1_of_3.explain @@ -11,7 +11,7 @@ Schema change plan for ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹foo │ ├── 1 element transitioning toward PUBLIC │ │ └── ABSENT → PUBLIC IndexZoneConfig:{DescID: 104 (t), IndexID: 2 (foo), SeqNum: 1} │ └── 1 Mutation operation - │ └── AddIndexZoneConfig {"TableID":104} + │ └── AddIndexZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} └── PreCommitPhase ├── Stage 1 of 2 in PreCommitPhase │ ├── 1 element transitioning toward PUBLIC @@ -22,4 +22,4 @@ Schema change plan for ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹foo ├── 1 element transitioning toward PUBLIC │ └── ABSENT → PUBLIC IndexZoneConfig:{DescID: 104 (t), IndexID: 2 (foo), SeqNum: 1} └── 1 Mutation operation - └── AddIndexZoneConfig {"TableID":104} + └── AddIndexZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_index_configure_zone_multiple/alter_index_configure_zone_multiple__statement_2_of_3.explain b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_index_configure_zone_multiple/alter_index_configure_zone_multiple__statement_2_of_3.explain index 55a38a0a8409..4a348e79ce51 100644 --- a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_index_configure_zone_multiple/alter_index_configure_zone_multiple__statement_2_of_3.explain +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_index_configure_zone_multiple/alter_index_configure_zone_multiple__statement_2_of_3.explain @@ -12,7 +12,7 @@ Schema change plan for ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹foo │ ├── 1 element transitioning toward PUBLIC │ │ └── ABSENT → PUBLIC IndexZoneConfig:{DescID: 104 (t), IndexID: 2 (foo), SeqNum: 2} │ └── 1 Mutation operation - │ └── AddIndexZoneConfig {"TableID":104} + │ └── AddIndexZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} └── PreCommitPhase ├── Stage 1 of 2 in PreCommitPhase │ ├── 2 elements transitioning toward PUBLIC @@ -25,5 +25,5 @@ Schema change plan for ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹foo │ ├── ABSENT → PUBLIC IndexZoneConfig:{DescID: 104 (t), IndexID: 2 (foo), SeqNum: 1} │ └── ABSENT → PUBLIC IndexZoneConfig:{DescID: 104 (t), IndexID: 2 (foo), SeqNum: 2} └── 2 Mutation operations - ├── AddIndexZoneConfig {"TableID":104} - └── AddIndexZoneConfig {"TableID":104} + ├── AddIndexZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + └── AddIndexZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_index_configure_zone_multiple/alter_index_configure_zone_multiple__statement_3_of_3.explain b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_index_configure_zone_multiple/alter_index_configure_zone_multiple__statement_3_of_3.explain index 5aabaff16e48..ae60174e8c91 100644 --- a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_index_configure_zone_multiple/alter_index_configure_zone_multiple__statement_3_of_3.explain +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_index_configure_zone_multiple/alter_index_configure_zone_multiple__statement_3_of_3.explain @@ -13,7 +13,7 @@ Schema change plan for ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹foo │ ├── 1 element transitioning toward PUBLIC │ │ └── ABSENT → PUBLIC IndexZoneConfig:{DescID: 104 (t), IndexID: 2 (foo), SeqNum: 3} │ └── 1 Mutation operation - │ └── AddIndexZoneConfig {"TableID":104} + │ └── AddIndexZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} └── PreCommitPhase ├── Stage 1 of 2 in PreCommitPhase │ ├── 3 elements transitioning toward PUBLIC @@ -28,6 +28,6 @@ Schema change plan for ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹foo │ ├── ABSENT → PUBLIC IndexZoneConfig:{DescID: 104 (t), IndexID: 2 (foo), SeqNum: 2} │ └── ABSENT → PUBLIC IndexZoneConfig:{DescID: 104 (t), IndexID: 2 (foo), SeqNum: 3} └── 3 Mutation operations - ├── AddIndexZoneConfig {"TableID":104} - ├── AddIndexZoneConfig {"TableID":104} - └── AddIndexZoneConfig {"TableID":104} + ├── AddIndexZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + ├── AddIndexZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + └── AddIndexZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone/alter_partition_configure_zone.explain b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone/alter_partition_configure_zone.explain index 9778e34fcc81..35ceafbb2f94 100644 --- a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone/alter_partition_configure_zone.explain +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone/alter_partition_configure_zone.explain @@ -16,7 +16,7 @@ Schema change plan for ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹publ │ ├── 1 element transitioning toward PUBLIC │ │ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1, PartitionName: "p1"} │ └── 1 Mutation operation - │ └── AddPartitionZoneConfig {"TableID":104} + │ └── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} └── PreCommitPhase ├── Stage 1 of 2 in PreCommitPhase │ ├── 1 element transitioning toward PUBLIC @@ -27,4 +27,4 @@ Schema change plan for ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹publ ├── 1 element transitioning toward PUBLIC │ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1, PartitionName: "p1"} └── 1 Mutation operation - └── AddPartitionZoneConfig {"TableID":104} + └── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard.definition b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard.definition new file mode 100644 index 000000000000..74882cee19cb --- /dev/null +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard.definition @@ -0,0 +1,16 @@ +setup +CREATE TABLE t ( + id INT PRIMARY KEY, + data STRING +) PARTITION BY LIST (id) ( + PARTITION p1 VALUES IN (1, 2, 3), + PARTITION p2 VALUES IN (4, 5, 6) +); +---- + +test +ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 11; +ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 12; +ALTER PARTITION p2 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 10; +ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE DISCARD; +---- diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard.side_effects b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard.side_effects new file mode 100644 index 000000000000..e22c448bbde5 --- /dev/null +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard.side_effects @@ -0,0 +1,82 @@ +/* setup */ +CREATE TABLE t ( + id INT PRIMARY KEY, + data STRING +) PARTITION BY LIST (id) ( + PARTITION p1 VALUES IN (1, 2, 3), + PARTITION p2 VALUES IN (4, 5, 6) +); +---- +... ++object {100 101 t} -> 104 + +/* test */ +ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 11; +ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 12; +ALTER PARTITION p2 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 10; +ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE DISCARD; +---- +begin transaction #1 +# begin StatementPhase +checking for feature: CONFIGURE ZONE +write *eventpb.SetZoneConfig to event log: + config: + options: + - num_replicas = 11 + target: PARTITION p1 OF INDEX defaultdb.public.t@t_pkey + resolvedOldConfig: 'inherited_constraints:false null_voter_constraints_is_empty:false inherited_lease_preferences:false ' + sql: + descriptorId: 104 + statement: ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹11› + tag: CONFIGURE ZONE + user: root +## StatementPhase stage 1 of 1 with 1 MutationType op +upsert zone config for #104 +checking for feature: CONFIGURE ZONE +write *eventpb.SetZoneConfig to event log: + config: + options: + - num_replicas = 12 + target: PARTITION p1 OF INDEX defaultdb.public.t@t_pkey + resolvedOldConfig: 'inherited_constraints:false null_voter_constraints_is_empty:false inherited_lease_preferences:false ' + sql: + descriptorId: 104 + statement: ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹12› + tag: CONFIGURE ZONE + user: root +## StatementPhase stage 1 of 1 with 1 MutationType op +upsert zone config for #104 +checking for feature: CONFIGURE ZONE +write *eventpb.SetZoneConfig to event log: + config: + options: + - num_replicas = 10 + target: PARTITION p2 OF INDEX defaultdb.public.t@t_pkey + resolvedOldConfig: 'inherited_constraints:false null_voter_constraints_is_empty:false inherited_lease_preferences:false ' + sql: + descriptorId: 104 + statement: ALTER PARTITION ‹p2› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹10› + tag: CONFIGURE ZONE + user: root +## StatementPhase stage 1 of 1 with 1 MutationType op +upsert zone config for #104 +checking for feature: CONFIGURE ZONE +write *eventpb.RemoveZoneConfig to event log: + config: + target: PARTITION p1 OF INDEX defaultdb.public.t@t_pkey + sql: + descriptorId: 104 + statement: ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE DISCARD + tag: CONFIGURE ZONE + user: root +## StatementPhase stage 1 of 1 with 2 MutationType ops +# end StatementPhase +# begin PreCommitPhase +## 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 1 MutationType op +upsert zone config for #104 +persist all catalog changes to storage +# end PreCommitPhase +commit transaction #1 diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_1_of_4.explain b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_1_of_4.explain new file mode 100644 index 000000000000..a290057827ff --- /dev/null +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_1_of_4.explain @@ -0,0 +1,30 @@ +/* setup */ +CREATE TABLE t ( + id INT PRIMARY KEY, + data STRING +) PARTITION BY LIST (id) ( + PARTITION p1 VALUES IN (1, 2, 3), + PARTITION p2 VALUES IN (4, 5, 6) +); + +/* test */ +EXPLAIN (DDL) ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 11; +---- +Schema change plan for ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹11›; + ├── StatementPhase + │ └── Stage 1 of 1 in StatementPhase + │ ├── 1 element transitioning toward PUBLIC + │ │ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1, PartitionName: "p1"} + │ └── 1 Mutation operation + │ └── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + └── PreCommitPhase + ├── Stage 1 of 2 in PreCommitPhase + │ ├── 1 element transitioning toward PUBLIC + │ │ └── PUBLIC → ABSENT PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1, PartitionName: "p1"} + │ └── 1 Mutation operation + │ └── UndoAllInTxnImmediateMutationOpSideEffects + └── Stage 2 of 2 in PreCommitPhase + ├── 1 element transitioning toward PUBLIC + │ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1, PartitionName: "p1"} + └── 1 Mutation operation + └── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_1_of_4.explain_shape b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_1_of_4.explain_shape new file mode 100644 index 000000000000..4cc519cbff26 --- /dev/null +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_1_of_4.explain_shape @@ -0,0 +1,14 @@ +/* setup */ +CREATE TABLE t ( + id INT PRIMARY KEY, + data STRING +) PARTITION BY LIST (id) ( + PARTITION p1 VALUES IN (1, 2, 3), + PARTITION p2 VALUES IN (4, 5, 6) +); + +/* test */ +EXPLAIN (DDL, SHAPE) ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 11; +---- +Schema change plan for ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹11›; + └── execute 1 system table mutations transaction diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_2_of_4.explain b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_2_of_4.explain new file mode 100644 index 000000000000..96eb6d8e85b0 --- /dev/null +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_2_of_4.explain @@ -0,0 +1,34 @@ +/* setup */ +CREATE TABLE t ( + id INT PRIMARY KEY, + data STRING +) PARTITION BY LIST (id) ( + PARTITION p1 VALUES IN (1, 2, 3), + PARTITION p2 VALUES IN (4, 5, 6) +); + +/* test */ +ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 11; +EXPLAIN (DDL) ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 12; +---- +Schema change plan for ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹12›; following ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹11›; + ├── StatementPhase + │ └── Stage 1 of 1 in StatementPhase + │ ├── 1 element transitioning toward PUBLIC + │ │ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 2, PartitionName: "p1"} + │ └── 1 Mutation operation + │ └── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + └── PreCommitPhase + ├── Stage 1 of 2 in PreCommitPhase + │ ├── 2 elements transitioning toward PUBLIC + │ │ ├── PUBLIC → ABSENT PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1, PartitionName: "p1"} + │ │ └── PUBLIC → ABSENT PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 2, PartitionName: "p1"} + │ └── 1 Mutation operation + │ └── UndoAllInTxnImmediateMutationOpSideEffects + └── Stage 2 of 2 in PreCommitPhase + ├── 2 elements transitioning toward PUBLIC + │ ├── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1, PartitionName: "p1"} + │ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 2, PartitionName: "p1"} + └── 2 Mutation operations + ├── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + └── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_2_of_4.explain_shape b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_2_of_4.explain_shape new file mode 100644 index 000000000000..801b33063b3e --- /dev/null +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_2_of_4.explain_shape @@ -0,0 +1,15 @@ +/* setup */ +CREATE TABLE t ( + id INT PRIMARY KEY, + data STRING +) PARTITION BY LIST (id) ( + PARTITION p1 VALUES IN (1, 2, 3), + PARTITION p2 VALUES IN (4, 5, 6) +); + +/* test */ +ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 11; +EXPLAIN (DDL, SHAPE) ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 12; +---- +Schema change plan for ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹12›; following ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹11›; + └── execute 1 system table mutations transaction diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_3_of_4.explain b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_3_of_4.explain new file mode 100644 index 000000000000..c9d6536547a2 --- /dev/null +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_3_of_4.explain @@ -0,0 +1,38 @@ +/* setup */ +CREATE TABLE t ( + id INT PRIMARY KEY, + data STRING +) PARTITION BY LIST (id) ( + PARTITION p1 VALUES IN (1, 2, 3), + PARTITION p2 VALUES IN (4, 5, 6) +); + +/* test */ +ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 11; +ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 12; +EXPLAIN (DDL) ALTER PARTITION p2 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 10; +---- +Schema change plan for ALTER PARTITION ‹p2› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹10›; following ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹11›; ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹12›; + ├── StatementPhase + │ └── Stage 1 of 1 in StatementPhase + │ ├── 1 element transitioning toward PUBLIC + │ │ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1, PartitionName: "p2"} + │ └── 1 Mutation operation + │ └── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + └── PreCommitPhase + ├── Stage 1 of 2 in PreCommitPhase + │ ├── 3 elements transitioning toward PUBLIC + │ │ ├── PUBLIC → ABSENT PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1, PartitionName: "p1"} + │ │ ├── PUBLIC → ABSENT PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 2, PartitionName: "p1"} + │ │ └── PUBLIC → ABSENT PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1, PartitionName: "p2"} + │ └── 1 Mutation operation + │ └── UndoAllInTxnImmediateMutationOpSideEffects + └── Stage 2 of 2 in PreCommitPhase + ├── 3 elements transitioning toward PUBLIC + │ ├── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1, PartitionName: "p1"} + │ ├── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 2, PartitionName: "p1"} + │ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1, PartitionName: "p2"} + └── 3 Mutation operations + ├── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + ├── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + └── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_3_of_4.explain_shape b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_3_of_4.explain_shape new file mode 100644 index 000000000000..cb5ebb3e9037 --- /dev/null +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_3_of_4.explain_shape @@ -0,0 +1,16 @@ +/* setup */ +CREATE TABLE t ( + id INT PRIMARY KEY, + data STRING +) PARTITION BY LIST (id) ( + PARTITION p1 VALUES IN (1, 2, 3), + PARTITION p2 VALUES IN (4, 5, 6) +); + +/* test */ +ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 11; +ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 12; +EXPLAIN (DDL, SHAPE) ALTER PARTITION p2 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 10; +---- +Schema change plan for ALTER PARTITION ‹p2› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹10›; following ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹11›; ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹12›; + └── execute 1 system table mutations transaction diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_4_of_4.explain b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_4_of_4.explain new file mode 100644 index 000000000000..edafcb05ef48 --- /dev/null +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_4_of_4.explain @@ -0,0 +1,35 @@ +/* setup */ +CREATE TABLE t ( + id INT PRIMARY KEY, + data STRING +) PARTITION BY LIST (id) ( + PARTITION p1 VALUES IN (1, 2, 3), + PARTITION p2 VALUES IN (4, 5, 6) +); + +/* test */ +ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 11; +ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 12; +ALTER PARTITION p2 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 10; +EXPLAIN (DDL) ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE DISCARD; +---- +Schema change plan for ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE DISCARD; following ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹11›; ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹12›; ALTER PARTITION ‹p2› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹10›; + ├── StatementPhase + │ └── Stage 1 of 1 in StatementPhase + │ ├── 2 elements transitioning toward ABSENT + │ │ ├── PUBLIC → ABSENT PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1, PartitionName: "p1"} + │ │ └── PUBLIC → ABSENT PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 2, PartitionName: "p1"} + │ └── 2 Mutation operations + │ ├── DiscardSubzoneConfig {"TableID":104} + │ └── DiscardSubzoneConfig {"TableID":104} + └── PreCommitPhase + ├── Stage 1 of 2 in PreCommitPhase + │ ├── 1 element transitioning toward PUBLIC + │ │ └── PUBLIC → ABSENT PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1, PartitionName: "p2"} + │ └── 1 Mutation operation + │ └── UndoAllInTxnImmediateMutationOpSideEffects + └── Stage 2 of 2 in PreCommitPhase + ├── 1 element transitioning toward PUBLIC + │ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1, PartitionName: "p2"} + └── 1 Mutation operation + └── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_4_of_4.explain_shape b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_4_of_4.explain_shape new file mode 100644 index 000000000000..6c6ee850c8b4 --- /dev/null +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_discard/alter_partition_configure_zone_discard__statement_4_of_4.explain_shape @@ -0,0 +1,17 @@ +/* setup */ +CREATE TABLE t ( + id INT PRIMARY KEY, + data STRING +) PARTITION BY LIST (id) ( + PARTITION p1 VALUES IN (1, 2, 3), + PARTITION p2 VALUES IN (4, 5, 6) +); + +/* test */ +ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 11; +ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 12; +ALTER PARTITION p2 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 10; +EXPLAIN (DDL, SHAPE) ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE DISCARD; +---- +Schema change plan for ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE DISCARD; following ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹11›; ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹12›; ALTER PARTITION ‹p2› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹10›; + └── execute 1 system table mutations transaction diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_multiple/alter_partition_configure_zone_multiple__statement_1_of_4.explain b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_multiple/alter_partition_configure_zone_multiple__statement_1_of_4.explain index 06fcb8e3a789..02ca9f270059 100644 --- a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_multiple/alter_partition_configure_zone_multiple__statement_1_of_4.explain +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_multiple/alter_partition_configure_zone_multiple__statement_1_of_4.explain @@ -20,7 +20,7 @@ Schema change plan for ALTER PARTITION ‹p3› OF INDEX ‹defaultdb›.‹publ │ ├── 1 element transitioning toward PUBLIC │ │ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1, PartitionName: "p3"} │ └── 1 Mutation operation - │ └── AddPartitionZoneConfig {"TableID":104} + │ └── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} └── PreCommitPhase ├── Stage 1 of 2 in PreCommitPhase │ ├── 1 element transitioning toward PUBLIC @@ -31,4 +31,4 @@ Schema change plan for ALTER PARTITION ‹p3› OF INDEX ‹defaultdb›.‹publ ├── 1 element transitioning toward PUBLIC │ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1, PartitionName: "p3"} └── 1 Mutation operation - └── AddPartitionZoneConfig {"TableID":104} + └── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_multiple/alter_partition_configure_zone_multiple__statement_2_of_4.explain b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_multiple/alter_partition_configure_zone_multiple__statement_2_of_4.explain index 90cde542d03d..f377e98dee4e 100644 --- a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_multiple/alter_partition_configure_zone_multiple__statement_2_of_4.explain +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_multiple/alter_partition_configure_zone_multiple__statement_2_of_4.explain @@ -21,7 +21,7 @@ Schema change plan for ALTER PARTITION ‹p3› OF INDEX ‹defaultdb›.‹publ │ ├── 1 element transitioning toward PUBLIC │ │ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 2, PartitionName: "p3"} │ └── 1 Mutation operation - │ └── AddPartitionZoneConfig {"TableID":104} + │ └── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} └── PreCommitPhase ├── Stage 1 of 2 in PreCommitPhase │ ├── 2 elements transitioning toward PUBLIC @@ -34,5 +34,5 @@ Schema change plan for ALTER PARTITION ‹p3› OF INDEX ‹defaultdb›.‹publ │ ├── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1, PartitionName: "p3"} │ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 2, PartitionName: "p3"} └── 2 Mutation operations - ├── AddPartitionZoneConfig {"TableID":104} - └── AddPartitionZoneConfig {"TableID":104} + ├── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + └── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_multiple/alter_partition_configure_zone_multiple__statement_3_of_4.explain b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_multiple/alter_partition_configure_zone_multiple__statement_3_of_4.explain index bc14ef856f5f..883ca35048c2 100644 --- a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_multiple/alter_partition_configure_zone_multiple__statement_3_of_4.explain +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_multiple/alter_partition_configure_zone_multiple__statement_3_of_4.explain @@ -22,7 +22,7 @@ Schema change plan for ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹publ │ ├── 1 element transitioning toward PUBLIC │ │ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (t), IndexID: 2 (idx), SeqNum: 1, PartitionName: "p1"} │ └── 1 Mutation operation - │ └── AddPartitionZoneConfig {"TableID":104} + │ └── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} └── PreCommitPhase ├── Stage 1 of 2 in PreCommitPhase │ ├── 3 elements transitioning toward PUBLIC @@ -37,6 +37,6 @@ Schema change plan for ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹publ │ ├── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 2, PartitionName: "p3"} │ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (t), IndexID: 2 (idx), SeqNum: 1, PartitionName: "p1"} └── 3 Mutation operations - ├── AddPartitionZoneConfig {"TableID":104} - ├── AddPartitionZoneConfig {"TableID":104} - └── AddPartitionZoneConfig {"TableID":104} + ├── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + ├── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + └── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_multiple/alter_partition_configure_zone_multiple__statement_4_of_4.explain b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_multiple/alter_partition_configure_zone_multiple__statement_4_of_4.explain index 6450e46174e4..8de099c4528f 100644 --- a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_multiple/alter_partition_configure_zone_multiple__statement_4_of_4.explain +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_multiple/alter_partition_configure_zone_multiple__statement_4_of_4.explain @@ -23,7 +23,7 @@ Schema change plan for ALTER PARTITION ‹p3› OF INDEX ‹defaultdb›.‹publ │ ├── 1 element transitioning toward PUBLIC │ │ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 3, PartitionName: "p3"} │ └── 1 Mutation operation - │ └── AddPartitionZoneConfig {"TableID":104} + │ └── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} └── PreCommitPhase ├── Stage 1 of 2 in PreCommitPhase │ ├── 4 elements transitioning toward PUBLIC @@ -40,7 +40,7 @@ Schema change plan for ALTER PARTITION ‹p3› OF INDEX ‹defaultdb›.‹publ │ ├── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (t), IndexID: 2 (idx), SeqNum: 1, PartitionName: "p1"} │ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 3, PartitionName: "p3"} └── 4 Mutation operations - ├── AddPartitionZoneConfig {"TableID":104} - ├── AddPartitionZoneConfig {"TableID":104} - ├── AddPartitionZoneConfig {"TableID":104} - └── AddPartitionZoneConfig {"TableID":104} + ├── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + ├── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + ├── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + └── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_subpartitions/alter_partition_configure_zone_subpartitions__statement_1_of_4.explain b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_subpartitions/alter_partition_configure_zone_subpartitions__statement_1_of_4.explain index c17a23c9400d..06a173e40fa0 100644 --- a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_subpartitions/alter_partition_configure_zone_subpartitions__statement_1_of_4.explain +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_subpartitions/alter_partition_configure_zone_subpartitions__statement_1_of_4.explain @@ -33,7 +33,7 @@ Schema change plan for ALTER PARTITION ‹australia› OF INDEX ‹defaultdb›. │ ├── 1 element transitioning toward PUBLIC │ │ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (person), IndexID: 1 (person_pkey), SeqNum: 1, PartitionName: "australia"} │ └── 1 Mutation operation - │ └── AddPartitionZoneConfig {"TableID":104} + │ └── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} └── PreCommitPhase ├── Stage 1 of 2 in PreCommitPhase │ ├── 1 element transitioning toward PUBLIC @@ -44,4 +44,4 @@ Schema change plan for ALTER PARTITION ‹australia› OF INDEX ‹defaultdb›. ├── 1 element transitioning toward PUBLIC │ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (person), IndexID: 1 (person_pkey), SeqNum: 1, PartitionName: "australia"} └── 1 Mutation operation - └── AddPartitionZoneConfig {"TableID":104} + └── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_subpartitions/alter_partition_configure_zone_subpartitions__statement_2_of_4.explain b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_subpartitions/alter_partition_configure_zone_subpartitions__statement_2_of_4.explain index 2830ef803a82..3579b2244c94 100644 --- a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_subpartitions/alter_partition_configure_zone_subpartitions__statement_2_of_4.explain +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_subpartitions/alter_partition_configure_zone_subpartitions__statement_2_of_4.explain @@ -34,7 +34,7 @@ Schema change plan for ALTER PARTITION ‹old_au› OF INDEX ‹defaultdb›.‹ │ ├── 1 element transitioning toward PUBLIC │ │ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (person), IndexID: 1 (person_pkey), SeqNum: 1, PartitionName: "old_au"} │ └── 1 Mutation operation - │ └── AddPartitionZoneConfig {"TableID":104} + │ └── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} └── PreCommitPhase ├── Stage 1 of 2 in PreCommitPhase │ ├── 2 elements transitioning toward PUBLIC @@ -47,5 +47,5 @@ Schema change plan for ALTER PARTITION ‹old_au› OF INDEX ‹defaultdb›.‹ │ ├── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (person), IndexID: 1 (person_pkey), SeqNum: 1, PartitionName: "australia"} │ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (person), IndexID: 1 (person_pkey), SeqNum: 1, PartitionName: "old_au"} └── 2 Mutation operations - ├── AddPartitionZoneConfig {"TableID":104} - └── AddPartitionZoneConfig {"TableID":104} + ├── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + └── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_subpartitions/alter_partition_configure_zone_subpartitions__statement_3_of_4.explain b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_subpartitions/alter_partition_configure_zone_subpartitions__statement_3_of_4.explain index 0a9db5dd140e..390be3358ba7 100644 --- a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_subpartitions/alter_partition_configure_zone_subpartitions__statement_3_of_4.explain +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_subpartitions/alter_partition_configure_zone_subpartitions__statement_3_of_4.explain @@ -35,7 +35,7 @@ Schema change plan for ALTER PARTITION ‹yung_au› OF INDEX ‹defaultdb›. │ ├── 1 element transitioning toward PUBLIC │ │ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (person), IndexID: 1 (person_pkey), SeqNum: 1, PartitionName: "yung_au"} │ └── 1 Mutation operation - │ └── AddPartitionZoneConfig {"TableID":104} + │ └── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} └── PreCommitPhase ├── Stage 1 of 2 in PreCommitPhase │ ├── 3 elements transitioning toward PUBLIC @@ -50,6 +50,6 @@ Schema change plan for ALTER PARTITION ‹yung_au› OF INDEX ‹defaultdb›. │ ├── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (person), IndexID: 1 (person_pkey), SeqNum: 1, PartitionName: "old_au"} │ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (person), IndexID: 1 (person_pkey), SeqNum: 1, PartitionName: "yung_au"} └── 3 Mutation operations - ├── AddPartitionZoneConfig {"TableID":104} - ├── AddPartitionZoneConfig {"TableID":104} - └── AddPartitionZoneConfig {"TableID":104} + ├── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + ├── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + └── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_subpartitions/alter_partition_configure_zone_subpartitions__statement_4_of_4.explain b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_subpartitions/alter_partition_configure_zone_subpartitions__statement_4_of_4.explain index 458258d37d1f..9b6156fd0116 100644 --- a/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_subpartitions/alter_partition_configure_zone_subpartitions__statement_4_of_4.explain +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/alter_partition_configure_zone_subpartitions/alter_partition_configure_zone_subpartitions__statement_4_of_4.explain @@ -36,7 +36,7 @@ Schema change plan for ALTER PARTITION ‹old_au› OF INDEX ‹defaultdb›.‹ │ ├── 1 element transitioning toward PUBLIC │ │ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (person), IndexID: 1 (person_pkey), SeqNum: 2, PartitionName: "old_au"} │ └── 1 Mutation operation - │ └── AddPartitionZoneConfig {"TableID":104} + │ └── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} └── PreCommitPhase ├── Stage 1 of 2 in PreCommitPhase │ ├── 4 elements transitioning toward PUBLIC @@ -53,7 +53,7 @@ Schema change plan for ALTER PARTITION ‹old_au› OF INDEX ‹defaultdb›.‹ │ ├── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (person), IndexID: 1 (person_pkey), SeqNum: 1, PartitionName: "yung_au"} │ └── ABSENT → PUBLIC PartitionZoneConfig:{DescID: 104 (person), IndexID: 1 (person_pkey), SeqNum: 2, PartitionName: "old_au"} └── 4 Mutation operations - ├── AddPartitionZoneConfig {"TableID":104} - ├── AddPartitionZoneConfig {"TableID":104} - ├── AddPartitionZoneConfig {"TableID":104} - └── AddPartitionZoneConfig {"TableID":104} + ├── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + ├── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + ├── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + └── AddPartitionZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} diff --git a/pkg/config/zonepb/zone.go b/pkg/config/zonepb/zone.go index 86ad446c7174..37164f25af8d 100644 --- a/pkg/config/zonepb/zone.go +++ b/pkg/config/zonepb/zone.go @@ -1210,11 +1210,11 @@ func (z *ZoneConfig) MergeSubzoneSpans(subzoneSpans []SubzoneSpan) { } // FilterSubzoneSpansByIdx retrieves all subzone spans with the given -// SubzoneIndex. -func (z *ZoneConfig) FilterSubzoneSpansByIdx(subzoneIdx int32) []SubzoneSpan { +// subzoneIndex. +func (z *ZoneConfig) FilterSubzoneSpansByIdx(subzoneIndex int32) []SubzoneSpan { filteredSpans := make([]SubzoneSpan, 0, len(z.SubzoneSpans)) for _, s := range z.SubzoneSpans { - if s.SubzoneIndex == subzoneIdx { + if s.SubzoneIndex == subzoneIndex { filteredSpans = append(filteredSpans, s) } } diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/configure_zone.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/configure_zone.go index 4f3bdeb172cd..0eca125fd876 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/configure_zone.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/configure_zone.go @@ -186,13 +186,6 @@ func astToZoneConfigObject(b BuildCtx, n *tree.SetZoneConfig) (zoneConfigObject, return &tzo, nil } - // TODO(annie): remove this when we add support for discarding subzone - // configs. - if n.Discard { - return nil, scerrors.NotImplementedErrorf(n, "discarding zone configurations on "+ - "subzones are not supported in the DSC") - } - izo := indexZoneConfigObj{tableZoneConfigObj: tzo} // We are an index object. Determine the index ID and fill this // information out in our zoneConfigObject. diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/database_zone_config.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/database_zone_config.go index 9d9ccad369b9..697120e9b469 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/database_zone_config.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/database_zone_config.go @@ -46,6 +46,9 @@ func (dzo *databaseZoneConfigObj) getZoneConfigElemForDrop( b BuildCtx, ) ([]scpb.Element, []scpb.Element) { var elems []scpb.Element + // Ensure that we drop all elements associated with this database. This + // becomes more relevant in explicit txns -- where there could be multiple + // zone config elements associated with this database with increasing seqNums. b.QueryByID(dzo.getTargetID()).FilterDatabaseZoneConfig(). ForEach(func(_ scpb.Status, _ scpb.TargetStatus, e *scpb.DatabaseZoneConfig) { elems = append(elems, e) @@ -102,7 +105,7 @@ func (dzo *databaseZoneConfigObj) checkZoneConfigChangePermittedForMultiRegion( return nil } - return maybeMultiregionErrorWithHint(b, dzo, options) + return maybeMultiregionErrorWithHint(b, dzo, zs, options) } func (dzo *databaseZoneConfigObj) getTargetID() catid.DescID { diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/index_zone_config.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/index_zone_config.go index 8300bad77649..ea3a78b65fe3 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/index_zone_config.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/index_zone_config.go @@ -60,7 +60,8 @@ func (izo *indexZoneConfigObj) getZoneConfigElemForAdd(b BuildCtx) (scpb.Element for i, sub := range subzones { if spans, ok := idxToSpansMap[int32(i)]; ok { if len(sub.PartitionName) > 0 { - szCfgsToUpdate = append(szCfgsToUpdate, constructSideEffectPartitionElem(b, izo, sub, spans)) + szCfgsToUpdate = append(szCfgsToUpdate, + constructSideEffectPartitionElem(b, izo, -1, sub, spans)) } else { if sub.IndexID == uint32(izo.indexID) { szCfg = &scpb.IndexZoneConfig{ @@ -69,9 +70,11 @@ func (izo *indexZoneConfigObj) getZoneConfigElemForAdd(b BuildCtx) (scpb.Element Subzone: sub, SubzoneSpans: spans, SeqNum: izo.seqNum + 1, + OldIdxRef: -1, } } else { - szCfgsToUpdate = append(szCfgsToUpdate, constructSideEffectIndexElem(b, izo, sub, spans)) + szCfgsToUpdate = append(szCfgsToUpdate, + constructSideEffectIndexElem(b, izo, -1, spans, sub)) } } } @@ -83,9 +86,82 @@ func (izo *indexZoneConfigObj) getZoneConfigElemForAdd(b BuildCtx) (scpb.Element func (izo *indexZoneConfigObj) getZoneConfigElemForDrop( b BuildCtx, ) ([]scpb.Element, []scpb.Element) { - // TODO(annie): this will need to be revised in order to implement subzone - // discards. - return nil, nil + var subzonesToWrite []zonepb.Subzone + var err error + + parentZoneConfig := izo.getTableZoneConfig() + if parentZoneConfig != nil { + // Get the list of subzones after we have dropped the target; this is so we + // can correctly generate the list of subzone spans to upsert. + modifiedZc := protoutil.Clone(parentZoneConfig).(*zonepb.ZoneConfig) + modifiedZc.DeleteSubzone(uint32(izo.indexID), "") + subzonesToWrite = modifiedZc.Subzones + } else { + // Likely in an explicit txn that has not created an overarching + // TableZoneConfig yet. + var toDropElems []scpb.Element + // Ensure that we drop all elements associated with this index. This + // becomes more relevant in explicit txns -- where there could be multiple + // zone config elements associated with this index with increasing seqNums. + b.QueryByID(izo.getTargetID()).FilterIndexZoneConfig(). + ForEach(func(_ scpb.Status, _ scpb.TargetStatus, e *scpb.IndexZoneConfig) { + if e.IndexID == izo.indexID { + toDropElems = append(toDropElems, e) + } + }) + + if len(toDropElems) == 0 { + panic(errors.AssertionFailedf( + "attempted to drop subzone config for table [%d], index %d that does not exist", + izo.tableID, izo.indexID)) + } + return toDropElems, nil + } + ss, err := generateSubzoneSpans(b, izo.tableID, subzonesToWrite) + if err != nil { + panic(err) + } + + // TODO(annie): This does a little more work than necessary -- we should be + // able to just update the affected subzone spans. This can be done by + // comparing the parent's subzone spans with `ss`. + // + // Update the index that is represented by izo, along with all other subzones. + // These other subzones are "side effects" that will need their subzoneSpans + // updated in some way. + idxToSpansMap := getSubzoneSpansWithIdx(len(subzonesToWrite), ss) + var szCfgsToUpdate []scpb.Element + for i, sub := range subzonesToWrite { + if spans, ok := idxToSpansMap[int32(i)]; ok { + oldIdxRefToDelete := parentZoneConfig.GetSubzoneIndex(sub.IndexID, sub.PartitionName) + if len(sub.PartitionName) > 0 { + szCfgsToUpdate = append(szCfgsToUpdate, + constructSideEffectPartitionElem(b, izo, oldIdxRefToDelete, sub, spans)) + } else { + szCfgsToUpdate = append(szCfgsToUpdate, + constructSideEffectIndexElem(b, izo, oldIdxRefToDelete, spans, sub)) + } + } + } + + var toDropElems []scpb.Element + if izo.seqNum > 0 { + for i := range izo.seqNum { + toDropElems = append(toDropElems, &scpb.IndexZoneConfig{ + TableID: izo.tableID, + IndexID: izo.indexID, + SeqNum: i + 1, + }) + } + } else { + toDropElems = append(toDropElems, &scpb.IndexZoneConfig{ + TableID: izo.tableID, + IndexID: izo.indexID, + SeqNum: 0, + }) + } + + return toDropElems, szCfgsToUpdate } func (izo *indexZoneConfigObj) retrievePartialZoneConfig(b BuildCtx) *zonepb.ZoneConfig { @@ -220,6 +296,11 @@ func (izo *indexZoneConfigObj) applyZoneConfig( subzonePlaceholder := false // No zone was found. Possibly a SubzonePlaceholder depending on the index. if partialZone == nil { + // If we are trying to discard a zone config that doesn't exist in + // system.zones, make this a no-op. + if n.Discard { + return nil, nil + } partialZone = zonepb.NewZoneConfig() subzonePlaceholder = true } diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/named_range_zone_config.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/named_range_zone_config.go index 1322558680af..84ba2db33892 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/named_range_zone_config.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/named_range_zone_config.go @@ -45,6 +45,10 @@ func (rzo *namedRangeZoneConfigObj) getZoneConfigElemForDrop( b BuildCtx, ) ([]scpb.Element, []scpb.Element) { var elems []scpb.Element + // Ensure that we drop all elements associated with this named range. This + // becomes more relevant in explicit txns -- where there could be multiple + // zone config elements associated with this named range with increasing + // seqNums. b.QueryByID(rzo.getTargetID()).FilterNamedRangeZoneConfig(). ForEach(func(_ scpb.Status, _ scpb.TargetStatus, e *scpb.NamedRangeZoneConfig) { elems = append(elems, e) diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/partition_zone_config.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/partition_zone_config.go index 38adede38390..fc6d33d5e45a 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/partition_zone_config.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/partition_zone_config.go @@ -75,13 +75,16 @@ func (pzo *partitionZoneConfigObj) getZoneConfigElemForAdd( PartitionName: sub.PartitionName, Subzone: sub, SubzoneSpans: spans, + OldIdxRef: -1, SeqNum: pzo.seqNum + 1, } } else { - szCfgsToUpdate = append(szCfgsToUpdate, constructSideEffectPartitionElem(b, pzo, sub, spans)) + szCfgsToUpdate = append(szCfgsToUpdate, + constructSideEffectPartitionElem(b, pzo, -1, sub, spans)) } } else { - szCfgsToUpdate = append(szCfgsToUpdate, constructSideEffectIndexElem(b, pzo, sub, spans)) + szCfgsToUpdate = append(szCfgsToUpdate, + constructSideEffectIndexElem(b, pzo, -1, spans, sub)) } } } @@ -92,9 +95,85 @@ func (pzo *partitionZoneConfigObj) getZoneConfigElemForAdd( func (pzo *partitionZoneConfigObj) getZoneConfigElemForDrop( b BuildCtx, ) ([]scpb.Element, []scpb.Element) { - // TODO(annie): this will need to be revised in order to implement subzone - // discards. This is fine for now as we fallback before we can get here. - return nil, nil + var subzonesToWrite []zonepb.Subzone + var err error + + parentZoneConfig := pzo.getTableZoneConfig() + if parentZoneConfig != nil { + // Get the list of subzones after we have dropped the target; this is so we + // can correctly generate the list of subzone spans to upsert. + modifiedZc := protoutil.Clone(parentZoneConfig).(*zonepb.ZoneConfig) + modifiedZc.DeleteSubzone(uint32(pzo.indexID), pzo.partitionName) + subzonesToWrite = modifiedZc.Subzones + } else { + // Likely in an explicit txn that has not created an overarching + // TableZoneConfig yet. + var toDropElems []scpb.Element + // Ensure that we drop all elements associated with this partition. This + // becomes more relevant in explicit txns -- where there could be multiple + // zone config elements associated with this partition with increasing + // seqNums. + b.QueryByID(pzo.getTargetID()).FilterPartitionZoneConfig(). + ForEach(func(_ scpb.Status, _ scpb.TargetStatus, e *scpb.PartitionZoneConfig) { + if e.PartitionName == pzo.partitionName && e.IndexID == pzo.indexID { + toDropElems = append(toDropElems, e) + } + }) + + if len(toDropElems) == 0 { + panic(errors.AssertionFailedf( + "attempted to drop subzone config for table [%d], partition %s of index %d that "+ + "does not exist", pzo.tableID, pzo.partitionName, pzo.indexID)) + } + return toDropElems, nil + } + ss, err := generateSubzoneSpans(b, pzo.tableID, subzonesToWrite) + if err != nil { + panic(err) + } + + // TODO(annie): This does a little more work than necessary -- we should be + // able to just update the affected subzone spans. This can be done by + // comparing the parent's subzone spans with `ss`. + // + // Update the partition that is represented by pzo, along with all other + // subzones. These other subzones are "side effects" that will need their + // subzoneSpans updated in some way. + idxToSpansMap := getSubzoneSpansWithIdx(len(subzonesToWrite), ss) + var szCfgsToUpdate []scpb.Element + for i, sub := range subzonesToWrite { + if spans, ok := idxToSpansMap[int32(i)]; ok { + oldIdxRefToDelete := parentZoneConfig.GetSubzoneIndex(sub.IndexID, sub.PartitionName) + if len(sub.PartitionName) > 0 { + szCfgsToUpdate = append(szCfgsToUpdate, + constructSideEffectPartitionElem(b, pzo, oldIdxRefToDelete, sub, spans)) + } else { + szCfgsToUpdate = append(szCfgsToUpdate, + constructSideEffectIndexElem(b, pzo, oldIdxRefToDelete, spans, sub)) + } + } + } + + var toDropElems []scpb.Element + if pzo.seqNum > 0 { + for i := range pzo.seqNum { + toDropElems = append(toDropElems, &scpb.PartitionZoneConfig{ + TableID: pzo.tableID, + IndexID: pzo.indexID, + PartitionName: pzo.partitionName, + SeqNum: i + 1, + }) + } + } else { + toDropElems = append(toDropElems, &scpb.PartitionZoneConfig{ + TableID: pzo.tableID, + IndexID: pzo.indexID, + PartitionName: pzo.partitionName, + SeqNum: 0, + }) + } + + return toDropElems, szCfgsToUpdate } func (pzo *partitionZoneConfigObj) retrievePartialZoneConfig(b BuildCtx) *zonepb.ZoneConfig { @@ -226,6 +305,11 @@ func (pzo *partitionZoneConfigObj) applyZoneConfig( subzonePlaceholder := false // No zone was found. Possibly a SubzonePlaceholder depending on the index. if partialZone == nil { + // If we are trying to discard a zone config that doesn't exist in + // system.zones, make this a no-op. + if n.Discard { + return nil, nil + } partialZone = zonepb.NewZoneConfig() subzonePlaceholder = true } diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/table_zone_config.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/table_zone_config.go index 95e958eb2bc1..e9af000831c7 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/table_zone_config.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/table_zone_config.go @@ -45,6 +45,9 @@ func (tzo *tableZoneConfigObj) getZoneConfigElemForDrop( b BuildCtx, ) ([]scpb.Element, []scpb.Element) { var elems []scpb.Element + // Ensure that we drop all elements associated with this table. This becomes + // more relevant in explicit txns -- where there could be multiple zone config + // elements associated with this table with increasing seqNums. b.QueryByID(tzo.getTargetID()).FilterTableZoneConfig(). ForEach(func(_ scpb.Status, _ scpb.TargetStatus, e *scpb.TableZoneConfig) { e.ZoneConfig.DeleteTableConfig() @@ -104,7 +107,7 @@ func (tzo *tableZoneConfigObj) checkZoneConfigChangePermittedForMultiRegion( return nil } - return maybeMultiregionErrorWithHint(b, tzo, options) + return maybeMultiregionErrorWithHint(b, tzo, zs, options) } func (tzo *tableZoneConfigObj) getTargetID() catid.DescID { diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/zone_config_helpers.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/zone_config_helpers.go index d0ea47288489..a896857f1464 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/zone_config_helpers.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/zone_config_helpers.go @@ -170,7 +170,9 @@ func resolvePhysicalTableName(b BuildCtx, n *tree.SetZoneConfig) { // maybeMultiregionErrorWithHint returns an error if the user is trying to // update a zone config value that's protected for multi-region databases. -func maybeMultiregionErrorWithHint(b BuildCtx, zco zoneConfigObject, options tree.KVOptions) error { +func maybeMultiregionErrorWithHint( + b BuildCtx, zco zoneConfigObject, zs tree.ZoneSpecifier, options tree.KVOptions, +) error { hint := "to override this error, SET override_multi_region_zone_config = true and reissue the command" // The request is to discard the zone configuration. Error in cases where // the zone configuration being discarded was created by the multi-region @@ -184,7 +186,7 @@ func maybeMultiregionErrorWithHint(b BuildCtx, zco zoneConfigObject, options tre needToError = true } else { var err error - needToError, err = blockDiscardOfZoneConfigForMultiRegionObject(b, zco.getTargetID()) + needToError, err = blockDiscardOfZoneConfigForMultiRegionObject(b, zs, zco.getTargetID()) if err != nil { return err } @@ -228,16 +230,30 @@ func maybeMultiregionErrorWithHint(b BuildCtx, zco zoneConfigObject, options tre // do a more explicit comparison (with a generated zone configuration). If, down // the road, the rules around writing zone configurations change, the tests in // multi_region_zone_configs will fail and this function will need updating. -func blockDiscardOfZoneConfigForMultiRegionObject(b BuildCtx, tblID catid.DescID) (bool, error) { +func blockDiscardOfZoneConfigForMultiRegionObject( + b BuildCtx, zs tree.ZoneSpecifier, tblID catid.DescID, +) (bool, error) { + isIndex := zs.TableOrIndex.Index != "" + isPartition := zs.Partition != "" tableElems := b.QueryByID(tblID) + RBRElem := tableElems.FilterTableLocalityRegionalByRow().MustGetZeroOrOneElement() + if isPartition { + // Multi-region abstractions only set partition-level zone configs for + // REGIONAL BY ROW tables. + return RBRElem != nil, nil + } else if isIndex { + // Multi-region will never set a zone config on an index, so no need to + // error if the user wants to drop the index zone config. + return false, nil + } + // It's a table zone config that the user is trying to discard. This // should only be present on GLOBAL and REGIONAL BY TABLE tables in a // specified region. globalElem := tableElems.FilterTableLocalityGlobal().MustGetZeroOrOneElement() primaryRegionElem := tableElems.FilterTableLocalityPrimaryRegion().MustGetZeroOrOneElement() secondaryRegionElem := tableElems.FilterTableLocalitySecondaryRegion().MustGetZeroOrOneElement() - RBRElem := tableElems.FilterTableLocalityRegionalByRow().MustGetZeroOrOneElement() if globalElem != nil { return true, nil @@ -1222,7 +1238,7 @@ func isCorrespondingTemporaryIndex( return maybeCorresponding != nil } -// getSubzoneSpansWithIdx groups each subzone span by their subzoneIndexs +// getSubzoneSpansWithIdx groups each subzone span by their subzoneIndexes // for a lookup of which subzone spans a particular subzone is referred to by. func getSubzoneSpansWithIdx( numSubzones int, newSubzoneSpans []zonepb.SubzoneSpan, @@ -1244,7 +1260,11 @@ func getSubzoneSpansWithIdx( // for existing subzone configs -- with the intent of updating its associated // subzone configs due to some other zone config change. func constructSideEffectIndexElem( - b BuildCtx, zco zoneConfigObject, subzone zonepb.Subzone, subzoneSpans []zonepb.SubzoneSpan, + b BuildCtx, + zco zoneConfigObject, + oldSubzoneIdx int32, + subzoneSpans []zonepb.SubzoneSpan, + subzone zonepb.Subzone, ) *scpb.IndexZoneConfig { // Get the most recent seqNum so we can properly update the side // effects. @@ -1265,6 +1285,7 @@ func constructSideEffectIndexElem( Subzone: subzone, SubzoneSpans: subzoneSpans, SeqNum: mostRecentElem.SeqNum + 1, + OldIdxRef: oldSubzoneIdx, } return elem } @@ -1275,7 +1296,11 @@ func constructSideEffectIndexElem( // configs -- with the intent of updating its associated subzone configs due to // some other zone config change. func constructSideEffectPartitionElem( - b BuildCtx, zco zoneConfigObject, subzone zonepb.Subzone, subzoneSpans []zonepb.SubzoneSpan, + b BuildCtx, + zco zoneConfigObject, + oldSubzoneIdx int32, + subzone zonepb.Subzone, + subzoneSpans []zonepb.SubzoneSpan, ) *scpb.PartitionZoneConfig { // Get the most recent seqNum so we can properly update the side // effects. @@ -1298,6 +1323,7 @@ func constructSideEffectPartitionElem( Subzone: subzone, SubzoneSpans: subzoneSpans, SeqNum: mostRecentElem.SeqNum + 1, + OldIdxRef: oldSubzoneIdx, } return elem } diff --git a/pkg/sql/schemachanger/scdecomp/decomp.go b/pkg/sql/schemachanger/scdecomp/decomp.go index 0200fdbccd7c..885ecb612b3e 100644 --- a/pkg/sql/schemachanger/scdecomp/decomp.go +++ b/pkg/sql/schemachanger/scdecomp/decomp.go @@ -154,7 +154,6 @@ func (w *walkCtx) walkDatabase(db catalog.DatabaseDescriptor) { w.ev(scpb.Status_PUBLIC, &scpb.DatabaseZoneConfig{ DatabaseID: db.GetID(), ZoneConfig: zoneConfig.ZoneConfigProto(), - SeqNum: 0, }) } } @@ -434,7 +433,6 @@ func (w *walkCtx) walkRelation(tbl catalog.TableDescriptor) { &scpb.TableZoneConfig{ TableID: tbl.GetID(), ZoneConfig: zc, - SeqNum: 0, }) for i, subZoneCfg := range zc.Subzones { if len(subZoneCfg.PartitionName) > 0 { @@ -445,7 +443,7 @@ func (w *walkCtx) walkRelation(tbl catalog.TableDescriptor) { PartitionName: subZoneCfg.PartitionName, Subzone: subZoneCfg, SubzoneSpans: zc.FilterSubzoneSpansByIdx(int32(i)), - SeqNum: 0, + OldIdxRef: -1, }) } else { w.ev(scpb.Status_PUBLIC, @@ -454,7 +452,7 @@ func (w *walkCtx) walkRelation(tbl catalog.TableDescriptor) { IndexID: catid.IndexID(subZoneCfg.IndexID), Subzone: subZoneCfg, SubzoneSpans: zc.FilterSubzoneSpansByIdx(int32(i)), - SeqNum: 0, + OldIdxRef: -1, }) } } @@ -1048,7 +1046,6 @@ func WalkNamedRanges( w.ev(scpb.Status_PUBLIC, &scpb.NamedRangeZoneConfig{ RangeID: rangeID, ZoneConfig: zoneConfig.ZoneConfigProto(), - SeqNum: 0, }) } } diff --git a/pkg/sql/schemachanger/scdeps/exec_deps.go b/pkg/sql/schemachanger/scdeps/exec_deps.go index 4d91cd28272a..03027b0bdeaa 100644 --- a/pkg/sql/schemachanger/scdeps/exec_deps.go +++ b/pkg/sql/schemachanger/scdeps/exec_deps.go @@ -264,6 +264,7 @@ func (d *txnDeps) UpdateSubzoneConfig( parentZone catalog.ZoneConfig, subzone zonepb.Subzone, subzoneSpans []zonepb.SubzoneSpan, + idxRefToDelete int32, ) (catalog.ZoneConfig, error) { var rawBytes []byte var zc *zonepb.ZoneConfig @@ -279,17 +280,19 @@ func (d *txnDeps) UpdateSubzoneConfig( zc.DeleteTableConfig() } + if idxRefToDelete == -1 { + idxRefToDelete = zc.GetSubzoneIndex(subzone.IndexID, subzone.PartitionName) + } + // Update the subzone in the zone config. zc.SetSubzone(subzone) - subzoneIdx := zc.GetSubzoneIndex(subzone.IndexID, subzone.PartitionName) - // Update the subzone spans. subzoneSpansToWrite := subzoneSpans // If there are subzone spans that currently exist, merge those with the new // spans we are updating. Otherwise, the zone config's set of subzone spans // will be our input subzoneSpans. if len(zc.SubzoneSpans) != 0 { - zc.DeleteSubzoneSpansForSubzoneIndex(subzoneIdx) + zc.DeleteSubzoneSpansForSubzoneIndex(idxRefToDelete) zc.MergeSubzoneSpans(subzoneSpansToWrite) subzoneSpansToWrite = zc.SubzoneSpans } @@ -304,6 +307,41 @@ func (d *txnDeps) DeleteZoneConfig(ctx context.Context, id descpb.ID) error { return d.descsCollection.DeleteZoneConfigInBatch(ctx, d.kvTrace, d.getOrCreateBatch(), id) } +// DeleteSubzoneConfig implements the scexec.Catalog interface. +func (d *txnDeps) DeleteSubzoneConfig( + ctx context.Context, tableID descpb.ID, subzone zonepb.Subzone, subzoneSpans []zonepb.SubzoneSpan, +) error { + var newZc catalog.ZoneConfig + oldZc, err := d.descsCollection.GetZoneConfig(ctx, d.txn.KV(), tableID) + if err != nil { + return err + } + + var rawBytes []byte + var zc *zonepb.ZoneConfig + if oldZc != nil { + rawBytes = oldZc.GetRawBytesInStorage() + zc = oldZc.ZoneConfigProto() + } else { + // No-op if nothing is there for us to discard. + return nil + } + + // Delete the subzone in the zone config. + zc.DeleteSubzone(subzone.IndexID, subzone.PartitionName) + // If there are no more subzones after our delete and this table is a + // placeholder, we can just delete the table zone config. + if len(zc.Subzones) == 0 && zc.IsSubzonePlaceholder() { + return d.DeleteZoneConfig(ctx, tableID) + } + // Delete the subzone spans. + zc.DeleteSubzoneSpans(subzoneSpans) + + newZc = zone.NewZoneConfigWithRawBytes(zc, rawBytes) + return d.descsCollection.WriteZoneConfigToBatch(ctx, d.kvTrace, d.getOrCreateBatch(), + tableID, newZc) +} + // Validate implements the scexec.Catalog interface. func (d *txnDeps) Validate(ctx context.Context) error { return d.descsCollection.ValidateUncommittedDescriptors(ctx, diff --git a/pkg/sql/schemachanger/scdeps/sctestdeps/test_deps.go b/pkg/sql/schemachanger/scdeps/sctestdeps/test_deps.go index 1e9a6dea2662..a0733008ce85 100644 --- a/pkg/sql/schemachanger/scdeps/sctestdeps/test_deps.go +++ b/pkg/sql/schemachanger/scdeps/sctestdeps/test_deps.go @@ -836,6 +836,7 @@ func (s *TestState) UpdateSubzoneConfig( parentZone catalog.ZoneConfig, subzone zonepb.Subzone, subzoneSpans []zonepb.SubzoneSpan, + idxRefToDelete int32, ) (catalog.ZoneConfig, error) { var rawBytes []byte var zc *zonepb.ZoneConfig @@ -851,17 +852,19 @@ func (s *TestState) UpdateSubzoneConfig( zc.DeleteTableConfig() } + if idxRefToDelete == -1 { + idxRefToDelete = zc.GetSubzoneIndex(subzone.IndexID, subzone.PartitionName) + } + // Update the subzone in the zone config. zc.SetSubzone(subzone) - subzoneIdx := zc.GetSubzoneIndex(subzone.IndexID, subzone.PartitionName) - // Update the subzone spans. subzoneSpansToWrite := subzoneSpans // If there are subzone spans that currently exist, merge those with the new // spans we are updating. Otherwise, the zone config's set of subzone spans // will be our input subzoneSpans. if len(zc.SubzoneSpans) != 0 { - zc.DeleteSubzoneSpansForSubzoneIndex(subzoneIdx) + zc.DeleteSubzoneSpansForSubzoneIndex(idxRefToDelete) zc.MergeSubzoneSpans(subzoneSpansToWrite) subzoneSpansToWrite = zc.SubzoneSpans } @@ -877,6 +880,31 @@ func (s *TestState) DeleteZoneConfig(_ context.Context, id descpb.ID) error { return nil } +// DeleteSubzoneConfig implements the scexec.Catalog interface. +func (s *TestState) DeleteSubzoneConfig( + ctx context.Context, tableID descpb.ID, subzone zonepb.Subzone, subzoneSpans []zonepb.SubzoneSpan, +) error { + var zc *zonepb.ZoneConfig + if czc, ok := s.catalogChanges.zoneConfigsToUpdate[tableID]; ok { + zc = czc + } else { + // No-op if nothing is there for us to discard. + return nil + } + + // Delete the subzone in the zone config. + zc.DeleteSubzone(subzone.IndexID, subzone.PartitionName) + // If there are no more subzones after our delete and this table is a + // placeholder, we can just delete the table zone config. + if len(zc.Subzones) == 0 && zc.IsSubzonePlaceholder() { + return s.DeleteZoneConfig(ctx, tableID) + } + // Delete the subzone spans. + zc.DeleteSubzoneSpans(subzoneSpans) + s.catalogChanges.zoneConfigsToUpdate[tableID] = zc + return nil +} + // UpdateComment implements the scexec.Catalog interface. func (s *TestState) UpdateComment( ctx context.Context, key catalogkeys.CommentKey, cmt string, diff --git a/pkg/sql/schemachanger/scexec/dependencies.go b/pkg/sql/schemachanger/scexec/dependencies.go index 626dc2b476f0..2c9f5fa2a330 100644 --- a/pkg/sql/schemachanger/scexec/dependencies.go +++ b/pkg/sql/schemachanger/scexec/dependencies.go @@ -84,11 +84,21 @@ type Catalog interface { parentZone catalog.ZoneConfig, subzone zonepb.Subzone, subzoneSpans []zonepb.SubzoneSpan, + idxRefToDelete int32, ) (catalog.ZoneConfig, error) // DeleteZoneConfig deletes the zone config for a descriptor. DeleteZoneConfig(ctx context.Context, id descpb.ID) error + // DeleteSubzoneConfig deletes a subzone config from the zone config for a + // table. + DeleteSubzoneConfig( + ctx context.Context, + tableID descpb.ID, + subzone zonepb.Subzone, + subzoneSpans []zonepb.SubzoneSpan, + ) error + // UpdateComment upserts a comment for the (objID, subID, cmtType) key. UpdateComment(ctx context.Context, key catalogkeys.CommentKey, cmt string) error diff --git a/pkg/sql/schemachanger/scexec/exec_immediate_mutation.go b/pkg/sql/schemachanger/scexec/exec_immediate_mutation.go index 73c786e0c00a..cf4c738c6942 100644 --- a/pkg/sql/schemachanger/scexec/exec_immediate_mutation.go +++ b/pkg/sql/schemachanger/scexec/exec_immediate_mutation.go @@ -29,8 +29,9 @@ type immediateState struct { sequencesToInit []sequenceToInit temporarySchemasToRegister map[descpb.ID]*temporarySchemaToRegister modifiedZoneConfigs []zoneConfigToUpsert - modifiedSubzoneConfigs []subzoneConfigToUpsert - zoneConfigsToDelete []zoneConfigToDelete + modifiedSubzoneConfigs map[descpb.ID][]subzoneConfigToUpsert + zoneConfigsToDelete map[descpb.ID]struct{} + subzoneConfigsToDelete map[descpb.ID][]subzoneConfigToDelete } type temporarySchemaToRegister struct { @@ -58,14 +59,15 @@ type zoneConfigToUpsert struct { zc *zonepb.ZoneConfig } -type zoneConfigToDelete struct { - id descpb.ID -} - // subzoneConfigToUpsert is a struct that holds the information needed to update // a subzone config. type subzoneConfigToUpsert struct { - tableID descpb.ID + subzone zonepb.Subzone + subzoneSpans []zonepb.SubzoneSpan + idxRefToDelete int32 +} + +type subzoneConfigToDelete struct { subzone zonepb.Subzone subzoneSpans []zonepb.SubzoneSpan } @@ -157,21 +159,50 @@ func (s *immediateState) UpdateZoneConfig(id descpb.ID, zc *zonepb.ZoneConfig) { } func (s *immediateState) UpdateSubzoneConfig( - tableID descpb.ID, subzone zonepb.Subzone, subzoneSpans []zonepb.SubzoneSpan, + tableID descpb.ID, + subzone zonepb.Subzone, + subzoneSpans []zonepb.SubzoneSpan, + idxRefToDelete int32, ) { - s.modifiedSubzoneConfigs = append(s.modifiedSubzoneConfigs, - subzoneConfigToUpsert{ - tableID: tableID, - subzone: subzone, - subzoneSpans: subzoneSpans, - }) + if s.modifiedSubzoneConfigs == nil { + s.modifiedSubzoneConfigs = make(map[descpb.ID][]subzoneConfigToUpsert) + } + szCfgToUpsert := subzoneConfigToUpsert{ + subzone: subzone, + subzoneSpans: subzoneSpans, + idxRefToDelete: idxRefToDelete, + } + if szCfgs, ok := s.modifiedSubzoneConfigs[tableID]; ok { + s.modifiedSubzoneConfigs[tableID] = append(szCfgs, szCfgToUpsert) + } else { + s.modifiedSubzoneConfigs[tableID] = []subzoneConfigToUpsert{szCfgToUpsert} + } } func (s *immediateState) DeleteZoneConfig(id descpb.ID) { - s.zoneConfigsToDelete = append(s.zoneConfigsToDelete, - zoneConfigToDelete{ - id: id, - }) + if s.zoneConfigsToDelete == nil { + s.zoneConfigsToDelete = make(map[descpb.ID]struct{}) + } + if _, ok := s.zoneConfigsToDelete[id]; !ok { + s.zoneConfigsToDelete[id] = struct{}{} + } +} + +func (s *immediateState) DeleteSubzoneConfig( + tableID descpb.ID, subzone zonepb.Subzone, subzoneSpans []zonepb.SubzoneSpan, +) { + if s.subzoneConfigsToDelete == nil { + s.subzoneConfigsToDelete = make(map[descpb.ID][]subzoneConfigToDelete) + } + szCfgToDelete := subzoneConfigToDelete{ + subzone: subzone, + subzoneSpans: subzoneSpans, + } + if szCfgs, ok := s.subzoneConfigsToDelete[tableID]; ok { + s.subzoneConfigsToDelete[tableID] = append(szCfgs, szCfgToDelete) + } else { + s.subzoneConfigsToDelete[tableID] = []subzoneConfigToDelete{szCfgToDelete} + } } func (s *immediateState) Reset() { @@ -240,8 +271,8 @@ func (s *immediateState) exec(ctx context.Context, c Catalog) error { c.InsertTemporarySchema(tempIdxToRegister.schemaName, tempIdxToRegister.parentID, tempIdxId) } - for _, zcToDelete := range s.zoneConfigsToDelete { - if err = c.DeleteZoneConfig(ctx, zcToDelete.id); err != nil { + for id := range s.zoneConfigsToDelete { + if err = c.DeleteZoneConfig(ctx, id); err != nil { return err } } @@ -252,24 +283,23 @@ func (s *immediateState) exec(ctx context.Context, c Catalog) error { } } - // Gather all subzone config updates for each unique descriptor ID and use a - // zone config accumulator that will be the final config we write. - subzoneUpdates := make(map[descpb.ID][]subzoneConfigToUpsert, len(s.modifiedSubzoneConfigs)) - for _, szcToUpdate := range s.modifiedSubzoneConfigs { - if ls, ok := subzoneUpdates[szcToUpdate.tableID]; ok { - subzoneUpdates[szcToUpdate.tableID] = append(ls, szcToUpdate) - } else { - subzoneUpdates[szcToUpdate.tableID] = []subzoneConfigToUpsert{szcToUpdate} + for id, szcs := range s.subzoneConfigsToDelete { + for _, toDelete := range szcs { + if err = c.DeleteSubzoneConfig( + ctx, id, toDelete.subzone, toDelete.subzoneSpans); err != nil { + return err + } } } - for id, updates := range subzoneUpdates { + for id, szcs := range s.modifiedSubzoneConfigs { zcToWrite, err := c.GetZoneConfig(ctx, id) if err != nil { return err } - for _, update := range updates { - zcToWrite, err = c.UpdateSubzoneConfig(ctx, zcToWrite, update.subzone, update.subzoneSpans) + for _, toUpdate := range szcs { + zcToWrite, err = c.UpdateSubzoneConfig(ctx, zcToWrite, toUpdate.subzone, + toUpdate.subzoneSpans, toUpdate.idxRefToDelete) if err != nil { return err } diff --git a/pkg/sql/schemachanger/scexec/mocks_generated_test.go b/pkg/sql/schemachanger/scexec/mocks_generated_test.go index ef914f7ae620..e543766290a5 100644 --- a/pkg/sql/schemachanger/scexec/mocks_generated_test.go +++ b/pkg/sql/schemachanger/scexec/mocks_generated_test.go @@ -114,6 +114,20 @@ func (mr *MockCatalogMockRecorder) DeleteName(arg0, arg1, arg2 interface{}) *gom return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteName", reflect.TypeOf((*MockCatalog)(nil).DeleteName), arg0, arg1, arg2) } +// DeleteSubzoneConfig mocks base method. +func (m *MockCatalog) DeleteSubzoneConfig(arg0 context.Context, arg1 catid.DescID, arg2 zonepb.Subzone, arg3 []zonepb.SubzoneSpan) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DeleteSubzoneConfig", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].(error) + return ret0 +} + +// DeleteSubzoneConfig indicates an expected call of DeleteSubzoneConfig. +func (mr *MockCatalogMockRecorder) DeleteSubzoneConfig(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteSubzoneConfig", reflect.TypeOf((*MockCatalog)(nil).DeleteSubzoneConfig), arg0, arg1, arg2, arg3) +} + // DeleteZoneConfig mocks base method. func (m *MockCatalog) DeleteZoneConfig(arg0 context.Context, arg1 catid.DescID) error { m.ctrl.T.Helper() @@ -260,18 +274,18 @@ func (mr *MockCatalogMockRecorder) UpdateComment(arg0, arg1, arg2 interface{}) * } // UpdateSubzoneConfig mocks base method. -func (m *MockCatalog) UpdateSubzoneConfig(arg0 context.Context, arg1 catalog.ZoneConfig, arg2 zonepb.Subzone, arg3 []zonepb.SubzoneSpan) (catalog.ZoneConfig, error) { +func (m *MockCatalog) UpdateSubzoneConfig(arg0 context.Context, arg1 catalog.ZoneConfig, arg2 zonepb.Subzone, arg3 []zonepb.SubzoneSpan, arg4 int32) (catalog.ZoneConfig, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateSubzoneConfig", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "UpdateSubzoneConfig", arg0, arg1, arg2, arg3, arg4) ret0, _ := ret[0].(catalog.ZoneConfig) ret1, _ := ret[1].(error) return ret0, ret1 } // UpdateSubzoneConfig indicates an expected call of UpdateSubzoneConfig. -func (mr *MockCatalogMockRecorder) UpdateSubzoneConfig(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { +func (mr *MockCatalogMockRecorder) UpdateSubzoneConfig(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateSubzoneConfig", reflect.TypeOf((*MockCatalog)(nil).UpdateSubzoneConfig), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateSubzoneConfig", reflect.TypeOf((*MockCatalog)(nil).UpdateSubzoneConfig), arg0, arg1, arg2, arg3, arg4) } // UpdateZoneConfig mocks base method. diff --git a/pkg/sql/schemachanger/scexec/scmutationexec/dependencies.go b/pkg/sql/schemachanger/scexec/scmutationexec/dependencies.go index 739774ebef69..5b79cb9514cb 100644 --- a/pkg/sql/schemachanger/scexec/scmutationexec/dependencies.go +++ b/pkg/sql/schemachanger/scexec/scmutationexec/dependencies.go @@ -82,15 +82,15 @@ type ImmediateMutationStateUpdater interface { UpdateZoneConfig(id descpb.ID, zc *zonepb.ZoneConfig) // UpdateSubzoneConfig upserts a subzone config. - UpdateSubzoneConfig( - tableid descpb.ID, - subzone zonepb.Subzone, - subzoneSpans []zonepb.SubzoneSpan, - ) + UpdateSubzoneConfig(tableID descpb.ID, subzone zonepb.Subzone, subzoneSpans []zonepb.SubzoneSpan, idxRefToDelete int32) // DeleteZoneConfig deletes the zone config for the given ID. DeleteZoneConfig(id descpb.ID) + // DeleteSubzoneConfig deletes the given subzone config for the given table + // ID. + DeleteSubzoneConfig(tableID descpb.ID, subzone zonepb.Subzone, subzoneSpans []zonepb.SubzoneSpan) + // Reset schedules a reset of the in-txn catalog state // to undo the modifications from earlier stages. Reset() diff --git a/pkg/sql/schemachanger/scexec/scmutationexec/index.go b/pkg/sql/schemachanger/scexec/scmutationexec/index.go index 94f805289b12..4a85646f0974 100644 --- a/pkg/sql/schemachanger/scexec/scmutationexec/index.go +++ b/pkg/sql/schemachanger/scexec/scmutationexec/index.go @@ -494,13 +494,15 @@ func (m *deferredVisitor) MaybeAddSplitForIndex( } func (i *immediateVisitor) AddIndexZoneConfig(_ context.Context, op scop.AddIndexZoneConfig) error { - i.ImmediateMutationStateUpdater.UpdateSubzoneConfig(op.TableID, op.Subzone, op.SubzoneSpans) + i.ImmediateMutationStateUpdater.UpdateSubzoneConfig( + op.TableID, op.Subzone, op.SubzoneSpans, op.SubzoneIndexToDelete) return nil } func (i *immediateVisitor) AddPartitionZoneConfig( _ context.Context, op scop.AddPartitionZoneConfig, ) error { - i.ImmediateMutationStateUpdater.UpdateSubzoneConfig(op.TableID, op.Subzone, op.SubzoneSpans) + i.ImmediateMutationStateUpdater.UpdateSubzoneConfig( + op.TableID, op.Subzone, op.SubzoneSpans, op.SubzoneIndexToDelete) return nil } diff --git a/pkg/sql/schemachanger/scexec/scmutationexec/zone_config.go b/pkg/sql/schemachanger/scexec/scmutationexec/zone_config.go index 47b58efb8247..8a336fa8ae5b 100644 --- a/pkg/sql/schemachanger/scexec/scmutationexec/zone_config.go +++ b/pkg/sql/schemachanger/scexec/scmutationexec/zone_config.go @@ -27,3 +27,10 @@ func (i *immediateVisitor) DiscardTableZoneConfig( } return nil } + +func (i *immediateVisitor) DiscardSubzoneConfig( + ctx context.Context, op scop.DiscardSubzoneConfig, +) error { + i.ImmediateMutationStateUpdater.DeleteSubzoneConfig(op.TableID, op.Subzone, op.SubzoneSpans) + return nil +} diff --git a/pkg/sql/schemachanger/scop/immediate_mutation.go b/pkg/sql/schemachanger/scop/immediate_mutation.go index 467bed436f34..39d9b43c94a4 100644 --- a/pkg/sql/schemachanger/scop/immediate_mutation.go +++ b/pkg/sql/schemachanger/scop/immediate_mutation.go @@ -1018,6 +1018,17 @@ type DiscardTableZoneConfig struct { ZoneConfig *zonepb.ZoneConfig } +// DiscardSubzoneConfig discards the subzone config for the given descriptor ID. +// If this is the only subzone for the table, we delete the entry from +// system.zones. +type DiscardSubzoneConfig struct { + immediateMutationOp + TableID descpb.ID + Subzone zonepb.Subzone + SubzoneSpans []zonepb.SubzoneSpan + SubzoneIndexToDelete int32 +} + // AddTableZoneConfig adds a zone config to a table. type AddTableZoneConfig struct { immediateMutationOp @@ -1028,15 +1039,17 @@ type AddTableZoneConfig struct { // AddIndexZoneConfig adds a zone config to an index. type AddIndexZoneConfig struct { immediateMutationOp - TableID descpb.ID - Subzone zonepb.Subzone - SubzoneSpans []zonepb.SubzoneSpan + TableID descpb.ID + Subzone zonepb.Subzone + SubzoneSpans []zonepb.SubzoneSpan + SubzoneIndexToDelete int32 } // AddPartitionZoneConfig adds a zone config to a partition. type AddPartitionZoneConfig struct { immediateMutationOp - TableID descpb.ID - Subzone zonepb.Subzone - SubzoneSpans []zonepb.SubzoneSpan + TableID descpb.ID + Subzone zonepb.Subzone + SubzoneSpans []zonepb.SubzoneSpan + SubzoneIndexToDelete int32 } diff --git a/pkg/sql/schemachanger/scop/immediate_mutation_visitor_generated.go b/pkg/sql/schemachanger/scop/immediate_mutation_visitor_generated.go index f238371ed885..f5dcffdb5390 100644 --- a/pkg/sql/schemachanger/scop/immediate_mutation_visitor_generated.go +++ b/pkg/sql/schemachanger/scop/immediate_mutation_visitor_generated.go @@ -149,6 +149,7 @@ type ImmediateMutationVisitor interface { AddDatabaseZoneConfig(context.Context, AddDatabaseZoneConfig) error DiscardZoneConfig(context.Context, DiscardZoneConfig) error DiscardTableZoneConfig(context.Context, DiscardTableZoneConfig) error + DiscardSubzoneConfig(context.Context, DiscardSubzoneConfig) error AddTableZoneConfig(context.Context, AddTableZoneConfig) error AddIndexZoneConfig(context.Context, AddIndexZoneConfig) error AddPartitionZoneConfig(context.Context, AddPartitionZoneConfig) error @@ -814,6 +815,11 @@ func (op DiscardTableZoneConfig) Visit(ctx context.Context, v ImmediateMutationV return v.DiscardTableZoneConfig(ctx, op) } +// Visit is part of the ImmediateMutationOp interface. +func (op DiscardSubzoneConfig) Visit(ctx context.Context, v ImmediateMutationVisitor) error { + return v.DiscardSubzoneConfig(ctx, op) +} + // Visit is part of the ImmediateMutationOp interface. func (op AddTableZoneConfig) Visit(ctx context.Context, v ImmediateMutationVisitor) error { return v.AddTableZoneConfig(ctx, op) diff --git a/pkg/sql/schemachanger/scpb/elements.proto b/pkg/sql/schemachanger/scpb/elements.proto index c933f50f3b71..acee26dddfc6 100644 --- a/pkg/sql/schemachanger/scpb/elements.proto +++ b/pkg/sql/schemachanger/scpb/elements.proto @@ -792,6 +792,7 @@ message IndexZoneConfig { // our solution is to drop the existing element and add a new element, with // different `seq_num`. uint32 seq_num = 6; + int32 old_idx_ref = 7; // In v24.3, we deprecated this field ID (previously: partition_name) in favor // of creating a new element that represents partitions -- // PartitionZoneConfig. @@ -809,6 +810,7 @@ message PartitionZoneConfig { // config, our solution is to drop the existing element and add a new element, // with different `seq_num`. uint32 seq_num = 6; + int32 old_idx_ref = 7; } // DatabaseData models what needs to be GCed when a database is dropped. diff --git a/pkg/sql/schemachanger/scpb/uml/table.puml b/pkg/sql/schemachanger/scpb/uml/table.puml index 8351452ec662..090fa61e3042 100644 --- a/pkg/sql/schemachanger/scpb/uml/table.puml +++ b/pkg/sql/schemachanger/scpb/uml/table.puml @@ -263,6 +263,7 @@ IndexZoneConfig : IndexID IndexZoneConfig : Subzone IndexZoneConfig : []SubzoneSpans IndexZoneConfig : SeqNum +IndexZoneConfig : OldIdxRef object LDRJobIDs @@ -295,6 +296,7 @@ PartitionZoneConfig : PartitionName PartitionZoneConfig : Subzone PartitionZoneConfig : []SubzoneSpans PartitionZoneConfig : SeqNum +PartitionZoneConfig : OldIdxRef object PrimaryIndex diff --git a/pkg/sql/schemachanger/scplan/internal/opgen/opgen_index_zone_config.go b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_index_zone_config.go index 3db2a4cb017a..369a6824c29a 100644 --- a/pkg/sql/schemachanger/scplan/internal/opgen/opgen_index_zone_config.go +++ b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_index_zone_config.go @@ -17,9 +17,10 @@ func init() { to(scpb.Status_PUBLIC, emit(func(this *scpb.IndexZoneConfig) *scop.AddIndexZoneConfig { return &scop.AddIndexZoneConfig{ - TableID: this.TableID, - Subzone: this.Subzone, - SubzoneSpans: this.SubzoneSpans, + TableID: this.TableID, + Subzone: this.Subzone, + SubzoneSpans: this.SubzoneSpans, + SubzoneIndexToDelete: this.OldIdxRef, } }), ), @@ -27,8 +28,12 @@ func init() { toAbsent( scpb.Status_PUBLIC, to(scpb.Status_ABSENT, - emit(func(this *scpb.IndexZoneConfig) *scop.NotImplementedForPublicObjects { - return notImplementedForPublicObjects(this) + emit(func(this *scpb.IndexZoneConfig) *scop.DiscardSubzoneConfig { + return &scop.DiscardSubzoneConfig{ + TableID: this.TableID, + Subzone: this.Subzone, + SubzoneSpans: this.SubzoneSpans, + } }), ), ), diff --git a/pkg/sql/schemachanger/scplan/internal/opgen/opgen_partition_zone_config.go b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_partition_zone_config.go index adfc47c2f067..9139abf35c53 100644 --- a/pkg/sql/schemachanger/scplan/internal/opgen/opgen_partition_zone_config.go +++ b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_partition_zone_config.go @@ -17,9 +17,10 @@ func init() { to(scpb.Status_PUBLIC, emit(func(this *scpb.PartitionZoneConfig) *scop.AddPartitionZoneConfig { return &scop.AddPartitionZoneConfig{ - TableID: this.TableID, - Subzone: this.Subzone, - SubzoneSpans: this.SubzoneSpans, + TableID: this.TableID, + Subzone: this.Subzone, + SubzoneSpans: this.SubzoneSpans, + SubzoneIndexToDelete: this.OldIdxRef, } }), ), @@ -27,8 +28,12 @@ func init() { toAbsent( scpb.Status_PUBLIC, to(scpb.Status_ABSENT, - emit(func(this *scpb.PartitionZoneConfig) *scop.NotImplementedForPublicObjects { - return notImplementedForPublicObjects(this) + emit(func(this *scpb.PartitionZoneConfig) *scop.DiscardSubzoneConfig { + return &scop.DiscardSubzoneConfig{ + TableID: this.TableID, + Subzone: this.Subzone, + SubzoneSpans: this.SubzoneSpans, + } }), ), ), diff --git a/pkg/sql/schemachanger/sctest_generated_test.go b/pkg/sql/schemachanger/sctest_generated_test.go index 0a508aac9311..e92626fd1358 100644 --- a/pkg/sql/schemachanger/sctest_generated_test.go +++ b/pkg/sql/schemachanger/sctest_generated_test.go @@ -99,6 +99,13 @@ func TestEndToEndSideEffects_alter_database_configure_zone_multiple(t *testing.T sctest.EndToEndSideEffects(t, path, sctest.SingleNodeTestClusterFactory{}) } +func TestEndToEndSideEffects_alter_index_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard" + sctest.EndToEndSideEffects(t, path, sctest.SingleNodeTestClusterFactory{}) +} + func TestEndToEndSideEffects_alter_named_range_configure_zone(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -659,6 +666,13 @@ func TestExecuteWithDMLInjection_alter_database_configure_zone_multiple(t *testi sctest.ExecuteWithDMLInjection(t, path, sctest.SingleNodeTestClusterFactory{}) } +func TestExecuteWithDMLInjection_alter_index_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard" + sctest.ExecuteWithDMLInjection(t, path, sctest.SingleNodeTestClusterFactory{}) +} + func TestExecuteWithDMLInjection_alter_named_range_configure_zone(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -1219,6 +1233,13 @@ func TestGenerateSchemaChangeCorpus_alter_database_configure_zone_multiple(t *te sctest.GenerateSchemaChangeCorpus(t, path, sctest.SingleNodeTestClusterFactory{}) } +func TestGenerateSchemaChangeCorpus_alter_index_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard" + sctest.GenerateSchemaChangeCorpus(t, path, sctest.SingleNodeTestClusterFactory{}) +} + func TestGenerateSchemaChangeCorpus_alter_named_range_configure_zone(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -1779,6 +1800,13 @@ func TestPause_alter_database_configure_zone_multiple(t *testing.T) { sctest.Pause(t, path, sctest.SingleNodeTestClusterFactory{}) } +func TestPause_alter_index_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard" + sctest.Pause(t, path, sctest.SingleNodeTestClusterFactory{}) +} + func TestPause_alter_named_range_configure_zone(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -2339,6 +2367,13 @@ func TestPauseMixedVersion_alter_database_configure_zone_multiple(t *testing.T) sctest.PauseMixedVersion(t, path, sctest.SingleNodeTestClusterFactory{}) } +func TestPauseMixedVersion_alter_index_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard" + sctest.PauseMixedVersion(t, path, sctest.SingleNodeTestClusterFactory{}) +} + func TestPauseMixedVersion_alter_named_range_configure_zone(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) @@ -2899,6 +2934,13 @@ func TestRollback_alter_database_configure_zone_multiple(t *testing.T) { sctest.Rollback(t, path, sctest.SingleNodeTestClusterFactory{}) } +func TestRollback_alter_index_configure_zone_discard(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + const path = "pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard" + sctest.Rollback(t, path, sctest.SingleNodeTestClusterFactory{}) +} + func TestRollback_alter_named_range_configure_zone(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard.definition b/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard.definition new file mode 100644 index 000000000000..1424245b2cd4 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard.definition @@ -0,0 +1,14 @@ +setup +CREATE TABLE t ( + id INT PRIMARY KEY, + data INT, + INDEX idx (data) +); +---- + +test +ALTER INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 11; +ALTER INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 12; +ALTER INDEX t@idx CONFIGURE ZONE USING num_replicas = 10; +ALTER INDEX t@t_pkey CONFIGURE ZONE DISCARD; +---- diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard.side_effects b/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard.side_effects new file mode 100644 index 000000000000..8fa2da90fcf4 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard.side_effects @@ -0,0 +1,80 @@ +/* setup */ +CREATE TABLE t ( + id INT PRIMARY KEY, + data INT, + INDEX idx (data) +); +---- +... ++object {100 101 t} -> 104 + +/* test */ +ALTER INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 11; +ALTER INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 12; +ALTER INDEX t@idx CONFIGURE ZONE USING num_replicas = 10; +ALTER INDEX t@t_pkey CONFIGURE ZONE DISCARD; +---- +begin transaction #1 +# begin StatementPhase +checking for feature: CONFIGURE ZONE +write *eventpb.SetZoneConfig to event log: + config: + options: + - num_replicas = 11 + target: INDEX defaultdb.public.t@t_pkey + resolvedOldConfig: 'range_min_bytes:134217728 range_max_bytes:536870912 gc: num_replicas:5 inherited_constraints:false null_voter_constraints_is_empty:true inherited_lease_preferences:false ' + sql: + descriptorId: 104 + statement: ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹11› + tag: CONFIGURE ZONE + user: root +## StatementPhase stage 1 of 1 with 1 MutationType op +upsert zone config for #104 +checking for feature: CONFIGURE ZONE +write *eventpb.SetZoneConfig to event log: + config: + options: + - num_replicas = 12 + target: INDEX defaultdb.public.t@t_pkey + resolvedOldConfig: 'range_min_bytes:134217728 range_max_bytes:536870912 gc: num_replicas:11 inherited_constraints:false null_voter_constraints_is_empty:true inherited_lease_preferences:false ' + sql: + descriptorId: 104 + statement: ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹12› + tag: CONFIGURE ZONE + user: root +## StatementPhase stage 1 of 1 with 1 MutationType op +upsert zone config for #104 +checking for feature: CONFIGURE ZONE +write *eventpb.SetZoneConfig to event log: + config: + options: + - num_replicas = 10 + target: INDEX defaultdb.public.t@idx + resolvedOldConfig: 'range_min_bytes:134217728 range_max_bytes:536870912 gc: num_replicas:5 inherited_constraints:false null_voter_constraints_is_empty:true inherited_lease_preferences:false subzones: num_replicas:11 inherited_constraints:false null_voter_constraints_is_empty:true inherited_lease_preferences:false > > ' + sql: + descriptorId: 104 + statement: ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹idx› CONFIGURE ZONE USING ‹num_replicas› = ‹10› + tag: CONFIGURE ZONE + user: root +## StatementPhase stage 1 of 1 with 1 MutationType op +upsert zone config for #104 +checking for feature: CONFIGURE ZONE +write *eventpb.RemoveZoneConfig to event log: + config: + target: INDEX defaultdb.public.t@t_pkey + sql: + descriptorId: 104 + statement: ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE DISCARD + tag: CONFIGURE ZONE + user: root +## StatementPhase stage 1 of 1 with 2 MutationType ops +# end StatementPhase +# begin PreCommitPhase +## 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 1 MutationType op +upsert zone config for #104 +persist all catalog changes to storage +# end PreCommitPhase +commit transaction #1 diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_1_of_4.explain b/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_1_of_4.explain new file mode 100644 index 000000000000..cd37c802db13 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_1_of_4.explain @@ -0,0 +1,28 @@ +/* setup */ +CREATE TABLE t ( + id INT PRIMARY KEY, + data INT, + INDEX idx (data) +); + +/* test */ +EXPLAIN (DDL) ALTER INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 11; +---- +Schema change plan for ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹11›; + ├── StatementPhase + │ └── Stage 1 of 1 in StatementPhase + │ ├── 1 element transitioning toward PUBLIC + │ │ └── ABSENT → PUBLIC IndexZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1} + │ └── 1 Mutation operation + │ └── AddIndexZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + └── PreCommitPhase + ├── Stage 1 of 2 in PreCommitPhase + │ ├── 1 element transitioning toward PUBLIC + │ │ └── PUBLIC → ABSENT IndexZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1} + │ └── 1 Mutation operation + │ └── UndoAllInTxnImmediateMutationOpSideEffects + └── Stage 2 of 2 in PreCommitPhase + ├── 1 element transitioning toward PUBLIC + │ └── ABSENT → PUBLIC IndexZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1} + └── 1 Mutation operation + └── AddIndexZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_1_of_4.explain_shape b/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_1_of_4.explain_shape new file mode 100644 index 000000000000..43abc9ebb61a --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_1_of_4.explain_shape @@ -0,0 +1,12 @@ +/* setup */ +CREATE TABLE t ( + id INT PRIMARY KEY, + data INT, + INDEX idx (data) +); + +/* test */ +EXPLAIN (DDL, SHAPE) ALTER INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 11; +---- +Schema change plan for ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹11›; + └── execute 1 system table mutations transaction diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_2_of_4.explain b/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_2_of_4.explain new file mode 100644 index 000000000000..c0b75e68cd7d --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_2_of_4.explain @@ -0,0 +1,32 @@ +/* setup */ +CREATE TABLE t ( + id INT PRIMARY KEY, + data INT, + INDEX idx (data) +); + +/* test */ +ALTER INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 11; +EXPLAIN (DDL) ALTER INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 12; +---- +Schema change plan for ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹12›; following ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹11›; + ├── StatementPhase + │ └── Stage 1 of 1 in StatementPhase + │ ├── 1 element transitioning toward PUBLIC + │ │ └── ABSENT → PUBLIC IndexZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 2} + │ └── 1 Mutation operation + │ └── AddIndexZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + └── PreCommitPhase + ├── Stage 1 of 2 in PreCommitPhase + │ ├── 2 elements transitioning toward PUBLIC + │ │ ├── PUBLIC → ABSENT IndexZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1} + │ │ └── PUBLIC → ABSENT IndexZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 2} + │ └── 1 Mutation operation + │ └── UndoAllInTxnImmediateMutationOpSideEffects + └── Stage 2 of 2 in PreCommitPhase + ├── 2 elements transitioning toward PUBLIC + │ ├── ABSENT → PUBLIC IndexZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1} + │ └── ABSENT → PUBLIC IndexZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 2} + └── 2 Mutation operations + ├── AddIndexZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + └── AddIndexZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_2_of_4.explain_shape b/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_2_of_4.explain_shape new file mode 100644 index 000000000000..c7d1c71f7733 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_2_of_4.explain_shape @@ -0,0 +1,13 @@ +/* setup */ +CREATE TABLE t ( + id INT PRIMARY KEY, + data INT, + INDEX idx (data) +); + +/* test */ +ALTER INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 11; +EXPLAIN (DDL, SHAPE) ALTER INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 12; +---- +Schema change plan for ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹12›; following ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹11›; + └── execute 1 system table mutations transaction diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_3_of_4.explain b/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_3_of_4.explain new file mode 100644 index 000000000000..91d1ed92be44 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_3_of_4.explain @@ -0,0 +1,36 @@ +/* setup */ +CREATE TABLE t ( + id INT PRIMARY KEY, + data INT, + INDEX idx (data) +); + +/* test */ +ALTER INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 11; +ALTER INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 12; +EXPLAIN (DDL) ALTER INDEX t@idx CONFIGURE ZONE USING num_replicas = 10; +---- +Schema change plan for ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹idx› CONFIGURE ZONE USING ‹num_replicas› = ‹10›; following ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹11›; ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹12›; + ├── StatementPhase + │ └── Stage 1 of 1 in StatementPhase + │ ├── 1 element transitioning toward PUBLIC + │ │ └── ABSENT → PUBLIC IndexZoneConfig:{DescID: 104 (t), IndexID: 2 (idx), SeqNum: 1} + │ └── 1 Mutation operation + │ └── AddIndexZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + └── PreCommitPhase + ├── Stage 1 of 2 in PreCommitPhase + │ ├── 3 elements transitioning toward PUBLIC + │ │ ├── PUBLIC → ABSENT IndexZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1} + │ │ ├── PUBLIC → ABSENT IndexZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 2} + │ │ └── PUBLIC → ABSENT IndexZoneConfig:{DescID: 104 (t), IndexID: 2 (idx), SeqNum: 1} + │ └── 1 Mutation operation + │ └── UndoAllInTxnImmediateMutationOpSideEffects + └── Stage 2 of 2 in PreCommitPhase + ├── 3 elements transitioning toward PUBLIC + │ ├── ABSENT → PUBLIC IndexZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1} + │ ├── ABSENT → PUBLIC IndexZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 2} + │ └── ABSENT → PUBLIC IndexZoneConfig:{DescID: 104 (t), IndexID: 2 (idx), SeqNum: 1} + └── 3 Mutation operations + ├── AddIndexZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + ├── AddIndexZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} + └── AddIndexZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_3_of_4.explain_shape b/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_3_of_4.explain_shape new file mode 100644 index 000000000000..a9edb2e5b778 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_3_of_4.explain_shape @@ -0,0 +1,14 @@ +/* setup */ +CREATE TABLE t ( + id INT PRIMARY KEY, + data INT, + INDEX idx (data) +); + +/* test */ +ALTER INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 11; +ALTER INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 12; +EXPLAIN (DDL, SHAPE) ALTER INDEX t@idx CONFIGURE ZONE USING num_replicas = 10; +---- +Schema change plan for ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹idx› CONFIGURE ZONE USING ‹num_replicas› = ‹10›; following ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹11›; ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹12›; + └── execute 1 system table mutations transaction diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_4_of_4.explain b/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_4_of_4.explain new file mode 100644 index 000000000000..f2e919c42781 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_4_of_4.explain @@ -0,0 +1,33 @@ +/* setup */ +CREATE TABLE t ( + id INT PRIMARY KEY, + data INT, + INDEX idx (data) +); + +/* test */ +ALTER INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 11; +ALTER INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 12; +ALTER INDEX t@idx CONFIGURE ZONE USING num_replicas = 10; +EXPLAIN (DDL) ALTER INDEX t@t_pkey CONFIGURE ZONE DISCARD; +---- +Schema change plan for ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE DISCARD; following ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹11›; ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹12›; ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹idx› CONFIGURE ZONE USING ‹num_replicas› = ‹10›; + ├── StatementPhase + │ └── Stage 1 of 1 in StatementPhase + │ ├── 2 elements transitioning toward ABSENT + │ │ ├── PUBLIC → ABSENT IndexZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 1} + │ │ └── PUBLIC → ABSENT IndexZoneConfig:{DescID: 104 (t), IndexID: 1 (t_pkey), SeqNum: 2} + │ └── 2 Mutation operations + │ ├── DiscardSubzoneConfig {"TableID":104} + │ └── DiscardSubzoneConfig {"TableID":104} + └── PreCommitPhase + ├── Stage 1 of 2 in PreCommitPhase + │ ├── 1 element transitioning toward PUBLIC + │ │ └── PUBLIC → ABSENT IndexZoneConfig:{DescID: 104 (t), IndexID: 2 (idx), SeqNum: 1} + │ └── 1 Mutation operation + │ └── UndoAllInTxnImmediateMutationOpSideEffects + └── Stage 2 of 2 in PreCommitPhase + ├── 1 element transitioning toward PUBLIC + │ └── ABSENT → PUBLIC IndexZoneConfig:{DescID: 104 (t), IndexID: 2 (idx), SeqNum: 1} + └── 1 Mutation operation + └── AddIndexZoneConfig {"SubzoneIndexToDelete":-1,"TableID":104} diff --git a/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_4_of_4.explain_shape b/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_4_of_4.explain_shape new file mode 100644 index 000000000000..e94c5f425328 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/alter_index_configure_zone_discard/alter_index_configure_zone_discard__statement_4_of_4.explain_shape @@ -0,0 +1,15 @@ +/* setup */ +CREATE TABLE t ( + id INT PRIMARY KEY, + data INT, + INDEX idx (data) +); + +/* test */ +ALTER INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 11; +ALTER INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 12; +ALTER INDEX t@idx CONFIGURE ZONE USING num_replicas = 10; +EXPLAIN (DDL, SHAPE) ALTER INDEX t@t_pkey CONFIGURE ZONE DISCARD; +---- +Schema change plan for ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE DISCARD; following ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹11›; ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹12›; ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹idx› CONFIGURE ZONE USING ‹num_replicas› = ‹10›; + └── execute 1 system table mutations transaction