Re: C trigger significantly slower than PL/pgSQL?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgchem pgchem <pgchem(at)tuschehund(dot)de>
Cc: "pgsql-interfaces(at)postgresql(dot)org" <pgsql-interfaces(at)postgresql(dot)org>
Subject: Re: C trigger significantly slower than PL/pgSQL?
Date: 2023-04-13 15:42:11
Message-ID: 1342580.1681400531@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

pgchem pgchem <pgchem(at)tuschehund(dot)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 replication worker'))::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

In response to

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Ernst-Georg Schmid 2023-04-14 17:39:20 Re: C trigger significantly slower than PL/pgSQL?
Previous Message pgchem pgchem 2023-04-13 09:31:27 Re: C trigger significantly slower than PL/pgSQL?