pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <hlinnaka@iki.fi>
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Fix GIST readme on LSN vs NSN
Date: Mon, 18 Sep 2023 14:09:43 +0300
Message-ID: <4cb46e18-e688-524a-0f73-b1f03ed5d6ee@iki.fi> (raw)

The GiST README says:

> If the F_FOLLOW_RIGHT flag is not set, a scan compares the NSN on the
> child and the LSN it saw in the parent. If NSN < LSN, the scan looked
> at the parent page before the downlink was inserted, so it should
> follow the rightlink. Otherwise the scan saw the downlink in the
> parent page, and will/did follow that as usual.

While the code does this (in gistget.c):

> 	if (!XLogRecPtrIsInvalid(pageItem->data.parentlsn) &&
> 		(GistFollowRight(page) ||
> 		 pageItem->data.parentlsn < GistPageGetNSN(page)) &&
> 		opaque->rightlink != InvalidBlockNumber /* sanity check */ )
> 	{
> 		/* There was a page split, follow right link to add pages */

Note the comparison on LSN and NSN. The code seems correct, but the 
README got it backwards.

The narrow fix would be to change the "NSN < LSN" to "LSN < NSN" in the 
README. But I propose the attached patch to reword the sentence a little 
more.

-- 
Heikki Linnakangas
Neon (https://neon.tech)

Attachments:

fix-gist-readme-nsn-lsn.patch (text/x-patch, 1.2K) download diff --git a/src/backend/access/gist/README b/src/backend/access/gist/README index efb2730e18..8015ff19f0 100644 --- a/src/backend/access/gist/README +++ b/src/backend/access/gist/README @@ -271,10 +271,10 @@ should be visited too. When split inserts the downlink to the parent, it clears the F_FOLLOW_RIGHT flag in the child, and sets the NSN field in the child page header to match the LSN of the insertion on the parent. If the F_FOLLOW_RIGHT flag is not set, a scan compares the NSN on the child and the -LSN it saw in the parent. If NSN < LSN, the scan looked at the parent page -before the downlink was inserted, so it should follow the rightlink. Otherwise -the scan saw the downlink in the parent page, and will/did follow that as -usual. +LSN it saw in the parent. If the child's NSN is greater than the LSN seen on +the parent, the scan looked at the parent page before the downlink was +inserted, so it should follow the rightlink. Otherwise the scan saw the +downlink in the parent page, and will/did follow that as usual. A scan can't normally see a page with the F_FOLLOW_RIGHT flag set, because a page split keeps the child pages locked until the downlink has been inserted

view thread (3+ messages)  latest in thread

Message-ID: <4cb46e18-e688-524a-0f73-b1f03ed5d6ee@iki.fi>
Permalink:  ../4cb46e18-e688-524a-0f73-b1f03ed5d6ee@iki.fi/
Also on:    postgresql.org/message-id/4cb46e18-e688-524a-0f73-b1f03ed5d6ee@iki.fi

 ·  · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: hlinnaka@iki.fi
  Subject: Re: Fix GIST readme on LSN vs NSN
  In-Reply-To: <4cb46e18-e688-524a-0f73-b1f03ed5d6ee@iki.fi>

* 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