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

Commit965d76f

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 parentc676f83 commit965d76f

File tree

3 files changed

+34
-25
lines changed

3 files changed

+34
-25
lines changed

‎src/bin/pg_dump/common.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,17 @@ static TableInfo *tblinfo;
5050
staticTypeInfo*typinfo;
5151
staticFuncInfo*funinfo;
5252
staticOprInfo*oprinfo;
53+
staticNamespaceInfo*nspinfo;
5354
staticintnumTables;
5455
staticintnumTypes;
5556
staticintnumFuncs;
5657
staticintnumOperators;
58+
staticintnumNamespaces;
5759
staticDumpableObject**tblinfoindex;
5860
staticDumpableObject**typinfoindex;
5961
staticDumpableObject**funinfoindex;
6062
staticDumpableObject**oprinfoindex;
63+
staticDumpableObject**nspinfoindex;
6164

6265

6366
staticvoidflagInhTables(TableInfo*tbinfo,intnumTables,
@@ -78,7 +81,6 @@ static intstrInArray(const char *pattern, char **arr, int arr_size);
7881
TableInfo*
7982
getSchemaData(int*numTablesPtr)
8083
{
81-
NamespaceInfo*nsinfo;
8284
AggInfo*agginfo;
8385
InhInfo*inhinfo;
8486
RuleInfo*ruleinfo;
@@ -94,7 +96,6 @@ getSchemaData(int *numTablesPtr)
9496
FdwInfo*fdwinfo;
9597
ForeignServerInfo*srvinfo;
9698
DefaultACLInfo*daclinfo;
97-
intnumNamespaces;
9899
intnumAggregates;
99100
intnumInherits;
100101
intnumRules;
@@ -113,7 +114,8 @@ getSchemaData(int *numTablesPtr)
113114

114115
if (g_verbose)
115116
write_msg(NULL,"reading schemas\n");
116-
nsinfo=getNamespaces(&numNamespaces);
117+
nspinfo=getNamespaces(&numNamespaces);
118+
nspinfoindex=buildIndexArray(nspinfo,numNamespaces,sizeof(NamespaceInfo));
117119

118120
/*
119121
* getTables should be done as soon as possible, so as to minimize the
@@ -714,6 +716,17 @@ findOprByOid(Oid oid)
714716
return (OprInfo*)findObjectByOid(oid,oprinfoindex,numOperators);
715717
}
716718

719+
/*
720+
* findNamespaceByOid
721+
* finds the entry (in nspinfo) of the namespace with the given oid
722+
* returns NULL if not found
723+
*/
724+
NamespaceInfo*
725+
findNamespaceByOid(Oidoid)
726+
{
727+
return (NamespaceInfo*)findObjectByOid(oid,nspinfoindex,numNamespaces);
728+
}
729+
717730

718731
/*
719732
* findParentsByOid

‎src/bin/pg_dump/pg_dump.c

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

117117
staticconstCatalogIdnilCatalogId= {0,0};
118118

119-
/* these are to avoid passing around info for findNamespace() */
120-
staticNamespaceInfo*g_namespaces;
121-
staticintg_numNamespaces;
122-
123119
/* flags for various command-line long options */
124120
staticintbinary_upgrade=0;
125121
staticintdisable_dollar_quoting=0;
@@ -2408,8 +2404,7 @@ getNamespaces(int *numNamespaces)
24082404

24092405
selectDumpableNamespace(&nsinfo[1]);
24102406

2411-
g_namespaces=nsinfo;
2412-
g_numNamespaces=*numNamespaces=2;
2407+
*numNamespaces=2;
24132408

24142409
returnnsinfo;
24152410
}
@@ -2462,8 +2457,7 @@ getNamespaces(int *numNamespaces)
24622457
PQclear(res);
24632458
destroyPQExpBuffer(query);
24642459

2465-
g_namespaces=nsinfo;
2466-
g_numNamespaces=*numNamespaces=ntups;
2460+
*numNamespaces=ntups;
24672461

24682462
returnnsinfo;
24692463
}
@@ -2474,36 +2468,37 @@ getNamespaces(int *numNamespaces)
24742468
*getNamespaces
24752469
*
24762470
* NB: for pre-7.3 source database, we use object OID to guess whether it's
2477-
* a system object or not.In 7.3 and later there is no guessing.
2471+
* a system object or not.In 7.3 and later there is no guessing, and we
2472+
* don't use objoid at all.
24782473
*/
24792474
staticNamespaceInfo*
24802475
findNamespace(Oidnsoid,Oidobjoid)
24812476
{
2482-
inti;
2477+
NamespaceInfo*nsinfo;
24832478

24842479
if (g_fout->remoteVersion >=70300)
24852480
{
2486-
for (i=0;i<g_numNamespaces;i++)
2487-
{
2488-
NamespaceInfo*nsinfo=&g_namespaces[i];
2489-
2490-
if (nsoid==nsinfo->dobj.catId.oid)
2491-
returnnsinfo;
2492-
}
2493-
write_msg(NULL,"schema with OID %u does not exist\n",nsoid);
2494-
exit_nicely();
2481+
nsinfo=findNamespaceByOid(nsoid);
24952482
}
24962483
else
24972484
{
2498-
/* This code depends on the layout set up by getNamespaces. */
2485+
/* This code depends on the dummy objects set up by getNamespaces. */
2486+
Oidi;
2487+
24992488
if (objoid>g_last_builtin_oid)
25002489
i=0;/* user object */
25012490
else
25022491
i=1;/* system object */
2503-
return&g_namespaces[i];
2492+
nsinfo=findNamespaceByOid(i);
25042493
}
25052494

2506-
returnNULL;/* keep compiler quiet */
2495+
if (nsinfo==NULL)
2496+
{
2497+
write_msg(NULL,"schema with OID %u does not exist\n",nsoid);
2498+
exit_nicely();
2499+
}
2500+
2501+
returnnsinfo;
25072502
}
25082503

25092504
/*

‎src/bin/pg_dump/pg_dump.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ extern TableInfo *findTableByOid(Oid oid);
482482
externTypeInfo*findTypeByOid(Oidoid);
483483
externFuncInfo*findFuncByOid(Oidoid);
484484
externOprInfo*findOprByOid(Oidoid);
485+
externNamespaceInfo*findNamespaceByOid(Oidoid);
485486

486487
externvoidsimple_oid_list_append(SimpleOidList*list,Oidval);
487488
externvoidsimple_string_list_append(SimpleStringList*list,constchar*val);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp