From: Andreas Joseph Krogh <andreas@visena.com>
To: pgsql-performance@postgresql.org
Subject: Re: Poor performance when deleting from entity-attribute-value type master-table
Date: Mon, 9 Feb 2015 22:50:31 +0100 (CET)
Message-ID: <VisenaEmail.71.c67d5354b8430fbc.14b704873bd@tc7-visena> (raw)
In-Reply-To: <A76B25F2823E954C9E45E32FA49D70ECC229EC97@mail.corp.perceptron.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>
På mandag 09. februar 2015 kl. 22:36:55, skrev Igor Neyman <
ineyman@perceptron.com <mailto:ineyman@perceptron.com>>:
From: pgsql-performance-owner@postgresql.org
[mailto:pgsql-performance-owner@postgresql.org]On Behalf Of Andreas Joseph Krogh
Sent: Monday, February 09, 2015 4:13 PM
To: pgsql-performance@postgresql.org
Subject: [PERFORM] Poor performance when deleting from entity-attribute-value
type master-table
Hi all.
Using PG-9.4.0 I'm seeing this trying to delete from an "entity"-master table:
*# explain analyze delete from onp_crm_entity where entity_id IN (select
tmp.delivery_id from temp_delete_delivery_id tmp);
QUERY
PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------
Delete on onp_crm_entity (cost=0.43..5673.40 rows=1770 width=12) (actual
time=7.370..7.370 rows=0 loops=1)
-> Nested Loop (cost=0.43..5673.40 rows=1770 width=12) (actual
time=0.050..1.374 rows=108 loops=1)
-> Seq Scan on temp_delete_delivery_id tmp (cost=0.00..27.70
rows=1770 width=14) (actual time=0.014..0.080 rows=108 loops=1)
-> Index Scan using onp_crm_entity_pkey on onp_crm_entity
(cost=0.43..3.18 rows=1 width=14) (actual time=0.010..0.011 rows=1 loops=108)
Index Cond: (entity_id = tmp.delivery_id)
Planning time: 0.314 ms
Trigger for constraint onp_crm_activity_entity_id_fkey: time=4.141 calls=108
Trigger for constraint ...
Trigger for constraint ...
Trigger for constraint ...
I have lots of tables referencing onp_crm_entity(entity_id) so I expect the
poor performance of deleting from it is caused by all the triggers firing to
check FKI-constraints.
Andreas, do you have indexes on FK columns in child tables?
If not – there is your problem.
Yes, they have indexes, but deleting 1M rows still results in calling the
triggers 1M times * number of FKs... -- Andreas Joseph Krogh CTO / Partner -
Visena AS Mobile: +47 909 56 963 andreas@visena.com <mailto:andreas@visena.com>
www.visena.com <https://www.visena.com; <https://www.visena.com;
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: pgsql-performance@postgresql.org
Cc: andreas@visena.com
Subject: Re: Poor performance when deleting from entity-attribute-value type master-table
In-Reply-To: <VisenaEmail.71.c67d5354b8430fbc.14b704873bd@tc7-visena>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox