Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b82a7be

Browse files
committed
Change pg_seclabel.provider and pg_shseclabel.provider to type "name".
These were "text", but that's a bad idea because it has collation-dependent ordering. No index in template0 should have collation-dependent ordering, especially not indexes on shared catalogs. There was general agreement that provider names don't need to be longer than other identifiers, so we can fix this at a small waste of table space by changing from text to name. There's no way to fix the problem in the back branches, but we can hope that security labels don't yet have widespread-enough usage to make it urgent to fix. There needs to be a regression sanity test to prevent us from making this same mistake again; but before putting that in, we'll need to get rid of similar brain fade in the recently-added pg_replication_origin catalog. Note: for lack of a suitable testing environment, I've not really exercised this change. I trust the buildfarm will show up any mistakes.
1 parent e4942f7 commit b82a7be

File tree

6 files changed

+22
-18
lines changed

6 files changed

+22
-18
lines changed

doc/src/sgml/catalogs.sgml

+3-3
Original file line numberDiff line numberDiff line change
@@ -5648,7 +5648,7 @@
56485648

56495649
<row>
56505650
<entry><structfield>provider</structfield></entry>
5651-
<entry><type>text</type></entry>
5651+
<entry><type>name</type></entry>
56525652
<entry></entry>
56535653
<entry>The label provider associated with this label.</entry>
56545654
</row>
@@ -5937,7 +5937,7 @@
59375937
</row>
59385938
<row>
59395939
<entry><structfield>provider</structfield></entry>
5940-
<entry><type>text</type></entry>
5940+
<entry><type>name</type></entry>
59415941
<entry></entry>
59425942
<entry>The label provider associated with this label.</entry>
59435943
</row>
@@ -9025,7 +9025,7 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx
90259025
</row>
90269026
<row>
90279027
<entry><structfield>provider</structfield></entry>
9028-
<entry><type>text</type></entry>
9028+
<entry><type>name</type></entry>
90299029
<entry><literal><link linkend="catalog-pg-seclabel"><structname>pg_seclabel</structname></link>.provider</literal></entry>
90309030
<entry>The label provider associated with this label.</entry>
90319031
</row>

src/backend/commands/seclabel.c

+14-10
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ GetSharedSecurityLabel(const ObjectAddress *object, const char *provider)
163163
ObjectIdGetDatum(object->classId));
164164
ScanKeyInit(&keys[2],
165165
Anum_pg_shseclabel_provider,
166-
BTEqualStrategyNumber, F_TEXTEQ,
167-
CStringGetTextDatum(provider));
166+
BTEqualStrategyNumber, F_NAMEEQ,
167+
CStringGetDatum(provider));
168168

169169
pg_shseclabel = heap_open(SharedSecLabelRelationId, AccessShareLock);
170170

@@ -220,8 +220,8 @@ GetSecurityLabel(const ObjectAddress *object, const char *provider)
220220
Int32GetDatum(object->objectSubId));
221221
ScanKeyInit(&keys[3],
222222
Anum_pg_seclabel_provider,
223-
BTEqualStrategyNumber, F_TEXTEQ,
224-
CStringGetTextDatum(provider));
223+
BTEqualStrategyNumber, F_NAMEEQ,
224+
CStringGetDatum(provider));
225225

226226
pg_seclabel = heap_open(SecLabelRelationId, AccessShareLock);
227227

@@ -256,6 +256,7 @@ SetSharedSecurityLabel(const ObjectAddress *object,
256256
SysScanDesc scan;
257257
HeapTuple oldtup;
258258
HeapTuple newtup = NULL;
259+
NameData providername;
259260
Datum values[Natts_pg_shseclabel];
260261
bool nulls[Natts_pg_shseclabel];
261262
bool replaces[Natts_pg_shseclabel];
@@ -265,7 +266,8 @@ SetSharedSecurityLabel(const ObjectAddress *object,
265266
memset(replaces, false, sizeof(replaces));
266267
values[Anum_pg_shseclabel_objoid - 1] = ObjectIdGetDatum(object->objectId);
267268
values[Anum_pg_shseclabel_classoid - 1] = ObjectIdGetDatum(object->classId);
268-
values[Anum_pg_shseclabel_provider - 1] = CStringGetTextDatum(provider);
269+
namestrcpy(&providername, provider);
270+
values[Anum_pg_shseclabel_provider - 1] = NameGetDatum(&providername);
269271
if (label != NULL)
270272
values[Anum_pg_shseclabel_label - 1] = CStringGetTextDatum(label);
271273

@@ -280,8 +282,8 @@ SetSharedSecurityLabel(const ObjectAddress *object,
280282
ObjectIdGetDatum(object->classId));
281283
ScanKeyInit(&keys[2],
282284
Anum_pg_shseclabel_provider,
283-
BTEqualStrategyNumber, F_TEXTEQ,
284-
CStringGetTextDatum(provider));
285+
BTEqualStrategyNumber, F_NAMEEQ,
286+
CStringGetDatum(provider));
285287

286288
pg_shseclabel = heap_open(SharedSecLabelRelationId, RowExclusiveLock);
287289

@@ -335,6 +337,7 @@ SetSecurityLabel(const ObjectAddress *object,
335337
SysScanDesc scan;
336338
HeapTuple oldtup;
337339
HeapTuple newtup = NULL;
340+
NameData providername;
338341
Datum values[Natts_pg_seclabel];
339342
bool nulls[Natts_pg_seclabel];
340343
bool replaces[Natts_pg_seclabel];
@@ -352,7 +355,8 @@ SetSecurityLabel(const ObjectAddress *object,
352355
values[Anum_pg_seclabel_objoid - 1] = ObjectIdGetDatum(object->objectId);
353356
values[Anum_pg_seclabel_classoid - 1] = ObjectIdGetDatum(object->classId);
354357
values[Anum_pg_seclabel_objsubid - 1] = Int32GetDatum(object->objectSubId);
355-
values[Anum_pg_seclabel_provider - 1] = CStringGetTextDatum(provider);
358+
namestrcpy(&providername, provider);
359+
values[Anum_pg_seclabel_provider - 1] = NameGetDatum(&providername);
356360
if (label != NULL)
357361
values[Anum_pg_seclabel_label - 1] = CStringGetTextDatum(label);
358362

@@ -371,8 +375,8 @@ SetSecurityLabel(const ObjectAddress *object,
371375
Int32GetDatum(object->objectSubId));
372376
ScanKeyInit(&keys[3],
373377
Anum_pg_seclabel_provider,
374-
BTEqualStrategyNumber, F_TEXTEQ,
375-
CStringGetTextDatum(provider));
378+
BTEqualStrategyNumber, F_NAMEEQ,
379+
CStringGetDatum(provider));
376380

377381
pg_seclabel = heap_open(SecLabelRelationId, RowExclusiveLock);
378382

src/include/catalog/catversion.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 201505153
56+
#define CATALOG_VERSION_NO 201505181
5757

5858
#endif

src/include/catalog/indexing.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,10 @@ DECLARE_UNIQUE_INDEX(pg_default_acl_oid_index, 828, on pg_default_acl using btre
290290
DECLARE_UNIQUE_INDEX(pg_db_role_setting_databaseid_rol_index, 2965, on pg_db_role_setting using btree(setdatabase oid_ops, setrole oid_ops));
291291
#define DbRoleSettingDatidRolidIndexId 2965
292292

293-
DECLARE_UNIQUE_INDEX(pg_seclabel_object_index, 3597, on pg_seclabel using btree(objoid oid_ops, classoid oid_ops, objsubid int4_ops, provider text_ops));
293+
DECLARE_UNIQUE_INDEX(pg_seclabel_object_index, 3597, on pg_seclabel using btree(objoid oid_ops, classoid oid_ops, objsubid int4_ops, provider name_ops));
294294
#define SecLabelObjectIndexId 3597
295295

296-
DECLARE_UNIQUE_INDEX(pg_shseclabel_object_index, 3593, on pg_shseclabel using btree(objoid oid_ops, classoid oid_ops, provider text_ops));
296+
DECLARE_UNIQUE_INDEX(pg_shseclabel_object_index, 3593, on pg_shseclabel using btree(objoid oid_ops, classoid oid_ops, provider name_ops));
297297
#define SharedSecLabelObjectIndexId 3593
298298

299299
DECLARE_UNIQUE_INDEX(pg_extension_oid_index, 3080, on pg_extension using btree(oid oid_ops));

src/include/catalog/pg_seclabel.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ CATALOG(pg_seclabel,3596) BKI_WITHOUT_OIDS
2525
Oid objoid; /* OID of the object itself */
2626
Oid classoid; /* OID of table containing the object */
2727
int32 objsubid; /* column number, or 0 if not used */
28+
NameData provider; /* name of label provider */
2829

2930
#ifdef CATALOG_VARLEN /* variable-length fields start here */
30-
text provider BKI_FORCE_NOT_NULL; /* name of label provider */
3131
text label BKI_FORCE_NOT_NULL; /* security label of the object */
3232
#endif
3333
} FormData_pg_seclabel;

src/include/catalog/pg_shseclabel.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ CATALOG(pg_shseclabel,3592) BKI_SHARED_RELATION BKI_WITHOUT_OIDS
2424
{
2525
Oid objoid; /* OID of the shared object itself */
2626
Oid classoid; /* OID of table containing the shared object */
27+
NameData provider; /* name of label provider */
2728

2829
#ifdef CATALOG_VARLEN /* variable-length fields start here */
29-
text provider BKI_FORCE_NOT_NULL; /* name of label provider */
3030
text label BKI_FORCE_NOT_NULL; /* security label of the object */
3131
#endif
3232
} FormData_pg_shseclabel;

0 commit comments

Comments
 (0)