Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TthC6-00070N-Bm for pgsql-hackers@arkaria.postgresql.org; Fri, 11 Jan 2013 16:10:58 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TthC5-0005Sm-Ks for pgsql-hackers@arkaria.postgresql.org; Fri, 11 Jan 2013 16:10:57 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TthC3-0005Qw-49 for pgsql-hackers@postgresql.org; Fri, 11 Jan 2013 16:10:55 +0000 Received: from smtprelay0162.b.hostedemail.com ([64.98.42.162] helo=smtprelay.b.hostedemail.com) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TthC1-00061Z-Lg for pgsql-hackers@postgresql.org; Fri, 11 Jan 2013 16:10:54 +0000 Received: from filter.hostedemail.com (b-bigip1 [10.5.19.254]) by smtprelay05.b.hostedemail.com (Postfix) with SMTP id DCB944FA31C; Fri, 11 Jan 2013 16:10:52 +0000 (UTC) X-Panda: scanned! X-Spam-Summary: 50, 0, 0, , d41d8cd98f00b204, alvherre@alvh.no-ip.org, :::::::, RULES_HIT:355:379:599:601:960:967:973:988:989:1260:1277:1311:1312:1313:1314:1345:1358:1359:1437:1515:1516:1518:1519:1534:1542:1593:1594:1595:1596:1711:1730:1747:1777:1792:2198:2199:2393:2525:2540:2560:2563:2682:2685:2828:2859:2895:2933:2937:2939:2942:2945:2947:2951:2954:3022:3027:3138:3139:3140:3141:3142:3354:3636:3865:3866:3867:3868:3869:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4250:4605:4659:5007:6119:6261:7679:7809:7875:7903:8957:9025:9121:10004:10400:10848:11233:11256:11257:11658:11914:12517:12519:12679, 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:0:0 X-Session-Marker: 616C76686572726540616C76682E6E6F2D69702E6F7267 X-Filterd-Recvd-Size: 3547 Received: from perhan.alvh.no-ip.org (unknown [190.95.24.72]) (Authenticated sender: alvherre@alvh.no-ip.org) by omf10.b.hostedemail.com (Postfix) with ESMTPA; Fri, 11 Jan 2013 16:10:51 +0000 (UTC) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id A11DF6E070; Fri, 11 Jan 2013 13:10:49 -0300 (CLST) Date: Fri, 11 Jan 2013 13:10:49 -0300 From: Alvaro Herrera To: Andres Freund Cc: Erik Rijkers , Kevin Grittner , pgsql-hackers@postgresql.org Subject: Re: foreign key locks Message-ID: <20130111161049.GD4208@alvh.no-ip.org> References: <20121129152326.69330@gmx.com> <20121129160220.GA4942@alvh.no-ip.org> <20121129161654.GB4942@alvh.no-ip.org> <20121228204847.GD4150@alvh.no-ip.org> <20130110210040.GB4110@alvh.no-ip.org> <20130110212218.GE4329@awork2.anarazel.de> <20130111151147.GB4208@alvh.no-ip.org> <20130111151930.GB6049@awork2.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <20130111151930.GB6049@awork2.anarazel.de> User-Agent: Mutt/1.5.21 (2010-09-15) Content-Transfer-Encoding: quoted-printable X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Andres Freund wrote: > No, I was thinking about an update without triggers present. >=20 > T0: CREATE TABLE tbl(id serial pk, name text unique, data text); > T1: BEGIN; -- read committed > T1: UPDATE tbl SET name =3D 'foo' WHERE name =3D 'blarg'; /* key update o= f row id =3D 1 */ > T2: BEGIN; -- read committed > T2: UPDATE tbl SET name =3D 'blarg', data =3D 'blarg' WHERE id =3D 1; /* = no key update, waiting */ > T1: COMMIT; > T2: /* UPDATE follows to updated row, due to the changed name its a key u= pdate now */ >=20 > Does that make sense? So I guess your question is "is T2 now holding a TupleLockExclusive lock?" To answer it, I turned your example into a isolationtester spec: setup { CREATE TABLE tbl(id serial primary key, name text unique, data text); INSERT INTO tbl VALUES (1, 'blarg', 'no data'); } teardown { DROP TABLE tbl; } session "s1" step "s1b" { BEGIN; } step "s1u" { UPDATE tbl SET name =3D 'foo' WHERE name =3D 'blarg'; } step "s1c" { COMMIT; } session "s2" step "s2b" { BEGIN; } step "s2u" { UPDATE tbl SET name =3D 'blarg', data =3D 'blarg' WHERE id =3D= 1; } step "s2c" { COMMIT; } session "s3" step "s3l" { SELECT * FROM tbl FOR KEY SHARE; } permutation "s1b" "s1u" "s2b" "s2u" "s1c" "s3l" "s2c" And the results: Parsed test spec with 3 sessions starting permutation: s1b s1u s2b s2u s1c s3l s2c step s1b: BEGIN; step s1u: UPDATE tbl SET name =3D 'foo' WHERE name =3D 'blarg'; step s2b: BEGIN; step s2u: UPDATE tbl SET name =3D 'blarg', data =3D 'blarg' WHERE id =3D 1;= step s1c: COMMIT; step s2u: <... completed> step s3l: SELECT * FROM tbl FOR KEY SHARE; step s2c: COMMIT; step s3l: <... completed> id name data=20=20=20=20=20=20=20=20=20=20=20 1 blarg blarg=20=20=20=20=20=20=20=20=20=20 So session 3 is correctly waiting for session 2 to finish before being ablt to grab its FOR KEY SHARE lock, indicating that session 2 is holding a FOR UPDATE lock. Good. If I change session 1 to update the data column instead of name, session 3 no longer needs to wait for session 2, meaning session 2 now only grabs a FOR NO KEY UPDATE lock. Also good. --=20 =C1lvaro Herrera http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services --=20 Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers