diff --git a/pkg/bench/rttanalysis/testdata/benchmark_expectations b/pkg/bench/rttanalysis/testdata/benchmark_expectations index 1b26b43deabc..3dd3b6c0a3b2 100644 --- a/pkg/bench/rttanalysis/testdata/benchmark_expectations +++ b/pkg/bench/rttanalysis/testdata/benchmark_expectations @@ -12,9 +12,9 @@ exp,benchmark 18,AlterTableAddForeignKey/alter_table_add_2_foreign_keys 22,AlterTableAddForeignKey/alter_table_add_3_foreign_keys 14,AlterTableAddForeignKey/alter_table_add_foreign_key_with_3_columns -18,AlterTableConfigureZone/alter_table_configure_zone_5_replicas -18,AlterTableConfigureZone/alter_table_configure_zone_7_replicas_ -18,AlterTableConfigureZone/alter_table_configure_zone_ranges +15,AlterTableConfigureZone/alter_table_configure_zone_5_replicas +15,AlterTableConfigureZone/alter_table_configure_zone_7_replicas_ +15,AlterTableConfigureZone/alter_table_configure_zone_ranges 16,AlterTableDropColumn/alter_table_drop_1_column 16,AlterTableDropColumn/alter_table_drop_2_columns 16,AlterTableDropColumn/alter_table_drop_3_columns diff --git a/pkg/ccl/backupccl/restore_job.go b/pkg/ccl/backupccl/restore_job.go index aef2e2dde27d..ebb08244cafb 100644 --- a/pkg/ccl/backupccl/restore_job.go +++ b/pkg/ccl/backupccl/restore_job.go @@ -33,7 +33,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/sql" "github.com/cockroachdb/cockroach/pkg/sql/catalog" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/dbdesc" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descidgen" @@ -718,6 +717,7 @@ func createImportingDescriptors( err error, ) { details := r.job.Details().(jobspb.RestoreDetails) + const kvTrace = false var allMutableDescs []catalog.MutableDescriptor var databases []catalog.DatabaseDescriptor @@ -1075,7 +1075,7 @@ func createImportingDescriptors( db.AddSchemaToDatabase(sc.GetName(), descpb.DatabaseDescriptor_SchemaInfo{ID: sc.GetID()}) } if err := descsCol.WriteDescToBatch( - ctx, false /* kvTrace */, db, b, + ctx, kvTrace, db, b, ); err != nil { return err } @@ -1119,7 +1119,7 @@ func createImportingDescriptors( } typDesc.AddReferencingDescriptorID(table.GetID()) if err := descsCol.WriteDescToBatch( - ctx, false /* kvTrace */, typDesc, b, + ctx, kvTrace, typDesc, b, ); err != nil { return err } @@ -1977,6 +1977,7 @@ func (r *restoreResumer) publishDescriptors( // Write the new descriptors and flip state over to public so they can be // accessed. + const kvTrace = false // Pre-fetch all the descriptors into the collection to avoid doing // round-trips per descriptor. @@ -2086,7 +2087,7 @@ func (r *restoreResumer) publishDescriptors( d := desc.(catalog.MutableDescriptor) d.SetPublic() return descsCol.WriteDescToBatch( - ctx, false /* kvTrace */, d, b, + ctx, kvTrace, d, b, ) }); err != nil { return err @@ -2282,6 +2283,7 @@ func (r *restoreResumer) dropDescriptors( } b := txn.NewBatch() + const kvTrace = false // Collect the tables into mutable versions. mutableTables := make([]*tabledesc.Mutable, len(details.TableDescs)) @@ -2355,8 +2357,9 @@ func (r *restoreResumer) dropDescriptors( // data was never visible to users, and so we don't need to preserve MVCC // semantics. tableToDrop.DropTime = dropTime - - b.Del(catalogkeys.EncodeNameKey(codec, tableToDrop)) + if err := descsCol.DeleteNamespaceEntryToBatch(ctx, kvTrace, tableToDrop, b); err != nil { + return err + } descsCol.NotifyOfDeletedDescriptor(tableToDrop.GetID()) } @@ -2374,12 +2377,14 @@ func (r *restoreResumer) dropDescriptors( if err != nil { return err } - - b.Del(catalogkeys.EncodeNameKey(codec, typDesc)) mutType.SetDropped() - // Remove the system.descriptor entry. - b.Del(catalogkeys.MakeDescMetadataKey(codec, typDesc.ID)) - descsCol.NotifyOfDeletedDescriptor(mutType.GetID()) + + if err := descsCol.DeleteNamespaceEntryToBatch(ctx, kvTrace, typDesc, b); err != nil { + return err + } + if err := descsCol.DeleteDescToBatch(ctx, kvTrace, typDesc.GetID(), b); err != nil { + return err + } } for i := range details.FunctionDescs { @@ -2394,8 +2399,9 @@ func (r *restoreResumer) dropDescriptors( return err } mutFn.SetDropped() - b.Del(catalogkeys.MakeDescMetadataKey(codec, fnDesc.ID)) - descsCol.NotifyOfDeletedDescriptor(fnDesc.ID) + if err := descsCol.DeleteDescToBatch(ctx, kvTrace, fnDesc.ID, b); err != nil { + return err + } } // Queue a GC job. @@ -2474,9 +2480,12 @@ func (r *restoreResumer) dropDescriptors( } // Delete schema entries in descriptor and namespace system tables. - b.Del(catalogkeys.EncodeNameKey(codec, mutSchema)) - b.Del(catalogkeys.MakeDescMetadataKey(codec, mutSchema.GetID())) - descsCol.NotifyOfDeletedDescriptor(mutSchema.GetID()) + if err := descsCol.DeleteNamespaceEntryToBatch(ctx, kvTrace, mutSchema, b); err != nil { + return err + } + if err := descsCol.DeleteDescToBatch(ctx, kvTrace, mutSchema.GetID(), b); err != nil { + return err + } // Add dropped descriptor as uncommitted to satisfy descriptor validation. mutSchema.SetDropped() mutSchema.MaybeIncrementVersion() @@ -2510,7 +2519,7 @@ func (r *restoreResumer) dropDescriptors( for dbID, entry := range dbsWithDeletedSchemas { log.Infof(ctx, "deleting %d schema entries from database %d", len(entry.schemas), dbID) if err := descsCol.WriteDescToBatch( - ctx, false /* kvTrace */, entry.db, b, + ctx, kvTrace, entry.db, b, ); err != nil { return err } @@ -2546,26 +2555,25 @@ func (r *restoreResumer) dropDescriptors( if err := descsCol.AddUncommittedDescriptor(ctx, db); err != nil { return err } - - descKey := catalogkeys.MakeDescMetadataKey(codec, db.GetID()) - b.Del(descKey) - // We have explicitly to delete the system.namespace entry for the public schema // if the database does not have a public schema backed by a descriptor. - if !db.(catalog.DatabaseDescriptor).HasPublicSchemaWithDescriptor() { - b.Del(catalogkeys.MakeSchemaNameKey(codec, db.GetID(), tree.PublicSchema)) + if db := db.(catalog.DatabaseDescriptor); db.HasPublicSchemaWithDescriptor() { + if err := descsCol.DeleteDescriptorlessPublicSchemaToBatch(ctx, kvTrace, db, b); err != nil { + return err + } + } + if err := descsCol.DeleteNamespaceEntryToBatch(ctx, kvTrace, db, b); err != nil { + return err + } + if err := descsCol.DeleteDescToBatch(ctx, kvTrace, db.GetID(), b); err != nil { + return err } - - nameKey := catalogkeys.MakeDatabaseNameKey(codec, db.GetName()) - b.Del(nameKey) - descsCol.NotifyOfDeletedDescriptor(db.GetID()) deletedDBs[db.GetID()] = struct{}{} } // Avoid telling the descriptor collection about the mutated descriptors // until after all relevant relations have been retrieved to avoid a // scenario whereby we make a descriptor invalid too early. - const kvTrace = false for _, t := range mutableTables { if err := descsCol.WriteDescToBatch(ctx, kvTrace, t, b); err != nil { return errors.Wrap(err, "writing dropping table to batch") diff --git a/pkg/ccl/backupccl/restore_old_versions_test.go b/pkg/ccl/backupccl/restore_old_versions_test.go index 5e26c0c276c8..9f59175e36f0 100644 --- a/pkg/ccl/backupccl/restore_old_versions_test.go +++ b/pkg/ccl/backupccl/restore_old_versions_test.go @@ -893,7 +893,7 @@ func TestRestoreWithDroppedSchemaCorruption(t *testing.T) { hasSameNameSchema := func(dbName string) (exists bool) { require.NoError(t, sql.DescsTxn(ctx, &execCfg, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) error { // Using this method to avoid validation. - id, err := col.Direct().LookupDatabaseID(ctx, txn, dbName) + id, err := col.LookupDatabaseID(ctx, txn, dbName) if err != nil { return err } diff --git a/pkg/ccl/backupccl/restore_planning.go b/pkg/ccl/backupccl/restore_planning.go index 1a4646b98f45..11391ae084a0 100644 --- a/pkg/ccl/backupccl/restore_planning.go +++ b/pkg/ccl/backupccl/restore_planning.go @@ -288,7 +288,7 @@ func allocateDescriptorRewrites( if err := sql.DescsTxn(ctx, p.ExecCfg(), func(ctx context.Context, txn *kv.Txn, col *descs.Collection) error { // Check that any DBs being restored do _not_ exist. for name := range restoreDBNames { - dbID, err := col.Direct().LookupDatabaseID(ctx, txn, name) + dbID, err := col.LookupDatabaseID(ctx, txn, name) if err != nil { return err } @@ -365,7 +365,7 @@ func allocateDescriptorRewrites( } else { var parentID descpb.ID { - newParentID, err := col.Direct().LookupDatabaseID(ctx, txn, targetDB) + newParentID, err := col.LookupDatabaseID(ctx, txn, targetDB) if err != nil { return err } @@ -440,7 +440,7 @@ func allocateDescriptorRewrites( } // Look up the parent database's ID. - parentID, err := col.Direct().LookupDatabaseID(ctx, txn, targetDB) + parentID, err := col.LookupDatabaseID(ctx, txn, targetDB) if err != nil { return err } @@ -688,7 +688,7 @@ func allocateDescriptorRewrites( func getDatabaseIDAndDesc( ctx context.Context, txn *kv.Txn, col *descs.Collection, targetDB string, ) (dbID descpb.ID, dbDesc catalog.DatabaseDescriptor, err error) { - dbID, err = col.Direct().LookupDatabaseID(ctx, txn, targetDB) + dbID, err = col.LookupDatabaseID(ctx, txn, targetDB) if err != nil { return 0, nil, err } diff --git a/pkg/ccl/logictestccl/testdata/logic_test/multi_region b/pkg/ccl/logictestccl/testdata/logic_test/multi_region index d3538107adfb..a5bdf1c63004 100644 --- a/pkg/ccl/logictestccl/testdata/logic_test/multi_region +++ b/pkg/ccl/logictestccl/testdata/logic_test/multi_region @@ -108,9 +108,9 @@ JOIN system.namespace parent ON (e."parentID" = parent.id) WHERE e.name='crdb_internal_region' ---- parentSchemaID db_name enum_name -112 multi_region_test_db crdb_internal_region -116 multi_region_test_explicit_primary_region_db crdb_internal_region -108 region_test_db crdb_internal_region +111 multi_region_test_db crdb_internal_region +115 multi_region_test_explicit_primary_region_db crdb_internal_region +107 region_test_db crdb_internal_region query TTTT colnames SHOW ENUMS FROM region_test_db.public diff --git a/pkg/ccl/logictestccl/testdata/logic_test/regional_by_row_query_behavior b/pkg/ccl/logictestccl/testdata/logic_test/regional_by_row_query_behavior index 69184ab4ca00..19d0fb7515cb 100644 --- a/pkg/ccl/logictestccl/testdata/logic_test/regional_by_row_query_behavior +++ b/pkg/ccl/logictestccl/testdata/logic_test/regional_by_row_query_behavior @@ -804,7 +804,7 @@ SELECT * FROM [EXPLAIN (DISTSQL) SELECT * FROM child WHERE NOT EXISTS (SELECT * table: child@child_pkey spans: [/'ca-central-1'/10 - /'ca-central-1'/10] [/'us-east-1'/10 - /'us-east-1'/10] · -Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJysk2Fro04Qxt__P8Uwb5L82SOr8biyULC0hrN4ppcIV2gkWHdovdpdb1VIKfnuh5qjMVwC7eWNurPzuL9nePYVy185Clx4gXcZwf8wnc--wZ13exNc-CEMr_xFtPgejKDfkD5muYQfX725B8NwFoF32zTCsN9WJIZUte0rVpmEc0hXzcdoBBfhFQzTrmjxUQyz6XThRWAjQ6UlhckzlSju0MKYYWF0SmWpTVN6bRt8uUbBGWaqqKumHDNMtSEUr1hlVU4oMEruc5pTIsmMOTKUVCVZ3v629eC2z1XxRC_I8FLn9bMqBTRYbIuKDBdF0lTHS1wu12d8iWOLjzkkSoIFunokg_GGoa6rN5KySh4IhbVhH6O1TkDrbkkP0tkH6d6gSjJZkkOttJFkSPa44s1fbIT6ky7Gdt9AkD1nFVgHUfh7BnWtM7Wd06R_TPRSkIDAm0ZwEUY-XM_8EBl2SXS7158BBlo_1QX81JkCrQQMXQfOYT1w-EAI4VqcW_zLNqiuDefgTka7cy-6uRt5vzL0kGl10Nzkg-ac05prbvR6cLZrj8F6kPb8nsSw8x7DcyoLrUraS9ahnMQMST5Ql9JS1yalG6PT9phuOWt1bUFSWXW7drfwVbvV3stdsfUvYvuoeNIT833x5KjYOS52joo_74njzX-_AwAA__-DDeJX +Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJysk9Fro0AQxt_vrxjmJcmxR1bjQVkoWFrDWTzTS4QrNBKsO7Re7a63KqSU_O-HmqMxXALt5UXd2fnc3zd8-4rl7xwFLrzAu4zgM0zns-9w593eBBd-CMMrfxEtfgQj6Dekj1ku4ec3b-7BMJxF4N02jTDstxWJIVVt-4pVJuEc0lXzMRrBRXgFw7QrWnwUw2w6XXgR2MhQaUlh8kwliju0MGZYGJ1SWWrTlF7bBl-uUXCGmSrqqinHDFNtCMUrVlmVEwqMkvuc5pRIMmOODCVVSZa3v209uO1zVTzRCzK81Hn9rEoBDRbboiLDRZE01fESl8v1GV_i2OJjDomSYIGuHslgvGGo6-qNpKySB0JhbdjHaK0T0Lpb0oN09kG6N6iSTJbkUCttJBmSPa548w8bof6ii7HdNxBkz1kF1kEU_p5BXetMbec06R8TvRQkIPCmEVyEkQ_XMz9Ehl0S3e71d4CB1k91Ab90pkArAUPXgXNYDxw-EEK4FucWP9sG1bXhHNzJaHfuRTd3I-9Xhh4yrQ6am3zQnHNac82NXg_Odu0xWA_Snt-TGHbeY3hOZaFVSXvJOpSTmCHJB-pSWurapHRjdNoe0y1nra4tSCqrbtfuFr5qt9p7uSu2_kdsHxVPemK-L54cFTvHxc5R8dc9cbz59CcAAP__ibHiWg== statement ok SET vectorize=on @@ -881,7 +881,7 @@ SELECT * FROM [EXPLAIN (DISTSQL) SELECT * FROM child WHERE EXISTS (SELECT * FROM table: child@child_pkey spans: [/'ca-central-1'/10 - /'ca-central-1'/10] [/'us-east-1'/10 - /'us-east-1'/10] · -Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJysk1Fr2zAQx9_3KY57STI0IjuBFUHApXWYi5t0sWGFxgTXOlKvjuTJNqSEfPdhO1vrrCl024ttne5_-ul_5x0WPzIUGLi-exHCR5gu5tdw597e-OfeDPqXXhAGX_0BdBOShzST8O2Lu3DBva1zoN_NyGNDqjyk5KtUwgSSVf0xgPPZJfSTNmbxQQTz6TRwQ7CRodKSZvGGChR3aGHEMDc6oaLQpg7tmgRPblFwhqnKq7IORwwTbQjFDsu0zAgFhvF9RguKJZkhR4aSyjjNmrINvdM8V_kjPSHDC51VG1UIqLHYgRQZBnlcR4dLXC63Z3yJQ4sPOcRKggW6fCCD0Z6hrspnkqKM14TC2rO_o7X-A61zID1JZ5-ke4YqyKRxBpXSRpIh2eGK9q9cY6Y_6Xxody_gp5u0BOskCn-PUVc6VQefRt1jwqecBPjuNITAvfbgau7NkGE7iE77-mWgr_VjlcN3nSrQSkDfGcMEtr0x7wkhHItzi38-DKpjwwSc0QAZLmijS4LsFXX9s2x7Zy_1DLa9pFPwz4q_O5m3nTTyfmVonWp10q7Re-xaUJFrVdBR6041ImJIck3tGBS6MgndGJ00x7TLeaNrApKKst2124Wnmq1m8F-KrX8R22-KRx0xPxaP3hSPj8TR_sPPAAAA__9GoJgk +Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJysk9Fro04Qx99_f8UwL0l-7JHV5CEsBCyt4Sw26UXhCo0E6w6pV7PrrQopIf_7oeauNdcUencv6s7Od_az3xn3WHzPUGDg-u5lCP_DbLm4gXv37ta_8ObQv_KCMPjiD6CbkDymmYSvn92lC-5dnQP9bkYeG1LlMSVfpxKmkKzrjwFczK-gn7Qxiw8iWMxmgRuCjQyVljSPt1SguEcLI4a50QkVhTZ1aN8keHKHgjNMVV6VdThimGhDKPZYpmVGKDCMHzJaUizJDDkylFTGadaUbeid5rnOn-gZGV7qrNqqQkCNxY6kyDDI4zo6XOFqtZvwFQ4tPuQQKwkW6PKRDEYHhroqX0iKMt4QCuvA_ozW-ge0zpH0LJ19lu4FqiCTxhlUShtJhmSHKzq8cY25_qTzod29gJ9u0xKssyj8I0Zd61QdfRp1jwmfcxLgu7MQAvfGg-uFN0eG7SA67eungb7WT1UO33SqQCsBfWcMU9j1xrwnhHAszi0-OQ6qY8MUnNEAGS5pq0uC7A11_bPsepPXega7XtIp-HvFX53M204a-bA2tEm1OmvX6CN2LanItSropHXnGhExJLmhdgwKXZmEbo1OmmPa5aLRNQFJRdnu2u3CU81WM_ivxdbfiO13xaOOmJ-KR--Kxyfi6PDfjwAAAP__S-6YJw== statement ok SET vectorize=on @@ -959,7 +959,7 @@ SELECT * FROM [EXPLAIN (DISTSQL) SELECT * FROM child INNER JOIN parent ON p_id = table: child@child_pkey spans: [/'ca-central-1'/10 - /'ca-central-1'/10] [/'us-east-1'/10 - /'us-east-1'/10] · -Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJysk2Fr2zwQgL-_v-K4L2lfNCLbgRVBwKV1mEtmd05gg8YE1zpSr47kyTJkhPz3ETtb66wpdNsX2zrpOT26k7dYfytR4CyYBldz-B8mSfwR7oIvt9PLMIKz63A2n32ankN_Qf5QlBLCKAoSuInDCKrMkLIQR1AtCwljyJftx-cPQRJA3sUcnkI8mcyCObjIUGlJUbamGsUdOpgyrIzOqa612Ye27YJQblBwhoWqGrsPpwxzbQjFFm1hS0KB8-y-pIQySWbIkaEkmxVlm7YV9dvnsnqk78jwSpfNWtWitWIHUWQ4q7J9dLjAxWJzwRc4dPiQQ6YkOKDtAxlMdwx1Y59MaputCIWzY39m6_wDW_9getLOPWn3JFWTKbISGqWNJEOy55XuXjhGpN_pauj2DzAt1oUF56QKf0uhbnShDnXy-tt0t83vXj8rNdX6sangqy4UaCXgzB_BGDaDER8IIXyHc4e_P4fL6BrOfBfG4HvnyDChtbYE5Qv0_gfYDC6e8ww2g7yX8PeMv1pWdS0z8n5paFVohQzjxgrwHea7zPdO1sl7S50Sqiutajrq2akOpAxJrqjrf60bk9Ot0Xm7TTeMW64NSKptN-t2g1C1U-2Nfw47fwO7r8JeD-bHsPcqPDqC091_PwIAAP__n0qQmg== +Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJysk1Fr2zAQgN_3K457STs0Itt9CIKAS-swl8zunMAGjQmudaReHcmTZcgI-e8jdrbWWVPothfbOuk7fbqTt1h_L1HgLJgGV3N4D5Mk_gR3wdfb6WUYwdl1OJvPPk_Pob8gfyhKCWEUBQncxGEEVWZIWYgjqJaFhDHky_bjy8cgCSDvYg5PIZ5MZsEcXGSotKQoW1ON4g4dTBlWRudU19rsQ9t2QSg3KDjDQlWN3YdThrk2hGKLtrAlocB5dl9SQpkkM-TIUJLNirJN24r67XNZPdIPZHily2atatFasYMoMpxV2T46XOBisRnxBQ4dPuSQKQkOaPtABtMdQ93YJ5PaZitC4ezY39k6_8HWP5ietHNP2j1J1WSKrIRGaSPJkOx5pbsXjhHpD7oauv0DTIt1YcE5qcLfUqgbXahDnbz-Nt1t87vXr0pNtX5sKvimCwVaCTjzL2AMm8EFHwghfIdzh4_O4TK6hjPfhTH43jkyTGitLUH5Ar3_ATaD0XOewWaQ9xL-mfF3y6quZUbeLw2tCq2QYdxYAb7DfJf53sk6eW-pU0J1pVVNRz071YGUIckVdf2vdWNyujU6b7fphnHLtQFJte1m3W4QqnaqvfHPYedfYPdV2OvB_Bj2XoUvjuB09-5nAAAA__-kyJCd statement ok SET vectorize=on @@ -1037,7 +1037,7 @@ SELECT * FROM [EXPLAIN (DISTSQL) SELECT * FROM child LEFT JOIN parent ON p_id = table: child@child_pkey spans: [/'ca-central-1'/10 - /'ca-central-1'/10] [/'us-east-1'/10 - /'us-east-1'/10] · -Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJysk2Fr2zwQx98_n-K4N2kfNCI7hRVBwaV1WIpnd47HBo0JrnW0Xh3Jk2VIKfnuI3K31llT6LY3tnTS__TT_04P2H6vUeA8jMKzDP6HaZp8hKvw62V0Oovh4Hw2z-afokMYbihvq1pCFE4zuEhmMTSFIWUhiaFZVhJOoFy6wZcPYRpC2cc8nkMync7DDHxkqLSkuFhRi-IKPcwZNkaX1LbabEMPbsNMrlFwhpVqOrsN5wxLbQjFA9rK1oQCs-K6ppQKSWbMkaEkW1S1S-s4A_ddNnd0jwzPdN2tVCscFXsERYbzpthGxwtcLNbHfIFjj485FEqCB9reksF8w1B39omktcUNofA27M9ovX9AGzyS7qXz99I9QbVkqqKGTmkjyZAccOWbF64R63e6GfvDC0TVqrLg7UXhbzHqQlfq0afJ8JjsviHRd1_yOQtT14PIsO_CoP_9dDDS-q5r4JuuFGgl4CA4ghNYj474SAgReJx7_P0hnMbncBD4cALB5BAZprTSlqB-Qb19F-vR8XM9g_WoHCT8PeOvUjZ9KY28Xhq6qbRChklnBQQeC3wWTPb6N3mLfym1jVYt7dRyX2VyhiRvqO-LVnempEujS3dMP02czgUktbZf9fvJTLkl9xKei72_EfuviicDMd8VT14VH-2I881_PwIAAP__xyaW3w== +Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJysk1Fr2zAQx9_3KY57STs0Ijt9KIKCS-uwFM_uHI8NGhNc62i9OpIny5BS8t1H5G6ts6bQbS-2dNL_9NP_Tg_Y_qhR4DyMwrMM3sM0TT7BVfjtMjqdxXBwPptn88_RIQw3lLdVLSEKpxlcJLMYmsKQspDE0CwrCSdQLt3g68cwDaHsYx7PIZlO52EGPjJUWlJcrKhFcYUe5gwbo0tqW222oQe3YSbXKDjDSjWd3YZzhqU2hOIBbWVrQoFZcV1TSoUkM-bIUJItqtqldZyB-y6bO7pHhme67laqFY6KPYIiw3lTbKPjBS4W62O-wLHHxxwKJcEDbW_JYL5hqDv7RNLa4oZQeBv2d7Tef6ANHkn30vl76Z6gWjJVUUOntJFkSA648s0L14j1B92M_eEFompVWfD2ovC3GHWhK_Xo02R4THbfkOi7L_mShanrQWTYd2HQ_345GGl91zXwXVcKtBJwEBzBCaxHR3wkhAg8zj1-fAin8TkcBD6cQDA5RIYprbQlqF9Qb9_FenT8XM9gPSoHCf_M-LuUTV9KI6-Xhm4qrZBh0lkBgccCnwWTvf5N3uJfSm2jVUs7tdxXmZwhyRvq-6LVnSnp0ujSHdNPE6dzAUmt7Vf9fjJTbsm9hOdi71_E_qviyUDMd8WTV8VHO-J88-5nAAAA___MpJbi statement ok SET vectorize=on diff --git a/pkg/ccl/schemachangerccl/testdata/decomp/multiregion b/pkg/ccl/schemachangerccl/testdata/decomp/multiregion index 03a5c8e55a6e..1262e4921760 100644 --- a/pkg/ccl/schemachangerccl/testdata/decomp/multiregion +++ b/pkg/ccl/schemachangerccl/testdata/decomp/multiregion @@ -18,7 +18,7 @@ decompose multi_region_test_db ---- BackReferencedIDs: - - 106 + - 105 ElementState: - Database: databaseId: 104 @@ -50,7 +50,7 @@ ElementState: Status: PUBLIC - DatabaseRegionConfig: databaseId: 104 - regionEnumTypeId: 105 + regionEnumTypeId: 106 Status: PUBLIC - DatabaseRoleSetting: databaseId: 104 @@ -303,7 +303,7 @@ ElementState: databaseId: 104 descriptorId: 110 name: table_global - schemaId: 106 + schemaId: 105 Status: PUBLIC - Owner: descriptorId: 110 @@ -321,7 +321,7 @@ ElementState: Status: PUBLIC - ObjectParent: objectId: 110 - parentSchemaId: 106 + parentSchemaId: 105 Status: PUBLIC decompose @@ -400,7 +400,7 @@ ElementState: tableId: 109 Status: PUBLIC - TableLocalitySecondaryRegion: - regionEnumTypeId: 105 + regionEnumTypeId: 106 regionName: us-east2 tableId: 109 Status: PUBLIC @@ -565,7 +565,7 @@ ElementState: databaseId: 104 descriptorId: 109 name: table_regional_by_table - schemaId: 106 + schemaId: 105 Status: PUBLIC - Owner: descriptorId: 109 @@ -583,7 +583,7 @@ ElementState: Status: PUBLIC - ObjectParent: objectId: 109 - parentSchemaId: 106 + parentSchemaId: 105 Status: PUBLIC decompose @@ -709,7 +709,7 @@ ElementState: Status: PUBLIC - ColumnType: closedTypeIds: - - 105 + - 106 - 107 columnId: 3 computeExpr: null @@ -725,7 +725,7 @@ ElementState: geoMetadata: null intervalDurationField: null locale: null - oid: 100105 + oid: 100106 precision: 0 timePrecisionIsSet: false tupleContents: [] @@ -837,12 +837,12 @@ ElementState: Status: PUBLIC - ColumnDefaultExpression: columnId: 3 - expr: default_to_database_primary_region(gateway_region())::@100105 + expr: default_to_database_primary_region(gateway_region())::@100106 referencedColumnIds: [] tableId: 108 usesSequenceIds: [] usesTypeIds: - - 105 + - 106 - 107 Status: PUBLIC - ColumnComment: @@ -932,7 +932,7 @@ ElementState: databaseId: 104 descriptorId: 108 name: table_regional_by_row - schemaId: 106 + schemaId: 105 Status: PUBLIC - Owner: descriptorId: 108 @@ -950,7 +950,7 @@ ElementState: Status: PUBLIC - ObjectParent: objectId: 108 - parentSchemaId: 106 + parentSchemaId: 105 Status: PUBLIC decompose @@ -963,49 +963,49 @@ ElementState: - EnumType: arrayTypeId: 107 isMultiRegion: true - typeId: 105 + typeId: 106 Status: PUBLIC - Namespace: databaseId: 104 - descriptorId: 105 + descriptorId: 106 name: crdb_internal_region - schemaId: 106 + schemaId: 105 Status: PUBLIC - Owner: - descriptorId: 105 + descriptorId: 106 owner: root Status: PUBLIC - UserPrivileges: - descriptorId: 105 + descriptorId: 106 privileges: 2 userName: admin Status: PUBLIC - UserPrivileges: - descriptorId: 105 + descriptorId: 106 privileges: 2 userName: root Status: PUBLIC - UserPrivileges: - descriptorId: 105 + descriptorId: 106 privileges: 512 userName: public Status: PUBLIC - ObjectParent: - objectId: 105 - parentSchemaId: 106 + objectId: 106 + parentSchemaId: 105 Status: PUBLIC - EnumTypeValue: logicalRepresentation: us-east1 physicalRepresentation: QA== - typeId: 105 + typeId: 106 Status: PUBLIC - EnumTypeValue: logicalRepresentation: us-east2 physicalRepresentation: gA== - typeId: 105 + typeId: 106 Status: PUBLIC - EnumTypeValue: logicalRepresentation: us-east3 physicalRepresentation: wA== - typeId: 105 + typeId: 106 Status: PUBLIC diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_database_multiregion_primary_region b/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_database_multiregion_primary_region index ef03602124d8..549dee14e60e 100644 --- a/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_database_multiregion_primary_region +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_database_multiregion_primary_region @@ -6,10 +6,10 @@ CREATE TABLE multi_region_test_db.public.table_regional_by_table ( ---- ... +database {0 0 multi_region_test_db} -> 104 -+object {104 106 crdb_internal_region} -> 105 -+schema {104 0 public} -> 106 -+object {104 106 _crdb_internal_region} -> 107 -+object {104 106 table_regional_by_table} -> 108 ++schema {104 0 public} -> 105 ++object {104 105 crdb_internal_region} -> 106 ++object {104 105 _crdb_internal_region} -> 107 ++object {104 105 table_regional_by_table} -> 108 test DROP DATABASE multi_region_test_db CASCADE @@ -29,12 +29,12 @@ add synthetic descriptor #104: privileges: ... public: - id: 106 + id: 105 + state: DROP version: "1" -add synthetic descriptor #106: +add synthetic descriptor #105: schema: - id: 106 + id: 105 - modificationTime: {} + modificationTime: + wallTime: "1640995200000000001" @@ -45,9 +45,9 @@ add synthetic descriptor #106: version: 2 + state: DROP version: "1" -add synthetic descriptor #105: +add synthetic descriptor #106: ... - id: 105 + id: 106 kind: MULTIREGION_ENUM - modificationTime: {} + modificationTime: @@ -86,16 +86,16 @@ add synthetic descriptor #108: replacementOf: time: {} + state: DROP - unexposedParentSchemaId: 106 + unexposedParentSchemaId: 105 version: "1" # end StatementPhase # begin PreCommitPhase ## PreCommitPhase stage 1 of 1 with 23 MutationType ops delete database namespace entry {0 0 multi_region_test_db} -> 104 -delete object namespace entry {104 106 crdb_internal_region} -> 105 -delete schema namespace entry {104 0 public} -> 106 -delete object namespace entry {104 106 _crdb_internal_region} -> 107 -delete object namespace entry {104 106 table_regional_by_table} -> 108 +delete schema namespace entry {104 0 public} -> 105 +delete object namespace entry {104 105 crdb_internal_region} -> 106 +delete object namespace entry {104 105 _crdb_internal_region} -> 107 +delete object namespace entry {104 105 table_regional_by_table} -> 108 upsert descriptor #104 database: + declarativeSchemaChangerState: @@ -114,13 +114,12 @@ upsert descriptor #104 modificationTime: {} ... public: - id: 106 + id: 105 - version: "1" + state: DROP + version: "2" upsert descriptor #105 - type: - arrayTypeId: 107 + schema: + declarativeSchemaChangerState: + authorization: + userName: root @@ -133,16 +132,17 @@ upsert descriptor #105 + statementTag: DROP DATABASE + targetRanks: + targets: - enumMembers: - - logicalRepresentation: us-east1 + id: 105 + modificationTime: {} ... - primaryRegion: us-east1 - zoneConfigExtensions: {} - - version: "2" + withGrantOption: 2 + version: 2 + - version: "1" + state: DROP - + version: "3" + + version: "2" upsert descriptor #106 - schema: + type: + arrayTypeId: 107 + declarativeSchemaChangerState: + authorization: + userName: root @@ -155,14 +155,14 @@ upsert descriptor #106 + statementTag: DROP DATABASE + targetRanks: + targets: - id: 106 - modificationTime: {} + enumMembers: + - logicalRepresentation: us-east1 ... - withGrantOption: 2 - version: 2 - - version: "1" + primaryRegion: us-east1 + zoneConfigExtensions: {} + - version: "2" + state: DROP - + version: "2" + + version: "3" upsert descriptor #107 ... family: ArrayFamily @@ -210,7 +210,7 @@ upsert descriptor #108 replacementOf: time: {} + state: DROP - unexposedParentSchemaId: 106 + unexposedParentSchemaId: 105 - version: "1" + version: "2" delete all comments for table descriptors [108] @@ -245,7 +245,7 @@ upsert descriptor #108 families: ... state: DROP - unexposedParentSchemaId: 106 + unexposedParentSchemaId: 105 - version: "2" + version: "3" delete descriptor #104 diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_table_multiregion b/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_table_multiregion index 794c2117de6d..41b20ca6f6ad 100644 --- a/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_table_multiregion +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_table_multiregion @@ -6,10 +6,10 @@ CREATE TABLE multi_region_test_db.public.table_regional_by_row ( ---- ... +database {0 0 multi_region_test_db} -> 104 -+object {104 106 crdb_internal_region} -> 105 -+schema {104 0 public} -> 106 -+object {104 106 _crdb_internal_region} -> 107 -+object {104 106 table_regional_by_row} -> 108 ++schema {104 0 public} -> 105 ++object {104 105 crdb_internal_region} -> 106 ++object {104 105 _crdb_internal_region} -> 107 ++object {104 105 table_regional_by_row} -> 108 test DROP TABLE multi_region_test_db.public.table_regional_by_row; @@ -32,13 +32,13 @@ add synthetic descriptor #108: replacementOf: time: {} + state: DROP - unexposedParentSchemaId: 106 + unexposedParentSchemaId: 105 version: "1" # end StatementPhase # begin PreCommitPhase ## PreCommitPhase stage 1 of 1 with 15 MutationType ops -delete object namespace entry {104 106 table_regional_by_row} -> 108 -upsert descriptor #105 +delete object namespace entry {104 105 table_regional_by_row} -> 108 +upsert descriptor #106 type: arrayTypeId: 107 + declarativeSchemaChangerState: @@ -97,12 +97,12 @@ upsert descriptor #108 replacementOf: time: {} + state: DROP - unexposedParentSchemaId: 106 + unexposedParentSchemaId: 105 - version: "1" + version: "2" delete all comments for table descriptors [108] create job #1 (non-cancelable: true): "DROP TABLE multi_region_test_db.public.table_regional_by_row" - descriptor IDs: [105 107 108] + descriptor IDs: [106 107 108] # end PreCommitPhase commit transaction #1 notified job registry to adopt jobs: [1] @@ -111,7 +111,7 @@ begin transaction #2 commit transaction #2 begin transaction #3 ## PostCommitNonRevertiblePhase stage 1 of 1 with 7 MutationType ops -upsert descriptor #105 +upsert descriptor #106 type: arrayTypeId: 107 - declarativeSchemaChangerState: @@ -160,7 +160,7 @@ upsert descriptor #108 families: ... state: DROP - unexposedParentSchemaId: 106 + unexposedParentSchemaId: 105 - version: "2" + version: "3" write *eventpb.DropTable to event log: DROP TABLE ‹multi_region_test_db›.‹public›.‹table_regional_by_row› diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_table_multiregion_primary_region b/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_table_multiregion_primary_region index 1e68ccfb5be0..66fa5599f01b 100644 --- a/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_table_multiregion_primary_region +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_table_multiregion_primary_region @@ -6,10 +6,10 @@ CREATE TABLE multi_region_test_db.public.table_regional_by_table ( ---- ... +database {0 0 multi_region_test_db} -> 104 -+object {104 106 crdb_internal_region} -> 105 -+schema {104 0 public} -> 106 -+object {104 106 _crdb_internal_region} -> 107 -+object {104 106 table_regional_by_table} -> 108 ++schema {104 0 public} -> 105 ++object {104 105 crdb_internal_region} -> 106 ++object {104 105 _crdb_internal_region} -> 107 ++object {104 105 table_regional_by_table} -> 108 test DROP TABLE multi_region_test_db.public.table_regional_by_table CASCADE @@ -32,13 +32,13 @@ add synthetic descriptor #108: replacementOf: time: {} + state: DROP - unexposedParentSchemaId: 106 + unexposedParentSchemaId: 105 version: "1" # end StatementPhase # begin PreCommitPhase ## PreCommitPhase stage 1 of 1 with 10 MutationType ops -delete object namespace entry {104 106 table_regional_by_table} -> 108 -upsert descriptor #105 +delete object namespace entry {104 105 table_regional_by_table} -> 108 +upsert descriptor #106 type: arrayTypeId: 107 + declarativeSchemaChangerState: @@ -82,12 +82,12 @@ upsert descriptor #108 replacementOf: time: {} + state: DROP - unexposedParentSchemaId: 106 + unexposedParentSchemaId: 105 - version: "1" + version: "2" delete all comments for table descriptors [108] create job #1 (non-cancelable: true): "DROP TABLE multi_region_test_db.public.table_regional_by_table CASCADE" - descriptor IDs: [105 108] + descriptor IDs: [106 108] # end PreCommitPhase commit transaction #1 notified job registry to adopt jobs: [1] @@ -96,7 +96,7 @@ begin transaction #2 commit transaction #2 begin transaction #3 ## PostCommitNonRevertiblePhase stage 1 of 1 with 6 MutationType ops -upsert descriptor #105 +upsert descriptor #106 type: arrayTypeId: 107 - declarativeSchemaChangerState: @@ -132,7 +132,7 @@ upsert descriptor #108 families: ... state: DROP - unexposedParentSchemaId: 106 + unexposedParentSchemaId: 105 - version: "2" + version: "3" write *eventpb.DropTable to event log: DROP TABLE ‹multi_region_test_db›.‹public›.‹table_regional_by_table› CASCADE diff --git a/pkg/ccl/schemachangerccl/testdata/explain/drop_database_multiregion_primary_region b/pkg/ccl/schemachangerccl/testdata/explain/drop_database_multiregion_primary_region index 95a97d862920..fb478f588d82 100644 --- a/pkg/ccl/schemachangerccl/testdata/explain/drop_database_multiregion_primary_region +++ b/pkg/ccl/schemachangerccl/testdata/explain/drop_database_multiregion_primary_region @@ -12,9 +12,9 @@ Schema change plan for DROP DATABASE ‹multi_region_test_db› CASCADE; │ └── Stage 1 of 1 in StatementPhase │ ├── 9 elements transitioning toward ABSENT │ │ ├── PUBLIC → TXN_DROPPED Database:{DescID: 104} - │ │ ├── PUBLIC → TXN_DROPPED Schema:{DescID: 106} - │ │ ├── PUBLIC → TXN_DROPPED EnumType:{DescID: 105} - │ │ ├── PUBLIC → TXN_DROPPED AliasType:{DescID: 107, ReferencedTypeIDs: [105 107]} + │ │ ├── PUBLIC → TXN_DROPPED Schema:{DescID: 105} + │ │ ├── PUBLIC → TXN_DROPPED EnumType:{DescID: 106} + │ │ ├── PUBLIC → TXN_DROPPED AliasType:{DescID: 107, ReferencedTypeIDs: [106 107]} │ │ ├── PUBLIC → TXN_DROPPED Table:{DescID: 108} │ │ ├── PUBLIC → WRITE_ONLY Column:{DescID: 108, ColumnID: 1} │ │ ├── PUBLIC → WRITE_ONLY Column:{DescID: 108, ColumnID: 4294967295} @@ -22,8 +22,8 @@ Schema change plan for DROP DATABASE ‹multi_region_test_db› CASCADE; │ │ └── PUBLIC → VALIDATED PrimaryIndex:{DescID: 108, IndexID: 1, ConstraintID: 1} │ └── 5 Mutation operations │ ├── MarkDescriptorAsSyntheticallyDropped {"DescriptorID":104} - │ ├── MarkDescriptorAsSyntheticallyDropped {"DescriptorID":106} │ ├── MarkDescriptorAsSyntheticallyDropped {"DescriptorID":105} + │ ├── MarkDescriptorAsSyntheticallyDropped {"DescriptorID":106} │ ├── MarkDescriptorAsSyntheticallyDropped {"DescriptorID":107} │ └── MarkDescriptorAsSyntheticallyDropped {"DescriptorID":108} ├── PreCommitPhase @@ -36,38 +36,38 @@ Schema change plan for DROP DATABASE ‹multi_region_test_db› CASCADE; │ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 104, Name: root} │ │ ├── TXN_DROPPED → DROPPED Database:{DescID: 104} │ │ ├── PUBLIC → ABSENT DatabaseRoleSetting:{DescID: 104, Name: __placeholder_role_name__} - │ │ ├── PUBLIC → ABSENT DatabaseRegionConfig:{DescID: 104, ReferencedDescID: 105} - │ │ ├── PUBLIC → ABSENT Namespace:{DescID: 106, Name: public, ReferencedDescID: 104} - │ │ ├── PUBLIC → ABSENT Owner:{DescID: 106} - │ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 106, Name: admin} - │ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 106, Name: public} - │ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 106, Name: root} - │ │ ├── TXN_DROPPED → DROPPED Schema:{DescID: 106} - │ │ ├── PUBLIC → ABSENT SchemaParent:{DescID: 106, ReferencedDescID: 104} - │ │ ├── PUBLIC → ABSENT Namespace:{DescID: 105, Name: crdb_internal_region, ReferencedDescID: 104} + │ │ ├── PUBLIC → ABSENT DatabaseRegionConfig:{DescID: 104, ReferencedDescID: 106} + │ │ ├── PUBLIC → ABSENT Namespace:{DescID: 105, Name: public, ReferencedDescID: 104} │ │ ├── PUBLIC → ABSENT Owner:{DescID: 105} │ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 105, Name: admin} │ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 105, Name: public} │ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 105, Name: root} - │ │ ├── TXN_DROPPED → DROPPED EnumType:{DescID: 105} - │ │ ├── PUBLIC → ABSENT EnumTypeValue:{DescID: 105, Name: us-east1} - │ │ ├── PUBLIC → ABSENT EnumTypeValue:{DescID: 105, Name: us-east2} - │ │ ├── PUBLIC → ABSENT EnumTypeValue:{DescID: 105, Name: us-east3} - │ │ ├── PUBLIC → ABSENT ObjectParent:{DescID: 105, ReferencedDescID: 106} + │ │ ├── TXN_DROPPED → DROPPED Schema:{DescID: 105} + │ │ ├── PUBLIC → ABSENT SchemaParent:{DescID: 105, ReferencedDescID: 104} + │ │ ├── PUBLIC → ABSENT Namespace:{DescID: 106, Name: crdb_internal_region, ReferencedDescID: 104} + │ │ ├── PUBLIC → ABSENT Owner:{DescID: 106} + │ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 106, Name: admin} + │ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 106, Name: public} + │ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 106, Name: root} + │ │ ├── TXN_DROPPED → DROPPED EnumType:{DescID: 106} + │ │ ├── PUBLIC → ABSENT EnumTypeValue:{DescID: 106, Name: us-east1} + │ │ ├── PUBLIC → ABSENT EnumTypeValue:{DescID: 106, Name: us-east2} + │ │ ├── PUBLIC → ABSENT EnumTypeValue:{DescID: 106, Name: us-east3} + │ │ ├── PUBLIC → ABSENT ObjectParent:{DescID: 106, ReferencedDescID: 105} │ │ ├── PUBLIC → ABSENT Namespace:{DescID: 107, Name: _crdb_internal_region, ReferencedDescID: 104} │ │ ├── PUBLIC → ABSENT Owner:{DescID: 107} │ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 107, Name: admin} │ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 107, Name: public} │ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 107, Name: root} - │ │ ├── TXN_DROPPED → DROPPED AliasType:{DescID: 107, ReferencedTypeIDs: [105 107]} - │ │ ├── PUBLIC → ABSENT ObjectParent:{DescID: 107, ReferencedDescID: 106} + │ │ ├── TXN_DROPPED → DROPPED AliasType:{DescID: 107, ReferencedTypeIDs: [106 107]} + │ │ ├── PUBLIC → ABSENT ObjectParent:{DescID: 107, ReferencedDescID: 105} │ │ ├── PUBLIC → ABSENT Namespace:{DescID: 108, Name: table_regional_by_table, ReferencedDescID: 104} │ │ ├── PUBLIC → ABSENT Owner:{DescID: 108} │ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 108, Name: admin} │ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 108, Name: root} │ │ ├── TXN_DROPPED → DROPPED Table:{DescID: 108} - │ │ ├── PUBLIC → ABSENT ObjectParent:{DescID: 108, ReferencedDescID: 106} - │ │ ├── PUBLIC → ABSENT TableLocalitySecondaryRegion:{DescID: 108, ReferencedDescID: 105} + │ │ ├── PUBLIC → ABSENT ObjectParent:{DescID: 108, ReferencedDescID: 105} + │ │ ├── PUBLIC → ABSENT TableLocalitySecondaryRegion:{DescID: 108, ReferencedDescID: 106} │ │ ├── PUBLIC → ABSENT ColumnFamily:{DescID: 108, Name: primary, ColumnFamilyID: 0} │ │ ├── WRITE_ONLY → ABSENT Column:{DescID: 108, ColumnID: 1} │ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 108, Name: a, ColumnID: 1} @@ -84,18 +84,18 @@ Schema change plan for DROP DATABASE ‹multi_region_test_db› CASCADE; │ └── 23 Mutation operations │ ├── MarkDescriptorAsDropped {"DescriptorID":104} │ ├── RemoveDatabaseRoleSettings {"DatabaseID":104} - │ ├── MarkDescriptorAsDropped {"DescriptorID":106} - │ ├── RemoveSchemaParent {"Parent":{"ParentDatabaseID":104,"SchemaID":106}} │ ├── MarkDescriptorAsDropped {"DescriptorID":105} + │ ├── RemoveSchemaParent {"Parent":{"ParentDatabaseID":104,"SchemaID":105}} + │ ├── MarkDescriptorAsDropped {"DescriptorID":106} │ ├── MarkDescriptorAsDropped {"DescriptorID":107} │ ├── MarkDescriptorAsDropped {"DescriptorID":108} │ ├── RemoveAllTableComments {"TableID":108} │ ├── RemoveBackReferenceInTypes {"BackReferencedDescriptorID":108} │ ├── DrainDescriptorName {"Namespace":{"DescriptorID":104,"Name":"multi_region_tes..."}} - │ ├── DrainDescriptorName {"Namespace":{"DatabaseID":104,"DescriptorID":106,"Name":"public"}} - │ ├── DrainDescriptorName {"Namespace":{"DatabaseID":104,"DescriptorID":105,"Name":"crdb_internal_re...","SchemaID":106}} - │ ├── DrainDescriptorName {"Namespace":{"DatabaseID":104,"DescriptorID":107,"Name":"_crdb_internal_r...","SchemaID":106}} - │ ├── DrainDescriptorName {"Namespace":{"DatabaseID":104,"DescriptorID":108,"Name":"table_regional_b...","SchemaID":106}} + │ ├── DrainDescriptorName {"Namespace":{"DatabaseID":104,"DescriptorID":105,"Name":"public"}} + │ ├── DrainDescriptorName {"Namespace":{"DatabaseID":104,"DescriptorID":106,"Name":"crdb_internal_re...","SchemaID":105}} + │ ├── DrainDescriptorName {"Namespace":{"DatabaseID":104,"DescriptorID":107,"Name":"_crdb_internal_r...","SchemaID":105}} + │ ├── DrainDescriptorName {"Namespace":{"DatabaseID":104,"DescriptorID":108,"Name":"table_regional_b...","SchemaID":105}} │ ├── MakeDeleteOnlyColumnAbsent {"ColumnID":1,"TableID":108} │ ├── MakeDeleteOnlyColumnAbsent {"ColumnID":4294967295,"TableID":108} │ ├── MakeDeleteOnlyColumnAbsent {"ColumnID":4294967294,"TableID":108} @@ -110,9 +110,9 @@ Schema change plan for DROP DATABASE ‹multi_region_test_db› CASCADE; ├── 8 elements transitioning toward ABSENT │ ├── DROPPED → ABSENT Database:{DescID: 104} │ ├── PUBLIC → ABSENT DatabaseData:{DescID: 104} - │ ├── DROPPED → ABSENT Schema:{DescID: 106} - │ ├── DROPPED → ABSENT EnumType:{DescID: 105} - │ ├── DROPPED → ABSENT AliasType:{DescID: 107, ReferencedTypeIDs: [105 107]} + │ ├── DROPPED → ABSENT Schema:{DescID: 105} + │ ├── DROPPED → ABSENT EnumType:{DescID: 106} + │ ├── DROPPED → ABSENT AliasType:{DescID: 107, ReferencedTypeIDs: [106 107]} │ ├── DROPPED → ABSENT Table:{DescID: 108} │ ├── PUBLIC → ABSENT IndexData:{DescID: 108, IndexID: 1} │ └── PUBLIC → ABSENT TableData:{DescID: 108, ReferencedDescID: 104} @@ -121,10 +121,10 @@ Schema change plan for DROP DATABASE ‹multi_region_test_db› CASCADE; ├── DeleteDescriptor {"DescriptorID":104} ├── CreateGCJobForDatabase {"DatabaseID":104} ├── LogEvent {"TargetStatus":1} - ├── DeleteDescriptor {"DescriptorID":106} - ├── LogEvent {"TargetStatus":1} ├── DeleteDescriptor {"DescriptorID":105} ├── LogEvent {"TargetStatus":1} + ├── DeleteDescriptor {"DescriptorID":106} + ├── LogEvent {"TargetStatus":1} ├── DeleteDescriptor {"DescriptorID":107} ├── LogEvent {"TargetStatus":1} ├── CreateGCJobForTable {"DatabaseID":104,"TableID":108} diff --git a/pkg/ccl/schemachangerccl/testdata/explain/drop_table_multiregion b/pkg/ccl/schemachangerccl/testdata/explain/drop_table_multiregion index 4a28016c1d0f..f98a0aac583b 100644 --- a/pkg/ccl/schemachangerccl/testdata/explain/drop_table_multiregion +++ b/pkg/ccl/schemachangerccl/testdata/explain/drop_table_multiregion @@ -27,7 +27,7 @@ Schema change plan for DROP TABLE ‹multi_region_test_db›.‹public›.‹tab │ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 108, Name: admin} │ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 108, Name: root} │ │ ├── TXN_DROPPED → DROPPED Table:{DescID: 108} - │ │ ├── PUBLIC → ABSENT ObjectParent:{DescID: 108, ReferencedDescID: 106} + │ │ ├── PUBLIC → ABSENT ObjectParent:{DescID: 108, ReferencedDescID: 105} │ │ ├── PUBLIC → ABSENT TablePartitioning:{DescID: 108} │ │ ├── PUBLIC → ABSENT TableLocalityRegionalByRow:{DescID: 108} │ │ ├── PUBLIC → ABSENT ColumnFamily:{DescID: 108, Name: primary, ColumnFamilyID: 0} @@ -36,8 +36,8 @@ Schema change plan for DROP TABLE ‹multi_region_test_db›.‹public›.‹tab │ │ ├── PUBLIC → ABSENT ColumnType:{DescID: 108, ColumnFamilyID: 0, ColumnID: 1} │ │ ├── WRITE_ONLY → ABSENT Column:{DescID: 108, ColumnID: 2} │ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 108, Name: crdb_region, ColumnID: 2} - │ │ ├── PUBLIC → ABSENT ColumnType:{DescID: 108, ReferencedTypeIDs: [105 107], ColumnFamilyID: 0, ColumnID: 2} - │ │ ├── PUBLIC → ABSENT ColumnDefaultExpression:{DescID: 108, ReferencedTypeIDs: [105 107], ColumnID: 2} + │ │ ├── PUBLIC → ABSENT ColumnType:{DescID: 108, ReferencedTypeIDs: [106 107], ColumnFamilyID: 0, ColumnID: 2} + │ │ ├── PUBLIC → ABSENT ColumnDefaultExpression:{DescID: 108, ReferencedTypeIDs: [106 107], ColumnID: 2} │ │ ├── WRITE_ONLY → ABSENT Column:{DescID: 108, ColumnID: 4294967295} │ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 108, Name: crdb_internal_mvcc_timestamp, ColumnID: 4294967295} │ │ ├── PUBLIC → ABSENT ColumnType:{DescID: 108, ColumnFamilyID: 0, ColumnID: 4294967295} @@ -54,14 +54,14 @@ Schema change plan for DROP TABLE ‹multi_region_test_db›.‹public›.‹tab │ ├── RemoveAllTableComments {"TableID":108} │ ├── RemoveColumnDefaultExpression {"ColumnID":2,"TableID":108} │ ├── UpdateTableBackReferencesInTypes {"BackReferencedTableID":108} - │ ├── DrainDescriptorName {"Namespace":{"DatabaseID":104,"DescriptorID":108,"Name":"table_regional_b...","SchemaID":106}} + │ ├── DrainDescriptorName {"Namespace":{"DatabaseID":104,"DescriptorID":108,"Name":"table_regional_b...","SchemaID":105}} │ ├── MakeDeleteOnlyColumnAbsent {"ColumnID":1,"TableID":108} │ ├── RemoveDroppedColumnType {"ColumnID":2,"TableID":108} │ ├── UpdateTableBackReferencesInTypes {"BackReferencedTableID":108} │ ├── MakeDeleteOnlyColumnAbsent {"ColumnID":4294967295,"TableID":108} │ ├── MakeDeleteOnlyColumnAbsent {"ColumnID":4294967294,"TableID":108} │ ├── MakeDeleteOnlyColumnAbsent {"ColumnID":2,"TableID":108} - │ ├── SetJobStateOnDescriptor {"DescriptorID":105,"Initialize":true} + │ ├── SetJobStateOnDescriptor {"DescriptorID":106,"Initialize":true} │ ├── SetJobStateOnDescriptor {"DescriptorID":107,"Initialize":true} │ ├── SetJobStateOnDescriptor {"DescriptorID":108,"Initialize":true} │ └── CreateSchemaChangerJob {"NonCancelable":true,"RunningStatus":"PostCommitNonRev..."} @@ -75,7 +75,7 @@ Schema change plan for DROP TABLE ‹multi_region_test_db›.‹public›.‹tab ├── LogEvent {"TargetStatus":1} ├── CreateGCJobForTable {"DatabaseID":104,"TableID":108} ├── CreateGCJobForIndex {"IndexID":1,"TableID":108} - ├── RemoveJobStateFromDescriptor {"DescriptorID":105} + ├── RemoveJobStateFromDescriptor {"DescriptorID":106} ├── RemoveJobStateFromDescriptor {"DescriptorID":107} ├── RemoveJobStateFromDescriptor {"DescriptorID":108} └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"all stages compl..."} diff --git a/pkg/ccl/schemachangerccl/testdata/explain/drop_table_multiregion_primary_region b/pkg/ccl/schemachangerccl/testdata/explain/drop_table_multiregion_primary_region index 98470bdf4789..03e00c1418cd 100644 --- a/pkg/ccl/schemachangerccl/testdata/explain/drop_table_multiregion_primary_region +++ b/pkg/ccl/schemachangerccl/testdata/explain/drop_table_multiregion_primary_region @@ -26,8 +26,8 @@ Schema change plan for DROP TABLE ‹multi_region_test_db›.‹public›.‹tab │ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 108, Name: admin} │ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 108, Name: root} │ │ ├── TXN_DROPPED → DROPPED Table:{DescID: 108} - │ │ ├── PUBLIC → ABSENT ObjectParent:{DescID: 108, ReferencedDescID: 106} - │ │ ├── PUBLIC → ABSENT TableLocalitySecondaryRegion:{DescID: 108, ReferencedDescID: 105} + │ │ ├── PUBLIC → ABSENT ObjectParent:{DescID: 108, ReferencedDescID: 105} + │ │ ├── PUBLIC → ABSENT TableLocalitySecondaryRegion:{DescID: 108, ReferencedDescID: 106} │ │ ├── PUBLIC → ABSENT ColumnFamily:{DescID: 108, Name: primary, ColumnFamilyID: 0} │ │ ├── WRITE_ONLY → ABSENT Column:{DescID: 108, ColumnID: 1} │ │ ├── PUBLIC → ABSENT ColumnName:{DescID: 108, Name: a, ColumnID: 1} @@ -45,11 +45,11 @@ Schema change plan for DROP TABLE ‹multi_region_test_db›.‹public›.‹tab │ ├── MarkDescriptorAsDropped {"DescriptorID":108} │ ├── RemoveAllTableComments {"TableID":108} │ ├── RemoveBackReferenceInTypes {"BackReferencedDescriptorID":108} - │ ├── DrainDescriptorName {"Namespace":{"DatabaseID":104,"DescriptorID":108,"Name":"table_regional_b...","SchemaID":106}} + │ ├── DrainDescriptorName {"Namespace":{"DatabaseID":104,"DescriptorID":108,"Name":"table_regional_b...","SchemaID":105}} │ ├── MakeDeleteOnlyColumnAbsent {"ColumnID":1,"TableID":108} │ ├── MakeDeleteOnlyColumnAbsent {"ColumnID":4294967295,"TableID":108} │ ├── MakeDeleteOnlyColumnAbsent {"ColumnID":4294967294,"TableID":108} - │ ├── SetJobStateOnDescriptor {"DescriptorID":105,"Initialize":true} + │ ├── SetJobStateOnDescriptor {"DescriptorID":106,"Initialize":true} │ ├── SetJobStateOnDescriptor {"DescriptorID":108,"Initialize":true} │ └── CreateSchemaChangerJob {"NonCancelable":true,"RunningStatus":"PostCommitNonRev..."} └── PostCommitNonRevertiblePhase @@ -62,6 +62,6 @@ Schema change plan for DROP TABLE ‹multi_region_test_db›.‹public›.‹tab ├── LogEvent {"TargetStatus":1} ├── CreateGCJobForTable {"DatabaseID":104,"TableID":108} ├── CreateGCJobForIndex {"IndexID":1,"TableID":108} - ├── RemoveJobStateFromDescriptor {"DescriptorID":105} + ├── RemoveJobStateFromDescriptor {"DescriptorID":106} ├── RemoveJobStateFromDescriptor {"DescriptorID":108} └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"all stages compl..."} diff --git a/pkg/ccl/schemachangerccl/testdata/explain_verbose/drop_database_multiregion_primary_region b/pkg/ccl/schemachangerccl/testdata/explain_verbose/drop_database_multiregion_primary_region index 83f513bdfb05..148c6c91c7b0 100644 --- a/pkg/ccl/schemachangerccl/testdata/explain_verbose/drop_database_multiregion_primary_region +++ b/pkg/ccl/schemachangerccl/testdata/explain_verbose/drop_database_multiregion_primary_region @@ -18,13 +18,13 @@ EXPLAIN (ddl, verbose) DROP DATABASE multi_region_test_db CASCADE; │ │ ├── • Database:{DescID: 104} │ │ │ PUBLIC → TXN_DROPPED │ │ │ -│ │ ├── • Schema:{DescID: 106} +│ │ ├── • Schema:{DescID: 105} │ │ │ PUBLIC → TXN_DROPPED │ │ │ -│ │ ├── • EnumType:{DescID: 105} +│ │ ├── • EnumType:{DescID: 106} │ │ │ PUBLIC → TXN_DROPPED │ │ │ -│ │ ├── • AliasType:{DescID: 107, ReferencedTypeIDs: [105 107]} +│ │ ├── • AliasType:{DescID: 107, ReferencedTypeIDs: [106 107]} │ │ │ PUBLIC → TXN_DROPPED │ │ │ │ │ ├── • Table:{DescID: 108} @@ -60,10 +60,10 @@ EXPLAIN (ddl, verbose) DROP DATABASE multi_region_test_db CASCADE; │ │ DescriptorID: 104 │ │ │ ├── • MarkDescriptorAsSyntheticallyDropped -│ │ DescriptorID: 106 +│ │ DescriptorID: 105 │ │ │ ├── • MarkDescriptorAsSyntheticallyDropped -│ │ DescriptorID: 105 +│ │ DescriptorID: 106 │ │ │ ├── • MarkDescriptorAsSyntheticallyDropped │ │ DescriptorID: 107 @@ -131,160 +131,160 @@ EXPLAIN (ddl, verbose) DROP DATABASE multi_region_test_db CASCADE; │ │ │ └── • Precedence dependency from DROPPED Database:{DescID: 104} │ │ │ rule: "descriptor drop right before dependent element removal" │ │ │ -│ │ ├── • DatabaseRegionConfig:{DescID: 104, ReferencedDescID: 105} +│ │ ├── • DatabaseRegionConfig:{DescID: 104, ReferencedDescID: 106} │ │ │ │ PUBLIC → ABSENT │ │ │ │ │ │ │ ├── • Precedence dependency from DROPPED Database:{DescID: 104} │ │ │ │ rule: "descriptor drop right before dependent element removal" │ │ │ │ -│ │ │ └── • SameStagePrecedence dependency from DROPPED EnumType:{DescID: 105} +│ │ │ └── • SameStagePrecedence dependency from DROPPED EnumType:{DescID: 106} │ │ │ rule: "descriptor drop right before removing dependent with attr ref" │ │ │ -│ │ ├── • Namespace:{DescID: 106, Name: public, ReferencedDescID: 104} +│ │ ├── • Namespace:{DescID: 105, Name: public, ReferencedDescID: 104} │ │ │ │ PUBLIC → ABSENT │ │ │ │ │ │ │ ├── • SameStagePrecedence dependency from DROPPED Database:{DescID: 104} │ │ │ │ rule: "descriptor drop right before removing dependent with attr ref" │ │ │ │ -│ │ │ └── • Precedence dependency from DROPPED Schema:{DescID: 106} +│ │ │ └── • Precedence dependency from DROPPED Schema:{DescID: 105} │ │ │ rule: "descriptor drop right before dependent element removal" │ │ │ -│ │ ├── • Owner:{DescID: 106} +│ │ ├── • Owner:{DescID: 105} │ │ │ │ PUBLIC → ABSENT │ │ │ │ -│ │ │ ├── • Precedence dependency from DROPPED Schema:{DescID: 106} +│ │ │ ├── • Precedence dependency from DROPPED Schema:{DescID: 105} │ │ │ │ rule: "descriptor drop right before dependent element removal" │ │ │ │ │ │ │ └── • skip PUBLIC → ABSENT operations │ │ │ rule: "skip element removal ops on descriptor drop" │ │ │ -│ │ ├── • UserPrivileges:{DescID: 106, Name: admin} +│ │ ├── • UserPrivileges:{DescID: 105, Name: admin} │ │ │ │ PUBLIC → ABSENT │ │ │ │ -│ │ │ ├── • Precedence dependency from DROPPED Schema:{DescID: 106} +│ │ │ ├── • Precedence dependency from DROPPED Schema:{DescID: 105} │ │ │ │ rule: "descriptor drop right before dependent element removal" │ │ │ │ │ │ │ └── • skip PUBLIC → ABSENT operations │ │ │ rule: "skip element removal ops on descriptor drop" │ │ │ -│ │ ├── • UserPrivileges:{DescID: 106, Name: public} +│ │ ├── • UserPrivileges:{DescID: 105, Name: public} │ │ │ │ PUBLIC → ABSENT │ │ │ │ -│ │ │ ├── • Precedence dependency from DROPPED Schema:{DescID: 106} +│ │ │ ├── • Precedence dependency from DROPPED Schema:{DescID: 105} │ │ │ │ rule: "descriptor drop right before dependent element removal" │ │ │ │ │ │ │ └── • skip PUBLIC → ABSENT operations │ │ │ rule: "skip element removal ops on descriptor drop" │ │ │ -│ │ ├── • UserPrivileges:{DescID: 106, Name: root} +│ │ ├── • UserPrivileges:{DescID: 105, Name: root} │ │ │ │ PUBLIC → ABSENT │ │ │ │ -│ │ │ ├── • Precedence dependency from DROPPED Schema:{DescID: 106} +│ │ │ ├── • Precedence dependency from DROPPED Schema:{DescID: 105} │ │ │ │ rule: "descriptor drop right before dependent element removal" │ │ │ │ │ │ │ └── • skip PUBLIC → ABSENT operations │ │ │ rule: "skip element removal ops on descriptor drop" │ │ │ -│ │ ├── • Schema:{DescID: 106} +│ │ ├── • Schema:{DescID: 105} │ │ │ │ TXN_DROPPED → DROPPED │ │ │ │ -│ │ │ └── • PreviousStagePrecedence dependency from TXN_DROPPED Schema:{DescID: 106} +│ │ │ └── • PreviousStagePrecedence dependency from TXN_DROPPED Schema:{DescID: 105} │ │ │ rule: "descriptor TXN_DROPPED before DROPPED" │ │ │ -│ │ ├── • SchemaParent:{DescID: 106, ReferencedDescID: 104} +│ │ ├── • SchemaParent:{DescID: 105, ReferencedDescID: 104} │ │ │ │ PUBLIC → ABSENT │ │ │ │ │ │ │ ├── • SameStagePrecedence dependency from DROPPED Database:{DescID: 104} │ │ │ │ rule: "descriptor drop right before removing dependent with attr ref" │ │ │ │ -│ │ │ └── • Precedence dependency from DROPPED Schema:{DescID: 106} +│ │ │ └── • Precedence dependency from DROPPED Schema:{DescID: 105} │ │ │ rule: "descriptor drop right before dependent element removal" │ │ │ -│ │ ├── • Namespace:{DescID: 105, Name: crdb_internal_region, ReferencedDescID: 104} +│ │ ├── • Namespace:{DescID: 106, Name: crdb_internal_region, ReferencedDescID: 104} │ │ │ │ PUBLIC → ABSENT │ │ │ │ │ │ │ ├── • SameStagePrecedence dependency from DROPPED Database:{DescID: 104} │ │ │ │ rule: "descriptor drop right before removing dependent with attr ref" │ │ │ │ -│ │ │ └── • Precedence dependency from DROPPED EnumType:{DescID: 105} +│ │ │ └── • Precedence dependency from DROPPED EnumType:{DescID: 106} │ │ │ rule: "descriptor drop right before dependent element removal" │ │ │ -│ │ ├── • Owner:{DescID: 105} +│ │ ├── • Owner:{DescID: 106} │ │ │ │ PUBLIC → ABSENT │ │ │ │ -│ │ │ ├── • Precedence dependency from DROPPED EnumType:{DescID: 105} +│ │ │ ├── • Precedence dependency from DROPPED EnumType:{DescID: 106} │ │ │ │ rule: "descriptor drop right before dependent element removal" │ │ │ │ │ │ │ └── • skip PUBLIC → ABSENT operations │ │ │ rule: "skip element removal ops on descriptor drop" │ │ │ -│ │ ├── • UserPrivileges:{DescID: 105, Name: admin} +│ │ ├── • UserPrivileges:{DescID: 106, Name: admin} │ │ │ │ PUBLIC → ABSENT │ │ │ │ -│ │ │ ├── • Precedence dependency from DROPPED EnumType:{DescID: 105} +│ │ │ ├── • Precedence dependency from DROPPED EnumType:{DescID: 106} │ │ │ │ rule: "descriptor drop right before dependent element removal" │ │ │ │ │ │ │ └── • skip PUBLIC → ABSENT operations │ │ │ rule: "skip element removal ops on descriptor drop" │ │ │ -│ │ ├── • UserPrivileges:{DescID: 105, Name: public} +│ │ ├── • UserPrivileges:{DescID: 106, Name: public} │ │ │ │ PUBLIC → ABSENT │ │ │ │ -│ │ │ ├── • Precedence dependency from DROPPED EnumType:{DescID: 105} +│ │ │ ├── • Precedence dependency from DROPPED EnumType:{DescID: 106} │ │ │ │ rule: "descriptor drop right before dependent element removal" │ │ │ │ │ │ │ └── • skip PUBLIC → ABSENT operations │ │ │ rule: "skip element removal ops on descriptor drop" │ │ │ -│ │ ├── • UserPrivileges:{DescID: 105, Name: root} +│ │ ├── • UserPrivileges:{DescID: 106, Name: root} │ │ │ │ PUBLIC → ABSENT │ │ │ │ -│ │ │ ├── • Precedence dependency from DROPPED EnumType:{DescID: 105} +│ │ │ ├── • Precedence dependency from DROPPED EnumType:{DescID: 106} │ │ │ │ rule: "descriptor drop right before dependent element removal" │ │ │ │ │ │ │ └── • skip PUBLIC → ABSENT operations │ │ │ rule: "skip element removal ops on descriptor drop" │ │ │ -│ │ ├── • EnumType:{DescID: 105} +│ │ ├── • EnumType:{DescID: 106} │ │ │ │ TXN_DROPPED → DROPPED │ │ │ │ -│ │ │ └── • PreviousStagePrecedence dependency from TXN_DROPPED EnumType:{DescID: 105} +│ │ │ └── • PreviousStagePrecedence dependency from TXN_DROPPED EnumType:{DescID: 106} │ │ │ rule: "descriptor TXN_DROPPED before DROPPED" │ │ │ -│ │ ├── • EnumTypeValue:{DescID: 105, Name: us-east1} +│ │ ├── • EnumTypeValue:{DescID: 106, Name: us-east1} │ │ │ │ PUBLIC → ABSENT │ │ │ │ -│ │ │ ├── • Precedence dependency from DROPPED EnumType:{DescID: 105} +│ │ │ ├── • Precedence dependency from DROPPED EnumType:{DescID: 106} │ │ │ │ rule: "descriptor drop right before dependent element removal" │ │ │ │ │ │ │ └── • skip PUBLIC → ABSENT operations │ │ │ rule: "skip element removal ops on descriptor drop" │ │ │ -│ │ ├── • EnumTypeValue:{DescID: 105, Name: us-east2} +│ │ ├── • EnumTypeValue:{DescID: 106, Name: us-east2} │ │ │ │ PUBLIC → ABSENT │ │ │ │ -│ │ │ ├── • Precedence dependency from DROPPED EnumType:{DescID: 105} +│ │ │ ├── • Precedence dependency from DROPPED EnumType:{DescID: 106} │ │ │ │ rule: "descriptor drop right before dependent element removal" │ │ │ │ │ │ │ └── • skip PUBLIC → ABSENT operations │ │ │ rule: "skip element removal ops on descriptor drop" │ │ │ -│ │ ├── • EnumTypeValue:{DescID: 105, Name: us-east3} +│ │ ├── • EnumTypeValue:{DescID: 106, Name: us-east3} │ │ │ │ PUBLIC → ABSENT │ │ │ │ -│ │ │ ├── • Precedence dependency from DROPPED EnumType:{DescID: 105} +│ │ │ ├── • Precedence dependency from DROPPED EnumType:{DescID: 106} │ │ │ │ rule: "descriptor drop right before dependent element removal" │ │ │ │ │ │ │ └── • skip PUBLIC → ABSENT operations │ │ │ rule: "skip element removal ops on descriptor drop" │ │ │ -│ │ ├── • ObjectParent:{DescID: 105, ReferencedDescID: 106} +│ │ ├── • ObjectParent:{DescID: 106, ReferencedDescID: 105} │ │ │ │ PUBLIC → ABSENT │ │ │ │ -│ │ │ ├── • SameStagePrecedence dependency from DROPPED Schema:{DescID: 106} +│ │ │ ├── • SameStagePrecedence dependency from DROPPED Schema:{DescID: 105} │ │ │ │ rule: "descriptor drop right before removing dependent with attr ref" │ │ │ │ -│ │ │ └── • Precedence dependency from DROPPED EnumType:{DescID: 105} +│ │ │ └── • Precedence dependency from DROPPED EnumType:{DescID: 106} │ │ │ rule: "descriptor drop right before dependent element removal" │ │ │ │ │ ├── • Namespace:{DescID: 107, Name: _crdb_internal_region, ReferencedDescID: 104} @@ -293,13 +293,13 @@ EXPLAIN (ddl, verbose) DROP DATABASE multi_region_test_db CASCADE; │ │ │ ├── • SameStagePrecedence dependency from DROPPED Database:{DescID: 104} │ │ │ │ rule: "descriptor drop right before removing dependent with attr ref" │ │ │ │ -│ │ │ └── • Precedence dependency from DROPPED AliasType:{DescID: 107, ReferencedTypeIDs: [105 107]} +│ │ │ └── • Precedence dependency from DROPPED AliasType:{DescID: 107, ReferencedTypeIDs: [106 107]} │ │ │ rule: "descriptor drop right before dependent element removal" │ │ │ │ │ ├── • Owner:{DescID: 107} │ │ │ │ PUBLIC → ABSENT │ │ │ │ -│ │ │ ├── • Precedence dependency from DROPPED AliasType:{DescID: 107, ReferencedTypeIDs: [105 107]} +│ │ │ ├── • Precedence dependency from DROPPED AliasType:{DescID: 107, ReferencedTypeIDs: [106 107]} │ │ │ │ rule: "descriptor drop right before dependent element removal" │ │ │ │ │ │ │ └── • skip PUBLIC → ABSENT operations @@ -308,7 +308,7 @@ EXPLAIN (ddl, verbose) DROP DATABASE multi_region_test_db CASCADE; │ │ ├── • UserPrivileges:{DescID: 107, Name: admin} │ │ │ │ PUBLIC → ABSENT │ │ │ │ -│ │ │ ├── • Precedence dependency from DROPPED AliasType:{DescID: 107, ReferencedTypeIDs: [105 107]} +│ │ │ ├── • Precedence dependency from DROPPED AliasType:{DescID: 107, ReferencedTypeIDs: [106 107]} │ │ │ │ rule: "descriptor drop right before dependent element removal" │ │ │ │ │ │ │ └── • skip PUBLIC → ABSENT operations @@ -317,7 +317,7 @@ EXPLAIN (ddl, verbose) DROP DATABASE multi_region_test_db CASCADE; │ │ ├── • UserPrivileges:{DescID: 107, Name: public} │ │ │ │ PUBLIC → ABSENT │ │ │ │ -│ │ │ ├── • Precedence dependency from DROPPED AliasType:{DescID: 107, ReferencedTypeIDs: [105 107]} +│ │ │ ├── • Precedence dependency from DROPPED AliasType:{DescID: 107, ReferencedTypeIDs: [106 107]} │ │ │ │ rule: "descriptor drop right before dependent element removal" │ │ │ │ │ │ │ └── • skip PUBLIC → ABSENT operations @@ -326,25 +326,25 @@ EXPLAIN (ddl, verbose) DROP DATABASE multi_region_test_db CASCADE; │ │ ├── • UserPrivileges:{DescID: 107, Name: root} │ │ │ │ PUBLIC → ABSENT │ │ │ │ -│ │ │ ├── • Precedence dependency from DROPPED AliasType:{DescID: 107, ReferencedTypeIDs: [105 107]} +│ │ │ ├── • Precedence dependency from DROPPED AliasType:{DescID: 107, ReferencedTypeIDs: [106 107]} │ │ │ │ rule: "descriptor drop right before dependent element removal" │ │ │ │ │ │ │ └── • skip PUBLIC → ABSENT operations │ │ │ rule: "skip element removal ops on descriptor drop" │ │ │ -│ │ ├── • AliasType:{DescID: 107, ReferencedTypeIDs: [105 107]} +│ │ ├── • AliasType:{DescID: 107, ReferencedTypeIDs: [106 107]} │ │ │ │ TXN_DROPPED → DROPPED │ │ │ │ -│ │ │ └── • PreviousStagePrecedence dependency from TXN_DROPPED AliasType:{DescID: 107, ReferencedTypeIDs: [105 107]} +│ │ │ └── • PreviousStagePrecedence dependency from TXN_DROPPED AliasType:{DescID: 107, ReferencedTypeIDs: [106 107]} │ │ │ rule: "descriptor TXN_DROPPED before DROPPED" │ │ │ -│ │ ├── • ObjectParent:{DescID: 107, ReferencedDescID: 106} +│ │ ├── • ObjectParent:{DescID: 107, ReferencedDescID: 105} │ │ │ │ PUBLIC → ABSENT │ │ │ │ -│ │ │ ├── • SameStagePrecedence dependency from DROPPED Schema:{DescID: 106} +│ │ │ ├── • SameStagePrecedence dependency from DROPPED Schema:{DescID: 105} │ │ │ │ rule: "descriptor drop right before removing dependent with attr ref" │ │ │ │ -│ │ │ └── • Precedence dependency from DROPPED AliasType:{DescID: 107, ReferencedTypeIDs: [105 107]} +│ │ │ └── • Precedence dependency from DROPPED AliasType:{DescID: 107, ReferencedTypeIDs: [106 107]} │ │ │ rule: "descriptor drop right before dependent element removal" │ │ │ │ │ ├── • Namespace:{DescID: 108, Name: table_regional_by_table, ReferencedDescID: 104} @@ -389,19 +389,19 @@ EXPLAIN (ddl, verbose) DROP DATABASE multi_region_test_db CASCADE; │ │ │ └── • PreviousStagePrecedence dependency from TXN_DROPPED Table:{DescID: 108} │ │ │ rule: "descriptor TXN_DROPPED before DROPPED" │ │ │ -│ │ ├── • ObjectParent:{DescID: 108, ReferencedDescID: 106} +│ │ ├── • ObjectParent:{DescID: 108, ReferencedDescID: 105} │ │ │ │ PUBLIC → ABSENT │ │ │ │ -│ │ │ ├── • SameStagePrecedence dependency from DROPPED Schema:{DescID: 106} +│ │ │ ├── • SameStagePrecedence dependency from DROPPED Schema:{DescID: 105} │ │ │ │ rule: "descriptor drop right before removing dependent with attr ref" │ │ │ │ │ │ │ └── • Precedence dependency from DROPPED Table:{DescID: 108} │ │ │ rule: "descriptor drop right before dependent element removal" │ │ │ -│ │ ├── • TableLocalitySecondaryRegion:{DescID: 108, ReferencedDescID: 105} +│ │ ├── • TableLocalitySecondaryRegion:{DescID: 108, ReferencedDescID: 106} │ │ │ │ PUBLIC → ABSENT │ │ │ │ -│ │ │ ├── • SameStagePrecedence dependency from DROPPED EnumType:{DescID: 105} +│ │ │ ├── • SameStagePrecedence dependency from DROPPED EnumType:{DescID: 106} │ │ │ │ rule: "descriptor drop right before removing dependent with attr ref" │ │ │ │ │ │ │ └── • Precedence dependency from DROPPED Table:{DescID: 108} @@ -573,15 +573,15 @@ EXPLAIN (ddl, verbose) DROP DATABASE multi_region_test_db CASCADE; │ │ DatabaseID: 104 │ │ │ ├── • MarkDescriptorAsDropped -│ │ DescriptorID: 106 +│ │ DescriptorID: 105 │ │ │ ├── • RemoveSchemaParent │ │ Parent: │ │ ParentDatabaseID: 104 -│ │ SchemaID: 106 +│ │ SchemaID: 105 │ │ │ ├── • MarkDescriptorAsDropped -│ │ DescriptorID: 105 +│ │ DescriptorID: 106 │ │ │ ├── • MarkDescriptorAsDropped │ │ DescriptorID: 107 @@ -595,7 +595,7 @@ EXPLAIN (ddl, verbose) DROP DATABASE multi_region_test_db CASCADE; │ ├── • RemoveBackReferenceInTypes │ │ BackReferencedDescriptorID: 108 │ │ TypeIDs: -│ │ - 105 +│ │ - 106 │ │ │ ├── • DrainDescriptorName │ │ Namespace: @@ -605,29 +605,29 @@ EXPLAIN (ddl, verbose) DROP DATABASE multi_region_test_db CASCADE; │ ├── • DrainDescriptorName │ │ Namespace: │ │ DatabaseID: 104 -│ │ DescriptorID: 106 +│ │ DescriptorID: 105 │ │ Name: public │ │ │ ├── • DrainDescriptorName │ │ Namespace: │ │ DatabaseID: 104 -│ │ DescriptorID: 105 +│ │ DescriptorID: 106 │ │ Name: crdb_internal_region -│ │ SchemaID: 106 +│ │ SchemaID: 105 │ │ │ ├── • DrainDescriptorName │ │ Namespace: │ │ DatabaseID: 104 │ │ DescriptorID: 107 │ │ Name: _crdb_internal_region -│ │ SchemaID: 106 +│ │ SchemaID: 105 │ │ │ ├── • DrainDescriptorName │ │ Namespace: │ │ DatabaseID: 104 │ │ DescriptorID: 108 │ │ Name: table_regional_by_table -│ │ SchemaID: 106 +│ │ SchemaID: 105 │ │ │ ├── • MakeDeleteOnlyColumnAbsent │ │ ColumnID: 1 @@ -721,22 +721,22 @@ EXPLAIN (ddl, verbose) DROP DATABASE multi_region_test_db CASCADE; │ │ └── • SameStagePrecedence dependency from ABSENT Database:{DescID: 104} │ │ rule: "descriptor removed right before garbage collection" │ │ - │ ├── • Schema:{DescID: 106} + │ ├── • Schema:{DescID: 105} │ │ │ DROPPED → ABSENT │ │ │ - │ │ └── • PreviousTransactionPrecedence dependency from DROPPED Schema:{DescID: 106} + │ │ └── • PreviousTransactionPrecedence dependency from DROPPED Schema:{DescID: 105} │ │ rule: "descriptor DROPPED in transaction before removal" │ │ - │ ├── • EnumType:{DescID: 105} + │ ├── • EnumType:{DescID: 106} │ │ │ DROPPED → ABSENT │ │ │ - │ │ └── • PreviousTransactionPrecedence dependency from DROPPED EnumType:{DescID: 105} + │ │ └── • PreviousTransactionPrecedence dependency from DROPPED EnumType:{DescID: 106} │ │ rule: "descriptor DROPPED in transaction before removal" │ │ - │ ├── • AliasType:{DescID: 107, ReferencedTypeIDs: [105 107]} + │ ├── • AliasType:{DescID: 107, ReferencedTypeIDs: [106 107]} │ │ │ DROPPED → ABSENT │ │ │ - │ │ └── • PreviousTransactionPrecedence dependency from DROPPED AliasType:{DescID: 107, ReferencedTypeIDs: [105 107]} + │ │ └── • PreviousTransactionPrecedence dependency from DROPPED AliasType:{DescID: 107, ReferencedTypeIDs: [106 107]} │ │ rule: "descriptor DROPPED in transaction before removal" │ │ │ ├── • Table:{DescID: 108} @@ -788,7 +788,7 @@ EXPLAIN (ddl, verbose) DROP DATABASE multi_region_test_db CASCADE; │ Element: │ Schema: │ isPublic: true - │ schemaId: 106 + │ schemaId: 105 │ EventBase: │ Authorization: │ UserName: root @@ -800,14 +800,14 @@ EXPLAIN (ddl, verbose) DROP DATABASE multi_region_test_db CASCADE; │ TargetStatus: 1 │ ├── • DeleteDescriptor - │ DescriptorID: 106 + │ DescriptorID: 105 │ ├── • LogEvent │ Element: │ EnumType: │ arrayTypeId: 107 │ isMultiRegion: true - │ typeId: 105 + │ typeId: 106 │ EventBase: │ Authorization: │ UserName: root @@ -819,18 +819,18 @@ EXPLAIN (ddl, verbose) DROP DATABASE multi_region_test_db CASCADE; │ TargetStatus: 1 │ ├── • DeleteDescriptor - │ DescriptorID: 105 + │ DescriptorID: 106 │ ├── • LogEvent │ Element: │ AliasType: │ closedTypeIds: - │ - 105 + │ - 106 │ - 107 │ type: │ arrayContents: │ family: EnumFamily - │ oid: 100105 + │ oid: 100106 │ udtMetadata: │ arrayTypeOid: 100107 │ arrayElemType: EnumFamily diff --git a/pkg/ccl/schemachangerccl/testdata/explain_verbose/drop_table_multiregion b/pkg/ccl/schemachangerccl/testdata/explain_verbose/drop_table_multiregion index 4ac4a840794c..0da2d8acf47b 100644 --- a/pkg/ccl/schemachangerccl/testdata/explain_verbose/drop_table_multiregion +++ b/pkg/ccl/schemachangerccl/testdata/explain_verbose/drop_table_multiregion @@ -98,7 +98,7 @@ EXPLAIN (ddl, verbose) DROP TABLE multi_region_test_db.public.table_regional_by_ │ │ │ └── • PreviousStagePrecedence dependency from TXN_DROPPED Table:{DescID: 108} │ │ │ rule: "descriptor TXN_DROPPED before DROPPED" │ │ │ -│ │ ├── • ObjectParent:{DescID: 108, ReferencedDescID: 106} +│ │ ├── • ObjectParent:{DescID: 108, ReferencedDescID: 105} │ │ │ │ PUBLIC → ABSENT │ │ │ │ │ │ │ └── • Precedence dependency from DROPPED Table:{DescID: 108} @@ -170,10 +170,10 @@ EXPLAIN (ddl, verbose) DROP TABLE multi_region_test_db.public.table_regional_by_ │ │ │ ├── • Precedence dependency from ABSENT ColumnName:{DescID: 108, Name: crdb_region, ColumnID: 2} │ │ │ │ rule: "dependents removed before column" │ │ │ │ -│ │ │ ├── • Precedence dependency from ABSENT ColumnType:{DescID: 108, ReferencedTypeIDs: [105 107], ColumnFamilyID: 0, ColumnID: 2} +│ │ │ ├── • Precedence dependency from ABSENT ColumnType:{DescID: 108, ReferencedTypeIDs: [106 107], ColumnFamilyID: 0, ColumnID: 2} │ │ │ │ rule: "dependents removed before column" │ │ │ │ -│ │ │ ├── • Precedence dependency from ABSENT ColumnDefaultExpression:{DescID: 108, ReferencedTypeIDs: [105 107], ColumnID: 2} +│ │ │ ├── • Precedence dependency from ABSENT ColumnDefaultExpression:{DescID: 108, ReferencedTypeIDs: [106 107], ColumnID: 2} │ │ │ │ rule: "dependents removed before column" │ │ │ │ │ │ │ ├── • Precedence dependency from ABSENT IndexColumn:{DescID: 108, ColumnID: 2, IndexID: 1} @@ -194,7 +194,7 @@ EXPLAIN (ddl, verbose) DROP TABLE multi_region_test_db.public.table_regional_by_ │ │ │ └── • skip PUBLIC → ABSENT operations │ │ │ rule: "skip column dependents removal ops on relation drop" │ │ │ -│ │ ├── • ColumnType:{DescID: 108, ReferencedTypeIDs: [105 107], ColumnFamilyID: 0, ColumnID: 2} +│ │ ├── • ColumnType:{DescID: 108, ReferencedTypeIDs: [106 107], ColumnFamilyID: 0, ColumnID: 2} │ │ │ │ PUBLIC → ABSENT │ │ │ │ │ │ │ ├── • Precedence dependency from DROPPED Table:{DescID: 108} @@ -203,10 +203,10 @@ EXPLAIN (ddl, verbose) DROP TABLE multi_region_test_db.public.table_regional_by_ │ │ │ ├── • Precedence dependency from WRITE_ONLY Column:{DescID: 108, ColumnID: 2} │ │ │ │ rule: "column no longer public before dependents" │ │ │ │ -│ │ │ └── • SameStagePrecedence dependency from ABSENT ColumnDefaultExpression:{DescID: 108, ReferencedTypeIDs: [105 107], ColumnID: 2} +│ │ │ └── • SameStagePrecedence dependency from ABSENT ColumnDefaultExpression:{DescID: 108, ReferencedTypeIDs: [106 107], ColumnID: 2} │ │ │ rule: "column type dependents removed right before column type" │ │ │ -│ │ ├── • ColumnDefaultExpression:{DescID: 108, ReferencedTypeIDs: [105 107], ColumnID: 2} +│ │ ├── • ColumnDefaultExpression:{DescID: 108, ReferencedTypeIDs: [106 107], ColumnID: 2} │ │ │ │ PUBLIC → ABSENT │ │ │ │ │ │ │ ├── • Precedence dependency from DROPPED Table:{DescID: 108} @@ -376,7 +376,7 @@ EXPLAIN (ddl, verbose) DROP TABLE multi_region_test_db.public.table_regional_by_ │ ├── • UpdateTableBackReferencesInTypes │ │ BackReferencedTableID: 108 │ │ TypeIDs: -│ │ - 105 +│ │ - 106 │ │ - 107 │ │ │ ├── • DrainDescriptorName @@ -384,7 +384,7 @@ EXPLAIN (ddl, verbose) DROP TABLE multi_region_test_db.public.table_regional_by_ │ │ DatabaseID: 104 │ │ DescriptorID: 108 │ │ Name: table_regional_by_row -│ │ SchemaID: 106 +│ │ SchemaID: 105 │ │ │ ├── • MakeDeleteOnlyColumnAbsent │ │ ColumnID: 1 @@ -405,7 +405,7 @@ EXPLAIN (ddl, verbose) DROP TABLE multi_region_test_db.public.table_regional_by_ │ ├── • UpdateTableBackReferencesInTypes │ │ BackReferencedTableID: 108 │ │ TypeIDs: -│ │ - 105 +│ │ - 106 │ │ - 107 │ │ │ ├── • MakeDeleteOnlyColumnAbsent @@ -445,7 +445,7 @@ EXPLAIN (ddl, verbose) DROP TABLE multi_region_test_db.public.table_regional_by_ │ │ TableID: 108 │ │ │ ├── • SetJobStateOnDescriptor -│ │ DescriptorID: 105 +│ │ DescriptorID: 106 │ │ Initialize: true │ │ │ ├── • SetJobStateOnDescriptor @@ -460,7 +460,7 @@ EXPLAIN (ddl, verbose) DROP TABLE multi_region_test_db.public.table_regional_by_ │ Authorization: │ UserName: root │ DescriptorIDs: -│ - 105 +│ - 106 │ - 107 │ - 108 │ JobID: 1 @@ -527,7 +527,7 @@ EXPLAIN (ddl, verbose) DROP TABLE multi_region_test_db.public.table_regional_by_ │ TableID: 108 │ ├── • RemoveJobStateFromDescriptor - │ DescriptorID: 105 + │ DescriptorID: 106 │ JobID: 1 │ ├── • RemoveJobStateFromDescriptor @@ -540,7 +540,7 @@ EXPLAIN (ddl, verbose) DROP TABLE multi_region_test_db.public.table_regional_by_ │ └── • UpdateSchemaChangerJob DescriptorIDsToRemove: - - 105 + - 106 - 107 - 108 IsNonCancelable: true diff --git a/pkg/ccl/schemachangerccl/testdata/explain_verbose/drop_table_multiregion_primary_region b/pkg/ccl/schemachangerccl/testdata/explain_verbose/drop_table_multiregion_primary_region index b9374eff09ee..49ccd15eeef3 100644 --- a/pkg/ccl/schemachangerccl/testdata/explain_verbose/drop_table_multiregion_primary_region +++ b/pkg/ccl/schemachangerccl/testdata/explain_verbose/drop_table_multiregion_primary_region @@ -92,13 +92,13 @@ EXPLAIN (ddl, verbose) DROP TABLE multi_region_test_db.public.table_regional_by_ │ │ │ └── • PreviousStagePrecedence dependency from TXN_DROPPED Table:{DescID: 108} │ │ │ rule: "descriptor TXN_DROPPED before DROPPED" │ │ │ -│ │ ├── • ObjectParent:{DescID: 108, ReferencedDescID: 106} +│ │ ├── • ObjectParent:{DescID: 108, ReferencedDescID: 105} │ │ │ │ PUBLIC → ABSENT │ │ │ │ │ │ │ └── • Precedence dependency from DROPPED Table:{DescID: 108} │ │ │ rule: "descriptor drop right before dependent element removal" │ │ │ -│ │ ├── • TableLocalitySecondaryRegion:{DescID: 108, ReferencedDescID: 105} +│ │ ├── • TableLocalitySecondaryRegion:{DescID: 108, ReferencedDescID: 106} │ │ │ │ PUBLIC → ABSENT │ │ │ │ │ │ │ └── • Precedence dependency from DROPPED Table:{DescID: 108} @@ -272,14 +272,14 @@ EXPLAIN (ddl, verbose) DROP TABLE multi_region_test_db.public.table_regional_by_ │ ├── • RemoveBackReferenceInTypes │ │ BackReferencedDescriptorID: 108 │ │ TypeIDs: -│ │ - 105 +│ │ - 106 │ │ │ ├── • DrainDescriptorName │ │ Namespace: │ │ DatabaseID: 104 │ │ DescriptorID: 108 │ │ Name: table_regional_by_table -│ │ SchemaID: 106 +│ │ SchemaID: 105 │ │ │ ├── • MakeDeleteOnlyColumnAbsent │ │ ColumnID: 1 @@ -321,7 +321,7 @@ EXPLAIN (ddl, verbose) DROP TABLE multi_region_test_db.public.table_regional_by_ │ │ TableID: 108 │ │ │ ├── • SetJobStateOnDescriptor -│ │ DescriptorID: 105 +│ │ DescriptorID: 106 │ │ Initialize: true │ │ │ ├── • SetJobStateOnDescriptor @@ -332,7 +332,7 @@ EXPLAIN (ddl, verbose) DROP TABLE multi_region_test_db.public.table_regional_by_ │ Authorization: │ UserName: root │ DescriptorIDs: -│ - 105 +│ - 106 │ - 108 │ JobID: 1 │ NonCancelable: true @@ -400,7 +400,7 @@ EXPLAIN (ddl, verbose) DROP TABLE multi_region_test_db.public.table_regional_by_ │ TableID: 108 │ ├── • RemoveJobStateFromDescriptor - │ DescriptorID: 105 + │ DescriptorID: 106 │ JobID: 1 │ ├── • RemoveJobStateFromDescriptor @@ -409,7 +409,7 @@ EXPLAIN (ddl, verbose) DROP TABLE multi_region_test_db.public.table_regional_by_ │ └── • UpdateSchemaChangerJob DescriptorIDsToRemove: - - 105 + - 106 - 108 IsNonCancelable: true JobID: 1 diff --git a/pkg/ccl/streamingccl/streamclient/random_stream_client.go b/pkg/ccl/streamingccl/streamclient/random_stream_client.go index 71b45a8f3b39..3b3892a19315 100644 --- a/pkg/ccl/streamingccl/streamclient/random_stream_client.go +++ b/pkg/ccl/streamingccl/streamclient/random_stream_client.go @@ -424,8 +424,7 @@ func getDescriptorAndNamespaceKVForTableID( // Generate namespace entry. codec := keys.MakeSQLCodec(config.tenantID) - key := catalogkeys.MakePublicObjectNameKey(codec, IngestionDatabaseID, testTable.Name) - k := rekey(config.tenantID, key) + k := rekey(config.tenantID, catalogkeys.EncodeNameKey(codec, testTable)) var value roachpb.Value value.SetInt(int64(testTable.GetID())) value.InitChecksum(k) diff --git a/pkg/sql/alter_schema.go b/pkg/sql/alter_schema.go index 1945dfd88f04..4614c8007870 100644 --- a/pkg/sql/alter_schema.go +++ b/pkg/sql/alter_schema.go @@ -235,7 +235,9 @@ func (p *planner) renameSchema( // Write the new name and remove the old name. b := p.txn.NewBatch() - p.renameNamespaceEntry(ctx, b, oldNameKey, desc) + if err := p.renameNamespaceEntry(ctx, b, oldNameKey, desc); err != nil { + return err + } if err := p.txn.Run(ctx, b); err != nil { return err } diff --git a/pkg/sql/alter_table_set_schema.go b/pkg/sql/alter_table_set_schema.go index a705b4c1a84a..644194b76fa2 100644 --- a/pkg/sql/alter_table_set_schema.go +++ b/pkg/sql/alter_table_set_schema.go @@ -124,7 +124,7 @@ func (n *alterTableSetSchemaNode) startExec(params runParams) error { return nil } - objectID, err := p.Descriptors().Direct().LookupObjectID( + objectID, err := p.Descriptors().LookupObjectID( ctx, p.txn, tableDesc.GetParentID(), desiredSchemaID, tableDesc.GetName(), ) if err == nil && objectID != descpb.InvalidID { @@ -138,7 +138,9 @@ func (n *alterTableSetSchemaNode) startExec(params runParams) error { tableDesc.SetParentSchemaID(desiredSchemaID) b := p.txn.NewBatch() - p.renameNamespaceEntry(ctx, b, oldNameKey, tableDesc) + if err := p.renameNamespaceEntry(ctx, b, oldNameKey, tableDesc); err != nil { + return err + } if err := p.writeSchemaChange( ctx, tableDesc, descpb.InvalidMutationID, tree.AsStringWithFQNames(n.n, params.Ann()), diff --git a/pkg/sql/alter_type.go b/pkg/sql/alter_type.go index 82dbabe0fd4f..bd858cfc472c 100644 --- a/pkg/sql/alter_type.go +++ b/pkg/sql/alter_type.go @@ -288,7 +288,9 @@ func (p *planner) performRenameTypeDesc( // Populate the namespace update batch. b := p.txn.NewBatch() - p.renameNamespaceEntry(ctx, b, oldNameKey, desc) + if err := p.renameNamespaceEntry(ctx, b, oldNameKey, desc); err != nil { + return err + } // Write the updated type descriptor. if err := p.writeTypeSchemaChange(ctx, desc, jobDesc); err != nil { diff --git a/pkg/sql/catalog/bootstrap/metadata.go b/pkg/sql/catalog/bootstrap/metadata.go index 1f549b8062b0..d3c57ab68403 100644 --- a/pkg/sql/catalog/bootstrap/metadata.go +++ b/pkg/sql/catalog/bootstrap/metadata.go @@ -173,6 +173,14 @@ func (ms MetadataSchema) GetInitialValues() ([]roachpb.KeyValue, []roachpb.RKey) add(keys.LegacyDescIDGenerator, legacyValue) } } + // Generate initial values for the system database's public schema, which + // doesn't have a descriptor. + { + publicSchemaValue := roachpb.Value{} + publicSchemaValue.SetInt(int64(keys.SystemPublicSchemaID)) + nameInfo := descpb.NameInfo{ParentID: keys.SystemDatabaseID, Name: tree.PublicSchema} + add(catalogkeys.EncodeNameKey(ms.codec, &nameInfo), publicSchemaValue) + } // Generate initial values for system databases and tables, which have // static descriptors that were generated elsewhere. @@ -180,16 +188,7 @@ func (ms MetadataSchema) GetInitialValues() ([]roachpb.KeyValue, []roachpb.RKey) // Create name metadata key. nameValue := roachpb.Value{} nameValue.SetInt(int64(desc.GetID())) - if desc.GetParentID() != keys.RootNamespaceID { - add(catalogkeys.MakePublicObjectNameKey(ms.codec, desc.GetParentID(), desc.GetName()), nameValue) - } else { - // Initializing a database. Databases must be initialized with - // the public schema, as all tables are scoped under the public schema. - add(catalogkeys.MakeDatabaseNameKey(ms.codec, desc.GetName()), nameValue) - publicSchemaValue := roachpb.Value{} - publicSchemaValue.SetInt(int64(keys.SystemPublicSchemaID)) - add(catalogkeys.MakeSchemaNameKey(ms.codec, desc.GetID(), tree.PublicSchema), publicSchemaValue) - } + add(catalogkeys.EncodeNameKey(ms.codec, desc), nameValue) // Set initial sequence values. if tbl, ok := desc.(catalog.TableDescriptor); ok && tbl.IsSequence() && tbl.GetID() != keys.DescIDSequenceID { diff --git a/pkg/sql/catalog/catalogkeys/BUILD.bazel b/pkg/sql/catalog/catalogkeys/BUILD.bazel index aabe8f9a3dc5..0ad79b9967f2 100644 --- a/pkg/sql/catalog/catalogkeys/BUILD.bazel +++ b/pkg/sql/catalog/catalogkeys/BUILD.bazel @@ -28,6 +28,7 @@ go_test( deps = [ "//pkg/keys", "//pkg/roachpb", + "//pkg/sql/catalog/descpb", "//pkg/util/leaktest", ], ) diff --git a/pkg/sql/catalog/catalogkeys/keys.go b/pkg/sql/catalog/catalogkeys/keys.go index 5412eaa5d5f2..436ebc40dc86 100644 --- a/pkg/sql/catalog/catalogkeys/keys.go +++ b/pkg/sql/catalog/catalogkeys/keys.go @@ -129,40 +129,6 @@ func PrettySpans(index catalog.Index, spans []roachpb.Span, skip int) string { return b.String() } -// NewNameKeyComponents returns a new catalog.NameKey instance for the given object -// name scoped under the given parent schema and parent database. -func NewNameKeyComponents( - parentID descpb.ID, parentSchemaID descpb.ID, name string, -) catalog.NameKey { - return descpb.NameInfo{ParentID: parentID, ParentSchemaID: parentSchemaID, Name: name} -} - -// MakeObjectNameKey returns the roachpb.Key for the given object name -// scoped under the given schema in the given database. -func MakeObjectNameKey( - codec keys.SQLCodec, parentID, parentSchemaID descpb.ID, name string, -) roachpb.Key { - return EncodeNameKey(codec, NewNameKeyComponents(parentID, parentSchemaID, name)) -} - -// MakePublicObjectNameKey returns the roachpb.Key for the given object name -// scoped under the public schema in the given database. -func MakePublicObjectNameKey(codec keys.SQLCodec, parentID descpb.ID, name string) roachpb.Key { - return EncodeNameKey(codec, NewNameKeyComponents(parentID, keys.PublicSchemaID, name)) -} - -// MakeSchemaNameKey returns the roachpb.Key for the given schema name scoped -// under the given database. -func MakeSchemaNameKey(codec keys.SQLCodec, parentID descpb.ID, name string) roachpb.Key { - return EncodeNameKey(codec, NewNameKeyComponents(parentID, keys.RootNamespaceID, name)) -} - -// MakeDatabaseNameKey returns the roachpb.Key corresponding to the database -// with the given name. -func MakeDatabaseNameKey(codec keys.SQLCodec, name string) roachpb.Key { - return EncodeNameKey(codec, NewNameKeyComponents(keys.RootNamespaceID, keys.RootNamespaceID, name)) -} - // MakeDatabaseChildrenNameKeyPrefix constructs a key which is a prefix to all // namespace entries for children of the requested database. func MakeDatabaseChildrenNameKeyPrefix(codec keys.SQLCodec, parentID descpb.ID) roachpb.Key { diff --git a/pkg/sql/catalog/catalogkeys/keys_test.go b/pkg/sql/catalog/catalogkeys/keys_test.go index 66d56183ade5..8d7f9fad2e9a 100644 --- a/pkg/sql/catalog/catalogkeys/keys_test.go +++ b/pkg/sql/catalog/catalogkeys/keys_test.go @@ -15,6 +15,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/roachpb" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/util/leaktest" ) @@ -27,16 +28,16 @@ func TestKeyAddress(t *testing.T) { }{ {MakeDescMetadataKey(tenSysCodec, 123)}, {MakeDescMetadataKey(tenSysCodec, 124)}, - {MakePublicObjectNameKey(tenSysCodec, 0, "BAR")}, - {MakePublicObjectNameKey(tenSysCodec, 1, "BAR")}, - {MakePublicObjectNameKey(tenSysCodec, 1, "foo")}, - {MakePublicObjectNameKey(tenSysCodec, 2, "foo")}, + {EncodeNameKey(tenSysCodec, &descpb.NameInfo{ParentID: 0, ParentSchemaID: 29, Name: "BAR"})}, + {EncodeNameKey(tenSysCodec, &descpb.NameInfo{ParentID: 1, ParentSchemaID: 29, Name: "BAR"})}, + {EncodeNameKey(tenSysCodec, &descpb.NameInfo{ParentID: 1, ParentSchemaID: 29, Name: "foo"})}, + {EncodeNameKey(tenSysCodec, &descpb.NameInfo{ParentID: 2, ParentSchemaID: 29, Name: "foo"})}, {MakeDescMetadataKey(ten5Codec, 123)}, {MakeDescMetadataKey(ten5Codec, 124)}, - {MakePublicObjectNameKey(ten5Codec, 0, "BAR")}, - {MakePublicObjectNameKey(ten5Codec, 1, "BAR")}, - {MakePublicObjectNameKey(ten5Codec, 1, "foo")}, - {MakePublicObjectNameKey(ten5Codec, 2, "foo")}, + {EncodeNameKey(ten5Codec, &descpb.NameInfo{ParentID: 0, ParentSchemaID: 29, Name: "BAR"})}, + {EncodeNameKey(ten5Codec, &descpb.NameInfo{ParentID: 1, ParentSchemaID: 29, Name: "BAR"})}, + {EncodeNameKey(ten5Codec, &descpb.NameInfo{ParentID: 1, ParentSchemaID: 29, Name: "foo"})}, + {EncodeNameKey(ten5Codec, &descpb.NameInfo{ParentID: 2, ParentSchemaID: 29, Name: "foo"})}, } var lastKey roachpb.Key for i, test := range testCases { diff --git a/pkg/sql/catalog/descs/collection.go b/pkg/sql/catalog/descs/collection.go index bbc6870622a9..bd5891d61a34 100644 --- a/pkg/sql/catalog/descs/collection.go +++ b/pkg/sql/catalog/descs/collection.go @@ -229,7 +229,7 @@ func (tc *Collection) AddUncommittedDescriptor( "cannot add uncommitted %s %q (%d) when a synthetic descriptor with the same name exists", desc.DescriptorType(), desc.GetName(), desc.GetID()) } - tc.stored.RemoveFromNameIndex(desc) + tc.stored.RemoveFromNameIndex(desc.GetID()) return tc.uncommitted.upsert(ctx, desc) } @@ -238,6 +238,9 @@ func (tc *Collection) AddUncommittedDescriptor( func (tc *Collection) WriteDescToBatch( ctx context.Context, kvTrace bool, desc catalog.MutableDescriptor, b *kv.Batch, ) error { + if desc.GetID() == descpb.InvalidID { + return errors.AssertionFailedf("cannot write descriptor with an empty ID: %v", desc) + } desc.MaybeIncrementVersion() if !tc.skipValidationOnWrite && tc.validationModeProvider.ValidateDescriptorsOnWrite() { if err := validate.Self(tc.version, desc); err != nil { @@ -264,12 +267,90 @@ func (tc *Collection) WriteDescToBatch( descKey := catalogkeys.MakeDescMetadataKey(tc.codec(), desc.GetID()) proto := desc.DescriptorProto() if kvTrace { - log.VEventf(ctx, 2, "Put %s -> %s", descKey, proto) + log.VEventf(ctx, 2, "CPut %s -> %s", descKey, proto) } b.CPut(descKey, proto, expected) return nil } +// DeleteDescToBatch adds a delete from system.descriptor to the batch. +func (tc *Collection) DeleteDescToBatch( + ctx context.Context, kvTrace bool, id descpb.ID, b *kv.Batch, +) error { + if id == descpb.InvalidID { + return errors.AssertionFailedf("cannot delete descriptor with an empty ID: %v", id) + } + descKey := catalogkeys.MakeDescMetadataKey(tc.codec(), id) + if kvTrace { + log.VEventf(ctx, 2, "Del %s", descKey) + } + b.Del(descKey) + tc.NotifyOfDeletedDescriptor(id) + return nil +} + +// InsertNamespaceEntryToBatch adds an insertion into system.namespace to the +// batch. +func (tc *Collection) InsertNamespaceEntryToBatch( + ctx context.Context, kvTrace bool, e catalog.NameEntry, b *kv.Batch, +) error { + if cachedID := tc.stored.GetCachedIDByName(e); cachedID != descpb.InvalidID { + tc.stored.RemoveFromNameIndex(cachedID) + } + tc.stored.RemoveFromNameIndex(e.GetID()) + if e.GetName() == "" || e.GetID() == descpb.InvalidID { + return errors.AssertionFailedf( + "cannot insert namespace entry (%d, %d, %q) -> %d with an empty name or ID", + e.GetParentID(), e.GetParentSchemaID(), e.GetName(), e.GetID(), + ) + } + nameKey := catalogkeys.EncodeNameKey(tc.codec(), e) + if kvTrace { + log.VEventf(ctx, 2, "CPut %s -> %d", nameKey, e.GetID()) + } + b.CPut(nameKey, e.GetID(), nil /* expValue */) + return nil +} + +// UpsertNamespaceEntryToBatch adds an upsert into system.namespace to the +// batch. +func (tc *Collection) UpsertNamespaceEntryToBatch( + ctx context.Context, kvTrace bool, e catalog.NameEntry, b *kv.Batch, +) error { + if cachedID := tc.stored.GetCachedIDByName(e); cachedID != descpb.InvalidID { + tc.stored.RemoveFromNameIndex(cachedID) + } + tc.stored.RemoveFromNameIndex(e.GetID()) + if e.GetName() == "" || e.GetID() == descpb.InvalidID { + return errors.AssertionFailedf( + "cannot upsert namespace entry (%d, %d, %q) -> %d with an empty name or ID", + e.GetParentID(), e.GetParentSchemaID(), e.GetName(), e.GetID(), + ) + } + nameKey := catalogkeys.EncodeNameKey(tc.codec(), e) + if kvTrace { + log.VEventf(ctx, 2, "Put %s -> %d", nameKey, e.GetID()) + } + b.Put(nameKey, e.GetID()) + return nil +} + +// DeleteNamespaceEntryToBatch adds a deletion from system.namespace to the +// batch. +func (tc *Collection) DeleteNamespaceEntryToBatch( + ctx context.Context, kvTrace bool, k catalog.NameKey, b *kv.Batch, +) error { + if cachedID := tc.stored.GetCachedIDByName(k); cachedID != descpb.InvalidID { + tc.stored.RemoveFromNameIndex(cachedID) + } + nameKey := catalogkeys.EncodeNameKey(tc.codec(), k) + if kvTrace { + log.VEventf(ctx, 2, "Del %s", nameKey) + } + b.Del(nameKey) + return nil +} + // WriteDesc constructs a new Batch, calls WriteDescToBatch and runs it. func (tc *Collection) WriteDesc( ctx context.Context, kvTrace bool, desc catalog.MutableDescriptor, txn *kv.Txn, @@ -281,6 +362,119 @@ func (tc *Collection) WriteDesc( return txn.Run(ctx, b) } +// LookupDatabaseID returns the descriptor ID assigned to a database name. +func (tc *Collection) LookupDatabaseID( + ctx context.Context, txn *kv.Txn, dbName string, +) (descpb.ID, error) { + // First look up in-memory descriptors in collection, + // except for leased descriptors. + dbInMemory, err := func() (catalog.Descriptor, error) { + flags := tree.CommonLookupFlags{ + Required: true, + AvoidLeased: true, + AvoidStorage: true, + IncludeOffline: true, + } + return tc.getDescriptorByName( + ctx, txn, nil /* db */, nil /* sc */, dbName, flags, catalog.Database, + ) + }() + if errors.IsAny(err, catalog.ErrDescriptorNotFound, catalog.ErrDescriptorDropped) { + // Swallow these errors to fall back to storage lookup. + err = nil + } + if err != nil { + return descpb.InvalidID, err + } + if dbInMemory != nil { + return dbInMemory.GetID(), nil + } + // Look up database ID in storage if nothing was found in memory. + return tc.stored.LookupDescriptorID(ctx, txn, keys.RootNamespaceID, keys.RootNamespaceID, dbName) +} + +// LookupSchemaID returns the descriptor ID assigned to a schema name. +func (tc *Collection) LookupSchemaID( + ctx context.Context, txn *kv.Txn, dbID descpb.ID, schemaName string, +) (descpb.ID, error) { + // First look up in-memory descriptors in collection, + // except for leased descriptors. + scInMemory, err := func() (catalog.Descriptor, error) { + flags := tree.CommonLookupFlags{ + Required: true, + AvoidLeased: true, + AvoidStorage: true, + IncludeOffline: true, + } + var parentDescs [1]catalog.Descriptor + if err := getDescriptorsByID(ctx, tc, txn, flags, parentDescs[:], dbID); err != nil { + return nil, err + } + db, err := catalog.AsDatabaseDescriptor(parentDescs[0]) + if err != nil { + return nil, err + } + return tc.getDescriptorByName( + ctx, txn, db, nil /* sc */, schemaName, flags, catalog.Schema, + ) + }() + if errors.IsAny(err, catalog.ErrDescriptorNotFound, catalog.ErrDescriptorDropped) { + // Swallow these errors to fall back to storage lookup. + err = nil + } + if err != nil { + return descpb.InvalidID, err + } + if scInMemory != nil { + return scInMemory.GetID(), nil + } + // Look up schema ID in storage if nothing was found in memory. + return tc.stored.LookupDescriptorID(ctx, txn, dbID, keys.RootNamespaceID, schemaName) +} + +// LookupObjectID returns the descriptor ID assigned to an object name. +func (tc *Collection) LookupObjectID( + ctx context.Context, txn *kv.Txn, dbID descpb.ID, schemaID descpb.ID, objectName string, +) (descpb.ID, error) { + // First look up in-memory descriptors in collection, + // except for leased descriptors. + objInMemory, err := func() (catalog.Descriptor, error) { + flags := tree.CommonLookupFlags{ + Required: true, + AvoidLeased: true, + AvoidStorage: true, + IncludeOffline: true, + } + var parentDescs [2]catalog.Descriptor + if err := getDescriptorsByID(ctx, tc, txn, flags, parentDescs[:], dbID, schemaID); err != nil { + return nil, err + } + db, err := catalog.AsDatabaseDescriptor(parentDescs[0]) + if err != nil { + return nil, err + } + sc, err := catalog.AsSchemaDescriptor(parentDescs[1]) + if err != nil { + return nil, err + } + return tc.getDescriptorByName( + ctx, txn, db, sc, objectName, flags, catalog.Any, + ) + }() + if errors.IsAny(err, catalog.ErrDescriptorNotFound, catalog.ErrDescriptorDropped) { + // Swallow these errors to fall back to storage lookup. + err = nil + } + if err != nil { + return descpb.InvalidID, err + } + if objInMemory != nil { + return objInMemory.GetID(), nil + } + // Look up ID in storage if nothing was found in memory. + return tc.stored.LookupDescriptorID(ctx, txn, dbID, schemaID, objectName) +} + // GetOriginalPreviousIDVersionsForUncommitted returns all the IDVersion // pairs for descriptors that have undergone a schema change. // Returns an empty slice for no schema changes. diff --git a/pkg/sql/catalog/descs/collection_test.go b/pkg/sql/catalog/descs/collection_test.go index 12ff0da2f274..8cd250b72328 100644 --- a/pkg/sql/catalog/descs/collection_test.go +++ b/pkg/sql/catalog/descs/collection_test.go @@ -35,7 +35,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descs" "github.com/cockroachdb/cockroach/pkg/sql/catalog/desctestutils" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/lease" "github.com/cockroachdb/cockroach/pkg/sql/catalog/nstree" "github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc" "github.com/cockroachdb/cockroach/pkg/sql/privilege" @@ -223,7 +222,6 @@ func TestAddUncommittedDescriptorAndMutableResolution(t *testing.T) { tdb.Exec(t, "CREATE SCHEMA db.sc") tdb.Exec(t, "CREATE TABLE db.sc.tab (i INT PRIMARY KEY)") tdb.Exec(t, "CREATE TYPE db.sc.typ AS ENUM ('foo')") - lm := s0.LeaseManager().(*lease.Manager) execCfg := s0.ExecutorConfig().(sql.ExecutorConfig) t.Run("database descriptors", func(t *testing.T) { require.NoError(t, sql.DescsTxn(ctx, &execCfg, func( @@ -233,44 +231,40 @@ func TestAddUncommittedDescriptorAndMutableResolution(t *testing.T) { flags.RequireMutable = true flags.Required = true - db, err := descriptors.GetMutableDatabaseByName(ctx, txn, "db", flags) - require.NoError(t, err) - - resolved, err := descriptors.GetMutableDatabaseByName(ctx, txn, "db", flags) + mut, err := descriptors.GetMutableDatabaseByName(ctx, txn, "db", flags) require.NoError(t, err) - require.Same(t, db, resolved) - - byID, err := descriptors.GetMutableDescriptorByID(ctx, txn, db.GetID()) + dbID := mut.GetID() + byID, err := descriptors.GetMutableDescriptorByID(ctx, txn, dbID) require.NoError(t, err) - require.Same(t, db, byID) + require.Same(t, mut, byID) - mut := db mut.MaybeIncrementVersion() - + mut.Name = "new_name" flags.RequireMutable = false + // Check that changes to the mutable descriptor don't impact the + // collection until they're added as uncommitted immByName, err := descriptors.GetImmutableDatabaseByName(ctx, txn, "db", flags) require.NoError(t, err) + require.Equal(t, dbID, immByName.GetID()) require.Equal(t, mut.OriginalVersion(), immByName.GetVersion()) - _, immByID, err := descriptors.GetImmutableDatabaseByID(ctx, txn, db.GetID(), flags) + _, immByID, err := descriptors.GetImmutableDatabaseByID(ctx, txn, dbID, flags) require.NoError(t, err) require.Same(t, immByName, immByID) - mut.Name = "new_name" - // Don't write the descriptor, just write the namespace entry. - // This will mean that resolution still is based on the old name. b := &kv.Batch{} - b.CPut(catalogkeys.MakeDatabaseNameKey(lm.Codec(), mut.Name), mut.GetID(), nil) + err = descriptors.InsertNamespaceEntryToBatch(ctx, false /* kvTrace */, mut, b) + require.NoError(t, err) err = txn.Run(ctx, b) require.NoError(t, err) - // Try to get the database descriptor by the new name and fail. - failedToResolve, err := descriptors.GetImmutableDatabaseByName(ctx, txn, "new_name", flags) - require.Regexp(t, `database "new_name" does not exist`, err) - require.Nil(t, failedToResolve) + // Should be able to get the database descriptor by the new name. + resolved, err := descriptors.GetImmutableDatabaseByName(ctx, txn, "new_name", flags) + require.Nil(t, err) + require.Equal(t, dbID, resolved.GetID()) // Try to get the database descriptor by the old name and succeed but get // the old version with the old name because the new version has not yet @@ -283,10 +277,10 @@ func TestAddUncommittedDescriptorAndMutableResolution(t *testing.T) { immByNameAfter, err := descriptors.GetImmutableDatabaseByName(ctx, txn, "new_name", flags) require.NoError(t, err) - require.Equal(t, db.GetVersion(), immByNameAfter.GetVersion()) + require.Equal(t, mut.GetVersion(), immByNameAfter.GetVersion()) require.Equal(t, mut.ImmutableCopy().DescriptorProto(), immByNameAfter.DescriptorProto()) - _, immByIDAfter, err := descriptors.GetImmutableDatabaseByID(ctx, txn, db.GetID(), flags) + _, immByIDAfter, err := descriptors.GetImmutableDatabaseByID(ctx, txn, dbID, flags) require.NoError(t, err) require.Same(t, immByNameAfter, immByIDAfter) @@ -1179,16 +1173,14 @@ SELECT id require.NoError(t, err) require.Equal(t, "foo", tabMut.GetName()) tabMut.Name = "baz" - if _, err := txn.Del(ctx, catalogkeys.MakeObjectNameKey( - codec, - tabMut.GetParentID(), tabMut.GetParentSchemaID(), tabMut.OriginalName(), - )); err != nil { + if _, err := txn.Del(ctx, catalogkeys.EncodeNameKey(codec, &descpb.NameInfo{ + ParentID: tabMut.GetParentID(), + ParentSchemaID: tabMut.GetParentSchemaID(), + Name: tabMut.OriginalName(), + })); err != nil { return err } - if err := txn.Put(ctx, catalogkeys.MakeObjectNameKey( - codec, - tabMut.GetParentID(), tabMut.GetParentSchemaID(), tabMut.GetName(), - ), int64(tabMut.ID)); err != nil { + if err := txn.Put(ctx, catalogkeys.EncodeNameKey(codec, tabMut), int64(tabMut.ID)); err != nil { return err } const kvTrace = false diff --git a/pkg/sql/catalog/descs/descriptor.go b/pkg/sql/catalog/descs/descriptor.go index ecd80bed7f06..8f1d0f38e546 100644 --- a/pkg/sql/catalog/descs/descriptor.go +++ b/pkg/sql/catalog/descs/descriptor.go @@ -132,14 +132,18 @@ func getDescriptorsByID( } // We want to avoid the allocation in the case that there is exactly one - // descriptor to resolve. This is the common case. The array stays on the - // stack. + // or two descriptors to resolve. These are the common cases. + // The array stays on the stack. var vls []catalog.ValidationLevel switch len(ids) { case 1: //gcassert:noescape var arr [1]catalog.ValidationLevel vls = arr[:] + case 2: + //gcassert:noescape + var arr [2]catalog.ValidationLevel + vls = arr[:] default: vls = make([]catalog.ValidationLevel, len(ids)) } @@ -188,6 +192,11 @@ func getDescriptorsByID( } } if !readIDs.Empty() { + if flags.AvoidStorage { + // Some descriptors are still missing and there's nowhere left to get + // them from. + return catalog.ErrDescriptorNotFound + } if err = tc.stored.EnsureFromStorageByIDs(ctx, txn, readIDs, catalog.Any); err != nil { return err } @@ -331,34 +340,24 @@ func (tc *Collection) getDescriptorByName( // When looking up descriptors by name, then descriptors in the adding state // must be uncommitted to be visible (among other things). flags.AvoidCommittedAdding = true - desc, err := tc.getDescriptorByID(ctx, txn, flags, id) - if err != nil { - // Swallow error if the descriptor is dropped. - if errors.Is(err, catalog.ErrDescriptorDropped) { - return nil, nil - } - if errors.Is(err, catalog.ErrDescriptorNotFound) { - // Special case for temporary schemas, which can't always be resolved by - // ID alone. - if db != nil && sc == nil && isTemporarySchema(name) { - return schemadesc.NewTemporarySchema(name, id, db.GetID()), nil - } - // In all other cases, having an ID should imply having a descriptor. - return nil, errors.WithAssertionFailure(err) - } - return nil, err + if err == nil { + return desc, nil } - if desc.GetName() != name && !(desc.DescriptorType() == catalog.Schema && isTemporarySchema(name)) { - // TODO(postamar): make Collection aware of name ops - // - // We're prevented from removing this check until the Collection mediates - // name changes in the system.namespace table similarly to how it mediates - // descriptor changes in system.descriptor via the uncommitted descriptors - // layer and the WriteDescsToBatch method. + // Swallow error if the descriptor is dropped. + if errors.Is(err, catalog.ErrDescriptorDropped) { return nil, nil } - return desc, nil + if errors.Is(err, catalog.ErrDescriptorNotFound) { + // Special case for temporary schemas, which can't always be resolved by + // ID alone. + if db != nil && sc == nil && isTemporarySchema(name) { + return schemadesc.NewTemporarySchema(name, id, db.GetID()), nil + } + // In all other cases, having an ID should imply having a descriptor. + return nil, errors.WithAssertionFailure(err) + } + return nil, err } type continueOrHalt bool @@ -385,11 +384,13 @@ func (tc *Collection) getVirtualDescriptorByName( }, } switch requestedType { + case catalog.Database, catalog.Function: + return continueLookups, nil, nil case catalog.Schema: if vs := tc.virtual.getSchemaByName(name); vs != nil { return haltLookups, vs, nil } - case catalog.Type: + case catalog.Type, catalog.Any: objFlags.DesiredObjectKind = tree.TypeObject fallthrough case catalog.Table: @@ -480,8 +481,12 @@ func (tc *Collection) getNonVirtualDescriptorID( return continueLookups, descpb.InvalidID, nil } lookupStoreCacheID := func() (continueOrHalt, descpb.ID, error) { - if cd := tc.stored.GetCachedByName(parentID, parentSchemaID, name); cd != nil { - return haltLookups, cd.GetID(), nil + if id := tc.stored.GetCachedIDByName(&descpb.NameInfo{ + ParentID: parentID, + ParentSchemaID: parentSchemaID, + Name: name, + }); id != descpb.InvalidID { + return haltLookups, id, nil } return continueLookups, descpb.InvalidID, nil } @@ -504,6 +509,9 @@ func (tc *Collection) getNonVirtualDescriptorID( return haltLookups, ld.GetID(), nil } lookupStoredID := func() (continueOrHalt, descpb.ID, error) { + if flags.AvoidStorage { + return haltLookups, descpb.InvalidID, nil + } id, err := tc.stored.LookupDescriptorID(ctx, txn, parentID, parentSchemaID, name) return haltLookups, id, err } diff --git a/pkg/sql/catalog/descs/schema.go b/pkg/sql/catalog/descs/schema.go index 044b755509a2..e49b2c0bc83d 100644 --- a/pkg/sql/catalog/descs/schema.go +++ b/pkg/sql/catalog/descs/schema.go @@ -14,6 +14,7 @@ import ( "context" "fmt" + "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/kv" "github.com/cockroachdb/cockroach/pkg/sql/catalog" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" @@ -133,3 +134,67 @@ func (tc *Collection) getSchemaByID( } return schemaDesc, nil } + +// InsertDescriptorlessPublicSchemaToBatch adds the creation of a new descriptorless public +// schema to the batch. +func (tc *Collection) InsertDescriptorlessPublicSchemaToBatch( + ctx context.Context, kvTrace bool, db catalog.DatabaseDescriptor, b *kv.Batch, +) error { + return tc.InsertTempSchemaToBatch(ctx, kvTrace, db, tree.PublicSchema, keys.PublicSchemaID, b) +} + +// DeleteDescriptorlessPublicSchemaToBatch adds the deletion of a new descriptorless public +// schema to the batch. +func (tc *Collection) DeleteDescriptorlessPublicSchemaToBatch( + ctx context.Context, kvTrace bool, db catalog.DatabaseDescriptor, b *kv.Batch, +) error { + return tc.DeleteTempSchemaToBatch(ctx, kvTrace, db, tree.PublicSchema, b) +} + +// InsertTempSchemaToBatch adds the creation of a new temporary schema to +// the batch. +func (tc *Collection) InsertTempSchemaToBatch( + ctx context.Context, + kvTrace bool, + db catalog.DatabaseDescriptor, + tempSchemaName string, + tempSchemaID descpb.ID, + b *kv.Batch, +) error { + entry := tempSchemaNameEntry{ + NameInfo: descpb.NameInfo{ + ParentID: db.GetID(), + Name: tempSchemaName, + }, + id: tempSchemaID, + } + return tc.InsertNamespaceEntryToBatch(ctx, kvTrace, &entry, b) +} + +// DeleteTempSchemaToBatch adds the deletion of a temporary schema to the +// batch. +func (tc *Collection) DeleteTempSchemaToBatch( + ctx context.Context, + kvTrace bool, + db catalog.DatabaseDescriptor, + tempSchemaName string, + b *kv.Batch, +) error { + nameInfo := descpb.NameInfo{ + ParentID: db.GetID(), + Name: tempSchemaName, + } + return tc.DeleteNamespaceEntryToBatch(ctx, kvTrace, &nameInfo, b) +} + +type tempSchemaNameEntry struct { + descpb.NameInfo + id descpb.ID +} + +var _ catalog.NameEntry = &tempSchemaNameEntry{} + +// GetID is part of the catalog.NameEntry interface. +func (t tempSchemaNameEntry) GetID() descpb.ID { + return t.id +} diff --git a/pkg/sql/catalog/descs/synthetic_descriptors.go b/pkg/sql/catalog/descs/synthetic_descriptors.go index 745f32055185..3be1be4999d3 100644 --- a/pkg/sql/catalog/descs/synthetic_descriptors.go +++ b/pkg/sql/catalog/descs/synthetic_descriptors.go @@ -33,11 +33,8 @@ func (sd *syntheticDescriptors) reset() { func (sd *syntheticDescriptors) getSyntheticByName( dbID descpb.ID, schemaID descpb.ID, name string, -) catalog.Descriptor { - if entry := sd.descs.GetByName(dbID, schemaID, name); entry != nil { - return entry.(catalog.Descriptor) - } - return nil +) catalog.NameEntry { + return sd.descs.GetByName(dbID, schemaID, name) } func (sd *syntheticDescriptors) getSyntheticByID(id descpb.ID) catalog.Descriptor { diff --git a/pkg/sql/catalog/descs/uncommitted_descriptors.go b/pkg/sql/catalog/descs/uncommitted_descriptors.go index 25b8559defc2..2e7b84b0323c 100644 --- a/pkg/sql/catalog/descs/uncommitted_descriptors.go +++ b/pkg/sql/catalog/descs/uncommitted_descriptors.go @@ -107,11 +107,8 @@ func (ud *uncommittedDescriptors) getUncommittedMutableByID( // it exists. func (ud *uncommittedDescriptors) getUncommittedByName( parentID, parentSchemaID descpb.ID, name string, -) catalog.Descriptor { - if e := ud.uncommitted.GetByName(parentID, parentSchemaID, name); e != nil { - return e.(catalog.Descriptor) - } - return nil +) catalog.NameEntry { + return ud.uncommitted.GetByName(parentID, parentSchemaID, name) } // iterateUncommittedByID applies fn to the uncommitted descriptors in ascending diff --git a/pkg/sql/catalog/ingesting/BUILD.bazel b/pkg/sql/catalog/ingesting/BUILD.bazel index b7ddc16b7013..0574c93a186f 100644 --- a/pkg/sql/catalog/ingesting/BUILD.bazel +++ b/pkg/sql/catalog/ingesting/BUILD.bazel @@ -15,7 +15,6 @@ go_library( "//pkg/roachpb", "//pkg/security/username", "//pkg/sql/catalog", - "//pkg/sql/catalog/catalogkeys", "//pkg/sql/catalog/catpb", "//pkg/sql/catalog/catprivilege", "//pkg/sql/catalog/dbdesc", diff --git a/pkg/sql/catalog/ingesting/write_descs.go b/pkg/sql/catalog/ingesting/write_descs.go index 3e80ea2e9d68..7af499bed3d0 100644 --- a/pkg/sql/catalog/ingesting/write_descs.go +++ b/pkg/sql/catalog/ingesting/write_descs.go @@ -18,7 +18,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/sql/catalog" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catprivilege" "github.com/cockroachdb/cockroach/pkg/sql/catalog/dbdesc" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" @@ -65,6 +64,7 @@ func WriteDescriptors( err = errors.Wrapf(err, "restoring table desc and namespace entries") }() + const kvTrace = false b := txn.NewBatch() // wroteDBs contains the database descriptors that are being published as part // of this restore. @@ -97,16 +97,20 @@ func WriteDescriptors( wroteDBs[desc.GetID()] = desc } if err := descsCol.WriteDescToBatch( - ctx, false /* kvTrace */, desc.(catalog.MutableDescriptor), b, + ctx, kvTrace, desc.(catalog.MutableDescriptor), b, ); err != nil { return err } - b.CPut(catalogkeys.EncodeNameKey(codec, desc), desc.GetID(), nil) + if err := descsCol.InsertNamespaceEntryToBatch(ctx, kvTrace, desc, b); err != nil { + return err + } // We also have to put a system.namespace entry for the public schema // if the database does not have a public schema backed by a descriptor. if !desc.HasPublicSchemaWithDescriptor() { - b.CPut(catalogkeys.MakeSchemaNameKey(codec, desc.GetID(), tree.PublicSchema), keys.PublicSchemaID, nil) + if err := descsCol.InsertDescriptorlessPublicSchemaToBatch(ctx, kvTrace, desc, b); err != nil { + return err + } } } @@ -130,11 +134,13 @@ func WriteDescriptors( wroteSchemas[sc.GetID()] = sc } if err := descsCol.WriteDescToBatch( - ctx, false /* kvTrace */, sc.(catalog.MutableDescriptor), b, + ctx, kvTrace, sc.(catalog.MutableDescriptor), b, ); err != nil { return err } - b.CPut(catalogkeys.EncodeNameKey(codec, sc), sc.GetID(), nil) + if err := descsCol.InsertNamespaceEntryToBatch(ctx, kvTrace, sc, b); err != nil { + return err + } } for i := range tables { @@ -160,11 +166,13 @@ func WriteDescriptors( } if err := descsCol.WriteDescToBatch( - ctx, false /* kvTrace */, tables[i].(catalog.MutableDescriptor), b, + ctx, kvTrace, tables[i].(catalog.MutableDescriptor), b, ); err != nil { return err } - b.CPut(catalogkeys.EncodeNameKey(codec, table), table.GetID(), nil) + if err := descsCol.InsertNamespaceEntryToBatch(ctx, kvTrace, table, b); err != nil { + return err + } } // Write all type descriptors -- create namespace entries and write to @@ -185,11 +193,13 @@ func WriteDescriptors( } } if err := descsCol.WriteDescToBatch( - ctx, false /* kvTrace */, typ.(catalog.MutableDescriptor), b, + ctx, kvTrace, typ.(catalog.MutableDescriptor), b, ); err != nil { return err } - b.CPut(catalogkeys.EncodeNameKey(codec, typ), typ.GetID(), nil) + if err := descsCol.InsertNamespaceEntryToBatch(ctx, kvTrace, typ, b); err != nil { + return err + } } for _, fn := range functions { @@ -207,7 +217,7 @@ func WriteDescriptors( } } if err := descsCol.WriteDescToBatch( - ctx, false /* kvTrace */, fn.(catalog.MutableDescriptor), b, + ctx, kvTrace, fn.(catalog.MutableDescriptor), b, ); err != nil { return err } diff --git a/pkg/sql/catalog/internal/catkv/catalog_reader.go b/pkg/sql/catalog/internal/catkv/catalog_reader.go index 9c7e9efa9ab2..873b9d946ce8 100644 --- a/pkg/sql/catalog/internal/catkv/catalog_reader.go +++ b/pkg/sql/catalog/internal/catkv/catalog_reader.go @@ -160,7 +160,7 @@ func (cr catalogReader) ScanNamespaceForDatabases( ctx context.Context, txn *kv.Txn, ) (nstree.Catalog, error) { return cr.scanNamespace( - ctx, txn, catalogkeys.MakeDatabaseNameKey(cr.codec, ""), + ctx, txn, catalogkeys.EncodeNameKey(cr.codec, &descpb.NameInfo{}), ) } @@ -169,7 +169,7 @@ func (cr catalogReader) ScanNamespaceForDatabaseSchemas( ctx context.Context, txn *kv.Txn, db catalog.DatabaseDescriptor, ) (nstree.Catalog, error) { return cr.scanNamespace( - ctx, txn, catalogkeys.MakeSchemaNameKey(cr.codec, db.GetID(), "" /* name */), + ctx, txn, catalogkeys.EncodeNameKey(cr.codec, &descpb.NameInfo{ParentID: db.GetID()}), ) } @@ -186,9 +186,10 @@ func (cr catalogReader) ScanNamespaceForDatabaseEntries( func (cr catalogReader) ScanNamespaceForSchemaObjects( ctx context.Context, txn *kv.Txn, db catalog.DatabaseDescriptor, sc catalog.SchemaDescriptor, ) (nstree.Catalog, error) { - return cr.scanNamespace(ctx, txn, catalogkeys.MakeObjectNameKey( - cr.codec, db.GetID(), sc.GetID(), "", /* name */ - )) + return cr.scanNamespace(ctx, txn, catalogkeys.EncodeNameKey(cr.codec, &descpb.NameInfo{ + ParentID: db.GetID(), + ParentSchemaID: sc.GetID(), + })) } // GetDescriptorEntries is part of the CatalogReader interface. diff --git a/pkg/sql/catalog/internal/catkv/direct.go b/pkg/sql/catalog/internal/catkv/direct.go index d94c7dcbd76f..4c3fbbd86948 100644 --- a/pkg/sql/catalog/internal/catkv/direct.go +++ b/pkg/sql/catalog/internal/catkv/direct.go @@ -17,13 +17,11 @@ import ( "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/kv" "github.com/cockroachdb/cockroach/pkg/sql/catalog" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/internal/validate" "github.com/cockroachdb/cockroach/pkg/sql/catalog/nstree" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sqlerrors" - "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/errors" ) @@ -129,14 +127,6 @@ type Direct interface { LookupObjectID( ctx context.Context, txn *kv.Txn, dbID descpb.ID, schemaID descpb.ID, objectName string, ) (descpb.ID, error) - - // WriteNewDescToBatch adds a CPut command writing a descriptor proto to the - // descriptors table. It writes the descriptor desc at the id descID, asserting - // that there was no previous descriptor at that id present already. If kvTrace - // is enabled, it will log an event explaining the CPut that was performed. - WriteNewDescToBatch( - ctx context.Context, kvTrace bool, b *kv.Batch, desc catalog.Descriptor, - ) error } // direct wraps a StoredCatalog to implement the Direct interface. @@ -232,15 +222,15 @@ func (d *direct) readDescriptorsForDirectAccess( if err != nil { return nil, err } + if err = d.ensure(ctx, c); err != nil { + return nil, err + } descs := make([]catalog.Descriptor, len(ids)) for i, id := range ids { desc := c.LookupDescriptorEntry(id) if desc == nil { continue } - if err := d.ensure(ctx, desc); err != nil { - return nil, err - } descs[i] = desc } return descs, nil @@ -383,16 +373,3 @@ func (d *direct) LookupDatabaseID( ) (descpb.ID, error) { return d.LookupDescriptorID(ctx, txn, keys.RootNamespaceID, keys.RootNamespaceID, dbName) } - -// WriteNewDescToBatch is part of the Direct interface. -func (d *direct) WriteNewDescToBatch( - ctx context.Context, kvTrace bool, b *kv.Batch, desc catalog.Descriptor, -) error { - descKey := catalogkeys.MakeDescMetadataKey(d.Codec(), desc.GetID()) - proto := desc.DescriptorProto() - if kvTrace { - log.VEventf(ctx, 2, "CPut %s -> %s", descKey, proto) - } - b.CPut(descKey, proto, nil) - return nil -} diff --git a/pkg/sql/catalog/internal/catkv/stored_catalog.go b/pkg/sql/catalog/internal/catkv/stored_catalog.go index b4c099f665a2..48e70d79295c 100644 --- a/pkg/sql/catalog/internal/catkv/stored_catalog.go +++ b/pkg/sql/catalog/internal/catkv/stored_catalog.go @@ -43,6 +43,9 @@ type StoredCatalog struct { // nameIndex is a subset of cache which allows lookups by name. nameIndex nstree.NameMap + // drainedNames is a set of keys which can't be looked up in nameIndex. + drainedNames map[descpb.NameInfo]struct{} + // validationLevels persists the levels to which each descriptor in cache // has already been validated. validationLevels map[descpb.ID]catalog.ValidationLevel @@ -108,20 +111,44 @@ func (sc *StoredCatalog) Reset(ctx context.Context) { } } -// ensure adds a descriptor to the StoredCatalog layer. +// ensure adds descriptors and namespace entries to the StoredCatalog layer. // This should not cause any information loss. -func (sc *StoredCatalog) ensure(ctx context.Context, desc catalog.Descriptor) error { - if _, isMutable := desc.(catalog.MutableDescriptor); isMutable { - return errors.AssertionFailedf("attempted to add mutable descriptor to StoredCatalog") - } - if sc.UpdateValidationLevel(desc, catalog.NoValidation) && sc.memAcc != nil { - if err := sc.memAcc.Grow(ctx, desc.ByteSize()); err != nil { - return err +func (sc *StoredCatalog) ensure(ctx context.Context, c nstree.Catalog) error { + if err := c.ForEachDescriptorEntry(func(desc catalog.Descriptor) error { + if _, isMutable := desc.(catalog.MutableDescriptor); isMutable { + return errors.AssertionFailedf("attempted to add mutable descriptor to StoredCatalog") + } + if sc.UpdateValidationLevel(desc, catalog.NoValidation) && sc.memAcc != nil { + if err := sc.memAcc.Grow(ctx, desc.ByteSize()); err != nil { + return err + } } + sc.cache.Upsert(desc) + skipNamespace := desc.Dropped() || desc.SkipNamespace() + sc.nameIndex.Upsert(desc, skipNamespace) + if !skipNamespace { + delete(sc.drainedNames, descpb.NameInfo{ + ParentID: desc.GetParentID(), + ParentSchemaID: desc.GetParentSchemaID(), + Name: desc.GetName(), + }) + } + return nil + }); err != nil { + return err } - sc.cache.Upsert(desc) - sc.nameIndex.Upsert(desc, desc.Dropped() || desc.SkipNamespace()) - return nil + return c.ForEachNamespaceEntry(func(e nstree.NamespaceEntry) error { + if sc.nameIndex.GetByID(e.GetID()) == nil && + sc.nameIndex.GetByName(e.GetParentID(), e.GetParentSchemaID(), e.GetName()) == nil { + sc.nameIndex.Upsert(e, false /* skipNameMap */) + } + delete(sc.drainedNames, descpb.NameInfo{ + ParentID: e.GetParentID(), + ParentSchemaID: e.GetParentSchemaID(), + Name: e.GetName(), + }) + return nil + }) } // GetCachedByID looks up a descriptor by ID. @@ -135,37 +162,31 @@ func (sc *StoredCatalog) GetCachedByID(id descpb.ID) catalog.Descriptor { return nil } -// getCachedIDByName looks up a descriptor ID by name in the cache. +// GetCachedIDByName looks up a descriptor ID by name in the cache. // Dropped descriptors are not added to the name index, so their IDs can't be // looked up by name in the cache. -func (sc *StoredCatalog) getCachedIDByName(key descpb.NameInfo) descpb.ID { - if e := sc.nameIndex.GetByName(key.ParentID, key.ParentSchemaID, key.Name); e != nil { +func (sc *StoredCatalog) GetCachedIDByName(key catalog.NameKey) descpb.ID { + if _, found := sc.drainedNames[descpb.NameInfo{ + ParentID: key.GetParentID(), + ParentSchemaID: key.GetParentSchemaID(), + Name: key.GetName(), + }]; found { + return descpb.InvalidID + } + if e := sc.nameIndex.GetByName(key.GetParentID(), key.GetParentSchemaID(), key.GetName()); e != nil { return e.GetID() } // If we're looking up a schema name, find it in the database if we have it. - if key.ParentID != descpb.InvalidID && key.ParentSchemaID == descpb.InvalidID { - if parentDesc := sc.GetCachedByID(key.ParentID); parentDesc != nil { + if key.GetParentID() != descpb.InvalidID && key.GetParentSchemaID() == descpb.InvalidID { + if parentDesc := sc.GetCachedByID(key.GetParentID()); parentDesc != nil { if db, ok := parentDesc.(catalog.DatabaseDescriptor); ok { - return db.GetSchemaID(key.Name) + return db.GetSchemaID(key.GetName()) } } } return descpb.InvalidID } -// GetCachedByName is the by-name equivalent of GetCachedByID. -func (sc *StoredCatalog) GetCachedByName( - dbID descpb.ID, schemaID descpb.ID, name string, -) catalog.Descriptor { - key := descpb.NameInfo{ParentID: dbID, ParentSchemaID: schemaID, Name: name} - if id := sc.getCachedIDByName(key); id != descpb.InvalidID { - if desc := sc.GetCachedByID(id); desc != nil && desc.GetName() == name { - return desc - } - } - return nil -} - // EnsureAllDescriptors ensures that all stored descriptors are cached. func (sc *StoredCatalog) EnsureAllDescriptors(ctx context.Context, txn *kv.Txn) error { if sc.hasAllDescriptors { @@ -175,9 +196,7 @@ func (sc *StoredCatalog) EnsureAllDescriptors(ctx context.Context, txn *kv.Txn) if err != nil { return err } - if err = c.ForEachDescriptorEntry(func(desc catalog.Descriptor) error { - return sc.ensure(ctx, desc) - }); err != nil { + if err = sc.ensure(ctx, c); err != nil { return err } sc.hasAllDescriptors = true @@ -194,6 +213,9 @@ func (sc *StoredCatalog) EnsureAllDatabaseDescriptors(ctx context.Context, txn * if err != nil { return err } + if err = sc.ensure(ctx, c); err != nil { + return err + } var readIDs catalog.DescriptorIDSet _ = c.ForEachNamespaceEntry(func(e nstree.NamespaceEntry) error { if id := e.GetID(); sc.GetCachedByID(id) == nil { @@ -224,6 +246,9 @@ func (sc *StoredCatalog) GetAllDescriptorNamesForDatabase( if err != nil { return nstree.Catalog{}, err } + if err = sc.ensure(ctx, c); err != nil { + return nstree.Catalog{}, err + } sc.allDescriptorsForDatabase[db.GetID()] = c } return c, nil @@ -242,6 +267,9 @@ func (sc *StoredCatalog) ensureAllSchemaIDsAndNamesForDatabase( if err != nil { return err } + if err = sc.ensure(ctx, c); err != nil { + return err + } m := make(map[descpb.ID]string) // This is needed at least for the temp system db during restores. if !db.HasPublicSchemaWithDescriptor() { @@ -294,7 +322,7 @@ func (sc *StoredCatalog) LookupDescriptorID( ) (descpb.ID, error) { // Look for the descriptor ID in memory first. key := descpb.NameInfo{ParentID: parentID, ParentSchemaID: parentSchemaID, Name: name} - if id := sc.getCachedIDByName(key); id != descpb.InvalidID { + if id := sc.GetCachedIDByName(&key); id != descpb.InvalidID { return id, nil } // Fall back to querying the namespace table. @@ -302,6 +330,9 @@ func (sc *StoredCatalog) LookupDescriptorID( if err != nil { return descpb.InvalidID, err } + if err = sc.ensure(ctx, c); err != nil { + return descpb.InvalidID, err + } if ne := c.LookupNamespaceEntry(key); ne != nil { return ne.GetID(), nil } @@ -324,9 +355,7 @@ func (sc *StoredCatalog) EnsureFromStorageByIDs( if err != nil { return err } - return c.ForEachDescriptorEntry(func(desc catalog.Descriptor) error { - return sc.ensure(ctx, desc) - }) + return sc.ensure(ctx, c) } // IterateCachedByID applies fn to all known descriptors in the cache in @@ -343,7 +372,11 @@ func (sc *StoredCatalog) IterateDatabasesByName( fn func(desc catalog.DatabaseDescriptor) error, ) error { return sc.nameIndex.IterateDatabasesByName(func(entry catalog.NameEntry) error { - db, err := catalog.AsDatabaseDescriptor(entry.(catalog.Descriptor)) + id := sc.GetCachedIDByName(entry) + if id == descpb.InvalidID { + return nil + } + db, err := catalog.AsDatabaseDescriptor(sc.GetCachedByID(id)) if err != nil { return err } @@ -376,11 +409,22 @@ func (sc *StoredCatalog) UpdateValidationLevel( return false } -// RemoveFromNameIndex removes a descriptor from the name index. -// This needs to be done if the descriptor is to be promoted to the uncommitted +// RemoveFromNameIndex removes an entry from the name index. +// This needs to be done if a descriptor is to be promoted to the uncommitted // layer which shadows this one in the descs.Collection. -func (sc *StoredCatalog) RemoveFromNameIndex(desc catalog.Descriptor) { - sc.nameIndex.Remove(desc.GetID()) +func (sc *StoredCatalog) RemoveFromNameIndex(id catid.DescID) { + e := sc.nameIndex.GetByID(id) + if e == nil { + return + } + if sc.drainedNames == nil { + sc.drainedNames = make(map[descpb.NameInfo]struct{}) + } + sc.drainedNames[descpb.NameInfo{ + ParentID: e.GetParentID(), + ParentSchemaID: e.GetParentSchemaID(), + Name: e.GetName(), + }] = struct{}{} } // NewValidationDereferencer returns this StoredCatalog object wrapped in a @@ -430,10 +474,7 @@ func (c storedCatalogBackedDereferencer) DereferenceDescriptors( return nil, err } // Add all descriptors to the cache BEFORE validating them. - err = read.ForEachDescriptorEntry(func(desc catalog.Descriptor) error { - return c.sc.ensure(ctx, desc) - }) - if err != nil { + if err = c.sc.ensure(ctx, read); err != nil { return nil, err } for j, id := range fallbackReqs { @@ -463,6 +504,9 @@ func (c storedCatalogBackedDereferencer) DereferenceDescriptorIDs( if err != nil { return nil, err } + if err = c.sc.ensure(ctx, read); err != nil { + return nil, err + } ret := make([]descpb.ID, len(reqs)) for i, nameInfo := range reqs { if ne := read.LookupNamespaceEntry(nameInfo); ne != nil { diff --git a/pkg/sql/crdb_internal_test.go b/pkg/sql/crdb_internal_test.go index 376960c68ebf..0e995c77d6ac 100644 --- a/pkg/sql/crdb_internal_test.go +++ b/pkg/sql/crdb_internal_test.go @@ -71,8 +71,8 @@ func TestGetAllNamesInternal(t *testing.T) { err := kvDB.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error { batch := txn.NewBatch() - batch.Put(catalogkeys.MakeObjectNameKey(keys.SystemSQLCodec, 999, 444, "bob"), 9999) - batch.Put(catalogkeys.MakePublicObjectNameKey(keys.SystemSQLCodec, 1000, "alice"), 10000) + batch.Put(catalogkeys.EncodeNameKey(keys.SystemSQLCodec, &descpb.NameInfo{ParentID: 999, ParentSchemaID: 444, Name: "bob"}), 9999) + batch.Put(catalogkeys.EncodeNameKey(keys.SystemSQLCodec, &descpb.NameInfo{ParentID: 1000, ParentSchemaID: 29, Name: "alice"}), 10000) return txn.CommitInBatch(ctx, batch) }) require.NoError(t, err) diff --git a/pkg/sql/create_function.go b/pkg/sql/create_function.go index 805c2bdbc015..45643fa50442 100644 --- a/pkg/sql/create_function.go +++ b/pkg/sql/create_function.go @@ -16,7 +16,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/keys" - "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catprivilege" @@ -129,10 +128,8 @@ func (n *createFunctionNode) createNewFunction( return err } - err := params.p.createDescriptorWithID( + err := params.p.createDescriptor( params.ctx, - roachpb.Key{}, // UDF does not have namespace entry. - udfDesc.GetID(), udfDesc, tree.AsStringWithFQNames(&n.cf.FuncName, params.Ann()), ) diff --git a/pkg/sql/create_schema.go b/pkg/sql/create_schema.go index 264fb58cb1a2..c84238919a05 100644 --- a/pkg/sql/create_schema.go +++ b/pkg/sql/create_schema.go @@ -18,7 +18,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/kv" "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/sql/catalog" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catprivilege" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" @@ -236,10 +235,8 @@ func (p *planner) createUserDefinedSchema(params runParams, n *tree.CreateSchema } // Finally create the schema on disk. - if err := p.createDescriptorWithID( + if err := p.createDescriptor( params.ctx, - catalogkeys.MakeSchemaNameKey(p.ExecCfg().Codec, db.ID, desc.Name), - desc.ID, desc, tree.AsStringWithFQNames(n, params.Ann()), ); err != nil { diff --git a/pkg/sql/create_sequence.go b/pkg/sql/create_sequence.go index df8f1c91b9b7..49d4fd5e004b 100644 --- a/pkg/sql/create_sequence.go +++ b/pkg/sql/create_sequence.go @@ -19,7 +19,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/server/telemetry" clustersettings "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/sql/catalog" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catprivilege" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catsessiondata" @@ -147,11 +146,7 @@ func doCreateSequence( return nil, err } - // makeSequenceTableDesc already validates the table. No call to - // desc.ValidateSelf() needed here. - - key := catalogkeys.MakeObjectNameKey(p.ExecCfg().Codec, dbDesc.GetID(), scDesc.GetID(), name.Object()) - if err = p.createDescriptorWithID(ctx, key, id, desc, jobDesc); err != nil { + if err = p.createDescriptor(ctx, desc, jobDesc); err != nil { return nil, err } diff --git a/pkg/sql/create_table.go b/pkg/sql/create_table.go index df3e49e4c14f..c4788bb323c3 100644 --- a/pkg/sql/create_table.go +++ b/pkg/sql/create_table.go @@ -28,7 +28,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/server/telemetry" "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/sql/catalog" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catprivilege" "github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo" @@ -415,10 +414,8 @@ func (n *createTableNode) startExec(params runParams) error { } // Descriptor written to store here. - if err := params.p.createDescriptorWithID( + if err := params.p.createDescriptor( params.ctx, - catalogkeys.MakeObjectNameKey(params.ExecCfg().Codec, n.dbDesc.GetID(), schema.GetID(), n.n.Table.Table()), - id, desc, tree.AsStringWithFQNames(n.n, params.Ann()), ); err != nil { diff --git a/pkg/sql/create_type.go b/pkg/sql/create_type.go index 3c53f5a919a6..4772efbd3b4d 100644 --- a/pkg/sql/create_type.go +++ b/pkg/sql/create_type.go @@ -17,7 +17,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/kv" "github.com/cockroachdb/cockroach/pkg/sql/catalog" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catprivilege" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descs" @@ -193,7 +192,7 @@ func findFreeArrayTypeName( arrayName := "_" + name for { // See if there is a collision with the current name. - objectID, err := col.Direct().LookupObjectID(ctx, txn, parentID, schemaID, arrayName) + objectID, err := col.LookupObjectID(ctx, txn, parentID, schemaID, arrayName) if err != nil { return "", err } @@ -264,7 +263,6 @@ func (p *planner) createArrayType( if err != nil { return 0, err } - arrayTypeKey := catalogkeys.MakeObjectNameKey(params.ExecCfg().Codec, db.GetID(), schemaID, arrayTypeName) // Generate the stable ID for the array type. id, err := params.EvalContext().DescIDGenerator.GenerateUniqueDescID(params.ctx) @@ -283,15 +281,8 @@ func (p *planner) createArrayType( if err != nil { return 0, err } - jobStr := fmt.Sprintf("implicit array type creation for %s", typ) - if err := p.createDescriptorWithID( - params.ctx, - arrayTypeKey, - id, - arrayTypDesc, - jobStr, - ); err != nil { + if err := p.createDescriptor(params.ctx, arrayTypDesc, jobStr); err != nil { return 0, err } return id, nil @@ -410,13 +401,7 @@ func (p *planner) createEnumWithID( typeDesc.ArrayTypeID = arrayTypeID // Now create the type after the implicit array type as been created. - if err := p.createDescriptorWithID( - params.ctx, - catalogkeys.MakeObjectNameKey(params.ExecCfg().Codec, dbDesc.GetID(), schema.GetID(), typeName.Type()), - id, - typeDesc, - typeName.String(), - ); err != nil { + if err := p.createDescriptor(params.ctx, typeDesc, typeName.String()); err != nil { return err } diff --git a/pkg/sql/create_view.go b/pkg/sql/create_view.go index 85a4e6887226..904efb0356d4 100644 --- a/pkg/sql/create_view.go +++ b/pkg/sql/create_view.go @@ -19,7 +19,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/server/telemetry" "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/sql/catalog" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catprivilege" "github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo" @@ -159,7 +158,7 @@ func (n *createViewNode) startExec(params runParams) error { case n.replace: // If we are replacing an existing view see if what we are // replacing is actually a view. - id, err := params.p.Descriptors().Direct().LookupObjectID( + id, err := params.p.Descriptors().LookupObjectID( params.ctx, params.p.txn, n.dbDesc.GetID(), @@ -289,19 +288,17 @@ func (n *createViewNode) startExec(params runParams) error { orderedTypeDeps.Add(backrefID) } desc.DependsOnTypes = append(desc.DependsOnTypes, orderedTypeDeps.Ordered()...) + newDesc = &desc // TODO (lucy): I think this needs a NodeFormatter implementation. For now, // do some basic string formatting (not accurate in the general case). - if err = params.p.createDescriptorWithID( + if err = params.p.createDescriptor( params.ctx, - catalogkeys.MakeObjectNameKey(params.ExecCfg().Codec, n.dbDesc.GetID(), schema.GetID(), n.viewName.Table()), - id, - &desc, + newDesc, fmt.Sprintf("CREATE VIEW %q AS %q", n.viewName, n.viewQuery), ); err != nil { return err } - newDesc = &desc } // Persist the back-references in all referenced table descriptors. diff --git a/pkg/sql/database.go b/pkg/sql/database.go index 84fdf737ed41..041028c5b70d 100644 --- a/pkg/sql/database.go +++ b/pkg/sql/database.go @@ -42,7 +42,7 @@ func (p *planner) renameDatabase( } // Check that the new name is available. - if dbID, err := p.Descriptors().Direct().LookupDatabaseID(ctx, p.txn, newName); err == nil && dbID != descpb.InvalidID { + if dbID, err := p.Descriptors().LookupDatabaseID(ctx, p.txn, newName); err == nil && dbID != descpb.InvalidID { return pgerror.Newf(pgcode.DuplicateDatabase, "the new database name %q already exists", newName) } else if err != nil { @@ -54,7 +54,9 @@ func (p *planner) renameDatabase( // Populate the namespace update batch. b := p.txn.NewBatch() - p.renameNamespaceEntry(ctx, b, oldNameKey, desc) + if err := p.renameNamespaceEntry(ctx, b, oldNameKey, desc); err != nil { + return err + } // Write the updated database descriptor. if err := p.writeNonDropDatabaseChange(ctx, desc, stmt); err != nil { diff --git a/pkg/sql/descriptor.go b/pkg/sql/descriptor.go index 33e5d00d20bb..abbbfab93aaa 100644 --- a/pkg/sql/descriptor.go +++ b/pkg/sql/descriptor.go @@ -13,23 +13,18 @@ package sql import ( "context" - "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/kv" - "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/server/telemetry" "github.com/cockroachdb/cockroach/pkg/settings" "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/sql/catalog" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/dbdesc" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/funcdesc" "github.com/cockroachdb/cockroach/pkg/sql/catalog/multiregion" "github.com/cockroachdb/cockroach/pkg/sql/catalog/schemadesc" "github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/typedesc" "github.com/cockroachdb/cockroach/pkg/sql/decodeusername" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" @@ -38,7 +33,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sqlerrors" "github.com/cockroachdb/cockroach/pkg/sql/sqltelemetry" - "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/uuid" "github.com/cockroachdb/errors" ) @@ -72,9 +66,8 @@ func (p *planner) createDatabase( ) (*dbdesc.Mutable, bool, error) { dbName := string(database.Name) - dKey := catalogkeys.MakeDatabaseNameKey(p.ExecCfg().Codec, dbName) - if dbID, err := p.Descriptors().Direct().LookupDatabaseID(ctx, p.txn, dbName); err == nil && dbID != descpb.InvalidID { + if dbID, err := p.Descriptors().LookupDatabaseID(ctx, p.txn, dbName); err == nil && dbID != descpb.InvalidID { if database.IfNotExists { // Check if the database is in a dropping state desc, err := p.Descriptors().Direct().MustGetDatabaseDescByID(ctx, p.txn, dbID) @@ -98,6 +91,10 @@ func (p *planner) createDatabase( if err != nil { return nil, false, err } + publicSchemaID, err := p.EvalContext().DescIDGenerator.GenerateUniqueDescID(ctx) + if err != nil { + return nil, false, err + } if database.PrimaryRegion != tree.PrimaryRegionNotSpecifiedName { telemetry.Inc(sqltelemetry.CreateMultiRegionDatabaseCounter) @@ -127,11 +124,6 @@ func (p *planner) createDatabase( return nil, false, err } - publicSchemaID, err := p.createPublicSchema(ctx, id, database) - if err != nil { - return nil, false, err - } - owner := p.SessionData().User() if !database.Owner.Undefined() { owner, err = decodeusername.FromRoleSpec( @@ -142,19 +134,33 @@ func (p *planner) createDatabase( } } - desc := dbdesc.NewInitial( + db := dbdesc.NewInitial( id, string(database.Name), owner, dbdesc.MaybeWithDatabaseRegionConfig(regionConfig), dbdesc.WithPublicSchemaID(publicSchemaID), ) + publicSchema := schemadesc.NewBuilder(&descpb.SchemaDescriptor{ + ParentID: id, + Name: tree.PublicSchema, + ID: publicSchemaID, + Privileges: catpb.NewPublicSchemaPrivilegeDescriptor(), + Version: 1, + }).BuildCreatedMutableSchema() - if err := p.checkCanAlterToNewOwner(ctx, desc, owner); err != nil { + if err := p.checkCanAlterToNewOwner(ctx, db, owner); err != nil { return nil, true, err } - if err := p.createDescriptorWithID(ctx, dKey, id, desc, jobDesc); err != nil { + if err := p.createDescriptor(ctx, db, jobDesc); err != nil { + return nil, true, err + } + if err := p.createDescriptor( + ctx, + publicSchema, + tree.AsStringWithFQNames(database, p.Ann()), + ); err != nil { return nil, true, err } @@ -162,144 +168,39 @@ func (p *planner) createDatabase( // database-level zone configuration if there is a region config on the // descriptor. - if err := p.maybeInitializeMultiRegionDatabase(ctx, desc, regionConfig); err != nil { + if err := p.maybeInitializeMultiRegionDatabase(ctx, db, regionConfig); err != nil { return nil, true, err } - return desc, true, nil -} - -func (p *planner) maybeCreatePublicSchemaWithDescriptor( - ctx context.Context, dbID descpb.ID, database *tree.CreateDatabase, -) (descpb.ID, error) { - publicSchemaID, err := p.EvalContext().DescIDGenerator.GenerateUniqueDescID(ctx) - if err != nil { - return descpb.InvalidID, err - } - - // Every database must be initialized with the public schema. - // Create the SchemaDescriptor. - publicSchemaPrivileges := catpb.NewPublicSchemaPrivilegeDescriptor() - publicSchemaDesc := schemadesc.NewBuilder(&descpb.SchemaDescriptor{ - ParentID: dbID, - Name: tree.PublicSchema, - ID: publicSchemaID, - Privileges: publicSchemaPrivileges, - Version: 1, - }).BuildCreatedMutableSchema() - - if err := p.createDescriptorWithID( - ctx, - catalogkeys.MakeSchemaNameKey(p.ExecCfg().Codec, dbID, tree.PublicSchema), - publicSchemaDesc.GetID(), - publicSchemaDesc, - tree.AsStringWithFQNames(database, p.Ann()), - ); err != nil { - return descpb.InvalidID, err - } - - return publicSchemaID, nil + return db, true, nil } -func (p *planner) createPublicSchema( - ctx context.Context, dbID descpb.ID, database *tree.CreateDatabase, -) (descpb.ID, error) { - publicSchemaID, err := p.maybeCreatePublicSchemaWithDescriptor(ctx, dbID, database) - if err != nil { - return descpb.InvalidID, err - } - if publicSchemaID != descpb.InvalidID { - return publicSchemaID, nil - } - // Every database must be initialized with the public schema. - key := catalogkeys.MakeSchemaNameKey(p.ExecCfg().Codec, dbID, tree.PublicSchema) - if err := p.CreateSchemaNamespaceEntry(ctx, key, keys.PublicSchemaID); err != nil { - return keys.PublicSchemaID, err - } - return keys.PublicSchemaID, nil -} - -func (p *planner) createDescriptorWithID( - ctx context.Context, - idKey roachpb.Key, - id descpb.ID, - descriptor catalog.Descriptor, - jobDesc string, +func (p *planner) createDescriptor( + ctx context.Context, descriptor catalog.MutableDescriptor, jobDesc string, ) error { - if descriptor.GetID() == 0 { - // TODO(ajwerner): Return the error here rather than fatal. - log.Fatalf(ctx, "%v", errors.AssertionFailedf("cannot create descriptor with an empty ID: %v", descriptor)) - } - if descriptor.GetID() != id { - log.Fatalf(ctx, "%v", errors.AssertionFailedf("cannot create descriptor with an unexpected (%v) ID: %v", id, descriptor)) + if !descriptor.IsNew() { + return errors.AssertionFailedf( + "expected new descriptor, not a modification of version %d", + descriptor.OriginalVersion()) } - // TODO(pmattis): The error currently returned below is likely going to be - // difficult to interpret. - // - // TODO(pmattis): Need to handle if-not-exists here as well. - // - // TODO(pmattis): This is writing the namespace and descriptor table entries, - // but not going through the normal INSERT logic and not performing a precise - // mimicry. In particular, we're only writing a single key per table, while - // perfect mimicry would involve writing a sentinel key for each row as well. - - if len(idKey) == 0 && !descriptor.SkipNamespace() { - log.Fatalf(ctx, "%v", errors.AssertionFailedf("cannot insert namespace entry with zero id key")) - } - if len(idKey) > 0 && descriptor.SkipNamespace() { - log.Fatalf(ctx, "%v", errors.AssertionFailedf("id key must be zero for descriptors skipping namespace")) - } - b := &kv.Batch{} - descID := descriptor.GetID() - - if !descriptor.SkipNamespace() { - if p.ExtendedEvalContext().Tracing.KVTracingEnabled() { - log.VEventf(ctx, 2, "CPut %s -> %d", idKey, descID) - } - b.CPut(idKey, descID, nil) - } - if err := p.Descriptors().Direct().WriteNewDescToBatch( - ctx, - p.ExtendedEvalContext().Tracing.KVTracingEnabled(), - b, - descriptor, - ); err != nil { + kvTrace := p.ExtendedEvalContext().Tracing.KVTracingEnabled() + if err := p.Descriptors().WriteDescToBatch(ctx, kvTrace, descriptor, b); err != nil { return err } - - mutDesc, ok := descriptor.(catalog.MutableDescriptor) - if !ok { - log.Fatalf(ctx, "unexpected type %T when creating descriptor", descriptor) - } - - isTable := false - addUncommitted := false - switch mutDesc.(type) { - case *dbdesc.Mutable, *schemadesc.Mutable, *typedesc.Mutable, *funcdesc.Mutable: - addUncommitted = true - case *tabledesc.Mutable: - addUncommitted = true - isTable = true - default: - log.Fatalf(ctx, "unexpected type %T when creating descriptor", mutDesc) - } - if addUncommitted { - if err := p.Descriptors().AddUncommittedDescriptor(ctx, mutDesc); err != nil { + if !descriptor.SkipNamespace() { + if err := p.Descriptors().InsertNamespaceEntryToBatch(ctx, kvTrace, descriptor, b); err != nil { return err } } - if err := p.txn.Run(ctx, b); err != nil { return err } - if isTable && mutDesc.Adding() { + if tbl, ok := descriptor.(*tabledesc.Mutable); ok && tbl.Adding() { // Queue a schema change job to eventually make the table public. if err := p.createOrUpdateSchemaChangeJob( - ctx, - mutDesc.(*tabledesc.Mutable), - jobDesc, - descpb.InvalidMutationID); err != nil { + ctx, tbl, jobDesc, descpb.InvalidMutationID, + ); err != nil { return err } } diff --git a/pkg/sql/drop_database.go b/pkg/sql/drop_database.go index e04084f1cb91..8e5b24fd746a 100644 --- a/pkg/sql/drop_database.go +++ b/pkg/sql/drop_database.go @@ -14,9 +14,9 @@ import ( "context" "github.com/cockroachdb/cockroach/pkg/keys" + "github.com/cockroachdb/cockroach/pkg/kv" "github.com/cockroachdb/cockroach/pkg/server/telemetry" "github.com/cockroachdb/cockroach/pkg/sql/catalog" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys" "github.com/cockroachdb/cockroach/pkg/sql/catalog/dbdesc" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc" @@ -145,11 +145,24 @@ func (n *dropDatabaseNode) startExec(params runParams) error { for _, schemaWithDbDesc := range n.d.schemasToDelete { schemaToDelete := schemaWithDbDesc.schema switch schemaToDelete.SchemaKind() { - case catalog.SchemaTemporary, catalog.SchemaPublic: - // The public schema and temporary schemas are cleaned up by just removing - // the existing namespace entries. - key := catalogkeys.MakeSchemaNameKey(p.ExecCfg().Codec, n.dbDesc.GetID(), schemaToDelete.GetName()) - if _, err := p.txn.Del(ctx, key); err != nil { + case catalog.SchemaPublic: + b := &kv.Batch{} + if err := p.Descriptors().DeleteDescriptorlessPublicSchemaToBatch( + ctx, p.ExtendedEvalContext().Tracing.KVTracingEnabled(), n.dbDesc, b, + ); err != nil { + return err + } + if err := p.txn.Run(ctx, b); err != nil { + return err + } + case catalog.SchemaTemporary: + b := &kv.Batch{} + if err := p.Descriptors().DeleteTempSchemaToBatch( + ctx, p.ExtendedEvalContext().Tracing.KVTracingEnabled(), n.dbDesc, schemaToDelete.GetName(), b, + ); err != nil { + return err + } + if err := p.txn.Run(ctx, b); err != nil { return err } case catalog.SchemaUserDefined: @@ -180,7 +193,9 @@ func (n *dropDatabaseNode) startExec(params runParams) error { n.dbDesc.SetDropped() b := p.txn.NewBatch() - p.dropNamespaceEntry(ctx, b, n.dbDesc) + if err := p.dropNamespaceEntry(ctx, b, n.dbDesc); err != nil { + return err + } // Note that a job was already queued above. if err := p.writeDatabaseChangeToBatch(ctx, n.dbDesc, b); err != nil { diff --git a/pkg/sql/drop_schema.go b/pkg/sql/drop_schema.go index f4bb7fcb1ae1..fe1f49ae8f5b 100644 --- a/pkg/sql/drop_schema.go +++ b/pkg/sql/drop_schema.go @@ -222,7 +222,9 @@ func (p *planner) dropSchemaImpl( // Populate namespace update batch. b := p.txn.NewBatch() - p.dropNamespaceEntry(ctx, b, sc) + if err := p.dropNamespaceEntry(ctx, b, sc); err != nil { + return err + } // Remove any associated comments. if err := p.removeSchemaComment(ctx, sc.GetID()); err != nil { diff --git a/pkg/sql/drop_table.go b/pkg/sql/drop_table.go index bd4fa82d72ff..4e33d39e929e 100644 --- a/pkg/sql/drop_table.go +++ b/pkg/sql/drop_table.go @@ -356,7 +356,9 @@ func (p *planner) initiateDropTable( // Delete namespace entry for table. b := p.txn.NewBatch() - p.dropNamespaceEntry(ctx, b, tableDesc) + if err := p.dropNamespaceEntry(ctx, b, tableDesc); err != nil { + return err + } if err := p.txn.Run(ctx, b); err != nil { return err } diff --git a/pkg/sql/drop_test.go b/pkg/sql/drop_test.go index c4f572106d29..62ad831ff465 100644 --- a/pkg/sql/drop_test.go +++ b/pkg/sql/drop_test.go @@ -234,7 +234,7 @@ CREATE DATABASE t; t.Fatal(err) } - dKey := catalogkeys.MakeDatabaseNameKey(keys.SystemSQLCodec, "t") + dKey := catalogkeys.EncodeNameKey(keys.SystemSQLCodec, descpb.NameInfo{Name: "t"}) r, err := kvDB.Get(ctx, dKey) if err != nil { t.Fatal(err) @@ -598,7 +598,11 @@ func TestDropTable(t *testing.T) { parentSchemaID := descpb.ID(sqlutils.QuerySchemaID(t, sqlDB, "t", "public")) tableDesc := desctestutils.TestingGetPublicTableDescriptor(kvDB, keys.SystemSQLCodec, "t", "kv") - nameKey := catalogkeys.MakeObjectNameKey(keys.SystemSQLCodec, parentDatabaseID, parentSchemaID, "kv") + nameKey := catalogkeys.EncodeNameKey(keys.SystemSQLCodec, &descpb.NameInfo{ + ParentID: parentDatabaseID, + ParentSchemaID: parentSchemaID, + Name: "kv", + }) gr, err := kvDB.Get(ctx, nameKey) if err != nil { @@ -702,7 +706,11 @@ func TestDropTableDeleteData(t *testing.T) { parentDatabaseID := descpb.ID(sqlutils.QueryDatabaseID(t, sqlDB, "t")) parentSchemaID := descpb.ID(sqlutils.QuerySchemaID(t, sqlDB, "t", "public")) - nameKey := catalogkeys.MakeObjectNameKey(keys.SystemSQLCodec, parentDatabaseID, parentSchemaID, tableName) + nameKey := catalogkeys.EncodeNameKey(keys.SystemSQLCodec, &descpb.NameInfo{ + ParentID: parentDatabaseID, + ParentSchemaID: parentSchemaID, + Name: tableName, + }) gr, err := kvDB.Get(ctx, nameKey) if err != nil { t.Fatal(err) diff --git a/pkg/sql/drop_type.go b/pkg/sql/drop_type.go index 3b7a22c3af05..31b1f2aa3bae 100644 --- a/pkg/sql/drop_type.go +++ b/pkg/sql/drop_type.go @@ -268,7 +268,9 @@ func (p *planner) dropTypeImpl( // Delete namespace entry for type. b := p.txn.NewBatch() - p.dropNamespaceEntry(ctx, b, typeDesc) + if err := p.dropNamespaceEntry(ctx, b, typeDesc); err != nil { + return err + } if err := p.txn.Run(ctx, b); err != nil { return err } diff --git a/pkg/sql/gcjob/table_garbage_collection.go b/pkg/sql/gcjob/table_garbage_collection.go index 430caea4c9ec..8d63463b2c08 100644 --- a/pkg/sql/gcjob/table_garbage_collection.go +++ b/pkg/sql/gcjob/table_garbage_collection.go @@ -89,9 +89,7 @@ func gcTables( } // Finished deleting all the table data, now delete the table meta data. - if err := sql.DeleteTableDescAndZoneConfig( - ctx, execCfg.DB, execCfg.Settings, execCfg.Codec, table, - ); err != nil { + if err := sql.DeleteTableDescAndZoneConfig(ctx, execCfg, table); err != nil { return errors.Wrapf(err, "dropping table descriptor for table %d", table.GetID()) } @@ -334,9 +332,7 @@ func deleteTableDescriptorsAfterGC( } // Finished deleting all the table data, now delete the table meta data. - if err := sql.DeleteTableDescAndZoneConfig( - ctx, execCfg.DB, execCfg.Settings, execCfg.Codec, table, - ); err != nil { + if err := sql.DeleteTableDescAndZoneConfig(ctx, execCfg, table); err != nil { return errors.Wrapf(err, "dropping table descriptor for table %d", table.GetID()) } diff --git a/pkg/sql/importer/BUILD.bazel b/pkg/sql/importer/BUILD.bazel index 2947bab5c919..c13825a525dd 100644 --- a/pkg/sql/importer/BUILD.bazel +++ b/pkg/sql/importer/BUILD.bazel @@ -52,7 +52,6 @@ go_library( "//pkg/settings/cluster", "//pkg/sql", "//pkg/sql/catalog", - "//pkg/sql/catalog/catalogkeys", "//pkg/sql/catalog/catpb", "//pkg/sql/catalog/colinfo", "//pkg/sql/catalog/dbdesc", diff --git a/pkg/sql/importer/import_job.go b/pkg/sql/importer/import_job.go index b05451ee0e13..0f515186efa1 100644 --- a/pkg/sql/importer/import_job.go +++ b/pkg/sql/importer/import_job.go @@ -30,7 +30,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/sql" "github.com/cockroachdb/cockroach/pkg/sql/catalog" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys" "github.com/cockroachdb/cockroach/pkg/sql/catalog/dbdesc" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descidgen" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" @@ -672,9 +671,17 @@ func (r *importResumer) prepareSchemasForIngestion( // Finally create the schemas on disk. for i, mutDesc := range mutableSchemaDescs { - nameKey := catalogkeys.MakeSchemaNameKey(p.ExecCfg().Codec, dbDesc.ID, mutDesc.GetName()) - err = createSchemaDescriptorWithID(ctx, nameKey, mutDesc.ID, mutDesc, p, descsCol, txn) - if err != nil { + b := &kv.Batch{} + kvTrace := p.ExtendedEvalContext().Tracing.KVTracingEnabled() + if err := descsCol.WriteDescToBatch(ctx, kvTrace, mutDesc, b); err != nil { + return nil, err + } + if !mutDesc.SkipNamespace() { + if err := descsCol.InsertNamespaceEntryToBatch(ctx, kvTrace, mutDesc, b); err != nil { + return nil, err + } + } + if err := txn.Run(ctx, b); err != nil { return nil, err } schemaMetadata.schemaPreparedDetails.Schemas[i] = jobspb.ImportDetails_Schema{ @@ -711,54 +718,6 @@ func bindImportStartTime( return nil } -// createSchemaDescriptorWithID writes a schema descriptor with `id` to disk. -func createSchemaDescriptorWithID( - ctx context.Context, - idKey roachpb.Key, - id descpb.ID, - descriptor catalog.Descriptor, - p sql.JobExecContext, - descsCol *descs.Collection, - txn *kv.Txn, -) error { - if descriptor.GetID() == descpb.InvalidID { - return errors.AssertionFailedf("cannot create descriptor with an empty ID: %v", descriptor) - } - if descriptor.GetID() != id { - return errors.AssertionFailedf("cannot create descriptor with an ID %v; expected ID %v; descriptor %v", - id, descriptor.GetID(), descriptor) - } - b := &kv.Batch{} - descID := descriptor.GetID() - if p.ExtendedEvalContext().Tracing.KVTracingEnabled() { - log.VEventf(ctx, 2, "CPut %s -> %d", idKey, descID) - } - b.CPut(idKey, descID, nil) - if err := descsCol.Direct().WriteNewDescToBatch( - ctx, - p.ExtendedEvalContext().Tracing.KVTracingEnabled(), - b, - descriptor, - ); err != nil { - return err - } - - mutDesc, ok := descriptor.(catalog.MutableDescriptor) - if !ok { - return errors.Newf("unexpected type %T when creating descriptor", descriptor) - } - switch mutDesc.(type) { - case *schemadesc.Mutable: - if err := descsCol.AddUncommittedDescriptor(ctx, mutDesc); err != nil { - return err - } - default: - return errors.Newf("unexpected type %T when creating descriptor", mutDesc) - } - - return txn.Run(ctx, b) -} - // parseBundleSchemaIfNeeded parses dump files (PGDUMP, MYSQLDUMP) for DDL // statements and creates the relevant database, schema, table and type // descriptors. Data from the dump files is ingested into these descriptors in @@ -1606,9 +1565,7 @@ func (r *importResumer) dropNewTables( // possible. This is safe since the table data was never visible to users, // and so we don't need to preserve MVCC semantics. newTableDesc.DropTime = dropTime - b.Del(catalogkeys.EncodeNameKey(execCfg.Codec, newTableDesc)) tablesToGC = append(tablesToGC, newTableDesc.ID) - descsCol.NotifyOfDeletedDescriptor(newTableDesc.GetID()) // Accumulate the changes before adding them to the batch to avoid // making any table invalid before having read it. @@ -1619,6 +1576,10 @@ func (r *importResumer) dropNewTables( if err := descsCol.WriteDescToBatch(ctx, kvTrace, d, b); err != nil { return err } + if err := descsCol.DeleteNamespaceEntryToBatch(ctx, kvTrace, d, b); err != nil { + return err + } + descsCol.NotifyOfDeletedDescriptor(d.GetID()) } // Queue a GC job. @@ -1693,10 +1654,14 @@ func (r *importResumer) dropSchemas( if dbDesc.Schemas != nil { delete(dbDesc.Schemas, schemaDesc.GetName()) } - b.Del(catalogkeys.EncodeNameKey(p.ExecCfg().Codec, schemaDesc)) - - if err := descsCol.WriteDescToBatch(ctx, p.ExtendedEvalContext().Tracing.KVTracingEnabled(), - schemaDesc, b); err != nil { + if err := descsCol.WriteDescToBatch( + ctx, p.ExtendedEvalContext().Tracing.KVTracingEnabled(), schemaDesc, b, + ); err != nil { + return nil, err + } + if err := descsCol.DeleteNamespaceEntryToBatch( + ctx, p.ExtendedEvalContext().Tracing.KVTracingEnabled(), schemaDesc, b, + ); err != nil { return nil, err } err = txn.Run(ctx, b) diff --git a/pkg/sql/name_util.go b/pkg/sql/name_util.go index 7a5dc4f12835..f5527db2a38b 100644 --- a/pkg/sql/name_util.go +++ b/pkg/sql/name_util.go @@ -15,41 +15,23 @@ import ( "github.com/cockroachdb/cockroach/pkg/kv" "github.com/cockroachdb/cockroach/pkg/sql/catalog" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys" - "github.com/cockroachdb/cockroach/pkg/util/log" ) func (p *planner) dropNamespaceEntry( - ctx context.Context, b *kv.Batch, desc catalog.MutableDescriptor, -) { - // Delete current namespace entry. - deleteNamespaceEntry(ctx, b, p, desc, desc) + ctx context.Context, b *kv.Batch, oldNameKey catalog.NameKey, +) error { + return p.Descriptors().DeleteNamespaceEntryToBatch( + ctx, p.ExtendedEvalContext().Tracing.KVTracingEnabled(), oldNameKey, b, + ) } func (p *planner) renameNamespaceEntry( ctx context.Context, b *kv.Batch, oldNameKey catalog.NameKey, desc catalog.MutableDescriptor, -) { - // Delete old namespace entry. - deleteNamespaceEntry(ctx, b, p, oldNameKey, desc) - - // Write new namespace entry. - marshalledKey := catalogkeys.EncodeNameKey(p.ExecCfg().Codec, desc) - if p.extendedEvalCtx.Tracing.KVTracingEnabled() { - log.VEventf(ctx, 2, "CPut %s -> %d", marshalledKey, desc.GetID()) - } - b.CPut(marshalledKey, desc.GetID(), nil) -} - -func deleteNamespaceEntry( - ctx context.Context, - b *kv.Batch, - p *planner, - nameKeyToDelete catalog.NameKey, - desc catalog.MutableDescriptor, -) { - marshalledKey := catalogkeys.EncodeNameKey(p.ExecCfg().Codec, nameKeyToDelete) - if p.extendedEvalCtx.Tracing.KVTracingEnabled() { - log.VEventf(ctx, 2, "Del %s", marshalledKey) +) error { + if err := p.dropNamespaceEntry(ctx, b, oldNameKey); err != nil { + return err } - b.Del(marshalledKey) + return p.Descriptors().InsertNamespaceEntryToBatch( + ctx, p.ExtendedEvalContext().Tracing.KVTracingEnabled(), desc, b, + ) } diff --git a/pkg/sql/opt/exec/execbuilder/testdata/show_trace b/pkg/sql/opt/exec/execbuilder/testdata/show_trace index e305f02d0462..f803c861d116 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/show_trace +++ b/pkg/sql/opt/exec/execbuilder/testdata/show_trace @@ -50,10 +50,10 @@ SET tracing = on,kv,results; CREATE DATABASE t; SET tracing = off query TT $trace_query ---- -create database CPut /NamespaceTable/30/1/106/0/"public"/4/1 -> 107 -create database CPut /Table/3/1/107/2/1 -> schema: version:1 parent_id:106 privileges: users: users: owner_proto:"admin" version:2 > > -create database CPut /NamespaceTable/30/1/0/0/"t"/4/1 -> 106 create database CPut /Table/3/1/106/2/1 -> database: version:1 privileges: users: users: owner_proto:"root" version:2 > schemas: > state:PUBLIC offline_reason:"" default_privileges: > +create database CPut /NamespaceTable/30/1/0/0/"t"/4/1 -> 106 +create database CPut /Table/3/1/107/2/1 -> schema: version:1 parent_id:106 privileges: users: users: owner_proto:"admin" version:2 > > +create database CPut /NamespaceTable/30/1/106/0/"public"/4/1 -> 107 sql query rows affected: 0 @@ -64,8 +64,8 @@ SET tracing = on,kv,results; CREATE TABLE t.kv(k INT PRIMARY KEY, v INT, FAMILY query TT $trace_query ---- -create table CPut /NamespaceTable/30/1/106/107/"kv"/4/1 -> 108 create table CPut /Table/3/1/108/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 not_visible:false > next_index_id:2 privileges: users: owner_proto:"root" version:2 > next_mutation_id:1 format_version:3 state:PUBLIC offline_reason:"" view_query:"" is_materialized_view:false refresh_view_required:false drop_time:0 replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:2 import_start_wall_time:0 > +create table CPut /NamespaceTable/30/1/106/107/"kv"/4/1 -> 108 sql query rows affected: 0 # We avoid using the full trace output, because that would make the @@ -80,7 +80,7 @@ SET tracing = on,kv,results; CREATE UNIQUE INDEX woo ON t.kv(v); SET tracing = o query TT $trace_query ---- -create index Put /Table/3/1/108/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 not_visible:false > next_index_id:4 privileges: users: owner_proto:"root" version:2 > mutations: interleave:<> partitioning: type:FORWARD created_explicitly:true encoding_type:0 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:2 not_visible:false > state:BACKFILLING direction:ADD mutation_id:1 rollback:false > mutations: interleave:<> partitioning: type:FORWARD created_explicitly:true encoding_type:0 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:true created_at_nanos:... constraint_id:3 not_visible:false > state:DELETE_ONLY direction:ADD mutation_id:1 rollback:false > next_mutation_id:2 format_version:3 state:PUBLIC offline_reason:"" view_query:"" is_materialized_view:false refresh_view_required:false mutationJobs:<...> drop_time:0 replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:4 import_start_wall_time:0 > +create index CPut /Table/3/1/108/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 not_visible:false > next_index_id:4 privileges: users: owner_proto:"root" version:2 > mutations: interleave:<> partitioning: type:FORWARD created_explicitly:true encoding_type:0 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:2 not_visible:false > state:BACKFILLING direction:ADD mutation_id:1 rollback:false > mutations: interleave:<> partitioning: type:FORWARD created_explicitly:true encoding_type:0 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:true created_at_nanos:... constraint_id:3 not_visible:false > state:DELETE_ONLY direction:ADD mutation_id:1 rollback:false > next_mutation_id:2 format_version:3 state:PUBLIC offline_reason:"" view_query:"" is_materialized_view:false refresh_view_required:false mutationJobs:<...> drop_time:0 replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:4 import_start_wall_time:0 > sql query rows affected: 0 statement ok @@ -126,8 +126,8 @@ SET tracing = off query TT $trace_query ---- -create table CPut /NamespaceTable/30/1/106/107/"kv2"/4/1 -> 109 create table CPut /Table/3/1/109/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:false default_expr:"unique_rowid()" hidden:true inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:4 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 not_visible:false > next_index_id:2 privileges: users: owner_proto:"root" version:2 > next_mutation_id:1 format_version:3 state:ADD offline_reason:"" view_query:"" is_materialized_view:false refresh_view_required:false drop_time:0 replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"TABLE t.public.kv" create_as_of_time:<> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:2 import_start_wall_time:0 > +create table CPut /NamespaceTable/30/1/106/107/"kv2"/4/1 -> 109 sql query rows affected: 0 statement ok @@ -165,7 +165,7 @@ query TT $trace_query ---- sql query rows affected: 0 -commit sql txn Put /Table/3/1/109/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:false default_expr:"unique_rowid()" hidden:true inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:4 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 not_visible:false > next_index_id:2 privileges: users: owner_proto:"root" version:2 > next_mutation_id:1 format_version:3 state:DROP offline_reason:"" view_query:"" is_materialized_view:false refresh_view_required:false declarative_schema_changer_state:<...> > metadata:<...> target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > > > metadata: target_status:ABSENT > targets: > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:DROPPED current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:PUBLIC current_statuses:PUBLIC target_ranks:0 target_ranks:1 target_ranks:2 target_ranks:3 target_ranks:4 target_ranks:5 target_ranks:6 target_ranks:7 target_ranks:8 target_ranks:9 target_ranks:10 target_ranks:11 target_ranks:12 target_ranks:13 target_ranks:14 target_ranks:15 target_ranks:16 target_ranks:17 target_ranks:18 target_ranks:19 target_ranks:20 target_ranks:21 target_ranks:22 target_ranks:23 target_ranks:24 target_ranks:25 target_ranks:26 target_ranks:27 target_ranks:28 target_ranks:29 relevant_statements: > authorization: > drop_time:... replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"TABLE t.public.kv" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:2 import_start_wall_time:0 > +commit sql txn CPut /Table/3/1/109/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:false default_expr:"unique_rowid()" hidden:true inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:4 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 not_visible:false > next_index_id:2 privileges: users: owner_proto:"root" version:2 > next_mutation_id:1 format_version:3 state:DROP offline_reason:"" view_query:"" is_materialized_view:false refresh_view_required:false declarative_schema_changer_state:<...> > metadata:<...> target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > > > metadata: target_status:ABSENT > targets: > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:DROPPED current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:PUBLIC current_statuses:PUBLIC target_ranks:0 target_ranks:1 target_ranks:2 target_ranks:3 target_ranks:4 target_ranks:5 target_ranks:6 target_ranks:7 target_ranks:8 target_ranks:9 target_ranks:10 target_ranks:11 target_ranks:12 target_ranks:13 target_ranks:14 target_ranks:15 target_ranks:16 target_ranks:17 target_ranks:18 target_ranks:19 target_ranks:20 target_ranks:21 target_ranks:22 target_ranks:23 target_ranks:24 target_ranks:25 target_ranks:26 target_ranks:27 target_ranks:28 target_ranks:29 relevant_statements: > authorization: > drop_time:... replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"TABLE t.public.kv" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:2 import_start_wall_time:0 > commit sql txn Del /NamespaceTable/30/1/106/107/"kv2"/4/1 statement ok @@ -193,7 +193,7 @@ SET tracing = off query TT $trace_query ---- -drop index Put /Table/3/1/108/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 not_visible:false > next_index_id:4 privileges: users: owner_proto:"root" version:2 > mutations: interleave:<> partitioning: type:FORWARD created_explicitly:true encoding_type:0 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:2 not_visible:false > state:WRITE_ONLY direction:DROP mutation_id:2 rollback:false > next_mutation_id:3 format_version:3 state:PUBLIC offline_reason:"" view_query:"" is_materialized_view:false refresh_view_required:false mutationJobs:<...> drop_time:0 replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:4 import_start_wall_time:0 > +drop index CPut /Table/3/1/108/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 not_visible:false > next_index_id:4 privileges: users: owner_proto:"root" version:2 > mutations: interleave:<> partitioning: type:FORWARD created_explicitly:true encoding_type:0 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:2 not_visible:false > state:WRITE_ONLY direction:DROP mutation_id:2 rollback:false > next_mutation_id:3 format_version:3 state:PUBLIC offline_reason:"" view_query:"" is_materialized_view:false refresh_view_required:false mutationJobs:<...> drop_time:0 replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:4 import_start_wall_time:0 > sql query rows affected: 0 statement ok @@ -206,7 +206,7 @@ query TT $trace_query ---- sql query rows affected: 0 -commit sql txn Put /Table/3/1/108/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 not_visible:false > next_index_id:4 privileges: users: owner_proto:"root" version:2 > next_mutation_id:3 format_version:3 state:DROP offline_reason:"" view_query:"" is_materialized_view:false refresh_view_required:false declarative_schema_changer_state:<...> > metadata:<...> target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:DROPPED current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:PUBLIC current_statuses:PUBLIC target_ranks:0 target_ranks:1 target_ranks:2 target_ranks:3 target_ranks:4 target_ranks:5 target_ranks:6 target_ranks:7 target_ranks:8 target_ranks:9 target_ranks:10 target_ranks:11 target_ranks:12 target_ranks:13 target_ranks:14 target_ranks:15 target_ranks:16 target_ranks:17 target_ranks:18 target_ranks:19 target_ranks:20 target_ranks:21 target_ranks:22 target_ranks:23 target_ranks:24 relevant_statements: > authorization: > drop_time:... replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:4 import_start_wall_time:0 > +commit sql txn CPut /Table/3/1/108/2/1 -> table: parent_id:106 unexposed_parent_schema_id:107 columns: nullable:false hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > columns: nullable:true hidden:false inaccessible:false generated_as_identity_type:NOT_IDENTITY_COLUMN virtual:false pg_attribute_num:0 alter_column_type_in_progress:false system_column_kind:NONE > next_column_id:3 families: next_family_id:1 primary_index: interleave:<> partitioning: type:FORWARD created_explicitly:false encoding_type:1 sharded: disabled:false geo_config:<> predicate:"" use_delete_preserving_encoding:false created_at_nanos:... constraint_id:1 not_visible:false > next_index_id:4 privileges: users: owner_proto:"root" version:2 > next_mutation_id:3 format_version:3 state:DROP offline_reason:"" view_query:"" is_materialized_view:false refresh_view_required:false declarative_schema_changer_state:<...> > metadata:<...> target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > is_nullable:true > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > targets: > metadata: target_status:ABSENT > current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:DROPPED current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:ABSENT current_statuses:PUBLIC current_statuses:PUBLIC target_ranks:0 target_ranks:1 target_ranks:2 target_ranks:3 target_ranks:4 target_ranks:5 target_ranks:6 target_ranks:7 target_ranks:8 target_ranks:9 target_ranks:10 target_ranks:11 target_ranks:12 target_ranks:13 target_ranks:14 target_ranks:15 target_ranks:16 target_ranks:17 target_ranks:18 target_ranks:19 target_ranks:20 target_ranks:21 target_ranks:22 target_ranks:23 target_ranks:24 relevant_statements: > authorization: > drop_time:... replacement_of: > audit_mode:DISABLED drop_job_id:0 create_query:"" create_as_of_time:<...> temporary:false partition_all_by:false exclude_data_from_backup:false next_constraint_id:4 import_start_wall_time:0 > commit sql txn Del /NamespaceTable/30/1/106/107/"kv"/4/1 # Check that session tracing does not inhibit the fast path for inserts & diff --git a/pkg/sql/plan.go b/pkg/sql/plan.go index 5b3c5e97d1fb..c8ca5172f89e 100644 --- a/pkg/sql/plan.go +++ b/pkg/sql/plan.go @@ -202,7 +202,6 @@ var _ planNode = &renameColumnNode{} var _ planNode = &renameDatabaseNode{} var _ planNode = &renameIndexNode{} var _ planNode = &renameTableNode{} -var _ planNode = &reparentDatabaseNode{} var _ planNode = &renderNode{} var _ planNode = &RevokeRoleNode{} var _ planNode = &rowCountNode{} @@ -251,7 +250,6 @@ var _ planNodeReadingOwnWrites = &changeDescriptorBackedPrivilegesNode{} var _ planNodeReadingOwnWrites = &dropSchemaNode{} var _ planNodeReadingOwnWrites = &dropTypeNode{} var _ planNodeReadingOwnWrites = &refreshMaterializedViewNode{} -var _ planNodeReadingOwnWrites = &reparentDatabaseNode{} var _ planNodeReadingOwnWrites = &setZoneConfigNode{} // planNodeRequireSpool serves as marker for nodes whose parent must diff --git a/pkg/sql/planhook.go b/pkg/sql/planhook.go index 9ca9967574af..e039e5e9bcbb 100644 --- a/pkg/sql/planhook.go +++ b/pkg/sql/planhook.go @@ -19,7 +19,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/spanconfig" "github.com/cockroachdb/cockroach/pkg/sql/catalog" "github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/lease" "github.com/cockroachdb/cockroach/pkg/sql/catalog/resolver" "github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc" @@ -121,8 +120,6 @@ type PlanHookState interface { ShowCreate( ctx context.Context, dbPrefix string, allHydratedDescs []catalog.Descriptor, desc catalog.TableDescriptor, displayOptions ShowCreateDisplayOptions, ) (string, error) - CreateSchemaNamespaceEntry(ctx context.Context, schemaNameKey roachpb.Key, - schemaID descpb.ID) error MigrationJobDeps() upgrade.JobDeps SpanConfigReconciler() spanconfig.Reconciler BufferClientNotice(ctx context.Context, notice pgnotice.Notice) diff --git a/pkg/sql/privileged_accessor_test.go b/pkg/sql/privileged_accessor_test.go index 60549dc5d07d..9824ba93dddb 100644 --- a/pkg/sql/privileged_accessor_test.go +++ b/pkg/sql/privileged_accessor_test.go @@ -17,6 +17,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/kv" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/tests" "github.com/cockroachdb/cockroach/pkg/testutils/serverutils" "github.com/cockroachdb/cockroach/pkg/util/leaktest" @@ -38,7 +39,7 @@ func TestLookupNamespaceID(t *testing.T) { err := kvDB.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error { return txn.Put( ctx, - catalogkeys.MakeObjectNameKey(keys.SystemSQLCodec, 999, 1000, "bob"), + catalogkeys.EncodeNameKey(keys.SystemSQLCodec, &descpb.NameInfo{ParentID: 999, ParentSchemaID: 1000, Name: "bob"}), 9999, ) }) diff --git a/pkg/sql/rename_table.go b/pkg/sql/rename_table.go index c286eaa6a94e..b0abd2fa30f7 100644 --- a/pkg/sql/rename_table.go +++ b/pkg/sql/rename_table.go @@ -215,7 +215,9 @@ func (n *renameTableNode) startExec(params runParams) error { // Populate namespace update batch. b := p.txn.NewBatch() - p.renameNamespaceEntry(ctx, b, oldNameKey, tableDesc) + if err := p.renameNamespaceEntry(ctx, b, oldNameKey, tableDesc); err != nil { + return err + } // Write the updated table descriptor. if err := p.writeSchemaChange( diff --git a/pkg/sql/repair.go b/pkg/sql/repair.go index d18d68e3d4a1..3582227ce5bd 100644 --- a/pkg/sql/repair.go +++ b/pkg/sql/repair.go @@ -400,8 +400,13 @@ func (p *planner) UnsafeUpsertNamespaceEntry( return err } parentID, parentSchemaID, descID := descpb.ID(parentIDInt), descpb.ID(parentSchemaIDInt), descpb.ID(descIDInt) - key := catalogkeys.MakeObjectNameKey(p.execCfg.Codec, parentID, parentSchemaID, name) - val, err := p.txn.Get(ctx, key) + nameInfo := descpb.NameInfo{ + ParentID: parentID, + ParentSchemaID: parentSchemaID, + Name: name, + } + nameKey := catalogkeys.EncodeNameKey(p.execCfg.Codec, &nameInfo) + val, err := p.txn.Get(ctx, nameKey) if err != nil { return errors.Wrapf(err, "failed to read namespace entry (%d, %d, %s)", parentID, parentSchemaID, name) @@ -489,9 +494,20 @@ func (p *planner) UnsafeUpsertNamespaceEntry( return err } } - if err := p.txn.Put(ctx, key, descID); err != nil { - return err + + { + b := p.txn.NewBatch() + entry := repairNameEntry{NameInfo: nameInfo, id: descID} + if err := p.Descriptors().UpsertNamespaceEntryToBatch( + ctx, p.ExtendedEvalContext().Tracing.KVTracingEnabled(), &entry, b, + ); err != nil { + return errors.Wrap(err, "failed to upsert entry") + } + if err := p.txn.Run(ctx, b); err != nil { + return errors.Wrap(err, "failed to upsert entry") + } } + var validationErrStr string if validationErr != nil { validationErrStr = validationErr.Error() @@ -508,6 +524,18 @@ func (p *planner) UnsafeUpsertNamespaceEntry( }) } +type repairNameEntry struct { + descpb.NameInfo + id descpb.ID +} + +var _ catalog.NameEntry = &repairNameEntry{} + +// GetID is part of the catalog.NameEntry interface. +func (r repairNameEntry) GetID() descpb.ID { + return r.id +} + // UnsafeDeleteNamespaceEntry powers the repair builtin of the same name. The // idea is that it should be used only by an administrator in the most dire of // circumstances. It exists to empower administrators to perform repair. @@ -527,8 +555,12 @@ func (p *planner) UnsafeDeleteNamespaceEntry( return err } parentID, parentSchemaID, descID := descpb.ID(parentIDInt), descpb.ID(parentSchemaIDInt), descpb.ID(descIDInt) - key := catalogkeys.MakeObjectNameKey(p.execCfg.Codec, parentID, parentSchemaID, name) - val, err := p.txn.Get(ctx, key) + nameInfo := descpb.NameInfo{ + ParentID: parentID, + ParentSchemaID: parentSchemaID, + Name: name, + } + val, err := p.txn.Get(ctx, catalogkeys.EncodeNameKey(p.execCfg.Codec, &nameInfo)) if err != nil { return errors.Wrapf(err, "failed to read namespace entry (%d, %d, %s)", parentID, parentSchemaID, name) @@ -555,7 +587,11 @@ func (p *planner) UnsafeDeleteNamespaceEntry( return pgerror.Newf(pgcode.ObjectNotInPrerequisiteState, "refusing to delete namespace entry for non-dropped descriptor") } - if _, err := p.txn.Del(ctx, key); err != nil { + b := p.txn.NewBatch() + if err := p.dropNamespaceEntry(ctx, b, &nameInfo); err != nil { + return errors.Wrap(err, "failed to delete entry") + } + if err := p.txn.Run(ctx, b); err != nil { return errors.Wrap(err, "failed to delete entry") } diff --git a/pkg/sql/reparent_database.go b/pkg/sql/reparent_database.go index b4b21f167608..c9d19e5ef1e2 100644 --- a/pkg/sql/reparent_database.go +++ b/pkg/sql/reparent_database.go @@ -14,30 +14,11 @@ import ( "context" "github.com/cockroachdb/cockroach/pkg/clusterversion" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/dbdesc" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/resolver" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/schemadesc" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/typedesc" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" - "github.com/cockroachdb/cockroach/pkg/sql/privilege" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" - "github.com/cockroachdb/cockroach/pkg/sql/sqlerrors" - "github.com/cockroachdb/cockroach/pkg/util/log/eventpb" - "github.com/cockroachdb/cockroach/pkg/util/protoutil" - "github.com/cockroachdb/errors" ) -type reparentDatabaseNode struct { - n *tree.ReparentDatabase - db *dbdesc.Mutable - newParent *dbdesc.Mutable -} - func (p *planner) ReparentDatabase( ctx context.Context, n *tree.ReparentDatabase, ) (planNode, error) { @@ -45,208 +26,3 @@ func (p *planner) ReparentDatabase( "cannot perform ALTER DATABASE CONVERT TO SCHEMA in version %v and beyond", clusterversion.TODOPreV22_1) } - -func (n *reparentDatabaseNode) startExec(params runParams) error { - ctx, p, codec := params.ctx, params.p, params.ExecCfg().Codec - - // Make a new schema corresponding to the target db. - id, err := p.EvalContext().DescIDGenerator.GenerateUniqueDescID(ctx) - if err != nil { - return err - } - - // Not all Privileges on databases are valid on schemas. - // Remove any privileges that are not valid for schemas. - schemaPrivs := privilege.GetValidPrivilegesForObject(privilege.Schema).ToBitField() - privs := n.db.GetPrivileges() - for i, u := range privs.Users { - // Remove privileges that are valid for databases but not for schemas. - privs.Users[i].Privileges = u.Privileges & schemaPrivs - } - - schema := schemadesc.NewBuilder(&descpb.SchemaDescriptor{ - ParentID: n.newParent.ID, - Name: n.db.Name, - ID: id, - Privileges: protoutil.Clone(n.db.Privileges).(*catpb.PrivilegeDescriptor), - Version: 1, - }).BuildCreatedMutable() - // Add the new schema to the parent database's name map. - n.newParent.AddSchemaToDatabase(n.db.Name, descpb.DatabaseDescriptor_SchemaInfo{ID: schema.GetID()}) - - if err := p.createDescriptorWithID( - ctx, - catalogkeys.MakeSchemaNameKey(p.ExecCfg().Codec, n.newParent.ID, schema.GetName()), - id, - schema, - tree.AsStringWithFQNames(n.n, params.Ann()), - ); err != nil { - return err - } - - b := p.txn.NewBatch() - - // Get all objects under the target database. - objNames, _, err := resolver.GetObjectNamesAndIDs(ctx, p.txn, p, codec, n.db, tree.PublicSchema, true /* explicitPrefix */) - if err != nil { - return err - } - - // For each object, adjust the ParentID and ParentSchemaID fields to point - // to the new parent DB and schema. - for _, objName := range objNames { - // First try looking up objName as a table. - found, _, desc, err := p.LookupObject( - ctx, - tree.ObjectLookupFlags{ - // Note we set required to be false here in order to not error out - // if we don't find the object. - CommonLookupFlags: tree.CommonLookupFlags{ - Required: false, - RequireMutable: true, - IncludeOffline: true, - }, - DesiredObjectKind: tree.TableObject, - }, - objName.Catalog(), - objName.Schema(), - objName.Object(), - ) - if err != nil { - return err - } - if found { - oldNameKey := descpb.NameInfo{ - ParentID: desc.GetParentID(), - ParentSchemaID: desc.GetParentSchemaID(), - Name: desc.GetName(), - } - // Remap the ID's on the table. - tbl, ok := desc.(*tabledesc.Mutable) - if !ok { - return errors.AssertionFailedf("%q was not a Mutable", objName.Object()) - } - - // If this table has any dependents, then we can't proceed (similar to the - // restrictions around renaming tables). See #10083. - if len(tbl.GetDependedOnBy()) > 0 { - var names []string - const errStr = "cannot convert database %q into schema because %q has dependent objects" - tblName, err := p.getQualifiedTableName(ctx, tbl) - if err != nil { - return errors.Wrapf(err, errStr, n.db.Name, tbl.Name) - } - for _, ref := range tbl.GetDependedOnBy() { - dep, err := p.Descriptors().GetMutableTableVersionByID(ctx, ref.ID, p.txn) - if err != nil { - return errors.Wrapf(err, errStr, n.db.Name, tblName.FQString()) - } - fqName, err := p.getQualifiedTableName(ctx, dep) - if err != nil { - return errors.Wrapf(err, errStr, n.db.Name, dep.Name) - } - names = append(names, fqName.FQString()) - } - return sqlerrors.NewDependentObjectErrorf( - "could not convert database %q into schema because %q has dependent objects %v", - n.db.Name, - tblName.FQString(), - names, - ) - } - - tbl.ParentID = n.newParent.ID - tbl.UnexposedParentSchemaID = schema.GetID() - p.renameNamespaceEntry(ctx, b, oldNameKey, tbl) - if err := p.writeSchemaChange(ctx, tbl, descpb.InvalidMutationID, tree.AsStringWithFQNames(n.n, params.Ann())); err != nil { - return err - } - } else { - // If we couldn't resolve objName as a table, try a type. - found, _, desc, err := p.LookupObject( - ctx, - tree.ObjectLookupFlags{ - CommonLookupFlags: tree.CommonLookupFlags{ - Required: true, - RequireMutable: true, - IncludeOffline: true, - }, - DesiredObjectKind: tree.TypeObject, - }, - objName.Catalog(), - objName.Schema(), - objName.Object(), - ) - if err != nil { - return err - } - // If we couldn't find the object at all, then continue. - if !found { - continue - } - oldNameKey := descpb.NameInfo{ - ParentID: desc.GetParentID(), - ParentSchemaID: desc.GetParentSchemaID(), - Name: desc.GetName(), - } - // Remap the ID's on the type. - typ, ok := desc.(*typedesc.Mutable) - if !ok { - return errors.AssertionFailedf("%q was not a Mutable", objName.Object()) - } - typ.ParentID = n.newParent.ID - typ.ParentSchemaID = schema.GetID() - p.renameNamespaceEntry(ctx, b, oldNameKey, typ) - if err := p.writeTypeSchemaChange(ctx, typ, tree.AsStringWithFQNames(n.n, params.Ann())); err != nil { - return err - } - } - } - - // Delete the public schema namespace entry for this database. Per our check - // during initialization, this is the only schema present under n.db. - b.Del(catalogkeys.MakeSchemaNameKey(codec, n.db.ID, tree.PublicSchema)) - - // This command can only be run when database leasing is supported, so we don't - // have to handle the case where it isn't. - p.dropNamespaceEntry(ctx, b, n.db) - - n.db.SetDropped() - if err := p.writeDatabaseChangeToBatch(ctx, n.db, b); err != nil { - return err - } - - // Update the new parent database with the new schema map. - if err := p.writeDatabaseChangeToBatch(ctx, n.newParent, b); err != nil { - return err - } - - if err := p.txn.Run(ctx, b); err != nil { - return err - } - - if err := p.createDropDatabaseJob( - ctx, - n.db.ID, - nil, /* schemasToDrop */ - nil, /* tableDropDetails */ - nil, /* typesToDrop */ - tree.AsStringWithFQNames(n.n, params.Ann()), - ); err != nil { - return err - } - - // Log Rename Database event. This is an auditable log event and is recorded - // in the same transaction as the table descriptor update. - return p.logEvent(ctx, - n.db.ID, - &eventpb.ConvertToSchema{ - DatabaseName: n.db.Name, - NewDatabaseParent: n.newParent.Name, - }) -} - -func (n *reparentDatabaseNode) Next(params runParams) (bool, error) { return false, nil } -func (n *reparentDatabaseNode) Values() tree.Datums { return tree.Datums{} } -func (n *reparentDatabaseNode) Close(ctx context.Context) {} -func (n *reparentDatabaseNode) ReadingOwnWrites() {} diff --git a/pkg/sql/schema.go b/pkg/sql/schema.go index d243ccb54307..1bd80e16a2eb 100644 --- a/pkg/sql/schema.go +++ b/pkg/sql/schema.go @@ -36,7 +36,7 @@ func schemaExists( } } // Now lookup in the namespace for other schemas. - schemaID, err := col.Direct().LookupSchemaID(ctx, txn, parentID, schema) + schemaID, err := col.LookupSchemaID(ctx, txn, parentID, schema) if err != nil || schemaID == descpb.InvalidID { return false, descpb.InvalidID, err } diff --git a/pkg/sql/schema_changer.go b/pkg/sql/schema_changer.go index 5a05bceb057a..7380a2d23b5a 100644 --- a/pkg/sql/schema_changer.go +++ b/pkg/sql/schema_changer.go @@ -732,9 +732,7 @@ func (sc *SchemaChanger) exec(ctx context.Context) error { } else { // We've dropped a non-physical table, no need for a GC job, let's delete // its descriptor and zone config immediately. - if err := DeleteTableDescAndZoneConfig( - ctx, sc.db, sc.settings, sc.execCfg.Codec, tableDesc, - ); err != nil { + if err := DeleteTableDescAndZoneConfig(ctx, sc.execCfg, tableDesc); err != nil { return err } } @@ -1055,10 +1053,13 @@ func (sc *SchemaChanger) rollbackSchemaChange(ctx context.Context, err error) er } scTable.SetDropped() scTable.DropTime = timeutil.Now().UnixNano() - if err := descsCol.WriteDescToBatch(ctx, false /* kvTrace */, scTable, b); err != nil { + const kvTrace = false + if err := descsCol.WriteDescToBatch(ctx, kvTrace, scTable, b); err != nil { + return err + } + if err := descsCol.DeleteNamespaceEntryToBatch(ctx, kvTrace, scTable, b); err != nil { return err } - b.Del(catalogkeys.EncodeNameKey(sc.execCfg.Codec, scTable)) // Queue a GC job. jobRecord := CreateGCJobRecord( @@ -3020,21 +3021,18 @@ func (sc *SchemaChanger) applyZoneConfigChangeForMutation( // DeleteTableDescAndZoneConfig removes a table's descriptor and zone config from the KV database. func DeleteTableDescAndZoneConfig( - ctx context.Context, - db *kv.DB, - settings *cluster.Settings, - codec keys.SQLCodec, - tableDesc catalog.TableDescriptor, + ctx context.Context, execCfg *ExecutorConfig, tableDesc catalog.TableDescriptor, ) error { log.Infof(ctx, "removing table descriptor and zone config for table %d", tableDesc.GetID()) - return db.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error { - b := &kv.Batch{} - + const kvTrace = false + return DescsTxn(ctx, execCfg, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) error { + b := txn.NewBatch() // Delete the descriptor. - descKey := catalogkeys.MakeDescMetadataKey(codec, tableDesc.GetID()) - b.Del(descKey) - // Delete the zone config entry for this table, if necessary. - if codec.ForSystemTenant() { + if err := col.DeleteDescToBatch(ctx, kvTrace, tableDesc.GetID(), b); err != nil { + return err + } + if codec := execCfg.Codec; codec.ForSystemTenant() { + // Delete the zone config entry for this table, if necessary. zoneKeyPrefix := config.MakeZoneKeyPrefix(codec, tableDesc.GetID()) b.DelRange(zoneKeyPrefix, zoneKeyPrefix.PrefixEnd(), false /* returnKeys */) } diff --git a/pkg/sql/schemachanger/scdeps/BUILD.bazel b/pkg/sql/schemachanger/scdeps/BUILD.bazel index 0522a7e42f6a..800d8d4f6230 100644 --- a/pkg/sql/schemachanger/scdeps/BUILD.bazel +++ b/pkg/sql/schemachanger/scdeps/BUILD.bazel @@ -24,7 +24,6 @@ go_library( "//pkg/settings", "//pkg/settings/cluster", "//pkg/sql/catalog", - "//pkg/sql/catalog/catalogkeys", "//pkg/sql/catalog/catpb", "//pkg/sql/catalog/descpb", "//pkg/sql/catalog/descs", diff --git a/pkg/sql/schemachanger/scdeps/exec_deps.go b/pkg/sql/schemachanger/scdeps/exec_deps.go index a4b25abe7daa..4209b8b2ee6c 100644 --- a/pkg/sql/schemachanger/scdeps/exec_deps.go +++ b/pkg/sql/schemachanger/scdeps/exec_deps.go @@ -26,7 +26,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/server/telemetry" "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/sql/catalog" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descs" "github.com/cockroachdb/cockroach/pkg/sql/oppurpose" @@ -111,7 +110,6 @@ type txnDeps struct { statsRefresher scexec.StatsRefresher tableStatsToRefresh []descpb.ID eventLogger scexec.EventLogger - deletedDescriptors catalog.DescriptorIDSet schemaChangerJobID jobspb.JobID schemaChangerJob *jobs.Job kvTrace bool @@ -236,24 +234,12 @@ func (b *catalogChangeBatcher) CreateOrUpdateDescriptor( func (b *catalogChangeBatcher) DeleteName( ctx context.Context, nameInfo descpb.NameInfo, id descpb.ID, ) error { - marshalledKey := catalogkeys.EncodeNameKey(b.codec, nameInfo) - if b.kvTrace { - log.VEventf(ctx, 2, "Del %s", marshalledKey) - } - b.batch.Del(marshalledKey) - return nil + return b.descsCollection.DeleteNamespaceEntryToBatch(ctx, b.kvTrace, &nameInfo, b.batch) } // DeleteDescriptor implements the scexec.CatalogChangeBatcher interface. func (b *catalogChangeBatcher) DeleteDescriptor(ctx context.Context, id descpb.ID) error { - marshalledKey := catalogkeys.MakeDescMetadataKey(b.codec, id) - b.batch.Del(marshalledKey) - if b.kvTrace { - log.VEventf(ctx, 2, "Del %s", marshalledKey) - } - b.deletedDescriptors.Add(id) - b.descsCollection.NotifyOfDeletedDescriptor(id) - return nil + return b.descsCollection.DeleteDescToBatch(ctx, b.kvTrace, id, b.batch) } // DeleteZoneConfig implements the scexec.CatalogChangeBatcher interface. diff --git a/pkg/sql/sem/tree/name_resolution.go b/pkg/sql/sem/tree/name_resolution.go index 161b9e04d9b7..c53a69e6e756 100644 --- a/pkg/sql/sem/tree/name_resolution.go +++ b/pkg/sql/sem/tree/name_resolution.go @@ -174,6 +174,8 @@ type CommonLookupFlags struct { IncludeDropped bool // AvoidSynthetic specifies if the synthetic descriptors will be ignored. AvoidSynthetic bool + // AvoidStorage specifies if the descriptors in storage will be ignored. + AvoidStorage bool // ParentID enforces that the resolved descriptor exist with this parent // ID if non-zero. ParentID catid.DescID diff --git a/pkg/sql/temporary_schema.go b/pkg/sql/temporary_schema.go index 20467d85d6cc..71630652d860 100644 --- a/pkg/sql/temporary_schema.go +++ b/pkg/sql/temporary_schema.go @@ -19,14 +19,12 @@ import ( "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/kv" - "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/server/serverpb" "github.com/cockroachdb/cockroach/pkg/server/telemetry" "github.com/cockroachdb/cockroach/pkg/settings" "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/sql/catalog" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descs" "github.com/cockroachdb/cockroach/pkg/sql/catalog/resolver" @@ -105,38 +103,28 @@ func (p *planner) getOrCreateTemporarySchema( if sc != nil || err != nil { return sc, err } - sKey := catalogkeys.NewNameKeyComponents(db.GetID(), keys.RootNamespaceID, tempSchemaName) // The temporary schema has not been created yet. id, err := p.EvalContext().DescIDGenerator.GenerateUniqueDescID(ctx) if err != nil { return nil, err } - if err := p.CreateSchemaNamespaceEntry(ctx, catalogkeys.EncodeNameKey(p.ExecCfg().Codec, sKey), id); err != nil { + b := &kv.Batch{} + if err := p.Descriptors().InsertTempSchemaToBatch( + ctx, p.ExtendedEvalContext().Tracing.KVTracingEnabled(), db, tempSchemaName, id, b, + ); err != nil { + return nil, err + } + if err := p.txn.Run(ctx, b); err != nil { return nil, err } p.sessionDataMutatorIterator.applyOnEachMutator(func(m sessionDataMutator) { - m.SetTemporarySchemaName(sKey.GetName()) + m.SetTemporarySchemaName(tempSchemaName) m.SetTemporarySchemaIDForDatabase(uint32(db.GetID()), uint32(id)) }) return p.Descriptors().GetImmutableSchemaByID(ctx, p.Txn(), id, p.CommonLookupFlagsRequired()) } -// CreateSchemaNamespaceEntry creates an entry for the schema in the -// system.namespace table. -func (p *planner) CreateSchemaNamespaceEntry( - ctx context.Context, schemaNameKey roachpb.Key, schemaID descpb.ID, -) error { - if p.ExtendedEvalContext().Tracing.KVTracingEnabled() { - log.VEventf(ctx, 2, "CPut %s -> %d", schemaNameKey, schemaID) - } - - b := &kv.Batch{} - b.CPut(schemaNameKey, schemaID, nil) - - return p.txn.Run(ctx, b) -} - // temporarySchemaName returns the session specific temporary schema name given // the sessionID. When the session creates a temporary object for the first // time, it must create a schema with the name returned by this function. @@ -202,8 +190,14 @@ func cleanupSessionTempObjects( // itself may still exist (eg. a temporary table was created and then // dropped). So we remove the namespace table entry of the temporary // schema. - key := catalogkeys.MakeSchemaNameKey(codec, dbDesc.GetID(), tempSchemaName) - if _, err := txn.Del(ctx, key); err != nil { + b := txn.NewBatch() + const kvTrace = false + if err := descsCol.DeleteTempSchemaToBatch( + ctx, kvTrace, dbDesc, tempSchemaName, b, + ); err != nil { + return err + } + if err := txn.Run(ctx, b); err != nil { return err } } diff --git a/pkg/sql/type_change.go b/pkg/sql/type_change.go index ee5a576941e2..46f86e022f71 100644 --- a/pkg/sql/type_change.go +++ b/pkg/sql/type_change.go @@ -25,7 +25,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/sql/catalog" - "github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkeys" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descs" @@ -243,7 +242,7 @@ func (t *typeSchemaChanger) exec(ctx context.Context) error { } ctx = logtags.AddTags(ctx, t.logTags()) leaseMgr := t.execCfg.LeaseManager - codec := t.execCfg.Codec + const kvTrace = true typeDesc, err := t.getTypeDescFromStore(ctx) if err != nil { @@ -435,7 +434,7 @@ func (t *typeSchemaChanger) exec(ctx context.Context) error { b := txn.NewBatch() if err := descsCol.WriteDescToBatch( - ctx, true /* kvTrace */, typeDesc, b, + ctx, kvTrace, typeDesc, b, ); err != nil { return err } @@ -448,7 +447,7 @@ func (t *typeSchemaChanger) exec(ctx context.Context) error { return err } if err := descsCol.WriteDescToBatch( - ctx, true /* kvTrace */, arrayTypeDesc, b, + ctx, kvTrace, arrayTypeDesc, b, ); err != nil { return err } @@ -487,9 +486,11 @@ func (t *typeSchemaChanger) exec(ctx context.Context) error { // If the type is being dropped, remove the descriptor here only // if the declarative schema changer is not in use. if typeDesc.Dropped() && typeDesc.GetDeclarativeSchemaChangerState() == nil { - if err := t.execCfg.DB.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error { + if err := DescsTxn(ctx, t.execCfg, func(ctx context.Context, txn *kv.Txn, col *descs.Collection) error { b := txn.NewBatch() - b.Del(catalogkeys.MakeDescMetadataKey(codec, typeDesc.GetID())) + if err := col.DeleteDescToBatch(ctx, kvTrace, typeDesc.GetID(), b); err != nil { + return err + } return txn.Run(ctx, b) }); err != nil { return err diff --git a/pkg/sql/walk.go b/pkg/sql/walk.go index 2116e68776db..b8ffeb7a5440 100644 --- a/pkg/sql/walk.go +++ b/pkg/sql/walk.go @@ -438,7 +438,6 @@ var planNodeNames = map[reflect.Type]string{ reflect.TypeOf(&renameDatabaseNode{}): "rename database", reflect.TypeOf(&renameIndexNode{}): "rename index", reflect.TypeOf(&renameTableNode{}): "rename table", - reflect.TypeOf(&reparentDatabaseNode{}): "reparent database", reflect.TypeOf(&renderNode{}): "render", reflect.TypeOf(&resetAllNode{}): "reset all", reflect.TypeOf(&RevokeRoleNode{}): "revoke role", diff --git a/pkg/sql/zone_config.go b/pkg/sql/zone_config.go index 39aac538b847..3a82b57f6815 100644 --- a/pkg/sql/zone_config.go +++ b/pkg/sql/zone_config.go @@ -445,7 +445,7 @@ func resolveZone( errMissingKey := errors.New("missing key") id, err := zonepb.ResolveZoneSpecifier(ctx, zs, func(parentID uint32, schemaID uint32, name string) (uint32, error) { - id, err := col.Direct().LookupObjectID(ctx, txn, descpb.ID(parentID), descpb.ID(schemaID), name) + id, err := col.LookupObjectID(ctx, txn, descpb.ID(parentID), descpb.ID(schemaID), name) if err != nil { return 0, err }