| 1 |
# Test for page level predicate locking in hash index |
| 2 |
# |
| 3 |
# Test to verify serialization failures and to check reduced false positives |
| 4 |
# |
| 5 |
# To verify serialization failures, queries and permutations are written in such |
| 6 |
# a way that an index scan (from one transaction) and an index insert (from |
| 7 |
# another transaction) will try to access the same bucket of the index |
| 8 |
# whereas to check reduced false positives, they will try to access different |
| 9 |
# buckets of the index. |
| 10 |
|
| 11 |
setup |
| 12 |
{ |
| 13 |
create table hash_tbl(id int4, p integer); |
| 14 |
create index hash_idx on hash_tbl using hash(p); |
| 15 |
insert into hash_tbl (id, p) |
| 16 |
select g, 10 from generate_series(1, 10) g; |
| 17 |
insert into hash_tbl (id, p) |
| 18 |
select g, 20 from generate_series(11, 20) g; |
| 19 |
insert into hash_tbl (id, p) |
| 20 |
select g, 30 from generate_series(21, 30) g; |
| 21 |
insert into hash_tbl (id, p) |
| 22 |
select g, 40 from generate_series(31, 40) g; |
| 23 |
} |
| 24 |
|
| 25 |
teardown |
| 26 |
{ |
| 27 |
drop table hash_tbl; |
| 28 |
} |
| 29 |
|
| 30 |
session s1 |
| 31 |
setup |
| 32 |
{ |
| 33 |
begin isolation level serializable; |
| 34 |
set enable_seqscan=off; |
| 35 |
set enable_bitmapscan=off; |
| 36 |
set enable_indexonlyscan=on; |
| 37 |
} |
| 38 |
step rxy1 { select sum(p) from hash_tbl where p=20; } |
| 39 |
step wx1 { insert into hash_tbl (id, p) |
| 40 |
select g, 30 from generate_series(41, 50) g; } |
| 41 |
step rxy3 { select sum(p) from hash_tbl where p=20; } |
| 42 |
step wx3 { insert into hash_tbl (id, p) |
| 43 |
select g, 50 from generate_series(41, 50) g; } |
| 44 |
step c1 { commit; } |
| 45 |
|
| 46 |
|
| 47 |
session s2 |
| 48 |
setup |
| 49 |
{ |
| 50 |
begin isolation level serializable; |
| 51 |
set enable_seqscan=off; |
| 52 |
set enable_bitmapscan=off; |
| 53 |
set enable_indexonlyscan=on; |
| 54 |
} |
| 55 |
step rxy2 { select sum(p) from hash_tbl where p=30; } |
| 56 |
step wy2 { insert into hash_tbl (id, p) |
| 57 |
select g, 20 from generate_series(51, 60) g; } |
| 58 |
step rxy4 { select sum(p) from hash_tbl where p=30; } |
| 59 |
step wy4 { insert into hash_tbl (id, p) |
| 60 |
select g, 60 from generate_series(51, 60) g; } |
| 61 |
step c2 { commit; } |
| 62 |
|
| 63 |
|
| 64 |
# An index scan (from one transaction) and an index insert (from another |
| 65 |
# transaction) try to access the same bucket of the index but one transaction |
| 66 |
# commits before other transaction begins so no r-w conflict. |
| 67 |
|
| 68 |
permutation rxy1 wx1 c1 rxy2 wy2 c2 |
| 69 |
permutation rxy2 wy2 c2 rxy1 wx1 c1 |
| 70 |
|
| 71 |
# An index scan (from one transaction) and an index insert (from another |
| 72 |
# transaction) try to access different buckets of the index and also one |
| 73 |
# transaction commits before other transaction begins, so no r-w conflict. |
| 74 |
|
| 75 |
permutation rxy3 wx3 c1 rxy4 wy4 c2 |
| 76 |
permutation rxy4 wy4 c2 rxy3 wx3 c1 |
| 77 |
|
| 78 |
|
| 79 |
# An index scan (from one transaction) and an index insert (from another |
| 80 |
# transaction) try to access the same bucket of the index and one transaction |
| 81 |
# begins before other transaction commits so there is a r-w conflict. |
| 82 |
|
| 83 |
permutation rxy1 wx1 rxy2 c1 wy2 c2 |
| 84 |
permutation rxy1 wx1 rxy2 wy2 c1 c2 |
| 85 |
permutation rxy1 wx1 rxy2 wy2 c2 c1 |
| 86 |
permutation rxy1 rxy2 wx1 c1 wy2 c2 |
| 87 |
permutation rxy1 rxy2 wx1 wy2 c1 c2 |
| 88 |
permutation rxy1 rxy2 wx1 wy2 c2 c1 |
| 89 |
permutation rxy1 rxy2 wy2 wx1 c1 c2 |
| 90 |
permutation rxy1 rxy2 wy2 wx1 c2 c1 |
| 91 |
permutation rxy1 rxy2 wy2 c2 wx1 c1 |
| 92 |
permutation rxy2 rxy1 wx1 c1 wy2 c2 |
| 93 |
permutation rxy2 rxy1 wx1 wy2 c1 c2 |
| 94 |
permutation rxy2 rxy1 wx1 wy2 c2 c1 |
| 95 |
permutation rxy2 rxy1 wy2 wx1 c1 c2 |
| 96 |
permutation rxy2 rxy1 wy2 wx1 c2 c1 |
| 97 |
permutation rxy2 rxy1 wy2 c2 wx1 c1 |
| 98 |
permutation rxy2 wy2 rxy1 wx1 c1 c2 |
| 99 |
permutation rxy2 wy2 rxy1 wx1 c2 c1 |
| 100 |
permutation rxy2 wy2 rxy1 c2 wx1 c1 |
| 101 |
|
| 102 |
# An index scan (from one transaction) and an index insert (from another |
| 103 |
# transaction) try to access different buckets of the index so no r-w conflict. |
| 104 |
|
| 105 |
permutation rxy3 wx3 rxy4 c1 wy4 c2 |
| 106 |
permutation rxy3 wx3 rxy4 wy4 c1 c2 |
| 107 |
permutation rxy3 wx3 rxy4 wy4 c2 c1 |
| 108 |
permutation rxy3 rxy4 wx3 c1 wy4 c2 |
| 109 |
permutation rxy3 rxy4 wx3 wy4 c1 c2 |
| 110 |
permutation rxy3 rxy4 wx3 wy4 c2 c1 |
| 111 |
permutation rxy3 rxy4 wy4 wx3 c1 c2 |
| 112 |
permutation rxy3 rxy4 wy4 wx3 c2 c1 |
| 113 |
permutation rxy3 rxy4 wy4 c2 wx3 c1 |
| 114 |
permutation rxy4 rxy3 wx3 c1 wy4 c2 |
| 115 |
permutation rxy4 rxy3 wx3 wy4 c1 c2 |
| 116 |
permutation rxy4 rxy3 wx3 wy4 c2 c1 |
| 117 |
permutation rxy4 rxy3 wy4 wx3 c1 c2 |
| 118 |
permutation rxy4 rxy3 wy4 wx3 c2 c1 |
| 119 |
permutation rxy4 rxy3 wy4 c2 wx3 c1 |
| 120 |
permutation rxy4 wy4 rxy3 wx3 c1 c2 |
| 121 |
permutation rxy4 wy4 rxy3 wx3 c2 c1 |
| 122 |
permutation rxy4 wy4 rxy3 c2 wx3 c1 |