Fix comments for buf_id field of BufferDesc structure

From: Daniil Davydov <3danissimo(at)gmail(dot)com>
To: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Fix comments for buf_id field of BufferDesc structure
Date: 2026-01-20 06:35:27
Message-ID: CAJDiXgj6xnpyCfrraiJEVBNUoFVGCNuAEWJtih5wHsQw2xvGww@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I noticed that the BufferDesc structure contains the following field
and a comment :

/*
* Buffer's index number (from 0). The field never changes after
* initialization, so does not need locking.
*/
int buf_id;

Actually, the comment is wrong, because we are using negative ids for
local buffers (i.e. "buf_id" field contains values -1, -2, and so on). We
have a comment about it in localbuf.c :

/*
* negative to indicate local buffer. This is tricky: shared buffers
* start with 0. We have to start with -2. (Note that the routine
* BufferDescriptorGetBuffer adds 1 to buf_id so our first buffer id
* is -1.)
*/

Maybe we should place this note in buf_internals.h? Anyone who
wants to know what this field means will look at the comment in
buf_internals.h and be misled.

I have attached a patch with my suggestion. What do you think?

--
Best regards,
Daniil Davydov

Attachment Content-Type Size
0001-Fix-comment-in-BufferDesc-struct.patch text/x-patch 1.6 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message shveta malik 2026-01-20 06:38:29 Re: pg_upgrade: optimize replication slot caught-up check
Previous Message zengman 2026-01-20 06:33:16 Re:Some cleanup of pg_stat_statements tests