[PATCH] pg_prewarm: validate that first_block <= last_block - Mailing list pgsql-hackers

From Postgress Cybrosys
Subject [PATCH] pg_prewarm: validate that first_block <= last_block
Date
Msg-id CAG+=MFWVYMvqDUVrZYBQ1TGLsUbEP5PxU0rK=0o_D5PY1ica1Q@mail.gmail.com
Whole thread
List 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@cybrosys.com

+91 8606827707

+91 8606827707


Attachment

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Refactor query normalization into core query jumbling
Next
From: Yugo Nagata
Date:
Subject: Re: Allow to collect statistics on virtual generated columns