public inbox for [email protected]
help / color / mirror / Atom feedFrom: Tom Lane <[email protected]>
To: MichaĆ Albrycht <[email protected]>
Cc: [email protected]
Subject: Re: Why plpython functions increase transaction counter much more then plpgsql functions?
Date: Fri, 08 Nov 2024 09:39:48 -0500
Message-ID: <[email protected]> (raw)
In-Reply-To: <CACsoHGCWgBJ4BKLtC=Q305WBEM+K2fj3BmzvEVYEGRg896QOYg@mail.gmail.com>
References: <CACsoHGCWgBJ4BKLtC=Q305WBEM+K2fj3BmzvEVYEGRg896QOYg@mail.gmail.com>
=?UTF-8?Q?Micha=C5=82_Albrycht?= <[email protected]> writes:
> This proves that the plpython function affects the transaction counter much
> more. Does anyone know why?
A quick look at PLy_spi_execute_query shows that it runs each command
in a subtransaction. It pretty much has to, because the coding rules
for a Python method don't permit it to just longjmp out of the Python
interpreter, so it has to set up a subtransaction so it can catch any
error. In this example, each subtransaction will consume an XID.
The plpgsql example is different because it doesn't trap errors,
hence no subtransaction needed, and all the rows will get inserted
under the XID of the outer command's main transaction. If you were
to wrap the insert_row_to_db call in BEGIN ... EXCEPTION then it'd
consume the same number of XIDs as plpython, for the same reason.
> Is there anything I can do about it?
Batch the DB updates, perhaps?
> What's interesting it happens only if the function called by plpyhon makes
> changes to DB.
Totally unsurprising. XIDs are acquired only when the current
transaction or subtransaction first needs to change the DB.
regards, tom lane
view thread (4+ 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], [email protected]
Subject: Re: Why plpython functions increase transaction counter much more then plpgsql functions?
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