| 12592 | } |
| 12593 | |
| 12594 | static int |
| 12595 | copy_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 |
no test coverage detected