Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YKw6Q-0006Fm-KZ for pgsql-performance@arkaria.postgresql.org; Mon, 09 Feb 2015 21:42:46 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YKw6Q-0001Xv-00 for pgsql-performance@arkaria.postgresql.org; Mon, 09 Feb 2015 21:42:46 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YKw6O-0001Xm-Hy for pgsql-performance@postgresql.org; Mon, 09 Feb 2015 21:42:44 +0000 Received: from resqmta-ch2-02v.sys.comcast.net ([2001:558:fe21:29:69:252:207:34]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1YKw6K-0004ot-Rd for pgsql-performance@postgresql.org; Mon, 09 Feb 2015 21:42:42 +0000 Received: from resomta-ch2-07v.sys.comcast.net ([69.252.207.103]) by resqmta-ch2-02v.sys.comcast.net with comcast id qMif1p0032EPM3101Mif6u; Mon, 09 Feb 2015 21:42:39 +0000 Received: from jerry.enova.com ([12.30.159.20]) by resomta-ch2-07v.sys.comcast.net with comcast id qMiU1p00Q0ShjPw01MiWDe; Mon, 09 Feb 2015 21:42:37 +0000 Received: by jerry.enova.com (Postfix, from userid 1001) id 6E8C07401ED; Mon, 9 Feb 2015 15:42:28 -0600 (CST) From: Jerry Sievers To: Andreas Joseph Krogh Cc: pgsql-performance@postgresql.org Subject: Re: Poor performance when deleting from entity-attribute-value type master-table References: Date: Mon, 09 Feb 2015 15:42:28 -0600 In-Reply-To: (Andreas Joseph Krogh's message of "Mon, 9 Feb 2015 22:12:55 +0100 (CET)") Message-ID: <86wq3qyd6j.fsf@jerry.enova.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1423518159; bh=wBo41JXyXg8C5jV/AeCroWfUh5ps/Svod1LCq8Ap4AE=; h=Received:Received:Received:From:To:Subject:Date:Message-ID: MIME-Version:Content-Type; b=UHIIqXgjJExMfTBCZ+1RFu5A0lwDZsQazLWzaBCPBZM7UP+h/veaURWKmyxBOwftA I9KUq2X39ornL6yUTEgh4Xp0rprlAqGKEpAsf/M8T01B7bg4RCNe4mjITq7b6T57+g ig0MDP1cV5NpyvFzmabE1zS6mykOhHpnLrD8W3Sf3K8uvwmImvG+0wDjshFQz/QE2V 5VdXioCTMcSm/R7jj1mKMc2e1OcK9LiQdwaDke3DRI5Yn1eICe5DHgxY9q3wGEzK12 PL4lEuRuMjgaJD/bbyZ5rkp+0cz4XXeBn4xYRtz5mtfbfhD8/diHrgmxTKgQWrqj2c BCQEjG0uBraZw== X-Pg-Spam-Score: -1.5 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Andreas Joseph Krogh 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