Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbdc3d7f

Browse files
committed
Return ObjectAddress in many ALTER TABLE sub-routines
Since commita2e35b5, most CREATE and ALTER commands return theObjectAddress of the affected object. This is useful for event triggersto try to figure out exactly what happened. This patch extends thisidea a bit further to cover ALTER TABLE as well: an auxiliaryObjectAddress is returned for each of several subcommands of ALTERTABLE. This makes it possible to decode with precision what happenedduring execution of any ALTER TABLE command; for instance, whichconstraint was added by ALTER TABLE ADD CONSTRAINT, or which parent gotdropped from the parents list by ALTER TABLE NO INHERIT.As with the previous patch, there is no immediate user-visible changehere.This is all really just continuing whatc504513 started.Reviewed by Stephen Frost.
1 parent06bf0dd commitbdc3d7f

File tree

6 files changed

+380
-154
lines changed

6 files changed

+380
-154
lines changed

‎src/backend/catalog/heap.c

Lines changed: 59 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static ObjectAddress AddNewRelationType(const char *typeName,
9797
Oidnew_row_type,
9898
Oidnew_array_type);
9999
staticvoidRelationRemoveInheritance(Oidrelid);
100-
staticvoidStoreRelCheck(Relationrel,char*ccname,Node*expr,
100+
staticOidStoreRelCheck(Relationrel,char*ccname,Node*expr,
101101
boolis_validated,boolis_local,intinhcount,
102102
boolis_no_inherit,boolis_internal);
103103
staticvoidStoreConstraints(Relationrel,List*cooked_constraints,
@@ -1852,8 +1852,10 @@ heap_drop_with_catalog(Oid relid)
18521852

18531853
/*
18541854
* Store a default expression for column attnum of relation rel.
1855+
*
1856+
* Returns the OID of the new pg_attrdef tuple.
18551857
*/
1856-
void
1858+
Oid
18571859
StoreAttrDefault(Relationrel,AttrNumberattnum,
18581860
Node*expr,boolis_internal)
18591861
{
@@ -1958,15 +1960,19 @@ StoreAttrDefault(Relation rel, AttrNumber attnum,
19581960
*/
19591961
InvokeObjectPostCreateHookArg(AttrDefaultRelationId,
19601962
RelationGetRelid(rel),attnum,is_internal);
1963+
1964+
returnattrdefOid;
19611965
}
19621966

19631967
/*
19641968
* Store a check-constraint expression for the given relation.
19651969
*
19661970
* Caller is responsible for updating the count of constraints
19671971
* in the pg_class entry for the relation.
1972+
*
1973+
* The OID of the new constraint is returned.
19681974
*/
1969-
staticvoid
1975+
staticOid
19701976
StoreRelCheck(Relationrel,char*ccname,Node*expr,
19711977
boolis_validated,boolis_local,intinhcount,
19721978
boolis_no_inherit,boolis_internal)
@@ -1976,6 +1982,7 @@ StoreRelCheck(Relation rel, char *ccname, Node *expr,
19761982
List*varList;
19771983
intkeycount;
19781984
int16*attNos;
1985+
OidconstrOid;
19791986

19801987
/*
19811988
* Flatten expression to string form for storage.
@@ -2027,42 +2034,47 @@ StoreRelCheck(Relation rel, char *ccname, Node *expr,
20272034
/*
20282035
* Create the Check Constraint
20292036
*/
2030-
CreateConstraintEntry(ccname,/* Constraint Name */
2031-
RelationGetNamespace(rel),/* namespace */
2032-
CONSTRAINT_CHECK,/* Constraint Type */
2033-
false,/* Is Deferrable */
2034-
false,/* Is Deferred */
2035-
is_validated,
2036-
RelationGetRelid(rel),/* relation */
2037-
attNos,/* attrs in the constraint */
2038-
keycount,/* # attrs in the constraint */
2039-
InvalidOid,/* not a domain constraint */
2040-
InvalidOid,/* no associated index */
2041-
InvalidOid,/* Foreign key fields */
2042-
NULL,
2043-
NULL,
2044-
NULL,
2045-
NULL,
2046-
0,
2047-
' ',
2048-
' ',
2049-
' ',
2050-
NULL,/* not an exclusion constraint */
2051-
expr,/* Tree form of check constraint */
2052-
ccbin,/* Binary form of check constraint */
2053-
ccsrc,/* Source form of check constraint */
2054-
is_local,/* conislocal */
2055-
inhcount,/* coninhcount */
2056-
is_no_inherit,/* connoinherit */
2057-
is_internal);/* internally constructed? */
2037+
constrOid=
2038+
CreateConstraintEntry(ccname,/* Constraint Name */
2039+
RelationGetNamespace(rel),/* namespace */
2040+
CONSTRAINT_CHECK,/* Constraint Type */
2041+
false,/* Is Deferrable */
2042+
false,/* Is Deferred */
2043+
is_validated,
2044+
RelationGetRelid(rel),/* relation */
2045+
attNos,/* attrs in the constraint */
2046+
keycount,/* # attrs in the constraint */
2047+
InvalidOid,/* not a domain constraint */
2048+
InvalidOid,/* no associated index */
2049+
InvalidOid,/* Foreign key fields */
2050+
NULL,
2051+
NULL,
2052+
NULL,
2053+
NULL,
2054+
0,
2055+
' ',
2056+
' ',
2057+
' ',
2058+
NULL,/* not an exclusion constraint */
2059+
expr,/* Tree form of check constraint */
2060+
ccbin,/* Binary form of check constraint */
2061+
ccsrc,/* Source form of check constraint */
2062+
is_local,/* conislocal */
2063+
inhcount,/* coninhcount */
2064+
is_no_inherit,/* connoinherit */
2065+
is_internal);/* internally constructed? */
20582066

20592067
pfree(ccbin);
20602068
pfree(ccsrc);
2069+
2070+
returnconstrOid;
20612071
}
20622072

20632073
/*
20642074
* Store defaults and constraints (passed as a list of CookedConstraint).
20652075
*
2076+
* Each CookedConstraint struct is modified to store the new catalog tuple OID.
2077+
*
20662078
* NOTE: only pre-cooked expressions will be passed this way, which is to
20672079
* say expressions inherited from an existing relation. Newly parsed
20682080
* expressions can be added later, by direct calls to StoreAttrDefault
@@ -2074,7 +2086,7 @@ StoreConstraints(Relation rel, List *cooked_constraints, bool is_internal)
20742086
intnumchecks=0;
20752087
ListCell*lc;
20762088

2077-
if (!cooked_constraints)
2089+
if (cooked_constraints==NIL)
20782090
return;/* nothing to do */
20792091

20802092
/*
@@ -2091,12 +2103,15 @@ StoreConstraints(Relation rel, List *cooked_constraints, bool is_internal)
20912103
switch (con->contype)
20922104
{
20932105
caseCONSTR_DEFAULT:
2094-
StoreAttrDefault(rel,con->attnum,con->expr,is_internal);
2106+
con->conoid=StoreAttrDefault(rel,con->attnum,con->expr,
2107+
is_internal);
20952108
break;
20962109
caseCONSTR_CHECK:
2097-
StoreRelCheck(rel,con->name,con->expr, !con->skip_validation,
2098-
con->is_local,con->inhcount,
2099-
con->is_no_inherit,is_internal);
2110+
con->conoid=
2111+
StoreRelCheck(rel,con->name,con->expr,
2112+
!con->skip_validation,con->is_local,
2113+
con->inhcount,con->is_no_inherit,
2114+
is_internal);
21002115
numchecks++;
21012116
break;
21022117
default:
@@ -2184,6 +2199,7 @@ AddRelationNewConstraints(Relation rel,
21842199
{
21852200
RawColumnDefault*colDef= (RawColumnDefault*)lfirst(cell);
21862201
Form_pg_attributeatp=rel->rd_att->attrs[colDef->attnum-1];
2202+
OiddefOid;
21872203

21882204
expr=cookDefault(pstate,colDef->raw_default,
21892205
atp->atttypid,atp->atttypmod,
@@ -2204,10 +2220,11 @@ AddRelationNewConstraints(Relation rel,
22042220
(IsA(expr,Const)&&((Const*)expr)->constisnull))
22052221
continue;
22062222

2207-
StoreAttrDefault(rel,colDef->attnum,expr,is_internal);
2223+
defOid=StoreAttrDefault(rel,colDef->attnum,expr,is_internal);
22082224

22092225
cooked= (CookedConstraint*)palloc(sizeof(CookedConstraint));
22102226
cooked->contype=CONSTR_DEFAULT;
2227+
cooked->conoid=defOid;
22112228
cooked->name=NULL;
22122229
cooked->attnum=colDef->attnum;
22132230
cooked->expr=expr;
@@ -2227,6 +2244,7 @@ AddRelationNewConstraints(Relation rel,
22272244
{
22282245
Constraint*cdef= (Constraint*)lfirst(cell);
22292246
char*ccname;
2247+
OidconstrOid;
22302248

22312249
if (cdef->contype!=CONSTR_CHECK)
22322250
continue;
@@ -2329,13 +2347,15 @@ AddRelationNewConstraints(Relation rel,
23292347
/*
23302348
* OK, store it.
23312349
*/
2332-
StoreRelCheck(rel,ccname,expr, !cdef->skip_validation,is_local,
2333-
is_local ?0 :1,cdef->is_no_inherit,is_internal);
2350+
constrOid=
2351+
StoreRelCheck(rel,ccname,expr, !cdef->skip_validation,is_local,
2352+
is_local ?0 :1,cdef->is_no_inherit,is_internal);
23342353

23352354
numchecks++;
23362355

23372356
cooked= (CookedConstraint*)palloc(sizeof(CookedConstraint));
23382357
cooked->contype=CONSTR_CHECK;
2358+
cooked->conoid=constrOid;
23392359
cooked->name=ccname;
23402360
cooked->attnum=0;
23412361
cooked->expr=expr;

‎src/backend/catalog/index.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ UpdateIndexRelation(Oid indexoid,
675675
*to fix it up.
676676
* is_internal: if true, post creation hook for new index
677677
* if_not_exists: if true, do not throw an error if a relation with
678-
*the same name already exists.
678+
*the same name already exists.
679679
*
680680
* Returns the OID of the created index.
681681
*/
@@ -1111,7 +1111,8 @@ index_create(Relation heapRelation,
11111111
/*
11121112
* index_constraint_create
11131113
*
1114-
* Set up a constraint associated with an index
1114+
* Set up a constraint associated with an index. Return the new constraint's
1115+
* address.
11151116
*
11161117
* heapRelation: table owning the index (must be suitably locked by caller)
11171118
* indexRelationId: OID of the index
@@ -1128,7 +1129,7 @@ index_create(Relation heapRelation,
11281129
* allow_system_table_mods: allow table to be a system catalog
11291130
* is_internal: index is constructed due to internal process
11301131
*/
1131-
void
1132+
ObjectAddress
11321133
index_constraint_create(RelationheapRelation,
11331134
OidindexRelationId,
11341135
IndexInfo*indexInfo,
@@ -1316,6 +1317,8 @@ index_constraint_create(Relation heapRelation,
13161317
heap_freetuple(indexTuple);
13171318
heap_close(pg_index,RowExclusiveLock);
13181319
}
1320+
1321+
returnreferenced;
13191322
}
13201323

13211324
/*

‎src/backend/catalog/pg_constraint.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
* Subsidiary records (such as triggers or indexes to implement the
4141
* constraint) are *not* created here. But we do make dependency links
4242
* from the constraint to the things it depends on.
43+
*
44+
* The new constraint's OID is returned.
4345
*/
4446
Oid
4547
CreateConstraintEntry(constchar*constraintName,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp