ha_myisam.cc 32.1 KB
Newer Older
unknown's avatar
unknown committed
1
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
2

unknown's avatar
unknown committed
3 4 5 6
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
7

unknown's avatar
unknown committed
8 9 10 11
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
12

unknown's avatar
unknown committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */


#ifdef __GNUC__
#pragma implementation				// gcc: Class implementation
#endif

#include "mysql_priv.h"
#include <m_ctype.h>
#include <myisampack.h>
#include "ha_myisam.h"
#include <stdarg.h>
#ifndef MASTER
#include "../srclib/myisam/myisamdef.h"
#else
#include "../myisam/myisamdef.h"
#endif

33
ulong myisam_sort_buffer_size;
34
ulong myisam_recover_options= HA_RECOVER_NONE;
35

36
/* bits in myisam_recover_options */
37
const char *myisam_recover_names[] =
38
{ "DEFAULT", "BACKUP", "FORCE", "QUICK"};
39 40 41
TYPELIB myisam_recover_typelib= {array_elements(myisam_recover_names),"",
				 myisam_recover_names};

42

unknown's avatar
unknown committed
43 44 45 46 47 48 49 50 51 52
/*****************************************************************************
** MyISAM tables
*****************************************************************************/

// collect errors printed by mi_check routines
static void mi_check_print_msg(MI_CHECK *param,	const char* msg_type,
			       const char *fmt, va_list args)
{
  THD* thd = (THD*)param->thd;
  String* packet = &thd->packet;
53
  uint length;
unknown's avatar
unknown committed
54
  char msgbuf[MI_MAX_MSG_BUF];
55 56
  char name[NAME_LEN*2+2];
  packet->length(0);
unknown's avatar
unknown committed
57

58
  msgbuf[0] = 0;		// healthy paranoia ?
unknown's avatar
unknown committed
59 60 61
  my_vsnprintf(msgbuf, sizeof(msgbuf), fmt, args);
  msgbuf[sizeof(msgbuf) - 1] = 0; // healthy paranoia

unknown's avatar
unknown committed
62 63
  DBUG_PRINT(msg_type,("message: %s",msgbuf));

unknown's avatar
unknown committed
64 65 66 67 68
  if (thd->net.vio == 0)
  {
    sql_print_error(msgbuf);
    return;
  }
69 70 71 72 73 74
  if (param->testflag & (T_CREATE_MISSING_KEYS | T_SAFE_REPAIR |
			 T_AUTO_REPAIR))
  {
    my_message(ER_NOT_KEYFILE,msgbuf,MYF(MY_WME));
    return;
  }
75 76 77
  length=(uint) (strxmov(name, param->db_name,".",param->table_name,NullS) -
		 name);
  net_store_data(packet, name, length);
unknown's avatar
unknown committed
78 79
  net_store_data(packet, param->op_name);
  net_store_data(packet, msg_type);
80

unknown's avatar
unknown committed
81 82 83 84 85
  net_store_data(packet, msgbuf);
  if (my_net_write(&thd->net, (char*)thd->packet.ptr(), thd->packet.length()))
    fprintf(stderr,
            "Failed on my_net_write, writing to stderr instead: %s\n",
            msgbuf);
86
  return;
unknown's avatar
unknown committed
87 88 89 90 91 92 93
}

extern "C" {

void mi_check_print_error(MI_CHECK *param, const char *fmt,...)
{
  param->error_printed|=1;
94
  param->out_flag|= O_DATA_LOST;
unknown's avatar
unknown committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
  va_list args;
  va_start(args, fmt);
  mi_check_print_msg(param, "error", fmt, args);
  va_end(args);
}

void mi_check_print_info(MI_CHECK *param, const char *fmt,...)
{
  va_list args;
  va_start(args, fmt);
  mi_check_print_msg(param, "info", fmt, args);
  va_end(args);
}

void mi_check_print_warning(MI_CHECK *param, const char *fmt,...)
{
  param->warning_printed=1;
112
  param->out_flag|= O_DATA_LOST;
unknown's avatar
unknown committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
  va_list args;
  va_start(args, fmt);
  mi_check_print_msg(param, "warning", fmt, args);
  va_end(args);
}

}

const char **ha_myisam::bas_ext() const
{ static const char *ext[]= { ".MYD",".MYI", NullS }; return ext; }


int ha_myisam::net_read_dump(NET* net)
{
  int data_fd = file->dfile;
  int error = 0;

  my_seek(data_fd, 0L, MY_SEEK_SET, MYF(MY_WME));
  for(;;)
  {
    uint packet_len = my_net_read(net);
    if (!packet_len)
      break ; // end of file
    if (packet_len == packet_error)
    {
      sql_print_error("ha_myisam::net_read_dump - read error ");
      error= -1;
      goto err;
    }
    if (my_write(data_fd, (byte*)net->read_pos, packet_len,
		 MYF(MY_WME|MY_FNABP)))
    {
      error = errno;
      goto err;
    }
  }
149

unknown's avatar
unknown committed
150 151 152 153 154 155 156 157 158 159 160 161 162
err:
  return error;
}


int ha_myisam::dump(THD* thd, int fd)
{
  MYISAM_SHARE* share = file->s;
  NET* net = &thd->net;
  uint blocksize = share->blocksize;
  my_off_t bytes_to_read = share->state.state.data_file_length;
  int data_fd = file->dfile;
  byte * buf = (byte*) my_malloc(blocksize, MYF(MY_WME));
163
  if (!buf)
unknown's avatar
unknown committed
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
    return ENOMEM;

  int error = 0;
  my_seek(data_fd, 0L, MY_SEEK_SET, MYF(MY_WME));
  for(; bytes_to_read > 0;)
  {
    uint bytes = my_read(data_fd, buf, blocksize, MYF(MY_WME));
    if (bytes == MY_FILE_ERROR)
    {
      error = errno;
      goto err;
    }

    if (fd >= 0)
    {
      if (my_write(fd, buf, bytes, MYF(MY_WME | MY_FNABP)))
      {
	error = errno ? errno : EPIPE;
	goto err;
      }
    }
    else
    {
      if (my_net_write(net, (char*) buf, bytes))
      {
	error = errno ? errno : EPIPE;
	goto err;
      }
    }
    bytes_to_read -= bytes;
  }

  if (fd < 0)
  {
    my_net_write(net, "", 0);
    net_flush(net);
  }
201

unknown's avatar
unknown committed
202 203 204 205 206
err:
  my_free((gptr) buf, MYF(0));
  return error;
}

207 208
	/* Name is here without an extension */

209
int ha_myisam::open(const char *name, int mode, uint test_if_locked)
unknown's avatar
unknown committed
210
{
211
  if (!(file=mi_open(name, mode, test_if_locked)))
unknown's avatar
unknown committed
212 213
    return (my_errno ? my_errno : -1);

214
  if (test_if_locked & (HA_OPEN_IGNORE_IF_LOCKED | HA_OPEN_TMP_TABLE))
unknown's avatar
unknown committed
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
    VOID(mi_extra(file,HA_EXTRA_NO_WAIT_LOCK));
  info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST);
  if (!(test_if_locked & HA_OPEN_WAIT_IF_LOCKED))
    VOID(mi_extra(file,HA_EXTRA_WAIT_LOCK));
  if (!table->db_record_offset)
    int_option_flag|=HA_REC_NOT_IN_SEQ;
  return (0);
}

int ha_myisam::close(void)
{
  MI_INFO *tmp=file;
  file=0;
  return mi_close(tmp);
}

int ha_myisam::write_row(byte * buf)
{
  statistic_increment(ha_write_count,&LOCK_status);
  if (table->time_stamp)
    update_timestamp(buf+table->time_stamp-1);
  if (table->next_number_field && buf == table->record[0])
    update_auto_increment();
  return mi_write(file,buf);
}

int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt)
{
243
  if (!file) return HA_ADMIN_INTERNAL_ERROR;
unknown's avatar
unknown committed
244
  int error;
unknown's avatar
unknown committed
245 246
  MI_CHECK param;
  MYISAM_SHARE* share = file->s;
unknown's avatar
unknown committed
247
  const char *old_proc_info=thd->proc_info;
248

unknown's avatar
unknown committed
249
  thd->proc_info="Checking table";
unknown's avatar
unknown committed
250 251 252
  myisamchk_init(&param);
  param.thd = thd;
  param.op_name = (char*)"check";
253
  param.db_name    = table->table_cache_key;
unknown's avatar
unknown committed
254
  param.table_name = table->table_name;
255
  param.testflag = check_opt->flags | T_CHECK | T_SILENT;
256

unknown's avatar
unknown committed
257 258 259 260
  if (!(table->db_stat & HA_READ_ONLY))
    param.testflag|= T_STATISTICS;
  param.using_global_keycache = 1;

261 262
  if (!mi_is_crashed(file) &&
      (((param.testflag & T_CHECK_ONLY_CHANGED) &&
263 264
	!(share->state.changed & (STATE_CHANGED | STATE_CRASHED |
				  STATE_CRASHED_ON_REPAIR)) &&
265
	share->state.open_count == 0) ||
266
       ((param.testflag & T_FAST) && (share->state.open_count ==
267
				      (uint) (share->global_changed ? 1 : 0)))))
268
    return HA_ADMIN_ALREADY_DONE;
269

270
  error = chk_status(&param, file);		// Not fatal
unknown's avatar
unknown committed
271
  error = chk_size(&param, file);
272 273 274 275 276
  if (!error)
    error |= chk_del(&param, file, param.testflag);
  if (!error)
    error = chk_key(&param, file);
  if (!error)
unknown's avatar
unknown committed
277
  {
278
    if ((!check_opt->quick &&
279 280 281
	 ((share->options &
	   (HA_OPTION_PACK_RECORD | HA_OPTION_COMPRESS_RECORD)) ||
	  (param.testflag & (T_EXTEND | T_MEDIUM)))) ||
282
	mi_is_crashed(file))
unknown's avatar
unknown committed
283
    {
284 285
      uint old_testflag=param.testflag;
      param.testflag|=T_MEDIUM;
286 287 288 289 290
      init_io_cache(&param.read_cache, file->dfile,
		    my_default_record_cache_size, READ_CACHE,
		    share->pack.header_length, 1, MYF(MY_WME));
      error |= chk_data_link(&param, file, param.testflag & T_EXTEND);
      end_io_cache(&(param.read_cache));
291
      param.testflag=old_testflag;
unknown's avatar
unknown committed
292 293 294
    }
  }
  if (!error)
295
  {
unknown's avatar
unknown committed
296
    if ((share->state.changed & (STATE_CHANGED |
297 298
				 STATE_CRASHED_ON_REPAIR |
				 STATE_CRASHED | STATE_NOT_ANALYZED)) ||
299 300
	(param.testflag & T_STATISTICS) ||
	mi_is_crashed(file))
unknown's avatar
unknown committed
301 302 303
    {
      file->update|=HA_STATE_CHANGED | HA_STATE_ROW_CHANGED;
      pthread_mutex_lock(&share->intern_lock);
304 305
      share->state.changed&= ~(STATE_CHANGED | STATE_CRASHED |
			       STATE_CRASHED_ON_REPAIR);
unknown's avatar
unknown committed
306
      if (!(table->db_stat & HA_READ_ONLY))
307 308
	error=update_state_info(&param,file,UPDATE_TIME | UPDATE_OPEN_COUNT |
				UPDATE_STAT);
unknown's avatar
unknown committed
309
      pthread_mutex_unlock(&share->intern_lock);
310 311
      info(HA_STATUS_NO_LOCK | HA_STATUS_TIME | HA_STATUS_VARIABLE |
	   HA_STATUS_CONST);
unknown's avatar
unknown committed
312 313 314 315 316 317 318
    }
  }
  else if (!mi_is_crashed(file))
  {
    mi_mark_crashed(file);
    file->update |= HA_STATE_CHANGED | HA_STATE_ROW_CHANGED;
  }
319
  check_opt->retry_without_quick=param.retry_without_quick;
320

unknown's avatar
unknown committed
321
  thd->proc_info=old_proc_info;
322
  return error ? HA_ADMIN_CORRUPT : HA_ADMIN_OK;
unknown's avatar
unknown committed
323 324 325 326 327 328 329 330 331
}


/*
  analyze the key distribution in the table
  As the table may be only locked for read, we have to take into account that
  two threads may do an analyze at the same time!
*/

332
int ha_myisam::analyze(THD *thd, HA_CHECK_OPT* check_opt)
unknown's avatar
unknown committed
333
{
334
  int error=0;
unknown's avatar
unknown committed
335 336
  MI_CHECK param;
  MYISAM_SHARE* share = file->s;
337

unknown's avatar
unknown committed
338 339
  myisamchk_init(&param);
  param.thd = thd;
340
  param.op_name = (char*) "analyze";
341
  param.db_name    = table->table_cache_key;
unknown's avatar
unknown committed
342 343 344 345 346
  param.table_name = table->table_name;
  param.testflag=(T_FAST | T_CHECK | T_SILENT | T_STATISTICS |
		  T_DONT_CHECK_CHECKSUM);
  param.using_global_keycache = 1;

347 348 349 350 351
  if (!(share->state.changed & STATE_NOT_ANALYZED))
    return HA_ADMIN_ALREADY_DONE;

  error = chk_key(&param, file);
  if (!error)
352
  {
353 354 355
    pthread_mutex_lock(&share->intern_lock);
    error=update_state_info(&param,file,UPDATE_STAT);
    pthread_mutex_unlock(&share->intern_lock);
unknown's avatar
unknown committed
356
  }
357 358 359
  else if (!mi_is_crashed(file))
    mi_mark_crashed(file);
  return error ? HA_ADMIN_CORRUPT : HA_ADMIN_OK;
unknown's avatar
unknown committed
360 361
}

362

unknown's avatar
unknown committed
363 364 365 366 367 368
int ha_myisam::restore(THD* thd, HA_CHECK_OPT *check_opt)
{
  HA_CHECK_OPT tmp_check_opt;
  char* backup_dir = thd->lex.backup_dir;
  char src_path[FN_REFLEN], dst_path[FN_REFLEN];
  char* table_name = table->real_name;
369
  if (!fn_format(src_path, table_name, backup_dir, MI_NAME_DEXT, 4 + 64))
unknown's avatar
unknown committed
370 371 372
    return HA_ADMIN_INVALID;

  int error = 0;
373
  const char* errmsg = "";
374

375 376 377 378
  if (my_copy(src_path, fn_format(dst_path, table->path, "",
				  MI_NAME_DEXT, 4), MYF(MY_WME)))
  {
    error = HA_ADMIN_FAILED;
unknown's avatar
unknown committed
379
    errmsg = "Failed in my_copy (Error %d)";
380 381
    goto err;
  }
382

unknown's avatar
unknown committed
383 384
  tmp_check_opt.init();
  tmp_check_opt.quick = 1;
385
  tmp_check_opt.flags |= T_VERY_SILENT;
unknown's avatar
unknown committed
386
  return repair(thd, &tmp_check_opt);
387

unknown's avatar
unknown committed
388 389
 err:
  {
unknown's avatar
unknown committed
390 391 392 393
    MI_CHECK param;
    myisamchk_init(&param);
    param.thd = thd;
    param.op_name = (char*)"restore";
394
    param.db_name    = table->table_cache_key;
unknown's avatar
unknown committed
395 396 397
    param.table_name = table->table_name;
    param.testflag = 0;
    mi_check_print_error(&param,errmsg, errno );
398
    return error;
unknown's avatar
unknown committed
399 400 401
  }
}

402

unknown's avatar
unknown committed
403 404 405 406 407
int ha_myisam::backup(THD* thd, HA_CHECK_OPT *check_opt)
{
  char* backup_dir = thd->lex.backup_dir;
  char src_path[FN_REFLEN], dst_path[FN_REFLEN];
  char* table_name = table->real_name;
408 409 410
  int error = 0;
  const char* errmsg = "";
  
411
  if (!fn_format(dst_path, table_name, backup_dir, reg_ext, 4 + 64))
412
    {
unknown's avatar
unknown committed
413
      errmsg = "Failed in fn_format() for .frm file: errno = %d";
414 415 416 417
      error = HA_ADMIN_INVALID;
      goto err;
    }
  
418
  if (my_copy(fn_format(src_path, table->path,"", reg_ext, 4),
419
	     dst_path,
unknown's avatar
unknown committed
420
	     MYF(MY_WME | MY_HOLD_ORIGINAL_MODES )))
421
  {
422 423 424
    error = HA_ADMIN_FAILED;
    errmsg = "Failed copying .frm file: errno = %d";
    goto err;
425
  }
unknown's avatar
unknown committed
426

427
  if (!fn_format(dst_path, table_name, backup_dir, MI_NAME_DEXT, 4 + 64))
428
    {
unknown's avatar
unknown committed
429
      errmsg = "Failed in fn_format() for .MYD file: errno = %d";
430 431 432
      error = HA_ADMIN_INVALID;
      goto err;
    }
433

434 435 436
  if (my_copy(fn_format(src_path, table->path,"", MI_NAME_DEXT, 4),
	      dst_path,
	      MYF(MY_WME | MY_HOLD_ORIGINAL_MODES ))  )
437 438 439 440 441
    {
      errmsg = "Failed copying .MYD file: errno = %d";
      error= HA_ADMIN_FAILED;
      goto err;
    }
unknown's avatar
unknown committed
442
  return HA_ADMIN_OK;
443 444 445 446 447 448
 err:
  {
    MI_CHECK param;
    myisamchk_init(&param);
    param.thd = thd;
    param.op_name = (char*)"backup";
449
    param.db_name    = table->table_cache_key;
450 451 452 453 454
    param.table_name = table->table_name;
    param.testflag = 0;
    mi_check_print_error(&param,errmsg, errno );
    return error;
  }
unknown's avatar
unknown committed
455 456
}

unknown's avatar
unknown committed
457

458
int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt)
unknown's avatar
unknown committed
459
{
460
  int error;
unknown's avatar
unknown committed
461
  MI_CHECK param;
462
  ha_rows start_records;
463

unknown's avatar
unknown committed
464 465
  if (!file) return HA_ADMIN_INTERNAL_ERROR;

unknown's avatar
unknown committed
466 467 468
  myisamchk_init(&param);
  param.thd = thd;
  param.op_name = (char*) "repair";
unknown's avatar
unknown committed
469 470
  param.testflag = ((check_opt->flags & ~T_EXTEND) | 
		    T_SILENT | T_FORCE_CREATE |
unknown's avatar
unknown committed
471
		    (check_opt->flags & T_EXTEND ? T_REP : T_REP_BY_SORT));
472
  if (check_opt->quick)
unknown's avatar
unknown committed
473
    param.opt_rep_quick++;
474
  param.sort_buffer_length=  check_opt->sort_buffer_size;
475 476
  start_records=file->state->records;
  while ((error=repair(thd,param,0)) && param.retry_repair)
477
  {
478
    param.retry_repair=0;
479 480 481
    if (param.retry_without_quick && param.opt_rep_quick)
    {
      param.opt_rep_quick=0;
unknown's avatar
unknown committed
482
      sql_print_error("Warning: Retrying repair of: '%s' without quick",
483
		      table->path);
484 485
      continue;
    }
unknown's avatar
unknown committed
486
    param.opt_rep_quick=0;			// Safety
487 488
    if ((param.testflag & T_REP_BY_SORT))
    {
unknown's avatar
unknown committed
489
      param.testflag= (param.testflag & ~T_REP_BY_SORT) | T_REP;
unknown's avatar
unknown committed
490
      sql_print_error("Warning: Retrying repair of: '%s' with keycache",
491
		      table->path);
492 493 494 495
      continue;
    }
    break;
  }
unknown's avatar
unknown committed
496 497
  if (!error && start_records != file->state->records &&
      !(check_opt->flags & T_VERY_SILENT))
498 499
  {
    char llbuff[22],llbuff2[22];
unknown's avatar
unknown committed
500
    sql_print_error("Warning: Found %s of %s rows when repairing '%s'",
501 502 503
		    llstr(file->state->records, llbuff),
		    llstr(start_records, llbuff2),
		    table->path);
504
  }
505
  return error;
506 507 508 509 510 511 512 513 514 515 516 517
}

int ha_myisam::optimize(THD* thd, HA_CHECK_OPT *check_opt)
{
  if (!file) return HA_ADMIN_INTERNAL_ERROR;
  MI_CHECK param;

  myisamchk_init(&param);
  param.thd = thd;
  param.op_name = (char*) "optimize";
  param.testflag = (check_opt->flags | T_SILENT | T_FORCE_CREATE |
		    T_REP_BY_SORT | T_STATISTICS | T_SORT_INDEX);
518 519
  if (check_opt->quick)
    param.opt_rep_quick++;
520 521
  param.sort_buffer_length=  check_opt->sort_buffer_size;
  return repair(thd,param,1);
522 523 524
}


525
int ha_myisam::repair(THD *thd, MI_CHECK &param, bool optimize)
526
{
527
  int error=0;
unknown's avatar
unknown committed
528
  uint extra_testflag=0;
529
  bool optimize_done= !optimize, statistics_done=0;
530
  char fixed_name[FN_REFLEN];
531
  const char *old_proc_info=thd->proc_info;
532
  MYISAM_SHARE* share = file->s;
unknown's avatar
unknown committed
533
  ha_rows rows= file->state->records;
unknown's avatar
unknown committed
534
  DBUG_ENTER("ha_myisam::repair");
535

536
  param.db_name    = table->table_cache_key;
537
  param.table_name = table->table_name;
unknown's avatar
unknown committed
538 539
  param.tmpfile_createflag = O_RDWR | O_TRUNC;
  param.using_global_keycache = 1;
540
  param.thd=thd;
541
  param.tmpdir=mysql_tmpdir;
unknown's avatar
unknown committed
542
  param.out_flag=0;
unknown's avatar
unknown committed
543 544
  VOID(fn_format(fixed_name,file->filename,"",MI_NAME_IEXT,
		     4+ (param.opt_follow_links ? 16 : 0)));
545

unknown's avatar
unknown committed
546 547
  // Don't lock tables if we have used LOCK TABLE
  if (!thd->locked_tables && mi_lock_database(file,F_WRLCK))
unknown's avatar
unknown committed
548 549 550 551 552
  {
    mi_check_print_error(&param,ER(ER_CANT_LOCK),my_errno);
    DBUG_RETURN(HA_ADMIN_FAILED);
  }

553
  if (!optimize ||
554 555 556
      ((file->state->del || share->state.split != file->state->records) &&
       (!param.opt_rep_quick ||
	!(share->state.changed & STATE_NOT_OPTIMIZED_KEYS))))
557
  {
558 559 560 561
    ulonglong key_map= ((param.testflag & T_CREATE_MISSING_KEYS) ? 
			((ulonglong) 1L << share->base.keys)-1 :
			share->state.key_map);
    if (mi_test_if_sort_rep(file,file->state->records,key_map,0) &&
unknown's avatar
unknown committed
562
	(param.testflag & T_REP_BY_SORT))
563
    {
unknown's avatar
unknown committed
564 565
      uint testflag=param.testflag;
      extra_testflag=  T_STATISTICS;
566
      param.testflag|= T_STATISTICS;		// We get this for free
unknown's avatar
unknown committed
567
      thd->proc_info="Repair by sorting";
568
      statistics_done=1;
569
      error = mi_repair_by_sort(&param, file, fixed_name, param.opt_rep_quick);
unknown's avatar
unknown committed
570
      param.testflag=testflag;
571 572 573
    }
    else
    {
unknown's avatar
unknown committed
574
      thd->proc_info="Repair with keycache";
575
      param.testflag &= ~T_REP_BY_SORT;
576 577 578 579 580 581 582 583 584 585 586 587
      error=  mi_repair(&param, file, fixed_name, param.opt_rep_quick);
    }
  }
  if (!error)
  {
    if ((param.testflag & T_SORT_INDEX) &&
	(share->state.changed & STATE_NOT_SORTED_PAGES))
    {
      optimize_done=1;
      thd->proc_info="Sorting index";
      error=mi_sort_index(&param,file,fixed_name);
    }
588
    if (!statistics_done && (param.testflag & T_STATISTICS) &&
589 590 591 592 593 594 595
	(share->state.changed & STATE_NOT_ANALYZED))
    {
      optimize_done=1;
      thd->proc_info="Analyzing";
      error = chk_key(&param, file);
    }
  }
unknown's avatar
unknown committed
596
  thd->proc_info="Saving state";
unknown's avatar
unknown committed
597
  if (!error)
598
  {
599
    if ((share->state.changed & STATE_CHANGED) || mi_is_crashed(file))
unknown's avatar
unknown committed
600
    {
601 602
      share->state.changed&= ~(STATE_CHANGED | STATE_CRASHED |
			       STATE_CRASHED_ON_REPAIR);
unknown's avatar
unknown committed
603 604 605 606 607
      file->update|=HA_STATE_CHANGED | HA_STATE_ROW_CHANGED;
    }
    file->save_state=file->s->state.state;
    if (file->s->base.auto_key)
      update_auto_increment_key(&param, file, 1);
608
    error = update_state_info(&param, file,
609
			      UPDATE_TIME | UPDATE_OPEN_COUNT |
unknown's avatar
unknown committed
610 611
			      ((param.testflag | extra_testflag) &
			       T_STATISTICS ? UPDATE_STAT : 0));
612 613
    info(HA_STATUS_NO_LOCK | HA_STATUS_TIME | HA_STATUS_VARIABLE |
	 HA_STATUS_CONST);
614
    if (rows != file->state->records && ! (param.testflag & T_VERY_SILENT))
unknown's avatar
unknown committed
615 616 617 618 619 620
    {
      char llbuff[22],llbuff2[22];
      mi_check_print_warning(&param,"Number of rows changed from %s to %s",
			     llstr(rows,llbuff),
			     llstr(file->state->records,llbuff2));
    }
unknown's avatar
unknown committed
621
  }
unknown's avatar
unknown committed
622
  else
unknown's avatar
unknown committed
623
  {
unknown's avatar
unknown committed
624
    mi_mark_crashed_on_repair(file);
unknown's avatar
unknown committed
625
    file->update |= HA_STATE_CHANGED | HA_STATE_ROW_CHANGED;
unknown's avatar
unknown committed
626
    update_state_info(&param, file, 0);
unknown's avatar
unknown committed
627
  }
628
  thd->proc_info=old_proc_info;
unknown's avatar
unknown committed
629 630
  if (!thd->locked_tables)
    mi_lock_database(file,F_UNLCK);
unknown's avatar
unknown committed
631 632
  DBUG_RETURN(error ? HA_ADMIN_FAILED :
	      !optimize_done ? HA_ADMIN_ALREADY_DONE : HA_ADMIN_OK);
unknown's avatar
unknown committed
633 634 635
}


636 637 638 639
/* Deactive all not unique index that can be recreated fast */

void ha_myisam::deactivate_non_unique_index(ha_rows rows)
{
640 641 642 643 644 645 646
  MYISAM_SHARE* share = file->s;
  if (share->state.key_map == ((ulonglong) 1L << share->base.keys)-1)
  {
    if (!(specialflag & SPECIAL_SAFE_MODE))
      if (rows==HA_POS_ERROR)
        mi_extra(file, HA_EXTRA_NO_KEYS);
      else
unknown's avatar
unknown committed
647
      {
648
        mi_disable_non_unique_index(file,rows);
unknown's avatar
unknown committed
649 650
        mi_extra(file, HA_EXTRA_BULK_INSERT_BEGIN);
      }
651 652 653 654
    enable_activate_all_index=1;
  }
  else
    enable_activate_all_index=0;
655 656 657 658 659 660 661 662 663
}


bool ha_myisam::activate_all_index(THD *thd)
{
  int error=0;
  MI_CHECK param;
  MYISAM_SHARE* share = file->s;
  DBUG_ENTER("activate_all_index");
unknown's avatar
unknown committed
664 665

  mi_extra(file, HA_EXTRA_BULK_INSERT_END);
666 667
  if (enable_activate_all_index &&
      share->state.key_map != ((ulonglong) 1L << share->base.keys)-1)
668 669
  {
    const char *save_proc_info=thd->proc_info;
unknown's avatar
unknown committed
670
    thd->proc_info="Creating index";
671 672
    myisamchk_init(&param);
    param.op_name = (char*) "recreating_index";
673
    param.testflag = (T_SILENT | T_REP_BY_SORT |
674
		      T_CREATE_MISSING_KEYS | T_TRUST_HEADER);
675 676
    param.myf_rw&= ~MY_WAIT_IF_FULL;
    param.sort_buffer_length=  myisam_sort_buffer_size;
unknown's avatar
unknown committed
677
    param.opt_rep_quick++;			// Don't copy data file
678
    param.tmpdir=mysql_tmpdir;
679
    error=repair(thd,param,0) != HA_ADMIN_OK;
680 681
    thd->proc_info=save_proc_info;
  }
682 683
  else
    enable_activate_all_index=1;
684 685
  DBUG_RETURN(error);
}
unknown's avatar
unknown committed
686

687

688
bool ha_myisam::check_and_repair(THD *thd)
689 690
{
  int error=0;
unknown's avatar
unknown committed
691
  int marked_crashed;
692 693 694 695
  HA_CHECK_OPT check_opt;
  DBUG_ENTER("ha_myisam::auto_check_and_repair");

  check_opt.init();
696 697 698 699
  check_opt.flags= T_MEDIUM | T_AUTO_REPAIR;
  // Don't use quick if deleted rows
  if (!file->state->del && (myisam_recover_options & HA_RECOVER_QUICK))
    check_opt.quick=1;
unknown's avatar
unknown committed
700 701
  sql_print_error("Warning: Checking table:   '%s'",table->path);
  if ((marked_crashed=mi_is_crashed(file)) || check(thd, &check_opt))
702
  {
unknown's avatar
unknown committed
703 704
    sql_print_error("Warning: Recovering table: '%s'",table->path);
    check_opt.quick= !check_opt.retry_without_quick && !marked_crashed;
705
    check_opt.flags=(((myisam_recover_options & HA_RECOVER_BACKUP) ?
706
		      T_BACKUP_DATA : 0) |
707
		     (!(myisam_recover_options & HA_RECOVER_FORCE) ?
708
		      T_SAFE_REPAIR : 0)) | T_AUTO_REPAIR;
709 710 711 712 713 714
    if (repair(thd, &check_opt))
      error=1;
  }
  DBUG_RETURN(error);
}

715 716 717 718 719
bool ha_myisam::is_crashed() const
{
  return (file->s->state.changed & STATE_CRASHED ||
	  (my_disable_locking && file->s->state.open_count));
}
720

unknown's avatar
unknown committed
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767
int ha_myisam::update_row(const byte * old_data, byte * new_data)
{
  statistic_increment(ha_update_count,&LOCK_status);
  if (table->time_stamp)
    update_timestamp(new_data+table->time_stamp-1);
  return mi_update(file,old_data,new_data);
}

int ha_myisam::delete_row(const byte * buf)
{
  statistic_increment(ha_delete_count,&LOCK_status);
  return mi_delete(file,buf);
}

int ha_myisam::index_read(byte * buf, const byte * key,
			  uint key_len, enum ha_rkey_function find_flag)
{
  statistic_increment(ha_read_key_count,&LOCK_status);
  int error=mi_rkey(file,buf,active_index, key, key_len, find_flag);
  table->status=error ? STATUS_NOT_FOUND: 0;
  return error;
}

int ha_myisam::index_read_idx(byte * buf, uint index, const byte * key,
			      uint key_len, enum ha_rkey_function find_flag)
{
  statistic_increment(ha_read_key_count,&LOCK_status);
  int error=mi_rkey(file,buf,index, key, key_len, find_flag);
  table->status=error ? STATUS_NOT_FOUND: 0;
  return error;
}

int ha_myisam::index_next(byte * buf)
{
  statistic_increment(ha_read_next_count,&LOCK_status);
  int error=mi_rnext(file,buf,active_index);
  table->status=error ? STATUS_NOT_FOUND: 0;
  return error;
}

int ha_myisam::index_prev(byte * buf)
{
  statistic_increment(ha_read_prev_count,&LOCK_status);
  int error=mi_rprev(file,buf, active_index);
  table->status=error ? STATUS_NOT_FOUND: 0;
  return error;
}
768

unknown's avatar
unknown committed
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902
int ha_myisam::index_first(byte * buf)
{
  statistic_increment(ha_read_first_count,&LOCK_status);
  int error=mi_rfirst(file, buf, active_index);
  table->status=error ? STATUS_NOT_FOUND: 0;
  return error;
}

int ha_myisam::index_last(byte * buf)
{
  statistic_increment(ha_read_last_count,&LOCK_status);
  int error=mi_rlast(file, buf, active_index);
  table->status=error ? STATUS_NOT_FOUND: 0;
  return error;
}

int ha_myisam::index_next_same(byte * buf,
			       const byte *key __attribute__((unused)),
			       uint length __attribute__((unused)))
{
  statistic_increment(ha_read_next_count,&LOCK_status);
  int error=mi_rnext_same(file,buf);
  table->status=error ? STATUS_NOT_FOUND: 0;
  return error;
}


int ha_myisam::rnd_init(bool scan)
{
  if (scan)
    return mi_scan_init(file);
  else
    return mi_extra(file,HA_EXTRA_RESET);
}

int ha_myisam::rnd_next(byte *buf)
{
  statistic_increment(ha_read_rnd_next_count,&LOCK_status);
  int error=mi_scan(file, buf);
  table->status=error ? STATUS_NOT_FOUND: 0;
  return error;
}

int ha_myisam::restart_rnd_next(byte *buf, byte *pos)
{
  return rnd_pos(buf,pos);
}

int ha_myisam::rnd_pos(byte * buf, byte *pos)
{
  statistic_increment(ha_read_rnd_count,&LOCK_status);
  int error=mi_rrnd(file, buf, ha_get_ptr(pos,ref_length));
  table->status=error ? STATUS_NOT_FOUND: 0;
  return error;
}

void ha_myisam::position(const byte* record)
{
  my_off_t position=mi_position(file);
  ha_store_ptr(ref, ref_length, position);
}

void ha_myisam::info(uint flag)
{
  MI_ISAMINFO info;
  (void) mi_status(file,&info,flag);
  if (flag & HA_STATUS_VARIABLE)
  {
    records = info.records;
    deleted = info.deleted;
    data_file_length=info.data_file_length;
    index_file_length=info.index_file_length;
    delete_length = info.delete_length;
    check_time  = info.check_time;
    mean_rec_length=info.mean_reclength;
  }
  if (flag & HA_STATUS_CONST)
  {
    max_data_file_length=info.max_data_file_length;
    max_index_file_length=info.max_index_file_length;
    create_time = info.create_time;
    sortkey = info.sortkey;
    ref_length=info.reflength;
    table->db_options_in_use    = info.options;
    block_size=myisam_block_size;
    table->keys_in_use &= info.key_map;
    table->db_record_offset=info.record_offset;
    if (table->key_parts)
      memcpy((char*) table->key_info[0].rec_per_key,
	     (char*) info.rec_per_key,
	     sizeof(ulong)*table->key_parts);
    raid_type=info.raid_type;
    raid_chunks=info.raid_chunks;
    raid_chunksize=info.raid_chunksize;
  }
  if (flag & HA_STATUS_ERRKEY)
  {
    errkey  = info.errkey;
    ha_store_ptr(dupp_ref, ref_length, info.dupp_key_pos);
  }
  if (flag & HA_STATUS_TIME)
    update_time = info.update_time;
  if (flag & HA_STATUS_AUTO)
    auto_increment_value= info.auto_increment;
}


int ha_myisam::extra(enum ha_extra_function operation)
{
  if (((specialflag & SPECIAL_SAFE_MODE) || (test_flags & TEST_NO_EXTRA)) &&
      (operation == HA_EXTRA_WRITE_CACHE ||
       operation == HA_EXTRA_KEYREAD))
    return 0;
  return mi_extra(file,operation);
}

int ha_myisam::reset(void)
{
  return mi_extra(file,HA_EXTRA_RESET);
}

int ha_myisam::delete_all_rows()
{
  return mi_delete_all_rows(file);
}

int ha_myisam::delete_table(const char *name)
{
  return mi_delete_table(name);
}

int ha_myisam::external_lock(THD *thd, int lock_type)
{
  return mi_lock_database(file,lock_type);
903
}
unknown's avatar
unknown committed
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109


THR_LOCK_DATA **ha_myisam::store_lock(THD *thd,
				      THR_LOCK_DATA **to,
				      enum thr_lock_type lock_type)
{
  if (lock_type != TL_IGNORE && file->lock.type == TL_UNLOCK)
    file->lock.type=lock_type;
  *to++= &file->lock;
  return to;
}

void ha_myisam::update_create_info(HA_CREATE_INFO *create_info)
{
  table->file->info(HA_STATUS_AUTO | HA_STATUS_CONST);
  if (!(create_info->used_fields & HA_CREATE_USED_AUTO))
  {
    create_info->auto_increment_value=auto_increment_value;
  }
  if (!(create_info->used_fields & HA_CREATE_USED_RAID))
  {
    create_info->raid_type= raid_type;
    create_info->raid_chunks= raid_chunks;
    create_info->raid_chunksize= raid_chunksize;
  }
}


int ha_myisam::create(const char *name, register TABLE *form,
		      HA_CREATE_INFO *info)
{
  int error;
  uint i,j,recpos,minpos,fieldpos,temp_length,length;
  bool found_auto_increment=0;
  enum ha_base_keytype type;
  char buff[FN_REFLEN];
  KEY *pos;
  MI_KEYDEF *keydef;
  MI_COLUMNDEF *recinfo,*recinfo_pos;
  MI_KEYSEG *keyseg;
  uint options=form->db_options_in_use;
  DBUG_ENTER("ha_myisam::create");

  type=HA_KEYTYPE_BINARY;				// Keep compiler happy
  if (!(my_multi_malloc(MYF(MY_WME),
			&recinfo,(form->fields*2+2)*sizeof(MI_COLUMNDEF),
			&keydef, form->keys*sizeof(MI_KEYDEF),
			&keyseg,
			((form->key_parts + form->keys) * sizeof(MI_KEYSEG)),
			0)))
    DBUG_RETURN(1);

  pos=form->key_info;
  for (i=0; i < form->keys ; i++, pos++)
  {
    keydef[i].flag= (pos->flags & (HA_NOSAME | HA_FULLTEXT));
    keydef[i].seg=keyseg;
    keydef[i].keysegs=pos->key_parts;
    for (j=0 ; j < pos->key_parts ; j++)
    {
      keydef[i].seg[j].flag=pos->key_part[j].key_part_flag;
      Field *field=pos->key_part[j].field;
      type=field->key_type();

      if (options & HA_OPTION_PACK_KEYS ||
	  (pos->flags & (HA_PACK_KEY | HA_BINARY_PACK_KEY |
			 HA_SPACE_PACK_USED)))
      {
	if (pos->key_part[j].length > 8 &&
	    (type == HA_KEYTYPE_TEXT ||
	     type == HA_KEYTYPE_NUM ||
	     (type == HA_KEYTYPE_BINARY && !field->zero_pack())))
	{
	  /* No blobs here */
	  if (j == 0)
	    keydef[i].flag|=HA_PACK_KEY;
	  if (!(field->flags & ZEROFILL_FLAG) &&
	      (field->type() == FIELD_TYPE_STRING ||
	       field->type() == FIELD_TYPE_VAR_STRING ||
	       ((int) (pos->key_part[j].length - field->decimals()))
	       >= 4))
	    keydef[i].seg[j].flag|=HA_SPACE_PACK;
	}
	else if (j == 0 && (!(pos->flags & HA_NOSAME) || pos->key_length > 16))
	  keydef[i].flag|= HA_BINARY_PACK_KEY;
      }
      keydef[i].seg[j].type=   (int) type;
      keydef[i].seg[j].start=  pos->key_part[j].offset;
      keydef[i].seg[j].length= pos->key_part[j].length;
      keydef[i].seg[j].bit_start=keydef[i].seg[j].bit_end=0;
      keydef[i].seg[j].language=MY_CHARSET_CURRENT;

      if (field->null_ptr)
      {
	keydef[i].seg[j].null_bit=field->null_bit;
	keydef[i].seg[j].null_pos= (uint) (field->null_ptr-
					   (uchar*) form->record[0]);
      }
      else
      {
	keydef[i].seg[j].null_bit=0;
	keydef[i].seg[j].null_pos=0;
      }
      if (j == 0 && field->flags & AUTO_INCREMENT_FLAG &&
	  !found_auto_increment)
      {
	keydef[i].flag|=HA_AUTO_KEY;
	found_auto_increment=1;
      }
      if (field->type() == FIELD_TYPE_BLOB)
      {
	keydef[i].seg[j].flag|=HA_BLOB_PART;
	/* save number of bytes used to pack length */
	keydef[i].seg[j].bit_start= (uint) (field->pack_length() -
					    form->blob_ptr_size);
      }
    }
    keyseg+=pos->key_parts;
  }

  recpos=0; recinfo_pos=recinfo;
  while (recpos < (uint) form->reclength)
  {
    Field **field,*found=0;
    minpos=form->reclength; length=0;

    for (field=form->field ; *field ; field++)
    {
      if ((fieldpos=(*field)->offset()) >= recpos &&
	  fieldpos <= minpos)
      {
	/* skip null fields */
	if (!(temp_length= (*field)->pack_length()))
	  continue;				/* Skipp null-fields */
	if (! found || fieldpos < minpos ||
	    (fieldpos == minpos && temp_length < length))
	{
	  minpos=fieldpos; found= *field; length=temp_length;
	}
      }
    }
    DBUG_PRINT("loop",("found: %lx  recpos: %d  minpos: %d  length: %d",
		       found,recpos,minpos,length));
    if (recpos != minpos)
    {						// Reserved space (Null bits?)
      bzero((char*) recinfo_pos,sizeof(*recinfo_pos));
      recinfo_pos->type=(int) FIELD_NORMAL;
      recinfo_pos++->length= (uint16) (minpos-recpos);
    }
    if (! found)
      break;

    if (found->flags & BLOB_FLAG)
    {
      recinfo_pos->type= (int) FIELD_BLOB;
    }
    else if (!(options & HA_OPTION_PACK_RECORD))
      recinfo_pos->type= (int) FIELD_NORMAL;
    else if (found->zero_pack())
      recinfo_pos->type= (int) FIELD_SKIPP_ZERO;
    else
      recinfo_pos->type= (int) ((length <= 3 ||
				      (found->flags & ZEROFILL_FLAG)) ?
				     FIELD_NORMAL :
				     found->type() == FIELD_TYPE_STRING ||
				     found->type() == FIELD_TYPE_VAR_STRING ?
				     FIELD_SKIPP_ENDSPACE :
				     FIELD_SKIPP_PRESPACE);
    if (found->null_ptr)
    {
      recinfo_pos->null_bit=found->null_bit;
      recinfo_pos->null_pos= (uint) (found->null_ptr-
				  (uchar*) form->record[0]);
    }
    else
    {
      recinfo_pos->null_bit=0;
      recinfo_pos->null_pos=0;
    }
    (recinfo_pos++) ->length=(uint16) length;
    recpos=minpos+length;
    DBUG_PRINT("loop",("length: %d  type: %d",
		       recinfo_pos[-1].length,recinfo_pos[-1].type));

  }
  MI_CREATE_INFO create_info;
  bzero((char*) &create_info,sizeof(create_info));
  create_info.max_rows=form->max_rows;
  create_info.reloc_rows=form->min_rows;
  create_info.auto_increment=(info->auto_increment_value ?
			      info->auto_increment_value -1 :
			      (ulonglong) 0);
  create_info.data_file_length=(ulonglong) form->max_rows*form->avg_row_length;
  create_info.raid_type=info->raid_type;
  create_info.raid_chunks=info->raid_chunks ? info->raid_chunks : RAID_DEFAULT_CHUNKS;
  create_info.raid_chunksize=info->raid_chunksize ? info->raid_chunksize : RAID_DEFAULT_CHUNKSIZE;

  error=mi_create(fn_format(buff,name,"","",2+4+16),
		  form->keys,keydef,
		  (uint) (recinfo_pos-recinfo), recinfo,
		  0, (MI_UNIQUEDEF*) 0,
		  &create_info,
		  (((options & HA_OPTION_PACK_RECORD) ? HA_PACK_RECORD : 0) |
		   ((options & HA_OPTION_CHECKSUM) ? HA_CREATE_CHECKSUM : 0) |
		   ((options & HA_OPTION_DELAY_KEY_WRITE) ?
		    HA_CREATE_DELAY_KEY_WRITE : 0)));
1110 1111


unknown's avatar
unknown committed
1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
  my_free((gptr) recinfo,MYF(0));
  DBUG_RETURN(error);
}


int ha_myisam::rename_table(const char * from, const char * to)
{
  return mi_rename(from,to);
}


longlong ha_myisam::get_auto_increment()
{
  if (!table->next_number_key_offset)
  {						// Autoincrement at key-start
    ha_myisam::info(HA_STATUS_AUTO);
    return auto_increment_value;
  }

  longlong nr;
  int error;
  byte key[MAX_KEY_LENGTH];
  (void) extra(HA_EXTRA_KEYREAD);
  key_copy(key,table,table->next_number_index,
	   table->next_number_key_offset);
  error=mi_rkey(file,table->record[1],(int) table->next_number_index,
		key,table->next_number_key_offset,HA_READ_PREFIX_LAST);
  if (error)
    nr=1;
  else
    nr=(longlong)
      table->next_number_field->val_int_offset(table->rec_buff_length)+1;
  extra(HA_EXTRA_NO_KEYREAD);
  return nr;
}


ha_rows ha_myisam::records_in_range(int inx,
				    const byte *start_key,uint start_key_len,
				    enum ha_rkey_function start_search_flag,
				    const byte *end_key,uint end_key_len,
				    enum ha_rkey_function end_search_flag)
{
  return (ha_rows) mi_records_in_range(file,
				       inx,
				       start_key,start_key_len,
				       start_search_flag,
				       end_key,end_key_len,
				       end_search_flag);
}

int ha_myisam::ft_read(byte * buf)
{
  int error;

1167 1168 1169
  if (!ft_handler)
    return -1;

unknown's avatar
unknown committed
1170 1171
  thread_safe_increment(ha_read_next_count,&LOCK_status); // why ?

unknown's avatar
unknown committed
1172 1173
  error=ft_read_next((FT_DOCLIST *) ft_handler,(char*) buf);

unknown's avatar
unknown committed
1174 1175 1176
  table->status=error ? STATUS_NOT_FOUND: 0;
  return error;
}
unknown's avatar
unknown committed
1177