Commit 8cff4f53 authored by Tom Lane's avatar Tom Lane

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
parent 42e61c77
...@@ -425,17 +425,31 @@ flagInhIndexes(Archive *fout, TableInfo tblinfo[], int numTables) ...@@ -425,17 +425,31 @@ flagInhIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
attachinfo[k].dobj.catId.oid = 0; attachinfo[k].dobj.catId.oid = 0;
AssignDumpId(&attachinfo[k].dobj); AssignDumpId(&attachinfo[k].dobj);
attachinfo[k].dobj.name = pg_strdup(index->dobj.name); attachinfo[k].dobj.name = pg_strdup(index->dobj.name);
attachinfo[k].dobj.namespace = index->indextable->dobj.namespace;
attachinfo[k].parentIdx = parentidx; attachinfo[k].parentIdx = parentidx;
attachinfo[k].partitionIdx = index; attachinfo[k].partitionIdx = index;
/* /*
* We want dependencies from parent to partition (so that the * We must state the DO_INDEX_ATTACH object's dependencies
* partition index is created first), and another one from attach * explicitly, since it will not match anything in pg_depend.
* object to parent (so that the partition index is attached once *
* the parent index has been created). * Give it dependencies on both the partition index and the parent
* index, so that it will not be executed till both of those
* exist. (There's no need to care what order those are created
* in.)
*
* In addition, give it dependencies on the indexes' underlying
* tables. This does nothing of great value so far as serial
* restore ordering goes, but it ensures that a parallel restore
* will not try to run the ATTACH concurrently with other
* operations on those tables.
*/ */
addObjectDependency(&parentidx->dobj, index->dobj.dumpId); addObjectDependency(&attachinfo[k].dobj, index->dobj.dumpId);
addObjectDependency(&attachinfo[k].dobj, parentidx->dobj.dumpId); addObjectDependency(&attachinfo[k].dobj, parentidx->dobj.dumpId);
addObjectDependency(&attachinfo[k].dobj,
index->indextable->dobj.dumpId);
addObjectDependency(&attachinfo[k].dobj,
parentidx->indextable->dobj.dumpId);
k++; k++;
} }
......
...@@ -16326,14 +16326,15 @@ dumpIndexAttach(Archive *fout, IndexAttachInfo *attachinfo) ...@@ -16326,14 +16326,15 @@ dumpIndexAttach(Archive *fout, IndexAttachInfo *attachinfo)
{ {
PQExpBuffer q = createPQExpBuffer(); PQExpBuffer q = createPQExpBuffer();
appendPQExpBuffer(q, "\nALTER INDEX %s ", appendPQExpBuffer(q, "ALTER INDEX %s ",
fmtQualifiedDumpable(attachinfo->parentIdx)); fmtQualifiedDumpable(attachinfo->parentIdx));
appendPQExpBuffer(q, "ATTACH PARTITION %s;\n", appendPQExpBuffer(q, "ATTACH PARTITION %s;\n",
fmtQualifiedDumpable(attachinfo->partitionIdx)); fmtQualifiedDumpable(attachinfo->partitionIdx));
ArchiveEntry(fout, attachinfo->dobj.catId, attachinfo->dobj.dumpId, ArchiveEntry(fout, attachinfo->dobj.catId, attachinfo->dobj.dumpId,
attachinfo->dobj.name, attachinfo->dobj.name,
NULL, NULL, attachinfo->dobj.namespace->dobj.name,
NULL,
"", "",
false, "INDEX ATTACH", SECTION_POST_DATA, false, "INDEX ATTACH", SECTION_POST_DATA,
q->data, "", NULL, q->data, "", NULL,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment