Skip to content

Commit 871a978

Browse files
author
Nikita Glukhov
committed
Add generic type subscription
1 parent f2e016f commit 871a978

File tree

38 files changed

+1371
-752
lines changed

38 files changed

+1371
-752
lines changed

contrib/pg_stat_statements/pg_stat_statements.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2464,14 +2464,14 @@ JumbleExpr(pgssJumbleState *jstate, Node *node)
24642464
JumbleExpr(jstate, (Node *) expr->aggfilter);
24652465
}
24662466
break;
2467-
case T_ArrayRef:
2467+
case T_SubscriptionRef:
24682468
{
2469-
ArrayRef *aref = (ArrayRef *) node;
2469+
SubscriptionRef *sbsref = (SubscriptionRef *) node;
24702470

2471-
JumbleExpr(jstate, (Node *) aref->refupperindexpr);
2472-
JumbleExpr(jstate, (Node *) aref->reflowerindexpr);
2473-
JumbleExpr(jstate, (Node *) aref->refexpr);
2474-
JumbleExpr(jstate, (Node *) aref->refassgnexpr);
2471+
JumbleExpr(jstate, (Node *) sbsref->refupperindexpr);
2472+
JumbleExpr(jstate, (Node *) sbsref->reflowerindexpr);
2473+
JumbleExpr(jstate, (Node *) sbsref->refexpr);
2474+
JumbleExpr(jstate, (Node *) sbsref->refassgnexpr);
24752475
}
24762476
break;
24772477
case T_FuncExpr:

contrib/postgres_fdw/deparse.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static void deparseExpr(Expr *expr, deparse_expr_cxt *context);
137137
static void deparseVar(Var *node, deparse_expr_cxt *context);
138138
static void deparseConst(Const *node, deparse_expr_cxt *context);
139139
static void deparseParam(Param *node, deparse_expr_cxt *context);
140-
static void deparseArrayRef(ArrayRef *node, deparse_expr_cxt *context);
140+
static void deparseSubscriptionRef(SubscriptionRef *node, deparse_expr_cxt *context);
141141
static void deparseFuncExpr(FuncExpr *node, deparse_expr_cxt *context);
142142
static void deparseOpExpr(OpExpr *node, deparse_expr_cxt *context);
143143
static void deparseOperatorName(StringInfo buf, Form_pg_operator opform);
@@ -357,9 +357,9 @@ foreign_expr_walker(Node *node,
357357
state = FDW_COLLATE_UNSAFE;
358358
}
359359
break;
360-
case T_ArrayRef:
360+
case T_SubscriptionRef:
361361
{
362-
ArrayRef *ar = (ArrayRef *) node;
362+
SubscriptionRef *ar = (SubscriptionRef *) node;
363363

364364
/* Assignment should not be in restrictions. */
365365
if (ar->refassgnexpr != NULL)
@@ -1799,8 +1799,8 @@ deparseExpr(Expr *node, deparse_expr_cxt *context)
17991799
case T_Param:
18001800
deparseParam((Param *) node, context);
18011801
break;
1802-
case T_ArrayRef:
1803-
deparseArrayRef((ArrayRef *) node, context);
1802+
case T_SubscriptionRef:
1803+
deparseSubscriptionRef((SubscriptionRef *) node, context);
18041804
break;
18051805
case T_FuncExpr:
18061806
deparseFuncExpr((FuncExpr *) node, context);
@@ -2020,7 +2020,7 @@ deparseParam(Param *node, deparse_expr_cxt *context)
20202020
* Deparse an array subscript expression.
20212021
*/
20222022
static void
2023-
deparseArrayRef(ArrayRef *node, deparse_expr_cxt *context)
2023+
deparseSubscriptionRef(SubscriptionRef *node, deparse_expr_cxt *context)
20242024
{
20252025
StringInfo buf = context->buf;
20262026
ListCell *lowlist_item;

src/backend/catalog/heap.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,8 @@ AddNewRelationType(const char *typeName,
977977
-1, /* typmod */
978978
0, /* array dimensions for typBaseType */
979979
false, /* Type NOT NULL */
980-
InvalidOid); /* rowtypes never have a collation */
980+
InvalidOid, /* rowtypes never have a collation */
981+
InvalidOid);
981982
}
982983

983984
/* --------------------------------
@@ -1244,7 +1245,8 @@ heap_create_with_catalog(const char *relname,
12441245
-1, /* typmod */
12451246
0, /* array dimensions for typBaseType */
12461247
false, /* Type NOT NULL */
1247-
InvalidOid); /* rowtypes never have a collation */
1248+
InvalidOid, /* rowtypes never have a collation */
1249+
F_ARRAY_SUBSCRIPTION);
12481250

12491251
pfree(relarrayname);
12501252
}

src/backend/catalog/pg_type.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
118118
values[Anum_pg_type_typtypmod - 1] = Int32GetDatum(-1);
119119
values[Anum_pg_type_typndims - 1] = Int32GetDatum(0);
120120
values[Anum_pg_type_typcollation - 1] = ObjectIdGetDatum(InvalidOid);
121+
values[Anum_pg_type_typsubscription - 1] = ObjectIdGetDatum(InvalidOid);
121122
nulls[Anum_pg_type_typdefaultbin - 1] = true;
122123
nulls[Anum_pg_type_typdefault - 1] = true;
123124
nulls[Anum_pg_type_typacl - 1] = true;
@@ -166,6 +167,7 @@ TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
166167
false,
167168
InvalidOid,
168169
InvalidOid,
170+
InvalidOid,
169171
NULL,
170172
false);
171173

@@ -224,7 +226,8 @@ TypeCreate(Oid newTypeOid,
224226
int32 typeMod,
225227
int32 typNDims, /* Array dimensions for baseType */
226228
bool typeNotNull,
227-
Oid typeCollation)
229+
Oid typeCollation,
230+
Oid subscriptionProcedure)
228231
{
229232
Relation pg_type_desc;
230233
Oid typeObjectId;
@@ -364,6 +367,7 @@ TypeCreate(Oid newTypeOid,
364367
values[Anum_pg_type_typtypmod - 1] = Int32GetDatum(typeMod);
365368
values[Anum_pg_type_typndims - 1] = Int32GetDatum(typNDims);
366369
values[Anum_pg_type_typcollation - 1] = ObjectIdGetDatum(typeCollation);
370+
values[Anum_pg_type_typsubscription - 1] = ObjectIdGetDatum(subscriptionProcedure);
367371

368372
/*
369373
* initialize the default binary value for this type. Check for nulls of
@@ -484,6 +488,7 @@ TypeCreate(Oid newTypeOid,
484488
isImplicitArray,
485489
baseType,
486490
typeCollation,
491+
subscriptionProcedure,
487492
(defaultTypeBin ?
488493
stringToNode(defaultTypeBin) :
489494
NULL),
@@ -530,6 +535,7 @@ GenerateTypeDependencies(Oid typeNamespace,
530535
bool isImplicitArray,
531536
Oid baseType,
532537
Oid typeCollation,
538+
Oid subscriptionProcedure,
533539
Node *defaultExpr,
534540
bool rebuild)
535541
{
@@ -682,6 +688,14 @@ GenerateTypeDependencies(Oid typeNamespace,
682688
/* Normal dependency on the default expression. */
683689
if (defaultExpr)
684690
recordDependencyOnExpr(&myself, defaultExpr, NIL, DEPENDENCY_NORMAL);
691+
692+
if (OidIsValid(subscriptionProcedure))
693+
{
694+
referenced.classId = ProcedureRelationId;
695+
referenced.objectId = subscriptionProcedure;
696+
referenced.objectSubId = 0;
697+
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
698+
}
685699
}
686700

687701
/*

src/backend/commands/typecmds.c

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ DefineType(List *names, List *parameters)
123123
List *typmodinName = NIL;
124124
List *typmodoutName = NIL;
125125
List *analyzeName = NIL;
126+
List *subscriptionName = NIL;
126127
char category = TYPCATEGORY_USER;
127128
bool preferred = false;
128129
char delimiter = DEFAULT_TYPDELIM;
@@ -141,6 +142,7 @@ DefineType(List *names, List *parameters)
141142
DefElem *typmodinNameEl = NULL;
142143
DefElem *typmodoutNameEl = NULL;
143144
DefElem *analyzeNameEl = NULL;
145+
DefElem *subscriptionNameEl = NULL;
144146
DefElem *categoryEl = NULL;
145147
DefElem *preferredEl = NULL;
146148
DefElem *delimiterEl = NULL;
@@ -163,6 +165,7 @@ DefineType(List *names, List *parameters)
163165
Oid resulttype;
164166
ListCell *pl;
165167
ObjectAddress address;
168+
Oid subscriptionOid;
166169

167170
/*
168171
* As of Postgres 8.4, we require superuser privilege to create a base
@@ -262,6 +265,9 @@ DefineType(List *names, List *parameters)
262265
else if (pg_strcasecmp(defel->defname, "analyze") == 0 ||
263266
pg_strcasecmp(defel->defname, "analyse") == 0)
264267
defelp = &analyzeNameEl;
268+
else if (pg_strcasecmp(defel->defname, "subscription") == 0 ||
269+
pg_strcasecmp(defel->defname, "subscription") == 0)
270+
defelp = &subscriptionNameEl;
265271
else if (pg_strcasecmp(defel->defname, "category") == 0)
266272
defelp = &categoryEl;
267273
else if (pg_strcasecmp(defel->defname, "preferred") == 0)
@@ -330,6 +336,8 @@ DefineType(List *names, List *parameters)
330336
typmodoutName = defGetQualifiedName(typmodoutNameEl);
331337
if (analyzeNameEl)
332338
analyzeName = defGetQualifiedName(analyzeNameEl);
339+
if (subscriptionNameEl)
340+
subscriptionName = defGetQualifiedName(subscriptionNameEl);
333341
if (categoryEl)
334342
{
335343
char *p = defGetString(categoryEl);
@@ -511,6 +519,9 @@ DefineType(List *names, List *parameters)
511519
if (analyzeName)
512520
analyzeOid = findTypeAnalyzeFunction(analyzeName, typoid);
513521

522+
if (subscriptionName)
523+
subscriptionOid = findTypeAnalyzeFunction(subscriptionName, typoid);
524+
514525
/*
515526
* Check permissions on functions. We choose to require the creator/owner
516527
* of a type to also own the underlying functions. Since creating a type
@@ -630,7 +641,8 @@ DefineType(List *names, List *parameters)
630641
-1, /* typMod (Domains only) */
631642
0, /* Array Dimensions of typbasetype */
632643
false, /* Type NOT NULL */
633-
collation); /* type's collation */
644+
collation, /* type's collation */
645+
subscriptionOid);
634646
Assert(typoid == address.objectId);
635647

636648
/*
@@ -671,7 +683,8 @@ DefineType(List *names, List *parameters)
671683
-1, /* typMod (Domains only) */
672684
0, /* Array dimensions of typbasetype */
673685
false, /* Type NOT NULL */
674-
collation); /* type's collation */
686+
collation, /* type's collation */
687+
F_ARRAY_SUBSCRIPTION);
675688

676689
pfree(array_type);
677690

@@ -733,6 +746,7 @@ DefineDomain(CreateDomainStmt *stmt)
733746
Oid receiveProcedure;
734747
Oid sendProcedure;
735748
Oid analyzeProcedure;
749+
Oid subscriptionProcedure;
736750
bool byValue;
737751
char category;
738752
char delimiter;
@@ -856,6 +870,9 @@ DefineDomain(CreateDomainStmt *stmt)
856870
/* Analysis function */
857871
analyzeProcedure = baseType->typanalyze;
858872

873+
/* Subscription function */
874+
subscriptionProcedure = baseType->typsubscription;
875+
859876
/* Inherited default value */
860877
datum = SysCacheGetAttr(TYPEOID, typeTup,
861878
Anum_pg_type_typdefault, &isnull);
@@ -1057,7 +1074,8 @@ DefineDomain(CreateDomainStmt *stmt)
10571074
basetypeMod, /* typeMod value */
10581075
typNDims, /* Array dimensions for base type */
10591076
typNotNull, /* Type NOT NULL */
1060-
domaincoll); /* type's collation */
1077+
domaincoll, /* type's collation */
1078+
subscriptionProcedure);
10611079

10621080
/*
10631081
* Process constraints which refer to the domain ID returned by TypeCreate
@@ -1169,7 +1187,8 @@ DefineEnum(CreateEnumStmt *stmt)
11691187
-1, /* typMod (Domains only) */
11701188
0, /* Array dimensions of typbasetype */
11711189
false, /* Type NOT NULL */
1172-
InvalidOid); /* type's collation */
1190+
InvalidOid, /* type's collation */
1191+
InvalidOid);
11731192

11741193
/* Enter the enum's values into pg_enum */
11751194
EnumValuesCreate(enumTypeAddr.objectId, stmt->vals);
@@ -1209,7 +1228,8 @@ DefineEnum(CreateEnumStmt *stmt)
12091228
-1, /* typMod (Domains only) */
12101229
0, /* Array dimensions of typbasetype */
12111230
false, /* Type NOT NULL */
1212-
InvalidOid); /* type's collation */
1231+
InvalidOid, /* type's collation */
1232+
F_ARRAY_SUBSCRIPTION);
12131233

12141234
pfree(enumArrayName);
12151235

@@ -1508,7 +1528,8 @@ DefineRange(CreateRangeStmt *stmt)
15081528
-1, /* typMod (Domains only) */
15091529
0, /* Array dimensions of typbasetype */
15101530
false, /* Type NOT NULL */
1511-
InvalidOid); /* type's collation (ranges never have one) */
1531+
InvalidOid, /* type's collation (ranges never have one) */
1532+
InvalidOid);
15121533
Assert(typoid == address.objectId);
15131534

15141535
/* Create the entry in pg_range */
@@ -1550,7 +1571,8 @@ DefineRange(CreateRangeStmt *stmt)
15501571
-1, /* typMod (Domains only) */
15511572
0, /* Array dimensions of typbasetype */
15521573
false, /* Type NOT NULL */
1553-
InvalidOid); /* typcollation */
1574+
InvalidOid, /* typcollation */
1575+
F_ARRAY_SUBSCRIPTION);
15541576

15551577
pfree(rangeArrayName);
15561578

@@ -2248,6 +2270,7 @@ AlterDomainDefault(List *names, Node *defaultRaw)
22482270
false, /* a domain isn't an implicit array */
22492271
typTup->typbasetype,
22502272
typTup->typcollation,
2273+
typTup->typsubscription,
22512274
defaultExpr,
22522275
true); /* Rebuild is true */
22532276

0 commit comments

Comments
 (0)