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

Method prepare_handle_duplicate

sql/sql_insert.cc:2453–2511  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2451
2452
2453int Write_record::prepare_handle_duplicate(int error)
2454{
2455 /*
2456 If we do more than one iteration of the replace loop, from the second one the
2457 row will have an explicit value in the autoinc field, which was set at
2458 the first call of handler::update_auto_increment(). So we must save
2459 the autogenerated value to avoid thd->insert_id_for_cur_row to become
2460 0.
2461 */
2462 if (table->file->insert_id_for_cur_row > 0)
2463 insert_id_for_cur_row= table->file->insert_id_for_cur_row;
2464 else
2465 table->file->insert_id_for_cur_row= insert_id_for_cur_row;
2466
2467 if (is_fatal_error(error))
2468 return on_ha_error(error);
2469
2470 bool is_duplicate_key_error=
2471 table->file->is_fatal_error(error, HA_CHECK_ALL & ~HA_CHECK_DUP);
2472 if (!is_duplicate_key_error)
2473 {
2474 /*
2475 We come here when we had an ignorable error which is not a duplicate
2476 key error. In this we ignore error if ignore flag is set, otherwise
2477 report error as usual. We will not do any duplicate key processing.
2478 */
2479 if (info->ignore)
2480 {
2481 table->file->print_error(error, MYF(ME_WARNING));
2482 ignored_error= true;
2483 return 1; /* Ignoring a not fatal error */
2484 }
2485 return on_ha_error(error);
2486 }
2487
2488 key_nr = table->file->get_dup_key(error);
2489
2490 if (unlikely(key_nr == std::numeric_limits<decltype(key_nr)>::max()))
2491 return on_ha_error(HA_ERR_FOUND_DUPP_KEY); /* Database can't find key */
2492
2493 DEBUG_SYNC(thd, "write_row_replace");
2494
2495 /* Read all columns for the row we are going to replace */
2496 table->use_all_columns();
2497 /*
2498 Don't allow REPLACE to replace a row when an auto_increment column
2499 was used. This ensures that we don't get a problem when the
2500 whole range of the key has been used.
2501 */
2502 if (info->handle_duplicates == DUP_REPLACE && table->next_number_field &&
2503 key_nr == table->s->next_number_index && insert_id_for_cur_row > 0)
2504 return on_ha_error(error);
2505
2506 error= locate_dup_record();
2507 if (error)
2508 return on_ha_error(error);
2509
2510 return 0;

Callers

nothing calls this directly

Calls 4

get_dup_keyMethod · 0.80
use_all_columnsMethod · 0.80
is_fatal_errorMethod · 0.45
print_errorMethod · 0.45

Tested by

no test coverage detected