pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
[PATCH] Fix argument in pg_indexam_progress_phasename()
3+ messages / 3 participants
[nested] [flat]

Commits from this thread:
  2026-10-22 66042bd3eb 2dc899f780 58998c33d1 8af1a12c9e 6f126b3289 e4ac005142 5259332a69  Fix argument handling in pg_indexam_progress_phasename()
* [PATCH] Fix argument in pg_indexam_progress_phasename()
@ 2026-10-21 14:15 Markos Fountoulakis <markos@planetscale.com>
  2026-10-22 00:31 ` Re: [PATCH] Fix argument in pg_indexam_progress_phasename() Chao Li <li.evan.chao@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Markos Fountoulakis @ 2026-10-21 14:15 UTC (permalink / raw)
  To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

Hello,

There is a oversight in pg_indexam_progress_phasename() since ab0dfc961b6 where the second argument is declared int8 in pg_proc.dat but gotten via PG_GETARG_INT32() in the C code.

This isn't much of a problem since 2a600a93c7b where Datums became 8 byte wide everywhere. However, this is an actual problem in 32-bit architecture in older PostgreSQL versions where int8 is passed by reference and returns bogus numbers. The side effect is that pg_stat_progress_create_index never shows the access method phasename. This should probably be backpatched.

-- 
Markos Fountoulakis
PlanetScale Postgres Core Team

Attachments:

v1-0001-Fix-argument-in-pg_indexam_progress_phasename.patch (text/plain, 956B) download From b231dd3982c4d59d37ad502db90a7ddb590fe828 Mon Sep 17 00:00:00 2001 From: Markos Fountoulakis <markos@planetscale.com> Date: Wed, 21 Oct 2026 16:37:04 +0300 Subject: [PATCH v1] Fix argument in pg_indexam_progress_phasename() The function is declared in pg_proc.dat as taking (oid, int8), but the C code fetched the second argument with PG_GETARG_INT32(). Use PG_GETARG_INT64() to match the declared signature. --- src/backend/utils/adt/amutils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/utils/adt/amutils.c b/src/backend/utils/adt/amutils.c index 9e758ebaa6f..b9cfb7e6687 100644 --- a/src/backend/utils/adt/amutils.c +++ b/src/backend/utils/adt/amutils.c @@ -449,7 +449,7 @@ Datum pg_indexam_progress_phasename(PG_FUNCTION_ARGS) { Oid amoid = PG_GETARG_OID(0); - int32 phasenum = PG_GETARG_INT32(1); + int64 phasenum = PG_GETARG_INT64(1); const IndexAmRoutine *routine; char *name; -- 2.53.0
^ permalink raw reply [nested|flat] 3+ messages in thread

* Re: [PATCH] Fix argument in pg_indexam_progress_phasename()
  2026-10-21 14:15 [PATCH] Fix argument in pg_indexam_progress_phasename() Markos Fountoulakis <markos@planetscale.com>
@ 2026-10-22 00:31 ` Chao Li <li.evan.chao@gmail.com>
  2026-10-22 04:10   ` Re: [PATCH] Fix argument in pg_indexam_progress_phasename() Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 3+ messages in thread

From: Chao Li @ 2026-10-22 00:31 UTC (permalink / raw)
  To: Markos Fountoulakis <markos@planetscale.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>



> On Oct 21, 2026, at 22:15, Markos Fountoulakis <markos@planetscale.com> wrote:
> 
> Hello,
> 
> There is a oversight in pg_indexam_progress_phasename() since ab0dfc961b6 where the second argument is declared int8 in pg_proc.dat but gotten via PG_GETARG_INT32() in the C code.

Good catch. pg_proc.dat defines the second argument as int8, and the AM callback also takes int64:
```
/* name of phase as used in progress reporting */
typedef char *(*ambuildphasename_function) (int64 phasenum);
```

pg_indexam_progress_phasename(), which sits between these two layers, should also use int64. So the patch looks correct to me.

> 
> This isn't much of a problem since 2a600a93c7b where Datums became 8 byte wide everywhere. However, this is an actual problem in 32-bit architecture in older PostgreSQL versions where int8 is passed by reference and returns bogus numbers. The side effect is that pg_stat_progress_create_index never shows the access method phasename. This should probably be backpatched.
> 

On older 32-bit builds, int8 arguments are passed by reference, so with PG_GETARG_INT32, pg_indexam_progress_phasename() would interpret a pointer value as phasenum. This makes me wonder whether we should add a simple test for this function. If there were such a test, I would have expected the CI to catch this bug, since I believe it includes 32-bit builds.

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










^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [PATCH] Fix argument in pg_indexam_progress_phasename()
  2026-10-21 14:15 [PATCH] Fix argument in pg_indexam_progress_phasename() Markos Fountoulakis <markos@planetscale.com>
  2026-10-22 00:31 ` Re: [PATCH] Fix argument in pg_indexam_progress_phasename() Chao Li <li.evan.chao@gmail.com>
@ 2026-10-22 04:10   ` Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 3+ messages in thread

From: Michael Paquier @ 2026-10-22 04:10 UTC (permalink / raw)
  To: Chao Li <li.evan.chao@gmail.com>; +Cc: Markos Fountoulakis <markos@planetscale.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>

On Thu, Oct 22, 2026 at 08:31:19AM +0800, Chao Li wrote:
> pg_indexam_progress_phasename(), which sits between these two
> layers, should also use int64. So the patch looks correct to me.

Yep, nice catch.  This warrants a backpatch.  Will fix, thanks for the
report.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2026-10-22 04:10 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-10-21 14:15 [PATCH] Fix argument in pg_indexam_progress_phasename() Markos Fountoulakis <markos@planetscale.com>
2026-10-22 00:31 ` Chao Li <li.evan.chao@gmail.com>
2026-10-22 04:10   ` Michael Paquier <michael@paquier.xyz>

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