I found a regression in v1 with a disabled AFTER UPDATE trigger on a
partitioned table:

    -- "loop" is a postgres_fdw server pointing to this database.
    CREATE TABLE public.remote_rows (k int);
    CREATE TABLE parent (k int) PARTITION BY LIST (k);
    CREATE TABLE local_part PARTITION OF parent FOR VALUES IN (1);
    CREATE FOREIGN TABLE foreign_part PARTITION OF parent FOR VALUES IN (2)
      SERVER loop OPTIONS (schema_name 'public', table_name 'remote_rows',
                           batch_size '1');

    CREATE FUNCTION unexpected_update() RETURNS trigger LANGUAGE plpgsql AS
      $$ BEGIN RAISE EXCEPTION 'disabled trigger fired'; END; $$;
    CREATE TRIGGER log_update AFTER UPDATE ON parent
      REFERENCING NEW TABLE AS new_rows
      FOR EACH STATEMENT EXECUTE FUNCTION unexpected_update();
    ALTER TABLE parent DISABLE TRIGGER log_update;

    INSERT INTO parent VALUES (1), (1);
    UPDATE parent SET k = 2 WHERE k = 1;

    ALTER FOREIGN TABLE foreign_part OPTIONS (SET batch_size '10');
    UPDATE parent SET k = 2 WHERE k = 1;

With the trigger disabled in all four cases, I got these results:

                batch_size = 1    batch_size = 10
    master      ERROR             UPDATE 2
    v1          ERROR             ERROR

All three errors were:

    ERROR:  cannot collect transition tuples from child foreign tables

I think v1 is right to make batch_size = 1 and batch_size = 10 behave
the same way here. But if the only trigger that requests a NEW TABLE
is disabled, should the UPDATE succeed in both cases instead of
raising an error?

I tried skipping disabled triggers in SetTriggerFlags() and then in
MakeTransitionCaptureState() instead, but both approaches had side effects.

Do you think it's worth changing v1 so that a disabled trigger alone
doesn't make this UPDATE fail?

Regards,
Rui


Reply via email to