londiste.subscriber_get_queue_valid_pending_fkeys: stricter check
authorMarko Kreen <markokr@gmail.com>
Fri, 30 Oct 2009 14:14:57 +0000 (14:14 +0000)
committerMarko Kreen <markokr@gmail.com>
Fri, 30 Oct 2009 14:14:57 +0000 (14:14 +0000)
Disallow automatic restore of fkey to unreplicated table.
Also to replicated table coming from other queue.

Otherwise there is possibility of restoring fk to unsynced table.

Based on report & patch by Hannu Krosing.

sql/londiste/functions/londiste.subscriber_fkeys_funcs.sql

index 3eda8d604841d1bf7cb845686c0556bfb9db3221..45331887eb6caa52e722691d30558a1f2fe5e225 100644 (file)
@@ -25,15 +25,14 @@ declare
     fkeys   record;
 begin
     for fkeys in
-        select pf.*
-        from londiste.subscriber_pending_fkeys pf
-             left join londiste.subscriber_table st_from on (st_from.table_name = pf.from_table)
-             left join londiste.subscriber_table st_to on (st_to.table_name = pf.to_table)
-        where (st_from.table_name is null or (st_from.merge_state = 'ok' and st_from.snapshot is null))
-          and (st_to.table_name is null or (st_to.merge_state = 'ok' and st_to.snapshot is null))
-          and (coalesce(st_from.queue_name = i_queue_name, false)
-               or coalesce(st_to.queue_name = i_queue_name, false))
-        order by 1, 2, 3
+        select pf.* from londiste.subscriber_pending_fkeys pf
+            join londiste.subscriber_table st_from 
+                on (st_from.table_name = pf.from_table and st_from.merge_state = 'ok' and st_from.snapshot is null)
+            join londiste.subscriber_table st_to   
+                on (st_to.table_name = pf.to_table and st_to.merge_state = 'ok' and st_to.snapshot is null)
+            -- change the AND to OR to allow fkeys between tables coming from different queues
+            where (st_from.queue_name = i_queue_name and st_to.queue_name = i_queue_name)
+            order by 1, 2, 3
     loop
         return next fkeys;
     end loop;