Skip to content

Commit 8febfd1

Browse files
committed
Switch to multi-inserts when registering dependencies for many code paths
This commit improves the dependency registrations by taking advantage of the preliminary work done in 63110c6, to group together the insertion of dependencies of the same type to pg_depend. With the current layer of routines available, and as only dependencies of the same type can be grouped, there are code paths still doing more than one multi-insert when it is necessary to register dependencies of multiple types (constraint and index creation are two cases doing that). While on it, this refactors some of the code to use ObjectAddressSet() when manipulating object addresses. Author: Daniel Gustafsson, Michael Paquier Reviewed-by: Andres Freund, Álvaro Herrera Discussion: https://postgr.es/m/[email protected]
1 parent 11b80d9 commit 8febfd1

File tree

13 files changed

+252
-220
lines changed

13 files changed

+252
-220
lines changed

src/backend/catalog/heap.c

+26-33
Original file line numberDiff line numberDiff line change
@@ -1428,28 +1428,25 @@ heap_create_with_catalog(const char *relname,
14281428
{
14291429
ObjectAddress myself,
14301430
referenced;
1431+
ObjectAddresses *addrs;
14311432

1432-
myself.classId = RelationRelationId;
1433-
myself.objectId = relid;
1434-
myself.objectSubId = 0;
1435-
1436-
referenced.classId = NamespaceRelationId;
1437-
referenced.objectId = relnamespace;
1438-
referenced.objectSubId = 0;
1439-
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
1433+
ObjectAddressSet(myself, RelationRelationId, relid);
14401434

14411435
recordDependencyOnOwner(RelationRelationId, relid, ownerid);
14421436

14431437
recordDependencyOnNewAcl(RelationRelationId, relid, 0, ownerid, relacl);
14441438

14451439
recordDependencyOnCurrentExtension(&myself, false);
14461440

1441+
addrs = new_object_addresses();
1442+
1443+
ObjectAddressSet(referenced, NamespaceRelationId, relnamespace);
1444+
add_exact_object_address(&referenced, addrs);
1445+
14471446
if (reloftypeid)
14481447
{
1449-
referenced.classId = TypeRelationId;
1450-
referenced.objectId = reloftypeid;
1451-
referenced.objectSubId = 0;
1452-
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
1448+
ObjectAddressSet(referenced, TypeRelationId, reloftypeid);
1449+
add_exact_object_address(&referenced, addrs);
14531450
}
14541451

14551452
/*
@@ -1462,11 +1459,12 @@ heap_create_with_catalog(const char *relname,
14621459
if (relkind == RELKIND_RELATION ||
14631460
relkind == RELKIND_MATVIEW)
14641461
{
1465-
referenced.classId = AccessMethodRelationId;
1466-
referenced.objectId = accessmtd;
1467-
referenced.objectSubId = 0;
1468-
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
1462+
ObjectAddressSet(referenced, AccessMethodRelationId, accessmtd);
1463+
add_exact_object_address(&referenced, addrs);
14691464
}
1465+
1466+
record_object_address_dependencies(&myself, addrs, DEPENDENCY_NORMAL);
1467+
free_object_addresses(addrs);
14701468
}
14711469

14721470
/* Post creation hook for new relation */
@@ -3574,6 +3572,7 @@ StorePartitionKey(Relation rel,
35743572
bool nulls[Natts_pg_partitioned_table];
35753573
ObjectAddress myself;
35763574
ObjectAddress referenced;
3575+
ObjectAddresses *addrs;
35773576

35783577
Assert(rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
35793578

@@ -3617,31 +3616,27 @@ StorePartitionKey(Relation rel,
36173616
table_close(pg_partitioned_table, RowExclusiveLock);
36183617

36193618
/* Mark this relation as dependent on a few things as follows */
3620-
myself.classId = RelationRelationId;
3621-
myself.objectId = RelationGetRelid(rel);
3622-
myself.objectSubId = 0;
3619+
addrs = new_object_addresses();
3620+
ObjectAddressSet(myself, RelationRelationId, RelationGetRelid(rel));
36233621

36243622
/* Operator class and collation per key column */
36253623
for (i = 0; i < partnatts; i++)
36263624
{
3627-
referenced.classId = OperatorClassRelationId;
3628-
referenced.objectId = partopclass[i];
3629-
referenced.objectSubId = 0;
3630-
3631-
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
3625+
ObjectAddressSet(referenced, OperatorClassRelationId, partopclass[i]);
3626+
add_exact_object_address(&referenced, addrs);
36323627

36333628
/* The default collation is pinned, so don't bother recording it */
36343629
if (OidIsValid(partcollation[i]) &&
36353630
partcollation[i] != DEFAULT_COLLATION_OID)
36363631
{
3637-
referenced.classId = CollationRelationId;
3638-
referenced.objectId = partcollation[i];
3639-
referenced.objectSubId = 0;
3640-
3641-
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
3632+
ObjectAddressSet(referenced, CollationRelationId, partcollation[i]);
3633+
add_exact_object_address(&referenced, addrs);
36423634
}
36433635
}
36443636

3637+
record_object_address_dependencies(&myself, addrs, DEPENDENCY_NORMAL);
3638+
free_object_addresses(addrs);
3639+
36453640
/*
36463641
* The partitioning columns are made internally dependent on the table,
36473642
* because we cannot drop any of them without dropping the whole table.
@@ -3653,10 +3648,8 @@ StorePartitionKey(Relation rel,
36533648
if (partattrs[i] == 0)
36543649
continue; /* ignore expressions here */
36553650

3656-
referenced.classId = RelationRelationId;
3657-
referenced.objectId = RelationGetRelid(rel);
3658-
referenced.objectSubId = partattrs[i];
3659-
3651+
ObjectAddressSubSet(referenced, RelationRelationId,
3652+
RelationGetRelid(rel), partattrs[i]);
36603653
recordDependencyOn(&referenced, &myself, DEPENDENCY_INTERNAL);
36613654
}
36623655

src/backend/catalog/index.c

+17-4
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,7 @@ index_create(Relation heapRelation,
10181018
{
10191019
ObjectAddress myself,
10201020
referenced;
1021+
ObjectAddresses *addrs;
10211022

10221023
ObjectAddressSet(myself, RelationRelationId, indexRelationId);
10231024

@@ -1054,6 +1055,8 @@ index_create(Relation heapRelation,
10541055
{
10551056
bool have_simple_col = false;
10561057

1058+
addrs = new_object_addresses();
1059+
10571060
/* Create auto dependencies on simply-referenced columns */
10581061
for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
10591062
{
@@ -1062,7 +1065,7 @@ index_create(Relation heapRelation,
10621065
ObjectAddressSubSet(referenced, RelationRelationId,
10631066
heapRelationId,
10641067
indexInfo->ii_IndexAttrNumbers[i]);
1065-
recordDependencyOn(&myself, &referenced, DEPENDENCY_AUTO);
1068+
add_exact_object_address(&referenced, addrs);
10661069
have_simple_col = true;
10671070
}
10681071
}
@@ -1077,8 +1080,11 @@ index_create(Relation heapRelation,
10771080
{
10781081
ObjectAddressSet(referenced, RelationRelationId,
10791082
heapRelationId);
1080-
recordDependencyOn(&myself, &referenced, DEPENDENCY_AUTO);
1083+
add_exact_object_address(&referenced, addrs);
10811084
}
1085+
1086+
record_object_address_dependencies(&myself, addrs, DEPENDENCY_AUTO);
1087+
free_object_addresses(addrs);
10821088
}
10831089

10841090
/*
@@ -1096,7 +1102,11 @@ index_create(Relation heapRelation,
10961102
recordDependencyOn(&myself, &referenced, DEPENDENCY_PARTITION_SEC);
10971103
}
10981104

1105+
/* placeholder for normal dependencies */
1106+
addrs = new_object_addresses();
1107+
10991108
/* Store dependency on collations */
1109+
11001110
/* The default collation is pinned, so don't bother recording it */
11011111
for (i = 0; i < indexInfo->ii_NumIndexKeyAttrs; i++)
11021112
{
@@ -1105,17 +1115,20 @@ index_create(Relation heapRelation,
11051115
{
11061116
ObjectAddressSet(referenced, CollationRelationId,
11071117
collationObjectId[i]);
1108-
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
1118+
add_exact_object_address(&referenced, addrs);
11091119
}
11101120
}
11111121

11121122
/* Store dependency on operator classes */
11131123
for (i = 0; i < indexInfo->ii_NumIndexKeyAttrs; i++)
11141124
{
11151125
ObjectAddressSet(referenced, OperatorClassRelationId, classObjectId[i]);
1116-
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
1126+
add_exact_object_address(&referenced, addrs);
11171127
}
11181128

1129+
record_object_address_dependencies(&myself, addrs, DEPENDENCY_NORMAL);
1130+
free_object_addresses(addrs);
1131+
11191132
/* Store dependencies on anything mentioned in index expressions */
11201133
if (indexInfo->ii_Expressions)
11211134
{

src/backend/catalog/pg_aggregate.c

+14-9
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ AggregateCreate(const char *aggName,
105105
int i;
106106
ObjectAddress myself,
107107
referenced;
108+
ObjectAddresses *addrs;
108109
AclResult aclresult;
109110

110111
/* sanity checks (caller should have caught these) */
@@ -741,66 +742,70 @@ AggregateCreate(const char *aggName,
741742
* way.
742743
*/
743744

745+
addrs = new_object_addresses();
746+
744747
/* Depends on transition function */
745748
ObjectAddressSet(referenced, ProcedureRelationId, transfn);
746-
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
749+
add_exact_object_address(&referenced, addrs);
747750

748751
/* Depends on final function, if any */
749752
if (OidIsValid(finalfn))
750753
{
751754
ObjectAddressSet(referenced, ProcedureRelationId, finalfn);
752-
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
755+
add_exact_object_address(&referenced, addrs);
753756
}
754757

755758
/* Depends on combine function, if any */
756759
if (OidIsValid(combinefn))
757760
{
758761
ObjectAddressSet(referenced, ProcedureRelationId, combinefn);
759-
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
762+
add_exact_object_address(&referenced, addrs);
760763
}
761764

762765
/* Depends on serialization function, if any */
763766
if (OidIsValid(serialfn))
764767
{
765768
ObjectAddressSet(referenced, ProcedureRelationId, serialfn);
766-
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
769+
add_exact_object_address(&referenced, addrs);
767770
}
768771

769772
/* Depends on deserialization function, if any */
770773
if (OidIsValid(deserialfn))
771774
{
772775
ObjectAddressSet(referenced, ProcedureRelationId, deserialfn);
773-
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
776+
add_exact_object_address(&referenced, addrs);
774777
}
775778

776779
/* Depends on forward transition function, if any */
777780
if (OidIsValid(mtransfn))
778781
{
779782
ObjectAddressSet(referenced, ProcedureRelationId, mtransfn);
780-
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
783+
add_exact_object_address(&referenced, addrs);
781784
}
782785

783786
/* Depends on inverse transition function, if any */
784787
if (OidIsValid(minvtransfn))
785788
{
786789
ObjectAddressSet(referenced, ProcedureRelationId, minvtransfn);
787-
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
790+
add_exact_object_address(&referenced, addrs);
788791
}
789792

790793
/* Depends on final function, if any */
791794
if (OidIsValid(mfinalfn))
792795
{
793796
ObjectAddressSet(referenced, ProcedureRelationId, mfinalfn);
794-
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
797+
add_exact_object_address(&referenced, addrs);
795798
}
796799

797800
/* Depends on sort operator, if any */
798801
if (OidIsValid(sortop))
799802
{
800803
ObjectAddressSet(referenced, OperatorRelationId, sortop);
801-
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
804+
add_exact_object_address(&referenced, addrs);
802805
}
803806

807+
record_object_address_dependencies(&myself, addrs, DEPENDENCY_NORMAL);
808+
free_object_addresses(addrs);
804809
return myself;
805810
}
806811

src/backend/catalog/pg_cast.c

+13-15
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ CastCreate(Oid sourcetypeid, Oid targettypeid, Oid funcid, char castcontext,
5050
bool nulls[Natts_pg_cast];
5151
ObjectAddress myself,
5252
referenced;
53+
ObjectAddresses *addrs;
5354

5455
relation = table_open(CastRelationId, RowExclusiveLock);
5556

@@ -83,32 +84,29 @@ CastCreate(Oid sourcetypeid, Oid targettypeid, Oid funcid, char castcontext,
8384

8485
CatalogTupleInsert(relation, tuple);
8586

87+
addrs = new_object_addresses();
88+
8689
/* make dependency entries */
87-
myself.classId = CastRelationId;
88-
myself.objectId = castid;
89-
myself.objectSubId = 0;
90+
ObjectAddressSet(myself, CastRelationId, castid);
9091

9192
/* dependency on source type */
92-
referenced.classId = TypeRelationId;
93-
referenced.objectId = sourcetypeid;
94-
referenced.objectSubId = 0;
95-
recordDependencyOn(&myself, &referenced, behavior);
93+
ObjectAddressSet(referenced, TypeRelationId, sourcetypeid);
94+
add_exact_object_address(&referenced, addrs);
9695

9796
/* dependency on target type */
98-
referenced.classId = TypeRelationId;
99-
referenced.objectId = targettypeid;
100-
referenced.objectSubId = 0;
101-
recordDependencyOn(&myself, &referenced, behavior);
97+
ObjectAddressSet(referenced, TypeRelationId, targettypeid);
98+
add_exact_object_address(&referenced, addrs);
10299

103100
/* dependency on function */
104101
if (OidIsValid(funcid))
105102
{
106-
referenced.classId = ProcedureRelationId;
107-
referenced.objectId = funcid;
108-
referenced.objectSubId = 0;
109-
recordDependencyOn(&myself, &referenced, behavior);
103+
ObjectAddressSet(referenced, ProcedureRelationId, funcid);
104+
add_exact_object_address(&referenced, addrs);
110105
}
111106

107+
record_object_address_dependencies(&myself, addrs, behavior);
108+
free_object_addresses(addrs);
109+
112110
/* dependency on extension */
113111
recordDependencyOnCurrentExtension(&myself, false);
114112

0 commit comments

Comments
 (0)