Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bVWkx-0005Kq-13 for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Aug 2016 04:29:11 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bVWkw-0004lw-HR for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Aug 2016 04:29:10 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bVWjY-0003Fz-IR for pgsql-hackers@postgresql.org; Fri, 05 Aug 2016 04:27:44 +0000 Received: from mail-oi0-x231.google.com ([2607:f8b0:4003:c06::231]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bVWjV-0002Nl-DW for pgsql-hackers@postgresql.org; Fri, 05 Aug 2016 04:27:43 +0000 Received: by mail-oi0-x231.google.com with SMTP id 4so139814649oih.2 for ; Thu, 04 Aug 2016 21:27:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=BhrivaY1cs55nHHVTgpRmKiP0DUBqthIq2ACWqjc35A=; b=pNqjYTYhAV3O3R8KLzvm1k0nOx/KZfAaDS7prnh5r1tqcpJQSeM3d11fDKK1ROxccC mdKlpbMZd7+vJ4K8wh8fF7mlndQnqGoRWkTxpzJEXjSptttdzTPF+Lt7pZCVjBjMZHGn BkXaAXnNhsK07EJ38jPMqou6Hd7Z9UHFtCyCOYnaXkulAV74Tmn7yVyRC7TVG16tqpAg HnsWaRwwqlnEGyRMgIaS/RJ3kAp+qxkBY13XfBOeJoP+K0L9NTKOIqPBt3MtU3AZEVMT wCbkg6vXFu9Pko/M0CjQJppnpmRXhS+DFRyYk5CAe+DLZrrXLwwzExmrjBWlc/e4gnRX qiCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=BhrivaY1cs55nHHVTgpRmKiP0DUBqthIq2ACWqjc35A=; b=clhYzAPge+0KV2l47upHP7FFFn3XWVoswu1XYhxbdzHnVFj1XI+aslohIJTUf38yLZ JNg6pNcVXIjeodragXN4KzvLuowwIbP6oMCY+Jy3izIv78SNBg1eAZIq5Zz9UFrBOPX/ AaQnOIEfoO7RZFFdUYjTieRjWWTqVMAp3tznExPA+ZMq29XtloCgVcLVISdKAlDjWXfv 5jG7mTO14lW8FNdz8iDuY8sxvTdMseBZgG0cfuEQ6dIN+Obcx22HMw62SPQ3PipW1ds1 yWAkIXEpnHmxsPLpN0iS0N4d79rWe0H9GdTT581t2nWB2Rc9TvNe3JKR/w45thuo7gpZ nBiQ== X-Gm-Message-State: AEkoousmu46ftytIkAoD7y0ynPoaxklKEh12b1F1B9jWLcaofS0QDDAaYKuoDN2zXxrCVPZOGrch2Pf5OAFH4A== X-Received: by 10.202.74.205 with SMTP id x196mr46384144oia.74.1470371260518; Thu, 04 Aug 2016 21:27:40 -0700 (PDT) MIME-Version: 1.0 Received: by 10.202.50.70 with HTTP; Thu, 4 Aug 2016 21:27:19 -0700 (PDT) In-Reply-To: References: <20160804180746.GT1702@momjian.us> <20160804222148.GA22567@momjian.us> <20160805021522.GE22567@momjian.us> From: Pavan Deolasee Date: Fri, 5 Aug 2016 09:57:19 +0530 Message-ID: Subject: Re: Heap WARM Tuples - Design Draft To: Claudio Freire Cc: Bruce Momjian , pgsql-hackers Content-Type: multipart/alternative; boundary=001a113dbc2aabd91705394b7c66 X-Pg-Spam-Score: -2.7 (--) 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 --001a113dbc2aabd91705394b7c66 Content-Type: text/plain; charset=UTF-8 On Fri, Aug 5, 2016 at 8:23 AM, Claudio Freire wrote: > On Thu, Aug 4, 2016 at 11:15 PM, Bruce Momjian wrote: > > > > > OK, that's a lot of text, and I am confused. Please tell me the > > advantage of having an index point to a string of HOT chains, rather > > than a single one? Is the advantage that the index points into the > > middle of the HOT chain rather than at the beginning? I can see some > > value to that, but having more ctid HOT headers that can't be removed > > except by VACUUM seems bad, plus the need for index rechecks as you > > cross to the next HOT chain seems bad. > > > > The value of WARM is to avoid index bloat --- right now we traverse the > > HOT chain on a single page just fine with no complaints about speed so I > > don't see a value to optimizing that traversal, and I think the key > > rechecks and ctid bloat will make it all much slower. > > > > It also seems much more complicated. > > 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); > UPDATE t SET dat = dat + 1 where id = 1; > UPDATE t SET dat = dat + 1, id = 2 where id = 1; > UPDATE t SET dat = dat + 1, id = 3, someid = 3 where id = 2; > UPDATE t SET dat = dat + 1, id = 1, someid = 2 where id = 3; > SELECT * FROM t WHERE someid = 2; > > That, I believe, will cause the problematic chains where the condition > recheck passes both times the last visible tuple is visited during the > scan. It will return more than one tuple when in reality there is only > one. > Hmm. That seems like a real problem. The only way to address that is to ensure that for a given WARM chain and given index key, there must exists only a single index entry. There can and will be multiple entries if the index key changes, but if the index key changes to the original value (or any other value already in the WARM chain) again, we must not add another index entry. Now that does not seem like a very common scenario and skipping a duplicate index entry does have its own benefit, so may be its not a terrible idea to try that. You're right, it may be expensive to search for an existing matching index key for the same root line pointer. But if we could somehow short-circuit the more common case, it might still be worth trying. The other idea you mentioned is to index intermediate tuples but somehow restrict WARM chain following knowing that the subsequent tuples are reachable via different index tuple. I see two major problems with that approach: 1. When HOT or WARM chains are pruned and dead tuples removed, we may lose the knowledge about key changes between intermediate updates. Without that its seems difficult to know when to stop while following chain starting from the old index tuple. 2. The existence of index pointers to intermediate tuples will lead to index bloat. This is the same problem that we found in Simon's original proposal (discussed internally). None of the intermediate line pointers can be vacuumed until the entire chain becomes DEAD. Event if the a duplicate index key is inserted for every index, knowing that and reclaiming to the index pointers to the original root line pointer, will be difficult. > > Not to mention the cost of scanning the chain of N tuples N times, > making it quadratic - bound by the number of tuples that can fit a > page, but still high. > > Solving that, I believe, will remove all the simplicity of pointing to > root tuples. > > You're right. But having all indexes point to the root line pointer makes things simpler to manage and less buggy. So if we can somehow solve the duplicate tuples problem, even at additional cost at update time, it might still be worth. I would suggest that we should think more and we can find some solution to the problem. > > I don't really see how you'd do that on yours. You seem to assume > finding a particular key-item pointer pair in an index would be > efficient, but IMHO that's not the case. > That's true. But we could somehow short-circuit the more common pattern, that might still be worth. For corner cases, we can fall back to non-HOT update and keep things simple. It will still be a huge improvement over what we have currently. Thanks, Pavan -- Pavan Deolasee http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services --001a113dbc2aabd91705394b7c66 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


On Fri, Aug 5, 2016 at 8:23 AM, Claudio Freire <klaussfreire@gmai= l.com> wrote:
On Thu, Aug 4, 2016 at 11:15 PM, Bruce Momjian &= lt;bruce@momjian.us> wrote:
<= br> >
> OK, that's a lot of text, and I am confused.=C2=A0 Please tell me = the
> advantage of having an index point to a string of HOT chains, rather > than a single one?=C2=A0 Is the advantage that the index points into t= he
> middle of the HOT chain rather than at the beginning?=C2=A0 I can see = some
> value to that, but having more ctid HOT headers that can't be remo= ved
> except by VACUUM seems bad, plus the need for index rechecks as you > cross to the next HOT chain seems bad.
>
> The value of WARM is to avoid index bloat --- right now we traverse th= e
> HOT chain on a single page just fine with no complaints about speed so= I
> don't see a value to optimizing that traversal, and I think the ke= y
> rechecks and ctid bloat will make it all much slower.
>
> It also seems much more complicated.

The point is avoiding duplicate rows in the output of index sca= ns.

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 intege= r);
CREATE INDEX i1 ON t (someid);

INSERT INTO t (id, someid, dat) VALUES (1, 2, 100);
UPDATE t SET dat =3D dat + 1 where id =3D 1;
UPDATE t SET dat =3D dat + 1, id =3D 2 where id =3D 1;
UPDATE t SET dat =3D dat + 1, id =3D 3, someid =3D 3 where id =3D 2;
UPDATE t SET dat =3D dat + 1, id =3D 1, someid =3D 2 where id =3D 3;
SELECT * FROM t WHERE someid =3D 2;

That, I believe, will cause the problematic chains where the condition
recheck passes both times the last visible tuple is visited during the
scan. It will return more than one tuple when in reality there is only
one.

Hmm. That seems like a real proble= m. The only way to address that is to ensure that for a given WARM chain an= d given index key, there must exists only a single index entry. There can a= nd will be multiple entries if the index key changes, but if the index key = changes to the original value (or any other value already in the WARM chain= ) again, we must not add another index entry. Now that does not seem like a= very common scenario and skipping a duplicate index entry does have its ow= n benefit, so may be its not a terrible idea to try that. You're right,= it may be expensive to search for an existing matching index key for the s= ame root line pointer. But if we could somehow short-circuit the more commo= n case, it might still be worth trying.

The other = idea you mentioned is to index intermediate tuples but somehow restrict WAR= M chain following knowing that the subsequent tuples are reachable via diff= erent index tuple. I see two major problems with that approach:
<= br>
1. When HOT or WARM chains are pruned and dead tuples removed= , we may lose the knowledge about key changes between intermediate updates.= Without that its seems difficult to know when to stop while following chai= n starting from the old index tuple.

2. The existe= nce of index pointers to intermediate tuples will lead to index bloat. This= is the same problem that we found in Simon's original proposal (discus= sed internally). None of the intermediate line pointers can be vacuumed unt= il the entire chain becomes DEAD. Event if the a duplicate index key is ins= erted for every index, knowing that and reclaiming to the index pointers to= the original root line pointer, will be difficult.
=C2=A0
<= blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px= #ccc solid;padding-left:1ex">
Not to mention the cost of scanning the chain of N tuples N times,
making it quadratic - bound by the number of tuples that can fit a
page, but still high.

Solving that, I believe, will remove all the simplicity of pointing to
root tuples.


You're right. But having all index= es point to the root line pointer makes things simpler to manage and less b= uggy. So if we can somehow solve the duplicate tuples problem, even at addi= tional cost at update time, it might still be worth. I would suggest that w= e should think more and we can find some solution to the problem.
=C2=A0

I don't really see how you'd do that on yours. You seem to assume finding a particular key-item pointer pair in an index would be
efficient, but IMHO that's not the case.

That's true. But we could somehow short-circuit = the more common pattern, that might still be worth. For corner cases, we ca= n fall back to non-HOT update and keep things simple. It will still be a hu= ge improvement over what we have currently.

Thanks,
Pavan

--
=C2=A0Pavan Deolasee =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 htt= p://www.2ndQuadrant.com/
=C2=A0PostgreSQL Development, 24x7 Support,= Training & Services
--001a113dbc2aabd91705394b7c66--