Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TMLL0-000793-Rp for pgsql-hackers@postgresql.org; Thu, 11 Oct 2012 16:10:19 +0000 Received: from smtprelay0129.b.hostedemail.com ([64.98.42.129] helo=smtprelay.b.hostedemail.com) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TMLKz-0003MR-6g for pgsql-hackers@postgresql.org; Thu, 11 Oct 2012 16:10:18 +0000 Received: from filter.hostedemail.com (b-bigip1 [10.5.19.254]) by smtprelay03.b.hostedemail.com (Postfix) with SMTP id 4A9A43F8D81; Thu, 11 Oct 2012 16:10:16 +0000 (UTC) X-Panda: scanned! X-Spam-Summary: 50, 0, 0, , d41d8cd98f00b204, alvherre@alvh.no-ip.org, :::::, RULES_HIT:2:152:355:379:481:599:601:945:947:967:968:973:988:989:1260:1277:1311:1312:1313:1314:1345:1358:1359:1437:1461:1515:1516:1518:1519:1535:1593:1594:1595:1596:1605:1606:1730:1747:1777:1792:2194:2198:2199:2200:2234:2379:2393:2525:2540:2551:2553:2561:2564:2682:2685:2689:2693:2857:2859:2895:2911:2915:2933:2937:2939:2942:2945:2947:2951:2954:3022:3027:3138:3139:3140:3141:3142:3653:3865:3866:3867:3868:3869:3870:3871:3872:3873:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4117:4321:4362:4425:4605:4659:5007:6119:6261:7679:7809:7903:8531:8957:8985:9025:9121:9388:10004:10848:10913:11026:11256:11257:11473:11651:11658:11854:11914:12043:12050:12296:12438:12517:12519:12663:12740, 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: 6504 Received: from perhan.alvh.no-ip.org (unknown [190.95.25.25]) (Authenticated sender: alvherre@alvh.no-ip.org) by omf03.b.hostedemail.com (Postfix) with ESMTPA; Thu, 11 Oct 2012 16:10:14 +0000 (UTC) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 625A56E12D; Thu, 11 Oct 2012 13:10:12 -0300 (CLST) Date: Thu, 11 Oct 2012 13:10:12 -0300 From: Alvaro Herrera To: Andres Freund Cc: pgsql-hackers@postgresql.org, Alvaro Herrera Subject: Re: foreign key locks Message-ID: <20121011161012.GD4997@alvh.no-ip.org> References: <4FEAB90A0200002500048B7D@gw.wicourts.gov> <1346095617-sup-567@alvh.no-ip.org> <1346389151-sup-8379@alvh.no-ip.org> <201210111736.01406.andres@2ndquadrant.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <201210111736.01406.andres@2ndquadrant.com> User-Agent: Mutt/1.5.21 (2010-09-15) Content-Transfer-Encoding: quoted-printable X-Pg-Spam-Score: -0.6 (/) X-Archive-Number: 201210/583 X-Sequence-Number: 214819 Andres Freund wrote: > On Friday, August 31, 2012 06:59:51 AM Alvaro Herrera wrote: > > v21 is merged to latest master. > Ok, I am starting to look at this. >=20 > (working with a git merge of alvherre/fklocks into todays master) >=20 > In a very first pass as somebody who hasn't followed the discussions in= the=20 > past I took notice of the following things: >=20 > * compiles and survives make check Please verify src/test/isolation's make installcheck as well. > * README.tuplock jumps in quite fast without any introduction Hmm .. I'll give that a second look. Maybe some material from the pgcon paper should be added as introduction. > * "This is a bit of a performance regression, but since we expect FOR S= HARE=20 > locks to be seldom used, we don=E2=80=99t feel this is a serious proble= m." makes me a=20 > bit uneasy, will look at performance separately Thanks. Keep in mind though that the bits we really want good performance for is FOR KEY SHARE, which is going to be used in foreign keys. FOR SHARE is staying just for hypothetical backwards compatibility. I just found that people is using it, see for example http://stackoverflow.com/a/3243083 > * Should RelationGetIndexattrBitmap check whether a unique index is ref= erenced=20 > from a pg_constraint row? Currently we pay part of the overhead indepen= dent=20 > from the existance of foreign keys. Noah also suggested something more or less in the along the same lines. My answer is that I don't want to do it currently; maybe we can improve on what indexes we use later, but since this can be seen as a modularity violation, I prefer to keep it as simple as possible. > * mode =3D=3D LockTupleKeyShare, =3D=3D LockTupleShare, =3D=3D LockTupl= eUpdate in=20 > heap_lock_tuple's BeingUpdated branch look like they should be an if/el= se if Hm, will look at that. > * I don't really like HEAP_UPDATE_KEY_REVOKED as a name, what about=20 > HEAP_KEYS_UPDATED (akin to HEAP_HOT_UPDATED) Thanks. > * how can we get infomask2 & HEAP_UPDATE_KEY_REVOKED && infomask &=20 > HEAP_XMAX_LOCK_ONLY? SELECT FOR KEY UPDATE? This didn't exist initially, but previous reviewers (Noah) felt that it made sense to have it for consistency. It makes the lock conflict table make more sense, anyway. > * heap_lock_tuple with mode =3D=3D LockTupleKeyShare && nowait looks li= ke it would=20 > wait anyway in heap_lock_updated_tuple_rec Oops. > * rename HeapSatisfiesHOTUpdate, adjust comments? Yeah. > * I wonder whether HeapSatisfiesHOTUpdate could be made to compute the = result=20 > for key_attrs and hot_attrs at the same time, often enough they will do= the=20 > same thing on the same column Hmm, I will look at that. > * you didn't start it but I find that all those l$i jump labels make th= e code=20 > harder to follow You mean you suggest to have them renamed? That can be arranged. > * shouldn't XmaxGetUpdateXid be rather called MultiXactIdGetUpdateXid o= r such?=20 Yes. > /* > * If the existing lock mode is identical to or weaker than the new > * one, we can act as though there is no existing lock and have the > * upper block handle this. > */ > "block"? Yeah, as in "the if {} block above". Since this is not clear maybe it needs rewording. > * I am not yet sure whether the (xmax =3D=3D add_to_xmax) optimization = in=20 > compute_new_xmax_infomask is actually safe Will think about it and add a/some comment(s). > * ConditionalMultiXactIdWait and MultiXactIdWait should probably rely o= n a=20 > common implementation Will look at that. > * I am not that convinced that moving the waiting functions away from=20 > multixact.c is a good idea, but I guess the required knowledge about lo= ckmodes=20 > makes it hard not to do so Yeah. The line between multixact.c and heapam.c is a zigzag currently, I think. Maybe it needs to be more clear; I think the multixact modes really belong into heapam.c, and they are just uint32 to multixact.c. I wasn't brave enough to attempt this; maybe I should. > * Haven't looked yet, but I have a slightly uneasy feeling about Hot St= andby=20 > interactions. Did you look at that? >=20 > * Hm? > HeapTupleSatisfiesVacuum > #if 0 > ResetMultiHintBit(tuple, buffer, xmax, true); > #endif Yeah. I had a couple of ResetMultiHintBit calls sprinkled in some of the tqual routines, with the idea that if they saw multis that were no longer live they could be removed, and replaced by just the remaining updater. However, this doesn't really work because it's not safe to change the Xmax when not holding exclusive lock, and the tqual routines don't know that. So we're stuck with keeping the multi in there, even when we know they are no longer interesting. This is a bit sad, because it would be a performance benefit to remove them; but it's not strictly necessary for correctness, so we can leave the optimization for a later phase. I let those #ifdefed out calls in place so that it's easy to see where the reset needs to happen. > This obviously is not a real review, but just learning what the problem= & patch=20 > actually try to do. This is quite a bit to take in ;). I will let it si= nk in=20 > ant try to have a look at the architecture and performance next. Well, the patch is large and complex so any review is obviously going to take a long time. --=20 =C3=81lvaro Herrera http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services