logical decoding: removing change_useless_for_repack()

Started by Alvaro Herrera1 day ago3 messageshackers
Jump to latest
#1Alvaro Herrera
alvherre@kurilemu.de

Hello

Antonin just posted a patch to get rid of the function in $SUBJECT, in a
thread that's not obviously related to that. I'm posting it again in a
new thread for visibility, with some cosmetic changes by me.

I think this is pretty straightforward, so I intend to push it early
next week.

[0]: /messages/by-id/57140.1795542599@chrudos

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/

Attachments:

t259943_1
v2-0001-Introduce-an-output-plugin-callback-to-filter-cha.patchtext/x-diff; charset=utf-8Download+186-70
#2Zhijie Hou
houzhijie22@gmail.com
In reply to: Alvaro Herrera (#1)
Re: logical decoding: removing change_useless_for_repack()

Hi,

On Sat, Nov28, 2026 at 04:10 AM Álvaro Herrera wrote:

Hello

Antonin just posted a patch to get rid of the function in $SUBJECT, in
a thread that's not obviously related to that. I'm posting it again in
a new thread for visibility, with some cosmetic changes by me.

I think this is pretty straightforward, so I intend to push it early
next week.

+1 for moving the filter to the output plugin.

I have a few comments:

1.
+ * If the given RelFileLocator matches one of the locators being 
processed by
+ * REPACK, return true to have this record be skipped by decoding. 
Otherwise
+ * return false.

The comment has the return value inverted; that is, when the locator
matches one of the locators being processed by REPACK, the function
returns false (so it is decoded), and returns true otherwise.

2.

cluster_rel() in repack.c still has a comment referencing
change_useless_for_repack().

3.

The patch does not call the callback in DecodeTruncate(). Since
thedocumentation describes this as a generic callback, it would be
better to allowfiltering TRUNCATE as well.

4.

+typedef bool (*LogicalDecodeFilterByRelFileLocator)

Since all other callback ends with "CB", I think it would be better
rename this to LogicalDecodeFilterByRelFileLocatorCB to be consistent.

--
Best Regards,
Zhijie Hou

#3Alvaro Herrera
alvherre@kurilemu.de
In reply to: Zhijie Hou (#2)
Re: logical decoding: removing change_useless_for_repack()

On 2026-Nov-28, Zhijie Hou wrote:

1.
+ * If the given RelFileLocator matches one of the locators being processed
by
+ * REPACK, return true to have this record be skipped by decoding.
Otherwise
+ * return false.

The comment has the return value inverted; that is, when the locator matches
one of the locators being processed by REPACK, the function returns false
(so it is decoded), and returns true otherwise.

Oh, yeah, this is my bug: I wanted to invert the sense of the booleans,
because as it is, it makes little sense to me. But then I noticed
Antonin was just doing the same as the FilterByOrigin callback does. So
it's not Antonin's or this patch's fault, but that of the old code, and
so for consistency we should keep it that way. But after that
realization I forgot to revert my update of the comment. Thanks for
noticing.

Also fixed #2 and #4 in this new version, thanks. The nocfbot patch is
the (trivial) diff from v2.

3.

The patch does not call the callback in DecodeTruncate(). Since
thedocumentation describes this as a generic callback, it would be better to
allowfiltering TRUNCATE as well.

Interesting thought. What happens with repack is that we don't filter,
thus the record is decoded and processed by decode.c. But pgrepack
doesn't have a truncate callback, so when it reaches logical.c, that
code simply skips the record doing nothing. That's perfectly fine,
because if you're repacking a table, nobody can truncate it, so this
cannot actually happen.

You suggest that we should look at the list of relations being
truncated, then skip decoding if none of these relations match the
RelFileLocator. I suspect you're right that for the general use case we
should do this. I didn't do this in this version, but we should do that
before commit. (Being of course careful not to waste time trying to
skip a record only to later find out that there's no truncate_cb
callback in the first place.)

--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/

Attachments:

t259943_3
nocfbot-0001-fixups.patchtext/x-diff; charset=utf-8Download+9-10
v3-0001-Introduce-an-output-plugin-callback-to-filter-cha.patchtext/x-diff; charset=utf-8Download+187-71