Skip to content

Commit 44c5288

Browse files
committed
Change the way pg_dump retrieves partitioning info
This gets rid of the code that issued separate queries to retrieve the partitioning parent-child relationship, parent partition key, and child partition bound information. With this patch, the information is retrieved instead using the queries issued from getTables() and getInherits(), which is both more efficient than the previous approach and doesn't require any new code. Since the partitioning parent-child relationship is now retrieved with the same old code that handles inheritance, partition attributes receive a proper flagInhAttrs() treatment (that it didn't receive before), which is needed so that the inherited NOT NULL constraints are not emitted if we already emitted it for the parent. Also, fix a bug in pg_dump's --binary-upgrade code, which caused pg_dump to emit invalid command to attach a partition to its parent. Author: Amit Langote, with some additional changes by me.
1 parent 5469e44 commit 44c5288

File tree

4 files changed

+153
-252
lines changed

4 files changed

+153
-252
lines changed

src/bin/pg_dump/common.c

-90
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,13 @@ static int numextmembers;
6868

6969
static void flagInhTables(TableInfo *tbinfo, int numTables,
7070
InhInfo *inhinfo, int numInherits);
71-
static void flagPartitions(TableInfo *tblinfo, int numTables,
72-
PartInfo *partinfo, int numPartitions);
7371
static void flagInhAttrs(DumpOptions *dopt, TableInfo *tblinfo, int numTables);
7472
static DumpableObject **buildIndexArray(void *objArray, int numObjs,
7573
Size objSize);
7674
static int DOCatalogIdCompare(const void *p1, const void *p2);
7775
static int ExtensionMemberIdCompare(const void *p1, const void *p2);
7876
static void findParentsByOid(TableInfo *self,
7977
InhInfo *inhinfo, int numInherits);
80-
static void findPartitionParentByOid(TableInfo *self, PartInfo *partinfo,
81-
int numPartitions);
8278
static int strInArray(const char *pattern, char **arr, int arr_size);
8379

8480

@@ -97,10 +93,8 @@ getSchemaData(Archive *fout, int *numTablesPtr)
9793
NamespaceInfo *nspinfo;
9894
ExtensionInfo *extinfo;
9995
InhInfo *inhinfo;
100-
PartInfo *partinfo;
10196
int numAggregates;
10297
int numInherits;
103-
int numPartitions;
10498
int numRules;
10599
int numProcLangs;
106100
int numCasts;
@@ -237,10 +231,6 @@ getSchemaData(Archive *fout, int *numTablesPtr)
237231
write_msg(NULL, "reading table inheritance information\n");
238232
inhinfo = getInherits(fout, &numInherits);
239233

240-
if (g_verbose)
241-
write_msg(NULL, "reading partition information\n");
242-
partinfo = getPartitions(fout, &numPartitions);
243-
244234
if (g_verbose)
245235
write_msg(NULL, "reading event triggers\n");
246236
getEventTriggers(fout, &numEventTriggers);
@@ -255,11 +245,6 @@ getSchemaData(Archive *fout, int *numTablesPtr)
255245
write_msg(NULL, "finding inheritance relationships\n");
256246
flagInhTables(tblinfo, numTables, inhinfo, numInherits);
257247

258-
/* Link tables to partition parents, mark parents as interesting */
259-
if (g_verbose)
260-
write_msg(NULL, "finding partition relationships\n");
261-
flagPartitions(tblinfo, numTables, partinfo, numPartitions);
262-
263248
if (g_verbose)
264249
write_msg(NULL, "reading column info for interesting tables\n");
265250
getTableAttrs(fout, tblinfo, numTables);
@@ -292,10 +277,6 @@ getSchemaData(Archive *fout, int *numTablesPtr)
292277
write_msg(NULL, "reading policies\n");
293278
getPolicies(fout, tblinfo, numTables);
294279

295-
if (g_verbose)
296-
write_msg(NULL, "reading partition key information for interesting tables\n");
297-
getTablePartitionKeyInfo(fout, tblinfo, numTables);
298-
299280
if (g_verbose)
300281
write_msg(NULL, "reading publications\n");
301282
getPublications(fout);
@@ -354,43 +335,6 @@ flagInhTables(TableInfo *tblinfo, int numTables,
354335
}
355336
}
356337

357-
/* flagPartitions -
358-
* Fill in parent link fields of every target table that is partition,
359-
* and mark parents of partitions as interesting
360-
*
361-
* modifies tblinfo
362-
*/
363-
static void
364-
flagPartitions(TableInfo *tblinfo, int numTables,
365-
PartInfo *partinfo, int numPartitions)
366-
{
367-
int i;
368-
369-
for (i = 0; i < numTables; i++)
370-
{
371-
/* Some kinds are never partitions */
372-
if (tblinfo[i].relkind == RELKIND_SEQUENCE ||
373-
tblinfo[i].relkind == RELKIND_VIEW ||
374-
tblinfo[i].relkind == RELKIND_MATVIEW)
375-
continue;
376-
377-
/* Don't bother computing anything for non-target tables, either */
378-
if (!tblinfo[i].dobj.dump)
379-
continue;
380-
381-
/* Find the parent TableInfo and save */
382-
findPartitionParentByOid(&tblinfo[i], partinfo, numPartitions);
383-
384-
/* Mark the parent as interesting for getTableAttrs */
385-
if (tblinfo[i].partitionOf)
386-
{
387-
tblinfo[i].partitionOf->interesting = true;
388-
addObjectDependency(&tblinfo[i].dobj,
389-
tblinfo[i].partitionOf->dobj.dumpId);
390-
}
391-
}
392-
}
393-
394338
/* flagInhAttrs -
395339
* for each dumpable table in tblinfo, flag its inherited attributes
396340
*
@@ -991,40 +935,6 @@ findParentsByOid(TableInfo *self,
991935
self->parents = NULL;
992936
}
993937

994-
/*
995-
* findPartitionParentByOid
996-
* find a partition's parent in tblinfo[]
997-
*/
998-
static void
999-
findPartitionParentByOid(TableInfo *self, PartInfo *partinfo,
1000-
int numPartitions)
1001-
{
1002-
Oid oid = self->dobj.catId.oid;
1003-
int i;
1004-
1005-
for (i = 0; i < numPartitions; i++)
1006-
{
1007-
if (partinfo[i].partrelid == oid)
1008-
{
1009-
TableInfo *parent;
1010-
1011-
parent = findTableByOid(partinfo[i].partparent);
1012-
if (parent == NULL)
1013-
{
1014-
write_msg(NULL, "failed sanity check, parent OID %u of table \"%s\" (OID %u) not found\n",
1015-
partinfo[i].partparent,
1016-
self->dobj.name,
1017-
oid);
1018-
exit_nicely(1);
1019-
}
1020-
self->partitionOf = parent;
1021-
1022-
/* While we're at it, also save the partdef */
1023-
self->partitiondef = partinfo[i].partdef;
1024-
}
1025-
}
1026-
}
1027-
1028938
/*
1029939
* parseOidArray
1030940
* parse a string of numbers delimited by spaces into a character array

0 commit comments

Comments
 (0)