[PATCH] pg_prewarm: validate that first_block <= last_block

From: Postgress Cybrosys <postgress(at)cybrosys(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: [PATCH] pg_prewarm: validate that first_block <= last_block
Date: 2026-03-27 05:32:10
Message-ID: CAG+=MFWVYMvqDUVrZYBQ1TGLsUbEP5PxU0rK=0o_D5PY1ica1Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi psql hackers,

While reviewing contrib/pg_prewarm/pg_prewarm.c, I noticed that
pg_prewarm() does not validate that first_block <= last_block after
both values are resolved. When a caller passes a reversed range such
as pg_prewarm('mytable', 'buffer', 'main', 100, 50), the function
silently returns 0 without any indication that the range was empty.
Both block numbers pass their individual bounds checks, so the caller
gets no feedback that anything went wrong.

The fix adds an explicit check after both endpoints are fully resolved
(including NULL defaults) and emits an ERROR message.

Reproduction:

CREATE TABLE t (id int);
INSERT INTO t SELECT generate_series(1, 10000);

-- Before patch: silently returns 0
SELECT pg_prewarm('t', 'buffer', 'main', 100, 50);
pg_prewarm
------------
0
(1 row)

-- After patch: raises a clear error

SELECT pg_prewarm('t', 'buffer', 'main', 100, 50);
ERROR: ending block number cannot be less than starting block number

The patch is attached. It touches only contrib/pg_prewarm/pg_prewarm.c

--

Thanks & Regards,

*Jhon k*

Postgres Specialist

Project & IT Department

Cybrosys Technologies

Mail

Mobile

WhatsApp

postgress(at)cybrosys(dot)com

+91 8606827707

+91 8606827707

Attachment Content-Type Size
0001-pg_prewarm-validate-that-first_block-last_block.patch text/x-patch 1.5 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Yugo Nagata 2026-03-27 05:35:11 Re: Allow to collect statistics on virtual generated columns
Previous Message Michael Paquier 2026-03-27 05:17:57 Re: Refactor query normalization into core query jumbling