104
104
mi_panic(HA_PANIC_CLOSE);
107
virtual Cursor *create(TableShare &table)
107
virtual Cursor *create(Table &table)
109
109
return new ha_myisam(*this, table);
546
546
ha_myisam::ha_myisam(plugin::StorageEngine &engine_arg,
547
TableShare &table_arg)
548
548
: Cursor(engine_arg, table_arg),
550
550
can_enable_indexes(true),
590
590
if (!(file= mi_open(identifier, mode, test_if_locked)))
591
591
return (errno ? errno : -1);
593
if (!table->getShare()->getType()) /* No need to perform a check for tmp table */
593
if (!getTable()->getShare()->getType()) /* No need to perform a check for tmp table */
595
if ((errno= table2myisam(table, &keyinfo, &recinfo, &recs)))
595
if ((errno= table2myisam(getTable(), &keyinfo, &recinfo, &recs)))
599
if (check_definition(keyinfo, recinfo, table->getShare()->sizeKeys(), recs,
599
if (check_definition(keyinfo, recinfo, getTable()->getShare()->sizeKeys(), recs,
600
600
file->s->keyinfo, file->s->rec,
601
601
file->s->base.keys, file->s->base.fields, true))
612
612
info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST);
613
613
if (!(test_if_locked & HA_OPEN_WAIT_IF_LOCKED))
614
614
mi_extra(file, HA_EXTRA_WAIT_LOCK, 0);
615
if (!table->getShare()->db_record_offset)
615
if (!getTable()->getShare()->db_record_offset)
616
616
is_ordered= false;
619
619
keys_with_parts.reset();
620
for (i= 0; i < table->getShare()->sizeKeys(); i++)
620
for (i= 0; i < getTable()->getShare()->sizeKeys(); i++)
622
table->key_info[i].block_size= file->s->keyinfo[i].block_length;
622
getTable()->key_info[i].block_size= file->s->keyinfo[i].block_length;
624
KeyPartInfo *kp= table->key_info[i].key_part;
625
KeyPartInfo *kp_end= kp + table->key_info[i].key_parts;
624
KeyPartInfo *kp= getTable()->key_info[i].key_part;
625
KeyPartInfo *kp_end= kp + getTable()->key_info[i].key_parts;
626
626
for (; kp != kp_end; kp++)
628
628
if (!kp->field->part_of_key.test(i))
659
659
If we have an auto_increment column and we are writing a changed row
660
660
or a new row, then update the auto_increment value in the record.
662
if (table->next_number_field && buf == table->getInsertRecord())
662
if (getTable()->next_number_field && buf == getTable()->getInsertRecord())
665
665
if ((error= update_auto_increment()))
692
692
errmsg_printf(ERRMSG_LVL_INFO, "Retrying repair of: '%s' failed. "
693
693
"Please try REPAIR EXTENDED or myisamchk",
694
table->getShare()->getPath());
694
getTable()->getShare()->getPath());
695
695
return(HA_ADMIN_FAILED);
698
param.db_name= table->getShare()->getSchemaName();
699
param.table_name= table->getAlias();
698
param.db_name= getTable()->getShare()->getSchemaName();
699
param.table_name= getTable()->getAlias();
700
700
param.tmpfile_createflag = O_RDWR | O_TRUNC;
701
701
param.using_global_keycache = 1;
702
702
param.session= session;
705
705
strcpy(fixed_name,file->filename);
707
707
// Don't lock tables if we have used LOCK Table
708
if (mi_lock_database(file, table->getShare()->getType() ? F_EXTRA_LCK : F_WRLCK))
708
if (mi_lock_database(file, getTable()->getShare()->getType() ? F_EXTRA_LCK : F_WRLCK))
710
710
mi_check_print_error(¶m,ER(ER_CANT_LOCK),errno);
711
711
return(HA_ADMIN_FAILED);
903
903
else if (mode == HA_KEY_SWITCH_NONUNIQ_SAVE)
905
Session *session= table->in_use;
905
Session *session= getTable()->in_use;
907
907
const char *save_proc_info= session->get_proc_info();
908
908
session->set_proc_info("Creating index");
979
979
void ha_myisam::start_bulk_insert(ha_rows rows)
981
Session *session= table->in_use;
981
Session *session= getTable()->in_use;
982
982
ulong size= session->variables.read_buff_size;
984
984
/* don't enable row cache if too few rows */
1063
1063
assert(inited==INDEX);
1064
1064
ha_statistic_increment(&system_status_var::ha_read_key_count);
1065
1065
int error=mi_rkey(file, buf, active_index, key, keypart_map, find_flag);
1066
table->status=error ? STATUS_NOT_FOUND: 0;
1066
getTable()->status=error ? STATUS_NOT_FOUND: 0;
1074
1074
ha_statistic_increment(&system_status_var::ha_read_key_count);
1075
1075
int error=mi_rkey(file, buf, index, key, keypart_map, find_flag);
1076
table->status=error ? STATUS_NOT_FOUND: 0;
1076
getTable()->status=error ? STATUS_NOT_FOUND: 0;
1084
1084
ha_statistic_increment(&system_status_var::ha_read_key_count);
1085
1085
int error=mi_rkey(file, buf, active_index, key, keypart_map,
1086
1086
HA_READ_PREFIX_LAST);
1087
table->status=error ? STATUS_NOT_FOUND: 0;
1087
getTable()->status=error ? STATUS_NOT_FOUND: 0;
1093
1093
assert(inited==INDEX);
1094
1094
ha_statistic_increment(&system_status_var::ha_read_next_count);
1095
1095
int error=mi_rnext(file,buf,active_index);
1096
table->status=error ? STATUS_NOT_FOUND: 0;
1096
getTable()->status=error ? STATUS_NOT_FOUND: 0;
1102
1102
assert(inited==INDEX);
1103
1103
ha_statistic_increment(&system_status_var::ha_read_prev_count);
1104
1104
int error=mi_rprev(file,buf, active_index);
1105
table->status=error ? STATUS_NOT_FOUND: 0;
1105
getTable()->status=error ? STATUS_NOT_FOUND: 0;
1111
1111
assert(inited==INDEX);
1112
1112
ha_statistic_increment(&system_status_var::ha_read_first_count);
1113
1113
int error=mi_rfirst(file, buf, active_index);
1114
table->status=error ? STATUS_NOT_FOUND: 0;
1114
getTable()->status=error ? STATUS_NOT_FOUND: 0;
1120
1120
assert(inited==INDEX);
1121
1121
ha_statistic_increment(&system_status_var::ha_read_last_count);
1122
1122
int error=mi_rlast(file, buf, active_index);
1123
table->status=error ? STATUS_NOT_FOUND: 0;
1123
getTable()->status=error ? STATUS_NOT_FOUND: 0;
1136
1136
error= mi_rnext_same(file,buf);
1137
1137
} while (error == HA_ERR_RECORD_DELETED);
1138
table->status=error ? STATUS_NOT_FOUND: 0;
1138
getTable()->status=error ? STATUS_NOT_FOUND: 0;
1177
1177
ha_statistic_increment(&system_status_var::ha_read_rnd_next_count);
1178
1178
int error=mi_scan(file, buf);
1179
table->status=error ? STATUS_NOT_FOUND: 0;
1179
getTable()->status=error ? STATUS_NOT_FOUND: 0;
1185
1185
ha_statistic_increment(&system_status_var::ha_read_rnd_count);
1186
1186
int error=mi_rrnd(file, buf, internal::my_get_ptr(pos,ref_length));
1187
table->status=error ? STATUS_NOT_FOUND: 0;
1187
getTable()->status=error ? STATUS_NOT_FOUND: 0;
1214
1214
if (flag & HA_STATUS_CONST)
1216
TableShare *share= table->getMutableShare();
1216
TableShare *share= getTable()->getMutableShare();
1217
1217
stats.max_data_file_length= misam_info.max_data_file_length;
1218
1218
stats.max_index_file_length= misam_info.max_index_file_length;
1219
1219
stats.create_time= misam_info.create_time;
1270
1270
share->keys_for_keyread&= share->keys_in_use;
1271
1271
share->db_record_offset= misam_info.record_offset;
1272
1272
if (share->key_parts)
1273
memcpy(table->key_info[0].rec_per_key,
1273
memcpy(getTable()->key_info[0].rec_per_key,
1274
1274
misam_info.rec_per_key,
1275
sizeof(table->key_info[0].rec_per_key)*share->key_parts);
1275
sizeof(getTable()->key_info[0].rec_per_key)*share->key_parts);
1276
1276
assert(share->getType() != message::Table::STANDARD);
1337
1337
int ha_myisam::external_lock(Session *session, int lock_type)
1339
1339
file->in_use= session;
1340
return mi_lock_database(file, !table->getShare()->getType() ?
1340
return mi_lock_database(file, !getTable()->getShare()->getType() ?
1341
1341
lock_type : ((lock_type == F_UNLCK) ?
1342
1342
F_UNLCK : F_EXTRA_LCK));
1409
1409
unsigned char key[MI_MAX_KEY_LENGTH];
1411
if (!table->getShare()->next_number_key_offset)
1411
if (!getTable()->getShare()->next_number_key_offset)
1412
1412
{ // Autoincrement at key-start
1413
1413
ha_myisam::info(HA_STATUS_AUTO);
1414
1414
*first_value= stats.auto_increment_value;
1420
1420
/* it's safe to call the following if bulk_insert isn't on */
1421
mi_flush_bulk_insert(file, table->getShare()->next_number_index);
1421
mi_flush_bulk_insert(file, getTable()->getShare()->next_number_index);
1423
1423
(void) extra(HA_EXTRA_KEYREAD);
1424
key_copy(key, table->getInsertRecord(),
1425
&table->key_info[table->getShare()->next_number_index],
1426
table->getShare()->next_number_key_offset);
1427
error= mi_rkey(file, table->getUpdateRecord(), (int) table->getShare()->next_number_index,
1428
key, make_prev_keypart_map(table->getShare()->next_number_keypart),
1424
key_copy(key, getTable()->getInsertRecord(),
1425
&getTable()->key_info[getTable()->getShare()->next_number_index],
1426
getTable()->getShare()->next_number_key_offset);
1427
error= mi_rkey(file, getTable()->getUpdateRecord(), (int) getTable()->getShare()->next_number_index,
1428
key, make_prev_keypart_map(getTable()->getShare()->next_number_keypart),
1429
1429
HA_READ_PREFIX_LAST);
1434
1434
/* Get data from getUpdateRecord() */
1435
nr= ((uint64_t) table->next_number_field->
1436
val_int_offset(table->getShare()->rec_buff_length)+1);
1435
nr= ((uint64_t) getTable()->next_number_field->
1436
val_int_offset(getTable()->getShare()->rec_buff_length)+1);
1438
1438
extra(HA_EXTRA_NO_KEYREAD);
1439
1439
*first_value= nr;