From: Bruce Momjian <bruce@momjian.us>
To: Claudio Freire <klaussfreire@gmail.com>
Cc: Pavan Deolasee <pavan.deolasee@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: Heap WARM Tuples - Design Draft
Date: Thu, 4 Aug 2016 23:44:23 -0400
Message-ID: <20160805034423.GF22567@momjian.us> (raw)
In-Reply-To: <CAGTBQpZPoHRSZM4MCXRR-BtyWbC2Zwhn_FbYaJYE2boaE7WqaQ@mail.gmail.com>
References: <CABOikdMop5Rb_RnS2xFdAXMZGSqcJ-P-BY2ruMd+buUkJ4iDPw@mail.gmail.com>
<CAGTBQpYpu463mQByEp5MLqcdqzOHN1qOBCDN6BRb+ehMF+b=UA@mail.gmail.com>
<CAGTBQpYsJnfyBhmvDvY9-vWex518=J4V8EfTEHvSC7MNmE=c9A@mail.gmail.com>
<20160804180746.GT1702@momjian.us>
<CAGTBQpZkYKO608bJPMgBkr75ujQvZTJxh4DdBXSJHZGSHZPr8g@mail.gmail.com>
<20160804222148.GA22567@momjian.us>
<CAGTBQpZPWzfN7roWOr-Li4GoCXnCGYPqbVPmZqJGAgh-qs0mow@mail.gmail.com>
<20160805021522.GE22567@momjian.us>
<CAGTBQpZPoHRSZM4MCXRR-BtyWbC2Zwhn_FbYaJYE2boaE7WqaQ@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
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 <bruce@momjian.us> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: bruce@momjian.us, klaussfreire@gmail.com, pavan.deolasee@gmail.com
Subject: Re: Heap WARM Tuples - Design Draft
In-Reply-To: <20160805034423.GF22567@momjian.us>
References: <CABOikdMop5Rb_RnS2xFdAXMZGSqcJ-P-BY2ruMd+buUkJ4iDPw@mail.gmail.com> <CAGTBQpYpu463mQByEp5MLqcdqzOHN1qOBCDN6BRb+ehMF+b=UA@mail.gmail.com> <CAGTBQpYsJnfyBhmvDvY9-vWex518=J4V8EfTEHvSC7MNmE=c9A@mail.gmail.com> <20160804180746.GT1702@momjian.us> <CAGTBQpZkYKO608bJPMgBkr75ujQvZTJxh4DdBXSJHZGSHZPr8g@mail.gmail.com> <20160804222148.GA22567@momjian.us> <CAGTBQpZPWzfN7roWOr-Li4GoCXnCGYPqbVPmZqJGAgh-qs0mow@mail.gmail.com> <20160805021522.GE22567@momjian.us> <CAGTBQpZPoHRSZM4MCXRR-BtyWbC2Zwhn_FbYaJYE2boaE7WqaQ@mail.gmail.com> <20160805034423.GF22567@momjian.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox