3262
3268
session->set_proc_info(save_proc_info);
3266
If a HEAP table gets full, create a MyISAM table and copy all rows
3270
bool create_myisam_from_heap(Session *session, Table *table,
3271
MI_COLUMNDEF *start_recinfo,
3272
MI_COLUMNDEF **recinfo,
3273
int error, bool ignore_last_dupp_key_error)
3277
const char *save_proc_info;
3280
if (table->s->db_type() != heap_engine ||
3281
error != HA_ERR_RECORD_FILE_FULL)
3283
table->print_error(error, MYF(0));
3287
// Release latches since this can take a long time
3288
plugin::TransactionalStorageEngine::releaseTemporaryLatches(session);
3292
new_table.s= &share;
3293
new_table.s->storage_engine= myisam_engine;
3294
if (not (new_table.cursor= new_table.s->db_type()->getCursor(share, &new_table.mem_root)))
3295
return true; // End of memory
3297
save_proc_info=session->get_proc_info();
3298
session->set_proc_info("converting HEAP to MyISAM");
3300
if (new_table.create_myisam_tmp_table(table->key_info, start_recinfo,
3301
recinfo, session->lex->select_lex.options |
3304
if (new_table.open_tmp_table())
3306
if (table->cursor->indexes_are_disabled())
3307
new_table.cursor->ha_disable_indexes(HA_KEY_SWITCH_ALL);
3308
table->cursor->ha_index_or_rnd_end();
3309
table->cursor->ha_rnd_init(1);
3312
new_table.cursor->extra(HA_EXTRA_NO_ROWS);
3313
new_table.no_rows=1;
3316
/* HA_EXTRA_WRITE_CACHE can stay until close, no need to disable it */
3317
new_table.cursor->extra(HA_EXTRA_WRITE_CACHE);
3320
copy all old rows from heap table to MyISAM table
3321
This is the only code that uses record[1] to read/write but this
3322
is safe as this is a temporary MyISAM table without timestamp/autoincrement.
3324
while (!table->cursor->rnd_next(new_table.record[1]))
3326
write_err= new_table.cursor->ha_write_row(new_table.record[1]);
3330
/* copy row that filled HEAP table */
3331
if ((write_err=new_table.cursor->ha_write_row(table->record[0])))
3333
if (new_table.cursor->is_fatal_error(write_err, HA_CHECK_DUP) ||
3334
!ignore_last_dupp_key_error)
3338
/* remove heap table and change to use myisam table */
3339
(void) table->cursor->ha_rnd_end();
3340
(void) table->cursor->close(); // This deletes the table !
3341
delete table->cursor;
3342
table->cursor= NULL;
3343
new_table.s= table->s; // Keep old share
3347
table->cursor->change_table_ptr(table, table->s);
3348
table->use_all_columns();
3351
const char *new_proc_info=
3352
(!strcmp(save_proc_info,"Copying to tmp table") ?
3353
"Copying to tmp table on disk" : save_proc_info);
3354
session->set_proc_info(new_proc_info);
3359
table->print_error(write_err, MYF(0));
3360
(void) table->cursor->ha_rnd_end();
3361
(void) new_table.cursor->close();
3365
TableIdentifier identifier(new_table.s->getSchemaName(), new_table.s->table_name.str, new_table.s->table_name.str);
3366
new_table.s->db_type()->doDropTable(*session, identifier);
3370
delete new_table.cursor;
3371
session->set_proc_info(save_proc_info);
3372
table->mem_root= new_table.mem_root;
3376
3271
my_bitmap_map *Table::use_all_columns(MyBitmap *bitmap)
3378
3273
my_bitmap_map *old= bitmap->getBitmap();