~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to sql/handler.h

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
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 */
 
15
 
 
16
 
 
17
/* Definitions for parameters to do with handler-routines */
 
18
 
 
19
#ifdef USE_PRAGMA_INTERFACE
 
20
#pragma interface                       /* gcc class implementation */
 
21
#endif
 
22
 
 
23
#include <my_handler.h>
 
24
#include <ft_global.h>
 
25
#include <keycache.h>
 
26
 
 
27
#ifndef NO_HASH
 
28
#define NO_HASH                         /* Not yet implemented */
 
29
#endif
 
30
 
 
31
#define USING_TRANSACTIONS
 
32
 
 
33
// the following is for checking tables
 
34
 
 
35
#define HA_ADMIN_ALREADY_DONE     1
 
36
#define HA_ADMIN_OK               0
 
37
#define HA_ADMIN_NOT_IMPLEMENTED -1
 
38
#define HA_ADMIN_FAILED          -2
 
39
#define HA_ADMIN_CORRUPT         -3
 
40
#define HA_ADMIN_INTERNAL_ERROR  -4
 
41
#define HA_ADMIN_INVALID         -5
 
42
#define HA_ADMIN_REJECT          -6
 
43
#define HA_ADMIN_TRY_ALTER       -7
 
44
#define HA_ADMIN_WRONG_CHECKSUM  -8
 
45
#define HA_ADMIN_NOT_BASE_TABLE  -9
 
46
#define HA_ADMIN_NEEDS_UPGRADE  -10
 
47
#define HA_ADMIN_NEEDS_ALTER    -11
 
48
#define HA_ADMIN_NEEDS_CHECK    -12
 
49
 
 
50
/* Bits in table_flags() to show what database can do */
 
51
 
 
52
#define HA_NO_TRANSACTIONS     (1 << 0) /* Doesn't support transactions */
 
53
#define HA_PARTIAL_COLUMN_READ (1 << 1) /* read may not return all columns */
 
54
#define HA_TABLE_SCAN_ON_INDEX (1 << 2) /* No separate data/index file */
 
55
/*
 
56
  The following should be set if the following is not true when scanning
 
57
  a table with rnd_next()
 
58
  - We will see all rows (including deleted ones)
 
59
  - Row positions are 'table->s->db_record_offset' apart
 
60
  If this flag is not set, filesort will do a postion() call for each matched
 
61
  row to be able to find the row later.
 
62
*/
 
63
#define HA_REC_NOT_IN_SEQ      (1 << 3)
 
64
#define HA_CAN_GEOMETRY        (1 << 4)
 
65
/*
 
66
  Reading keys in random order is as fast as reading keys in sort order
 
67
  (Used in records.cc to decide if we should use a record cache and by
 
68
  filesort to decide if we should sort key + data or key + pointer-to-row
 
69
*/
 
70
#define HA_FAST_KEY_READ       (1 << 5)
 
71
/*
 
72
  Set the following flag if we on delete should force all key to be read
 
73
  and on update read all keys that changes
 
74
*/
 
75
#define HA_REQUIRES_KEY_COLUMNS_FOR_DELETE (1 << 6)
 
76
#define HA_NULL_IN_KEY         (1 << 7) /* One can have keys with NULL */
 
77
#define HA_DUPLICATE_POS       (1 << 8)    /* ha_position() gives dup row */
 
78
#define HA_NO_BLOBS            (1 << 9) /* Doesn't support blobs */
 
79
#define HA_CAN_INDEX_BLOBS     (1 << 10)
 
80
#define HA_AUTO_PART_KEY       (1 << 11) /* auto-increment in multi-part key */
 
81
#define HA_REQUIRE_PRIMARY_KEY (1 << 12) /* .. and can't create a hidden one */
 
82
#define HA_STATS_RECORDS_IS_EXACT (1 << 13) /* stats.records is exact */
 
83
/*
 
84
  INSERT_DELAYED only works with handlers that uses MySQL internal table
 
85
  level locks
 
86
*/
 
87
#define HA_CAN_INSERT_DELAYED  (1 << 14)
 
88
/*
 
89
  If we get the primary key columns for free when we do an index read
 
90
  It also implies that we have to retrive the primary key when using
 
91
  position() and rnd_pos().
 
92
*/
 
93
#define HA_PRIMARY_KEY_IN_READ_INDEX (1 << 15)
 
94
/*
 
95
  If HA_PRIMARY_KEY_REQUIRED_FOR_POSITION is set, it means that to position()
 
96
  uses a primary key. Without primary key, we can't call position().
 
97
*/ 
 
98
#define HA_PRIMARY_KEY_REQUIRED_FOR_POSITION (1 << 16) 
 
99
#define HA_CAN_RTREEKEYS       (1 << 17)
 
100
#define HA_NOT_DELETE_WITH_CACHE (1 << 18)
 
101
/*
 
102
  The following is we need to a primary key to delete (and update) a row.
 
103
  If there is no primary key, all columns needs to be read on update and delete
 
104
*/
 
105
#define HA_PRIMARY_KEY_REQUIRED_FOR_DELETE (1 << 19)
 
106
#define HA_NO_PREFIX_CHAR_KEYS (1 << 20)
 
107
#define HA_CAN_FULLTEXT        (1 << 21)
 
108
#define HA_CAN_SQL_HANDLER     (1 << 22)
 
109
#define HA_NO_AUTO_INCREMENT   (1 << 23)
 
110
#define HA_HAS_CHECKSUM        (1 << 24)
 
111
/* Table data are stored in separate files (for lower_case_table_names) */
 
112
#define HA_FILE_BASED          (1 << 26)
 
113
#define HA_NO_VARCHAR          (1 << 27)
 
114
#define HA_CAN_BIT_FIELD       (1 << 28) /* supports bit fields */
 
115
#define HA_NEED_READ_RANGE_BUFFER (1 << 29) /* for read_multi_range */
 
116
#define HA_ANY_INDEX_MAY_BE_UNIQUE (1 << 30)
 
117
#define HA_NO_COPY_ON_ALTER    (LL(1) << 31)
 
118
#define HA_HAS_RECORDS         (LL(1) << 32) /* records() gives exact count*/
 
119
/* Has it's own method of binlog logging */
 
120
#define HA_HAS_OWN_BINLOGGING  (LL(1) << 33)
 
121
/*
 
122
  Engine is capable of row-format and statement-format logging,
 
123
  respectively
 
124
*/
 
125
#define HA_BINLOG_ROW_CAPABLE  (LL(1) << 34)
 
126
#define HA_BINLOG_STMT_CAPABLE (LL(1) << 35)
 
127
 
 
128
/*
 
129
  Set of all binlog flags. Currently only contain the capabilities
 
130
  flags.
 
131
 */
 
132
#define HA_BINLOG_FLAGS (HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE)
 
133
 
 
134
/* bits in index_flags(index_number) for what you can do with index */
 
135
#define HA_READ_NEXT            1       /* TODO really use this flag */
 
136
#define HA_READ_PREV            2       /* supports ::index_prev */
 
137
#define HA_READ_ORDER           4       /* index_next/prev follow sort order */
 
138
#define HA_READ_RANGE           8       /* can find all records in a range */
 
139
#define HA_ONLY_WHOLE_INDEX     16      /* Can't use part key searches */
 
140
#define HA_KEYREAD_ONLY         64      /* Support HA_EXTRA_KEYREAD */
 
141
 
 
142
/*
 
143
  bits in alter_table_flags:
 
144
*/
 
145
/*
 
146
  These bits are set if different kinds of indexes can be created
 
147
  off-line without re-create of the table (but with a table lock).
 
148
*/
 
149
#define HA_ONLINE_ADD_INDEX_NO_WRITES           (1L << 0) /*add index w/lock*/
 
150
#define HA_ONLINE_DROP_INDEX_NO_WRITES          (1L << 1) /*drop index w/lock*/
 
151
#define HA_ONLINE_ADD_UNIQUE_INDEX_NO_WRITES    (1L << 2) /*add unique w/lock*/
 
152
#define HA_ONLINE_DROP_UNIQUE_INDEX_NO_WRITES   (1L << 3) /*drop uniq. w/lock*/
 
153
#define HA_ONLINE_ADD_PK_INDEX_NO_WRITES        (1L << 4) /*add prim. w/lock*/
 
154
#define HA_ONLINE_DROP_PK_INDEX_NO_WRITES       (1L << 5) /*drop prim. w/lock*/
 
155
/*
 
156
  These are set if different kinds of indexes can be created on-line
 
157
  (without a table lock). If a handler is capable of one or more of
 
158
  these, it should also set the corresponding *_NO_WRITES bit(s).
 
159
*/
 
160
#define HA_ONLINE_ADD_INDEX                     (1L << 6) /*add index online*/
 
161
#define HA_ONLINE_DROP_INDEX                    (1L << 7) /*drop index online*/
 
162
#define HA_ONLINE_ADD_UNIQUE_INDEX              (1L << 8) /*add unique online*/
 
163
#define HA_ONLINE_DROP_UNIQUE_INDEX             (1L << 9) /*drop uniq. online*/
 
164
#define HA_ONLINE_ADD_PK_INDEX                  (1L << 10)/*add prim. online*/
 
165
#define HA_ONLINE_DROP_PK_INDEX                 (1L << 11)/*drop prim. online*/
 
166
/*
 
167
  HA_PARTITION_FUNCTION_SUPPORTED indicates that the function is
 
168
  supported at all.
 
169
  HA_FAST_CHANGE_PARTITION means that optimised variants of the changes
 
170
  exists but they are not necessarily done online.
 
171
 
 
172
  HA_ONLINE_DOUBLE_WRITE means that the handler supports writing to both
 
173
  the new partition and to the old partitions when updating through the
 
174
  old partitioning schema while performing a change of the partitioning.
 
175
  This means that we can support updating of the table while performing
 
176
  the copy phase of the change. For no lock at all also a double write
 
177
  from new to old must exist and this is not required when this flag is
 
178
  set.
 
179
  This is actually removed even before it was introduced the first time.
 
180
  The new idea is that handlers will handle the lock level already in
 
181
  store_lock for ALTER TABLE partitions.
 
182
 
 
183
  HA_PARTITION_ONE_PHASE is a flag that can be set by handlers that take
 
184
  care of changing the partitions online and in one phase. Thus all phases
 
185
  needed to handle the change are implemented inside the storage engine.
 
186
  The storage engine must also support auto-discovery since the frm file
 
187
  is changed as part of the change and this change must be controlled by
 
188
  the storage engine. A typical engine to support this is NDB (through
 
189
  WL #2498).
 
190
*/
 
191
#define HA_PARTITION_FUNCTION_SUPPORTED         (1L << 12)
 
192
#define HA_FAST_CHANGE_PARTITION                (1L << 13)
 
193
#define HA_PARTITION_ONE_PHASE                  (1L << 14)
 
194
 
 
195
/*
 
196
  Index scan will not return records in rowid order. Not guaranteed to be
 
197
  set for unordered (e.g. HASH) indexes.
 
198
*/
 
199
#define HA_KEY_SCAN_NOT_ROR     128 
 
200
 
 
201
/* operations for disable/enable indexes */
 
202
#define HA_KEY_SWITCH_NONUNIQ      0
 
203
#define HA_KEY_SWITCH_ALL          1
 
204
#define HA_KEY_SWITCH_NONUNIQ_SAVE 2
 
205
#define HA_KEY_SWITCH_ALL_SAVE     3
 
206
 
 
207
/*
 
208
  Note: the following includes binlog and closing 0.
 
209
  so: innodb + bdb + ndb + binlog + myisam + myisammrg + archive +
 
210
      example + csv + heap + blackhole + federated + 0
 
211
  (yes, the sum is deliberately inaccurate)
 
212
  TODO remove the limit, use dynarrays
 
213
*/
 
214
#define MAX_HA 15
 
215
 
 
216
/*
 
217
  Parameters for open() (in register form->filestat)
 
218
  HA_GET_INFO does an implicit HA_ABORT_IF_LOCKED
 
219
*/
 
220
 
 
221
#define HA_OPEN_KEYFILE         1
 
222
#define HA_OPEN_RNDFILE         2
 
223
#define HA_GET_INDEX            4
 
224
#define HA_GET_INFO             8       /* do a ha_info() after open */
 
225
#define HA_READ_ONLY            16      /* File opened as readonly */
 
226
/* Try readonly if can't open with read and write */
 
227
#define HA_TRY_READ_ONLY        32
 
228
#define HA_WAIT_IF_LOCKED       64      /* Wait if locked on open */
 
229
#define HA_ABORT_IF_LOCKED      128     /* skip if locked on open.*/
 
230
#define HA_BLOCK_LOCK           256     /* unlock when reading some records */
 
231
#define HA_OPEN_TEMPORARY       512
 
232
 
 
233
        /* Some key definitions */
 
234
#define HA_KEY_NULL_LENGTH      1
 
235
#define HA_KEY_BLOB_LENGTH      2
 
236
 
 
237
#define HA_LEX_CREATE_TMP_TABLE 1
 
238
#define HA_LEX_CREATE_IF_NOT_EXISTS 2
 
239
#define HA_LEX_CREATE_TABLE_LIKE 4
 
240
#define HA_OPTION_NO_CHECKSUM   (1L << 17)
 
241
#define HA_OPTION_NO_DELAY_KEY_WRITE (1L << 18)
 
242
#define HA_MAX_REC_LENGTH       65535
 
243
 
 
244
/* Table caching type */
 
245
#define HA_CACHE_TBL_NONTRANSACT 0
 
246
#define HA_CACHE_TBL_NOCACHE     1
 
247
#define HA_CACHE_TBL_ASKTRANSACT 2
 
248
#define HA_CACHE_TBL_TRANSACT    4
 
249
 
 
250
/* Options of START TRANSACTION statement (and later of SET TRANSACTION stmt) */
 
251
#define MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT 1
 
252
 
 
253
/* Flags for method is_fatal_error */
 
254
#define HA_CHECK_DUP_KEY 1
 
255
#define HA_CHECK_DUP_UNIQUE 2
 
256
#define HA_CHECK_DUP (HA_CHECK_DUP_KEY + HA_CHECK_DUP_UNIQUE)
 
257
 
 
258
enum legacy_db_type
 
259
{
 
260
  DB_TYPE_UNKNOWN=0,DB_TYPE_DIAB_ISAM=1,
 
261
  DB_TYPE_HASH,DB_TYPE_MISAM,DB_TYPE_PISAM,
 
262
  DB_TYPE_RMS_ISAM, DB_TYPE_HEAP, DB_TYPE_ISAM,
 
263
  DB_TYPE_MRG_ISAM, DB_TYPE_MYISAM, DB_TYPE_MRG_MYISAM,
 
264
  DB_TYPE_BERKELEY_DB, DB_TYPE_INNODB,
 
265
  DB_TYPE_GEMINI, DB_TYPE_NDBCLUSTER,
 
266
  DB_TYPE_EXAMPLE_DB, DB_TYPE_ARCHIVE_DB, DB_TYPE_CSV_DB,
 
267
  DB_TYPE_FEDERATED_DB,
 
268
  DB_TYPE_BLACKHOLE_DB,
 
269
  DB_TYPE_PARTITION_DB,
 
270
  DB_TYPE_BINLOG,
 
271
  DB_TYPE_SOLID,
 
272
  DB_TYPE_PBXT,
 
273
  DB_TYPE_TABLE_FUNCTION,
 
274
  DB_TYPE_MEMCACHE,
 
275
  DB_TYPE_FALCON,
 
276
  DB_TYPE_MARIA,
 
277
  DB_TYPE_FIRST_DYNAMIC=42,
 
278
  DB_TYPE_DEFAULT=127 // Must be last
 
279
};
 
280
 
 
281
enum row_type { ROW_TYPE_NOT_USED=-1, ROW_TYPE_DEFAULT, ROW_TYPE_FIXED,
 
282
                ROW_TYPE_DYNAMIC, ROW_TYPE_COMPRESSED,
 
283
                ROW_TYPE_REDUNDANT, ROW_TYPE_COMPACT,
 
284
                /** Unused. Reserved for future versions. */
 
285
                ROW_TYPE_PAGE };
 
286
 
 
287
enum enum_binlog_func {
 
288
  BFN_RESET_LOGS=        1,
 
289
  BFN_RESET_SLAVE=       2,
 
290
  BFN_BINLOG_WAIT=       3,
 
291
  BFN_BINLOG_END=        4,
 
292
  BFN_BINLOG_PURGE_FILE= 5
 
293
};
 
294
 
 
295
enum enum_binlog_command {
 
296
  LOGCOM_CREATE_TABLE,
 
297
  LOGCOM_ALTER_TABLE,
 
298
  LOGCOM_RENAME_TABLE,
 
299
  LOGCOM_DROP_TABLE,
 
300
  LOGCOM_CREATE_DB,
 
301
  LOGCOM_ALTER_DB,
 
302
  LOGCOM_DROP_DB
 
303
};
 
304
 
 
305
/* struct to hold information about the table that should be created */
 
306
 
 
307
/* Bits in used_fields */
 
308
#define HA_CREATE_USED_AUTO             (1L << 0)
 
309
#define HA_CREATE_USED_RAID             (1L << 1) //RAID is no longer availble
 
310
#define HA_CREATE_USED_UNION            (1L << 2)
 
311
#define HA_CREATE_USED_INSERT_METHOD    (1L << 3)
 
312
#define HA_CREATE_USED_MIN_ROWS         (1L << 4)
 
313
#define HA_CREATE_USED_MAX_ROWS         (1L << 5)
 
314
#define HA_CREATE_USED_AVG_ROW_LENGTH   (1L << 6)
 
315
#define HA_CREATE_USED_PACK_KEYS        (1L << 7)
 
316
#define HA_CREATE_USED_CHARSET          (1L << 8)
 
317
#define HA_CREATE_USED_DEFAULT_CHARSET  (1L << 9)
 
318
#define HA_CREATE_USED_DATADIR          (1L << 10)
 
319
#define HA_CREATE_USED_INDEXDIR         (1L << 11)
 
320
#define HA_CREATE_USED_ENGINE           (1L << 12)
 
321
#define HA_CREATE_USED_CHECKSUM         (1L << 13)
 
322
#define HA_CREATE_USED_DELAY_KEY_WRITE  (1L << 14)
 
323
#define HA_CREATE_USED_ROW_FORMAT       (1L << 15)
 
324
#define HA_CREATE_USED_COMMENT          (1L << 16)
 
325
#define HA_CREATE_USED_PASSWORD         (1L << 17)
 
326
#define HA_CREATE_USED_CONNECTION       (1L << 18)
 
327
#define HA_CREATE_USED_KEY_BLOCK_SIZE   (1L << 19)
 
328
/** Unused. Reserved for future versions. */
 
329
#define HA_CREATE_USED_TRANSACTIONAL    (1L << 20)
 
330
/** Unused. Reserved for future versions. */
 
331
#define HA_CREATE_USED_PAGE_CHECKSUM    (1L << 21)
 
332
 
 
333
typedef ulonglong my_xid; // this line is the same as in log_event.h
 
334
#define MYSQL_XID_PREFIX "MySQLXid"
 
335
#define MYSQL_XID_PREFIX_LEN 8 // must be a multiple of 8
 
336
#define MYSQL_XID_OFFSET (MYSQL_XID_PREFIX_LEN+sizeof(server_id))
 
337
#define MYSQL_XID_GTRID_LEN (MYSQL_XID_OFFSET+sizeof(my_xid))
 
338
 
 
339
#define XIDDATASIZE MYSQL_XIDDATASIZE
 
340
#define MAXGTRIDSIZE 64
 
341
#define MAXBQUALSIZE 64
 
342
 
 
343
#define COMPATIBLE_DATA_YES 0
 
344
#define COMPATIBLE_DATA_NO  1
 
345
 
 
346
/**
 
347
  struct xid_t is binary compatible with the XID structure as
 
348
  in the X/Open CAE Specification, Distributed Transaction Processing:
 
349
  The XA Specification, X/Open Company Ltd., 1991.
 
350
  http://www.opengroup.org/bookstore/catalog/c193.htm
 
351
 
 
352
  @see MYSQL_XID in mysql/plugin.h
 
353
*/
 
354
struct xid_t {
 
355
  long formatID;
 
356
  long gtrid_length;
 
357
  long bqual_length;
 
358
  char data[XIDDATASIZE];  // not \0-terminated !
 
359
 
 
360
  xid_t() {}                                /* Remove gcc warning */  
 
361
  bool eq(struct xid_t *xid)
 
362
  { return eq(xid->gtrid_length, xid->bqual_length, xid->data); }
 
363
  bool eq(long g, long b, const char *d)
 
364
  { return g == gtrid_length && b == bqual_length && !memcmp(d, data, g+b); }
 
365
  void set(struct xid_t *xid)
 
366
  { memcpy(this, xid, xid->length()); }
 
367
  void set(long f, const char *g, long gl, const char *b, long bl)
 
368
  {
 
369
    formatID= f;
 
370
    memcpy(data, g, gtrid_length= gl);
 
371
    memcpy(data+gl, b, bqual_length= bl);
 
372
  }
 
373
  void set(ulonglong xid)
 
374
  {
 
375
    my_xid tmp;
 
376
    formatID= 1;
 
377
    set(MYSQL_XID_PREFIX_LEN, 0, MYSQL_XID_PREFIX);
 
378
    memcpy(data+MYSQL_XID_PREFIX_LEN, &server_id, sizeof(server_id));
 
379
    tmp= xid;
 
380
    memcpy(data+MYSQL_XID_OFFSET, &tmp, sizeof(tmp));
 
381
    gtrid_length=MYSQL_XID_GTRID_LEN;
 
382
  }
 
383
  void set(long g, long b, const char *d)
 
384
  {
 
385
    formatID= 1;
 
386
    gtrid_length= g;
 
387
    bqual_length= b;
 
388
    memcpy(data, d, g+b);
 
389
  }
 
390
  bool is_null() { return formatID == -1; }
 
391
  void null() { formatID= -1; }
 
392
  my_xid quick_get_my_xid()
 
393
  {
 
394
    my_xid tmp;
 
395
    memcpy(&tmp, data+MYSQL_XID_OFFSET, sizeof(tmp));
 
396
    return tmp;
 
397
  }
 
398
  my_xid get_my_xid()
 
399
  {
 
400
    return gtrid_length == MYSQL_XID_GTRID_LEN && bqual_length == 0 &&
 
401
           !memcmp(data, MYSQL_XID_PREFIX, MYSQL_XID_PREFIX_LEN) ?
 
402
           quick_get_my_xid() : 0;
 
403
  }
 
404
  uint length()
 
405
  {
 
406
    return sizeof(formatID)+sizeof(gtrid_length)+sizeof(bqual_length)+
 
407
           gtrid_length+bqual_length;
 
408
  }
 
409
  uchar *key()
 
410
  {
 
411
    return (uchar *)&gtrid_length;
 
412
  }
 
413
  uint key_length()
 
414
  {
 
415
    return sizeof(gtrid_length)+sizeof(bqual_length)+gtrid_length+bqual_length;
 
416
  }
 
417
};
 
418
typedef struct xid_t XID;
 
419
 
 
420
/* for recover() handlerton call */
 
421
#define MIN_XID_LIST_SIZE  128
 
422
#ifdef SAFEMALLOC
 
423
#define MAX_XID_LIST_SIZE  256
 
424
#else
 
425
#define MAX_XID_LIST_SIZE  (1024*128)
 
426
#endif
 
427
 
 
428
/*
 
429
  These structures are used to pass information from a set of SQL commands
 
430
  on add/drop/change tablespace definitions to the proper hton.
 
431
*/
 
432
#define UNDEF_NODEGROUP 65535
 
433
enum ts_command_type
 
434
{
 
435
  TS_CMD_NOT_DEFINED = -1,
 
436
  CREATE_TABLESPACE = 0,
 
437
  ALTER_TABLESPACE = 1,
 
438
  CREATE_LOGFILE_GROUP = 2,
 
439
  ALTER_LOGFILE_GROUP = 3,
 
440
  DROP_TABLESPACE = 4,
 
441
  DROP_LOGFILE_GROUP = 5,
 
442
  CHANGE_FILE_TABLESPACE = 6,
 
443
  ALTER_ACCESS_MODE_TABLESPACE = 7
 
444
};
 
445
 
 
446
enum ts_alter_tablespace_type
 
447
{
 
448
  TS_ALTER_TABLESPACE_TYPE_NOT_DEFINED = -1,
 
449
  ALTER_TABLESPACE_ADD_FILE = 1,
 
450
  ALTER_TABLESPACE_DROP_FILE = 2
 
451
};
 
452
 
 
453
enum tablespace_access_mode
 
454
{
 
455
  TS_NOT_DEFINED= -1,
 
456
  TS_READ_ONLY = 0,
 
457
  TS_READ_WRITE = 1,
 
458
  TS_NOT_ACCESSIBLE = 2
 
459
};
 
460
 
 
461
struct handlerton;
 
462
class st_alter_tablespace : public Sql_alloc
 
463
{
 
464
  public:
 
465
  const char *tablespace_name;
 
466
  const char *logfile_group_name;
 
467
  enum ts_command_type ts_cmd_type;
 
468
  enum ts_alter_tablespace_type ts_alter_tablespace_type;
 
469
  const char *data_file_name;
 
470
  const char *undo_file_name;
 
471
  const char *redo_file_name;
 
472
  ulonglong extent_size;
 
473
  ulonglong undo_buffer_size;
 
474
  ulonglong redo_buffer_size;
 
475
  ulonglong initial_size;
 
476
  ulonglong autoextend_size;
 
477
  ulonglong max_size;
 
478
  uint nodegroup_id;
 
479
  handlerton *storage_engine;
 
480
  bool wait_until_completed;
 
481
  const char *ts_comment;
 
482
  enum tablespace_access_mode ts_access_mode;
 
483
  st_alter_tablespace()
 
484
  {
 
485
    tablespace_name= NULL;
 
486
    logfile_group_name= "DEFAULT_LG"; //Default log file group
 
487
    ts_cmd_type= TS_CMD_NOT_DEFINED;
 
488
    data_file_name= NULL;
 
489
    undo_file_name= NULL;
 
490
    redo_file_name= NULL;
 
491
    extent_size= 1024*1024;        //Default 1 MByte
 
492
    undo_buffer_size= 8*1024*1024; //Default 8 MByte
 
493
    redo_buffer_size= 8*1024*1024; //Default 8 MByte
 
494
    initial_size= 128*1024*1024;   //Default 128 MByte
 
495
    autoextend_size= 0;            //No autoextension as default
 
496
    max_size= 0;                   //Max size == initial size => no extension
 
497
    storage_engine= NULL;
 
498
    nodegroup_id= UNDEF_NODEGROUP;
 
499
    wait_until_completed= TRUE;
 
500
    ts_comment= NULL;
 
501
    ts_access_mode= TS_NOT_DEFINED;
 
502
  }
 
503
};
 
504
 
 
505
/* The handler for a table type.  Will be included in the TABLE structure */
 
506
 
 
507
struct st_table;
 
508
typedef struct st_table TABLE;
 
509
typedef struct st_table_share TABLE_SHARE;
 
510
struct st_foreign_key_info;
 
511
typedef struct st_foreign_key_info FOREIGN_KEY_INFO;
 
512
typedef bool (stat_print_fn)(THD *thd, const char *type, uint type_len,
 
513
                             const char *file, uint file_len,
 
514
                             const char *status, uint status_len);
 
515
enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
 
516
extern st_plugin_int *hton2plugin[MAX_HA];
 
517
 
 
518
/* Transaction log maintains type definitions */
 
519
enum log_status
 
520
{
 
521
  HA_LOG_STATUS_FREE= 0,      /* log is free and can be deleted */
 
522
  HA_LOG_STATUS_INUSE= 1,     /* log can't be deleted because it is in use */
 
523
  HA_LOG_STATUS_NOSUCHLOG= 2  /* no such log (can't be returned by
 
524
                                the log iterator status) */
 
525
};
 
526
/*
 
527
  Function for signaling that the log file changed its state from
 
528
  LOG_STATUS_INUSE to LOG_STATUS_FREE
 
529
 
 
530
  Now it do nothing, will be implemented as part of new transaction
 
531
  log management for engines.
 
532
  TODO: implement the function.
 
533
*/
 
534
void signal_log_not_needed(struct handlerton, char *log_file);
 
535
/*
 
536
  Data of transaction log iterator.
 
537
*/
 
538
struct handler_log_file_data {
 
539
  LEX_STRING filename;
 
540
  enum log_status status;
 
541
};
 
542
 
 
543
 
 
544
enum handler_iterator_type
 
545
{
 
546
  /* request of transaction log iterator */
 
547
  HA_TRANSACTLOG_ITERATOR= 1
 
548
};
 
549
enum handler_create_iterator_result
 
550
{
 
551
  HA_ITERATOR_OK,          /* iterator created */
 
552
  HA_ITERATOR_UNSUPPORTED, /* such type of iterator is not supported */
 
553
  HA_ITERATOR_ERROR        /* error during iterator creation */
 
554
};
 
555
 
 
556
/*
 
557
  Iterator structure. Can be used by handler/handlerton for different purposes.
 
558
 
 
559
  Iterator should be created in the way to point "before" the first object
 
560
  it iterate, so next() call move it to the first object or return !=0 if
 
561
  there is nothing to iterate through.
 
562
*/
 
563
struct handler_iterator {
 
564
  /*
 
565
    Moves iterator to next record and return 0 or return !=0
 
566
    if there is no records.
 
567
    iterator_object will be filled by this function if next() returns 0.
 
568
    Content of the iterator_object depend on iterator type.
 
569
  */
 
570
  int (*next)(struct handler_iterator *, void *iterator_object);
 
571
  /*
 
572
    Free resources allocated by iterator, after this call iterator
 
573
    is not usable.
 
574
  */
 
575
  void (*destroy)(struct handler_iterator *);
 
576
  /*
 
577
    Pointer to buffer for the iterator to use.
 
578
    Should be allocated by function which created the iterator and
 
579
    destroied by freed by above "destroy" call
 
580
  */
 
581
  void *buffer;
 
582
};
 
583
 
 
584
/*
 
585
  handlerton is a singleton structure - one instance per storage engine -
 
586
  to provide access to storage engine functionality that works on the
 
587
  "global" level (unlike handler class that works on a per-table basis)
 
588
 
 
589
  usually handlerton instance is defined statically in ha_xxx.cc as
 
590
 
 
591
  static handlerton { ... } xxx_hton;
 
592
 
 
593
  savepoint_*, prepare, recover, and *_by_xid pointers can be 0.
 
594
*/
 
595
struct handlerton
 
596
{
 
597
  /*
 
598
    Historical marker for if the engine is available of not
 
599
  */
 
600
  SHOW_COMP_OPTION state;
 
601
 
 
602
  /*
 
603
    Historical number used for frm file to determine the correct storage engine.
 
604
    This is going away and new engines will just use "name" for this.
 
605
  */
 
606
  enum legacy_db_type db_type;
 
607
  /*
 
608
    each storage engine has it's own memory area (actually a pointer)
 
609
    in the thd, for storing per-connection information.
 
610
    It is accessed as
 
611
 
 
612
      thd->ha_data[xxx_hton.slot]
 
613
 
 
614
   slot number is initialized by MySQL after xxx_init() is called.
 
615
   */
 
616
   uint slot;
 
617
   /*
 
618
     to store per-savepoint data storage engine is provided with an area
 
619
     of a requested size (0 is ok here).
 
620
     savepoint_offset must be initialized statically to the size of
 
621
     the needed memory to store per-savepoint information.
 
622
     After xxx_init it is changed to be an offset to savepoint storage
 
623
     area and need not be used by storage engine.
 
624
     see binlog_hton and binlog_savepoint_set/rollback for an example.
 
625
   */
 
626
   uint savepoint_offset;
 
627
   /*
 
628
     handlerton methods:
 
629
 
 
630
     close_connection is only called if
 
631
     thd->ha_data[xxx_hton.slot] is non-zero, so even if you don't need
 
632
     this storage area - set it to something, so that MySQL would know
 
633
     this storage engine was accessed in this connection
 
634
   */
 
635
   int  (*close_connection)(handlerton *hton, THD *thd);
 
636
   /*
 
637
     sv points to an uninitialized storage area of requested size
 
638
     (see savepoint_offset description)
 
639
   */
 
640
   int  (*savepoint_set)(handlerton *hton, THD *thd, void *sv);
 
641
   /*
 
642
     sv points to a storage area, that was earlier passed
 
643
     to the savepoint_set call
 
644
   */
 
645
   int  (*savepoint_rollback)(handlerton *hton, THD *thd, void *sv);
 
646
   int  (*savepoint_release)(handlerton *hton, THD *thd, void *sv);
 
647
   /*
 
648
     'all' is true if it's a real commit, that makes persistent changes
 
649
     'all' is false if it's not in fact a commit but an end of the
 
650
     statement that is part of the transaction.
 
651
     NOTE 'all' is also false in auto-commit mode where 'end of statement'
 
652
     and 'real commit' mean the same event.
 
653
   */
 
654
   int  (*commit)(handlerton *hton, THD *thd, bool all);
 
655
   int  (*rollback)(handlerton *hton, THD *thd, bool all);
 
656
   int  (*prepare)(handlerton *hton, THD *thd, bool all);
 
657
   int  (*recover)(handlerton *hton, XID *xid_list, uint len);
 
658
   int  (*commit_by_xid)(handlerton *hton, XID *xid);
 
659
   int  (*rollback_by_xid)(handlerton *hton, XID *xid);
 
660
   void *(*create_cursor_read_view)(handlerton *hton, THD *thd);
 
661
   void (*set_cursor_read_view)(handlerton *hton, THD *thd, void *read_view);
 
662
   void (*close_cursor_read_view)(handlerton *hton, THD *thd, void *read_view);
 
663
   handler *(*create)(handlerton *hton, TABLE_SHARE *table, MEM_ROOT *mem_root);
 
664
   void (*drop_database)(handlerton *hton, char* path);
 
665
   int (*panic)(handlerton *hton, enum ha_panic_function flag);
 
666
   int (*start_consistent_snapshot)(handlerton *hton, THD *thd);
 
667
   bool (*flush_logs)(handlerton *hton);
 
668
   bool (*show_status)(handlerton *hton, THD *thd, stat_print_fn *print, enum ha_stat_type stat);
 
669
   uint (*partition_flags)();
 
670
   uint (*alter_table_flags)(uint flags);
 
671
   int (*alter_tablespace)(handlerton *hton, THD *thd, st_alter_tablespace *ts_info);
 
672
   int (*fill_files_table)(handlerton *hton, THD *thd,
 
673
                           TABLE_LIST *tables,
 
674
                           class Item *cond);
 
675
   uint32 flags;                                /* global handler flags */
 
676
   /*
 
677
      Those handlerton functions below are properly initialized at handler
 
678
      init.
 
679
   */
 
680
   int (*binlog_func)(handlerton *hton, THD *thd, enum_binlog_func fn, void *arg);
 
681
   void (*binlog_log_query)(handlerton *hton, THD *thd, 
 
682
                            enum_binlog_command binlog_command,
 
683
                            const char *query, uint query_length,
 
684
                            const char *db, const char *table_name);
 
685
   int (*release_temporary_latches)(handlerton *hton, THD *thd);
 
686
 
 
687
   /*
 
688
     Get log status.
 
689
     If log_status is null then the handler do not support transaction
 
690
     log information (i.e. log iterator can't be created).
 
691
     (see example of implementation in handler.cc, TRANS_LOG_MGM_EXAMPLE_CODE)
 
692
 
 
693
   */
 
694
   enum log_status (*get_log_status)(handlerton *hton, char *log);
 
695
 
 
696
   /*
 
697
     Iterators creator.
 
698
     Presence of the pointer should be checked before using
 
699
   */
 
700
   enum handler_create_iterator_result
 
701
     (*create_iterator)(handlerton *hton, enum handler_iterator_type type,
 
702
                        struct handler_iterator *fill_this_in);
 
703
   int (*discover)(handlerton *hton, THD* thd, const char *db, 
 
704
                   const char *name,
 
705
                   uchar **frmblob, 
 
706
                   size_t *frmlen);
 
707
   int (*find_files)(handlerton *hton, THD *thd,
 
708
                     const char *db,
 
709
                     const char *path,
 
710
                     const char *wild, bool dir, List<LEX_STRING> *files);
 
711
   int (*table_exists_in_engine)(handlerton *hton, THD* thd, const char *db,
 
712
                                 const char *name);
 
713
   uint32 license; /* Flag for Engine License */
 
714
   void *data; /* Location for engines to keep personal structures */
 
715
};
 
716
 
 
717
 
 
718
/* Possible flags of a handlerton (there can be 32 of them) */
 
719
#define HTON_NO_FLAGS                 0
 
720
#define HTON_CLOSE_CURSORS_AT_COMMIT (1 << 0)
 
721
#define HTON_ALTER_NOT_SUPPORTED     (1 << 1) //Engine does not support alter
 
722
#define HTON_CAN_RECREATE            (1 << 2) //Delete all is used fro truncate
 
723
#define HTON_HIDDEN                  (1 << 3) //Engine does not appear in lists
 
724
#define HTON_FLUSH_AFTER_RENAME      (1 << 4)
 
725
#define HTON_NOT_USER_SELECTABLE     (1 << 5)
 
726
#define HTON_TEMPORARY_NOT_SUPPORTED (1 << 6) //Having temporary tables not supported
 
727
#define HTON_SUPPORT_LOG_TABLES      (1 << 7) //Engine supports log tables
 
728
#define HTON_NO_PARTITION            (1 << 8) //You can not partition these tables
 
729
 
 
730
class Ha_trx_info;
 
731
 
 
732
struct THD_TRANS
 
733
{
 
734
  /* true is not all entries in the ht[] support 2pc */
 
735
  bool        no_2pc;
 
736
  /* storage engines that registered in this transaction */
 
737
  Ha_trx_info *ha_list;
 
738
  /* 
 
739
    The purpose of this flag is to keep track of non-transactional
 
740
    tables that were modified in scope of:
 
741
    - transaction, when the variable is a member of
 
742
    THD::transaction.all
 
743
    - top-level statement or sub-statement, when the variable is a
 
744
    member of THD::transaction.stmt
 
745
    This member has the following life cycle:
 
746
    * stmt.modified_non_trans_table is used to keep track of
 
747
    modified non-transactional tables of top-level statements. At
 
748
    the end of the previous statement and at the beginning of the session,
 
749
    it is reset to FALSE.  If such functions
 
750
    as mysql_insert, mysql_update, mysql_delete etc modify a
 
751
    non-transactional table, they set this flag to TRUE.  At the
 
752
    end of the statement, the value of stmt.modified_non_trans_table 
 
753
    is merged with all.modified_non_trans_table and gets reset.
 
754
    * all.modified_non_trans_table is reset at the end of transaction
 
755
    
 
756
    * Since we do not have a dedicated context for execution of a
 
757
    sub-statement, to keep track of non-transactional changes in a
 
758
    sub-statement, we re-use stmt.modified_non_trans_table. 
 
759
    At entrance into a sub-statement, a copy of the value of
 
760
    stmt.modified_non_trans_table (containing the changes of the
 
761
    outer statement) is saved on stack. Then 
 
762
    stmt.modified_non_trans_table is reset to FALSE and the
 
763
    substatement is executed. Then the new value is merged with the
 
764
    saved value.
 
765
  */
 
766
  bool modified_non_trans_table;
 
767
 
 
768
  void reset() { no_2pc= FALSE; modified_non_trans_table= FALSE; }
 
769
};
 
770
 
 
771
 
 
772
/**
 
773
  Either statement transaction or normal transaction - related
 
774
  thread-specific storage engine data.
 
775
 
 
776
  If a storage engine participates in a statement/transaction,
 
777
  an instance of this class is present in
 
778
  thd->transaction.{stmt|all}.ha_list. The addition to
 
779
  {stmt|all}.ha_list is made by trans_register_ha().
 
780
 
 
781
  When it's time to commit or rollback, each element of ha_list
 
782
  is used to access storage engine's prepare()/commit()/rollback()
 
783
  methods, and also to evaluate if a full two phase commit is
 
784
  necessary.
 
785
 
 
786
  @sa General description of transaction handling in handler.cc.
 
787
*/
 
788
 
 
789
class Ha_trx_info
 
790
{
 
791
public:
 
792
  /** Register this storage engine in the given transaction context. */
 
793
  void register_ha(THD_TRANS *trans, handlerton *ht_arg)
 
794
  {
 
795
    DBUG_ASSERT(m_flags == 0);
 
796
    DBUG_ASSERT(m_ht == NULL);
 
797
    DBUG_ASSERT(m_next == NULL);
 
798
 
 
799
    m_ht= ht_arg;
 
800
    m_flags= (int) TRX_READ_ONLY; /* Assume read-only at start. */
 
801
 
 
802
    m_next= trans->ha_list;
 
803
    trans->ha_list= this;
 
804
  }
 
805
 
 
806
  /** Clear, prepare for reuse. */
 
807
  void reset()
 
808
  {
 
809
    m_next= NULL;
 
810
    m_ht= NULL;
 
811
    m_flags= 0;
 
812
  }
 
813
 
 
814
  Ha_trx_info() { reset(); }
 
815
 
 
816
  void set_trx_read_write()
 
817
  {
 
818
    DBUG_ASSERT(is_started());
 
819
    m_flags|= (int) TRX_READ_WRITE;
 
820
  }
 
821
  bool is_trx_read_write() const
 
822
  {
 
823
    DBUG_ASSERT(is_started());
 
824
    return m_flags & (int) TRX_READ_WRITE;
 
825
  }
 
826
  bool is_started() const { return m_ht != NULL; }
 
827
  /** Mark this transaction read-write if the argument is read-write. */
 
828
  void coalesce_trx_with(const Ha_trx_info *stmt_trx)
 
829
  {
 
830
    /*
 
831
      Must be called only after the transaction has been started.
 
832
      Can be called many times, e.g. when we have many
 
833
      read-write statements in a transaction.
 
834
    */
 
835
    DBUG_ASSERT(is_started());
 
836
    if (stmt_trx->is_trx_read_write())
 
837
      set_trx_read_write();
 
838
  }
 
839
  Ha_trx_info *next() const
 
840
  {
 
841
    DBUG_ASSERT(is_started());
 
842
    return m_next;
 
843
  }
 
844
  handlerton *ht() const
 
845
  {
 
846
    DBUG_ASSERT(is_started());
 
847
    return m_ht;
 
848
  }
 
849
private:
 
850
  enum { TRX_READ_ONLY= 0, TRX_READ_WRITE= 1 };
 
851
  /** Auxiliary, used for ha_list management */
 
852
  Ha_trx_info *m_next;
 
853
  /**
 
854
    Although a given Ha_trx_info instance is currently always used
 
855
    for the same storage engine, 'ht' is not-NULL only when the
 
856
    corresponding storage is a part of a transaction.
 
857
  */
 
858
  handlerton *m_ht;
 
859
  /**
 
860
    Transaction flags related to this engine.
 
861
    Not-null only if this instance is a part of transaction.
 
862
    May assume a combination of enum values above.
 
863
  */
 
864
  uchar       m_flags;
 
865
};
 
866
 
 
867
 
 
868
enum enum_tx_isolation { ISO_READ_UNCOMMITTED, ISO_READ_COMMITTED,
 
869
                         ISO_REPEATABLE_READ, ISO_SERIALIZABLE};
 
870
 
 
871
 
 
872
enum ndb_distribution { ND_KEYHASH= 0, ND_LINHASH= 1 };
 
873
 
 
874
 
 
875
typedef struct {
 
876
  ulonglong data_file_length;
 
877
  ulonglong max_data_file_length;
 
878
  ulonglong index_file_length;
 
879
  ulonglong delete_length;
 
880
  ha_rows records;
 
881
  ulong mean_rec_length;
 
882
  ulong create_time;
 
883
  ulong check_time;
 
884
  ulong update_time;
 
885
  ulonglong check_sum;
 
886
} PARTITION_INFO;
 
887
 
 
888
#define UNDEF_NODEGROUP 65535
 
889
class Item;
 
890
struct st_table_log_memory_entry;
 
891
 
 
892
class partition_info;
 
893
 
 
894
struct st_partition_iter;
 
895
#define NOT_A_PARTITION_ID ((uint32)-1)
 
896
 
 
897
enum enum_ha_unused { HA_CHOICE_UNDEF, HA_CHOICE_NO, HA_CHOICE_YES };
 
898
 
 
899
typedef struct st_ha_create_information
 
900
{
 
901
  CHARSET_INFO *table_charset, *default_table_charset;
 
902
  LEX_STRING connect_string;
 
903
  const char *password, *tablespace;
 
904
  LEX_STRING comment;
 
905
  const char *data_file_name, *index_file_name;
 
906
  const char *alias;
 
907
  ulonglong max_rows,min_rows;
 
908
  ulonglong auto_increment_value;
 
909
  ulong table_options;
 
910
  ulong avg_row_length;
 
911
  ulong used_fields;
 
912
  ulong key_block_size;
 
913
  SQL_LIST merge_list;
 
914
  handlerton *db_type;
 
915
  /**
 
916
    Row type of the table definition.
 
917
 
 
918
    Defaults to ROW_TYPE_DEFAULT for all non-ALTER statements.
 
919
    For ALTER TABLE defaults to ROW_TYPE_NOT_USED (means "keep the current").
 
920
 
 
921
    Can be changed either explicitly by the parser.
 
922
    If nothing speficied inherits the value of the original table (if present).
 
923
  */
 
924
  enum row_type row_type;
 
925
  uint null_bits;                       /* NULL bits at start of record */
 
926
  uint options;                         /* OR of HA_CREATE_ options */
 
927
  uint merge_insert_method;
 
928
  uint extra_size;                      /* length of extra data segment */
 
929
  enum enum_ha_unused unused1;
 
930
  bool table_existed;                   /* 1 in create if table existed */
 
931
  bool frm_only;                        /* 1 if no ha_create_table() */
 
932
  bool varchar;                         /* 1 if table has a VARCHAR */
 
933
  enum ha_storage_media storage_media;  /* DEFAULT, DISK or MEMORY */
 
934
  enum enum_ha_unused unused2;
 
935
} HA_CREATE_INFO;
 
936
 
 
937
 
 
938
typedef struct st_key_create_information
 
939
{
 
940
  enum ha_key_alg algorithm;
 
941
  ulong block_size;
 
942
  LEX_STRING parser_name;
 
943
} KEY_CREATE_INFO;
 
944
 
 
945
 
 
946
/*
 
947
  Class for maintaining hooks used inside operations on tables such
 
948
  as: create table functions, delete table functions, and alter table
 
949
  functions.
 
950
 
 
951
  Class is using the Template Method pattern to separate the public
 
952
  usage interface from the private inheritance interface.  This
 
953
  imposes no overhead, since the public non-virtual function is small
 
954
  enough to be inlined.
 
955
 
 
956
  The hooks are usually used for functions that does several things,
 
957
  e.g., create_table_from_items(), which both create a table and lock
 
958
  it.
 
959
 */
 
960
class TABLEOP_HOOKS
 
961
{
 
962
public:
 
963
  TABLEOP_HOOKS() {}
 
964
  virtual ~TABLEOP_HOOKS() {}
 
965
 
 
966
  inline void prelock(TABLE **tables, uint count)
 
967
  {
 
968
    do_prelock(tables, count);
 
969
  }
 
970
 
 
971
  inline int postlock(TABLE **tables, uint count)
 
972
  {
 
973
    return do_postlock(tables, count);
 
974
  }
 
975
private:
 
976
  /* Function primitive that is called prior to locking tables */
 
977
  virtual void do_prelock(TABLE **tables, uint count)
 
978
  {
 
979
    /* Default is to do nothing */
 
980
  }
 
981
 
 
982
  /**
 
983
     Primitive called after tables are locked.
 
984
 
 
985
     If an error is returned, the tables will be unlocked and error
 
986
     handling start.
 
987
 
 
988
     @return Error code or zero.
 
989
   */
 
990
  virtual int do_postlock(TABLE **tables, uint count)
 
991
  {
 
992
    return 0;                           /* Default is to do nothing */
 
993
  }
 
994
};
 
995
 
 
996
typedef struct st_savepoint SAVEPOINT;
 
997
extern ulong savepoint_alloc_size;
 
998
extern KEY_CREATE_INFO default_key_create_info;
 
999
 
 
1000
/* Forward declaration for condition pushdown to storage engine */
 
1001
typedef class Item COND;
 
1002
 
 
1003
typedef struct st_ha_check_opt
 
1004
{
 
1005
  st_ha_check_opt() {}                        /* Remove gcc warning */
 
1006
  ulong sort_buffer_size;
 
1007
  uint flags;       /* isam layer flags (e.g. for myisamchk) */
 
1008
  uint sql_flags;   /* sql layer flags - for something myisamchk cannot do */
 
1009
  KEY_CACHE *key_cache; /* new key cache when changing key cache */
 
1010
  void init();
 
1011
} HA_CHECK_OPT;
 
1012
 
 
1013
 
 
1014
 
 
1015
/*
 
1016
  This is a buffer area that the handler can use to store rows.
 
1017
  'end_of_used_area' should be kept updated after calls to
 
1018
  read-functions so that other parts of the code can use the
 
1019
  remaining area (until next read calls is issued).
 
1020
*/
 
1021
 
 
1022
typedef struct st_handler_buffer
 
1023
{
 
1024
  const uchar *buffer;         /* Buffer one can start using */
 
1025
  const uchar *buffer_end;     /* End of buffer */
 
1026
  uchar *end_of_used_area;     /* End of area that was used by handler */
 
1027
} HANDLER_BUFFER;
 
1028
 
 
1029
typedef struct system_status_var SSV;
 
1030
 
 
1031
class ha_statistics
 
1032
{
 
1033
public:
 
1034
  ulonglong data_file_length;           /* Length off data file */
 
1035
  ulonglong max_data_file_length;       /* Length off data file */
 
1036
  ulonglong index_file_length;
 
1037
  ulonglong max_index_file_length;
 
1038
  ulonglong delete_length;              /* Free bytes */
 
1039
  ulonglong auto_increment_value;
 
1040
  /*
 
1041
    The number of records in the table. 
 
1042
      0    - means the table has exactly 0 rows
 
1043
    other  - if (table_flags() & HA_STATS_RECORDS_IS_EXACT)
 
1044
               the value is the exact number of records in the table
 
1045
             else
 
1046
               it is an estimate
 
1047
  */
 
1048
  ha_rows records;
 
1049
  ha_rows deleted;                      /* Deleted records */
 
1050
  ulong mean_rec_length;                /* physical reclength */
 
1051
  ulong create_time;                    /* When table was created */
 
1052
  ulong check_time;
 
1053
  ulong update_time;
 
1054
  uint block_size;                      /* index block size */
 
1055
 
 
1056
  ha_statistics():
 
1057
    data_file_length(0), max_data_file_length(0),
 
1058
    index_file_length(0), delete_length(0), auto_increment_value(0),
 
1059
    records(0), deleted(0), mean_rec_length(0), create_time(0),
 
1060
    check_time(0), update_time(0), block_size(0)
 
1061
  {}
 
1062
};
 
1063
 
 
1064
uint calculate_key_len(TABLE *, uint, const uchar *, key_part_map);
 
1065
/*
 
1066
  bitmap with first N+1 bits set
 
1067
  (keypart_map for a key prefix of [0..N] keyparts)
 
1068
*/
 
1069
#define make_keypart_map(N) (((key_part_map)2 << (N)) - 1)
 
1070
/*
 
1071
  bitmap with first N bits set
 
1072
  (keypart_map for a key prefix of [0..N-1] keyparts)
 
1073
*/
 
1074
#define make_prev_keypart_map(N) (((key_part_map)1 << (N)) - 1)
 
1075
 
 
1076
/**
 
1077
  The handler class is the interface for dynamically loadable
 
1078
  storage engines. Do not add ifdefs and take care when adding or
 
1079
  changing virtual functions to avoid vtable confusion
 
1080
*/
 
1081
 
 
1082
class handler :public Sql_alloc
 
1083
{
 
1084
public:
 
1085
  typedef ulonglong Table_flags;
 
1086
protected:
 
1087
  struct st_table_share *table_share;   /* The table definition */
 
1088
  struct st_table *table;               /* The current open table */
 
1089
  Table_flags cached_table_flags;       /* Set on init() and open() */
 
1090
 
 
1091
  ha_rows estimation_rows_to_insert;
 
1092
public:
 
1093
  handlerton *ht;                 /* storage engine of this handler */
 
1094
  uchar *ref;                           /* Pointer to current row */
 
1095
  uchar *dup_ref;                       /* Pointer to duplicate row */
 
1096
 
 
1097
  ha_statistics stats;
 
1098
 
 
1099
  /** The following are for read_multi_range */
 
1100
  bool multi_range_sorted;
 
1101
  KEY_MULTI_RANGE *multi_range_curr;
 
1102
  KEY_MULTI_RANGE *multi_range_end;
 
1103
  HANDLER_BUFFER *multi_range_buffer;
 
1104
 
 
1105
  /** The following are for read_range() */
 
1106
  key_range save_end_range, *end_range;
 
1107
  KEY_PART_INFO *range_key_part;
 
1108
  int key_compare_result_on_equal;
 
1109
  bool eq_range;
 
1110
 
 
1111
  uint errkey;                          /* Last dup key */
 
1112
  uint key_used_on_scan;
 
1113
  uint active_index;
 
1114
  /** Length of ref (1-8 or the clustered key length) */
 
1115
  uint ref_length;
 
1116
  FT_INFO *ft_handler;
 
1117
  enum {NONE=0, INDEX, RND} inited;
 
1118
  bool locked;
 
1119
  bool implicit_emptied;                /* Can be !=0 only if HEAP */
 
1120
  const COND *pushed_cond;
 
1121
  /**
 
1122
    next_insert_id is the next value which should be inserted into the
 
1123
    auto_increment column: in a inserting-multi-row statement (like INSERT
 
1124
    SELECT), for the first row where the autoinc value is not specified by the
 
1125
    statement, get_auto_increment() called and asked to generate a value,
 
1126
    next_insert_id is set to the next value, then for all other rows
 
1127
    next_insert_id is used (and increased each time) without calling
 
1128
    get_auto_increment().
 
1129
  */
 
1130
  ulonglong next_insert_id;
 
1131
  /**
 
1132
    insert id for the current row (*autogenerated*; if not
 
1133
    autogenerated, it's 0).
 
1134
    At first successful insertion, this variable is stored into
 
1135
    THD::first_successful_insert_id_in_cur_stmt.
 
1136
  */
 
1137
  ulonglong insert_id_for_cur_row;
 
1138
  /**
 
1139
    Interval returned by get_auto_increment() and being consumed by the
 
1140
    inserter.
 
1141
  */
 
1142
  Discrete_interval auto_inc_interval_for_cur_row;
 
1143
  /**
 
1144
     Number of reserved auto-increment intervals. Serves as a heuristic
 
1145
     when we have no estimation of how many records the statement will insert:
 
1146
     the more intervals we have reserved, the bigger the next one. Reset in
 
1147
     handler::ha_release_auto_increment().
 
1148
  */
 
1149
  uint auto_inc_intervals_count;
 
1150
 
 
1151
  handler(handlerton *ht_arg, TABLE_SHARE *share_arg)
 
1152
    :table_share(share_arg), table(0),
 
1153
    estimation_rows_to_insert(0), ht(ht_arg),
 
1154
    ref(0), key_used_on_scan(MAX_KEY), active_index(MAX_KEY),
 
1155
    ref_length(sizeof(my_off_t)),
 
1156
    ft_handler(0), inited(NONE),
 
1157
    locked(FALSE), implicit_emptied(0),
 
1158
    pushed_cond(0), next_insert_id(0), insert_id_for_cur_row(0),
 
1159
    auto_inc_intervals_count(0)
 
1160
    {}
 
1161
  virtual ~handler(void)
 
1162
  {
 
1163
    DBUG_ASSERT(locked == FALSE);
 
1164
    /* TODO: DBUG_ASSERT(inited == NONE); */
 
1165
  }
 
1166
  virtual handler *clone(MEM_ROOT *mem_root);
 
1167
  /** This is called after create to allow us to set up cached variables */
 
1168
  void init()
 
1169
  {
 
1170
    cached_table_flags= table_flags();
 
1171
  }
 
1172
  /* ha_ methods: pubilc wrappers for private virtual API */
 
1173
 
 
1174
  int ha_open(TABLE *table, const char *name, int mode, int test_if_locked);
 
1175
  int ha_index_init(uint idx, bool sorted)
 
1176
  {
 
1177
    int result;
 
1178
    DBUG_ENTER("ha_index_init");
 
1179
    DBUG_ASSERT(inited==NONE);
 
1180
    if (!(result= index_init(idx, sorted)))
 
1181
      inited=INDEX;
 
1182
    DBUG_RETURN(result);
 
1183
  }
 
1184
  int ha_index_end()
 
1185
  {
 
1186
    DBUG_ENTER("ha_index_end");
 
1187
    DBUG_ASSERT(inited==INDEX);
 
1188
    inited=NONE;
 
1189
    DBUG_RETURN(index_end());
 
1190
  }
 
1191
  int ha_rnd_init(bool scan)
 
1192
  {
 
1193
    int result;
 
1194
    DBUG_ENTER("ha_rnd_init");
 
1195
    DBUG_ASSERT(inited==NONE || (inited==RND && scan));
 
1196
    inited= (result= rnd_init(scan)) ? NONE: RND;
 
1197
    DBUG_RETURN(result);
 
1198
  }
 
1199
  int ha_rnd_end()
 
1200
  {
 
1201
    DBUG_ENTER("ha_rnd_end");
 
1202
    DBUG_ASSERT(inited==RND);
 
1203
    inited=NONE;
 
1204
    DBUG_RETURN(rnd_end());
 
1205
  }
 
1206
  int ha_reset();
 
1207
  /* this is necessary in many places, e.g. in HANDLER command */
 
1208
  int ha_index_or_rnd_end()
 
1209
  {
 
1210
    return inited == INDEX ? ha_index_end() : inited == RND ? ha_rnd_end() : 0;
 
1211
  }
 
1212
  /**
 
1213
    The cached_table_flags is set at ha_open and ha_external_lock
 
1214
  */
 
1215
  Table_flags ha_table_flags() const { return cached_table_flags; }
 
1216
  /**
 
1217
    These functions represent the public interface to *users* of the
 
1218
    handler class, hence they are *not* virtual. For the inheritance
 
1219
    interface, see the (private) functions write_row(), update_row(),
 
1220
    and delete_row() below.
 
1221
  */
 
1222
  int ha_external_lock(THD *thd, int lock_type);
 
1223
  int ha_write_row(uchar * buf);
 
1224
  int ha_update_row(const uchar * old_data, uchar * new_data);
 
1225
  int ha_delete_row(const uchar * buf);
 
1226
  void ha_release_auto_increment();
 
1227
 
 
1228
  int check_collation_compatibility();
 
1229
  int ha_check_for_upgrade(HA_CHECK_OPT *check_opt);
 
1230
  /** to be actually called to get 'check()' functionality*/
 
1231
  int ha_check(THD *thd, HA_CHECK_OPT *check_opt);
 
1232
  int ha_repair(THD* thd, HA_CHECK_OPT* check_opt);
 
1233
  void ha_start_bulk_insert(ha_rows rows)
 
1234
  {
 
1235
    estimation_rows_to_insert= rows;
 
1236
    start_bulk_insert(rows);
 
1237
  }
 
1238
  int ha_end_bulk_insert()
 
1239
  {
 
1240
    estimation_rows_to_insert= 0;
 
1241
    return end_bulk_insert();
 
1242
  }
 
1243
  int ha_bulk_update_row(const uchar *old_data, uchar *new_data,
 
1244
                         uint *dup_key_found);
 
1245
  int ha_delete_all_rows();
 
1246
  int ha_reset_auto_increment(ulonglong value);
 
1247
  int ha_backup(THD* thd, HA_CHECK_OPT* check_opt);
 
1248
  int ha_restore(THD* thd, HA_CHECK_OPT* check_opt);
 
1249
  int ha_optimize(THD* thd, HA_CHECK_OPT* check_opt);
 
1250
  int ha_analyze(THD* thd, HA_CHECK_OPT* check_opt);
 
1251
  bool ha_check_and_repair(THD *thd);
 
1252
  int ha_disable_indexes(uint mode);
 
1253
  int ha_enable_indexes(uint mode);
 
1254
  int ha_discard_or_import_tablespace(my_bool discard);
 
1255
  void ha_prepare_for_alter();
 
1256
  int ha_rename_table(const char *from, const char *to);
 
1257
  int ha_delete_table(const char *name);
 
1258
  void ha_drop_table(const char *name);
 
1259
 
 
1260
  int ha_create(const char *name, TABLE *form, HA_CREATE_INFO *info);
 
1261
 
 
1262
  int ha_create_handler_files(const char *name, const char *old_name,
 
1263
                              int action_flag, HA_CREATE_INFO *info);
 
1264
 
 
1265
  int ha_change_partitions(HA_CREATE_INFO *create_info,
 
1266
                           const char *path,
 
1267
                           ulonglong * const copied,
 
1268
                           ulonglong * const deleted,
 
1269
                           const uchar *pack_frm_data,
 
1270
                           size_t pack_frm_len);
 
1271
  int ha_drop_partitions(const char *path);
 
1272
  int ha_rename_partitions(const char *path);
 
1273
 
 
1274
  void adjust_next_insert_id_after_explicit_value(ulonglong nr);
 
1275
  int update_auto_increment();
 
1276
  void print_keydup_error(uint key_nr, const char *msg);
 
1277
  virtual void print_error(int error, myf errflag);
 
1278
  virtual bool get_error_message(int error, String *buf);
 
1279
  uint get_dup_key(int error);
 
1280
  virtual void change_table_ptr(TABLE *table_arg, TABLE_SHARE *share)
 
1281
  {
 
1282
    table= table_arg;
 
1283
    table_share= share;
 
1284
  }
 
1285
  virtual double scan_time()
 
1286
  { return ulonglong2double(stats.data_file_length) / IO_SIZE + 2; }
 
1287
  virtual double read_time(uint index, uint ranges, ha_rows rows)
 
1288
  { return rows2double(ranges+rows); }
 
1289
  virtual const key_map *keys_to_use_for_scanning() { return &key_map_empty; }
 
1290
  bool has_transactions()
 
1291
  { return (ha_table_flags() & HA_NO_TRANSACTIONS) == 0; }
 
1292
  virtual uint extra_rec_buf_length() const { return 0; }
 
1293
 
 
1294
  /**
 
1295
    This method is used to analyse the error to see whether the error
 
1296
    is ignorable or not, certain handlers can have more error that are
 
1297
    ignorable than others. E.g. the partition handler can get inserts
 
1298
    into a range where there is no partition and this is an ignorable
 
1299
    error.
 
1300
    HA_ERR_FOUND_DUP_UNIQUE is a special case in MyISAM that means the
 
1301
    same thing as HA_ERR_FOUND_DUP_KEY but can in some cases lead to
 
1302
    a slightly different error message.
 
1303
  */
 
1304
  virtual bool is_fatal_error(int error, uint flags)
 
1305
  {
 
1306
    if (!error ||
 
1307
        ((flags & HA_CHECK_DUP_KEY) &&
 
1308
         (error == HA_ERR_FOUND_DUPP_KEY ||
 
1309
          error == HA_ERR_FOUND_DUPP_UNIQUE)))
 
1310
      return FALSE;
 
1311
    return TRUE;
 
1312
  }
 
1313
 
 
1314
  /**
 
1315
    Number of rows in table. It will only be called if
 
1316
    (table_flags() & (HA_HAS_RECORDS | HA_STATS_RECORDS_IS_EXACT)) != 0
 
1317
  */
 
1318
  virtual ha_rows records() { return stats.records; }
 
1319
  /**
 
1320
    Return upper bound of current number of records in the table
 
1321
    (max. of how many records one will retrieve when doing a full table scan)
 
1322
    If upper bound is not known, HA_POS_ERROR should be returned as a max
 
1323
    possible upper bound.
 
1324
  */
 
1325
  virtual ha_rows estimate_rows_upper_bound()
 
1326
  { return stats.records+EXTRA_RECORDS; }
 
1327
 
 
1328
  /**
 
1329
    Get the row type from the storage engine.  If this method returns
 
1330
    ROW_TYPE_NOT_USED, the information in HA_CREATE_INFO should be used.
 
1331
  */
 
1332
  virtual enum row_type get_row_type() const { return ROW_TYPE_NOT_USED; }
 
1333
 
 
1334
  virtual const char *index_type(uint key_number) { DBUG_ASSERT(0); return "";}
 
1335
 
 
1336
 
 
1337
  /**
 
1338
    Signal that the table->read_set and table->write_set table maps changed
 
1339
    The handler is allowed to set additional bits in the above map in this
 
1340
    call. Normally the handler should ignore all calls until we have done
 
1341
    a ha_rnd_init() or ha_index_init(), write_row(), update_row or delete_row()
 
1342
    as there may be several calls to this routine.
 
1343
  */
 
1344
  virtual void column_bitmaps_signal();
 
1345
  uint get_index(void) const { return active_index; }
 
1346
  virtual int close(void)=0;
 
1347
 
 
1348
  /**
 
1349
    @retval  0   Bulk update used by handler
 
1350
    @retval  1   Bulk update not used, normal operation used
 
1351
  */
 
1352
  virtual bool start_bulk_update() { return 1; }
 
1353
  /**
 
1354
    @retval  0   Bulk delete used by handler
 
1355
    @retval  1   Bulk delete not used, normal operation used
 
1356
  */
 
1357
  virtual bool start_bulk_delete() { return 1; }
 
1358
  /**
 
1359
    After this call all outstanding updates must be performed. The number
 
1360
    of duplicate key errors are reported in the duplicate key parameter.
 
1361
    It is allowed to continue to the batched update after this call, the
 
1362
    handler has to wait until end_bulk_update with changing state.
 
1363
 
 
1364
    @param    dup_key_found       Number of duplicate keys found
 
1365
 
 
1366
    @retval  0           Success
 
1367
    @retval  >0          Error code
 
1368
  */
 
1369
  virtual int exec_bulk_update(uint *dup_key_found)
 
1370
  {
 
1371
    DBUG_ASSERT(FALSE);
 
1372
    return HA_ERR_WRONG_COMMAND;
 
1373
  }
 
1374
  /**
 
1375
    Perform any needed clean-up, no outstanding updates are there at the
 
1376
    moment.
 
1377
  */
 
1378
  virtual void end_bulk_update() { return; }
 
1379
  /**
 
1380
    Execute all outstanding deletes and close down the bulk delete.
 
1381
 
 
1382
    @retval 0             Success
 
1383
    @retval >0            Error code
 
1384
  */
 
1385
  virtual int end_bulk_delete()
 
1386
  {
 
1387
    DBUG_ASSERT(FALSE);
 
1388
    return HA_ERR_WRONG_COMMAND;
 
1389
  }
 
1390
  /**
 
1391
     @brief
 
1392
     Positions an index cursor to the index specified in the handle. Fetches the
 
1393
     row if available. If the key value is null, begin at the first key of the
 
1394
     index.
 
1395
  */
 
1396
  virtual int index_read_map(uchar * buf, const uchar * key,
 
1397
                             key_part_map keypart_map,
 
1398
                             enum ha_rkey_function find_flag)
 
1399
  {
 
1400
    uint key_len= calculate_key_len(table, active_index, key, keypart_map);
 
1401
    return  index_read(buf, key, key_len, find_flag);
 
1402
  }
 
1403
  /**
 
1404
     @brief
 
1405
     Positions an index cursor to the index specified in the handle. Fetches the
 
1406
     row if available. If the key value is null, begin at the first key of the
 
1407
     index.
 
1408
  */
 
1409
  virtual int index_read_idx_map(uchar * buf, uint index, const uchar * key,
 
1410
                                 key_part_map keypart_map,
 
1411
                                 enum ha_rkey_function find_flag);
 
1412
  virtual int index_next(uchar * buf)
 
1413
   { return  HA_ERR_WRONG_COMMAND; }
 
1414
  virtual int index_prev(uchar * buf)
 
1415
   { return  HA_ERR_WRONG_COMMAND; }
 
1416
  virtual int index_first(uchar * buf)
 
1417
   { return  HA_ERR_WRONG_COMMAND; }
 
1418
  virtual int index_last(uchar * buf)
 
1419
   { return  HA_ERR_WRONG_COMMAND; }
 
1420
  virtual int index_next_same(uchar *buf, const uchar *key, uint keylen);
 
1421
  /**
 
1422
     @brief
 
1423
     The following functions works like index_read, but it find the last
 
1424
     row with the current key value or prefix.
 
1425
  */
 
1426
  virtual int index_read_last_map(uchar * buf, const uchar * key,
 
1427
                                  key_part_map keypart_map)
 
1428
  {
 
1429
    uint key_len= calculate_key_len(table, active_index, key, keypart_map);
 
1430
    return index_read_last(buf, key, key_len);
 
1431
  }
 
1432
  virtual int read_multi_range_first(KEY_MULTI_RANGE **found_range_p,
 
1433
                                     KEY_MULTI_RANGE *ranges, uint range_count,
 
1434
                                     bool sorted, HANDLER_BUFFER *buffer);
 
1435
  virtual int read_multi_range_next(KEY_MULTI_RANGE **found_range_p);
 
1436
  virtual int read_range_first(const key_range *start_key,
 
1437
                               const key_range *end_key,
 
1438
                               bool eq_range, bool sorted);
 
1439
  virtual int read_range_next();
 
1440
  int compare_key(key_range *range);
 
1441
  virtual int ft_init() { return HA_ERR_WRONG_COMMAND; }
 
1442
  void ft_end() { ft_handler=NULL; }
 
1443
  virtual FT_INFO *ft_init_ext(uint flags, uint inx,String *key)
 
1444
    { return NULL; }
 
1445
  virtual int ft_read(uchar *buf) { return HA_ERR_WRONG_COMMAND; }
 
1446
  virtual int rnd_next(uchar *buf)=0;
 
1447
  virtual int rnd_pos(uchar * buf, uchar *pos)=0;
 
1448
  /**
 
1449
    One has to use this method when to find
 
1450
    random position by record as the plain
 
1451
    position() call doesn't work for some
 
1452
    handlers for random position.
 
1453
  */
 
1454
  virtual int rnd_pos_by_record(uchar *record)
 
1455
    {
 
1456
      position(record);
 
1457
      return rnd_pos(record, ref);
 
1458
    }
 
1459
  virtual int read_first_row(uchar *buf, uint primary_key);
 
1460
  /**
 
1461
    The following function is only needed for tables that may be temporary
 
1462
    tables during joins.
 
1463
  */
 
1464
  virtual int restart_rnd_next(uchar *buf, uchar *pos)
 
1465
    { return HA_ERR_WRONG_COMMAND; }
 
1466
  virtual int rnd_same(uchar *buf, uint inx)
 
1467
    { return HA_ERR_WRONG_COMMAND; }
 
1468
  virtual ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key)
 
1469
    { return (ha_rows) 10; }
 
1470
  virtual void position(const uchar *record)=0;
 
1471
  virtual int info(uint)=0; // see my_base.h for full description
 
1472
  virtual void get_dynamic_partition_info(PARTITION_INFO *stat_info,
 
1473
                                          uint part_id);
 
1474
  virtual int extra(enum ha_extra_function operation)
 
1475
  { return 0; }
 
1476
  virtual int extra_opt(enum ha_extra_function operation, ulong cache_size)
 
1477
  { return extra(operation); }
 
1478
 
 
1479
  /**
 
1480
    In an UPDATE or DELETE, if the row under the cursor was locked by another
 
1481
    transaction, and the engine used an optimistic read of the last
 
1482
    committed row value under the cursor, then the engine returns 1 from this
 
1483
    function. MySQL must NOT try to update this optimistic value. If the
 
1484
    optimistic value does not match the WHERE condition, MySQL can decide to
 
1485
    skip over this row. Currently only works for InnoDB. This can be used to
 
1486
    avoid unnecessary lock waits.
 
1487
 
 
1488
    If this method returns nonzero, it will also signal the storage
 
1489
    engine that the next read will be a locking re-read of the row.
 
1490
  */
 
1491
  virtual bool was_semi_consistent_read() { return 0; }
 
1492
  /**
 
1493
    Tell the engine whether it should avoid unnecessary lock waits.
 
1494
    If yes, in an UPDATE or DELETE, if the row under the cursor was locked
 
1495
    by another transaction, the engine may try an optimistic read of
 
1496
    the last committed row value under the cursor.
 
1497
  */
 
1498
  virtual void try_semi_consistent_read(bool) {}
 
1499
  virtual void unlock_row() {}
 
1500
  virtual int start_stmt(THD *thd, thr_lock_type lock_type) {return 0;}
 
1501
  virtual void get_auto_increment(ulonglong offset, ulonglong increment,
 
1502
                                  ulonglong nb_desired_values,
 
1503
                                  ulonglong *first_value,
 
1504
                                  ulonglong *nb_reserved_values);
 
1505
  void set_next_insert_id(ulonglong id)
 
1506
  {
 
1507
    DBUG_PRINT("info",("auto_increment: next value %lu", (ulong)id));
 
1508
    next_insert_id= id;
 
1509
  }
 
1510
  void restore_auto_increment(ulonglong prev_insert_id)
 
1511
  {
 
1512
    /*
 
1513
      Insertion of a row failed, re-use the lastly generated auto_increment
 
1514
      id, for the next row. This is achieved by resetting next_insert_id to
 
1515
      what it was before the failed insertion (that old value is provided by
 
1516
      the caller). If that value was 0, it was the first row of the INSERT;
 
1517
      then if insert_id_for_cur_row contains 0 it means no id was generated
 
1518
      for this first row, so no id was generated since the INSERT started, so
 
1519
      we should set next_insert_id to 0; if insert_id_for_cur_row is not 0, it
 
1520
      is the generated id of the first and failed row, so we use it.
 
1521
    */
 
1522
    next_insert_id= (prev_insert_id > 0) ? prev_insert_id :
 
1523
      insert_id_for_cur_row;
 
1524
  }
 
1525
 
 
1526
  virtual void update_create_info(HA_CREATE_INFO *create_info) {}
 
1527
  int check_old_types();
 
1528
  virtual int assign_to_keycache(THD* thd, HA_CHECK_OPT* check_opt)
 
1529
  { return HA_ADMIN_NOT_IMPLEMENTED; }
 
1530
  virtual int preload_keys(THD* thd, HA_CHECK_OPT* check_opt)
 
1531
  { return HA_ADMIN_NOT_IMPLEMENTED; }
 
1532
  /* end of the list of admin commands */
 
1533
 
 
1534
  virtual int dump(THD* thd, int fd = -1) { return HA_ERR_WRONG_COMMAND; }
 
1535
  virtual int indexes_are_disabled(void) {return 0;}
 
1536
  virtual int net_read_dump(NET* net) { return HA_ERR_WRONG_COMMAND; }
 
1537
  virtual char *update_table_comment(const char * comment)
 
1538
  { return (char*) comment;}
 
1539
  virtual void append_create_info(String *packet) {}
 
1540
  /**
 
1541
    If index == MAX_KEY then a check for table is made and if index <
 
1542
    MAX_KEY then a check is made if the table has foreign keys and if
 
1543
    a foreign key uses this index (and thus the index cannot be dropped).
 
1544
 
 
1545
    @param  index            Index to check if foreign key uses it
 
1546
 
 
1547
    @retval   TRUE            Foreign key defined on table or index
 
1548
    @retval   FALSE           No foreign key defined
 
1549
  */
 
1550
  virtual bool is_fk_defined_on_table_or_index(uint index)
 
1551
  { return FALSE; }
 
1552
  virtual char* get_foreign_key_create_info()
 
1553
  { return(NULL);}  /* gets foreign key create string from InnoDB */
 
1554
  virtual char* get_tablespace_name(THD *thd, char *name, uint name_len)
 
1555
  { return(NULL);}  /* gets tablespace name from handler */
 
1556
  /** used in ALTER TABLE; 1 if changing storage engine is allowed */
 
1557
  virtual bool can_switch_engines() { return 1; }
 
1558
  /** used in REPLACE; is > 0 if table is referred by a FOREIGN KEY */
 
1559
  virtual int get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list)
 
1560
  { return 0; }
 
1561
  virtual uint referenced_by_foreign_key() { return 0;}
 
1562
  virtual void init_table_handle_for_HANDLER()
 
1563
  { return; }       /* prepare InnoDB for HANDLER */
 
1564
  virtual void free_foreign_key_create_info(char* str) {}
 
1565
  /** The following can be called without an open handler */
 
1566
  virtual const char *table_type() const =0;
 
1567
  /**
 
1568
    If frm_error() is called then we will use this to find out what file
 
1569
    extentions exist for the storage engine. This is also used by the default
 
1570
    rename_table and delete_table method in handler.cc.
 
1571
 
 
1572
    For engines that have two file name extentions (separate meta/index file
 
1573
    and data file), the order of elements is relevant. First element of engine
 
1574
    file name extentions array should be meta/index file extention. Second
 
1575
    element - data file extention. This order is assumed by
 
1576
    prepare_for_repair() when REPAIR TABLE ... USE_FRM is issued.
 
1577
  */
 
1578
  virtual const char **bas_ext() const =0;
 
1579
 
 
1580
  virtual int get_default_no_partitions(HA_CREATE_INFO *info) { return 1;}
 
1581
  virtual void set_auto_partitions(partition_info *part_info) { return; }
 
1582
  virtual bool get_no_parts(const char *name,
 
1583
                            uint *no_parts)
 
1584
  {
 
1585
    *no_parts= 0;
 
1586
    return 0;
 
1587
  }
 
1588
  virtual void set_part_info(partition_info *part_info) {return;}
 
1589
 
 
1590
  virtual ulong index_flags(uint idx, uint part, bool all_parts) const =0;
 
1591
 
 
1592
  virtual int add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys)
 
1593
  { return (HA_ERR_WRONG_COMMAND); }
 
1594
  virtual int prepare_drop_index(TABLE *table_arg, uint *key_num,
 
1595
                                 uint num_of_keys)
 
1596
  { return (HA_ERR_WRONG_COMMAND); }
 
1597
  virtual int final_drop_index(TABLE *table_arg)
 
1598
  { return (HA_ERR_WRONG_COMMAND); }
 
1599
 
 
1600
  uint max_record_length() const
 
1601
  { return min(HA_MAX_REC_LENGTH, max_supported_record_length()); }
 
1602
  uint max_keys() const
 
1603
  { return min(MAX_KEY, max_supported_keys()); }
 
1604
  uint max_key_parts() const
 
1605
  { return min(MAX_REF_PARTS, max_supported_key_parts()); }
 
1606
  uint max_key_length() const
 
1607
  { return min(MAX_KEY_LENGTH, max_supported_key_length()); }
 
1608
  uint max_key_part_length() const
 
1609
  { return min(MAX_KEY_LENGTH, max_supported_key_part_length()); }
 
1610
 
 
1611
  virtual uint max_supported_record_length() const { return HA_MAX_REC_LENGTH; }
 
1612
  virtual uint max_supported_keys() const { return 0; }
 
1613
  virtual uint max_supported_key_parts() const { return MAX_REF_PARTS; }
 
1614
  virtual uint max_supported_key_length() const { return MAX_KEY_LENGTH; }
 
1615
  virtual uint max_supported_key_part_length() const { return 255; }
 
1616
  virtual uint min_record_length(uint options) const { return 1; }
 
1617
 
 
1618
  virtual bool low_byte_first() const { return 1; }
 
1619
  virtual uint checksum() const { return 0; }
 
1620
  virtual bool is_crashed() const  { return 0; }
 
1621
  virtual bool auto_repair() const { return 0; }
 
1622
 
 
1623
 
 
1624
#define CHF_CREATE_FLAG 0
 
1625
#define CHF_DELETE_FLAG 1
 
1626
#define CHF_RENAME_FLAG 2
 
1627
#define CHF_INDEX_FLAG  3
 
1628
 
 
1629
 
 
1630
  /**
 
1631
    @note lock_count() can return > 1 if the table is MERGE or partitioned.
 
1632
  */
 
1633
  virtual uint lock_count(void) const { return 1; }
 
1634
  /**
 
1635
    Is not invoked for non-transactional temporary tables.
 
1636
 
 
1637
    @note store_lock() can return more than one lock if the table is MERGE
 
1638
    or partitioned.
 
1639
 
 
1640
    @note that one can NOT rely on table->in_use in store_lock().  It may
 
1641
    refer to a different thread if called from mysql_lock_abort_for_thread().
 
1642
 
 
1643
    @note If the table is MERGE, store_lock() can return less locks
 
1644
    than lock_count() claimed. This can happen when the MERGE children
 
1645
    are not attached when this is called from another thread.
 
1646
  */
 
1647
  virtual THR_LOCK_DATA **store_lock(THD *thd,
 
1648
                                     THR_LOCK_DATA **to,
 
1649
                                     enum thr_lock_type lock_type)=0;
 
1650
 
 
1651
  /** Type of table for caching query */
 
1652
  virtual uint8 table_cache_type() { return HA_CACHE_TBL_NONTRANSACT; }
 
1653
 
 
1654
 
 
1655
  /**
 
1656
    @brief Register a named table with a call back function to the query cache.
 
1657
 
 
1658
    @param thd The thread handle
 
1659
    @param table_key A pointer to the table name in the table cache
 
1660
    @param key_length The length of the table name
 
1661
    @param[out] engine_callback The pointer to the storage engine call back
 
1662
      function
 
1663
    @param[out] engine_data Storage engine specific data which could be
 
1664
      anything
 
1665
 
 
1666
    This method offers the storage engine, the possibility to store a reference
 
1667
    to a table name which is going to be used with query cache. 
 
1668
    The method is called each time a statement is written to the cache and can
 
1669
    be used to verify if a specific statement is cachable. It also offers
 
1670
    the possibility to register a generic (but static) call back function which
 
1671
    is called each time a statement is matched against the query cache.
 
1672
 
 
1673
    @note If engine_data supplied with this function is different from
 
1674
      engine_data supplied with the callback function, and the callback returns
 
1675
      FALSE, a table invalidation on the current table will occur.
 
1676
 
 
1677
    @return Upon success the engine_callback will point to the storage engine
 
1678
      call back function, if any, and engine_data will point to any storage
 
1679
      engine data used in the specific implementation.
 
1680
      @retval TRUE Success
 
1681
      @retval FALSE The specified table or current statement should not be
 
1682
        cached
 
1683
  */
 
1684
 
 
1685
  virtual my_bool register_query_cache_table(THD *thd, char *table_key,
 
1686
                                             uint key_length,
 
1687
                                             qc_engine_callback
 
1688
                                             *engine_callback,
 
1689
                                             ulonglong *engine_data)
 
1690
  {
 
1691
    *engine_callback= 0;
 
1692
    return TRUE;
 
1693
  }
 
1694
 
 
1695
 
 
1696
 /*
 
1697
   @retval TRUE   Primary key (if there is one) is clustered
 
1698
                  key covering all fields
 
1699
   @retval FALSE  otherwise
 
1700
 */
 
1701
 virtual bool primary_key_is_clustered() { return FALSE; }
 
1702
 virtual int cmp_ref(const uchar *ref1, const uchar *ref2)
 
1703
 {
 
1704
   return memcmp(ref1, ref2, ref_length);
 
1705
 }
 
1706
 
 
1707
 /*
 
1708
   Condition pushdown to storage engines
 
1709
 */
 
1710
 
 
1711
 /**
 
1712
   Push condition down to the table handler.
 
1713
 
 
1714
   @param  cond   Condition to be pushed. The condition tree must not be
 
1715
                  modified by the by the caller.
 
1716
 
 
1717
   @return
 
1718
     The 'remainder' condition that caller must use to filter out records.
 
1719
     NULL means the handler will not return rows that do not match the
 
1720
     passed condition.
 
1721
 
 
1722
   @note
 
1723
   The pushed conditions form a stack (from which one can remove the
 
1724
   last pushed condition using cond_pop).
 
1725
   The table handler filters out rows using (pushed_cond1 AND pushed_cond2 
 
1726
   AND ... AND pushed_condN)
 
1727
   or less restrictive condition, depending on handler's capabilities.
 
1728
 
 
1729
   handler->ha_reset() call empties the condition stack.
 
1730
   Calls to rnd_init/rnd_end, index_init/index_end etc do not affect the
 
1731
   condition stack.
 
1732
 */ 
 
1733
 virtual const COND *cond_push(const COND *cond) { return cond; };
 
1734
 /**
 
1735
   Pop the top condition from the condition stack of the handler instance.
 
1736
 
 
1737
   Pops the top if condition stack, if stack is not empty.
 
1738
 */
 
1739
 virtual void cond_pop() { return; };
 
1740
 virtual bool check_if_incompatible_data(HA_CREATE_INFO *create_info,
 
1741
                                         uint table_changes)
 
1742
 { return COMPATIBLE_DATA_NO; }
 
1743
 
 
1744
  /**
 
1745
    use_hidden_primary_key() is called in case of an update/delete when
 
1746
    (table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
 
1747
    but we don't have a primary key
 
1748
  */
 
1749
  virtual void use_hidden_primary_key();
 
1750
  virtual uint alter_table_flags(uint flags)
 
1751
  {
 
1752
    if (ht->alter_table_flags)
 
1753
      return ht->alter_table_flags(flags);
 
1754
    return 0;
 
1755
  }
 
1756
 
 
1757
protected:
 
1758
  /* Service methods for use by storage engines. */
 
1759
  void ha_statistic_increment(ulong SSV::*offset) const;
 
1760
  void **ha_data(THD *) const;
 
1761
  THD *ha_thd(void) const;
 
1762
 
 
1763
  /**
 
1764
    Default rename_table() and delete_table() rename/delete files with a
 
1765
    given name and extensions from bas_ext().
 
1766
 
 
1767
    These methods can be overridden, but their default implementation
 
1768
    provide useful functionality.
 
1769
  */
 
1770
  virtual int rename_table(const char *from, const char *to);
 
1771
  /**
 
1772
    Delete a table in the engine. Called for base as well as temporary
 
1773
    tables.
 
1774
  */
 
1775
  virtual int delete_table(const char *name);
 
1776
private:
 
1777
  /* Private helpers */
 
1778
  inline void mark_trx_read_write();
 
1779
private:
 
1780
  /*
 
1781
    Low-level primitives for storage engines.  These should be
 
1782
    overridden by the storage engine class. To call these methods, use
 
1783
    the corresponding 'ha_*' method above.
 
1784
  */
 
1785
 
 
1786
  virtual int open(const char *name, int mode, uint test_if_locked)=0;
 
1787
  virtual int index_init(uint idx, bool sorted) { active_index= idx; return 0; }
 
1788
  virtual int index_end() { active_index= MAX_KEY; return 0; }
 
1789
  /**
 
1790
    rnd_init() can be called two times without rnd_end() in between
 
1791
    (it only makes sense if scan=1).
 
1792
    then the second call should prepare for the new table scan (e.g
 
1793
    if rnd_init allocates the cursor, second call should position it
 
1794
    to the start of the table, no need to deallocate and allocate it again
 
1795
  */
 
1796
  virtual int rnd_init(bool scan)= 0;
 
1797
  virtual int rnd_end() { return 0; }
 
1798
  virtual int write_row(uchar *buf __attribute__((unused)))
 
1799
  {
 
1800
    return HA_ERR_WRONG_COMMAND;
 
1801
  }
 
1802
 
 
1803
  virtual int update_row(const uchar *old_data __attribute__((unused)),
 
1804
                         uchar *new_data __attribute__((unused)))
 
1805
  {
 
1806
    return HA_ERR_WRONG_COMMAND;
 
1807
  }
 
1808
 
 
1809
  virtual int delete_row(const uchar *buf __attribute__((unused)))
 
1810
  {
 
1811
    return HA_ERR_WRONG_COMMAND;
 
1812
  }
 
1813
  /**
 
1814
    Reset state of file to after 'open'.
 
1815
    This function is called after every statement for all tables used
 
1816
    by that statement.
 
1817
  */
 
1818
  virtual int reset() { return 0; }
 
1819
  virtual Table_flags table_flags(void) const= 0;
 
1820
  /**
 
1821
    Is not invoked for non-transactional temporary tables.
 
1822
 
 
1823
    Tells the storage engine that we intend to read or write data
 
1824
    from the table. This call is prefixed with a call to handler::store_lock()
 
1825
    and is invoked only for those handler instances that stored the lock.
 
1826
 
 
1827
    Calls to rnd_init/index_init are prefixed with this call. When table
 
1828
    IO is complete, we call external_lock(F_UNLCK).
 
1829
    A storage engine writer should expect that each call to
 
1830
    ::external_lock(F_[RD|WR]LOCK is followed by a call to
 
1831
    ::external_lock(F_UNLCK). If it is not, it is a bug in MySQL.
 
1832
 
 
1833
    The name and signature originate from the first implementation
 
1834
    in MyISAM, which would call fcntl to set/clear an advisory
 
1835
    lock on the data file in this method.
 
1836
 
 
1837
    @param   lock_type    F_RDLCK, F_WRLCK, F_UNLCK
 
1838
 
 
1839
    @return  non-0 in case of failure, 0 in case of success.
 
1840
    When lock_type is F_UNLCK, the return value is ignored.
 
1841
  */
 
1842
  virtual int external_lock(THD *thd __attribute__((unused)),
 
1843
                            int lock_type __attribute__((unused)))
 
1844
  {
 
1845
    return 0;
 
1846
  }
 
1847
  virtual void release_auto_increment() { return; };
 
1848
  /** admin commands - called from mysql_admin_table */
 
1849
  virtual int check_for_upgrade(HA_CHECK_OPT *check_opt)
 
1850
  { return 0; }
 
1851
  virtual int check(THD* thd, HA_CHECK_OPT* check_opt)
 
1852
  { return HA_ADMIN_NOT_IMPLEMENTED; }
 
1853
 
 
1854
  /**
 
1855
     In this method check_opt can be modified
 
1856
     to specify CHECK option to use to call check()
 
1857
     upon the table.
 
1858
  */
 
1859
  virtual int repair(THD* thd, HA_CHECK_OPT* check_opt)
 
1860
  { return HA_ADMIN_NOT_IMPLEMENTED; }
 
1861
  virtual void start_bulk_insert(ha_rows rows) {}
 
1862
  virtual int end_bulk_insert() { return 0; }
 
1863
  virtual int index_read(uchar * buf, const uchar * key, uint key_len,
 
1864
                         enum ha_rkey_function find_flag)
 
1865
   { return  HA_ERR_WRONG_COMMAND; }
 
1866
  virtual int index_read_last(uchar * buf, const uchar * key, uint key_len)
 
1867
   { return (my_errno= HA_ERR_WRONG_COMMAND); }
 
1868
  /**
 
1869
    This method is similar to update_row, however the handler doesn't need
 
1870
    to execute the updates at this point in time. The handler can be certain
 
1871
    that another call to bulk_update_row will occur OR a call to
 
1872
    exec_bulk_update before the set of updates in this query is concluded.
 
1873
 
 
1874
    @param    old_data       Old record
 
1875
    @param    new_data       New record
 
1876
    @param    dup_key_found  Number of duplicate keys found
 
1877
 
 
1878
    @retval  0   Bulk delete used by handler
 
1879
    @retval  1   Bulk delete not used, normal operation used
 
1880
  */
 
1881
  virtual int bulk_update_row(const uchar *old_data, uchar *new_data,
 
1882
                              uint *dup_key_found)
 
1883
  {
 
1884
    DBUG_ASSERT(FALSE);
 
1885
    return HA_ERR_WRONG_COMMAND;
 
1886
  }
 
1887
  /**
 
1888
    This is called to delete all rows in a table
 
1889
    If the handler don't support this, then this function will
 
1890
    return HA_ERR_WRONG_COMMAND and MySQL will delete the rows one
 
1891
    by one. It should reset auto_increment if
 
1892
    thd->lex->sql_command == SQLCOM_TRUNCATE.
 
1893
  */
 
1894
  virtual int delete_all_rows()
 
1895
  { return (my_errno=HA_ERR_WRONG_COMMAND); }
 
1896
  /**
 
1897
    Reset the auto-increment counter to the given value, i.e. the next row
 
1898
    inserted will get the given value. This is called e.g. after TRUNCATE
 
1899
    is emulated by doing a 'DELETE FROM t'. HA_ERR_WRONG_COMMAND is
 
1900
    returned by storage engines that don't support this operation.
 
1901
  */
 
1902
  virtual int reset_auto_increment(ulonglong value)
 
1903
  { return HA_ERR_WRONG_COMMAND; }
 
1904
  virtual int backup(THD* thd, HA_CHECK_OPT* check_opt)
 
1905
  { return HA_ADMIN_NOT_IMPLEMENTED; }
 
1906
  /**
 
1907
    Restore assumes .frm file must exist, and that generate_table() has been
 
1908
    called; It will just copy the data file and run repair.
 
1909
  */
 
1910
  virtual int restore(THD* thd, HA_CHECK_OPT* check_opt)
 
1911
  { return HA_ADMIN_NOT_IMPLEMENTED; }
 
1912
  virtual int optimize(THD* thd, HA_CHECK_OPT* check_opt)
 
1913
  { return HA_ADMIN_NOT_IMPLEMENTED; }
 
1914
  virtual int analyze(THD* thd, HA_CHECK_OPT* check_opt)
 
1915
  { return HA_ADMIN_NOT_IMPLEMENTED; }
 
1916
  virtual bool check_and_repair(THD *thd) { return TRUE; }
 
1917
  virtual int disable_indexes(uint mode) { return HA_ERR_WRONG_COMMAND; }
 
1918
  virtual int enable_indexes(uint mode) { return HA_ERR_WRONG_COMMAND; }
 
1919
  virtual int discard_or_import_tablespace(my_bool discard)
 
1920
  { return (my_errno=HA_ERR_WRONG_COMMAND); }
 
1921
  virtual void prepare_for_alter() { return; }
 
1922
  virtual void drop_table(const char *name);
 
1923
  virtual int create(const char *name, TABLE *form, HA_CREATE_INFO *info)=0;
 
1924
 
 
1925
  virtual int create_handler_files(const char *name, const char *old_name,
 
1926
                                   int action_flag, HA_CREATE_INFO *info)
 
1927
  { return FALSE; }
 
1928
 
 
1929
  virtual int change_partitions(HA_CREATE_INFO *create_info,
 
1930
                                const char *path,
 
1931
                                ulonglong * const copied,
 
1932
                                ulonglong * const deleted,
 
1933
                                const uchar *pack_frm_data,
 
1934
                                size_t pack_frm_len)
 
1935
  { return HA_ERR_WRONG_COMMAND; }
 
1936
  virtual int drop_partitions(const char *path)
 
1937
  { return HA_ERR_WRONG_COMMAND; }
 
1938
  virtual int rename_partitions(const char *path)
 
1939
  { return HA_ERR_WRONG_COMMAND; }
 
1940
};
 
1941
 
 
1942
 
 
1943
        /* Some extern variables used with handlers */
 
1944
 
 
1945
extern const char *ha_row_type[];
 
1946
extern MYSQL_PLUGIN_IMPORT const char *tx_isolation_names[];
 
1947
extern MYSQL_PLUGIN_IMPORT const char *binlog_format_names[];
 
1948
extern TYPELIB tx_isolation_typelib;
 
1949
extern TYPELIB myisam_stats_method_typelib;
 
1950
extern ulong total_ha, total_ha_2pc;
 
1951
 
 
1952
       /* Wrapper functions */
 
1953
#define ha_commit(thd) (ha_commit_trans((thd), TRUE))
 
1954
#define ha_rollback(thd) (ha_rollback_trans((thd), TRUE))
 
1955
 
 
1956
/* lookups */
 
1957
handlerton *ha_default_handlerton(THD *thd);
 
1958
plugin_ref ha_resolve_by_name(THD *thd, const LEX_STRING *name);
 
1959
plugin_ref ha_lock_engine(THD *thd, handlerton *hton);
 
1960
handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type);
 
1961
handler *get_new_handler(TABLE_SHARE *share, MEM_ROOT *alloc,
 
1962
                         handlerton *db_type);
 
1963
handlerton *ha_checktype(THD *thd, enum legacy_db_type database_type,
 
1964
                          bool no_substitute, bool report_error);
 
1965
 
 
1966
 
 
1967
static inline enum legacy_db_type ha_legacy_type(const handlerton *db_type)
 
1968
{
 
1969
  return (db_type == NULL) ? DB_TYPE_UNKNOWN : db_type->db_type;
 
1970
}
 
1971
 
 
1972
static inline const char *ha_resolve_storage_engine_name(const handlerton *db_type)
 
1973
{
 
1974
  return db_type == NULL ? "UNKNOWN" : hton2plugin[db_type->slot]->name.str;
 
1975
}
 
1976
 
 
1977
static inline bool ha_check_storage_engine_flag(const handlerton *db_type, uint32 flag)
 
1978
{
 
1979
  return db_type == NULL ? FALSE : test(db_type->flags & flag);
 
1980
}
 
1981
 
 
1982
static inline bool ha_storage_engine_is_enabled(const handlerton *db_type)
 
1983
{
 
1984
  return (db_type && db_type->create) ?
 
1985
         (db_type->state == SHOW_OPTION_YES) : FALSE;
 
1986
}
 
1987
 
 
1988
/* basic stuff */
 
1989
int ha_init_errors(void);
 
1990
int ha_init(void);
 
1991
int ha_end(void);
 
1992
int ha_initialize_handlerton(st_plugin_int *plugin);
 
1993
int ha_finalize_handlerton(st_plugin_int *plugin);
 
1994
 
 
1995
TYPELIB *ha_known_exts(void);
 
1996
int ha_panic(enum ha_panic_function flag);
 
1997
void ha_close_connection(THD* thd);
 
1998
bool ha_flush_logs(handlerton *db_type);
 
1999
void ha_drop_database(char* path);
 
2000
int ha_create_table(THD *thd, const char *path,
 
2001
                    const char *db, const char *table_name,
 
2002
                    HA_CREATE_INFO *create_info,
 
2003
                    bool update_create_info);
 
2004
int ha_delete_table(THD *thd, handlerton *db_type, const char *path,
 
2005
                    const char *db, const char *alias, bool generate_warning);
 
2006
 
 
2007
/* statistics and info */
 
2008
bool ha_show_status(THD *thd, handlerton *db_type, enum ha_stat_type stat);
 
2009
 
 
2010
/* discovery */
 
2011
int ha_create_table_from_engine(THD* thd, const char *db, const char *name);
 
2012
int ha_discover(THD* thd, const char* dbname, const char* name,
 
2013
                uchar** frmblob, size_t* frmlen);
 
2014
int ha_find_files(THD *thd,const char *db,const char *path,
 
2015
                  const char *wild, bool dir, List<LEX_STRING>* files);
 
2016
int ha_table_exists_in_engine(THD* thd, const char* db, const char* name);
 
2017
 
 
2018
/* key cache */
 
2019
extern "C" int ha_init_key_cache(const char *name, KEY_CACHE *key_cache);
 
2020
int ha_resize_key_cache(KEY_CACHE *key_cache);
 
2021
int ha_change_key_cache_param(KEY_CACHE *key_cache);
 
2022
int ha_change_key_cache(KEY_CACHE *old_key_cache, KEY_CACHE *new_key_cache);
 
2023
int ha_end_key_cache(KEY_CACHE *key_cache);
 
2024
 
 
2025
/* report to InnoDB that control passes to the client */
 
2026
int ha_release_temporary_latches(THD *thd);
 
2027
 
 
2028
/* transactions: interface to handlerton functions */
 
2029
int ha_start_consistent_snapshot(THD *thd);
 
2030
int ha_commit_or_rollback_by_xid(XID *xid, bool commit);
 
2031
int ha_commit_one_phase(THD *thd, bool all);
 
2032
int ha_rollback_trans(THD *thd, bool all);
 
2033
int ha_prepare(THD *thd);
 
2034
int ha_recover(HASH *commit_list);
 
2035
 
 
2036
/* transactions: these functions never call handlerton functions directly */
 
2037
int ha_commit_trans(THD *thd, bool all);
 
2038
int ha_autocommit_or_rollback(THD *thd, int error);
 
2039
int ha_enable_transaction(THD *thd, bool on);
 
2040
 
 
2041
/* savepoints */
 
2042
int ha_rollback_to_savepoint(THD *thd, SAVEPOINT *sv);
 
2043
int ha_savepoint(THD *thd, SAVEPOINT *sv);
 
2044
int ha_release_savepoint(THD *thd, SAVEPOINT *sv);
 
2045
 
 
2046
/* these are called by storage engines */
 
2047
void trans_register_ha(THD *thd, bool all, handlerton *ht);
 
2048
 
 
2049
/*
 
2050
  Storage engine has to assume the transaction will end up with 2pc if
 
2051
   - there is more than one 2pc-capable storage engine available
 
2052
   - in the current transaction 2pc was not disabled yet
 
2053
*/
 
2054
#define trans_need_2pc(thd, all)                   ((total_ha_2pc > 1) && \
 
2055
        !((all ? &thd->transaction.all : &thd->transaction.stmt)->no_2pc))
 
2056
 
 
2057
#ifdef HAVE_NDB_BINLOG
 
2058
int ha_reset_logs(THD *thd);
 
2059
int ha_binlog_index_purge_file(THD *thd, const char *file);
 
2060
void ha_reset_slave(THD *thd);
 
2061
void ha_binlog_log_query(THD *thd, handlerton *db_type,
 
2062
                         enum_binlog_command binlog_command,
 
2063
                         const char *query, uint query_length,
 
2064
                         const char *db, const char *table_name);
 
2065
void ha_binlog_wait(THD *thd);
 
2066
int ha_binlog_end(THD *thd);
 
2067
#else
 
2068
#define ha_reset_logs(a) do {} while (0)
 
2069
#define ha_binlog_index_purge_file(a,b) do {} while (0)
 
2070
#define ha_reset_slave(a) do {} while (0)
 
2071
#define ha_binlog_log_query(a,b,c,d,e,f,g) do {} while (0)
 
2072
#define ha_binlog_wait(a) do {} while (0)
 
2073
#define ha_binlog_end(a)  do {} while (0)
 
2074
#endif