Merge lp:~vkolesnikov/pbxt/pbxt-bug-340316 into lp:pbxt

Proposed by Vladimir Kolesnikov on 2009-03-11
Status: Merged
Merged at revision: not available
Proposed branch: lp:~vkolesnikov/pbxt/pbxt-bug-340316
Merge into: lp:pbxt
Diff against target: None lines
To merge this branch: bzr merge lp:~vkolesnikov/pbxt/pbxt-bug-340316
Reviewer Review Type Date Requested Status
PBXT Core 2009-03-11 Pending
Review via email: mp+4370@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2009-03-05 15:28:42 +0000
3+++ ChangeLog 2009-03-10 17:43:39 +0000
4@@ -3,6 +3,10 @@
5
6 ------- 1.0.08 RC - Not yet released
7
8+RN226: Fixed bug #340316: Issue with bigint unsigned auto-increment field
9+
10+RN225: Fixed bug #308557: UPDATE fails to match all rows in a transactional scenario
11+
12 RN224: Fixed a deadlock which could occur during table scans.
13
14 RN223: Index scans now use handles to cache buffers instead of making a copy of the index page. The handles are "copy-on-write".
15
16=== modified file 'src/ha_pbxt.cc'
17--- src/ha_pbxt.cc 2009-02-27 09:22:44 +0000
18+++ src/ha_pbxt.cc 2009-03-11 11:18:00 +0000
19@@ -2065,7 +2065,7 @@
20 MX_ULONGLONG_T *nb_reserved_values __attribute__((unused)))
21 {
22 register XTTableHPtr tab;
23- MX_ULONGLONG_T nr;
24+ MX_ULONGLONG_T nr, nr_plus_inc;
25
26 ASSERT_NS(pb_ex_in_use);
27
28@@ -2077,7 +2077,11 @@
29 nr = offset;
30 else if (increment > 1 && ((nr - offset) % increment) != 0)
31 nr += increment - ((nr - offset) % increment);
32- tab->tab_auto_inc = (xtWord8) (nr + increment);
33+ nr_plus_inc = nr + increment;
34+ if (table->next_number_field->cmp((const unsigned char *)&nr, (const unsigned char *)&nr_plus_inc) < 0)
35+ tab->tab_auto_inc = (xtWord8) (nr_plus_inc);
36+ else
37+ nr = ~0; /* indicate error to the caller */
38 xt_spinlock_unlock(&tab->tab_ainc_lock);
39
40 *first_value = nr;
41@@ -2091,25 +2095,34 @@
42 * insert into t1 values (-1);
43 * insert into t1 values (NULL);
44 */
45-void ha_pbxt::set_auto_increment(MX_LONGLONG_T nr)
46+void ha_pbxt::set_auto_increment(Field *nr)
47 {
48 register XTTableHPtr tab;
49+ MX_ULONGLONG_T nr_int_val;
50+
51+ nr_int_val = nr->val_int();
52+ tab = pb_open_tab->ot_table;
53
54- tab = pb_open_tab->ot_table;
55- if ((MX_LONGLONG_T) tab->tab_auto_inc <= nr) {
56+ if (nr->cmp((const unsigned char *)&tab->tab_auto_inc) > 0) {
57 xt_spinlock_lock(&tab->tab_ainc_lock);
58- if ((MX_LONGLONG_T) tab->tab_auto_inc <= nr && nr > 0)
59- tab->tab_auto_inc = nr + 1;
60+
61+ if (nr->cmp((const unsigned char *)&tab->tab_auto_inc) > 0) {
62+ MX_ULONGLONG_T nr_int_val_plus_one = nr_int_val + 1;
63+ if (nr->cmp((const unsigned char *)&nr_int_val_plus_one) < 0)
64+ tab->tab_auto_inc = nr_int_val_plus_one;
65+ else
66+ tab->tab_auto_inc = nr_int_val;
67+ }
68 xt_spinlock_unlock(&tab->tab_ainc_lock);
69 }
70
71 if (xt_db_auto_increment_mode == 1) {
72- if (nr > (MX_LONGLONG_T) tab->tab_dic.dic_min_auto_inc) {
73+ if (nr_int_val > (MX_ULONGLONG_T) tab->tab_dic.dic_min_auto_inc) {
74 /* Do this every 100 calls: */
75 #ifdef DEBUG
76- tab->tab_dic.dic_min_auto_inc = nr + 5;
77+ tab->tab_dic.dic_min_auto_inc = nr_int_val + 5;
78 #else
79- tab->tab_dic.dic_min_auto_inc = nr + 100;
80+ tab->tab_dic.dic_min_auto_inc = nr_int_val + 100;
81 #endif
82 pb_open_tab->ot_thread = xt_get_self();
83 if (!xt_tab_write_min_auto_inc(pb_open_tab))
84@@ -2187,8 +2200,12 @@
85 table->timestamp_field->set_time();
86
87 if (table->next_number_field && buf == table->record[0]) {
88- update_auto_increment();
89- set_auto_increment(table->next_number_field->val_int());
90+ int err = update_auto_increment();
91+ if (err) {
92+ ha_log_pbxt_thread_error_for_mysql(pb_ignore_dup_key);
93+ return err;
94+ }
95+ set_auto_increment(table->next_number_field);
96 }
97
98 if (!xt_tab_new_record(pb_open_tab, (xtWord1 *) buf))
99@@ -2281,8 +2298,8 @@
100
101 old_map = mx_tmp_use_all_columns(table, table->read_set);
102 nr = table->found_next_number_field->val_int();
103+ set_auto_increment(table->found_next_number_field);
104 mx_tmp_restore_column_map(table, old_map);
105- set_auto_increment(nr);
106 }
107
108 if (!xt_tab_update_record(pb_open_tab, (xtWord1 *) old_data, (xtWord1 *) new_data))
109
110=== modified file 'src/ha_pbxt.h'
111--- src/ha_pbxt.h 2008-12-10 20:34:30 +0000
112+++ src/ha_pbxt.h 2009-03-10 17:43:39 +0000
113@@ -171,7 +171,7 @@
114 MX_ULONGLONG_T nb_desired_values,
115 MX_ULONGLONG_T *first_value,
116 MX_ULONGLONG_T *nb_reserved_values);
117- void set_auto_increment(MX_LONGLONG_T nr);
118+ void set_auto_increment(Field *nr);
119
120 int write_row(byte * buf);
121 int update_row(const byte * old_data, byte * new_data);
122
123=== modified file 'src/index_xt.cc'
124--- src/index_xt.cc 2009-03-06 13:40:00 +0000
125+++ src/index_xt.cc 2009-03-10 08:28:54 +0000
126@@ -2327,7 +2327,9 @@
127 #endif
128 ASSERT_NS(ot->ot_ind_rhandle);
129 xt_ind_lock_handle(ot->ot_ind_rhandle);
130- if (!ot->ot_ind_state.i_node_ref_size && ot->ot_ind_state.i_item_offset < ot->ot_ind_state.i_total_size) {
131+ if (!ot->ot_ind_state.i_node_ref_size &&
132+ ot->ot_ind_state.i_item_offset < ot->ot_ind_state.i_total_size &&
133+ ot->ot_ind_rhandle->ih_cache_reference) {
134 key_value.sv_key = &ot->ot_ind_rhandle->ih_branch->tb_data[ot->ot_ind_state.i_item_offset];
135 key_value.sv_length = ot->ot_ind_state.i_item_size - XT_RECORD_REF_SIZE;
136
137
138=== modified file 'test/mysql-test/r/pbxt_bugs.result'
139--- test/mysql-test/r/pbxt_bugs.result 2008-12-16 13:39:34 +0000
140+++ test/mysql-test/r/pbxt_bugs.result 2009-03-11 11:18:00 +0000
141@@ -986,3 +986,62 @@
142 insert into t1 values ("1");
143 insert into t2 values ("1");
144 DROP TABLE IF EXISTS t2,t1;
145+DROP TABLE IF EXISTS t5;
146+CREATE TABLE t5 (
147+c1 BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
148+c2 BIGINT SIGNED NULL,
149+c3 BIGINT SIGNED NOT NULL,
150+c4 TINYINT, c5 SMALLINT,
151+c6 MEDIUMINT,
152+c7 INT,
153+c8 INTEGER,
154+PRIMARY KEY(c1,c2), UNIQUE INDEX(c3));
155+INSERT INTO t5 VALUES
156+(0,-9223372036854775808,1,2,3,4,5,5),
157+(255,-2147483648,6,7,8,9,10,10),
158+(65535,-8388608,11,12,13,14,15,15),
159+(16777215,-32768,16,17,18,19,20,20),
160+(4294967295,-128,21,22,23,24,25,25),
161+(18446744073709551615,9223372036854775807,26,27,28,29,30,30);
162+INSERT INTO t5(c2,c3) VALUES(33,34) /* tries to increment out of range */;
163+ERROR HY000: Failed to read auto-increment value from storage engine
164+INSERT INTO t5(c2,c3) VALUES(33,34);
165+ERROR HY000: Failed to read auto-increment value from storage engine
166+SELECT * FROM t5;
167+c1 c2 c3 c4 c5 c6 c7 c8
168+1 -9223372036854775808 1 2 3 4 5 5
169+255 -2147483648 6 7 8 9 10 10
170+65535 -8388608 11 12 13 14 15 15
171+16777215 -32768 16 17 18 19 20 20
172+4294967295 -128 21 22 23 24 25 25
173+18446744073709551615 9223372036854775807 26 27 28 29 30 30
174+DROP TABLE t5;
175+/* same test as above with signed bigint */
176+CREATE TABLE t5 (
177+c1 BIGINT SIGNED NOT NULL AUTO_INCREMENT,
178+c2 BIGINT SIGNED NULL,
179+c3 BIGINT SIGNED NOT NULL,
180+c4 TINYINT, c5 SMALLINT,
181+c6 MEDIUMINT,
182+c7 INT,
183+c8 INTEGER,
184+PRIMARY KEY(c1,c2), UNIQUE INDEX(c3));
185+INSERT INTO t5 VALUES
186+(0,-9223372036854775808,1,2,3,4,5,5),
187+(255,-2147483648,6,7,8,9,10,10),
188+(65535,-8388608,11,12,13,14,15,15),
189+(16777215,-32768,16,17,18,19,20,20),
190+(4294967295,-128,21,22,23,24,25,25),
191+(9223372036854775807,9223372036854775807,26,27,28,29,30,30);
192+INSERT INTO t5(c2,c3) VALUES(33,34) /* tries to increment out of range */;
193+ERROR HY000: Failed to read auto-increment value from storage engine
194+INSERT INTO t5(c2,c3) VALUES(33,34);
195+ERROR HY000: Failed to read auto-increment value from storage engine
196+SELECT * FROM t5;
197+c1 c2 c3 c4 c5 c6 c7 c8
198+1 -9223372036854775808 1 2 3 4 5 5
199+255 -2147483648 6 7 8 9 10 10
200+65535 -8388608 11 12 13 14 15 15
201+16777215 -32768 16 17 18 19 20 20
202+4294967295 -128 21 22 23 24 25 25
203+9223372036854775807 9223372036854775807 26 27 28 29 30 30
204
205=== modified file 'test/mysql-test/t/pbxt_bugs.test'
206--- test/mysql-test/t/pbxt_bugs.test 2008-12-16 13:39:34 +0000
207+++ test/mysql-test/t/pbxt_bugs.test 2009-03-11 11:18:00 +0000
208@@ -807,3 +807,61 @@
209 insert into t2 values ("1");
210
211 DROP TABLE IF EXISTS t2,t1;
212+
213+# bug 340316: Issue with bigint unsigned auto-increment field
214+
215+--disable_warnings
216+DROP TABLE IF EXISTS t5;
217+--enable_warnings
218+CREATE TABLE t5 (
219+ c1 BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
220+ c2 BIGINT SIGNED NULL,
221+ c3 BIGINT SIGNED NOT NULL,
222+ c4 TINYINT, c5 SMALLINT,
223+ c6 MEDIUMINT,
224+ c7 INT,
225+ c8 INTEGER,
226+ PRIMARY KEY(c1,c2), UNIQUE INDEX(c3));
227+
228+INSERT INTO t5 VALUES
229+ (0,-9223372036854775808,1,2,3,4,5,5),
230+ (255,-2147483648,6,7,8,9,10,10),
231+ (65535,-8388608,11,12,13,14,15,15),
232+ (16777215,-32768,16,17,18,19,20,20),
233+ (4294967295,-128,21,22,23,24,25,25),
234+ (18446744073709551615,9223372036854775807,26,27,28,29,30,30);
235+
236+--error 1467
237+INSERT INTO t5(c2,c3) VALUES(33,34) /* tries to increment out of range */;
238+--error 1467
239+INSERT INTO t5(c2,c3) VALUES(33,34);
240+
241+SELECT * FROM t5;
242+
243+DROP TABLE t5;
244+
245+/* same test as above with signed bigint */
246+CREATE TABLE t5 (
247+ c1 BIGINT SIGNED NOT NULL AUTO_INCREMENT,
248+ c2 BIGINT SIGNED NULL,
249+ c3 BIGINT SIGNED NOT NULL,
250+ c4 TINYINT, c5 SMALLINT,
251+ c6 MEDIUMINT,
252+ c7 INT,
253+ c8 INTEGER,
254+ PRIMARY KEY(c1,c2), UNIQUE INDEX(c3));
255+
256+INSERT INTO t5 VALUES
257+ (0,-9223372036854775808,1,2,3,4,5,5),
258+ (255,-2147483648,6,7,8,9,10,10),
259+ (65535,-8388608,11,12,13,14,15,15),
260+ (16777215,-32768,16,17,18,19,20,20),
261+ (4294967295,-128,21,22,23,24,25,25),
262+ (9223372036854775807,9223372036854775807,26,27,28,29,30,30);
263+
264+--error 1467
265+INSERT INTO t5(c2,c3) VALUES(33,34) /* tries to increment out of range */;
266+--error 1467
267+INSERT INTO t5(c2,c3) VALUES(33,34);
268+
269+SELECT * FROM t5;

Subscribers

People subscribed via source and target branches