mirror of
https://github.com/postgres/postgres.git
synced 2025-12-10 14:22:35 +03:00
Fix O(N^2) performance issue in pg_publication_tables view.
The original coding of this view relied on a correlated IN sub-query. Our planner is not very bright about correlated sub-queries, and even if it were, there's no way for it to know that the output of pg_get_publication_tables() is duplicate-free, making the de-duplicating semantics of IN unnecessary. Hence, rewrite as a LATERAL sub-query. This provides circa 100X speedup for me with a few hundred published tables (the whole regression database), and things would degrade as roughly O(published_relations * all_relations) beyond that. Because the rules.out expected output changes, force a catversion bump. Ordinarily we might not want to do that post-beta1; but we already know we'll be doing a catversion bump before beta2 to fix pg_statistic_ext issues, so it's pretty much free to fix it now instead of waiting for v13. Per report and fix suggestion from PegoraroF10. Discussion: https://postgr.es/m/1551385426763-0.post@n3.nabble.com
This commit is contained in:
@@ -1441,10 +1441,10 @@ pg_publication_tables| SELECT p.pubname,
|
||||
n.nspname AS schemaname,
|
||||
c.relname AS tablename
|
||||
FROM pg_publication p,
|
||||
LATERAL pg_get_publication_tables((p.pubname)::text) gpt(relid),
|
||||
(pg_class c
|
||||
JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
|
||||
WHERE (c.oid IN ( SELECT pg_get_publication_tables.relid
|
||||
FROM pg_get_publication_tables((p.pubname)::text) pg_get_publication_tables(relid)));
|
||||
WHERE (c.oid = gpt.relid);
|
||||
pg_replication_origin_status| SELECT pg_show_replication_origin_status.local_id,
|
||||
pg_show_replication_origin_status.external_id,
|
||||
pg_show_replication_origin_status.remote_lsn,
|
||||
|
||||
Reference in New Issue
Block a user