Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bjSQd-0001rY-FC for pgsql-performance@arkaria.postgresql.org; Mon, 12 Sep 2016 14:41:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bjSQc-0004c3-Rg for pgsql-performance@arkaria.postgresql.org; Mon, 12 Sep 2016 14:41:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bjSQc-0004bu-Aa for pgsql-performance@postgresql.org; Mon, 12 Sep 2016 14:41:46 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bjSQV-0005B0-4L for pgsql-performance@postgresql.org; Mon, 12 Sep 2016 14:41:44 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u8CEfZIl025257; Mon, 12 Sep 2016 10:41:35 -0400 From: Tom Lane To: phb07 cc: pgsql-performance@postgresql.org Subject: Re: Strange nested loop for an INSERT In-reply-to: <1f22a3fa-dcc5-eeac-a708-7f10fada4674@apra.asso.fr> References: <1f22a3fa-dcc5-eeac-a708-7f10fada4674@apra.asso.fr> Comments: In-reply-to phb07 message dated "Mon, 12 Sep 2016 16:15:05 +0200" Date: Mon, 12 Sep 2016 10:41:35 -0400 Message-ID: <25256.1473691295@sss.pgh.pa.us> X-Pg-Spam-Score: -4.1 (----) 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 phb07 writes: > The performance issue, encountered in very specific situations, is the > time needed to cancel a significant number of insertions. > I have build a simple test case that reproduces the problem without the > need of the extension. It just mimics the behaviour. At least for this example, the problem is that the DELETE enormously alters the statistics for the t1_log.tuple column (going from 100% "NEW" to 50% "NEW" and 50% "OLD"), but the plan for your last command is generated with stats saying there are no "OLD" entries. So you get a plan that would be fast for small numbers of "OLD" entries, but it sucks when there are lots of them. The fix I would recommend is to do a manual "ANALYZE t1_log" after such a large data change. Auto-ANALYZE would fix it for you after a minute or so, probably, but if your script doesn't want to wait around then an extra ANALYZE is the ticket. regards, tom lane -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance