Re: BUG #17558: 15beta2: Endless loop with UNIQUE NULLS NOT DISTINCT and INSERT ... ON CONFLICT
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Michael Paquier <michael@paquier.xyz>
Cc: Richard Guo <guofenglinux@gmail.com>, postgresql@middaysomewhere.com,
Peter Eisentraut <peter.eisentraut@enterprisedb.com>,
PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Date: 2022-08-04T17:17:48Z
Lists: pgsql-bugs
Attachments
- fix-infinite-loop-in-ON-CONFLICT.patch (text/x-diff) patch
Michael Paquier <michael@paquier.xyz> writes: > On Tue, Jul 26, 2022 at 11:17:45AM +0800, Richard Guo wrote: >> Yeah, I can see the same problem. _bt_check_unique() can catch violation >> of unique index constraint successfully, so insert without 'ON CONFLICT' >> has no problem. But ExecCheckIndexConstraints() fails to tell the NULL >> tuple violates unique constraint, and the logic below is quite >> suspicious to me. > This is still an open item assigned to Peter, and beta3 is planned for > the 11th of August. Would a resolution by the beginning of next week > be doable? Since nothing seems to be happening here, I looked into it. I think Richard has correctly fingered the buggy code: we need to teach check_exclusion_or_unique_constraint() that a NULL isn't necessarily an instant pass. As attached. Since the presented test case caused an uninterruptible loop, I also added a CHECK_FOR_INTERRUPTS() that could stop it. (I was initially pretty surprised that we could get through an index scan without hitting any CFI, but on reflection it's less surprising, because no index scan actually happens: check_exclusion_or_unique_constraint() short-circuits things before very much code has been reached.) I'm kind of inclined to back-patch the nodeModifyTable.c change all the way, just for safety. regards, tom lane
Commits
-
Fix check_exclusion_or_unique_constraint for UNIQUE NULLS NOT DISTINCT.
- d59383924c58 16.0 landed
- 3419d51e1957 15.0 landed
-
Add CHECK_FOR_INTERRUPTS in ExecInsert's speculative insertion loop.
- efba7a63ffbe 14.5 landed
- 963a6b6fa45d 12.12 landed
- 6ad86feecb24 16.0 landed
- 4c7b16312ea3 15.0 landed
- 2e2f3435af8b 11.17 landed
- 23edf0e8b4d1 13.8 landed
- 138213684ad4 10.22 landed