MCPcopy Create free account
hub / github.com/MariaDB/server / is_foreign_key_prefix

Function is_foreign_key_prefix

sql/sql_class.cc:215–274  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

213*/
214
215bool is_foreign_key_prefix(Key *a, Key *b)
216{
217 ha_key_alg a_alg= a->key_create_info.algorithm;
218 ha_key_alg b_alg= b->key_create_info.algorithm;
219
220 // The real algorithm in InnoDB will be BTREE if none was given by user.
221 a_alg= a_alg == HA_KEY_ALG_UNDEF ? HA_KEY_ALG_BTREE : a_alg;
222 b_alg= b_alg == HA_KEY_ALG_UNDEF ? HA_KEY_ALG_BTREE : b_alg;
223
224 if (a_alg != b_alg)
225 return false;
226
227 /* Ensure that 'a' is the generated key */
228 if (a->generated)
229 {
230 if (b->generated && a->columns.elements > b->columns.elements)
231 swap_variables(Key*, a, b); // Put shorter key in 'a'
232 }
233 else
234 {
235 if (!b->generated)
236 return false; // No foreign key
237 swap_variables(Key*, a, b); // Put generated key in 'a'
238 }
239
240 /* Test if 'a' is a prefix of 'b' */
241 if (a->columns.elements > b->columns.elements)
242 return false; // Can't be prefix
243
244 List_iterator<Key_part_spec> col_it1(a->columns);
245 List_iterator<Key_part_spec> col_it2(b->columns);
246 const Key_part_spec *col1, *col2;
247
248#ifdef ENABLE_WHEN_INNODB_CAN_HANDLE_SWAPED_FOREIGN_KEY_COLUMNS
249 while ((col1= col_it1++))
250 {
251 bool found= 0;
252 col_it2.rewind();
253 while ((col2= col_it2++))
254 {
255 if (*col1 == *col2)
256 {
257 found= TRUE;
258 break;
259 }
260 }
261 if (!found)
262 return false; // Error
263 }
264 return true; // Is prefix
265#else
266 while ((col1= col_it1++))
267 {
268 col2= col_it2++;
269 if (!(*col1 == *col2))
270 return false;
271 }
272 return true; // Is prefix

Callers 1

Calls 1

rewindMethod · 0.45

Tested by

no test coverage detected