~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/handler.h

  • Committer: Monty Taylor
  • Date: 2008-07-05 11:20:18 UTC
  • mto: This revision was merged to the branch mainline in revision 62.
  • Revision ID: monty@inaugust.com-20080705112018-fr12kkmgphtu7m29
Changes so that removal of duplicate curr_dir from my_sys.h work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
 
1
/* Copyright (C) 2000-2006 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
19
15
 
20
16
 
21
17
/* Definitions for parameters to do with handler-routines */
24
20
#pragma interface                       /* gcc class implementation */
25
21
#endif
26
22
 
27
 
#include <mysys/my_handler.h>
28
 
#include <storage/myisam/keycache.h>
 
23
#include <my_handler.h>
 
24
#include <ft_global.h>
 
25
#include <keycache.h>
29
26
 
30
27
#ifndef NO_HASH
31
28
#define NO_HASH                         /* Not yet implemented */
49
46
#define HA_ADMIN_NEEDS_CHECK    -12
50
47
 
51
48
/* Bits to show what an alter table will do */
52
 
#include <drizzled/sql_bitmap.h>
 
49
#include <sql_bitmap.h>
53
50
 
54
51
#define HA_MAX_ALTER_FLAGS 39
55
52
typedef Bitmap<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
111
108
  row to be able to find the row later.
112
109
*/
113
110
#define HA_REC_NOT_IN_SEQ      (1 << 3)
114
 
 
 
111
/* This is now a dead option, just left for compatibility */
 
112
#define HA_CAN_GEOMETRY        (1 << 4)
115
113
/*
116
114
  Reading keys in random order is as fast as reading keys in sort order
117
115
  (Used in records.cc to decide if we should use a record cache and by
131
129
#define HA_REQUIRE_PRIMARY_KEY (1 << 12) /* .. and can't create a hidden one */
132
130
#define HA_STATS_RECORDS_IS_EXACT (1 << 13) /* stats.records is exact */
133
131
/*
 
132
  INSERT_DELAYED only works with handlers that uses MySQL internal table
 
133
  level locks
 
134
*/
 
135
#define HA_CAN_INSERT_DELAYED  (1 << 14)
 
136
/*
134
137
  If we get the primary key columns for free when we do an index read
135
138
  It also implies that we have to retrive the primary key when using
136
139
  position() and rnd_pos().
141
144
  uses a primary key. Without primary key, we can't call position().
142
145
*/ 
143
146
#define HA_PRIMARY_KEY_REQUIRED_FOR_POSITION (1 << 16) 
 
147
#define HA_CAN_RTREEKEYS       (1 << 17)
144
148
#define HA_NOT_DELETE_WITH_CACHE (1 << 18)
145
149
/*
146
150
  The following is we need to a primary key to delete (and update) a row.
148
152
*/
149
153
#define HA_PRIMARY_KEY_REQUIRED_FOR_DELETE (1 << 19)
150
154
#define HA_NO_PREFIX_CHAR_KEYS (1 << 20)
 
155
#define HA_CAN_FULLTEXT        (1 << 21)
 
156
#define HA_CAN_SQL_HANDLER     (1 << 22)
151
157
#define HA_NO_AUTO_INCREMENT   (1 << 23)
152
158
#define HA_HAS_CHECKSUM        (1 << 24)
153
159
/* Table data are stored in separate files (for lower_case_table_names) */
154
160
#define HA_FILE_BASED          (1 << 26)
 
161
#define HA_NO_VARCHAR          (1 << 27)
 
162
#define HA_CAN_BIT_FIELD       (1 << 28) /* supports bit fields */
155
163
#define HA_NEED_READ_RANGE_BUFFER (1 << 29) /* for read_multi_range */
156
164
#define HA_ANY_INDEX_MAY_BE_UNIQUE (1 << 30)
157
 
#define HA_NO_COPY_ON_ALTER    (INT64_C(1) << 31)
158
 
#define HA_HAS_RECORDS         (INT64_C(1) << 32) /* records() gives exact count*/
159
 
#define HA_MRR_CANT_SORT       (INT64_C(1) << 34)
 
165
#define HA_NO_COPY_ON_ALTER    (LL(1) << 31)
 
166
#define HA_HAS_RECORDS         (LL(1) << 32) /* records() gives exact count*/
 
167
/* Has it's own method of binlog logging */
 
168
#define HA_HAS_OWN_BINLOGGING  (LL(1) << 33)
 
169
#define HA_MRR_CANT_SORT       (LL(1) << 34)
160
170
 
161
171
/*
162
172
  Engine is capable of row-format and statement-format logging,
163
173
  respectively
164
174
*/
165
 
#define HA_BINLOG_ROW_CAPABLE  (INT64_C(1) << 35)
166
 
#define HA_BINLOG_STMT_CAPABLE (INT64_C(1) << 36)
 
175
#define HA_BINLOG_ROW_CAPABLE  (LL(1) << 35)
 
176
#define HA_BINLOG_STMT_CAPABLE (LL(1) << 36)
167
177
 
168
 
#define HA_ONLINE_ALTER        (INT64_C(1) << 37)
 
178
#define HA_ONLINE_ALTER        (LL(1) << 37)
169
179
 
170
180
/*
171
181
  Set of all binlog flags. Currently only contain the capabilities
204
214
  set.
205
215
  This is actually removed even before it was introduced the first time.
206
216
  The new idea is that handlers will handle the lock level already in
207
 
  store_lock for ALTER Table partitions.
 
217
  store_lock for ALTER TABLE partitions.
208
218
 
209
219
  HA_PARTITION_ONE_PHASE is a flag that can be set by handlers that take
210
220
  care of changing the partitions online and in one phase. Thus all phases
250
260
#define HA_BLOCK_LOCK           256     /* unlock when reading some records */
251
261
#define HA_OPEN_TEMPORARY       512
252
262
 
253
 
/* For transactional LOCK Table. handler::lock_table() */
 
263
/* For transactional LOCK TABLE. handler::lock_table() */
254
264
#define HA_LOCK_IN_SHARE_MODE      F_RDLCK
255
265
#define HA_LOCK_IN_EXCLUSIVE_MODE  F_WRLCK
256
266
 
272
282
#define HA_CACHE_TBL_TRANSACT    4
273
283
 
274
284
/* Options of START TRANSACTION statement (and later of SET TRANSACTION stmt) */
275
 
#define DRIZZLE_START_TRANS_OPT_WITH_CONS_SNAPSHOT 1
 
285
#define MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT 1
276
286
 
277
287
/* Flags for method is_fatal_error */
278
288
#define HA_CHECK_DUP_KEY 1
281
291
 
282
292
enum legacy_db_type
283
293
{
284
 
  DB_TYPE_UNKNOWN=0,
 
294
  DB_TYPE_UNKNOWN=0,DB_TYPE_DIAB_ISAM=1,
 
295
  DB_TYPE_HASH,DB_TYPE_MISAM,DB_TYPE_PISAM,
 
296
  DB_TYPE_RMS_ISAM, DB_TYPE_HEAP, DB_TYPE_ISAM,
 
297
  DB_TYPE_MRG_ISAM, DB_TYPE_MYISAM, DB_TYPE_MRG_MYISAM,
 
298
  DB_TYPE_BERKELEY_DB, DB_TYPE_INNODB,
 
299
  DB_TYPE_GEMINI, DB_TYPE_NDBCLUSTER,
 
300
  DB_TYPE_EXAMPLE_DB, DB_TYPE_ARCHIVE_DB, DB_TYPE_CSV_DB,
 
301
  DB_TYPE_FEDERATED_DB,
 
302
  DB_TYPE_BLACKHOLE_DB,
 
303
  DB_TYPE_PARTITION_DB,
 
304
  DB_TYPE_BINLOG,
 
305
  DB_TYPE_SOLID,
 
306
  DB_TYPE_PBXT,
 
307
  DB_TYPE_TABLE_FUNCTION,
 
308
  DB_TYPE_MEMCACHE,
 
309
  DB_TYPE_FALCON,
 
310
  DB_TYPE_MARIA,
285
311
  DB_TYPE_FIRST_DYNAMIC=42,
286
312
  DB_TYPE_DEFAULT=127 // Must be last
287
313
};
317
343
 
318
344
/* Bits in used_fields */
319
345
#define HA_CREATE_USED_AUTO             (1L << 0)
320
 
#ifdef DEAD_OPTIONS
321
 
#define HA_CREATE_USED_RAID             (1L << 1) /* Historical, no longer supported */
 
346
#define HA_CREATE_USED_RAID             (1L << 1) //RAID is no longer availble
322
347
#define HA_CREATE_USED_UNION            (1L << 2)
323
 
#define HA_CREATE_USED_PASSWORD         (1L << 17)
324
 
#endif
325
348
#define HA_CREATE_USED_INSERT_METHOD    (1L << 3)
326
349
#define HA_CREATE_USED_MIN_ROWS         (1L << 4)
327
350
#define HA_CREATE_USED_MAX_ROWS         (1L << 5)
336
359
#define HA_CREATE_USED_DELAY_KEY_WRITE  (1L << 14)
337
360
#define HA_CREATE_USED_ROW_FORMAT       (1L << 15)
338
361
#define HA_CREATE_USED_COMMENT          (1L << 16)
 
362
#define HA_CREATE_USED_PASSWORD         (1L << 17)
339
363
#define HA_CREATE_USED_CONNECTION       (1L << 18)
340
364
#define HA_CREATE_USED_KEY_BLOCK_SIZE   (1L << 19)
 
365
#define HA_CREATE_USED_TRANSACTIONAL    (1L << 20)
341
366
#define HA_CREATE_USED_PAGE_CHECKSUM    (1L << 21)
342
 
#define HA_CREATE_USED_BLOCK_SIZE       (1L << 22)
343
367
 
344
368
typedef uint64_t my_xid; // this line is the same as in log_event.h
345
 
#define DRIZZLE_XID_PREFIX "MySQLXid"
346
 
#define DRIZZLE_XID_PREFIX_LEN 8 // must be a multiple of 8
347
 
#define DRIZZLE_XID_OFFSET (DRIZZLE_XID_PREFIX_LEN+sizeof(server_id))
348
 
#define DRIZZLE_XID_GTRID_LEN (DRIZZLE_XID_OFFSET+sizeof(my_xid))
 
369
#define MYSQL_XID_PREFIX "MySQLXid"
 
370
#define MYSQL_XID_PREFIX_LEN 8 // must be a multiple of 8
 
371
#define MYSQL_XID_OFFSET (MYSQL_XID_PREFIX_LEN+sizeof(server_id))
 
372
#define MYSQL_XID_GTRID_LEN (MYSQL_XID_OFFSET+sizeof(my_xid))
349
373
 
350
 
#define XIDDATASIZE DRIZZLE_XIDDATASIZE
 
374
#define XIDDATASIZE MYSQL_XIDDATASIZE
351
375
#define MAXGTRIDSIZE 64
352
376
#define MAXBQUALSIZE 64
353
377
 
354
378
#define COMPATIBLE_DATA_YES 0
355
379
#define COMPATIBLE_DATA_NO  1
356
380
 
357
 
typedef bool (*qc_engine_callback)(THD *thd, char *table_key,
358
 
                                      uint32_t key_length,
359
 
                                      uint64_t *engine_data);
360
 
 
361
381
/**
362
382
  struct xid_t is binary compatible with the XID structure as
363
383
  in the X/Open CAE Specification, Distributed Transaction Processing:
364
384
  The XA Specification, X/Open Company Ltd., 1991.
365
385
  http://www.opengroup.org/bookstore/catalog/c193.htm
366
386
 
367
 
  @see DRIZZLE_XID in mysql/plugin.h
 
387
  @see MYSQL_XID in mysql/plugin.h
368
388
*/
369
389
struct xid_t {
370
390
  long formatID;
389
409
  {
390
410
    my_xid tmp;
391
411
    formatID= 1;
392
 
    set(DRIZZLE_XID_PREFIX_LEN, 0, DRIZZLE_XID_PREFIX);
393
 
    memcpy(data+DRIZZLE_XID_PREFIX_LEN, &server_id, sizeof(server_id));
 
412
    set(MYSQL_XID_PREFIX_LEN, 0, MYSQL_XID_PREFIX);
 
413
    memcpy(data+MYSQL_XID_PREFIX_LEN, &server_id, sizeof(server_id));
394
414
    tmp= xid;
395
 
    memcpy(data+DRIZZLE_XID_OFFSET, &tmp, sizeof(tmp));
396
 
    gtrid_length=DRIZZLE_XID_GTRID_LEN;
 
415
    memcpy(data+MYSQL_XID_OFFSET, &tmp, sizeof(tmp));
 
416
    gtrid_length=MYSQL_XID_GTRID_LEN;
397
417
  }
398
418
  void set(long g, long b, const char *d)
399
419
  {
407
427
  my_xid quick_get_my_xid()
408
428
  {
409
429
    my_xid tmp;
410
 
    memcpy(&tmp, data+DRIZZLE_XID_OFFSET, sizeof(tmp));
 
430
    memcpy(&tmp, data+MYSQL_XID_OFFSET, sizeof(tmp));
411
431
    return tmp;
412
432
  }
413
433
  my_xid get_my_xid()
414
434
  {
415
 
    return gtrid_length == DRIZZLE_XID_GTRID_LEN && bqual_length == 0 &&
416
 
           !memcmp(data+DRIZZLE_XID_PREFIX_LEN, &server_id, sizeof(server_id)) &&
417
 
           !memcmp(data, DRIZZLE_XID_PREFIX, DRIZZLE_XID_PREFIX_LEN) ?
 
435
    return gtrid_length == MYSQL_XID_GTRID_LEN && bqual_length == 0 &&
 
436
           !memcmp(data+MYSQL_XID_PREFIX_LEN, &server_id, sizeof(server_id)) &&
 
437
           !memcmp(data, MYSQL_XID_PREFIX, MYSQL_XID_PREFIX_LEN) ?
418
438
           quick_get_my_xid() : 0;
419
439
  }
420
 
  uint32_t length()
 
440
  uint length()
421
441
  {
422
442
    return sizeof(formatID)+sizeof(gtrid_length)+sizeof(bqual_length)+
423
443
           gtrid_length+bqual_length;
424
444
  }
425
 
  unsigned char *key()
 
445
  uchar *key()
426
446
  {
427
 
    return (unsigned char *)&gtrid_length;
 
447
    return (uchar *)&gtrid_length;
428
448
  }
429
 
  uint32_t key_length()
 
449
  uint key_length()
430
450
  {
431
451
    return sizeof(gtrid_length)+sizeof(bqual_length)+gtrid_length+bqual_length;
432
452
  }
437
457
#define MIN_XID_LIST_SIZE  128
438
458
#define MAX_XID_LIST_SIZE  (1024*128)
439
459
 
 
460
/*
 
461
  These structures are used to pass information from a set of SQL commands
 
462
  on add/drop/change tablespace definitions to the proper hton.
 
463
*/
 
464
#define UNDEF_NODEGROUP 65535
 
465
enum ts_command_type
 
466
{
 
467
  TS_CMD_NOT_DEFINED = -1,
 
468
  CREATE_TABLESPACE = 0,
 
469
  ALTER_TABLESPACE = 1,
 
470
  CREATE_LOGFILE_GROUP = 2,
 
471
  ALTER_LOGFILE_GROUP = 3,
 
472
  DROP_TABLESPACE = 4,
 
473
  DROP_LOGFILE_GROUP = 5,
 
474
  CHANGE_FILE_TABLESPACE = 6,
 
475
  ALTER_ACCESS_MODE_TABLESPACE = 7
 
476
};
 
477
 
 
478
enum ts_alter_tablespace_type
 
479
{
 
480
  TS_ALTER_TABLESPACE_TYPE_NOT_DEFINED = -1,
 
481
  ALTER_TABLESPACE_ADD_FILE = 1,
 
482
  ALTER_TABLESPACE_DROP_FILE = 2
 
483
};
 
484
 
 
485
enum tablespace_access_mode
 
486
{
 
487
  TS_NOT_DEFINED= -1,
 
488
  TS_READ_ONLY = 0,
 
489
  TS_READ_WRITE = 1,
 
490
  TS_NOT_ACCESSIBLE = 2
 
491
};
 
492
 
440
493
struct handlerton;
441
 
 
442
 
/* The handler for a table type.  Will be included in the Table structure */
443
 
 
444
 
class Table;
 
494
class st_alter_tablespace : public Sql_alloc
 
495
{
 
496
  public:
 
497
  const char *tablespace_name;
 
498
  const char *logfile_group_name;
 
499
  enum ts_command_type ts_cmd_type;
 
500
  enum ts_alter_tablespace_type ts_alter_tablespace_type;
 
501
  const char *data_file_name;
 
502
  const char *undo_file_name;
 
503
  const char *redo_file_name;
 
504
  uint64_t extent_size;
 
505
  uint64_t undo_buffer_size;
 
506
  uint64_t redo_buffer_size;
 
507
  uint64_t initial_size;
 
508
  uint64_t autoextend_size;
 
509
  uint64_t max_size;
 
510
  uint nodegroup_id;
 
511
  handlerton *storage_engine;
 
512
  bool wait_until_completed;
 
513
  const char *ts_comment;
 
514
  enum tablespace_access_mode ts_access_mode;
 
515
  st_alter_tablespace()
 
516
  {
 
517
    tablespace_name= NULL;
 
518
    logfile_group_name= "DEFAULT_LG"; //Default log file group
 
519
    ts_cmd_type= TS_CMD_NOT_DEFINED;
 
520
    data_file_name= NULL;
 
521
    undo_file_name= NULL;
 
522
    redo_file_name= NULL;
 
523
    extent_size= 1024*1024;        //Default 1 MByte
 
524
    undo_buffer_size= 8*1024*1024; //Default 8 MByte
 
525
    redo_buffer_size= 8*1024*1024; //Default 8 MByte
 
526
    initial_size= 128*1024*1024;   //Default 128 MByte
 
527
    autoextend_size= 0;            //No autoextension as default
 
528
    max_size= 0;                   //Max size == initial size => no extension
 
529
    storage_engine= NULL;
 
530
    nodegroup_id= UNDEF_NODEGROUP;
 
531
    wait_until_completed= TRUE;
 
532
    ts_comment= NULL;
 
533
    ts_access_mode= TS_NOT_DEFINED;
 
534
  }
 
535
};
 
536
 
 
537
/* The handler for a table type.  Will be included in the TABLE structure */
 
538
 
 
539
struct st_table;
 
540
typedef struct st_table TABLE;
445
541
typedef struct st_table_share TABLE_SHARE;
446
542
struct st_foreign_key_info;
447
543
typedef struct st_foreign_key_info FOREIGN_KEY_INFO;
448
 
typedef bool (stat_print_fn)(THD *thd, const char *type, uint32_t type_len,
449
 
                             const char *file, uint32_t file_len,
450
 
                             const char *status, uint32_t status_len);
 
544
typedef bool (stat_print_fn)(THD *thd, const char *type, uint type_len,
 
545
                             const char *file, uint file_len,
 
546
                             const char *status, uint status_len);
451
547
enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
452
548
extern st_plugin_int *hton2plugin[MAX_HA];
453
549
 
483
579
 
484
580
   slot number is initialized by MySQL after xxx_init() is called.
485
581
   */
486
 
   uint32_t slot;
 
582
   uint slot;
487
583
   /*
488
584
     to store per-savepoint data storage engine is provided with an area
489
585
     of a requested size (0 is ok here).
493
589
     area and need not be used by storage engine.
494
590
     see binlog_hton and binlog_savepoint_set/rollback for an example.
495
591
   */
496
 
   uint32_t savepoint_offset;
 
592
   uint savepoint_offset;
497
593
   /*
498
594
     handlerton methods:
499
595
 
524
620
   int  (*commit)(handlerton *hton, THD *thd, bool all);
525
621
   int  (*rollback)(handlerton *hton, THD *thd, bool all);
526
622
   int  (*prepare)(handlerton *hton, THD *thd, bool all);
527
 
   int  (*recover)(handlerton *hton, XID *xid_list, uint32_t len);
 
623
   int  (*recover)(handlerton *hton, XID *xid_list, uint len);
528
624
   int  (*commit_by_xid)(handlerton *hton, XID *xid);
529
625
   int  (*rollback_by_xid)(handlerton *hton, XID *xid);
530
626
   void *(*create_cursor_read_view)(handlerton *hton, THD *thd);
532
628
   void (*close_cursor_read_view)(handlerton *hton, THD *thd, void *read_view);
533
629
   handler *(*create)(handlerton *hton, TABLE_SHARE *table, MEM_ROOT *mem_root);
534
630
   void (*drop_database)(handlerton *hton, char* path);
 
631
   int (*panic)(handlerton *hton, enum ha_panic_function flag);
535
632
   int (*start_consistent_snapshot)(handlerton *hton, THD *thd);
536
633
   bool (*flush_logs)(handlerton *hton);
537
634
   bool (*show_status)(handlerton *hton, THD *thd, stat_print_fn *print, enum ha_stat_type stat);
 
635
   int (*alter_tablespace)(handlerton *hton, THD *thd, st_alter_tablespace *ts_info);
538
636
   int (*fill_files_table)(handlerton *hton, THD *thd,
539
 
                           TableList *tables,
 
637
                           TABLE_LIST *tables,
540
638
                           class Item *cond);
541
 
   uint32_t flags;                                /* global handler flags */
 
639
   uint32 flags;                                /* global handler flags */
542
640
   int (*release_temporary_latches)(handlerton *hton, THD *thd);
543
641
 
544
642
   int (*discover)(handlerton *hton, THD* thd, const char *db, 
545
643
                   const char *name,
546
 
                   unsigned char **frmblob, 
 
644
                   uchar **frmblob, 
547
645
                   size_t *frmlen);
548
646
   int (*table_exists_in_engine)(handlerton *hton, THD* thd, const char *db,
549
647
                                 const char *name);
550
 
   uint32_t license; /* Flag for Engine License */
 
648
   uint32 license; /* Flag for Engine License */
551
649
   void *data; /* Location for engines to keep personal structures */
552
650
};
553
651
 
583
681
    * stmt.modified_non_trans_table is used to keep track of
584
682
    modified non-transactional tables of top-level statements. At
585
683
    the end of the previous statement and at the beginning of the session,
586
 
    it is reset to false.  If such functions
 
684
    it is reset to FALSE.  If such functions
587
685
    as mysql_insert, mysql_update, mysql_delete etc modify a
588
 
    non-transactional table, they set this flag to true.  At the
 
686
    non-transactional table, they set this flag to TRUE.  At the
589
687
    end of the statement, the value of stmt.modified_non_trans_table 
590
688
    is merged with all.modified_non_trans_table and gets reset.
591
689
    * all.modified_non_trans_table is reset at the end of transaction
596
694
    At entrance into a sub-statement, a copy of the value of
597
695
    stmt.modified_non_trans_table (containing the changes of the
598
696
    outer statement) is saved on stack. Then 
599
 
    stmt.modified_non_trans_table is reset to false and the
 
697
    stmt.modified_non_trans_table is reset to FALSE and the
600
698
    substatement is executed. Then the new value is merged with the
601
699
    saved value.
602
700
  */
603
701
  bool modified_non_trans_table;
604
702
 
605
 
  void reset() { no_2pc= false; modified_non_trans_table= false; }
 
703
  void reset() { no_2pc= FALSE; modified_non_trans_table= FALSE; }
606
704
};
607
705
 
608
706
 
629
727
  /** Register this storage engine in the given transaction context. */
630
728
  void register_ha(THD_TRANS *trans, handlerton *ht_arg)
631
729
  {
632
 
    assert(m_flags == 0);
633
 
    assert(m_ht == NULL);
634
 
    assert(m_next == NULL);
 
730
    DBUG_ASSERT(m_flags == 0);
 
731
    DBUG_ASSERT(m_ht == NULL);
 
732
    DBUG_ASSERT(m_next == NULL);
635
733
 
636
734
    m_ht= ht_arg;
637
735
    m_flags= (int) TRX_READ_ONLY; /* Assume read-only at start. */
652
750
 
653
751
  void set_trx_read_write()
654
752
  {
655
 
    assert(is_started());
 
753
    DBUG_ASSERT(is_started());
656
754
    m_flags|= (int) TRX_READ_WRITE;
657
755
  }
658
756
  bool is_trx_read_write() const
659
757
  {
660
 
    assert(is_started());
 
758
    DBUG_ASSERT(is_started());
661
759
    return m_flags & (int) TRX_READ_WRITE;
662
760
  }
663
761
  bool is_started() const { return m_ht != NULL; }
669
767
      Can be called many times, e.g. when we have many
670
768
      read-write statements in a transaction.
671
769
    */
672
 
    assert(is_started());
 
770
    DBUG_ASSERT(is_started());
673
771
    if (stmt_trx->is_trx_read_write())
674
772
      set_trx_read_write();
675
773
  }
676
774
  Ha_trx_info *next() const
677
775
  {
678
 
    assert(is_started());
 
776
    DBUG_ASSERT(is_started());
679
777
    return m_next;
680
778
  }
681
779
  handlerton *ht() const
682
780
  {
683
 
    assert(is_started());
 
781
    DBUG_ASSERT(is_started());
684
782
    return m_ht;
685
783
  }
686
784
private:
698
796
    Not-null only if this instance is a part of transaction.
699
797
    May assume a combination of enum values above.
700
798
  */
701
 
  unsigned char       m_flags;
 
799
  uchar       m_flags;
702
800
};
703
801
 
704
802
 
705
803
enum enum_tx_isolation { ISO_READ_UNCOMMITTED, ISO_READ_COMMITTED,
706
804
                         ISO_REPEATABLE_READ, ISO_SERIALIZABLE};
707
805
 
 
806
 
 
807
enum ndb_distribution { ND_KEYHASH= 0, ND_LINHASH= 1 };
 
808
 
 
809
 
708
810
typedef struct {
709
811
  uint64_t data_file_length;
710
812
  uint64_t max_data_file_length;
711
813
  uint64_t index_file_length;
712
814
  uint64_t delete_length;
713
815
  ha_rows records;
714
 
  uint32_t mean_rec_length;
 
816
  ulong mean_rec_length;
715
817
  time_t create_time;
716
818
  time_t check_time;
717
819
  time_t update_time;
722
824
class Item;
723
825
struct st_table_log_memory_entry;
724
826
 
725
 
#define NOT_A_PARTITION_ID ((uint32_t)-1)
 
827
#define NOT_A_PARTITION_ID ((uint32)-1)
726
828
 
727
829
enum ha_choice { HA_CHOICE_UNDEF, HA_CHOICE_NO, HA_CHOICE_YES };
728
830
 
729
831
typedef struct st_ha_create_information
730
832
{
731
 
  const CHARSET_INFO *table_charset, *default_table_charset;
 
833
  CHARSET_INFO *table_charset, *default_table_charset;
732
834
  LEX_STRING connect_string;
 
835
  const char *password, *tablespace;
733
836
  LEX_STRING comment;
734
837
  const char *data_file_name, *index_file_name;
735
838
  const char *alias;
736
839
  uint64_t max_rows,min_rows;
737
840
  uint64_t auto_increment_value;
738
 
  uint32_t table_options;
739
 
  uint32_t avg_row_length;
740
 
  uint32_t used_fields;
741
 
  uint32_t key_block_size;
742
 
  uint32_t block_size;
 
841
  ulong table_options;
 
842
  ulong avg_row_length;
 
843
  ulong used_fields;
 
844
  ulong key_block_size;
 
845
  SQL_LIST merge_list;
743
846
  handlerton *db_type;
744
847
  enum row_type row_type;
745
 
  uint32_t null_bits;                       /* NULL bits at start of record */
746
 
  uint32_t options;                             /* OR of HA_CREATE_ options */
747
 
  uint32_t extra_size;                      /* length of extra data segment */
 
848
  uint null_bits;                       /* NULL bits at start of record */
 
849
  uint options;                         /* OR of HA_CREATE_ options */
 
850
  uint merge_insert_method;
 
851
  uint extra_size;                      /* length of extra data segment */
 
852
  /* 0 not used, 1 if not transactional, 2 if transactional */
 
853
  enum ha_choice transactional;
748
854
  bool table_existed;                   /* 1 in create if table existed */
749
855
  bool frm_only;                        /* 1 if no ha_create_table() */
750
856
  bool varchar;                         /* 1 if table has a VARCHAR */
 
857
  enum ha_storage_media default_storage_media;  /* DEFAULT, DISK or MEMORY */
751
858
  enum ha_choice page_checksum;         /* If we have page_checksums */
752
859
} HA_CREATE_INFO;
753
860
 
754
861
typedef struct st_ha_alter_information
755
862
{
756
863
  KEY  *key_info_buffer;
757
 
  uint32_t key_count;
758
 
  uint32_t index_drop_count;
759
 
  uint32_t *index_drop_buffer;
760
 
  uint32_t index_add_count;
761
 
  uint32_t *index_add_buffer;
 
864
  uint key_count;
 
865
  uint index_drop_count;
 
866
  uint *index_drop_buffer;
 
867
  uint index_add_count;
 
868
  uint *index_add_buffer;
762
869
  void *data;
763
870
} HA_ALTER_INFO;
764
871
 
766
873
typedef struct st_key_create_information
767
874
{
768
875
  enum ha_key_alg algorithm;
769
 
  uint32_t block_size;
 
876
  ulong block_size;
770
877
  LEX_STRING parser_name;
771
878
  LEX_STRING comment;
772
879
} KEY_CREATE_INFO;
792
899
  TABLEOP_HOOKS() {}
793
900
  virtual ~TABLEOP_HOOKS() {}
794
901
 
795
 
  inline void prelock(Table **tables, uint32_t count)
 
902
  inline void prelock(TABLE **tables, uint count)
796
903
  {
797
904
    do_prelock(tables, count);
798
905
  }
799
906
 
800
 
  inline int postlock(Table **tables, uint32_t count)
 
907
  inline int postlock(TABLE **tables, uint count)
801
908
  {
802
909
    return do_postlock(tables, count);
803
910
  }
804
911
private:
805
912
  /* Function primitive that is called prior to locking tables */
806
 
  virtual void do_prelock(Table **tables __attribute__((unused)),
807
 
                          uint32_t count __attribute__((unused)))
 
913
  virtual void do_prelock(TABLE **tables, uint count)
808
914
  {
809
915
    /* Default is to do nothing */
810
916
  }
817
923
 
818
924
     @return Error code or zero.
819
925
   */
820
 
  virtual int do_postlock(Table **tables __attribute__((unused)),
821
 
                          uint32_t count __attribute__((unused)))
 
926
  virtual int do_postlock(TABLE **tables, uint count)
822
927
  {
823
928
    return 0;                           /* Default is to do nothing */
824
929
  }
825
930
};
826
931
 
827
932
typedef struct st_savepoint SAVEPOINT;
828
 
extern uint32_t savepoint_alloc_size;
 
933
extern ulong savepoint_alloc_size;
829
934
extern KEY_CREATE_INFO default_key_create_info;
830
935
 
831
936
/* Forward declaration for condition pushdown to storage engine */
834
939
typedef struct st_ha_check_opt
835
940
{
836
941
  st_ha_check_opt() {}                        /* Remove gcc warning */
837
 
  uint32_t sort_buffer_size;
838
 
  uint32_t flags;       /* isam layer flags (e.g. for myisamchk) */
839
 
  uint32_t sql_flags;   /* sql layer flags - for something myisamchk cannot do */
 
942
  ulong sort_buffer_size;
 
943
  uint flags;       /* isam layer flags (e.g. for myisamchk) */
 
944
  uint sql_flags;   /* sql layer flags - for something myisamchk cannot do */
840
945
  KEY_CACHE *key_cache; /* new key cache when changing key cache */
841
946
  void init();
842
947
} HA_CHECK_OPT;
852
957
 
853
958
typedef struct st_handler_buffer
854
959
{
855
 
  unsigned char *buffer;         /* Buffer one can start using */
856
 
  unsigned char *buffer_end;     /* End of buffer */
857
 
  unsigned char *end_of_used_area;     /* End of area that was used by handler */
 
960
  uchar *buffer;         /* Buffer one can start using */
 
961
  uchar *buffer_end;     /* End of buffer */
 
962
  uchar *end_of_used_area;     /* End of area that was used by handler */
858
963
} HANDLER_BUFFER;
859
964
 
860
965
typedef struct system_status_var SSV;
876
981
    RETURN
877
982
      An opaque value to be used as RANGE_SEQ_IF::next() parameter
878
983
  */
879
 
  range_seq_t (*init)(void *init_params, uint32_t n_ranges, uint32_t flags);
 
984
  range_seq_t (*init)(void *init_params, uint n_ranges, uint flags);
880
985
 
881
986
 
882
987
  /*
891
996
      0 - Ok, the range structure filled with info about the next range
892
997
      1 - No more ranges
893
998
  */
894
 
  uint32_t (*next) (range_seq_t seq, KEY_MULTI_RANGE *range);
 
999
  uint (*next) (range_seq_t seq, KEY_MULTI_RANGE *range);
895
1000
} RANGE_SEQ_IF;
896
1001
 
897
 
uint16_t &mrr_persistent_flag_storage(range_seq_t seq, uint32_t idx);
898
 
char* &mrr_get_ptr_by_idx(range_seq_t seq, uint32_t idx);
 
1002
uint16 &mrr_persistent_flag_storage(range_seq_t seq, uint idx);
 
1003
char* &mrr_get_ptr_by_idx(range_seq_t seq, uint idx);
899
1004
 
900
1005
class COST_VECT
901
1006
949
1054
  }
950
1055
};
951
1056
 
952
 
void get_sweep_read_cost(Table *table, ha_rows nrows, bool interrupted, 
 
1057
void get_sweep_read_cost(TABLE *table, ha_rows nrows, bool interrupted, 
953
1058
                         COST_VECT *cost);
954
1059
 
955
1060
/*
1017
1122
  */
1018
1123
  ha_rows records;
1019
1124
  ha_rows deleted;                      /* Deleted records */
1020
 
  uint32_t mean_rec_length;             /* physical reclength */
 
1125
  ulong mean_rec_length;                /* physical reclength */
1021
1126
  time_t create_time;                   /* When table was created */
1022
1127
  time_t check_time;
1023
1128
  time_t update_time;
1024
 
  uint32_t block_size;                  /* index block size */
 
1129
  uint block_size;                      /* index block size */
1025
1130
 
1026
1131
  ha_statistics():
1027
1132
    data_file_length(0), max_data_file_length(0),
1031
1136
  {}
1032
1137
};
1033
1138
 
1034
 
uint32_t calculate_key_len(Table *, uint, const unsigned char *, key_part_map);
 
1139
uint calculate_key_len(TABLE *, uint, const uchar *, key_part_map);
1035
1140
/*
1036
1141
  bitmap with first N+1 bits set
1037
1142
  (keypart_map for a key prefix of [0..N] keyparts)
1097
1202
  typedef uint64_t Table_flags;
1098
1203
protected:
1099
1204
  struct st_table_share *table_share;   /* The table definition */
1100
 
  Table *table;               /* The current open table */
 
1205
  struct st_table *table;               /* The current open table */
1101
1206
  Table_flags cached_table_flags;       /* Set on init() and open() */
1102
1207
 
1103
1208
  ha_rows estimation_rows_to_insert;
1104
1209
public:
1105
1210
  handlerton *ht;                 /* storage engine of this handler */
1106
 
  unsigned char *ref;                           /* Pointer to current row */
1107
 
  unsigned char *dup_ref;                       /* Pointer to duplicate row */
 
1211
  uchar *ref;                           /* Pointer to current row */
 
1212
  uchar *dup_ref;                       /* Pointer to duplicate row */
1108
1213
 
1109
1214
  ha_statistics stats;
1110
1215
  /** MultiRangeRead-related members: */
1111
1216
  range_seq_t mrr_iter;    /* Interator to traverse the range sequence */
1112
1217
  RANGE_SEQ_IF mrr_funcs;  /* Range sequence traversal functions */
1113
1218
  HANDLER_BUFFER *multi_range_buffer; /* MRR buffer info */
1114
 
  uint32_t ranges_in_seq; /* Total number of ranges in the traversed sequence */
1115
 
  /* true <=> source MRR ranges and the output are ordered */
 
1219
  uint ranges_in_seq; /* Total number of ranges in the traversed sequence */
 
1220
  /* TRUE <=> source MRR ranges and the output are ordered */
1116
1221
  bool mrr_is_output_sorted;
1117
1222
 
1118
 
  /** true <=> we're currently traversing a range in mrr_cur_range. */
 
1223
  /** TRUE <=> we're currently traversing a range in mrr_cur_range. */
1119
1224
  bool mrr_have_range;
1120
1225
  /** Current range (the one we're now returning rows from) */
1121
1226
  KEY_MULTI_RANGE mrr_cur_range;
1126
1231
  int key_compare_result_on_equal;
1127
1232
  bool eq_range;
1128
1233
  /* 
1129
 
    true <=> the engine guarantees that returned records are within the range
 
1234
    TRUE <=> the engine guarantees that returned records are within the range
1130
1235
    being scanned.
1131
1236
  */
1132
1237
  bool in_range_check_pushed_down;
1133
1238
 
1134
 
  uint32_t errkey;                              /* Last dup key */
1135
 
  uint32_t key_used_on_scan;
1136
 
  uint32_t active_index;
 
1239
  uint errkey;                          /* Last dup key */
 
1240
  uint key_used_on_scan;
 
1241
  uint active_index;
1137
1242
  /** Length of ref (1-8 or the clustered key length) */
1138
 
  uint32_t ref_length;
 
1243
  uint ref_length;
 
1244
  FT_INFO *ft_handler;
1139
1245
  enum {NONE=0, INDEX, RND} inited;
1140
1246
  bool locked;
1141
1247
  bool implicit_emptied;                /* Can be !=0 only if HEAP */
1142
1248
  const Item *pushed_cond;
1143
1249
 
1144
1250
  Item *pushed_idx_cond;
1145
 
  uint32_t pushed_idx_cond_keyno;  /* The index which the above condition is for */
 
1251
  uint pushed_idx_cond_keyno;  /* The index which the above condition is for */
1146
1252
 
1147
1253
  /**
1148
1254
    next_insert_id is the next value which should be inserted into the
1170
1276
  handler(handlerton *ht_arg, TABLE_SHARE *share_arg)
1171
1277
    :table_share(share_arg), table(0),
1172
1278
    estimation_rows_to_insert(0), ht(ht_arg),
1173
 
    ref(0), in_range_check_pushed_down(false),
 
1279
    ref(0), in_range_check_pushed_down(FALSE),
1174
1280
    key_used_on_scan(MAX_KEY), active_index(MAX_KEY),
1175
1281
    ref_length(sizeof(my_off_t)),
1176
 
    inited(NONE),
1177
 
    locked(false), implicit_emptied(0),
 
1282
    ft_handler(0), inited(NONE),
 
1283
    locked(FALSE), implicit_emptied(0),
1178
1284
    pushed_cond(0), pushed_idx_cond(NULL), pushed_idx_cond_keyno(MAX_KEY),
1179
1285
    next_insert_id(0), insert_id_for_cur_row(0)
1180
1286
    {}
1181
1287
  virtual ~handler(void)
1182
1288
  {
1183
 
    assert(locked == false);
1184
 
    /* TODO: assert(inited == NONE); */
 
1289
    DBUG_ASSERT(locked == FALSE);
 
1290
    /* TODO: DBUG_ASSERT(inited == NONE); */
1185
1291
  }
1186
1292
  virtual handler *clone(MEM_ROOT *mem_root);
1187
1293
  /** This is called after create to allow us to set up cached variables */
1191
1297
  }
1192
1298
  /* ha_ methods: pubilc wrappers for private virtual API */
1193
1299
 
1194
 
  int ha_open(Table *table, const char *name, int mode, int test_if_locked);
1195
 
  int ha_index_init(uint32_t idx, bool sorted)
 
1300
  int ha_open(TABLE *table, const char *name, int mode, int test_if_locked);
 
1301
  int ha_index_init(uint idx, bool sorted)
1196
1302
  {
1197
1303
    int result;
1198
 
    assert(inited==NONE);
 
1304
    DBUG_ENTER("ha_index_init");
 
1305
    DBUG_ASSERT(inited==NONE);
1199
1306
    if (!(result= index_init(idx, sorted)))
1200
1307
      inited=INDEX;
1201
1308
    end_range= NULL;
1202
 
    return(result);
 
1309
    DBUG_RETURN(result);
1203
1310
  }
1204
1311
  int ha_index_end()
1205
1312
  {
1206
 
    assert(inited==INDEX);
 
1313
    DBUG_ENTER("ha_index_end");
 
1314
    DBUG_ASSERT(inited==INDEX);
1207
1315
    inited=NONE;
1208
1316
    end_range= NULL;
1209
 
    return(index_end());
 
1317
    DBUG_RETURN(index_end());
1210
1318
  }
1211
1319
  int ha_rnd_init(bool scan)
1212
1320
  {
1213
1321
    int result;
1214
 
    assert(inited==NONE || (inited==RND && scan));
 
1322
    DBUG_ENTER("ha_rnd_init");
 
1323
    DBUG_ASSERT(inited==NONE || (inited==RND && scan));
1215
1324
    inited= (result= rnd_init(scan)) ? NONE: RND;
1216
 
    return(result);
 
1325
    DBUG_RETURN(result);
1217
1326
  }
1218
1327
  int ha_rnd_end()
1219
1328
  {
1220
 
    assert(inited==RND);
 
1329
    DBUG_ENTER("ha_rnd_end");
 
1330
    DBUG_ASSERT(inited==RND);
1221
1331
    inited=NONE;
1222
 
    return(rnd_end());
 
1332
    DBUG_RETURN(rnd_end());
1223
1333
  }
1224
1334
  int ha_reset();
1225
1335
  /* this is necessary in many places, e.g. in HANDLER command */
1235
1345
    and delete_row() below.
1236
1346
  */
1237
1347
  int ha_external_lock(THD *thd, int lock_type);
1238
 
  int ha_write_row(unsigned char * buf);
1239
 
  int ha_update_row(const unsigned char * old_data, unsigned char * new_data);
1240
 
  int ha_delete_row(const unsigned char * buf);
 
1348
  int ha_write_row(uchar * buf);
 
1349
  int ha_update_row(const uchar * old_data, uchar * new_data);
 
1350
  int ha_delete_row(const uchar * buf);
1241
1351
  void ha_release_auto_increment();
1242
1352
 
1243
1353
  int ha_check_for_upgrade(HA_CHECK_OPT *check_opt);
1254
1364
    estimation_rows_to_insert= 0;
1255
1365
    return end_bulk_insert();
1256
1366
  }
1257
 
  int ha_bulk_update_row(const unsigned char *old_data, unsigned char *new_data,
1258
 
                         uint32_t *dup_key_found);
 
1367
  int ha_bulk_update_row(const uchar *old_data, uchar *new_data,
 
1368
                         uint *dup_key_found);
1259
1369
  int ha_delete_all_rows();
1260
1370
  int ha_reset_auto_increment(uint64_t value);
1261
1371
  int ha_optimize(THD* thd, HA_CHECK_OPT* check_opt);
1262
1372
  int ha_analyze(THD* thd, HA_CHECK_OPT* check_opt);
1263
1373
  bool ha_check_and_repair(THD *thd);
1264
 
  int ha_disable_indexes(uint32_t mode);
1265
 
  int ha_enable_indexes(uint32_t mode);
1266
 
  int ha_discard_or_import_tablespace(bool discard);
 
1374
  int ha_disable_indexes(uint mode);
 
1375
  int ha_enable_indexes(uint mode);
 
1376
  int ha_discard_or_import_tablespace(my_bool discard);
1267
1377
  void ha_prepare_for_alter();
1268
1378
  int ha_rename_table(const char *from, const char *to);
1269
1379
  int ha_delete_table(const char *name);
1270
1380
  void ha_drop_table(const char *name);
1271
1381
 
1272
 
  int ha_create(const char *name, Table *form, HA_CREATE_INFO *info);
 
1382
  int ha_create(const char *name, TABLE *form, HA_CREATE_INFO *info);
1273
1383
 
1274
1384
  int ha_create_handler_files(const char *name, const char *old_name,
1275
1385
                              int action_flag, HA_CREATE_INFO *info);
1276
1386
 
1277
1387
  void adjust_next_insert_id_after_explicit_value(uint64_t nr);
1278
1388
  int update_auto_increment();
1279
 
  void print_keydup_error(uint32_t key_nr, const char *msg);
 
1389
  void print_keydup_error(uint key_nr, const char *msg);
1280
1390
  virtual void print_error(int error, myf errflag);
1281
1391
  virtual bool get_error_message(int error, String *buf);
1282
 
  uint32_t get_dup_key(int error);
1283
 
  virtual void change_table_ptr(Table *table_arg, TABLE_SHARE *share)
 
1392
  uint get_dup_key(int error);
 
1393
  virtual void change_table_ptr(TABLE *table_arg, TABLE_SHARE *share)
1284
1394
  {
1285
1395
    table= table_arg;
1286
1396
    table_share= share;
1287
1397
  }
1288
1398
  /* Estimates calculation */
1289
 
  virtual double scan_time(void)
1290
 
  { return uint64_t2double(stats.data_file_length) / IO_SIZE + 2; }
1291
 
  virtual double read_time(uint32_t index __attribute__((unused)),
1292
 
                           uint32_t ranges, ha_rows rows)
 
1399
  virtual double scan_time()
 
1400
  { return ulonglong2double(stats.data_file_length) / IO_SIZE + 2; }
 
1401
  virtual double read_time(uint index, uint ranges, ha_rows rows)
1293
1402
  { return rows2double(ranges+rows); }
1294
1403
 
1295
 
  virtual double index_only_read_time(uint32_t keynr, double records);
 
1404
  virtual double index_only_read_time(uint keynr, double records);
1296
1405
  
1297
 
  virtual ha_rows multi_range_read_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
 
1406
  virtual ha_rows multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq,
1298
1407
                                              void *seq_init_param, 
1299
 
                                              uint32_t n_ranges, uint32_t *bufsz,
1300
 
                                              uint32_t *flags, COST_VECT *cost);
1301
 
  virtual int multi_range_read_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys,
1302
 
                                    uint32_t *bufsz, uint32_t *flags, COST_VECT *cost);
 
1408
                                              uint n_ranges, uint *bufsz,
 
1409
                                              uint *flags, COST_VECT *cost);
 
1410
  virtual int multi_range_read_info(uint keyno, uint n_ranges, uint keys,
 
1411
                                    uint *bufsz, uint *flags, COST_VECT *cost);
1303
1412
  virtual int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
1304
 
                                    uint32_t n_ranges, uint32_t mode,
 
1413
                                    uint n_ranges, uint mode,
1305
1414
                                    HANDLER_BUFFER *buf);
1306
1415
  virtual int multi_range_read_next(char **range_info);
1307
1416
 
1309
1418
  virtual const key_map *keys_to_use_for_scanning() { return &key_map_empty; }
1310
1419
  bool has_transactions()
1311
1420
  { return (ha_table_flags() & HA_NO_TRANSACTIONS) == 0; }
1312
 
  virtual uint32_t extra_rec_buf_length() const { return 0; }
 
1421
  virtual uint extra_rec_buf_length() const { return 0; }
1313
1422
 
1314
1423
  /**
1315
1424
    This method is used to analyse the error to see whether the error
1321
1430
    same thing as HA_ERR_FOUND_DUP_KEY but can in some cases lead to
1322
1431
    a slightly different error message.
1323
1432
  */
1324
 
  virtual bool is_fatal_error(int error, uint32_t flags)
 
1433
  virtual bool is_fatal_error(int error, uint flags)
1325
1434
  {
1326
1435
    if (!error ||
1327
1436
        ((flags & HA_CHECK_DUP_KEY) &&
1328
1437
         (error == HA_ERR_FOUND_DUPP_KEY ||
1329
1438
          error == HA_ERR_FOUND_DUPP_UNIQUE)))
1330
 
      return false;
1331
 
    return true;
 
1439
      return FALSE;
 
1440
    return TRUE;
1332
1441
  }
1333
1442
 
1334
1443
  /**
1351
1460
  */
1352
1461
  virtual enum row_type get_row_type() const { return ROW_TYPE_NOT_USED; }
1353
1462
 
1354
 
  virtual const char *index_type(uint32_t key_number __attribute__((unused)))
1355
 
  { assert(0); return "";}
 
1463
  virtual const char *index_type(uint key_number) { DBUG_ASSERT(0); return "";}
1356
1464
 
1357
1465
 
1358
1466
  /**
1363
1471
    as there may be several calls to this routine.
1364
1472
  */
1365
1473
  virtual void column_bitmaps_signal();
1366
 
  uint32_t get_index(void) const { return active_index; }
 
1474
  uint get_index(void) const { return active_index; }
1367
1475
  virtual int close(void)=0;
1368
1476
 
1369
1477
  /**
1387
1495
    @retval  0           Success
1388
1496
    @retval  >0          Error code
1389
1497
  */
1390
 
  virtual int exec_bulk_update(uint32_t *dup_key_found __attribute__((unused)))
 
1498
  virtual int exec_bulk_update(uint *dup_key_found)
1391
1499
  {
1392
 
    assert(false);
 
1500
    DBUG_ASSERT(FALSE);
1393
1501
    return HA_ERR_WRONG_COMMAND;
1394
1502
  }
1395
1503
  /**
1405
1513
  */
1406
1514
  virtual int end_bulk_delete()
1407
1515
  {
1408
 
    assert(false);
 
1516
    DBUG_ASSERT(FALSE);
1409
1517
    return HA_ERR_WRONG_COMMAND;
1410
1518
  }
1411
1519
  /**
1414
1522
     row if available. If the key value is null, begin at the first key of the
1415
1523
     index.
1416
1524
  */
1417
 
  virtual int index_read_map(unsigned char * buf, const unsigned char * key,
 
1525
  virtual int index_read_map(uchar * buf, const uchar * key,
1418
1526
                             key_part_map keypart_map,
1419
1527
                             enum ha_rkey_function find_flag)
1420
1528
  {
1421
 
    uint32_t key_len= calculate_key_len(table, active_index, key, keypart_map);
 
1529
    uint key_len= calculate_key_len(table, active_index, key, keypart_map);
1422
1530
    return  index_read(buf, key, key_len, find_flag);
1423
1531
  }
1424
1532
  /**
1427
1535
     row if available. If the key value is null, begin at the first key of the
1428
1536
     index.
1429
1537
  */
1430
 
  virtual int index_read_idx_map(unsigned char * buf, uint32_t index, const unsigned char * key,
 
1538
  virtual int index_read_idx_map(uchar * buf, uint index, const uchar * key,
1431
1539
                                 key_part_map keypart_map,
1432
1540
                                 enum ha_rkey_function find_flag);
1433
 
  virtual int index_next(unsigned char * buf __attribute__((unused)))
1434
 
   { return  HA_ERR_WRONG_COMMAND; }
1435
 
  virtual int index_prev(unsigned char * buf __attribute__((unused)))
1436
 
   { return  HA_ERR_WRONG_COMMAND; }
1437
 
  virtual int index_first(unsigned char * buf __attribute__((unused)))
1438
 
   { return  HA_ERR_WRONG_COMMAND; }
1439
 
  virtual int index_last(unsigned char * buf __attribute__((unused)))
1440
 
   { return  HA_ERR_WRONG_COMMAND; }
1441
 
  virtual int index_next_same(unsigned char *buf __attribute__((unused)),
1442
 
                              const unsigned char *key __attribute__((unused)),
1443
 
                              uint32_t keylen __attribute__((unused)));
 
1541
  virtual int index_next(uchar * buf)
 
1542
   { return  HA_ERR_WRONG_COMMAND; }
 
1543
  virtual int index_prev(uchar * buf)
 
1544
   { return  HA_ERR_WRONG_COMMAND; }
 
1545
  virtual int index_first(uchar * buf)
 
1546
   { return  HA_ERR_WRONG_COMMAND; }
 
1547
  virtual int index_last(uchar * buf)
 
1548
   { return  HA_ERR_WRONG_COMMAND; }
 
1549
  virtual int index_next_same(uchar *buf, const uchar *key, uint keylen);
1444
1550
  /**
1445
1551
     @brief
1446
1552
     The following functions works like index_read, but it find the last
1447
1553
     row with the current key value or prefix.
1448
1554
  */
1449
 
  virtual int index_read_last_map(unsigned char * buf, const unsigned char * key,
 
1555
  virtual int index_read_last_map(uchar * buf, const uchar * key,
1450
1556
                                  key_part_map keypart_map)
1451
1557
  {
1452
 
    uint32_t key_len= calculate_key_len(table, active_index, key, keypart_map);
 
1558
    uint key_len= calculate_key_len(table, active_index, key, keypart_map);
1453
1559
    return index_read_last(buf, key, key_len);
1454
1560
  }
1455
1561
  virtual int read_range_first(const key_range *start_key,
1458
1564
  virtual int read_range_next();
1459
1565
  int compare_key(key_range *range);
1460
1566
  int compare_key2(key_range *range);
1461
 
  virtual int rnd_next(unsigned char *buf __attribute__((unused)))=0;
1462
 
  virtual int rnd_pos(unsigned char * buf __attribute__((unused)),
1463
 
                      unsigned char *pos __attribute__((unused)))=0;
 
1567
  virtual int ft_init() { return HA_ERR_WRONG_COMMAND; }
 
1568
  void ft_end() { ft_handler=NULL; }
 
1569
  virtual FT_INFO *ft_init_ext(uint flags, uint inx,String *key)
 
1570
    { return NULL; }
 
1571
  virtual int ft_read(uchar *buf) { return HA_ERR_WRONG_COMMAND; }
 
1572
  virtual int rnd_next(uchar *buf)=0;
 
1573
  virtual int rnd_pos(uchar * buf, uchar *pos)=0;
1464
1574
  /**
1465
1575
    One has to use this method when to find
1466
1576
    random position by record as the plain
1467
1577
    position() call doesn't work for some
1468
1578
    handlers for random position.
1469
1579
  */
1470
 
  virtual int rnd_pos_by_record(unsigned char *record);
1471
 
  virtual int read_first_row(unsigned char *buf, uint32_t primary_key);
 
1580
  virtual int rnd_pos_by_record(uchar *record);
 
1581
  virtual int read_first_row(uchar *buf, uint primary_key);
1472
1582
  /**
1473
1583
    The following function is only needed for tables that may be temporary
1474
1584
    tables during joins.
1475
1585
  */
1476
 
  virtual int restart_rnd_next(unsigned char *buf __attribute__((unused)),
1477
 
                               unsigned char *pos __attribute__((unused)))
1478
 
    { return HA_ERR_WRONG_COMMAND; }
1479
 
  virtual int rnd_same(unsigned char *buf __attribute__((unused)),
1480
 
                       uint32_t inx __attribute__((unused)))
1481
 
    { return HA_ERR_WRONG_COMMAND; }
1482
 
  virtual ha_rows records_in_range(uint32_t inx __attribute__((unused)),
1483
 
                                   key_range *min_key __attribute__((unused)),
1484
 
                                   key_range *max_key __attribute__((unused)))
 
1586
  virtual int restart_rnd_next(uchar *buf, uchar *pos)
 
1587
    { return HA_ERR_WRONG_COMMAND; }
 
1588
  virtual int rnd_same(uchar *buf, uint inx)
 
1589
    { return HA_ERR_WRONG_COMMAND; }
 
1590
  virtual ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key)
1485
1591
    { return (ha_rows) 10; }
1486
 
  virtual void position(const unsigned char *record)=0;
 
1592
  virtual void position(const uchar *record)=0;
1487
1593
  virtual int info(uint)=0; // see my_base.h for full description
1488
 
  virtual uint32_t calculate_key_hash_value(Field **field_array __attribute__((unused)))
1489
 
  { assert(0); return 0; }
1490
 
  virtual int extra(enum ha_extra_function operation __attribute__((unused)))
 
1594
  virtual uint32 calculate_key_hash_value(Field **field_array)
 
1595
  { DBUG_ASSERT(0); return 0; }
 
1596
  virtual int extra(enum ha_extra_function operation)
1491
1597
  { return 0; }
1492
 
  virtual int extra_opt(enum ha_extra_function operation,
1493
 
                        uint32_t cache_size __attribute__((unused)))
 
1598
  virtual int extra_opt(enum ha_extra_function operation, ulong cache_size)
1494
1599
  { return extra(operation); }
1495
1600
 
1496
1601
  /**
1513
1618
    the last committed row value under the cursor.
1514
1619
  */
1515
1620
  virtual void try_semi_consistent_read(bool) {}
1516
 
  virtual void unlock_row(void) {}
1517
 
  virtual int start_stmt(THD *thd __attribute__((unused)),
1518
 
                         thr_lock_type lock_type __attribute__((unused)))
1519
 
  {return 0;}
 
1621
  virtual void unlock_row() {}
 
1622
  virtual int start_stmt(THD *thd, thr_lock_type lock_type) {return 0;}
1520
1623
  virtual void get_auto_increment(uint64_t offset, uint64_t increment,
1521
1624
                                  uint64_t nb_desired_values,
1522
1625
                                  uint64_t *first_value,
1523
1626
                                  uint64_t *nb_reserved_values);
1524
1627
  void set_next_insert_id(uint64_t id)
1525
1628
  {
 
1629
    DBUG_PRINT("info",("auto_increment: next value %lu", (ulong)id));
1526
1630
    next_insert_id= id;
1527
1631
  }
1528
1632
  void restore_auto_increment(uint64_t prev_insert_id)
1541
1645
      insert_id_for_cur_row;
1542
1646
  }
1543
1647
 
1544
 
  virtual void update_create_info(HA_CREATE_INFO *create_info __attribute__((unused))) {}
1545
 
  int check_old_types(void);
1546
 
  virtual int assign_to_keycache(THD* thd __attribute__((unused)),
1547
 
                                 HA_CHECK_OPT* check_opt __attribute__((unused)))
 
1648
  virtual void update_create_info(HA_CREATE_INFO *create_info) {}
 
1649
  int check_old_types();
 
1650
  virtual int assign_to_keycache(THD* thd, HA_CHECK_OPT* check_opt)
 
1651
  { return HA_ADMIN_NOT_IMPLEMENTED; }
 
1652
  virtual int preload_keys(THD* thd, HA_CHECK_OPT* check_opt)
1548
1653
  { return HA_ADMIN_NOT_IMPLEMENTED; }
1549
1654
  /* end of the list of admin commands */
1550
1655
 
1551
1656
  virtual int indexes_are_disabled(void) {return 0;}
1552
1657
  virtual char *update_table_comment(const char * comment)
1553
1658
  { return (char*) comment;}
1554
 
  virtual void append_create_info(String *packet __attribute__((unused)))
1555
 
  {}
 
1659
  virtual void append_create_info(String *packet) {}
1556
1660
  /**
1557
1661
      If index == MAX_KEY then a check for table is made and if index <
1558
1662
      MAX_KEY then a check is made if the table has foreign keys and if
1560
1664
 
1561
1665
    @param  index            Index to check if foreign key uses it
1562
1666
 
1563
 
    @retval   true            Foreign key defined on table or index
1564
 
    @retval   false           No foreign key defined
 
1667
    @retval   TRUE            Foreign key defined on table or index
 
1668
    @retval   FALSE           No foreign key defined
1565
1669
  */
1566
 
  virtual bool is_fk_defined_on_table_or_index(uint32_t index __attribute__((unused)))
1567
 
  { return false; }
1568
 
  virtual char* get_foreign_key_create_info(void)
 
1670
  virtual bool is_fk_defined_on_table_or_index(uint index)
 
1671
  { return FALSE; }
 
1672
  virtual char* get_foreign_key_create_info()
1569
1673
  { return(NULL);}  /* gets foreign key create string from InnoDB */
1570
 
  /** used in ALTER Table; 1 if changing storage engine is allowed */
1571
 
  virtual bool can_switch_engines(void) { return 1; }
 
1674
  /* gets tablespace name from handler */
 
1675
  const char* get_tablespace_name();
 
1676
  /** used in ALTER TABLE; 1 if changing storage engine is allowed */
 
1677
  virtual bool can_switch_engines() { return 1; }
1572
1678
  /** used in REPLACE; is > 0 if table is referred by a FOREIGN KEY */
1573
 
  virtual int get_foreign_key_list(THD *thd __attribute__((unused)),
1574
 
                                   List<FOREIGN_KEY_INFO> *f_key_list __attribute__((unused)))
 
1679
  virtual int get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list)
1575
1680
  { return 0; }
1576
 
  virtual uint32_t referenced_by_foreign_key() { return 0;}
 
1681
  virtual uint referenced_by_foreign_key() { return 0;}
1577
1682
  virtual void init_table_handle_for_HANDLER()
1578
1683
  { return; }       /* prepare InnoDB for HANDLER */
1579
 
  virtual void free_foreign_key_create_info(char* str __attribute__((unused))) {}
 
1684
  virtual void free_foreign_key_create_info(char* str) {}
1580
1685
  /** The following can be called without an open handler */
1581
1686
  virtual const char *table_type() const =0;
1582
1687
  /**
1588
1693
    and data file), the order of elements is relevant. First element of engine
1589
1694
    file name extentions array should be meta/index file extention. Second
1590
1695
    element - data file extention. This order is assumed by
1591
 
    prepare_for_repair() when REPAIR Table ... USE_FRM is issued.
 
1696
    prepare_for_repair() when REPAIR TABLE ... USE_FRM is issued.
1592
1697
  */
1593
1698
  virtual const char **bas_ext() const =0;
1594
1699
 
1595
 
  virtual int get_default_no_partitions(HA_CREATE_INFO *info __attribute__((unused))) { return 1;}
1596
 
  virtual bool get_no_parts(const char *name __attribute__((unused)),
1597
 
                            uint32_t *no_parts)
 
1700
  virtual int get_default_no_partitions(HA_CREATE_INFO *info) { return 1;}
 
1701
  virtual bool get_no_parts(const char *name,
 
1702
                            uint *no_parts)
1598
1703
  {
1599
1704
    *no_parts= 0;
1600
1705
    return 0;
1601
1706
  }
1602
1707
 
1603
 
  virtual uint32_t index_flags(uint32_t idx, uint32_t part, bool all_parts) const =0;
1604
 
 
1605
 
  virtual int add_index(Table *table_arg __attribute__((unused)),
1606
 
                        KEY *key_info __attribute__((unused)),
1607
 
                        uint32_t num_of_keys __attribute__((unused)))
1608
 
  { return (HA_ERR_WRONG_COMMAND); }
1609
 
  virtual int prepare_drop_index(Table *table_arg __attribute__((unused)),
1610
 
                                 uint32_t *key_num __attribute__((unused)),
1611
 
                                 uint32_t num_of_keys __attribute__((unused)))
1612
 
  { return (HA_ERR_WRONG_COMMAND); }
1613
 
  virtual int final_drop_index(Table *table_arg __attribute__((unused)))
1614
 
  { return (HA_ERR_WRONG_COMMAND); }
1615
 
 
1616
 
  uint32_t max_record_length() const
1617
 
  { return cmin((unsigned int)HA_MAX_REC_LENGTH, max_supported_record_length()); }
1618
 
  uint32_t max_keys() const
1619
 
  { return cmin((unsigned int)MAX_KEY, max_supported_keys()); }
1620
 
  uint32_t max_key_parts() const
1621
 
  { return cmin((unsigned int)MAX_REF_PARTS, max_supported_key_parts()); }
1622
 
  uint32_t max_key_length() const
1623
 
  { return cmin((unsigned int)MAX_KEY_LENGTH, max_supported_key_length()); }
1624
 
  uint32_t max_key_part_length(void) const
1625
 
  { return cmin((unsigned int)MAX_KEY_LENGTH, max_supported_key_part_length()); }
1626
 
 
1627
 
  virtual uint32_t max_supported_record_length(void) const
1628
 
  { return HA_MAX_REC_LENGTH; }
1629
 
  virtual uint32_t max_supported_keys(void) const { return 0; }
1630
 
  virtual uint32_t max_supported_key_parts(void) const { return MAX_REF_PARTS; }
1631
 
  virtual uint32_t max_supported_key_length(void) const { return MAX_KEY_LENGTH; }
1632
 
  virtual uint32_t max_supported_key_part_length(void) const { return 255; }
1633
 
  virtual uint32_t min_record_length(uint32_t options __attribute__((unused))) const
1634
 
  { return 1; }
1635
 
 
1636
 
  virtual bool low_byte_first(void) const { return 1; }
1637
 
  virtual uint32_t checksum(void) const { return 0; }
1638
 
  virtual bool is_crashed(void) const  { return 0; }
1639
 
  virtual bool auto_repair(void) const { return 0; }
 
1708
  virtual ulong index_flags(uint idx, uint part, bool all_parts) const =0;
 
1709
 
 
1710
  virtual int add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys)
 
1711
  { return (HA_ERR_WRONG_COMMAND); }
 
1712
  virtual int prepare_drop_index(TABLE *table_arg, uint *key_num,
 
1713
                                 uint num_of_keys)
 
1714
  { return (HA_ERR_WRONG_COMMAND); }
 
1715
  virtual int final_drop_index(TABLE *table_arg)
 
1716
  { return (HA_ERR_WRONG_COMMAND); }
 
1717
 
 
1718
  uint max_record_length() const
 
1719
  { return min(HA_MAX_REC_LENGTH, max_supported_record_length()); }
 
1720
  uint max_keys() const
 
1721
  { return min(MAX_KEY, max_supported_keys()); }
 
1722
  uint max_key_parts() const
 
1723
  { return min(MAX_REF_PARTS, max_supported_key_parts()); }
 
1724
  uint max_key_length() const
 
1725
  { return min(MAX_KEY_LENGTH, max_supported_key_length()); }
 
1726
  uint max_key_part_length() const
 
1727
  { return min(MAX_KEY_LENGTH, max_supported_key_part_length()); }
 
1728
 
 
1729
  virtual uint max_supported_record_length() const { return HA_MAX_REC_LENGTH; }
 
1730
  virtual uint max_supported_keys() const { return 0; }
 
1731
  virtual uint max_supported_key_parts() const { return MAX_REF_PARTS; }
 
1732
  virtual uint max_supported_key_length() const { return MAX_KEY_LENGTH; }
 
1733
  virtual uint max_supported_key_part_length() const { return 255; }
 
1734
  virtual uint min_record_length(uint options) const { return 1; }
 
1735
 
 
1736
  virtual bool low_byte_first() const { return 1; }
 
1737
  virtual uint checksum() const { return 0; }
 
1738
  virtual bool is_crashed() const  { return 0; }
 
1739
  virtual bool auto_repair() const { return 0; }
1640
1740
 
1641
1741
 
1642
1742
#define CHF_CREATE_FLAG 0
1647
1747
  /**
1648
1748
    @note lock_count() can return > 1 if the table is MERGE or partitioned.
1649
1749
  */
1650
 
  virtual uint32_t lock_count(void) const { return 1; }
 
1750
  virtual uint lock_count(void) const { return 1; }
1651
1751
  /**
1652
1752
    Is not invoked for non-transactional temporary tables.
1653
1753
 
1666
1766
                                     enum thr_lock_type lock_type)=0;
1667
1767
 
1668
1768
  /** Type of table for caching query */
1669
 
  virtual uint8_t table_cache_type() { return HA_CACHE_TBL_NONTRANSACT; }
 
1769
  virtual uint8 table_cache_type() { return HA_CACHE_TBL_NONTRANSACT; }
1670
1770
 
1671
1771
 
1672
1772
  /**
1689
1789
 
1690
1790
    @note If engine_data supplied with this function is different from
1691
1791
      engine_data supplied with the callback function, and the callback returns
1692
 
      false, a table invalidation on the current table will occur.
 
1792
      FALSE, a table invalidation on the current table will occur.
1693
1793
 
1694
1794
    @return Upon success the engine_callback will point to the storage engine
1695
1795
      call back function, if any, and engine_data will point to any storage
1696
1796
      engine data used in the specific implementation.
1697
 
      @retval true Success
1698
 
      @retval false The specified table or current statement should not be
 
1797
      @retval TRUE Success
 
1798
      @retval FALSE The specified table or current statement should not be
1699
1799
        cached
1700
1800
  */
1701
1801
 
1702
 
  virtual bool
1703
 
    register_query_cache_table(THD *thd __attribute__((unused)),
1704
 
                               char *table_key __attribute__((unused)),
1705
 
                               uint32_t key_length __attribute__((unused)),
1706
 
                               qc_engine_callback *engine_callback,
1707
 
                               uint64_t *engine_data __attribute__((unused)))
 
1802
  virtual my_bool register_query_cache_table(THD *thd, char *table_key,
 
1803
                                             uint key_length,
 
1804
                                             qc_engine_callback
 
1805
                                             *engine_callback,
 
1806
                                             uint64_t *engine_data)
1708
1807
  {
1709
1808
    *engine_callback= 0;
1710
 
    return true;
 
1809
    return TRUE;
1711
1810
  }
1712
1811
 
1713
1812
 
1714
1813
 /*
1715
 
   @retval true   Primary key (if there is one) is clustered
 
1814
   @retval TRUE   Primary key (if there is one) is clustered
1716
1815
                  key covering all fields
1717
 
   @retval false  otherwise
 
1816
   @retval FALSE  otherwise
1718
1817
 */
1719
 
 virtual bool primary_key_is_clustered() { return false; }
1720
 
 virtual int cmp_ref(const unsigned char *ref1, const unsigned char *ref2)
 
1818
 virtual bool primary_key_is_clustered() { return FALSE; }
 
1819
 virtual int cmp_ref(const uchar *ref1, const uchar *ref2)
1721
1820
 {
1722
1821
   return memcmp(ref1, ref2, ref_length);
1723
1822
 }
1749
1848
   condition stack.
1750
1849
 */ 
1751
1850
 virtual const COND *cond_push(const COND *cond) { return cond; }
1752
 
 
 
1851
 
1753
1852
 /**
1754
1853
   Pop the top condition from the condition stack of the handler instance.
1755
1854
 
1756
1855
   Pops the top if condition stack, if stack is not empty.
1757
1856
 */
1758
 
 virtual void cond_pop(void) { return; }
 
1857
 virtual void cond_pop() { return; }
1759
1858
 
1760
 
 virtual Item
1761
 
   *idx_cond_push(uint32_t keyno __attribute__((unused)),
1762
 
                  Item* idx_cond __attribute__((unused)))
1763
 
 { return idx_cond; }
 
1859
 virtual Item *idx_cond_push(uint keyno, Item* idx_cond) { return idx_cond; }
1764
1860
 
1765
1861
 /*
1766
1862
    Part of old fast alter table, to be depricated
1767
1863
  */
1768
 
 virtual bool
1769
 
   check_if_incompatible_data(HA_CREATE_INFO *create_info __attribute__((unused)),
1770
 
                              uint32_t table_changes __attribute__((unused)))
 
1864
 virtual bool check_if_incompatible_data(HA_CREATE_INFO *create_info,
 
1865
                                         uint table_changes)
1771
1866
 { return COMPATIBLE_DATA_NO; }
1772
1867
 
1773
 
 /* On-line ALTER Table interface */
 
1868
 /* On-line ALTER TABLE interface */
1774
1869
 
1775
1870
 /**
1776
1871
    Check if a storage engine supports a particular alter table on-line
1793
1888
      The default implementation is implemented to support fast
1794
1889
      alter table (storage engines that support some changes by
1795
1890
      just changing the frm file) without any change in the handler
1796
 
      implementation.
 
1891
      implementation.    
1797
1892
 */
1798
 
 virtual int
1799
 
   check_if_supported_alter(Table *altered_table __attribute__((unused)),
1800
 
                            HA_CREATE_INFO *create_info,
1801
 
                            HA_ALTER_FLAGS *alter_flags __attribute__((unused)),
1802
 
                            uint32_t table_changes)
 
1893
 virtual int check_if_supported_alter(TABLE *altered_table,
 
1894
                                      HA_CREATE_INFO *create_info,
 
1895
                                      HA_ALTER_FLAGS *alter_flags,
 
1896
                                      uint table_changes)
1803
1897
 {
 
1898
   DBUG_ENTER("check_if_supported_alter");
1804
1899
   if (this->check_if_incompatible_data(create_info, table_changes)
1805
1900
       == COMPATIBLE_DATA_NO)
1806
 
     return(HA_ALTER_NOT_SUPPORTED);
 
1901
     DBUG_RETURN(HA_ALTER_NOT_SUPPORTED);
1807
1902
   else
1808
 
     return(HA_ALTER_SUPPORTED_WAIT_LOCK);
 
1903
     DBUG_RETURN(HA_ALTER_SUPPORTED_WAIT_LOCK);
1809
1904
 }
1810
1905
 /**
1811
1906
   Tell storage engine to prepare for the on-line alter table (pre-alter)
1820
1915
   @retval   0      OK
1821
1916
   @retval   error  error code passed from storage engine
1822
1917
 */
1823
 
 virtual int alter_table_phase1(THD *thd __attribute__((unused)),
1824
 
                                Table *altered_table __attribute__((unused)),
1825
 
                                HA_CREATE_INFO *create_info __attribute__((unused)),
1826
 
                                HA_ALTER_INFO *alter_info __attribute__((unused)),
1827
 
                                HA_ALTER_FLAGS *alter_flags  __attribute__((unused)))
 
1918
 virtual int alter_table_phase1(THD *thd,
 
1919
                                TABLE *altered_table,
 
1920
                                HA_CREATE_INFO *create_info,
 
1921
                                HA_ALTER_INFO *alter_info,
 
1922
                                HA_ALTER_FLAGS *alter_flags)
1828
1923
 {
1829
1924
   return HA_ERR_UNSUPPORTED;
1830
1925
 }
1846
1941
      this call is to be wrapped with a DDL lock. This is currently NOT
1847
1942
      supported.
1848
1943
 */
1849
 
 virtual int alter_table_phase2(THD *thd  __attribute__((unused)),
1850
 
                                Table *altered_table  __attribute__((unused)),
1851
 
                                HA_CREATE_INFO *create_info __attribute__((unused)),
1852
 
                                HA_ALTER_INFO *alter_info __attribute__((unused)),
1853
 
                                HA_ALTER_FLAGS *alter_flags __attribute__((unused)))
 
1944
 virtual int alter_table_phase2(THD *thd,
 
1945
                                TABLE *altered_table,
 
1946
                                HA_CREATE_INFO *create_info,
 
1947
                                HA_ALTER_INFO *alter_info,
 
1948
                                HA_ALTER_FLAGS *alter_flags)
1854
1949
 {
1855
1950
   return HA_ERR_UNSUPPORTED;
1856
1951
 }
1861
1956
    @param    thd               The thread handle
1862
1957
    @param    table             The altered table, re-opened
1863
1958
 */
1864
 
 virtual int alter_table_phase3(THD *thd __attribute__((unused)),
1865
 
                                Table *table __attribute__((unused)))
 
1959
 virtual int alter_table_phase3(THD *thd, TABLE *table)
1866
1960
 {
1867
1961
   return HA_ERR_UNSUPPORTED;
1868
1962
 }
1935
2029
    the corresponding 'ha_*' method above.
1936
2030
  */
1937
2031
 
1938
 
  virtual int open(const char *name, int mode, uint32_t test_if_locked)=0;
1939
 
  virtual int index_init(uint32_t idx,
1940
 
                         bool sorted __attribute__((unused)))
1941
 
  { active_index= idx; return 0; }
 
2032
  virtual int open(const char *name, int mode, uint test_if_locked)=0;
 
2033
  virtual int index_init(uint idx, bool sorted) { active_index= idx; return 0; }
1942
2034
  virtual int index_end() { active_index= MAX_KEY; return 0; }
1943
2035
  /**
1944
2036
    rnd_init() can be called two times without rnd_end() in between
1949
2041
  */
1950
2042
  virtual int rnd_init(bool scan)= 0;
1951
2043
  virtual int rnd_end() { return 0; }
1952
 
  virtual int write_row(unsigned char *buf __attribute__((unused)))
1953
 
  {
1954
 
    return HA_ERR_WRONG_COMMAND;
1955
 
  }
1956
 
 
1957
 
  virtual int update_row(const unsigned char *old_data __attribute__((unused)),
1958
 
                         unsigned char *new_data __attribute__((unused)))
1959
 
  {
1960
 
    return HA_ERR_WRONG_COMMAND;
1961
 
  }
1962
 
 
1963
 
  virtual int delete_row(const unsigned char *buf __attribute__((unused)))
 
2044
  virtual int write_row(uchar *buf __attribute__((unused)))
 
2045
  {
 
2046
    return HA_ERR_WRONG_COMMAND;
 
2047
  }
 
2048
 
 
2049
  virtual int update_row(const uchar *old_data __attribute__((unused)),
 
2050
                         uchar *new_data __attribute__((unused)))
 
2051
  {
 
2052
    return HA_ERR_WRONG_COMMAND;
 
2053
  }
 
2054
 
 
2055
  virtual int delete_row(const uchar *buf __attribute__((unused)))
1964
2056
  {
1965
2057
    return HA_ERR_WRONG_COMMAND;
1966
2058
  }
1999
2091
  {
2000
2092
    return 0;
2001
2093
  }
2002
 
  virtual void release_auto_increment(void) { return; };
 
2094
  virtual void release_auto_increment() { return; };
2003
2095
  /** admin commands - called from mysql_admin_table */
2004
 
  virtual int check_for_upgrade(HA_CHECK_OPT *check_opt __attribute__((unused)))
 
2096
  virtual int check_for_upgrade(HA_CHECK_OPT *check_opt)
2005
2097
  { return 0; }
2006
 
  virtual int check(THD* thd __attribute__((unused)),
2007
 
                    HA_CHECK_OPT* check_opt __attribute__((unused)))
 
2098
  virtual int check(THD* thd, HA_CHECK_OPT* check_opt)
2008
2099
  { return HA_ADMIN_NOT_IMPLEMENTED; }
2009
2100
 
2010
2101
  /**
2012
2103
     to specify CHECK option to use to call check()
2013
2104
     upon the table.
2014
2105
  */
2015
 
  virtual int repair(THD* thd __attribute__((unused)),
2016
 
                     HA_CHECK_OPT* check_opt __attribute__((unused)))
 
2106
  virtual int repair(THD* thd, HA_CHECK_OPT* check_opt)
2017
2107
  { return HA_ADMIN_NOT_IMPLEMENTED; }
2018
 
  virtual void start_bulk_insert(ha_rows rows __attribute__((unused)))
2019
 
  {}
2020
 
  virtual int end_bulk_insert(void) { return 0; }
2021
 
  virtual int index_read(unsigned char * buf __attribute__((unused)),
2022
 
                         const unsigned char * key __attribute__((unused)),
2023
 
                         uint32_t key_len __attribute__((unused)),
2024
 
                         enum ha_rkey_function find_flag __attribute__((unused)))
 
2108
  virtual void start_bulk_insert(ha_rows rows) {}
 
2109
  virtual int end_bulk_insert() { return 0; }
 
2110
  virtual int index_read(uchar * buf, const uchar * key, uint key_len,
 
2111
                         enum ha_rkey_function find_flag)
2025
2112
   { return  HA_ERR_WRONG_COMMAND; }
2026
 
  virtual int index_read_last(unsigned char * buf __attribute__((unused)),
2027
 
                              const unsigned char * key __attribute__((unused)),
2028
 
                              uint32_t key_len __attribute__((unused)))
 
2113
  virtual int index_read_last(uchar * buf, const uchar * key, uint key_len)
2029
2114
   { return (my_errno= HA_ERR_WRONG_COMMAND); }
2030
2115
  /**
2031
2116
    This method is similar to update_row, however the handler doesn't need
2040
2125
    @retval  0   Bulk delete used by handler
2041
2126
    @retval  1   Bulk delete not used, normal operation used
2042
2127
  */
2043
 
  virtual int bulk_update_row(const unsigned char *old_data __attribute__((unused)),
2044
 
                              unsigned char *new_data __attribute__((unused)),
2045
 
                              uint32_t *dup_key_found __attribute__((unused)))
 
2128
  virtual int bulk_update_row(const uchar *old_data, uchar *new_data,
 
2129
                              uint *dup_key_found)
2046
2130
  {
2047
 
    assert(false);
 
2131
    DBUG_ASSERT(FALSE);
2048
2132
    return HA_ERR_WRONG_COMMAND;
2049
2133
  }
2050
2134
  /**
2053
2137
    return HA_ERR_WRONG_COMMAND and MySQL will delete the rows one
2054
2138
    by one.
2055
2139
  */
2056
 
  virtual int delete_all_rows(void)
 
2140
  virtual int delete_all_rows()
2057
2141
  { return (my_errno=HA_ERR_WRONG_COMMAND); }
2058
2142
  /**
2059
2143
    Reset the auto-increment counter to the given value, i.e. the next row
2061
2145
    is emulated by doing a 'DELETE FROM t'. HA_ERR_WRONG_COMMAND is
2062
2146
    returned by storage engines that don't support this operation.
2063
2147
  */
2064
 
  virtual int reset_auto_increment(uint64_t value __attribute__((unused)))
2065
 
  { return HA_ERR_WRONG_COMMAND; }
2066
 
  virtual int optimize(THD* thd __attribute__((unused)),
2067
 
                       HA_CHECK_OPT* check_opt __attribute__((unused)))
2068
 
  { return HA_ADMIN_NOT_IMPLEMENTED; }
2069
 
  virtual int analyze(THD* thd __attribute__((unused)),
2070
 
                      HA_CHECK_OPT* check_opt __attribute__((unused)))
2071
 
  { return HA_ADMIN_NOT_IMPLEMENTED; }
2072
 
  virtual bool check_and_repair(THD *thd __attribute__((unused)))
2073
 
  { return true; }
2074
 
  virtual int disable_indexes(uint32_t mode __attribute__((unused)))
2075
 
  { return HA_ERR_WRONG_COMMAND; }
2076
 
  virtual int enable_indexes(uint32_t mode __attribute__((unused)))
2077
 
  { return HA_ERR_WRONG_COMMAND; }
2078
 
  virtual int discard_or_import_tablespace(bool discard __attribute__((unused)))
 
2148
  virtual int reset_auto_increment(uint64_t value)
 
2149
  { return HA_ERR_WRONG_COMMAND; }
 
2150
  virtual int optimize(THD* thd, HA_CHECK_OPT* check_opt)
 
2151
  { return HA_ADMIN_NOT_IMPLEMENTED; }
 
2152
  virtual int analyze(THD* thd, HA_CHECK_OPT* check_opt)
 
2153
  { return HA_ADMIN_NOT_IMPLEMENTED; }
 
2154
  virtual bool check_and_repair(THD *thd) { return TRUE; }
 
2155
  virtual int disable_indexes(uint mode) { return HA_ERR_WRONG_COMMAND; }
 
2156
  virtual int enable_indexes(uint mode) { return HA_ERR_WRONG_COMMAND; }
 
2157
  virtual int discard_or_import_tablespace(my_bool discard)
2079
2158
  { return (my_errno=HA_ERR_WRONG_COMMAND); }
2080
 
  virtual void prepare_for_alter(void) { return; }
 
2159
  virtual void prepare_for_alter() { return; }
2081
2160
  virtual void drop_table(const char *name);
2082
 
  virtual int create(const char *name __attribute__((unused)),
2083
 
                     Table *form __attribute__((unused)),
2084
 
                     HA_CREATE_INFO *info __attribute__((unused)))=0;
 
2161
  virtual int create(const char *name, TABLE *form, HA_CREATE_INFO *info)=0;
2085
2162
 
2086
 
  virtual int create_handler_files(const char *name __attribute__((unused)),
2087
 
                                   const char *old_name __attribute__((unused)),
2088
 
                                   int action_flag __attribute__((unused)),
2089
 
                                   HA_CREATE_INFO *info __attribute__((unused)))
2090
 
  { return false; }
 
2163
  virtual int create_handler_files(const char *name, const char *old_name,
 
2164
                                   int action_flag, HA_CREATE_INFO *info)
 
2165
  { return FALSE; }
2091
2166
};
2092
2167
 
2093
2168
 
2111
2186
    : h2(NULL) {};
2112
2187
 
2113
2188
  handler *h; /* The "owner" handler object. It is used for scanning the index */
2114
 
  Table *table; /* Always equal to h->table */
 
2189
  TABLE *table; /* Always equal to h->table */
2115
2190
private:
2116
2191
  /*
2117
2192
    Secondary handler object. It is used to retrieve full table rows by
2120
2195
  handler *h2;
2121
2196
 
2122
2197
  /* Buffer to store rowids, or (rowid, range_id) pairs */
2123
 
  unsigned char *rowids_buf;
2124
 
  unsigned char *rowids_buf_cur;   /* Current position when reading/writing */
2125
 
  unsigned char *rowids_buf_last;  /* When reading: end of used buffer space */
2126
 
  unsigned char *rowids_buf_end;   /* End of the buffer */
2127
 
 
2128
 
  bool dsmrr_eof; /* true <=> We have reached EOF when reading index tuples */
2129
 
 
2130
 
  /* true <=> need range association, buffer holds {rowid, range_id} pairs */
 
2198
  uchar *rowids_buf;
 
2199
  uchar *rowids_buf_cur;   /* Current position when reading/writing */
 
2200
  uchar *rowids_buf_last;  /* When reading: end of used buffer space */
 
2201
  uchar *rowids_buf_end;   /* End of the buffer */
 
2202
 
 
2203
  bool dsmrr_eof; /* TRUE <=> We have reached EOF when reading index tuples */
 
2204
 
 
2205
  /* TRUE <=> need range association, buffer holds {rowid, range_id} pairs */
2131
2206
  bool is_mrr_assoc;
2132
2207
 
2133
 
  bool use_default_impl; /* true <=> shortcut all calls to default MRR impl */
 
2208
  bool use_default_impl; /* TRUE <=> shortcut all calls to default MRR impl */
2134
2209
public:
2135
 
  void init(handler *h_arg, Table *table_arg)
 
2210
  void init(handler *h_arg, TABLE *table_arg)
2136
2211
  {
2137
2212
    h= h_arg; 
2138
2213
    table= table_arg;
2139
2214
  }
2140
2215
  int dsmrr_init(handler *h, KEY *key, RANGE_SEQ_IF *seq_funcs, 
2141
 
                 void *seq_init_param, uint32_t n_ranges, uint32_t mode, 
 
2216
                 void *seq_init_param, uint n_ranges, uint mode, 
2142
2217
                 HANDLER_BUFFER *buf);
2143
2218
  void dsmrr_close();
2144
2219
  int dsmrr_fill_buffer(handler *h);
2145
2220
  int dsmrr_next(handler *h, char **range_info);
2146
2221
 
2147
 
  int dsmrr_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys, uint32_t *bufsz,
2148
 
                 uint32_t *flags, COST_VECT *cost);
 
2222
  int dsmrr_info(uint keyno, uint n_ranges, uint keys, uint *bufsz,
 
2223
                 uint *flags, COST_VECT *cost);
2149
2224
 
2150
 
  ha_rows dsmrr_info_const(uint32_t keyno, RANGE_SEQ_IF *seq, 
2151
 
                            void *seq_init_param, uint32_t n_ranges, uint32_t *bufsz,
2152
 
                            uint32_t *flags, COST_VECT *cost);
 
2225
  ha_rows dsmrr_info_const(uint keyno, RANGE_SEQ_IF *seq, 
 
2226
                            void *seq_init_param, uint n_ranges, uint *bufsz,
 
2227
                            uint *flags, COST_VECT *cost);
2153
2228
private:
2154
 
  bool key_uses_partial_cols(uint32_t keyno);
2155
 
  bool choose_mrr_impl(uint32_t keyno, ha_rows rows, uint32_t *flags, uint32_t *bufsz, 
 
2229
  bool key_uses_partial_cols(uint keyno);
 
2230
  bool choose_mrr_impl(uint keyno, ha_rows rows, uint *flags, uint *bufsz, 
2156
2231
                       COST_VECT *cost);
2157
 
  bool get_disk_sweep_mrr_cost(uint32_t keynr, ha_rows rows, uint32_t flags, 
2158
 
                               uint32_t *buffer_size, COST_VECT *cost);
 
2232
  bool get_disk_sweep_mrr_cost(uint keynr, ha_rows rows, uint flags, 
 
2233
                               uint *buffer_size, COST_VECT *cost);
2159
2234
};
2160
2235
 
2161
2236
extern const char *ha_row_type[];
2163
2238
extern const char *binlog_format_names[];
2164
2239
extern TYPELIB tx_isolation_typelib;
2165
2240
extern TYPELIB myisam_stats_method_typelib;
2166
 
extern uint32_t total_ha, total_ha_2pc;
 
2241
extern ulong total_ha, total_ha_2pc;
2167
2242
 
2168
2243
       /* Wrapper functions */
2169
 
#define ha_commit(thd) (ha_commit_trans((thd), true))
2170
 
#define ha_rollback(thd) (ha_rollback_trans((thd), true))
 
2244
#define ha_commit(thd) (ha_commit_trans((thd), TRUE))
 
2245
#define ha_rollback(thd) (ha_rollback_trans((thd), TRUE))
2171
2246
 
2172
2247
/* lookups */
2173
2248
handlerton *ha_default_handlerton(THD *thd);
2190
2265
  return db_type == NULL ? "UNKNOWN" : hton2plugin[db_type->slot]->name.str;
2191
2266
}
2192
2267
 
2193
 
static inline bool ha_check_storage_engine_flag(const handlerton *db_type, uint32_t flag)
 
2268
static inline bool ha_check_storage_engine_flag(const handlerton *db_type, uint32 flag)
2194
2269
{
2195
 
  return db_type == NULL ? false : test(db_type->flags & flag);
 
2270
  return db_type == NULL ? FALSE : test(db_type->flags & flag);
2196
2271
}
2197
2272
 
2198
2273
static inline bool ha_storage_engine_is_enabled(const handlerton *db_type)
2199
2274
{
2200
2275
  return (db_type && db_type->create) ?
2201
 
         (db_type->state == SHOW_OPTION_YES) : false;
 
2276
         (db_type->state == SHOW_OPTION_YES) : FALSE;
2202
2277
}
2203
2278
 
2204
2279
/* basic stuff */
2209
2284
int ha_finalize_handlerton(st_plugin_int *plugin);
2210
2285
 
2211
2286
TYPELIB *ha_known_exts(void);
 
2287
int ha_panic(enum ha_panic_function flag);
2212
2288
void ha_close_connection(THD* thd);
2213
2289
bool ha_flush_logs(handlerton *db_type);
2214
2290
void ha_drop_database(char* path);
2225
2301
/* discovery */
2226
2302
int ha_create_table_from_engine(THD* thd, const char *db, const char *name);
2227
2303
int ha_discover(THD* thd, const char* dbname, const char* name,
2228
 
                unsigned char** frmblob, size_t* frmlen);
 
2304
                uchar** frmblob, size_t* frmlen);
2229
2305
int ha_find_files(THD *thd,const char *db,const char *path,
2230
2306
                  const char *wild, bool dir, List<LEX_STRING>* files);
2231
2307
int ha_table_exists_in_engine(THD* thd, const char* db, const char* name);
2268
2344
*/
2269
2345
#define trans_need_2pc(thd, all)                   ((total_ha_2pc > 1) && \
2270
2346
        !((all ? &thd->transaction.all : &thd->transaction.stmt)->no_2pc))
 
2347
 
 
2348
#ifdef HAVE_NDB_BINLOG
 
2349
int ha_reset_logs(THD *thd);
 
2350
int ha_binlog_index_purge_file(THD *thd, const char *file);
 
2351
void ha_reset_slave(THD *thd);
 
2352
void ha_binlog_log_query(THD *thd, handlerton *db_type,
 
2353
                         enum_binlog_command binlog_command,
 
2354
                         const char *query, uint query_length,
 
2355
                         const char *db, const char *table_name);
 
2356
void ha_binlog_wait(THD *thd);
 
2357
int ha_binlog_end(THD *thd);
 
2358
#else
 
2359
#define ha_reset_logs(a) do {} while (0)
 
2360
#define ha_binlog_index_purge_file(a,b) do {} while (0)
 
2361
#define ha_reset_slave(a) do {} while (0)
 
2362
#define ha_binlog_log_query(a,b,c,d,e,f,g) do {} while (0)
 
2363
#define ha_binlog_wait(a) do {} while (0)
 
2364
#define ha_binlog_end(a)  do {} while (0)
 
2365
#endif