Re: Fix incorrect assertion in heapgettup_pagemode()

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: cca5507 <cca5507(at)qq(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fix incorrect assertion in heapgettup_pagemode()
Date: 2025-12-25 13:34:06
Message-ID: E36843D3-666D-4FC6-A2CE-41DB44FE612C@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Dec 25, 2025, at 19:13, cca5507 <cca5507(at)qq(dot)com> wrote:
>
> Hi,
>
> diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
> index 469397e7344..1229e22e78a 100644
> --- a/src/backend/access/heap/heapam.c
> +++ b/src/backend/access/heap/heapam.c
> @@ -1077,7 +1077,7 @@ continue_page:
> ItemId lpp;
> OffsetNumber lineoff;
>
> - Assert(lineindex <= scan->rs_ntuples);
> + Assert(lineindex < scan->rs_ntuples);
> lineoff = scan->rs_vistuples[lineindex];
> lpp = PageGetItemId(page, lineoff);
> Assert(ItemIdIsNormal(lpp));
>
> The lineindex is 0-based, so it should be '<' rather than '<=', thoughts?
>
> --
> Regards,
> ChangAo Chen
> <v1-0001-Fix-incorrect-assertion-in-heapgettup_pagemode.patch>

Good catch. The function comment clearly mentions that lineindex is 0 based.
```
* tuples listed in rs_vistuples[] rather than all tuples on the page. Notice
* that lineindex is 0-based, where the corresponding loop variable lineoff in
* heapgettup is 1-based.
* ----------------
*/
static void
heapgettup_pagemode(HeapScanDesc scan,
ScanDirection dir,
int nkeys,
ScanKey key)
{
HeapTuple tuple = &(scan->rs_ctup);
Page page;
uint32 lineindex;
uint32 linesleft;
```

So, the fix looks correct.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Андрей Казачков 2025-12-25 14:27:19 Re: [PATCH] Optionally record Plan IDs to track plan changes for a query
Previous Message Aya Iwata (Fujitsu) 2025-12-25 13:24:33 RE: [PROPOSAL] Termination of Background Workers for ALTER/DROP DATABASE