pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chao Li <li.evan.chao@gmail.com>
To: Peter Eisentraut <peter@eisentraut.org>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: Fix signed/unsigned integer handling in pg_restore_relation_stats()
Date: Thu, 20 Aug 2026 10:08:24 +0800
Message-ID: <17513C42-CBBA-463A-9E33-456E2198EC32@gmail.com> (raw)
In-Reply-To: <db993f34-e3e1-4e6e-85c3-4f248d2ff29b@eisentraut.org>
References: <db993f34-e3e1-4e6e-85c3-4f248d2ff29b@eisentraut.org>



> On Aug 18, 2026, at 16:36, Peter Eisentraut <peter@eisentraut.org> wrote:
> 
> The pg_class fields relpages, relallvisible, and relallfrozen are of
> type int32, but the statistics restoration code internally dealt with them as uint32 for a little bit, after which they would turn back into int32.  This all happens to work, but it doesn't make sense, so I propose the attached fix.
> 
> While researching this, I noticed that we don't appear to document how page/block counts larger than INT32_MAX are represented in the catalogs.  A C programmer would have a certain expectation, but we shouldn't expect everyone to guess that.  So I'm proposing a small addition to the catalog documentation to clarify this.
> <0001-Fix-signed-unsigned-integer-handling-in-pg_restore_r.patch><0002-doc-Document-overflow-handling-of-pg_class.relpages-.patch>

Overall looks good to me. Only one small comment on 0001:
```
inline patch 1: src/backend/statistics/relation_stats.c (+1/-1 lines) download inline-1.patch--- a/src/backend/statistics/relation_stats.c +++ b/src/backend/statistics/relation_stats.c @@ -99,13 +99,13 @@ relation_statistics_update(FunctionCallInfo fcinfo) static bool relation_statistics_update_internal(Oid reloid, FunctionCallInfo fcinfo) { - BlockNumber relpages = 0; + int32 relpages = 0;
``` relpages is changed to int32, so the later code of PG_GETARG_UINT32(RELPAGES_ARG) to PG_GETARG_INT32. ``` if (!PG_ARGISNULL(RELPAGES_ARG)) { relpages = PG_GETARG_UINT32(RELPAGES_ARG); ``` Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/

view thread (3+ messages)  latest in thread

Message-ID: <17513C42-CBBA-463A-9E33-456E2198EC32@gmail.com>
Permalink:  ../17513C42-CBBA-463A-9E33-456E2198EC32@gmail.com/
Also on:    postgresql.org/message-id/17513C42-CBBA-463A-9E33-456E2198EC32@gmail.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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: li.evan.chao@gmail.com, peter@eisentraut.org
  Subject: Re: Fix signed/unsigned integer handling in pg_restore_relation_stats()
  In-Reply-To: <17513C42-CBBA-463A-9E33-456E2198EC32@gmail.com>
  References: <db993f34-e3e1-4e6e-85c3-4f248d2ff29b@eisentraut.org> <17513C42-CBBA-463A-9E33-456E2198EC32@gmail.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