summaryrefslogtreecommitdiff
path: root/src/bin/pg_dump/pg_dump.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-03-31 14:42:38 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2012-03-31 14:42:38 -0400
commit55eb256789e43cc1b6113fe82efdc34a370aa8a2 (patch)
tree99cf9d5456bc41edade5b63463f581f90855e75b /src/bin/pg_dump/pg_dump.c
parent38350a496509d6aa4dc481b1f9f143a136e4c661 (diff)
Fix O(N^2) behavior in pg_dump for large numbers of owned sequences.
The loop that matched owned sequences to their owning tables required time proportional to number of owned sequences times number of tables; although this work was only expended in selective-dump situations, which is probably why the issue wasn't recognized long since. Refactor slightly so that we can perform this work after the index array for findTableByOid has been set up, reducing the time to O(M log N). Per gripe from Mike Roest. Since this is a longstanding performance bug, backpatch to all supported versions.
Diffstat (limited to 'src/bin/pg_dump/pg_dump.c')
-rw-r--r--src/bin/pg_dump/pg_dump.c45
1 files changed, 25 insertions, 20 deletions
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index afd4b184cdf..d4c82bea8be 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -3201,40 +3201,45 @@ getTables(int *numTables)
PQclear(res);
+ destroyPQExpBuffer(query);
+ destroyPQExpBuffer(delqry);
+ destroyPQExpBuffer(lockquery);
+
+ return tblinfo;
+}
+
+/*
+ * getOwnedSeqs
+ * identify owned sequences and mark them as dumpable if owning table is
+ *
+ * We used to do this in getTables(), but it's better to do it after the
+ * index used by findTableByOid() has been set up.
+ */
+void
+getOwnedSeqs(TableInfo tblinfo[], int numTables)
+{
+ int i;
+
/*
* Force sequences that are "owned" by table columns to be dumped whenever
* their owning table is being dumped.
*/
- for (i = 0; i < ntups; i++)
+ for (i = 0; i < numTables; i++)
{
TableInfo *seqinfo = &tblinfo[i];
- int j;
+ TableInfo *owning_tab;
if (!OidIsValid(seqinfo->owning_tab))
continue; /* not an owned sequence */
if (seqinfo->dobj.dump)
continue; /* no need to search */
-
- /* can't use findTableByOid yet, unfortunately */
- for (j = 0; j < ntups; j++)
+ owning_tab = findTableByOid(seqinfo->owning_tab);
+ if (owning_tab && owning_tab->dobj.dump)
{
- if (tblinfo[j].dobj.catId.oid == seqinfo->owning_tab)
- {
- if (tblinfo[j].dobj.dump)
- {
- seqinfo->interesting = true;
- seqinfo->dobj.dump = true;
- }
- break;
- }
+ seqinfo->interesting = true;
+ seqinfo->dobj.dump = true;
}
}
-
- destroyPQExpBuffer(query);
- destroyPQExpBuffer(delqry);
- destroyPQExpBuffer(lockquery);
-
- return tblinfo;
}
/*