diff options
author | Tomas Vondra <tomas.vondra@postgresql.org> | 2022-03-17 17:03:45 +0100 |
---|---|---|
committer | Tomas Vondra <tomas.vondra@postgresql.org> | 2022-03-17 17:03:48 +0100 |
commit | 5a079662256e381fde699c4fbbed6c2504a6d30a (patch) | |
tree | 70bd035b005499f834f4bf071118e881f708559b /src/backend/replication/pgoutput/pgoutput.c | |
parent | a9b7e92084cdea1bd397ec26c3233206932f29c7 (diff) | |
download | postgresql-5a079662256e381fde699c4fbbed6c2504a6d30a.tar.gz postgresql-5a079662256e381fde699c4fbbed6c2504a6d30a.zip |
Fix row filters with multiple publications
When publishing changes through a artition root, we should use the row
filter for the top-most ancestor. The relation may be added to multiple
publications, using different ancestors, and 52e4f0cd47 handled this
incorrectly. With c91f71b9dc we find the correct top-most ancestor, but
the code tried to fetch the row filter from all publications, including
those using a different ancestor etc. No row filter can be found for
such publications, which was treated as replicating all rows.
Similarly to c91f71b9dc, this seems to be a rare issue in practice. It
requires multiple publications including the same partitioned relation,
through different ancestors.
Fixed by only passing publications containing the top-most ancestor to
pgoutput_row_filter_init(), so that treating a missing row filter as
replicating all rows is correct.
Report and fix by me, test case by Hou zj. Reviews and improvements by
Amit Kapila.
Author: Tomas Vondra, Hou zj, Amit Kapila
Reviewed-by: Amit Kapila, Hou zj
Discussion: https://postgr.es/m/d26d24dd-2fab-3c48-0162-2b7f84a9c893%40enterprisedb.com
Diffstat (limited to 'src/backend/replication/pgoutput/pgoutput.c')
-rw-r--r-- | src/backend/replication/pgoutput/pgoutput.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c index d869f3e93eb..5fddab3a3d4 100644 --- a/src/backend/replication/pgoutput/pgoutput.c +++ b/src/backend/replication/pgoutput/pgoutput.c @@ -1890,8 +1890,6 @@ get_rel_sync_entry(PGOutputData *data, Relation relation) entry->pubactions.pubdelete |= pub->pubactions.pubdelete; entry->pubactions.pubtruncate |= pub->pubactions.pubtruncate; - rel_publications = lappend(rel_publications, pub); - /* * We want to publish the changes as the top-most ancestor * across all publications. So we need to check if the @@ -1902,9 +1900,27 @@ get_rel_sync_entry(PGOutputData *data, Relation relation) if (publish_ancestor_level > ancestor_level) continue; - /* The new value is an ancestor, so let's keep it. */ - publish_as_relid = pub_relid; - publish_ancestor_level = ancestor_level; + /* + * If we found an ancestor higher up in the tree, discard + * the list of publications through which we replicate it, + * and use the new ancestor. + */ + if (publish_ancestor_level < ancestor_level) + { + publish_as_relid = pub_relid; + publish_ancestor_level = ancestor_level; + + /* reset the publication list for this relation */ + rel_publications = NIL; + } + else + { + /* Same ancestor level, has to be the same OID. */ + Assert(publish_as_relid == pub_relid); + } + + /* Track publications for this ancestor. */ + rel_publications = lappend(rel_publications, pub); } } |