Re: [PING] [PATCH v2] parallel pg_restore: avoid disk seeks when jumping short distance forward

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dimitrios Apostolou <jimis(at)gmx(dot)net>
Cc: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, Nathan Bossart <nathandbossart(at)gmail(dot)com>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: [PING] [PATCH v2] parallel pg_restore: avoid disk seeks when jumping short distance forward
Date: 2025-10-20 21:29:22
Message-ID: 376918.1760995762@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Dimitrios Apostolou <jimis(at)gmx(dot)net> writes:
> + /* Dump buffer if full */
> + if (nonecs->bufdata >= nonecs->buflen)

> Shouldn't this be equality check instead:
> if (nonecs->bufdata == nonecs->buflen)

Old defensive-programming habit. The invariant we want to establish
is that there's some space available, ie
nonecs->bufdata < nonecs->buflen
and if we just test for equality then we haven't proven that.
Agreed that bufdata shouldn't ever be greater than buflen, but if
it somehow is, an equality test here would contribute to making
things worse (writing ever further past the buffer) not better.

> And possibly also assert(nonecs->bufdata <= nonecs->buflen) ?

Maybe, but that code is simple enough that I didn't see a big
need for an assertion check.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Mihail Nikalayeu 2025-10-20 21:30:43 Re: Fix race condition in SSI when reading PredXact->SxactGlobalXmin
Previous Message David E. Wheeler 2025-10-20 21:22:29 Re: abi-compliance-check failure due to recent changes to pg_{clear,restore}_{attribute,relation}_stats()