~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/ha_myisam.cc

  • Committer: Brian Aker
  • Date: 2010-08-12 17:19:46 UTC
  • mfrom: (1701.1.1 turn-off-csv)
  • Revision ID: brian@tangent.org-20100812171946-n44naaqhg27gehlh
MErge Monty, remove CSV from auto-build

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
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 */
15
 
 
16
 
 
17
 
 
18
 
#include <config.h>
19
 
#include <drizzled/internal/my_bit.h>
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
 
 
17
 
 
18
#include "config.h"
 
19
#include "drizzled/internal/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>
26
 
#include <drizzled/util/test.h>
27
 
#include <drizzled/error.h>
28
 
#include <drizzled/errmsg_print.h>
29
 
#include <drizzled/gettext.h>
30
 
#include <drizzled/session.h>
 
23
#include "drizzled/option.h"
 
24
#include "drizzled/internal/my_bit.h"
 
25
#include "drizzled/internal/m_string.h"
 
26
#include "drizzled/util/test.h"
 
27
#include "drizzled/error.h"
 
28
#include "drizzled/errmsg_print.h"
 
29
#include "drizzled/gettext.h"
 
30
#include "drizzled/session.h"
 
31
#include "drizzled/set_var.h"
31
32
#include <drizzled/plugin.h>
32
 
#include <drizzled/plugin/client.h>
33
 
#include <drizzled/table.h>
34
 
#include <drizzled/memory/multi_malloc.h>
35
 
#include <drizzled/plugin/daemon.h>
36
 
 
37
 
#include <drizzled/plugin/storage_engine.h>
 
33
#include "drizzled/plugin/client.h"
 
34
#include "drizzled/table.h"
 
35
#include "drizzled/field/timestamp.h"
 
36
#include "drizzled/memory/multi_malloc.h"
 
37
#include "drizzled/plugin/daemon.h"
38
38
 
39
39
#include <boost/algorithm/string.hpp>
40
 
#include <boost/scoped_ptr.hpp>
41
40
 
42
41
#include <string>
43
42
#include <sstream>
44
43
#include <map>
45
44
#include <algorithm>
46
 
#include <memory>
47
45
#include <boost/program_options.hpp>
48
46
#include <drizzled/module/option_map.h>
49
47
 
54
52
 
55
53
static const string engine_name("MyISAM");
56
54
 
57
 
boost::mutex THR_LOCK_myisam;
 
55
pthread_mutex_t THR_LOCK_myisam= PTHREAD_MUTEX_INITIALIZER;
58
56
 
59
57
static uint32_t myisam_key_cache_block_size= KEY_CACHE_BLOCK_SIZE;
60
58
static uint32_t myisam_key_cache_size;
61
59
static uint32_t myisam_key_cache_division_limit;
62
60
static uint32_t myisam_key_cache_age_threshold;
63
61
static uint64_t max_sort_file_size;
64
 
typedef constrained_check<size_t, SIZE_MAX, 1024, 1024> sort_buffer_constraint;
65
 
static sort_buffer_constraint sort_buffer_size;
 
62
static uint64_t sort_buffer_size;
66
63
 
67
64
void st_mi_isam_share::setKeyCache()
68
65
{
100
97
                          HTON_AUTO_PART_KEY |
101
98
                          HTON_SKIP_STORE_LOCK)
102
99
  {
 
100
    pthread_mutex_init(&THR_LOCK_myisam,MY_MUTEX_INIT_FAST);
103
101
  }
104
102
 
105
103
  virtual ~MyisamEngine()
106
104
  { 
 
105
    pthread_mutex_destroy(&THR_LOCK_myisam);
 
106
 
107
107
    mi_panic(HA_PANIC_CLOSE);
108
108
  }
109
109
 
110
 
  virtual Cursor *create(Table &table)
 
110
  virtual Cursor *create(TableShare &table)
111
111
  {
112
112
    return new ha_myisam(*this, table);
113
113
  }
118
118
 
119
119
  int doCreateTable(Session&,
120
120
                    Table& table_arg,
121
 
                    const identifier::Table &identifier,
 
121
                    const TableIdentifier &identifier,
122
122
                    message::Table&);
123
123
 
124
 
  int doRenameTable(Session&, const identifier::Table &from, const identifier::Table &to);
 
124
  int doRenameTable(Session&, const TableIdentifier &from, const TableIdentifier &to);
125
125
 
126
 
  int doDropTable(Session&, const identifier::Table &identifier);
 
126
  int doDropTable(Session&, const TableIdentifier &identifier);
127
127
 
128
128
  int doGetTableDefinition(Session& session,
129
 
                           const identifier::Table &identifier,
 
129
                           const TableIdentifier &identifier,
130
130
                           message::Table &table_message);
131
131
 
 
132
  /* Temp only engine, so do not return values. */
 
133
  void doGetTableNames(CachedDirectory &, const SchemaIdentifier &, set<string>&) { };
 
134
 
132
135
  uint32_t max_supported_keys()          const { return MI_MAX_KEY; }
133
136
  uint32_t max_supported_key_length()    const { return MI_MAX_KEY_LENGTH; }
134
137
  uint32_t max_supported_key_part_length() const { return MI_MAX_KEY_LENGTH; }
141
144
            HA_READ_ORDER |
142
145
            HA_KEYREAD_ONLY);
143
146
  }
144
 
  bool doDoesTableExist(Session& session, const identifier::Table &identifier);
 
147
  bool doDoesTableExist(Session& session, const TableIdentifier &identifier);
145
148
 
146
149
  void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
147
 
                             const drizzled::identifier::Schema &schema_identifier,
148
 
                             drizzled::identifier::Table::vector &set_of_identifiers);
 
150
                             const drizzled::SchemaIdentifier &schema_identifier,
 
151
                             drizzled::TableIdentifiers &set_of_identifiers);
149
152
  bool validateCreateTableOption(const std::string &key, const std::string &state)
150
153
  {
151
154
    (void)state;
159
162
};
160
163
 
161
164
void MyisamEngine::doGetTableIdentifiers(drizzled::CachedDirectory&,
162
 
                                         const drizzled::identifier::Schema&,
163
 
                                         drizzled::identifier::Table::vector&)
 
165
                                         const drizzled::SchemaIdentifier&,
 
166
                                         drizzled::TableIdentifiers&)
164
167
{
165
168
}
166
169
 
167
 
bool MyisamEngine::doDoesTableExist(Session &session, const identifier::Table &identifier)
 
170
bool MyisamEngine::doDoesTableExist(Session &session, const TableIdentifier &identifier)
168
171
{
169
 
  return session.getMessageCache().doesTableMessageExist(identifier);
 
172
  return session.doesTableMessageExist(identifier);
170
173
}
171
174
 
172
175
int MyisamEngine::doGetTableDefinition(Session &session,
173
 
                                       const identifier::Table &identifier,
 
176
                                       const TableIdentifier &identifier,
174
177
                                       message::Table &table_message)
175
178
{
176
 
  if (session.getMessageCache().getTableMessage(identifier, table_message))
 
179
  if (session.getTableMessage(identifier, table_message))
177
180
    return EEXIST;
178
181
  return ENOENT;
179
182
}
286
289
        keydef[i].seg[j].flag|= HA_BLOB_PART;
287
290
        /* save number of bytes used to pack length */
288
291
        keydef[i].seg[j].bit_start= (uint) (field->pack_length() -
289
 
                                            share->sizeBlobPtr());
 
292
                                            share->blob_ptr_size);
290
293
      }
291
294
    }
292
295
    keyseg+= pos->key_parts;
296
299
  record= table_arg->getInsertRecord();
297
300
  recpos= 0;
298
301
  recinfo_pos= recinfo;
299
 
 
300
 
  while (recpos < (uint) share->sizeStoredRecord())
 
302
  while (recpos < (uint) share->stored_rec_length)
301
303
  {
302
304
    Field **field, *found= 0;
303
305
    minpos= share->getRecordLength();
311
313
        /* skip null fields */
312
314
        if (!(temp_length= (*field)->pack_length_in_rec()))
313
315
          continue; /* Skip null-fields */
314
 
 
315
316
        if (! found || fieldpos < minpos ||
316
317
            (fieldpos == minpos && temp_length < length))
317
318
        {
482
483
volatile int *killed_ptr(MI_CHECK *param)
483
484
{
484
485
  /* In theory Unsafe conversion, but should be ok for now */
485
 
  return (int*) (((Session *)(param->session))->getKilledPtr());
 
486
  return (int*) &(((Session *)(param->session))->killed);
486
487
}
487
488
 
488
489
void mi_check_print_error(MI_CHECK *param, const char *fmt,...)
533
534
{
534
535
  Session *cur_session;
535
536
  if ((cur_session= file->in_use))
536
 
  {
537
 
    errmsg_printf(error::ERROR, _("Got an error from thread_id=%"PRIu64", %s:%d"),
 
537
    errmsg_printf(ERRMSG_LVL_ERROR, _("Got an error from thread_id=%"PRIu64", %s:%d"),
538
538
                    cur_session->thread_id,
539
539
                    sfile, sline);
540
 
  }
541
540
  else
542
 
  {
543
 
    errmsg_printf(error::ERROR, _("Got an error from unknown thread, %s:%d"), sfile, sline);
544
 
  }
545
 
 
 
541
    errmsg_printf(ERRMSG_LVL_ERROR, _("Got an error from unknown thread, %s:%d"), sfile, sline);
546
542
  if (message)
547
 
    errmsg_printf(error::ERROR, "%s", message);
548
 
 
 
543
    errmsg_printf(ERRMSG_LVL_ERROR, "%s", message);
549
544
  list<Session *>::iterator it= file->s->in_use->begin();
550
545
  while (it != file->s->in_use->end())
551
546
  {
552
 
    errmsg_printf(error::ERROR, "%s", _("Unknown thread accessing table"));
 
547
    errmsg_printf(ERRMSG_LVL_ERROR, "%s", _("Unknown thread accessing table"));
553
548
    ++it;
554
549
  }
555
550
}
556
551
 
557
552
ha_myisam::ha_myisam(plugin::StorageEngine &engine_arg,
558
 
                     Table &table_arg)
 
553
                     TableShare &table_arg)
559
554
  : Cursor(engine_arg, table_arg),
560
555
  file(0),
561
556
  can_enable_indexes(true),
576
571
}
577
572
 
578
573
/* Name is here without an extension */
579
 
int ha_myisam::doOpen(const drizzled::identifier::Table &identifier, int mode, uint32_t test_if_locked)
 
574
int ha_myisam::open(const char *name, int mode, uint32_t test_if_locked)
580
575
{
581
576
  MI_KEYDEF *keyinfo;
582
577
  MI_COLUMNDEF *recinfo= 0;
598
593
    open of a table that is in use by other threads already (if the
599
594
    MyISAM share exists already).
600
595
  */
601
 
  if (!(file= mi_open(identifier, mode, test_if_locked)))
 
596
  if (!(file=mi_open(name, mode, test_if_locked)))
602
597
    return (errno ? errno : -1);
603
598
 
604
 
  if (!getTable()->getShare()->getType()) /* No need to perform a check for tmp table */
 
599
  if (!table->getShare()->getType()) /* No need to perform a check for tmp table */
605
600
  {
606
 
    if ((errno= table2myisam(getTable(), &keyinfo, &recinfo, &recs)))
 
601
    if ((errno= table2myisam(table, &keyinfo, &recinfo, &recs)))
607
602
    {
608
603
      goto err;
609
604
    }
610
 
    if (check_definition(keyinfo, recinfo, getTable()->getShare()->sizeKeys(), recs,
 
605
    if (check_definition(keyinfo, recinfo, table->getShare()->sizeKeys(), recs,
611
606
                         file->s->keyinfo, file->s->rec,
612
607
                         file->s->base.keys, file->s->base.fields, true))
613
608
    {
623
618
  info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST);
624
619
  if (!(test_if_locked & HA_OPEN_WAIT_IF_LOCKED))
625
620
    mi_extra(file, HA_EXTRA_WAIT_LOCK, 0);
626
 
  if (!getTable()->getShare()->db_record_offset)
 
621
  if (!table->getShare()->db_record_offset)
627
622
    is_ordered= false;
628
623
 
629
624
 
630
625
  keys_with_parts.reset();
631
 
  for (i= 0; i < getTable()->getShare()->sizeKeys(); i++)
 
626
  for (i= 0; i < table->getShare()->sizeKeys(); i++)
632
627
  {
633
 
    getTable()->key_info[i].block_size= file->s->keyinfo[i].block_length;
 
628
    table->key_info[i].block_size= file->s->keyinfo[i].block_length;
634
629
 
635
 
    KeyPartInfo *kp= getTable()->key_info[i].key_part;
636
 
    KeyPartInfo *kp_end= kp + getTable()->key_info[i].key_parts;
 
630
    KeyPartInfo *kp= table->key_info[i].key_part;
 
631
    KeyPartInfo *kp_end= kp + table->key_info[i].key_parts;
637
632
    for (; kp != kp_end; kp++)
638
633
    {
639
634
      if (!kp->field->part_of_key.test(i))
670
665
    If we have an auto_increment column and we are writing a changed row
671
666
    or a new row, then update the auto_increment value in the record.
672
667
  */
673
 
  if (getTable()->next_number_field && buf == getTable()->getInsertRecord())
 
668
  if (table->next_number_field && buf == table->getInsertRecord())
674
669
  {
675
670
    int error;
676
671
    if ((error= update_auto_increment()))
700
695
  */
701
696
  if (file->dfile == -1)
702
697
  {
703
 
    errmsg_printf(error::INFO, "Retrying repair of: '%s' failed. "
704
 
                  "Please try REPAIR EXTENDED or myisamchk",
705
 
                  getTable()->getShare()->getPath());
 
698
    errmsg_printf(ERRMSG_LVL_INFO, "Retrying repair of: '%s' failed. "
 
699
                          "Please try REPAIR EXTENDED or myisamchk",
 
700
                          table->getShare()->getPath());
706
701
    return(HA_ADMIN_FAILED);
707
702
  }
708
703
 
709
 
  param.db_name=    getTable()->getShare()->getSchemaName();
710
 
  param.table_name= getTable()->getAlias();
 
704
  param.db_name=    table->getShare()->getSchemaName();
 
705
  param.table_name= table->getAlias();
711
706
  param.tmpfile_createflag = O_RDWR | O_TRUNC;
712
707
  param.using_global_keycache = 1;
713
708
  param.session= session;
714
709
  param.out_flag= 0;
715
 
  param.sort_buffer_length= static_cast<size_t>(sort_buffer_size);
 
710
  param.sort_buffer_length= (size_t)sort_buffer_size;
716
711
  strcpy(fixed_name,file->filename);
717
712
 
718
713
  // Don't lock tables if we have used LOCK Table
719
 
  if (mi_lock_database(file, getTable()->getShare()->getType() ? F_EXTRA_LCK : F_WRLCK))
 
714
  if (mi_lock_database(file, table->getShare()->getType() ? F_EXTRA_LCK : F_WRLCK))
720
715
  {
721
716
    mi_check_print_error(&param,ER(ER_CANT_LOCK),errno);
722
717
    return(HA_ADMIN_FAILED);
913
908
  }
914
909
  else if (mode == HA_KEY_SWITCH_NONUNIQ_SAVE)
915
910
  {
916
 
    Session *session= getTable()->in_use;
917
 
    boost::scoped_ptr<MI_CHECK> param_ap(new MI_CHECK);
918
 
    MI_CHECK &param= *param_ap.get();
 
911
    Session *session= table->in_use;
 
912
    MI_CHECK param;
919
913
    const char *save_proc_info= session->get_proc_info();
920
914
    session->set_proc_info("Creating index");
921
915
    myisamchk_init(&param);
923
917
    param.testflag= (T_SILENT | T_REP_BY_SORT | T_QUICK |
924
918
                     T_CREATE_MISSING_KEYS);
925
919
    param.myf_rw&= ~MY_WAIT_IF_FULL;
926
 
    param.sort_buffer_length=  static_cast<size_t>(sort_buffer_size);
 
920
    param.sort_buffer_length=  (size_t)sort_buffer_size;
927
921
    param.stats_method= MI_STATS_METHOD_NULLS_NOT_EQUAL;
928
922
    if ((error= (repair(session,param,0) != HA_ADMIN_OK)) && param.retry_repair)
929
923
    {
930
 
      errmsg_printf(error::WARN, "Warning: Enabling keys got errno %d on %s.%s, retrying",
 
924
      errmsg_printf(ERRMSG_LVL_WARN, "Warning: Enabling keys got errno %d on %s.%s, retrying",
931
925
                        errno, param.db_name, param.table_name);
932
926
      /* Repairing by sort failed. Now try standard repair method. */
933
927
      param.testflag&= ~(T_REP_BY_SORT | T_QUICK);
937
931
        might have been set by the first repair. They can still be seen
938
932
        with SHOW WARNINGS then.
939
933
      */
940
 
      if (not error)
 
934
      if (! error)
941
935
        session->clear_error();
942
936
    }
943
937
    info(HA_STATUS_CONST);
990
984
 
991
985
void ha_myisam::start_bulk_insert(ha_rows rows)
992
986
{
993
 
  Session *session= getTable()->in_use;
 
987
  Session *session= table->in_use;
994
988
  ulong size= session->variables.read_buff_size;
995
989
 
996
990
  /* don't enable row cache if too few rows */
1075
1069
  assert(inited==INDEX);
1076
1070
  ha_statistic_increment(&system_status_var::ha_read_key_count);
1077
1071
  int error=mi_rkey(file, buf, active_index, key, keypart_map, find_flag);
1078
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
1072
  table->status=error ? STATUS_NOT_FOUND: 0;
1079
1073
  return error;
1080
1074
}
1081
1075
 
1085
1079
{
1086
1080
  ha_statistic_increment(&system_status_var::ha_read_key_count);
1087
1081
  int error=mi_rkey(file, buf, index, key, keypart_map, find_flag);
1088
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
1082
  table->status=error ? STATUS_NOT_FOUND: 0;
1089
1083
  return error;
1090
1084
}
1091
1085
 
1096
1090
  ha_statistic_increment(&system_status_var::ha_read_key_count);
1097
1091
  int error=mi_rkey(file, buf, active_index, key, keypart_map,
1098
1092
                    HA_READ_PREFIX_LAST);
1099
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
1093
  table->status=error ? STATUS_NOT_FOUND: 0;
1100
1094
  return(error);
1101
1095
}
1102
1096
 
1105
1099
  assert(inited==INDEX);
1106
1100
  ha_statistic_increment(&system_status_var::ha_read_next_count);
1107
1101
  int error=mi_rnext(file,buf,active_index);
1108
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
1102
  table->status=error ? STATUS_NOT_FOUND: 0;
1109
1103
  return error;
1110
1104
}
1111
1105
 
1114
1108
  assert(inited==INDEX);
1115
1109
  ha_statistic_increment(&system_status_var::ha_read_prev_count);
1116
1110
  int error=mi_rprev(file,buf, active_index);
1117
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
1111
  table->status=error ? STATUS_NOT_FOUND: 0;
1118
1112
  return error;
1119
1113
}
1120
1114
 
1123
1117
  assert(inited==INDEX);
1124
1118
  ha_statistic_increment(&system_status_var::ha_read_first_count);
1125
1119
  int error=mi_rfirst(file, buf, active_index);
1126
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
1120
  table->status=error ? STATUS_NOT_FOUND: 0;
1127
1121
  return error;
1128
1122
}
1129
1123
 
1132
1126
  assert(inited==INDEX);
1133
1127
  ha_statistic_increment(&system_status_var::ha_read_last_count);
1134
1128
  int error=mi_rlast(file, buf, active_index);
1135
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
1129
  table->status=error ? STATUS_NOT_FOUND: 0;
1136
1130
  return error;
1137
1131
}
1138
1132
 
1147
1141
  {
1148
1142
    error= mi_rnext_same(file,buf);
1149
1143
  } while (error == HA_ERR_RECORD_DELETED);
1150
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
1144
  table->status=error ? STATUS_NOT_FOUND: 0;
1151
1145
  return error;
1152
1146
}
1153
1147
 
1188
1182
{
1189
1183
  ha_statistic_increment(&system_status_var::ha_read_rnd_next_count);
1190
1184
  int error=mi_scan(file, buf);
1191
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
1185
  table->status=error ? STATUS_NOT_FOUND: 0;
1192
1186
  return error;
1193
1187
}
1194
1188
 
1196
1190
{
1197
1191
  ha_statistic_increment(&system_status_var::ha_read_rnd_count);
1198
1192
  int error=mi_rrnd(file, buf, internal::my_get_ptr(pos,ref_length));
1199
 
  getTable()->status=error ? STATUS_NOT_FOUND: 0;
 
1193
  table->status=error ? STATUS_NOT_FOUND: 0;
1200
1194
  return error;
1201
1195
}
1202
1196
 
1225
1219
  }
1226
1220
  if (flag & HA_STATUS_CONST)
1227
1221
  {
1228
 
    TableShare *share= getTable()->getMutableShare();
 
1222
    TableShare *share= table->getMutableShare();
1229
1223
    stats.max_data_file_length=  misam_info.max_data_file_length;
1230
1224
    stats.max_index_file_length= misam_info.max_index_file_length;
1231
1225
    stats.create_time= misam_info.create_time;
1282
1276
    share->keys_for_keyread&= share->keys_in_use;
1283
1277
    share->db_record_offset= misam_info.record_offset;
1284
1278
    if (share->key_parts)
1285
 
      memcpy(getTable()->key_info[0].rec_per_key,
 
1279
      memcpy(table->key_info[0].rec_per_key,
1286
1280
             misam_info.rec_per_key,
1287
 
             sizeof(getTable()->key_info[0].rec_per_key)*share->key_parts);
 
1281
             sizeof(table->key_info[0].rec_per_key)*share->key_parts);
1288
1282
    assert(share->getType() != message::Table::STANDARD);
1289
1283
 
1290
1284
   /*
1338
1332
}
1339
1333
 
1340
1334
int MyisamEngine::doDropTable(Session &session,
1341
 
                              const identifier::Table &identifier)
 
1335
                              const TableIdentifier &identifier)
1342
1336
{
1343
 
  session.getMessageCache().removeTableMessage(identifier);
 
1337
  session.removeTableMessage(identifier);
1344
1338
 
1345
1339
  return mi_delete_table(identifier.getPath().c_str());
1346
1340
}
1349
1343
int ha_myisam::external_lock(Session *session, int lock_type)
1350
1344
{
1351
1345
  file->in_use= session;
1352
 
  return mi_lock_database(file, !getTable()->getShare()->getType() ?
 
1346
  return mi_lock_database(file, !table->getShare()->getType() ?
1353
1347
                          lock_type : ((lock_type == F_UNLCK) ?
1354
1348
                                       F_UNLCK : F_EXTRA_LCK));
1355
1349
}
1356
1350
 
1357
1351
int MyisamEngine::doCreateTable(Session &session,
1358
1352
                                Table& table_arg,
1359
 
                                const identifier::Table &identifier,
 
1353
                                const TableIdentifier &identifier,
1360
1354
                                message::Table& create_proto)
1361
1355
{
1362
1356
  int error;
1396
1390
                   &create_info, create_flags);
1397
1391
  free((unsigned char*) recinfo);
1398
1392
 
1399
 
  session.getMessageCache().storeTableMessage(identifier, create_proto);
 
1393
  session.storeTableMessage(identifier, create_proto);
1400
1394
 
1401
1395
  return error;
1402
1396
}
1403
1397
 
1404
1398
 
1405
 
int MyisamEngine::doRenameTable(Session &session, const identifier::Table &from, const identifier::Table &to)
 
1399
int MyisamEngine::doRenameTable(Session &session, const TableIdentifier &from, const TableIdentifier &to)
1406
1400
{
1407
 
  session.getMessageCache().renameTableMessage(from, to);
 
1401
  session.renameTableMessage(from, to);
1408
1402
 
1409
1403
  return mi_rename(from.getPath().c_str(), to.getPath().c_str());
1410
1404
}
1420
1414
  int error;
1421
1415
  unsigned char key[MI_MAX_KEY_LENGTH];
1422
1416
 
1423
 
  if (!getTable()->getShare()->next_number_key_offset)
 
1417
  if (!table->getShare()->next_number_key_offset)
1424
1418
  {                                             // Autoincrement at key-start
1425
1419
    ha_myisam::info(HA_STATUS_AUTO);
1426
1420
    *first_value= stats.auto_increment_value;
1430
1424
  }
1431
1425
 
1432
1426
  /* it's safe to call the following if bulk_insert isn't on */
1433
 
  mi_flush_bulk_insert(file, getTable()->getShare()->next_number_index);
 
1427
  mi_flush_bulk_insert(file, table->getShare()->next_number_index);
1434
1428
 
1435
1429
  (void) extra(HA_EXTRA_KEYREAD);
1436
 
  key_copy(key, getTable()->getInsertRecord(),
1437
 
           &getTable()->key_info[getTable()->getShare()->next_number_index],
1438
 
           getTable()->getShare()->next_number_key_offset);
1439
 
  error= mi_rkey(file, getTable()->getUpdateRecord(), (int) getTable()->getShare()->next_number_index,
1440
 
                 key, make_prev_keypart_map(getTable()->getShare()->next_number_keypart),
 
1430
  key_copy(key, table->getInsertRecord(),
 
1431
           &table->key_info[table->getShare()->next_number_index],
 
1432
           table->getShare()->next_number_key_offset);
 
1433
  error= mi_rkey(file, table->getUpdateRecord(), (int) table->getShare()->next_number_index,
 
1434
                 key, make_prev_keypart_map(table->getShare()->next_number_keypart),
1441
1435
                 HA_READ_PREFIX_LAST);
1442
1436
  if (error)
1443
1437
    nr= 1;
1444
1438
  else
1445
1439
  {
1446
1440
    /* Get data from getUpdateRecord() */
1447
 
    nr= ((uint64_t) getTable()->next_number_field->
1448
 
         val_int_offset(getTable()->getShare()->rec_buff_length)+1);
 
1441
    nr= ((uint64_t) table->next_number_field->
 
1442
         val_int_offset(table->getShare()->rec_buff_length)+1);
1449
1443
  }
1450
1444
  extra(HA_EXTRA_NO_KEYREAD);
1451
1445
  *first_value= nr;
1496
1490
  return (uint)file->state->checksum;
1497
1491
}
1498
1492
 
 
1493
static MyisamEngine *engine= NULL;
 
1494
 
1499
1495
static int myisam_init(module::Context &context)
1500
1496
1501
 
  context.add(new MyisamEngine(engine_name));
1502
 
  context.registerVariable(new sys_var_constrained_value<size_t>("sort-buffer-size",
1503
 
                                                                 sort_buffer_size));
1504
 
  context.registerVariable(new sys_var_uint64_t_ptr("max_sort_file_size",
1505
 
                                                    &max_sort_file_size,
1506
 
                                                    context.getOptions()["max-sort-file-size"].as<uint64_t>()));
 
1497
  const module::option_map &vm= context.getOptions();
 
1498
 
 
1499
  if (vm.count("max-sort-file-size"))
 
1500
  {
 
1501
    if (max_sort_file_size > UINT64_MAX)
 
1502
    {
 
1503
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for max-sort-file-size\n"));
 
1504
      exit(-1);
 
1505
    }
 
1506
  }
 
1507
 
 
1508
  if (vm.count("sort-buffer-size"))
 
1509
  {
 
1510
    if (sort_buffer_size < 1024 || sort_buffer_size > SIZE_MAX)
 
1511
    {
 
1512
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for sort-buffer-size\n"));
 
1513
      exit(-1);
 
1514
    }
 
1515
  }
 
1516
 
 
1517
  engine= new MyisamEngine(engine_name);
 
1518
  context.add(engine);
1507
1519
 
1508
1520
  return 0;
1509
1521
}
1510
1522
 
1511
1523
 
 
1524
static DRIZZLE_SYSVAR_ULONGLONG(max_sort_file_size, max_sort_file_size,
 
1525
                                PLUGIN_VAR_RQCMDARG,
 
1526
                                N_("Don't use the fast sort index method to created index if the temporary file would get bigger than this."),
 
1527
                                NULL, NULL, INT32_MAX, 0, UINT64_MAX, 0);
 
1528
 
 
1529
static DRIZZLE_SYSVAR_ULONGLONG(sort_buffer_size, sort_buffer_size,
 
1530
                                PLUGIN_VAR_RQCMDARG,
 
1531
                                N_("The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE."),
 
1532
                                NULL, NULL, 8192*1024, 1024, SIZE_MAX, 0);
 
1533
 
 
1534
extern uint32_t data_pointer_size;
 
1535
static DRIZZLE_SYSVAR_UINT(data_pointer_size, data_pointer_size,
 
1536
                            PLUGIN_VAR_RQCMDARG,
 
1537
                            N_("Default pointer size to be used for MyISAM tables."),
 
1538
                            NULL, NULL, 6, 2, 7, 0);
 
1539
 
1512
1540
static void init_options(drizzled::module::option_context &context)
1513
1541
{
1514
1542
  context("max-sort-file-size",
1515
1543
          po::value<uint64_t>(&max_sort_file_size)->default_value(INT32_MAX),
1516
 
          _("Don't use the fast sort index method to created index if the temporary file would get bigger than this."));
 
1544
          N_("Don't use the fast sort index method to created index if the temporary file would get bigger than this."));
1517
1545
  context("sort-buffer-size",
1518
 
          po::value<sort_buffer_constraint>(&sort_buffer_size)->default_value(8192*1024),
1519
 
          _("The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE."));
 
1546
          po::value<uint64_t>(&sort_buffer_size)->default_value(8192*1024),
 
1547
          N_("The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE."));
 
1548
  context("data-pointer-size",
 
1549
          po::value<uint32_t>(&data_pointer_size)->default_value(6),
 
1550
          N_("Default pointer size to be used for MyISAM tables."));
1520
1551
}
1521
1552
 
 
1553
static drizzle_sys_var* sys_variables[]= {
 
1554
  DRIZZLE_SYSVAR(max_sort_file_size),
 
1555
  DRIZZLE_SYSVAR(sort_buffer_size),
 
1556
  DRIZZLE_SYSVAR(data_pointer_size),
 
1557
  NULL
 
1558
};
 
1559
 
1522
1560
 
1523
1561
DRIZZLE_DECLARE_PLUGIN
1524
1562
{
1529
1567
  "Default engine as of MySQL 3.23 with great performance",
1530
1568
  PLUGIN_LICENSE_GPL,
1531
1569
  myisam_init, /* Plugin Init */
1532
 
  NULL,           /* depends */
 
1570
  sys_variables,           /* system variables */
1533
1571
  init_options                        /* config options                  */
1534
1572
}
1535
1573
DRIZZLE_DECLARE_PLUGIN_END;