From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: os@ohmu.fi
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #8470: 9.3 locking/subtransaction performance regression
Date: Fri, 20 Dec 2013 17:47:53 -0300
Message-ID: <20131220204753.GG22570@eldon.alvh.no-ip.org> (raw)
In-Reply-To: <E1VOpEt-0003nc-4J@wrigleys.postgresql.org>
References: <E1VOpEt-0003nc-4J@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
> Removing the BEGIN/EXCEPTION/END block and just doing a 'SELECT FOR UPDATE'
> for a suitable row is significantly slower in 9.3.0 (314.765 ms vs 118.894
> ms on 9.2.4). A 'SELECT' without a FOR UPDATE and BEGIN/EXCEPTION/END has
> the same performance on 9.2.4 and 9.3.0.
I have come up with the attached patch. As far as I can tell it
restores performance roughly to the level of 9.2 for this test case;
could you please try it out and see if it fixes things for you? It'd be
particularly good if you can check not only the test case you submitted
but also the one that made you explore this in the first place.
I haven't pushed it yet because I haven't yet convinced myself that this
is safe, but my intention is to do it shortly so that it will be in
9.3.3.
--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugsAttachments:optimize-multi-locks.patch (text/x-diff, 4.2K) download
*** a/src/backend/access/heap/heapam.c
--- b/src/backend/access/heap/heapam.c
***************
*** 4585,4591 **** l5:
}
else if (old_infomask & HEAP_XMAX_IS_MULTI)
{
! MultiXactStatus new_status;
/*
* Currently we don't allow XMAX_COMMITTED to be set for multis, so
--- 4585,4591 ----
}
else if (old_infomask & HEAP_XMAX_IS_MULTI)
{
! bool keepmulti = false;
/*
* Currently we don't allow XMAX_COMMITTED to be set for multis, so
***************
*** 4609,4630 **** l5:
}
/*
! * If the XMAX is already a MultiXactId, then we need to expand it to
! * include add_to_xmax; but if all the members were lockers and are
! * all gone, we can do away with the IS_MULTI bit and just set
! * add_to_xmax as the only locker/updater. If all lockers are gone
! * and we have an updater that aborted, we can also do without a
! * multi.
! *
! * The cost of doing GetMultiXactIdMembers would be paid by
! * MultiXactIdExpand if we weren't to do this, so this check is not
! * incurring extra work anyhow.
*/
! if (!MultiXactIdIsRunning(xmax))
{
! if (HEAP_XMAX_IS_LOCKED_ONLY(old_infomask) ||
! TransactionIdDidAbort(MultiXactIdGetUpdateXid(xmax,
! old_infomask)))
{
/*
* Reset these bits and restart; otherwise fall through to
--- 4609,4673 ----
}
/*
! * Examine the members of the existing MultiXact. If any of them is
! * the current transaction and holds a lock at least as strong as we
! * are requesting, then the lock request can be satisfied with the
! * existing MultiXactId; there's no need to create a new one. Note we
! * only try this for locks, not updates, for three reasons: 1. if the
! * savepoint with the update later tried to abort, we'd be screwed;
! * 2. there's no way to "upgrade" a lock to an update within a
! * multixact anyway; 3. there is no point in trying because if the
! * multixact had a valid (non-aborted) update, the tuple would be
! * invisible and we wouldn't be trying to lock it.
*/
! if (!is_update)
! {
! MultiXactMember *members;
! int nmembers;
!
! nmembers = GetMultiXactIdMembers(xmax, &members, true);
! if (nmembers > 0)
! {
! int i;
! MultiXactStatus new_status;
!
! new_status = get_mxact_status_for_lock(mode, false);
!
! for (i = 0; i < nmembers; i++)
! {
! if (TransactionIdIsCurrentTransactionId(members[i].xid) &&
! (members[i].status >= new_status))
! {
! keepmulti = true;
! break;
! }
! }
! pfree(members);
! }
! }
!
! if (keepmulti)
! new_xmax = xmax;
! else
{
! MultiXactStatus new_status;
!
! /*
! * If the XMAX is already a MultiXactId, then we need to expand it
! * to include add_to_xmax; but if all the members were lockers and
! * are all gone, we can do away with the IS_MULTI bit and just set
! * add_to_xmax as the only locker/updater. If all lockers are
! * gone and we have an updater that aborted, we can also do
! * without a multi.
! *
! * The cost of doing GetMultiXactIdMembers would be paid by
! * MultiXactIdExpand if we weren't to do this, so this check is
! * not incurring extra work anyhow.
! */
! if (!MultiXactIdIsRunning(xmax) &&
! (HEAP_XMAX_IS_LOCKED_ONLY(old_infomask) ||
! !TransactionIdDidCommit(MultiXactIdGetUpdateXid(xmax,
! old_infomask))))
{
/*
* Reset these bits and restart; otherwise fall through to
***************
*** 4634,4645 **** l5:
old_infomask |= HEAP_XMAX_INVALID;
goto l5;
}
- }
! new_status = get_mxact_status_for_lock(mode, is_update);
- new_xmax = MultiXactIdExpand((MultiXactId) xmax, add_to_xmax,- new_status);
GetMultiXactIdHintBits(new_xmax, &new_infomask, &new_infomask2);
}
else if (old_infomask & HEAP_XMAX_COMMITTED)
--- 4677,4689 ----
old_infomask |= HEAP_XMAX_INVALID;
goto l5;
}
! new_status = get_mxact_status_for_lock(mode, is_update);
!
! new_xmax = MultiXactIdExpand((MultiXactId) xmax, add_to_xmax,
! new_status);
! }
GetMultiXactIdHintBits(new_xmax, &new_infomask, &new_infomask2);
}
else if (old_infomask & HEAP_XMAX_COMMITTED)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: alvherre@2ndquadrant.com, os@ohmu.fi
Subject: Re: BUG #8470: 9.3 locking/subtransaction performance regression
In-Reply-To: <20131220204753.GG22570@eldon.alvh.no-ip.org>
References: <E1VOpEt-0003nc-4J@wrigleys.postgresql.org> <20131220204753.GG22570@eldon.alvh.no-ip.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox