Re: Poor performance when deleting from entity-attribute-value type master-table

From: Jerry Sievers <gsievers19(at)comcast(dot)net>
To: Andreas Joseph Krogh <andreas(at)visena(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Poor performance when deleting from entity-attribute-value type master-table
Date: 2015-02-09 21:42:28
Message-ID: 86wq3qyd6j.fsf@jerry.enova.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Andreas Joseph Krogh <andreas(at)visena(dot)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(at)visena(dot)com
> www.visena.com
> [cid]
>

--
Jerry Sievers
Postgres DBA/Development Consulting
e: postgres(dot)consulting(at)comcast(dot)net
p: 312.241.7800

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Andreas Joseph Krogh 2015-02-09 21:50:31 Re: Poor performance when deleting from entity-attribute-value type master-table
Previous Message Igor Neyman 2015-02-09 21:36:55 Re: Poor performance when deleting from entity-attribute-value type master-table