12
12
You should have received a copy of the GNU General Public License
13
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
19
#include "drizzled/internal/my_bit.h"
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18
#include <drizzled/server_includes.h>
19
#include <mysys/my_bit.h>
20
20
#include "myisampack.h"
21
21
#include "ha_myisam.h"
22
22
#include "myisam_priv.h"
23
#include "drizzled/option.h"
24
#include "drizzled/internal/my_bit.h"
25
#include "drizzled/internal/m_string.h"
23
#include "mysys/my_bit.h"
26
24
#include "drizzled/util/test.h"
27
25
#include "drizzled/error.h"
28
26
#include "drizzled/errmsg_print.h"
29
27
#include "drizzled/gettext.h"
30
28
#include "drizzled/session.h"
31
#include "drizzled/plugin.h"
32
29
#include "drizzled/plugin/client.h"
33
30
#include "drizzled/table.h"
34
31
#include "drizzled/field/timestamp.h"
35
32
#include "drizzled/memory/multi_malloc.h"
36
#include "drizzled/plugin/daemon.h"
38
#include <boost/algorithm/string.hpp>
39
#include <boost/scoped_ptr.hpp>
44
36
#include <algorithm>
46
#include <boost/program_options.hpp>
47
#include <drizzled/module/option_map.h>
49
namespace po= boost::program_options;
51
38
using namespace std;
52
using namespace drizzled;
54
40
static const string engine_name("MyISAM");
56
boost::mutex THR_LOCK_myisam;
42
pthread_mutex_t THR_LOCK_myisam= PTHREAD_MUTEX_INITIALIZER;
58
static uint32_t myisam_key_cache_block_size= KEY_CACHE_BLOCK_SIZE;
59
static uint32_t myisam_key_cache_size;
60
static uint32_t myisam_key_cache_division_limit;
61
static uint32_t myisam_key_cache_age_threshold;
44
static uint32_t repair_threads;
45
static uint32_t block_size;
62
46
static uint64_t max_sort_file_size;
63
typedef constrained_check<size_t, SIZE_MAX, 1024, 1024> sort_buffer_constraint;
64
static sort_buffer_constraint sort_buffer_size;
66
void st_mi_isam_share::setKeyCache()
68
(void)init_key_cache(&key_cache,
69
myisam_key_cache_block_size,
70
myisam_key_cache_size,
71
myisam_key_cache_division_limit,
72
myisam_key_cache_age_threshold);
47
static uint64_t sort_buffer_size;
75
49
/*****************************************************************************
85
class MyisamEngine : public plugin::StorageEngine
59
class MyisamEngine : public drizzled::plugin::StorageEngine
88
MyisamEngine(const MyisamEngine&);
89
MyisamEngine& operator=(const MyisamEngine&);
91
explicit MyisamEngine(string name_arg) :
92
plugin::StorageEngine(name_arg,
93
HTON_CAN_INDEX_BLOBS |
94
HTON_STATS_RECORDS_IS_EXACT |
100
HTON_SKIP_STORE_LOCK)
104
virtual ~MyisamEngine()
106
mi_panic(HA_PANIC_CLOSE);
109
virtual Cursor *create(Table &table)
111
return new ha_myisam(*this, table);
62
MyisamEngine(string name_arg)
63
: drizzled::plugin::StorageEngine(name_arg,
64
HTON_HAS_DATA_DICTIONARY |
65
HTON_CAN_INDEX_BLOBS |
66
HTON_STATS_RECORDS_IS_EXACT |
73
HTON_NEED_READ_RANGE_BUFFER |
74
HTON_SKIP_STORE_LOCK |
80
virtual Cursor *create(TableShare &table,
83
return new (mem_root) ha_myisam(*this, table);
114
86
const char **bas_ext() const {
115
87
return ha_myisam_exts;
118
int doCreateTable(Session&,
90
int doCreateTable(Session *, const char *table_name,
120
const TableIdentifier &identifier,
123
int doRenameTable(Session&, const TableIdentifier &from, const TableIdentifier &to);
125
int doDropTable(Session&, const TableIdentifier &identifier);
92
drizzled::message::Table&);
94
int doRenameTable(Session*, const char *from, const char *to);
96
int doDropTable(Session&, const string table_name);
127
98
int doGetTableDefinition(Session& session,
128
const TableIdentifier &identifier,
129
message::Table &table_message);
101
const char *table_name,
103
drizzled::message::Table *table_proto);
105
/* Temp only engine, so do not return values. */
106
void doGetTableNames(CachedDirectory &, string& , set<string>&) { };
131
108
uint32_t max_supported_keys() const { return MI_MAX_KEY; }
132
109
uint32_t max_supported_key_length() const { return MI_MAX_KEY_LENGTH; }
141
118
HA_KEYREAD_ONLY);
143
bool doDoesTableExist(Session& session, const TableIdentifier &identifier);
145
void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
146
const drizzled::SchemaIdentifier &schema_identifier,
147
drizzled::TableIdentifier::vector &set_of_identifiers);
148
bool validateCreateTableOption(const std::string &key, const std::string &state)
122
int MyisamEngine::doGetTableDefinition(Session&,
127
drizzled::message::Table *table_proto)
130
ProtoCache::iterator iter;
132
pthread_mutex_lock(&proto_cache_mutex);
133
iter= proto_cache.find(path);
135
if (iter!= proto_cache.end())
151
if (boost::iequals(key, "ROW_FORMAT"))
138
table_proto->CopyFrom(((*iter).second));
160
void MyisamEngine::doGetTableIdentifiers(drizzled::CachedDirectory&,
161
const drizzled::SchemaIdentifier&,
162
drizzled::TableIdentifier::vector&)
166
bool MyisamEngine::doDoesTableExist(Session &session, const TableIdentifier &identifier)
168
return session.getMessageCache().doesTableMessageExist(identifier);
171
int MyisamEngine::doGetTableDefinition(Session &session,
172
const TableIdentifier &identifier,
173
message::Table &table_message)
175
if (session.getMessageCache().getTableMessage(identifier, table_message))
141
pthread_mutex_unlock(&proto_cache_mutex);
217
183
uint32_t i, j, recpos, minpos, fieldpos, temp_length, length;
218
184
enum ha_base_keytype type= HA_KEYTYPE_BINARY;
219
185
unsigned char *record;
220
187
MI_KEYDEF *keydef;
221
188
MI_COLUMNDEF *recinfo, *recinfo_pos;
222
189
HA_KEYSEG *keyseg;
223
TableShare *share= table_arg->getMutableShare();
190
TableShare *share= table_arg->s;
224
191
uint32_t options= share->db_options_in_use;
225
if (!(memory::multi_malloc(false,
226
recinfo_out, (share->sizeFields() * 2 + 2) * sizeof(MI_COLUMNDEF),
227
keydef_out, share->sizeKeys() * sizeof(MI_KEYDEF),
228
&keyseg, (share->key_parts + share->sizeKeys()) * sizeof(HA_KEYSEG),
192
if (!(drizzled::memory::multi_malloc(false,
193
recinfo_out, (share->fields * 2 + 2) * sizeof(MI_COLUMNDEF),
194
keydef_out, share->keys * sizeof(MI_KEYDEF),
195
&keyseg, (share->key_parts + share->keys) * sizeof(HA_KEYSEG),
230
197
return(HA_ERR_OUT_OF_MEM);
231
198
keydef= *keydef_out;
232
199
recinfo= *recinfo_out;
233
for (i= 0; i < share->sizeKeys(); i++)
200
pos= table_arg->key_info;
201
for (i= 0; i < share->keys; i++, pos++)
235
KeyInfo *pos= &table_arg->key_info[i];
236
203
keydef[i].flag= ((uint16_t) pos->flags & (HA_NOSAME));
237
204
keydef[i].key_alg= HA_KEY_ALG_BTREE;
238
205
keydef[i].block_length= pos->block_size;
589
562
open of a table that is in use by other threads already (if the
590
563
MyISAM share exists already).
592
if (!(file= mi_open(identifier, mode, test_if_locked)))
593
return (errno ? errno : -1);
565
if (!(file=mi_open(name, mode, test_if_locked)))
566
return (my_errno ? my_errno : -1);
595
if (!getTable()->getShare()->getType()) /* No need to perform a check for tmp table */
568
if (!table->s->tmp_table) /* No need to perform a check for tmp table */
597
if ((errno= table2myisam(getTable(), &keyinfo, &recinfo, &recs)))
570
if ((my_errno= table2myisam(table, &keyinfo, &recinfo, &recs)))
601
if (check_definition(keyinfo, recinfo, getTable()->getShare()->sizeKeys(), recs,
574
if (check_definition(keyinfo, recinfo, table->s->keys, recs,
602
575
file->s->keyinfo, file->s->rec,
603
576
file->s->base.keys, file->s->base.fields, true))
605
errno= HA_ERR_CRASHED;
578
my_errno= HA_ERR_CRASHED;
610
assert(test_if_locked);
611
583
if (test_if_locked & (HA_OPEN_IGNORE_IF_LOCKED | HA_OPEN_TMP_TABLE))
612
584
mi_extra(file, HA_EXTRA_NO_WAIT_LOCK, 0);
614
586
info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST);
615
587
if (!(test_if_locked & HA_OPEN_WAIT_IF_LOCKED))
616
588
mi_extra(file, HA_EXTRA_WAIT_LOCK, 0);
617
if (!getTable()->getShare()->db_record_offset)
589
if (!table->s->db_record_offset)
618
590
is_ordered= false;
621
593
keys_with_parts.reset();
622
for (i= 0; i < getTable()->getShare()->sizeKeys(); i++)
594
for (i= 0; i < table->s->keys; i++)
624
getTable()->key_info[i].block_size= file->s->keyinfo[i].block_length;
596
table->key_info[i].block_size= file->s->keyinfo[i].block_length;
626
KeyPartInfo *kp= getTable()->key_info[i].key_part;
627
KeyPartInfo *kp_end= kp + getTable()->key_info[i].key_parts;
598
KEY_PART_INFO *kp= table->key_info[i].key_part;
599
KEY_PART_INFO *kp_end= kp + table->key_info[i].key_parts;
628
600
for (; kp != kp_end; kp++)
630
602
if (!kp->field->part_of_key.test(i))
694
668
errmsg_printf(ERRMSG_LVL_INFO, "Retrying repair of: '%s' failed. "
695
669
"Please try REPAIR EXTENDED or myisamchk",
696
getTable()->getShare()->getPath());
697
671
return(HA_ADMIN_FAILED);
700
param.db_name= getTable()->getShare()->getSchemaName();
701
param.table_name= getTable()->getAlias();
674
param.db_name= table->s->db.str;
675
param.table_name= table->alias;
702
676
param.tmpfile_createflag = O_RDWR | O_TRUNC;
703
677
param.using_global_keycache = 1;
704
678
param.session= session;
705
679
param.out_flag= 0;
706
param.sort_buffer_length= static_cast<size_t>(sort_buffer_size);
680
param.sort_buffer_length= (size_t)sort_buffer_size;
707
681
strcpy(fixed_name,file->filename);
709
683
// Don't lock tables if we have used LOCK Table
710
if (mi_lock_database(file, getTable()->getShare()->getType() ? F_EXTRA_LCK : F_WRLCK))
684
if (mi_lock_database(file, table->s->tmp_table ? F_EXTRA_LCK : F_WRLCK))
712
mi_check_print_error(¶m,ER(ER_CANT_LOCK),errno);
686
mi_check_print_error(¶m,ER(ER_CANT_LOCK),my_errno);
713
687
return(HA_ADMIN_FAILED);
728
702
local_testflag|= T_STATISTICS;
729
703
param.testflag|= T_STATISTICS; // We get this for free
730
704
statistics_done=1;
705
if (repair_threads > 1)
708
/* TODO: respect myisam_repair_threads variable */
709
snprintf(buf, 40, "Repair with %d threads", my_count_bits(key_map));
710
session->set_proc_info(buf);
711
error = mi_repair_parallel(¶m, file, fixed_name,
712
param.testflag & T_QUICK);
713
session->set_proc_info("Repair done"); // to reset proc_info, as
714
// it was pointing to local buffer
732
718
session->set_proc_info("Repair by sorting");
733
719
error = mi_repair_by_sort(¶m, file, fixed_name,
914
899
param.testflag= (T_SILENT | T_REP_BY_SORT | T_QUICK |
915
900
T_CREATE_MISSING_KEYS);
916
901
param.myf_rw&= ~MY_WAIT_IF_FULL;
917
param.sort_buffer_length= static_cast<size_t>(sort_buffer_size);
902
param.sort_buffer_length= (size_t)sort_buffer_size;
918
903
param.stats_method= MI_STATS_METHOD_NULLS_NOT_EQUAL;
919
904
if ((error= (repair(session,param,0) != HA_ADMIN_OK)) && param.retry_repair)
921
906
errmsg_printf(ERRMSG_LVL_WARN, "Warning: Enabling keys got errno %d on %s.%s, retrying",
922
errno, param.db_name, param.table_name);
907
my_errno, param.db_name, param.table_name);
923
908
/* Repairing by sort failed. Now try standard repair method. */
924
909
param.testflag&= ~(T_REP_BY_SORT | T_QUICK);
925
910
error= (repair(session,param,0) != HA_ADMIN_OK);
1036
int ha_myisam::doUpdateRecord(const unsigned char *old_data, unsigned char *new_data)
1021
int ha_myisam::update_row(const unsigned char *old_data, unsigned char *new_data)
1023
ha_statistic_increment(&SSV::ha_update_count);
1024
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
1025
table->timestamp_field->set_time();
1038
1026
return mi_update(file,old_data,new_data);
1041
int ha_myisam::doDeleteRecord(const unsigned char *buf)
1029
int ha_myisam::delete_row(const unsigned char *buf)
1031
ha_statistic_increment(&SSV::ha_delete_count);
1043
1032
return mi_delete(file,buf);
1047
int ha_myisam::doStartIndexScan(uint32_t idx, bool )
1036
int ha_myisam::index_init(uint32_t idx, bool )
1049
1038
active_index=idx;
1050
1039
//in_range_read= false;
1084
1073
key_part_map keypart_map)
1086
1075
assert(inited==INDEX);
1087
ha_statistic_increment(&system_status_var::ha_read_key_count);
1076
ha_statistic_increment(&SSV::ha_read_key_count);
1088
1077
int error=mi_rkey(file, buf, active_index, key, keypart_map,
1089
1078
HA_READ_PREFIX_LAST);
1090
getTable()->status=error ? STATUS_NOT_FOUND: 0;
1079
table->status=error ? STATUS_NOT_FOUND: 0;
1094
1083
int ha_myisam::index_next(unsigned char *buf)
1096
1085
assert(inited==INDEX);
1097
ha_statistic_increment(&system_status_var::ha_read_next_count);
1086
ha_statistic_increment(&SSV::ha_read_next_count);
1098
1087
int error=mi_rnext(file,buf,active_index);
1099
getTable()->status=error ? STATUS_NOT_FOUND: 0;
1088
table->status=error ? STATUS_NOT_FOUND: 0;
1103
1092
int ha_myisam::index_prev(unsigned char *buf)
1105
1094
assert(inited==INDEX);
1106
ha_statistic_increment(&system_status_var::ha_read_prev_count);
1095
ha_statistic_increment(&SSV::ha_read_prev_count);
1107
1096
int error=mi_rprev(file,buf, active_index);
1108
getTable()->status=error ? STATUS_NOT_FOUND: 0;
1097
table->status=error ? STATUS_NOT_FOUND: 0;
1112
1101
int ha_myisam::index_first(unsigned char *buf)
1114
1103
assert(inited==INDEX);
1115
ha_statistic_increment(&system_status_var::ha_read_first_count);
1104
ha_statistic_increment(&SSV::ha_read_first_count);
1116
1105
int error=mi_rfirst(file, buf, active_index);
1117
getTable()->status=error ? STATUS_NOT_FOUND: 0;
1106
table->status=error ? STATUS_NOT_FOUND: 0;
1121
1110
int ha_myisam::index_last(unsigned char *buf)
1123
1112
assert(inited==INDEX);
1124
ha_statistic_increment(&system_status_var::ha_read_last_count);
1113
ha_statistic_increment(&SSV::ha_read_last_count);
1125
1114
int error=mi_rlast(file, buf, active_index);
1126
getTable()->status=error ? STATUS_NOT_FOUND: 0;
1115
table->status=error ? STATUS_NOT_FOUND: 0;
1178
1167
int ha_myisam::rnd_next(unsigned char *buf)
1180
ha_statistic_increment(&system_status_var::ha_read_rnd_next_count);
1169
ha_statistic_increment(&SSV::ha_read_rnd_next_count);
1181
1170
int error=mi_scan(file, buf);
1182
getTable()->status=error ? STATUS_NOT_FOUND: 0;
1171
table->status=error ? STATUS_NOT_FOUND: 0;
1175
int ha_myisam::restart_rnd_next(unsigned char *buf, unsigned char *pos)
1177
return rnd_pos(buf,pos);
1186
1180
int ha_myisam::rnd_pos(unsigned char *buf, unsigned char *pos)
1188
ha_statistic_increment(&system_status_var::ha_read_rnd_count);
1189
int error=mi_rrnd(file, buf, internal::my_get_ptr(pos,ref_length));
1190
getTable()->status=error ? STATUS_NOT_FOUND: 0;
1182
ha_statistic_increment(&SSV::ha_read_rnd_count);
1183
int error=mi_rrnd(file, buf, my_get_ptr(pos,ref_length));
1184
table->status=error ? STATUS_NOT_FOUND: 0;
1195
1189
void ha_myisam::position(const unsigned char *)
1197
internal::my_off_t row_position= mi_position(file);
1198
internal::my_store_ptr(ref, ref_length, row_position);
1191
my_off_t row_position= mi_position(file);
1192
my_store_ptr(ref, ref_length, row_position);
1201
1195
int ha_myisam::info(uint32_t flag)
1217
1211
if (flag & HA_STATUS_CONST)
1219
TableShare *share= getTable()->getMutableShare();
1213
TableShare *share= table->s;
1220
1214
stats.max_data_file_length= misam_info.max_data_file_length;
1221
1215
stats.max_index_file_length= misam_info.max_index_file_length;
1222
1216
stats.create_time= misam_info.create_time;
1223
1217
ref_length= misam_info.reflength;
1224
1218
share->db_options_in_use= misam_info.options;
1225
stats.block_size= myisam_key_cache_block_size; /* record block size */
1219
stats.block_size= block_size; /* record block size */
1227
set_prefix(share->keys_in_use, share->sizeKeys());
1222
if (share->tmp_table == NO_TMP_TABLE)
1223
pthread_mutex_lock(&share->mutex);
1224
set_prefix(share->keys_in_use, share->keys);
1229
1226
* Due to bug 394932 (32-bit solaris build failure), we need
1230
1227
* to convert the uint64_t key_map member of the misam_info
1273
1270
share->keys_for_keyread&= share->keys_in_use;
1274
1271
share->db_record_offset= misam_info.record_offset;
1275
1272
if (share->key_parts)
1276
memcpy(getTable()->key_info[0].rec_per_key,
1273
memcpy(table->key_info[0].rec_per_key,
1277
1274
misam_info.rec_per_key,
1278
sizeof(getTable()->key_info[0].rec_per_key)*share->key_parts);
1279
assert(share->getType() != message::Table::STANDARD);
1275
sizeof(table->key_info[0].rec_per_key)*share->key_parts);
1276
if (share->tmp_table == NO_TMP_TABLE)
1277
pthread_mutex_unlock(&share->mutex);
1282
1280
Set data_file_name and index_file_name to point at the symlink value
1283
1281
if table is symlinked (Ie; Real name is not same as generated name)
1285
1283
data_file_name= index_file_name= 0;
1286
internal::fn_format(name_buff, file->filename, "", MI_NAME_DEXT,
1284
fn_format(name_buff, file->filename, "", MI_NAME_DEXT,
1287
1285
MY_APPEND_EXT | MY_UNPACK_FILENAME);
1288
1286
if (strcmp(name_buff, misam_info.data_file_name))
1289
1287
data_file_name=misam_info.data_file_name;
1290
internal::fn_format(name_buff, file->filename, "", MI_NAME_IEXT,
1288
fn_format(name_buff, file->filename, "", MI_NAME_IEXT,
1291
1289
MY_APPEND_EXT | MY_UNPACK_FILENAME);
1292
1290
if (strcmp(name_buff, misam_info.index_file_name))
1293
1291
index_file_name=misam_info.index_file_name;
1328
1326
return mi_delete_all_rows(file);
1331
int MyisamEngine::doDropTable(Session &session,
1332
const TableIdentifier &identifier)
1329
int MyisamEngine::doDropTable(Session&, const string table_path)
1334
session.getMessageCache().removeTableMessage(identifier);
1336
return mi_delete_table(identifier.getPath().c_str());
1331
ProtoCache::iterator iter;
1333
pthread_mutex_lock(&proto_cache_mutex);
1334
iter= proto_cache.find(table_path.c_str());
1336
if (iter!= proto_cache.end())
1337
proto_cache.erase(iter);
1339
pthread_mutex_unlock(&proto_cache_mutex);
1341
return mi_delete_table(table_path.c_str());
1340
1345
int ha_myisam::external_lock(Session *session, int lock_type)
1342
1347
file->in_use= session;
1343
return mi_lock_database(file, !getTable()->getShare()->getType() ?
1348
return mi_lock_database(file, !table->s->tmp_table ?
1344
1349
lock_type : ((lock_type == F_UNLCK) ?
1345
1350
F_UNLCK : F_EXTRA_LCK));
1348
int MyisamEngine::doCreateTable(Session &session,
1353
int MyisamEngine::doCreateTable(Session *, const char *table_name,
1349
1354
Table& table_arg,
1350
const TableIdentifier &identifier,
1351
message::Table& create_proto)
1355
drizzled::message::Table& create_proto)
1354
1358
uint32_t create_flags= 0, create_records;
1373
1377
create_info.index_file_name= NULL;
1374
1378
create_info.language= share->table_charset->number;
1376
if (create_proto.type() == message::Table::TEMPORARY)
1380
if (create_proto.type() == drizzled::message::Table::TEMPORARY)
1377
1381
create_flags|= HA_CREATE_TMP_TABLE;
1378
1382
if (options & HA_OPTION_PACK_RECORD)
1379
1383
create_flags|= HA_PACK_RECORD;
1381
/* TODO: Check that the following internal::fn_format is really needed */
1382
error= mi_create(internal::fn_format(buff, identifier.getPath().c_str(), "", "",
1383
MY_UNPACK_FILENAME|MY_APPEND_EXT),
1384
share->sizeKeys(), keydef,
1385
/* TODO: Check that the following fn_format is really needed */
1386
error= mi_create(fn_format(buff, table_name, "", "",
1387
MY_UNPACK_FILENAME|MY_APPEND_EXT),
1388
share->keys, keydef,
1385
1389
create_records, recinfo,
1386
1390
0, (MI_UNIQUEDEF*) 0,
1387
1391
&create_info, create_flags);
1388
1392
free((unsigned char*) recinfo);
1390
session.getMessageCache().storeTableMessage(identifier, create_proto);
1394
pthread_mutex_lock(&proto_cache_mutex);
1395
proto_cache.insert(make_pair(table_name, create_proto));
1396
pthread_mutex_unlock(&proto_cache_mutex);
1396
int MyisamEngine::doRenameTable(Session &session, const TableIdentifier &from, const TableIdentifier &to)
1402
int MyisamEngine::doRenameTable(Session*,
1403
const char *from, const char *to)
1398
session.getMessageCache().renameTableMessage(from, to);
1400
return mi_rename(from.getPath().c_str(), to.getPath().c_str());
1405
return mi_rename(from,to);
1423
1428
/* it's safe to call the following if bulk_insert isn't on */
1424
mi_flush_bulk_insert(file, getTable()->getShare()->next_number_index);
1429
mi_flush_bulk_insert(file, table->s->next_number_index);
1426
1431
(void) extra(HA_EXTRA_KEYREAD);
1427
key_copy(key, getTable()->getInsertRecord(),
1428
&getTable()->key_info[getTable()->getShare()->next_number_index],
1429
getTable()->getShare()->next_number_key_offset);
1430
error= mi_rkey(file, getTable()->getUpdateRecord(), (int) getTable()->getShare()->next_number_index,
1431
key, make_prev_keypart_map(getTable()->getShare()->next_number_keypart),
1432
key_copy(key, table->record[0],
1433
table->key_info + table->s->next_number_index,
1434
table->s->next_number_key_offset);
1435
error= mi_rkey(file, table->record[1], (int) table->s->next_number_index,
1436
key, make_prev_keypart_map(table->s->next_number_keypart),
1432
1437
HA_READ_PREFIX_LAST);
1437
/* Get data from getUpdateRecord() */
1438
nr= ((uint64_t) getTable()->next_number_field->
1439
val_int_offset(getTable()->getShare()->rec_buff_length)+1);
1442
/* Get data from record[1] */
1443
nr= ((uint64_t) table->next_number_field->
1444
val_int_offset(table->s->rec_buff_length)+1);
1441
1446
extra(HA_EXTRA_NO_KEYREAD);
1442
1447
*first_value= nr;
1487
1492
return (uint)file->state->checksum;
1490
static int myisam_init(module::Context &context)
1492
context.add(new MyisamEngine(engine_name));
1493
context.registerVariable(new sys_var_constrained_value<size_t>("sort-buffer-size",
1495
context.registerVariable(new sys_var_uint64_t_ptr("max_sort_file_size",
1496
&max_sort_file_size,
1497
context.getOptions()["max-sort-file-size"].as<uint64_t>()));
1495
static MyisamEngine *engine= NULL;
1497
static int myisam_init(drizzled::plugin::Registry ®istry)
1500
engine= new MyisamEngine(engine_name);
1501
registry.add(engine);
1503
pthread_mutex_init(&THR_LOCK_myisam,MY_MUTEX_INIT_FAST);
1505
/* call ha_init_key_cache() on all key caches to init them */
1506
error= init_key_cache(dflt_key_cache,
1507
(uint32_t) dflt_key_cache->param_block_size,
1508
(uint32_t) dflt_key_cache->param_buff_size,
1509
dflt_key_cache->param_division_limit,
1510
dflt_key_cache->param_age_threshold);
1513
exit(1); /* Memory Allocation Failure */
1503
static void init_options(drizzled::module::option_context &context)
1518
static int myisam_deinit(drizzled::plugin::Registry ®istry)
1505
context("max-sort-file-size",
1506
po::value<uint64_t>(&max_sort_file_size)->default_value(INT32_MAX),
1507
N_("Don't use the fast sort index method to created index if the temporary file would get bigger than this."));
1508
context("sort-buffer-size",
1509
po::value<sort_buffer_constraint>(&sort_buffer_size)->default_value(8192*1024),
1510
N_("The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE."));
1520
registry.remove(engine);
1523
pthread_mutex_destroy(&THR_LOCK_myisam);
1524
end_key_cache(dflt_key_cache, 1); // Can never fail
1526
return mi_panic(HA_PANIC_CLOSE);
1529
static DRIZZLE_SYSVAR_UINT(block_size, block_size,
1530
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
1531
N_("Block size to be used for MyISAM index pages."),
1532
NULL, NULL, MI_KEY_BLOCK_LENGTH, MI_MIN_KEY_BLOCK_LENGTH,
1533
MI_MAX_KEY_BLOCK_LENGTH, 0);
1535
static DRIZZLE_SYSVAR_UINT(repair_threads, repair_threads,
1536
PLUGIN_VAR_RQCMDARG,
1537
N_("Number of threads to use when repairing MyISAM tables. The value of "
1538
"1 disables parallel repair."),
1539
NULL, NULL, 1, 1, UINT32_MAX, 0);
1541
static DRIZZLE_SYSVAR_ULONGLONG(max_sort_file_size, max_sort_file_size,
1542
PLUGIN_VAR_RQCMDARG,
1543
N_("Don't use the fast sort index method to created index if the temporary file would get bigger than this."),
1544
NULL, NULL, INT32_MAX, 0, UINT64_MAX, 0);
1546
static DRIZZLE_SYSVAR_ULONGLONG(sort_buffer_size, sort_buffer_size,
1547
PLUGIN_VAR_RQCMDARG,
1548
N_("The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE."),
1549
NULL, NULL, 8192*1024, 1024, SIZE_MAX, 0);
1551
extern uint32_t data_pointer_size;
1552
static DRIZZLE_SYSVAR_UINT(data_pointer_size, data_pointer_size,
1553
PLUGIN_VAR_RQCMDARG,
1554
N_("Default pointer size to be used for MyISAM tables."),
1555
NULL, NULL, 6, 2, 7, 0);
1557
static drizzle_sys_var* system_variables[]= {
1558
DRIZZLE_SYSVAR(block_size),
1559
DRIZZLE_SYSVAR(repair_threads),
1560
DRIZZLE_SYSVAR(max_sort_file_size),
1561
DRIZZLE_SYSVAR(sort_buffer_size),
1562
DRIZZLE_SYSVAR(data_pointer_size),
1514
1567
DRIZZLE_DECLARE_PLUGIN
1520
1572
"Default engine as of MySQL 3.23 with great performance",
1521
1573
PLUGIN_LICENSE_GPL,
1522
1574
myisam_init, /* Plugin Init */
1523
NULL, /* system variables */
1524
init_options /* config options */
1575
myisam_deinit, /* Plugin Deinit */
1576
NULL, /* status variables */
1577
system_variables, /* system variables */
1578
NULL /* config options */
1526
1580
DRIZZLE_DECLARE_PLUGIN_END;