Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1a93588

Browse files
committed
Use binary search instead of brute-force scan in findNamespace().
The previous coding presented a significant bottleneck when dumpingdatabases containing many thousands of schemas, since the total timespent 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 theexisting findObjectByOid infrastructure.Since this is a longstanding performance bug, backpatch to all supportedversions.
1 parent4615d2c commit1a93588

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

‎src/bin/pg_dump/common.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,19 @@ static TableInfo *tblinfo;
5050
staticTypeInfo*typinfo;
5151
staticFuncInfo*funinfo;
5252
staticOprInfo*oprinfo;
53+
staticNamespaceInfo*nspinfo;
5354
staticintnumTables;
5455
staticintnumTypes;
5556
staticintnumFuncs;
5657
staticintnumOperators;
5758
staticintnumCollations;
59+
staticintnumNamespaces;
5860
staticDumpableObject**tblinfoindex;
5961
staticDumpableObject**typinfoindex;
6062
staticDumpableObject**funinfoindex;
6163
staticDumpableObject**oprinfoindex;
6264
staticDumpableObject**collinfoindex;
65+
staticDumpableObject**nspinfoindex;
6366

6467

6568
staticvoidflagInhTables(TableInfo*tbinfo,intnumTables,
@@ -83,7 +86,6 @@ getSchemaData(int *numTablesPtr)
8386
ExtensionInfo*extinfo;
8487
InhInfo*inhinfo;
8588
CollInfo*collinfo;
86-
intnumNamespaces;
8789
intnumExtensions;
8890
intnumAggregates;
8991
intnumInherits;
@@ -103,7 +105,8 @@ getSchemaData(int *numTablesPtr)
103105

104106
if (g_verbose)
105107
write_msg(NULL,"reading schemas\n");
106-
getNamespaces(&numNamespaces);
108+
nspinfo=getNamespaces(&numNamespaces);
109+
nspinfoindex=buildIndexArray(nspinfo,numNamespaces,sizeof(NamespaceInfo));
107110

108111
/*
109112
* getTables should be done as soon as possible, so as to minimize the
@@ -734,6 +737,17 @@ findCollationByOid(Oid oid)
734737
return (CollInfo*)findObjectByOid(oid,collinfoindex,numCollations);
735738
}
736739

740+
/*
741+
* findNamespaceByOid
742+
* finds the entry (in nspinfo) of the namespace with the given oid
743+
* returns NULL if not found
744+
*/
745+
NamespaceInfo*
746+
findNamespaceByOid(Oidoid)
747+
{
748+
return (NamespaceInfo*)findObjectByOid(oid,nspinfoindex,numNamespaces);
749+
}
750+
737751

738752
/*
739753
* findParentsByOid

‎src/bin/pg_dump/pg_dump.c

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,6 @@ charg_comment_end[10];
126126

127127
staticconstCatalogIdnilCatalogId= {0,0};
128128

129-
/* these are to avoid passing around info for findNamespace() */
130-
staticNamespaceInfo*g_namespaces;
131-
staticintg_numNamespaces;
132-
133129
/* flags for various command-line long options */
134130
staticintbinary_upgrade=0;
135131
staticintdisable_dollar_quoting=0;
@@ -2619,8 +2615,7 @@ getNamespaces(int *numNamespaces)
26192615

26202616
selectDumpableNamespace(&nsinfo[1]);
26212617

2622-
g_namespaces=nsinfo;
2623-
g_numNamespaces=*numNamespaces=2;
2618+
*numNamespaces=2;
26242619

26252620
returnnsinfo;
26262621
}
@@ -2673,8 +2668,7 @@ getNamespaces(int *numNamespaces)
26732668
PQclear(res);
26742669
destroyPQExpBuffer(query);
26752670

2676-
g_namespaces=nsinfo;
2677-
g_numNamespaces=*numNamespaces=ntups;
2671+
*numNamespaces=ntups;
26782672

26792673
returnnsinfo;
26802674
}
@@ -2685,36 +2679,37 @@ getNamespaces(int *numNamespaces)
26852679
*getNamespaces
26862680
*
26872681
* NB: for pre-7.3 source database, we use object OID to guess whether it's
2688-
* a system object or not.In 7.3 and later there is no guessing.
2682+
* a system object or not.In 7.3 and later there is no guessing, and we
2683+
* don't use objoid at all.
26892684
*/
26902685
staticNamespaceInfo*
26912686
findNamespace(Oidnsoid,Oidobjoid)
26922687
{
2693-
inti;
2688+
NamespaceInfo*nsinfo;
26942689

26952690
if (g_fout->remoteVersion >=70300)
26962691
{
2697-
for (i=0;i<g_numNamespaces;i++)
2698-
{
2699-
NamespaceInfo*nsinfo=&g_namespaces[i];
2700-
2701-
if (nsoid==nsinfo->dobj.catId.oid)
2702-
returnnsinfo;
2703-
}
2704-
write_msg(NULL,"schema with OID %u does not exist\n",nsoid);
2705-
exit_nicely();
2692+
nsinfo=findNamespaceByOid(nsoid);
27062693
}
27072694
else
27082695
{
2709-
/* This code depends on the layout set up by getNamespaces. */
2696+
/* This code depends on the dummy objects set up by getNamespaces. */
2697+
Oidi;
2698+
27102699
if (objoid>g_last_builtin_oid)
27112700
i=0;/* user object */
27122701
else
27132702
i=1;/* system object */
2714-
return&g_namespaces[i];
2703+
nsinfo=findNamespaceByOid(i);
27152704
}
27162705

2717-
returnNULL;/* keep compiler quiet */
2706+
if (nsinfo==NULL)
2707+
{
2708+
write_msg(NULL,"schema with OID %u does not exist\n",nsoid);
2709+
exit_nicely();
2710+
}
2711+
2712+
returnnsinfo;
27182713
}
27192714

27202715
/*

‎src/bin/pg_dump/pg_dump.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ extern TypeInfo *findTypeByOid(Oid oid);
506506
externFuncInfo*findFuncByOid(Oidoid);
507507
externOprInfo*findOprByOid(Oidoid);
508508
externCollInfo*findCollationByOid(Oidoid);
509+
externNamespaceInfo*findNamespaceByOid(Oidoid);
509510

510511
externvoidsimple_oid_list_append(SimpleOidList*list,Oidval);
511512
externvoidsimple_string_list_append(SimpleStringList*list,constchar*val);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp