pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #8470: 9.3 locking/subtransaction performance regression
26+ messages / 8 participants
[nested] [flat]
* BUG #8470: 9.3 locking/subtransaction performance regression
@ 2013-09-25 13:34 os@ohmu.fi
2013-09-25 14:26 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-20 20:47 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2014-02-26 03:30 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression chrisrow <chrisrow@hushmail.com>
0 siblings, 3 replies; 26+ messages in thread
From: os@ohmu.fi @ 2013-09-25 13:34 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
Bug reference: 8470
Logged by: Oskari Saarenmaa
Email address: os@ohmu.fi
PostgreSQL version: 9.3.0
Operating system: Linux
Description:
The following code performs a lot slower on PostgreSQL 9.3.0 than on
PostgreSQL 9.2.4:
DROP TABLE IF EXISTS tmp;
CREATE TABLE tmp (id BIGSERIAL, vals BIGINT[]);
DO $$
DECLARE
r_id BIGINT;
n BIGINT;
BEGIN
FOR n IN 1..1000 LOOP
BEGIN
SELECT id INTO r_id FROM tmp WHERE array_length(vals, 1) < 100
LIMIT 1 FOR UPDATE NOWAIT;
EXCEPTION WHEN lock_not_available THEN
r_id := NULL;
END;
IF r_id IS NULL THEN
INSERT INTO tmp (vals) VALUES (ARRAY[n]::BIGINT[]);
ELSE
UPDATE tmp SET vals = array_append(vals, n::BIGINT) WHERE id =
r_id;
END IF;
END LOOP;
END;
$$;
PostgreSQL 9.3.0:
Time: 7278.910 ms
PostgreSQL 9.2.4:
Time: 128.008 ms
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'm running 9.2.4 and 9.3.0 packages from apt.postgresql.org on a Debian
Squeeze host.
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 26+ messages in thread
* Re: BUG #8470: 9.3 locking/subtransaction performance regression
2013-09-25 13:34 BUG #8470: 9.3 locking/subtransaction performance regression os@ohmu.fi
@ 2013-09-25 14:26 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2013-10-04 22:31 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2 siblings, 1 reply; 26+ messages in thread
From: Alvaro Herrera @ 2013-09-25 14:26 UTC (permalink / raw)
To: os@ohmu.fi; +Cc: pgsql-bugs
os@ohmu.fi wrote:
> The following code performs a lot slower on PostgreSQL 9.3.0 than on
> PostgreSQL 9.2.4:
>
> DROP TABLE IF EXISTS tmp;
> CREATE TABLE tmp (id BIGSERIAL, vals BIGINT[]);
> DO $$
> DECLARE
> r_id BIGINT;
> n BIGINT;
> BEGIN
> FOR n IN 1..1000 LOOP
> BEGIN
> SELECT id INTO r_id FROM tmp WHERE array_length(vals, 1) < 100
> LIMIT 1 FOR UPDATE NOWAIT;
Most likely, this is caused by the new tuple lock code in 9.3. I can't
look at this immediately but I will give it a look as soon as I'm able.
--
Á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-bugs
^ permalink raw reply [nested|flat] 26+ messages in thread
* Re: BUG #8470: 9.3 locking/subtransaction performance regression
2013-09-25 13:34 BUG #8470: 9.3 locking/subtransaction performance regression os@ohmu.fi
2013-09-25 14:26 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2013-10-04 22:31 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2013-10-05 07:59 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Oskari Saarenmaa <os@ohmu.fi>
2013-10-06 17:41 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
0 siblings, 2 replies; 26+ messages in thread
From: Alvaro Herrera @ 2013-10-04 22:31 UTC (permalink / raw)
To: os@ohmu.fi; +Cc: pgsql-bugs
AFAICS the problem here is that this test doesn't use MultiXactIds at
all in 9.2, but it does in 9.3. I vaguely recall Noah tried to convince
me to put in an optimization which would have avoided this issue; I will
give that a thought. I don't think I will be able to get it done for
9.3.1 though.
--
Á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-bugs
^ permalink raw reply [nested|flat] 26+ messages in thread
* Re: BUG #8470: 9.3 locking/subtransaction performance regression
2013-09-25 13:34 BUG #8470: 9.3 locking/subtransaction performance regression os@ohmu.fi
2013-09-25 14:26 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-10-04 22:31 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2013-10-05 07:59 ` Oskari Saarenmaa <os@ohmu.fi>
2013-10-05 15:14 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-10-05 15:23 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
1 sibling, 2 replies; 26+ messages in thread
From: Oskari Saarenmaa @ 2013-10-05 07:59 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: pgsql-bugs
05.10.2013 01:31, Alvaro Herrera kirjoitti:
> AFAICS the problem here is that this test doesn't use MultiXactIds at
> all in 9.2, but it does in 9.3. I vaguely recall Noah tried to convince
> me to put in an optimization which would have avoided this issue; I will
> give that a thought. I don't think I will be able to get it done for
> 9.3.1 though.
Is the schedule for 9.3.1 visible somewhere? Please reconsider trying
to get a fix for this in as it's a pretty big regression from 9.2. My
application test case that triggered this ran in roughly 3 seconds with
9.2 but timed out after 3 minutes on 9.3.0. And even without a loop
that amplifies this, just a single 'select for update' inside a
subtransaction is significantly slower in 9.3.
Thanks,
Oskari
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 26+ messages in thread
* Re: BUG #8470: 9.3 locking/subtransaction performance regression
2013-09-25 13:34 BUG #8470: 9.3 locking/subtransaction performance regression os@ohmu.fi
2013-09-25 14:26 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-10-04 22:31 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-10-05 07:59 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Oskari Saarenmaa <os@ohmu.fi>
@ 2013-10-05 15:14 ` Alvaro Herrera <alvherre@2ndquadrant.com>
1 sibling, 0 replies; 26+ messages in thread
From: Alvaro Herrera @ 2013-10-05 15:14 UTC (permalink / raw)
To: Oskari Saarenmaa <os@ohmu.fi>; +Cc: pgsql-bugs
Oskari Saarenmaa wrote:
> 05.10.2013 01:31, Alvaro Herrera kirjoitti:
> > AFAICS the problem here is that this test doesn't use MultiXactIds at
> > all in 9.2, but it does in 9.3. I vaguely recall Noah tried to convince
> > me to put in an optimization which would have avoided this issue; I will
> > give that a thought. I don't think I will be able to get it done for
> > 9.3.1 though.
>
> Is the schedule for 9.3.1 visible somewhere?
Not sure. I just happen to know it'll be git-tagged early next week.
> Please reconsider trying to get a fix for this in as it's a pretty big
> regression from 9.2.
I understand the pressure. Sadly, I have other things scheduled right
now that I can't postpone. I might still be able to get to it over the
weekend; if someone else has time and can submit and/or test a patch,
that would perhaps allow me to get it done in time.
--
Á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-bugs
^ permalink raw reply [nested|flat] 26+ messages in thread
* Re: BUG #8470: 9.3 locking/subtransaction performance regression
2013-09-25 13:34 BUG #8470: 9.3 locking/subtransaction performance regression os@ohmu.fi
2013-09-25 14:26 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-10-04 22:31 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-10-05 07:59 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Oskari Saarenmaa <os@ohmu.fi>
@ 2013-10-05 15:23 ` Alvaro Herrera <alvherre@2ndquadrant.com>
1 sibling, 0 replies; 26+ messages in thread
From: Alvaro Herrera @ 2013-10-05 15:23 UTC (permalink / raw)
To: Oskari Saarenmaa <os@ohmu.fi>; +Cc: pgsql-bugs
Oskari Saarenmaa wrote:
> 05.10.2013 01:31, Alvaro Herrera kirjoitti:
> > AFAICS the problem here is that this test doesn't use MultiXactIds at
> > all in 9.2, but it does in 9.3. I vaguely recall Noah tried to convince
> > me to put in an optimization which would have avoided this issue; I will
> > give that a thought. I don't think I will be able to get it done for
> > 9.3.1 though.
>
> Is the schedule for 9.3.1 visible somewhere?
http://www.postgresql.org/message-id/CA+OCxozG4PhbFphbg+ehpJk3TgLFDVyMuzwy+wyf=x1Utt-WAA@mail.gmail....
--
Á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-bugs
^ permalink raw reply [nested|flat] 26+ messages in thread
* Re: BUG #8470: 9.3 locking/subtransaction performance regression
2013-09-25 13:34 BUG #8470: 9.3 locking/subtransaction performance regression os@ohmu.fi
2013-09-25 14:26 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-10-04 22:31 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2013-10-06 17:41 ` Alvaro Herrera <alvherre@2ndquadrant.com>
1 sibling, 0 replies; 26+ messages in thread
From: Alvaro Herrera @ 2013-10-06 17:41 UTC (permalink / raw)
To: os@ohmu.fi; +Cc: pgsql-bugs
Alvaro Herrera wrote:
> AFAICS the problem here is that this test doesn't use MultiXactIds at
> all in 9.2, but it does in 9.3. I vaguely recall Noah tried to convince
> me to put in an optimization which would have avoided this issue; I will
> give that a thought. I don't think I will be able to get it done for
> 9.3.1 though.
I gave this a deeper look yesterday. Sadly, that optimization would not
work here; we give stronger guarantees now than 9.2 and that's the
reason for the slowness. Previously, we just overwrote the lock held by
the ancestor transaction if a subxact grabbed a stronger lock; we no
longer do that, and instead create a multi comprising both of those
locks. That way if the subxact rolls back, we don't lose the previous
lock we held.
It seems that we could avoid creating a new multixact in a few more
cases, by reusing an already existing multixact; or, if we're forced to
create a new one, omit the member from the old one that is superceded by
our own member with the stronger lock. However, there is no way this
will affect this test case *at all*.
I see another way forward: if an ancestor takes lock of a certain
strength, and then subxact takes a stronger lock, we could record this
as "ancestor taking the stronger lock", so this could be stored as a
plain Xid and not a Multi. That way, (1) we do not incur a new
multixact, and (2) the lock would not be lost if the subxact aborts.
This would come at the cost that if the subxact rolls back, the stronger
lock would not be released.
Another thing we could look at is whether we can optimize for the case
of sub-committed subtransactions, i.e. we know these won't roll back in
relation to the current xact. It seems that would apply here because
when you finish the BEGIN/EXCEPTION/END block, that automatic subxact is
marked sub-committed. It seems to me we could collapse the locks
acquired by those subxacts to appear as locks owned by its currently
open ancestor.
--
Á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-bugs
^ permalink raw reply [nested|flat] 26+ messages in thread
* Re: BUG #8470: 9.3 locking/subtransaction performance regression
2013-09-25 13:34 BUG #8470: 9.3 locking/subtransaction performance regression os@ohmu.fi
@ 2013-12-20 20:47 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 15:56 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2 siblings, 1 reply; 26+ messages in thread
From: Alvaro Herrera @ 2013-12-20 20:47 UTC (permalink / raw)
To: os@ohmu.fi; +Cc: pgsql-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-bugs
Attachments:
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)
^ permalink raw reply [nested|flat] 26+ messages in thread
* Re: BUG #8470: 9.3 locking/subtransaction performance regression
2013-09-25 13:34 BUG #8470: 9.3 locking/subtransaction performance regression os@ohmu.fi
2013-12-20 20:47 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2013-12-23 15:56 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 16:29 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
0 siblings, 1 reply; 26+ messages in thread
From: Alvaro Herrera @ 2013-12-23 15:56 UTC (permalink / raw)
To: os@ohmu.fi; +Cc: pgsql-bugs
After looking at this some more, I am more convinced that we need to
have HeapTupleSatisfiesUpdate return BeingUpdated when a row is locked
by the same xact. This is more in line with what we do for MultiXacts,
and allows us to treat some cases in a saner fashion: in particular, if
a transaction grabs a lock on a tuple and a subxact grabs a stronger
lock, we now create a multi recording both locks instead of silently
ignoring the second request.
The fallout from this change wasn't as bad as I had feared; I had to add
some coding in heap_update and heap_delete to prevent them from trying
to wait on their own Xid, but it looks pretty innocuous otherwise.
In ran your test case inflating the loop counters a bit, so that it
shows more exaggerated timings. The results of running this twice on
9.2 are:
Timing: 6140,506 ms
Timing: 6054,553 ms
I only ran it once in an unpatched 9.3:
Timing: 221204,352
This is patched 9.3:
Timing: 13757,925 ms
Note patched 9.3 is 2x slower than 9.2, which is understandable because
it does more work ... yet I think it returns performance to a much more
acceptable level, comparable to 9.2.
I have more confidence in this patch than in the previous version,
despite it being more intrusive. The fact that it allows us to get rid
of some very strange coding in pgrowlocks is comforting: we now know
that anytime a tuple is locked we will get BeingUpdated from
HeapTupleSatisfiesUpdate, regardless of *who* locked it, and all the
callers are able to identify this case and act in consequence. This
seems saner in concept that sometimes returning MayBeUpdated, because
that turns each such return into a condition that must be double-checked
by callers. This means cleaner code in pgrowlocks around a HTSU call,
for instance. Also, we have discussed and seriously considered this
idea in several occasions previously in connection with other things.
--
Á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-bugs
Attachments:
optimize-locking-locked-multi.patch (text/x-diff, 12.0K) download
diff --git a/contrib/pgrowlocks/pgrowlocks.c b/contrib/pgrowlocks/pgrowlocks.c
index 075d781..9ef90cd 100644
*** a/contrib/pgrowlocks/pgrowlocks.c
--- b/contrib/pgrowlocks/pgrowlocks.c
***************
*** 138,151 **** pgrowlocks(PG_FUNCTION_ARGS)
infomask = tuple->t_data->t_infomask;
/*
! * a tuple is locked if HTSU returns BeingUpdated, and if it returns
! * MayBeUpdated but the Xmax is valid and pointing at us.
*/
! if (htsu == HeapTupleBeingUpdated ||
! (htsu == HeapTupleMayBeUpdated &&
! !(infomask & HEAP_XMAX_INVALID) &&
! !(infomask & HEAP_XMAX_IS_MULTI) &&
! (xmax == GetCurrentTransactionIdIfAny())))
{
char **values;
--- 138,146 ----
infomask = tuple->t_data->t_infomask;
/*
! * A tuple is locked if HTSU returns BeingUpdated.
*/
! if (htsu == HeapTupleBeingUpdated)
{
char **values;
diff --git a/src/backend/access/heap/hindex b5977da..6eb1de2 100644
*** a/src/backend/access/heap/heapam.c
--- b/src/backend/access/heap/heapam.c
***************
*** 2596,2601 **** l1:
--- 2596,2621 ----
TransactionId xwait;
uint16 infomask;
+ /*
+ * If any subtransaction of the current top transaction already holds
+ * a lock on this tuple, (and no one else does,) we must skip sleeping
+ * on the xwait; that would raise an assert about sleeping on our own
+ * Xid (or sleep indefinitely in a non-assertion enabled build.) Note
+ * we don't need to do this when the Xmax is a multi, because that
+ * code is prepared to deal with transactions of the same session.
+ *
+ * This must be done before acquiring our tuple lock, to avoid
+ * deadlocks with other transaction that are already waiting on the
+ * lock we hold.
+ */
+ if (!(tp.t_data->t_infomask & HEAP_XMAX_IS_MULTI) &&
+ TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetRawXmax(tp.t_data)))
+ {
+ Assert(HEAP_XMAX_IS_LOCKED_ONLY(tp.t_data->t_infomask));
+
+ goto continue_deletion;
+ }
+
/* must copy state data before unlocking buffer */
xwait = HeapTupleHeaderGetRawXmax(tp.t_data);
infomask = tp.t_data->t_infomask;
***************
*** 2669,2674 **** l1:
--- 2689,2695 ----
UpdateXmaxHintBits(tp.t_data, buffer, xwait);
}
+ continue_deletion:
/*
* We may overwrite if previous xmax aborted, or if it committed but
* only locked the tuple without updating it.
***************
*** 3089,3094 **** l2:
--- 3110,3137 ----
* heap_update directly.
*/
+ /*
+ * If any subtransaction of the current top transaction already holds
+ * a lock on this tuple, (and no one else does,) we must skip sleeping
+ * on the xwait; that would raise an assert about sleeping on our own
+ * Xid (or sleep indefinitely in a non-assertion enabled build.) Note
+ * we don't need to do this when the Xmax is a multi, because that
+ * code is prepared to deal with transactions of the same session.
+ *
+ * This must be done before acquiring our tuple lock, to avoid
+ * deadlocks with other transaction that are already waiting on the
+ * lock we hold.
+ */
+ if (!(oldtup.t_data->t_infomask & HEAP_XMAX_IS_MULTI) &&
+ TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetRawXmax(oldtup.t_data)))
+ {
+ Assert(HEAP_XMAX_IS_LOCKED_ONLY(oldtup.t_data->t_infomask));
+
+ can_continue = true;
+ locker_remains = true;
+ goto continue_updating;
+ }
+
/* must copy state data before unlocking buffer */
xwait = HeapTupleHeaderGetRawXmax(oldtup.t_data);
infomask = oldtup.t_data->t_infomask;
***************
*** 3223,3228 **** l2:
--- 3266,3272 ----
}
}
+ continue_updating:
result = can_continue ? HeapTupleMayBeUpdated : HeapTupleUpdated;
}
***************
*** 3945,3951 **** l3:
TransactionId xwait;
uint16 infomask;
uint16 infomask2;
! bool require_sleep;
ItemPointerData t_ctid;
/* must copy state data before unlocking buffer */
--- 3989,3995 ----
TransactionId xwait;
uint16 infomask;
uint16 infomask2;
! bool require_sleep = true;
ItemPointerData t_ctid;
/* must copy state data before unlocking buffer */
***************
*** 3997,4002 **** l3:
--- 4041,4064 ----
pfree(members);
}
+ else if (HEAP_XMAX_IS_LOCKED_ONLY(infomask) &&
+ TransactionIdIsCurrentTransactionId(xwait))
+ {
+ /*
+ * If we already hold a lock on this tuple, we can fall through
+ * to perhaps create a new MultiXact including the previous lock
+ * and ours, or perhaps just keep the old lock.
+ */
+ result = HeapTupleMayBeUpdated;
+
+ LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE);
+ /* If xmax changed while we weren't looking, start over */
+ if ((tuple->t_data->t_infomask & HEAP_XMAX_IS_MULTI) ||
+ !TransactionIdEquals(HeapTupleHeaderGetRawXmax(tuple->t_data),
+ xwait))
+ goto l3;
+ goto continue_locking;
+ }
/*
* Acquire tuple lock to establish our priority for the tuple.
***************
*** 4330,4335 **** l3:
--- 4392,4399 ----
/* By here, we're certain that we hold buffer exclusive lock again */
+ continue_locking:
+
/*
* We may lock if previous xmax aborted, or if it committed but only
* locked the tuple without updating it; or if we didn't have to wait
***************
*** 4365,4401 **** failed:
old_infomask = tuple->t_data->t_infomask;
/*
- * We might already hold the desired lock (or stronger), possibly under a
- * different subtransaction of the current top transaction. If so, there
- * is no need to change state or issue a WAL record. We already handled
- * the case where this is true for xmax being a MultiXactId, so now check
- * for cases where it is a plain TransactionId.
- *
- * Note in particular that this covers the case where we already hold
- * exclusive lock on the tuple and the caller only wants key share or
- * share lock. It would certainly not do to give up the exclusive lock.
- */
- if (!(old_infomask & (HEAP_XMAX_INVALID |
- HEAP_XMAX_COMMITTED |
- HEAP_XMAX_IS_MULTI)) &&
- (mode == LockTupleKeyShare ?
- (HEAP_XMAX_IS_KEYSHR_LOCKED(old_infomask) ||
- HEAP_XMAX_IS_SHR_LOCKED(old_infomask) ||
- HEAP_XMAX_IS_EXCL_LOCKED(old_infomask)) :
- mode == LockTupleShare ?
- (HEAP_XMAX_IS_SHR_LOCKED(old_infomask) ||
- HEAP_XMAX_IS_EXCL_LOCKED(old_infomask)) :
- (HEAP_XMAX_IS_EXCL_LOCKED(old_infomask))) &&
- TransactionIdIsCurrentTransactionId(xmax))
- {
- LockBuffer(*buffer, BUFFER_LOCK_UNLOCK);
- /* Probably can't hold tuple lock here, but may as well check */
- if (have_tuple_lock)
- UnlockTupleTuplock(relation, tid, mode);
- return HeapTupleMayBeUpdated;
- }
-
- /*
* If this is the first possibly-multixact-able operation in the current
* transaction, set my per-backend OldestMemberMXactId setting. We can be
* certain that the transaction will never become a member of any older
--- 4429,4434 ----
***************
*** 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
--- 4618,4624 ----
}
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
--- 4642,4706 ----
}
/*
! * 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 MultiXact; 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)
--- 4710,4722 ----
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)
diff --git a/src/backend/utils/time/tquindex 44b4ddc..0d82523 100644
*** a/src/backend/utils/time/tqual.c
--- b/src/backend/utils/time/tqual.c
***************
*** 846,852 **** HeapTupleSatisfiesUpdate(HeapTupleHeader tuple, CommandId curcid,
if (TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetRawXmax(tuple)))
{
if (HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_infomask))
! return HeapTupleMayBeUpdated;
if (HeapTupleHeaderGetCmax(tuple) >= curcid)
return HeapTupleSelfUpdated; /* updated after scan started */
else
--- 846,852 ----
if (TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetRawXmax(tuple)))
{
if (HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_infomask))
! return HeapTupleBeingUpdated;
if (HeapTupleHeaderGetCmax(tuple) >= curcid)
return HeapTupleSelfUpdated; /* updated after scan started */
else
diff --git a/src/include/access/xlog.index 83e5832..16a4c3b 100644
diff --git a/src/test/isolation/index f625650..2dfd872 100644
^ permalink raw reply [nested|flat] 26+ messages in thread
* Re: BUG #8470: 9.3 locking/subtransaction performance regression
2013-09-25 13:34 BUG #8470: 9.3 locking/subtransaction performance regression os@ohmu.fi
2013-12-20 20:47 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 15:56 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2013-12-23 16:29 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 19:53 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
0 siblings, 1 reply; 26+ messages in thread
From: Alvaro Herrera @ 2013-12-23 16:29 UTC (permalink / raw)
To: os@ohmu.fi; +Cc: pgsql-bugs
Alvaro Herrera wrote:
> I have more confidence in this patch than in the previous version,
> despite it being more intrusive. The fact that it allows us to get rid
> of some very strange coding in pgrowlocks is comforting: we now know
> that anytime a tuple is locked we will get BeingUpdated from
> HeapTupleSatisfiesUpdate, regardless of *who* locked it, and all the
> callers are able to identify this case and act in consequence. This
> seems saner in concept that sometimes returning MayBeUpdated, because
> that turns each such return into a condition that must be double-checked
> by callers. This means cleaner code in pgrowlocks around a HTSU call,
> for instance. Also, we have discussed and seriously considered this
> idea in several occasions previously in connection with other things.
... in particular, this change allows us to revert the addition of
MultiXactHasRunningRemoteMembers(), and simply use
MultiXactIdIsRunning() in the two places that required it.
--
Á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-bugs
^ permalink raw reply [nested|flat] 26+ messages in thread
* Re: BUG #8470: 9.3 locking/subtransaction performance regression
2013-09-25 13:34 BUG #8470: 9.3 locking/subtransaction performance regression os@ohmu.fi
2013-12-20 20:47 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 15:56 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 16:29 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2013-12-23 19:53 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 20:06 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-30 18:11 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Andres Freund <andres@2ndquadrant.com>
0 siblings, 2 replies; 26+ messages in thread
From: Alvaro Herrera @ 2013-12-23 19:53 UTC (permalink / raw)
To: os@ohmu.fi; +Cc: pgsql-bugs
Alvaro Herrera wrote:
> ... in particular, this change allows us to revert the addition of
> MultiXactHasRunningRemoteMembers(), and simply use
> MultiXactIdIsRunning() in the two places that required it.
And doing that enables simplifying this patch a bit, so here it is one
more time. Hopefully this is the final version -- I intend to push it
to 9.3 and master.
Please *note the behavior change* of HeapTupleSatisfiesUpdate: it will
now return HeapTupleBeingUpdated when a tuple is locked by an Xid that's
a subtransaction of the current top transactionn. That case previously
returned HeapTupleBeingUpdated. If someone wants to say that we
shouldn't change that in 9.3, please speak up. But do note that it was
already returning that valu ewhen the lock was a multixact, so the new
behavior can be said to be more consistent.
--
Á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-bugs
Attachments:
0001-Optimize-locking-a-tuple-already-locked-by-another-s.patch (text/x-diff, 11.2K) download
From 24d88cb5d6baf840f981913f224d89c792903462 Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Mon, 23 Dec 2013 16:07:51 -0300
Subject: [PATCH] Optimize locking a tuple already locked by another subxact
The original coding tried to avoid locking tuples twice when other
subtransactions of the current top transaction already held the
requested lock, but the coding was bogus and some cases were slow, as
reported by Oskari Saarenmaa in bug #8470.
In order to make it work, HeapTupleSatisfiesUpdate is changed so that it
always returns HeapTupleBeingUpdated when the tuple is locked, even if
the locker is the current transaction or another subtransaction of the
current transaction; that case previously returned HeapTupleMayBeUpdated
and was handled specially by callers, but it turns out to be less
error-prone to instead have them check whether the reported lock is held
by the current transaction. That way, more optimizations are enabled in
compute_new_xmax_infomask.
The reported test case is still slower than 9.2, but it's only 2x slower
not 56x.
---
contrib/pgrowlocks/pgrowlocks.c | 9 +--
src/backend/access/heap/heapam.c | 107 +++++++++++++++++++++-----------
src/backend/access/transam/multixact.c | 33 ----------
src/backend/utils/time/tqual.c | 6 +-
src/include/access/multixact.h | 1 -
5 files changed, 77 insertions(+), 79 deletions(-)
diff --git a/contrib/pgrowlocks/pgrowlocks.c b/contrib/pgrowlocks/pgrowlocks.c
index 075d781..9ef90cd 100644
--- a/contrib/pgrowlocks/pgrowlocks.c
+++ b/contrib/pgrowlocks/pgrowlocks.c
@@ -138,14 +138,9 @@ pgrowlocks(PG_FUNCTION_ARGS)
infomask = tuple->t_data->t_infomask;
/*
- * a tuple is locked if HTSU returns BeingUpdated, and if it returns
- * MayBeUpdated but the Xmax is valid and pointing at us.
+ * A tuple is locked if HTSU returns BeingUpdated.
*/
- if (htsu == HeapTupleBeingUpdated ||
- (htsu == HeapTupleMayBeUpdated &&
- !(infomask & HEAP_XMAX_INVALID) &&
- !(infomask & HEAP_XMAX_IS_MULTI) &&
- (xmax == GetCurrentTransactionIdIfAny())))
+ if (htsu == HeapTupleBeingUpdated)
{
char **values;
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index b5977da..523d216 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2596,6 +2596,30 @@ l1:
TransactionId xwait;
uint16 infomask;
+ /*
+ * If any subtransaction of the current top transaction already holds
+ * a lock on this tuple, (and no one else does,) we must skip sleeping
+ * on the xwait; that would raise an assert about sleeping on our own
+ * Xid (or sleep indefinitely in a non-asserts-enabled build.)
+ *
+ * Note we don't need to do anything about this when the Xmax is a
+ * multixact, because that code is already prepared to ignore
+ * subtransactions of the current top transaction; also, trying to do
+ * anything other than sleeping during a delete when someone else is
+ * holding a lock on this tuple would be wrong.
+ *
+ * This must be done before acquiring our tuple lock, to avoid
+ * deadlocks with other transaction that are already waiting on the
+ * lock we hold.
+ */
+ if (!(tp.t_data->t_infomask & HEAP_XMAX_IS_MULTI) &&
+ TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetRawXmax(tp.t_data)))
+ {
+ Assert(HEAP_XMAX_IS_LOCKED_ONLY(tp.t_data->t_infomask));
+
+ goto continue_deletion;
+ }
+
/* must copy state data before unlocking buffer */
xwait = HeapTupleHeaderGetRawXmax(tp.t_data);
infomask = tp.t_data->t_infomask;
@@ -2669,6 +2693,7 @@ l1:
UpdateXmaxHintBits(tp.t_data, buffer, xwait);
}
+continue_deletion:
/*
* We may overwrite if previous xmax aborted, or if it committed but
* only locked the tuple without updating it.
@@ -3089,6 +3114,30 @@ l2:
* heap_update directly.
*/
+ /*
+ * If any subtransaction of the current top transaction already holds
+ * a lock on this tuple, (and no one else does,) we must skip sleeping
+ * on the xwait; that would raise an assert about sleeping on our own
+ * Xid (or sleep indefinitely in a non-assertion enabled build.)
+ *
+ * Note we don't need to do anything about this when the Xmax is a
+ * multixact, because that code is prepared to ignore subtransactions
+ * of the current top transaction.
+ *
+ * This must be done before acquiring our tuple lock, to avoid
+ * deadlocks with other transaction that are already waiting on the
+ * lock we hold.
+ */
+ if (!(oldtup.t_data->t_infomask & HEAP_XMAX_IS_MULTI) &&
+ TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetRawXmax(oldtup.t_data)))
+ {
+ Assert(HEAP_XMAX_IS_LOCKED_ONLY(oldtup.t_data->t_infomask));
+
+ can_continue = true;
+ locker_remains = true;
+ goto continue_updating;
+ }
+
/* must copy state data before unlocking buffer */
xwait = HeapTupleHeaderGetRawXmax(oldtup.t_data);
infomask = oldtup.t_data->t_infomask;
@@ -3223,6 +3272,7 @@ l2:
}
}
+continue_updating:
result = can_continue ? HeapTupleMayBeUpdated : HeapTupleUpdated;
}
@@ -3945,7 +3995,7 @@ l3:
TransactionId xwait;
uint16 infomask;
uint16 infomask2;
- bool require_sleep;
+ bool require_sleep = true;
ItemPointerData t_ctid;
/* must copy state data before unlocking buffer */
@@ -3997,6 +4047,22 @@ l3:
pfree(members);
}
+ else if (HEAP_XMAX_IS_LOCKED_ONLY(infomask) &&
+ TransactionIdIsCurrentTransactionId(xwait))
+ {
+ /*
+ * If we already hold a lock on this tuple, we can fall through
+ * to perhaps create a new MultiXact including the previous lock
+ * and ours, or perhaps just keep the old lock.
+ */
+ LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE);
+ /* If xmax changed while we weren't looking, start over */
+ if ((tuple->t_data->t_infomask & HEAP_XMAX_IS_MULTI) ||
+ !TransactionIdEquals(HeapTupleHeaderGetRawXmax(tuple->t_data),
+ xwait))
+ goto l3;
+ goto continue_locking;
+ }
/*
* Acquire tuple lock to establish our priority for the tuple.
@@ -4330,6 +4396,8 @@ l3:
/* By here, we're certain that we hold buffer exclusive lock again */
+continue_locking:
+
/*
* We may lock if previous xmax aborted, or if it committed but only
* locked the tuple without updating it; or if we didn't have to wait
@@ -4365,37 +4433,6 @@ failed:
old_infomask = tuple->t_data->t_infomask;
/*
- * We might already hold the desired lock (or stronger), possibly under a
- * different subtransaction of the current top transaction. If so, there
- * is no need to change state or issue a WAL record. We already handled
- * the case where this is true for xmax being a MultiXactId, so now check
- * for cases where it is a plain TransactionId.
- *
- * Note in particular that this covers the case where we already hold
- * exclusive lock on the tuple and the caller only wants key share or
- * share lock. It would certainly not do to give up the exclusive lock.
- */
- if (!(old_infomask & (HEAP_XMAX_INVALID |
- HEAP_XMAX_COMMITTED |
- HEAP_XMAX_IS_MULTI)) &&
- (mode == LockTupleKeyShare ?
- (HEAP_XMAX_IS_KEYSHR_LOCKED(old_infomask) ||
- HEAP_XMAX_IS_SHR_LOCKED(old_infomask) ||
- HEAP_XMAX_IS_EXCL_LOCKED(old_infomask)) :
- mode == LockTupleShare ?
- (HEAP_XMAX_IS_SHR_LOCKED(old_infomask) ||
- HEAP_XMAX_IS_EXCL_LOCKED(old_infomask)) :
- (HEAP_XMAX_IS_EXCL_LOCKED(old_infomask))) &&
- TransactionIdIsCurrentTransactionId(xmax))
- {
- LockBuffer(*buffer, BUFFER_LOCK_UNLOCK);
- /* Probably can't hold tuple lock here, but may as well check */
- if (have_tuple_lock)
- UnlockTupleTuplock(relation, tid, mode);
- return HeapTupleMayBeUpdated;
- }
-
- /*
* If this is the first possibly-multixact-able operation in the current
* transaction, set my per-backend OldestMemberMXactId setting. We can be
* certain that the transaction will never become a member of any older
@@ -4622,9 +4659,9 @@ l5:
*/
if (!MultiXactIdIsRunning(xmax))
{
- if (HEAP_XMAX_IS_LOCKED_ONLY(old_infomask) ||
- TransactionIdDidAbort(MultiXactIdGetUpdateXid(xmax,
- old_infomask)))
+ if ((HEAP_XMAX_IS_LOCKED_ONLY(old_infomask) ||
+ !TransactionIdDidCommit(MultiXactIdGetUpdateXid(xmax,
+ old_infomask))))
{
/*
* Reset these bits and restart; otherwise fall through to
diff --git a/src/backend/access/transam/multixact.c b/src/backend/access/transam/multixact.c
index 03581be..55a8ca7 100644
--- a/src/backend/access/transam/multixact.c
+++ b/src/backend/access/transam/multixact.c
@@ -1275,39 +1275,6 @@ retry:
}
/*
- * MultiXactHasRunningRemoteMembers
- * Does the given multixact have still-live members from
- * transactions other than our own?
- */
-bool
-MultiXactHasRunningRemoteMembers(MultiXactId multi)
-{
- MultiXactMember *members;
- int nmembers;
- int i;
-
- nmembers = GetMultiXactIdMembers(multi, &members, true);
- if (nmembers <= 0)
- return false;
-
- for (i = 0; i < nmembers; i++)
- {
- /* not interested in our own members */
- if (TransactionIdIsCurrentTransactionId(members[i].xid))
- continue;
-
- if (TransactionIdIsInProgress(members[i].xid))
- {
- pfree(members);
- return true;
- }
- }
-
- pfree(members);
- return false;
-}
-
-/*
* mxactMemberComparator
* qsort comparison function for MultiXactMember
*
diff --git a/src/backend/utils/time/tqual.c b/src/backend/utils/time/tqual.c
index 44b4ddc..7f876ad 100644
--- a/src/backend/utils/time/tqual.c
+++ b/src/backend/utils/time/tqual.c
@@ -701,7 +701,7 @@ HeapTupleSatisfiesUpdate(HeapTupleHeader tuple, CommandId curcid,
if (tuple->t_infomask & HEAP_XMAX_IS_MULTI)
{
- if (MultiXactHasRunningRemoteMembers(xmax))
+ if (MultiXactIdIsRunning(xmax))
return HeapTupleBeingUpdated;
else
return HeapTupleMayBeUpdated;
@@ -729,7 +729,7 @@ HeapTupleSatisfiesUpdate(HeapTupleHeader tuple, CommandId curcid,
/* updating subtransaction must have aborted */
if (!TransactionIdIsCurrentTransactionId(xmax))
{
- if (MultiXactHasRunningRemoteMembers(HeapTupleHeaderGetRawXmax(tuple)))
+ if (MultiXactIdIsRunning(HeapTupleHeaderGetRawXmax(tuple)))
return HeapTupleBeingUpdated;
return HeapTupleMayBeUpdated;
}
@@ -846,7 +846,7 @@ HeapTupleSatisfiesUpdate(HeapTupleHeader tuple, CommandId curcid,
if (TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetRawXmax(tuple)))
{
if (HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_infomask))
- return HeapTupleMayBeUpdated;
+ return HeapTupleBeingUpdated;
if (HeapTupleHeaderGetCmax(tuple) >= curcid)
return HeapTupleSelfUpdated; /* updated after scan started */
else
diff --git a/src/include/access/multixact.h b/src/include/access/multixact.h
index 5f82907..0e3b273 100644
--- a/src/include/access/multixact.h
+++ b/src/include/access/multixact.h
@@ -89,7 +89,6 @@ extern bool MultiXactIdIsRunning(MultiXactId multi);
extern void MultiXactIdSetOldestMember(void);
extern int GetMultiXactIdMembers(MultiXactId multi, MultiXactMember **xids,
bool allow_old);
-extern bool MultiXactHasRunningRemoteMembers(MultiXactId multi);
extern bool MultiXactIdPrecedes(MultiXactId multi1, MultiXactId multi2);
extern bool MultiXactIdPrecedesOrEquals(MultiXactId multi1,
MultiXactId multi2);
--
1.7.10.4
^ permalink raw reply [nested|flat] 26+ messages in thread
* Re: BUG #8470: 9.3 locking/subtransaction performance regression
2013-09-25 13:34 BUG #8470: 9.3 locking/subtransaction performance regression os@ohmu.fi
2013-12-20 20:47 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 15:56 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 16:29 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 19:53 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2013-12-23 20:06 ` Alvaro Herrera <alvherre@2ndquadrant.com>
1 sibling, 0 replies; 26+ messages in thread
From: Alvaro Herrera @ 2013-12-23 20:06 UTC (permalink / raw)
To: os@ohmu.fi; +Cc: pgsql-bugs
Alvaro Herrera wrote:
> Please *note the behavior change* of HeapTupleSatisfiesUpdate: it will
> now return HeapTupleBeingUpdated when a tuple is locked by an Xid that's
> a subtransaction of the current top transactionn. That case previously
> returned HeapTupleBeingUpdated. If someone wants to say that we
> shouldn't change that in 9.3, please speak up. But do note that it was
> already returning that valu ewhen the lock was a multixact, so the new
> behavior can be said to be more consistent.
I hate to keep replying to myself, but above I intended to say "that
case previously returned HeapTupleMayBeUpdated".
--
Á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-bugs
^ permalink raw reply [nested|flat] 26+ messages in thread
* Re: BUG #8470: 9.3 locking/subtransaction performance regression
2013-09-25 13:34 BUG #8470: 9.3 locking/subtransaction performance regression os@ohmu.fi
2013-12-20 20:47 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 15:56 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 16:29 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 19:53 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2013-12-30 18:11 ` Andres Freund <andres@2ndquadrant.com>
2013-12-31 16:34 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
1 sibling, 1 reply; 26+ messages in thread
From: Andres Freund @ 2013-12-30 18:11 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: os@ohmu.fi; pgsql-bugs
On 2013-12-23 16:53:00 -0300, Alvaro Herrera wrote:
> + /*
> + * If any subtransaction of the current top transaction already holds
> + * a lock on this tuple, (and no one else does,) we must skip sleeping
> + * on the xwait; that would raise an assert about sleeping on our own
> + * Xid (or sleep indefinitely in a non-asserts-enabled build.)
> + *
> + * Note we don't need to do anything about this when the Xmax is a
> + * multixact, because that code is already prepared to ignore
> + * subtransactions of the current top transaction; also, trying to do
> + * anything other than sleeping during a delete when someone else is
> + * holding a lock on this tuple would be wrong.
I don't really understand why those two issues are in the same
paragraph, what's their relation? Just that a deleting xact shouldn't be
a multi?
> + * This must be done before acquiring our tuple lock, to avoid
> + * deadlocks with other transaction that are already waiting on the
> + * lock we hold.
> + */
> + if (!(tp.t_data->t_infomask & HEAP_XMAX_IS_MULTI) &&
> + TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetRawXmax(tp.t_data)))
> + {
> + Assert(HEAP_XMAX_IS_LOCKED_ONLY(tp.t_data->t_infomask));
> +
> + goto continue_deletion;
> + }
Man, the control flow in heapam.c isn't getting simpler :/. Could you
rename the label to perform_deletion or such? It's no really continuing
it from my POV.
> + /*
> + * If any subtransaction of the current top transaction already holds
> + * a lock on this tuple, (and no one else does,) we must skip sleeping
> + * on the xwait; that would raise an assert about sleeping on our own
> + * Xid (or sleep indefinitely in a non-assertion enabled build.)
I'd reformulate this to note that we'd wait for ourselves - perhaps
noting that that fact would be caught by an assert in assert enabled
builds. The assert isn't the real reason we cannot do this.
> /*
> - * We might already hold the desired lock (or stronger), possibly under a
> - * different subtransaction of the current top transaction. If so, there
> - * is no need to change state or issue a WAL record. We already handled
> - * the case where this is true for xmax being a MultiXactId, so now check
> - * for cases where it is a plain TransactionId.
> - *
> - * Note in particular that this covers the case where we already hold
> - * exclusive lock on the tuple and the caller only wants key share or
> - * share lock. It would certainly not do to give up the exclusive lock.
> - */
> - if (!(old_infomask & (HEAP_XMAX_INVALID |
> - HEAP_XMAX_COMMITTED |
> - HEAP_XMAX_IS_MULTI)) &&
> - (mode == LockTupleKeyShare ?
> - (HEAP_XMAX_IS_KEYSHR_LOCKED(old_infomask) ||
> - HEAP_XMAX_IS_SHR_LOCKED(old_infomask) ||
> - HEAP_XMAX_IS_EXCL_LOCKED(old_infomask)) :
> - mode == LockTupleShare ?
> - (HEAP_XMAX_IS_SHR_LOCKED(old_infomask) ||
> - HEAP_XMAX_IS_EXCL_LOCKED(old_infomask)) :
> - (HEAP_XMAX_IS_EXCL_LOCKED(old_infomask))) &&
> - TransactionIdIsCurrentTransactionId(xmax))
> - {
> - LockBuffer(*buffer, BUFFER_LOCK_UNLOCK);
> - /* Probably can't hold tuple lock here, but may as well check */
> - if (have_tuple_lock)
> - UnlockTupleTuplock(relation, tid, mode);
> - return HeapTupleMayBeUpdated;
> - }
Are you sure transforming this hunk the way you did is functionally
equivalent?
> if (!MultiXactIdIsRunning(xmax))
> {
> - if (HEAP_XMAX_IS_LOCKED_ONLY(old_infomask) ||
> - TransactionIdDidAbort(MultiXactIdGetUpdateXid(xmax,
> - old_infomask)))
> + if ((HEAP_XMAX_IS_LOCKED_ONLY(old_infomask) ||
> + !TransactionIdDidCommit(MultiXactIdGetUpdateXid(xmax,
> + old_infomask))))
Heh, that's actually a (independent) bug...
What's the test coverage for these cases? It better be 110%...
Greetings,
Andres Freund
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 26+ messages in thread
* Re: BUG #8470: 9.3 locking/subtransaction performance regression
2013-09-25 13:34 BUG #8470: 9.3 locking/subtransaction performance regression os@ohmu.fi
2013-12-20 20:47 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 15:56 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 16:29 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 19:53 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-30 18:11 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Andres Freund <andres@2ndquadrant.com>
@ 2013-12-31 16:34 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-31 20:27 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
0 siblings, 1 reply; 26+ messages in thread
From: Alvaro Herrera @ 2013-12-31 16:34 UTC (permalink / raw)
To: Andres Freund <andres@2ndquadrant.com>; +Cc: os@ohmu.fi; pgsql-bugs
Andres Freund wrote:
> On 2013-12-23 16:53:00 -0300, Alvaro Herrera wrote:
> > + * This must be done before acquiring our tuple lock, to avoid
> > + * deadlocks with other transaction that are already waiting on the
> > + * lock we hold.
> > + */
> > + if (!(tp.t_data->t_infomask & HEAP_XMAX_IS_MULTI) &&
> > + TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetRawXmax(tp.t_data)))
> > + {
> > + Assert(HEAP_XMAX_IS_LOCKED_ONLY(tp.t_data->t_infomask));
> > +
> > + goto continue_deletion;
> > + }
>
> Man, the control flow in heapam.c isn't getting simpler :/. Could you
> rename the label to perform_deletion or such? It's no really continuing
> it from my POV.
I considered the idea of putting the rest of that block inside a new
"else" block. That would have the same effect. From a control flow POV
that might be simpler, not sure. Any opinions on that? I renamed the
labels for now.
> > /*
> > - * We might already hold the desired lock (or stronger), possibly under a
> > - * different subtransaction of the current top transaction. If so, there
> > - * is no need to change state or issue a WAL record. We already handled
> > - * the case where this is true for xmax being a MultiXactId, so now check
> > - * for cases where it is a plain TransactionId.
> > - *
> > - * Note in particular that this covers the case where we already hold
> > - * exclusive lock on the tuple and the caller only wants key share or
> > - * share lock. It would certainly not do to give up the exclusive lock.
> > - */
> > - if (!(old_infomask & (HEAP_XMAX_INVALID |
> > - HEAP_XMAX_COMMITTED |
> > - HEAP_XMAX_IS_MULTI)) &&
> > - (mode == LockTupleKeyShare ?
> > - (HEAP_XMAX_IS_KEYSHR_LOCKED(old_infomask) ||
> > - HEAP_XMAX_IS_SHR_LOCKED(old_infomask) ||
> > - HEAP_XMAX_IS_EXCL_LOCKED(old_infomask)) :
> > - mode == LockTupleShare ?
> > - (HEAP_XMAX_IS_SHR_LOCKED(old_infomask) ||
> > - HEAP_XMAX_IS_EXCL_LOCKED(old_infomask)) :
> > - (HEAP_XMAX_IS_EXCL_LOCKED(old_infomask))) &&
> > - TransactionIdIsCurrentTransactionId(xmax))
> > - {
> > - LockBuffer(*buffer, BUFFER_LOCK_UNLOCK);
> > - /* Probably can't hold tuple lock here, but may as well check */
> > - if (have_tuple_lock)
> > - UnlockTupleTuplock(relation, tid, mode);
> > - return HeapTupleMayBeUpdated;
> > - }
>
> Are you sure transforming this hunk the way you did is functionally
> equivalent?
It's not, actually -- with the new code, we will go to all the trouble
of setting OldestMulti, marking the buffer dirty and doing some
WAL-logging, whereas the old code wouldn't do any of that. But the new
code handles more cases and is easier to understand (at least IMV).
I considered the idea of checking whether the new Xmax we would be
setting on the tuple is the same as the Xmax the tuple already had, and
skip doing those things if so. But it didn't seem enough of a win to me
to warrant the complexity of checking (I think we'd need to check the
lock/update bits also, not just the xmax value itself.)
> > if (!MultiXactIdIsRunning(xmax))
> > {
> > - if (HEAP_XMAX_IS_LOCKED_ONLY(old_infomask) ||
> > - TransactionIdDidAbort(MultiXactIdGetUpdateXid(xmax,
> > - old_infomask)))
> > + if ((HEAP_XMAX_IS_LOCKED_ONLY(old_infomask) ||
> > + !TransactionIdDidCommit(MultiXactIdGetUpdateXid(xmax,
> > + old_infomask))))
>
> Heh, that's actually a (independent) bug...
I'm not sure it's a bug fix ... this is just additionally considering
optimizing (avoiding a multi) in the case that a transaction has crashed
without aborting; I don't think there would be any functional
difference. We would end up spuriously calling MultiXactIdExpand, but
that routine already ignores crashed updaters so it would end up
creating a singleton multi.
This doesn't seem worth a separate commit, if that's what you're
thinking. Do you disagree?
> What's the test coverage for these cases? It better be 110%...
110% is rather hard to achieve, particularly because of the cases
involving crashed transactions. Other than that I think I tested all
those paths. I will go through it again.
Thanks for the review; here's an updated version.
--
Á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-bugs
Attachments:
0001-Optimize-locking-a-tuple-already-locked-by-another-s.patch (text/x-diff, 11.8K) download
From 5553f4211e9d6159a99f3de5a21d1a29baeee73a Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Mon, 23 Dec 2013 16:07:51 -0300
Subject: [PATCH 1/6] Optimize locking a tuple already locked by another
subxact
The original coding tried to avoid locking tuples twice when other
subtransactions of the current top transaction already held the
requested lock, but the coding was bogus and some cases were slow, as
reported by Oskari Saarenmaa in bug #8470.
In order to make it work, HeapTupleSatisfiesUpdate is changed so that it
always returns HeapTupleBeingUpdated when the tuple is locked, even if
the locker is the current transaction or another subtransaction of the
current transaction; that case previously returned HeapTupleMayBeUpdated
and was handled specially by callers, but it turns out to be less
error-prone to instead have them check whether the reported lock is held
by the current transaction. That way, more optimizations are enabled in
compute_new_xmax_infomask.
The difference in performance between 9.2 and patched 9.3 is now more
reasonable -- in my measurements it is indistinguishable from noise in
the test case supplied in bug #8470 (instead of 17x worse), and up to 2x
worse in a tweaked version (instead of 56x worse).
---
contrib/pgrowlocks/pgrowlocks.c | 9 +--
src/backend/access/heap/heapam.c | 105 +++++++++++++++++++++-----------
src/backend/access/transam/multixact.c | 33 ----------
src/backend/utils/time/tqual.c | 20 +++---
src/include/access/multixact.h | 1 -
5 files changed, 82 insertions(+), 86 deletions(-)
diff --git a/contrib/pgrowlocks/pgrowlocks.c b/contrib/pgrowlocks/pgrowlocks.c
index 075d781..9ef90cd 100644
--- a/contrib/pgrowlocks/pgrowlocks.c
+++ b/contrib/pgrowlocks/pgrowlocks.c
@@ -138,14 +138,9 @@ pgrowlocks(PG_FUNCTION_ARGS)
infomask = tuple->t_data->t_infomask;
/*
- * a tuple is locked if HTSU returns BeingUpdated, and if it returns
- * MayBeUpdated but the Xmax is valid and pointing at us.
+ * A tuple is locked if HTSU returns BeingUpdated.
*/
- if (htsu == HeapTupleBeingUpdated ||
- (htsu == HeapTupleMayBeUpdated &&
- !(infomask & HEAP_XMAX_INVALID) &&
- !(infomask & HEAP_XMAX_IS_MULTI) &&
- (xmax == GetCurrentTransactionIdIfAny())))
+ if (htsu == HeapTupleBeingUpdated)
{
char **values;
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index b5977da..8523d08 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2596,6 +2596,28 @@ l1:
TransactionId xwait;
uint16 infomask;
+ /*
+ * If any subtransaction of the current top transaction already holds
+ * a lock on this tuple, (and no one else does,) we must skip sleeping
+ * on the xwait; that would lead to us sleeping on our own transaction,
+ * which is unlikely to end up well.
+ *
+ * Note we don't need to do anything about this when the xwait is a
+ * multixact, because that code is already prepared to ignore
+ * subtransactions of the current top transaction.
+ *
+ * This must be done before acquiring our tuple lock, to avoid
+ * deadlocks with other transaction that are already waiting on the
+ * lock we hold.
+ */
+ if (!(tp.t_data->t_infomask & HEAP_XMAX_IS_MULTI) &&
+ TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetRawXmax(tp.t_data)))
+ {
+ Assert(HEAP_XMAX_IS_LOCKED_ONLY(tp.t_data->t_infomask));
+
+ goto perform_deletion;
+ }
+
/* must copy state data before unlocking buffer */
xwait = HeapTupleHeaderGetRawXmax(tp.t_data);
infomask = tp.t_data->t_infomask;
@@ -2669,6 +2691,7 @@ l1:
UpdateXmaxHintBits(tp.t_data, buffer, xwait);
}
+perform_deletion:
/*
* We may overwrite if previous xmax aborted, or if it committed but
* only locked the tuple without updating it.
@@ -3089,6 +3112,30 @@ l2:
* heap_update directly.
*/
+ /*
+ * If any subtransaction of the current top transaction already holds
+ * a lock on this tuple, (and no one else does,) we must skip sleeping
+ * on the xwait; that would lead to us sleeping on our own transaction,
+ * which is unlikely to end up well.
+ *
+ * Note we don't need to do anything about this when the xwait is a
+ * multixact, because that code is already prepared to ignore
+ * subtransactions of the current top transaction.
+ *
+ * This must be done before acquiring our tuple lock, to avoid
+ * deadlocks with other transaction that are already waiting on the
+ * lock we hold.
+ */
+ if (!(oldtup.t_data->t_infomask & HEAP_XMAX_IS_MULTI) &&
+ TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetRawXmax(oldtup.t_data)))
+ {
+ Assert(HEAP_XMAX_IS_LOCKED_ONLY(oldtup.t_data->t_infomask));
+
+ can_continue = true;
+ locker_remains = true;
+ goto perform_update;
+ }
+
/* must copy state data before unlocking buffer */
xwait = HeapTupleHeaderGetRawXmax(oldtup.t_data);
infomask = oldtup.t_data->t_infomask;
@@ -3223,6 +3270,7 @@ l2:
}
}
+perform_update:
result = can_continue ? HeapTupleMayBeUpdated : HeapTupleUpdated;
}
@@ -3945,7 +3993,7 @@ l3:
TransactionId xwait;
uint16 infomask;
uint16 infomask2;
- bool require_sleep;
+ bool require_sleep = true;
ItemPointerData t_ctid;
/* must copy state data before unlocking buffer */
@@ -3997,6 +4045,22 @@ l3:
pfree(members);
}
+ else if (HEAP_XMAX_IS_LOCKED_ONLY(infomask) &&
+ TransactionIdIsCurrentTransactionId(xwait))
+ {
+ /*
+ * If we already hold a lock on this tuple, we can fall through to
+ * either create a new MultiXact including the previous lock and
+ * ours, or just keep the old lock.
+ */
+ LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE);
+ /* If xmax changed while we weren't looking, start over */
+ if ((tuple->t_data->t_infomask & HEAP_XMAX_IS_MULTI) ||
+ !TransactionIdEquals(HeapTupleHeaderGetRawXmax(tuple->t_data),
+ xwait))
+ goto l3;
+ goto perform_locking;
+ }
/*
* Acquire tuple lock to establish our priority for the tuple.
@@ -4330,6 +4394,8 @@ l3:
/* By here, we're certain that we hold buffer exclusive lock again */
+perform_locking:
+
/*
* We may lock if previous xmax aborted, or if it committed but only
* locked the tuple without updating it; or if we didn't have to wait
@@ -4365,37 +4431,6 @@ failed:
old_infomask = tuple->t_data->t_infomask;
/*
- * We might already hold the desired lock (or stronger), possibly under a
- * different subtransaction of the current top transaction. If so, there
- * is no need to change state or issue a WAL record. We already handled
- * the case where this is true for xmax being a MultiXactId, so now check
- * for cases where it is a plain TransactionId.
- *
- * Note in particular that this covers the case where we already hold
- * exclusive lock on the tuple and the caller only wants key share or
- * share lock. It would certainly not do to give up the exclusive lock.
- */
- if (!(old_infomask & (HEAP_XMAX_INVALID |
- HEAP_XMAX_COMMITTED |
- HEAP_XMAX_IS_MULTI)) &&
- (mode == LockTupleKeyShare ?
- (HEAP_XMAX_IS_KEYSHR_LOCKED(old_infomask) ||
- HEAP_XMAX_IS_SHR_LOCKED(old_infomask) ||
- HEAP_XMAX_IS_EXCL_LOCKED(old_infomask)) :
- mode == LockTupleShare ?
- (HEAP_XMAX_IS_SHR_LOCKED(old_infomask) ||
- HEAP_XMAX_IS_EXCL_LOCKED(old_infomask)) :
- (HEAP_XMAX_IS_EXCL_LOCKED(old_infomask))) &&
- TransactionIdIsCurrentTransactionId(xmax))
- {
- LockBuffer(*buffer, BUFFER_LOCK_UNLOCK);
- /* Probably can't hold tuple lock here, but may as well check */
- if (have_tuple_lock)
- UnlockTupleTuplock(relation, tid, mode);
- return HeapTupleMayBeUpdated;
- }
-
- /*
* If this is the first possibly-multixact-able operation in the current
* transaction, set my per-backend OldestMemberMXactId setting. We can be
* certain that the transaction will never become a member of any older
@@ -4622,9 +4657,9 @@ l5:
*/
if (!MultiXactIdIsRunning(xmax))
{
- if (HEAP_XMAX_IS_LOCKED_ONLY(old_infomask) ||
- TransactionIdDidAbort(MultiXactIdGetUpdateXid(xmax,
- old_infomask)))
+ if ((HEAP_XMAX_IS_LOCKED_ONLY(old_infomask) ||
+ !TransactionIdDidCommit(MultiXactIdGetUpdateXid(xmax,
+ old_infomask))))
{
/*
* Reset these bits and restart; otherwise fall through to
diff --git a/src/backend/access/transam/multixact.c b/src/backend/access/transam/multixact.c
index 03581be..55a8ca7 100644
--- a/src/backend/access/transam/multixact.c
+++ b/src/backend/access/transam/multixact.c
@@ -1275,39 +1275,6 @@ retry:
}
/*
- * MultiXactHasRunningRemoteMembers
- * Does the given multixact have still-live members from
- * transactions other than our own?
- */
-bool
-MultiXactHasRunningRemoteMembers(MultiXactId multi)
-{
- MultiXactMember *members;
- int nmembers;
- int i;
-
- nmembers = GetMultiXactIdMembers(multi, &members, true);
- if (nmembers <= 0)
- return false;
-
- for (i = 0; i < nmembers; i++)
- {
- /* not interested in our own members */
- if (TransactionIdIsCurrentTransactionId(members[i].xid))
- continue;
-
- if (TransactionIdIsInProgress(members[i].xid))
- {
- pfree(members);
- return true;
- }
- }
-
- pfree(members);
- return false;
-}
-
-/*
* mxactMemberComparator
* qsort comparison function for MultiXactMember
*
diff --git a/src/backend/utils/time/tqual.c b/src/backend/utils/time/tqual.c
index 44b4ddc..ad8c7a0 100644
--- a/src/backend/utils/time/tqual.c
+++ b/src/backend/utils/time/tqual.c
@@ -701,20 +701,20 @@ HeapTupleSatisfiesUpdate(HeapTupleHeader tuple, CommandId curcid,
if (tuple->t_infomask & HEAP_XMAX_IS_MULTI)
{
- if (MultiXactHasRunningRemoteMembers(xmax))
+ if (MultiXactIdIsRunning(xmax))
return HeapTupleBeingUpdated;
else
return HeapTupleMayBeUpdated;
}
- /* if locker is gone, all's well */
+ /*
+ * If the locker is gone, then there is nothing of interest
+ * left in this Xmax; otherwise, report the tuple as
+ * locked/updated.
+ */
if (!TransactionIdIsInProgress(xmax))
return HeapTupleMayBeUpdated;
-
- if (!TransactionIdIsCurrentTransactionId(xmax))
- return HeapTupleBeingUpdated;
- else
- return HeapTupleMayBeUpdated;
+ return HeapTupleBeingUpdated;
}
if (tuple->t_infomask & HEAP_XMAX_IS_MULTI)
@@ -726,10 +726,10 @@ HeapTupleSatisfiesUpdate(HeapTupleHeader tuple, CommandId curcid,
/* not LOCKED_ONLY, so it has to have an xmax */
Assert(TransactionIdIsValid(xmax));
- /* updating subtransaction must have aborted */
+ /* deleting subtransaction must have aborted */
if (!TransactionIdIsCurrentTransactionId(xmax))
{
- if (MultiXactHasRunningRemoteMembers(HeapTupleHeaderGetRawXmax(tuple)))
+ if (MultiXactIdIsRunning(HeapTupleHeaderGetRawXmax(tuple)))
return HeapTupleBeingUpdated;
return HeapTupleMayBeUpdated;
}
@@ -846,7 +846,7 @@ HeapTupleSatisfiesUpdate(HeapTupleHeader tuple, CommandId curcid,
if (TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetRawXmax(tuple)))
{
if (HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_infomask))
- return HeapTupleMayBeUpdated;
+ return HeapTupleBeingUpdated;
if (HeapTupleHeaderGetCmax(tuple) >= curcid)
return HeapTupleSelfUpdated; /* updated after scan started */
else
diff --git a/src/include/access/multixact.h b/src/include/access/multixact.h
index 5f82907..0e3b273 100644
--- a/src/include/access/multixact.h
+++ b/src/include/access/multixact.h
@@ -89,7 +89,6 @@ extern bool MultiXactIdIsRunning(MultiXactId multi);
extern void MultiXactIdSetOldestMember(void);
extern int GetMultiXactIdMembers(MultiXactId multi, MultiXactMember **xids,
bool allow_old);
-extern bool MultiXactHasRunningRemoteMembers(MultiXactId multi);
extern bool MultiXactIdPrecedes(MultiXactId multi1, MultiXactId multi2);
extern bool MultiXactIdPrecedesOrEquals(MultiXactId multi1,
MultiXactId multi2);
--
1.7.10.4
^ permalink raw reply [nested|flat] 26+ messages in thread
* Re: BUG #8470: 9.3 locking/subtransaction performance regression
2013-09-25 13:34 BUG #8470: 9.3 locking/subtransaction performance regression os@ohmu.fi
2013-12-20 20:47 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 15:56 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 16:29 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 19:53 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-30 18:11 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Andres Freund <andres@2ndquadrant.com>
2013-12-31 16:34 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2013-12-31 20:27 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2014-01-14 12:43 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Oskari Saarenmaa <os@ohmu.fi>
0 siblings, 1 reply; 26+ messages in thread
From: Alvaro Herrera @ 2013-12-31 20:27 UTC (permalink / raw)
To: Andres Freund <andres@2ndquadrant.com>; +Cc: os@ohmu.fi; pgsql-bugs
Alvaro Herrera wrote:
> > What's the test coverage for these cases? It better be 110%...
>
> 110% is rather hard to achieve, particularly because of the cases
> involving crashed transactions. Other than that I think I tested all
> those paths. I will go through it again.
Actually, there was a nasty bug in that formulation of the patch; in
heap_lock_tuple I mixed the "is multi" case in with the "do we own a
lock" check, which are completely unrelated and cause a number of
regressions in isolation tests. Here's a reworked version. I removed
those new labels and gotos; seems better this way.
Note there are some new blocks that need to be reflowed and pgindented;
also the diff contain some spurious whitespace changes that are undoing
some pgindent decisions. There are also some spurious changes which
have to do with a later patch I have -- the one that optimizes for
LOCK_ONLY multis. I tried to avoid including unnecessary whitespace
changes so that the actual code changes are easier to spot, but if I was
to remove them all I wouldn't have been able to submit the patch this
year, so please bear with me.
I generated the "make coverage" report after having run initdb, the
isolation tests and the regular regression tests; it shows almost all
the interesting paths here are being taken. (There are only a couple of
cases not being tested in compute_new_xmax_infomask, but they are
simpler ones. I will see about modifying one of the existing isolation
tests to cover those cases as well.)
--
Á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-bugs
Attachments:
multixact-optimize.patch (text/x-diff, 18.6K) download
*** a/contrib/pgrowlocks/pgrowlocks.c
--- b/contrib/pgrowlocks/pgrowlocks.c
***************
*** 138,151 **** pgrowlocks(PG_FUNCTION_ARGS)
infomask = tuple->t_data->t_infomask;
/*
! * a tuple is locked if HTSU returns BeingUpdated, and if it returns
! * MayBeUpdated but the Xmax is valid and pointing at us.
*/
! if (htsu == HeapTupleBeingUpdated ||
! (htsu == HeapTupleMayBeUpdated &&
! !(infomask & HEAP_XMAX_INVALID) &&
! !(infomask & HEAP_XMAX_IS_MULTI) &&
! (xmax == GetCurrentTransactionIdIfAny())))
{
char **values;
--- 138,146 ----
infomask = tuple->t_data->t_infomask;
/*
! * A tuple is locked if HTSU returns BeingUpdated.
*/
! if (htsu == HeapTupleBeingUpdated)
{
char **values;
*** a/src/backend/access/heap/heapam.c
--- b/src/backend/access/heap/heapam.c
***************
*** 2596,2601 **** l1:
--- 2596,2623 ----
TransactionId xwait;
uint16 infomask;
+ /*
+ * If any subtransaction of the current top transaction already holds
+ * a lock on this tuple, (and no one else does,) we must skip sleeping
+ * on the xwait; that would lead to us sleeping on our own transaction,
+ * which is unlikely to end up well.
+ *
+ * Note we don't need to do anything about this when the xwait is a
+ * multixact, because that code is already prepared to ignore
+ * subtransactions of the current top transaction.
+ *
+ * This must be done before acquiring our tuple lock, to avoid
+ * deadlocks with other transaction that are already waiting on the
+ * lock we hold.
+ */
+ if (!(tp.t_data->t_infomask & HEAP_XMAX_IS_MULTI) &&
+ TransactionIdIsCurrentTransactionId(
+ HeapTupleHeaderGetRawXmax(tp.t_data)))
+ {
+ Assert(HEAP_XMAX_IS_LOCKED_ONLY(tp.t_data->t_infomask));
+ }
+ else
+ {
/* must copy state data before unlocking buffer */
xwait = HeapTupleHeaderGetRawXmax(tp.t_data);
infomask = tp.t_data->t_infomask;
***************
*** 2630,2638 **** l1:
LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
/*
! * If xwait had just locked the tuple then some other xact could
! * update this tuple before we get to this point. Check for xmax
! * change, and start over if so.
*/
if (!(tp.t_data->t_infomask & HEAP_XMAX_IS_MULTI) ||
!TransactionIdEquals(HeapTupleHeaderGetRawXmax(tp.t_data),
--- 2652,2660 ----
LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
/*
! * If xwait had just locked the tuple then some other xact
! * could update this tuple before we get to this point. Check
! * for xmax change, and start over if so.
*/
if (!(tp.t_data->t_infomask & HEAP_XMAX_IS_MULTI) ||
!TransactionIdEquals(HeapTupleHeaderGetRawXmax(tp.t_data),
***************
*** 2640,2652 **** l1:
goto l1;
/*
! * You might think the multixact is necessarily done here, but not
! * so: it could have surviving members, namely our own xact or
! * other subxacts of this backend. It is legal for us to delete
! * the tuple in either case, however (the latter case is
! * essentially a situation of upgrading our former shared lock to
! * exclusive). We don't bother changing the on-disk hint bits
! * since we are about to overwrite the xmax altogether.
*/
}
else
--- 2662,2674 ----
goto l1;
/*
! * You might think the multixact is necessarily done here, but
! * not so: it could have surviving members, namely our own xact
! * or other subxacts of this backend. It is legal for us to
! * delete the tuple in either case, however (the latter case is
! * essentially a situation of upgrading our former shared lock
! * to exclusive). We don't bother changing the on-disk hint
! * bits since we are about to overwrite the xmax altogether.
*/
}
else
***************
*** 2656,2664 **** l1:
LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
/*
! * xwait is done, but if xwait had just locked the tuple then some
! * other xact could update this tuple before we get to this point.
! * Check for xmax change, and start over if so.
*/
if ((tp.t_data->t_infomask & HEAP_XMAX_IS_MULTI) ||
!TransactionIdEquals(HeapTupleHeaderGetRawXmax(tp.t_data),
--- 2678,2686 ----
LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
/*
! * xwait is done, but if xwait had just locked the tuple then
! * some other xact could update this tuple before we get to
! * this point. Check for xmax change, and start over if so.
*/
if ((tp.t_data->t_infomask & HEAP_XMAX_IS_MULTI) ||
!TransactionIdEquals(HeapTupleHeaderGetRawXmax(tp.t_data),
***************
*** 2668,2673 **** l1:
--- 2690,2696 ----
/* Otherwise check if it committed or aborted */
UpdateXmaxHintBits(tp.t_data, buffer, xwait);
}
+ }
/*
* We may overwrite if previous xmax aborted, or if it committed but
***************
*** 3070,3077 **** l2:
}
else if (result == HeapTupleBeingUpdated && wait)
{
- TransactionId xwait;
- uint16 infomask;
bool can_continue = false;
checked_lockers = true;
--- 3093,3098 ----
***************
*** 3089,3094 **** l2:
--- 3110,3143 ----
* heap_update directly.
*/
+ /*
+ * If any subtransaction of the current top transaction already holds
+ * a lock on this tuple, (and no one else does,) we must skip sleeping
+ * on the xwait; that would lead to us sleeping on our own transaction,
+ * which is unlikely to end up well.
+ *
+ * Note we don't need to do anything about this when the xwait is a
+ * multixact, because that code is already prepared to ignore
+ * subtransactions of the current top transaction.
+ *
+ * This must be done before acquiring our tuple lock, to avoid
+ * deadlocks with other transaction that are already waiting on the
+ * lock we hold.
+ */
+ if (!(oldtup.t_data->t_infomask & HEAP_XMAX_IS_MULTI) &&
+ TransactionIdIsCurrentTransactionId(
+ HeapTupleHeaderGetRawXmax(oldtup.t_data)))
+ {
+ Assert(HEAP_XMAX_IS_LOCKED_ONLY(oldtup.t_data->t_infomask));
+
+ can_continue = true;
+ locker_remains = true;
+ }
+ else
+ {
+ TransactionId xwait;
+ uint16 infomask;
+
/* must copy state data before unlocking buffer */
xwait = HeapTupleHeaderGetRawXmax(oldtup.t_data);
infomask = oldtup.t_data->t_infomask;
***************
*** 3192,3198 **** l2:
*/
if ((oldtup.t_data->t_infomask & HEAP_XMAX_IS_MULTI) ||
!TransactionIdEquals(
! HeapTupleHeaderGetRawXmax(oldtup.t_data),
xwait))
goto l2;
--- 3241,3247 ----
*/
if ((oldtup.t_data->t_infomask & HEAP_XMAX_IS_MULTI) ||
!TransactionIdEquals(
! HeapTupleHeaderGetRawXmax(oldtup.t_data),
xwait))
goto l2;
***************
*** 3212,3218 **** l2:
*/
if ((oldtup.t_data->t_infomask & HEAP_XMAX_IS_MULTI) ||
!TransactionIdEquals(
! HeapTupleHeaderGetRawXmax(oldtup.t_data),
xwait))
goto l2;
--- 3261,3267 ----
*/
if ((oldtup.t_data->t_infomask & HEAP_XMAX_IS_MULTI) ||
!TransactionIdEquals(
! HeapTupleHeaderGetRawXmax(oldtup.t_data),
xwait))
goto l2;
***************
*** 3222,3227 **** l2:
--- 3271,3277 ----
can_continue = true;
}
}
+ }
result = can_continue ? HeapTupleMayBeUpdated : HeapTupleUpdated;
}
***************
*** 3945,3951 **** l3:
TransactionId xwait;
uint16 infomask;
uint16 infomask2;
! bool require_sleep;
ItemPointerData t_ctid;
/* must copy state data before unlocking buffer */
--- 3995,4001 ----
TransactionId xwait;
uint16 infomask;
uint16 infomask2;
! bool require_sleep = true;
ItemPointerData t_ctid;
/* must copy state data before unlocking buffer */
***************
*** 3998,4003 **** l3:
--- 4048,4072 ----
pfree(members);
}
+ if (!(infomask & HEAP_XMAX_IS_MULTI) &&
+ HEAP_XMAX_IS_LOCKED_ONLY(infomask) &&
+ TransactionIdIsCurrentTransactionId(xwait))
+ {
+ /*
+ * If we already hold a lock on this tuple, (and no one else does,)
+ * no matter what the strength, we can fall through to either
+ * create a new MultiXact including the previous lock and ours, or
+ * just keep the old lock.
+ */
+ LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE);
+ /* If xmax changed while we weren't looking, start over */
+ if ((tuple->t_data->t_infomask & HEAP_XMAX_IS_MULTI) ||
+ !TransactionIdEquals(HeapTupleHeaderGetRawXmax(tuple->t_data),
+ xwait))
+ goto l3;
+ }
+ else
+ {
/*
* Acquire tuple lock to establish our priority for the tuple.
* LockTuple will release us when we are next-in-line for the tuple.
***************
*** 4014,4021 **** l3:
if (!ConditionalLockTupleTuplock(relation, tid, mode))
ereport(ERROR,
(errcode(ERRCODE_LOCK_NOT_AVAILABLE),
! errmsg("could not obtain lock on row in relation \"%s\"",
! RelationGetRelationName(relation))));
}
else
LockTupleTuplock(relation, tid, mode);
--- 4083,4090 ----
if (!ConditionalLockTupleTuplock(relation, tid, mode))
ereport(ERROR,
(errcode(ERRCODE_LOCK_NOT_AVAILABLE),
! errmsg("could not obtain lock on row in relation \"%s\"",
! RelationGetRelationName(relation))));
}
else
LockTupleTuplock(relation, tid, mode);
***************
*** 4144,4150 **** l3:
* been the case, HeapTupleSatisfiesUpdate would have returned
* MayBeUpdated and we wouldn't be here.
*/
! nmembers = GetMultiXactIdMembers(xwait, &members, false);
if (nmembers <= 0)
{
--- 4213,4220 ----
* been the case, HeapTupleSatisfiesUpdate would have returned
* MayBeUpdated and we wouldn't be here.
*/
! nmembers =
! GetMultiXactIdMembers(xwait, &members, false);
if (nmembers <= 0)
{
***************
*** 4175,4181 **** l3:
*/
LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE);
if (!(tuple->t_data->t_infomask & HEAP_XMAX_IS_MULTI) ||
! !TransactionIdEquals(HeapTupleHeaderGetRawXmax(tuple->t_data),
xwait))
{
pfree(members);
--- 4245,4252 ----
*/
LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE);
if (!(tuple->t_data->t_infomask & HEAP_XMAX_IS_MULTI) ||
! !TransactionIdEquals(
! HeapTupleHeaderGetRawXmax(tuple->t_data),
xwait))
{
pfree(members);
***************
*** 4195,4201 **** l3:
/* if the xmax changed in the meantime, start over */
if ((tuple->t_data->t_infomask & HEAP_XMAX_IS_MULTI) ||
!TransactionIdEquals(
! HeapTupleHeaderGetRawXmax(tuple->t_data),
xwait))
goto l3;
/* otherwise, we're good */
--- 4266,4272 ----
/* if the xmax changed in the meantime, start over */
if ((tuple->t_data->t_infomask & HEAP_XMAX_IS_MULTI) ||
!TransactionIdEquals(
! HeapTupleHeaderGetRawXmax(tuple->t_data),
xwait))
goto l3;
/* otherwise, we're good */
***************
*** 4259,4265 **** l3:
*/
if (!(tuple->t_data->t_infomask & HEAP_XMAX_IS_MULTI) ||
!TransactionIdEquals(
! HeapTupleHeaderGetRawXmax(tuple->t_data),
xwait))
goto l3;
--- 4330,4336 ----
*/
if (!(tuple->t_data->t_infomask & HEAP_XMAX_IS_MULTI) ||
!TransactionIdEquals(
! HeapTupleHeaderGetRawXmax(tuple->t_data),
xwait))
goto l3;
***************
*** 4314,4320 **** l3:
*/
if ((tuple->t_data->t_infomask & HEAP_XMAX_IS_MULTI) ||
!TransactionIdEquals(
! HeapTupleHeaderGetRawXmax(tuple->t_data),
xwait))
goto l3;
--- 4385,4391 ----
*/
if ((tuple->t_data->t_infomask & HEAP_XMAX_IS_MULTI) ||
!TransactionIdEquals(
! HeapTupleHeaderGetRawXmax(tuple->t_data),
xwait))
goto l3;
***************
*** 4327,4332 **** l3:
--- 4398,4404 ----
UpdateXmaxHintBits(tuple->t_data, *buffer, xwait);
}
}
+ }
/* By here, we're certain that we hold buffer exclusive lock again */
***************
*** 4365,4401 **** failed:
old_infomask = tuple->t_data->t_infomask;
/*
- * We might already hold the desired lock (or stronger), possibly under a
- * different subtransaction of the current top transaction. If so, there
- * is no need to change state or issue a WAL record. We already handled
- * the case where this is true for xmax being a MultiXactId, so now check
- * for cases where it is a plain TransactionId.
- *
- * Note in particular that this covers the case where we already hold
- * exclusive lock on the tuple and the caller only wants key share or
- * share lock. It would certainly not do to give up the exclusive lock.
- */
- if (!(old_infomask & (HEAP_XMAX_INVALID |
- HEAP_XMAX_COMMITTED |
- HEAP_XMAX_IS_MULTI)) &&
- (mode == LockTupleKeyShare ?
- (HEAP_XMAX_IS_KEYSHR_LOCKED(old_infomask) ||
- HEAP_XMAX_IS_SHR_LOCKED(old_infomask) ||
- HEAP_XMAX_IS_EXCL_LOCKED(old_infomask)) :
- mode == LockTupleShare ?
- (HEAP_XMAX_IS_SHR_LOCKED(old_infomask) ||
- HEAP_XMAX_IS_EXCL_LOCKED(old_infomask)) :
- (HEAP_XMAX_IS_EXCL_LOCKED(old_infomask))) &&
- TransactionIdIsCurrentTransactionId(xmax))
- {
- LockBuffer(*buffer, BUFFER_LOCK_UNLOCK);
- /* Probably can't hold tuple lock here, but may as well check */
- if (have_tuple_lock)
- UnlockTupleTuplock(relation, tid, mode);
- return HeapTupleMayBeUpdated;
- }
-
- /*
* If this is the first possibly-multixact-able operation in the current
* transaction, set my per-backend OldestMemberMXactId setting. We can be
* certain that the transaction will never become a member of any older
--- 4437,4442 ----
***************
*** 4622,4630 **** l5:
*/
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
--- 4663,4671 ----
*/
if (!MultiXactIdIsRunning(xmax))
{
! if ((HEAP_XMAX_IS_LOCKED_ONLY(old_infomask) ||
! !TransactionIdDidCommit(MultiXactIdGetUpdateXid(xmax,
! old_infomask))))
{
/*
* Reset these bits and restart; otherwise fall through to
*** a/src/backend/access/transam/multixact.c
--- b/src/backend/access/transam/multixact.c
***************
*** 1275,1313 **** retry:
}
/*
- * MultiXactHasRunningRemoteMembers
- * Does the given multixact have still-live members from
- * transactions other than our own?
- */
- bool
- MultiXactHasRunningRemoteMembers(MultiXactId multi)
- {
- MultiXactMember *members;
- int nmembers;
- int i;
-
- nmembers = GetMultiXactIdMembers(multi, &members, true);
- if (nmembers <= 0)
- return false;
-
- for (i = 0; i < nmembers; i++)
- {
- /* not interested in our own members */
- if (TransactionIdIsCurrentTransactionId(members[i].xid))
- continue;
-
- if (TransactionIdIsInProgress(members[i].xid))
- {
- pfree(members);
- return true;
- }
- }
-
- pfree(members);
- return false;
- }
-
- /*
* mxactMemberComparator
* qsort comparison function for MultiXactMember
*
--- 1275,1280 ----
*** a/src/backend/utils/time/tqual.c
--- b/src/backend/utils/time/tqual.c
***************
*** 701,720 **** HeapTupleSatisfiesUpdate(HeapTupleHeader tuple, CommandId curcid,
if (tuple->t_infomask & HEAP_XMAX_IS_MULTI)
{
! if (MultiXactHasRunningRemoteMembers(xmax))
return HeapTupleBeingUpdated;
else
return HeapTupleMayBeUpdated;
}
! /* if locker is gone, all's well */
if (!TransactionIdIsInProgress(xmax))
return HeapTupleMayBeUpdated;
!
! if (!TransactionIdIsCurrentTransactionId(xmax))
! return HeapTupleBeingUpdated;
! else
! return HeapTupleMayBeUpdated;
}
if (tuple->t_infomask & HEAP_XMAX_IS_MULTI)
--- 701,720 ----
if (tuple->t_infomask & HEAP_XMAX_IS_MULTI)
{
! if (MultiXactIdIsRunning(xmax))
return HeapTupleBeingUpdated;
else
return HeapTupleMayBeUpdated;
}
! /*
! * If the locker is gone, then there is nothing of interest
! * left in this Xmax; otherwise, report the tuple as
! * locked/updated.
! */
if (!TransactionIdIsInProgress(xmax))
return HeapTupleMayBeUpdated;
! return HeapTupleBeingUpdated;
}
if (tuple->t_infomask & HEAP_XMAX_IS_MULTI)
***************
*** 726,735 **** HeapTupleSatisfiesUpdate(HeapTupleHeader tuple, CommandId curcid,
/* not LOCKED_ONLY, so it has to have an xmax */
Assert(TransactionIdIsValid(xmax));
! /* updating subtransaction must have aborted */
if (!TransactionIdIsCurrentTransactionId(xmax))
{
! if (MultiXactHasRunningRemoteMembers(HeapTupleHeaderGetRawXmax(tuple)))
return HeapTupleBeingUpdated;
return HeapTupleMayBeUpdated;
}
--- 726,735 ----
/* not LOCKED_ONLY, so it has to have an xmax */
Assert(TransactionIdIsValid(xmax));
! /* deleting subtransaction must have aborted */
if (!TransactionIdIsCurrentTransactionId(xmax))
{
! if (MultiXactIdIsRunning(HeapTupleHeaderGetRawXmax(tuple)))
return HeapTupleBeingUpdated;
return HeapTupleMayBeUpdated;
}
***************
*** 846,852 **** HeapTupleSatisfiesUpdate(HeapTupleHeader tuple, CommandId curcid,
if (TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetRawXmax(tuple)))
{
if (HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_infomask))
! return HeapTupleMayBeUpdated;
if (HeapTupleHeaderGetCmax(tuple) >= curcid)
return HeapTupleSelfUpdated; /* updated after scan started */
else
--- 846,852 ----
if (TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetRawXmax(tuple)))
{
if (HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_infomask))
! return HeapTupleBeingUpdated;
if (HeapTupleHeaderGetCmax(tuple) >= curcid)
return HeapTupleSelfUpdated; /* updated after scan started */
else
*** a/src/include/access/multixact.h
--- b/src/include/access/multixact.h
***************
*** 89,95 **** extern bool MultiXactIdIsRunning(MultiXactId multi);
extern void MultiXactIdSetOldestMember(void);
extern int GetMultiXactIdMembers(MultiXactId multi, MultiXactMember **xids,
bool allow_old);
- extern bool MultiXactHasRunningRemoteMembers(MultiXactId multi);
extern bool MultiXactIdPrecedes(MultiXactId multi1, MultiXactId multi2);
extern bool MultiXactIdPrecedesOrEquals(MultiXactId multi1,
MultiXactId multi2);
--- 89,94 ----
^ permalink raw reply [nested|flat] 26+ messages in thread
* Re: BUG #8470: 9.3 locking/subtransaction performance regression
2013-09-25 13:34 BUG #8470: 9.3 locking/subtransaction performance regression os@ohmu.fi
2013-12-20 20:47 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 15:56 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 16:29 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 19:53 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-30 18:11 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Andres Freund <andres@2ndquadrant.com>
2013-12-31 16:34 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-31 20:27 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2014-01-14 12:43 ` Oskari Saarenmaa <os@ohmu.fi>
2014-01-14 13:09 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2015-01-05 17:23 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2015-04-10 16:57 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
0 siblings, 3 replies; 26+ messages in thread
From: Oskari Saarenmaa @ 2014-01-14 12:43 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Andres Freund <andres@2ndquadrant.com>; pgsql-bugs
Thanks for looking at this and sorry about the late reply, I finally got
around to testing your latest patch.
20.12.2013 22:47, Alvaro Herrera kirjoitti:
>> 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 didn't try this patch, but I built today's REL9_3_STABLE with the patch
from your mail on the 31st of Dec
(http://github.com/saaros/postgres/tree/alvaro-multixact-optimize-9.3) and
ran the older version of my appliaction's test suite which has a case that
times out after 3 minutes with unpatched 9.3. With the current patch the
test case successfully completes in ~20 seconds which is a major improvement
although it's still slower than 9.2 It also passes all other test cases in
my test suite.
Do you think it'll make it to 9.3.3?
Thanks,
Oskari
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 26+ messages in thread
* Re: BUG #8470: 9.3 locking/subtransaction performance regression
2013-09-25 13:34 BUG #8470: 9.3 locking/subtransaction performance regression os@ohmu.fi
2013-12-20 20:47 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 15:56 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 16:29 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 19:53 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-30 18:11 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Andres Freund <andres@2ndquadrant.com>
2013-12-31 16:34 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-31 20:27 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2014-01-14 12:43 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Oskari Saarenmaa <os@ohmu.fi>
@ 2014-01-14 13:09 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2014-02-12 06:36 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Tomonari Katsumata <katsumata.tomonari@po.ntts.co.jp>
2 siblings, 1 reply; 26+ messages in thread
From: Alvaro Herrera @ 2014-01-14 13:09 UTC (permalink / raw)
To: Oskari Saarenmaa <os@ohmu.fi>; +Cc: Andres Freund <andres@2ndquadrant.com>; pgsql-bugs
Oskari Saarenmaa wrote:
> Thanks for looking at this and sorry about the late reply, I finally got
> around to testing your latest patch.
>
> 20.12.2013 22:47, Alvaro Herrera kirjoitti:
> >> 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 didn't try this patch, but I built today's REL9_3_STABLE with the patch
> from your mail on the 31st of Dec
> (http://github.com/saaros/postgres/tree/alvaro-multixact-optimize-9.3) and
> ran the older version of my appliaction's test suite which has a case that
> times out after 3 minutes with unpatched 9.3. With the current patch the
> test case successfully completes in ~20 seconds which is a major improvement
> although it's still slower than 9.2 It also passes all other test cases in
> my test suite.
>
> Do you think it'll make it to 9.3.3?
Well, I gave this patch a long, careful look and eventually noticed that
there was a rather subtle but serious design bug in it, and I had to
ditch it. I have the intention to come back to this problem again
later, but right now I cannot.
I'm not sure whether I will have something for 9.3.3, but it's not
likely because that'll happen only in a week or two.
--
Á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-bugs
^ permalink raw reply [nested|flat] 26+ messages in thread
* Re: BUG #8470: 9.3 locking/subtransaction performance regression
2013-09-25 13:34 BUG #8470: 9.3 locking/subtransaction performance regression os@ohmu.fi
2013-12-20 20:47 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 15:56 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 16:29 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 19:53 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-30 18:11 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Andres Freund <andres@2ndquadrant.com>
2013-12-31 16:34 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-31 20:27 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2014-01-14 12:43 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Oskari Saarenmaa <os@ohmu.fi>
2014-01-14 13:09 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2014-02-12 06:36 ` Tomonari Katsumata <katsumata.tomonari@po.ntts.co.jp>
0 siblings, 0 replies; 26+ messages in thread
From: Tomonari Katsumata @ 2014-02-12 06:36 UTC (permalink / raw)
To: pgsql-bugs
Hi,
I don't understand about this problem, but
it seems this problem is still remaining in 93_STABLE(*).
(*)f1e522696fbc01b5c8a41dbd45d6cbae229be425
9.3.2 : 4.225(s)
93_STABE: 2.819(s)
9.2.6 : 0.135(s)
93_STABLE is faster than 9.3.2, but it's apparently
slower than 9.2.6.
9.3.3 is going to be released in next week.
Will any fixes be included in 9.3.3?
regards,
-----------
Tomonari Katsumata
(2014/01/14 22:09), Alvaro Herrera wrote:
> Oskari Saarenmaa wrote:
>> Thanks for looking at this and sorry about the late reply, I finally got
>> around to testing your latest patch.
>>
>> 20.12.2013 22:47, Alvaro Herrera kirjoitti:
>>>> 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 didn't try this patch, but I built today's REL9_3_STABLE with the
patch
>> from your mail on the 31st of Dec
>>
(http://github.com/saaros/postgres/tree/alvaro-multixact-optimize-9.3) and
>> ran the older version of my appliaction's test suite which has a
case that
>> times out after 3 minutes with unpatched 9.3. With the current
patch the
>> test case successfully completes in ~20 seconds which is a major
improvement
>> although it's still slower than 9.2 It also passes all other test
cases in
>> my test suite.
>>
>> Do you think it'll make it to 9.3.3?
>
> Well, I gave this patch a long, careful look and eventually noticed that
> there was a rather subtle but serious design bug in it, and I had to
> ditch it. I have the intention to come back to this problem again
> later, but right now I cannot.
>
> I'm not sure whether I will have something for 9.3.3, but it's not
> likely because that'll happen only in a week or two.
>
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 26+ messages in thread
* Re: BUG #8470: 9.3 locking/subtransaction performance regression
2013-09-25 13:34 BUG #8470: 9.3 locking/subtransaction performance regression os@ohmu.fi
2013-12-20 20:47 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 15:56 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 16:29 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 19:53 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-30 18:11 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Andres Freund <andres@2ndquadrant.com>
2013-12-31 16:34 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-31 20:27 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2014-01-14 12:43 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Oskari Saarenmaa <os@ohmu.fi>
@ 2015-01-05 17:23 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2015-04-02 00:56 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Bruce Momjian <bruce@momjian.us>
2 siblings, 1 reply; 26+ messages in thread
From: Alvaro Herrera @ 2015-01-05 17:23 UTC (permalink / raw)
To: Oskari Saarenmaa <os@ohmu.fi>; +Cc: Andres Freund <andres@2ndquadrant.com>; pgsql-bugs
I just got around to merging this patch to 9.5 sources. I'm glad I
did it because in the course of doing so I noticed a bug in a recent
patch, which led to commit d5e3d1e969d2f65009f718d3100d6565f47f9112
(back-patched to 9.3).
I'm now more confident in this code and will probably push this a few
days, but only to 9.5 at least for now. It probably won't apply cleanly
to 9.3 due to other changes in the area, such as 05315498012530d44cd89a2
and df630b0dd5ea2de52972d456f5978a012436115e and others.
--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
optimize-locking-locked-multi-5.patch (text/x-diff, 24.1K) download
diff --git a/contrib/pgrowlocks/pgrowlocks.c b/contrib/pgrowlocks/pgrowlocks.c
index 36974f7..88f7137 100644
--- a/contrib/pgrowlocks/pgrowlocks.c
+++ b/contrib/pgrowlocks/pgrowlocks.c
@@ -136,14 +136,9 @@ pgrowlocks(PG_FUNCTION_ARGS)
infomask = tuple->t_data->t_infomask;
/*
- * a tuple is locked if HTSU returns BeingUpdated, and if it returns
- * MayBeUpdated but the Xmax is valid and pointing at us.
+ * A tuple is locked if HTSU returns BeingUpdated.
*/
- if (htsu == HeapTupleBeingUpdated ||
- (htsu == HeapTupleMayBeUpdated &&
- !(infomask & HEAP_XMAX_INVALID) &&
- !(infomask & HEAP_XMAX_IS_MULTI) &&
- (xmax == GetCurrentTransactionIdIfAny())))
+ if (htsu == HeapTupleBeingUpdated)
{
char **values;
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 24e300c..e351a96 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2694,42 +2694,47 @@ l1:
xwait = HeapTupleHeaderGetRawXmax(tp.t_data);
infomask = tp.t_data->t_infomask;
- LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
-
/*
- * Acquire tuple lock to establish our priority for the tuple (see
- * heap_lock_tuple). LockTuple will release us when we are
- * next-in-line for the tuple.
+ * Sleep until concurrent transaction ends -- except when there's a single
+ * locker and it's our own transaction. Note we don't care
+ * which lock mode the locker has, because we need the strongest one.
+ *
+ * Before sleeping, we need to acquire tuple lock to establish our
+ * priority for the tuple (see heap_lock_tuple). LockTuple will
+ * release us when we are next-in-line for the tuple.
*
* If we are forced to "start over" below, we keep the tuple lock;
* this arranges that we stay at the head of the line while rechecking
* tuple state.
*/
- heap_acquire_tuplock(relation, &(tp.t_self), LockTupleExclusive,
- LockWaitBlock, &have_tuple_lock);
-
- /*
- * Sleep until concurrent transaction ends. Note that we don't care
- * which lock mode the locker has, because we need the strongest one.
- */
-
if (infomask & HEAP_XMAX_IS_MULTI)
{
/* wait for multixact */
- MultiXactIdWait((MultiXactId) xwait, MultiXactStatusUpdate, infomask,
- relation, &tp.t_data->t_ctid, XLTW_Delete,
- NULL);
- LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
+ if (DoesMultiXactIdConflict((MultiXactId) xwait, infomask,
+ LockTupleExclusive))
+ {
+ LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
- /*
- * If xwait had just locked the tuple then some other xact could
- * update this tuple before we get to this point. Check for xmax
- * change, and start over if so.
- */
- if (xmax_infomask_changed(tp.t_data->t_infomask, infomask) ||
- !TransactionIdEquals(HeapTupleHeaderGetRawXmax(tp.t_data),
- xwait))
- goto l1;
+ /* acquire tuple lock, if necessary */
+ heap_acquire_tuplock(relation, &(tp.t_self), LockTupleExclusive,
+ LockWaitBlock, &have_tuple_lock);
+
+ /* wait for multixact */
+ MultiXactIdWait((MultiXactId) xwait, MultiXactStatusUpdate, infomask,
+ relation, &tp.t_data->t_ctid, XLTW_Delete,
+ NULL);
+ LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
+
+ /*
+ * If xwait had just locked the tuple then some other xact
+ * could update this tuple before we get to this point. Check
+ * for xmax change, and start over if so.
+ */
+ if (xmax_infomask_changed(tp.t_data->t_infomask, infomask) ||
+ !TransactionIdEquals(HeapTupleHeaderGetRawXmax(tp.t_data),
+ xwait))
+ goto l1;
+ }
/*
* You might think the multixact is necessarily done here, but not
@@ -2741,9 +2746,15 @@ l1:
* since we are about to overwrite the xmax altogether.
*/
}
- else
+ else if (!TransactionIdIsCurrentTransactionId(xwait))
{
- /* wait for regular transaction to end */
+ /*
+ * Wait for regular transaction to end; but first, acquire
+ * tuple lock.
+ */
+ LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
+ heap_acquire_tuplock(relation, &(tp.t_self), LockTupleExclusive,
+ LockWaitBlock, &have_tuple_lock);
XactLockTableWait(xwait, relation, &tp.t_data->t_ctid, XLTW_Delete);
LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
@@ -3223,8 +3234,6 @@ l2:
xwait = HeapTupleHeaderGetRawXmax(oldtup.t_data);
infomask = oldtup.t_data->t_infomask;
- LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
-
/*
* Now we have to do something about the existing locker. If it's a
* multi, sleep on it; we might be awakened before it is completely
@@ -3252,28 +3261,32 @@ l2:
TransactionId update_xact;
int remain;
- /* acquire tuple lock, if necessary */
- if (DoesMultiXactIdConflict((MultiXactId) xwait, infomask, *lockmode))
+ if (DoesMultiXactIdConflict((MultiXactId) xwait, infomask,
+ *lockmode))
{
+ LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
+
+ /* acquire tuple lock, if necessary */
heap_acquire_tuplock(relation, &(oldtup.t_self), *lockmode,
LockWaitBlock, &have_tuple_lock);
- }
- /* wait for multixact */
- MultiXactIdWait((MultiXactId) xwait, mxact_status, infomask,
- relation, &oldtup.t_data->t_ctid, XLTW_Update,
- &remain);
- LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
+ /* wait for multixact */
+ MultiXactIdWait((MultiXactId) xwait, mxact_status, infomask,
+ relation, &oldtup.t_data->t_ctid, XLTW_Update,
+ &remain);
+ LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
- /*
- * If xwait had just locked the tuple then some other xact could
- * update this tuple before we get to this point. Check for xmax
- * change, and start over if so.
- */
- if (xmax_infomask_changed(oldtup.t_data->t_infomask, infomask) ||
- !TransactionIdEquals(HeapTupleHeaderGetRawXmax(oldtup.t_data),
- xwait))
- goto l2;
+ /*
+ * If xwait had just locked the tuple then some other xact
+ * could update this tuple before we get to this point. Check
+ * for xmax change, and start over if so.
+ */
+ if (xmax_infomask_changed(oldtup.t_data->t_infomask,
+ infomask) ||
+ !TransactionIdEquals(HeapTupleHeaderGetRawXmax(oldtup.t_data),
+ xwait))
+ goto l2;
+ }
/*
* Note that the multixact may not be done by now. It could have
@@ -3309,58 +3322,52 @@ l2:
locker_remains = remain != 0;
}
+ else if (TransactionIdIsCurrentTransactionId(xwait))
+ {
+ /*
+ * The only locker is ourselves; we can avoid grabbing the tuple
+ * lock here, but must preserve our locking information.
+ */
+ can_continue = true;
+ locker_remains = true;
+ }
+ else if (HEAP_XMAX_IS_KEYSHR_LOCKED(infomask) && key_intact)
+ {
+ /*
+ * If it's just a key-share locker, and we're not changing the
+ * key columns, we don't need to wait for it to end; but we
+ * need to preserve it as locker.
+ */
+ can_continue = true;
+ locker_remains = true;
+ }
else
{
/*
- * If it's just a key-share locker, and we're not changing the key
- * columns, we don't need to wait for it to end; but we need to
- * preserve it as locker.
+ * Wait for regular transaction to end; but first, acquire
+ * tuple lock.
*/
- if (HEAP_XMAX_IS_KEYSHR_LOCKED(infomask) && key_intact)
- {
- LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
+ LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
+ heap_acquire_tuplock(relation, &(oldtup.t_self), *lockmode,
+ LockWaitBlock, &have_tuple_lock);
+ XactLockTableWait(xwait, relation, &oldtup.t_data->t_ctid,
+ XLTW_Update);
+ LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
- /*
- * recheck the locker; if someone else changed the tuple while
- * we weren't looking, start over.
- */
- if (xmax_infomask_changed(oldtup.t_data->t_infomask, infomask) ||
- !TransactionIdEquals(
- HeapTupleHeaderGetRawXmax(oldtup.t_data),
- xwait))
- goto l2;
+ /*
+ * xwait is done, but if xwait had just locked the tuple then some
+ * other xact could update this tuple before we get to this point.
+ * Check for xmax change, and start over if so.
+ */
+ if (xmax_infomask_changed(oldtup.t_data->t_infomask, infomask) ||
+ !TransactionIdEquals(xwait,
+ HeapTupleHeaderGetRawXmax(oldtup.t_data)))
+ goto l2;
+ /* Otherwise check if it committed or aborted */
+ UpdateXmaxHintBits(oldtup.t_data, buffer, xwait);
+ if (oldtup.t_data->t_infomask & HEAP_XMAX_INVALID)
can_continue = true;
- locker_remains = true;
- }
- else
- {
- /*
- * Wait for regular transaction to end; but first, acquire
- * tuple lock.
- */
- heap_acquire_tuplock(relation, &(oldtup.t_self), *lockmode,
- LockWaitBlock, &have_tuple_lock);
- XactLockTableWait(xwait, relation, &oldtup.t_data->t_ctid,
- XLTW_Update);
- LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
-
- /*
- * xwait is done, but if xwait had just locked the tuple then
- * some other xact could update this tuple before we get to
- * this point. Check for xmax change, and start over if so.
- */
- if (xmax_infomask_changed(oldtup.t_data->t_infomask, infomask) ||
- !TransactionIdEquals(
- HeapTupleHeaderGetRawXmax(oldtup.t_data),
- xwait))
- goto l2;
-
- /* Otherwise check if it committed or aborted */
- UpdateXmaxHintBits(oldtup.t_data, buffer, xwait);
- if (oldtup.t_data->t_infomask & HEAP_XMAX_INVALID)
- can_continue = true;
- }
}
result = can_continue ? HeapTupleMayBeUpdated : HeapTupleUpdated;
@@ -4097,6 +4104,7 @@ heap_lock_tuple(Relation relation, HeapTuple tuple,
uint16 old_infomask,
new_infomask,
new_infomask2;
+ bool first_time = true;
bool have_tuple_lock = false;
*buffer = ReadBuffer(relation, ItemPointerGetBlockNumber(tid));
@@ -4136,47 +4144,77 @@ l3:
/*
* If any subtransaction of the current top transaction already holds
- * a lock as strong or stronger than what we're requesting, we
+ * a lock as strong as or stronger than what we're requesting, we
* effectively hold the desired lock already. We *must* succeed
* without trying to take the tuple lock, else we will deadlock
* against anyone wanting to acquire a stronger lock.
+ *
+ * Note we only do this the first time we loop on the HTSU result;
+ * there is no point in testing in subsequent passes, because
+ * evidently our own transaction cannot have acquired a new lock after
+ * the first time we checked.
*/
- if (infomask & HEAP_XMAX_IS_MULTI)
+ if (first_time)
{
- int i;
- int nmembers;
- MultiXactMember *members;
-
- /*
- * We don't need to allow old multixacts here; if that had been
- * the case, HeapTupleSatisfiesUpdate would have returned
- * MayBeUpdated and we wouldn't be here.
- */
- nmembers =
- GetMultiXactIdMembers(xwait, &members, false,
- HEAP_XMAX_IS_LOCKED_ONLY(infomask));
+ first_time = false;
- for (i = 0; i < nmembers; i++)
+ if (infomask & HEAP_XMAX_IS_MULTI)
{
- if (TransactionIdIsCurrentTransactionId(members[i].xid))
- {
- LockTupleMode membermode;
+ int i;
+ int nmembers;
+ MultiXactMember *members;
- membermode = TUPLOCK_from_mxstatus(members[i].status);
+ /*
+ * We don't need to allow old multixacts here; if that had
+ * been the case, HeapTupleSatisfiesUpdate would have returned
+ * MayBeUpdated and we wouldn't be here.
+ */
+ nmembers =
+ GetMultiXactIdMembers(xwait, &members, false,
+ HEAP_XMAX_IS_LOCKED_ONLY(infomask));
- if (membermode >= mode)
- {
- if (have_tuple_lock)
- UnlockTupleTuplock(relation, tid, mode);
+ for (i = 0; i < nmembers; i++)
+ {
+ /* only consider members of our own transaction */
+ if (!TransactionIdIsCurrentTransactionId(members[i].xid))
+ continue;
+ if (TUPLOCK_from_mxstatus(members[i].status) >= mode)
+ {
pfree(members);
return HeapTupleMayBeUpdated;
}
}
- }
- if (members)
- pfree(members);
+ if (members)
+ pfree(members);
+ }
+ else if (TransactionIdIsCurrentTransactionId(xwait))
+ {
+ switch (mode)
+ {
+ case LockTupleKeyShare:
+ Assert(HEAP_XMAX_IS_KEYSHR_LOCKED(infomask) ||
+ HEAP_XMAX_IS_SHR_LOCKED(infomask) ||
+ HEAP_XMAX_IS_EXCL_LOCKED(infomask));
+ return HeapTupleMayBeUpdated;
+ break;
+ case LockTupleShare:
+ if (HEAP_XMAX_IS_SHR_LOCKED(infomask) ||
+ HEAP_XMAX_IS_EXCL_LOCKED(infomask))
+ return HeapTupleMayBeUpdated;
+ break;
+ case LockTupleNoKeyExclusive:
+ if (HEAP_XMAX_IS_EXCL_LOCKED(infomask))
+ return HeapTupleMayBeUpdated;
+ break;
+ case LockTupleExclusive:
+ if (HEAP_XMAX_IS_EXCL_LOCKED(infomask) &&
+ infomask2 & HEAP_KEYS_UPDATED)
+ return HeapTupleMayBeUpdated;
+ break;
+ }
+ }
}
/*
@@ -4323,6 +4361,31 @@ l3:
}
/*
+ * As a check independent from those above, we can also avoid sleeping
+ * if the current transaction is the sole locker of the tuple. Note
+ * that the strength of the lock already held is irrelevant; this is
+ * not about recording the lock in Xmax (which will be done regardless
+ * of this optimization, below). Also, note that the cases where we
+ * hold a lock stronger than we are requesting are already handled
+ * above by not doing anything.
+ *
+ * Note we only deal with the non-multixact case here; MultiXactIdWait
+ * is well equipped to deal with this situation on its own.
+ */
+ if (require_sleep && !(infomask & HEAP_XMAX_IS_MULTI) &&
+ TransactionIdIsCurrentTransactionId(xwait))
+ {
+ /* ... but if the xmax changed in the meantime, start over */
+ LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE);
+ if (xmax_infomask_changed(tuple->t_data->t_infomask, infomask) ||
+ !TransactionIdEquals(HeapTupleHeaderGetRawXmax(tuple->t_data),
+ xwait))
+ goto l3;
+ Assert(HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_data->t_infomask));
+ require_sleep = false;
+ }
+
+ /*
* By here, we either have already acquired the buffer exclusive lock,
* or we must wait for the locking transaction or multixact; so below
* we ensure that we grab buffer lock after the sleep.
@@ -4331,9 +4394,9 @@ l3:
if (require_sleep)
{
/*
- * Acquire tuple lock to establish our priority for the tuple.
- * LockTuple will release us when we are next-in-line for the tuple.
- * We must do this even if we are share-locking.
+ * Acquire tuple lock to establish our priority for the tuple, or
+ * die trying. LockTuple will release us when we are next-in-line
+ * for the tuple. We must do this even if we are share-locking.
*
* If we are forced to "start over" below, we keep the tuple lock;
* this arranges that we stay at the head of the line while rechecking
@@ -4390,37 +4453,6 @@ l3:
break;
}
- /* if there are updates, follow the update chain */
- if (follow_updates &&
- !HEAP_XMAX_IS_LOCKED_ONLY(infomask))
- {
- HTSU_Result res;
-
- res = heap_lock_updated_tuple(relation, tuple, &t_ctid,
- GetCurrentTransactionId(),
- mode);
- if (res != HeapTupleMayBeUpdated)
- {
- result = res;
- /* recovery code expects to have buffer lock held */
- LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE);
- goto failed;
- }
- }
-
- LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE);
-
- /*
- * If xwait had just locked the tuple then some other xact
- * could update this tuple before we get to this point. Check
- * for xmax change, and start over if so.
- */
- if (xmax_infomask_changed(tuple->t_data->t_infomask, infomask) ||
- !TransactionIdEquals(
- HeapTupleHeaderGetRawXmax(tuple->t_data),
- xwait))
- goto l3;
-
/*
* Of course, the multixact might not be done here: if we're
* requesting a light lock mode, other transactions with light
@@ -4457,43 +4489,46 @@ l3:
RelationGetRelationName(relation))));
break;
}
+ }
- /* if there are updates, follow the update chain */
- if (follow_updates &&
- !HEAP_XMAX_IS_LOCKED_ONLY(infomask))
- {
- HTSU_Result res;
+ /* if there are updates, follow the update chain */
+ if (follow_updates && !HEAP_XMAX_IS_LOCKED_ONLY(infomask))
+ {
+ HTSU_Result res;
- res = heap_lock_updated_tuple(relation, tuple, &t_ctid,
- GetCurrentTransactionId(),
- mode);
- if (res != HeapTupleMayBeUpdated)
- {
- result = res;
- /* recovery code expects to have buffer lock held */
- LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE);
- goto failed;
- }
+ res = heap_lock_updated_tuple(relation, tuple, &t_ctid,
+ GetCurrentTransactionId(),
+ mode);
+ if (res != HeapTupleMayBeUpdated)
+ {
+ result = res;
+ /* recovery code expects to have buffer lock held */
+ LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE);
+ goto failed;
}
+ }
- LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE);
+ LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE);
- /*
- * xwait is done, but if xwait had just locked the tuple then
- * some other xact could update this tuple before we get to
- * this point. Check for xmax change, and start over if so.
- */
- if (xmax_infomask_changed(tuple->t_data->t_infomask, infomask) ||
- !TransactionIdEquals(
- HeapTupleHeaderGetRawXmax(tuple->t_data),
- xwait))
- goto l3;
+ /*
+ * xwait is done, but if xwait had just locked the tuple then
+ * some other xact could update this tuple before we get to
+ * this point. Check for xmax change, and start over if so.
+ */
+ if (xmax_infomask_changed(tuple->t_data->t_infomask, infomask) ||
+ !TransactionIdEquals(HeapTupleHeaderGetRawXmax(tuple->t_data),
+ xwait))
+ goto l3;
+ if (!(infomask & HEAP_XMAX_IS_MULTI))
+ {
/*
* Otherwise check if it committed or aborted. Note we cannot
* be here if the tuple was only locked by somebody who didn't
- * conflict with us; that should have been handled above. So
- * that transaction must necessarily be gone by now.
+ * conflict with us; that would have been handled above. So
+ * that transaction must necessarily be gone by now. But don't
+ * check for this in the multixact case, because some locker
+ * transactions might still be running.
*/
UpdateXmaxHintBits(tuple->t_data, *buffer, xwait);
}
@@ -4537,37 +4572,6 @@ failed:
old_infomask = tuple->t_data->t_infomask;
/*
- * We might already hold the desired lock (or stronger), possibly under a
- * different subtransaction of the current top transaction. If so, there
- * is no need to change state or issue a WAL record. We already handled
- * the case where this is true for xmax being a MultiXactId, so now check
- * for cases where it is a plain TransactionId.
- *
- * Note in particular that this covers the case where we already hold
- * exclusive lock on the tuple and the caller only wants key share or
- * share lock. It would certainly not do to give up the exclusive lock.
- */
- if (!(old_infomask & (HEAP_XMAX_INVALID |
- HEAP_XMAX_COMMITTED |
- HEAP_XMAX_IS_MULTI)) &&
- (mode == LockTupleKeyShare ?
- (HEAP_XMAX_IS_KEYSHR_LOCKED(old_infomask) ||
- HEAP_XMAX_IS_SHR_LOCKED(old_infomask) ||
- HEAP_XMAX_IS_EXCL_LOCKED(old_infomask)) :
- mode == LockTupleShare ?
- (HEAP_XMAX_IS_SHR_LOCKED(old_infomask) ||
- HEAP_XMAX_IS_EXCL_LOCKED(old_infomask)) :
- (HEAP_XMAX_IS_EXCL_LOCKED(old_infomask))) &&
- TransactionIdIsCurrentTransactionId(xmax))
- {
- LockBuffer(*buffer, BUFFER_LOCK_UNLOCK);
- /* Probably can't hold tuple lock here, but may as well check */
- if (have_tuple_lock)
- UnlockTupleTuplock(relation, tid, mode);
- return HeapTupleMayBeUpdated;
- }
-
- /*
* If this is the first possibly-multixact-able operation in the current
* transaction, set my per-backend OldestMemberMXactId setting. We can be
* certain that the transaction will never become a member of any older
@@ -4829,7 +4833,7 @@ l5:
if (!MultiXactIdIsRunning(xmax, HEAP_XMAX_IS_LOCKED_ONLY(old_infomask)))
{
if (HEAP_XMAX_IS_LOCKED_ONLY(old_infomask) ||
- TransactionIdDidAbort(MultiXactIdGetUpdateXid(xmax,
+ !TransactionIdDidCommit(MultiXactIdGetUpdateXid(xmax,
old_infomask)))
{
/*
diff --git a/src/backend/access/transam/multixact.c b/src/backend/access/transam/multixact.c
index fff9f83..f8af11c 100644
--- a/src/backend/access/transam/multixact.c
+++ b/src/backend/access/transam/multixact.c
@@ -533,7 +533,7 @@ MultiXactIdIsRunning(MultiXactId multi, bool isLockOnly)
*/
nmembers = GetMultiXactIdMembers(multi, &members, false, isLockOnly);
- if (nmembers < 0)
+ if (nmembers <= 0)
{
debug_elog2(DEBUG2, "IsRunning: no members");
return false;
@@ -1338,39 +1338,6 @@ retry:
}
/*
- * MultiXactHasRunningRemoteMembers
- * Does the given multixact have still-live members from
- * transactions other than our own?
- */
-bool
-MultiXactHasRunningRemoteMembers(MultiXactId multi)
-{
- MultiXactMember *members;
- int nmembers;
- int i;
-
- nmembers = GetMultiXactIdMembers(multi, &members, true, false);
- if (nmembers <= 0)
- return false;
-
- for (i = 0; i < nmembers; i++)
- {
- /* not interested in our own members */
- if (TransactionIdIsCurrentTransactionId(members[i].xid))
- continue;
-
- if (TransactionIdIsInProgress(members[i].xid))
- {
- pfree(members);
- return true;
- }
- }
-
- pfree(members);
- return false;
-}
-
-/*
* mxactMemberComparator
* qsort comparison function for MultiXactMember
*
diff --git a/src/backend/utils/time/tqual.c b/src/backend/utils/time/tqual.c
index a2c4989..c8b65cc 100644
--- a/src/backend/utils/time/tqual.c
+++ b/src/backend/utils/time/tqual.c
@@ -514,20 +514,20 @@ HeapTupleSatisfiesUpdate(HeapTuple htup, CommandId curcid,
if (tuple->t_infomask & HEAP_XMAX_IS_MULTI)
{
- if (MultiXactHasRunningRemoteMembers(xmax))
+ if (MultiXactIdIsRunning(xmax, true))
return HeapTupleBeingUpdated;
else
return HeapTupleMayBeUpdated;
}
- /* if locker is gone, all's well */
+ /*
+ * If the locker is gone, then there is nothing of interest
+ * left in this Xmax; otherwise, report the tuple as
+ * locked/updated.
+ */
if (!TransactionIdIsInProgress(xmax))
return HeapTupleMayBeUpdated;
-
- if (!TransactionIdIsCurrentTransactionId(xmax))
- return HeapTupleBeingUpdated;
- else
- return HeapTupleMayBeUpdated;
+ return HeapTupleBeingUpdated;
}
if (tuple->t_infomask & HEAP_XMAX_IS_MULTI)
@@ -539,10 +539,11 @@ HeapTupleSatisfiesUpdate(HeapTuple htup, CommandId curcid,
/* not LOCKED_ONLY, so it has to have an xmax */
Assert(TransactionIdIsValid(xmax));
- /* updating subtransaction must have aborted */
+ /* deleting subtransaction must have aborted */
if (!TransactionIdIsCurrentTransactionId(xmax))
{
- if (MultiXactHasRunningRemoteMembers(HeapTupleHeaderGetRawXmax(tuple)))
+ if (MultiXactIdIsRunning(HeapTupleHeaderGetRawXmax(tuple),
+ false))
return HeapTupleBeingUpdated;
return HeapTupleMayBeUpdated;
}
@@ -664,7 +665,7 @@ HeapTupleSatisfiesUpdate(HeapTuple htup, CommandId curcid,
if (TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetRawXmax(tuple)))
{
if (HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_infomask))
- return HeapTupleMayBeUpdated;
+ return HeapTupleBeingUpdated;
if (HeapTupleHeaderGetCmax(tuple) >= curcid)
return HeapTupleSelfUpdated; /* updated after scan started */
else
diff --git a/src/include/access/multixact.h b/src/include/access/multixact.h
index ac58a37..ec265c8 100644
--- a/src/include/access/multixact.h
+++ b/src/include/access/multixact.h
@@ -96,7 +96,6 @@ extern bool MultiXactIdIsRunning(MultiXactId multi, bool isLockOnly);
extern void MultiXactIdSetOldestMember(void);
extern int GetMultiXactIdMembers(MultiXactId multi, MultiXactMember **xids,
bool allow_old, bool isLockOnly);
-extern bool MultiXactHasRunningRemoteMembers(MultiXactId multi);
extern bool MultiXactIdPrecedes(MultiXactId multi1, MultiXactId multi2);
extern bool MultiXactIdPrecedesOrEquals(MultiXactId multi1,
MultiXactId multi2);
^ permalink raw reply [nested|flat] 26+ messages in thread
* Re: BUG #8470: 9.3 locking/subtransaction performance regression
2013-09-25 13:34 BUG #8470: 9.3 locking/subtransaction performance regression os@ohmu.fi
2013-12-20 20:47 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 15:56 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 16:29 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 19:53 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-30 18:11 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Andres Freund <andres@2ndquadrant.com>
2013-12-31 16:34 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-31 20:27 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2014-01-14 12:43 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Oskari Saarenmaa <os@ohmu.fi>
2015-01-05 17:23 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2015-04-02 00:56 ` Bruce Momjian <bruce@momjian.us>
2015-04-10 16:17 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
0 siblings, 1 reply; 26+ messages in thread
From: Bruce Momjian @ 2015-04-02 00:56 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Oskari Saarenmaa <os@ohmu.fi>; Andres Freund <andres@2ndquadrant.com>; pgsql-bugs
On Mon, Jan 5, 2015 at 02:23:18PM -0300, Alvaro Herrera wrote:
> I just got around to merging this patch to 9.5 sources. I'm glad I
> did it because in the course of doing so I noticed a bug in a recent
> patch, which led to commit d5e3d1e969d2f65009f718d3100d6565f47f9112
> (back-patched to 9.3).
>
> I'm now more confident in this code and will probably push this a few
> days, but only to 9.5 at least for now. It probably won't apply cleanly
> to 9.3 due to other changes in the area, such as 05315498012530d44cd89a2
> and df630b0dd5ea2de52972d456f5978a012436115e and others.
Where are we on this?
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ Everyone has their own god. +
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 26+ messages in thread
* Re: BUG #8470: 9.3 locking/subtransaction performance regression
2013-09-25 13:34 BUG #8470: 9.3 locking/subtransaction performance regression os@ohmu.fi
2013-12-20 20:47 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 15:56 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 16:29 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 19:53 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-30 18:11 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Andres Freund <andres@2ndquadrant.com>
2013-12-31 16:34 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-31 20:27 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2014-01-14 12:43 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Oskari Saarenmaa <os@ohmu.fi>
2015-01-05 17:23 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2015-04-02 00:56 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Bruce Momjian <bruce@momjian.us>
@ 2015-04-10 16:17 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2015-06-20 04:36 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
0 siblings, 1 reply; 26+ messages in thread
From: Alvaro Herrera @ 2015-04-10 16:17 UTC (permalink / raw)
To: Bruce Momjian <bruce@momjian.us>; +Cc: Oskari Saarenmaa <os@ohmu.fi>; pgsql-bugs
Bruce Momjian wrote:
> On Mon, Jan 5, 2015 at 02:23:18PM -0300, Alvaro Herrera wrote:
> > I just got around to merging this patch to 9.5 sources. I'm glad I
> > did it because in the course of doing so I noticed a bug in a recent
> > patch, which led to commit d5e3d1e969d2f65009f718d3100d6565f47f9112
> > (back-patched to 9.3).
> >
> > I'm now more confident in this code and will probably push this a few
> > days, but only to 9.5 at least for now. It probably won't apply cleanly
> > to 9.3 due to other changes in the area, such as 05315498012530d44cd89a2
> > and df630b0dd5ea2de52972d456f5978a012436115e and others.
>
> Where are we on this?
That's indeed the question. I gave this a look yesterday and came up
with two patches that "fix" the issue. (I had to fix one additional bug
in the formulation of the complex patch that I posted in January). I
leave the details of the bug as exercise for the interested readers
(hint: run the isolation tests). First some timings. Ran the script
against unpatched master and each of the patches five times. Results:
unpatched:
real 0m8.192s
real 0m8.230s
real 0m8.233s
real 0m8.187s
real 0m8.212s
simple patch:
real 0m0.741s
real 0m0.728s
real 0m0.729s
real 0m0.738s
real 0m0.731s
complex patch:
real 0m0.732s
real 0m0.723s
real 0m0.730s
real 0m0.725s
real 0m0.726s
In 9.2 the time is about 0.150s, so the regression is not completely
resolved, but it's a huge improvement.
The main catch of the "simple" formulation of the patch is that we do
the new GetMultiXactIdMembers call with the buffer lock held, which is a
horrible idea from a concurrency point of view; it will make many cases
where the optimization doesn't apply a lot slower. I think with some
extra contortions we could fix that problem, but it's already quite ugly
that we have a duplicate check for the are-we-already-a-multixact-locker
so I reject the idea that this seemingly simple patch is any good. I
much prefer the complex formulation, which is what I had to start with,
and makes thing a bit less unclear(*).
There was some traction to the idea of backpatching this, but I'm no
longer on board with that. If somebody wants to, I would like some
commitment to a huge testing effort.
(*) In a scale 1 to 10 with 10 being most unclear, the original code is
about 12-unclear, and with the patch is 11-unclear. So it's an
improvement anyhow.
PS: Apologies for unified diff. This is one case where filterdiff
dropped some hunks from the patch produced by git diff.
--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments: download all (2 files, .tar.gz)
8470-simple.patch (text/x-diff, 2.5K) download
*** a/src/backend/access/heap/heapam.c
--- b/src/backend/access/heap/heapam.c
***************
*** 4539,4547 **** failed:
/*
* We might already hold the desired lock (or stronger), possibly under a
* different subtransaction of the current top transaction. If so, there
! * is no need to change state or issue a WAL record. We already handled
! * the case where this is true for xmax being a MultiXactId, so now check
! * for cases where it is a plain TransactionId.
*
* Note in particular that this covers the case where we already hold
* exclusive lock on the tuple and the caller only wants key share or
--- 4539,4546 ----
/*
* We might already hold the desired lock (or stronger), possibly under a
* different subtransaction of the current top transaction. If so, there
! * is no need to change state or issue a WAL record. First check
! * for cases where xmax is a plain TransactionId.
*
* Note in particular that this covers the case where we already hold
* exclusive lock on the tuple and the caller only wants key share or
***************
*** 4568,4573 **** failed:
--- 4567,4618 ----
}
/*
+ * Now check the multixact case. It was already checked above, but it's
+ * possible to get MayBeUpdated from HTSU and so we wouldn't have run
+ * through it.
+ *
+ * XXX this is run with buffer lock held -- probably not a good idea.
+ */
+ if (old_infomask & HEAP_XMAX_IS_MULTI)
+ {
+ int i;
+ int nmembers;
+ MultiXactMember *members;
+
+ /*
+ * We don't need to allow old multixacts here; if that had been
+ * the case, HeapTupleSatisfiesUpdate would have returned
+ * MayBeUpdated and we wouldn't be here.
+ */
+ nmembers =
+ GetMultiXactIdMembers(xmax, &members, false,
+ HEAP_XMAX_IS_LOCKED_ONLY(old_infomask));
+
+ for (i = 0; i < nmembers; i++)
+ {
+ if (TransactionIdIsCurrentTransactionId(members[i].xid))
+ {
+ LockTupleMode membermode;
+
+ membermode = TUPLOCK_from_mxstatus(members[i].status);
+
+ if (membermode >= mode)
+ {
+ LockBuffer(*buffer, BUFFER_LOCK_UNLOCK);
+ if (have_tuple_lock)
+ UnlockTupleTuplock(relation, tid, mode);
+
+ pfree(members);
+ return HeapTupleMayBeUpdated;
+ }
+ }
+ }
+
+ if (members)
+ pfree(members);
+ }
+
+ /*
* If this is the first possibly-multixact-able operation in the current
* transaction, set my per-backend OldestMemberMXactId setting. We can be
* certain that the transaction will never become a member of any older
8470-complex.patch (text/x-diff, 24.9K) download
diff --git a/contrib/pgrowlocks/pgrowlocks.c b/contrib/pgrowlocks/pgrowlocks.c
index 36974f7..88f7137 100644
--- a/contrib/pgrowlocks/pgrowlocks.c
+++ b/contrib/pgrowlocks/pgrowlocks.c
@@ -136,14 +136,9 @@ pgrowlocks(PG_FUNCTION_ARGS)
infomask = tuple->t_data->t_infomask;
/*
- * a tuple is locked if HTSU returns BeingUpdated, and if it returns
- * MayBeUpdated but the Xmax is valid and pointing at us.
+ * A tuple is locked if HTSU returns BeingUpdated.
*/
- if (htsu == HeapTupleBeingUpdated ||
- (htsu == HeapTupleMayBeUpdated &&
- !(infomask & HEAP_XMAX_INVALID) &&
- !(infomask & HEAP_XMAX_IS_MULTI) &&
- (xmax == GetCurrentTransactionIdIfAny())))
+ if (htsu == HeapTupleBeingUpdated)
{
char **values;
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index cb6f8a3..457cd70 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2694,42 +2694,47 @@ l1:
xwait = HeapTupleHeaderGetRawXmax(tp.t_data);
infomask = tp.t_data->t_infomask;
- LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
-
/*
- * Acquire tuple lock to establish our priority for the tuple (see
- * heap_lock_tuple). LockTuple will release us when we are
- * next-in-line for the tuple.
+ * Sleep until concurrent transaction ends -- except when there's a single
+ * locker and it's our own transaction. Note we don't care
+ * which lock mode the locker has, because we need the strongest one.
+ *
+ * Before sleeping, we need to acquire tuple lock to establish our
+ * priority for the tuple (see heap_lock_tuple). LockTuple will
+ * release us when we are next-in-line for the tuple.
*
* If we are forced to "start over" below, we keep the tuple lock;
* this arranges that we stay at the head of the line while rechecking
* tuple state.
*/
- heap_acquire_tuplock(relation, &(tp.t_self), LockTupleExclusive,
- LockWaitBlock, &have_tuple_lock);
-
- /*
- * Sleep until concurrent transaction ends. Note that we don't care
- * which lock mode the locker has, because we need the strongest one.
- */
-
if (infomask & HEAP_XMAX_IS_MULTI)
{
/* wait for multixact */
- MultiXactIdWait((MultiXactId) xwait, MultiXactStatusUpdate, infomask,
- relation, &(tp.t_self), XLTW_Delete,
- NULL);
- LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
+ if (DoesMultiXactIdConflict((MultiXactId) xwait, infomask,
+ LockTupleExclusive))
+ {
+ LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
- /*
- * If xwait had just locked the tuple then some other xact could
- * update this tuple before we get to this point. Check for xmax
- * change, and start over if so.
- */
- if (xmax_infomask_changed(tp.t_data->t_infomask, infomask) ||
- !TransactionIdEquals(HeapTupleHeaderGetRawXmax(tp.t_data),
- xwait))
- goto l1;
+ /* acquire tuple lock, if necessary */
+ heap_acquire_tuplock(relation, &(tp.t_self), LockTupleExclusive,
+ LockWaitBlock, &have_tuple_lock);
+
+ /* wait for multixact */
+ MultiXactIdWait((MultiXactId) xwait, MultiXactStatusUpdate, infomask,
+ relation, &(tp.t_self), XLTW_Delete,
+ NULL);
+ LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
+
+ /*
+ * If xwait had just locked the tuple then some other xact
+ * could update this tuple before we get to this point. Check
+ * for xmax change, and start over if so.
+ */
+ if (xmax_infomask_changed(tp.t_data->t_infomask, infomask) ||
+ !TransactionIdEquals(HeapTupleHeaderGetRawXmax(tp.t_data),
+ xwait))
+ goto l1;
+ }
/*
* You might think the multixact is necessarily done here, but not
@@ -2741,9 +2746,15 @@ l1:
* since we are about to overwrite the xmax altogether.
*/
}
- else
+ else if (!TransactionIdIsCurrentTransactionId(xwait))
{
- /* wait for regular transaction to end */
+ /*
+ * Wait for regular transaction to end; but first, acquire
+ * tuple lock.
+ */
+ LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
+ heap_acquire_tuplock(relation, &(tp.t_self), LockTupleExclusive,
+ LockWaitBlock, &have_tuple_lock);
XactLockTableWait(xwait, relation, &(tp.t_self), XLTW_Delete);
LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
@@ -3204,8 +3215,6 @@ l2:
uint16 infomask;
bool can_continue = false;
- checked_lockers = true;
-
/*
* XXX note that we don't consider the "no wait" case here. This
* isn't a problem currently because no caller uses that case, but it
@@ -3223,8 +3232,6 @@ l2:
xwait = HeapTupleHeaderGetRawXmax(oldtup.t_data);
infomask = oldtup.t_data->t_infomask;
- LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
-
/*
* Now we have to do something about the existing locker. If it's a
* multi, sleep on it; we might be awakened before it is completely
@@ -3252,28 +3259,34 @@ l2:
TransactionId update_xact;
int remain;
- /* acquire tuple lock, if necessary */
- if (DoesMultiXactIdConflict((MultiXactId) xwait, infomask, *lockmode))
+ if (DoesMultiXactIdConflict((MultiXactId) xwait, infomask,
+ *lockmode))
{
+ LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
+
+ /* acquire tuple lock, if necessary */
heap_acquire_tuplock(relation, &(oldtup.t_self), *lockmode,
LockWaitBlock, &have_tuple_lock);
- }
- /* wait for multixact */
- MultiXactIdWait((MultiXactId) xwait, mxact_status, infomask,
- relation, &oldtup.t_self, XLTW_Update,
- &remain);
- LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
+ /* wait for multixact */
+ MultiXactIdWait((MultiXactId) xwait, mxact_status, infomask,
+ relation, &oldtup.t_self, XLTW_Update,
+ &remain);
+ checked_lockers = true;
+ locker_remains = remain != 0;
+ LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
- /*
- * If xwait had just locked the tuple then some other xact could
- * update this tuple before we get to this point. Check for xmax
- * change, and start over if so.
- */
- if (xmax_infomask_changed(oldtup.t_data->t_infomask, infomask) ||
- !TransactionIdEquals(HeapTupleHeaderGetRawXmax(oldtup.t_data),
- xwait))
- goto l2;
+ /*
+ * If xwait had just locked the tuple then some other xact
+ * could update this tuple before we get to this point. Check
+ * for xmax change, and start over if so.
+ */
+ if (xmax_infomask_changed(oldtup.t_data->t_infomask,
+ infomask) ||
+ !TransactionIdEquals(HeapTupleHeaderGetRawXmax(oldtup.t_data),
+ xwait))
+ goto l2;
+ }
/*
* Note that the multixact may not be done by now. It could have
@@ -3294,9 +3307,10 @@ l2:
* before this one, which are important to keep in case this
* subxact aborts.
*/
- update_xact = InvalidTransactionId;
if (!HEAP_XMAX_IS_LOCKED_ONLY(oldtup.t_data->t_infomask))
update_xact = HeapTupleGetUpdateXid(oldtup.t_data);
+ else
+ update_xact = InvalidTransactionId;
/*
* There was no UPDATE in the MultiXact; or it aborted. No
@@ -3306,61 +3320,56 @@ l2:
if (!TransactionIdIsValid(update_xact) ||
TransactionIdDidAbort(update_xact))
can_continue = true;
-
- locker_remains = remain != 0;
+ }
+ else if (TransactionIdIsCurrentTransactionId(xwait))
+ {
+ /*
+ * The only locker is ourselves; we can avoid grabbing the tuple
+ * lock here, but must preserve our locking information.
+ */
+ checked_lockers = true;
+ locker_remains = true;
+ can_continue = true;
+ }
+ else if (HEAP_XMAX_IS_KEYSHR_LOCKED(infomask) && key_intact)
+ {
+ /*
+ * If it's just a key-share locker, and we're not changing the
+ * key columns, we don't need to wait for it to end; but we
+ * need to preserve it as locker.
+ */
+ checked_lockers = true;
+ locker_remains = true;
+ can_continue = true;
}
else
{
/*
- * If it's just a key-share locker, and we're not changing the key
- * columns, we don't need to wait for it to end; but we need to
- * preserve it as locker.
+ * Wait for regular transaction to end; but first, acquire
+ * tuple lock.
*/
- if (HEAP_XMAX_IS_KEYSHR_LOCKED(infomask) && key_intact)
- {
- LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
+ LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
+ heap_acquire_tuplock(relation, &(oldtup.t_self), *lockmode,
+ LockWaitBlock, &have_tuple_lock);
+ XactLockTableWait(xwait, relation, &oldtup.t_self,
+ XLTW_Update);
+ checked_lockers = true;
+ LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
- /*
- * recheck the locker; if someone else changed the tuple while
- * we weren't looking, start over.
- */
- if (xmax_infomask_changed(oldtup.t_data->t_infomask, infomask) ||
- !TransactionIdEquals(
- HeapTupleHeaderGetRawXmax(oldtup.t_data),
- xwait))
- goto l2;
+ /*
+ * xwait is done, but if xwait had just locked the tuple then some
+ * other xact could update this tuple before we get to this point.
+ * Check for xmax change, and start over if so.
+ */
+ if (xmax_infomask_changed(oldtup.t_data->t_infomask, infomask) ||
+ !TransactionIdEquals(xwait,
+ HeapTupleHeaderGetRawXmax(oldtup.t_data)))
+ goto l2;
+ /* Otherwise check if it committed or aborted */
+ UpdateXmaxHintBits(oldtup.t_data, buffer, xwait);
+ if (oldtup.t_data->t_infomask & HEAP_XMAX_INVALID)
can_continue = true;
- locker_remains = true;
- }
- else
- {
- /*
- * Wait for regular transaction to end; but first, acquire
- * tuple lock.
- */
- heap_acquire_tuplock(relation, &(oldtup.t_self), *lockmode,
- LockWaitBlock, &have_tuple_lock);
- XactLockTableWait(xwait, relation, &oldtup.t_self,
- XLTW_Update);
- LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
-
- /*
- * xwait is done, but if xwait had just locked the tuple then
- * some other xact could update this tuple before we get to
- * this point. Check for xmax change, and start over if so.
- */
- if (xmax_infomask_changed(oldtup.t_data->t_infomask, infomask) ||
- !TransactionIdEquals(
- HeapTupleHeaderGetRawXmax(oldtup.t_data),
- xwait))
- goto l2;
-
- /* Otherwise check if it committed or aborted */
- UpdateXmaxHintBits(oldtup.t_data, buffer, xwait);
- if (oldtup.t_data->t_infomask & HEAP_XMAX_INVALID)
- can_continue = true;
- }
}
result = can_continue ? HeapTupleMayBeUpdated : HeapTupleUpdated;
@@ -4097,6 +4106,7 @@ heap_lock_tuple(Relation relation, HeapTuple tuple,
uint16 old_infomask,
new_infomask,
new_infomask2;
+ bool first_time = true;
bool have_tuple_lock = false;
*buffer = ReadBuffer(relation, ItemPointerGetBlockNumber(tid));
@@ -4136,47 +4146,77 @@ l3:
/*
* If any subtransaction of the current top transaction already holds
- * a lock as strong or stronger than what we're requesting, we
+ * a lock as strong as or stronger than what we're requesting, we
* effectively hold the desired lock already. We *must* succeed
* without trying to take the tuple lock, else we will deadlock
* against anyone wanting to acquire a stronger lock.
+ *
+ * Note we only do this the first time we loop on the HTSU result;
+ * there is no point in testing in subsequent passes, because
+ * evidently our own transaction cannot have acquired a new lock after
+ * the first time we checked.
*/
- if (infomask & HEAP_XMAX_IS_MULTI)
+ if (first_time)
{
- int i;
- int nmembers;
- MultiXactMember *members;
-
- /*
- * We don't need to allow old multixacts here; if that had been
- * the case, HeapTupleSatisfiesUpdate would have returned
- * MayBeUpdated and we wouldn't be here.
- */
- nmembers =
- GetMultiXactIdMembers(xwait, &members, false,
- HEAP_XMAX_IS_LOCKED_ONLY(infomask));
+ first_time = false;
- for (i = 0; i < nmembers; i++)
+ if (infomask & HEAP_XMAX_IS_MULTI)
{
- if (TransactionIdIsCurrentTransactionId(members[i].xid))
- {
- LockTupleMode membermode;
+ int i;
+ int nmembers;
+ MultiXactMember *members;
- membermode = TUPLOCK_from_mxstatus(members[i].status);
+ /*
+ * We don't need to allow old multixacts here; if that had
+ * been the case, HeapTupleSatisfiesUpdate would have returned
+ * MayBeUpdated and we wouldn't be here.
+ */
+ nmembers =
+ GetMultiXactIdMembers(xwait, &members, false,
+ HEAP_XMAX_IS_LOCKED_ONLY(infomask));
- if (membermode >= mode)
- {
- if (have_tuple_lock)
- UnlockTupleTuplock(relation, tid, mode);
+ for (i = 0; i < nmembers; i++)
+ {
+ /* only consider members of our own transaction */
+ if (!TransactionIdIsCurrentTransactionId(members[i].xid))
+ continue;
+ if (TUPLOCK_from_mxstatus(members[i].status) >= mode)
+ {
pfree(members);
return HeapTupleMayBeUpdated;
}
}
- }
- if (members)
- pfree(members);
+ if (members)
+ pfree(members);
+ }
+ else if (TransactionIdIsCurrentTransactionId(xwait))
+ {
+ switch (mode)
+ {
+ case LockTupleKeyShare:
+ Assert(HEAP_XMAX_IS_KEYSHR_LOCKED(infomask) ||
+ HEAP_XMAX_IS_SHR_LOCKED(infomask) ||
+ HEAP_XMAX_IS_EXCL_LOCKED(infomask));
+ return HeapTupleMayBeUpdated;
+ break;
+ case LockTupleShare:
+ if (HEAP_XMAX_IS_SHR_LOCKED(infomask) ||
+ HEAP_XMAX_IS_EXCL_LOCKED(infomask))
+ return HeapTupleMayBeUpdated;
+ break;
+ case LockTupleNoKeyExclusive:
+ if (HEAP_XMAX_IS_EXCL_LOCKED(infomask))
+ return HeapTupleMayBeUpdated;
+ break;
+ case LockTupleExclusive:
+ if (HEAP_XMAX_IS_EXCL_LOCKED(infomask) &&
+ infomask2 & HEAP_KEYS_UPDATED)
+ return HeapTupleMayBeUpdated;
+ break;
+ }
+ }
}
/*
@@ -4323,6 +4363,31 @@ l3:
}
/*
+ * As a check independent from those above, we can also avoid sleeping
+ * if the current transaction is the sole locker of the tuple. Note
+ * that the strength of the lock already held is irrelevant; this is
+ * not about recording the lock in Xmax (which will be done regardless
+ * of this optimization, below). Also, note that the cases where we
+ * hold a lock stronger than we are requesting are already handled
+ * above by not doing anything.
+ *
+ * Note we only deal with the non-multixact case here; MultiXactIdWait
+ * is well equipped to deal with this situation on its own.
+ */
+ if (require_sleep && !(infomask & HEAP_XMAX_IS_MULTI) &&
+ TransactionIdIsCurrentTransactionId(xwait))
+ {
+ /* ... but if the xmax changed in the meantime, start over */
+ LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE);
+ if (xmax_infomask_changed(tuple->t_data->t_infomask, infomask) ||
+ !TransactionIdEquals(HeapTupleHeaderGetRawXmax(tuple->t_data),
+ xwait))
+ goto l3;
+ Assert(HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_data->t_infomask));
+ require_sleep = false;
+ }
+
+ /*
* By here, we either have already acquired the buffer exclusive lock,
* or we must wait for the locking transaction or multixact; so below
* we ensure that we grab buffer lock after the sleep.
@@ -4331,9 +4396,9 @@ l3:
if (require_sleep)
{
/*
- * Acquire tuple lock to establish our priority for the tuple.
- * LockTuple will release us when we are next-in-line for the tuple.
- * We must do this even if we are share-locking.
+ * Acquire tuple lock to establish our priority for the tuple, or
+ * die trying. LockTuple will release us when we are next-in-line
+ * for the tuple. We must do this even if we are share-locking.
*
* If we are forced to "start over" below, we keep the tuple lock;
* this arranges that we stay at the head of the line while rechecking
@@ -4390,37 +4455,6 @@ l3:
break;
}
- /* if there are updates, follow the update chain */
- if (follow_updates &&
- !HEAP_XMAX_IS_LOCKED_ONLY(infomask))
- {
- HTSU_Result res;
-
- res = heap_lock_updated_tuple(relation, tuple, &t_ctid,
- GetCurrentTransactionId(),
- mode);
- if (res != HeapTupleMayBeUpdated)
- {
- result = res;
- /* recovery code expects to have buffer lock held */
- LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE);
- goto failed;
- }
- }
-
- LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE);
-
- /*
- * If xwait had just locked the tuple then some other xact
- * could update this tuple before we get to this point. Check
- * for xmax change, and start over if so.
- */
- if (xmax_infomask_changed(tuple->t_data->t_infomask, infomask) ||
- !TransactionIdEquals(
- HeapTupleHeaderGetRawXmax(tuple->t_data),
- xwait))
- goto l3;
-
/*
* Of course, the multixact might not be done here: if we're
* requesting a light lock mode, other transactions with light
@@ -4457,43 +4491,46 @@ l3:
RelationGetRelationName(relation))));
break;
}
+ }
- /* if there are updates, follow the update chain */
- if (follow_updates &&
- !HEAP_XMAX_IS_LOCKED_ONLY(infomask))
- {
- HTSU_Result res;
+ /* if there are updates, follow the update chain */
+ if (follow_updates && !HEAP_XMAX_IS_LOCKED_ONLY(infomask))
+ {
+ HTSU_Result res;
- res = heap_lock_updated_tuple(relation, tuple, &t_ctid,
- GetCurrentTransactionId(),
- mode);
- if (res != HeapTupleMayBeUpdated)
- {
- result = res;
- /* recovery code expects to have buffer lock held */
- LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE);
- goto failed;
- }
+ res = heap_lock_updated_tuple(relation, tuple, &t_ctid,
+ GetCurrentTransactionId(),
+ mode);
+ if (res != HeapTupleMayBeUpdated)
+ {
+ result = res;
+ /* recovery code expects to have buffer lock held */
+ LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE);
+ goto failed;
}
+ }
- LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE);
+ LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE);
- /*
- * xwait is done, but if xwait had just locked the tuple then
- * some other xact could update this tuple before we get to
- * this point. Check for xmax change, and start over if so.
- */
- if (xmax_infomask_changed(tuple->t_data->t_infomask, infomask) ||
- !TransactionIdEquals(
- HeapTupleHeaderGetRawXmax(tuple->t_data),
- xwait))
- goto l3;
+ /*
+ * xwait is done, but if xwait had just locked the tuple then
+ * some other xact could update this tuple before we get to
+ * this point. Check for xmax change, and start over if so.
+ */
+ if (xmax_infomask_changed(tuple->t_data->t_infomask, infomask) ||
+ !TransactionIdEquals(HeapTupleHeaderGetRawXmax(tuple->t_data),
+ xwait))
+ goto l3;
+ if (!(infomask & HEAP_XMAX_IS_MULTI))
+ {
/*
* Otherwise check if it committed or aborted. Note we cannot
* be here if the tuple was only locked by somebody who didn't
- * conflict with us; that should have been handled above. So
- * that transaction must necessarily be gone by now.
+ * conflict with us; that would have been handled above. So
+ * that transaction must necessarily be gone by now. But don't
+ * check for this in the multixact case, because some locker
+ * transactions might still be running.
*/
UpdateXmaxHintBits(tuple->t_data, *buffer, xwait);
}
@@ -4537,37 +4574,6 @@ failed:
old_infomask = tuple->t_data->t_infomask;
/*
- * We might already hold the desired lock (or stronger), possibly under a
- * different subtransaction of the current top transaction. If so, there
- * is no need to change state or issue a WAL record. We already handled
- * the case where this is true for xmax being a MultiXactId, so now check
- * for cases where it is a plain TransactionId.
- *
- * Note in particular that this covers the case where we already hold
- * exclusive lock on the tuple and the caller only wants key share or
- * share lock. It would certainly not do to give up the exclusive lock.
- */
- if (!(old_infomask & (HEAP_XMAX_INVALID |
- HEAP_XMAX_COMMITTED |
- HEAP_XMAX_IS_MULTI)) &&
- (mode == LockTupleKeyShare ?
- (HEAP_XMAX_IS_KEYSHR_LOCKED(old_infomask) ||
- HEAP_XMAX_IS_SHR_LOCKED(old_infomask) ||
- HEAP_XMAX_IS_EXCL_LOCKED(old_infomask)) :
- mode == LockTupleShare ?
- (HEAP_XMAX_IS_SHR_LOCKED(old_infomask) ||
- HEAP_XMAX_IS_EXCL_LOCKED(old_infomask)) :
- (HEAP_XMAX_IS_EXCL_LOCKED(old_infomask))) &&
- TransactionIdIsCurrentTransactionId(xmax))
- {
- LockBuffer(*buffer, BUFFER_LOCK_UNLOCK);
- /* Probably can't hold tuple lock here, but may as well check */
- if (have_tuple_lock)
- UnlockTupleTuplock(relation, tid, mode);
- return HeapTupleMayBeUpdated;
- }
-
- /*
* If this is the first possibly-multixact-able operation in the current
* transaction, set my per-backend OldestMemberMXactId setting. We can be
* certain that the transaction will never become a member of any older
@@ -4829,7 +4835,7 @@ l5:
if (!MultiXactIdIsRunning(xmax, HEAP_XMAX_IS_LOCKED_ONLY(old_infomask)))
{
if (HEAP_XMAX_IS_LOCKED_ONLY(old_infomask) ||
- TransactionIdDidAbort(MultiXactIdGetUpdateXid(xmax,
+ !TransactionIdDidCommit(MultiXactIdGetUpdateXid(xmax,
old_infomask)))
{
/*
diff --git a/src/backend/access/transam/multixact.c b/src/backend/access/transam/multixact.c
index f9ca028..3dbf6b9 100644
--- a/src/backend/access/transam/multixact.c
+++ b/src/backend/access/transam/multixact.c
@@ -533,7 +533,7 @@ MultiXactIdIsRunning(MultiXactId multi, bool isLockOnly)
*/
nmembers = GetMultiXactIdMembers(multi, &members, false, isLockOnly);
- if (nmembers < 0)
+ if (nmembers <= 0)
{
debug_elog2(DEBUG2, "IsRunning: no members");
return false;
@@ -1338,39 +1338,6 @@ retry:
}
/*
- * MultiXactHasRunningRemoteMembers
- * Does the given multixact have still-live members from
- * transactions other than our own?
- */
-bool
-MultiXactHasRunningRemoteMembers(MultiXactId multi)
-{
- MultiXactMember *members;
- int nmembers;
- int i;
-
- nmembers = GetMultiXactIdMembers(multi, &members, true, false);
- if (nmembers <= 0)
- return false;
-
- for (i = 0; i < nmembers; i++)
- {
- /* not interested in our own members */
- if (TransactionIdIsCurrentTransactionId(members[i].xid))
- continue;
-
- if (TransactionIdIsInProgress(members[i].xid))
- {
- pfree(members);
- return true;
- }
- }
-
- pfree(members);
- return false;
-}
-
-/*
* mxactMemberComparator
* qsort comparison function for MultiXactMember
*
diff --git a/src/backend/utils/time/tqual.c b/src/backend/utils/time/tqual.c
index 777f55c..a4a478d 100644
--- a/src/backend/utils/time/tqual.c
+++ b/src/backend/utils/time/tqual.c
@@ -514,20 +514,20 @@ HeapTupleSatisfiesUpdate(HeapTuple htup, CommandId curcid,
if (tuple->t_infomask & HEAP_XMAX_IS_MULTI)
{
- if (MultiXactHasRunningRemoteMembers(xmax))
+ if (MultiXactIdIsRunning(xmax, true))
return HeapTupleBeingUpdated;
else
return HeapTupleMayBeUpdated;
}
- /* if locker is gone, all's well */
+ /*
+ * If the locker is gone, then there is nothing of interest
+ * left in this Xmax; otherwise, report the tuple as
+ * locked/updated.
+ */
if (!TransactionIdIsInProgress(xmax))
return HeapTupleMayBeUpdated;
-
- if (!TransactionIdIsCurrentTransactionId(xmax))
- return HeapTupleBeingUpdated;
- else
- return HeapTupleMayBeUpdated;
+ return HeapTupleBeingUpdated;
}
if (tuple->t_infomask & HEAP_XMAX_IS_MULTI)
@@ -539,10 +539,11 @@ HeapTupleSatisfiesUpdate(HeapTuple htup, CommandId curcid,
/* not LOCKED_ONLY, so it has to have an xmax */
Assert(TransactionIdIsValid(xmax));
- /* updating subtransaction must have aborted */
+ /* deleting subtransaction must have aborted */
if (!TransactionIdIsCurrentTransactionId(xmax))
{
- if (MultiXactHasRunningRemoteMembers(HeapTupleHeaderGetRawXmax(tuple)))
+ if (MultiXactIdIsRunning(HeapTupleHeaderGetRawXmax(tuple),
+ false))
return HeapTupleBeingUpdated;
return HeapTupleMayBeUpdated;
}
@@ -664,7 +665,7 @@ HeapTupleSatisfiesUpdate(HeapTuple htup, CommandId curcid,
if (TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetRawXmax(tuple)))
{
if (HEAP_XMAX_IS_LOCKED_ONLY(tuple->t_infomask))
- return HeapTupleMayBeUpdated;
+ return HeapTupleBeingUpdated;
if (HeapTupleHeaderGetCmax(tuple) >= curcid)
return HeapTupleSelfUpdated; /* updated after scan started */
else
diff --git a/src/include/access/multixact.h b/src/include/access/multixact.h
index 45dc32a..640b198 100644
--- a/src/include/access/multixact.h
+++ b/src/include/access/multixact.h
@@ -96,7 +96,6 @@ extern bool MultiXactIdIsRunning(MultiXactId multi, bool isLockOnly);
extern void MultiXactIdSetOldestMember(void);
extern int GetMultiXactIdMembers(MultiXactId multi, MultiXactMember **xids,
bool allow_old, bool isLockOnly);
-extern bool MultiXactHasRunningRemoteMembers(MultiXactId multi);
extern bool MultiXactIdPrecedes(MultiXactId multi1, MultiXactId multi2);
extern bool MultiXactIdPrecedesOrEquals(MultiXactId multi1,
MultiXactId multi2);
^ permalink raw reply [nested|flat] 26+ messages in thread
* Re: BUG #8470: 9.3 locking/subtransaction performance regression
2013-09-25 13:34 BUG #8470: 9.3 locking/subtransaction performance regression os@ohmu.fi
2013-12-20 20:47 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 15:56 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 16:29 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 19:53 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-30 18:11 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Andres Freund <andres@2ndquadrant.com>
2013-12-31 16:34 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-31 20:27 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2014-01-14 12:43 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Oskari Saarenmaa <os@ohmu.fi>
2015-01-05 17:23 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2015-04-02 00:56 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Bruce Momjian <bruce@momjian.us>
2015-04-10 16:17 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2015-06-20 04:36 ` Alvaro Herrera <alvherre@2ndquadrant.com>
0 siblings, 0 replies; 26+ messages in thread
From: Alvaro Herrera @ 2015-06-20 04:36 UTC (permalink / raw)
To: Bruce Momjian <bruce@momjian.us>; +Cc: pgsql-bugs
Alvaro Herrera wrote:
> The main catch of the "simple" formulation of the patch is that we do
> the new GetMultiXactIdMembers call with the buffer lock held, which is a
> horrible idea from a concurrency point of view; it will make many cases
> where the optimization doesn't apply a lot slower. I think with some
> extra contortions we could fix that problem, but it's already quite ugly
> that we have a duplicate check for the are-we-already-a-multixact-locker
> so I reject the idea that this seemingly simple patch is any good. I
> much prefer the complex formulation, which is what I had to start with,
> and makes thing a bit less unclear(*).
Here's an updated version of this patch. This applies to 9.3 and 9.4 and
restores performance to what's in master, while being much less invasive
than what was committed to master. But more importantly, what it does
is reduce the typical size of multixacts.
Since the size of multixacts is so critical with regards to the problems
of members overrun, I think it is a good idea to reduce it. In master
we already have an equivalent of this optimization.
--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
0001-Optimize-locking-a-tuple-already-locked-by-another-s.patch (text/x-diff, 3.8K) download
From 449df66162775adf27f5297f381f0ae199938064 Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Fri, 10 Apr 2015 12:46:56 -0300
Subject: [PATCH] Optimize locking a tuple already locked by another subxact
This is equivalent to the fix in 27846f02c176eebe7e08ce51e, except less
invasive: we don't change the API of HeapTupleSatisfiesUpdate here, but
instead cope with the possibility by checking for multixacts separately.
This patch, for 9.3 and 9.4, is much simpler and restores performance
almost to what it was in 9.2 for the test case supplied by Oskari
Saarenmaa in bug #8470.
---
src/backend/access/heap/heapam.c | 70 ++++++++++++++++++++++++++++++++++++++--
1 file changed, 67 insertions(+), 3 deletions(-)
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 2209db1..70a084c 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -4134,6 +4134,7 @@ heap_lock_tuple(Relation relation, HeapTuple tuple,
new_infomask,
new_infomask2;
bool have_tuple_lock = false;
+ bool checked_our_multi = false;
*buffer = ReadBuffer(relation, ItemPointerGetBlockNumber(tid));
LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE);
@@ -4535,9 +4536,8 @@ failed:
/*
* We might already hold the desired lock (or stronger), possibly under a
* different subtransaction of the current top transaction. If so, there
- * is no need to change state or issue a WAL record. We already handled
- * the case where this is true for xmax being a MultiXactId, so now check
- * for cases where it is a plain TransactionId.
+ * is no need to change state or issue a WAL record. First check
+ * for cases where xmax is a plain TransactionId.
*
* Note in particular that this covers the case where we already hold
* exclusive lock on the tuple and the caller only wants key share or
@@ -4564,6 +4564,70 @@ failed:
}
/*
+ * Now check the multixact case. It was already checked above in the
+ * HeapTupleBeingUpdated case, but it's possible to get
+ * HeapTupleMayBeUpdated from HTSU in some cases.
+ */
+ if (!checked_our_multi &&
+ (old_infomask & HEAP_XMAX_IS_MULTI))
+ {
+ int nmembers;
+ MultiXactMember *members;
+ uint16 infomask;
+ TransactionId xwait;
+
+ /* must copy state data before unlocking buffer */
+ infomask = tuple->t_data->t_infomask;
+ xwait = HeapTupleHeaderGetRawXmax(tuple->t_data);
+
+ LockBuffer(*buffer, BUFFER_LOCK_UNLOCK);
+
+ nmembers = GetMultiXactIdMembers(xmax, &members,
+ !(infomask & HEAP_LOCK_MASK) &&
+ HEAP_XMAX_IS_LOCKED_ONLY(infomask));
+ if (nmembers > 0)
+ {
+ int i;
+
+ for (i = 0; i < nmembers; i++)
+ {
+ if (TransactionIdIsCurrentTransactionId(members[i].xid))
+ {
+ LockTupleMode membermode;
+
+ membermode = TUPLOCK_from_mxstatus(members[i].status);
+
+ if (membermode >= mode)
+ {
+ if (have_tuple_lock)
+ UnlockTupleTuplock(relation, tid, mode);
+
+ pfree(members);
+ return HeapTupleMayBeUpdated;
+ }
+ }
+ }
+
+ pfree(members);
+ }
+
+ /* make sure to only do this once */
+ checked_our_multi = true;
+
+ /*
+ * If we reach this point, then we know the optimization doesn't apply
+ * and we need to fall through to lock the tuple. However, the xmax
+ * might have changed in the meantime, so recheck and start again if so.
+ */
+ LockBuffer(*buffer, BUFFER_LOCK_EXCLUSIVE);
+ if (xmax_infomask_changed(tuple->t_data->t_infomask, infomask) ||
+ !TransactionIdEquals(HeapTupleHeaderGetRawXmax(tuple->t_data),
+ xwait))
+ goto l3;
+
+ }
+
+ /*
* If this is the first possibly-multixact-able operation in the current
* transaction, set my per-backend OldestMemberMXactId setting. We can be
* certain that the transaction will never become a member of any older
--
2.1.4
^ permalink raw reply [nested|flat] 26+ messages in thread
* Re: BUG #8470: 9.3 locking/subtransaction performance regression
2013-09-25 13:34 BUG #8470: 9.3 locking/subtransaction performance regression os@ohmu.fi
2013-12-20 20:47 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 15:56 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 16:29 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 19:53 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-30 18:11 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Andres Freund <andres@2ndquadrant.com>
2013-12-31 16:34 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-31 20:27 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2014-01-14 12:43 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Oskari Saarenmaa <os@ohmu.fi>
@ 2015-04-10 16:57 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2015-04-17 08:50 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Oskari Saarenmaa <os@ohmu.fi>
2 siblings, 1 reply; 26+ messages in thread
From: Alvaro Herrera @ 2015-04-10 16:57 UTC (permalink / raw)
To: Oskari Saarenmaa <os@ohmu.fi>; +Cc: Andres Freund <andres@2ndquadrant.com>; pgsql-bugs
Oskari Saarenmaa wrote:
Hi,
> I didn't try this patch, but I built today's REL9_3_STABLE with the patch
> from your mail on the 31st of Dec
> (http://github.com/saaros/postgres/tree/alvaro-multixact-optimize-9.3) and
> ran the older version of my appliaction's test suite which has a case that
> times out after 3 minutes with unpatched 9.3. With the current patch the
> test case successfully completes in ~20 seconds which is a major improvement
> although it's still slower than 9.2 It also passes all other test cases in
> my test suite.
>
> Do you think it'll make it to 9.3.3?
I just pushed this to 9.5. I'm not sure how much value I place on a
backpatch at this point. There were a number of complaints about the
performance regression, but other than yours I got no report on whether
the fix was good, or on whether it was stable. If you have other
thoughts, I'm willing to listen. Anyway if you could test the patch I
pushed, it'd be great.
--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 26+ messages in thread
* Re: BUG #8470: 9.3 locking/subtransaction performance regression
2013-09-25 13:34 BUG #8470: 9.3 locking/subtransaction performance regression os@ohmu.fi
2013-12-20 20:47 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 15:56 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 16:29 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 19:53 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-30 18:11 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Andres Freund <andres@2ndquadrant.com>
2013-12-31 16:34 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-31 20:27 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
2014-01-14 12:43 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Oskari Saarenmaa <os@ohmu.fi>
2015-04-10 16:57 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2015-04-17 08:50 ` Oskari Saarenmaa <os@ohmu.fi>
0 siblings, 0 replies; 26+ messages in thread
From: Oskari Saarenmaa @ 2015-04-17 08:50 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Andres Freund <andres@2ndquadrant.com>; pgsql-bugs
10.04.2015, 19:57, Alvaro Herrera kirjoitti:
>> I didn't try this patch, but I built today's REL9_3_STABLE with the patch
>> from your mail on the 31st of Dec
>> (http://github.com/saaros/postgres/tree/alvaro-multixact-optimize-9.3) and
>> ran the older version of my appliaction's test suite which has a case that
>> times out after 3 minutes with unpatched 9.3. With the current patch the
>> test case successfully completes in ~20 seconds which is a major improvement
>> although it's still slower than 9.2 It also passes all other test cases in
>> my test suite.
>>
>> Do you think it'll make it to 9.3.3?
>
> I just pushed this to 9.5. I'm not sure how much value I place on a
> backpatch at this point. There were a number of complaints about the
> performance regression, but other than yours I got no report on whether
> the fix was good, or on whether it was stable. If you have other
> thoughts, I'm willing to listen. Anyway if you could test the patch I
> pushed, it'd be great.
The component where this was an issue was totally rewritten already a
while ago to allow us to take 9.3 into use and as I can't run the old
version anymore I can't verify the fix in a real application. The code
we had there was almost identical to the test case I posted.
I don't think the fix needs to be backpatched.
Thanks,
Oskari
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 26+ messages in thread
* Re: BUG #8470: 9.3 locking/subtransaction performance regression
2013-09-25 13:34 BUG #8470: 9.3 locking/subtransaction performance regression os@ohmu.fi
@ 2014-02-26 03:30 ` chrisrow <chrisrow@hushmail.com>
2014-05-28 09:47 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression yosxpe23 <wigsalemall.com@gmail.com>
2 siblings, 1 reply; 26+ messages in thread
From: chrisrow @ 2014-02-26 03:30 UTC (permalink / raw)
To: pgsql-bugs
In spare time,different people have different hobbies.Some people may choose
to go on a date with their lovers with beautiful hairdressing and
fashionable clothes.To improve personal image,more and more people choose to
wear * <http://www.hairwigsall.com/categories/Synthetic-Wigs/; synthetic
wig* even including men.And to my surprise,there are mens long wigs for
sale in the market.
--
View this message in context: http://postgresql.1045698.n5.nabble.com/BUG-8470-9-3-locking-subtransaction-performance-regression-t...
Sent from the PostgreSQL - bugs mailing list archive at Nabble.com.
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 26+ messages in thread
* Re: BUG #8470: 9.3 locking/subtransaction performance regression
2013-09-25 13:34 BUG #8470: 9.3 locking/subtransaction performance regression os@ohmu.fi
2014-02-26 03:30 ` Re: BUG #8470: 9.3 locking/subtransaction performance regression chrisrow <chrisrow@hushmail.com>
@ 2014-05-28 09:47 ` yosxpe23 <wigsalemall.com@gmail.com>
0 siblings, 0 replies; 26+ messages in thread
From: yosxpe23 @ 2014-05-28 09:47 UTC (permalink / raw)
To: pgsql-bugs
i also like to collect all kinds of fantastic wigs which i purchase online
with great discount price! In my opinion, wigsalemall.com
<http://wigsalemall.com > is a good choice!
--
View this message in context: http://postgresql.1045698.n5.nabble.com/BUG-8470-9-3-locking-subtransaction-performance-regression-t...
Sent from the PostgreSQL - bugs mailing list archive at Nabble.com.
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 26+ messages in thread
end of thread, other threads:[~2015-06-20 04:36 UTC | newest]
Thread overview: 26+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-09-25 13:34 BUG #8470: 9.3 locking/subtransaction performance regression os@ohmu.fi
2013-09-25 14:26 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2013-10-04 22:31 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2013-10-05 07:59 ` Oskari Saarenmaa <os@ohmu.fi>
2013-10-05 15:14 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2013-10-05 15:23 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2013-10-06 17:41 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-20 20:47 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 15:56 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 16:29 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 19:53 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-23 20:06 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-30 18:11 ` Andres Freund <andres@2ndquadrant.com>
2013-12-31 16:34 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2013-12-31 20:27 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2014-01-14 12:43 ` Oskari Saarenmaa <os@ohmu.fi>
2014-01-14 13:09 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2014-02-12 06:36 ` Tomonari Katsumata <katsumata.tomonari@po.ntts.co.jp>
2015-01-05 17:23 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2015-04-02 00:56 ` Bruce Momjian <bruce@momjian.us>
2015-04-10 16:17 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2015-06-20 04:36 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2015-04-10 16:57 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2015-04-17 08:50 ` Oskari Saarenmaa <os@ohmu.fi>
2014-02-26 03:30 ` chrisrow <chrisrow@hushmail.com>
2014-05-28 09:47 ` yosxpe23 <wigsalemall.com@gmail.com>
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