Re: In progress INSERT wrecks plans on table

From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
Cc: Mark Kirkwood <mark(dot)kirkwood(at)catalyst(dot)net(dot)nz>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Gavin Flower <gavinflower(at)archidevsys(dot)co(dot)nz>, "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: In progress INSERT wrecks plans on table
Date: 2013-06-16 17:25:25
Message-ID: CA+U5nM+ektySz_cx0uPU=9P7ueSxxKzHVaNvE9p1sTV_E30LGA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-performance

On 16 June 2013 16:04, Heikki Linnakangas <hlinnakangas(at)vmware(dot)com> wrote:
> 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?

Do you think that is significantly different from what I've done?

> Did you have some simple performance test script for this?

Files attached to set up and tear down the test. Needs
max_prepared_transactions = 100

--
Simon Riggs http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachment Content-Type Size
inprogr1.sql application/octet-stream 5.8 KB
inprogr2.sql application/octet-stream 2.3 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Simon Riggs 2013-06-16 17:28:43 Re: In progress INSERT wrecks plans on table
Previous Message Tom Lane 2013-06-16 16:59:55 Re: In progress INSERT wrecks plans on table

Browse pgsql-performance by date

  From Date Subject
Next Message Simon Riggs 2013-06-16 17:28:43 Re: In progress INSERT wrecks plans on table
Previous Message Tom Lane 2013-06-16 16:59:55 Re: In progress INSERT wrecks plans on table