pg.ddx.io pgsql-performance@postgresql.org mailing list archive
help / color / mirror / Atom feedPoor performance when deleting from entity-attribute-value type master-table
5+ messages / 4 participants
[nested] [flat]
* Poor performance when deleting from entity-attribute-value type master-table
@ 2015-02-09 21:12 Andreas Joseph Krogh <andreas@visena.com>
2015-02-09 21:36 ` Re: Poor performance when deleting from entity-attribute-value type master-table Igor Neyman <ineyman@perceptron.com>
2015-02-09 21:42 ` Re: Poor performance when deleting from entity-attribute-value type master-table Jerry Sievers <gsievers19@comcast.net>
2015-02-09 22:04 ` Re: Poor performance when deleting from entity-attribute-value type master-table Josh Berkus <josh@agliodbs.com>
0 siblings, 3 replies; 5+ messages in thread
From: Andreas Joseph Krogh @ 2015-02-09 21:12 UTC (permalink / raw)
To: pgsql-performance
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. Are there any ways around this or do people simply
avoid having FKs in schemas like this? Thanks. -- 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;
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Poor performance when deleting from entity-attribute-value type master-table
2015-02-09 21:12 Poor performance when deleting from entity-attribute-value type master-table Andreas Joseph Krogh <andreas@visena.com>
@ 2015-02-09 21:36 ` Igor Neyman <ineyman@perceptron.com>
2015-02-09 21:50 ` Re: Poor performance when deleting from entity-attribute-value type master-table Andreas Joseph Krogh <andreas@visena.com>
2 siblings, 1 reply; 5+ messages in thread
From: Igor Neyman @ 2015-02-09 21:36 UTC (permalink / raw)
To: Andreas Joseph Krogh <andreas@visena.com>; pgsql-performance
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.
Regards,
Igor Neyman
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Poor performance when deleting from entity-attribute-value type master-table
2015-02-09 21:12 Poor performance when deleting from entity-attribute-value type master-table Andreas Joseph Krogh <andreas@visena.com>
2015-02-09 21:36 ` Re: Poor performance when deleting from entity-attribute-value type master-table Igor Neyman <ineyman@perceptron.com>
@ 2015-02-09 21:50 ` Andreas Joseph Krogh <andreas@visena.com>
0 siblings, 0 replies; 5+ messages in thread
From: Andreas Joseph Krogh @ 2015-02-09 21:50 UTC (permalink / raw)
To: pgsql-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;
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Poor performance when deleting from entity-attribute-value type master-table
2015-02-09 21:12 Poor performance when deleting from entity-attribute-value type master-table Andreas Joseph Krogh <andreas@visena.com>
@ 2015-02-09 21:42 ` Jerry Sievers <gsievers19@comcast.net>
2 siblings, 0 replies; 5+ messages in thread
From: Jerry Sievers @ 2015-02-09 21:42 UTC (permalink / raw)
To: Andreas Joseph Krogh <andreas@visena.com>; +Cc: pgsql-performance
Andreas Joseph Krogh <andreas@visena.com> writes:
> 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.
>
> Are there any ways around this or do people simply avoid having FKs in schemas like this?
The classic problem is that one/more of your referring tables is
non-trivial in size and you are missing an index on the referring column(s).
Insure that this condition does not exist before butchering your design :-)
> Thanks.
>
> --
> Andreas Joseph Krogh
> CTO / Partner - Visena AS
> Mobile: +47 909 56 963
> andreas@visena.com
> www.visena.com
> [cid]
>
--
Jerry Sievers
Postgres DBA/Development Consulting
e: postgres.consulting@comcast.net
p: 312.241.7800
--
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Poor performance when deleting from entity-attribute-value type master-table
2015-02-09 21:12 Poor performance when deleting from entity-attribute-value type master-table Andreas Joseph Krogh <andreas@visena.com>
@ 2015-02-09 22:04 ` Josh Berkus <josh@agliodbs.com>
2 siblings, 0 replies; 5+ messages in thread
From: Josh Berkus @ 2015-02-09 22:04 UTC (permalink / raw)
To: Andreas Joseph Krogh <andreas@visena.com>; pgsql-performance
On 02/09/2015 01:12 PM, Andreas Joseph Krogh wrote:
> Are there any ways around this or do people simply avoid having FKs in
> schemas like this?
Don't use EAV. It's a bad design pattern, especially for you, and
you've just discovered one of the reasons why.
(In fact, I am just today dismantling an EAV database and normalizing
it, and so far application throughput is up 500%)
--
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com
--
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2015-02-09 22:04 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-02-09 21:12 Poor performance when deleting from entity-attribute-value type master-table Andreas Joseph Krogh <andreas@visena.com>
2015-02-09 21:36 ` Igor Neyman <ineyman@perceptron.com>
2015-02-09 21:50 ` Andreas Joseph Krogh <andreas@visena.com>
2015-02-09 21:42 ` Jerry Sievers <gsievers19@comcast.net>
2015-02-09 22:04 ` Josh Berkus <josh@agliodbs.com>
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