diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2012-05-25 14:35:41 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2012-05-25 14:35:41 -0400 |
commit | 1a93588ffcad3e4876c9610c0a35d79c7fcdeffe (patch) | |
tree | 839e744d925a458f14331eea9d145369267e2fce /src/bin/pg_dump/common.c | |
parent | 4615d2ca28fe9dff6e5ebaebd6caf190a0c78ba5 (diff) | |
download | postgresql-1a93588ffcad3e4876c9610c0a35d79c7fcdeffe.tar.gz postgresql-1a93588ffcad3e4876c9610c0a35d79c7fcdeffe.zip |
Use binary search instead of brute-force scan in findNamespace().
The previous coding presented a significant bottleneck when dumping
databases containing many thousands of schemas, since the total time
spent searching would increase roughly as O(N^2) in the number of objects.
Noted by Jeff Janes, though I rewrote his proposed patch to use the
existing findObjectByOid infrastructure.
Since this is a longstanding performance bug, backpatch to all supported
versions.
Diffstat (limited to 'src/bin/pg_dump/common.c')
-rw-r--r-- | src/bin/pg_dump/common.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/bin/pg_dump/common.c b/src/bin/pg_dump/common.c index d52566d64e4..7415f0d00fb 100644 --- a/src/bin/pg_dump/common.c +++ b/src/bin/pg_dump/common.c @@ -50,16 +50,19 @@ static TableInfo *tblinfo; static TypeInfo *typinfo; static FuncInfo *funinfo; static OprInfo *oprinfo; +static NamespaceInfo *nspinfo; static int numTables; static int numTypes; static int numFuncs; static int numOperators; static int numCollations; +static int numNamespaces; static DumpableObject **tblinfoindex; static DumpableObject **typinfoindex; static DumpableObject **funinfoindex; static DumpableObject **oprinfoindex; static DumpableObject **collinfoindex; +static DumpableObject **nspinfoindex; static void flagInhTables(TableInfo *tbinfo, int numTables, @@ -83,7 +86,6 @@ getSchemaData(int *numTablesPtr) ExtensionInfo *extinfo; InhInfo *inhinfo; CollInfo *collinfo; - int numNamespaces; int numExtensions; int numAggregates; int numInherits; @@ -103,7 +105,8 @@ getSchemaData(int *numTablesPtr) if (g_verbose) write_msg(NULL, "reading schemas\n"); - getNamespaces(&numNamespaces); + nspinfo = getNamespaces(&numNamespaces); + nspinfoindex = buildIndexArray(nspinfo, numNamespaces, sizeof(NamespaceInfo)); /* * getTables should be done as soon as possible, so as to minimize the @@ -734,6 +737,17 @@ findCollationByOid(Oid oid) return (CollInfo *) findObjectByOid(oid, collinfoindex, numCollations); } +/* + * findNamespaceByOid + * finds the entry (in nspinfo) of the namespace with the given oid + * returns NULL if not found + */ +NamespaceInfo * +findNamespaceByOid(Oid oid) +{ + return (NamespaceInfo *) findObjectByOid(oid, nspinfoindex, numNamespaces); +} + /* * findParentsByOid |