pgsql: Avoid per-object queries in performance-critical paths in pg_dum - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Avoid per-object queries in performance-critical paths in pg_dum
Date
Msg-id E1muIe0-0007N0-Qc@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Avoid per-object queries in performance-critical paths in pg_dump.

Instead of issuing a secondary data-collection query against each
table to be dumped, issue just one query, with a WHERE clause
restricting it to be applied to only the tables we intend to dump.
Likewise for indexes, constraints, and triggers.  This greatly
reduces the number of queries needed to dump a database containing
many tables.  It might seem that WHERE clauses listing many target
OIDs could be inefficient, but at least on recent server versions
this provides a very substantial speedup.

(In principle the same thing could be done with other object types
such as functions; but that would require significant refactoring
of pg_dump, so those will be tackled in a different way in a
following patch.)

The new WHERE clauses depend on the unnest() function, which is
only present in 8.4 and above.  We could implement them differently
for older servers, but there is an ongoing discussion that will
probably result in dropping pg_dump support for servers before 9.2,
so that seems like it'd be wasted work.  For now, just bump the
server version check to require >= 8.4, without stopping to remove
any of the code that's thereby rendered dead.  We'll mop that
situation up soon.

Patch by me, based on an idea from Andres Freund.

Discussion: https://postgr.es/m/7d7eb6128f40401d81b3b7a898b6b4de@W2012-02.nidsa.loc

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/9895961529ef8ff3fc12b39229f9a93e08bca7b7

Modified Files
--------------
src/bin/pg_dump/pg_dump.c    | 1772 ++++++++++++++++++++++++------------------
src/bin/pg_dump/pg_dumpall.c |    4 +-
2 files changed, 1012 insertions(+), 764 deletions(-)


pgsql-committers by date:

Previous
From: Peter Eisentraut
Date:
Subject: pgsql: Fix inappropriate uses of PG_GETARG_UINT32()
Next
From: Peter Eisentraut
Date:
Subject: pgsql: Update snowball