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

Commit0d8117a

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 parentc252a17 commit0d8117a

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
@@ -114,6 +114,9 @@ getSchemaData(Archive *fout, int *numTablesPtr)
114114
tblinfo=getTables(fout,&numTables);
115115
tblinfoindex=buildIndexArray(tblinfo,numTables,sizeof(TableInfo));
116116

117+
/* Do this after we've built tblinfoindex */
118+
getOwnedSeqs(fout,tblinfo,numTables);
119+
117120
if (g_verbose)
118121
write_msg(NULL,"reading extensions\n");
119122
extinfo=getExtensions(fout,&numExtensions);

‎src/bin/pg_dump/pg_dump.c

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

43084308
PQclear(res);
43094309

4310+
destroyPQExpBuffer(query);
4311+
4312+
returntblinfo;
4313+
}
4314+
4315+
/*
4316+
* getOwnedSeqs
4317+
* identify owned sequences and mark them as dumpable if owning table is
4318+
*
4319+
* We used to do this in getTables(), but it's better to do it after the
4320+
* index used by findTableByOid() has been set up.
4321+
*/
4322+
void
4323+
getOwnedSeqs(Archive*fout,TableInfotblinfo[],intnumTables)
4324+
{
4325+
inti;
4326+
43104327
/*
43114328
* Force sequences that are "owned" by table columns to be dumped whenever
43124329
* their owning table is being dumped.
43134330
*/
4314-
for (i=0;i<ntups;i++)
4331+
for (i=0;i<numTables;i++)
43154332
{
43164333
TableInfo*seqinfo=&tblinfo[i];
4317-
intj;
4334+
TableInfo*owning_tab;
43184335

43194336
if (!OidIsValid(seqinfo->owning_tab))
43204337
continue;/* not an owned sequence */
43214338
if (seqinfo->dobj.dump)
43224339
continue;/* no need to search */
4323-
4324-
/* can't use findTableByOid yet, unfortunately */
4325-
for (j=0;j<ntups;j++)
4340+
owning_tab=findTableByOid(seqinfo->owning_tab);
4341+
if (owning_tab&&owning_tab->dobj.dump)
43264342
{
4327-
if (tblinfo[j].dobj.catId.oid==seqinfo->owning_tab)
4328-
{
4329-
if (tblinfo[j].dobj.dump)
4330-
{
4331-
seqinfo->interesting= true;
4332-
seqinfo->dobj.dump= true;
4333-
}
4334-
break;
4335-
}
4343+
seqinfo->interesting= true;
4344+
seqinfo->dobj.dump= true;
43364345
}
43374346
}
4338-
4339-
destroyPQExpBuffer(query);
4340-
4341-
returntblinfo;
43424347
}
43434348

43444349
/*

‎src/bin/pg_dump/pg_dump.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ extern OpfamilyInfo *getOpfamilies(Archive *fout, int *numOpfamilies);
538538
externCollInfo*getCollations(Archive*fout,int*numCollations);
539539
externConvInfo*getConversions(Archive*fout,int*numConversions);
540540
externTableInfo*getTables(Archive*fout,int*numTables);
541+
externvoidgetOwnedSeqs(Archive*fout,TableInfotblinfo[],intnumTables);
541542
externInhInfo*getInherits(Archive*fout,int*numInherits);
542543
externvoidgetIndexes(Archive*fout,TableInfotblinfo[],intnumTables);
543544
externvoidgetConstraints(Archive*fout,TableInfotblinfo[],intnumTables);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp