@@ -21,6 +21,7 @@ import (
21
21
"github.com/cockroachdb/cockroach/pkg/sql/catalog/schemadesc"
22
22
"github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc"
23
23
"github.com/cockroachdb/cockroach/pkg/sql/catalog/typedesc"
24
+ "github.com/cockroachdb/cockroach/pkg/sql/sem/catconstants"
24
25
"github.com/cockroachdb/cockroach/pkg/util/hlc"
25
26
"github.com/cockroachdb/cockroach/pkg/util/protoutil"
26
27
"github.com/cockroachdb/errors"
@@ -64,7 +65,7 @@ func SetupOrAdvanceStandbyReaderCatalog(
64
65
// below.
65
66
descriptorsToWrite := make ([]catalog.MutableDescriptor , 0 , len (allExistingDescs .OrderedDescriptorIDs ()))
66
67
if err := extracted .ForEachDescriptor (func (fromDesc catalog.Descriptor ) error {
67
- if ! shouldSetupForReader (fromDesc .GetID (), fromDesc .GetParentID ()) {
68
+ if ! shouldSetupForReader (fromDesc .GetID (), fromDesc .GetName (), fromDesc . GetParentID ()) {
68
69
return nil
69
70
}
70
71
// Track this descriptor was updated.
@@ -138,7 +139,7 @@ func SetupOrAdvanceStandbyReaderCatalog(
138
139
}
139
140
}
140
141
if err := extracted .ForEachNamespaceEntry (func (e nstree.NamespaceEntry ) error {
141
- if ! shouldSetupForReader (e .GetID (), e .GetParentID ()) {
142
+ if ! shouldSetupForReader (e .GetID (), e .GetName (), e . GetParentID ()) {
142
143
return nil
143
144
}
144
145
// Do not upsert entries if one already exists.
@@ -153,7 +154,7 @@ func SetupOrAdvanceStandbyReaderCatalog(
153
154
// Figure out which descriptors should be deleted.
154
155
if err := allExistingDescs .ForEachDescriptor (func (desc catalog.Descriptor ) error {
155
156
// Skip descriptors that were updated above
156
- if ! shouldSetupForReader (desc .GetID (), desc .GetParentID ()) ||
157
+ if ! shouldSetupForReader (desc .GetID (), desc .GetName (), desc . GetParentID ()) ||
157
158
descriptorsUpdated .Contains (desc .GetID ()) {
158
159
return nil
159
160
}
@@ -167,7 +168,7 @@ func SetupOrAdvanceStandbyReaderCatalog(
167
168
if err := allExistingDescs .ForEachNamespaceEntry (func (e nstree.NamespaceEntry ) error {
168
169
// Skip descriptors that were updated above that were
169
170
// not renamed.
170
- if ! shouldSetupForReader (e .GetID (), e .GetParentID ()) ||
171
+ if ! shouldSetupForReader (e .GetID (), e .GetName (), e . GetParentID ()) ||
171
172
(descriptorsUpdated .Contains (e .GetID ()) &&
172
173
! descriptorsRenamed .Contains (e .GetID ())) {
173
174
return nil
@@ -292,15 +293,23 @@ func replicateDescriptorForReader(
292
293
}
293
294
294
295
// shouldSetupForReader determines if a descriptor should be setup
295
- // access via external row data.
296
- func shouldSetupForReader (id descpb.ID , parentID descpb.ID ) bool {
296
+ // access via external row data, based on the ID for tables with fixed IDs or on
297
+ // the name and parentID for tables with dynamic IDs.
298
+ func shouldSetupForReader (id descpb.ID , name string , parentID descpb.ID ) bool {
297
299
switch id {
298
300
case keys .UsersTableID , keys .RoleMembersTableID , keys .RoleOptionsTableID ,
299
301
keys .DatabaseRoleSettingsTableID , keys .TableStatisticsTableID :
300
302
return true
301
303
default :
302
- return parentID != keys .SystemDatabaseID &&
303
- id != keys .SystemDatabaseID
304
+ if parentID == keys .SystemDatabaseID {
305
+ switch name {
306
+ case string (catconstants .SystemPrivilegeTableName ):
307
+ return true
308
+ default :
309
+ return false
310
+ }
311
+ }
312
+ return id != keys .SystemDatabaseID
304
313
}
305
314
}
306
315
0 commit comments