Skip site navigation (1) Skip section navigation (2)

pgsql: Eliminate O(N^2) behavior in parallel restore with many blobs.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Eliminate O(N^2) behavior in parallel restore with many blobs.
Date: 2010-12-09 18:04:55
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-committers
Eliminate O(N^2) behavior in parallel restore with many blobs.

With hundreds of thousands of TOC entries, the repeated searches in
reduce_dependencies() become the dominant cost.  Get rid of that searching
by constructing reverse-dependency lists, which we can do in O(N) time
during the fix_dependencies() preprocessing.  I chose to store the reverse
dependencies as DumpId arrays for consistency with the forward-dependency
representation, and keep the previously-transient tocsByDumpId[] array
around to locate actual TOC entry structs quickly from dump IDs.

While this fixes the slow case reported by Vlad Arkhipov, there is still
a potential for O(N^2) behavior with sufficiently many tables:
fix_dependencies itself, as well as mark_create_done and
inhibit_data_for_failed_table, are doing repeated searches to deal with
table-to-table-data dependencies.  Possibly this work could be extended
to deal with that, although the latter two functions are also used in
non-parallel restore where we currently don't run fix_dependencies.

Another TODO is that we fail to parallelize restore of multiple blobs
at all.  This appears to require changes in the archive format to fix.

Back-patch to 9.0 where the problem was reported.  8.4 has potential issues
as well; but since it doesn't create a separate TOC entry for each blob,
it's at much less risk of having enough TOC entries to cause real problems.



Modified Files
src/bin/pg_dump/pg_backup_archiver.c |  116 +++++++++++++++++++++------------
src/bin/pg_dump/pg_backup_archiver.h |    2 +
2 files changed, 76 insertions(+), 42 deletions(-)

pgsql-committers by date

Next:From: Simon RiggsDate: 2010-12-10 07:00:42
Subject: pgsql: Reduce spurious Hot Standby conflicts from never-visiblerecords
Previous:From: User HinoueDate: 2010-12-09 12:41:12
Subject: psqlodbc - psqlodbc: Change to read and skip the rest of result data

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group