Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bVW3l-0003lV-Sa for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Aug 2016 03:44:33 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bVW3k-00081L-QZ for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Aug 2016 03:44:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bVW3k-00081E-AB for pgsql-hackers@postgresql.org; Fri, 05 Aug 2016 03:44:32 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bVW3d-0001xB-QC for pgsql-hackers@postgresql.org; Fri, 05 Aug 2016 03:44:31 +0000 Received: from bruce by momjian.us with local (Exim 4.84_2) (envelope-from ) id 1bVW3b-0001LL-Ic; Thu, 04 Aug 2016 23:44:23 -0400 Date: Thu, 4 Aug 2016 23:44:23 -0400 From: Bruce Momjian To: Claudio Freire Cc: Pavan Deolasee , pgsql-hackers Subject: Re: Heap WARM Tuples - Design Draft Message-ID: <20160805034423.GF22567@momjian.us> References: <20160804180746.GT1702@momjian.us> <20160804222148.GA22567@momjian.us> <20160805021522.GE22567@momjian.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-Pg-Spam-Score: -3.1 (---) 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 On Thu, Aug 4, 2016 at 11:53:05PM -0300, Claudio Freire wrote: > The point is avoiding duplicate rows in the output of index scans. > > I don't think you can avoid it simply by applying index condition > rechecks as the original proposal implies, in this case: > > CREATE TABLE t (id integer not null primary key, someid integer, dat integer); > CREATE INDEX i1 ON t (someid); > > INSERT INTO t (id, someid, dat) VALUES (1, 2, 100); OK, let me run through this and you can tell me where I am wrong. At this point there are two indexes, one on 'id' and one on 'someid'. > UPDATE t SET dat = dat + 1 where id = 1; This is a HOT update because no indexes were changed. > UPDATE t SET dat = dat + 1, id = 2 where id = 1; This changes the HOT chain to a WARM chain because one index is changed. That means that lookups on both indexes recheck the single visible tuple, if there is one. > UPDATE t SET dat = dat + 1, id = 3, someid = 3 where id = 2; This is ends the WARM chain, and creates new index entries because all indexes are changed. > UPDATE t SET dat = dat + 1, id = 1, someid = 2 where id = 3; This does the same thing. > SELECT * FROM t WHERE someid = 2; This uses the 'someid' index. The index contains three entries: 1. {someid=2} pointing to first WARM chain 2. {someid=3} pointing to single tuple (no HOT chain) 3. {someid=2} pointing to single tuple (no HOT chain) The scan of #1 returns no visible rows. #2 doesn't match the value in the WHERE clause, so we don't even check the heap. The scan of #3 returns one row. Remember, we don't scan past the end of the HOT chain, which is what we do now. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + As you are, so once was I. As I am, so you will be. + + Ancient Roman grave inscription + -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers