|
3 | 3 | """ |
4 | 4 | ID: issue-8084 |
5 | 5 | ISSUE: https://github.com/FirebirdSQL/firebird/issues/8084 |
6 | | -TITLE: Partial index uniqueness violation |
| 6 | +TITLE: Partial index uniqueness violation (changes in columns participating in index filtering expression are not properly tracked). |
7 | 7 | DESCRIPTION: |
8 | 8 | NOTES: |
9 | | - [18.04.2024] pzotov |
10 | | - Confirmed bug on 6.0.0.315 |
11 | | - Checked on 6.0.0.321 #1d96c10 - all OK. |
| 9 | + [19.04.2024] pzotov |
| 10 | + Reduced min_version to 5.0.1 after backporting (commit #0e9ef69). |
| 11 | + Confirmed bug on 6.0.0.315; confirmed problem noted as second case (see ticket) in 6.0.0.321 #1d96c10. |
| 12 | + Checked on 6.0.0.325 #f5930a5, 5.0.1.1383 #0e9ef69 (intermediate snapshot) - all OK. |
12 | 13 | """ |
13 | 14 |
|
14 | 15 | import pytest |
|
18 | 19 |
|
19 | 20 | test_script = """ |
20 | 21 | set list on; |
21 | | - recreate table test ( |
22 | | - id bigint primary key |
23 | | - ,a bigint not null |
24 | | - ,b smallint not null |
| 22 | +
|
| 23 | + -- https://github.com/FirebirdSQL/firebird/issues/8084#issue-2247604539 |
| 24 | + recreate table test1 ( |
| 25 | + t1_id bigint primary key |
| 26 | + ,t1_a bigint not null |
| 27 | + ,t1_b smallint not null |
25 | 28 | ); |
26 | 29 |
|
27 | | - create unique index idx_test_a on test(a) where (b = 1); |
| 30 | + create unique index test1_idx_a on test1(t1_a) where (t1_b = 1); |
28 | 31 |
|
29 | | - insert into test(id, a, b) values (1, 1, 0); |
30 | | - insert into test(id, a, b) values (2, 2, 1); |
| 32 | + insert into test1(t1_id, t1_a, t1_b) values (1, 1, 0); |
| 33 | + insert into test1(t1_id, t1_a, t1_b) values (2, 2, 1); |
31 | 34 | commit; |
32 | 35 |
|
33 | | - insert into test(id, a, b) values (3, 1, 0); -- must pass |
| 36 | + insert into test1(t1_id, t1_a, t1_b) values (3, 1, 0); -- must pass |
34 | 37 | commit; |
35 | | - insert into test(id, a, b) values (4, 2, 1); -- must fail with "attempt to store duplicate value" |
| 38 | + insert into test1(t1_id, t1_a, t1_b) values (4, 2, 1); -- must fail with "attempt to store duplicate value" |
36 | 39 | rollback; |
37 | 40 |
|
38 | | - update test set b = 1 where id = 1; -- must pass |
| 41 | + update test1 set t1_b = 1 where t1_id = 1; -- must pass |
| 42 | + commit; |
| 43 | +
|
| 44 | + update test1 set t1_b = 1 where t1_id = 3; -- BUG was here: passed before fix but must fail. |
| 45 | + commit; |
| 46 | +
|
| 47 | + select t1_a+0 as t1_a, count(*) as t1_a_cnt from test1 where t1_b+0 = 1 group by t1_a+0; |
| 48 | + rollback; |
| 49 | +
|
| 50 | + ------------------------------------------------------------------------- |
| 51 | +
|
| 52 | + -- https://github.com/FirebirdSQL/firebird/issues/8084#issuecomment-2063121843 |
| 53 | + recreate table test2 ( |
| 54 | + t2_id bigint not null, |
| 55 | + t2_a bigint not null, |
| 56 | + t2_b smallint not null, |
| 57 | + constraint pk_test2 primary key(t2_id) |
| 58 | + ); |
| 59 | +
|
| 60 | + create unique index test2_idx_a on test2(t2_a) where (t2_b = 1); |
| 61 | +
|
| 62 | + insert into test2(t2_id, t2_a, t2_b) values (1, 1, 0); |
| 63 | + insert into test2(t2_id, t2_a, t2_b) values (2, 2, 1); |
| 64 | + insert into test2(t2_id, t2_a, t2_b) values (3, 1, 0); |
39 | 65 | commit; |
40 | 66 |
|
41 | | - update test set b = 1 where id = 3; -- BUG was here: passed before fix but must fail. |
| 67 | + update test2 set t2_b=0; |
42 | 68 | commit; |
43 | 69 |
|
44 | | - select a+0 as a, count(*) as a_cnt from test where b+0 = 1 group by a+0; |
| 70 | + insert into test2(t2_id, t2_a, t2_b) values (4, 2, 1); -- must pass |
| 71 | +
|
| 72 | + select * from test2; |
| 73 | +
|
45 | 74 | """ |
46 | 75 |
|
47 | 76 | act = isql_act('db', test_script, substitutions=[('[ \t]+', ' ')]) |
48 | 77 |
|
49 | 78 | expected_stdout = """ |
50 | 79 | Statement failed, SQLSTATE = 23000 |
51 | | - attempt to store duplicate value (visible to active transactions) in unique index "IDX_TEST_A" |
52 | | - -Problematic key value is ("A" = 2) |
53 | | -
|
| 80 | + attempt to store duplicate value (visible to active transactions) in unique index "TEST1_IDX_A" |
| 81 | + -Problematic key value is ("T1_A" = 2) |
54 | 82 | Statement failed, SQLSTATE = 23000 |
55 | | - attempt to store duplicate value (visible to active transactions) in unique index "IDX_TEST_A" |
56 | | - -Problematic key value is ("A" = 1) |
| 83 | + attempt to store duplicate value (visible to active transactions) in unique index "TEST1_IDX_A" |
| 84 | + -Problematic key value is ("T1_A" = 1) |
| 85 | +
|
| 86 | + T1_A 1 |
| 87 | + T1_A_CNT 1 |
| 88 | +
|
| 89 | + T1_A 2 |
| 90 | + T1_A_CNT 1 |
| 91 | +
|
| 92 | + T2_ID 1 |
| 93 | + T2_A 1 |
| 94 | + T2_B 0 |
| 95 | +
|
| 96 | + T2_ID 2 |
| 97 | + T2_A 2 |
| 98 | + T2_B 0 |
57 | 99 |
|
58 | | - A 1 |
59 | | - A_CNT 1 |
| 100 | + T2_ID 3 |
| 101 | + T2_A 1 |
| 102 | + T2_B 0 |
60 | 103 |
|
61 | | - A 2 |
62 | | - A_CNT 1 |
| 104 | + T2_ID 4 |
| 105 | + T2_A 2 |
| 106 | + T2_B 1 |
63 | 107 | """ |
64 | 108 |
|
65 | | -@pytest.mark.version('>=6.0.0') |
| 109 | +@pytest.mark.version('>=5.0.1') |
66 | 110 | def test_1(act: Action): |
67 | 111 | act.expected_stdout = expected_stdout |
68 | 112 | act.execute(combine_output = True) |
|
0 commit comments