Re: Fix WITHOUT OVERLAPS multirange with location replication

From: Zhijie Hou <houzhijie22(at)gmail(dot)com>
To: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Cc: kedar anavardekar <kedar(dot)anavardekar(at)gmail(dot)com>, Paul A Jungwirth <pj(at)illuminatedcomputing(dot)com>, Nisha Moond <nisha(dot)moond412(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, Peter Eisentraut <peter(at)eisentraut(dot)org>
Subject: Re: Fix WITHOUT OVERLAPS multirange with location replication
Date: 2026-10-11 15:28:02
Message-ID: CAFvd2n-id-=deWuukX8VH4Z8OOyt04REfhNKf8u3gGN54c+Kew@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Sun, Oct 11, 2026 at 1:51 PM Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> wrote:
>
> On Sat, Oct 10, 2026 at 9:31 PM kedar anavardekar
> <kedar(dot)anavardekar(at)gmail(dot)com> wrote:
> >
> > > v2 attached, rebased on current master.
> >
> > Would it make sense to build the recheck bitmap from the scanned
> > index's own key columns (idxrel->rd_index->indkey, up to indnkeyatts)?
> > That would remove the dependency on the relation's current identity.
> > Or do you think the current approach is safe for a reason I'm missing?
> >
>
> IIUC, the current approach is safe because concurrent operations won't
> change index columns. Having said that, I think your suggested
> approach sounds more robust. Additionally, I think we can build the
> bitmap inside (if (eq == NULL)) check to avoid building it again and
> again for each tuple scan.

I think that instead of building a bitmap and passing it to tuples_equal(), we
can write a new helper function that directly traverses the index columns in
the slot and compares each of them, similar to what identity_key_equal() does
in pg_repack. I think that's a more standard approach, because we can use the
index's opclass equality function and collation for the comparison rather than
reusing the table attributes'. It is also more efficient, since it avoids
building a new bitmap and avoids the typecache lookup. It may not show a
performance difference, but I feel it's worth doing better in a common code
path (update/delete replay) like this one.

And based on the above, testing further, I realized this can fix a real issue:
when the index's operator class and collation differ from the table's default
ones, the patch's code (and the code on HEAD) uses the table's pg_attribute
collation to compare the tuple, which is inconsistent with the index's. For the
WITHOUT OVERLAPS index, we need to create a new extension with a new operator
class to reproduce the issue (I did not find a way to use WITHOUT OVERLAPS
together with a index specific collation, otherwise setting a different index
collation can also reproduce it); see 0003 (generated with AI assistance),
which reproduces it that way (it fails with v2 and passes with v3). I don't
think we should commit this heavy test patch, so I'm just sharing it for
reference.

The same issue exists on HEAD as well for the update_deleted detection code
path. I tried writing a patch to replace the update_deleted code path first in
0001 (since it's an existing issue, I've kept it in a separate patch for now to
make it easier to review; we can merge the two patches and commit them together
later if we agree). 0001 includes a test for the collation inconsistency issue.

And I rebased the WITHOUT OVERLAPS fix on top of it, modifying it to use the
new approach for tuple comparison and slightly adjusting some commit messages
and comments.

I'm sharing both patches here since both touch the same code path
and overlap. Hope it helps move the thread forward.

Best Regards,
Zhijie Hou

Attachment Content-Type Size
v3-0002-Fix-wrong-replication-for-multirange-WITHOUT-OVER.patch application/octet-stream 11.8 KB
v3-0001-Fix-equality-semantics-in-RelationFindDeletedTupl.patch application/octet-stream 13.1 KB
v3-0003-Add-test-for-replica-identity-recheck-with-non-de.patch application/octet-stream 14.0 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Muzzammil Sarwar 2026-10-11 15:31:00 [PATCH] Fix leak when a plpgsql exception block catches an error from CALL
Previous Message Richard Guo 2026-10-11 14:27:26 Assert failure in standard_join_search()