Hi. During some ad-hoc filter testing I observed a quirk when there are duplicate tables. I think we need to define/implement some proper rules for this behaviour.
===== BACKGROUND When the same table appears multiple times in a CREATE PUBLICATION then those duplicates are simply ignored. The end result is that the table is only one time in the publication. This is fine and makes no difference where there are no row-filters (because the duplicates are all exactly the same as each other), but if there *are* row-filters there there is a quirky behaviour. ===== PROBLEM Apparently it is the *first* of the occurrences that is used and all the other duplicates are ignored. In practice it looks like this. ex.1) DROP PUBLICATION test_pub=# CREATE PUBLICATION p1 FOR TABLE t1 WHERE (a=1), t1 WHERE (a=2); CREATE PUBLICATION test_pub=# \dRp+ p1 Publication p1 Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root ----------+------------+---------+---------+---------+-----------+---------- postgres | f | t | t | t | t | f Tables: "public.t1" WHERE ((a = 1)) ** Notice that the 2nd filter (a=2) was ignored ~ IMO ex1 is wrong behaviour. I think that any subsequent duplicate table names should behave the same as if the CREATE was a combination of CREATE PUBLICATION then ALTER PUBLICATION SET. Like this: ex.2) test_pub=# CREATE PUBLICATION p1 FOR TABLE t1 WHERE (a=1); CREATE PUBLICATION test_pub=# ALTER PUBLICATION p1 SET TABLE t1 WHERE (a=2); ALTER PUBLICATION test_pub=# \dRp+ p1 Publication p1 Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root ----------+------------+---------+---------+---------+-----------+---------- postgres | f | t | t | t | t | f Tables: "public.t1" WHERE ((a = 2)) ** Notice that the 2nd filter (a=2) overwrites the 1st filter (a=1) as expected. ~~ The current behaviour of duplicates becomes even more "unexpected" if duplicate tables occur in a single ALTER PUBLICATION ... SET command. ex.3) test_pub=# CREATE PUBLICATION p1; CREATE PUBLICATION test_pub=# ALTER PUBLICATION p1 SET TABLE t1 WHERE (a=1), t1 WHERE (a=2); ALTER PUBLICATION test_pub=# \dRp+ p1 Publication p1 Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root ----------+------------+---------+---------+---------+-----------+---------- postgres | f | t | t | t | t | f Tables: "public.t1" WHERE ((a = 1)) ** Notice the 2nd filter (a=2) did not overwrite the 1st filter (a=1). I think a user would be quite surprised by this behaviour. ===== PROPOSAL I propose that we change the way duplicate tables are processed to make it so that it is always the *last* one that takes effect (instead of the *first* one). AFAIK doing this won't affect any current PG behaviour, but doing this will let the new row-filter feature work in a consistent/predictable/sane way. Thoughts? ------ Kind Regards, Peter Smith. Fujitsu Australia