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

Function check_duplicate_key

sql/sql_table.cc:2505–2542  ·  view source on GitHub ↗

Check if there is a duplicate key. Report a warning for every duplicate key. @param thd Thread context. @param key Key to be checked. @param key_info Key meta-data info. @param key_list List of existing keys. */

Source from the content-addressed store, hash-verified

2503 @param key_list List of existing keys.
2504*/
2505static void check_duplicate_key(THD *thd, const Key *key, const KEY *key_info,
2506 const List<Key> *key_list)
2507{
2508 /*
2509 We only check for duplicate indexes if it is requested and the
2510 key is not auto-generated.
2511
2512 Check is requested if the key was explicitly created or altered
2513 by the user (unless it's a foreign key).
2514 */
2515 if (key->old || key->type == Key::FOREIGN_KEY || key->generated)
2516 return;
2517
2518 for (const Key &k : *key_list)
2519 {
2520 // Looking for a similar key...
2521
2522 if (&k == key)
2523 break;
2524
2525 if (k.generated ||
2526 (key->type != k.type) ||
2527 (key->key_create_info.algorithm != k.key_create_info.algorithm) ||
2528 (key->columns.elements != k.columns.elements))
2529 {
2530 // Keys are different.
2531 continue;
2532 }
2533
2534 if (std::equal(key->columns.begin(), key->columns.end(), k.columns.begin(),
2535 key_cmp))
2536 {
2537 push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_DUP_INDEX,
2538 ER_THD(thd, ER_DUP_INDEX), key_info->name.str);
2539 return;
2540 }
2541 }
2542}
2543
2544
2545bool Column_definition::prepare_stage1_typelib(THD *thd,

Callers 1

Calls 4

push_warning_printfFunction · 0.85
equalFunction · 0.70
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected