Re: improvements / reworks for FDW insert batching

From: Rui Zhao <zhaorui126(at)gmail(dot)com>
To: Tomas Vondra <tomas(at)vondra(dot)me>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: improvements / reworks for FDW insert batching
Date: 2026-12-01 12:46:21
Message-ID: CAHWVJhESKV-YPs4xCvPhn7hMxhBkvifFwW-73NVA_sHH-QqKaw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Zhijie Hou 2026-12-01 12:47:52 Re: Fix race between copying and dropping a replication slot
Previous Message Zhijie Hou 2026-12-01 12:35:43 Re: REPACK (CONCURRENTLY) fails during parallel build of exclusion constraint indexes