~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/handler.h

  • Committer: Brian Aker
  • Date: 2009-04-27 14:36:40 UTC
  • Revision ID: brian@gaz-20090427143640-f6zjmtt9vm55qgm2
Patch on show processlist from  davi@apache.org

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
 
20
#ifndef DRIZZLED_HANDLER_H
 
21
#define DRIZZLED_HANDLER_H
 
22
 
 
23
#include <drizzled/xid.h>
 
24
#include <drizzled/discrete_interval.h>
20
25
 
21
26
/* Definitions for parameters to do with handler-routines */
22
27
 
23
 
#ifdef USE_PRAGMA_INTERFACE
24
 
#pragma interface                       /* gcc class implementation */
25
 
#endif
26
 
 
27
 
#include <mysys/my_handler.h>
28
28
#include <storage/myisam/keycache.h>
29
 
 
30
 
#ifndef NO_HASH
31
 
#define NO_HASH                         /* Not yet implemented */
32
 
#endif
33
 
 
34
 
// the following is for checking tables
35
 
 
36
 
#define HA_ADMIN_ALREADY_DONE     1
37
 
#define HA_ADMIN_OK               0
38
 
#define HA_ADMIN_NOT_IMPLEMENTED -1
39
 
#define HA_ADMIN_FAILED          -2
40
 
#define HA_ADMIN_CORRUPT         -3
41
 
#define HA_ADMIN_INTERNAL_ERROR  -4
42
 
#define HA_ADMIN_INVALID         -5
43
 
#define HA_ADMIN_REJECT          -6
44
 
#define HA_ADMIN_TRY_ALTER       -7
45
 
#define HA_ADMIN_WRONG_CHECKSUM  -8
46
 
#define HA_ADMIN_NOT_BASE_TABLE  -9
47
 
#define HA_ADMIN_NEEDS_UPGRADE  -10
48
 
#define HA_ADMIN_NEEDS_ALTER    -11
49
 
#define HA_ADMIN_NEEDS_CHECK    -12
 
29
#include <mysys/thr_lock.h>
 
30
#include <mysys/hash.h>
 
31
#include <drizzled/sql_string.h>
 
32
#include <drizzled/sql_list.h>
 
33
#include <drizzled/plugin/storage_engine.h>
 
34
#include <drizzled/handler_structs.h>
 
35
#include <drizzled/ha_statistics.h>
50
36
 
51
37
/* Bits to show what an alter table will do */
52
38
#include <drizzled/sql_bitmap.h>
53
39
 
54
 
#define HA_MAX_ALTER_FLAGS 39
55
 
typedef Bitmap<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
56
 
 
57
 
#define HA_ADD_INDEX                  (0)
58
 
#define HA_DROP_INDEX                 (1)
59
 
#define HA_ALTER_INDEX                (2)
60
 
#define HA_RENAME_INDEX               (3)
61
 
#define HA_ADD_UNIQUE_INDEX           (4)
62
 
#define HA_DROP_UNIQUE_INDEX          (5)
63
 
#define HA_ALTER_UNIQUE_INDEX         (6)
64
 
#define HA_RENAME_UNIQUE_INDEX        (7)
65
 
#define HA_ADD_PK_INDEX               (8)
66
 
#define HA_DROP_PK_INDEX              (9)
67
 
#define HA_ALTER_PK_INDEX             (10)
68
 
#define HA_ADD_COLUMN                 (11)
69
 
#define HA_DROP_COLUMN                (12)
70
 
#define HA_CHANGE_COLUMN              (13)
71
 
#define HA_ALTER_COLUMN_NAME          (14)
72
 
#define HA_ALTER_COLUMN_TYPE          (15)
73
 
#define HA_ALTER_COLUMN_ORDER         (16)
74
 
#define HA_ALTER_COLUMN_NULLABLE      (17)
75
 
#define HA_COLUMN_DEFAULT_VALUE       (18)
76
 
#define HA_COLUMN_STORAGE             (19)
77
 
#define HA_COLUMN_FORMAT              (20)
78
 
#define HA_ADD_FOREIGN_KEY            (21)
79
 
#define HA_DROP_FOREIGN_KEY           (22)
80
 
#define HA_ALTER_FOREIGN_KEY          (23)
81
 
#define HA_ADD_CONSTRAINT             (24)
82
 
#define HA_CHANGE_CHARACTER_SET       (30)
83
 
#define HA_SET_DEFAULT_CHARACTER_SET  (31)
84
 
#define HA_CHANGE_AUTOINCREMENT_VALUE (32)
85
 
#define HA_ALTER_STORAGE              (33)
86
 
#define HA_ALTER_TABLESPACE           (34)
87
 
#define HA_ALTER_ROW_FORMAT           (35)
88
 
#define HA_RENAME_TABLE               (36)
89
 
#define HA_ALTER_STORAGE_ENGINE       (37)
90
 
#define HA_RECREATE                   (38)
91
 
/* Remember to increase HA_MAX_ALTER_FLAGS when adding more flags! */
92
 
 
93
 
/* Return values for check_if_supported_alter */
94
 
 
95
 
#define HA_ALTER_ERROR               -1
96
 
#define HA_ALTER_SUPPORTED_WAIT_LOCK  0
97
 
#define HA_ALTER_SUPPORTED_NO_LOCK    1
98
 
#define HA_ALTER_NOT_SUPPORTED        2
99
 
 
100
 
/* Bits in table_flags() to show what database can do */
101
 
 
102
 
#define HA_NO_TRANSACTIONS     (1 << 0) /* Doesn't support transactions */
103
 
#define HA_PARTIAL_COLUMN_READ (1 << 1) /* read may not return all columns */
104
 
#define HA_TABLE_SCAN_ON_INDEX (1 << 2) /* No separate data/index file */
105
 
/*
106
 
  The following should be set if the following is not true when scanning
107
 
  a table with rnd_next()
108
 
  - We will see all rows (including deleted ones)
109
 
  - Row positions are 'table->s->db_record_offset' apart
110
 
  If this flag is not set, filesort will do a postion() call for each matched
111
 
  row to be able to find the row later.
112
 
*/
113
 
#define HA_REC_NOT_IN_SEQ      (1 << 3)
114
 
 
115
 
/*
116
 
  Reading keys in random order is as fast as reading keys in sort order
117
 
  (Used in records.cc to decide if we should use a record cache and by
118
 
  filesort to decide if we should sort key + data or key + pointer-to-row
119
 
*/
120
 
#define HA_FAST_KEY_READ       (1 << 5)
121
 
/*
122
 
  Set the following flag if we on delete should force all key to be read
123
 
  and on update read all keys that changes
124
 
*/
125
 
#define HA_REQUIRES_KEY_COLUMNS_FOR_DELETE (1 << 6)
126
 
#define HA_NULL_IN_KEY         (1 << 7) /* One can have keys with NULL */
127
 
#define HA_DUPLICATE_POS       (1 << 8)    /* ha_position() gives dup row */
128
 
#define HA_NO_BLOBS            (1 << 9) /* Doesn't support blobs */
129
 
#define HA_CAN_INDEX_BLOBS     (1 << 10)
130
 
#define HA_AUTO_PART_KEY       (1 << 11) /* auto-increment in multi-part key */
131
 
#define HA_REQUIRE_PRIMARY_KEY (1 << 12) /* .. and can't create a hidden one */
132
 
#define HA_STATS_RECORDS_IS_EXACT (1 << 13) /* stats.records is exact */
133
 
/*
134
 
  If we get the primary key columns for free when we do an index read
135
 
  It also implies that we have to retrive the primary key when using
136
 
  position() and rnd_pos().
137
 
*/
138
 
#define HA_PRIMARY_KEY_IN_READ_INDEX (1 << 15)
139
 
/*
140
 
  If HA_PRIMARY_KEY_REQUIRED_FOR_POSITION is set, it means that to position()
141
 
  uses a primary key. Without primary key, we can't call position().
142
 
*/ 
143
 
#define HA_PRIMARY_KEY_REQUIRED_FOR_POSITION (1 << 16) 
144
 
#define HA_NOT_DELETE_WITH_CACHE (1 << 18)
145
 
/*
146
 
  The following is we need to a primary key to delete (and update) a row.
147
 
  If there is no primary key, all columns needs to be read on update and delete
148
 
*/
149
 
#define HA_PRIMARY_KEY_REQUIRED_FOR_DELETE (1 << 19)
150
 
#define HA_NO_PREFIX_CHAR_KEYS (1 << 20)
151
 
#define HA_NO_AUTO_INCREMENT   (1 << 23)
152
 
#define HA_HAS_CHECKSUM        (1 << 24)
153
 
/* Table data are stored in separate files (for lower_case_table_names) */
154
 
#define HA_FILE_BASED          (1 << 26)
155
 
#define HA_NEED_READ_RANGE_BUFFER (1 << 29) /* for read_multi_range */
156
 
#define HA_ANY_INDEX_MAY_BE_UNIQUE (1 << 30)
157
 
#define HA_NO_COPY_ON_ALTER    (INT64_C(1) << 31)
158
 
#define HA_HAS_RECORDS         (INT64_C(1) << 32) /* records() gives exact count*/
159
 
#define HA_MRR_CANT_SORT       (INT64_C(1) << 34)
160
 
 
161
 
/*
162
 
  Engine is capable of row-format and statement-format logging,
163
 
  respectively
164
 
*/
165
 
#define HA_BINLOG_ROW_CAPABLE  (INT64_C(1) << 35)
166
 
#define HA_BINLOG_STMT_CAPABLE (INT64_C(1) << 36)
167
 
 
168
 
#define HA_ONLINE_ALTER        (INT64_C(1) << 37)
169
 
 
170
 
/*
171
 
  Set of all binlog flags. Currently only contain the capabilities
172
 
  flags.
173
 
 */
174
 
#define HA_BINLOG_FLAGS (HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE)
175
 
 
176
 
/* bits in index_flags(index_number) for what you can do with index */
177
 
#define HA_READ_NEXT            1       /* TODO really use this flag */
178
 
#define HA_READ_PREV            2       /* supports ::index_prev */
179
 
#define HA_READ_ORDER           4       /* index_next/prev follow sort order */
180
 
#define HA_READ_RANGE           8       /* can find all records in a range */
181
 
#define HA_ONLY_WHOLE_INDEX     16      /* Can't use part key searches */
182
 
#define HA_KEYREAD_ONLY         64      /* Support HA_EXTRA_KEYREAD */
183
 
/*
184
 
  Index scan will not return records in rowid order. Not guaranteed to be
185
 
  set for unordered (e.g. HASH) indexes.
186
 
*/
187
 
#define HA_KEY_SCAN_NOT_ROR     128 
188
 
#define HA_DO_INDEX_COND_PUSHDOWN  256 /* Supports Index Condition Pushdown */
189
 
 
190
 
 
191
 
 
192
 
/*
193
 
  HA_PARTITION_FUNCTION_SUPPORTED indicates that the function is
194
 
  supported at all.
195
 
  HA_FAST_CHANGE_PARTITION means that optimised variants of the changes
196
 
  exists but they are not necessarily done online.
197
 
 
198
 
  HA_ONLINE_DOUBLE_WRITE means that the handler supports writing to both
199
 
  the new partition and to the old partitions when updating through the
200
 
  old partitioning schema while performing a change of the partitioning.
201
 
  This means that we can support updating of the table while performing
202
 
  the copy phase of the change. For no lock at all also a double write
203
 
  from new to old must exist and this is not required when this flag is
204
 
  set.
205
 
  This is actually removed even before it was introduced the first time.
206
 
  The new idea is that handlers will handle the lock level already in
207
 
  store_lock for ALTER Table partitions.
208
 
 
209
 
  HA_PARTITION_ONE_PHASE is a flag that can be set by handlers that take
210
 
  care of changing the partitions online and in one phase. Thus all phases
211
 
  needed to handle the change are implemented inside the storage engine.
212
 
  The storage engine must also support auto-discovery since the frm file
213
 
  is changed as part of the change and this change must be controlled by
214
 
  the storage engine. A typical engine to support this is NDB (through
215
 
  WL #2498).
216
 
*/
217
 
#define HA_PARTITION_FUNCTION_SUPPORTED         (1L << 1)
218
 
#define HA_FAST_CHANGE_PARTITION                (1L << 2)
219
 
#define HA_PARTITION_ONE_PHASE                  (1L << 3)
220
 
 
221
 
/* operations for disable/enable indexes */
222
 
#define HA_KEY_SWITCH_NONUNIQ      0
223
 
#define HA_KEY_SWITCH_ALL          1
224
 
#define HA_KEY_SWITCH_NONUNIQ_SAVE 2
225
 
#define HA_KEY_SWITCH_ALL_SAVE     3
226
 
 
227
 
/*
228
 
  Note: the following includes binlog and closing 0.
229
 
  so: innodb + bdb + ndb + binlog + myisam + myisammrg + archive +
230
 
      example + csv + heap + blackhole + federated + 0
231
 
  (yes, the sum is deliberately inaccurate)
232
 
  TODO remove the limit, use dynarrays
233
 
*/
234
 
#define MAX_HA 15
235
 
 
236
 
/*
237
 
  Parameters for open() (in register form->filestat)
238
 
  HA_GET_INFO does an implicit HA_ABORT_IF_LOCKED
239
 
*/
240
 
 
241
 
#define HA_OPEN_KEYFILE         1
242
 
#define HA_OPEN_RNDFILE         2
243
 
#define HA_GET_INDEX            4
244
 
#define HA_GET_INFO             8       /* do a ha_info() after open */
245
 
#define HA_READ_ONLY            16      /* File opened as readonly */
246
 
/* Try readonly if can't open with read and write */
247
 
#define HA_TRY_READ_ONLY        32
248
 
#define HA_WAIT_IF_LOCKED       64      /* Wait if locked on open */
249
 
#define HA_ABORT_IF_LOCKED      128     /* skip if locked on open.*/
250
 
#define HA_BLOCK_LOCK           256     /* unlock when reading some records */
251
 
#define HA_OPEN_TEMPORARY       512
252
 
 
253
 
/* For transactional LOCK Table. handler::lock_table() */
254
 
#define HA_LOCK_IN_SHARE_MODE      F_RDLCK
255
 
#define HA_LOCK_IN_EXCLUSIVE_MODE  F_WRLCK
256
 
 
257
 
/* Some key definitions */
258
 
#define HA_KEY_NULL_LENGTH      1
259
 
#define HA_KEY_BLOB_LENGTH      2
260
 
 
261
 
#define HA_LEX_CREATE_TMP_TABLE 1
262
 
#define HA_LEX_CREATE_IF_NOT_EXISTS 2
263
 
#define HA_LEX_CREATE_TABLE_LIKE 4
264
 
#define HA_OPTION_NO_CHECKSUM   (1L << 17)
265
 
#define HA_OPTION_NO_DELAY_KEY_WRITE (1L << 18)
266
 
#define HA_MAX_REC_LENGTH       65535
267
 
 
268
 
/* Table caching type */
269
 
#define HA_CACHE_TBL_NONTRANSACT 0
270
 
#define HA_CACHE_TBL_NOCACHE     1
271
 
#define HA_CACHE_TBL_ASKTRANSACT 2
272
 
#define HA_CACHE_TBL_TRANSACT    4
273
 
 
274
 
/* Options of START TRANSACTION statement (and later of SET TRANSACTION stmt) */
275
 
#define DRIZZLE_START_TRANS_OPT_WITH_CONS_SNAPSHOT 1
276
 
 
277
 
/* Flags for method is_fatal_error */
278
 
#define HA_CHECK_DUP_KEY 1
279
 
#define HA_CHECK_DUP_UNIQUE 2
280
 
#define HA_CHECK_DUP (HA_CHECK_DUP_KEY + HA_CHECK_DUP_UNIQUE)
281
 
 
282
 
enum legacy_db_type
283
 
{
284
 
  DB_TYPE_UNKNOWN=0,
285
 
  DB_TYPE_FIRST_DYNAMIC=42,
286
 
  DB_TYPE_DEFAULT=127 // Must be last
287
 
};
288
 
 
289
 
enum row_type { ROW_TYPE_NOT_USED=-1, ROW_TYPE_DEFAULT, ROW_TYPE_FIXED,
290
 
                ROW_TYPE_DYNAMIC, ROW_TYPE_COMPRESSED,
291
 
                ROW_TYPE_REDUNDANT, ROW_TYPE_COMPACT, ROW_TYPE_PAGE };
292
 
 
293
 
enum column_format_type { COLUMN_FORMAT_TYPE_NOT_USED= -1,
294
 
                          COLUMN_FORMAT_TYPE_DEFAULT=   0,
295
 
                          COLUMN_FORMAT_TYPE_FIXED=     1,
296
 
                          COLUMN_FORMAT_TYPE_DYNAMIC=   2 };
297
 
 
298
 
enum enum_binlog_func {
299
 
  BFN_RESET_LOGS=        1,
300
 
  BFN_RESET_SLAVE=       2,
301
 
  BFN_BINLOG_WAIT=       3,
302
 
  BFN_BINLOG_END=        4,
303
 
  BFN_BINLOG_PURGE_FILE= 5
304
 
};
305
 
 
306
 
enum enum_binlog_command {
307
 
  LOGCOM_CREATE_TABLE,
308
 
  LOGCOM_ALTER_TABLE,
309
 
  LOGCOM_RENAME_TABLE,
310
 
  LOGCOM_DROP_TABLE,
311
 
  LOGCOM_CREATE_DB,
312
 
  LOGCOM_ALTER_DB,
313
 
  LOGCOM_DROP_DB
314
 
};
315
 
 
316
 
/* struct to hold information about the table that should be created */
317
 
 
318
 
/* Bits in used_fields */
319
 
#define HA_CREATE_USED_AUTO             (1L << 0)
320
 
#ifdef DEAD_OPTIONS
321
 
#define HA_CREATE_USED_RAID             (1L << 1) /* Historical, no longer supported */
322
 
#define HA_CREATE_USED_UNION            (1L << 2)
323
 
#define HA_CREATE_USED_PASSWORD         (1L << 17)
324
 
#endif
325
 
#define HA_CREATE_USED_INSERT_METHOD    (1L << 3)
326
 
#define HA_CREATE_USED_MIN_ROWS         (1L << 4)
327
 
#define HA_CREATE_USED_MAX_ROWS         (1L << 5)
328
 
#define HA_CREATE_USED_AVG_ROW_LENGTH   (1L << 6)
329
 
#define HA_CREATE_USED_PACK_KEYS        (1L << 7)
330
 
#define HA_CREATE_USED_CHARSET          (1L << 8)
331
 
#define HA_CREATE_USED_DEFAULT_CHARSET  (1L << 9)
332
 
#define HA_CREATE_USED_DATADIR          (1L << 10)
333
 
#define HA_CREATE_USED_INDEXDIR         (1L << 11)
334
 
#define HA_CREATE_USED_ENGINE           (1L << 12)
335
 
#define HA_CREATE_USED_CHECKSUM         (1L << 13)
336
 
#define HA_CREATE_USED_DELAY_KEY_WRITE  (1L << 14)
337
 
#define HA_CREATE_USED_ROW_FORMAT       (1L << 15)
338
 
#define HA_CREATE_USED_COMMENT          (1L << 16)
339
 
#define HA_CREATE_USED_CONNECTION       (1L << 18)
340
 
#define HA_CREATE_USED_KEY_BLOCK_SIZE   (1L << 19)
341
 
#define HA_CREATE_USED_PAGE_CHECKSUM    (1L << 21)
342
 
#define HA_CREATE_USED_BLOCK_SIZE       (1L << 22)
343
 
 
344
 
typedef uint64_t my_xid; // this line is the same as in log_event.h
345
 
#define DRIZZLE_XID_PREFIX "MySQLXid"
346
 
#define DRIZZLE_XID_PREFIX_LEN 8 // must be a multiple of 8
347
 
#define DRIZZLE_XID_OFFSET (DRIZZLE_XID_PREFIX_LEN+sizeof(server_id))
348
 
#define DRIZZLE_XID_GTRID_LEN (DRIZZLE_XID_OFFSET+sizeof(my_xid))
349
 
 
350
 
#define XIDDATASIZE DRIZZLE_XIDDATASIZE
351
 
#define MAXGTRIDSIZE 64
352
 
#define MAXBQUALSIZE 64
353
 
 
354
 
#define COMPATIBLE_DATA_YES 0
355
 
#define COMPATIBLE_DATA_NO  1
356
 
 
357
 
typedef bool (*qc_engine_callback)(THD *thd, char *table_key,
 
40
#include<bitset>
 
41
 
 
42
#define HA_MAX_ALTER_FLAGS 40
 
43
typedef std::bitset<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
 
44
 
 
45
 
 
46
typedef bool (*qc_engine_callback)(Session *session, char *table_key,
358
47
                                      uint32_t key_length,
359
48
                                      uint64_t *engine_data);
360
49
 
361
 
/**
362
 
  struct xid_t is binary compatible with the XID structure as
363
 
  in the X/Open CAE Specification, Distributed Transaction Processing:
364
 
  The XA Specification, X/Open Company Ltd., 1991.
365
 
  http://www.opengroup.org/bookstore/catalog/c193.htm
366
 
 
367
 
  @see DRIZZLE_XID in mysql/plugin.h
368
 
*/
369
 
struct xid_t {
370
 
  long formatID;
371
 
  long gtrid_length;
372
 
  long bqual_length;
373
 
  char data[XIDDATASIZE];  // not \0-terminated !
374
 
 
375
 
  xid_t() {}                                /* Remove gcc warning */  
376
 
  bool eq(struct xid_t *xid)
377
 
  { return eq(xid->gtrid_length, xid->bqual_length, xid->data); }
378
 
  bool eq(long g, long b, const char *d)
379
 
  { return g == gtrid_length && b == bqual_length && !memcmp(d, data, g+b); }
380
 
  void set(struct xid_t *xid)
381
 
  { memcpy(this, xid, xid->length()); }
382
 
  void set(long f, const char *g, long gl, const char *b, long bl)
383
 
  {
384
 
    formatID= f;
385
 
    memcpy(data, g, gtrid_length= gl);
386
 
    memcpy(data+gl, b, bqual_length= bl);
387
 
  }
388
 
  void set(uint64_t xid)
389
 
  {
390
 
    my_xid tmp;
391
 
    formatID= 1;
392
 
    set(DRIZZLE_XID_PREFIX_LEN, 0, DRIZZLE_XID_PREFIX);
393
 
    memcpy(data+DRIZZLE_XID_PREFIX_LEN, &server_id, sizeof(server_id));
394
 
    tmp= xid;
395
 
    memcpy(data+DRIZZLE_XID_OFFSET, &tmp, sizeof(tmp));
396
 
    gtrid_length=DRIZZLE_XID_GTRID_LEN;
397
 
  }
398
 
  void set(long g, long b, const char *d)
399
 
  {
400
 
    formatID= 1;
401
 
    gtrid_length= g;
402
 
    bqual_length= b;
403
 
    memcpy(data, d, g+b);
404
 
  }
405
 
  bool is_null() { return formatID == -1; }
406
 
  void null() { formatID= -1; }
407
 
  my_xid quick_get_my_xid()
408
 
  {
409
 
    my_xid tmp;
410
 
    memcpy(&tmp, data+DRIZZLE_XID_OFFSET, sizeof(tmp));
411
 
    return tmp;
412
 
  }
413
 
  my_xid get_my_xid()
414
 
  {
415
 
    return gtrid_length == DRIZZLE_XID_GTRID_LEN && bqual_length == 0 &&
416
 
           !memcmp(data+DRIZZLE_XID_PREFIX_LEN, &server_id, sizeof(server_id)) &&
417
 
           !memcmp(data, DRIZZLE_XID_PREFIX, DRIZZLE_XID_PREFIX_LEN) ?
418
 
           quick_get_my_xid() : 0;
419
 
  }
420
 
  uint32_t length()
421
 
  {
422
 
    return sizeof(formatID)+sizeof(gtrid_length)+sizeof(bqual_length)+
423
 
           gtrid_length+bqual_length;
424
 
  }
425
 
  unsigned char *key()
426
 
  {
427
 
    return (unsigned char *)&gtrid_length;
428
 
  }
429
 
  uint32_t key_length()
430
 
  {
431
 
    return sizeof(gtrid_length)+sizeof(bqual_length)+gtrid_length+bqual_length;
432
 
  }
433
 
};
434
 
typedef struct xid_t XID;
435
 
 
436
 
/* for recover() handlerton call */
437
 
#define MIN_XID_LIST_SIZE  128
438
 
#define MAX_XID_LIST_SIZE  (1024*128)
439
 
 
440
 
struct handlerton;
441
50
 
442
51
/* The handler for a table type.  Will be included in the Table structure */
443
52
 
444
53
class Table;
445
 
typedef struct st_table_share TABLE_SHARE;
 
54
class TableList;
 
55
class TABLE_SHARE;
 
56
class Select_Lex_Unit;
446
57
struct st_foreign_key_info;
447
58
typedef struct st_foreign_key_info FOREIGN_KEY_INFO;
448
 
typedef bool (stat_print_fn)(THD *thd, const char *type, uint32_t type_len,
449
 
                             const char *file, uint32_t file_len,
450
 
                             const char *status, uint32_t status_len);
451
 
enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
452
 
extern st_plugin_int *hton2plugin[MAX_HA];
453
 
 
454
 
/*
455
 
  handlerton is a singleton structure - one instance per storage engine -
456
 
  to provide access to storage engine functionality that works on the
457
 
  "global" level (unlike handler class that works on a per-table basis)
458
 
 
459
 
  usually handlerton instance is defined statically in ha_xxx.cc as
460
 
 
461
 
  static handlerton { ... } xxx_hton;
462
 
 
463
 
  savepoint_*, prepare, recover, and *_by_xid pointers can be 0.
464
 
*/
465
 
struct handlerton
466
 
{
467
 
  /*
468
 
    Historical marker for if the engine is available of not
469
 
  */
470
 
  SHOW_COMP_OPTION state;
471
 
 
472
 
  /*
473
 
    Historical number used for frm file to determine the correct storage engine.
474
 
    This is going away and new engines will just use "name" for this.
475
 
  */
476
 
  enum legacy_db_type db_type;
477
 
  /*
478
 
    each storage engine has it's own memory area (actually a pointer)
479
 
    in the thd, for storing per-connection information.
480
 
    It is accessed as
481
 
 
482
 
      thd->ha_data[xxx_hton.slot]
483
 
 
484
 
   slot number is initialized by MySQL after xxx_init() is called.
485
 
   */
486
 
   uint32_t slot;
487
 
   /*
488
 
     to store per-savepoint data storage engine is provided with an area
489
 
     of a requested size (0 is ok here).
490
 
     savepoint_offset must be initialized statically to the size of
491
 
     the needed memory to store per-savepoint information.
492
 
     After xxx_init it is changed to be an offset to savepoint storage
493
 
     area and need not be used by storage engine.
494
 
     see binlog_hton and binlog_savepoint_set/rollback for an example.
495
 
   */
496
 
   uint32_t savepoint_offset;
497
 
   /*
498
 
     handlerton methods:
499
 
 
500
 
     close_connection is only called if
501
 
     thd->ha_data[xxx_hton.slot] is non-zero, so even if you don't need
502
 
     this storage area - set it to something, so that MySQL would know
503
 
     this storage engine was accessed in this connection
504
 
   */
505
 
   int  (*close_connection)(handlerton *hton, THD *thd);
506
 
   /*
507
 
     sv points to an uninitialized storage area of requested size
508
 
     (see savepoint_offset description)
509
 
   */
510
 
   int  (*savepoint_set)(handlerton *hton, THD *thd, void *sv);
511
 
   /*
512
 
     sv points to a storage area, that was earlier passed
513
 
     to the savepoint_set call
514
 
   */
515
 
   int  (*savepoint_rollback)(handlerton *hton, THD *thd, void *sv);
516
 
   int  (*savepoint_release)(handlerton *hton, THD *thd, void *sv);
517
 
   /*
518
 
     'all' is true if it's a real commit, that makes persistent changes
519
 
     'all' is false if it's not in fact a commit but an end of the
520
 
     statement that is part of the transaction.
521
 
     NOTE 'all' is also false in auto-commit mode where 'end of statement'
522
 
     and 'real commit' mean the same event.
523
 
   */
524
 
   int  (*commit)(handlerton *hton, THD *thd, bool all);
525
 
   int  (*rollback)(handlerton *hton, THD *thd, bool all);
526
 
   int  (*prepare)(handlerton *hton, THD *thd, bool all);
527
 
   int  (*recover)(handlerton *hton, XID *xid_list, uint32_t len);
528
 
   int  (*commit_by_xid)(handlerton *hton, XID *xid);
529
 
   int  (*rollback_by_xid)(handlerton *hton, XID *xid);
530
 
   void *(*create_cursor_read_view)(handlerton *hton, THD *thd);
531
 
   void (*set_cursor_read_view)(handlerton *hton, THD *thd, void *read_view);
532
 
   void (*close_cursor_read_view)(handlerton *hton, THD *thd, void *read_view);
533
 
   handler *(*create)(handlerton *hton, TABLE_SHARE *table, MEM_ROOT *mem_root);
534
 
   void (*drop_database)(handlerton *hton, char* path);
535
 
   int (*start_consistent_snapshot)(handlerton *hton, THD *thd);
536
 
   bool (*flush_logs)(handlerton *hton);
537
 
   bool (*show_status)(handlerton *hton, THD *thd, stat_print_fn *print, enum ha_stat_type stat);
538
 
   int (*fill_files_table)(handlerton *hton, THD *thd,
539
 
                           TableList *tables,
540
 
                           class Item *cond);
541
 
   uint32_t flags;                                /* global handler flags */
542
 
   int (*release_temporary_latches)(handlerton *hton, THD *thd);
543
 
 
544
 
   int (*discover)(handlerton *hton, THD* thd, const char *db, 
545
 
                   const char *name,
546
 
                   unsigned char **frmblob, 
547
 
                   size_t *frmlen);
548
 
   int (*table_exists_in_engine)(handlerton *hton, THD* thd, const char *db,
549
 
                                 const char *name);
550
 
   uint32_t license; /* Flag for Engine License */
551
 
   void *data; /* Location for engines to keep personal structures */
552
 
};
553
 
 
554
 
 
555
 
/* Possible flags of a handlerton (there can be 32 of them) */
556
 
#define HTON_NO_FLAGS                 0
557
 
#define HTON_CLOSE_CURSORS_AT_COMMIT (1 << 0)
558
 
#define HTON_ALTER_NOT_SUPPORTED     (1 << 1) //Engine does not support alter
559
 
#define HTON_CAN_RECREATE            (1 << 2) //Delete all is used fro truncate
560
 
#define HTON_HIDDEN                  (1 << 3) //Engine does not appear in lists
561
 
#define HTON_FLUSH_AFTER_RENAME      (1 << 4)
562
 
#define HTON_NOT_USER_SELECTABLE     (1 << 5)
563
 
#define HTON_TEMPORARY_NOT_SUPPORTED (1 << 6) //Having temporary tables not supported
564
 
#define HTON_SUPPORT_LOG_TABLES      (1 << 7) //Engine supports log tables
565
 
#define HTON_NO_PARTITION            (1 << 8) //You can not partition these tables
566
 
 
567
 
class Ha_trx_info;
568
 
 
569
 
struct THD_TRANS
570
 
{
571
 
  /* true is not all entries in the ht[] support 2pc */
572
 
  bool        no_2pc;
573
 
  /* storage engines that registered in this transaction */
574
 
  Ha_trx_info *ha_list;
575
 
  /* 
576
 
    The purpose of this flag is to keep track of non-transactional
577
 
    tables that were modified in scope of:
578
 
    - transaction, when the variable is a member of
579
 
    THD::transaction.all
580
 
    - top-level statement or sub-statement, when the variable is a
581
 
    member of THD::transaction.stmt
582
 
    This member has the following life cycle:
583
 
    * stmt.modified_non_trans_table is used to keep track of
584
 
    modified non-transactional tables of top-level statements. At
585
 
    the end of the previous statement and at the beginning of the session,
586
 
    it is reset to false.  If such functions
587
 
    as mysql_insert, mysql_update, mysql_delete etc modify a
588
 
    non-transactional table, they set this flag to true.  At the
589
 
    end of the statement, the value of stmt.modified_non_trans_table 
590
 
    is merged with all.modified_non_trans_table and gets reset.
591
 
    * all.modified_non_trans_table is reset at the end of transaction
592
 
    
593
 
    * Since we do not have a dedicated context for execution of a
594
 
    sub-statement, to keep track of non-transactional changes in a
595
 
    sub-statement, we re-use stmt.modified_non_trans_table. 
596
 
    At entrance into a sub-statement, a copy of the value of
597
 
    stmt.modified_non_trans_table (containing the changes of the
598
 
    outer statement) is saved on stack. Then 
599
 
    stmt.modified_non_trans_table is reset to false and the
600
 
    substatement is executed. Then the new value is merged with the
601
 
    saved value.
602
 
  */
603
 
  bool modified_non_trans_table;
604
 
 
605
 
  void reset() { no_2pc= false; modified_non_trans_table= false; }
606
 
};
607
 
 
608
 
 
609
 
/**
610
 
  Either statement transaction or normal transaction - related
611
 
  thread-specific storage engine data.
612
 
 
613
 
  If a storage engine participates in a statement/transaction,
614
 
  an instance of this class is present in
615
 
  thd->transaction.{stmt|all}.ha_list. The addition to
616
 
  {stmt|all}.ha_list is made by trans_register_ha().
617
 
 
618
 
  When it's time to commit or rollback, each element of ha_list
619
 
  is used to access storage engine's prepare()/commit()/rollback()
620
 
  methods, and also to evaluate if a full two phase commit is
621
 
  necessary.
622
 
 
623
 
  @sa General description of transaction handling in handler.cc.
624
 
*/
625
 
 
626
 
class Ha_trx_info
627
 
{
628
 
public:
629
 
  /** Register this storage engine in the given transaction context. */
630
 
  void register_ha(THD_TRANS *trans, handlerton *ht_arg)
631
 
  {
632
 
    assert(m_flags == 0);
633
 
    assert(m_ht == NULL);
634
 
    assert(m_next == NULL);
635
 
 
636
 
    m_ht= ht_arg;
637
 
    m_flags= (int) TRX_READ_ONLY; /* Assume read-only at start. */
638
 
 
639
 
    m_next= trans->ha_list;
640
 
    trans->ha_list= this;
641
 
  }
642
 
 
643
 
  /** Clear, prepare for reuse. */
644
 
  void reset()
645
 
  {
646
 
    m_next= NULL;
647
 
    m_ht= NULL;
648
 
    m_flags= 0;
649
 
  }
650
 
 
651
 
  Ha_trx_info() { reset(); }
652
 
 
653
 
  void set_trx_read_write()
654
 
  {
655
 
    assert(is_started());
656
 
    m_flags|= (int) TRX_READ_WRITE;
657
 
  }
658
 
  bool is_trx_read_write() const
659
 
  {
660
 
    assert(is_started());
661
 
    return m_flags & (int) TRX_READ_WRITE;
662
 
  }
663
 
  bool is_started() const { return m_ht != NULL; }
664
 
  /** Mark this transaction read-write if the argument is read-write. */
665
 
  void coalesce_trx_with(const Ha_trx_info *stmt_trx)
666
 
  {
667
 
    /*
668
 
      Must be called only after the transaction has been started.
669
 
      Can be called many times, e.g. when we have many
670
 
      read-write statements in a transaction.
671
 
    */
672
 
    assert(is_started());
673
 
    if (stmt_trx->is_trx_read_write())
674
 
      set_trx_read_write();
675
 
  }
676
 
  Ha_trx_info *next() const
677
 
  {
678
 
    assert(is_started());
679
 
    return m_next;
680
 
  }
681
 
  handlerton *ht() const
682
 
  {
683
 
    assert(is_started());
684
 
    return m_ht;
685
 
  }
686
 
private:
687
 
  enum { TRX_READ_ONLY= 0, TRX_READ_WRITE= 1 };
688
 
  /** Auxiliary, used for ha_list management */
689
 
  Ha_trx_info *m_next;
690
 
  /**
691
 
    Although a given Ha_trx_info instance is currently always used
692
 
    for the same storage engine, 'ht' is not-NULL only when the
693
 
    corresponding storage is a part of a transaction.
694
 
  */
695
 
  handlerton *m_ht;
696
 
  /**
697
 
    Transaction flags related to this engine.
698
 
    Not-null only if this instance is a part of transaction.
699
 
    May assume a combination of enum values above.
700
 
  */
701
 
  unsigned char       m_flags;
702
 
};
703
 
 
704
 
 
705
 
enum enum_tx_isolation { ISO_READ_UNCOMMITTED, ISO_READ_COMMITTED,
706
 
                         ISO_REPEATABLE_READ, ISO_SERIALIZABLE};
707
 
 
708
 
typedef struct {
709
 
  uint64_t data_file_length;
710
 
  uint64_t max_data_file_length;
711
 
  uint64_t index_file_length;
712
 
  uint64_t delete_length;
713
 
  ha_rows records;
714
 
  uint32_t mean_rec_length;
715
 
  time_t create_time;
716
 
  time_t check_time;
717
 
  time_t update_time;
718
 
  uint64_t check_sum;
719
 
} PARTITION_INFO;
720
 
 
721
 
#define UNDEF_NODEGROUP 65535
 
59
struct order_st;
 
60
 
722
61
class Item;
723
62
struct st_table_log_memory_entry;
724
63
 
725
 
#define NOT_A_PARTITION_ID ((uint32_t)-1)
726
 
 
727
 
enum ha_choice { HA_CHOICE_UNDEF, HA_CHOICE_NO, HA_CHOICE_YES };
728
 
 
729
 
typedef struct st_ha_create_information
730
 
{
731
 
  const CHARSET_INFO *table_charset, *default_table_charset;
732
 
  LEX_STRING connect_string;
733
 
  LEX_STRING comment;
734
 
  const char *data_file_name, *index_file_name;
735
 
  const char *alias;
736
 
  uint64_t max_rows,min_rows;
737
 
  uint64_t auto_increment_value;
738
 
  uint32_t table_options;
739
 
  uint32_t avg_row_length;
740
 
  uint32_t used_fields;
741
 
  uint32_t key_block_size;
742
 
  uint32_t block_size;
743
 
  handlerton *db_type;
744
 
  enum row_type row_type;
745
 
  uint32_t null_bits;                       /* NULL bits at start of record */
746
 
  uint32_t options;                             /* OR of HA_CREATE_ options */
747
 
  uint32_t extra_size;                      /* length of extra data segment */
748
 
  bool table_existed;                   /* 1 in create if table existed */
749
 
  bool frm_only;                        /* 1 if no ha_create_table() */
750
 
  bool varchar;                         /* 1 if table has a VARCHAR */
751
 
  enum ha_choice page_checksum;         /* If we have page_checksums */
752
 
} HA_CREATE_INFO;
753
 
 
754
 
typedef struct st_ha_alter_information
755
 
{
756
 
  KEY  *key_info_buffer;
757
 
  uint32_t key_count;
758
 
  uint32_t index_drop_count;
759
 
  uint32_t *index_drop_buffer;
760
 
  uint32_t index_add_count;
761
 
  uint32_t *index_add_buffer;
762
 
  void *data;
763
 
} HA_ALTER_INFO;
764
 
 
765
 
 
766
 
typedef struct st_key_create_information
767
 
{
768
 
  enum ha_key_alg algorithm;
769
 
  uint32_t block_size;
770
 
  LEX_STRING parser_name;
771
 
  LEX_STRING comment;
772
 
} KEY_CREATE_INFO;
773
 
 
774
 
 
775
 
/*
776
 
  Class for maintaining hooks used inside operations on tables such
777
 
  as: create table functions, delete table functions, and alter table
778
 
  functions.
779
 
 
780
 
  Class is using the Template Method pattern to separate the public
781
 
  usage interface from the private inheritance interface.  This
782
 
  imposes no overhead, since the public non-virtual function is small
783
 
  enough to be inlined.
784
 
 
785
 
  The hooks are usually used for functions that does several things,
786
 
  e.g., create_table_from_items(), which both create a table and lock
787
 
  it.
788
 
 */
789
 
class TABLEOP_HOOKS
790
 
{
791
 
public:
792
 
  TABLEOP_HOOKS() {}
793
 
  virtual ~TABLEOP_HOOKS() {}
794
 
 
795
 
  inline void prelock(Table **tables, uint32_t count)
796
 
  {
797
 
    do_prelock(tables, count);
798
 
  }
799
 
 
800
 
  inline int postlock(Table **tables, uint32_t count)
801
 
  {
802
 
    return do_postlock(tables, count);
803
 
  }
804
 
private:
805
 
  /* Function primitive that is called prior to locking tables */
806
 
  virtual void do_prelock(Table **tables __attribute__((unused)),
807
 
                          uint32_t count __attribute__((unused)))
808
 
  {
809
 
    /* Default is to do nothing */
810
 
  }
811
 
 
812
 
  /**
813
 
     Primitive called after tables are locked.
814
 
 
815
 
     If an error is returned, the tables will be unlocked and error
816
 
     handling start.
817
 
 
818
 
     @return Error code or zero.
819
 
   */
820
 
  virtual int do_postlock(Table **tables __attribute__((unused)),
821
 
                          uint32_t count __attribute__((unused)))
822
 
  {
823
 
    return 0;                           /* Default is to do nothing */
824
 
  }
825
 
};
 
64
class LEX;
 
65
class Select_Lex;
 
66
class Alter_info;
 
67
class select_result;
 
68
class Create_field;
 
69
class sys_var_str;
 
70
class Item_ident;
 
71
typedef struct st_sort_field SORT_FIELD;
 
72
 
 
73
typedef List<Item> List_item;
826
74
 
827
75
typedef struct st_savepoint SAVEPOINT;
828
76
extern uint32_t savepoint_alloc_size;
831
79
/* Forward declaration for condition pushdown to storage engine */
832
80
typedef class Item COND;
833
81
 
834
 
typedef struct st_ha_check_opt
835
 
{
836
 
  st_ha_check_opt() {}                        /* Remove gcc warning */
837
 
  uint32_t sort_buffer_size;
838
 
  uint32_t flags;       /* isam layer flags (e.g. for myisamchk) */
839
 
  uint32_t sql_flags;   /* sql layer flags - for something myisamchk cannot do */
840
 
  KEY_CACHE *key_cache; /* new key cache when changing key cache */
841
 
  void init();
842
 
} HA_CHECK_OPT;
843
 
 
844
 
 
845
 
 
846
 
/*
847
 
  This is a buffer area that the handler can use to store rows.
848
 
  'end_of_used_area' should be kept updated after calls to
849
 
  read-functions so that other parts of the code can use the
850
 
  remaining area (until next read calls is issued).
851
 
*/
852
 
 
853
 
typedef struct st_handler_buffer
854
 
{
855
 
  unsigned char *buffer;         /* Buffer one can start using */
856
 
  unsigned char *buffer_end;     /* End of buffer */
857
 
  unsigned char *end_of_used_area;     /* End of area that was used by handler */
858
 
} HANDLER_BUFFER;
859
 
 
860
82
typedef struct system_status_var SSV;
861
83
 
862
 
 
863
 
typedef void *range_seq_t;
864
 
 
865
 
typedef struct st_range_seq_if
866
 
{
867
 
  /*
868
 
    Initialize the traversal of range sequence
869
 
    
870
 
    SYNOPSIS
871
 
      init()
872
 
        init_params  The seq_init_param parameter 
873
 
        n_ranges     The number of ranges obtained 
874
 
        flags        A combination of HA_MRR_SINGLE_POINT, HA_MRR_FIXED_KEY
875
 
 
876
 
    RETURN
877
 
      An opaque value to be used as RANGE_SEQ_IF::next() parameter
878
 
  */
879
 
  range_seq_t (*init)(void *init_params, uint32_t n_ranges, uint32_t flags);
880
 
 
881
 
 
882
 
  /*
883
 
    Get the next range in the range sequence
884
 
 
885
 
    SYNOPSIS
886
 
      next()
887
 
        seq    The value returned by RANGE_SEQ_IF::init()
888
 
        range  OUT Information about the next range
889
 
    
890
 
    RETURN
891
 
      0 - Ok, the range structure filled with info about the next range
892
 
      1 - No more ranges
893
 
  */
894
 
  uint32_t (*next) (range_seq_t seq, KEY_MULTI_RANGE *range);
895
 
} RANGE_SEQ_IF;
 
84
class COST_VECT;
896
85
 
897
86
uint16_t &mrr_persistent_flag_storage(range_seq_t seq, uint32_t idx);
898
87
char* &mrr_get_ptr_by_idx(range_seq_t seq, uint32_t idx);
899
88
 
900
 
class COST_VECT
901
 
902
 
public:
903
 
  double io_count;     /* number of I/O                 */
904
 
  double avg_io_cost;  /* cost of an average I/O oper.  */
905
 
  double cpu_cost;     /* cost of operations in CPU     */
906
 
  double mem_cost;     /* cost of used memory           */ 
907
 
  double import_cost;  /* cost of remote operations     */
908
 
  
909
 
  enum { IO_COEFF=1 };
910
 
  enum { CPU_COEFF=1 };
911
 
  enum { MEM_COEFF=1 };
912
 
  enum { IMPORT_COEFF=1 };
913
 
 
914
 
  COST_VECT() {}                              // keep gcc happy
915
 
 
916
 
  double total_cost() 
917
 
  {
918
 
    return IO_COEFF*io_count*avg_io_cost + CPU_COEFF * cpu_cost +
919
 
           MEM_COEFF*mem_cost + IMPORT_COEFF*import_cost;
920
 
  }
921
 
 
922
 
  void zero()
923
 
  {
924
 
    avg_io_cost= 1.0;
925
 
    io_count= cpu_cost= mem_cost= import_cost= 0.0;
926
 
  }
927
 
 
928
 
  void multiply(double m)
929
 
  {
930
 
    io_count *= m;
931
 
    cpu_cost *= m;
932
 
    import_cost *= m;
933
 
    /* Don't multiply mem_cost */
934
 
  }
935
 
 
936
 
  void add(const COST_VECT* cost)
937
 
  {
938
 
    double io_count_sum= io_count + cost->io_count;
939
 
    add_io(cost->io_count, cost->avg_io_cost);
940
 
    io_count= io_count_sum;
941
 
    cpu_cost += cost->cpu_cost;
942
 
  }
943
 
  void add_io(double add_io_cnt, double add_avg_cost)
944
 
  {
945
 
    double io_count_sum= io_count + add_io_cnt;
946
 
    avg_io_cost= (io_count * avg_io_cost + 
947
 
                  add_io_cnt * add_avg_cost) / io_count_sum;
948
 
    io_count= io_count_sum;
949
 
  }
950
 
};
951
 
 
952
 
void get_sweep_read_cost(Table *table, ha_rows nrows, bool interrupted, 
953
 
                         COST_VECT *cost);
954
 
 
955
 
/*
956
 
  The below two are not used (and not handled) in this milestone of this WL
957
 
  entry because there seems to be no use for them at this stage of
958
 
  implementation.
959
 
*/
960
 
#define HA_MRR_SINGLE_POINT 1
961
 
#define HA_MRR_FIXED_KEY  2
962
 
 
963
 
/* 
964
 
  Indicates that RANGE_SEQ_IF::next(&range) doesn't need to fill in the
965
 
  'range' parameter.
966
 
*/
967
 
#define HA_MRR_NO_ASSOCIATION 4
968
 
 
969
 
/* 
970
 
  The MRR user will provide ranges in key order, and MRR implementation
971
 
  must return rows in key order.
972
 
*/
973
 
#define HA_MRR_SORTED 8
974
 
 
975
 
/* MRR implementation doesn't have to retrieve full records */
976
 
#define HA_MRR_INDEX_ONLY 16
977
 
 
978
 
/* 
979
 
  The passed memory buffer is of maximum possible size, the caller can't
980
 
  assume larger buffer.
981
 
*/
982
 
#define HA_MRR_LIMITS 32
983
 
 
984
 
 
985
 
/*
986
 
  Flag set <=> default MRR implementation is used
987
 
  (The choice is made by **_info[_const]() function which may set this
988
 
   flag. SQL layer remembers the flag value and then passes it to
989
 
   multi_read_range_init().
990
 
*/
991
 
#define HA_MRR_USE_DEFAULT_IMPL 64
992
 
 
993
 
/*
994
 
  Used only as parameter to multi_range_read_info():
995
 
  Flag set <=> the caller guarantees that the bounds of the scanned ranges
996
 
  will not have NULL values.
997
 
*/
998
 
#define HA_MRR_NO_NULL_ENDPOINTS 128
999
 
 
1000
 
 
1001
 
class ha_statistics
1002
 
{
1003
 
public:
1004
 
  uint64_t data_file_length;            /* Length off data file */
1005
 
  uint64_t max_data_file_length;        /* Length off data file */
1006
 
  uint64_t index_file_length;
1007
 
  uint64_t max_index_file_length;
1008
 
  uint64_t delete_length;               /* Free bytes */
1009
 
  uint64_t auto_increment_value;
1010
 
  /*
1011
 
    The number of records in the table. 
1012
 
      0    - means the table has exactly 0 rows
1013
 
    other  - if (table_flags() & HA_STATS_RECORDS_IS_EXACT)
1014
 
               the value is the exact number of records in the table
1015
 
             else
1016
 
               it is an estimate
1017
 
  */
1018
 
  ha_rows records;
1019
 
  ha_rows deleted;                      /* Deleted records */
1020
 
  uint32_t mean_rec_length;             /* physical reclength */
1021
 
  time_t create_time;                   /* When table was created */
1022
 
  time_t check_time;
1023
 
  time_t update_time;
1024
 
  uint32_t block_size;                  /* index block size */
1025
 
 
1026
 
  ha_statistics():
1027
 
    data_file_length(0), max_data_file_length(0),
1028
 
    index_file_length(0), delete_length(0), auto_increment_value(0),
1029
 
    records(0), deleted(0), mean_rec_length(0), create_time(0),
1030
 
    check_time(0), update_time(0), block_size(0)
1031
 
  {}
1032
 
};
1033
 
 
1034
89
uint32_t calculate_key_len(Table *, uint, const unsigned char *, key_part_map);
1035
90
/*
1036
91
  bitmap with first N+1 bits set
1037
92
  (keypart_map for a key prefix of [0..N] keyparts)
1038
93
*/
1039
 
#define make_keypart_map(N) (((key_part_map)2 << (N)) - 1)
 
94
template<class T>
 
95
inline key_part_map make_keypart_map(T a)
 
96
{
 
97
  return (((key_part_map)2 << a) - 1);
 
98
}
 
99
 
1040
100
/*
1041
101
  bitmap with first N bits set
1042
102
  (keypart_map for a key prefix of [0..N-1] keyparts)
1043
103
*/
1044
 
#define make_prev_keypart_map(N) (((key_part_map)1 << (N)) - 1)
 
104
template<class T>
 
105
inline key_part_map make_prev_keypart_map(T a)
 
106
{
 
107
  return (((key_part_map)1 << a) - 1);
 
108
}
1045
109
 
1046
110
/**
1047
111
  The handler class is the interface for dynamically loadable
1060
124
  =================
1061
125
  [Warning: this description is work in progress and may be incomplete]
1062
126
  The table record is stored in a fixed-size buffer:
1063
 
   
 
127
 
1064
128
    record: null_bytes, column1_data, column2_data, ...
1065
 
  
1066
 
  The offsets of the parts of the buffer are also fixed: every column has 
 
129
 
 
130
  The offsets of the parts of the buffer are also fixed: every column has
1067
131
  an offset to its column{i}_data, and if it is nullable it also has its own
1068
 
  bit in null_bytes. 
 
132
  bit in null_bytes.
1069
133
 
1070
134
  The record buffer only includes data about columns that are marked in the
1071
135
  relevant column set (table->read_set and/or table->write_set, depending on
1072
 
  the situation). 
 
136
  the situation).
1073
137
  <not-sure>It could be that it is required that null bits of non-present
1074
138
  columns are set to 1</not-sure>
1075
139
 
1076
140
  VARIOUS EXCEPTIONS AND SPECIAL CASES
1077
141
 
1078
 
  f the table has no nullable columns, then null_bytes is still 
1079
 
  present, its length is one byte <not-sure> which must be set to 0xFF 
 
142
  f the table has no nullable columns, then null_bytes is still
 
143
  present, its length is one byte <not-sure> which must be set to 0xFF
1080
144
  at all times. </not-sure>
1081
 
  
 
145
 
1082
146
  If the table has columns of type BIT, then certain bits from those columns
1083
147
  may be stored in null_bytes as well. Grep around for Field_bit for
1084
148
  details.
1085
149
 
1086
 
  For blob columns (see Field_blob), the record buffer stores length of the 
1087
 
  data, following by memory pointer to the blob data. The pointer is owned 
 
150
  For blob columns (see Field_blob), the record buffer stores length of the
 
151
  data, following by memory pointer to the blob data. The pointer is owned
1088
152
  by the storage engine and is valid until the next operation.
1089
153
 
1090
154
  If a blob column has NULL value, then its length and blob data pointer
1095
159
{
1096
160
public:
1097
161
  typedef uint64_t Table_flags;
 
162
 
1098
163
protected:
1099
 
  struct st_table_share *table_share;   /* The table definition */
 
164
  TABLE_SHARE *table_share;   /* The table definition */
1100
165
  Table *table;               /* The current open table */
1101
166
  Table_flags cached_table_flags;       /* Set on init() and open() */
1102
167
 
1103
168
  ha_rows estimation_rows_to_insert;
1104
169
public:
1105
 
  handlerton *ht;                 /* storage engine of this handler */
1106
 
  unsigned char *ref;                           /* Pointer to current row */
 
170
  StorageEngine *engine;      /* storage engine of this handler */
 
171
  unsigned char *ref;                           /* Pointer to current row */
1107
172
  unsigned char *dup_ref;                       /* Pointer to duplicate row */
1108
173
 
1109
174
  ha_statistics stats;
1125
190
  KEY_PART_INFO *range_key_part;
1126
191
  int key_compare_result_on_equal;
1127
192
  bool eq_range;
1128
 
  /* 
 
193
  /*
1129
194
    true <=> the engine guarantees that returned records are within the range
1130
195
    being scanned.
1131
196
  */
1158
223
    insert id for the current row (*autogenerated*; if not
1159
224
    autogenerated, it's 0).
1160
225
    At first successful insertion, this variable is stored into
1161
 
    THD::first_successful_insert_id_in_cur_stmt.
 
226
    Session::first_successful_insert_id_in_cur_stmt.
1162
227
  */
1163
228
  uint64_t insert_id_for_cur_row;
1164
229
  /**
1167
232
  */
1168
233
  Discrete_interval auto_inc_interval_for_cur_row;
1169
234
 
1170
 
  handler(handlerton *ht_arg, TABLE_SHARE *share_arg)
 
235
  handler(StorageEngine *engine_arg, TABLE_SHARE *share_arg)
1171
236
    :table_share(share_arg), table(0),
1172
 
    estimation_rows_to_insert(0), ht(ht_arg),
 
237
    estimation_rows_to_insert(0), engine(engine_arg),
1173
238
    ref(0), in_range_check_pushed_down(false),
1174
239
    key_used_on_scan(MAX_KEY), active_index(MAX_KEY),
1175
240
    ref_length(sizeof(my_off_t)),
1189
254
  {
1190
255
    cached_table_flags= table_flags();
1191
256
  }
 
257
 
1192
258
  /* ha_ methods: pubilc wrappers for private virtual API */
1193
259
 
1194
260
  int ha_open(Table *table, const char *name, int mode, int test_if_locked);
1195
 
  int ha_index_init(uint32_t idx, bool sorted)
1196
 
  {
1197
 
    int result;
1198
 
    assert(inited==NONE);
1199
 
    if (!(result= index_init(idx, sorted)))
1200
 
      inited=INDEX;
1201
 
    end_range= NULL;
1202
 
    return(result);
1203
 
  }
1204
 
  int ha_index_end()
1205
 
  {
1206
 
    assert(inited==INDEX);
1207
 
    inited=NONE;
1208
 
    end_range= NULL;
1209
 
    return(index_end());
1210
 
  }
1211
 
  int ha_rnd_init(bool scan)
1212
 
  {
1213
 
    int result;
1214
 
    assert(inited==NONE || (inited==RND && scan));
1215
 
    inited= (result= rnd_init(scan)) ? NONE: RND;
1216
 
    return(result);
1217
 
  }
1218
 
  int ha_rnd_end()
1219
 
  {
1220
 
    assert(inited==RND);
1221
 
    inited=NONE;
1222
 
    return(rnd_end());
1223
 
  }
 
261
  int ha_index_init(uint32_t idx, bool sorted);
 
262
  int ha_index_end();
 
263
  int ha_rnd_init(bool scan);
 
264
  int ha_rnd_end();
1224
265
  int ha_reset();
 
266
 
1225
267
  /* this is necessary in many places, e.g. in HANDLER command */
1226
 
  int ha_index_or_rnd_end()
1227
 
  {
1228
 
    return inited == INDEX ? ha_index_end() : inited == RND ? ha_rnd_end() : 0;
1229
 
  }
1230
 
  Table_flags ha_table_flags() const { return cached_table_flags; }
 
268
  int ha_index_or_rnd_end();
 
269
  Table_flags ha_table_flags() const;
 
270
 
1231
271
  /**
1232
272
    These functions represent the public interface to *users* of the
1233
273
    handler class, hence they are *not* virtual. For the inheritance
1234
274
    interface, see the (private) functions write_row(), update_row(),
1235
275
    and delete_row() below.
1236
276
  */
1237
 
  int ha_external_lock(THD *thd, int lock_type);
 
277
  int ha_external_lock(Session *session, int lock_type);
1238
278
  int ha_write_row(unsigned char * buf);
1239
279
  int ha_update_row(const unsigned char * old_data, unsigned char * new_data);
1240
280
  int ha_delete_row(const unsigned char * buf);
1242
282
 
1243
283
  int ha_check_for_upgrade(HA_CHECK_OPT *check_opt);
1244
284
  /** to be actually called to get 'check()' functionality*/
1245
 
  int ha_check(THD *thd, HA_CHECK_OPT *check_opt);
1246
 
  int ha_repair(THD* thd, HA_CHECK_OPT* check_opt);
1247
 
  void ha_start_bulk_insert(ha_rows rows)
1248
 
  {
1249
 
    estimation_rows_to_insert= rows;
1250
 
    start_bulk_insert(rows);
1251
 
  }
1252
 
  int ha_end_bulk_insert()
1253
 
  {
1254
 
    estimation_rows_to_insert= 0;
1255
 
    return end_bulk_insert();
1256
 
  }
 
285
  int ha_check(Session *session, HA_CHECK_OPT *check_opt);
 
286
  int ha_repair(Session* session, HA_CHECK_OPT* check_opt);
 
287
  void ha_start_bulk_insert(ha_rows rows);
 
288
  int ha_end_bulk_insert();
1257
289
  int ha_bulk_update_row(const unsigned char *old_data, unsigned char *new_data,
1258
290
                         uint32_t *dup_key_found);
1259
291
  int ha_delete_all_rows();
1260
292
  int ha_reset_auto_increment(uint64_t value);
1261
 
  int ha_optimize(THD* thd, HA_CHECK_OPT* check_opt);
1262
 
  int ha_analyze(THD* thd, HA_CHECK_OPT* check_opt);
1263
 
  bool ha_check_and_repair(THD *thd);
 
293
  int ha_optimize(Session* session, HA_CHECK_OPT* check_opt);
 
294
  int ha_analyze(Session* session, HA_CHECK_OPT* check_opt);
 
295
  bool ha_check_and_repair(Session *session);
1264
296
  int ha_disable_indexes(uint32_t mode);
1265
297
  int ha_enable_indexes(uint32_t mode);
1266
298
  int ha_discard_or_import_tablespace(bool discard);
1280
312
  virtual void print_error(int error, myf errflag);
1281
313
  virtual bool get_error_message(int error, String *buf);
1282
314
  uint32_t get_dup_key(int error);
1283
 
  virtual void change_table_ptr(Table *table_arg, TABLE_SHARE *share)
1284
 
  {
1285
 
    table= table_arg;
1286
 
    table_share= share;
1287
 
  }
 
315
  virtual void change_table_ptr(Table *table_arg, TABLE_SHARE *share);
 
316
 
1288
317
  /* Estimates calculation */
1289
318
  virtual double scan_time(void)
1290
319
  { return uint64_t2double(stats.data_file_length) / IO_SIZE + 2; }
1291
 
  virtual double read_time(uint32_t index __attribute__((unused)),
1292
 
                           uint32_t ranges, ha_rows rows)
 
320
  virtual double read_time(uint32_t, uint32_t ranges, ha_rows rows)
1293
321
  { return rows2double(ranges+rows); }
1294
322
 
1295
323
  virtual double index_only_read_time(uint32_t keynr, double records);
1296
 
  
 
324
 
1297
325
  virtual ha_rows multi_range_read_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
1298
 
                                              void *seq_init_param, 
 
326
                                              void *seq_init_param,
1299
327
                                              uint32_t n_ranges, uint32_t *bufsz,
1300
328
                                              uint32_t *flags, COST_VECT *cost);
1301
329
  virtual int multi_range_read_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys,
1306
334
  virtual int multi_range_read_next(char **range_info);
1307
335
 
1308
336
 
1309
 
  virtual const key_map *keys_to_use_for_scanning() { return &key_map_empty; }
1310
 
  bool has_transactions()
1311
 
  { return (ha_table_flags() & HA_NO_TRANSACTIONS) == 0; }
1312
 
  virtual uint32_t extra_rec_buf_length() const { return 0; }
 
337
  virtual const key_map *keys_to_use_for_scanning();
 
338
  bool has_transactions();
1313
339
 
1314
340
  /**
1315
341
    This method is used to analyse the error to see whether the error
1321
347
    same thing as HA_ERR_FOUND_DUP_KEY but can in some cases lead to
1322
348
    a slightly different error message.
1323
349
  */
1324
 
  virtual bool is_fatal_error(int error, uint32_t flags)
1325
 
  {
1326
 
    if (!error ||
1327
 
        ((flags & HA_CHECK_DUP_KEY) &&
1328
 
         (error == HA_ERR_FOUND_DUPP_KEY ||
1329
 
          error == HA_ERR_FOUND_DUPP_UNIQUE)))
1330
 
      return false;
1331
 
    return true;
1332
 
  }
 
350
  virtual bool is_fatal_error(int error, uint32_t flags);
1333
351
 
1334
352
  /**
1335
353
    Number of rows in table. It will only be called if
1336
354
    (table_flags() & (HA_HAS_RECORDS | HA_STATS_RECORDS_IS_EXACT)) != 0
1337
355
  */
1338
 
  virtual ha_rows records() { return stats.records; }
 
356
  virtual ha_rows records();
1339
357
  /**
1340
358
    Return upper bound of current number of records in the table
1341
359
    (max. of how many records one will retrieve when doing a full table scan)
1351
369
  */
1352
370
  virtual enum row_type get_row_type() const { return ROW_TYPE_NOT_USED; }
1353
371
 
1354
 
  virtual const char *index_type(uint32_t key_number __attribute__((unused)))
 
372
  virtual const char *index_type(uint32_t)
1355
373
  { assert(0); return "";}
1356
374
 
1357
375
 
1387
405
    @retval  0           Success
1388
406
    @retval  >0          Error code
1389
407
  */
1390
 
  virtual int exec_bulk_update(uint32_t *dup_key_found __attribute__((unused)))
 
408
  virtual int exec_bulk_update(uint32_t *)
1391
409
  {
1392
410
    assert(false);
1393
411
    return HA_ERR_WRONG_COMMAND;
1427
445
     row if available. If the key value is null, begin at the first key of the
1428
446
     index.
1429
447
  */
1430
 
  virtual int index_read_idx_map(unsigned char * buf, uint32_t index, const unsigned char * key,
 
448
  virtual int index_read_idx_map(unsigned char * buf, uint32_t index,
 
449
                                 const unsigned char * key,
1431
450
                                 key_part_map keypart_map,
1432
451
                                 enum ha_rkey_function find_flag);
1433
 
  virtual int index_next(unsigned char * buf __attribute__((unused)))
1434
 
   { return  HA_ERR_WRONG_COMMAND; }
1435
 
  virtual int index_prev(unsigned char * buf __attribute__((unused)))
1436
 
   { return  HA_ERR_WRONG_COMMAND; }
1437
 
  virtual int index_first(unsigned char * buf __attribute__((unused)))
1438
 
   { return  HA_ERR_WRONG_COMMAND; }
1439
 
  virtual int index_last(unsigned char * buf __attribute__((unused)))
1440
 
   { return  HA_ERR_WRONG_COMMAND; }
1441
 
  virtual int index_next_same(unsigned char *buf __attribute__((unused)),
1442
 
                              const unsigned char *key __attribute__((unused)),
1443
 
                              uint32_t keylen __attribute__((unused)));
 
452
  virtual int index_next(unsigned char *)
 
453
   { return  HA_ERR_WRONG_COMMAND; }
 
454
  virtual int index_prev(unsigned char *)
 
455
   { return  HA_ERR_WRONG_COMMAND; }
 
456
  virtual int index_first(unsigned char *)
 
457
   { return  HA_ERR_WRONG_COMMAND; }
 
458
  virtual int index_last(unsigned char *)
 
459
   { return  HA_ERR_WRONG_COMMAND; }
 
460
  virtual int index_next_same(unsigned char *, const unsigned char *, uint32_t);
1444
461
  /**
1445
462
     @brief
1446
463
     The following functions works like index_read, but it find the last
1458
475
  virtual int read_range_next();
1459
476
  int compare_key(key_range *range);
1460
477
  int compare_key2(key_range *range);
1461
 
  virtual int rnd_next(unsigned char *buf __attribute__((unused)))=0;
1462
 
  virtual int rnd_pos(unsigned char * buf __attribute__((unused)),
1463
 
                      unsigned char *pos __attribute__((unused)))=0;
 
478
  virtual int rnd_next(unsigned char *)=0;
 
479
  virtual int rnd_pos(unsigned char *, unsigned char *)=0;
1464
480
  /**
1465
481
    One has to use this method when to find
1466
482
    random position by record as the plain
1473
489
    The following function is only needed for tables that may be temporary
1474
490
    tables during joins.
1475
491
  */
1476
 
  virtual int restart_rnd_next(unsigned char *buf __attribute__((unused)),
1477
 
                               unsigned char *pos __attribute__((unused)))
1478
 
    { return HA_ERR_WRONG_COMMAND; }
1479
 
  virtual int rnd_same(unsigned char *buf __attribute__((unused)),
1480
 
                       uint32_t inx __attribute__((unused)))
1481
 
    { return HA_ERR_WRONG_COMMAND; }
1482
 
  virtual ha_rows records_in_range(uint32_t inx __attribute__((unused)),
1483
 
                                   key_range *min_key __attribute__((unused)),
1484
 
                                   key_range *max_key __attribute__((unused)))
 
492
  virtual int restart_rnd_next(unsigned char *, unsigned char *)
 
493
    { return HA_ERR_WRONG_COMMAND; }
 
494
  virtual int rnd_same(unsigned char *, uint32_t)
 
495
    { return HA_ERR_WRONG_COMMAND; }
 
496
  virtual ha_rows records_in_range(uint32_t, key_range *, key_range *)
1485
497
    { return (ha_rows) 10; }
1486
498
  virtual void position(const unsigned char *record)=0;
1487
 
  virtual int info(uint)=0; // see my_base.h for full description
1488
 
  virtual uint32_t calculate_key_hash_value(Field **field_array __attribute__((unused)))
 
499
  virtual int info(uint32_t)=0; // see my_base.h for full description
 
500
  virtual uint32_t calculate_key_hash_value(Field **)
1489
501
  { assert(0); return 0; }
1490
 
  virtual int extra(enum ha_extra_function operation __attribute__((unused)))
 
502
  virtual int extra(enum ha_extra_function)
1491
503
  { return 0; }
1492
 
  virtual int extra_opt(enum ha_extra_function operation,
1493
 
                        uint32_t cache_size __attribute__((unused)))
 
504
  virtual int extra_opt(enum ha_extra_function operation, uint32_t)
1494
505
  { return extra(operation); }
1495
506
 
1496
507
  /**
1514
525
  */
1515
526
  virtual void try_semi_consistent_read(bool) {}
1516
527
  virtual void unlock_row(void) {}
1517
 
  virtual int start_stmt(THD *thd __attribute__((unused)),
1518
 
                         thr_lock_type lock_type __attribute__((unused)))
 
528
  virtual int start_stmt(Session *, thr_lock_type)
1519
529
  {return 0;}
1520
530
  virtual void get_auto_increment(uint64_t offset, uint64_t increment,
1521
531
                                  uint64_t nb_desired_values,
1541
551
      insert_id_for_cur_row;
1542
552
  }
1543
553
 
1544
 
  virtual void update_create_info(HA_CREATE_INFO *create_info __attribute__((unused))) {}
 
554
  virtual void update_create_info(HA_CREATE_INFO *) {}
1545
555
  int check_old_types(void);
1546
 
  virtual int assign_to_keycache(THD* thd __attribute__((unused)),
1547
 
                                 HA_CHECK_OPT* check_opt __attribute__((unused)))
 
556
  virtual int assign_to_keycache(Session*, HA_CHECK_OPT *)
1548
557
  { return HA_ADMIN_NOT_IMPLEMENTED; }
1549
558
  /* end of the list of admin commands */
1550
559
 
1551
560
  virtual int indexes_are_disabled(void) {return 0;}
1552
561
  virtual char *update_table_comment(const char * comment)
1553
562
  { return (char*) comment;}
1554
 
  virtual void append_create_info(String *packet __attribute__((unused)))
 
563
  virtual void append_create_info(String *)
1555
564
  {}
1556
565
  /**
1557
566
      If index == MAX_KEY then a check for table is made and if index <
1563
572
    @retval   true            Foreign key defined on table or index
1564
573
    @retval   false           No foreign key defined
1565
574
  */
1566
 
  virtual bool is_fk_defined_on_table_or_index(uint32_t index __attribute__((unused)))
 
575
  virtual bool is_fk_defined_on_table_or_index(uint32_t)
1567
576
  { return false; }
1568
577
  virtual char* get_foreign_key_create_info(void)
1569
578
  { return(NULL);}  /* gets foreign key create string from InnoDB */
1570
579
  /** used in ALTER Table; 1 if changing storage engine is allowed */
1571
580
  virtual bool can_switch_engines(void) { return 1; }
1572
581
  /** used in REPLACE; is > 0 if table is referred by a FOREIGN KEY */
1573
 
  virtual int get_foreign_key_list(THD *thd __attribute__((unused)),
1574
 
                                   List<FOREIGN_KEY_INFO> *f_key_list __attribute__((unused)))
 
582
  virtual int get_foreign_key_list(Session *, List<FOREIGN_KEY_INFO> *)
1575
583
  { return 0; }
1576
584
  virtual uint32_t referenced_by_foreign_key() { return 0;}
1577
585
  virtual void init_table_handle_for_HANDLER()
1578
586
  { return; }       /* prepare InnoDB for HANDLER */
1579
 
  virtual void free_foreign_key_create_info(char* str __attribute__((unused))) {}
 
587
  virtual void free_foreign_key_create_info(char *) {}
1580
588
  /** The following can be called without an open handler */
1581
589
  virtual const char *table_type() const =0;
1582
590
  /**
1592
600
  */
1593
601
  virtual const char **bas_ext() const =0;
1594
602
 
1595
 
  virtual int get_default_no_partitions(HA_CREATE_INFO *info __attribute__((unused))) { return 1;}
1596
 
  virtual bool get_no_parts(const char *name __attribute__((unused)),
1597
 
                            uint32_t *no_parts)
 
603
  virtual int get_default_no_partitions(HA_CREATE_INFO *) { return 1;}
 
604
  virtual bool get_no_parts(const char *, uint32_t *no_parts)
1598
605
  {
1599
606
    *no_parts= 0;
1600
607
    return 0;
1602
609
 
1603
610
  virtual uint32_t index_flags(uint32_t idx, uint32_t part, bool all_parts) const =0;
1604
611
 
1605
 
  virtual int add_index(Table *table_arg __attribute__((unused)),
1606
 
                        KEY *key_info __attribute__((unused)),
1607
 
                        uint32_t num_of_keys __attribute__((unused)))
1608
 
  { return (HA_ERR_WRONG_COMMAND); }
1609
 
  virtual int prepare_drop_index(Table *table_arg __attribute__((unused)),
1610
 
                                 uint32_t *key_num __attribute__((unused)),
1611
 
                                 uint32_t num_of_keys __attribute__((unused)))
1612
 
  { return (HA_ERR_WRONG_COMMAND); }
1613
 
  virtual int final_drop_index(Table *table_arg __attribute__((unused)))
 
612
  virtual int add_index(Table *, KEY *, uint32_t)
 
613
  { return (HA_ERR_WRONG_COMMAND); }
 
614
  virtual int prepare_drop_index(Table *, uint32_t *, uint32_t)
 
615
  { return (HA_ERR_WRONG_COMMAND); }
 
616
  virtual int final_drop_index(Table *)
1614
617
  { return (HA_ERR_WRONG_COMMAND); }
1615
618
 
1616
619
  uint32_t max_record_length() const
1630
633
  virtual uint32_t max_supported_key_parts(void) const { return MAX_REF_PARTS; }
1631
634
  virtual uint32_t max_supported_key_length(void) const { return MAX_KEY_LENGTH; }
1632
635
  virtual uint32_t max_supported_key_part_length(void) const { return 255; }
1633
 
  virtual uint32_t min_record_length(uint32_t options __attribute__((unused))) const
1634
 
  { return 1; }
1635
636
 
1636
637
  virtual bool low_byte_first(void) const { return 1; }
1637
638
  virtual uint32_t checksum(void) const { return 0; }
1661
662
    than lock_count() claimed. This can happen when the MERGE children
1662
663
    are not attached when this is called from another thread.
1663
664
  */
1664
 
  virtual THR_LOCK_DATA **store_lock(THD *thd,
 
665
  virtual THR_LOCK_DATA **store_lock(Session *session,
1665
666
                                     THR_LOCK_DATA **to,
1666
667
                                     enum thr_lock_type lock_type)=0;
1667
668
 
1669
670
  virtual uint8_t table_cache_type() { return HA_CACHE_TBL_NONTRANSACT; }
1670
671
 
1671
672
 
1672
 
  /**
1673
 
    @brief Register a named table with a call back function to the query cache.
1674
 
 
1675
 
    @param thd The thread handle
1676
 
    @param table_key A pointer to the table name in the table cache
1677
 
    @param key_length The length of the table name
1678
 
    @param[out] engine_callback The pointer to the storage engine call back
1679
 
      function
1680
 
    @param[out] engine_data Storage engine specific data which could be
1681
 
      anything
1682
 
 
1683
 
    This method offers the storage engine, the possibility to store a reference
1684
 
    to a table name which is going to be used with query cache. 
1685
 
    The method is called each time a statement is written to the cache and can
1686
 
    be used to verify if a specific statement is cachable. It also offers
1687
 
    the possibility to register a generic (but static) call back function which
1688
 
    is called each time a statement is matched against the query cache.
1689
 
 
1690
 
    @note If engine_data supplied with this function is different from
1691
 
      engine_data supplied with the callback function, and the callback returns
1692
 
      false, a table invalidation on the current table will occur.
1693
 
 
1694
 
    @return Upon success the engine_callback will point to the storage engine
1695
 
      call back function, if any, and engine_data will point to any storage
1696
 
      engine data used in the specific implementation.
1697
 
      @retval true Success
1698
 
      @retval false The specified table or current statement should not be
1699
 
        cached
1700
 
  */
1701
 
 
1702
 
  virtual bool
1703
 
    register_query_cache_table(THD *thd __attribute__((unused)),
1704
 
                               char *table_key __attribute__((unused)),
1705
 
                               uint32_t key_length __attribute__((unused)),
1706
 
                               qc_engine_callback *engine_callback,
1707
 
                               uint64_t *engine_data __attribute__((unused)))
1708
 
  {
1709
 
    *engine_callback= 0;
1710
 
    return true;
1711
 
  }
1712
 
 
1713
 
 
1714
673
 /*
1715
674
   @retval true   Primary key (if there is one) is clustered
1716
675
                  key covering all fields
1740
699
   @note
1741
700
   The pushed conditions form a stack (from which one can remove the
1742
701
   last pushed condition using cond_pop).
1743
 
   The table handler filters out rows using (pushed_cond1 AND pushed_cond2 
 
702
   The table handler filters out rows using (pushed_cond1 AND pushed_cond2
1744
703
   AND ... AND pushed_condN)
1745
704
   or less restrictive condition, depending on handler's capabilities.
1746
705
 
1747
706
   handler->ha_reset() call empties the condition stack.
1748
707
   Calls to rnd_init/rnd_end, index_init/index_end etc do not affect the
1749
708
   condition stack.
1750
 
 */ 
 
709
 */
1751
710
 virtual const COND *cond_push(const COND *cond) { return cond; }
1752
711
 
1753
712
 /**
1757
716
 */
1758
717
 virtual void cond_pop(void) { return; }
1759
718
 
1760
 
 virtual Item
1761
 
   *idx_cond_push(uint32_t keyno __attribute__((unused)),
1762
 
                  Item* idx_cond __attribute__((unused)))
 
719
 virtual Item *idx_cond_push(uint32_t, Item *idx_cond)
1763
720
 { return idx_cond; }
1764
721
 
1765
722
 /*
1766
723
    Part of old fast alter table, to be depricated
1767
724
  */
1768
725
 virtual bool
1769
 
   check_if_incompatible_data(HA_CREATE_INFO *create_info __attribute__((unused)),
1770
 
                              uint32_t table_changes __attribute__((unused)))
 
726
   check_if_incompatible_data(HA_CREATE_INFO *, uint32_t)
1771
727
 { return COMPATIBLE_DATA_NO; }
1772
728
 
 
729
 /*
 
730
  * Check if the HA_ALTER_STORED_VCOL bit is set. If it is, then
 
731
  * we will clear all other bits and return true; otherwise 
 
732
  * clear all the bits in the the bitset and return false.
 
733
  *
 
734
  * @param    alter_flags    Bitmap that shows what will be changed
 
735
  */
 
736
 virtual bool check_stored_vcol_flag(HA_ALTER_FLAGS *alter_flags)
 
737
 {
 
738
   if (alter_flags->test(HA_ALTER_STORED_VCOL))
 
739
   {
 
740
     alter_flags->reset();
 
741
     alter_flags->set(HA_ALTER_STORED_VCOL);
 
742
   }
 
743
   else
 
744
   {
 
745
     alter_flags->reset();
 
746
   }
 
747
   return (alter_flags->any());
 
748
 }
 
749
 
1773
750
 /* On-line ALTER Table interface */
1774
751
 
1775
752
 /**
1795
772
      just changing the frm file) without any change in the handler
1796
773
      implementation.
1797
774
 */
1798
 
 virtual int
1799
 
   check_if_supported_alter(Table *altered_table __attribute__((unused)),
1800
 
                            HA_CREATE_INFO *create_info,
1801
 
                            HA_ALTER_FLAGS *alter_flags __attribute__((unused)),
1802
 
                            uint32_t table_changes)
 
775
 virtual int check_if_supported_alter(Table *, HA_CREATE_INFO *create_info,
 
776
                                      HA_ALTER_FLAGS * alter_flags, uint32_t table_changes)
1803
777
 {
1804
778
   if (this->check_if_incompatible_data(create_info, table_changes)
1805
779
       == COMPATIBLE_DATA_NO)
1806
780
     return(HA_ALTER_NOT_SUPPORTED);
 
781
   else if (this->check_stored_vcol_flag(alter_flags))
 
782
     return(HA_ALTER_NOT_SUPPORTED);
1807
783
   else
1808
784
     return(HA_ALTER_SUPPORTED_WAIT_LOCK);
1809
785
 }
1810
786
 /**
1811
787
   Tell storage engine to prepare for the on-line alter table (pre-alter)
1812
788
 
1813
 
   @param     thd               The thread handle
 
789
   @param     session               The thread handle
1814
790
   @param     altered_table     A temporary table show what table is to
1815
791
                                change to
1816
792
   @param     alter_info        Storage place for data used during phase1
1820
796
   @retval   0      OK
1821
797
   @retval   error  error code passed from storage engine
1822
798
 */
1823
 
 virtual int alter_table_phase1(THD *thd __attribute__((unused)),
1824
 
                                Table *altered_table __attribute__((unused)),
1825
 
                                HA_CREATE_INFO *create_info __attribute__((unused)),
1826
 
                                HA_ALTER_INFO *alter_info __attribute__((unused)),
1827
 
                                HA_ALTER_FLAGS *alter_flags  __attribute__((unused)))
 
799
 virtual int alter_table_phase1(Session *, Table *, HA_CREATE_INFO *, HA_ALTER_INFO *,
 
800
                                HA_ALTER_FLAGS *)
1828
801
 {
1829
802
   return HA_ERR_UNSUPPORTED;
1830
803
 }
1831
804
 /**
1832
805
    Tell storage engine to perform the on-line alter table (alter)
1833
806
 
1834
 
    @param    thd               The thread handle
 
807
    @param    session               The thread handle
1835
808
    @param    altered_table     A temporary table show what table is to
1836
809
                                change to
1837
810
    @param    alter_info        Storage place for data used during phase1
1846
819
      this call is to be wrapped with a DDL lock. This is currently NOT
1847
820
      supported.
1848
821
 */
1849
 
 virtual int alter_table_phase2(THD *thd  __attribute__((unused)),
1850
 
                                Table *altered_table  __attribute__((unused)),
1851
 
                                HA_CREATE_INFO *create_info __attribute__((unused)),
1852
 
                                HA_ALTER_INFO *alter_info __attribute__((unused)),
1853
 
                                HA_ALTER_FLAGS *alter_flags __attribute__((unused)))
 
822
 virtual int alter_table_phase2(Session *, Table *, HA_CREATE_INFO *, HA_ALTER_INFO *,
 
823
                                HA_ALTER_FLAGS *)
1854
824
 {
1855
825
   return HA_ERR_UNSUPPORTED;
1856
826
 }
1858
828
    Tell storage engine that changed frm file is now on disk and table
1859
829
    has been re-opened (post-alter)
1860
830
 
1861
 
    @param    thd               The thread handle
 
831
    @param    session               The thread handle
1862
832
    @param    table             The altered table, re-opened
1863
833
 */
1864
 
 virtual int alter_table_phase3(THD *thd __attribute__((unused)),
1865
 
                                Table *table __attribute__((unused)))
 
834
 virtual int alter_table_phase3(Session *, Table *)
1866
835
 {
1867
836
   return HA_ERR_UNSUPPORTED;
1868
837
 }
1877
846
  /**
1878
847
    Lock table.
1879
848
 
1880
 
    @param    thd                     Thread handle
 
849
    @param    session                     Thread handle
1881
850
    @param    lock_type               HA_LOCK_IN_SHARE_MODE     (F_RDLCK)
1882
851
                                      HA_LOCK_IN_EXCLUSIVE_MODE (F_WRLCK)
1883
852
    @param    lock_timeout            -1 default timeout
1898
867
                                      lock conflict with NOWAIT option
1899
868
    @retval HA_ERR_LOCK_DEADLOCK      Deadlock detected
1900
869
  */
1901
 
  virtual int lock_table(THD *thd         __attribute__((unused)),
1902
 
                         int lock_type    __attribute__((unused)),
1903
 
                         int lock_timeout __attribute__((unused)))
 
870
  virtual int lock_table(Session *, int, int)
1904
871
  {
1905
872
    return HA_ERR_WRONG_COMMAND;
1906
873
  }
 
874
  /*
 
875
    This procedure defines if the storage engine supports virtual columns.
 
876
    Default false means "not supported".
 
877
  */
 
878
  virtual bool check_if_supported_virtual_columns(void)
 
879
  { return false; }
1907
880
 
1908
881
protected:
1909
882
  /* Service methods for use by storage engines. */
1910
883
  void ha_statistic_increment(ulong SSV::*offset) const;
1911
 
  void **ha_data(THD *) const;
1912
 
  THD *ha_thd(void) const;
 
884
  void **ha_data(Session *) const;
 
885
  Session *ha_session(void) const;
1913
886
 
1914
887
  /**
1915
888
    Default rename_table() and delete_table() rename/delete files with a
1936
909
  */
1937
910
 
1938
911
  virtual int open(const char *name, int mode, uint32_t test_if_locked)=0;
1939
 
  virtual int index_init(uint32_t idx,
1940
 
                         bool sorted __attribute__((unused)))
 
912
  virtual int index_init(uint32_t idx, bool)
1941
913
  { active_index= idx; return 0; }
1942
914
  virtual int index_end() { active_index= MAX_KEY; return 0; }
1943
915
  /**
1949
921
  */
1950
922
  virtual int rnd_init(bool scan)= 0;
1951
923
  virtual int rnd_end() { return 0; }
1952
 
  virtual int write_row(unsigned char *buf __attribute__((unused)))
1953
 
  {
1954
 
    return HA_ERR_WRONG_COMMAND;
1955
 
  }
1956
 
 
1957
 
  virtual int update_row(const unsigned char *old_data __attribute__((unused)),
1958
 
                         unsigned char *new_data __attribute__((unused)))
1959
 
  {
1960
 
    return HA_ERR_WRONG_COMMAND;
1961
 
  }
1962
 
 
1963
 
  virtual int delete_row(const unsigned char *buf __attribute__((unused)))
 
924
  virtual int write_row(unsigned char *)
 
925
  {
 
926
    return HA_ERR_WRONG_COMMAND;
 
927
  }
 
928
 
 
929
  virtual int update_row(const unsigned char *, unsigned char *)
 
930
  {
 
931
    return HA_ERR_WRONG_COMMAND;
 
932
  }
 
933
 
 
934
  virtual int delete_row(const unsigned char *)
1964
935
  {
1965
936
    return HA_ERR_WRONG_COMMAND;
1966
937
  }
1994
965
    @return  non-0 in case of failure, 0 in case of success.
1995
966
    When lock_type is F_UNLCK, the return value is ignored.
1996
967
  */
1997
 
  virtual int external_lock(THD *thd __attribute__((unused)),
1998
 
                            int lock_type __attribute__((unused)))
 
968
  virtual int external_lock(Session *, int)
1999
969
  {
2000
970
    return 0;
2001
971
  }
2002
972
  virtual void release_auto_increment(void) { return; };
2003
973
  /** admin commands - called from mysql_admin_table */
2004
 
  virtual int check_for_upgrade(HA_CHECK_OPT *check_opt __attribute__((unused)))
 
974
  virtual int check_for_upgrade(HA_CHECK_OPT *)
2005
975
  { return 0; }
2006
 
  virtual int check(THD* thd __attribute__((unused)),
2007
 
                    HA_CHECK_OPT* check_opt __attribute__((unused)))
 
976
  virtual int check(Session *, HA_CHECK_OPT *)
2008
977
  { return HA_ADMIN_NOT_IMPLEMENTED; }
2009
978
 
2010
979
  /**
2012
981
     to specify CHECK option to use to call check()
2013
982
     upon the table.
2014
983
  */
2015
 
  virtual int repair(THD* thd __attribute__((unused)),
2016
 
                     HA_CHECK_OPT* check_opt __attribute__((unused)))
 
984
  virtual int repair(Session *, HA_CHECK_OPT *)
2017
985
  { return HA_ADMIN_NOT_IMPLEMENTED; }
2018
 
  virtual void start_bulk_insert(ha_rows rows __attribute__((unused)))
 
986
  virtual void start_bulk_insert(ha_rows)
2019
987
  {}
2020
988
  virtual int end_bulk_insert(void) { return 0; }
2021
 
  virtual int index_read(unsigned char * buf __attribute__((unused)),
2022
 
                         const unsigned char * key __attribute__((unused)),
2023
 
                         uint32_t key_len __attribute__((unused)),
2024
 
                         enum ha_rkey_function find_flag __attribute__((unused)))
 
989
  virtual int index_read(unsigned char *, const unsigned char *,
 
990
                         uint32_t, enum ha_rkey_function)
2025
991
   { return  HA_ERR_WRONG_COMMAND; }
2026
 
  virtual int index_read_last(unsigned char * buf __attribute__((unused)),
2027
 
                              const unsigned char * key __attribute__((unused)),
2028
 
                              uint32_t key_len __attribute__((unused)))
 
992
  virtual int index_read_last(unsigned char *, const unsigned char *, uint32_t)
2029
993
   { return (my_errno= HA_ERR_WRONG_COMMAND); }
2030
994
  /**
2031
995
    This method is similar to update_row, however the handler doesn't need
2040
1004
    @retval  0   Bulk delete used by handler
2041
1005
    @retval  1   Bulk delete not used, normal operation used
2042
1006
  */
2043
 
  virtual int bulk_update_row(const unsigned char *old_data __attribute__((unused)),
2044
 
                              unsigned char *new_data __attribute__((unused)),
2045
 
                              uint32_t *dup_key_found __attribute__((unused)))
 
1007
  virtual int bulk_update_row(const unsigned char *, unsigned char *, uint32_t *)
2046
1008
  {
2047
1009
    assert(false);
2048
1010
    return HA_ERR_WRONG_COMMAND;
2061
1023
    is emulated by doing a 'DELETE FROM t'. HA_ERR_WRONG_COMMAND is
2062
1024
    returned by storage engines that don't support this operation.
2063
1025
  */
2064
 
  virtual int reset_auto_increment(uint64_t value __attribute__((unused)))
 
1026
  virtual int reset_auto_increment(uint64_t)
2065
1027
  { return HA_ERR_WRONG_COMMAND; }
2066
 
  virtual int optimize(THD* thd __attribute__((unused)),
2067
 
                       HA_CHECK_OPT* check_opt __attribute__((unused)))
2068
 
  { return HA_ADMIN_NOT_IMPLEMENTED; }
2069
 
  virtual int analyze(THD* thd __attribute__((unused)),
2070
 
                      HA_CHECK_OPT* check_opt __attribute__((unused)))
2071
 
  { return HA_ADMIN_NOT_IMPLEMENTED; }
2072
 
  virtual bool check_and_repair(THD *thd __attribute__((unused)))
 
1028
  virtual int optimize(Session *, HA_CHECK_OPT *)
 
1029
  { return HA_ADMIN_NOT_IMPLEMENTED; }
 
1030
  virtual int analyze(Session *, HA_CHECK_OPT *)
 
1031
  { return HA_ADMIN_NOT_IMPLEMENTED; }
 
1032
  virtual bool check_and_repair(Session *)
2073
1033
  { return true; }
2074
 
  virtual int disable_indexes(uint32_t mode __attribute__((unused)))
2075
 
  { return HA_ERR_WRONG_COMMAND; }
2076
 
  virtual int enable_indexes(uint32_t mode __attribute__((unused)))
2077
 
  { return HA_ERR_WRONG_COMMAND; }
2078
 
  virtual int discard_or_import_tablespace(bool discard __attribute__((unused)))
 
1034
  virtual int disable_indexes(uint32_t)
 
1035
  { return HA_ERR_WRONG_COMMAND; }
 
1036
  virtual int enable_indexes(uint32_t)
 
1037
  { return HA_ERR_WRONG_COMMAND; }
 
1038
  virtual int discard_or_import_tablespace(bool)
2079
1039
  { return (my_errno=HA_ERR_WRONG_COMMAND); }
2080
1040
  virtual void prepare_for_alter(void) { return; }
2081
1041
  virtual void drop_table(const char *name);
2082
 
  virtual int create(const char *name __attribute__((unused)),
2083
 
                     Table *form __attribute__((unused)),
2084
 
                     HA_CREATE_INFO *info __attribute__((unused)))=0;
 
1042
  virtual int create(const char *, Table *, HA_CREATE_INFO *)=0;
2085
1043
 
2086
 
  virtual int create_handler_files(const char *name __attribute__((unused)),
2087
 
                                   const char *old_name __attribute__((unused)),
2088
 
                                   int action_flag __attribute__((unused)),
2089
 
                                   HA_CREATE_INFO *info __attribute__((unused)))
 
1044
  virtual int create_handler_files(const char *, const char *, int, HA_CREATE_INFO *)
2090
1045
  { return false; }
2091
1046
};
2092
1047
 
2096
1051
  A Disk-Sweep MRR interface implementation
2097
1052
 
2098
1053
  This implementation makes range (and, in the future, 'ref') scans to read
2099
 
  table rows in disk sweeps. 
2100
 
  
 
1054
  table rows in disk sweeps.
 
1055
 
2101
1056
  Currently it is used by MyISAM and InnoDB. Potentially it can be used with
2102
1057
  any table handler that has non-clustered indexes and on-disk rows.
2103
1058
*/
2134
1089
public:
2135
1090
  void init(handler *h_arg, Table *table_arg)
2136
1091
  {
2137
 
    h= h_arg; 
 
1092
    h= h_arg;
2138
1093
    table= table_arg;
2139
1094
  }
2140
 
  int dsmrr_init(handler *h, KEY *key, RANGE_SEQ_IF *seq_funcs, 
2141
 
                 void *seq_init_param, uint32_t n_ranges, uint32_t mode, 
 
1095
  int dsmrr_init(handler *h, KEY *key, RANGE_SEQ_IF *seq_funcs,
 
1096
                 void *seq_init_param, uint32_t n_ranges, uint32_t mode,
2142
1097
                 HANDLER_BUFFER *buf);
2143
1098
  void dsmrr_close();
2144
1099
  int dsmrr_fill_buffer(handler *h);
2147
1102
  int dsmrr_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys, uint32_t *bufsz,
2148
1103
                 uint32_t *flags, COST_VECT *cost);
2149
1104
 
2150
 
  ha_rows dsmrr_info_const(uint32_t keyno, RANGE_SEQ_IF *seq, 
 
1105
  ha_rows dsmrr_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
2151
1106
                            void *seq_init_param, uint32_t n_ranges, uint32_t *bufsz,
2152
1107
                            uint32_t *flags, COST_VECT *cost);
2153
1108
private:
2154
1109
  bool key_uses_partial_cols(uint32_t keyno);
2155
 
  bool choose_mrr_impl(uint32_t keyno, ha_rows rows, uint32_t *flags, uint32_t *bufsz, 
 
1110
  bool choose_mrr_impl(uint32_t keyno, ha_rows rows, uint32_t *flags, uint32_t *bufsz,
2156
1111
                       COST_VECT *cost);
2157
 
  bool get_disk_sweep_mrr_cost(uint32_t keynr, ha_rows rows, uint32_t flags, 
 
1112
  bool get_disk_sweep_mrr_cost(uint32_t keynr, ha_rows rows, uint32_t flags,
2158
1113
                               uint32_t *buffer_size, COST_VECT *cost);
2159
1114
};
2160
1115
 
2166
1121
extern uint32_t total_ha, total_ha_2pc;
2167
1122
 
2168
1123
       /* Wrapper functions */
2169
 
#define ha_commit(thd) (ha_commit_trans((thd), true))
2170
 
#define ha_rollback(thd) (ha_rollback_trans((thd), true))
2171
 
 
2172
 
/* lookups */
2173
 
handlerton *ha_default_handlerton(THD *thd);
2174
 
plugin_ref ha_resolve_by_name(THD *thd, const LEX_STRING *name);
2175
 
plugin_ref ha_lock_engine(THD *thd, handlerton *hton);
2176
 
handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type);
2177
 
handler *get_new_handler(TABLE_SHARE *share, MEM_ROOT *alloc,
2178
 
                         handlerton *db_type);
2179
 
handlerton *ha_checktype(THD *thd, enum legacy_db_type database_type,
2180
 
                          bool no_substitute, bool report_error);
2181
 
 
2182
 
 
2183
 
static inline enum legacy_db_type ha_legacy_type(const handlerton *db_type)
2184
 
{
2185
 
  return (db_type == NULL) ? DB_TYPE_UNKNOWN : db_type->db_type;
2186
 
}
2187
 
 
2188
 
static inline const char *ha_resolve_storage_engine_name(const handlerton *db_type)
2189
 
{
2190
 
  return db_type == NULL ? "UNKNOWN" : hton2plugin[db_type->slot]->name.str;
2191
 
}
2192
 
 
2193
 
static inline bool ha_check_storage_engine_flag(const handlerton *db_type, uint32_t flag)
2194
 
{
2195
 
  return db_type == NULL ? false : test(db_type->flags & flag);
2196
 
}
2197
 
 
2198
 
static inline bool ha_storage_engine_is_enabled(const handlerton *db_type)
2199
 
{
2200
 
  return (db_type && db_type->create) ?
2201
 
         (db_type->state == SHOW_OPTION_YES) : false;
2202
 
}
 
1124
#define ha_commit(session) (ha_commit_trans((session), true))
 
1125
#define ha_rollback(session) (ha_rollback_trans((session), true))
2203
1126
 
2204
1127
/* basic stuff */
2205
1128
int ha_init_errors(void);
2206
1129
int ha_init(void);
2207
1130
int ha_end(void);
2208
 
int ha_initialize_handlerton(st_plugin_int *plugin);
2209
 
int ha_finalize_handlerton(st_plugin_int *plugin);
2210
 
 
2211
 
TYPELIB *ha_known_exts(void);
2212
 
void ha_close_connection(THD* thd);
2213
 
bool ha_flush_logs(handlerton *db_type);
 
1131
 
 
1132
void add_storage_engine(StorageEngine *engine);
 
1133
void remove_storage_engine(StorageEngine *engine);
 
1134
 
 
1135
void ha_close_connection(Session* session);
 
1136
bool ha_flush_logs(StorageEngine *db_type);
2214
1137
void ha_drop_database(char* path);
2215
 
int ha_create_table(THD *thd, const char *path,
 
1138
int ha_create_table(Session *session, const char *path,
2216
1139
                    const char *db, const char *table_name,
2217
1140
                    HA_CREATE_INFO *create_info,
2218
1141
                    bool update_create_info);
2219
 
int ha_delete_table(THD *thd, handlerton *db_type, const char *path,
 
1142
int ha_delete_table(Session *session, const char *path,
2220
1143
                    const char *db, const char *alias, bool generate_warning);
2221
1144
 
2222
1145
/* statistics and info */
2223
 
bool ha_show_status(THD *thd, handlerton *db_type, enum ha_stat_type stat);
 
1146
bool ha_show_status(Session *session, StorageEngine *db_type, enum ha_stat_type stat);
2224
1147
 
2225
 
/* discovery */
2226
 
int ha_create_table_from_engine(THD* thd, const char *db, const char *name);
2227
 
int ha_discover(THD* thd, const char* dbname, const char* name,
2228
 
                unsigned char** frmblob, size_t* frmlen);
2229
 
int ha_find_files(THD *thd,const char *db,const char *path,
 
1148
int ha_find_files(Session *session,const char *db,const char *path,
2230
1149
                  const char *wild, bool dir, List<LEX_STRING>* files);
2231
 
int ha_table_exists_in_engine(THD* thd, const char* db, const char* name);
 
1150
int ha_table_exists_in_engine(Session* session, const char* db, const char* name, StorageEngine **engine= NULL);
2232
1151
 
2233
1152
/* key cache */
2234
1153
extern "C" int ha_init_key_cache(const char *name, KEY_CACHE *key_cache);
2238
1157
int ha_end_key_cache(KEY_CACHE *key_cache);
2239
1158
 
2240
1159
/* report to InnoDB that control passes to the client */
2241
 
int ha_release_temporary_latches(THD *thd);
 
1160
int ha_release_temporary_latches(Session *session);
2242
1161
 
2243
 
/* transactions: interface to handlerton functions */
2244
 
int ha_start_consistent_snapshot(THD *thd);
 
1162
/* transactions: interface to StorageEngine functions */
 
1163
int ha_start_consistent_snapshot(Session *session);
2245
1164
int ha_commit_or_rollback_by_xid(XID *xid, bool commit);
2246
 
int ha_commit_one_phase(THD *thd, bool all);
2247
 
int ha_rollback_trans(THD *thd, bool all);
2248
 
int ha_prepare(THD *thd);
 
1165
int ha_commit_one_phase(Session *session, bool all);
 
1166
int ha_rollback_trans(Session *session, bool all);
 
1167
int ha_prepare(Session *session);
2249
1168
int ha_recover(HASH *commit_list);
2250
1169
 
2251
 
/* transactions: these functions never call handlerton functions directly */
2252
 
int ha_commit_trans(THD *thd, bool all);
2253
 
int ha_autocommit_or_rollback(THD *thd, int error);
2254
 
int ha_enable_transaction(THD *thd, bool on);
 
1170
/* transactions: these functions never call StorageEngine functions directly */
 
1171
int ha_commit_trans(Session *session, bool all);
 
1172
int ha_autocommit_or_rollback(Session *session, int error);
 
1173
int ha_enable_transaction(Session *session, bool on);
2255
1174
 
2256
1175
/* savepoints */
2257
 
int ha_rollback_to_savepoint(THD *thd, SAVEPOINT *sv);
2258
 
int ha_savepoint(THD *thd, SAVEPOINT *sv);
2259
 
int ha_release_savepoint(THD *thd, SAVEPOINT *sv);
 
1176
int ha_rollback_to_savepoint(Session *session, SAVEPOINT *sv);
 
1177
int ha_savepoint(Session *session, SAVEPOINT *sv);
 
1178
int ha_release_savepoint(Session *session, SAVEPOINT *sv);
2260
1179
 
2261
1180
/* these are called by storage engines */
2262
 
void trans_register_ha(THD *thd, bool all, handlerton *ht);
 
1181
void trans_register_ha(Session *session, bool all, StorageEngine *engine);
 
1182
 
 
1183
void table_case_convert(char * name, uint32_t length);
 
1184
const char *table_case_name(HA_CREATE_INFO *info, const char *name);
 
1185
 
 
1186
extern ulong specialflag;
 
1187
extern uint32_t lower_case_table_names;
 
1188
uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length);
 
1189
uint32_t tablename_to_filename(const char *from, char *to, uint32_t to_length);
 
1190
 
 
1191
 
 
1192
bool mysql_ha_open(Session *session, TableList *tables, bool reopen);
 
1193
bool mysql_ha_close(Session *session, TableList *tables);
 
1194
bool mysql_ha_read(Session *, TableList *,enum enum_ha_read_modes,char *,
 
1195
                   List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows);
 
1196
void mysql_ha_flush(Session *session);
 
1197
void mysql_ha_rm_tables(Session *session, TableList *tables, bool is_locked);
 
1198
void mysql_ha_cleanup(Session *session);
2263
1199
 
2264
1200
/*
2265
1201
  Storage engine has to assume the transaction will end up with 2pc if
2266
1202
   - there is more than one 2pc-capable storage engine available
2267
1203
   - in the current transaction 2pc was not disabled yet
2268
1204
*/
2269
 
#define trans_need_2pc(thd, all)                   ((total_ha_2pc > 1) && \
2270
 
        !((all ? &thd->transaction.all : &thd->transaction.stmt)->no_2pc))
 
1205
#define trans_need_2pc(session, all)                   ((total_ha_2pc > 1) && \
 
1206
        !((all ? &session->transaction.all : &session->transaction.stmt)->no_2pc))
 
1207
 
 
1208
 
 
1209
bool mysql_xa_recover(Session *session);
 
1210
 
 
1211
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
 
1212
                                   SORT_FIELD *sortorder);
 
1213
int setup_order(Session *session, Item **ref_pointer_array, TableList *tables,
 
1214
                List<Item> &fields, List <Item> &all_fields, order_st *order);
 
1215
int setup_group(Session *session, Item **ref_pointer_array, TableList *tables,
 
1216
                List<Item> &fields, List<Item> &all_fields, order_st *order,
 
1217
                bool *hidden_group_fields);
 
1218
bool fix_inner_refs(Session *session, List<Item> &all_fields, Select_Lex *select,
 
1219
                    Item **ref_pointer_array);
 
1220
 
 
1221
bool handle_select(Session *session, LEX *lex, select_result *result,
 
1222
                   uint64_t setup_tables_done_option);
 
1223
bool mysql_select(Session *session, Item ***rref_pointer_array,
 
1224
                  TableList *tables, uint32_t wild_num,  List<Item> &list,
 
1225
                  COND *conds, uint32_t og_num, order_st *order, order_st *group,
 
1226
                  Item *having, uint64_t select_type,
 
1227
                  select_result *result, Select_Lex_Unit *unit,
 
1228
                  Select_Lex *select_lex);
 
1229
void free_underlaid_joins(Session *session, Select_Lex *select);
 
1230
bool mysql_explain_union(Session *session, Select_Lex_Unit *unit,
 
1231
                         select_result *result);
 
1232
int mysql_explain_select(Session *session, Select_Lex *sl, char const *type,
 
1233
                         select_result *result);
 
1234
bool mysql_union(Session *session, LEX *lex, select_result *result,
 
1235
                 Select_Lex_Unit *unit, uint64_t setup_tables_done_option);
 
1236
bool mysql_handle_derived(LEX *lex, bool (*processor)(Session *session,
 
1237
                                                      LEX *lex,
 
1238
                                                      TableList *table));
 
1239
bool mysql_derived_prepare(Session *session, LEX *lex, TableList *t);
 
1240
bool mysql_derived_filling(Session *session, LEX *lex, TableList *t);
 
1241
void sp_prepare_create_field(Session *session, Create_field *sql_field);
 
1242
int prepare_create_field(Create_field *sql_field,
 
1243
                         uint32_t *blob_columns,
 
1244
                         int *timestamps, int *timestamps_with_niladic,
 
1245
                         int64_t table_flags);
 
1246
bool mysql_create_table(Session *session,const char *db, const char *table_name,
 
1247
                        HA_CREATE_INFO *create_info,
 
1248
                        Alter_info *alter_info,
 
1249
                        bool tmp_table, uint32_t select_field_count);
 
1250
bool mysql_create_table_no_lock(Session *session, const char *db,
 
1251
                                const char *table_name,
 
1252
                                HA_CREATE_INFO *create_info,
 
1253
                                Alter_info *alter_info,
 
1254
                                bool tmp_table, uint32_t select_field_count,
 
1255
                                bool lock_open_lock);
 
1256
 
 
1257
bool mysql_alter_table(Session *session, char *new_db, char *new_name,
 
1258
                       HA_CREATE_INFO *create_info,
 
1259
                       TableList *table_list,
 
1260
                       Alter_info *alter_info,
 
1261
                       uint32_t order_num, order_st *order, bool ignore);
 
1262
bool mysql_recreate_table(Session *session, TableList *table_list);
 
1263
bool mysql_create_like_table(Session *session, TableList *table,
 
1264
                             TableList *src_table,
 
1265
                             HA_CREATE_INFO *create_info);
 
1266
bool mysql_rename_table(StorageEngine *base, const char *old_db,
 
1267
                        const char * old_name, const char *new_db,
 
1268
                        const char * new_name, uint32_t flags);
 
1269
bool mysql_prepare_update(Session *session, TableList *table_list,
 
1270
                          Item **conds, uint32_t order_num, order_st *order);
 
1271
int mysql_update(Session *session,TableList *tables,List<Item> &fields,
 
1272
                 List<Item> &values,COND *conds,
 
1273
                 uint32_t order_num, order_st *order, ha_rows limit,
 
1274
                 enum enum_duplicates handle_duplicates, bool ignore);
 
1275
bool mysql_multi_update(Session *session, TableList *table_list,
 
1276
                        List<Item> *fields, List<Item> *values,
 
1277
                        COND *conds, uint64_t options,
 
1278
                        enum enum_duplicates handle_duplicates, bool ignore,
 
1279
                        Select_Lex_Unit *unit, Select_Lex *select_lex);
 
1280
bool mysql_prepare_insert(Session *session, TableList *table_list, Table *table,
 
1281
                          List<Item> &fields, List_item *values,
 
1282
                          List<Item> &update_fields,
 
1283
                          List<Item> &update_values, enum_duplicates duplic,
 
1284
                          COND **where, bool select_insert,
 
1285
                          bool check_fields, bool abort_on_warning);
 
1286
bool mysql_insert(Session *session,TableList *table,List<Item> &fields,
 
1287
                  List<List_item> &values, List<Item> &update_fields,
 
1288
                  List<Item> &update_values, enum_duplicates flag,
 
1289
                  bool ignore);
 
1290
int check_that_all_fields_are_given_values(Session *session, Table *entry,
 
1291
                                           TableList *table_list);
 
1292
int mysql_prepare_delete(Session *session, TableList *table_list, Item **conds);
 
1293
bool mysql_delete(Session *session, TableList *table_list, COND *conds,
 
1294
                  SQL_LIST *order, ha_rows rows, uint64_t options,
 
1295
                  bool reset_auto_increment);
 
1296
bool mysql_truncate(Session *session, TableList *table_list, bool dont_send_ok);
 
1297
uint32_t create_table_def_key(Session *session, char *key, TableList *table_list,
 
1298
                              bool tmp_table);
 
1299
TABLE_SHARE *get_table_share(Session *session, TableList *table_list, char *key,
 
1300
                             uint32_t key_length, uint32_t db_flags, int *error);
 
1301
void release_table_share(TABLE_SHARE *share, enum release_type type);
 
1302
TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name);
 
1303
Table *open_ltable(Session *session, TableList *table_list, thr_lock_type update,
 
1304
                   uint32_t lock_flags);
 
1305
Table *open_table(Session *session, TableList *table_list, bool *refresh, uint32_t flags);
 
1306
bool name_lock_locked_table(Session *session, TableList *tables);
 
1307
bool reopen_name_locked_table(Session* session, TableList* table_list, bool link_in);
 
1308
Table *table_cache_insert_placeholder(Session *session, const char *key,
 
1309
                                      uint32_t key_length);
 
1310
bool lock_table_name_if_not_cached(Session *session, const char *db,
 
1311
                                   const char *table_name, Table **table);
 
1312
Table *find_locked_table(Session *session, const char *db,const char *table_name);
 
1313
void detach_merge_children(Table *table, bool clear_refs);
 
1314
bool fix_merge_after_open(TableList *old_child_list, TableList **old_last,
 
1315
                          TableList *new_child_list, TableList **new_last);
 
1316
bool reopen_table(Table *table);
 
1317
bool reopen_tables(Session *session,bool get_locks,bool in_refresh);
 
1318
void close_data_files_and_morph_locks(Session *session, const char *db,
 
1319
                                      const char *table_name);
 
1320
void close_handle_and_leave_table_as_lock(Table *table);
 
1321
bool open_new_frm(Session *session, TABLE_SHARE *share, const char *alias,
 
1322
                  uint32_t db_stat, uint32_t prgflag,
 
1323
                  uint32_t ha_open_flags, Table *outparam,
 
1324
                  TableList *table_desc, MEM_ROOT *mem_root);
 
1325
bool wait_for_tables(Session *session);
 
1326
bool table_is_used(Table *table, bool wait_for_name_lock);
 
1327
Table *drop_locked_tables(Session *session,const char *db, const char *table_name);
 
1328
void abort_locked_tables(Session *session,const char *db, const char *table_name);
 
1329
extern Field *not_found_field;
 
1330
extern Field *view_ref_found;
 
1331
 
 
1332
Field *
 
1333
find_field_in_tables(Session *session, Item_ident *item,
 
1334
                     TableList *first_table, TableList *last_table,
 
1335
                     Item **ref, find_item_error_report_type report_error,
 
1336
                     bool check_privileges, bool register_tree_change);
 
1337
Field *
 
1338
find_field_in_table_ref(Session *session, TableList *table_list,
 
1339
                        const char *name, uint32_t length,
 
1340
                        const char *item_name, const char *db_name,
 
1341
                        const char *table_name, Item **ref,
 
1342
                        bool check_privileges, bool allow_rowid,
 
1343
                        uint32_t *cached_field_index_ptr,
 
1344
                        bool register_tree_change, TableList **actual_table);
 
1345
Field *
 
1346
find_field_in_table(Session *session, Table *table, const char *name, uint32_t length,
 
1347
                    bool allow_rowid, uint32_t *cached_field_index_ptr);
 
1348
Field *
 
1349
find_field_in_table_sef(Table *table, const char *name);
 
1350
int update_virtual_fields_marked_for_write(Table *table,
 
1351
                                           bool ignore_stored=true);
 
1352
 
 
1353
 
 
1354
#endif /* DRIZZLED_HANDLER_H */