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