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

Proposed by Vladimir Kolesnikov
Status: Merged
Merge reported by: Paul McCullagh
Merged at revision: not available
Proposed branch: lp:~vkolesnikov/pbxt/pbxt-bug-377788
Merge into: lp:pbxt
Diff against target: None lines
To merge this branch: bzr merge lp:~vkolesnikov/pbxt/pbxt-bug-377788
Reviewer Review Type Date Requested Status
PBXT Core Pending
Review via email: mp+9132@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-07-13 12:15:15 +0000
3+++ ChangeLog 2009-07-22 08:35:24 +0000
4@@ -3,6 +3,8 @@
5
6 ------- 1.0.09 RC2 - Not released yet
7
8+RN259: Fixed bug 377788: Cannot find index for FK, fixed buffer overflow
9+
10 RN258: updated xt_p_join implementation for Windows to check if a thread has already exited or has not yet started
11
12 RN257: Removed false assertion that could fail during restore if a transaction log page was zero-filled
13
14=== modified file 'src/datadic_xt.cc'
15--- src/datadic_xt.cc 2009-06-26 12:56:46 +0000
16+++ src/datadic_xt.cc 2009-07-22 08:31:39 +0000
17@@ -1735,8 +1735,8 @@
18 void XTDDConstraint::getColumnList(char *buffer, size_t size)
19 {
20 if (co_table->dt_table) {
21- xt_strcat(size, buffer, "`");
22- xt_strcpy(size, buffer, co_table->dt_table->tab_name->ps_path);
23+ xt_strcpy(size, buffer, "`");
24+ xt_strcat(size, buffer, co_table->dt_table->tab_name->ps_path);
25 xt_strcat(size, buffer, "` (`");
26 }
27 else
28@@ -1763,6 +1763,20 @@
29 return OK;
30 }
31
32+bool XTDDConstraint::samePrefixColumns(XTDDConstraint *co)
33+{
34+ u_int i = 0;
35+
36+ if (co_cols.size() > co->co_cols.size())
37+ return false;
38+ while (i<co_cols.size()) {
39+ if (myxt_strcasecmp(co_cols.itemAt(i)->cr_col_name, co->co_cols.itemAt(i)->cr_col_name) != 0)
40+ return false;
41+ i++;
42+ }
43+ return OK;
44+}
45+
46 bool XTDDConstraint::attachColumns()
47 {
48 XTDDColumn *col;
49@@ -2176,6 +2190,20 @@
50 return OK;
51 }
52
53+bool XTDDForeignKey::samePrefixReferenceColumns(XTDDConstraint *co)
54+{
55+ u_int i = 0;
56+
57+ if (fk_ref_cols.size() > co->co_cols.size())
58+ return false;
59+ while (i<fk_ref_cols.size()) {
60+ if (myxt_strcasecmp(fk_ref_cols.itemAt(i)->cr_col_name, co->co_cols.itemAt(i)->cr_col_name) != 0)
61+ return false;
62+ i++;
63+ }
64+ return OK;
65+}
66+
67 bool XTDDForeignKey::checkReferencedTypes(XTDDTable *dt)
68 {
69 XTDDColumn *col, *ref_col;
70@@ -2720,16 +2748,24 @@
71
72 XTDDIndex *XTDDTable::findIndex(XTDDConstraint *co)
73 {
74- XTDDIndex *ind;
75+ XTDDIndex *ind = NULL;
76+ XTDDIndex *cur_ind;
77+ u_int index_size = UINT_MAX;
78
79 for (u_int i=0; i<dt_indexes.size(); i++) {
80- ind = dt_indexes.itemAt(i);
81- if (co->sameColumns(ind))
82- return ind;
83+ cur_ind = dt_indexes.itemAt(i);
84+ u_int sz = cur_ind->getIndexPtr()->mi_key_size;
85+ if (sz < index_size && co->samePrefixColumns(cur_ind)) {
86+ ind = cur_ind;
87+ index_size = sz;
88+ }
89 }
90+
91+ if (ind)
92+ return ind;
93+
94 {
95 char buffer[XT_ERR_MSG_SIZE - 200];
96-
97 co->getColumnList(buffer, XT_ERR_MSG_SIZE - 200);
98 xt_register_ixterr(XT_REG_CONTEXT, XT_ERR_NO_MATCHING_INDEX, buffer);
99 }
100@@ -2738,16 +2774,24 @@
101
102 XTDDIndex *XTDDTable::findReferenceIndex(XTDDForeignKey *fk)
103 {
104- XTDDIndex *ind;
105+ XTDDIndex *ind = NULL;
106+ XTDDIndex *cur_ind;
107 XTDDColumnRef *cr;
108 u_int i;
109+ u_int index_size = UINT_MAX;
110
111 for (i=0; i<dt_indexes.size(); i++) {
112- ind = dt_indexes.itemAt(i);
113- if (fk->sameReferenceColumns(ind))
114- return ind;
115+ cur_ind = dt_indexes.itemAt(i);
116+ u_int sz = cur_ind->getIndexPtr()->mi_key_size;
117+ if (sz < index_size && fk->samePrefixReferenceColumns(cur_ind)) {
118+ ind = cur_ind;
119+ index_size = sz;
120+ }
121 }
122
123+ if (ind)
124+ return ind;
125+
126 /* If the index does not exist, maybe the columns do not exist?! */
127 for (i=0; i<fk->fk_ref_cols.size(); i++) {
128 cr = fk->fk_ref_cols.itemAt(i);
129
130=== modified file 'src/datadic_xt.h'
131--- src/datadic_xt.h 2009-06-12 14:29:30 +0000
132+++ src/datadic_xt.h 2009-07-22 08:31:39 +0000
133@@ -171,6 +171,7 @@
134 virtual void alterColumnName(XTThreadPtr self, char *from_name, char *to_name);
135 void getColumnList(char *buffer, size_t size);
136 bool sameColumns(XTDDConstraint *co);
137+ bool samePrefixColumns(XTDDConstraint *co);
138 bool attachColumns();
139 };
140
141@@ -240,6 +241,7 @@
142 void getReferenceList(char *buffer, size_t size);
143 struct XTIndex *getReferenceIndexPtr();
144 bool sameReferenceColumns(XTDDConstraint *co);
145+ bool samePrefixReferenceColumns(XTDDConstraint *co);
146 bool checkReferencedTypes(XTDDTable *dt);
147 void removeReference(XTThreadPtr self);
148 bool insertRow(xtWord1 *before, xtWord1 *after, XTThreadPtr thread);
149
150=== modified file 'src/table_xt.cc'
151--- src/table_xt.cc 2009-07-07 15:08:14 +0000
152+++ src/table_xt.cc 2009-07-22 08:35:24 +0000
153@@ -410,9 +410,11 @@
154 {
155 XTTableDescRec desc;
156 XTTableEntryRec te_tab;
157+ XTTableEntryPtr te_ptr;
158 XTTablePathPtr db_path;
159- char pbuf[PATH_MAX];
160+ char pbuf[PATH_MAX];
161 int len;
162+ u_int edx;
163
164 enter_();
165 pushr_(xt_tab_exit_db, db);
166@@ -487,13 +489,19 @@
167 desc.td_tab_path->tp_tab_count++;
168 te_tab.te_table = NULL;
169 xt_sl_insert(self, db->db_table_by_id, &desc.td_tab_id, &te_tab);
170+ }
171+ freer_(); // xt_describe_tables_exit(&desc)
172
173- xt_strcpy(PATH_MAX, pbuf, desc.td_tab_path->tp_path);
174+ /* Cannot open tables in the loop above because db->db_table_by_id which is built
175+ * above is used by xt_use_table_no_lock()
176+ */
177+ xt_enum_tables_init(&edx);
178+ while ((te_ptr = xt_enum_tables_next(self, db, &edx))) {
179+ xt_strcpy(PATH_MAX, pbuf, te_ptr->te_tab_path->tp_path);
180 xt_add_dir_char(PATH_MAX, pbuf);
181- xt_strcat(PATH_MAX, pbuf, desc.td_tab_name);
182+ xt_strcat(PATH_MAX, pbuf, te_ptr->te_tab_name);
183 xt_heap_release(self, xt_use_table_no_lock(self, db, (XTPathStrPtr)pbuf, FALSE, FALSE, NULL, NULL));
184 }
185- freer_(); // xt_describe_tables_exit(&desc)
186
187 popr_(); // Discard xt_tab_exit_db(db)
188 exit_();
189
190=== modified file 'test/mysql-test/r/pbxt_bugs.result'
191--- test/mysql-test/r/pbxt_bugs.result 2009-07-02 12:13:58 +0000
192+++ test/mysql-test/r/pbxt_bugs.result 2009-07-22 08:31:39 +0000
193@@ -1306,3 +1306,13 @@
194 DATA_LENGTH INDEX_LENGTH
195 5120 53248
196 drop table t1;
197+drop table if exists t2, t1;
198+create table t1 (c1 int, c2 int, index(c1, c2), index(c2, c1)) engine = pbxt;
199+create table t2 (c1 int, c2 int, index(c1, c2), index(c2, c1),
200+constraint fk1 foreign key (c1) references t1 (c1),
201+constraint fk2 foreign key (c2) references t1 (c2)) engine = pbxt;
202+insert into t1 values (1,1), (2,2);
203+insert into t2 values (1,1), (2,2);
204+insert into t2 values (1,3);
205+ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Constraint: `fk1`)
206+drop table t2, t1;
207
208=== modified file 'test/mysql-test/t/pbxt_bugs.test'
209--- test/mysql-test/t/pbxt_bugs.test 2009-07-02 12:13:58 +0000
210+++ test/mysql-test/t/pbxt_bugs.test 2009-07-22 08:31:39 +0000
211@@ -1005,8 +1005,26 @@
212 SELECT DATA_LENGTH, INDEX_LENGTH FROM information_schema.TABLES WHERE TABLE_SCHEMA='test' AND TABLE_NAME='t1';
213 drop table t1;
214
215+# bug 377788: Cannot find index for FK
216+
217+--disable_warnings
218+drop table if exists t2, t1;
219+--enable_warnings
220+
221+create table t1 (c1 int, c2 int, index(c1, c2), index(c2, c1)) engine = pbxt;
222+create table t2 (c1 int, c2 int, index(c1, c2), index(c2, c1),
223+ constraint fk1 foreign key (c1) references t1 (c1),
224+ constraint fk2 foreign key (c2) references t1 (c2)) engine = pbxt;
225+
226+insert into t1 values (1,1), (2,2);
227+insert into t2 values (1,1), (2,2);
228+--error 1452
229+insert into t2 values (1,3);
230+
231+drop table t2, t1;
232+
233 --disable_query_log
234
235-DROP TABLE t2, t5;
236+DROP TABLE t5;
237 drop database pbxt;
238 --enable_query_log

Subscribers

People subscribed via source and target branches