Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YXabX-0004W5-I6 for pgsql-performance@arkaria.postgresql.org; Mon, 16 Mar 2015 19:23:11 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YXabW-0000Xx-TO for pgsql-performance@arkaria.postgresql.org; Mon, 16 Mar 2015 19:23:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YXabW-0000Xr-1P for pgsql-performance@postgresql.org; Mon, 16 Mar 2015 19:23:10 +0000 Received: from mail-bl2on0647.outbound.protection.outlook.com ([2a01:111:f400:fc09::647] helo=na01-bl2-obe.outbound.protection.outlook.com) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YXabM-0004ND-9Q for pgsql-performance@postgresql.org; Mon, 16 Mar 2015 19:23:08 +0000 Received: from decina.attlocal.net (2602:306:ce8b:3460:bc26:f347:3a6e:b9f2) by DM2PR11MB0350.namprd11.prod.outlook.com (25.160.136.156) with Microsoft SMTP Server (TLS) id 15.1.112.19; Mon, 16 Mar 2015 19:22:49 +0000 Message-ID: <55072D9F.40808@BlueTreble.com> Date: Mon, 16 Mar 2015 14:23:11 -0500 From: Jim Nasby User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Tom Lane , Gunnlaugur Thor Briem CC: Tomas Vondra , Jeff Janes , Kevin Grittner , "pgsql-performance@postgresql.org" Subject: Re: EXPLAIN (no ANALYZE) taking an hour for INSERT FROM SELECT References: <54F9E179.4000804@2ndquadrant.com> <1407502480.21180.1425691482543.JavaMail.yahoo@mail.yahoo.com> <27245.1425692294@sss.pgh.pa.us> <54FB1CDA.1080606@2ndquadrant.com> <17467.1426090533@sss.pgh.pa.us> In-Reply-To: <17467.1426090533@sss.pgh.pa.us> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [2602:306:ce8b:3460:bc26:f347:3a6e:b9f2] X-ClientProxiedBy: BN1PR12CA0013.namprd12.prod.outlook.com (25.160.77.23) To DM2PR11MB0350.namprd11.prod.outlook.com (25.160.136.156) Authentication-Results: postgresql.org; dkim=none (message not signed) header.d=none; X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR11MB0350; X-Forefront-Antispam-Report: BMV:1; SFV:NSPM; SFS:(10009020)(6009001)(24454002)(51704005)(377454003)(479174004)(51444003)(54356999)(36756003)(92566002)(42186005)(65956001)(65806001)(23746002)(50986999)(122386002)(86362001)(47776003)(19580405001)(2950100001)(77156002)(19580395003)(87976001)(50466002)(53416004)(551934003)(40100003)(15975445007)(83506001)(33656002)(62966003)(46102003)(93886004)(3826002)(217873001)(85282002)(18886065003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR11MB0350; H:decina.attlocal.net; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5002010)(5005006); SRVR:DM2PR11MB0350; BCL:0; PCL:0; RULEID:; SRVR:DM2PR11MB0350; X-Forefront-PRVS: 05177D47DC X-OriginatorOrg: bluetreble.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Mar 2015 19:22:49.4932 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR11MB0350 X-Pg-Spam-Score: -1.9 (-) 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 On 3/11/15 11:15 AM, Tom Lane wrote: > Gunnlaugur Thor Briem writes: >> Yes, I think that's it: I've just realized that immediately prior to the >> INSERT, in the same transaction, an unfiltered DELETE has been issued; i.e. >> the whole table is being rewritten. Then the INSERT is issued ... with a >> WHERE clause on non-existence in the (now empty) table. > >> In that case of course the WHERE clause is unnecessary, as it will always >> evaluate as true (and we've locked the whole table for writes). Looks like >> it is a lot worse than unnecessary, though, if it triggers this performance >> snafu in EXPLAIN INSERT. > > Ah-hah. So what's happening is that the planner is doing an indexscan > over the entire table of now-dead rows, looking vainly for an undeleted > maximal row. Ouch. > > I wonder how hard it would be to make the indexscan give up after hitting > N consecutive dead rows, for some suitable N, maybe ~1000. From the > planner's viewpoint it'd be easy enough to fall back to using whatever > it had in the histogram after all. But that's all happening down inside > index_getnext, and I'm hesitant to stick some kind of wart into that > machinery for this purpose. ISTM what we really want here is a time-based behavior, not number of rows. Given that, could we do the index probe in a subtransaction, set an alarm for X ms, and simply abort the subtransaction if the alarm fires? -- Jim Nasby, Data Architect, Blue Treble Consulting Data in Trouble? Get it in Treble! http://BlueTreble.com -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance