Skip to content

Commit 8cff4f5

Browse files
committed
Code review for pg_dump's handling of ALTER INDEX ATTACH PARTITION.
Ensure the TOC entry is marked with the correct schema, so that its name is as unique as the index's is. Fix the dependencies: we want dependencies from this TOC entry to the two indexes it depends on, and we don't care (at least not for this purpose) what order the indexes are created in. Also, add dependencies on the indexes' underlying tables. Those might seem pointless given the index dependencies, but they are helpful to cue parallel restore to avoid running the ATTACH PARTITION in parallel with other DDL on the same tables. Discussion: https://postgr.es/m/10817.1535494963@sss.pgh.pa.us
1 parent 42e61c7 commit 8cff4f5

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/bin/pg_dump/common.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,17 +425,31 @@ flagInhIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
425425
attachinfo[k].dobj.catId.oid = 0;
426426
AssignDumpId(&attachinfo[k].dobj);
427427
attachinfo[k].dobj.name = pg_strdup(index->dobj.name);
428+
attachinfo[k].dobj.namespace = index->indextable->dobj.namespace;
428429
attachinfo[k].parentIdx = parentidx;
429430
attachinfo[k].partitionIdx = index;
430431

431432
/*
432-
* We want dependencies from parent to partition (so that the
433-
* partition index is created first), and another one from attach
434-
* object to parent (so that the partition index is attached once
435-
* the parent index has been created).
433+
* We must state the DO_INDEX_ATTACH object's dependencies
434+
* explicitly, since it will not match anything in pg_depend.
435+
*
436+
* Give it dependencies on both the partition index and the parent
437+
* index, so that it will not be executed till both of those
438+
* exist. (There's no need to care what order those are created
439+
* in.)
440+
*
441+
* In addition, give it dependencies on the indexes' underlying
442+
* tables. This does nothing of great value so far as serial
443+
* restore ordering goes, but it ensures that a parallel restore
444+
* will not try to run the ATTACH concurrently with other
445+
* operations on those tables.
436446
*/
437-
addObjectDependency(&parentidx->dobj, index->dobj.dumpId);
447+
addObjectDependency(&attachinfo[k].dobj, index->dobj.dumpId);
438448
addObjectDependency(&attachinfo[k].dobj, parentidx->dobj.dumpId);
449+
addObjectDependency(&attachinfo[k].dobj,
450+
index->indextable->dobj.dumpId);
451+
addObjectDependency(&attachinfo[k].dobj,
452+
parentidx->indextable->dobj.dumpId);
439453

440454
k++;
441455
}

src/bin/pg_dump/pg_dump.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16326,14 +16326,15 @@ dumpIndexAttach(Archive *fout, IndexAttachInfo *attachinfo)
1632616326
{
1632716327
PQExpBuffer q = createPQExpBuffer();
1632816328

16329-
appendPQExpBuffer(q, "\nALTER INDEX %s ",
16329+
appendPQExpBuffer(q, "ALTER INDEX %s ",
1633016330
fmtQualifiedDumpable(attachinfo->parentIdx));
1633116331
appendPQExpBuffer(q, "ATTACH PARTITION %s;\n",
1633216332
fmtQualifiedDumpable(attachinfo->partitionIdx));
1633316333

1633416334
ArchiveEntry(fout, attachinfo->dobj.catId, attachinfo->dobj.dumpId,
1633516335
attachinfo->dobj.name,
16336-
NULL, NULL,
16336+
attachinfo->dobj.namespace->dobj.name,
16337+
NULL,
1633716338
"",
1633816339
false, "INDEX ATTACH", SECTION_POST_DATA,
1633916340
q->data, "", NULL,

0 commit comments

Comments
 (0)