Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h9ttq-0003Ci-7O for pgsql-committers@arkaria.postgresql.org; Fri, 29 Mar 2019 15:58:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h9ttn-0007Gv-Vx for pgsql-committers@arkaria.postgresql.org; Fri, 29 Mar 2019 15:58:31 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1h9ttn-0007Gn-LD for pgsql-committers@lists.postgresql.org; Fri, 29 Mar 2019 15:58:31 +0000 Received: from mail-oi1-x244.google.com ([2607:f8b0:4864:20::244]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h9ttk-0003Eq-8I for pgsql-committers@lists.postgresql.org; Fri, 29 Mar 2019 15:58:30 +0000 Received: by mail-oi1-x244.google.com with SMTP id w137so2046743oiw.5 for ; Fri, 29 Mar 2019 08:58:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Vl55hi7MlTRoTGpJpmQrVEne9PmNCXp72QSNb/VrPN4=; b=xXQ4F/cHjo2LmdXfgUk9TozmcKUDkPxQPvzMvuWjxsC81tnGy7Ja3PB5U9HoLnjEKq nQBB3wd6RMFrKrs2B41nRHURQ+CwHvtoDat5TGQWTJcDK5SCs+38Tk7SMS0QGI3tJf16 rBkX2CfdyZmFm9+G7kmq/yKnREs5sWJm/Sr2/VjRJoedo2X1+81om/wkLGQkNHpb/euE I9XdITL4L73ZJfDhhPVAd0tUU34DGARIy7saCa7hJU/ngpKyZAbcUwQ6EnPyDdLacM1P yvAby/CtA/7htn8JNhrd7NUrBskW7HgaKuXME2Eht/ZmQYQl13+2Lxjr8i2kSJPvkwSY FbiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Vl55hi7MlTRoTGpJpmQrVEne9PmNCXp72QSNb/VrPN4=; b=O7pjV2N5ZMYR/vTi1H0yTGnxr5s/se/U5fsYMNHW7rKUMldXlTShrkGSjnhUQCGJTc o2R3IsqWfr4k8JgIKYo901sD/7IcXHK5MqsgNNRG3FLbm9JKjVi2ughkXRlvMIixr3BT HmBnYcuUNBIM1R7+RoSfunMabgQv2NNdlgdzLYLpD7BTDUszFS1VdOS9zPXsd19GlID4 Ps5a+eZIson28qdb0KmwV3X03qmKMFktfZ7FZSe6TupsGNt455XK+rEi3ckPmkM0eHbF S2KLLASPbdJEJ0HCZcmE3vqTPVzlzDne5YTBj/Ari7KlwfHiDbTudaCwe6VbBbdSG90Y gu6Q== X-Gm-Message-State: APjAAAU7yPfeVkBKBzt5nX+zFJQVWx0cmeM8r0A5TqrodC4LDYZ/LDrf r8QtAkRQkh77T7dMEMjcqcfYv088tfAc6cA2Tq1nRQ== X-Google-Smtp-Source: APXvYqyle2sHjL4YDwNSSmp7KrYPVP+122WwsE0XOLB+PlKPpZ7p5k8+4Qor0WPJSDey8fqasDKA9Wf/RpRQOa0HOdA= X-Received: by 2002:aca:544b:: with SMTP id i72mr3982719oib.51.1553875105787; Fri, 29 Mar 2019 08:58:25 -0700 (PDT) MIME-Version: 1.0 References: <20190329152906.356icmttz7yjgsyh@alap3.anarazel.de> In-Reply-To: <20190329152906.356icmttz7yjgsyh@alap3.anarazel.de> From: Simon Riggs Date: Fri, 29 Mar 2019 15:58:14 +0000 Message-ID: Subject: Re: pgsql: Compute XID horizon for page level index vacuum on primary. To: Andres Freund Cc: pgsql-committers , PostgreSQL Hackers Content-Type: multipart/alternative; boundary="000000000000b4d0be05853dbdd7" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --000000000000b4d0be05853dbdd7 Content-Type: text/plain; charset="UTF-8" On Fri, 29 Mar 2019 at 15:29, Andres Freund wrote: > On 2019-03-29 09:37:11 +0000, Simon Riggs wrote: > > > While trying to understand this, I see there is an even better way to > > optimize this. Since we are removing dead index tuples, we could alter > the > > killed index tuple interface so that it returns the xmax of the tuple > being > > marked as killed, rather than just a boolean to say it is dead. > > Wouldn't that quite possibly result in additional and unnecessary > conflicts? Right now the page level horizon is computed whenever the > page is actually reused, rather than when an item is marked as > deleted. As it stands right now, the computed horizons are commonly very > "old", because of that delay, leading to lower rates of conflicts. > I wasn't suggesting we change when the horizon is calculated, so no change there. The idea was to cache the data for later use, replacing the hint bit with a hint xid. That won't change the rate of conflicts, up or down - but it does avoid I/O. > > Indexes can then mark the killed tuples with the xmax that killed them > > rather than just a hint bit. This is possible since the index tuples > > are dead and cannot be used to follow the htid to the heap, so the > > htid is redundant and so the block number of the tid could be > > overwritten with the xmax, zeroing the itemid. Each killed item we > > mark with its xmax means one less heap fetch we need to perform when > > we delete the page - it's possible we optimize that away completely by > > doing this. > > That's far from a trivial feature imo. It seems quite possible that we'd > end up with increased overhead, because the current logic can get away > with only doing hint bit style writes - but would that be true if we > started actually replacing the item pointers? Because I don't see any > guarantee they couldn't cross a page boundary etc? So I think we'd need > to do WAL logging during index searches, which seems prohibitively > expensive. > Don't see that. I was talking about reusing the first 4 bytes of an index tuple's ItemPointerData, which is the first field of an index tuple. Index tuples are MAXALIGNed, so I can't see how that would ever cross a page boundary. > And I'm also doubtful it's worth it because: > > > Since this point of the code is clearly going to be a performance issue > it > > seems like something we should do now. > > I've tried quite a bit to find a workload where this matters, but after > avoiding redundant buffer accesses by sorting, and prefetching I was > unable to do so. What workload do you see where this would be really be > bad? Without the performance optimization I'd found a very minor > regression by trying to force the heap visits to happen in a pretty > random order, but after sorting that went away. I'm sure it's possible > to find a case on overloaded rotational disks where you'd find a small > regression, but I don't think it'd be particularly bad. > The code can do literally hundreds of random I/Os in an 8192 blocksize. What happens with 16 or 32kB? "Small regression" ? -- Simon Riggs http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --000000000000b4d0be05853dbdd7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Fri, 29 Mar 2019 at 15:29, Andres Freu= nd <andres@anarazel.de> wro= te:
=C2=A0
= On 2019-03-29 09:37:11 +0000, Simon Riggs wrote:
=C2= =A0
> While trying to understand this, I see there= is an even better way to
> optimize this. Since we are removing dead index tuples, we could alter= the
> killed index tuple interface so that it returns the xmax of the tuple = being
> marked as killed, rather than just a boolean to say it is dead.

Wouldn't that quite possibly result in additional and unnecessary
conflicts? Right now the page level horizon is computed whenever the
page is actually reused, rather than when an item is marked as
deleted. As it stands right now, the computed horizons are commonly very "old", because of that delay, leading to lower rates of conflicts= .

I wasn't suggesting we change whe= n the horizon is calculated, so no change there.

T= he idea was to cache the data for later use, replacing the hint bit with a = hint xid.

That won't change the rate of confli= cts, up or down - but it does avoid I/O.
=C2=A0
> Indexes can then mark the killed tuples with the xmax that killed them=
> rather than just a hint bit. This is possible since the index tuples > are dead and cannot be used to follow the htid to the heap, so the
> htid is redundant and so the block number of the tid could be
> overwritten with the xmax, zeroing the itemid. Each killed item we
> mark with its xmax means one less heap fetch we need to perform when > we delete the page - it's possible we optimize that away completel= y by
> doing this.

That's far from a trivial feature imo. It seems quite possible that we&= #39;d
end up with increased overhead, because the current logic can get away
with only doing hint bit style writes - but would that be true if we
started actually replacing the item pointers? Because I don't see any guarantee they couldn't cross a page boundary etc? So I think we'd = need
to do WAL logging during index searches, which seems prohibitively
expensive.

Don't see that.

I was talking about reusing the first 4 bytes of an index = tuple's ItemPointerData,
which is the first field of an index= tuple. Index tuples are MAXALIGNed, so I can't see how that would ever= cross a page boundary.
=C2=A0
And I'm also doubtful it's worth it because:

> Since this point of the code is clearly going to be a performance issu= e it
> seems like something we should do now.

I've tried quite a bit to find a workload where this matters, but after=
avoiding redundant buffer accesses by sorting, and prefetching I was
unable to do so.=C2=A0 What workload do you see where this would be really = be
bad? Without the performance optimization I'd found a very minor
regression by trying to force the heap visits to happen in a pretty
random order, but after sorting that went away.=C2=A0 I'm sure it's= possible
to find a case on overloaded rotational disks where you'd find a small<= br> regression, but I don't think it'd be particularly bad.

The code can do literally hundreds of random I/Os = in an 8192 blocksize. What happens with 16 or 32kB?

"Small regression" ?

--
Simon Riggs =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0=C2=A0=C2=A0http://www.2ndQuadrant.com/
Postgre= SQL Development, 24x7 Support, Remote DBA, Training & Services
--000000000000b4d0be05853dbdd7--