[PATCH] pg_prewarm: validate that first_block <= last_block

Started by Postgress Cybrosys20 days ago1 messageshackers
Jump to latest
#1Postgress Cybrosys
postgress@cybrosys.com

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@cybrosys.com

+91 8606827707

+91 8606827707

Attachments:

0001-pg_prewarm-validate-that-first_block-last_block.patchtext/x-patch; charset=US-ASCII; name=0001-pg_prewarm-validate-that-first_block-last_block.patchDownload+6-1