~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/handler.h

Removed explcit dependencies listing from Makefile.am, since that's what Automake is for...

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 */
22
18
 
 
19
#ifdef USE_PRAGMA_INTERFACE
 
20
#pragma interface                       /* gcc class implementation */
 
21
#endif
23
22
 
24
 
#include <mysys/my_handler.h>
25
 
#include <storage/myisam/keycache.h>
 
23
#include <my_handler.h>
 
24
#include <ft_global.h>
 
25
#include <keycache.h>
26
26
 
27
27
#ifndef NO_HASH
28
28
#define NO_HASH                         /* Not yet implemented */
46
46
#define HA_ADMIN_NEEDS_CHECK    -12
47
47
 
48
48
/* Bits to show what an alter table will do */
49
 
#include <drizzled/sql_bitmap.h>
 
49
#include <sql_bitmap.h>
50
50
 
51
 
#define HA_MAX_ALTER_FLAGS 40
 
51
#define HA_MAX_ALTER_FLAGS 39
52
52
typedef Bitmap<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
53
53
 
54
54
#define HA_ADD_INDEX                  (0)
85
85
#define HA_RENAME_TABLE               (36)
86
86
#define HA_ALTER_STORAGE_ENGINE       (37)
87
87
#define HA_RECREATE                   (38)
88
 
#define HA_ALTER_STORED_VCOL          (39)
89
88
/* Remember to increase HA_MAX_ALTER_FLAGS when adding more flags! */
90
89
 
91
90
/* Return values for check_if_supported_alter */
109
108
  row to be able to find the row later.
110
109
*/
111
110
#define HA_REC_NOT_IN_SEQ      (1 << 3)
112
 
 
 
111
/* This is now a dead option, just left for compatibility */
 
112
#define HA_CAN_GEOMETRY        (1 << 4)
113
113
/*
114
114
  Reading keys in random order is as fast as reading keys in sort order
115
115
  (Used in records.cc to decide if we should use a record cache and by
129
129
#define HA_REQUIRE_PRIMARY_KEY (1 << 12) /* .. and can't create a hidden one */
130
130
#define HA_STATS_RECORDS_IS_EXACT (1 << 13) /* stats.records is exact */
131
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
/*
132
137
  If we get the primary key columns for free when we do an index read
133
138
  It also implies that we have to retrive the primary key when using
134
139
  position() and rnd_pos().
139
144
  uses a primary key. Without primary key, we can't call position().
140
145
*/ 
141
146
#define HA_PRIMARY_KEY_REQUIRED_FOR_POSITION (1 << 16) 
 
147
#define HA_CAN_RTREEKEYS       (1 << 17)
142
148
#define HA_NOT_DELETE_WITH_CACHE (1 << 18)
143
149
/*
144
150
  The following is we need to a primary key to delete (and update) a row.
146
152
*/
147
153
#define HA_PRIMARY_KEY_REQUIRED_FOR_DELETE (1 << 19)
148
154
#define HA_NO_PREFIX_CHAR_KEYS (1 << 20)
 
155
#define HA_CAN_FULLTEXT        (1 << 21)
 
156
#define HA_CAN_SQL_HANDLER     (1 << 22)
149
157
#define HA_NO_AUTO_INCREMENT   (1 << 23)
150
158
#define HA_HAS_CHECKSUM        (1 << 24)
151
159
/* Table data are stored in separate files (for lower_case_table_names) */
152
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 */
153
163
#define HA_NEED_READ_RANGE_BUFFER (1 << 29) /* for read_multi_range */
154
164
#define HA_ANY_INDEX_MAY_BE_UNIQUE (1 << 30)
155
 
#define HA_NO_COPY_ON_ALTER    (INT64_C(1) << 31)
156
 
#define HA_HAS_RECORDS         (INT64_C(1) << 32) /* records() gives exact count*/
157
 
#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)
158
170
 
159
171
/*
160
172
  Engine is capable of row-format and statement-format logging,
161
173
  respectively
162
174
*/
163
 
#define HA_BINLOG_ROW_CAPABLE  (INT64_C(1) << 35)
164
 
#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)
165
177
 
166
 
#define HA_ONLINE_ALTER        (INT64_C(1) << 37)
 
178
#define HA_ONLINE_ALTER        (LL(1) << 37)
167
179
 
168
180
/*
169
181
  Set of all binlog flags. Currently only contain the capabilities
202
214
  set.
203
215
  This is actually removed even before it was introduced the first time.
204
216
  The new idea is that handlers will handle the lock level already in
205
 
  store_lock for ALTER Table partitions.
 
217
  store_lock for ALTER TABLE partitions.
206
218
 
207
219
  HA_PARTITION_ONE_PHASE is a flag that can be set by handlers that take
208
220
  care of changing the partitions online and in one phase. Thus all phases
248
260
#define HA_BLOCK_LOCK           256     /* unlock when reading some records */
249
261
#define HA_OPEN_TEMPORARY       512
250
262
 
251
 
/* For transactional LOCK Table. handler::lock_table() */
 
263
/* For transactional LOCK TABLE. handler::lock_table() */
252
264
#define HA_LOCK_IN_SHARE_MODE      F_RDLCK
253
265
#define HA_LOCK_IN_EXCLUSIVE_MODE  F_WRLCK
254
266
 
270
282
#define HA_CACHE_TBL_TRANSACT    4
271
283
 
272
284
/* Options of START TRANSACTION statement (and later of SET TRANSACTION stmt) */
273
 
#define DRIZZLE_START_TRANS_OPT_WITH_CONS_SNAPSHOT 1
 
285
#define MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT 1
274
286
 
275
287
/* Flags for method is_fatal_error */
276
288
#define HA_CHECK_DUP_KEY 1
279
291
 
280
292
enum legacy_db_type
281
293
{
282
 
  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,
283
311
  DB_TYPE_FIRST_DYNAMIC=42,
284
312
  DB_TYPE_DEFAULT=127 // Must be last
285
313
};
315
343
 
316
344
/* Bits in used_fields */
317
345
#define HA_CREATE_USED_AUTO             (1L << 0)
318
 
#ifdef DEAD_OPTIONS
 
346
#define HA_CREATE_USED_RAID             (1L << 1) //RAID is no longer availble
319
347
#define HA_CREATE_USED_UNION            (1L << 2)
320
 
#define HA_CREATE_USED_PASSWORD         (1L << 17)
321
 
#endif
322
348
#define HA_CREATE_USED_INSERT_METHOD    (1L << 3)
323
349
#define HA_CREATE_USED_MIN_ROWS         (1L << 4)
324
350
#define HA_CREATE_USED_MAX_ROWS         (1L << 5)
333
359
#define HA_CREATE_USED_DELAY_KEY_WRITE  (1L << 14)
334
360
#define HA_CREATE_USED_ROW_FORMAT       (1L << 15)
335
361
#define HA_CREATE_USED_COMMENT          (1L << 16)
 
362
#define HA_CREATE_USED_PASSWORD         (1L << 17)
336
363
#define HA_CREATE_USED_CONNECTION       (1L << 18)
337
364
#define HA_CREATE_USED_KEY_BLOCK_SIZE   (1L << 19)
 
365
#define HA_CREATE_USED_TRANSACTIONAL    (1L << 20)
338
366
#define HA_CREATE_USED_PAGE_CHECKSUM    (1L << 21)
339
 
#define HA_CREATE_USED_BLOCK_SIZE       (1L << 22)
340
367
 
341
368
typedef uint64_t my_xid; // this line is the same as in log_event.h
342
 
#define DRIZZLE_XID_PREFIX "MySQLXid"
343
 
#define DRIZZLE_XID_PREFIX_LEN 8 // must be a multiple of 8
344
 
#define DRIZZLE_XID_OFFSET (DRIZZLE_XID_PREFIX_LEN+sizeof(server_id))
345
 
#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))
346
373
 
347
 
#define XIDDATASIZE DRIZZLE_XIDDATASIZE
 
374
#define XIDDATASIZE MYSQL_XIDDATASIZE
348
375
#define MAXGTRIDSIZE 64
349
376
#define MAXBQUALSIZE 64
350
377
 
351
378
#define COMPATIBLE_DATA_YES 0
352
379
#define COMPATIBLE_DATA_NO  1
353
380
 
354
 
typedef bool (*qc_engine_callback)(THD *thd, char *table_key,
355
 
                                      uint32_t key_length,
356
 
                                      uint64_t *engine_data);
357
 
 
358
381
/**
359
382
  struct xid_t is binary compatible with the XID structure as
360
383
  in the X/Open CAE Specification, Distributed Transaction Processing:
361
384
  The XA Specification, X/Open Company Ltd., 1991.
362
385
  http://www.opengroup.org/bookstore/catalog/c193.htm
363
386
 
364
 
  @see DRIZZLE_XID in mysql/plugin.h
 
387
  @see MYSQL_XID in mysql/plugin.h
365
388
*/
366
389
struct xid_t {
367
390
  long formatID;
386
409
  {
387
410
    my_xid tmp;
388
411
    formatID= 1;
389
 
    set(DRIZZLE_XID_PREFIX_LEN, 0, DRIZZLE_XID_PREFIX);
390
 
    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));
391
414
    tmp= xid;
392
 
    memcpy(data+DRIZZLE_XID_OFFSET, &tmp, sizeof(tmp));
393
 
    gtrid_length=DRIZZLE_XID_GTRID_LEN;
 
415
    memcpy(data+MYSQL_XID_OFFSET, &tmp, sizeof(tmp));
 
416
    gtrid_length=MYSQL_XID_GTRID_LEN;
394
417
  }
395
418
  void set(long g, long b, const char *d)
396
419
  {
404
427
  my_xid quick_get_my_xid()
405
428
  {
406
429
    my_xid tmp;
407
 
    memcpy(&tmp, data+DRIZZLE_XID_OFFSET, sizeof(tmp));
 
430
    memcpy(&tmp, data+MYSQL_XID_OFFSET, sizeof(tmp));
408
431
    return tmp;
409
432
  }
410
433
  my_xid get_my_xid()
411
434
  {
412
 
    return gtrid_length == DRIZZLE_XID_GTRID_LEN && bqual_length == 0 &&
413
 
           !memcmp(data+DRIZZLE_XID_PREFIX_LEN, &server_id, sizeof(server_id)) &&
414
 
           !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) ?
415
438
           quick_get_my_xid() : 0;
416
439
  }
417
 
  uint32_t length()
 
440
  uint length()
418
441
  {
419
442
    return sizeof(formatID)+sizeof(gtrid_length)+sizeof(bqual_length)+
420
443
           gtrid_length+bqual_length;
421
444
  }
422
 
  unsigned char *key()
 
445
  uchar *key()
423
446
  {
424
 
    return (unsigned char *)&gtrid_length;
 
447
    return (uchar *)&gtrid_length;
425
448
  }
426
 
  uint32_t key_length()
 
449
  uint key_length()
427
450
  {
428
451
    return sizeof(gtrid_length)+sizeof(bqual_length)+gtrid_length+bqual_length;
429
452
  }
434
457
#define MIN_XID_LIST_SIZE  128
435
458
#define MAX_XID_LIST_SIZE  (1024*128)
436
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
 
437
493
struct handlerton;
438
 
 
439
 
/* The handler for a table type.  Will be included in the Table structure */
440
 
 
441
 
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;
442
541
typedef struct st_table_share TABLE_SHARE;
443
542
struct st_foreign_key_info;
444
543
typedef struct st_foreign_key_info FOREIGN_KEY_INFO;
445
 
typedef bool (stat_print_fn)(THD *thd, const char *type, uint32_t type_len,
446
 
                             const char *file, uint32_t file_len,
447
 
                             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);
448
547
enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
449
548
extern st_plugin_int *hton2plugin[MAX_HA];
450
549
 
480
579
 
481
580
   slot number is initialized by MySQL after xxx_init() is called.
482
581
   */
483
 
   uint32_t slot;
 
582
   uint slot;
484
583
   /*
485
584
     to store per-savepoint data storage engine is provided with an area
486
585
     of a requested size (0 is ok here).
490
589
     area and need not be used by storage engine.
491
590
     see binlog_hton and binlog_savepoint_set/rollback for an example.
492
591
   */
493
 
   uint32_t savepoint_offset;
 
592
   uint savepoint_offset;
494
593
   /*
495
594
     handlerton methods:
496
595
 
521
620
   int  (*commit)(handlerton *hton, THD *thd, bool all);
522
621
   int  (*rollback)(handlerton *hton, THD *thd, bool all);
523
622
   int  (*prepare)(handlerton *hton, THD *thd, bool all);
524
 
   int  (*recover)(handlerton *hton, XID *xid_list, uint32_t len);
 
623
   int  (*recover)(handlerton *hton, XID *xid_list, uint len);
525
624
   int  (*commit_by_xid)(handlerton *hton, XID *xid);
526
625
   int  (*rollback_by_xid)(handlerton *hton, XID *xid);
527
626
   void *(*create_cursor_read_view)(handlerton *hton, THD *thd);
529
628
   void (*close_cursor_read_view)(handlerton *hton, THD *thd, void *read_view);
530
629
   handler *(*create)(handlerton *hton, TABLE_SHARE *table, MEM_ROOT *mem_root);
531
630
   void (*drop_database)(handlerton *hton, char* path);
 
631
   int (*panic)(handlerton *hton, enum ha_panic_function flag);
532
632
   int (*start_consistent_snapshot)(handlerton *hton, THD *thd);
533
633
   bool (*flush_logs)(handlerton *hton);
534
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);
535
636
   int (*fill_files_table)(handlerton *hton, THD *thd,
536
 
                           TableList *tables,
 
637
                           TABLE_LIST *tables,
537
638
                           class Item *cond);
538
 
   uint32_t flags;                                /* global handler flags */
 
639
   uint32 flags;                                /* global handler flags */
539
640
   int (*release_temporary_latches)(handlerton *hton, THD *thd);
540
641
 
541
642
   int (*discover)(handlerton *hton, THD* thd, const char *db, 
542
643
                   const char *name,
543
 
                   unsigned char **frmblob, 
 
644
                   uchar **frmblob, 
544
645
                   size_t *frmlen);
545
646
   int (*table_exists_in_engine)(handlerton *hton, THD* thd, const char *db,
546
647
                                 const char *name);
547
 
   uint32_t license; /* Flag for Engine License */
 
648
   uint32 license; /* Flag for Engine License */
548
649
   void *data; /* Location for engines to keep personal structures */
549
650
};
550
651
 
580
681
    * stmt.modified_non_trans_table is used to keep track of
581
682
    modified non-transactional tables of top-level statements. At
582
683
    the end of the previous statement and at the beginning of the session,
583
 
    it is reset to false.  If such functions
 
684
    it is reset to FALSE.  If such functions
584
685
    as mysql_insert, mysql_update, mysql_delete etc modify a
585
 
    non-transactional table, they set this flag to true.  At the
 
686
    non-transactional table, they set this flag to TRUE.  At the
586
687
    end of the statement, the value of stmt.modified_non_trans_table 
587
688
    is merged with all.modified_non_trans_table and gets reset.
588
689
    * all.modified_non_trans_table is reset at the end of transaction
593
694
    At entrance into a sub-statement, a copy of the value of
594
695
    stmt.modified_non_trans_table (containing the changes of the
595
696
    outer statement) is saved on stack. Then 
596
 
    stmt.modified_non_trans_table is reset to false and the
 
697
    stmt.modified_non_trans_table is reset to FALSE and the
597
698
    substatement is executed. Then the new value is merged with the
598
699
    saved value.
599
700
  */
600
701
  bool modified_non_trans_table;
601
702
 
602
 
  void reset() { no_2pc= false; modified_non_trans_table= false; }
 
703
  void reset() { no_2pc= FALSE; modified_non_trans_table= FALSE; }
603
704
};
604
705
 
605
706
 
626
727
  /** Register this storage engine in the given transaction context. */
627
728
  void register_ha(THD_TRANS *trans, handlerton *ht_arg)
628
729
  {
629
 
    assert(m_flags == 0);
630
 
    assert(m_ht == NULL);
631
 
    assert(m_next == NULL);
 
730
    DBUG_ASSERT(m_flags == 0);
 
731
    DBUG_ASSERT(m_ht == NULL);
 
732
    DBUG_ASSERT(m_next == NULL);
632
733
 
633
734
    m_ht= ht_arg;
634
735
    m_flags= (int) TRX_READ_ONLY; /* Assume read-only at start. */
649
750
 
650
751
  void set_trx_read_write()
651
752
  {
652
 
    assert(is_started());
 
753
    DBUG_ASSERT(is_started());
653
754
    m_flags|= (int) TRX_READ_WRITE;
654
755
  }
655
756
  bool is_trx_read_write() const
656
757
  {
657
 
    assert(is_started());
 
758
    DBUG_ASSERT(is_started());
658
759
    return m_flags & (int) TRX_READ_WRITE;
659
760
  }
660
761
  bool is_started() const { return m_ht != NULL; }
666
767
      Can be called many times, e.g. when we have many
667
768
      read-write statements in a transaction.
668
769
    */
669
 
    assert(is_started());
 
770
    DBUG_ASSERT(is_started());
670
771
    if (stmt_trx->is_trx_read_write())
671
772
      set_trx_read_write();
672
773
  }
673
774
  Ha_trx_info *next() const
674
775
  {
675
 
    assert(is_started());
 
776
    DBUG_ASSERT(is_started());
676
777
    return m_next;
677
778
  }
678
779
  handlerton *ht() const
679
780
  {
680
 
    assert(is_started());
 
781
    DBUG_ASSERT(is_started());
681
782
    return m_ht;
682
783
  }
683
784
private:
695
796
    Not-null only if this instance is a part of transaction.
696
797
    May assume a combination of enum values above.
697
798
  */
698
 
  unsigned char       m_flags;
 
799
  uchar       m_flags;
699
800
};
700
801
 
701
802
 
702
803
enum enum_tx_isolation { ISO_READ_UNCOMMITTED, ISO_READ_COMMITTED,
703
804
                         ISO_REPEATABLE_READ, ISO_SERIALIZABLE};
704
805
 
 
806
 
 
807
enum ndb_distribution { ND_KEYHASH= 0, ND_LINHASH= 1 };
 
808
 
 
809
 
705
810
typedef struct {
706
811
  uint64_t data_file_length;
707
812
  uint64_t max_data_file_length;
719
824
class Item;
720
825
struct st_table_log_memory_entry;
721
826
 
722
 
#define NOT_A_PARTITION_ID ((uint32_t)-1)
 
827
#define NOT_A_PARTITION_ID ((uint32)-1)
723
828
 
724
829
enum ha_choice { HA_CHOICE_UNDEF, HA_CHOICE_NO, HA_CHOICE_YES };
725
830
 
726
831
typedef struct st_ha_create_information
727
832
{
728
 
  const CHARSET_INFO *table_charset, *default_table_charset;
 
833
  CHARSET_INFO *table_charset, *default_table_charset;
729
834
  LEX_STRING connect_string;
 
835
  const char *password, *tablespace;
730
836
  LEX_STRING comment;
731
837
  const char *data_file_name, *index_file_name;
732
838
  const char *alias;
736
842
  uint32_t avg_row_length;
737
843
  uint32_t used_fields;
738
844
  uint32_t key_block_size;
739
 
  uint32_t block_size;
 
845
  SQL_LIST merge_list;
740
846
  handlerton *db_type;
741
847
  enum row_type row_type;
742
 
  uint32_t null_bits;                       /* NULL bits at start of record */
743
 
  uint32_t options;                             /* OR of HA_CREATE_ options */
744
 
  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;
745
854
  bool table_existed;                   /* 1 in create if table existed */
746
855
  bool frm_only;                        /* 1 if no ha_create_table() */
747
856
  bool varchar;                         /* 1 if table has a VARCHAR */
 
857
  enum ha_storage_media default_storage_media;  /* DEFAULT, DISK or MEMORY */
748
858
  enum ha_choice page_checksum;         /* If we have page_checksums */
749
859
} HA_CREATE_INFO;
750
860
 
751
861
typedef struct st_ha_alter_information
752
862
{
753
863
  KEY  *key_info_buffer;
754
 
  uint32_t key_count;
755
 
  uint32_t index_drop_count;
756
 
  uint32_t *index_drop_buffer;
757
 
  uint32_t index_add_count;
758
 
  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;
759
869
  void *data;
760
870
} HA_ALTER_INFO;
761
871
 
789
899
  TABLEOP_HOOKS() {}
790
900
  virtual ~TABLEOP_HOOKS() {}
791
901
 
792
 
  inline void prelock(Table **tables, uint32_t count)
 
902
  inline void prelock(TABLE **tables, uint count)
793
903
  {
794
904
    do_prelock(tables, count);
795
905
  }
796
906
 
797
 
  inline int postlock(Table **tables, uint32_t count)
 
907
  inline int postlock(TABLE **tables, uint count)
798
908
  {
799
909
    return do_postlock(tables, count);
800
910
  }
801
911
private:
802
912
  /* Function primitive that is called prior to locking tables */
803
 
  virtual void do_prelock(Table **tables __attribute__((unused)),
804
 
                          uint32_t count __attribute__((unused)))
 
913
  virtual void do_prelock(TABLE **tables __attribute__((__unused__)),
 
914
                          uint count __attribute__((__unused__)))
805
915
  {
806
916
    /* Default is to do nothing */
807
917
  }
814
924
 
815
925
     @return Error code or zero.
816
926
   */
817
 
  virtual int do_postlock(Table **tables __attribute__((unused)),
818
 
                          uint32_t count __attribute__((unused)))
 
927
  virtual int do_postlock(TABLE **tables __attribute__((__unused__)),
 
928
                          uint count __attribute__((__unused__)))
819
929
  {
820
930
    return 0;                           /* Default is to do nothing */
821
931
  }
832
942
{
833
943
  st_ha_check_opt() {}                        /* Remove gcc warning */
834
944
  uint32_t sort_buffer_size;
835
 
  uint32_t flags;       /* isam layer flags (e.g. for myisamchk) */
836
 
  uint32_t sql_flags;   /* sql layer flags - for something myisamchk cannot do */
 
945
  uint flags;       /* isam layer flags (e.g. for myisamchk) */
 
946
  uint sql_flags;   /* sql layer flags - for something myisamchk cannot do */
837
947
  KEY_CACHE *key_cache; /* new key cache when changing key cache */
838
948
  void init();
839
949
} HA_CHECK_OPT;
849
959
 
850
960
typedef struct st_handler_buffer
851
961
{
852
 
  unsigned char *buffer;         /* Buffer one can start using */
853
 
  unsigned char *buffer_end;     /* End of buffer */
854
 
  unsigned char *end_of_used_area;     /* End of area that was used by handler */
 
962
  uchar *buffer;         /* Buffer one can start using */
 
963
  uchar *buffer_end;     /* End of buffer */
 
964
  uchar *end_of_used_area;     /* End of area that was used by handler */
855
965
} HANDLER_BUFFER;
856
966
 
857
967
typedef struct system_status_var SSV;
873
983
    RETURN
874
984
      An opaque value to be used as RANGE_SEQ_IF::next() parameter
875
985
  */
876
 
  range_seq_t (*init)(void *init_params, uint32_t n_ranges, uint32_t flags);
 
986
  range_seq_t (*init)(void *init_params, uint n_ranges, uint flags);
877
987
 
878
988
 
879
989
  /*
888
998
      0 - Ok, the range structure filled with info about the next range
889
999
      1 - No more ranges
890
1000
  */
891
 
  uint32_t (*next) (range_seq_t seq, KEY_MULTI_RANGE *range);
 
1001
  uint (*next) (range_seq_t seq, KEY_MULTI_RANGE *range);
892
1002
} RANGE_SEQ_IF;
893
1003
 
894
 
uint16_t &mrr_persistent_flag_storage(range_seq_t seq, uint32_t idx);
895
 
char* &mrr_get_ptr_by_idx(range_seq_t seq, uint32_t idx);
 
1004
uint16 &mrr_persistent_flag_storage(range_seq_t seq, uint idx);
 
1005
char* &mrr_get_ptr_by_idx(range_seq_t seq, uint idx);
896
1006
 
897
1007
class COST_VECT
898
1008
946
1056
  }
947
1057
};
948
1058
 
949
 
void get_sweep_read_cost(Table *table, ha_rows nrows, bool interrupted, 
 
1059
void get_sweep_read_cost(TABLE *table, ha_rows nrows, bool interrupted, 
950
1060
                         COST_VECT *cost);
951
1061
 
952
1062
/*
1018
1128
  time_t create_time;                   /* When table was created */
1019
1129
  time_t check_time;
1020
1130
  time_t update_time;
1021
 
  uint32_t block_size;                  /* index block size */
 
1131
  uint block_size;                      /* index block size */
1022
1132
 
1023
1133
  ha_statistics():
1024
1134
    data_file_length(0), max_data_file_length(0),
1028
1138
  {}
1029
1139
};
1030
1140
 
1031
 
uint32_t calculate_key_len(Table *, uint, const unsigned char *, key_part_map);
 
1141
uint calculate_key_len(TABLE *, uint, const uchar *, key_part_map);
1032
1142
/*
1033
1143
  bitmap with first N+1 bits set
1034
1144
  (keypart_map for a key prefix of [0..N] keyparts)
1094
1204
  typedef uint64_t Table_flags;
1095
1205
protected:
1096
1206
  struct st_table_share *table_share;   /* The table definition */
1097
 
  Table *table;               /* The current open table */
 
1207
  struct st_table *table;               /* The current open table */
1098
1208
  Table_flags cached_table_flags;       /* Set on init() and open() */
1099
1209
 
1100
1210
  ha_rows estimation_rows_to_insert;
1101
1211
public:
1102
1212
  handlerton *ht;                 /* storage engine of this handler */
1103
 
  unsigned char *ref;                           /* Pointer to current row */
1104
 
  unsigned char *dup_ref;                       /* Pointer to duplicate row */
 
1213
  uchar *ref;                           /* Pointer to current row */
 
1214
  uchar *dup_ref;                       /* Pointer to duplicate row */
1105
1215
 
1106
1216
  ha_statistics stats;
1107
1217
  /** MultiRangeRead-related members: */
1108
1218
  range_seq_t mrr_iter;    /* Interator to traverse the range sequence */
1109
1219
  RANGE_SEQ_IF mrr_funcs;  /* Range sequence traversal functions */
1110
1220
  HANDLER_BUFFER *multi_range_buffer; /* MRR buffer info */
1111
 
  uint32_t ranges_in_seq; /* Total number of ranges in the traversed sequence */
1112
 
  /* true <=> source MRR ranges and the output are ordered */
 
1221
  uint ranges_in_seq; /* Total number of ranges in the traversed sequence */
 
1222
  /* TRUE <=> source MRR ranges and the output are ordered */
1113
1223
  bool mrr_is_output_sorted;
1114
1224
 
1115
 
  /** true <=> we're currently traversing a range in mrr_cur_range. */
 
1225
  /** TRUE <=> we're currently traversing a range in mrr_cur_range. */
1116
1226
  bool mrr_have_range;
1117
1227
  /** Current range (the one we're now returning rows from) */
1118
1228
  KEY_MULTI_RANGE mrr_cur_range;
1123
1233
  int key_compare_result_on_equal;
1124
1234
  bool eq_range;
1125
1235
  /* 
1126
 
    true <=> the engine guarantees that returned records are within the range
 
1236
    TRUE <=> the engine guarantees that returned records are within the range
1127
1237
    being scanned.
1128
1238
  */
1129
1239
  bool in_range_check_pushed_down;
1130
1240
 
1131
 
  uint32_t errkey;                              /* Last dup key */
1132
 
  uint32_t key_used_on_scan;
1133
 
  uint32_t active_index;
 
1241
  uint errkey;                          /* Last dup key */
 
1242
  uint key_used_on_scan;
 
1243
  uint active_index;
1134
1244
  /** Length of ref (1-8 or the clustered key length) */
1135
 
  uint32_t ref_length;
 
1245
  uint ref_length;
 
1246
  FT_INFO *ft_handler;
1136
1247
  enum {NONE=0, INDEX, RND} inited;
1137
1248
  bool locked;
1138
1249
  bool implicit_emptied;                /* Can be !=0 only if HEAP */
1139
1250
  const Item *pushed_cond;
1140
1251
 
1141
1252
  Item *pushed_idx_cond;
1142
 
  uint32_t pushed_idx_cond_keyno;  /* The index which the above condition is for */
 
1253
  uint pushed_idx_cond_keyno;  /* The index which the above condition is for */
1143
1254
 
1144
1255
  /**
1145
1256
    next_insert_id is the next value which should be inserted into the
1167
1278
  handler(handlerton *ht_arg, TABLE_SHARE *share_arg)
1168
1279
    :table_share(share_arg), table(0),
1169
1280
    estimation_rows_to_insert(0), ht(ht_arg),
1170
 
    ref(0), in_range_check_pushed_down(false),
 
1281
    ref(0), in_range_check_pushed_down(FALSE),
1171
1282
    key_used_on_scan(MAX_KEY), active_index(MAX_KEY),
1172
1283
    ref_length(sizeof(my_off_t)),
1173
 
    inited(NONE),
1174
 
    locked(false), implicit_emptied(0),
 
1284
    ft_handler(0), inited(NONE),
 
1285
    locked(FALSE), implicit_emptied(0),
1175
1286
    pushed_cond(0), pushed_idx_cond(NULL), pushed_idx_cond_keyno(MAX_KEY),
1176
1287
    next_insert_id(0), insert_id_for_cur_row(0)
1177
1288
    {}
1178
1289
  virtual ~handler(void)
1179
1290
  {
1180
 
    assert(locked == false);
1181
 
    /* TODO: assert(inited == NONE); */
 
1291
    DBUG_ASSERT(locked == FALSE);
 
1292
    /* TODO: DBUG_ASSERT(inited == NONE); */
1182
1293
  }
1183
1294
  virtual handler *clone(MEM_ROOT *mem_root);
1184
1295
  /** This is called after create to allow us to set up cached variables */
1188
1299
  }
1189
1300
  /* ha_ methods: pubilc wrappers for private virtual API */
1190
1301
 
1191
 
  int ha_open(Table *table, const char *name, int mode, int test_if_locked);
1192
 
  int ha_index_init(uint32_t idx, bool sorted)
 
1302
  int ha_open(TABLE *table, const char *name, int mode, int test_if_locked);
 
1303
  int ha_index_init(uint idx, bool sorted)
1193
1304
  {
1194
1305
    int result;
1195
 
    assert(inited==NONE);
 
1306
    DBUG_ENTER("ha_index_init");
 
1307
    DBUG_ASSERT(inited==NONE);
1196
1308
    if (!(result= index_init(idx, sorted)))
1197
1309
      inited=INDEX;
1198
1310
    end_range= NULL;
1199
 
    return(result);
 
1311
    DBUG_RETURN(result);
1200
1312
  }
1201
1313
  int ha_index_end()
1202
1314
  {
1203
 
    assert(inited==INDEX);
 
1315
    DBUG_ENTER("ha_index_end");
 
1316
    DBUG_ASSERT(inited==INDEX);
1204
1317
    inited=NONE;
1205
1318
    end_range= NULL;
1206
 
    return(index_end());
 
1319
    DBUG_RETURN(index_end());
1207
1320
  }
1208
1321
  int ha_rnd_init(bool scan)
1209
1322
  {
1210
1323
    int result;
1211
 
    assert(inited==NONE || (inited==RND && scan));
 
1324
    DBUG_ENTER("ha_rnd_init");
 
1325
    DBUG_ASSERT(inited==NONE || (inited==RND && scan));
1212
1326
    inited= (result= rnd_init(scan)) ? NONE: RND;
1213
 
    return(result);
 
1327
    DBUG_RETURN(result);
1214
1328
  }
1215
1329
  int ha_rnd_end()
1216
1330
  {
1217
 
    assert(inited==RND);
 
1331
    DBUG_ENTER("ha_rnd_end");
 
1332
    DBUG_ASSERT(inited==RND);
1218
1333
    inited=NONE;
1219
 
    return(rnd_end());
 
1334
    DBUG_RETURN(rnd_end());
1220
1335
  }
1221
1336
  int ha_reset();
1222
1337
  /* this is necessary in many places, e.g. in HANDLER command */
1232
1347
    and delete_row() below.
1233
1348
  */
1234
1349
  int ha_external_lock(THD *thd, int lock_type);
1235
 
  int ha_write_row(unsigned char * buf);
1236
 
  int ha_update_row(const unsigned char * old_data, unsigned char * new_data);
1237
 
  int ha_delete_row(const unsigned char * buf);
 
1350
  int ha_write_row(uchar * buf);
 
1351
  int ha_update_row(const uchar * old_data, uchar * new_data);
 
1352
  int ha_delete_row(const uchar * buf);
1238
1353
  void ha_release_auto_increment();
1239
1354
 
1240
1355
  int ha_check_for_upgrade(HA_CHECK_OPT *check_opt);
1251
1366
    estimation_rows_to_insert= 0;
1252
1367
    return end_bulk_insert();
1253
1368
  }
1254
 
  int ha_bulk_update_row(const unsigned char *old_data, unsigned char *new_data,
1255
 
                         uint32_t *dup_key_found);
 
1369
  int ha_bulk_update_row(const uchar *old_data, uchar *new_data,
 
1370
                         uint *dup_key_found);
1256
1371
  int ha_delete_all_rows();
1257
1372
  int ha_reset_auto_increment(uint64_t value);
1258
1373
  int ha_optimize(THD* thd, HA_CHECK_OPT* check_opt);
1259
1374
  int ha_analyze(THD* thd, HA_CHECK_OPT* check_opt);
1260
1375
  bool ha_check_and_repair(THD *thd);
1261
 
  int ha_disable_indexes(uint32_t mode);
1262
 
  int ha_enable_indexes(uint32_t mode);
1263
 
  int ha_discard_or_import_tablespace(bool discard);
 
1376
  int ha_disable_indexes(uint mode);
 
1377
  int ha_enable_indexes(uint mode);
 
1378
  int ha_discard_or_import_tablespace(my_bool discard);
1264
1379
  void ha_prepare_for_alter();
1265
1380
  int ha_rename_table(const char *from, const char *to);
1266
1381
  int ha_delete_table(const char *name);
1267
1382
  void ha_drop_table(const char *name);
1268
1383
 
1269
 
  int ha_create(const char *name, Table *form, HA_CREATE_INFO *info);
 
1384
  int ha_create(const char *name, TABLE *form, HA_CREATE_INFO *info);
1270
1385
 
1271
1386
  int ha_create_handler_files(const char *name, const char *old_name,
1272
1387
                              int action_flag, HA_CREATE_INFO *info);
1273
1388
 
1274
1389
  void adjust_next_insert_id_after_explicit_value(uint64_t nr);
1275
1390
  int update_auto_increment();
1276
 
  void print_keydup_error(uint32_t key_nr, const char *msg);
 
1391
  void print_keydup_error(uint key_nr, const char *msg);
1277
1392
  virtual void print_error(int error, myf errflag);
1278
1393
  virtual bool get_error_message(int error, String *buf);
1279
 
  uint32_t get_dup_key(int error);
1280
 
  virtual void change_table_ptr(Table *table_arg, TABLE_SHARE *share)
 
1394
  uint get_dup_key(int error);
 
1395
  virtual void change_table_ptr(TABLE *table_arg, TABLE_SHARE *share)
1281
1396
  {
1282
1397
    table= table_arg;
1283
1398
    table_share= share;
1284
1399
  }
1285
1400
  /* Estimates calculation */
1286
1401
  virtual double scan_time(void)
1287
 
  { return uint64_t2double(stats.data_file_length) / IO_SIZE + 2; }
1288
 
  virtual double read_time(uint32_t index __attribute__((unused)),
1289
 
                           uint32_t ranges, ha_rows rows)
 
1402
  { return ulonglong2double(stats.data_file_length) / IO_SIZE + 2; }
 
1403
  virtual double read_time(uint index __attribute__((__unused__)),
 
1404
                           uint ranges, ha_rows rows)
1290
1405
  { return rows2double(ranges+rows); }
1291
1406
 
1292
 
  virtual double index_only_read_time(uint32_t keynr, double records);
 
1407
  virtual double index_only_read_time(uint keynr, double records);
1293
1408
  
1294
 
  virtual ha_rows multi_range_read_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
 
1409
  virtual ha_rows multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq,
1295
1410
                                              void *seq_init_param, 
1296
 
                                              uint32_t n_ranges, uint32_t *bufsz,
1297
 
                                              uint32_t *flags, COST_VECT *cost);
1298
 
  virtual int multi_range_read_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys,
1299
 
                                    uint32_t *bufsz, uint32_t *flags, COST_VECT *cost);
 
1411
                                              uint n_ranges, uint *bufsz,
 
1412
                                              uint *flags, COST_VECT *cost);
 
1413
  virtual int multi_range_read_info(uint keyno, uint n_ranges, uint keys,
 
1414
                                    uint *bufsz, uint *flags, COST_VECT *cost);
1300
1415
  virtual int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
1301
 
                                    uint32_t n_ranges, uint32_t mode,
 
1416
                                    uint n_ranges, uint mode,
1302
1417
                                    HANDLER_BUFFER *buf);
1303
1418
  virtual int multi_range_read_next(char **range_info);
1304
1419
 
1306
1421
  virtual const key_map *keys_to_use_for_scanning() { return &key_map_empty; }
1307
1422
  bool has_transactions()
1308
1423
  { return (ha_table_flags() & HA_NO_TRANSACTIONS) == 0; }
1309
 
  virtual uint32_t extra_rec_buf_length() const { return 0; }
 
1424
  virtual uint extra_rec_buf_length() const { return 0; }
1310
1425
 
1311
1426
  /**
1312
1427
    This method is used to analyse the error to see whether the error
1318
1433
    same thing as HA_ERR_FOUND_DUP_KEY but can in some cases lead to
1319
1434
    a slightly different error message.
1320
1435
  */
1321
 
  virtual bool is_fatal_error(int error, uint32_t flags)
 
1436
  virtual bool is_fatal_error(int error, uint flags)
1322
1437
  {
1323
1438
    if (!error ||
1324
1439
        ((flags & HA_CHECK_DUP_KEY) &&
1325
1440
         (error == HA_ERR_FOUND_DUPP_KEY ||
1326
1441
          error == HA_ERR_FOUND_DUPP_UNIQUE)))
1327
 
      return false;
1328
 
    return true;
 
1442
      return FALSE;
 
1443
    return TRUE;
1329
1444
  }
1330
1445
 
1331
1446
  /**
1348
1463
  */
1349
1464
  virtual enum row_type get_row_type() const { return ROW_TYPE_NOT_USED; }
1350
1465
 
1351
 
  virtual const char *index_type(uint32_t key_number __attribute__((unused)))
1352
 
  { assert(0); return "";}
 
1466
  virtual const char *index_type(uint key_number __attribute__((__unused__)))
 
1467
  { DBUG_ASSERT(0); return "";}
1353
1468
 
1354
1469
 
1355
1470
  /**
1360
1475
    as there may be several calls to this routine.
1361
1476
  */
1362
1477
  virtual void column_bitmaps_signal();
1363
 
  uint32_t get_index(void) const { return active_index; }
 
1478
  uint get_index(void) const { return active_index; }
1364
1479
  virtual int close(void)=0;
1365
1480
 
1366
1481
  /**
1384
1499
    @retval  0           Success
1385
1500
    @retval  >0          Error code
1386
1501
  */
1387
 
  virtual int exec_bulk_update(uint32_t *dup_key_found __attribute__((unused)))
 
1502
  virtual int exec_bulk_update(uint *dup_key_found __attribute__((__unused__)))
1388
1503
  {
1389
 
    assert(false);
 
1504
    DBUG_ASSERT(FALSE);
1390
1505
    return HA_ERR_WRONG_COMMAND;
1391
1506
  }
1392
1507
  /**
1402
1517
  */
1403
1518
  virtual int end_bulk_delete()
1404
1519
  {
1405
 
    assert(false);
 
1520
    DBUG_ASSERT(FALSE);
1406
1521
    return HA_ERR_WRONG_COMMAND;
1407
1522
  }
1408
1523
  /**
1411
1526
     row if available. If the key value is null, begin at the first key of the
1412
1527
     index.
1413
1528
  */
1414
 
  virtual int index_read_map(unsigned char * buf, const unsigned char * key,
 
1529
  virtual int index_read_map(uchar * buf, const uchar * key,
1415
1530
                             key_part_map keypart_map,
1416
1531
                             enum ha_rkey_function find_flag)
1417
1532
  {
1418
 
    uint32_t key_len= calculate_key_len(table, active_index, key, keypart_map);
 
1533
    uint key_len= calculate_key_len(table, active_index, key, keypart_map);
1419
1534
    return  index_read(buf, key, key_len, find_flag);
1420
1535
  }
1421
1536
  /**
1424
1539
     row if available. If the key value is null, begin at the first key of the
1425
1540
     index.
1426
1541
  */
1427
 
  virtual int index_read_idx_map(unsigned char * buf, uint32_t index, const unsigned char * key,
 
1542
  virtual int index_read_idx_map(uchar * buf, uint index, const uchar * key,
1428
1543
                                 key_part_map keypart_map,
1429
1544
                                 enum ha_rkey_function find_flag);
1430
 
  virtual int index_next(unsigned char * buf __attribute__((unused)))
1431
 
   { return  HA_ERR_WRONG_COMMAND; }
1432
 
  virtual int index_prev(unsigned char * buf __attribute__((unused)))
1433
 
   { return  HA_ERR_WRONG_COMMAND; }
1434
 
  virtual int index_first(unsigned char * buf __attribute__((unused)))
1435
 
   { return  HA_ERR_WRONG_COMMAND; }
1436
 
  virtual int index_last(unsigned char * buf __attribute__((unused)))
1437
 
   { return  HA_ERR_WRONG_COMMAND; }
1438
 
  virtual int index_next_same(unsigned char *buf __attribute__((unused)),
1439
 
                              const unsigned char *key __attribute__((unused)),
1440
 
                              uint32_t keylen __attribute__((unused)));
 
1545
  virtual int index_next(uchar * buf __attribute__((__unused__)))
 
1546
   { return  HA_ERR_WRONG_COMMAND; }
 
1547
  virtual int index_prev(uchar * buf __attribute__((__unused__)))
 
1548
   { return  HA_ERR_WRONG_COMMAND; }
 
1549
  virtual int index_first(uchar * buf __attribute__((__unused__)))
 
1550
   { return  HA_ERR_WRONG_COMMAND; }
 
1551
  virtual int index_last(uchar * buf __attribute__((__unused__)))
 
1552
   { return  HA_ERR_WRONG_COMMAND; }
 
1553
  virtual int index_next_same(uchar *buf __attribute__((__unused__)),
 
1554
                              const uchar *key __attribute__((__unused__)),
 
1555
                              uint keylen __attribute__((__unused__)));
1441
1556
  /**
1442
1557
     @brief
1443
1558
     The following functions works like index_read, but it find the last
1444
1559
     row with the current key value or prefix.
1445
1560
  */
1446
 
  virtual int index_read_last_map(unsigned char * buf, const unsigned char * key,
 
1561
  virtual int index_read_last_map(uchar * buf, const uchar * key,
1447
1562
                                  key_part_map keypart_map)
1448
1563
  {
1449
 
    uint32_t key_len= calculate_key_len(table, active_index, key, keypart_map);
 
1564
    uint key_len= calculate_key_len(table, active_index, key, keypart_map);
1450
1565
    return index_read_last(buf, key, key_len);
1451
1566
  }
1452
1567
  virtual int read_range_first(const key_range *start_key,
1455
1570
  virtual int read_range_next();
1456
1571
  int compare_key(key_range *range);
1457
1572
  int compare_key2(key_range *range);
1458
 
  virtual int rnd_next(unsigned char *buf __attribute__((unused)))=0;
1459
 
  virtual int rnd_pos(unsigned char * buf __attribute__((unused)),
1460
 
                      unsigned char *pos __attribute__((unused)))=0;
 
1573
  virtual int ft_init() { return HA_ERR_WRONG_COMMAND; }
 
1574
  void ft_end() { ft_handler=NULL; }
 
1575
  virtual FT_INFO *ft_init_ext(uint flags __attribute__((__unused__)),
 
1576
                               uint inx __attribute__((__unused__)),
 
1577
                               String *key __attribute__((__unused__)))
 
1578
    { return NULL; }
 
1579
  virtual int ft_read(uchar *buf __attribute__((__unused__))) { return HA_ERR_WRONG_COMMAND; }
 
1580
  virtual int rnd_next(uchar *buf __attribute__((__unused__)))=0;
 
1581
  virtual int rnd_pos(uchar * buf __attribute__((__unused__)),
 
1582
                      uchar *pos __attribute__((__unused__)))=0;
1461
1583
  /**
1462
1584
    One has to use this method when to find
1463
1585
    random position by record as the plain
1464
1586
    position() call doesn't work for some
1465
1587
    handlers for random position.
1466
1588
  */
1467
 
  virtual int rnd_pos_by_record(unsigned char *record);
1468
 
  virtual int read_first_row(unsigned char *buf, uint32_t primary_key);
 
1589
  virtual int rnd_pos_by_record(uchar *record);
 
1590
  virtual int read_first_row(uchar *buf, uint primary_key);
1469
1591
  /**
1470
1592
    The following function is only needed for tables that may be temporary
1471
1593
    tables during joins.
1472
1594
  */
1473
 
  virtual int restart_rnd_next(unsigned char *buf __attribute__((unused)),
1474
 
                               unsigned char *pos __attribute__((unused)))
1475
 
    { return HA_ERR_WRONG_COMMAND; }
1476
 
  virtual int rnd_same(unsigned char *buf __attribute__((unused)),
1477
 
                       uint32_t inx __attribute__((unused)))
1478
 
    { return HA_ERR_WRONG_COMMAND; }
1479
 
  virtual ha_rows records_in_range(uint32_t inx __attribute__((unused)),
1480
 
                                   key_range *min_key __attribute__((unused)),
1481
 
                                   key_range *max_key __attribute__((unused)))
 
1595
  virtual int restart_rnd_next(uchar *buf __attribute__((__unused__)),
 
1596
                               uchar *pos __attribute__((__unused__)))
 
1597
    { return HA_ERR_WRONG_COMMAND; }
 
1598
  virtual int rnd_same(uchar *buf __attribute__((__unused__)),
 
1599
                       uint inx __attribute__((__unused__)))
 
1600
    { return HA_ERR_WRONG_COMMAND; }
 
1601
  virtual ha_rows records_in_range(uint inx __attribute__((__unused__)),
 
1602
                                   key_range *min_key __attribute__((__unused__)),
 
1603
                                   key_range *max_key __attribute__((__unused__)))
1482
1604
    { return (ha_rows) 10; }
1483
 
  virtual void position(const unsigned char *record)=0;
 
1605
  virtual void position(const uchar *record)=0;
1484
1606
  virtual int info(uint)=0; // see my_base.h for full description
1485
 
  virtual uint32_t calculate_key_hash_value(Field **field_array __attribute__((unused)))
1486
 
  { assert(0); return 0; }
1487
 
  virtual int extra(enum ha_extra_function operation __attribute__((unused)))
 
1607
  virtual uint32 calculate_key_hash_value(Field **field_array __attribute__((__unused__)))
 
1608
  { DBUG_ASSERT(0); return 0; }
 
1609
  virtual int extra(enum ha_extra_function operation __attribute__((__unused__)))
1488
1610
  { return 0; }
1489
1611
  virtual int extra_opt(enum ha_extra_function operation,
1490
 
                        uint32_t cache_size __attribute__((unused)))
 
1612
                        uint32_t cache_size __attribute__((__unused__)))
1491
1613
  { return extra(operation); }
1492
1614
 
1493
1615
  /**
1511
1633
  */
1512
1634
  virtual void try_semi_consistent_read(bool) {}
1513
1635
  virtual void unlock_row(void) {}
1514
 
  virtual int start_stmt(THD *thd __attribute__((unused)),
1515
 
                         thr_lock_type lock_type __attribute__((unused)))
 
1636
  virtual int start_stmt(THD *thd __attribute__((__unused__)),
 
1637
                         thr_lock_type lock_type __attribute__((__unused__)))
1516
1638
  {return 0;}
1517
1639
  virtual void get_auto_increment(uint64_t offset, uint64_t increment,
1518
1640
                                  uint64_t nb_desired_values,
1520
1642
                                  uint64_t *nb_reserved_values);
1521
1643
  void set_next_insert_id(uint64_t id)
1522
1644
  {
 
1645
    DBUG_PRINT("info",("auto_increment: next value %lu", (uint32_t)id));
1523
1646
    next_insert_id= id;
1524
1647
  }
1525
1648
  void restore_auto_increment(uint64_t prev_insert_id)
1538
1661
      insert_id_for_cur_row;
1539
1662
  }
1540
1663
 
1541
 
  virtual void update_create_info(HA_CREATE_INFO *create_info __attribute__((unused))) {}
 
1664
  virtual void update_create_info(HA_CREATE_INFO *create_info __attribute__((__unused__))) {}
1542
1665
  int check_old_types(void);
1543
 
  virtual int assign_to_keycache(THD* thd __attribute__((unused)),
1544
 
                                 HA_CHECK_OPT* check_opt __attribute__((unused)))
 
1666
  virtual int assign_to_keycache(THD* thd __attribute__((__unused__)),
 
1667
                                 HA_CHECK_OPT* check_opt __attribute__((__unused__)))
1545
1668
  { return HA_ADMIN_NOT_IMPLEMENTED; }
1546
1669
  /* end of the list of admin commands */
1547
1670
 
1548
1671
  virtual int indexes_are_disabled(void) {return 0;}
1549
1672
  virtual char *update_table_comment(const char * comment)
1550
1673
  { return (char*) comment;}
1551
 
  virtual void append_create_info(String *packet __attribute__((unused)))
 
1674
  virtual void append_create_info(String *packet __attribute__((__unused__)))
1552
1675
  {}
1553
1676
  /**
1554
1677
      If index == MAX_KEY then a check for table is made and if index <
1557
1680
 
1558
1681
    @param  index            Index to check if foreign key uses it
1559
1682
 
1560
 
    @retval   true            Foreign key defined on table or index
1561
 
    @retval   false           No foreign key defined
 
1683
    @retval   TRUE            Foreign key defined on table or index
 
1684
    @retval   FALSE           No foreign key defined
1562
1685
  */
1563
 
  virtual bool is_fk_defined_on_table_or_index(uint32_t index __attribute__((unused)))
1564
 
  { return false; }
 
1686
  virtual bool is_fk_defined_on_table_or_index(uint index __attribute__((__unused__)))
 
1687
  { return FALSE; }
1565
1688
  virtual char* get_foreign_key_create_info(void)
1566
1689
  { return(NULL);}  /* gets foreign key create string from InnoDB */
1567
 
  /** used in ALTER Table; 1 if changing storage engine is allowed */
 
1690
  /* gets tablespace name from handler */
 
1691
  const char* get_tablespace_name(void);
 
1692
  /** used in ALTER TABLE; 1 if changing storage engine is allowed */
1568
1693
  virtual bool can_switch_engines(void) { return 1; }
1569
1694
  /** used in REPLACE; is > 0 if table is referred by a FOREIGN KEY */
1570
 
  virtual int get_foreign_key_list(THD *thd __attribute__((unused)),
1571
 
                                   List<FOREIGN_KEY_INFO> *f_key_list __attribute__((unused)))
 
1695
  virtual int get_foreign_key_list(THD *thd __attribute__((__unused__)),
 
1696
                                   List<FOREIGN_KEY_INFO> *f_key_list __attribute__((__unused__)))
1572
1697
  { return 0; }
1573
 
  virtual uint32_t referenced_by_foreign_key() { return 0;}
 
1698
  virtual uint referenced_by_foreign_key() { return 0;}
1574
1699
  virtual void init_table_handle_for_HANDLER()
1575
1700
  { return; }       /* prepare InnoDB for HANDLER */
1576
 
  virtual void free_foreign_key_create_info(char* str __attribute__((unused))) {}
 
1701
  virtual void free_foreign_key_create_info(char* str __attribute__((__unused__))) {}
1577
1702
  /** The following can be called without an open handler */
1578
1703
  virtual const char *table_type() const =0;
1579
1704
  /**
1585
1710
    and data file), the order of elements is relevant. First element of engine
1586
1711
    file name extentions array should be meta/index file extention. Second
1587
1712
    element - data file extention. This order is assumed by
1588
 
    prepare_for_repair() when REPAIR Table ... USE_FRM is issued.
 
1713
    prepare_for_repair() when REPAIR TABLE ... USE_FRM is issued.
1589
1714
  */
1590
1715
  virtual const char **bas_ext() const =0;
1591
1716
 
1592
 
  virtual int get_default_no_partitions(HA_CREATE_INFO *info __attribute__((unused))) { return 1;}
1593
 
  virtual bool get_no_parts(const char *name __attribute__((unused)),
1594
 
                            uint32_t *no_parts)
 
1717
  virtual int get_default_no_partitions(HA_CREATE_INFO *info __attribute__((__unused__))) { return 1;}
 
1718
  virtual bool get_no_parts(const char *name __attribute__((__unused__)),
 
1719
                            uint *no_parts)
1595
1720
  {
1596
1721
    *no_parts= 0;
1597
1722
    return 0;
1598
1723
  }
1599
1724
 
1600
 
  virtual uint32_t index_flags(uint32_t idx, uint32_t part, bool all_parts) const =0;
1601
 
 
1602
 
  virtual int add_index(Table *table_arg __attribute__((unused)),
1603
 
                        KEY *key_info __attribute__((unused)),
1604
 
                        uint32_t num_of_keys __attribute__((unused)))
1605
 
  { return (HA_ERR_WRONG_COMMAND); }
1606
 
  virtual int prepare_drop_index(Table *table_arg __attribute__((unused)),
1607
 
                                 uint32_t *key_num __attribute__((unused)),
1608
 
                                 uint32_t num_of_keys __attribute__((unused)))
1609
 
  { return (HA_ERR_WRONG_COMMAND); }
1610
 
  virtual int final_drop_index(Table *table_arg __attribute__((unused)))
1611
 
  { return (HA_ERR_WRONG_COMMAND); }
1612
 
 
1613
 
  uint32_t max_record_length() const
1614
 
  { return cmin((unsigned int)HA_MAX_REC_LENGTH, max_supported_record_length()); }
1615
 
  uint32_t max_keys() const
1616
 
  { return cmin((unsigned int)MAX_KEY, max_supported_keys()); }
1617
 
  uint32_t max_key_parts() const
1618
 
  { return cmin((unsigned int)MAX_REF_PARTS, max_supported_key_parts()); }
1619
 
  uint32_t max_key_length() const
1620
 
  { return cmin((unsigned int)MAX_KEY_LENGTH, max_supported_key_length()); }
1621
 
  uint32_t max_key_part_length(void) const
1622
 
  { return cmin((unsigned int)MAX_KEY_LENGTH, max_supported_key_part_length()); }
1623
 
 
1624
 
  virtual uint32_t max_supported_record_length(void) const
 
1725
  virtual uint32_t index_flags(uint idx, uint part, bool all_parts) const =0;
 
1726
 
 
1727
  virtual int add_index(TABLE *table_arg __attribute__((__unused__)),
 
1728
                        KEY *key_info __attribute__((__unused__)),
 
1729
                        uint num_of_keys __attribute__((__unused__)))
 
1730
  { return (HA_ERR_WRONG_COMMAND); }
 
1731
  virtual int prepare_drop_index(TABLE *table_arg __attribute__((__unused__)),
 
1732
                                 uint *key_num __attribute__((__unused__)),
 
1733
                                 uint num_of_keys __attribute__((__unused__)))
 
1734
  { return (HA_ERR_WRONG_COMMAND); }
 
1735
  virtual int final_drop_index(TABLE *table_arg __attribute__((__unused__)))
 
1736
  { return (HA_ERR_WRONG_COMMAND); }
 
1737
 
 
1738
  uint max_record_length() const
 
1739
  { return min(HA_MAX_REC_LENGTH, max_supported_record_length()); }
 
1740
  uint max_keys() const
 
1741
  { return min(MAX_KEY, max_supported_keys()); }
 
1742
  uint max_key_parts() const
 
1743
  { return min(MAX_REF_PARTS, max_supported_key_parts()); }
 
1744
  uint max_key_length() const
 
1745
  { return min(MAX_KEY_LENGTH, max_supported_key_length()); }
 
1746
  uint max_key_part_length(void) const
 
1747
  { return min(MAX_KEY_LENGTH, max_supported_key_part_length()); }
 
1748
 
 
1749
  virtual uint max_supported_record_length(void) const
1625
1750
  { return HA_MAX_REC_LENGTH; }
1626
 
  virtual uint32_t max_supported_keys(void) const { return 0; }
1627
 
  virtual uint32_t max_supported_key_parts(void) const { return MAX_REF_PARTS; }
1628
 
  virtual uint32_t max_supported_key_length(void) const { return MAX_KEY_LENGTH; }
1629
 
  virtual uint32_t max_supported_key_part_length(void) const { return 255; }
1630
 
  virtual uint32_t min_record_length(uint32_t options __attribute__((unused))) const
 
1751
  virtual uint max_supported_keys(void) const { return 0; }
 
1752
  virtual uint max_supported_key_parts(void) const { return MAX_REF_PARTS; }
 
1753
  virtual uint max_supported_key_length(void) const { return MAX_KEY_LENGTH; }
 
1754
  virtual uint max_supported_key_part_length(void) const { return 255; }
 
1755
  virtual uint min_record_length(uint options __attribute__((__unused__))) const
1631
1756
  { return 1; }
1632
1757
 
1633
1758
  virtual bool low_byte_first(void) const { return 1; }
1634
 
  virtual uint32_t checksum(void) const { return 0; }
 
1759
  virtual uint checksum(void) const { return 0; }
1635
1760
  virtual bool is_crashed(void) const  { return 0; }
1636
1761
  virtual bool auto_repair(void) const { return 0; }
1637
1762
 
1644
1769
  /**
1645
1770
    @note lock_count() can return > 1 if the table is MERGE or partitioned.
1646
1771
  */
1647
 
  virtual uint32_t lock_count(void) const { return 1; }
 
1772
  virtual uint lock_count(void) const { return 1; }
1648
1773
  /**
1649
1774
    Is not invoked for non-transactional temporary tables.
1650
1775
 
1663
1788
                                     enum thr_lock_type lock_type)=0;
1664
1789
 
1665
1790
  /** Type of table for caching query */
1666
 
  virtual uint8_t table_cache_type() { return HA_CACHE_TBL_NONTRANSACT; }
 
1791
  virtual uint8 table_cache_type() { return HA_CACHE_TBL_NONTRANSACT; }
1667
1792
 
1668
1793
 
1669
1794
  /**
1686
1811
 
1687
1812
    @note If engine_data supplied with this function is different from
1688
1813
      engine_data supplied with the callback function, and the callback returns
1689
 
      false, a table invalidation on the current table will occur.
 
1814
      FALSE, a table invalidation on the current table will occur.
1690
1815
 
1691
1816
    @return Upon success the engine_callback will point to the storage engine
1692
1817
      call back function, if any, and engine_data will point to any storage
1693
1818
      engine data used in the specific implementation.
1694
 
      @retval true Success
1695
 
      @retval false The specified table or current statement should not be
 
1819
      @retval TRUE Success
 
1820
      @retval FALSE The specified table or current statement should not be
1696
1821
        cached
1697
1822
  */
1698
1823
 
1699
 
  virtual bool
1700
 
    register_query_cache_table(THD *thd __attribute__((unused)),
1701
 
                               char *table_key __attribute__((unused)),
1702
 
                               uint32_t key_length __attribute__((unused)),
 
1824
  virtual my_bool
 
1825
    register_query_cache_table(THD *thd __attribute__((__unused__)),
 
1826
                               char *table_key __attribute__((__unused__)),
 
1827
                               uint key_length __attribute__((__unused__)),
1703
1828
                               qc_engine_callback *engine_callback,
1704
 
                               uint64_t *engine_data __attribute__((unused)))
 
1829
                               uint64_t *engine_data __attribute__((__unused__)))
1705
1830
  {
1706
1831
    *engine_callback= 0;
1707
 
    return true;
 
1832
    return TRUE;
1708
1833
  }
1709
1834
 
1710
1835
 
1711
1836
 /*
1712
 
   @retval true   Primary key (if there is one) is clustered
 
1837
   @retval TRUE   Primary key (if there is one) is clustered
1713
1838
                  key covering all fields
1714
 
   @retval false  otherwise
 
1839
   @retval FALSE  otherwise
1715
1840
 */
1716
 
 virtual bool primary_key_is_clustered() { return false; }
1717
 
 virtual int cmp_ref(const unsigned char *ref1, const unsigned char *ref2)
 
1841
 virtual bool primary_key_is_clustered() { return FALSE; }
 
1842
 virtual int cmp_ref(const uchar *ref1, const uchar *ref2)
1718
1843
 {
1719
1844
   return memcmp(ref1, ref2, ref_length);
1720
1845
 }
1755
1880
 virtual void cond_pop(void) { return; }
1756
1881
 
1757
1882
 virtual Item
1758
 
   *idx_cond_push(uint32_t keyno __attribute__((unused)),
1759
 
                  Item* idx_cond __attribute__((unused)))
 
1883
   *idx_cond_push(uint keyno __attribute__((__unused__)),
 
1884
                  Item* idx_cond __attribute__((__unused__)))
1760
1885
 { return idx_cond; }
1761
1886
 
1762
1887
 /*
1763
1888
    Part of old fast alter table, to be depricated
1764
1889
  */
1765
1890
 virtual bool
1766
 
   check_if_incompatible_data(HA_CREATE_INFO *create_info __attribute__((unused)),
1767
 
                              uint32_t table_changes __attribute__((unused)))
 
1891
   check_if_incompatible_data(HA_CREATE_INFO *create_info __attribute__((__unused__)),
 
1892
                              uint table_changes __attribute__((__unused__)))
1768
1893
 { return COMPATIBLE_DATA_NO; }
1769
1894
 
1770
 
 /* On-line ALTER Table interface */
 
1895
 /* On-line ALTER TABLE interface */
1771
1896
 
1772
1897
 /**
1773
1898
    Check if a storage engine supports a particular alter table on-line
1793
1918
      implementation.
1794
1919
 */
1795
1920
 virtual int
1796
 
   check_if_supported_alter(Table *altered_table __attribute__((unused)),
 
1921
   check_if_supported_alter(TABLE *altered_table __attribute__((__unused__)),
1797
1922
                            HA_CREATE_INFO *create_info,
1798
 
                            HA_ALTER_FLAGS *alter_flags __attribute__((unused)),
1799
 
                            uint32_t table_changes)
 
1923
                            HA_ALTER_FLAGS *alter_flags __attribute__((__unused__)),
 
1924
                            uint table_changes)
1800
1925
 {
 
1926
   DBUG_ENTER("check_if_supported_alter");
1801
1927
   if (this->check_if_incompatible_data(create_info, table_changes)
1802
1928
       == COMPATIBLE_DATA_NO)
1803
 
     return(HA_ALTER_NOT_SUPPORTED);
1804
 
   else if ((*alter_flags & HA_ALTER_STORED_VCOL).is_set())
1805
 
     return(HA_ALTER_NOT_SUPPORTED);
 
1929
     DBUG_RETURN(HA_ALTER_NOT_SUPPORTED);
1806
1930
   else
1807
 
     return(HA_ALTER_SUPPORTED_WAIT_LOCK);
 
1931
     DBUG_RETURN(HA_ALTER_SUPPORTED_WAIT_LOCK);
1808
1932
 }
1809
1933
 /**
1810
1934
   Tell storage engine to prepare for the on-line alter table (pre-alter)
1819
1943
   @retval   0      OK
1820
1944
   @retval   error  error code passed from storage engine
1821
1945
 */
1822
 
 virtual int alter_table_phase1(THD *thd __attribute__((unused)),
1823
 
                                Table *altered_table __attribute__((unused)),
1824
 
                                HA_CREATE_INFO *create_info __attribute__((unused)),
1825
 
                                HA_ALTER_INFO *alter_info __attribute__((unused)),
1826
 
                                HA_ALTER_FLAGS *alter_flags  __attribute__((unused)))
 
1946
 virtual int alter_table_phase1(THD *thd __attribute__((__unused__)),
 
1947
                                TABLE *altered_table __attribute__((__unused__)),
 
1948
                                HA_CREATE_INFO *create_info __attribute__((__unused__)),
 
1949
                                HA_ALTER_INFO *alter_info __attribute__((__unused__)),
 
1950
                                HA_ALTER_FLAGS *alter_flags  __attribute__((__unused__)))
1827
1951
 {
1828
1952
   return HA_ERR_UNSUPPORTED;
1829
1953
 }
1845
1969
      this call is to be wrapped with a DDL lock. This is currently NOT
1846
1970
      supported.
1847
1971
 */
1848
 
 virtual int alter_table_phase2(THD *thd  __attribute__((unused)),
1849
 
                                Table *altered_table  __attribute__((unused)),
1850
 
                                HA_CREATE_INFO *create_info __attribute__((unused)),
1851
 
                                HA_ALTER_INFO *alter_info __attribute__((unused)),
1852
 
                                HA_ALTER_FLAGS *alter_flags __attribute__((unused)))
 
1972
 virtual int alter_table_phase2(THD *thd  __attribute__((__unused__)),
 
1973
                                TABLE *altered_table  __attribute__((__unused__)),
 
1974
                                HA_CREATE_INFO *create_info __attribute__((__unused__)),
 
1975
                                HA_ALTER_INFO *alter_info __attribute__((__unused__)),
 
1976
                                HA_ALTER_FLAGS *alter_flags __attribute__((__unused__)))
1853
1977
 {
1854
1978
   return HA_ERR_UNSUPPORTED;
1855
1979
 }
1860
1984
    @param    thd               The thread handle
1861
1985
    @param    table             The altered table, re-opened
1862
1986
 */
1863
 
 virtual int alter_table_phase3(THD *thd __attribute__((unused)),
1864
 
                                Table *table __attribute__((unused)))
 
1987
 virtual int alter_table_phase3(THD *thd __attribute__((__unused__)),
 
1988
                                TABLE *table __attribute__((__unused__)))
1865
1989
 {
1866
1990
   return HA_ERR_UNSUPPORTED;
1867
1991
 }
1903
2027
  {
1904
2028
    return HA_ERR_WRONG_COMMAND;
1905
2029
  }
1906
 
  /*
1907
 
    This procedure defines if the storage engine supports virtual columns.
1908
 
    Default false means "not supported".
1909
 
  */
1910
 
  virtual bool check_if_supported_virtual_columns(void) 
1911
 
  { return false; }
1912
2030
 
1913
2031
protected:
1914
2032
  /* Service methods for use by storage engines. */
1940
2058
    the corresponding 'ha_*' method above.
1941
2059
  */
1942
2060
 
1943
 
  virtual int open(const char *name, int mode, uint32_t test_if_locked)=0;
1944
 
  virtual int index_init(uint32_t idx,
1945
 
                         bool sorted __attribute__((unused)))
 
2061
  virtual int open(const char *name, int mode, uint test_if_locked)=0;
 
2062
  virtual int index_init(uint idx,
 
2063
                         bool sorted __attribute__((__unused__)))
1946
2064
  { active_index= idx; return 0; }
1947
2065
  virtual int index_end() { active_index= MAX_KEY; return 0; }
1948
2066
  /**
1954
2072
  */
1955
2073
  virtual int rnd_init(bool scan)= 0;
1956
2074
  virtual int rnd_end() { return 0; }
1957
 
  virtual int write_row(unsigned char *buf __attribute__((unused)))
1958
 
  {
1959
 
    return HA_ERR_WRONG_COMMAND;
1960
 
  }
1961
 
 
1962
 
  virtual int update_row(const unsigned char *old_data __attribute__((unused)),
1963
 
                         unsigned char *new_data __attribute__((unused)))
1964
 
  {
1965
 
    return HA_ERR_WRONG_COMMAND;
1966
 
  }
1967
 
 
1968
 
  virtual int delete_row(const unsigned char *buf __attribute__((unused)))
 
2075
  virtual int write_row(uchar *buf __attribute__((unused)))
 
2076
  {
 
2077
    return HA_ERR_WRONG_COMMAND;
 
2078
  }
 
2079
 
 
2080
  virtual int update_row(const uchar *old_data __attribute__((unused)),
 
2081
                         uchar *new_data __attribute__((unused)))
 
2082
  {
 
2083
    return HA_ERR_WRONG_COMMAND;
 
2084
  }
 
2085
 
 
2086
  virtual int delete_row(const uchar *buf __attribute__((unused)))
1969
2087
  {
1970
2088
    return HA_ERR_WRONG_COMMAND;
1971
2089
  }
2006
2124
  }
2007
2125
  virtual void release_auto_increment(void) { return; };
2008
2126
  /** admin commands - called from mysql_admin_table */
2009
 
  virtual int check_for_upgrade(HA_CHECK_OPT *check_opt __attribute__((unused)))
 
2127
  virtual int check_for_upgrade(HA_CHECK_OPT *check_opt __attribute__((__unused__)))
2010
2128
  { return 0; }
2011
 
  virtual int check(THD* thd __attribute__((unused)),
2012
 
                    HA_CHECK_OPT* check_opt __attribute__((unused)))
 
2129
  virtual int check(THD* thd __attribute__((__unused__)),
 
2130
                    HA_CHECK_OPT* check_opt __attribute__((__unused__)))
2013
2131
  { return HA_ADMIN_NOT_IMPLEMENTED; }
2014
2132
 
2015
2133
  /**
2017
2135
     to specify CHECK option to use to call check()
2018
2136
     upon the table.
2019
2137
  */
2020
 
  virtual int repair(THD* thd __attribute__((unused)),
2021
 
                     HA_CHECK_OPT* check_opt __attribute__((unused)))
 
2138
  virtual int repair(THD* thd __attribute__((__unused__)),
 
2139
                     HA_CHECK_OPT* check_opt __attribute__((__unused__)))
2022
2140
  { return HA_ADMIN_NOT_IMPLEMENTED; }
2023
 
  virtual void start_bulk_insert(ha_rows rows __attribute__((unused)))
 
2141
  virtual void start_bulk_insert(ha_rows rows __attribute__((__unused__)))
2024
2142
  {}
2025
2143
  virtual int end_bulk_insert(void) { return 0; }
2026
 
  virtual int index_read(unsigned char * buf __attribute__((unused)),
2027
 
                         const unsigned char * key __attribute__((unused)),
2028
 
                         uint32_t key_len __attribute__((unused)),
2029
 
                         enum ha_rkey_function find_flag __attribute__((unused)))
 
2144
  virtual int index_read(uchar * buf __attribute__((__unused__)),
 
2145
                         const uchar * key __attribute__((__unused__)),
 
2146
                         uint key_len __attribute__((__unused__)),
 
2147
                         enum ha_rkey_function find_flag __attribute__((__unused__)))
2030
2148
   { return  HA_ERR_WRONG_COMMAND; }
2031
 
  virtual int index_read_last(unsigned char * buf __attribute__((unused)),
2032
 
                              const unsigned char * key __attribute__((unused)),
2033
 
                              uint32_t key_len __attribute__((unused)))
 
2149
  virtual int index_read_last(uchar * buf __attribute__((__unused__)),
 
2150
                              const uchar * key __attribute__((__unused__)),
 
2151
                              uint key_len __attribute__((__unused__)))
2034
2152
   { return (my_errno= HA_ERR_WRONG_COMMAND); }
2035
2153
  /**
2036
2154
    This method is similar to update_row, however the handler doesn't need
2045
2163
    @retval  0   Bulk delete used by handler
2046
2164
    @retval  1   Bulk delete not used, normal operation used
2047
2165
  */
2048
 
  virtual int bulk_update_row(const unsigned char *old_data __attribute__((unused)),
2049
 
                              unsigned char *new_data __attribute__((unused)),
2050
 
                              uint32_t *dup_key_found __attribute__((unused)))
 
2166
  virtual int bulk_update_row(const uchar *old_data __attribute__((__unused__)),
 
2167
                              uchar *new_data __attribute__((__unused__)),
 
2168
                              uint *dup_key_found __attribute__((__unused__)))
2051
2169
  {
2052
 
    assert(false);
 
2170
    DBUG_ASSERT(FALSE);
2053
2171
    return HA_ERR_WRONG_COMMAND;
2054
2172
  }
2055
2173
  /**
2066
2184
    is emulated by doing a 'DELETE FROM t'. HA_ERR_WRONG_COMMAND is
2067
2185
    returned by storage engines that don't support this operation.
2068
2186
  */
2069
 
  virtual int reset_auto_increment(uint64_t value __attribute__((unused)))
2070
 
  { return HA_ERR_WRONG_COMMAND; }
2071
 
  virtual int optimize(THD* thd __attribute__((unused)),
2072
 
                       HA_CHECK_OPT* check_opt __attribute__((unused)))
2073
 
  { return HA_ADMIN_NOT_IMPLEMENTED; }
2074
 
  virtual int analyze(THD* thd __attribute__((unused)),
2075
 
                      HA_CHECK_OPT* check_opt __attribute__((unused)))
2076
 
  { return HA_ADMIN_NOT_IMPLEMENTED; }
2077
 
  virtual bool check_and_repair(THD *thd __attribute__((unused)))
2078
 
  { return true; }
2079
 
  virtual int disable_indexes(uint32_t mode __attribute__((unused)))
2080
 
  { return HA_ERR_WRONG_COMMAND; }
2081
 
  virtual int enable_indexes(uint32_t mode __attribute__((unused)))
2082
 
  { return HA_ERR_WRONG_COMMAND; }
2083
 
  virtual int discard_or_import_tablespace(bool discard __attribute__((unused)))
 
2187
  virtual int reset_auto_increment(uint64_t value __attribute__((__unused__)))
 
2188
  { return HA_ERR_WRONG_COMMAND; }
 
2189
  virtual int optimize(THD* thd __attribute__((__unused__)),
 
2190
                       HA_CHECK_OPT* check_opt __attribute__((__unused__)))
 
2191
  { return HA_ADMIN_NOT_IMPLEMENTED; }
 
2192
  virtual int analyze(THD* thd __attribute__((__unused__)),
 
2193
                      HA_CHECK_OPT* check_opt __attribute__((__unused__)))
 
2194
  { return HA_ADMIN_NOT_IMPLEMENTED; }
 
2195
  virtual bool check_and_repair(THD *thd __attribute__((__unused__)))
 
2196
  { return TRUE; }
 
2197
  virtual int disable_indexes(uint mode __attribute__((__unused__)))
 
2198
  { return HA_ERR_WRONG_COMMAND; }
 
2199
  virtual int enable_indexes(uint mode __attribute__((__unused__)))
 
2200
  { return HA_ERR_WRONG_COMMAND; }
 
2201
  virtual int discard_or_import_tablespace(my_bool discard __attribute__((__unused__)))
2084
2202
  { return (my_errno=HA_ERR_WRONG_COMMAND); }
2085
2203
  virtual void prepare_for_alter(void) { return; }
2086
2204
  virtual void drop_table(const char *name);
2087
 
  virtual int create(const char *name __attribute__((unused)),
2088
 
                     Table *form __attribute__((unused)),
2089
 
                     HA_CREATE_INFO *info __attribute__((unused)))=0;
 
2205
  virtual int create(const char *name __attribute__((__unused__)),
 
2206
                     TABLE *form __attribute__((__unused__)),
 
2207
                     HA_CREATE_INFO *info __attribute__((__unused__)))=0;
2090
2208
 
2091
 
  virtual int create_handler_files(const char *name __attribute__((unused)),
2092
 
                                   const char *old_name __attribute__((unused)),
2093
 
                                   int action_flag __attribute__((unused)),
2094
 
                                   HA_CREATE_INFO *info __attribute__((unused)))
2095
 
  { return false; }
 
2209
  virtual int create_handler_files(const char *name __attribute__((__unused__)),
 
2210
                                   const char *old_name __attribute__((__unused__)),
 
2211
                                   int action_flag __attribute__((__unused__)),
 
2212
                                   HA_CREATE_INFO *info __attribute__((__unused__)))
 
2213
  { return FALSE; }
2096
2214
};
2097
2215
 
2098
2216
 
2116
2234
    : h2(NULL) {};
2117
2235
 
2118
2236
  handler *h; /* The "owner" handler object. It is used for scanning the index */
2119
 
  Table *table; /* Always equal to h->table */
 
2237
  TABLE *table; /* Always equal to h->table */
2120
2238
private:
2121
2239
  /*
2122
2240
    Secondary handler object. It is used to retrieve full table rows by
2125
2243
  handler *h2;
2126
2244
 
2127
2245
  /* Buffer to store rowids, or (rowid, range_id) pairs */
2128
 
  unsigned char *rowids_buf;
2129
 
  unsigned char *rowids_buf_cur;   /* Current position when reading/writing */
2130
 
  unsigned char *rowids_buf_last;  /* When reading: end of used buffer space */
2131
 
  unsigned char *rowids_buf_end;   /* End of the buffer */
2132
 
 
2133
 
  bool dsmrr_eof; /* true <=> We have reached EOF when reading index tuples */
2134
 
 
2135
 
  /* true <=> need range association, buffer holds {rowid, range_id} pairs */
 
2246
  uchar *rowids_buf;
 
2247
  uchar *rowids_buf_cur;   /* Current position when reading/writing */
 
2248
  uchar *rowids_buf_last;  /* When reading: end of used buffer space */
 
2249
  uchar *rowids_buf_end;   /* End of the buffer */
 
2250
 
 
2251
  bool dsmrr_eof; /* TRUE <=> We have reached EOF when reading index tuples */
 
2252
 
 
2253
  /* TRUE <=> need range association, buffer holds {rowid, range_id} pairs */
2136
2254
  bool is_mrr_assoc;
2137
2255
 
2138
 
  bool use_default_impl; /* true <=> shortcut all calls to default MRR impl */
 
2256
  bool use_default_impl; /* TRUE <=> shortcut all calls to default MRR impl */
2139
2257
public:
2140
 
  void init(handler *h_arg, Table *table_arg)
 
2258
  void init(handler *h_arg, TABLE *table_arg)
2141
2259
  {
2142
2260
    h= h_arg; 
2143
2261
    table= table_arg;
2144
2262
  }
2145
2263
  int dsmrr_init(handler *h, KEY *key, RANGE_SEQ_IF *seq_funcs, 
2146
 
                 void *seq_init_param, uint32_t n_ranges, uint32_t mode, 
 
2264
                 void *seq_init_param, uint n_ranges, uint mode, 
2147
2265
                 HANDLER_BUFFER *buf);
2148
2266
  void dsmrr_close();
2149
2267
  int dsmrr_fill_buffer(handler *h);
2150
2268
  int dsmrr_next(handler *h, char **range_info);
2151
2269
 
2152
 
  int dsmrr_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys, uint32_t *bufsz,
2153
 
                 uint32_t *flags, COST_VECT *cost);
 
2270
  int dsmrr_info(uint keyno, uint n_ranges, uint keys, uint *bufsz,
 
2271
                 uint *flags, COST_VECT *cost);
2154
2272
 
2155
 
  ha_rows dsmrr_info_const(uint32_t keyno, RANGE_SEQ_IF *seq, 
2156
 
                            void *seq_init_param, uint32_t n_ranges, uint32_t *bufsz,
2157
 
                            uint32_t *flags, COST_VECT *cost);
 
2273
  ha_rows dsmrr_info_const(uint keyno, RANGE_SEQ_IF *seq, 
 
2274
                            void *seq_init_param, uint n_ranges, uint *bufsz,
 
2275
                            uint *flags, COST_VECT *cost);
2158
2276
private:
2159
 
  bool key_uses_partial_cols(uint32_t keyno);
2160
 
  bool choose_mrr_impl(uint32_t keyno, ha_rows rows, uint32_t *flags, uint32_t *bufsz, 
 
2277
  bool key_uses_partial_cols(uint keyno);
 
2278
  bool choose_mrr_impl(uint keyno, ha_rows rows, uint *flags, uint *bufsz, 
2161
2279
                       COST_VECT *cost);
2162
 
  bool get_disk_sweep_mrr_cost(uint32_t keynr, ha_rows rows, uint32_t flags, 
2163
 
                               uint32_t *buffer_size, COST_VECT *cost);
 
2280
  bool get_disk_sweep_mrr_cost(uint keynr, ha_rows rows, uint flags, 
 
2281
                               uint *buffer_size, COST_VECT *cost);
2164
2282
};
2165
2283
 
2166
2284
extern const char *ha_row_type[];
2171
2289
extern uint32_t total_ha, total_ha_2pc;
2172
2290
 
2173
2291
       /* Wrapper functions */
2174
 
#define ha_commit(thd) (ha_commit_trans((thd), true))
2175
 
#define ha_rollback(thd) (ha_rollback_trans((thd), true))
 
2292
#define ha_commit(thd) (ha_commit_trans((thd), TRUE))
 
2293
#define ha_rollback(thd) (ha_rollback_trans((thd), TRUE))
2176
2294
 
2177
2295
/* lookups */
2178
2296
handlerton *ha_default_handlerton(THD *thd);
2195
2313
  return db_type == NULL ? "UNKNOWN" : hton2plugin[db_type->slot]->name.str;
2196
2314
}
2197
2315
 
2198
 
static inline bool ha_check_storage_engine_flag(const handlerton *db_type, uint32_t flag)
 
2316
static inline bool ha_check_storage_engine_flag(const handlerton *db_type, uint32 flag)
2199
2317
{
2200
 
  return db_type == NULL ? false : test(db_type->flags & flag);
 
2318
  return db_type == NULL ? FALSE : test(db_type->flags & flag);
2201
2319
}
2202
2320
 
2203
2321
static inline bool ha_storage_engine_is_enabled(const handlerton *db_type)
2204
2322
{
2205
2323
  return (db_type && db_type->create) ?
2206
 
         (db_type->state == SHOW_OPTION_YES) : false;
 
2324
         (db_type->state == SHOW_OPTION_YES) : FALSE;
2207
2325
}
2208
2326
 
2209
2327
/* basic stuff */
2214
2332
int ha_finalize_handlerton(st_plugin_int *plugin);
2215
2333
 
2216
2334
TYPELIB *ha_known_exts(void);
 
2335
int ha_panic(enum ha_panic_function flag);
2217
2336
void ha_close_connection(THD* thd);
2218
2337
bool ha_flush_logs(handlerton *db_type);
2219
2338
void ha_drop_database(char* path);
2230
2349
/* discovery */
2231
2350
int ha_create_table_from_engine(THD* thd, const char *db, const char *name);
2232
2351
int ha_discover(THD* thd, const char* dbname, const char* name,
2233
 
                unsigned char** frmblob, size_t* frmlen);
 
2352
                uchar** frmblob, size_t* frmlen);
2234
2353
int ha_find_files(THD *thd,const char *db,const char *path,
2235
2354
                  const char *wild, bool dir, List<LEX_STRING>* files);
2236
2355
int ha_table_exists_in_engine(THD* thd, const char* db, const char* name);
2273
2392
*/
2274
2393
#define trans_need_2pc(thd, all)                   ((total_ha_2pc > 1) && \
2275
2394
        !((all ? &thd->transaction.all : &thd->transaction.stmt)->no_2pc))
 
2395
 
 
2396
#ifdef HAVE_NDB_BINLOG
 
2397
int ha_reset_logs(THD *thd);
 
2398
int ha_binlog_index_purge_file(THD *thd, const char *file);
 
2399
void ha_reset_slave(THD *thd);
 
2400
void ha_binlog_log_query(THD *thd, handlerton *db_type,
 
2401
                         enum_binlog_command binlog_command,
 
2402
                         const char *query, uint query_length,
 
2403
                         const char *db, const char *table_name);
 
2404
void ha_binlog_wait(THD *thd);
 
2405
int ha_binlog_end(THD *thd);
 
2406
#else
 
2407
#define ha_reset_logs(a) do {} while (0)
 
2408
#define ha_binlog_index_purge_file(a,b) do {} while (0)
 
2409
#define ha_reset_slave(a) do {} while (0)
 
2410
#define ha_binlog_log_query(a,b,c,d,e,f,g) do {} while (0)
 
2411
#define ha_binlog_wait(a) do {} while (0)
 
2412
#define ha_binlog_end(a)  do {} while (0)
 
2413
#endif