Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vu6zP-00085S-NZ for pgsql-bugs@arkaria.postgresql.org; Fri, 20 Dec 2013 20:48:07 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Vu6zP-0007Is-7q for pgsql-bugs@arkaria.postgresql.org; Fri, 20 Dec 2013 20:48:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vu6zN-0007Il-S9 for pgsql-bugs@postgresql.org; Fri, 20 Dec 2013 20:48:05 +0000 Received: from smtprelay0165.b.hostedemail.com ([64.98.42.165] helo=smtprelay.b.hostedemail.com) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vu6zF-0000s7-UF for pgsql-bugs@postgresql.org; Fri, 20 Dec 2013 20:48:05 +0000 Received: from filter.hostedemail.com (b-bigip1 [10.5.19.254]) by smtprelay01.b.hostedemail.com (Postfix) with ESMTP id 03C0C2D2B5E; Fri, 20 Dec 2013 20:47:56 +0000 (UTC) X-Session-Marker: 616C76686572726540616C76682E6E6F2D69702E6F7267 X-Spam-Summary: 30, 2, 0, , d41d8cd98f00b204, alvherre@alvh.no-ip.org, :::, RULES_HIT:41:355:379:599:871:967:973:988:989:1260:1311:1312:1313:1314:1345:1359:1437:1515:1516:1518:1519:1535:1540:1575:1594:1595:1596:1711:1730:1747:1764:1777:1792:2194:2199:2393:2525:2560:2563:2682:2685:2693:2859:2895:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3352:3865:3866:3867:3868:3870:3871:3872:3873:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4117:4605:4659:5007:6119:6261:6748:7281:7809:7903:9025:9121:10010:10394:10400:10848:11232:11256:11257:11604:11658:11914:12517:12519:13894:13895, 0, RBL:none, CacheIP:none, Bayesian:0.5, 0.5, 0.5, Netcheck:none, DomainCache:0, MSF:not bulk, SPF:fn, MSBL:0, DNSBL:none, Custom_rules:0:1:0 X-HE-Tag: stick01_45256e66ab92f X-Filterd-Recvd-Size: 6594 Received: from eldon.alvh.no-ip.org (pc-211-245-160-190.cm.vtr.net [190.160.245.211]) (Authenticated sender: alvherre@alvh.no-ip.org) by omf14.b.hostedemail.com (Postfix) with ESMTPA; Fri, 20 Dec 2013 20:47:55 +0000 (UTC) Received: by eldon.alvh.no-ip.org (Postfix, from userid 1000) id 107751FC9; Fri, 20 Dec 2013 17:47:54 -0300 (CLST) Date: Fri, 20 Dec 2013 17:47:53 -0300 From: Alvaro Herrera To: os@ohmu.fi Cc: pgsql-bugs@postgresql.org Subject: Re: BUG #8470: 9.3 locking/subtransaction performance regression Message-ID: <20131220204753.GG22570@eldon.alvh.no-ip.org> References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="liOOAslEiF7prFVr" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --liOOAslEiF7prFVr Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit > 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 --liOOAslEiF7prFVr Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="optimize-multi-locks.patch" *** 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) --liOOAslEiF7prFVr Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --liOOAslEiF7prFVr--