public inbox for [email protected]  
help / color / mirror / Atom feed
From: Tom Lane <[email protected]>
To: pgchem pgchem <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: C trigger significantly slower than PL/pgSQL?
Date: Thu, 13 Apr 2023 11:42:11 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>

pgchem pgchem <[email protected]> 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





view thread (9+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: C trigger significantly slower than PL/pgSQL?
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox