Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 18f6258

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 8ede269 commit 18f6258

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
@@ -16317,14 +16317,15 @@ dumpIndexAttach(Archive *fout, IndexAttachInfo *attachinfo)
1631716317
{
1631816318
PQExpBuffer q = createPQExpBuffer();
1631916319

16320-
appendPQExpBuffer(q, "\nALTER INDEX %s ",
16320+
appendPQExpBuffer(q, "ALTER INDEX %s ",
1632116321
fmtQualifiedDumpable(attachinfo->parentIdx));
1632216322
appendPQExpBuffer(q, "ATTACH PARTITION %s;\n",
1632316323
fmtQualifiedDumpable(attachinfo->partitionIdx));
1632416324

1632516325
ArchiveEntry(fout, attachinfo->dobj.catId, attachinfo->dobj.dumpId,
1632616326
attachinfo->dobj.name,
16327-
NULL, NULL,
16327+
attachinfo->dobj.namespace->dobj.name,
16328+
NULL,
1632816329
"",
1632916330
false, "INDEX ATTACH", SECTION_POST_DATA,
1633016331
q->data, "", NULL,

0 commit comments

Comments
 (0)