Skip to content

Commit be85727

Browse files
committed
Use PREPARE/EXECUTE for repetitive per-object queries in pg_dump.
For objects such as functions, pg_dump issues the same secondary data-collection query against each object to be dumped. This can't readily be refactored to avoid the repetitive queries, but we can PREPARE these queries to reduce planning costs. This patch applies the idea to functions, aggregates, operators, and data types. While it could be carried further, the remaining sorts of objects aren't likely to appear in typical databases enough times to be worth worrying over. Moreover, doing the PREPARE is likely to be a net loss if there aren't at least some dozens of objects to apply the prepared query to. Discussion: https://postgr.es/m/7d7eb6128f40401d81b3b7a898b6b4de@W2012-02.nidsa.loc
1 parent 9895961 commit be85727

File tree

2 files changed

+532
-366
lines changed

2 files changed

+532
-366
lines changed

src/bin/pg_dump/pg_backup.h

+20
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,23 @@ typedef enum _teSection
5858
SECTION_POST_DATA /* stuff to be processed after data */
5959
} teSection;
6060

61+
/* We need one enum entry per prepared query in pg_dump */
62+
enum _dumpPreparedQueries
63+
{
64+
PREPQUERY_DUMPAGG,
65+
PREPQUERY_DUMPBASETYPE,
66+
PREPQUERY_DUMPCOMPOSITETYPE,
67+
PREPQUERY_DUMPDOMAIN,
68+
PREPQUERY_DUMPENUMTYPE,
69+
PREPQUERY_DUMPFUNC,
70+
PREPQUERY_DUMPOPR,
71+
PREPQUERY_DUMPRANGETYPE,
72+
PREPQUERY_DUMPTABLEATTACH,
73+
PREPQUERY_GETCOLUMNACLS,
74+
PREPQUERY_GETDOMAINCONSTRAINTS,
75+
NUM_PREP_QUERIES /* must be last */
76+
};
77+
6178
/* Parameters needed by ConnectDatabase; same for dump and restore */
6279
typedef struct _connParams
6380
{
@@ -214,6 +231,9 @@ typedef struct Archive
214231
bool exit_on_error; /* whether to exit on SQL errors... */
215232
int n_errors; /* number of errors (if no die) */
216233

234+
/* prepared-query status */
235+
bool *is_prepared; /* indexed by enum _dumpPreparedQueries */
236+
217237
/* The rest is private */
218238
} Archive;
219239

0 commit comments

Comments
 (0)