On 2019-12-14 03:13, Euler Taveira wrote:
> Using the regression test example, table tab_fk_ref have columns id
> and bid. If you add a trigger "BEFORE UPDATE OF bid" into subscriber
> that fires on replica, it will always fire even if you are **not**
> changed bid in publisher. In logical replication protocol all columns
> were changed unless it is a (unchanged) TOAST column (if a column is
> part of the PK/REPLICA IDENTITY we can compare both values and figure
> out if the value changed, however, we can't ensure that a value
> changed for the other columns -- those that are not PK/REPLICA
> IDENTITY). It is clear that not firing the trigger is wrong but firing
> it when you say that you won't fire it is also wrong. Whichever
> behavior we choose, limitation should be documented. I prefer the
> behavior that ignores "OF col1" and always fire the trigger (because
> we can add a filter inside the function/procedure).
There is a small difference: If the subscriber has extra columns not
present on the publisher, then a column trigger covering only columns in
published column set will not fire.
In practice, a column trigger is just an optimization. The column it is
triggering on might not have actually changed. The opposite is worse,
not firing the trigger when the column actually has changed.
> + /* Populate updatedCols for trigger manager */
> Add a comment that explains it is not possible to (always) determine
> if a column changed. Hence, "OF col1" syntax will be ignored.
done
> + for (int i = 0; i < remoteslot->tts_tupleDescriptor->natts; i++)
> + {
> + RangeTblEntry *target_rte = list_nth(estate->es_range_table, 0);
> +
> It should be outside the loop.
fixed
> + if (newtup.changed)
> It should be newtup.changed[i].
fixed
> You should add a test that exposes "ignore OF col1" such as:
>
> $node_publisher->safe_psql('postgres',
> "UPDATE tab_fk_ref SET id = 6 WHERE id = 1;");
done
New patch attached.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services