Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UoEVw-0001zK-5B for pgsql-performance@arkaria.postgresql.org; Sun, 16 Jun 2013 15:05:08 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1UoEVv-0000bp-8S for pgsql-performance@arkaria.postgresql.org; Sun, 16 Jun 2013 15:05:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UoEVu-0000bH-Ch for pgsql-performance@postgresql.org; Sun, 16 Jun 2013 15:05:06 +0000 Received: from smtp-outbound-1.vmware.com ([208.91.2.12]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UoEVp-0001hC-4w for pgsql-performance@postgresql.org; Sun, 16 Jun 2013 15:05:04 +0000 Received: from sc9-mailhost2.vmware.com (sc9-mailhost2.vmware.com [10.113.161.72]) by smtp-outbound-1.vmware.com (Postfix) with ESMTP id 1D90828B47; Sun, 16 Jun 2013 08:04:57 -0700 (PDT) Received: from zcs-prod-ext-mta-1.vmware.com (zcs-prod-ext-mta-1.vmware.com [10.113.62.223]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 1AC8AB05CC; Sun, 16 Jun 2013 08:04:57 -0700 (PDT) Received: from zcs-prod-ext-mta-1.vmware.com (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-1.vmware.com (Postfix) with ESMTP id 9B79412002A; Sun, 16 Jun 2013 08:10:53 -0700 (PDT) Received: from [192.168.1.90] (zimbra-prod-ext-proxy-vip.vmware.com [10.113.63.87]) by zcs-prod-ext-mta-1.vmware.com (Postfix) with ESMTPSA; Sun, 16 Jun 2013 08:10:52 -0700 (PDT) Message-ID: <51BDD415.4050506@vmware.com> Date: Sun, 16 Jun 2013 18:04:53 +0300 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20130116 Icedove/10.0.12 MIME-Version: 1.0 To: Simon Riggs CC: Mark Kirkwood , Tom Lane , Gavin Flower , "pgsql-performance@postgresql.org" Subject: Re: In progress INSERT wrecks plans on table References: <5179E77B.7050601@catalyst.net.nz> <5179ECC5.2010206@archidevsys.co.nz> <5179F259.3010509@catalyst.net.nz> <5179F5C6.8070702@archidevsys.co.nz> <5180E3C8.3010201@catalyst.net.nz> <2121.1367417215@sss.pgh.pa.us> <5181B80D.70404@catalyst.net.nz> <916bff05a5ab130c76d7835abbaf7762.squirrel@mail.catalyst.net.nz> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -8.0 (--------) 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 03.05.2013 15:41, Simon Riggs wrote: > What appears to be happening is we're spending a lot of time in > TransactionIdIsInProgress() so we can set hints and then when we find > it is still in progress we then spend more time in XidIsInSnapshot() > while we check that it is still invisible to us. Even if the > transaction we see repeatedly ends, we will still pay the cost in > XidIsInSnapshot repeatedly as we execute. > > Given that code path, I would expect it to suck worse on a live system > with many sessions, and even worse with many subtransactions. > > (1) A proposed fix is attached, but its only a partial one and barely tested. > > Deeper fixes might be > > (2) to sort the xid array if we call XidIsInSnapshot too many times > in a transaction. I don't think that is worth it, because a long > running snapshot may be examined many times, but is unlikely to see > multiple in-progress xids repeatedly. Whereas your case seems > reasonably common. Yeah, sorting would be a waste of time most of the time. Instead of adding a new cache field, how about just swapping the matched XID to the beginning of the array? Did you have some simple performance test script for this? - Heikki -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance