Skip to content

Commit b49afa3

Browse files
zhangwenchao-123my-ship-it
authored andcommitted
Implementation of tag.
We implement tag in this commit. Tag can be attached to target database object, which maybe database, user, schema, table etc. Tag has allowed values, when we attach one tag to target object, we should specify this tag's value which must be in allowed values array, otherwise will error out. To use it, we will illustrate some example as following: CREATE TAG tag_example allowed_values '123', 'abc'; CREATE USER tag_user; ALTER USER tag_user TAG (tag_example = '123'); ALTER TAG tag_example ADD ALLOWED_VALUES 'def'; ALTER TAG tag_example DROP ALLOWED_VALUES 'abc'; Authored-by: Zhang Wenchao zwcpostgres@gmail.com
1 parent 3c1f29a commit b49afa3

65 files changed

Lines changed: 7166 additions & 70 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/backend/catalog/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ CATALOG_HEADERS := \
9595
pg_sequence.h pg_publication.h pg_publication_rel.h pg_subscription.h \
9696
pg_subscription_rel.h gp_partition_template.h pg_task.h pg_task_run_history.h \
9797
pg_profile.h pg_password_history.h pg_directory_table.h gp_storage_server.h \
98+
gp_storage_user_mapping.h pg_tag.h pg_tag_description.h \
9899
gp_matview_aux.h \
99-
gp_matview_tables.h \
100-
gp_storage_user_mapping.h
100+
gp_matview_tables.h
101101

102102
USE_INTERNAL_FTS_FOUND := $(if $(findstring USE_INTERNAL_FTS,$(CFLAGS)),true,false)
103103

src/backend/catalog/aclchk.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include "catalog/pg_statistic_ext.h"
5959
#include "catalog/pg_subscription.h"
6060
#include "catalog/pg_tablespace.h"
61+
#include "catalog/pg_tag.h"
6162
#include "catalog/pg_transform.h"
6263
#include "catalog/pg_ts_config.h"
6364
#include "catalog/pg_ts_dict.h"
@@ -3791,6 +3792,9 @@ aclcheck_error(AclResult aclerr, ObjectType objtype,
37913792
case OBJECT_EXTPROTOCOL:
37923793
msg = gettext_noop("permission denied for external protocol %s");
37933794
break;
3795+
case OBJECT_TAG:
3796+
msg = gettext_noop("permission denied for tag %s");
3797+
break;
37943798
/* these currently aren't used */
37953799
case OBJECT_ACCESS_METHOD:
37963800
case OBJECT_AMOP:
@@ -3902,6 +3906,9 @@ aclcheck_error(AclResult aclerr, ObjectType objtype,
39023906
case OBJECT_TABLE:
39033907
msg = gettext_noop("must be owner of table %s");
39043908
break;
3909+
case OBJECT_TAG:
3910+
msg = gettext_noop("must be owner of tag %s");
3911+
break;
39053912
case OBJECT_TYPE:
39063913
msg = gettext_noop("must be owner of type %s");
39073914
break;
@@ -5647,6 +5654,33 @@ pg_opfamily_ownercheck(Oid opf_oid, Oid roleid)
56475654
return has_privs_of_role(roleid, ownerId);
56485655
}
56495656

5657+
/*
5658+
* Ownership check for a tag (specified by OID).
5659+
*/
5660+
bool
5661+
pg_tag_ownercheck(Oid tag_oid, Oid roleid)
5662+
{
5663+
HeapTuple tuple;
5664+
Oid ownerId;
5665+
5666+
/* Superusers bypass all permission checking. */
5667+
if (superuser_arg(roleid))
5668+
return true;
5669+
5670+
tuple = SearchSysCache1(TAGOID, ObjectIdGetDatum(tag_oid));
5671+
if (!HeapTupleIsValid(tuple))
5672+
ereport(ERROR,
5673+
(errcode(ERRCODE_UNDEFINED_OBJECT),
5674+
errmsg("tag with OID %u does not exist",
5675+
tag_oid)));
5676+
5677+
ownerId = ((Form_pg_tag) GETSTRUCT(tuple))->tagowner;
5678+
5679+
ReleaseSysCache(tuple);
5680+
5681+
return has_privs_of_role(roleid, ownerId);
5682+
}
5683+
56505684
/*
56515685
* Ownership check for a text search dictionary (specified by OID).
56525686
*/

src/backend/catalog/catalog.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
#include "catalog/pg_shseclabel.h"
4545
#include "catalog/pg_subscription.h"
4646
#include "catalog/pg_tablespace.h"
47+
#include "catalog/pg_tag.h"
48+
#include "catalog/pg_tag_description.h"
4749
#include "catalog/pg_task.h"
4850
#include "catalog/pg_task_run_history.h"
4951
#include "catalog/pg_type.h"
@@ -447,7 +449,10 @@ IsSharedRelation(Oid relationId)
447449
relationId == StorageServerRelationId ||
448450

449451
relationId == ProfileRelationId ||
450-
relationId == PasswordHistoryRelationId)
452+
relationId == PasswordHistoryRelationId ||
453+
454+
relationId == TagRelationId ||
455+
relationId == TagDescriptionRelationId)
451456
return true;
452457

453458
/* These are their indexes */
@@ -501,7 +506,12 @@ IsSharedRelation(Oid relationId)
501506
relationId == ProfileOidIndexId ||
502507
relationId == ProfileVerifyFunctionIndexId ||
503508
relationId == PasswordHistoryRolePasswordIndexId ||
504-
relationId == PasswordHistoryRolePasswordsetatIndexId)
509+
relationId == PasswordHistoryRolePasswordsetatIndexId ||
510+
relationId == TagNameIndexId ||
511+
relationId == TagOidIndexId ||
512+
relationId == TagDescriptionIndexId ||
513+
relationId == TagDescriptionTagidvalueIndexId ||
514+
relationId == TagDescriptionOidIndexId)
505515
{
506516
return true;
507517
}

src/backend/catalog/dependency.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
#include "catalog/pg_statistic_ext.h"
5959
#include "catalog/pg_subscription.h"
6060
#include "catalog/pg_tablespace.h"
61+
#include "catalog/pg_tag.h"
62+
#include "catalog/pg_tag_description.h"
6163
#include "catalog/pg_task.h"
6264
#include "catalog/pg_transform.h"
6365
#include "catalog/pg_trigger.h"
@@ -78,6 +80,7 @@
7880
#include "commands/schemacmds.h"
7981
#include "commands/seclabel.h"
8082
#include "commands/sequence.h"
83+
#include "commands/tag.h"
8184
#include "commands/taskcmds.h"
8285
#include "commands/trigger.h"
8386
#include "commands/typecmds.h"
@@ -209,6 +212,8 @@ static const Oid object_classes[] = {
209212
DirectoryTableRelationId, /* OCLASS_DIRECTORY_TABLE */
210213
StorageServerRelationId, /* OCLASS_STORAGE_SERVER */
211214
StorageUserMappingRelationId, /* OCLASS_STORAGE_USER_MAPPING */
215+
TagRelationId, /* OCLASS_TAG */
216+
TagDescriptionRelationId, /* OCLASS_TAG_DESCRIPTION */
212217
ExtprotocolRelationId, /* OCLASS_EXTPROTOCOL */
213218
GpMatviewAuxId, /* OCLASS_MATVIEW_AUX */
214219
TaskRelationId, /* OCLASS_TASK */
@@ -1474,14 +1479,31 @@ doDeletion(const ObjectAddress *object, int flags)
14741479

14751480
Assert(object->objectSubId == 0);
14761481
index_drop(object->objectId, concurrent, concurrent_lock_mode);
1482+
1483+
/*
1484+
* Delete tag description.
1485+
*/
1486+
DeleteTagDescriptions(MyDatabaseId,
1487+
object->classId,
1488+
object->objectId);
14771489
}
14781490
else
14791491
{
14801492
if (object->objectSubId != 0)
14811493
RemoveAttributeById(object->objectId,
14821494
object->objectSubId);
14831495
else
1496+
{
14841497
heap_drop_with_catalog(object->objectId);
1498+
1499+
/*
1500+
* Delete tag description.
1501+
*/
1502+
DeleteTagDescriptions(MyDatabaseId,
1503+
object->classId,
1504+
object->objectId);
1505+
}
1506+
14851507
}
14861508

14871509
/*
@@ -1551,6 +1573,12 @@ doDeletion(const ObjectAddress *object, int flags)
15511573

15521574
case OCLASS_SCHEMA:
15531575
RemoveSchemaById(object->objectId);
1576+
/*
1577+
* Delete tag description.
1578+
*/
1579+
DeleteTagDescriptions(MyDatabaseId,
1580+
object->classId,
1581+
object->objectId);
15541582
break;
15551583
case OCLASS_TASK:
15561584
RemoveTaskById(object->objectId);
@@ -1593,6 +1621,8 @@ doDeletion(const ObjectAddress *object, int flags)
15931621
case OCLASS_PASSWORDHISTORY:
15941622
case OCLASS_STORAGE_SERVER:
15951623
case OCLASS_STORAGE_USER_MAPPING:
1624+
case OCLASS_TAG:
1625+
case OCLASS_TAG_DESCRIPTION:
15961626
elog(ERROR, "global objects cannot be deleted by doDeletion");
15971627
break;
15981628

@@ -2996,6 +3026,12 @@ getObjectClass(const ObjectAddress *object)
29963026
case StorageUserMappingRelationId:
29973027
return OCLASS_STORAGE_USER_MAPPING;
29983028

3029+
case TagRelationId:
3030+
return OCLASS_TAG;
3031+
3032+
case TagDescriptionRelationId:
3033+
return OCLASS_TAG_DESCRIPTION;
3034+
29993035
default:
30003036
{
30013037
struct CustomObjectClass *coc;

0 commit comments

Comments
 (0)