Re: Fix "could not find memoization table entry"

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Tender Wang <tndrwang(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fix "could not find memoization table entry"
Date: 2026-03-24 02:39:40
Message-ID: CAApHDvpQ4HhHDqjXZBRMan_BTrk_qerq9YiUkZTg6ZqswkHBcA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, 24 Mar 2026 at 14:10, Tender Wang <tndrwang(at)gmail(dot)com> wrote:
> Actually, I haven't quite figured out why `typLen` cannot be used here.

This is because we sign-extend rather than zero-extend up to Datum.
Consider this code from master:

typedef uint64_t Datum;

static inline Datum
Int32GetDatum(int32 X)
{
return (Datum) X;
}

So we cast to uint64_t when converting int32 to Datum.

And consider the output of this C program:

drowley(at)amd3990x:~$ cat datum.c
#include <stdio.h>
#include <stdint.h>

int main(void)
{
int32_t i32 = -1;
uint64_t i64 = (uint64_t) i32;

for (int i = 0; i < 64; i++)
{
putchar(i64 & 0x8000000000000000ULL ? '1' : '0');
i64 <<= 1;
}
putchar('\n');
return 0;
}

drowley(at)amd3990x:~$ gcc datum.c -o datum && ./datum
1111111111111111111111111111111111111111111111111111111111111111

If you only look at the lower 32 bits of that Datum, then you're not
looking at the entire value.

I don't have hardware to try it, but I also don't suppose comparing
the first attlen bytes of a Datum does the same thing on big-endian
machines as that would look at the most significant side of the Datum
rather than the least significant side as it would on little-endian.

David

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message shihao zhong 2026-03-24 02:49:41 Re: [Patch] New pg_stat_tablespace view
Previous Message Mahendra Singh Thalor 2026-03-24 02:34:01 Re: [BUG] CRASH: ECPGprepared_statement() and ECPGdeallocate_all() when connection is NULL