pgchem pgchem <pgchem@tuschehund.de> writes:
> as requested, here is the C code:
> ...
> ret = SPI_execute("SELECT pg_backend_pid() = ANY((SELECT pid FROM pg_stat_activity WHERE backend_type = 'logical
replicationworker'))::boolean AS is_replicated", true, 1);
Yeah, there's your problem. Each time through the trigger, that query
is being parsed, planned, and executed from scratch. plpgsql knows
how to cache the planned statement, so it's doing less work per-call.
regards, tom lane