mirror of
https://github.com/postgres/postgres.git
synced 2026-10-23 13:29:09 +03:00
pg_dump: Fix performance regression in attribute statistics query.
After adding pg_stats.tableid, we taught pg_dump to use it in the
attribute statistics query for servers running v19 or later.
Notably, we did not give this new form of the query a "redundant
filter clause" like we did the pre-v19 form. Testing indicates
that produces a significant performance regression, and that adding
a similar filter clause to the v19-or-later form of the query fixes
it.
Oversight in commit 4b5ba0c4ca.
Reviewed-by: Sami Imseih <samimseih@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/apQ9nvLW_zFdarYd%40nathan
Backpatch-through: 19
This commit is contained in:
@@ -11342,12 +11342,9 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te)
|
||||
/*
|
||||
* The results must be in the order of the relations supplied in the
|
||||
* parameters to ensure we remain in sync as we walk through the TOC.
|
||||
*
|
||||
* For v9.4 through v18, the redundant filter clause on s.tablename =
|
||||
* ANY(...) seems sufficient to convince the planner to use
|
||||
* pg_class_relname_nsp_index, which avoids a full scan of pg_stats.
|
||||
* In newer versions, pg_stats returns the table OIDs, eliminating the
|
||||
* need for that hack.
|
||||
* The redundant filter clause seems sufficient to convince the
|
||||
* planner to use pg_class_relname_nsp_index, which avoids a full scan
|
||||
* of pg_stats. This may not work for all versions.
|
||||
*
|
||||
* Our query for retrieving statistics for multiple relations uses
|
||||
* WITH ORDINALITY and multi-argument UNNEST(), both of which were
|
||||
@@ -11359,6 +11356,7 @@ dumpRelationStats_dumper(Archive *fout, const void *userArg, const TocEntry *te)
|
||||
"FROM pg_catalog.pg_stats s "
|
||||
"JOIN unnest($1) WITH ORDINALITY AS u (tableid, ord) "
|
||||
"ON s.tableid = u.tableid "
|
||||
"WHERE s.tableid = ANY($1) "
|
||||
"ORDER BY u.ord, s.attname, s.inherited");
|
||||
else if (fout->remoteVersion >= 90400)
|
||||
appendPQExpBufferStr(query,
|
||||
|
||||
Reference in New Issue
Block a user