Re: Linear slow-down while inserting into a table with an ON INSERT trigger ?

From: Tobias Gierke <tobias(dot)gierke(at)code-sourcery(dot)de>
To: David Rowley <dgrowleyml(at)gmail(dot)com>, Justin Pryzby <pryzby(at)telsasoft(dot)com>
Cc: pgsql-performance <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Linear slow-down while inserting into a table with an ON INSERT trigger ?
Date: 2021-07-18 07:25:19
Message-ID: 9f2df5fb-50a4-fefd-810a-d3b915717190@code-sourcery.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Great idea ! This brought the time per INSERT into the parent table down
to a consistent ~0.065ms again (compared to 0.05ms when completely
removing the trigger, so penalty for the trigger is roughly ~20%).

> On Sat, 17 Jul 2021 at 16:40, Justin Pryzby <pryzby(at)telsasoft(dot)com> wrote:
>> You could run a single UPDATE rather than 30k triggers.
>> Or switch to an INSERT on the table, with an index on it, and call
>> max(last_parent_table_change) from whatever needs to ingest it. And prune the
>> old entries and vacuum it outside the transaction. Maybe someone else will
>> have a better suggestion.
> Maybe just change the UPDATE statement to:
>
> UPDATE data_sync SET last_parent_table_change=CURRENT_TIMESTAMP WHERE
> last_parent_table_change <> CURRENT_TIMESTAMP;
>
> That should reduce the number of actual updates to 1 per transaction.
>
> David

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Tobias Gierke 2021-07-18 07:36:33 Re: Linear slow-down while inserting into a table with an ON INSERT trigger ?
Previous Message Tobias Gierke 2021-07-18 07:19:00 Re: Linear slow-down while inserting into a table with an ON INSERT trigger ?