Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TZjFy-0004Mt-4X for pgsql-hackers@postgresql.org; Sat, 17 Nov 2012 14:20:26 +0000 Received: from moutng.kundenserver.de ([212.227.126.186]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TZjFv-00038x-Hw for pgsql-hackers@postgresql.org; Sat, 17 Nov 2012 14:20:25 +0000 Received: from anarazel.de (p5DDC6278.dip.t-dialin.net [93.220.98.120]) by mrelayeu.kundenserver.de (node=mreu4) with ESMTP (Nemesis) id 0Lsaqr-1TBDDQ3241-012cuG; Sat, 17 Nov 2012 15:20:21 +0100 Received: by anarazel.de (Postfix, from userid 1000) id C8F951C00E5; Sat, 17 Nov 2012 15:20:20 +0100 (CET) Date: Sat, 17 Nov 2012 15:20:20 +0100 From: Andres Freund To: Noah Misch Cc: Alvaro Herrera , pgsql-hackers@postgresql.org Subject: Re: foreign key locks Message-ID: <20121117142020.GB4222@awork2.anarazel.de> References: <4FEAB90A0200002500048B7D@gw.wicourts.gov> <1346389151-sup-8379@alvh.no-ip.org> <20121018195820.GO3763@alvh.no-ip.org> <201210270006.54728.andres@2ndquadrant.com> <20121114152347.GA5161@alvh.no-ip.org> <20121114162726.GE5161@alvh.no-ip.org> <20121116002459.GB4347@tornado.leadboat.com> <20121116161747.GC4454@alvh.no-ip.org> <20121116163112.GF6505@awork2.anarazel.de> <20121117033151.GB24972@tornado.leadboat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20121117033151.GB24972@tornado.leadboat.com> X-Provags-ID: V02:K0:P6HNa+ggUhrLCao2SEj5TcQtYGCVvw36ZL19gz6uQKC 4qxeL5vAwHGSsUhiwfRHtdi5oTAftsgw1thLmCWby2pJV3Rtox DLkP+mt7RfSqx1tzKXQOS8psoi+yllh4YJLrh9uZEKGN4awaJS /TESHibbRL60XRSIJ670MM07YR+0nPYQJA0Hdy+V44EsN+GuaC D91YyiU/8RmI9EsO5WhvxPWRRxJLbpZjGtLzw++x6C7tzRQ3+h uLq3P2srBSHZ4x14l7wSqK5BKV8zcpy5g8Y4ws5ZEJdcu0FKCS ynIgZq5QA3LExVxbStAfThLNo5ANkJjhhtI6FehPlN02hR9MLa qi1oWFG0nfZIb2h5odnL204NQf/16QNJbNQC6CZYm X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201211/940 X-Sequence-Number: 216792 On 2012-11-16 22:31:51 -0500, Noah Misch wrote: > On Fri, Nov 16, 2012 at 05:31:12PM +0100, Andres Freund wrote: > > On 2012-11-16 13:17:47 -0300, Alvaro Herrera wrote: > > > Andres is on the verge of convincing me that we need to support > > > singleton FOR SHARE without multixacts due to performance concerns. > > > > I don't really see any arguments against doing so. We aren't in a that > > big shortage of flags and if we need more than available I think we can > > free some (e.g. XMAX/XMIN_INVALID). > > The patch currently leaves two unallocated bits. Reclaiming currently-used > bits means a binary compatibility break. Until we plan out such a thing, > reclaimable bits are not as handy as never-allocated bits. I don't think we > should lightly expend one of the final two. Not sure what you mean with a binary compatibility break? pg_upgrade'ability? What I previously suggested somewhere was: #define HEAP_XMAX_SHR_LOCK 0x0010 #define HEAP_XMAX_EXCL_LOCK 0x0040 #define HEAP_XMAX_KEYSHR_LOCK (HEAP_XMAX_SHR_LOCK|HEAP_XMAX_EXCL_LOCK) /* * Different from _LOCK_BITS because it doesn't include LOCK_ONLY */ #define HEAP_LOCK_MASK (HEAP_XMAX_SHR_LOCK|HEAP_XMAX_EXCL_LOCK) #define HEAP_XMAX_IS_SHR_LOCKED(tup) \ (((tup)->t_infomask & HEAP_LOCK_BITS) == HEAP_XMAX_SHR_LOCK) #define HEAP_XMAX_IS_EXCL_LOCKED(tup) \ (((tup)->t_infomask & HEAP_LOCK_BITS) == HEAP_XMAX_EXCL_LOCK) #define HEAP_XMAX_IS_KEYSHR_LOCKED(tup) \ (((tup)->t_infomask & HEAP_LOCK_BITS) == HEAP_XMAX_KEYSHR_LOCK) It makes checking for locks sightly more more complicated, but its not too bad... > > > It > > > would be useful for more people to chime in here: is FOR SHARE an > > > important case to cater for? I wonder if using FOR KEY SHARE (keep > > > performance characteristics, but would need to revise application code) > > > would satisfy Andres' users, for example. > > > > It definitely wouldn't help in the cases I have seen because the point > > is to protect against actual content changes of the rows, not just the > > keys. > > Note that you actually need to use explicit FOR SHARE/UPDATE for > > correctness purposes in many scenarios unless youre running in 9.1+ > > serializable mode. And that cannot be used in some cases (try queuing > > for example) because the rollback rates would be excessive. > > I agree that tripling FOR SHARE cost is risky. Where is the added cost > concentrated? Perchance that multiple belies optimization opportunities. Good question, let me play a bit. Greetings, Andres Freund -- Andres Freund http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services