Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TZNKl-0005Zu-62 for pgsql-hackers@postgresql.org; Fri, 16 Nov 2012 14:55:55 +0000 Received: from moutng.kundenserver.de ([212.227.17.10]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TZNKi-000342-Am for pgsql-hackers@postgresql.org; Fri, 16 Nov 2012 14:55:54 +0000 Received: from anarazel.de (p5DDC6278.dip.t-dialin.net [93.220.98.120]) by mrelayeu.kundenserver.de (node=mreu0) with ESMTP (Nemesis) id 0M2YnR-1TH1T023uv-00sGT6; Fri, 16 Nov 2012 15:55:51 +0100 Received: by anarazel.de (Postfix, from userid 1000) id 99B5E1C00E5; Fri, 16 Nov 2012 15:55:50 +0100 (CET) Date: Fri, 16 Nov 2012 15:55:50 +0100 From: Andres Freund To: Alvaro Herrera Cc: pgsql-hackers@postgresql.org Subject: Re: foreign key locks Message-ID: <20121116145550.GC6505@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20121114162726.GE5161@alvh.no-ip.org> X-Provags-ID: V02:K0:8ptshzcHWtBFAfcMM0qzwsV1OX4KCqyqt1VgVwINK/S e5uHqJ06rCN7M6KtVNN28KgQibO8UZHdk/sngLtsKukiRoetPe ZklTtk0emKrZDTc2P6S6Q7MqcItVtHc4eXn5R6vPb+2sfT+oBy ZuluHDi/PJA5XoGO/MSgOp+VN6S2B8AJvKgKdSZUgPMbmyhWMM 7W5tePnQ85jrphpMWuoMILAIHVCwAwWkeVxbS+n2eWX731Fn7u DxEj3qrOcFlwwBBEAwDdgQc5nBH3cFuDy1jjGNXvld7Nh21LZ2 AUG5TO+pQFfLyC2kcBTtv/TGoTswg1Ju4ItbDhTxWGNatAphyQ MRwlj5/lleTjvaU99JShSA380a+1pRbqhxdlrZH7J X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201211/881 X-Sequence-Number: 216733 On 2012-11-14 13:27:26 -0300, Alvaro Herrera wrote: > Alvaro Herrera wrote: > > > > * In heap_lock_tuple's XMAX_IS_MULTI case > > > > > > [snip] > > > > > > why is it membermode > mode and not membermode >= mode? > > > > Uh, that's a bug. Fixed. As noticed in the comment above that snippet, > > there was a deadlock possible here. Maybe I should add a test to ensure > > this doesn't happen. > > Done: > https://github.com/alvherre/postgres/commit/df2847e38198e99f57e52490e1e9391ebb70d770 > > (I don't think this is worth a v24 submission). I have started doing some performance testing and I fear I was right in being suspicious about the performance difference for FOR SHARE locks: Tested with pgbench -p 5442 -U andres \ -c 30 -j 30 \ -M prepared -f ~/tmp/postgres-fklocks/select-for-share.sql \ -T 20 postgres on a pgbench -i -s 10 database, where select-for-share.sql is: BEGIN; \set naccounts 1000000 \setrandom aid 1 :naccounts SELECT abalance FROM pgbench_accounts WHERE aid = :aid FOR SHARE; \setrandom aid 1 :naccounts SELECT abalance FROM pgbench_accounts WHERE aid = :aid FOR SHARE; \setrandom aid 1 :naccounts SELECT abalance FROM pgbench_accounts WHERE aid = :aid FOR SHARE; COMMIT; which very roughly resembles workloads I have seen in reality (locking some records your rely on while you do some work). With 52b4729fcfc20f056f17531a6670d8c4b9696c39 (alvherre/fklocks) vs 273986bf0d39e5166eb15ba42ebff4803e23a688 (latest merged master) I get tps = 8986.133496 (excluding connections establishing) vs tps = 25307.861193 (excluding connections establishing) Thats nearly a factor of three which seems to be too big to be acceptable to me. So I really think we need to bring FOR SHARE locks back as a flag. I have done some benchmarking of other cases (plain pgbench, pgbench with foreign keys, large insertions, large amounts of FOR SHARE locks) and haven't found anything really outstanding so far. Greetings, Andres Freund -- Andres Freund http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services