Re: [PATCH] Hooks at XactCommand level - Mailing list pgsql-hackers

From Gilles Darold
Subject Re: [PATCH] Hooks at XactCommand level
Date
Msg-id b727cc11-982a-e9c9-5321-e0e7fe45fa68@darold.net
Whole thread Raw
In response to Re: [PATCH] Hooks at XactCommand level  (Gilles Darold <gilles@darold.net>)
Responses Re: [PATCH] Hooks at XactCommand level  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hi,


I have renamed the patch and the title of this proposal registered in
the commitfest "Xact/SubXact event callback at command start" to reflect
the last changes that do not include new hooks anymore.


Here is the new description corresponding to the current patch.


This patch allow to execute user-defined code for the start of any
command through a xact registered callback. It introduce two new events
in XactEvent and SubXactEvent enum called respectively
XACT_EVENT_COMMAND_START and SUBXACT_EVENT_COMMAND_START. The callback
is not called if a transaction is not started.


The objective of this new callback is to be able to call user-defined
code before any new statement is executed. For example it can call a
rollback to savepoint if there was an error in the previous transaction
statement, which allow to implements Rollback at Statement Level at
server side using a PostgreSQL extension, see [1] .


The patch compile and regressions tests with assert enabled passed
successfully.

There is no regression test for this feature but extension at [1] has
been used for validation of the new callback.


The patch adds insignificant overhead by looking at an existing callback
definition but clearly it is the responsibility to the developer to
evaluate the performances impact of its user-defined code for this
callback as it will be called before each statement. Here is a very
simple test using pgbench -c 20 -j 8 -T 30

     tps = 669.930274 (without user-defined code)
     tps = 640.718361 (with user-defined code from extension [1])

the overhead for this extension is around 4.5% which I think is not so
bad good for such feature (internally it adds calls to RELEASE +
SAVEPOINT before each write statement execution and in case of error a
ROLLBACK TO savepoint).


[1] https://github.com/darold/pg_statement_rollbackv2

--
Gilles Darold
http://www.darold.net/


Attachment

pgsql-hackers by date:

Previous
From: Daniil Zakhlystov
Date:
Subject: Re: libpq compression
Next
From: Peter Eisentraut
Date:
Subject: Re: [PATCH] Partial foreign key updates in referential integrity triggers