RE: BUG #19892: Logical replication skips UPDATE/DELETE of rows with NULL in a hash-indexed subscriber column

From: "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>
To: 'Nisha Moond' <nisha(dot)moond412(at)gmail(dot)com>, "kehan5800(at)gmail(dot)com" <kehan5800(at)gmail(dot)com>
Cc: "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: RE: BUG #19892: Logical replication skips UPDATE/DELETE of rows with NULL in a hash-indexed subscriber column
Date: 2026-11-16 08:01:04
Message-ID: OS7PR01MB1831731C0A17AAED9DA406AAEF57C2@OS7PR01MB18317.jpnprd01.prod.outlook.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi Ke and Nisha,

Good catch and thanks for working on it.
I was an author of edca3424342, which allowed to use hash index while finding
tuples for REPLICA IDENTITY FULL case. Sadly, I have not known the handling of
NULL by hash index, my fault.

I reviewed the proposed patch and basically LGTM. As for the test code, I confirmed
they could fail before fixing the source and can pass after that.
Few comments:

01.
```
+/*
+ * Return true if 'searchslot' has a NULL in a key column of 'idxrel' and the
+ * index can't search for NULLs (e.g. hash). Such a scan finds nothing.
+ */
+static bool
+replindex_key_unsearchable(Relation idxrel, TupleTableSlot *searchslot)
```

02.
```
+ /*
+ * The index can't find this row, so use a sequential scan.
+ * !skipduplicates means the index was chosen for REPLICA IDENTITY FULL,
+ * so 'searchslot' has the whole row.
+ */
+ if (!skipduplicates && replindex_key_unsearchable(idxrel, searchslot))
+ {
+ index_close(idxrel, NoLock);
+ return RelationFindReplTupleSeq(rel, lockmode, searchslot, outslot);
+ }
```

This comment looks bit strange because it does not describe why the index cannot
find the row. How about:

```
/*
* Fall back to a sequential scan if the index cannot search for a NULL
* key. !skipduplicates means the index was chosen for REPLICA IDENTITY
* FULL, so 'searchslot' has the whole row.
*/

```

03.
```
+ /* The index can't find this row, so use a sequential scan. */
+ if (!skipduplicates && replindex_key_unsearchable(idxrel, searchslot))
+ {
```

This can also adjust like:

```
/*
* Fall back to a sequential scan if the index cannot search for a NULL
* key. See RelationFindReplTupleByIndex().
*/
```

Best regards,
Hayato Kuroda
FUJITSU LIMITED

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Magnus Hagander 2026-11-16 10:26:14 Re: Timing issue in pg_basebackup
Previous Message Rui Zhao 2026-11-16 07:47:27 Re: Two bugs around ALTER TYPE