Re: Trigger performance problem - Mailing list pgsql-performance

From Tom Lane
Subject Re: Trigger performance problem
Date
Msg-id 705.1116352043@sss.pgh.pa.us
Whole thread Raw
In response to Trigger performance problem  ("Manuel Wenger" <manuel.wenger@ticinocom.com>)
List pgsql-performance
"Manuel Wenger" <manuel.wenger@ticinocom.com> writes:
> We're having a performance problem with PostgresQL 8.0.2 running on
> RHEL3 Update 4. There is a frequently updated table logging all our ADSL
> customer logins which has 2 related triggers. An INSERT on that table,
> "calls", takes about 300ms to execute according to the logs, and the
> process takes up to 30% of the server CPU. When removing the triggers it
> drops to 10-20ms.

You need to figure out exactly which operation(s) inside the triggers
is so expensive.  You could try removing commands one at a time and
timing the modified triggers.

Just on general principles, I'd guess that this might be the problem:

>     delete from currentip where ip is null;

Since an IS NULL test isn't indexable by a normal index, this is going
to cause a full scan of the currentip table every time.  I don't really
understand why you need that executed every time anyway ... why is it
this trigger's responsibility to clean out null IPs?  But if you really
do need to make that run quickly, you could create a partial index with
a WHERE clause of "ip is null".

            regards, tom lane

pgsql-performance by date:

Previous
From: "Manuel Wenger"
Date:
Subject: Trigger performance problem
Next
From: lists@boutiquenumerique.com
Date:
Subject: Re: Trigger performance problem