From: | Robert Haas <robertmhaas(at)gmail(dot)com> |
---|---|
To: | Aidar Imamov <a(dot)imamov(at)postgrespro(dot)ru> |
Cc: | Nazir Bilal Yavuz <byavuz81(at)gmail(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, koshy44(at)gmail(dot)com |
Subject: | Re: Add pg_buffercache_evict_all() and pg_buffercache_mark_dirty[_all]() functions |
Date: | 2025-04-10 20:05:48 |
Message-ID: | CA+Tgmoa-epr=JDyD4rJYc+CCtP6bZPamJuXxtOe2PBt0EXQ9VA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Tue, Mar 18, 2025 at 6:03 PM Aidar Imamov <a(dot)imamov(at)postgrespro(dot)ru> wrote:
> > for (int buf = 1; buf < NBuffers; buf++)
> Mb it would be more correct to use <= NBuffers?
I agree that (int buf = 1; buf < NBuffers; buf++) isn't right because
that iterates one fewer times than the number of buffers. What was
ultimately committed was:
+ for (int buf = 1; buf <= NBuffers; buf++)
+ {
+ BufferDesc *desc = GetBufferDescriptor(buf - 1);
Curiously, there is no other instance of <= NBuffers in the code.
Elsewhere we instead do:
for (i = 0; i < NBuffers; i++)
{
BufferDesc *bufHdr = GetBufferDescriptor(i);
Or in BufferSync:
for (buf_id = 0; buf_id < NBuffers; buf_id++)
{
BufferDesc *bufHdr = GetBufferDescriptor(buf_id);
Nonetheless what was committed seems pretty defensible, because we
have lots of other places that do GetBufferDescriptor(buffer - 1) and
similar. Alternating between 0-based indexing and 1-based indexing
like this seems rather error-prone somehow. :-(
--
Robert Haas
EDB: http://www.enterprisedb.com
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Haas | 2025-04-10 20:07:25 | Re: Reduce "Var IS [NOT] NULL" quals during constant folding |
Previous Message | Andres Freund | 2025-04-10 20:05:42 | Re: pgsql: Add function to get memory context stats for processes |