pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: yuansong <yyuansong@126.com>
To: Peter Geoghegan <pg@bowt.ie>
To: pgsql-hackers@lists.postgresql.org <pgsql-hackers@lists.postgresql.org>
Subject: Re:Re: Re:Re:Re: backup server core when redo btree_xlog_insert that type is XLOG_BTREE_INSERT_POST
Date: Sun, 1 Dec 2024 23:07:16 +0800 (CST)
Message-ID: <51c0c5bb.2330.19382c2fb6f.Coremail.yyuansong@126.com> (raw)
In-Reply-To: <CAH2-WznTAAbNJMCddUwxepgpicxhH6y55+zWSnOMiKOSLKY2TQ@mail.gmail.com>
References: <bdc9e08.a2c5.1934f3f42d0.Coremail.yyuansong@126.com>
	<CAH2-Wznps8CcjbmRAmOMqv5K6pKZQxR0TTQLBhQAu+PxynmjBQ@mail.gmail.com>
	<64d41b6e.9246.1936d410e18.Coremail.yyuansong@126.com>
	<39b023e9.1ed0.19382575335.Coremail.yyuansong@126.com>
	<CAH2-WznTAAbNJMCddUwxepgpicxhH6y55+zWSnOMiKOSLKY2TQ@mail.gmail.com>

I confirmed that there's an issue with prematurely ending the loop. When I enter the if (unlikely(result == 0 && key->scantid != NULL)) block, low = 2, mid = 4, and high = 4. At this point, the offset of insertstate->postingoff is obtained from the mid value, which is 3. However, the loop doesn't terminate and continues, causing the value of low to become 4. This is where I applied my fix based on master.




I aslo don't know how to fix the bug and commit it to the community master.


At 2024-12-01 21:33:28, "Peter Geoghegan" <pg@bowt.ie> wrote:
>On Sun, Dec 1, 2024 at 8:11 AM yuansong <yyuansong@126.com> wrote:
>> the _bt_binsrch_insert function always returns low, but during the post list search, are there cases where low and mid are unequal?
>>
>> If so, this could potentially cause an offset in the subsequent _bt_insertonpg function.
>>
>> maybe we fix it like this ?
>
>Why?
>
>The "if (unlikely(result == 0 && key->scantid != NULL))" block is only
>hit when we have an "exactly-equal" index tuple -- which means an
>index tuple with a posting list covering a range of heap TIDs that our
>scantid is covered by. There should be at most one index tuple like
>this on any leaf page -- otherwise the index is corrupt.
>
>The hardening that I added for the posting list split stuff was added
>to 13.4 and 13.5. You're running a very old point release (13.2), so
>you weren't running a version of the server with that hardening.
>
>--
>Peter Geoghegan


Attachments:

0001-Fix-the-error-in-the-B-tree-binary-search-for-the-po.patch (application/octet-stream, 1.2K) download From a493dabdce0faea127c049b2a4cc58be0e934e04 Mon Sep 17 00:00:00 2001 From: yyuansong <yyuansong@126.com> Date: Sun, 1 Dec 2024 21:38:35 +0800 Subject: [PATCH] Fix the error in the B-tree binary search for the post list. The _bt_binsrch_insert function always returns low, but during the post list search, there may be cases where the values of low and mid are not equal. Additionally, modify the code to terminate the search early once a matching post list value is found. Discussion: https://www.postgresql.org/message-id/flat/bdc9e08.a2c5.1934f3f42d0.Coremail.yyuansong%40126.com Signed-off-by: yyuansong <yyuansong@126.com> --- src/backend/access/nbtree/nbtsearch.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/backend/access/nbtree/nbtsearch.c b/src/backend/access/nbtree/nbtsearch.c index 2551df8a67..ae9c25e6c2 100644 --- a/src/backend/access/nbtree/nbtsearch.c +++ b/src/backend/access/nbtree/nbtsearch.c @@ -567,6 +567,8 @@ _bt_binsrch_insert(Relation rel, BTInsertState insertstate) RelationGetRelationName(rel)))); insertstate->postingoff = _bt_binsrch_posting(key, page, mid); + low = mid; + break; } } -- 2.46.0.windows.1

view thread (11+ messages)  latest in thread

Message-ID: <51c0c5bb.2330.19382c2fb6f.Coremail.yyuansong@126.com>
Permalink:  ../51c0c5bb.2330.19382c2fb6f.Coremail.yyuansong@126.com/
Also on:    postgresql.org/message-id/51c0c5bb.2330.19382c2fb6f.Coremail.yyuansong@126.com

 ·  · 

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-bugs@postgresql.org
  Cc: yyuansong@126.com, pg@bowt.ie, pgsql-hackers@lists.postgresql.org
  Subject: Re:Re: Re:Re:Re: backup server core when redo btree_xlog_insert that type is XLOG_BTREE_INSERT_POST
  In-Reply-To: <51c0c5bb.2330.19382c2fb6f.Coremail.yyuansong@126.com>

* 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