From: | David Zhang <david(dot)zhang(at)highgo(dot)ca> |
---|---|
To: | Bruce Momjian <bruce(at)momjian(dot)us>, Simon Riggs <simon(dot)riggs(at)enterprisedb(dot)com> |
Cc: | Cary Huang <cary(dot)huang(at)highgo(dot)ca>, Pgsql Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Patch: Global Unique Index |
Date: | 2022-11-26 01:03:06 |
Message-ID: | 46a0f6fb-1c0b-bbd8-ef3e-366216a89501@highgo.ca |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi Bruce,
Thank you for helping review the patches in such detail.
On 2022-11-25 9:48 a.m., Bruce Momjian wrote:
> Looking at the patch, I am unclear how the the patch prevents concurrent
> duplicate value insertion during the partitioned index checking. I am
> actually not sure how that can be done without locking all indexes or
> inserting placeholder entries in all indexes. (Yeah, that sounds bad,
> unless I am missing something.)
For the uniqueness check cross all partitions, we tried to follow the
implementation of uniqueness check on a single partition, and added a
loop to check uniqueness on other partitions after the index tuple has
been inserted to current index partition but before this index tuple has
been made visible. The uniqueness check will wait `XactLockTableWait` if
there is a valid transaction in process, and performs the uniqueness
check again after the in-process transaction finished.
We tried to simulate this duplicate value case in blow steps:
1) prepare the partitioned table,
CREATE TABLE gidx_part (a int, b int, c text) PARTITION BY RANGE (a);
CREATE TABLE gidx_part1 partition of gidx_part FOR VALUES FROM (0) TO (10);
CREATE TABLE gidx_part2 partition of gidx_part FOR VALUES FROM (10) TO (20);
2) having two psql consoles hooked up with gdbs and set break points
after _bt_doinsert
result = _bt_doinsert(rel, itup, checkUnique, indexUnchanged, heapRel);
inside btinsert function in nbtree.c file.
3) first, execute `INSERT INTO gidx_part values(1, 1, 'test');` on
console-1, and then execute `INSERT INTO gidx_part values(11, 1,
'test');` on console-2 (expect duplicated value '1' in the 2nd column to
be detected),
The test results is that: console-2 query will have to wait until either
console-1 committed or aborted. If console-1 committed, then console-2
reports duplicated value already exists; if console-1 aborted, then
console-2 will report insert successfully. If there is a deadlock, then
the one detected this deadlock will error out to allow the other one
continue.
I am not quite sure if this is a proper way to deal with a deadlock in
this case. It would be so grateful if someone could help provide some
cases/methods to verify this cross all partitions uniqueness.
Best regards,
David
============================
HighGo Software Canada
www.highgo.ca <http://www.highgo.ca>
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Paquier | 2022-11-26 01:21:18 | Re: Small miscellaneous fixes |
Previous Message | Andres Freund | 2022-11-26 00:43:58 | Re: MSVC vs Perl |