~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/handler.h

  • Committer: Brian Aker
  • Date: 2008-09-04 19:31:00 UTC
  • Revision ID: brian@tangent.org-20080904193100-l849hgghfy4urj43
Changing default character set from this point on.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
20
 
#ifndef DRIZZLED_HANDLER_H
21
 
#define DRIZZLED_HANDLER_H
22
 
 
23
 
#include <drizzled/xid.h>
 
1
/* Copyright (C) 2000-2006 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
24
16
 
25
17
/* Definitions for parameters to do with handler-routines */
26
18
 
 
19
#ifdef USE_PRAGMA_INTERFACE
 
20
#pragma interface                       /* gcc class implementation */
 
21
#endif
 
22
 
 
23
#include <mysys/my_handler.h>
27
24
#include <storage/myisam/keycache.h>
28
 
#include <mysys/thr_lock.h>
29
 
#include <mysys/hash.h>
30
 
#include <drizzled/sql_string.h>
31
 
#include <drizzled/sql_list.h>
 
25
 
 
26
#ifndef NO_HASH
 
27
#define NO_HASH                         /* Not yet implemented */
 
28
#endif
 
29
 
 
30
// the following is for checking tables
 
31
 
 
32
#define HA_ADMIN_ALREADY_DONE     1
 
33
#define HA_ADMIN_OK               0
 
34
#define HA_ADMIN_NOT_IMPLEMENTED -1
 
35
#define HA_ADMIN_FAILED          -2
 
36
#define HA_ADMIN_CORRUPT         -3
 
37
#define HA_ADMIN_INTERNAL_ERROR  -4
 
38
#define HA_ADMIN_INVALID         -5
 
39
#define HA_ADMIN_REJECT          -6
 
40
#define HA_ADMIN_TRY_ALTER       -7
 
41
#define HA_ADMIN_WRONG_CHECKSUM  -8
 
42
#define HA_ADMIN_NOT_BASE_TABLE  -9
 
43
#define HA_ADMIN_NEEDS_UPGRADE  -10
 
44
#define HA_ADMIN_NEEDS_ALTER    -11
 
45
#define HA_ADMIN_NEEDS_CHECK    -12
32
46
 
33
47
/* Bits to show what an alter table will do */
34
48
#include <drizzled/sql_bitmap.h>
35
49
 
36
 
#define HA_MAX_ALTER_FLAGS 40
 
50
#define HA_MAX_ALTER_FLAGS 39
37
51
typedef Bitmap<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
38
52
 
39
 
 
40
 
typedef bool (*qc_engine_callback)(Session *session, char *table_key,
41
 
                                      uint32_t key_length,
 
53
#define HA_ADD_INDEX                  (0)
 
54
#define HA_DROP_INDEX                 (1)
 
55
#define HA_ALTER_INDEX                (2)
 
56
#define HA_RENAME_INDEX               (3)
 
57
#define HA_ADD_UNIQUE_INDEX           (4)
 
58
#define HA_DROP_UNIQUE_INDEX          (5)
 
59
#define HA_ALTER_UNIQUE_INDEX         (6)
 
60
#define HA_RENAME_UNIQUE_INDEX        (7)
 
61
#define HA_ADD_PK_INDEX               (8)
 
62
#define HA_DROP_PK_INDEX              (9)
 
63
#define HA_ALTER_PK_INDEX             (10)
 
64
#define HA_ADD_COLUMN                 (11)
 
65
#define HA_DROP_COLUMN                (12)
 
66
#define HA_CHANGE_COLUMN              (13)
 
67
#define HA_ALTER_COLUMN_NAME          (14)
 
68
#define HA_ALTER_COLUMN_TYPE          (15)
 
69
#define HA_ALTER_COLUMN_ORDER         (16)
 
70
#define HA_ALTER_COLUMN_NULLABLE      (17)
 
71
#define HA_COLUMN_DEFAULT_VALUE       (18)
 
72
#define HA_COLUMN_STORAGE             (19)
 
73
#define HA_COLUMN_FORMAT              (20)
 
74
#define HA_ADD_FOREIGN_KEY            (21)
 
75
#define HA_DROP_FOREIGN_KEY           (22)
 
76
#define HA_ALTER_FOREIGN_KEY          (23)
 
77
#define HA_ADD_CONSTRAINT             (24)
 
78
#define HA_CHANGE_CHARACTER_SET       (30)
 
79
#define HA_SET_DEFAULT_CHARACTER_SET  (31)
 
80
#define HA_CHANGE_AUTOINCREMENT_VALUE (32)
 
81
#define HA_ALTER_STORAGE              (33)
 
82
#define HA_ALTER_TABLESPACE           (34)
 
83
#define HA_ALTER_ROW_FORMAT           (35)
 
84
#define HA_RENAME_TABLE               (36)
 
85
#define HA_ALTER_STORAGE_ENGINE       (37)
 
86
#define HA_RECREATE                   (38)
 
87
/* Remember to increase HA_MAX_ALTER_FLAGS when adding more flags! */
 
88
 
 
89
/* Return values for check_if_supported_alter */
 
90
 
 
91
#define HA_ALTER_ERROR               -1
 
92
#define HA_ALTER_SUPPORTED_WAIT_LOCK  0
 
93
#define HA_ALTER_SUPPORTED_NO_LOCK    1
 
94
#define HA_ALTER_NOT_SUPPORTED        2
 
95
 
 
96
/* Bits in table_flags() to show what database can do */
 
97
 
 
98
#define HA_NO_TRANSACTIONS     (1 << 0) /* Doesn't support transactions */
 
99
#define HA_PARTIAL_COLUMN_READ (1 << 1) /* read may not return all columns */
 
100
#define HA_TABLE_SCAN_ON_INDEX (1 << 2) /* No separate data/index file */
 
101
/*
 
102
  The following should be set if the following is not true when scanning
 
103
  a table with rnd_next()
 
104
  - We will see all rows (including deleted ones)
 
105
  - Row positions are 'table->s->db_record_offset' apart
 
106
  If this flag is not set, filesort will do a postion() call for each matched
 
107
  row to be able to find the row later.
 
108
*/
 
109
#define HA_REC_NOT_IN_SEQ      (1 << 3)
 
110
/* This is now a dead option, just left for compatibility */
 
111
#define HA_CAN_GEOMETRY        (1 << 4)
 
112
/*
 
113
  Reading keys in random order is as fast as reading keys in sort order
 
114
  (Used in records.cc to decide if we should use a record cache and by
 
115
  filesort to decide if we should sort key + data or key + pointer-to-row
 
116
*/
 
117
#define HA_FAST_KEY_READ       (1 << 5)
 
118
/*
 
119
  Set the following flag if we on delete should force all key to be read
 
120
  and on update read all keys that changes
 
121
*/
 
122
#define HA_REQUIRES_KEY_COLUMNS_FOR_DELETE (1 << 6)
 
123
#define HA_NULL_IN_KEY         (1 << 7) /* One can have keys with NULL */
 
124
#define HA_DUPLICATE_POS       (1 << 8)    /* ha_position() gives dup row */
 
125
#define HA_NO_BLOBS            (1 << 9) /* Doesn't support blobs */
 
126
#define HA_CAN_INDEX_BLOBS     (1 << 10)
 
127
#define HA_AUTO_PART_KEY       (1 << 11) /* auto-increment in multi-part key */
 
128
#define HA_REQUIRE_PRIMARY_KEY (1 << 12) /* .. and can't create a hidden one */
 
129
#define HA_STATS_RECORDS_IS_EXACT (1 << 13) /* stats.records is exact */
 
130
/*
 
131
  INSERT_DELAYED only works with handlers that uses MySQL internal table
 
132
  level locks
 
133
*/
 
134
#define HA_CAN_INSERT_DELAYED  (1 << 14)
 
135
/*
 
136
  If we get the primary key columns for free when we do an index read
 
137
  It also implies that we have to retrive the primary key when using
 
138
  position() and rnd_pos().
 
139
*/
 
140
#define HA_PRIMARY_KEY_IN_READ_INDEX (1 << 15)
 
141
/*
 
142
  If HA_PRIMARY_KEY_REQUIRED_FOR_POSITION is set, it means that to position()
 
143
  uses a primary key. Without primary key, we can't call position().
 
144
*/ 
 
145
#define HA_PRIMARY_KEY_REQUIRED_FOR_POSITION (1 << 16) 
 
146
#define HA_CAN_RTREEKEYS       (1 << 17) /* Historical, no longer supported */
 
147
#define HA_NOT_DELETE_WITH_CACHE (1 << 18)
 
148
/*
 
149
  The following is we need to a primary key to delete (and update) a row.
 
150
  If there is no primary key, all columns needs to be read on update and delete
 
151
*/
 
152
#define HA_PRIMARY_KEY_REQUIRED_FOR_DELETE (1 << 19)
 
153
#define HA_NO_PREFIX_CHAR_KEYS (1 << 20)
 
154
#define HA_CAN_FULLTEXT        (1 << 21) /* Historical, no longer supported */
 
155
#define HA_CAN_SQL_HANDLER     (1 << 22) /* Historical, no longer supported */
 
156
#define HA_NO_AUTO_INCREMENT   (1 << 23)
 
157
#define HA_HAS_CHECKSUM        (1 << 24)
 
158
/* Table data are stored in separate files (for lower_case_table_names) */
 
159
#define HA_FILE_BASED          (1 << 26)
 
160
#define HA_NO_VARCHAR          (1 << 27) /* Historical, no longer supported */
 
161
#define HA_CAN_BIT_FIELD       (1 << 28) /* Historical, no longer supported */
 
162
#define HA_NEED_READ_RANGE_BUFFER (1 << 29) /* for read_multi_range */
 
163
#define HA_ANY_INDEX_MAY_BE_UNIQUE (1 << 30)
 
164
#define HA_NO_COPY_ON_ALTER    (1LL << 31)
 
165
#define HA_HAS_RECORDS         (1LL << 32) /* records() gives exact count*/
 
166
/* Has it's own method of binlog logging */
 
167
#define HA_HAS_OWN_BINLOGGING  (1LL << 33) /* Historical, no longer supported */
 
168
#define HA_MRR_CANT_SORT       (1LL << 34)
 
169
 
 
170
/*
 
171
  Engine is capable of row-format and statement-format logging,
 
172
  respectively
 
173
*/
 
174
#define HA_BINLOG_ROW_CAPABLE  (1LL << 35)
 
175
#define HA_BINLOG_STMT_CAPABLE (1LL << 36)
 
176
 
 
177
#define HA_ONLINE_ALTER        (1LL << 37)
 
178
 
 
179
/*
 
180
  Set of all binlog flags. Currently only contain the capabilities
 
181
  flags.
 
182
 */
 
183
#define HA_BINLOG_FLAGS (HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE)
 
184
 
 
185
/* bits in index_flags(index_number) for what you can do with index */
 
186
#define HA_READ_NEXT            1       /* TODO really use this flag */
 
187
#define HA_READ_PREV            2       /* supports ::index_prev */
 
188
#define HA_READ_ORDER           4       /* index_next/prev follow sort order */
 
189
#define HA_READ_RANGE           8       /* can find all records in a range */
 
190
#define HA_ONLY_WHOLE_INDEX     16      /* Can't use part key searches */
 
191
#define HA_KEYREAD_ONLY         64      /* Support HA_EXTRA_KEYREAD */
 
192
/*
 
193
  Index scan will not return records in rowid order. Not guaranteed to be
 
194
  set for unordered (e.g. HASH) indexes.
 
195
*/
 
196
#define HA_KEY_SCAN_NOT_ROR     128 
 
197
#define HA_DO_INDEX_COND_PUSHDOWN  256 /* Supports Index Condition Pushdown */
 
198
 
 
199
 
 
200
 
 
201
/*
 
202
  HA_PARTITION_FUNCTION_SUPPORTED indicates that the function is
 
203
  supported at all.
 
204
  HA_FAST_CHANGE_PARTITION means that optimised variants of the changes
 
205
  exists but they are not necessarily done online.
 
206
 
 
207
  HA_ONLINE_DOUBLE_WRITE means that the handler supports writing to both
 
208
  the new partition and to the old partitions when updating through the
 
209
  old partitioning schema while performing a change of the partitioning.
 
210
  This means that we can support updating of the table while performing
 
211
  the copy phase of the change. For no lock at all also a double write
 
212
  from new to old must exist and this is not required when this flag is
 
213
  set.
 
214
  This is actually removed even before it was introduced the first time.
 
215
  The new idea is that handlers will handle the lock level already in
 
216
  store_lock for ALTER Table partitions.
 
217
 
 
218
  HA_PARTITION_ONE_PHASE is a flag that can be set by handlers that take
 
219
  care of changing the partitions online and in one phase. Thus all phases
 
220
  needed to handle the change are implemented inside the storage engine.
 
221
  The storage engine must also support auto-discovery since the frm file
 
222
  is changed as part of the change and this change must be controlled by
 
223
  the storage engine. A typical engine to support this is NDB (through
 
224
  WL #2498).
 
225
*/
 
226
#define HA_PARTITION_FUNCTION_SUPPORTED         (1L << 1)
 
227
#define HA_FAST_CHANGE_PARTITION                (1L << 2)
 
228
#define HA_PARTITION_ONE_PHASE                  (1L << 3)
 
229
 
 
230
/* operations for disable/enable indexes */
 
231
#define HA_KEY_SWITCH_NONUNIQ      0
 
232
#define HA_KEY_SWITCH_ALL          1
 
233
#define HA_KEY_SWITCH_NONUNIQ_SAVE 2
 
234
#define HA_KEY_SWITCH_ALL_SAVE     3
 
235
 
 
236
/*
 
237
  Note: the following includes binlog and closing 0.
 
238
  so: innodb + bdb + ndb + binlog + myisam + myisammrg + archive +
 
239
      example + csv + heap + blackhole + federated + 0
 
240
  (yes, the sum is deliberately inaccurate)
 
241
  TODO remove the limit, use dynarrays
 
242
*/
 
243
#define MAX_HA 15
 
244
 
 
245
/*
 
246
  Parameters for open() (in register form->filestat)
 
247
  HA_GET_INFO does an implicit HA_ABORT_IF_LOCKED
 
248
*/
 
249
 
 
250
#define HA_OPEN_KEYFILE         1
 
251
#define HA_OPEN_RNDFILE         2
 
252
#define HA_GET_INDEX            4
 
253
#define HA_GET_INFO             8       /* do a ha_info() after open */
 
254
#define HA_READ_ONLY            16      /* File opened as readonly */
 
255
/* Try readonly if can't open with read and write */
 
256
#define HA_TRY_READ_ONLY        32
 
257
#define HA_WAIT_IF_LOCKED       64      /* Wait if locked on open */
 
258
#define HA_ABORT_IF_LOCKED      128     /* skip if locked on open.*/
 
259
#define HA_BLOCK_LOCK           256     /* unlock when reading some records */
 
260
#define HA_OPEN_TEMPORARY       512
 
261
 
 
262
/* For transactional LOCK Table. handler::lock_table() */
 
263
#define HA_LOCK_IN_SHARE_MODE      F_RDLCK
 
264
#define HA_LOCK_IN_EXCLUSIVE_MODE  F_WRLCK
 
265
 
 
266
/* Some key definitions */
 
267
#define HA_KEY_NULL_LENGTH      1
 
268
#define HA_KEY_BLOB_LENGTH      2
 
269
 
 
270
#define HA_LEX_CREATE_TMP_TABLE 1
 
271
#define HA_LEX_CREATE_IF_NOT_EXISTS 2
 
272
#define HA_LEX_CREATE_TABLE_LIKE 4
 
273
#define HA_OPTION_NO_CHECKSUM   (1L << 17)
 
274
#define HA_OPTION_NO_DELAY_KEY_WRITE (1L << 18)
 
275
#define HA_MAX_REC_LENGTH       65535
 
276
 
 
277
/* Table caching type */
 
278
#define HA_CACHE_TBL_NONTRANSACT 0
 
279
#define HA_CACHE_TBL_NOCACHE     1
 
280
#define HA_CACHE_TBL_ASKTRANSACT 2
 
281
#define HA_CACHE_TBL_TRANSACT    4
 
282
 
 
283
/* Options of START TRANSACTION statement (and later of SET TRANSACTION stmt) */
 
284
#define DRIZZLE_START_TRANS_OPT_WITH_CONS_SNAPSHOT 1
 
285
 
 
286
/* Flags for method is_fatal_error */
 
287
#define HA_CHECK_DUP_KEY 1
 
288
#define HA_CHECK_DUP_UNIQUE 2
 
289
#define HA_CHECK_DUP (HA_CHECK_DUP_KEY + HA_CHECK_DUP_UNIQUE)
 
290
 
 
291
enum legacy_db_type
 
292
{
 
293
  DB_TYPE_UNKNOWN=0,DB_TYPE_DIAB_ISAM=1,
 
294
  DB_TYPE_HASH,DB_TYPE_MISAM,DB_TYPE_PISAM,
 
295
  DB_TYPE_RMS_ISAM, DB_TYPE_HEAP, DB_TYPE_ISAM,
 
296
  DB_TYPE_MRG_ISAM, DB_TYPE_MYISAM, DB_TYPE_MRG_MYISAM,
 
297
  DB_TYPE_BERKELEY_DB, DB_TYPE_INNODB,
 
298
  DB_TYPE_GEMINI, DB_TYPE_NDBCLUSTER,
 
299
  DB_TYPE_EXAMPLE_DB, DB_TYPE_ARCHIVE_DB, DB_TYPE_CSV_DB,
 
300
  DB_TYPE_FEDERATED_DB,
 
301
  DB_TYPE_BLACKHOLE_DB,
 
302
  DB_TYPE_PARTITION_DB,
 
303
  DB_TYPE_BINLOG,
 
304
  DB_TYPE_SOLID,
 
305
  DB_TYPE_PBXT,
 
306
  DB_TYPE_TABLE_FUNCTION,
 
307
  DB_TYPE_MEMCACHE,
 
308
  DB_TYPE_FALCON,
 
309
  DB_TYPE_MARIA,
 
310
  DB_TYPE_FIRST_DYNAMIC=42,
 
311
  DB_TYPE_DEFAULT=127 // Must be last
 
312
};
 
313
 
 
314
enum row_type { ROW_TYPE_NOT_USED=-1, ROW_TYPE_DEFAULT, ROW_TYPE_FIXED,
 
315
                ROW_TYPE_DYNAMIC, ROW_TYPE_COMPRESSED,
 
316
                ROW_TYPE_REDUNDANT, ROW_TYPE_COMPACT, ROW_TYPE_PAGE };
 
317
 
 
318
enum column_format_type { COLUMN_FORMAT_TYPE_NOT_USED= -1,
 
319
                          COLUMN_FORMAT_TYPE_DEFAULT=   0,
 
320
                          COLUMN_FORMAT_TYPE_FIXED=     1,
 
321
                          COLUMN_FORMAT_TYPE_DYNAMIC=   2 };
 
322
 
 
323
enum enum_binlog_func {
 
324
  BFN_RESET_LOGS=        1,
 
325
  BFN_RESET_SLAVE=       2,
 
326
  BFN_BINLOG_WAIT=       3,
 
327
  BFN_BINLOG_END=        4,
 
328
  BFN_BINLOG_PURGE_FILE= 5
 
329
};
 
330
 
 
331
enum enum_binlog_command {
 
332
  LOGCOM_CREATE_TABLE,
 
333
  LOGCOM_ALTER_TABLE,
 
334
  LOGCOM_RENAME_TABLE,
 
335
  LOGCOM_DROP_TABLE,
 
336
  LOGCOM_CREATE_DB,
 
337
  LOGCOM_ALTER_DB,
 
338
  LOGCOM_DROP_DB
 
339
};
 
340
 
 
341
/* struct to hold information about the table that should be created */
 
342
 
 
343
/* Bits in used_fields */
 
344
#define HA_CREATE_USED_AUTO             (1L << 0)
 
345
#ifdef DEAD_OPTIONS
 
346
#define HA_CREATE_USED_RAID             (1L << 1) /* Historical, no longer supported */
 
347
#define HA_CREATE_USED_UNION            (1L << 2)
 
348
#define HA_CREATE_USED_PASSWORD         (1L << 17)
 
349
#endif
 
350
#define HA_CREATE_USED_INSERT_METHOD    (1L << 3)
 
351
#define HA_CREATE_USED_MIN_ROWS         (1L << 4)
 
352
#define HA_CREATE_USED_MAX_ROWS         (1L << 5)
 
353
#define HA_CREATE_USED_AVG_ROW_LENGTH   (1L << 6)
 
354
#define HA_CREATE_USED_PACK_KEYS        (1L << 7)
 
355
#define HA_CREATE_USED_CHARSET          (1L << 8)
 
356
#define HA_CREATE_USED_DEFAULT_CHARSET  (1L << 9)
 
357
#define HA_CREATE_USED_DATADIR          (1L << 10)
 
358
#define HA_CREATE_USED_INDEXDIR         (1L << 11)
 
359
#define HA_CREATE_USED_ENGINE           (1L << 12)
 
360
#define HA_CREATE_USED_CHECKSUM         (1L << 13)
 
361
#define HA_CREATE_USED_DELAY_KEY_WRITE  (1L << 14)
 
362
#define HA_CREATE_USED_ROW_FORMAT       (1L << 15)
 
363
#define HA_CREATE_USED_COMMENT          (1L << 16)
 
364
#define HA_CREATE_USED_CONNECTION       (1L << 18)
 
365
#define HA_CREATE_USED_KEY_BLOCK_SIZE   (1L << 19)
 
366
#define HA_CREATE_USED_TRANSACTIONAL    (1L << 20)
 
367
#define HA_CREATE_USED_PAGE_CHECKSUM    (1L << 21)
 
368
#define HA_CREATE_USED_BLOCK_SIZE       (1L << 22)
 
369
 
 
370
typedef uint64_t my_xid; // this line is the same as in log_event.h
 
371
#define DRIZZLE_XID_PREFIX "MySQLXid"
 
372
#define DRIZZLE_XID_PREFIX_LEN 8 // must be a multiple of 8
 
373
#define DRIZZLE_XID_OFFSET (DRIZZLE_XID_PREFIX_LEN+sizeof(server_id))
 
374
#define DRIZZLE_XID_GTRID_LEN (DRIZZLE_XID_OFFSET+sizeof(my_xid))
 
375
 
 
376
#define XIDDATASIZE DRIZZLE_XIDDATASIZE
 
377
#define MAXGTRIDSIZE 64
 
378
#define MAXBQUALSIZE 64
 
379
 
 
380
#define COMPATIBLE_DATA_YES 0
 
381
#define COMPATIBLE_DATA_NO  1
 
382
 
 
383
typedef bool (*qc_engine_callback)(THD *thd, char *table_key,
 
384
                                      uint key_length,
42
385
                                      uint64_t *engine_data);
43
386
 
 
387
/**
 
388
  struct xid_t is binary compatible with the XID structure as
 
389
  in the X/Open CAE Specification, Distributed Transaction Processing:
 
390
  The XA Specification, X/Open Company Ltd., 1991.
 
391
  http://www.opengroup.org/bookstore/catalog/c193.htm
 
392
 
 
393
  @see DRIZZLE_XID in mysql/plugin.h
 
394
*/
 
395
struct xid_t {
 
396
  long formatID;
 
397
  long gtrid_length;
 
398
  long bqual_length;
 
399
  char data[XIDDATASIZE];  // not \0-terminated !
 
400
 
 
401
  xid_t() {}                                /* Remove gcc warning */  
 
402
  bool eq(struct xid_t *xid)
 
403
  { return eq(xid->gtrid_length, xid->bqual_length, xid->data); }
 
404
  bool eq(long g, long b, const char *d)
 
405
  { return g == gtrid_length && b == bqual_length && !memcmp(d, data, g+b); }
 
406
  void set(struct xid_t *xid)
 
407
  { memcpy(this, xid, xid->length()); }
 
408
  void set(long f, const char *g, long gl, const char *b, long bl)
 
409
  {
 
410
    formatID= f;
 
411
    memcpy(data, g, gtrid_length= gl);
 
412
    memcpy(data+gl, b, bqual_length= bl);
 
413
  }
 
414
  void set(uint64_t xid)
 
415
  {
 
416
    my_xid tmp;
 
417
    formatID= 1;
 
418
    set(DRIZZLE_XID_PREFIX_LEN, 0, DRIZZLE_XID_PREFIX);
 
419
    memcpy(data+DRIZZLE_XID_PREFIX_LEN, &server_id, sizeof(server_id));
 
420
    tmp= xid;
 
421
    memcpy(data+DRIZZLE_XID_OFFSET, &tmp, sizeof(tmp));
 
422
    gtrid_length=DRIZZLE_XID_GTRID_LEN;
 
423
  }
 
424
  void set(long g, long b, const char *d)
 
425
  {
 
426
    formatID= 1;
 
427
    gtrid_length= g;
 
428
    bqual_length= b;
 
429
    memcpy(data, d, g+b);
 
430
  }
 
431
  bool is_null() { return formatID == -1; }
 
432
  void null() { formatID= -1; }
 
433
  my_xid quick_get_my_xid()
 
434
  {
 
435
    my_xid tmp;
 
436
    memcpy(&tmp, data+DRIZZLE_XID_OFFSET, sizeof(tmp));
 
437
    return tmp;
 
438
  }
 
439
  my_xid get_my_xid()
 
440
  {
 
441
    return gtrid_length == DRIZZLE_XID_GTRID_LEN && bqual_length == 0 &&
 
442
           !memcmp(data+DRIZZLE_XID_PREFIX_LEN, &server_id, sizeof(server_id)) &&
 
443
           !memcmp(data, DRIZZLE_XID_PREFIX, DRIZZLE_XID_PREFIX_LEN) ?
 
444
           quick_get_my_xid() : 0;
 
445
  }
 
446
  uint length()
 
447
  {
 
448
    return sizeof(formatID)+sizeof(gtrid_length)+sizeof(bqual_length)+
 
449
           gtrid_length+bqual_length;
 
450
  }
 
451
  uchar *key()
 
452
  {
 
453
    return (uchar *)&gtrid_length;
 
454
  }
 
455
  uint key_length()
 
456
  {
 
457
    return sizeof(gtrid_length)+sizeof(bqual_length)+gtrid_length+bqual_length;
 
458
  }
 
459
};
 
460
typedef struct xid_t XID;
 
461
 
 
462
/* for recover() handlerton call */
 
463
#define MIN_XID_LIST_SIZE  128
 
464
#define MAX_XID_LIST_SIZE  (1024*128)
44
465
 
45
466
struct handlerton;
46
467
 
47
468
/* The handler for a table type.  Will be included in the Table structure */
48
469
 
49
470
class Table;
50
 
class TableList;
51
471
typedef struct st_table_share TABLE_SHARE;
52
472
struct st_foreign_key_info;
53
473
typedef struct st_foreign_key_info FOREIGN_KEY_INFO;
54
 
typedef bool (stat_print_fn)(Session *session, const char *type, uint32_t type_len,
55
 
                             const char *file, uint32_t file_len,
56
 
                             const char *status, uint32_t status_len);
 
474
typedef bool (stat_print_fn)(THD *thd, const char *type, uint type_len,
 
475
                             const char *file, uint file_len,
 
476
                             const char *status, uint status_len);
57
477
enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
58
478
extern st_plugin_int *hton2plugin[MAX_HA];
59
479
 
82
502
  enum legacy_db_type db_type;
83
503
  /*
84
504
    each storage engine has it's own memory area (actually a pointer)
85
 
    in the session, for storing per-connection information.
 
505
    in the thd, for storing per-connection information.
86
506
    It is accessed as
87
507
 
88
 
      session->ha_data[xxx_hton.slot]
 
508
      thd->ha_data[xxx_hton.slot]
89
509
 
90
510
   slot number is initialized by MySQL after xxx_init() is called.
91
511
   */
92
 
   uint32_t slot;
 
512
   uint slot;
93
513
   /*
94
514
     to store per-savepoint data storage engine is provided with an area
95
515
     of a requested size (0 is ok here).
99
519
     area and need not be used by storage engine.
100
520
     see binlog_hton and binlog_savepoint_set/rollback for an example.
101
521
   */
102
 
   uint32_t savepoint_offset;
 
522
   uint savepoint_offset;
103
523
   /*
104
524
     handlerton methods:
105
525
 
106
526
     close_connection is only called if
107
 
     session->ha_data[xxx_hton.slot] is non-zero, so even if you don't need
 
527
     thd->ha_data[xxx_hton.slot] is non-zero, so even if you don't need
108
528
     this storage area - set it to something, so that MySQL would know
109
529
     this storage engine was accessed in this connection
110
530
   */
111
 
   int  (*close_connection)(handlerton *hton, Session *session);
 
531
   int  (*close_connection)(handlerton *hton, THD *thd);
112
532
   /*
113
533
     sv points to an uninitialized storage area of requested size
114
534
     (see savepoint_offset description)
115
535
   */
116
 
   int  (*savepoint_set)(handlerton *hton, Session *session, void *sv);
 
536
   int  (*savepoint_set)(handlerton *hton, THD *thd, void *sv);
117
537
   /*
118
538
     sv points to a storage area, that was earlier passed
119
539
     to the savepoint_set call
120
540
   */
121
 
   int  (*savepoint_rollback)(handlerton *hton, Session *session, void *sv);
122
 
   int  (*savepoint_release)(handlerton *hton, Session *session, void *sv);
 
541
   int  (*savepoint_rollback)(handlerton *hton, THD *thd, void *sv);
 
542
   int  (*savepoint_release)(handlerton *hton, THD *thd, void *sv);
123
543
   /*
124
544
     'all' is true if it's a real commit, that makes persistent changes
125
545
     'all' is false if it's not in fact a commit but an end of the
127
547
     NOTE 'all' is also false in auto-commit mode where 'end of statement'
128
548
     and 'real commit' mean the same event.
129
549
   */
130
 
   int  (*commit)(handlerton *hton, Session *session, bool all);
131
 
   int  (*rollback)(handlerton *hton, Session *session, bool all);
132
 
   int  (*prepare)(handlerton *hton, Session *session, bool all);
133
 
   int  (*recover)(handlerton *hton, XID *xid_list, uint32_t len);
 
550
   int  (*commit)(handlerton *hton, THD *thd, bool all);
 
551
   int  (*rollback)(handlerton *hton, THD *thd, bool all);
 
552
   int  (*prepare)(handlerton *hton, THD *thd, bool all);
 
553
   int  (*recover)(handlerton *hton, XID *xid_list, uint len);
134
554
   int  (*commit_by_xid)(handlerton *hton, XID *xid);
135
555
   int  (*rollback_by_xid)(handlerton *hton, XID *xid);
136
 
   void *(*create_cursor_read_view)(handlerton *hton, Session *session);
137
 
   void (*set_cursor_read_view)(handlerton *hton, Session *session, void *read_view);
138
 
   void (*close_cursor_read_view)(handlerton *hton, Session *session, void *read_view);
 
556
   void *(*create_cursor_read_view)(handlerton *hton, THD *thd);
 
557
   void (*set_cursor_read_view)(handlerton *hton, THD *thd, void *read_view);
 
558
   void (*close_cursor_read_view)(handlerton *hton, THD *thd, void *read_view);
139
559
   handler *(*create)(handlerton *hton, TABLE_SHARE *table, MEM_ROOT *mem_root);
140
560
   void (*drop_database)(handlerton *hton, char* path);
141
 
   int (*start_consistent_snapshot)(handlerton *hton, Session *session);
 
561
   int (*start_consistent_snapshot)(handlerton *hton, THD *thd);
142
562
   bool (*flush_logs)(handlerton *hton);
143
 
   bool (*show_status)(handlerton *hton, Session *session, stat_print_fn *print, enum ha_stat_type stat);
144
 
   int (*fill_files_table)(handlerton *hton, Session *session,
 
563
   bool (*show_status)(handlerton *hton, THD *thd, stat_print_fn *print, enum ha_stat_type stat);
 
564
   int (*fill_files_table)(handlerton *hton, THD *thd,
145
565
                           TableList *tables,
146
566
                           class Item *cond);
147
567
   uint32_t flags;                                /* global handler flags */
148
 
   int (*release_temporary_latches)(handlerton *hton, Session *session);
 
568
   int (*release_temporary_latches)(handlerton *hton, THD *thd);
149
569
 
150
 
   int (*discover)(handlerton *hton, Session* session, const char *db, 
 
570
   int (*discover)(handlerton *hton, THD* thd, const char *db, 
151
571
                   const char *name,
152
 
                   unsigned char **frmblob, 
 
572
                   uchar **frmblob, 
153
573
                   size_t *frmlen);
154
 
   int (*table_exists_in_engine)(handlerton *hton, Session* session, const char *db,
 
574
   int (*table_exists_in_engine)(handlerton *hton, THD* thd, const char *db,
155
575
                                 const char *name);
156
576
   uint32_t license; /* Flag for Engine License */
157
577
   void *data; /* Location for engines to keep personal structures */
158
578
};
159
579
 
160
580
 
 
581
/* Possible flags of a handlerton (there can be 32 of them) */
 
582
#define HTON_NO_FLAGS                 0
 
583
#define HTON_CLOSE_CURSORS_AT_COMMIT (1 << 0)
 
584
#define HTON_ALTER_NOT_SUPPORTED     (1 << 1) //Engine does not support alter
 
585
#define HTON_CAN_RECREATE            (1 << 2) //Delete all is used fro truncate
 
586
#define HTON_HIDDEN                  (1 << 3) //Engine does not appear in lists
 
587
#define HTON_FLUSH_AFTER_RENAME      (1 << 4)
 
588
#define HTON_NOT_USER_SELECTABLE     (1 << 5)
 
589
#define HTON_TEMPORARY_NOT_SUPPORTED (1 << 6) //Having temporary tables not supported
 
590
#define HTON_SUPPORT_LOG_TABLES      (1 << 7) //Engine supports log tables
 
591
#define HTON_NO_PARTITION            (1 << 8) //You can not partition these tables
161
592
 
162
593
class Ha_trx_info;
163
594
 
164
 
struct Session_TRANS
 
595
struct THD_TRANS
165
596
{
166
597
  /* true is not all entries in the ht[] support 2pc */
167
598
  bool        no_2pc;
171
602
    The purpose of this flag is to keep track of non-transactional
172
603
    tables that were modified in scope of:
173
604
    - transaction, when the variable is a member of
174
 
    Session::transaction.all
 
605
    THD::transaction.all
175
606
    - top-level statement or sub-statement, when the variable is a
176
 
    member of Session::transaction.stmt
 
607
    member of THD::transaction.stmt
177
608
    This member has the following life cycle:
178
609
    * stmt.modified_non_trans_table is used to keep track of
179
610
    modified non-transactional tables of top-level statements. At
207
638
 
208
639
  If a storage engine participates in a statement/transaction,
209
640
  an instance of this class is present in
210
 
  session->transaction.{stmt|all}.ha_list. The addition to
 
641
  thd->transaction.{stmt|all}.ha_list. The addition to
211
642
  {stmt|all}.ha_list is made by trans_register_ha().
212
643
 
213
644
  When it's time to commit or rollback, each element of ha_list
222
653
{
223
654
public:
224
655
  /** Register this storage engine in the given transaction context. */
225
 
  void register_ha(Session_TRANS *trans, handlerton *ht_arg)
 
656
  void register_ha(THD_TRANS *trans, handlerton *ht_arg)
226
657
  {
227
658
    assert(m_flags == 0);
228
659
    assert(m_ht == NULL);
293
724
    Not-null only if this instance is a part of transaction.
294
725
    May assume a combination of enum values above.
295
726
  */
296
 
  unsigned char       m_flags;
 
727
  uchar       m_flags;
297
728
};
298
729
 
299
730
 
313
744
  uint64_t check_sum;
314
745
} PARTITION_INFO;
315
746
 
 
747
#define UNDEF_NODEGROUP 65535
316
748
class Item;
317
749
struct st_table_log_memory_entry;
318
750
 
 
751
#define NOT_A_PARTITION_ID ((uint32_t)-1)
 
752
 
 
753
enum ha_choice { HA_CHOICE_UNDEF, HA_CHOICE_NO, HA_CHOICE_YES };
319
754
 
320
755
typedef struct st_ha_create_information
321
756
{
331
766
  uint32_t used_fields;
332
767
  uint32_t key_block_size;
333
768
  uint32_t block_size;
 
769
  SQL_LIST merge_list;
334
770
  handlerton *db_type;
335
771
  enum row_type row_type;
336
 
  uint32_t null_bits;                       /* NULL bits at start of record */
337
 
  uint32_t options;                             /* OR of HA_CREATE_ options */
338
 
  uint32_t extra_size;                      /* length of extra data segment */
 
772
  uint null_bits;                       /* NULL bits at start of record */
 
773
  uint options;                         /* OR of HA_CREATE_ options */
 
774
  uint merge_insert_method;
 
775
  uint extra_size;                      /* length of extra data segment */
 
776
  /* 0 not used, 1 if not transactional, 2 if transactional */
 
777
  enum ha_choice transactional;
339
778
  bool table_existed;                   /* 1 in create if table existed */
340
779
  bool frm_only;                        /* 1 if no ha_create_table() */
341
780
  bool varchar;                         /* 1 if table has a VARCHAR */
345
784
typedef struct st_ha_alter_information
346
785
{
347
786
  KEY  *key_info_buffer;
348
 
  uint32_t key_count;
349
 
  uint32_t index_drop_count;
350
 
  uint32_t *index_drop_buffer;
351
 
  uint32_t index_add_count;
352
 
  uint32_t *index_add_buffer;
 
787
  uint key_count;
 
788
  uint index_drop_count;
 
789
  uint *index_drop_buffer;
 
790
  uint index_add_count;
 
791
  uint *index_add_buffer;
353
792
  void *data;
354
793
} HA_ALTER_INFO;
355
794
 
383
822
  TABLEOP_HOOKS() {}
384
823
  virtual ~TABLEOP_HOOKS() {}
385
824
 
386
 
  inline void prelock(Table **tables, uint32_t count)
 
825
  inline void prelock(Table **tables, uint count)
387
826
  {
388
827
    do_prelock(tables, count);
389
828
  }
390
829
 
391
 
  inline int postlock(Table **tables, uint32_t count)
 
830
  inline int postlock(Table **tables, uint count)
392
831
  {
393
832
    return do_postlock(tables, count);
394
833
  }
395
834
private:
396
835
  /* Function primitive that is called prior to locking tables */
397
836
  virtual void do_prelock(Table **tables __attribute__((unused)),
398
 
                          uint32_t count __attribute__((unused)))
 
837
                          uint count __attribute__((unused)))
399
838
  {
400
839
    /* Default is to do nothing */
401
840
  }
409
848
     @return Error code or zero.
410
849
   */
411
850
  virtual int do_postlock(Table **tables __attribute__((unused)),
412
 
                          uint32_t count __attribute__((unused)))
 
851
                          uint count __attribute__((unused)))
413
852
  {
414
853
    return 0;                           /* Default is to do nothing */
415
854
  }
426
865
{
427
866
  st_ha_check_opt() {}                        /* Remove gcc warning */
428
867
  uint32_t sort_buffer_size;
429
 
  uint32_t flags;       /* isam layer flags (e.g. for myisamchk) */
430
 
  uint32_t sql_flags;   /* sql layer flags - for something myisamchk cannot do */
 
868
  uint flags;       /* isam layer flags (e.g. for myisamchk) */
 
869
  uint sql_flags;   /* sql layer flags - for something myisamchk cannot do */
431
870
  KEY_CACHE *key_cache; /* new key cache when changing key cache */
432
871
  void init();
433
872
} HA_CHECK_OPT;
443
882
 
444
883
typedef struct st_handler_buffer
445
884
{
446
 
  unsigned char *buffer;         /* Buffer one can start using */
447
 
  unsigned char *buffer_end;     /* End of buffer */
448
 
  unsigned char *end_of_used_area;     /* End of area that was used by handler */
 
885
  uchar *buffer;         /* Buffer one can start using */
 
886
  uchar *buffer_end;     /* End of buffer */
 
887
  uchar *end_of_used_area;     /* End of area that was used by handler */
449
888
} HANDLER_BUFFER;
450
889
 
451
890
typedef struct system_status_var SSV;
467
906
    RETURN
468
907
      An opaque value to be used as RANGE_SEQ_IF::next() parameter
469
908
  */
470
 
  range_seq_t (*init)(void *init_params, uint32_t n_ranges, uint32_t flags);
 
909
  range_seq_t (*init)(void *init_params, uint n_ranges, uint flags);
471
910
 
472
911
 
473
912
  /*
482
921
      0 - Ok, the range structure filled with info about the next range
483
922
      1 - No more ranges
484
923
  */
485
 
  uint32_t (*next) (range_seq_t seq, KEY_MULTI_RANGE *range);
 
924
  uint (*next) (range_seq_t seq, KEY_MULTI_RANGE *range);
486
925
} RANGE_SEQ_IF;
487
926
 
488
 
uint16_t &mrr_persistent_flag_storage(range_seq_t seq, uint32_t idx);
489
 
char* &mrr_get_ptr_by_idx(range_seq_t seq, uint32_t idx);
 
927
uint16_t &mrr_persistent_flag_storage(range_seq_t seq, uint idx);
 
928
char* &mrr_get_ptr_by_idx(range_seq_t seq, uint idx);
490
929
 
491
930
class COST_VECT
492
931
543
982
void get_sweep_read_cost(Table *table, ha_rows nrows, bool interrupted, 
544
983
                         COST_VECT *cost);
545
984
 
 
985
/*
 
986
  The below two are not used (and not handled) in this milestone of this WL
 
987
  entry because there seems to be no use for them at this stage of
 
988
  implementation.
 
989
*/
 
990
#define HA_MRR_SINGLE_POINT 1
 
991
#define HA_MRR_FIXED_KEY  2
 
992
 
 
993
/* 
 
994
  Indicates that RANGE_SEQ_IF::next(&range) doesn't need to fill in the
 
995
  'range' parameter.
 
996
*/
 
997
#define HA_MRR_NO_ASSOCIATION 4
 
998
 
 
999
/* 
 
1000
  The MRR user will provide ranges in key order, and MRR implementation
 
1001
  must return rows in key order.
 
1002
*/
 
1003
#define HA_MRR_SORTED 8
 
1004
 
 
1005
/* MRR implementation doesn't have to retrieve full records */
 
1006
#define HA_MRR_INDEX_ONLY 16
 
1007
 
 
1008
/* 
 
1009
  The passed memory buffer is of maximum possible size, the caller can't
 
1010
  assume larger buffer.
 
1011
*/
 
1012
#define HA_MRR_LIMITS 32
 
1013
 
 
1014
 
 
1015
/*
 
1016
  Flag set <=> default MRR implementation is used
 
1017
  (The choice is made by **_info[_const]() function which may set this
 
1018
   flag. SQL layer remembers the flag value and then passes it to
 
1019
   multi_read_range_init().
 
1020
*/
 
1021
#define HA_MRR_USE_DEFAULT_IMPL 64
 
1022
 
 
1023
/*
 
1024
  Used only as parameter to multi_range_read_info():
 
1025
  Flag set <=> the caller guarantees that the bounds of the scanned ranges
 
1026
  will not have NULL values.
 
1027
*/
 
1028
#define HA_MRR_NO_NULL_ENDPOINTS 128
546
1029
 
547
1030
 
548
1031
class ha_statistics
568
1051
  time_t create_time;                   /* When table was created */
569
1052
  time_t check_time;
570
1053
  time_t update_time;
571
 
  uint32_t block_size;                  /* index block size */
 
1054
  uint block_size;                      /* index block size */
572
1055
 
573
1056
  ha_statistics():
574
1057
    data_file_length(0), max_data_file_length(0),
578
1061
  {}
579
1062
};
580
1063
 
581
 
uint32_t calculate_key_len(Table *, uint, const unsigned char *, key_part_map);
 
1064
uint calculate_key_len(Table *, uint, const uchar *, key_part_map);
582
1065
/*
583
1066
  bitmap with first N+1 bits set
584
1067
  (keypart_map for a key prefix of [0..N] keyparts)
650
1133
  ha_rows estimation_rows_to_insert;
651
1134
public:
652
1135
  handlerton *ht;                 /* storage engine of this handler */
653
 
  unsigned char *ref;                           /* Pointer to current row */
654
 
  unsigned char *dup_ref;                       /* Pointer to duplicate row */
 
1136
  uchar *ref;                           /* Pointer to current row */
 
1137
  uchar *dup_ref;                       /* Pointer to duplicate row */
655
1138
 
656
1139
  ha_statistics stats;
657
1140
  /** MultiRangeRead-related members: */
658
1141
  range_seq_t mrr_iter;    /* Interator to traverse the range sequence */
659
1142
  RANGE_SEQ_IF mrr_funcs;  /* Range sequence traversal functions */
660
1143
  HANDLER_BUFFER *multi_range_buffer; /* MRR buffer info */
661
 
  uint32_t ranges_in_seq; /* Total number of ranges in the traversed sequence */
 
1144
  uint ranges_in_seq; /* Total number of ranges in the traversed sequence */
662
1145
  /* true <=> source MRR ranges and the output are ordered */
663
1146
  bool mrr_is_output_sorted;
664
1147
 
678
1161
  */
679
1162
  bool in_range_check_pushed_down;
680
1163
 
681
 
  uint32_t errkey;                              /* Last dup key */
682
 
  uint32_t key_used_on_scan;
683
 
  uint32_t active_index;
 
1164
  uint errkey;                          /* Last dup key */
 
1165
  uint key_used_on_scan;
 
1166
  uint active_index;
684
1167
  /** Length of ref (1-8 or the clustered key length) */
685
 
  uint32_t ref_length;
 
1168
  uint ref_length;
686
1169
  enum {NONE=0, INDEX, RND} inited;
687
1170
  bool locked;
688
1171
  bool implicit_emptied;                /* Can be !=0 only if HEAP */
689
1172
  const Item *pushed_cond;
690
1173
 
691
1174
  Item *pushed_idx_cond;
692
 
  uint32_t pushed_idx_cond_keyno;  /* The index which the above condition is for */
 
1175
  uint pushed_idx_cond_keyno;  /* The index which the above condition is for */
693
1176
 
694
1177
  /**
695
1178
    next_insert_id is the next value which should be inserted into the
705
1188
    insert id for the current row (*autogenerated*; if not
706
1189
    autogenerated, it's 0).
707
1190
    At first successful insertion, this variable is stored into
708
 
    Session::first_successful_insert_id_in_cur_stmt.
 
1191
    THD::first_successful_insert_id_in_cur_stmt.
709
1192
  */
710
1193
  uint64_t insert_id_for_cur_row;
711
1194
  /**
739
1222
  /* ha_ methods: pubilc wrappers for private virtual API */
740
1223
 
741
1224
  int ha_open(Table *table, const char *name, int mode, int test_if_locked);
742
 
  int ha_index_init(uint32_t idx, bool sorted)
 
1225
  int ha_index_init(uint idx, bool sorted)
743
1226
  {
744
1227
    int result;
745
1228
    assert(inited==NONE);
781
1264
    interface, see the (private) functions write_row(), update_row(),
782
1265
    and delete_row() below.
783
1266
  */
784
 
  int ha_external_lock(Session *session, int lock_type);
785
 
  int ha_write_row(unsigned char * buf);
786
 
  int ha_update_row(const unsigned char * old_data, unsigned char * new_data);
787
 
  int ha_delete_row(const unsigned char * buf);
 
1267
  int ha_external_lock(THD *thd, int lock_type);
 
1268
  int ha_write_row(uchar * buf);
 
1269
  int ha_update_row(const uchar * old_data, uchar * new_data);
 
1270
  int ha_delete_row(const uchar * buf);
788
1271
  void ha_release_auto_increment();
789
1272
 
790
1273
  int ha_check_for_upgrade(HA_CHECK_OPT *check_opt);
791
1274
  /** to be actually called to get 'check()' functionality*/
792
 
  int ha_check(Session *session, HA_CHECK_OPT *check_opt);
793
 
  int ha_repair(Session* session, HA_CHECK_OPT* check_opt);
 
1275
  int ha_check(THD *thd, HA_CHECK_OPT *check_opt);
 
1276
  int ha_repair(THD* thd, HA_CHECK_OPT* check_opt);
794
1277
  void ha_start_bulk_insert(ha_rows rows)
795
1278
  {
796
1279
    estimation_rows_to_insert= rows;
801
1284
    estimation_rows_to_insert= 0;
802
1285
    return end_bulk_insert();
803
1286
  }
804
 
  int ha_bulk_update_row(const unsigned char *old_data, unsigned char *new_data,
805
 
                         uint32_t *dup_key_found);
 
1287
  int ha_bulk_update_row(const uchar *old_data, uchar *new_data,
 
1288
                         uint *dup_key_found);
806
1289
  int ha_delete_all_rows();
807
1290
  int ha_reset_auto_increment(uint64_t value);
808
 
  int ha_optimize(Session* session, HA_CHECK_OPT* check_opt);
809
 
  int ha_analyze(Session* session, HA_CHECK_OPT* check_opt);
810
 
  bool ha_check_and_repair(Session *session);
811
 
  int ha_disable_indexes(uint32_t mode);
812
 
  int ha_enable_indexes(uint32_t mode);
 
1291
  int ha_optimize(THD* thd, HA_CHECK_OPT* check_opt);
 
1292
  int ha_analyze(THD* thd, HA_CHECK_OPT* check_opt);
 
1293
  bool ha_check_and_repair(THD *thd);
 
1294
  int ha_disable_indexes(uint mode);
 
1295
  int ha_enable_indexes(uint mode);
813
1296
  int ha_discard_or_import_tablespace(bool discard);
814
1297
  void ha_prepare_for_alter();
815
1298
  int ha_rename_table(const char *from, const char *to);
823
1306
 
824
1307
  void adjust_next_insert_id_after_explicit_value(uint64_t nr);
825
1308
  int update_auto_increment();
826
 
  void print_keydup_error(uint32_t key_nr, const char *msg);
 
1309
  void print_keydup_error(uint key_nr, const char *msg);
827
1310
  virtual void print_error(int error, myf errflag);
828
1311
  virtual bool get_error_message(int error, String *buf);
829
 
  uint32_t get_dup_key(int error);
 
1312
  uint get_dup_key(int error);
830
1313
  virtual void change_table_ptr(Table *table_arg, TABLE_SHARE *share)
831
1314
  {
832
1315
    table= table_arg;
835
1318
  /* Estimates calculation */
836
1319
  virtual double scan_time(void)
837
1320
  { return uint64_t2double(stats.data_file_length) / IO_SIZE + 2; }
838
 
  virtual double read_time(uint32_t index __attribute__((unused)),
839
 
                           uint32_t ranges, ha_rows rows)
 
1321
  virtual double read_time(uint index __attribute__((unused)),
 
1322
                           uint ranges, ha_rows rows)
840
1323
  { return rows2double(ranges+rows); }
841
1324
 
842
 
  virtual double index_only_read_time(uint32_t keynr, double records);
 
1325
  virtual double index_only_read_time(uint keynr, double records);
843
1326
  
844
 
  virtual ha_rows multi_range_read_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
 
1327
  virtual ha_rows multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq,
845
1328
                                              void *seq_init_param, 
846
 
                                              uint32_t n_ranges, uint32_t *bufsz,
847
 
                                              uint32_t *flags, COST_VECT *cost);
848
 
  virtual int multi_range_read_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys,
849
 
                                    uint32_t *bufsz, uint32_t *flags, COST_VECT *cost);
 
1329
                                              uint n_ranges, uint *bufsz,
 
1330
                                              uint *flags, COST_VECT *cost);
 
1331
  virtual int multi_range_read_info(uint keyno, uint n_ranges, uint keys,
 
1332
                                    uint *bufsz, uint *flags, COST_VECT *cost);
850
1333
  virtual int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
851
 
                                    uint32_t n_ranges, uint32_t mode,
 
1334
                                    uint n_ranges, uint mode,
852
1335
                                    HANDLER_BUFFER *buf);
853
1336
  virtual int multi_range_read_next(char **range_info);
854
1337
 
856
1339
  virtual const key_map *keys_to_use_for_scanning() { return &key_map_empty; }
857
1340
  bool has_transactions()
858
1341
  { return (ha_table_flags() & HA_NO_TRANSACTIONS) == 0; }
859
 
  virtual uint32_t extra_rec_buf_length() const { return 0; }
 
1342
  virtual uint extra_rec_buf_length() const { return 0; }
860
1343
 
861
1344
  /**
862
1345
    This method is used to analyse the error to see whether the error
868
1351
    same thing as HA_ERR_FOUND_DUP_KEY but can in some cases lead to
869
1352
    a slightly different error message.
870
1353
  */
871
 
  virtual bool is_fatal_error(int error, uint32_t flags)
 
1354
  virtual bool is_fatal_error(int error, uint flags)
872
1355
  {
873
1356
    if (!error ||
874
1357
        ((flags & HA_CHECK_DUP_KEY) &&
898
1381
  */
899
1382
  virtual enum row_type get_row_type() const { return ROW_TYPE_NOT_USED; }
900
1383
 
901
 
  virtual const char *index_type(uint32_t key_number __attribute__((unused)))
 
1384
  virtual const char *index_type(uint key_number __attribute__((unused)))
902
1385
  { assert(0); return "";}
903
1386
 
904
1387
 
910
1393
    as there may be several calls to this routine.
911
1394
  */
912
1395
  virtual void column_bitmaps_signal();
913
 
  uint32_t get_index(void) const { return active_index; }
 
1396
  uint get_index(void) const { return active_index; }
914
1397
  virtual int close(void)=0;
915
1398
 
916
1399
  /**
934
1417
    @retval  0           Success
935
1418
    @retval  >0          Error code
936
1419
  */
937
 
  virtual int exec_bulk_update(uint32_t *dup_key_found __attribute__((unused)))
 
1420
  virtual int exec_bulk_update(uint *dup_key_found __attribute__((unused)))
938
1421
  {
939
1422
    assert(false);
940
1423
    return HA_ERR_WRONG_COMMAND;
961
1444
     row if available. If the key value is null, begin at the first key of the
962
1445
     index.
963
1446
  */
964
 
  virtual int index_read_map(unsigned char * buf, const unsigned char * key,
 
1447
  virtual int index_read_map(uchar * buf, const uchar * key,
965
1448
                             key_part_map keypart_map,
966
1449
                             enum ha_rkey_function find_flag)
967
1450
  {
968
 
    uint32_t key_len= calculate_key_len(table, active_index, key, keypart_map);
 
1451
    uint key_len= calculate_key_len(table, active_index, key, keypart_map);
969
1452
    return  index_read(buf, key, key_len, find_flag);
970
1453
  }
971
1454
  /**
974
1457
     row if available. If the key value is null, begin at the first key of the
975
1458
     index.
976
1459
  */
977
 
  virtual int index_read_idx_map(unsigned char * buf, uint32_t index, const unsigned char * key,
 
1460
  virtual int index_read_idx_map(uchar * buf, uint index, const uchar * key,
978
1461
                                 key_part_map keypart_map,
979
1462
                                 enum ha_rkey_function find_flag);
980
 
  virtual int index_next(unsigned char * buf __attribute__((unused)))
981
 
   { return  HA_ERR_WRONG_COMMAND; }
982
 
  virtual int index_prev(unsigned char * buf __attribute__((unused)))
983
 
   { return  HA_ERR_WRONG_COMMAND; }
984
 
  virtual int index_first(unsigned char * buf __attribute__((unused)))
985
 
   { return  HA_ERR_WRONG_COMMAND; }
986
 
  virtual int index_last(unsigned char * buf __attribute__((unused)))
987
 
   { return  HA_ERR_WRONG_COMMAND; }
988
 
  virtual int index_next_same(unsigned char *buf __attribute__((unused)),
989
 
                              const unsigned char *key __attribute__((unused)),
990
 
                              uint32_t keylen __attribute__((unused)));
 
1463
  virtual int index_next(uchar * buf __attribute__((unused)))
 
1464
   { return  HA_ERR_WRONG_COMMAND; }
 
1465
  virtual int index_prev(uchar * buf __attribute__((unused)))
 
1466
   { return  HA_ERR_WRONG_COMMAND; }
 
1467
  virtual int index_first(uchar * buf __attribute__((unused)))
 
1468
   { return  HA_ERR_WRONG_COMMAND; }
 
1469
  virtual int index_last(uchar * buf __attribute__((unused)))
 
1470
   { return  HA_ERR_WRONG_COMMAND; }
 
1471
  virtual int index_next_same(uchar *buf __attribute__((unused)),
 
1472
                              const uchar *key __attribute__((unused)),
 
1473
                              uint keylen __attribute__((unused)));
991
1474
  /**
992
1475
     @brief
993
1476
     The following functions works like index_read, but it find the last
994
1477
     row with the current key value or prefix.
995
1478
  */
996
 
  virtual int index_read_last_map(unsigned char * buf, const unsigned char * key,
 
1479
  virtual int index_read_last_map(uchar * buf, const uchar * key,
997
1480
                                  key_part_map keypart_map)
998
1481
  {
999
 
    uint32_t key_len= calculate_key_len(table, active_index, key, keypart_map);
 
1482
    uint key_len= calculate_key_len(table, active_index, key, keypart_map);
1000
1483
    return index_read_last(buf, key, key_len);
1001
1484
  }
1002
1485
  virtual int read_range_first(const key_range *start_key,
1005
1488
  virtual int read_range_next();
1006
1489
  int compare_key(key_range *range);
1007
1490
  int compare_key2(key_range *range);
1008
 
  virtual int rnd_next(unsigned char *buf __attribute__((unused)))=0;
1009
 
  virtual int rnd_pos(unsigned char * buf __attribute__((unused)),
1010
 
                      unsigned char *pos __attribute__((unused)))=0;
 
1491
  virtual int rnd_next(uchar *buf __attribute__((unused)))=0;
 
1492
  virtual int rnd_pos(uchar * buf __attribute__((unused)),
 
1493
                      uchar *pos __attribute__((unused)))=0;
1011
1494
  /**
1012
1495
    One has to use this method when to find
1013
1496
    random position by record as the plain
1014
1497
    position() call doesn't work for some
1015
1498
    handlers for random position.
1016
1499
  */
1017
 
  virtual int rnd_pos_by_record(unsigned char *record);
1018
 
  virtual int read_first_row(unsigned char *buf, uint32_t primary_key);
 
1500
  virtual int rnd_pos_by_record(uchar *record);
 
1501
  virtual int read_first_row(uchar *buf, uint primary_key);
1019
1502
  /**
1020
1503
    The following function is only needed for tables that may be temporary
1021
1504
    tables during joins.
1022
1505
  */
1023
 
  virtual int restart_rnd_next(unsigned char *buf __attribute__((unused)),
1024
 
                               unsigned char *pos __attribute__((unused)))
1025
 
    { return HA_ERR_WRONG_COMMAND; }
1026
 
  virtual int rnd_same(unsigned char *buf __attribute__((unused)),
1027
 
                       uint32_t inx __attribute__((unused)))
1028
 
    { return HA_ERR_WRONG_COMMAND; }
1029
 
  virtual ha_rows records_in_range(uint32_t inx __attribute__((unused)),
 
1506
  virtual int restart_rnd_next(uchar *buf __attribute__((unused)),
 
1507
                               uchar *pos __attribute__((unused)))
 
1508
    { return HA_ERR_WRONG_COMMAND; }
 
1509
  virtual int rnd_same(uchar *buf __attribute__((unused)),
 
1510
                       uint inx __attribute__((unused)))
 
1511
    { return HA_ERR_WRONG_COMMAND; }
 
1512
  virtual ha_rows records_in_range(uint inx __attribute__((unused)),
1030
1513
                                   key_range *min_key __attribute__((unused)),
1031
1514
                                   key_range *max_key __attribute__((unused)))
1032
1515
    { return (ha_rows) 10; }
1033
 
  virtual void position(const unsigned char *record)=0;
 
1516
  virtual void position(const uchar *record)=0;
1034
1517
  virtual int info(uint)=0; // see my_base.h for full description
1035
1518
  virtual uint32_t calculate_key_hash_value(Field **field_array __attribute__((unused)))
1036
1519
  { assert(0); return 0; }
1061
1544
  */
1062
1545
  virtual void try_semi_consistent_read(bool) {}
1063
1546
  virtual void unlock_row(void) {}
1064
 
  virtual int start_stmt(Session *session __attribute__((unused)),
 
1547
  virtual int start_stmt(THD *thd __attribute__((unused)),
1065
1548
                         thr_lock_type lock_type __attribute__((unused)))
1066
1549
  {return 0;}
1067
1550
  virtual void get_auto_increment(uint64_t offset, uint64_t increment,
1090
1573
 
1091
1574
  virtual void update_create_info(HA_CREATE_INFO *create_info __attribute__((unused))) {}
1092
1575
  int check_old_types(void);
1093
 
  virtual int assign_to_keycache(Session* session __attribute__((unused)),
 
1576
  virtual int assign_to_keycache(THD* thd __attribute__((unused)),
1094
1577
                                 HA_CHECK_OPT* check_opt __attribute__((unused)))
1095
1578
  { return HA_ADMIN_NOT_IMPLEMENTED; }
1096
1579
  /* end of the list of admin commands */
1110
1593
    @retval   true            Foreign key defined on table or index
1111
1594
    @retval   false           No foreign key defined
1112
1595
  */
1113
 
  virtual bool is_fk_defined_on_table_or_index(uint32_t index __attribute__((unused)))
 
1596
  virtual bool is_fk_defined_on_table_or_index(uint index __attribute__((unused)))
1114
1597
  { return false; }
1115
1598
  virtual char* get_foreign_key_create_info(void)
1116
1599
  { return(NULL);}  /* gets foreign key create string from InnoDB */
1117
1600
  /** used in ALTER Table; 1 if changing storage engine is allowed */
1118
1601
  virtual bool can_switch_engines(void) { return 1; }
1119
1602
  /** used in REPLACE; is > 0 if table is referred by a FOREIGN KEY */
1120
 
  virtual int get_foreign_key_list(Session *session __attribute__((unused)),
 
1603
  virtual int get_foreign_key_list(THD *thd __attribute__((unused)),
1121
1604
                                   List<FOREIGN_KEY_INFO> *f_key_list __attribute__((unused)))
1122
1605
  { return 0; }
1123
 
  virtual uint32_t referenced_by_foreign_key() { return 0;}
 
1606
  virtual uint referenced_by_foreign_key() { return 0;}
1124
1607
  virtual void init_table_handle_for_HANDLER()
1125
1608
  { return; }       /* prepare InnoDB for HANDLER */
1126
1609
  virtual void free_foreign_key_create_info(char* str __attribute__((unused))) {}
1141
1624
 
1142
1625
  virtual int get_default_no_partitions(HA_CREATE_INFO *info __attribute__((unused))) { return 1;}
1143
1626
  virtual bool get_no_parts(const char *name __attribute__((unused)),
1144
 
                            uint32_t *no_parts)
 
1627
                            uint *no_parts)
1145
1628
  {
1146
1629
    *no_parts= 0;
1147
1630
    return 0;
1148
1631
  }
1149
1632
 
1150
 
  virtual uint32_t index_flags(uint32_t idx, uint32_t part, bool all_parts) const =0;
 
1633
  virtual uint32_t index_flags(uint idx, uint part, bool all_parts) const =0;
1151
1634
 
1152
1635
  virtual int add_index(Table *table_arg __attribute__((unused)),
1153
1636
                        KEY *key_info __attribute__((unused)),
1154
 
                        uint32_t num_of_keys __attribute__((unused)))
 
1637
                        uint num_of_keys __attribute__((unused)))
1155
1638
  { return (HA_ERR_WRONG_COMMAND); }
1156
1639
  virtual int prepare_drop_index(Table *table_arg __attribute__((unused)),
1157
 
                                 uint32_t *key_num __attribute__((unused)),
1158
 
                                 uint32_t num_of_keys __attribute__((unused)))
 
1640
                                 uint *key_num __attribute__((unused)),
 
1641
                                 uint num_of_keys __attribute__((unused)))
1159
1642
  { return (HA_ERR_WRONG_COMMAND); }
1160
1643
  virtual int final_drop_index(Table *table_arg __attribute__((unused)))
1161
1644
  { return (HA_ERR_WRONG_COMMAND); }
1162
1645
 
1163
 
  uint32_t max_record_length() const
1164
 
  { return cmin((unsigned int)HA_MAX_REC_LENGTH, max_supported_record_length()); }
1165
 
  uint32_t max_keys() const
1166
 
  { return cmin((unsigned int)MAX_KEY, max_supported_keys()); }
1167
 
  uint32_t max_key_parts() const
1168
 
  { return cmin((unsigned int)MAX_REF_PARTS, max_supported_key_parts()); }
1169
 
  uint32_t max_key_length() const
1170
 
  { return cmin((unsigned int)MAX_KEY_LENGTH, max_supported_key_length()); }
1171
 
  uint32_t max_key_part_length(void) const
1172
 
  { return cmin((unsigned int)MAX_KEY_LENGTH, max_supported_key_part_length()); }
 
1646
  uint max_record_length() const
 
1647
  { return min((unsigned int)HA_MAX_REC_LENGTH, max_supported_record_length()); }
 
1648
  uint max_keys() const
 
1649
  { return min((unsigned int)MAX_KEY, max_supported_keys()); }
 
1650
  uint max_key_parts() const
 
1651
  { return min((unsigned int)MAX_REF_PARTS, max_supported_key_parts()); }
 
1652
  uint max_key_length() const
 
1653
  { return min((unsigned int)MAX_KEY_LENGTH, max_supported_key_length()); }
 
1654
  uint max_key_part_length(void) const
 
1655
  { return min((unsigned int)MAX_KEY_LENGTH, max_supported_key_part_length()); }
1173
1656
 
1174
 
  virtual uint32_t max_supported_record_length(void) const
 
1657
  virtual uint max_supported_record_length(void) const
1175
1658
  { return HA_MAX_REC_LENGTH; }
1176
 
  virtual uint32_t max_supported_keys(void) const { return 0; }
1177
 
  virtual uint32_t max_supported_key_parts(void) const { return MAX_REF_PARTS; }
1178
 
  virtual uint32_t max_supported_key_length(void) const { return MAX_KEY_LENGTH; }
1179
 
  virtual uint32_t max_supported_key_part_length(void) const { return 255; }
1180
 
  virtual uint32_t min_record_length(uint32_t options __attribute__((unused))) const
 
1659
  virtual uint max_supported_keys(void) const { return 0; }
 
1660
  virtual uint max_supported_key_parts(void) const { return MAX_REF_PARTS; }
 
1661
  virtual uint max_supported_key_length(void) const { return MAX_KEY_LENGTH; }
 
1662
  virtual uint max_supported_key_part_length(void) const { return 255; }
 
1663
  virtual uint min_record_length(uint options __attribute__((unused))) const
1181
1664
  { return 1; }
1182
1665
 
1183
1666
  virtual bool low_byte_first(void) const { return 1; }
1184
 
  virtual uint32_t checksum(void) const { return 0; }
 
1667
  virtual uint checksum(void) const { return 0; }
1185
1668
  virtual bool is_crashed(void) const  { return 0; }
1186
1669
  virtual bool auto_repair(void) const { return 0; }
1187
1670
 
1194
1677
  /**
1195
1678
    @note lock_count() can return > 1 if the table is MERGE or partitioned.
1196
1679
  */
1197
 
  virtual uint32_t lock_count(void) const { return 1; }
 
1680
  virtual uint lock_count(void) const { return 1; }
1198
1681
  /**
1199
1682
    Is not invoked for non-transactional temporary tables.
1200
1683
 
1208
1691
    than lock_count() claimed. This can happen when the MERGE children
1209
1692
    are not attached when this is called from another thread.
1210
1693
  */
1211
 
  virtual THR_LOCK_DATA **store_lock(Session *session,
 
1694
  virtual THR_LOCK_DATA **store_lock(THD *thd,
1212
1695
                                     THR_LOCK_DATA **to,
1213
1696
                                     enum thr_lock_type lock_type)=0;
1214
1697
 
1219
1702
  /**
1220
1703
    @brief Register a named table with a call back function to the query cache.
1221
1704
 
1222
 
    @param session The thread handle
 
1705
    @param thd The thread handle
1223
1706
    @param table_key A pointer to the table name in the table cache
1224
1707
    @param key_length The length of the table name
1225
1708
    @param[out] engine_callback The pointer to the storage engine call back
1247
1730
  */
1248
1731
 
1249
1732
  virtual bool
1250
 
    register_query_cache_table(Session *session __attribute__((unused)),
 
1733
    register_query_cache_table(THD *thd __attribute__((unused)),
1251
1734
                               char *table_key __attribute__((unused)),
1252
 
                               uint32_t key_length __attribute__((unused)),
 
1735
                               uint key_length __attribute__((unused)),
1253
1736
                               qc_engine_callback *engine_callback,
1254
1737
                               uint64_t *engine_data __attribute__((unused)))
1255
1738
  {
1264
1747
   @retval false  otherwise
1265
1748
 */
1266
1749
 virtual bool primary_key_is_clustered() { return false; }
1267
 
 virtual int cmp_ref(const unsigned char *ref1, const unsigned char *ref2)
 
1750
 virtual int cmp_ref(const uchar *ref1, const uchar *ref2)
1268
1751
 {
1269
1752
   return memcmp(ref1, ref2, ref_length);
1270
1753
 }
1305
1788
 virtual void cond_pop(void) { return; }
1306
1789
 
1307
1790
 virtual Item
1308
 
   *idx_cond_push(uint32_t keyno __attribute__((unused)),
 
1791
   *idx_cond_push(uint keyno __attribute__((unused)),
1309
1792
                  Item* idx_cond __attribute__((unused)))
1310
1793
 { return idx_cond; }
1311
1794
 
1314
1797
  */
1315
1798
 virtual bool
1316
1799
   check_if_incompatible_data(HA_CREATE_INFO *create_info __attribute__((unused)),
1317
 
                              uint32_t table_changes __attribute__((unused)))
 
1800
                              uint table_changes __attribute__((unused)))
1318
1801
 { return COMPATIBLE_DATA_NO; }
1319
1802
 
1320
1803
 /* On-line ALTER Table interface */
1346
1829
   check_if_supported_alter(Table *altered_table __attribute__((unused)),
1347
1830
                            HA_CREATE_INFO *create_info,
1348
1831
                            HA_ALTER_FLAGS *alter_flags __attribute__((unused)),
1349
 
                            uint32_t table_changes)
 
1832
                            uint table_changes)
1350
1833
 {
1351
1834
   if (this->check_if_incompatible_data(create_info, table_changes)
1352
1835
       == COMPATIBLE_DATA_NO)
1353
1836
     return(HA_ALTER_NOT_SUPPORTED);
1354
 
   else if ((*alter_flags & HA_ALTER_STORED_VCOL).is_set())
1355
 
     return(HA_ALTER_NOT_SUPPORTED);
1356
1837
   else
1357
1838
     return(HA_ALTER_SUPPORTED_WAIT_LOCK);
1358
1839
 }
1359
1840
 /**
1360
1841
   Tell storage engine to prepare for the on-line alter table (pre-alter)
1361
1842
 
1362
 
   @param     session               The thread handle
 
1843
   @param     thd               The thread handle
1363
1844
   @param     altered_table     A temporary table show what table is to
1364
1845
                                change to
1365
1846
   @param     alter_info        Storage place for data used during phase1
1369
1850
   @retval   0      OK
1370
1851
   @retval   error  error code passed from storage engine
1371
1852
 */
1372
 
 virtual int alter_table_phase1(Session *session __attribute__((unused)),
 
1853
 virtual int alter_table_phase1(THD *thd __attribute__((unused)),
1373
1854
                                Table *altered_table __attribute__((unused)),
1374
1855
                                HA_CREATE_INFO *create_info __attribute__((unused)),
1375
1856
                                HA_ALTER_INFO *alter_info __attribute__((unused)),
1380
1861
 /**
1381
1862
    Tell storage engine to perform the on-line alter table (alter)
1382
1863
 
1383
 
    @param    session               The thread handle
 
1864
    @param    thd               The thread handle
1384
1865
    @param    altered_table     A temporary table show what table is to
1385
1866
                                change to
1386
1867
    @param    alter_info        Storage place for data used during phase1
1395
1876
      this call is to be wrapped with a DDL lock. This is currently NOT
1396
1877
      supported.
1397
1878
 */
1398
 
 virtual int alter_table_phase2(Session *session  __attribute__((unused)),
 
1879
 virtual int alter_table_phase2(THD *thd  __attribute__((unused)),
1399
1880
                                Table *altered_table  __attribute__((unused)),
1400
1881
                                HA_CREATE_INFO *create_info __attribute__((unused)),
1401
1882
                                HA_ALTER_INFO *alter_info __attribute__((unused)),
1407
1888
    Tell storage engine that changed frm file is now on disk and table
1408
1889
    has been re-opened (post-alter)
1409
1890
 
1410
 
    @param    session               The thread handle
 
1891
    @param    thd               The thread handle
1411
1892
    @param    table             The altered table, re-opened
1412
1893
 */
1413
 
 virtual int alter_table_phase3(Session *session __attribute__((unused)),
 
1894
 virtual int alter_table_phase3(THD *thd __attribute__((unused)),
1414
1895
                                Table *table __attribute__((unused)))
1415
1896
 {
1416
1897
   return HA_ERR_UNSUPPORTED;
1426
1907
  /**
1427
1908
    Lock table.
1428
1909
 
1429
 
    @param    session                     Thread handle
 
1910
    @param    thd                     Thread handle
1430
1911
    @param    lock_type               HA_LOCK_IN_SHARE_MODE     (F_RDLCK)
1431
1912
                                      HA_LOCK_IN_EXCLUSIVE_MODE (F_WRLCK)
1432
1913
    @param    lock_timeout            -1 default timeout
1447
1928
                                      lock conflict with NOWAIT option
1448
1929
    @retval HA_ERR_LOCK_DEADLOCK      Deadlock detected
1449
1930
  */
1450
 
  virtual int lock_table(Session *session         __attribute__((unused)),
 
1931
  virtual int lock_table(THD *thd         __attribute__((unused)),
1451
1932
                         int lock_type    __attribute__((unused)),
1452
1933
                         int lock_timeout __attribute__((unused)))
1453
1934
  {
1454
1935
    return HA_ERR_WRONG_COMMAND;
1455
1936
  }
1456
 
  /*
1457
 
    This procedure defines if the storage engine supports virtual columns.
1458
 
    Default false means "not supported".
1459
 
  */
1460
 
  virtual bool check_if_supported_virtual_columns(void) 
1461
 
  { return false; }
1462
1937
 
1463
1938
protected:
1464
1939
  /* Service methods for use by storage engines. */
1465
1940
  void ha_statistic_increment(ulong SSV::*offset) const;
1466
 
  void **ha_data(Session *) const;
1467
 
  Session *ha_session(void) const;
 
1941
  void **ha_data(THD *) const;
 
1942
  THD *ha_thd(void) const;
1468
1943
 
1469
1944
  /**
1470
1945
    Default rename_table() and delete_table() rename/delete files with a
1490
1965
    the corresponding 'ha_*' method above.
1491
1966
  */
1492
1967
 
1493
 
  virtual int open(const char *name, int mode, uint32_t test_if_locked)=0;
1494
 
  virtual int index_init(uint32_t idx,
 
1968
  virtual int open(const char *name, int mode, uint test_if_locked)=0;
 
1969
  virtual int index_init(uint idx,
1495
1970
                         bool sorted __attribute__((unused)))
1496
1971
  { active_index= idx; return 0; }
1497
1972
  virtual int index_end() { active_index= MAX_KEY; return 0; }
1504
1979
  */
1505
1980
  virtual int rnd_init(bool scan)= 0;
1506
1981
  virtual int rnd_end() { return 0; }
1507
 
  virtual int write_row(unsigned char *buf __attribute__((unused)))
1508
 
  {
1509
 
    return HA_ERR_WRONG_COMMAND;
1510
 
  }
1511
 
 
1512
 
  virtual int update_row(const unsigned char *old_data __attribute__((unused)),
1513
 
                         unsigned char *new_data __attribute__((unused)))
1514
 
  {
1515
 
    return HA_ERR_WRONG_COMMAND;
1516
 
  }
1517
 
 
1518
 
  virtual int delete_row(const unsigned char *buf __attribute__((unused)))
 
1982
  virtual int write_row(uchar *buf __attribute__((unused)))
 
1983
  {
 
1984
    return HA_ERR_WRONG_COMMAND;
 
1985
  }
 
1986
 
 
1987
  virtual int update_row(const uchar *old_data __attribute__((unused)),
 
1988
                         uchar *new_data __attribute__((unused)))
 
1989
  {
 
1990
    return HA_ERR_WRONG_COMMAND;
 
1991
  }
 
1992
 
 
1993
  virtual int delete_row(const uchar *buf __attribute__((unused)))
1519
1994
  {
1520
1995
    return HA_ERR_WRONG_COMMAND;
1521
1996
  }
1549
2024
    @return  non-0 in case of failure, 0 in case of success.
1550
2025
    When lock_type is F_UNLCK, the return value is ignored.
1551
2026
  */
1552
 
  virtual int external_lock(Session *session __attribute__((unused)),
 
2027
  virtual int external_lock(THD *thd __attribute__((unused)),
1553
2028
                            int lock_type __attribute__((unused)))
1554
2029
  {
1555
2030
    return 0;
1558
2033
  /** admin commands - called from mysql_admin_table */
1559
2034
  virtual int check_for_upgrade(HA_CHECK_OPT *check_opt __attribute__((unused)))
1560
2035
  { return 0; }
1561
 
  virtual int check(Session* session __attribute__((unused)),
 
2036
  virtual int check(THD* thd __attribute__((unused)),
1562
2037
                    HA_CHECK_OPT* check_opt __attribute__((unused)))
1563
2038
  { return HA_ADMIN_NOT_IMPLEMENTED; }
1564
2039
 
1567
2042
     to specify CHECK option to use to call check()
1568
2043
     upon the table.
1569
2044
  */
1570
 
  virtual int repair(Session* session __attribute__((unused)),
 
2045
  virtual int repair(THD* thd __attribute__((unused)),
1571
2046
                     HA_CHECK_OPT* check_opt __attribute__((unused)))
1572
2047
  { return HA_ADMIN_NOT_IMPLEMENTED; }
1573
2048
  virtual void start_bulk_insert(ha_rows rows __attribute__((unused)))
1574
2049
  {}
1575
2050
  virtual int end_bulk_insert(void) { return 0; }
1576
 
  virtual int index_read(unsigned char * buf __attribute__((unused)),
1577
 
                         const unsigned char * key __attribute__((unused)),
1578
 
                         uint32_t key_len __attribute__((unused)),
 
2051
  virtual int index_read(uchar * buf __attribute__((unused)),
 
2052
                         const uchar * key __attribute__((unused)),
 
2053
                         uint key_len __attribute__((unused)),
1579
2054
                         enum ha_rkey_function find_flag __attribute__((unused)))
1580
2055
   { return  HA_ERR_WRONG_COMMAND; }
1581
 
  virtual int index_read_last(unsigned char * buf __attribute__((unused)),
1582
 
                              const unsigned char * key __attribute__((unused)),
1583
 
                              uint32_t key_len __attribute__((unused)))
 
2056
  virtual int index_read_last(uchar * buf __attribute__((unused)),
 
2057
                              const uchar * key __attribute__((unused)),
 
2058
                              uint key_len __attribute__((unused)))
1584
2059
   { return (my_errno= HA_ERR_WRONG_COMMAND); }
1585
2060
  /**
1586
2061
    This method is similar to update_row, however the handler doesn't need
1595
2070
    @retval  0   Bulk delete used by handler
1596
2071
    @retval  1   Bulk delete not used, normal operation used
1597
2072
  */
1598
 
  virtual int bulk_update_row(const unsigned char *old_data __attribute__((unused)),
1599
 
                              unsigned char *new_data __attribute__((unused)),
1600
 
                              uint32_t *dup_key_found __attribute__((unused)))
 
2073
  virtual int bulk_update_row(const uchar *old_data __attribute__((unused)),
 
2074
                              uchar *new_data __attribute__((unused)),
 
2075
                              uint *dup_key_found __attribute__((unused)))
1601
2076
  {
1602
2077
    assert(false);
1603
2078
    return HA_ERR_WRONG_COMMAND;
1618
2093
  */
1619
2094
  virtual int reset_auto_increment(uint64_t value __attribute__((unused)))
1620
2095
  { return HA_ERR_WRONG_COMMAND; }
1621
 
  virtual int optimize(Session* session __attribute__((unused)),
 
2096
  virtual int optimize(THD* thd __attribute__((unused)),
1622
2097
                       HA_CHECK_OPT* check_opt __attribute__((unused)))
1623
2098
  { return HA_ADMIN_NOT_IMPLEMENTED; }
1624
 
  virtual int analyze(Session* session __attribute__((unused)),
 
2099
  virtual int analyze(THD* thd __attribute__((unused)),
1625
2100
                      HA_CHECK_OPT* check_opt __attribute__((unused)))
1626
2101
  { return HA_ADMIN_NOT_IMPLEMENTED; }
1627
 
  virtual bool check_and_repair(Session *session __attribute__((unused)))
 
2102
  virtual bool check_and_repair(THD *thd __attribute__((unused)))
1628
2103
  { return true; }
1629
 
  virtual int disable_indexes(uint32_t mode __attribute__((unused)))
 
2104
  virtual int disable_indexes(uint mode __attribute__((unused)))
1630
2105
  { return HA_ERR_WRONG_COMMAND; }
1631
 
  virtual int enable_indexes(uint32_t mode __attribute__((unused)))
 
2106
  virtual int enable_indexes(uint mode __attribute__((unused)))
1632
2107
  { return HA_ERR_WRONG_COMMAND; }
1633
2108
  virtual int discard_or_import_tablespace(bool discard __attribute__((unused)))
1634
2109
  { return (my_errno=HA_ERR_WRONG_COMMAND); }
1675
2150
  handler *h2;
1676
2151
 
1677
2152
  /* Buffer to store rowids, or (rowid, range_id) pairs */
1678
 
  unsigned char *rowids_buf;
1679
 
  unsigned char *rowids_buf_cur;   /* Current position when reading/writing */
1680
 
  unsigned char *rowids_buf_last;  /* When reading: end of used buffer space */
1681
 
  unsigned char *rowids_buf_end;   /* End of the buffer */
 
2153
  uchar *rowids_buf;
 
2154
  uchar *rowids_buf_cur;   /* Current position when reading/writing */
 
2155
  uchar *rowids_buf_last;  /* When reading: end of used buffer space */
 
2156
  uchar *rowids_buf_end;   /* End of the buffer */
1682
2157
 
1683
2158
  bool dsmrr_eof; /* true <=> We have reached EOF when reading index tuples */
1684
2159
 
1693
2168
    table= table_arg;
1694
2169
  }
1695
2170
  int dsmrr_init(handler *h, KEY *key, RANGE_SEQ_IF *seq_funcs, 
1696
 
                 void *seq_init_param, uint32_t n_ranges, uint32_t mode, 
 
2171
                 void *seq_init_param, uint n_ranges, uint mode, 
1697
2172
                 HANDLER_BUFFER *buf);
1698
2173
  void dsmrr_close();
1699
2174
  int dsmrr_fill_buffer(handler *h);
1700
2175
  int dsmrr_next(handler *h, char **range_info);
1701
2176
 
1702
 
  int dsmrr_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys, uint32_t *bufsz,
1703
 
                 uint32_t *flags, COST_VECT *cost);
 
2177
  int dsmrr_info(uint keyno, uint n_ranges, uint keys, uint *bufsz,
 
2178
                 uint *flags, COST_VECT *cost);
1704
2179
 
1705
 
  ha_rows dsmrr_info_const(uint32_t keyno, RANGE_SEQ_IF *seq, 
1706
 
                            void *seq_init_param, uint32_t n_ranges, uint32_t *bufsz,
1707
 
                            uint32_t *flags, COST_VECT *cost);
 
2180
  ha_rows dsmrr_info_const(uint keyno, RANGE_SEQ_IF *seq, 
 
2181
                            void *seq_init_param, uint n_ranges, uint *bufsz,
 
2182
                            uint *flags, COST_VECT *cost);
1708
2183
private:
1709
 
  bool key_uses_partial_cols(uint32_t keyno);
1710
 
  bool choose_mrr_impl(uint32_t keyno, ha_rows rows, uint32_t *flags, uint32_t *bufsz, 
 
2184
  bool key_uses_partial_cols(uint keyno);
 
2185
  bool choose_mrr_impl(uint keyno, ha_rows rows, uint *flags, uint *bufsz, 
1711
2186
                       COST_VECT *cost);
1712
 
  bool get_disk_sweep_mrr_cost(uint32_t keynr, ha_rows rows, uint32_t flags, 
1713
 
                               uint32_t *buffer_size, COST_VECT *cost);
 
2187
  bool get_disk_sweep_mrr_cost(uint keynr, ha_rows rows, uint flags, 
 
2188
                               uint *buffer_size, COST_VECT *cost);
1714
2189
};
1715
2190
 
1716
2191
extern const char *ha_row_type[];
1721
2196
extern uint32_t total_ha, total_ha_2pc;
1722
2197
 
1723
2198
       /* Wrapper functions */
1724
 
#define ha_commit(session) (ha_commit_trans((session), true))
1725
 
#define ha_rollback(session) (ha_rollback_trans((session), true))
 
2199
#define ha_commit(thd) (ha_commit_trans((thd), true))
 
2200
#define ha_rollback(thd) (ha_rollback_trans((thd), true))
1726
2201
 
1727
2202
/* lookups */
1728
 
handlerton *ha_default_handlerton(Session *session);
1729
 
plugin_ref ha_resolve_by_name(Session *session, const LEX_STRING *name);
1730
 
plugin_ref ha_lock_engine(Session *session, handlerton *hton);
1731
 
handlerton *ha_resolve_by_legacy_type(Session *session, enum legacy_db_type db_type);
 
2203
handlerton *ha_default_handlerton(THD *thd);
 
2204
plugin_ref ha_resolve_by_name(THD *thd, const LEX_STRING *name);
 
2205
plugin_ref ha_lock_engine(THD *thd, handlerton *hton);
 
2206
handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type);
1732
2207
handler *get_new_handler(TABLE_SHARE *share, MEM_ROOT *alloc,
1733
2208
                         handlerton *db_type);
1734
 
handlerton *ha_checktype(Session *session, enum legacy_db_type database_type,
 
2209
handlerton *ha_checktype(THD *thd, enum legacy_db_type database_type,
1735
2210
                          bool no_substitute, bool report_error);
1736
2211
 
1737
2212
 
1764
2239
int ha_finalize_handlerton(st_plugin_int *plugin);
1765
2240
 
1766
2241
TYPELIB *ha_known_exts(void);
1767
 
void ha_close_connection(Session* session);
 
2242
void ha_close_connection(THD* thd);
1768
2243
bool ha_flush_logs(handlerton *db_type);
1769
2244
void ha_drop_database(char* path);
1770
 
int ha_create_table(Session *session, const char *path,
 
2245
int ha_create_table(THD *thd, const char *path,
1771
2246
                    const char *db, const char *table_name,
1772
2247
                    HA_CREATE_INFO *create_info,
1773
2248
                    bool update_create_info);
1774
 
int ha_delete_table(Session *session, handlerton *db_type, const char *path,
 
2249
int ha_delete_table(THD *thd, handlerton *db_type, const char *path,
1775
2250
                    const char *db, const char *alias, bool generate_warning);
1776
2251
 
1777
2252
/* statistics and info */
1778
 
bool ha_show_status(Session *session, handlerton *db_type, enum ha_stat_type stat);
 
2253
bool ha_show_status(THD *thd, handlerton *db_type, enum ha_stat_type stat);
1779
2254
 
1780
2255
/* discovery */
1781
 
int ha_create_table_from_engine(Session* session, const char *db, const char *name);
1782
 
int ha_discover(Session* session, const char* dbname, const char* name,
1783
 
                unsigned char** frmblob, size_t* frmlen);
1784
 
int ha_find_files(Session *session,const char *db,const char *path,
 
2256
int ha_create_table_from_engine(THD* thd, const char *db, const char *name);
 
2257
int ha_discover(THD* thd, const char* dbname, const char* name,
 
2258
                uchar** frmblob, size_t* frmlen);
 
2259
int ha_find_files(THD *thd,const char *db,const char *path,
1785
2260
                  const char *wild, bool dir, List<LEX_STRING>* files);
1786
 
int ha_table_exists_in_engine(Session* session, const char* db, const char* name);
 
2261
int ha_table_exists_in_engine(THD* thd, const char* db, const char* name);
1787
2262
 
1788
2263
/* key cache */
1789
2264
extern "C" int ha_init_key_cache(const char *name, KEY_CACHE *key_cache);
1793
2268
int ha_end_key_cache(KEY_CACHE *key_cache);
1794
2269
 
1795
2270
/* report to InnoDB that control passes to the client */
1796
 
int ha_release_temporary_latches(Session *session);
 
2271
int ha_release_temporary_latches(THD *thd);
1797
2272
 
1798
2273
/* transactions: interface to handlerton functions */
1799
 
int ha_start_consistent_snapshot(Session *session);
 
2274
int ha_start_consistent_snapshot(THD *thd);
1800
2275
int ha_commit_or_rollback_by_xid(XID *xid, bool commit);
1801
 
int ha_commit_one_phase(Session *session, bool all);
1802
 
int ha_rollback_trans(Session *session, bool all);
1803
 
int ha_prepare(Session *session);
 
2276
int ha_commit_one_phase(THD *thd, bool all);
 
2277
int ha_rollback_trans(THD *thd, bool all);
 
2278
int ha_prepare(THD *thd);
1804
2279
int ha_recover(HASH *commit_list);
1805
2280
 
1806
2281
/* transactions: these functions never call handlerton functions directly */
1807
 
int ha_commit_trans(Session *session, bool all);
1808
 
int ha_autocommit_or_rollback(Session *session, int error);
1809
 
int ha_enable_transaction(Session *session, bool on);
 
2282
int ha_commit_trans(THD *thd, bool all);
 
2283
int ha_autocommit_or_rollback(THD *thd, int error);
 
2284
int ha_enable_transaction(THD *thd, bool on);
1810
2285
 
1811
2286
/* savepoints */
1812
 
int ha_rollback_to_savepoint(Session *session, SAVEPOINT *sv);
1813
 
int ha_savepoint(Session *session, SAVEPOINT *sv);
1814
 
int ha_release_savepoint(Session *session, SAVEPOINT *sv);
 
2287
int ha_rollback_to_savepoint(THD *thd, SAVEPOINT *sv);
 
2288
int ha_savepoint(THD *thd, SAVEPOINT *sv);
 
2289
int ha_release_savepoint(THD *thd, SAVEPOINT *sv);
1815
2290
 
1816
2291
/* these are called by storage engines */
1817
 
void trans_register_ha(Session *session, bool all, handlerton *ht);
1818
 
 
1819
 
void table_case_convert(char * name, uint32_t length);
1820
 
const char *table_case_name(HA_CREATE_INFO *info, const char *name);
1821
 
 
1822
 
extern char reg_ext[FN_EXTLEN];
1823
 
extern uint32_t reg_ext_length;
1824
 
extern ulong specialflag;
1825
 
extern uint32_t lower_case_table_names;
1826
 
uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length);
1827
 
uint32_t tablename_to_filename(const char *from, char *to, uint32_t to_length);
1828
 
 
 
2292
void trans_register_ha(THD *thd, bool all, handlerton *ht);
1829
2293
 
1830
2294
/*
1831
2295
  Storage engine has to assume the transaction will end up with 2pc if
1832
2296
   - there is more than one 2pc-capable storage engine available
1833
2297
   - in the current transaction 2pc was not disabled yet
1834
2298
*/
1835
 
#define trans_need_2pc(session, all)                   ((total_ha_2pc > 1) && \
1836
 
        !((all ? &session->transaction.all : &session->transaction.stmt)->no_2pc))
 
2299
#define trans_need_2pc(thd, all)                   ((total_ha_2pc > 1) && \
 
2300
        !((all ? &thd->transaction.all : &thd->transaction.stmt)->no_2pc))
1837
2301
 
1838
 
#endif /* DRIZZLED_HANDLER_H */
 
2302
#ifdef HAVE_NDB_BINLOG
 
2303
int ha_reset_logs(THD *thd);
 
2304
int ha_binlog_index_purge_file(THD *thd, const char *file);
 
2305
void ha_reset_slave(THD *thd);
 
2306
void ha_binlog_log_query(THD *thd, handlerton *db_type,
 
2307
                         enum_binlog_command binlog_command,
 
2308
                         const char *query, uint query_length,
 
2309
                         const char *db, const char *table_name);
 
2310
void ha_binlog_wait(THD *thd);
 
2311
int ha_binlog_end(THD *thd);
 
2312
#else
 
2313
#define ha_reset_logs(a) do {} while (0)
 
2314
#define ha_binlog_index_purge_file(a,b) do {} while (0)
 
2315
#define ha_reset_slave(a) do {} while (0)
 
2316
#define ha_binlog_log_query(a,b,c,d,e,f,g) do {} while (0)
 
2317
#define ha_binlog_wait(a) do {} while (0)
 
2318
#define ha_binlog_end(a)  do {} while (0)
 
2319
#endif