diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 358ac1d390e..9cba2aae380 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -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,