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

Function copy_data_between_tables

sql/sql_table.cc:12594–13232  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12592}
12593
12594static int
12595copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
12596 bool ignore,
12597 uint order_num, ORDER *order,
12598 ha_rows *copied, ha_rows *deleted,
12599 Alter_info *alter_info,
12600 Alter_table_ctx *alter_ctx, bool online,
12601 uint64 start_alter_id)
12602{
12603 int error= 1;
12604 Copy_field *copy= NULL, *copy_end;
12605 void *rli_buff;
12606 ha_rows found_count= 0, delete_count= 0;
12607 SORT_INFO *file_sort= 0;
12608 READ_RECORD info;
12609 bool auto_increment_field_copied= 0;
12610 bool cleanup_done= 0;
12611 bool init_read_record_done= 0;
12612 sql_mode_t save_sql_mode= thd->variables.sql_mode;
12613 ulonglong prev_insert_id, time_to_report_progress;
12614 Field **dfield_ptr= to->default_field;
12615 bool make_versioned= !from->versioned() && to->versioned();
12616 bool make_unversioned= from->versioned() && !to->versioned();
12617 bool keep_versioned= from->versioned() && to->versioned();
12618 bool bulk_insert_started= 0;
12619 Field *to_row_start= NULL, *to_row_end= NULL, *from_row_end= NULL;
12620 MYSQL_TIME query_start;
12621 DBUG_ENTER("copy_data_between_tables");
12622
12623 /*
12624 Various operations as part of the copy may cause call to trans_commit()
12625 or otherwise cause wakeup_subsequent_commits() before completion. So
12626 suspend those wakeups temporarily.
12627 */
12628 std::unique_ptr<wait_for_commit, std::function<void(wait_for_commit *)> >
12629 suspended_wfc(thd->suspend_subsequent_commits(),
12630 [thd](wait_for_commit *wfc) { thd->resume_subsequent_commits(wfc); });
12631
12632 // Relay_log_info is too big to put on a stack
12633 if (!(rli_buff= thd->alloc(sizeof(Relay_log_info))) ||
12634 !(copy= new (thd->mem_root) Copy_field[to->s->fields]))
12635 DBUG_RETURN(-1);
12636
12637 if (mysql_trans_prepare_alter_copy_data(thd))
12638 {
12639 delete [] copy;
12640 DBUG_RETURN(-1);
12641 }
12642
12643 /* We need external lock before we can disable/enable keys */
12644 if (to->file->ha_external_lock(thd, F_WRLCK))
12645 {
12646 /* Undo call to mysql_trans_prepare_alter_copy_data() */
12647 ha_enable_transaction(thd, TRUE);
12648 delete [] copy;
12649 DBUG_RETURN(-1);
12650 }
12651

Callers 1

mysql_alter_tableFunction · 0.85

Calls 15

ha_enable_transactionFunction · 0.85
alter_table_manage_keysFunction · 0.85
my_errorFunction · 0.85
bitmap_set_bitFunction · 0.85
my_snprintfFunction · 0.85
push_warningFunction · 0.85
setup_orderFunction · 0.85
filesortFunction · 0.85
thd_progress_next_stageFunction · 0.85
init_read_recordFunction · 0.85

Tested by

no test coverage detected