Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u0erc-005Kl5-NF for pgsql-bugs@arkaria.postgresql.org; Fri, 04 Apr 2025 11:05:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1u0erb-00Gf3t-8p for pgsql-bugs@arkaria.postgresql.org; Fri, 04 Apr 2025 11:05:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u0er5-00GcIj-Q7 for pgsql-bugs@lists.postgresql.org; Fri, 04 Apr 2025 11:04:59 +0000 Received: from meesny.iki.fi ([195.140.195.201]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u0er3-003L1c-0G for pgsql-bugs@lists.postgresql.org; Fri, 04 Apr 2025 11:04:59 +0000 Received: from [192.168.1.112] (iptv-hkibng21-58c090-167.dhcp.inet.fi [88.192.144.167]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by meesny.iki.fi (Postfix) with ESMTPSA id 4ZTbNR2WfrzyRf; Fri, 4 Apr 2025 14:04:55 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1743764695; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+vmg4RfmTtPqsDHAYM/LYJgVHuBAd/5JvTDYlLeXqhw=; b=XbP3MDv3F4PBt/QwGR+ebZ4b9L03zdVmCw+4eHR3ycmyZLNGxE/s1Ho8MaVAmTAD5Zib+5 18BF+XIaIdNXKfmP1oQCG9WNgHzdV4Su86PmhrN09Y5GmYX5N6Q2W9C+rHBhg0Qb3Pmu1r ARiwSuiT8aZ8eqa/p1fO8v72xIcs2hw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1743764695; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+vmg4RfmTtPqsDHAYM/LYJgVHuBAd/5JvTDYlLeXqhw=; b=fDokzbV6BQMI7bCH2YU925+vk/DiyzT7cfBqRapCCMP6nYeIKAixJ+xFJpA5V5x2YphdPx tg790HS0yi50e7sbQWUCCI4IYJy8Vr+OE12LPNfvS7GA/+we6ZwbyFCgH7zpkSpAh/h8jI QtuwTUZGb09Mojd0Ym8Ot0ISLOgyjIc= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1743764695; a=rsa-sha256; cv=none; b=PLIcaoKRGS2TGr3SXKr0UhP9iVvqsnXe9NZ2mjY/LL0wRI4YZ0BH87mJlMAVzJ98S4WtkO arzLFde25EO83xTGNch/TsjxjWOTAkcTRBC9UwL2QcefSNWUZDwAXICZr66nWYEmWOwLGB 4jtt0uJ+GO/ssVmFfis9oFcKcmQdQcs= Message-ID: Date: Fri, 4 Apr 2025 14:04:54 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #18396: Assert in gistFindCorrectParent() fails on inserting large tuples into gist index To: Tender Wang Cc: exclusion@gmail.com, pgsql-bugs@lists.postgresql.org References: <18396-03cac9beb2f7aac3@postgresql.org> <4af76123-c80a-4bd4-8674-47129093f227@iki.fi> Content-Language: en-US From: Heikki Linnakangas In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 15/11/2024 11:10, Tender Wang wrote: > Heikki Linnakangas > 于2024年3 > 月19日周二 22:26写道: > > On 19/03/2024 14:07, Tender Wang wrote: > > Thanks for your report. I can reproduce this issue. > > I try to delete the Assert, no coredump anymore. > > I need some time to learn GiST to find the root cause. > At first glance, I think the assertion is too strict. In > gistFindCorrectParent(), if we walk right, we update the parent's block > number and reset its memorized downlinkoffnum to > InvalidOffsetNumber. If > we later call gistFindCorrectParent() again with the same stack, > because > the parent also needs to be split, we hit that assertion. But it's > OK in > that case, we don't know the downlink because we had moved right. > Attached patch relaxes that. > > > I picked up this issue again, and I took some time to dig into it. > The patch works for me. > Can we update the comments above the Assert together?  If we go to the > Assert() code, > The comments say that the page has changed or we are in index build process. > But in the issue, the page didn't change(because we created temp table, > no concurrent), but we were not in > index build process, too. So the comments cannot reflect this case. > > > But now I'm having some second thoughts. gistFindCorrectParent() looks > like this: > > >       /* > >        * Scan the page to re-find the downlink. If the page was > split, it might > >        * have moved to a different page, so follow the right > links until we find > >        * it. > >        */ > >       while (true) > >       { > >               OffsetNumber i; > > > >               maxoff = PageGetMaxOffsetNumber(parent->page); > >               for (i = FirstOffsetNumber; i <= maxoff; i = > OffsetNumberNext(i)) > >               { > >                       iid = PageGetItemId(parent->page, i); > >                       idxtuple = (IndexTuple) PageGetItem(parent- > >page, iid); > >                       if (ItemPointerGetBlockNumber(&(idxtuple- > >t_tid)) == child->blkno) > >                       { > >                               /* yes!!, found */ > >                               child->downlinkoffnum = i; > >                               return; > >                       } > >               } > > > >               parent->blkno = GistPageGetOpaque(parent->page)- > >rightlink; > >               parent->downlinkoffnum = InvalidOffsetNumber; > >               UnlockReleaseBuffer(parent->buffer); > >               if (parent->blkno == InvalidBlockNumber) > >               { > >                       /* > >                        * End of chain and still didn't find > parent. It's a very-very > >                        * rare situation when the root was split. > >                        */ > >                       break; > >               } > >               parent->buffer = ReadBuffer(r, parent->blkno); > >               LockBuffer(parent->buffer, GIST_EXCLUSIVE); > >               gistcheckpage(r, parent->buffer); > >               parent->page = (Page) BufferGetPage(parent->buffer); > >       } > > When we step right and update parent->blkno, shouldn't we also update > parent->lsn? Otherwise, we might fail to detect a concurrent page split > with the LSN-NSN interlock checks. Or maybe it's correct, and we should > indeed not update the memorized LSN. Or maybe it doesn't matter because > we retry from the parent anyway, thanks to the 'retry_from_parent' > flag? > I'm not sure.. > > I agree that it doesn't matter. If internal page split due to adjust key > consistent with the key we're inserting. > The 'retry_from_parent' flag can help us get corrent downlinkoffnum. Ok, thanks for checking! Committed. -- Heikki Linnakangas Neon (https://neon.tech)