Batch API for After Triggers

Поиск
Список
Период
Сортировка
От Simon Riggs
Тема Batch API for After Triggers
Дата
Msg-id CA+U5nM+D4+2kWgVCjQb9f5sPTWk+MD=29k_wpMvTJzUrMvebCw@mail.gmail.com
обсуждение исходный текст
Ответы Re: Batch API for After Triggers  (Kevin Grittner <kgrittn@ymail.com>)
Re: Batch API for After Triggers  (Stephen Frost <sfrost@snowman.net>)
Re: Batch API for After Triggers  (Robert Haas <robertmhaas@gmail.com>)
Список pgsql-hackers
While fiddling with FK tuning, Noah suggested batching trigger
executions together to avoid execution overhead.

It turns out there is no easy way to write triggers that can take
advantage of the knowledge that they are being executed as a set of
trigger executions. Some API is required to allow a trigger to
understand that there may be other related trigger executions in the
very near future, so it can attempt to amortise call overhead across
many invocations ("batching").

The attached patch adds two fields to the TriggerDesc trigger
functions are handed, allowing them to inspect (if they choose) the
additional fields and thus potentially use some form of batching.

This is backwards compatible with earlier trigger API.

Two fields are

int   tg_tot_num_events;
int   tg_event_num

So your trigger can work out it is e.g. number 3 of 56 invocations in
the current set of after triggers.

Going back to Noah's example, this would allow you to collect all 56
values and then execute a single statement with an array of 56 values
in it. Knowing there are 56 means you can wait until the 56th
invocation before executing the batched statement, without risking
skipping some checks because you've only got half a batch left.

If you don't do this, then you'd need to introduce the concept of a
"final function" similar to the way aggregates work. But that seems
much too complex to be real world useful.

This seemed a generally useful approach for any after trigger author,
not just for RI.

Comments please.

--
 Simon Riggs                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services

Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Greg Smith
Дата:
Сообщение: Re: Cost limited statements RFC
Следующее
От: Simon Riggs
Дата:
Сообщение: Re: Hard limit on WAL space used (because PANIC sucks)