~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/ha_myisam.cc

  • Committer: Brian Aker
  • Date: 2010-10-27 20:29:24 UTC
  • mfrom: (1883 staging)
  • mto: This revision was merged to the branch mainline in revision 1885.
  • Revision ID: brian@tangent.org-20101027202924-7o9s4nhvqgj9oskq
Merge with trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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);
105
104
  }
106
105
 
107
 
  virtual Cursor *create(TableShare &table)
 
106
  virtual Cursor *create(Table &table)
108
107
  {
109
108
    return new ha_myisam(*this, table);
110
109
  }
544
543
}
545
544
 
546
545
ha_myisam::ha_myisam(plugin::StorageEngine &engine_arg,
547
 
                     TableShare &table_arg)
 
546
                     Table &table_arg)
548
547
  : Cursor(engine_arg, table_arg),
549
548
  file(0),
550
549
  can_enable_indexes(true),
590
589
  if (!(file= mi_open(identifier, mode, test_if_locked)))
591
590
    return (errno ? errno : -1);
592
591
 
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 */
594
593
  {
595
 
    if ((errno= table2myisam(table, &keyinfo, &recinfo, &recs)))
 
594
    if ((errno= table2myisam(getTable(), &keyinfo, &recinfo, &recs)))
596
595
    {
597
596
      goto err;
598
597
    }
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))
602
601
    {
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;
617
616
 
618
617
 
619
618
  keys_with_parts.reset();
620
 
  for (i= 0; i < table->getShare()->sizeKeys(); i++)
 
619
  for (i= 0; i < getTable()->getShare()->sizeKeys(); i++)
621
620
  {
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;
623
622
 
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++)
627
626
    {
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.
661
660
  */
662
 
  if (table->next_number_field && buf == table->getInsertRecord())
 
661
  if (getTable()->next_number_field && buf == getTable()->getInsertRecord())
663
662
  {
664
663
    int error;
665
664
    if ((error= update_auto_increment()))
691
690
  {
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);
696
695
  }
697
696
 
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);
706
705
 
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))
709
708
  {
710
709
    mi_check_print_error(&param,ER(ER_CANT_LOCK),errno);
711
710
    return(HA_ADMIN_FAILED);
902
901
  }
903
902
  else if (mode == HA_KEY_SWITCH_NONUNIQ_SAVE)
904
903
  {
905
 
    Session *session= table->in_use;
 
904
    Session *session= getTable()->in_use;
906
905
    MI_CHECK param;
907
906
    const char *save_proc_info= session->get_proc_info();
908
907
    session->set_proc_info("Creating index");
978
977
 
979
978
void ha_myisam::start_bulk_insert(ha_rows rows)
980
979
{
981
 
  Session *session= table->in_use;
 
980
  Session *session= getTable()->in_use;
982
981
  ulong size= session->variables.read_buff_size;
983
982
 
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;
1067
1066
  return error;
1068
1067
}
1069
1068
 
1073
1072
{
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;
1077
1076
  return error;
1078
1077
}
1079
1078
 
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;
1088
1087
  return(error);
1089
1088
}
1090
1089
 
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;
1097
1096
  return error;
1098
1097
}
1099
1098
 
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;
1106
1105
  return error;
1107
1106
}
1108
1107
 
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;
1115
1114
  return error;
1116
1115
}
1117
1116
 
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;
1124
1123
  return error;
1125
1124
}
1126
1125
 
1135
1134
  {
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;
1139
1138
  return error;
1140
1139
}
1141
1140
 
1176
1175
{
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;
1180
1179
  return error;
1181
1180
}
1182
1181
 
1184
1183
{
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;
1188
1187
  return error;
1189
1188
}
1190
1189
 
1213
1212
  }
1214
1213
  if (flag & HA_STATUS_CONST)
1215
1214
  {
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);
1277
1276
 
1278
1277
   /*
1337
1336
int ha_myisam::external_lock(Session *session, int lock_type)
1338
1337
{
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));
1343
1342
}
1408
1407
  int error;
1409
1408
  unsigned char key[MI_MAX_KEY_LENGTH];
1410
1409
 
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;
1418
1417
  }
1419
1418
 
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);
1422
1421
 
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);
1430
1429
  if (error)
1431
1430
    nr= 1;
1432
1431
  else
1433
1432
  {
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);
1437
1436
  }
1438
1437
  extra(HA_EXTRA_NO_KEYREAD);
1439
1438
  *first_value= nr;