postgresql/src
Tomas Vondra c91f71b9dc Fix publish_as_relid with multiple publications
Commit 83fd4532a7 allowed publishing of changes via ancestors, for
publications defined with publish_via_partition_root. But the way
the ancestor was determined in get_rel_sync_entry() was incorrect,
simply updating the same variable. So with multiple publications,
replicating different ancestors, the outcome depended on the order
of publications in the list - the value from the last loop was used,
even if it wasn't the top-most ancestor.

This is a probably rare situation, as in most cases publications do
not overlap, so each partition has exactly one candidate ancestor
to replicate as and there's no ambiguity.

Fixed by tracking the "ancestor level" for each publication, and
picking the top-most ancestor. Adds a test case, verifying the
correct ancestor is used for publishing the changes and that this
does not depend on order of publications in the list.

Older releases have another bug in this loop - once all actions are
replicated, the loop is terminated, on the assumption that inspecting
additional publications is unecessary. But that misses the fact that
those additional applications may replicate different ancestors.

Fixed by removal of this break condition. We might still terminate the
loop in some cases (e.g. when replicating all actions and the ancestor
is the partition root).

Backpatch to 13, where publish_via_partition_root was introduced.

Initial report and fix by me, test added 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
2022-03-16 18:05:58 +01:00
..
backend Fix publish_as_relid with multiple publications 2022-03-16 18:05:58 +01:00
bin Change HAVE_LIBLZ4 and HAVE_LIBZSTD tests to USE_LZ4 and USE_ZSTD. 2022-03-15 13:06:25 -04:00
common Use bitwise rotate functions in more places 2022-02-20 13:22:08 +07:00
fe_utils Clean up assorted failures under clang's -fsanitize=undefined checks. 2022-03-03 18:13:24 -05:00
include Fix publish_as_relid with multiple publications 2022-03-16 18:05:58 +01:00
interfaces Fix collection of typos in the code and the documentation 2022-03-15 11:29:35 +09:00
makefiles
pl plpython: Restore alternative output for plpython_error test. 2022-03-08 10:34:06 -08:00
port Simplify coding around path_contains_parent_reference(). 2022-01-31 13:53:38 -05:00
template
test Fix publish_as_relid with multiple publications 2022-03-16 18:05:58 +01:00
timezone
tools dshash: Add sequential scan support. 2022-03-10 12:57:05 -08:00
tutorial
.gitignore
DEVELOPERS
Makefile
Makefile.global.in Run tap tests in src/interfaces/libpq. 2022-02-26 16:51:47 -08:00
Makefile.shlib
nls-global.mk