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

Commitfa76bb0

Browse files
committed
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 timeproportional to number of owned sequences times number of tables; althoughthis work was only expended in selective-dump situations, which is probablywhy the issue wasn't recognized long since. Refactor slightly so that wecan perform this work after the index array for findTableByOid has beenset 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.
1 parentdde1813 commitfa76bb0

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

‎src/bin/pg_dump/common.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ getSchemaData(int *numTablesPtr)
116116
tblinfo=getTables(&numTables);
117117
tblinfoindex=buildIndexArray(tblinfo,numTables,sizeof(TableInfo));
118118

119+
/* Do this after we've built tblinfoindex */
120+
getOwnedSeqs(tblinfo,numTables);
121+
119122
if (g_verbose)
120123
write_msg(NULL,"reading extensions\n");
121124
extinfo=getExtensions(&numExtensions);

‎src/bin/pg_dump/pg_dump.c

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4303,38 +4303,43 @@ getTables(int *numTables)
43034303

43044304
PQclear(res);
43054305

4306+
destroyPQExpBuffer(query);
4307+
4308+
returntblinfo;
4309+
}
4310+
4311+
/*
4312+
* getOwnedSeqs
4313+
* identify owned sequences and mark them as dumpable if owning table is
4314+
*
4315+
* We used to do this in getTables(), but it's better to do it after the
4316+
* index used by findTableByOid() has been set up.
4317+
*/
4318+
void
4319+
getOwnedSeqs(TableInfotblinfo[],intnumTables)
4320+
{
4321+
inti;
4322+
43064323
/*
43074324
* Force sequences that are "owned" by table columns to be dumped whenever
43084325
* their owning table is being dumped.
43094326
*/
4310-
for (i=0;i<ntups;i++)
4327+
for (i=0;i<numTables;i++)
43114328
{
43124329
TableInfo*seqinfo=&tblinfo[i];
4313-
intj;
4330+
TableInfo*owning_tab;
43144331

43154332
if (!OidIsValid(seqinfo->owning_tab))
43164333
continue;/* not an owned sequence */
43174334
if (seqinfo->dobj.dump)
43184335
continue;/* no need to search */
4319-
4320-
/* can't use findTableByOid yet, unfortunately */
4321-
for (j=0;j<ntups;j++)
4336+
owning_tab=findTableByOid(seqinfo->owning_tab);
4337+
if (owning_tab&&owning_tab->dobj.dump)
43224338
{
4323-
if (tblinfo[j].dobj.catId.oid==seqinfo->owning_tab)
4324-
{
4325-
if (tblinfo[j].dobj.dump)
4326-
{
4327-
seqinfo->interesting= true;
4328-
seqinfo->dobj.dump= true;
4329-
}
4330-
break;
4331-
}
4339+
seqinfo->interesting= true;
4340+
seqinfo->dobj.dump= true;
43324341
}
43334342
}
4334-
4335-
destroyPQExpBuffer(query);
4336-
4337-
returntblinfo;
43384343
}
43394344

43404345
/*

‎src/bin/pg_dump/pg_dump.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ extern OpfamilyInfo *getOpfamilies(int *numOpfamilies);
540540
externCollInfo*getCollations(int*numCollations);
541541
externConvInfo*getConversions(int*numConversions);
542542
externTableInfo*getTables(int*numTables);
543+
externvoidgetOwnedSeqs(TableInfotblinfo[],intnumTables);
543544
externInhInfo*getInherits(int*numInherits);
544545
externvoidgetIndexes(TableInfotblinfo[],intnumTables);
545546
externvoidgetConstraints(TableInfotblinfo[],intnumTables);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp