public inbox for [email protected]  
help / color / mirror / Atom feed
From: Tom Lane <[email protected]>
To: Gurjeet Singh <[email protected]>
Cc: Bharath Rupireddy <[email protected]>
Cc: PostgreSQL Hackers <[email protected]>
Subject: Re: Remove extraneous break condition in logical slot advance function
Date: Sat, 21 Oct 2023 14:10:09 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <CABwTF4X0c97t0PP+A7iTY5JfM76TYa0FUqrGZo1F5ZJomv-48g@mail.gmail.com>
References: <CALj2ACWfGDLQ2cy7ZKwxnJqbDkO6Yvqqrqxne5ZN4HYm=PRTGg@mail.gmail.com>
	<CABwTF4X0c97t0PP+A7iTY5JfM76TYa0FUqrGZo1F5ZJomv-48g@mail.gmail.com>

Gurjeet Singh <[email protected]> writes:
> On Fri, Oct 20, 2023 at 7:30 PM Bharath Rupireddy
> <[email protected]> wrote:
>> There exists an extraneous break condition in
>> pg_logical_replication_slot_advance(). When the end of WAL or moveto
>> LSN is reached, the main while condition helps to exit the loop, so no
>> separate break condition is needed. Attached patch removes it.

> The only advantage I see of the code as it stands right now is that it
> avoids one last call to CHECK_FOR_INTERRUPTS() by break'ing early. I
> don't think we'd lose much in terms of performance by making one (very
> cheap, in common case) extra call of this macro.

Agreed, bypassing the last CHECK_FOR_INTERRUPTS() shouldn't save
anything noticeable.  Could there be a correctness argument for it
though?  Can't see what.  We should assume that CFIs might happen
down inside LogicalDecodingProcessRecord.

I wondered why the code looks like this, and whether there used
to be more of a reason for it.  "git blame" reveals the probable
answer: when this code was added, in 9c7d06d60, the loop
condition was different so the break was necessary.
38a957316 simplified the loop condition to what we see today,
but didn't notice that the break was thereby made pointless.

While we're here ... the comment above the loop seems wrong
already, and this makes it more so.  I suggest something like

-		/* Decode at least one record, until we run out of records */
+		/* Decode records until we reach the requested target */
		while (ctx->reader->EndRecPtr < moveto)

			regards, tom lane






view thread (3+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected]
  Subject: Re: Remove extraneous break condition in logical slot advance function
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox