~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/handler.h

Removed/replaced a couple DBUG calls

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
 
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
 
 
16
 
 
17
/* Definitions for parameters to do with handler-routines */
 
18
 
 
19
#ifdef USE_PRAGMA_INTERFACE
 
20
#pragma interface                       /* gcc class implementation */
 
21
#endif
 
22
 
 
23
#include <my_handler.h>
 
24
#include <ft_global.h>
 
25
#include <keycache.h>
 
26
 
 
27
#ifndef NO_HASH
 
28
#define NO_HASH                         /* Not yet implemented */
 
29
#endif
 
30
 
 
31
// the following is for checking tables
 
32
 
 
33
#define HA_ADMIN_ALREADY_DONE     1
 
34
#define HA_ADMIN_OK               0
 
35
#define HA_ADMIN_NOT_IMPLEMENTED -1
 
36
#define HA_ADMIN_FAILED          -2
 
37
#define HA_ADMIN_CORRUPT         -3
 
38
#define HA_ADMIN_INTERNAL_ERROR  -4
 
39
#define HA_ADMIN_INVALID         -5
 
40
#define HA_ADMIN_REJECT          -6
 
41
#define HA_ADMIN_TRY_ALTER       -7
 
42
#define HA_ADMIN_WRONG_CHECKSUM  -8
 
43
#define HA_ADMIN_NOT_BASE_TABLE  -9
 
44
#define HA_ADMIN_NEEDS_UPGRADE  -10
 
45
#define HA_ADMIN_NEEDS_ALTER    -11
 
46
#define HA_ADMIN_NEEDS_CHECK    -12
 
47
 
 
48
/* Bits to show what an alter table will do */
 
49
#include <sql_bitmap.h>
 
50
 
 
51
#define HA_MAX_ALTER_FLAGS 39
 
52
typedef Bitmap<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
 
53
 
 
54
#define HA_ADD_INDEX                  (0)
 
55
#define HA_DROP_INDEX                 (1)
 
56
#define HA_ALTER_INDEX                (2)
 
57
#define HA_RENAME_INDEX               (3)
 
58
#define HA_ADD_UNIQUE_INDEX           (4)
 
59
#define HA_DROP_UNIQUE_INDEX          (5)
 
60
#define HA_ALTER_UNIQUE_INDEX         (6)
 
61
#define HA_RENAME_UNIQUE_INDEX        (7)
 
62
#define HA_ADD_PK_INDEX               (8)
 
63
#define HA_DROP_PK_INDEX              (9)
 
64
#define HA_ALTER_PK_INDEX             (10)
 
65
#define HA_ADD_COLUMN                 (11)
 
66
#define HA_DROP_COLUMN                (12)
 
67
#define HA_CHANGE_COLUMN              (13)
 
68
#define HA_ALTER_COLUMN_NAME          (14)
 
69
#define HA_ALTER_COLUMN_TYPE          (15)
 
70
#define HA_ALTER_COLUMN_ORDER         (16)
 
71
#define HA_ALTER_COLUMN_NULLABLE      (17)
 
72
#define HA_COLUMN_DEFAULT_VALUE       (18)
 
73
#define HA_COLUMN_STORAGE             (19)
 
74
#define HA_COLUMN_FORMAT              (20)
 
75
#define HA_ADD_FOREIGN_KEY            (21)
 
76
#define HA_DROP_FOREIGN_KEY           (22)
 
77
#define HA_ALTER_FOREIGN_KEY          (23)
 
78
#define HA_ADD_CONSTRAINT             (24)
 
79
#define HA_CHANGE_CHARACTER_SET       (30)
 
80
#define HA_SET_DEFAULT_CHARACTER_SET  (31)
 
81
#define HA_CHANGE_AUTOINCREMENT_VALUE (32)
 
82
#define HA_ALTER_STORAGE              (33)
 
83
#define HA_ALTER_TABLESPACE           (34)
 
84
#define HA_ALTER_ROW_FORMAT           (35)
 
85
#define HA_RENAME_TABLE               (36)
 
86
#define HA_ALTER_STORAGE_ENGINE       (37)
 
87
#define HA_RECREATE                   (38)
 
88
/* Remember to increase HA_MAX_ALTER_FLAGS when adding more flags! */
 
89
 
 
90
/* Return values for check_if_supported_alter */
 
91
 
 
92
#define HA_ALTER_ERROR               -1
 
93
#define HA_ALTER_SUPPORTED_WAIT_LOCK  0
 
94
#define HA_ALTER_SUPPORTED_NO_LOCK    1
 
95
#define HA_ALTER_NOT_SUPPORTED        2
 
96
 
 
97
/* Bits in table_flags() to show what database can do */
 
98
 
 
99
#define HA_NO_TRANSACTIONS     (1 << 0) /* Doesn't support transactions */
 
100
#define HA_PARTIAL_COLUMN_READ (1 << 1) /* read may not return all columns */
 
101
#define HA_TABLE_SCAN_ON_INDEX (1 << 2) /* No separate data/index file */
 
102
/*
 
103
  The following should be set if the following is not true when scanning
 
104
  a table with rnd_next()
 
105
  - We will see all rows (including deleted ones)
 
106
  - Row positions are 'table->s->db_record_offset' apart
 
107
  If this flag is not set, filesort will do a postion() call for each matched
 
108
  row to be able to find the row later.
 
109
*/
 
110
#define HA_REC_NOT_IN_SEQ      (1 << 3)
 
111
/* This is now a dead option, just left for compatibility */
 
112
#define HA_CAN_GEOMETRY        (1 << 4)
 
113
/*
 
114
  Reading keys in random order is as fast as reading keys in sort order
 
115
  (Used in records.cc to decide if we should use a record cache and by
 
116
  filesort to decide if we should sort key + data or key + pointer-to-row
 
117
*/
 
118
#define HA_FAST_KEY_READ       (1 << 5)
 
119
/*
 
120
  Set the following flag if we on delete should force all key to be read
 
121
  and on update read all keys that changes
 
122
*/
 
123
#define HA_REQUIRES_KEY_COLUMNS_FOR_DELETE (1 << 6)
 
124
#define HA_NULL_IN_KEY         (1 << 7) /* One can have keys with NULL */
 
125
#define HA_DUPLICATE_POS       (1 << 8)    /* ha_position() gives dup row */
 
126
#define HA_NO_BLOBS            (1 << 9) /* Doesn't support blobs */
 
127
#define HA_CAN_INDEX_BLOBS     (1 << 10)
 
128
#define HA_AUTO_PART_KEY       (1 << 11) /* auto-increment in multi-part key */
 
129
#define HA_REQUIRE_PRIMARY_KEY (1 << 12) /* .. and can't create a hidden one */
 
130
#define HA_STATS_RECORDS_IS_EXACT (1 << 13) /* stats.records is exact */
 
131
/*
 
132
  INSERT_DELAYED only works with handlers that uses MySQL internal table
 
133
  level locks
 
134
*/
 
135
#define HA_CAN_INSERT_DELAYED  (1 << 14)
 
136
/*
 
137
  If we get the primary key columns for free when we do an index read
 
138
  It also implies that we have to retrive the primary key when using
 
139
  position() and rnd_pos().
 
140
*/
 
141
#define HA_PRIMARY_KEY_IN_READ_INDEX (1 << 15)
 
142
/*
 
143
  If HA_PRIMARY_KEY_REQUIRED_FOR_POSITION is set, it means that to position()
 
144
  uses a primary key. Without primary key, we can't call position().
 
145
*/ 
 
146
#define HA_PRIMARY_KEY_REQUIRED_FOR_POSITION (1 << 16) 
 
147
#define HA_CAN_RTREEKEYS       (1 << 17) /* Historical, no longer supported */
 
148
#define HA_NOT_DELETE_WITH_CACHE (1 << 18)
 
149
/*
 
150
  The following is we need to a primary key to delete (and update) a row.
 
151
  If there is no primary key, all columns needs to be read on update and delete
 
152
*/
 
153
#define HA_PRIMARY_KEY_REQUIRED_FOR_DELETE (1 << 19)
 
154
#define HA_NO_PREFIX_CHAR_KEYS (1 << 20)
 
155
#define HA_CAN_FULLTEXT        (1 << 21) /* Historical, no longer supported */
 
156
#define HA_CAN_SQL_HANDLER     (1 << 22) /* Historical, no longer supported */
 
157
#define HA_NO_AUTO_INCREMENT   (1 << 23)
 
158
#define HA_HAS_CHECKSUM        (1 << 24)
 
159
/* Table data are stored in separate files (for lower_case_table_names) */
 
160
#define HA_FILE_BASED          (1 << 26)
 
161
#define HA_NO_VARCHAR          (1 << 27) /* Historical, no longer supported */
 
162
#define HA_CAN_BIT_FIELD       (1 << 28) /* Historical, no longer supported */
 
163
#define HA_NEED_READ_RANGE_BUFFER (1 << 29) /* for read_multi_range */
 
164
#define HA_ANY_INDEX_MAY_BE_UNIQUE (1 << 30)
 
165
#define HA_NO_COPY_ON_ALTER    (1LL << 31)
 
166
#define HA_HAS_RECORDS         (1LL << 32) /* records() gives exact count*/
 
167
/* Has it's own method of binlog logging */
 
168
#define HA_HAS_OWN_BINLOGGING  (1LL << 33) /* Historical, no longer supported */
 
169
#define HA_MRR_CANT_SORT       (1LL << 34)
 
170
 
 
171
/*
 
172
  Engine is capable of row-format and statement-format logging,
 
173
  respectively
 
174
*/
 
175
#define HA_BINLOG_ROW_CAPABLE  (1LL << 35)
 
176
#define HA_BINLOG_STMT_CAPABLE (1LL << 36)
 
177
 
 
178
#define HA_ONLINE_ALTER        (1LL << 37)
 
179
 
 
180
/*
 
181
  Set of all binlog flags. Currently only contain the capabilities
 
182
  flags.
18
183
 */
19
 
 
20
 
#ifndef DRIZZLED_CURSOR_H
21
 
#define DRIZZLED_CURSOR_H
22
 
 
23
 
#include <drizzled/xid.h>
24
 
#include <drizzled/discrete_interval.h>
25
 
#include <drizzled/identifier.h>
26
 
#include <drizzled/definitions.h>
27
 
#include <drizzled/key_map.h>
28
 
 
29
 
/* Definitions for parameters to do with Cursor-routines */
30
 
 
31
 
#include <drizzled/thr_lock.h>
32
 
#include <drizzled/sql_string.h>
33
 
#include <drizzled/sql_list.h>
34
 
#include <drizzled/plugin/storage_engine.h>
35
 
#include <drizzled/handler_structs.h>
36
 
#include <drizzled/ha_statistics.h>
37
 
#include <drizzled/atomics.h>
38
 
 
39
 
#include <drizzled/message/table.pb.h>
40
 
 
41
 
#include <bitset>
42
 
#include <algorithm>
43
 
 
44
 
namespace drizzled
45
 
{
46
 
 
47
 
#define HA_MAX_ALTER_FLAGS 40
48
 
 
49
 
typedef std::bitset<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
50
 
 
51
 
extern uint64_t refresh_version;  /* Increments on each reload */
52
 
 
53
 
class Table;
54
 
class TableList;
55
 
class TableShare;
56
 
class Select_Lex_Unit;
57
 
class ForeignKeyInfo;
58
 
struct Order;
59
 
 
 
184
#define HA_BINLOG_FLAGS (HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE)
 
185
 
 
186
/* bits in index_flags(index_number) for what you can do with index */
 
187
#define HA_READ_NEXT            1       /* TODO really use this flag */
 
188
#define HA_READ_PREV            2       /* supports ::index_prev */
 
189
#define HA_READ_ORDER           4       /* index_next/prev follow sort order */
 
190
#define HA_READ_RANGE           8       /* can find all records in a range */
 
191
#define HA_ONLY_WHOLE_INDEX     16      /* Can't use part key searches */
 
192
#define HA_KEYREAD_ONLY         64      /* Support HA_EXTRA_KEYREAD */
 
193
/*
 
194
  Index scan will not return records in rowid order. Not guaranteed to be
 
195
  set for unordered (e.g. HASH) indexes.
 
196
*/
 
197
#define HA_KEY_SCAN_NOT_ROR     128 
 
198
#define HA_DO_INDEX_COND_PUSHDOWN  256 /* Supports Index Condition Pushdown */
 
199
 
 
200
 
 
201
 
 
202
/*
 
203
  HA_PARTITION_FUNCTION_SUPPORTED indicates that the function is
 
204
  supported at all.
 
205
  HA_FAST_CHANGE_PARTITION means that optimised variants of the changes
 
206
  exists but they are not necessarily done online.
 
207
 
 
208
  HA_ONLINE_DOUBLE_WRITE means that the handler supports writing to both
 
209
  the new partition and to the old partitions when updating through the
 
210
  old partitioning schema while performing a change of the partitioning.
 
211
  This means that we can support updating of the table while performing
 
212
  the copy phase of the change. For no lock at all also a double write
 
213
  from new to old must exist and this is not required when this flag is
 
214
  set.
 
215
  This is actually removed even before it was introduced the first time.
 
216
  The new idea is that handlers will handle the lock level already in
 
217
  store_lock for ALTER TABLE partitions.
 
218
 
 
219
  HA_PARTITION_ONE_PHASE is a flag that can be set by handlers that take
 
220
  care of changing the partitions online and in one phase. Thus all phases
 
221
  needed to handle the change are implemented inside the storage engine.
 
222
  The storage engine must also support auto-discovery since the frm file
 
223
  is changed as part of the change and this change must be controlled by
 
224
  the storage engine. A typical engine to support this is NDB (through
 
225
  WL #2498).
 
226
*/
 
227
#define HA_PARTITION_FUNCTION_SUPPORTED         (1L << 1)
 
228
#define HA_FAST_CHANGE_PARTITION                (1L << 2)
 
229
#define HA_PARTITION_ONE_PHASE                  (1L << 3)
 
230
 
 
231
/* operations for disable/enable indexes */
 
232
#define HA_KEY_SWITCH_NONUNIQ      0
 
233
#define HA_KEY_SWITCH_ALL          1
 
234
#define HA_KEY_SWITCH_NONUNIQ_SAVE 2
 
235
#define HA_KEY_SWITCH_ALL_SAVE     3
 
236
 
 
237
/*
 
238
  Note: the following includes binlog and closing 0.
 
239
  so: innodb + bdb + ndb + binlog + myisam + myisammrg + archive +
 
240
      example + csv + heap + blackhole + federated + 0
 
241
  (yes, the sum is deliberately inaccurate)
 
242
  TODO remove the limit, use dynarrays
 
243
*/
 
244
#define MAX_HA 15
 
245
 
 
246
/*
 
247
  Parameters for open() (in register form->filestat)
 
248
  HA_GET_INFO does an implicit HA_ABORT_IF_LOCKED
 
249
*/
 
250
 
 
251
#define HA_OPEN_KEYFILE         1
 
252
#define HA_OPEN_RNDFILE         2
 
253
#define HA_GET_INDEX            4
 
254
#define HA_GET_INFO             8       /* do a ha_info() after open */
 
255
#define HA_READ_ONLY            16      /* File opened as readonly */
 
256
/* Try readonly if can't open with read and write */
 
257
#define HA_TRY_READ_ONLY        32
 
258
#define HA_WAIT_IF_LOCKED       64      /* Wait if locked on open */
 
259
#define HA_ABORT_IF_LOCKED      128     /* skip if locked on open.*/
 
260
#define HA_BLOCK_LOCK           256     /* unlock when reading some records */
 
261
#define HA_OPEN_TEMPORARY       512
 
262
 
 
263
/* For transactional LOCK TABLE. handler::lock_table() */
 
264
#define HA_LOCK_IN_SHARE_MODE      F_RDLCK
 
265
#define HA_LOCK_IN_EXCLUSIVE_MODE  F_WRLCK
 
266
 
 
267
/* Some key definitions */
 
268
#define HA_KEY_NULL_LENGTH      1
 
269
#define HA_KEY_BLOB_LENGTH      2
 
270
 
 
271
#define HA_LEX_CREATE_TMP_TABLE 1
 
272
#define HA_LEX_CREATE_IF_NOT_EXISTS 2
 
273
#define HA_LEX_CREATE_TABLE_LIKE 4
 
274
#define HA_OPTION_NO_CHECKSUM   (1L << 17)
 
275
#define HA_OPTION_NO_DELAY_KEY_WRITE (1L << 18)
 
276
#define HA_MAX_REC_LENGTH       65535
 
277
 
 
278
/* Table caching type */
 
279
#define HA_CACHE_TBL_NONTRANSACT 0
 
280
#define HA_CACHE_TBL_NOCACHE     1
 
281
#define HA_CACHE_TBL_ASKTRANSACT 2
 
282
#define HA_CACHE_TBL_TRANSACT    4
 
283
 
 
284
/* Options of START TRANSACTION statement (and later of SET TRANSACTION stmt) */
 
285
#define MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT 1
 
286
 
 
287
/* Flags for method is_fatal_error */
 
288
#define HA_CHECK_DUP_KEY 1
 
289
#define HA_CHECK_DUP_UNIQUE 2
 
290
#define HA_CHECK_DUP (HA_CHECK_DUP_KEY + HA_CHECK_DUP_UNIQUE)
 
291
 
 
292
enum legacy_db_type
 
293
{
 
294
  DB_TYPE_UNKNOWN=0,DB_TYPE_DIAB_ISAM=1,
 
295
  DB_TYPE_HASH,DB_TYPE_MISAM,DB_TYPE_PISAM,
 
296
  DB_TYPE_RMS_ISAM, DB_TYPE_HEAP, DB_TYPE_ISAM,
 
297
  DB_TYPE_MRG_ISAM, DB_TYPE_MYISAM, DB_TYPE_MRG_MYISAM,
 
298
  DB_TYPE_BERKELEY_DB, DB_TYPE_INNODB,
 
299
  DB_TYPE_GEMINI, DB_TYPE_NDBCLUSTER,
 
300
  DB_TYPE_EXAMPLE_DB, DB_TYPE_ARCHIVE_DB, DB_TYPE_CSV_DB,
 
301
  DB_TYPE_FEDERATED_DB,
 
302
  DB_TYPE_BLACKHOLE_DB,
 
303
  DB_TYPE_PARTITION_DB,
 
304
  DB_TYPE_BINLOG,
 
305
  DB_TYPE_SOLID,
 
306
  DB_TYPE_PBXT,
 
307
  DB_TYPE_TABLE_FUNCTION,
 
308
  DB_TYPE_MEMCACHE,
 
309
  DB_TYPE_FALCON,
 
310
  DB_TYPE_MARIA,
 
311
  DB_TYPE_FIRST_DYNAMIC=42,
 
312
  DB_TYPE_DEFAULT=127 // Must be last
 
313
};
 
314
 
 
315
enum row_type { ROW_TYPE_NOT_USED=-1, ROW_TYPE_DEFAULT, ROW_TYPE_FIXED,
 
316
                ROW_TYPE_DYNAMIC, ROW_TYPE_COMPRESSED,
 
317
                ROW_TYPE_REDUNDANT, ROW_TYPE_COMPACT, ROW_TYPE_PAGE };
 
318
 
 
319
enum column_format_type { COLUMN_FORMAT_TYPE_NOT_USED= -1,
 
320
                          COLUMN_FORMAT_TYPE_DEFAULT=   0,
 
321
                          COLUMN_FORMAT_TYPE_FIXED=     1,
 
322
                          COLUMN_FORMAT_TYPE_DYNAMIC=   2 };
 
323
 
 
324
enum enum_binlog_func {
 
325
  BFN_RESET_LOGS=        1,
 
326
  BFN_RESET_SLAVE=       2,
 
327
  BFN_BINLOG_WAIT=       3,
 
328
  BFN_BINLOG_END=        4,
 
329
  BFN_BINLOG_PURGE_FILE= 5
 
330
};
 
331
 
 
332
enum enum_binlog_command {
 
333
  LOGCOM_CREATE_TABLE,
 
334
  LOGCOM_ALTER_TABLE,
 
335
  LOGCOM_RENAME_TABLE,
 
336
  LOGCOM_DROP_TABLE,
 
337
  LOGCOM_CREATE_DB,
 
338
  LOGCOM_ALTER_DB,
 
339
  LOGCOM_DROP_DB
 
340
};
 
341
 
 
342
/* struct to hold information about the table that should be created */
 
343
 
 
344
/* Bits in used_fields */
 
345
#define HA_CREATE_USED_AUTO             (1L << 0)
 
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_INSERT_METHOD    (1L << 3)
 
349
#define HA_CREATE_USED_MIN_ROWS         (1L << 4)
 
350
#define HA_CREATE_USED_MAX_ROWS         (1L << 5)
 
351
#define HA_CREATE_USED_AVG_ROW_LENGTH   (1L << 6)
 
352
#define HA_CREATE_USED_PACK_KEYS        (1L << 7)
 
353
#define HA_CREATE_USED_CHARSET          (1L << 8)
 
354
#define HA_CREATE_USED_DEFAULT_CHARSET  (1L << 9)
 
355
#define HA_CREATE_USED_DATADIR          (1L << 10)
 
356
#define HA_CREATE_USED_INDEXDIR         (1L << 11)
 
357
#define HA_CREATE_USED_ENGINE           (1L << 12)
 
358
#define HA_CREATE_USED_CHECKSUM         (1L << 13)
 
359
#define HA_CREATE_USED_DELAY_KEY_WRITE  (1L << 14)
 
360
#define HA_CREATE_USED_ROW_FORMAT       (1L << 15)
 
361
#define HA_CREATE_USED_COMMENT          (1L << 16)
 
362
#define HA_CREATE_USED_PASSWORD         (1L << 17)
 
363
#define HA_CREATE_USED_CONNECTION       (1L << 18)
 
364
#define HA_CREATE_USED_KEY_BLOCK_SIZE   (1L << 19)
 
365
#define HA_CREATE_USED_TRANSACTIONAL    (1L << 20)
 
366
#define HA_CREATE_USED_PAGE_CHECKSUM    (1L << 21)
 
367
 
 
368
typedef uint64_t my_xid; // this line is the same as in log_event.h
 
369
#define MYSQL_XID_PREFIX "MySQLXid"
 
370
#define MYSQL_XID_PREFIX_LEN 8 // must be a multiple of 8
 
371
#define MYSQL_XID_OFFSET (MYSQL_XID_PREFIX_LEN+sizeof(server_id))
 
372
#define MYSQL_XID_GTRID_LEN (MYSQL_XID_OFFSET+sizeof(my_xid))
 
373
 
 
374
#define XIDDATASIZE MYSQL_XIDDATASIZE
 
375
#define MAXGTRIDSIZE 64
 
376
#define MAXBQUALSIZE 64
 
377
 
 
378
#define COMPATIBLE_DATA_YES 0
 
379
#define COMPATIBLE_DATA_NO  1
 
380
 
 
381
/**
 
382
  struct xid_t is binary compatible with the XID structure as
 
383
  in the X/Open CAE Specification, Distributed Transaction Processing:
 
384
  The XA Specification, X/Open Company Ltd., 1991.
 
385
  http://www.opengroup.org/bookstore/catalog/c193.htm
 
386
 
 
387
  @see MYSQL_XID in mysql/plugin.h
 
388
*/
 
389
struct xid_t {
 
390
  long formatID;
 
391
  long gtrid_length;
 
392
  long bqual_length;
 
393
  char data[XIDDATASIZE];  // not \0-terminated !
 
394
 
 
395
  xid_t() {}                                /* Remove gcc warning */  
 
396
  bool eq(struct xid_t *xid)
 
397
  { return eq(xid->gtrid_length, xid->bqual_length, xid->data); }
 
398
  bool eq(long g, long b, const char *d)
 
399
  { return g == gtrid_length && b == bqual_length && !memcmp(d, data, g+b); }
 
400
  void set(struct xid_t *xid)
 
401
  { memcpy(this, xid, xid->length()); }
 
402
  void set(long f, const char *g, long gl, const char *b, long bl)
 
403
  {
 
404
    formatID= f;
 
405
    memcpy(data, g, gtrid_length= gl);
 
406
    memcpy(data+gl, b, bqual_length= bl);
 
407
  }
 
408
  void set(uint64_t xid)
 
409
  {
 
410
    my_xid tmp;
 
411
    formatID= 1;
 
412
    set(MYSQL_XID_PREFIX_LEN, 0, MYSQL_XID_PREFIX);
 
413
    memcpy(data+MYSQL_XID_PREFIX_LEN, &server_id, sizeof(server_id));
 
414
    tmp= xid;
 
415
    memcpy(data+MYSQL_XID_OFFSET, &tmp, sizeof(tmp));
 
416
    gtrid_length=MYSQL_XID_GTRID_LEN;
 
417
  }
 
418
  void set(long g, long b, const char *d)
 
419
  {
 
420
    formatID= 1;
 
421
    gtrid_length= g;
 
422
    bqual_length= b;
 
423
    memcpy(data, d, g+b);
 
424
  }
 
425
  bool is_null() { return formatID == -1; }
 
426
  void null() { formatID= -1; }
 
427
  my_xid quick_get_my_xid()
 
428
  {
 
429
    my_xid tmp;
 
430
    memcpy(&tmp, data+MYSQL_XID_OFFSET, sizeof(tmp));
 
431
    return tmp;
 
432
  }
 
433
  my_xid get_my_xid()
 
434
  {
 
435
    return gtrid_length == MYSQL_XID_GTRID_LEN && bqual_length == 0 &&
 
436
           !memcmp(data+MYSQL_XID_PREFIX_LEN, &server_id, sizeof(server_id)) &&
 
437
           !memcmp(data, MYSQL_XID_PREFIX, MYSQL_XID_PREFIX_LEN) ?
 
438
           quick_get_my_xid() : 0;
 
439
  }
 
440
  uint length()
 
441
  {
 
442
    return sizeof(formatID)+sizeof(gtrid_length)+sizeof(bqual_length)+
 
443
           gtrid_length+bqual_length;
 
444
  }
 
445
  uchar *key()
 
446
  {
 
447
    return (uchar *)&gtrid_length;
 
448
  }
 
449
  uint key_length()
 
450
  {
 
451
    return sizeof(gtrid_length)+sizeof(bqual_length)+gtrid_length+bqual_length;
 
452
  }
 
453
};
 
454
typedef struct xid_t XID;
 
455
 
 
456
/* for recover() handlerton call */
 
457
#define MIN_XID_LIST_SIZE  128
 
458
#define MAX_XID_LIST_SIZE  (1024*128)
 
459
 
 
460
struct handlerton;
 
461
 
 
462
/* The handler for a table type.  Will be included in the TABLE structure */
 
463
 
 
464
struct st_table;
 
465
typedef struct st_table TABLE;
 
466
typedef struct st_table_share TABLE_SHARE;
 
467
struct st_foreign_key_info;
 
468
typedef struct st_foreign_key_info FOREIGN_KEY_INFO;
 
469
typedef bool (stat_print_fn)(THD *thd, const char *type, uint type_len,
 
470
                             const char *file, uint file_len,
 
471
                             const char *status, uint status_len);
 
472
enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
 
473
extern st_plugin_int *hton2plugin[MAX_HA];
 
474
 
 
475
/*
 
476
  handlerton is a singleton structure - one instance per storage engine -
 
477
  to provide access to storage engine functionality that works on the
 
478
  "global" level (unlike handler class that works on a per-table basis)
 
479
 
 
480
  usually handlerton instance is defined statically in ha_xxx.cc as
 
481
 
 
482
  static handlerton { ... } xxx_hton;
 
483
 
 
484
  savepoint_*, prepare, recover, and *_by_xid pointers can be 0.
 
485
*/
 
486
struct handlerton
 
487
{
 
488
  /*
 
489
    Historical marker for if the engine is available of not
 
490
  */
 
491
  SHOW_COMP_OPTION state;
 
492
 
 
493
  /*
 
494
    Historical number used for frm file to determine the correct storage engine.
 
495
    This is going away and new engines will just use "name" for this.
 
496
  */
 
497
  enum legacy_db_type db_type;
 
498
  /*
 
499
    each storage engine has it's own memory area (actually a pointer)
 
500
    in the thd, for storing per-connection information.
 
501
    It is accessed as
 
502
 
 
503
      thd->ha_data[xxx_hton.slot]
 
504
 
 
505
   slot number is initialized by MySQL after xxx_init() is called.
 
506
   */
 
507
   uint slot;
 
508
   /*
 
509
     to store per-savepoint data storage engine is provided with an area
 
510
     of a requested size (0 is ok here).
 
511
     savepoint_offset must be initialized statically to the size of
 
512
     the needed memory to store per-savepoint information.
 
513
     After xxx_init it is changed to be an offset to savepoint storage
 
514
     area and need not be used by storage engine.
 
515
     see binlog_hton and binlog_savepoint_set/rollback for an example.
 
516
   */
 
517
   uint savepoint_offset;
 
518
   /*
 
519
     handlerton methods:
 
520
 
 
521
     close_connection is only called if
 
522
     thd->ha_data[xxx_hton.slot] is non-zero, so even if you don't need
 
523
     this storage area - set it to something, so that MySQL would know
 
524
     this storage engine was accessed in this connection
 
525
   */
 
526
   int  (*close_connection)(handlerton *hton, THD *thd);
 
527
   /*
 
528
     sv points to an uninitialized storage area of requested size
 
529
     (see savepoint_offset description)
 
530
   */
 
531
   int  (*savepoint_set)(handlerton *hton, THD *thd, void *sv);
 
532
   /*
 
533
     sv points to a storage area, that was earlier passed
 
534
     to the savepoint_set call
 
535
   */
 
536
   int  (*savepoint_rollback)(handlerton *hton, THD *thd, void *sv);
 
537
   int  (*savepoint_release)(handlerton *hton, THD *thd, void *sv);
 
538
   /*
 
539
     'all' is true if it's a real commit, that makes persistent changes
 
540
     'all' is false if it's not in fact a commit but an end of the
 
541
     statement that is part of the transaction.
 
542
     NOTE 'all' is also false in auto-commit mode where 'end of statement'
 
543
     and 'real commit' mean the same event.
 
544
   */
 
545
   int  (*commit)(handlerton *hton, THD *thd, bool all);
 
546
   int  (*rollback)(handlerton *hton, THD *thd, bool all);
 
547
   int  (*prepare)(handlerton *hton, THD *thd, bool all);
 
548
   int  (*recover)(handlerton *hton, XID *xid_list, uint len);
 
549
   int  (*commit_by_xid)(handlerton *hton, XID *xid);
 
550
   int  (*rollback_by_xid)(handlerton *hton, XID *xid);
 
551
   void *(*create_cursor_read_view)(handlerton *hton, THD *thd);
 
552
   void (*set_cursor_read_view)(handlerton *hton, THD *thd, void *read_view);
 
553
   void (*close_cursor_read_view)(handlerton *hton, THD *thd, void *read_view);
 
554
   handler *(*create)(handlerton *hton, TABLE_SHARE *table, MEM_ROOT *mem_root);
 
555
   void (*drop_database)(handlerton *hton, char* path);
 
556
   int (*panic)(handlerton *hton, enum ha_panic_function flag);
 
557
   int (*start_consistent_snapshot)(handlerton *hton, THD *thd);
 
558
   bool (*flush_logs)(handlerton *hton);
 
559
   bool (*show_status)(handlerton *hton, THD *thd, stat_print_fn *print, enum ha_stat_type stat);
 
560
   int (*fill_files_table)(handlerton *hton, THD *thd,
 
561
                           TABLE_LIST *tables,
 
562
                           class Item *cond);
 
563
   uint32 flags;                                /* global handler flags */
 
564
   int (*release_temporary_latches)(handlerton *hton, THD *thd);
 
565
 
 
566
   int (*discover)(handlerton *hton, THD* thd, const char *db, 
 
567
                   const char *name,
 
568
                   uchar **frmblob, 
 
569
                   size_t *frmlen);
 
570
   int (*table_exists_in_engine)(handlerton *hton, THD* thd, const char *db,
 
571
                                 const char *name);
 
572
   uint32 license; /* Flag for Engine License */
 
573
   void *data; /* Location for engines to keep personal structures */
 
574
};
 
575
 
 
576
 
 
577
/* Possible flags of a handlerton (there can be 32 of them) */
 
578
#define HTON_NO_FLAGS                 0
 
579
#define HTON_CLOSE_CURSORS_AT_COMMIT (1 << 0)
 
580
#define HTON_ALTER_NOT_SUPPORTED     (1 << 1) //Engine does not support alter
 
581
#define HTON_CAN_RECREATE            (1 << 2) //Delete all is used fro truncate
 
582
#define HTON_HIDDEN                  (1 << 3) //Engine does not appear in lists
 
583
#define HTON_FLUSH_AFTER_RENAME      (1 << 4)
 
584
#define HTON_NOT_USER_SELECTABLE     (1 << 5)
 
585
#define HTON_TEMPORARY_NOT_SUPPORTED (1 << 6) //Having temporary tables not supported
 
586
#define HTON_SUPPORT_LOG_TABLES      (1 << 7) //Engine supports log tables
 
587
#define HTON_NO_PARTITION            (1 << 8) //You can not partition these tables
 
588
 
 
589
class Ha_trx_info;
 
590
 
 
591
struct THD_TRANS
 
592
{
 
593
  /* true is not all entries in the ht[] support 2pc */
 
594
  bool        no_2pc;
 
595
  /* storage engines that registered in this transaction */
 
596
  Ha_trx_info *ha_list;
 
597
  /* 
 
598
    The purpose of this flag is to keep track of non-transactional
 
599
    tables that were modified in scope of:
 
600
    - transaction, when the variable is a member of
 
601
    THD::transaction.all
 
602
    - top-level statement or sub-statement, when the variable is a
 
603
    member of THD::transaction.stmt
 
604
    This member has the following life cycle:
 
605
    * stmt.modified_non_trans_table is used to keep track of
 
606
    modified non-transactional tables of top-level statements. At
 
607
    the end of the previous statement and at the beginning of the session,
 
608
    it is reset to FALSE.  If such functions
 
609
    as mysql_insert, mysql_update, mysql_delete etc modify a
 
610
    non-transactional table, they set this flag to TRUE.  At the
 
611
    end of the statement, the value of stmt.modified_non_trans_table 
 
612
    is merged with all.modified_non_trans_table and gets reset.
 
613
    * all.modified_non_trans_table is reset at the end of transaction
 
614
    
 
615
    * Since we do not have a dedicated context for execution of a
 
616
    sub-statement, to keep track of non-transactional changes in a
 
617
    sub-statement, we re-use stmt.modified_non_trans_table. 
 
618
    At entrance into a sub-statement, a copy of the value of
 
619
    stmt.modified_non_trans_table (containing the changes of the
 
620
    outer statement) is saved on stack. Then 
 
621
    stmt.modified_non_trans_table is reset to FALSE and the
 
622
    substatement is executed. Then the new value is merged with the
 
623
    saved value.
 
624
  */
 
625
  bool modified_non_trans_table;
 
626
 
 
627
  void reset() { no_2pc= FALSE; modified_non_trans_table= FALSE; }
 
628
};
 
629
 
 
630
 
 
631
/**
 
632
  Either statement transaction or normal transaction - related
 
633
  thread-specific storage engine data.
 
634
 
 
635
  If a storage engine participates in a statement/transaction,
 
636
  an instance of this class is present in
 
637
  thd->transaction.{stmt|all}.ha_list. The addition to
 
638
  {stmt|all}.ha_list is made by trans_register_ha().
 
639
 
 
640
  When it's time to commit or rollback, each element of ha_list
 
641
  is used to access storage engine's prepare()/commit()/rollback()
 
642
  methods, and also to evaluate if a full two phase commit is
 
643
  necessary.
 
644
 
 
645
  @sa General description of transaction handling in handler.cc.
 
646
*/
 
647
 
 
648
class Ha_trx_info
 
649
{
 
650
public:
 
651
  /** Register this storage engine in the given transaction context. */
 
652
  void register_ha(THD_TRANS *trans, handlerton *ht_arg)
 
653
  {
 
654
    DBUG_ASSERT(m_flags == 0);
 
655
    DBUG_ASSERT(m_ht == NULL);
 
656
    DBUG_ASSERT(m_next == NULL);
 
657
 
 
658
    m_ht= ht_arg;
 
659
    m_flags= (int) TRX_READ_ONLY; /* Assume read-only at start. */
 
660
 
 
661
    m_next= trans->ha_list;
 
662
    trans->ha_list= this;
 
663
  }
 
664
 
 
665
  /** Clear, prepare for reuse. */
 
666
  void reset()
 
667
  {
 
668
    m_next= NULL;
 
669
    m_ht= NULL;
 
670
    m_flags= 0;
 
671
  }
 
672
 
 
673
  Ha_trx_info() { reset(); }
 
674
 
 
675
  void set_trx_read_write()
 
676
  {
 
677
    DBUG_ASSERT(is_started());
 
678
    m_flags|= (int) TRX_READ_WRITE;
 
679
  }
 
680
  bool is_trx_read_write() const
 
681
  {
 
682
    DBUG_ASSERT(is_started());
 
683
    return m_flags & (int) TRX_READ_WRITE;
 
684
  }
 
685
  bool is_started() const { return m_ht != NULL; }
 
686
  /** Mark this transaction read-write if the argument is read-write. */
 
687
  void coalesce_trx_with(const Ha_trx_info *stmt_trx)
 
688
  {
 
689
    /*
 
690
      Must be called only after the transaction has been started.
 
691
      Can be called many times, e.g. when we have many
 
692
      read-write statements in a transaction.
 
693
    */
 
694
    DBUG_ASSERT(is_started());
 
695
    if (stmt_trx->is_trx_read_write())
 
696
      set_trx_read_write();
 
697
  }
 
698
  Ha_trx_info *next() const
 
699
  {
 
700
    DBUG_ASSERT(is_started());
 
701
    return m_next;
 
702
  }
 
703
  handlerton *ht() const
 
704
  {
 
705
    DBUG_ASSERT(is_started());
 
706
    return m_ht;
 
707
  }
 
708
private:
 
709
  enum { TRX_READ_ONLY= 0, TRX_READ_WRITE= 1 };
 
710
  /** Auxiliary, used for ha_list management */
 
711
  Ha_trx_info *m_next;
 
712
  /**
 
713
    Although a given Ha_trx_info instance is currently always used
 
714
    for the same storage engine, 'ht' is not-NULL only when the
 
715
    corresponding storage is a part of a transaction.
 
716
  */
 
717
  handlerton *m_ht;
 
718
  /**
 
719
    Transaction flags related to this engine.
 
720
    Not-null only if this instance is a part of transaction.
 
721
    May assume a combination of enum values above.
 
722
  */
 
723
  uchar       m_flags;
 
724
};
 
725
 
 
726
 
 
727
enum enum_tx_isolation { ISO_READ_UNCOMMITTED, ISO_READ_COMMITTED,
 
728
                         ISO_REPEATABLE_READ, ISO_SERIALIZABLE};
 
729
 
 
730
 
 
731
enum ndb_distribution { ND_KEYHASH= 0, ND_LINHASH= 1 };
 
732
 
 
733
 
 
734
typedef struct {
 
735
  uint64_t data_file_length;
 
736
  uint64_t max_data_file_length;
 
737
  uint64_t index_file_length;
 
738
  uint64_t delete_length;
 
739
  ha_rows records;
 
740
  uint32_t mean_rec_length;
 
741
  time_t create_time;
 
742
  time_t check_time;
 
743
  time_t update_time;
 
744
  uint64_t check_sum;
 
745
} PARTITION_INFO;
 
746
 
 
747
#define UNDEF_NODEGROUP 65535
60
748
class Item;
61
 
 
62
 
class LEX;
63
 
class Select_Lex;
64
 
class AlterInfo;
65
 
class select_result;
66
 
class CreateField;
67
 
class sys_var_str;
68
 
class Item_ident;
69
 
 
70
 
typedef List<Item> List_item;
 
749
struct st_table_log_memory_entry;
 
750
 
 
751
#define NOT_A_PARTITION_ID ((uint32)-1)
 
752
 
 
753
enum ha_choice { HA_CHOICE_UNDEF, HA_CHOICE_NO, HA_CHOICE_YES };
 
754
 
 
755
typedef struct st_ha_create_information
 
756
{
 
757
  CHARSET_INFO *table_charset, *default_table_charset;
 
758
  LEX_STRING connect_string;
 
759
  LEX_STRING comment;
 
760
  const char *data_file_name, *index_file_name;
 
761
  const char *alias;
 
762
  uint64_t max_rows,min_rows;
 
763
  uint64_t auto_increment_value;
 
764
  uint32_t table_options;
 
765
  uint32_t avg_row_length;
 
766
  uint32_t used_fields;
 
767
  uint32_t key_block_size;
 
768
  SQL_LIST merge_list;
 
769
  handlerton *db_type;
 
770
  enum row_type row_type;
 
771
  uint null_bits;                       /* NULL bits at start of record */
 
772
  uint options;                         /* OR of HA_CREATE_ options */
 
773
  uint merge_insert_method;
 
774
  uint extra_size;                      /* length of extra data segment */
 
775
  /* 0 not used, 1 if not transactional, 2 if transactional */
 
776
  enum ha_choice transactional;
 
777
  bool table_existed;                   /* 1 in create if table existed */
 
778
  bool frm_only;                        /* 1 if no ha_create_table() */
 
779
  bool varchar;                         /* 1 if table has a VARCHAR */
 
780
  enum ha_choice page_checksum;         /* If we have page_checksums */
 
781
} HA_CREATE_INFO;
 
782
 
 
783
typedef struct st_ha_alter_information
 
784
{
 
785
  KEY  *key_info_buffer;
 
786
  uint key_count;
 
787
  uint index_drop_count;
 
788
  uint *index_drop_buffer;
 
789
  uint index_add_count;
 
790
  uint *index_add_buffer;
 
791
  void *data;
 
792
} HA_ALTER_INFO;
 
793
 
 
794
 
 
795
typedef struct st_key_create_information
 
796
{
 
797
  enum ha_key_alg algorithm;
 
798
  uint32_t block_size;
 
799
  LEX_STRING parser_name;
 
800
  LEX_STRING comment;
 
801
} KEY_CREATE_INFO;
 
802
 
 
803
 
 
804
/*
 
805
  Class for maintaining hooks used inside operations on tables such
 
806
  as: create table functions, delete table functions, and alter table
 
807
  functions.
 
808
 
 
809
  Class is using the Template Method pattern to separate the public
 
810
  usage interface from the private inheritance interface.  This
 
811
  imposes no overhead, since the public non-virtual function is small
 
812
  enough to be inlined.
 
813
 
 
814
  The hooks are usually used for functions that does several things,
 
815
  e.g., create_table_from_items(), which both create a table and lock
 
816
  it.
 
817
 */
 
818
class TABLEOP_HOOKS
 
819
{
 
820
public:
 
821
  TABLEOP_HOOKS() {}
 
822
  virtual ~TABLEOP_HOOKS() {}
 
823
 
 
824
  inline void prelock(TABLE **tables, uint count)
 
825
  {
 
826
    do_prelock(tables, count);
 
827
  }
 
828
 
 
829
  inline int postlock(TABLE **tables, uint count)
 
830
  {
 
831
    return do_postlock(tables, count);
 
832
  }
 
833
private:
 
834
  /* Function primitive that is called prior to locking tables */
 
835
  virtual void do_prelock(TABLE **tables __attribute__((__unused__)),
 
836
                          uint count __attribute__((__unused__)))
 
837
  {
 
838
    /* Default is to do nothing */
 
839
  }
 
840
 
 
841
  /**
 
842
     Primitive called after tables are locked.
 
843
 
 
844
     If an error is returned, the tables will be unlocked and error
 
845
     handling start.
 
846
 
 
847
     @return Error code or zero.
 
848
   */
 
849
  virtual int do_postlock(TABLE **tables __attribute__((__unused__)),
 
850
                          uint count __attribute__((__unused__)))
 
851
  {
 
852
    return 0;                           /* Default is to do nothing */
 
853
  }
 
854
};
 
855
 
 
856
typedef struct st_savepoint SAVEPOINT;
 
857
extern uint32_t savepoint_alloc_size;
71
858
extern KEY_CREATE_INFO default_key_create_info;
72
859
 
73
860
/* Forward declaration for condition pushdown to storage engine */
74
861
typedef class Item COND;
75
862
 
76
 
typedef struct system_status_var system_status_var;
77
 
 
78
 
namespace optimizer
79
 
{
80
 
  class CostVector;
81
 
}
82
 
 
 
863
typedef struct st_ha_check_opt
 
864
{
 
865
  st_ha_check_opt() {}                        /* Remove gcc warning */
 
866
  uint32_t sort_buffer_size;
 
867
  uint flags;       /* isam layer flags (e.g. for myisamchk) */
 
868
  uint sql_flags;   /* sql layer flags - for something myisamchk cannot do */
 
869
  KEY_CACHE *key_cache; /* new key cache when changing key cache */
 
870
  void init();
 
871
} HA_CHECK_OPT;
 
872
 
 
873
 
 
874
 
 
875
/*
 
876
  This is a buffer area that the handler can use to store rows.
 
877
  'end_of_used_area' should be kept updated after calls to
 
878
  read-functions so that other parts of the code can use the
 
879
  remaining area (until next read calls is issued).
 
880
*/
 
881
 
 
882
typedef struct st_handler_buffer
 
883
{
 
884
  uchar *buffer;         /* Buffer one can start using */
 
885
  uchar *buffer_end;     /* End of buffer */
 
886
  uchar *end_of_used_area;     /* End of area that was used by handler */
 
887
} HANDLER_BUFFER;
 
888
 
 
889
typedef struct system_status_var SSV;
 
890
 
 
891
 
 
892
typedef void *range_seq_t;
 
893
 
 
894
typedef struct st_range_seq_if
 
895
{
 
896
  /*
 
897
    Initialize the traversal of range sequence
 
898
    
 
899
    SYNOPSIS
 
900
      init()
 
901
        init_params  The seq_init_param parameter 
 
902
        n_ranges     The number of ranges obtained 
 
903
        flags        A combination of HA_MRR_SINGLE_POINT, HA_MRR_FIXED_KEY
 
904
 
 
905
    RETURN
 
906
      An opaque value to be used as RANGE_SEQ_IF::next() parameter
 
907
  */
 
908
  range_seq_t (*init)(void *init_params, uint n_ranges, uint flags);
 
909
 
 
910
 
 
911
  /*
 
912
    Get the next range in the range sequence
 
913
 
 
914
    SYNOPSIS
 
915
      next()
 
916
        seq    The value returned by RANGE_SEQ_IF::init()
 
917
        range  OUT Information about the next range
 
918
    
 
919
    RETURN
 
920
      0 - Ok, the range structure filled with info about the next range
 
921
      1 - No more ranges
 
922
  */
 
923
  uint (*next) (range_seq_t seq, KEY_MULTI_RANGE *range);
 
924
} RANGE_SEQ_IF;
 
925
 
 
926
uint16 &mrr_persistent_flag_storage(range_seq_t seq, uint idx);
 
927
char* &mrr_get_ptr_by_idx(range_seq_t seq, uint idx);
 
928
 
 
929
class COST_VECT
 
930
 
931
public:
 
932
  double io_count;     /* number of I/O                 */
 
933
  double avg_io_cost;  /* cost of an average I/O oper.  */
 
934
  double cpu_cost;     /* cost of operations in CPU     */
 
935
  double mem_cost;     /* cost of used memory           */ 
 
936
  double import_cost;  /* cost of remote operations     */
 
937
  
 
938
  enum { IO_COEFF=1 };
 
939
  enum { CPU_COEFF=1 };
 
940
  enum { MEM_COEFF=1 };
 
941
  enum { IMPORT_COEFF=1 };
 
942
 
 
943
  COST_VECT() {}                              // keep gcc happy
 
944
 
 
945
  double total_cost() 
 
946
  {
 
947
    return IO_COEFF*io_count*avg_io_cost + CPU_COEFF * cpu_cost +
 
948
           MEM_COEFF*mem_cost + IMPORT_COEFF*import_cost;
 
949
  }
 
950
 
 
951
  void zero()
 
952
  {
 
953
    avg_io_cost= 1.0;
 
954
    io_count= cpu_cost= mem_cost= import_cost= 0.0;
 
955
  }
 
956
 
 
957
  void multiply(double m)
 
958
  {
 
959
    io_count *= m;
 
960
    cpu_cost *= m;
 
961
    import_cost *= m;
 
962
    /* Don't multiply mem_cost */
 
963
  }
 
964
 
 
965
  void add(const COST_VECT* cost)
 
966
  {
 
967
    double io_count_sum= io_count + cost->io_count;
 
968
    add_io(cost->io_count, cost->avg_io_cost);
 
969
    io_count= io_count_sum;
 
970
    cpu_cost += cost->cpu_cost;
 
971
  }
 
972
  void add_io(double add_io_cnt, double add_avg_cost)
 
973
  {
 
974
    double io_count_sum= io_count + add_io_cnt;
 
975
    avg_io_cost= (io_count * avg_io_cost + 
 
976
                  add_io_cnt * add_avg_cost) / io_count_sum;
 
977
    io_count= io_count_sum;
 
978
  }
 
979
};
 
980
 
 
981
void get_sweep_read_cost(TABLE *table, ha_rows nrows, bool interrupted, 
 
982
                         COST_VECT *cost);
 
983
 
 
984
/*
 
985
  The below two are not used (and not handled) in this milestone of this WL
 
986
  entry because there seems to be no use for them at this stage of
 
987
  implementation.
 
988
*/
 
989
#define HA_MRR_SINGLE_POINT 1
 
990
#define HA_MRR_FIXED_KEY  2
 
991
 
 
992
/* 
 
993
  Indicates that RANGE_SEQ_IF::next(&range) doesn't need to fill in the
 
994
  'range' parameter.
 
995
*/
 
996
#define HA_MRR_NO_ASSOCIATION 4
 
997
 
 
998
/* 
 
999
  The MRR user will provide ranges in key order, and MRR implementation
 
1000
  must return rows in key order.
 
1001
*/
 
1002
#define HA_MRR_SORTED 8
 
1003
 
 
1004
/* MRR implementation doesn't have to retrieve full records */
 
1005
#define HA_MRR_INDEX_ONLY 16
 
1006
 
 
1007
/* 
 
1008
  The passed memory buffer is of maximum possible size, the caller can't
 
1009
  assume larger buffer.
 
1010
*/
 
1011
#define HA_MRR_LIMITS 32
 
1012
 
 
1013
 
 
1014
/*
 
1015
  Flag set <=> default MRR implementation is used
 
1016
  (The choice is made by **_info[_const]() function which may set this
 
1017
   flag. SQL layer remembers the flag value and then passes it to
 
1018
   multi_read_range_init().
 
1019
*/
 
1020
#define HA_MRR_USE_DEFAULT_IMPL 64
 
1021
 
 
1022
/*
 
1023
  Used only as parameter to multi_range_read_info():
 
1024
  Flag set <=> the caller guarantees that the bounds of the scanned ranges
 
1025
  will not have NULL values.
 
1026
*/
 
1027
#define HA_MRR_NO_NULL_ENDPOINTS 128
 
1028
 
 
1029
 
 
1030
class ha_statistics
 
1031
{
 
1032
public:
 
1033
  uint64_t data_file_length;            /* Length off data file */
 
1034
  uint64_t max_data_file_length;        /* Length off data file */
 
1035
  uint64_t index_file_length;
 
1036
  uint64_t max_index_file_length;
 
1037
  uint64_t delete_length;               /* Free bytes */
 
1038
  uint64_t auto_increment_value;
 
1039
  /*
 
1040
    The number of records in the table. 
 
1041
      0    - means the table has exactly 0 rows
 
1042
    other  - if (table_flags() & HA_STATS_RECORDS_IS_EXACT)
 
1043
               the value is the exact number of records in the table
 
1044
             else
 
1045
               it is an estimate
 
1046
  */
 
1047
  ha_rows records;
 
1048
  ha_rows deleted;                      /* Deleted records */
 
1049
  uint32_t mean_rec_length;             /* physical reclength */
 
1050
  time_t create_time;                   /* When table was created */
 
1051
  time_t check_time;
 
1052
  time_t update_time;
 
1053
  uint block_size;                      /* index block size */
 
1054
 
 
1055
  ha_statistics():
 
1056
    data_file_length(0), max_data_file_length(0),
 
1057
    index_file_length(0), delete_length(0), auto_increment_value(0),
 
1058
    records(0), deleted(0), mean_rec_length(0), create_time(0),
 
1059
    check_time(0), update_time(0), block_size(0)
 
1060
  {}
 
1061
};
 
1062
 
 
1063
uint calculate_key_len(TABLE *, uint, const uchar *, key_part_map);
83
1064
/*
84
1065
  bitmap with first N+1 bits set
85
1066
  (keypart_map for a key prefix of [0..N] keyparts)
86
1067
*/
87
 
template<class T>
88
 
inline key_part_map make_keypart_map(T a)
89
 
{
90
 
  return (((key_part_map)2 << a) - 1);
91
 
}
92
 
 
 
1068
#define make_keypart_map(N) (((key_part_map)2 << (N)) - 1)
93
1069
/*
94
1070
  bitmap with first N bits set
95
1071
  (keypart_map for a key prefix of [0..N-1] keyparts)
96
1072
*/
97
 
template<class T>
98
 
inline key_part_map make_prev_keypart_map(T a)
99
 
{
100
 
  return (((key_part_map)1 << a) - 1);
101
 
}
 
1073
#define make_prev_keypart_map(N) (((key_part_map)1 << (N)) - 1)
102
1074
 
103
1075
/**
104
 
  The Cursor class is the interface for dynamically loadable
 
1076
  The handler class is the interface for dynamically loadable
105
1077
  storage engines. Do not add ifdefs and take care when adding or
106
1078
  changing virtual functions to avoid vtable confusion
107
1079
 
111
1083
     storage engine
112
1084
 
113
1085
  2. KeyTupleFormat - used to pass index search tuples (aka "keys") to
114
 
     storage engine. See optimizer/range.cc for description of this format.
 
1086
     storage engine. See opt_range.cc for description of this format.
115
1087
 
116
1088
  TableRecordFormat
117
1089
  =================
118
1090
  [Warning: this description is work in progress and may be incomplete]
119
1091
  The table record is stored in a fixed-size buffer:
120
 
 
 
1092
   
121
1093
    record: null_bytes, column1_data, column2_data, ...
122
 
 
123
 
  The offsets of the parts of the buffer are also fixed: every column has
 
1094
  
 
1095
  The offsets of the parts of the buffer are also fixed: every column has 
124
1096
  an offset to its column{i}_data, and if it is nullable it also has its own
125
 
  bit in null_bytes.
 
1097
  bit in null_bytes. 
126
1098
 
127
1099
  The record buffer only includes data about columns that are marked in the
128
1100
  relevant column set (table->read_set and/or table->write_set, depending on
129
 
  the situation).
 
1101
  the situation). 
130
1102
  <not-sure>It could be that it is required that null bits of non-present
131
1103
  columns are set to 1</not-sure>
132
1104
 
133
1105
  VARIOUS EXCEPTIONS AND SPECIAL CASES
134
1106
 
135
 
  f the table has no nullable columns, then null_bytes is still
136
 
  present, its length is one byte <not-sure> which must be set to 0xFF
 
1107
  f the table has no nullable columns, then null_bytes is still 
 
1108
  present, its length is one byte <not-sure> which must be set to 0xFF 
137
1109
  at all times. </not-sure>
 
1110
  
 
1111
  If the table has columns of type BIT, then certain bits from those columns
 
1112
  may be stored in null_bytes as well. Grep around for Field_bit for
 
1113
  details.
138
1114
 
139
 
  For blob columns (see Field_blob), the record buffer stores length of the
140
 
  data, following by memory pointer to the blob data. The pointer is owned
 
1115
  For blob columns (see Field_blob), the record buffer stores length of the 
 
1116
  data, following by memory pointer to the blob data. The pointer is owned 
141
1117
  by the storage engine and is valid until the next operation.
142
1118
 
143
1119
  If a blob column has NULL value, then its length and blob data pointer
144
1120
  must be set to 0.
145
1121
*/
146
 
class Cursor
 
1122
 
 
1123
class handler :public Sql_alloc
147
1124
{
148
 
  Table &table;               /* The current open table */
149
 
  plugin::StorageEngine &engine;      /* storage engine of this Cursor */
150
 
 
 
1125
public:
 
1126
  typedef uint64_t Table_flags;
151
1127
protected:
 
1128
  struct st_table_share *table_share;   /* The table definition */
 
1129
  struct st_table *table;               /* The current open table */
 
1130
  Table_flags cached_table_flags;       /* Set on init() and open() */
 
1131
 
152
1132
  ha_rows estimation_rows_to_insert;
153
 
 
154
1133
public:
155
 
  inline plugin::StorageEngine *getEngine() const       /* table_type for handler */
156
 
  {
157
 
    return &engine;
158
 
  }
159
 
  unsigned char *ref;                           /* Pointer to current row */
160
 
  unsigned char *dup_ref;                       /* Pointer to duplicate row */
161
 
 
162
 
  TableShare *getShare();
163
 
 
164
 
  Table *getTable() const
165
 
  {
166
 
    return &table;
167
 
  }
 
1134
  handlerton *ht;                 /* storage engine of this handler */
 
1135
  uchar *ref;                           /* Pointer to current row */
 
1136
  uchar *dup_ref;                       /* Pointer to duplicate row */
168
1137
 
169
1138
  ha_statistics stats;
170
1139
  /** MultiRangeRead-related members: */
171
1140
  range_seq_t mrr_iter;    /* Interator to traverse the range sequence */
172
1141
  RANGE_SEQ_IF mrr_funcs;  /* Range sequence traversal functions */
173
 
 
174
 
  uint32_t ranges_in_seq; /* Total number of ranges in the traversed sequence */
175
 
  /* true <=> source MRR ranges and the output are ordered */
 
1142
  HANDLER_BUFFER *multi_range_buffer; /* MRR buffer info */
 
1143
  uint ranges_in_seq; /* Total number of ranges in the traversed sequence */
 
1144
  /* TRUE <=> source MRR ranges and the output are ordered */
176
1145
  bool mrr_is_output_sorted;
177
1146
 
178
 
  /** true <=> we're currently traversing a range in mrr_cur_range. */
 
1147
  /** TRUE <=> we're currently traversing a range in mrr_cur_range. */
179
1148
  bool mrr_have_range;
180
 
 
181
 
  bool eq_range;
182
 
 
183
1149
  /** Current range (the one we're now returning rows from) */
184
1150
  KEY_MULTI_RANGE mrr_cur_range;
185
1151
 
186
1152
  /** The following are for read_range() */
187
1153
  key_range save_end_range, *end_range;
188
 
  KeyPartInfo *range_key_part;
 
1154
  KEY_PART_INFO *range_key_part;
189
1155
  int key_compare_result_on_equal;
 
1156
  bool eq_range;
 
1157
  /* 
 
1158
    TRUE <=> the engine guarantees that returned records are within the range
 
1159
    being scanned.
 
1160
  */
 
1161
  bool in_range_check_pushed_down;
190
1162
 
191
 
  uint32_t errkey;                              /* Last dup key */
192
 
  uint32_t key_used_on_scan;
193
 
  uint32_t active_index;
 
1163
  uint errkey;                          /* Last dup key */
 
1164
  uint key_used_on_scan;
 
1165
  uint active_index;
194
1166
  /** Length of ref (1-8 or the clustered key length) */
195
 
  uint32_t ref_length;
 
1167
  uint ref_length;
 
1168
  FT_INFO *ft_handler;
196
1169
  enum {NONE=0, INDEX, RND} inited;
197
1170
  bool locked;
 
1171
  bool implicit_emptied;                /* Can be !=0 only if HEAP */
 
1172
  const Item *pushed_cond;
 
1173
 
 
1174
  Item *pushed_idx_cond;
 
1175
  uint pushed_idx_cond_keyno;  /* The index which the above condition is for */
198
1176
 
199
1177
  /**
200
1178
    next_insert_id is the next value which should be inserted into the
206
1184
    get_auto_increment().
207
1185
  */
208
1186
  uint64_t next_insert_id;
209
 
  uint64_t getNextInsertId()
210
 
  {
211
 
    return next_insert_id;
212
 
  }
213
 
 
214
1187
  /**
215
1188
    insert id for the current row (*autogenerated*; if not
216
1189
    autogenerated, it's 0).
217
1190
    At first successful insertion, this variable is stored into
218
 
    Session::first_successful_insert_id_in_cur_stmt.
 
1191
    THD::first_successful_insert_id_in_cur_stmt.
219
1192
  */
220
1193
  uint64_t insert_id_for_cur_row;
221
1194
  /**
224
1197
  */
225
1198
  Discrete_interval auto_inc_interval_for_cur_row;
226
1199
 
227
 
  Cursor(plugin::StorageEngine &engine_arg, Table &share_arg);
228
 
  virtual ~Cursor(void);
229
 
  virtual Cursor *clone(memory::Root *mem_root);
230
 
 
 
1200
  handler(handlerton *ht_arg, TABLE_SHARE *share_arg)
 
1201
    :table_share(share_arg), table(0),
 
1202
    estimation_rows_to_insert(0), ht(ht_arg),
 
1203
    ref(0), in_range_check_pushed_down(FALSE),
 
1204
    key_used_on_scan(MAX_KEY), active_index(MAX_KEY),
 
1205
    ref_length(sizeof(my_off_t)),
 
1206
    ft_handler(0), inited(NONE),
 
1207
    locked(FALSE), implicit_emptied(0),
 
1208
    pushed_cond(0), pushed_idx_cond(NULL), pushed_idx_cond_keyno(MAX_KEY),
 
1209
    next_insert_id(0), insert_id_for_cur_row(0)
 
1210
    {}
 
1211
  virtual ~handler(void)
 
1212
  {
 
1213
    DBUG_ASSERT(locked == FALSE);
 
1214
    /* TODO: DBUG_ASSERT(inited == NONE); */
 
1215
  }
 
1216
  virtual handler *clone(MEM_ROOT *mem_root);
 
1217
  /** This is called after create to allow us to set up cached variables */
 
1218
  void init()
 
1219
  {
 
1220
    cached_table_flags= table_flags();
 
1221
  }
231
1222
  /* ha_ methods: pubilc wrappers for private virtual API */
232
1223
 
233
 
  int ha_open(const TableIdentifier &identifier, int mode, int test_if_locked);
234
 
  int startIndexScan(uint32_t idx, bool sorted);
235
 
  int endIndexScan();
236
 
  int startTableScan(bool scan);
237
 
  int endTableScan();
 
1224
  int ha_open(TABLE *table, const char *name, int mode, int test_if_locked);
 
1225
  int ha_index_init(uint idx, bool sorted)
 
1226
  {
 
1227
    int result;
 
1228
    DBUG_ENTER("ha_index_init");
 
1229
    DBUG_ASSERT(inited==NONE);
 
1230
    if (!(result= index_init(idx, sorted)))
 
1231
      inited=INDEX;
 
1232
    end_range= NULL;
 
1233
    DBUG_RETURN(result);
 
1234
  }
 
1235
  int ha_index_end()
 
1236
  {
 
1237
    DBUG_ENTER("ha_index_end");
 
1238
    DBUG_ASSERT(inited==INDEX);
 
1239
    inited=NONE;
 
1240
    end_range= NULL;
 
1241
    DBUG_RETURN(index_end());
 
1242
  }
 
1243
  int ha_rnd_init(bool scan)
 
1244
  {
 
1245
    int result;
 
1246
    DBUG_ENTER("ha_rnd_init");
 
1247
    DBUG_ASSERT(inited==NONE || (inited==RND && scan));
 
1248
    inited= (result= rnd_init(scan)) ? NONE: RND;
 
1249
    DBUG_RETURN(result);
 
1250
  }
 
1251
  int ha_rnd_end()
 
1252
  {
 
1253
    DBUG_ENTER("ha_rnd_end");
 
1254
    DBUG_ASSERT(inited==RND);
 
1255
    inited=NONE;
 
1256
    DBUG_RETURN(rnd_end());
 
1257
  }
238
1258
  int ha_reset();
239
 
 
240
1259
  /* this is necessary in many places, e.g. in HANDLER command */
241
 
  int ha_index_or_rnd_end();
242
 
 
 
1260
  int ha_index_or_rnd_end()
 
1261
  {
 
1262
    return inited == INDEX ? ha_index_end() : inited == RND ? ha_rnd_end() : 0;
 
1263
  }
 
1264
  Table_flags ha_table_flags() const { return cached_table_flags; }
243
1265
  /**
244
1266
    These functions represent the public interface to *users* of the
245
 
    Cursor class, hence they are *not* virtual. For the inheritance
246
 
    interface, see the (private) functions doInsertRecord(), doUpdateRecord(),
247
 
    and doDeleteRecord() below.
 
1267
    handler class, hence they are *not* virtual. For the inheritance
 
1268
    interface, see the (private) functions write_row(), update_row(),
 
1269
    and delete_row() below.
248
1270
  */
249
 
  int ha_external_lock(Session *session, int lock_type);
250
 
  int insertRecord(unsigned char * buf);
251
 
  int updateRecord(const unsigned char * old_data, unsigned char * new_data);
252
 
  int deleteRecord(const unsigned char * buf);
 
1271
  int ha_external_lock(THD *thd, int lock_type);
 
1272
  int ha_write_row(uchar * buf);
 
1273
  int ha_update_row(const uchar * old_data, uchar * new_data);
 
1274
  int ha_delete_row(const uchar * buf);
253
1275
  void ha_release_auto_increment();
254
1276
 
 
1277
  int ha_check_for_upgrade(HA_CHECK_OPT *check_opt);
255
1278
  /** to be actually called to get 'check()' functionality*/
256
 
  int ha_check(Session *session, HA_CHECK_OPT *check_opt);
257
 
 
258
 
  void ha_start_bulk_insert(ha_rows rows);
259
 
  int ha_end_bulk_insert();
 
1279
  int ha_check(THD *thd, HA_CHECK_OPT *check_opt);
 
1280
  int ha_repair(THD* thd, HA_CHECK_OPT* check_opt);
 
1281
  void ha_start_bulk_insert(ha_rows rows)
 
1282
  {
 
1283
    estimation_rows_to_insert= rows;
 
1284
    start_bulk_insert(rows);
 
1285
  }
 
1286
  int ha_end_bulk_insert()
 
1287
  {
 
1288
    estimation_rows_to_insert= 0;
 
1289
    return end_bulk_insert();
 
1290
  }
 
1291
  int ha_bulk_update_row(const uchar *old_data, uchar *new_data,
 
1292
                         uint *dup_key_found);
260
1293
  int ha_delete_all_rows();
261
1294
  int ha_reset_auto_increment(uint64_t value);
262
 
  int ha_analyze(Session* session, HA_CHECK_OPT* check_opt);
263
 
 
264
 
  int ha_disable_indexes(uint32_t mode);
265
 
  int ha_enable_indexes(uint32_t mode);
266
 
  int ha_discard_or_import_tablespace(bool discard);
267
 
  void closeMarkForDelete(const char *name);
 
1295
  int ha_optimize(THD* thd, HA_CHECK_OPT* check_opt);
 
1296
  int ha_analyze(THD* thd, HA_CHECK_OPT* check_opt);
 
1297
  bool ha_check_and_repair(THD *thd);
 
1298
  int ha_disable_indexes(uint mode);
 
1299
  int ha_enable_indexes(uint mode);
 
1300
  int ha_discard_or_import_tablespace(my_bool discard);
 
1301
  void ha_prepare_for_alter();
 
1302
  int ha_rename_table(const char *from, const char *to);
 
1303
  int ha_delete_table(const char *name);
 
1304
  void ha_drop_table(const char *name);
 
1305
 
 
1306
  int ha_create(const char *name, TABLE *form, HA_CREATE_INFO *info);
 
1307
 
 
1308
  int ha_create_handler_files(const char *name, const char *old_name,
 
1309
                              int action_flag, HA_CREATE_INFO *info);
268
1310
 
269
1311
  void adjust_next_insert_id_after_explicit_value(uint64_t nr);
270
1312
  int update_auto_increment();
271
 
 
 
1313
  void print_keydup_error(uint key_nr, const char *msg);
 
1314
  virtual void print_error(int error, myf errflag);
 
1315
  virtual bool get_error_message(int error, String *buf);
 
1316
  uint get_dup_key(int error);
 
1317
  virtual void change_table_ptr(TABLE *table_arg, TABLE_SHARE *share)
 
1318
  {
 
1319
    table= table_arg;
 
1320
    table_share= share;
 
1321
  }
272
1322
  /* Estimates calculation */
273
1323
  virtual double scan_time(void)
274
 
  { return uint64_t2double(stats.data_file_length) / IO_SIZE + 2; }
275
 
  virtual double read_time(uint32_t, uint32_t ranges, ha_rows rows)
 
1324
  { return ulonglong2double(stats.data_file_length) / IO_SIZE + 2; }
 
1325
  virtual double read_time(uint index __attribute__((__unused__)),
 
1326
                           uint ranges, ha_rows rows)
276
1327
  { return rows2double(ranges+rows); }
277
1328
 
278
 
  virtual double index_only_read_time(uint32_t keynr, double records);
279
 
 
280
 
  virtual ha_rows multi_range_read_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
281
 
                                              void *seq_init_param,
282
 
                                              uint32_t n_ranges, uint32_t *bufsz,
283
 
                                              uint32_t *flags, optimizer::CostVector *cost);
284
 
  virtual int multi_range_read_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys,
285
 
                                    uint32_t *bufsz, uint32_t *flags, optimizer::CostVector *cost);
 
1329
  virtual double index_only_read_time(uint keynr, double records);
 
1330
  
 
1331
  virtual ha_rows multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq,
 
1332
                                              void *seq_init_param, 
 
1333
                                              uint n_ranges, uint *bufsz,
 
1334
                                              uint *flags, COST_VECT *cost);
 
1335
  virtual int multi_range_read_info(uint keyno, uint n_ranges, uint keys,
 
1336
                                    uint *bufsz, uint *flags, COST_VECT *cost);
286
1337
  virtual int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
287
 
                                    uint32_t n_ranges, uint32_t mode);
 
1338
                                    uint n_ranges, uint mode,
 
1339
                                    HANDLER_BUFFER *buf);
288
1340
  virtual int multi_range_read_next(char **range_info);
289
1341
 
290
1342
 
291
 
  virtual const key_map *keys_to_use_for_scanning();
292
 
  bool has_transactions();
 
1343
  virtual const key_map *keys_to_use_for_scanning() { return &key_map_empty; }
 
1344
  bool has_transactions()
 
1345
  { return (ha_table_flags() & HA_NO_TRANSACTIONS) == 0; }
 
1346
  virtual uint extra_rec_buf_length() const { return 0; }
293
1347
 
294
1348
  /**
295
1349
    This method is used to analyse the error to see whether the error
296
1350
    is ignorable or not, certain handlers can have more error that are
297
 
    ignorable than others. E.g. the partition Cursor can get inserts
 
1351
    ignorable than others. E.g. the partition handler can get inserts
298
1352
    into a range where there is no partition and this is an ignorable
299
1353
    error.
300
1354
    HA_ERR_FOUND_DUP_UNIQUE is a special case in MyISAM that means the
301
1355
    same thing as HA_ERR_FOUND_DUP_KEY but can in some cases lead to
302
1356
    a slightly different error message.
303
1357
  */
304
 
  virtual bool is_fatal_error(int error, uint32_t flags);
 
1358
  virtual bool is_fatal_error(int error, uint flags)
 
1359
  {
 
1360
    if (!error ||
 
1361
        ((flags & HA_CHECK_DUP_KEY) &&
 
1362
         (error == HA_ERR_FOUND_DUPP_KEY ||
 
1363
          error == HA_ERR_FOUND_DUPP_UNIQUE)))
 
1364
      return FALSE;
 
1365
    return TRUE;
 
1366
  }
305
1367
 
306
1368
  /**
307
1369
    Number of rows in table. It will only be called if
308
1370
    (table_flags() & (HA_HAS_RECORDS | HA_STATS_RECORDS_IS_EXACT)) != 0
309
1371
  */
310
 
  virtual ha_rows records();
311
 
  virtual uint64_t tableSize();
312
 
  virtual uint64_t rowSize();
 
1372
  virtual ha_rows records() { return stats.records; }
313
1373
  /**
314
1374
    Return upper bound of current number of records in the table
315
1375
    (max. of how many records one will retrieve when doing a full table scan)
319
1379
  virtual ha_rows estimate_rows_upper_bound()
320
1380
  { return stats.records+EXTRA_RECORDS; }
321
1381
 
322
 
  virtual const char *index_type(uint32_t)
323
 
  { assert(0); return "";}
324
 
 
325
 
 
326
 
  uint32_t get_index(void) const { return active_index; }
 
1382
  /**
 
1383
    Get the row type from the storage engine.  If this method returns
 
1384
    ROW_TYPE_NOT_USED, the information in HA_CREATE_INFO should be used.
 
1385
  */
 
1386
  virtual enum row_type get_row_type() const { return ROW_TYPE_NOT_USED; }
 
1387
 
 
1388
  virtual const char *index_type(uint key_number __attribute__((__unused__)))
 
1389
  { DBUG_ASSERT(0); return "";}
 
1390
 
 
1391
 
 
1392
  /**
 
1393
    Signal that the table->read_set and table->write_set table maps changed
 
1394
    The handler is allowed to set additional bits in the above map in this
 
1395
    call. Normally the handler should ignore all calls until we have done
 
1396
    a ha_rnd_init() or ha_index_init(), write_row(), update_row or delete_row()
 
1397
    as there may be several calls to this routine.
 
1398
  */
 
1399
  virtual void column_bitmaps_signal();
 
1400
  uint get_index(void) const { return active_index; }
327
1401
  virtual int close(void)=0;
328
1402
 
329
1403
  /**
 
1404
    @retval  0   Bulk update used by handler
 
1405
    @retval  1   Bulk update not used, normal operation used
 
1406
  */
 
1407
  virtual bool start_bulk_update() { return 1; }
 
1408
  /**
 
1409
    @retval  0   Bulk delete used by handler
 
1410
    @retval  1   Bulk delete not used, normal operation used
 
1411
  */
 
1412
  virtual bool start_bulk_delete() { return 1; }
 
1413
  /**
 
1414
    After this call all outstanding updates must be performed. The number
 
1415
    of duplicate key errors are reported in the duplicate key parameter.
 
1416
    It is allowed to continue to the batched update after this call, the
 
1417
    handler has to wait until end_bulk_update with changing state.
 
1418
 
 
1419
    @param    dup_key_found       Number of duplicate keys found
 
1420
 
 
1421
    @retval  0           Success
 
1422
    @retval  >0          Error code
 
1423
  */
 
1424
  virtual int exec_bulk_update(uint *dup_key_found __attribute__((__unused__)))
 
1425
  {
 
1426
    DBUG_ASSERT(FALSE);
 
1427
    return HA_ERR_WRONG_COMMAND;
 
1428
  }
 
1429
  /**
 
1430
    Perform any needed clean-up, no outstanding updates are there at the
 
1431
    moment.
 
1432
  */
 
1433
  virtual void end_bulk_update() { return; }
 
1434
  /**
 
1435
    Execute all outstanding deletes and close down the bulk delete.
 
1436
 
 
1437
    @retval 0             Success
 
1438
    @retval >0            Error code
 
1439
  */
 
1440
  virtual int end_bulk_delete()
 
1441
  {
 
1442
    DBUG_ASSERT(FALSE);
 
1443
    return HA_ERR_WRONG_COMMAND;
 
1444
  }
 
1445
  /**
330
1446
     @brief
331
1447
     Positions an index cursor to the index specified in the handle. Fetches the
332
1448
     row if available. If the key value is null, begin at the first key of the
333
1449
     index.
334
1450
  */
335
 
  virtual int index_read_map(unsigned char * buf, const unsigned char *key,
 
1451
  virtual int index_read_map(uchar * buf, const uchar * key,
336
1452
                             key_part_map keypart_map,
337
1453
                             enum ha_rkey_function find_flag)
338
1454
  {
339
 
    uint32_t key_len= calculate_key_len(active_index, keypart_map);
 
1455
    uint key_len= calculate_key_len(table, active_index, key, keypart_map);
340
1456
    return  index_read(buf, key, key_len, find_flag);
341
1457
  }
342
1458
  /**
345
1461
     row if available. If the key value is null, begin at the first key of the
346
1462
     index.
347
1463
  */
348
 
  virtual int index_read_idx_map(unsigned char * buf, uint32_t index,
349
 
                                 const unsigned char * key,
 
1464
  virtual int index_read_idx_map(uchar * buf, uint index, const uchar * key,
350
1465
                                 key_part_map keypart_map,
351
1466
                                 enum ha_rkey_function find_flag);
352
 
  virtual int index_next(unsigned char *)
353
 
   { return  HA_ERR_WRONG_COMMAND; }
354
 
  virtual int index_prev(unsigned char *)
355
 
   { return  HA_ERR_WRONG_COMMAND; }
356
 
  virtual int index_first(unsigned char *)
357
 
   { return  HA_ERR_WRONG_COMMAND; }
358
 
  virtual int index_last(unsigned char *)
359
 
   { return  HA_ERR_WRONG_COMMAND; }
360
 
  virtual int index_next_same(unsigned char *, const unsigned char *, uint32_t);
361
 
 
362
 
private:
363
 
  uint32_t calculate_key_len(uint32_t key_position, key_part_map keypart_map_arg);
364
 
public:
365
 
 
 
1467
  virtual int index_next(uchar * buf __attribute__((__unused__)))
 
1468
   { return  HA_ERR_WRONG_COMMAND; }
 
1469
  virtual int index_prev(uchar * buf __attribute__((__unused__)))
 
1470
   { return  HA_ERR_WRONG_COMMAND; }
 
1471
  virtual int index_first(uchar * buf __attribute__((__unused__)))
 
1472
   { return  HA_ERR_WRONG_COMMAND; }
 
1473
  virtual int index_last(uchar * buf __attribute__((__unused__)))
 
1474
   { return  HA_ERR_WRONG_COMMAND; }
 
1475
  virtual int index_next_same(uchar *buf __attribute__((__unused__)),
 
1476
                              const uchar *key __attribute__((__unused__)),
 
1477
                              uint keylen __attribute__((__unused__)));
366
1478
  /**
367
1479
     @brief
368
1480
     The following functions works like index_read, but it find the last
369
1481
     row with the current key value or prefix.
370
1482
  */
371
 
  virtual int index_read_last_map(unsigned char * buf, const unsigned char * key,
 
1483
  virtual int index_read_last_map(uchar * buf, const uchar * key,
372
1484
                                  key_part_map keypart_map)
373
1485
  {
374
 
    uint32_t key_len= calculate_key_len(active_index, keypart_map);
 
1486
    uint key_len= calculate_key_len(table, active_index, key, keypart_map);
375
1487
    return index_read_last(buf, key, key_len);
376
1488
  }
377
1489
  virtual int read_range_first(const key_range *start_key,
379
1491
                               bool eq_range, bool sorted);
380
1492
  virtual int read_range_next();
381
1493
  int compare_key(key_range *range);
382
 
  virtual int rnd_next(unsigned char *)=0;
383
 
  virtual int rnd_pos(unsigned char *, unsigned char *)=0;
384
 
  virtual int read_first_row(unsigned char *buf, uint32_t primary_key);
385
 
  virtual int rnd_same(unsigned char *, uint32_t)
386
 
    { return HA_ERR_WRONG_COMMAND; }
387
 
  virtual ha_rows records_in_range(uint32_t, key_range *, key_range *)
 
1494
  int compare_key2(key_range *range);
 
1495
  virtual int ft_init() { return HA_ERR_WRONG_COMMAND; }
 
1496
  void ft_end() { ft_handler=NULL; }
 
1497
  virtual FT_INFO *ft_init_ext(uint flags __attribute__((__unused__)),
 
1498
                               uint inx __attribute__((__unused__)),
 
1499
                               String *key __attribute__((__unused__)))
 
1500
    { return NULL; }
 
1501
  virtual int ft_read(uchar *buf __attribute__((__unused__))) { return HA_ERR_WRONG_COMMAND; }
 
1502
  virtual int rnd_next(uchar *buf __attribute__((__unused__)))=0;
 
1503
  virtual int rnd_pos(uchar * buf __attribute__((__unused__)),
 
1504
                      uchar *pos __attribute__((__unused__)))=0;
 
1505
  /**
 
1506
    One has to use this method when to find
 
1507
    random position by record as the plain
 
1508
    position() call doesn't work for some
 
1509
    handlers for random position.
 
1510
  */
 
1511
  virtual int rnd_pos_by_record(uchar *record);
 
1512
  virtual int read_first_row(uchar *buf, uint primary_key);
 
1513
  /**
 
1514
    The following function is only needed for tables that may be temporary
 
1515
    tables during joins.
 
1516
  */
 
1517
  virtual int restart_rnd_next(uchar *buf __attribute__((__unused__)),
 
1518
                               uchar *pos __attribute__((__unused__)))
 
1519
    { return HA_ERR_WRONG_COMMAND; }
 
1520
  virtual int rnd_same(uchar *buf __attribute__((__unused__)),
 
1521
                       uint inx __attribute__((__unused__)))
 
1522
    { return HA_ERR_WRONG_COMMAND; }
 
1523
  virtual ha_rows records_in_range(uint inx __attribute__((__unused__)),
 
1524
                                   key_range *min_key __attribute__((__unused__)),
 
1525
                                   key_range *max_key __attribute__((__unused__)))
388
1526
    { return (ha_rows) 10; }
389
 
  virtual void position(const unsigned char *record)=0;
390
 
  virtual int info(uint32_t)=0; // see my_base.h for full description
391
 
  virtual uint32_t calculate_key_hash_value(Field **)
392
 
  { assert(0); return 0; }
393
 
  virtual int extra(enum ha_extra_function)
 
1527
  virtual void position(const uchar *record)=0;
 
1528
  virtual int info(uint)=0; // see my_base.h for full description
 
1529
  virtual uint32 calculate_key_hash_value(Field **field_array __attribute__((__unused__)))
 
1530
  { DBUG_ASSERT(0); return 0; }
 
1531
  virtual int extra(enum ha_extra_function operation __attribute__((__unused__)))
394
1532
  { return 0; }
395
 
  virtual int extra_opt(enum ha_extra_function operation, uint32_t)
 
1533
  virtual int extra_opt(enum ha_extra_function operation,
 
1534
                        uint32_t cache_size __attribute__((__unused__)))
396
1535
  { return extra(operation); }
397
1536
 
398
1537
  /**
416
1555
  */
417
1556
  virtual void try_semi_consistent_read(bool) {}
418
1557
  virtual void unlock_row(void) {}
 
1558
  virtual int start_stmt(THD *thd __attribute__((__unused__)),
 
1559
                         thr_lock_type lock_type __attribute__((__unused__)))
 
1560
  {return 0;}
419
1561
  virtual void get_auto_increment(uint64_t offset, uint64_t increment,
420
1562
                                  uint64_t nb_desired_values,
421
1563
                                  uint64_t *first_value,
422
 
                                  uint64_t *nb_reserved_values)= 0;
423
 
 
 
1564
                                  uint64_t *nb_reserved_values);
424
1565
  void set_next_insert_id(uint64_t id)
425
1566
  {
 
1567
    DBUG_PRINT("info",("auto_increment: next value %lu", (uint32_t)id));
426
1568
    next_insert_id= id;
427
1569
  }
428
1570
  void restore_auto_increment(uint64_t prev_insert_id)
441
1583
      insert_id_for_cur_row;
442
1584
  }
443
1585
 
 
1586
  virtual void update_create_info(HA_CREATE_INFO *create_info __attribute__((__unused__))) {}
 
1587
  int check_old_types(void);
 
1588
  virtual int assign_to_keycache(THD* thd __attribute__((__unused__)),
 
1589
                                 HA_CHECK_OPT* check_opt __attribute__((__unused__)))
 
1590
  { return HA_ADMIN_NOT_IMPLEMENTED; }
444
1591
  /* end of the list of admin commands */
445
1592
 
446
1593
  virtual int indexes_are_disabled(void) {return 0;}
447
 
  virtual void append_create_info(String *)
 
1594
  virtual char *update_table_comment(const char * comment)
 
1595
  { return (char*) comment;}
 
1596
  virtual void append_create_info(String *packet __attribute__((__unused__)))
448
1597
  {}
449
1598
  /**
450
1599
      If index == MAX_KEY then a check for table is made and if index <
453
1602
 
454
1603
    @param  index            Index to check if foreign key uses it
455
1604
 
456
 
    @retval   true            Foreign key defined on table or index
457
 
    @retval   false           No foreign key defined
 
1605
    @retval   TRUE            Foreign key defined on table or index
 
1606
    @retval   FALSE           No foreign key defined
458
1607
  */
 
1608
  virtual bool is_fk_defined_on_table_or_index(uint index __attribute__((__unused__)))
 
1609
  { return FALSE; }
459
1610
  virtual char* get_foreign_key_create_info(void)
460
 
  { return NULL;}  /* gets foreign key create string from InnoDB */
461
 
  /** used in ALTER Table; if changing storage engine is allowed.
462
 
      e.g. not be allowed if table has foreign key constraints in engine.
463
 
   */
464
 
  virtual bool can_switch_engines(void) { return true; }
 
1611
  { return(NULL);}  /* gets foreign key create string from InnoDB */
 
1612
  /** used in ALTER TABLE; 1 if changing storage engine is allowed */
 
1613
  virtual bool can_switch_engines(void) { return 1; }
465
1614
  /** used in REPLACE; is > 0 if table is referred by a FOREIGN KEY */
466
 
  virtual int get_foreign_key_list(Session *, List<ForeignKeyInfo> *)
 
1615
  virtual int get_foreign_key_list(THD *thd __attribute__((__unused__)),
 
1616
                                   List<FOREIGN_KEY_INFO> *f_key_list __attribute__((__unused__)))
467
1617
  { return 0; }
468
 
  virtual uint32_t referenced_by_foreign_key() { return 0;}
469
 
  virtual void free_foreign_key_create_info(char *) {}
470
 
 
 
1618
  virtual uint referenced_by_foreign_key() { return 0;}
 
1619
  virtual void init_table_handle_for_HANDLER()
 
1620
  { return; }       /* prepare InnoDB for HANDLER */
 
1621
  virtual void free_foreign_key_create_info(char* str __attribute__((__unused__))) {}
 
1622
  /** The following can be called without an open handler */
 
1623
  virtual const char *table_type() const =0;
 
1624
  /**
 
1625
    If frm_error() is called then we will use this to find out what file
 
1626
    extentions exist for the storage engine. This is also used by the default
 
1627
    rename_table and delete_table method in handler.cc.
 
1628
 
 
1629
    For engines that have two file name extentions (separate meta/index file
 
1630
    and data file), the order of elements is relevant. First element of engine
 
1631
    file name extentions array should be meta/index file extention. Second
 
1632
    element - data file extention. This order is assumed by
 
1633
    prepare_for_repair() when REPAIR TABLE ... USE_FRM is issued.
 
1634
  */
 
1635
  virtual const char **bas_ext() const =0;
 
1636
 
 
1637
  virtual int get_default_no_partitions(HA_CREATE_INFO *info __attribute__((__unused__))) { return 1;}
 
1638
  virtual bool get_no_parts(const char *name __attribute__((__unused__)),
 
1639
                            uint *no_parts)
 
1640
  {
 
1641
    *no_parts= 0;
 
1642
    return 0;
 
1643
  }
 
1644
 
 
1645
  virtual uint32_t index_flags(uint idx, uint part, bool all_parts) const =0;
 
1646
 
 
1647
  virtual int add_index(TABLE *table_arg __attribute__((__unused__)),
 
1648
                        KEY *key_info __attribute__((__unused__)),
 
1649
                        uint num_of_keys __attribute__((__unused__)))
 
1650
  { return (HA_ERR_WRONG_COMMAND); }
 
1651
  virtual int prepare_drop_index(TABLE *table_arg __attribute__((__unused__)),
 
1652
                                 uint *key_num __attribute__((__unused__)),
 
1653
                                 uint num_of_keys __attribute__((__unused__)))
 
1654
  { return (HA_ERR_WRONG_COMMAND); }
 
1655
  virtual int final_drop_index(TABLE *table_arg __attribute__((__unused__)))
 
1656
  { return (HA_ERR_WRONG_COMMAND); }
 
1657
 
 
1658
  uint max_record_length() const
 
1659
  { return min(HA_MAX_REC_LENGTH, max_supported_record_length()); }
 
1660
  uint max_keys() const
 
1661
  { return min(MAX_KEY, max_supported_keys()); }
 
1662
  uint max_key_parts() const
 
1663
  { return min(MAX_REF_PARTS, max_supported_key_parts()); }
 
1664
  uint max_key_length() const
 
1665
  { return min(MAX_KEY_LENGTH, max_supported_key_length()); }
 
1666
  uint max_key_part_length(void) const
 
1667
  { return min(MAX_KEY_LENGTH, max_supported_key_part_length()); }
 
1668
 
 
1669
  virtual uint max_supported_record_length(void) const
 
1670
  { return HA_MAX_REC_LENGTH; }
 
1671
  virtual uint max_supported_keys(void) const { return 0; }
 
1672
  virtual uint max_supported_key_parts(void) const { return MAX_REF_PARTS; }
 
1673
  virtual uint max_supported_key_length(void) const { return MAX_KEY_LENGTH; }
 
1674
  virtual uint max_supported_key_part_length(void) const { return 255; }
 
1675
  virtual uint min_record_length(uint options __attribute__((__unused__))) const
 
1676
  { return 1; }
 
1677
 
 
1678
  virtual bool low_byte_first(void) const { return 1; }
 
1679
  virtual uint checksum(void) const { return 0; }
 
1680
  virtual bool is_crashed(void) const  { return 0; }
 
1681
  virtual bool auto_repair(void) const { return 0; }
 
1682
 
 
1683
 
 
1684
#define CHF_CREATE_FLAG 0
 
1685
#define CHF_DELETE_FLAG 1
 
1686
#define CHF_RENAME_FLAG 2
 
1687
 
 
1688
 
 
1689
  /**
 
1690
    @note lock_count() can return > 1 if the table is MERGE or partitioned.
 
1691
  */
 
1692
  virtual uint lock_count(void) const { return 1; }
471
1693
  /**
472
1694
    Is not invoked for non-transactional temporary tables.
473
1695
 
475
1697
    or partitioned.
476
1698
 
477
1699
    @note that one can NOT rely on table->in_use in store_lock().  It may
478
 
    refer to a different thread if called from abortLockForThread().
 
1700
    refer to a different thread if called from mysql_lock_abort_for_thread().
479
1701
 
480
1702
    @note If the table is MERGE, store_lock() can return less locks
481
1703
    than lock_count() claimed. This can happen when the MERGE children
482
1704
    are not attached when this is called from another thread.
483
1705
  */
484
 
  virtual THR_LOCK_DATA **store_lock(Session *,
 
1706
  virtual THR_LOCK_DATA **store_lock(THD *thd,
485
1707
                                     THR_LOCK_DATA **to,
486
 
                                     enum thr_lock_type)
 
1708
                                     enum thr_lock_type lock_type)=0;
 
1709
 
 
1710
  /** Type of table for caching query */
 
1711
  virtual uint8 table_cache_type() { return HA_CACHE_TBL_NONTRANSACT; }
 
1712
 
 
1713
 
 
1714
  /**
 
1715
    @brief Register a named table with a call back function to the query cache.
 
1716
 
 
1717
    @param thd The thread handle
 
1718
    @param table_key A pointer to the table name in the table cache
 
1719
    @param key_length The length of the table name
 
1720
    @param[out] engine_callback The pointer to the storage engine call back
 
1721
      function
 
1722
    @param[out] engine_data Storage engine specific data which could be
 
1723
      anything
 
1724
 
 
1725
    This method offers the storage engine, the possibility to store a reference
 
1726
    to a table name which is going to be used with query cache. 
 
1727
    The method is called each time a statement is written to the cache and can
 
1728
    be used to verify if a specific statement is cachable. It also offers
 
1729
    the possibility to register a generic (but static) call back function which
 
1730
    is called each time a statement is matched against the query cache.
 
1731
 
 
1732
    @note If engine_data supplied with this function is different from
 
1733
      engine_data supplied with the callback function, and the callback returns
 
1734
      FALSE, a table invalidation on the current table will occur.
 
1735
 
 
1736
    @return Upon success the engine_callback will point to the storage engine
 
1737
      call back function, if any, and engine_data will point to any storage
 
1738
      engine data used in the specific implementation.
 
1739
      @retval TRUE Success
 
1740
      @retval FALSE The specified table or current statement should not be
 
1741
        cached
 
1742
  */
 
1743
 
 
1744
  virtual my_bool
 
1745
    register_query_cache_table(THD *thd __attribute__((__unused__)),
 
1746
                               char *table_key __attribute__((__unused__)),
 
1747
                               uint key_length __attribute__((__unused__)),
 
1748
                               qc_engine_callback *engine_callback,
 
1749
                               uint64_t *engine_data __attribute__((__unused__)))
487
1750
  {
488
 
    assert(0); // Impossible programming situation
489
 
 
490
 
    return(to);
 
1751
    *engine_callback= 0;
 
1752
    return TRUE;
491
1753
  }
492
1754
 
 
1755
 
493
1756
 /*
494
 
   @retval true   Primary key (if there is one) is clustered
 
1757
   @retval TRUE   Primary key (if there is one) is clustered
495
1758
                  key covering all fields
496
 
   @retval false  otherwise
 
1759
   @retval FALSE  otherwise
497
1760
 */
498
 
 virtual bool primary_key_is_clustered() { return false; }
499
 
 virtual int cmp_ref(const unsigned char *ref1, const unsigned char *ref2)
 
1761
 virtual bool primary_key_is_clustered() { return FALSE; }
 
1762
 virtual int cmp_ref(const uchar *ref1, const uchar *ref2)
500
1763
 {
501
1764
   return memcmp(ref1, ref2, ref_length);
502
1765
 }
503
1766
 
504
 
  virtual bool isOrdered(void)
 
1767
 /*
 
1768
   Condition pushdown to storage engines
 
1769
 */
 
1770
 
 
1771
 /**
 
1772
   Push condition down to the table handler.
 
1773
 
 
1774
   @param  cond   Condition to be pushed. The condition tree must not be
 
1775
                  modified by the by the caller.
 
1776
 
 
1777
   @return
 
1778
     The 'remainder' condition that caller must use to filter out records.
 
1779
     NULL means the handler will not return rows that do not match the
 
1780
     passed condition.
 
1781
 
 
1782
   @note
 
1783
   The pushed conditions form a stack (from which one can remove the
 
1784
   last pushed condition using cond_pop).
 
1785
   The table handler filters out rows using (pushed_cond1 AND pushed_cond2 
 
1786
   AND ... AND pushed_condN)
 
1787
   or less restrictive condition, depending on handler's capabilities.
 
1788
 
 
1789
   handler->ha_reset() call empties the condition stack.
 
1790
   Calls to rnd_init/rnd_end, index_init/index_end etc do not affect the
 
1791
   condition stack.
 
1792
 */ 
 
1793
 virtual const COND *cond_push(const COND *cond) { return cond; }
 
1794
 
 
1795
 /**
 
1796
   Pop the top condition from the condition stack of the handler instance.
 
1797
 
 
1798
   Pops the top if condition stack, if stack is not empty.
 
1799
 */
 
1800
 virtual void cond_pop(void) { return; }
 
1801
 
 
1802
 virtual Item
 
1803
   *idx_cond_push(uint keyno __attribute__((__unused__)),
 
1804
                  Item* idx_cond __attribute__((__unused__)))
 
1805
 { return idx_cond; }
 
1806
 
 
1807
 /*
 
1808
    Part of old fast alter table, to be depricated
 
1809
  */
 
1810
 virtual bool
 
1811
   check_if_incompatible_data(HA_CREATE_INFO *create_info __attribute__((__unused__)),
 
1812
                              uint table_changes __attribute__((__unused__)))
 
1813
 { return COMPATIBLE_DATA_NO; }
 
1814
 
 
1815
 /* On-line ALTER TABLE interface */
 
1816
 
 
1817
 /**
 
1818
    Check if a storage engine supports a particular alter table on-line
 
1819
 
 
1820
    @param    altered_table     A temporary table show what table is to
 
1821
                                change to
 
1822
    @param    create_info       Information from the parsing phase about new
 
1823
                                table properties.
 
1824
    @param    alter_flags       Bitmask that shows what will be changed
 
1825
    @param    table_changes     Shows if table layout has changed (for
 
1826
                                backwards compatibility with
 
1827
                                check_if_incompatible_data
 
1828
 
 
1829
    @retval   HA_ALTER_ERROR                Unexpected error
 
1830
    @retval   HA_ALTER_SUPPORTED_WAIT_LOCK  Supported, but requires DDL lock
 
1831
    @retval   HA_ALTER_SUPPORTED_NO_LOCK    Supported
 
1832
    @retval   HA_ALTER_NOT_SUPPORTED        Not supported
 
1833
 
 
1834
    @note
 
1835
      The default implementation is implemented to support fast
 
1836
      alter table (storage engines that support some changes by
 
1837
      just changing the frm file) without any change in the handler
 
1838
      implementation.
 
1839
 */
 
1840
 virtual int
 
1841
   check_if_supported_alter(TABLE *altered_table __attribute__((__unused__)),
 
1842
                            HA_CREATE_INFO *create_info,
 
1843
                            HA_ALTER_FLAGS *alter_flags __attribute__((__unused__)),
 
1844
                            uint table_changes)
 
1845
 {
 
1846
   DBUG_ENTER("check_if_supported_alter");
 
1847
   if (this->check_if_incompatible_data(create_info, table_changes)
 
1848
       == COMPATIBLE_DATA_NO)
 
1849
     DBUG_RETURN(HA_ALTER_NOT_SUPPORTED);
 
1850
   else
 
1851
     DBUG_RETURN(HA_ALTER_SUPPORTED_WAIT_LOCK);
 
1852
 }
 
1853
 /**
 
1854
   Tell storage engine to prepare for the on-line alter table (pre-alter)
 
1855
 
 
1856
   @param     thd               The thread handle
 
1857
   @param     altered_table     A temporary table show what table is to
 
1858
                                change to
 
1859
   @param     alter_info        Storage place for data used during phase1
 
1860
                                and phase2
 
1861
   @param     alter_flags       Bitmask that shows what will be changed
 
1862
 
 
1863
   @retval   0      OK
 
1864
   @retval   error  error code passed from storage engine
 
1865
 */
 
1866
 virtual int alter_table_phase1(THD *thd __attribute__((__unused__)),
 
1867
                                TABLE *altered_table __attribute__((__unused__)),
 
1868
                                HA_CREATE_INFO *create_info __attribute__((__unused__)),
 
1869
                                HA_ALTER_INFO *alter_info __attribute__((__unused__)),
 
1870
                                HA_ALTER_FLAGS *alter_flags  __attribute__((__unused__)))
 
1871
 {
 
1872
   return HA_ERR_UNSUPPORTED;
 
1873
 }
 
1874
 /**
 
1875
    Tell storage engine to perform the on-line alter table (alter)
 
1876
 
 
1877
    @param    thd               The thread handle
 
1878
    @param    altered_table     A temporary table show what table is to
 
1879
                                change to
 
1880
    @param    alter_info        Storage place for data used during phase1
 
1881
                                and phase2
 
1882
    @param    alter_flags       Bitmask that shows what will be changed
 
1883
 
 
1884
    @retval  0      OK
 
1885
    @retval  error  error code passed from storage engine
 
1886
 
 
1887
    @note
 
1888
      If check_if_supported_alter returns HA_ALTER_SUPPORTED_WAIT_LOCK
 
1889
      this call is to be wrapped with a DDL lock. This is currently NOT
 
1890
      supported.
 
1891
 */
 
1892
 virtual int alter_table_phase2(THD *thd  __attribute__((__unused__)),
 
1893
                                TABLE *altered_table  __attribute__((__unused__)),
 
1894
                                HA_CREATE_INFO *create_info __attribute__((__unused__)),
 
1895
                                HA_ALTER_INFO *alter_info __attribute__((__unused__)),
 
1896
                                HA_ALTER_FLAGS *alter_flags __attribute__((__unused__)))
 
1897
 {
 
1898
   return HA_ERR_UNSUPPORTED;
 
1899
 }
 
1900
 /**
 
1901
    Tell storage engine that changed frm file is now on disk and table
 
1902
    has been re-opened (post-alter)
 
1903
 
 
1904
    @param    thd               The thread handle
 
1905
    @param    table             The altered table, re-opened
 
1906
 */
 
1907
 virtual int alter_table_phase3(THD *thd __attribute__((__unused__)),
 
1908
                                TABLE *table __attribute__((__unused__)))
 
1909
 {
 
1910
   return HA_ERR_UNSUPPORTED;
 
1911
 }
 
1912
 
 
1913
  /**
 
1914
    use_hidden_primary_key() is called in case of an update/delete when
 
1915
    (table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
 
1916
    but we don't have a primary key
 
1917
  */
 
1918
  virtual void use_hidden_primary_key();
 
1919
 
 
1920
  /**
 
1921
    Lock table.
 
1922
 
 
1923
    @param    thd                     Thread handle
 
1924
    @param    lock_type               HA_LOCK_IN_SHARE_MODE     (F_RDLCK)
 
1925
                                      HA_LOCK_IN_EXCLUSIVE_MODE (F_WRLCK)
 
1926
    @param    lock_timeout            -1 default timeout
 
1927
                                      0  no wait
 
1928
                                      >0 wait timeout in milliseconds.
 
1929
 
 
1930
   @note
 
1931
      lock_timeout >0 is not used by MySQL currently. If the storage
 
1932
      engine does not support NOWAIT (lock_timeout == 0) it should
 
1933
      return an error. But if it does not support WAIT X (lock_timeout
 
1934
      >0) it should treat it as lock_timeout == -1 and wait a default
 
1935
      (or even hard-coded) timeout.
 
1936
 
 
1937
    @retval HA_ERR_WRONG_COMMAND      Storage engine does not support
 
1938
                                      lock_table()
 
1939
    @retval HA_ERR_UNSUPPORTED        Storage engine does not support NOWAIT
 
1940
    @retval HA_ERR_LOCK_WAIT_TIMEOUT  Lock request timed out or
 
1941
                                      lock conflict with NOWAIT option
 
1942
    @retval HA_ERR_LOCK_DEADLOCK      Deadlock detected
 
1943
  */
 
1944
  virtual int lock_table(THD *thd         __attribute__((unused)),
 
1945
                         int lock_type    __attribute__((unused)),
 
1946
                         int lock_timeout __attribute__((unused)))
505
1947
  {
506
 
    return false;
 
1948
    return HA_ERR_WRONG_COMMAND;
507
1949
  }
508
1950
 
509
 
 
510
1951
protected:
511
1952
  /* Service methods for use by storage engines. */
512
 
  void ha_statistic_increment(uint64_t system_status_var::*offset) const;
513
 
  void **ha_data(Session *) const;
 
1953
  void ha_statistic_increment(ulong SSV::*offset) const;
 
1954
  void **ha_data(THD *) const;
 
1955
  THD *ha_thd(void) const;
 
1956
 
 
1957
  /**
 
1958
    Default rename_table() and delete_table() rename/delete files with a
 
1959
    given name and extensions from bas_ext().
 
1960
 
 
1961
    These methods can be overridden, but their default implementation
 
1962
    provide useful functionality.
 
1963
  */
 
1964
  virtual int rename_table(const char *from, const char *to);
 
1965
  /**
 
1966
    Delete a table in the engine. Called for base as well as temporary
 
1967
    tables.
 
1968
  */
 
1969
  virtual int delete_table(const char *name);
514
1970
 
515
1971
private:
516
1972
  /* Private helpers */
517
 
  inline void setTransactionReadWrite();
 
1973
  inline void mark_trx_read_write();
518
1974
private:
519
1975
  /*
520
1976
    Low-level primitives for storage engines.  These should be
522
1978
    the corresponding 'ha_*' method above.
523
1979
  */
524
1980
 
525
 
  virtual int open(const char *, int , uint32_t ) { assert(0); return -1; }
526
 
  virtual int doOpen(const TableIdentifier &identifier, int mode, uint32_t test_if_locked);
527
 
  virtual int doStartIndexScan(uint32_t idx, bool)
 
1981
  virtual int open(const char *name, int mode, uint test_if_locked)=0;
 
1982
  virtual int index_init(uint idx,
 
1983
                         bool sorted __attribute__((__unused__)))
528
1984
  { active_index= idx; return 0; }
529
 
  virtual int doEndIndexScan() { active_index= MAX_KEY; return 0; }
 
1985
  virtual int index_end() { active_index= MAX_KEY; return 0; }
530
1986
  /**
531
 
    doStartTableScan() can be called two times without doEndTableScan() in between
 
1987
    rnd_init() can be called two times without rnd_end() in between
532
1988
    (it only makes sense if scan=1).
533
1989
    then the second call should prepare for the new table scan (e.g
534
1990
    if rnd_init allocates the cursor, second call should position it
535
1991
    to the start of the table, no need to deallocate and allocate it again
536
1992
  */
537
 
  virtual int doStartTableScan(bool scan)= 0;
538
 
  virtual int doEndTableScan() { return 0; }
539
 
  virtual int doInsertRecord(unsigned char *)
540
 
  {
541
 
    return HA_ERR_WRONG_COMMAND;
542
 
  }
543
 
 
544
 
  virtual int doUpdateRecord(const unsigned char *, unsigned char *)
545
 
  {
546
 
    return HA_ERR_WRONG_COMMAND;
547
 
  }
548
 
 
549
 
  virtual int doDeleteRecord(const unsigned char *)
 
1993
  virtual int rnd_init(bool scan)= 0;
 
1994
  virtual int rnd_end() { return 0; }
 
1995
  virtual int write_row(uchar *buf __attribute__((unused)))
 
1996
  {
 
1997
    return HA_ERR_WRONG_COMMAND;
 
1998
  }
 
1999
 
 
2000
  virtual int update_row(const uchar *old_data __attribute__((unused)),
 
2001
                         uchar *new_data __attribute__((unused)))
 
2002
  {
 
2003
    return HA_ERR_WRONG_COMMAND;
 
2004
  }
 
2005
 
 
2006
  virtual int delete_row(const uchar *buf __attribute__((unused)))
550
2007
  {
551
2008
    return HA_ERR_WRONG_COMMAND;
552
2009
  }
556
2013
    by that statement.
557
2014
  */
558
2015
  virtual int reset() { return 0; }
 
2016
  virtual Table_flags table_flags(void) const= 0;
559
2017
 
560
2018
  /**
561
2019
    Is not invoked for non-transactional temporary tables.
562
2020
 
563
2021
    Tells the storage engine that we intend to read or write data
564
 
    from the table. This call is prefixed with a call to Cursor::store_lock()
565
 
    and is invoked only for those Cursor instances that stored the lock.
 
2022
    from the table. This call is prefixed with a call to handler::store_lock()
 
2023
    and is invoked only for those handler instances that stored the lock.
566
2024
 
567
2025
    Calls to rnd_init/index_init are prefixed with this call. When table
568
2026
    IO is complete, we call external_lock(F_UNLCK).
579
2037
    @return  non-0 in case of failure, 0 in case of success.
580
2038
    When lock_type is F_UNLCK, the return value is ignored.
581
2039
  */
582
 
  virtual int external_lock(Session *, int)
 
2040
  virtual int external_lock(THD *thd __attribute__((unused)),
 
2041
                            int lock_type __attribute__((unused)))
583
2042
  {
584
2043
    return 0;
585
2044
  }
586
 
  virtual void release_auto_increment(void) { return; }
 
2045
  virtual void release_auto_increment(void) { return; };
587
2046
  /** admin commands - called from mysql_admin_table */
588
 
  virtual int check(Session *)
 
2047
  virtual int check_for_upgrade(HA_CHECK_OPT *check_opt __attribute__((__unused__)))
 
2048
  { return 0; }
 
2049
  virtual int check(THD* thd __attribute__((__unused__)),
 
2050
                    HA_CHECK_OPT* check_opt __attribute__((__unused__)))
589
2051
  { return HA_ADMIN_NOT_IMPLEMENTED; }
590
2052
 
591
 
  virtual void start_bulk_insert(ha_rows)
 
2053
  /**
 
2054
     In this method check_opt can be modified
 
2055
     to specify CHECK option to use to call check()
 
2056
     upon the table.
 
2057
  */
 
2058
  virtual int repair(THD* thd __attribute__((__unused__)),
 
2059
                     HA_CHECK_OPT* check_opt __attribute__((__unused__)))
 
2060
  { return HA_ADMIN_NOT_IMPLEMENTED; }
 
2061
  virtual void start_bulk_insert(ha_rows rows __attribute__((__unused__)))
592
2062
  {}
593
2063
  virtual int end_bulk_insert(void) { return 0; }
594
 
  virtual int index_read(unsigned char *, const unsigned char *,
595
 
                         uint32_t, enum ha_rkey_function)
 
2064
  virtual int index_read(uchar * buf __attribute__((__unused__)),
 
2065
                         const uchar * key __attribute__((__unused__)),
 
2066
                         uint key_len __attribute__((__unused__)),
 
2067
                         enum ha_rkey_function find_flag __attribute__((__unused__)))
596
2068
   { return  HA_ERR_WRONG_COMMAND; }
597
 
  virtual int index_read_last(unsigned char *, const unsigned char *, uint32_t)
598
 
   { return (errno= HA_ERR_WRONG_COMMAND); }
 
2069
  virtual int index_read_last(uchar * buf __attribute__((__unused__)),
 
2070
                              const uchar * key __attribute__((__unused__)),
 
2071
                              uint key_len __attribute__((__unused__)))
 
2072
   { return (my_errno= HA_ERR_WRONG_COMMAND); }
 
2073
  /**
 
2074
    This method is similar to update_row, however the handler doesn't need
 
2075
    to execute the updates at this point in time. The handler can be certain
 
2076
    that another call to bulk_update_row will occur OR a call to
 
2077
    exec_bulk_update before the set of updates in this query is concluded.
 
2078
 
 
2079
    @param    old_data       Old record
 
2080
    @param    new_data       New record
 
2081
    @param    dup_key_found  Number of duplicate keys found
 
2082
 
 
2083
    @retval  0   Bulk delete used by handler
 
2084
    @retval  1   Bulk delete not used, normal operation used
 
2085
  */
 
2086
  virtual int bulk_update_row(const uchar *old_data __attribute__((__unused__)),
 
2087
                              uchar *new_data __attribute__((__unused__)),
 
2088
                              uint *dup_key_found __attribute__((__unused__)))
 
2089
  {
 
2090
    DBUG_ASSERT(FALSE);
 
2091
    return HA_ERR_WRONG_COMMAND;
 
2092
  }
599
2093
  /**
600
2094
    This is called to delete all rows in a table
601
 
    If the Cursor don't support this, then this function will
 
2095
    If the handler don't support this, then this function will
602
2096
    return HA_ERR_WRONG_COMMAND and MySQL will delete the rows one
603
2097
    by one.
604
2098
  */
605
2099
  virtual int delete_all_rows(void)
606
 
  { return (errno=HA_ERR_WRONG_COMMAND); }
 
2100
  { return (my_errno=HA_ERR_WRONG_COMMAND); }
607
2101
  /**
608
2102
    Reset the auto-increment counter to the given value, i.e. the next row
609
2103
    inserted will get the given value. This is called e.g. after TRUNCATE
610
2104
    is emulated by doing a 'DELETE FROM t'. HA_ERR_WRONG_COMMAND is
611
2105
    returned by storage engines that don't support this operation.
612
2106
  */
613
 
  virtual int reset_auto_increment(uint64_t)
614
 
  { return HA_ERR_WRONG_COMMAND; }
615
 
 
616
 
  virtual int analyze(Session *)
617
 
  { return HA_ADMIN_NOT_IMPLEMENTED; }
618
 
 
619
 
  virtual int disable_indexes(uint32_t)
620
 
  { return HA_ERR_WRONG_COMMAND; }
621
 
 
622
 
  virtual int enable_indexes(uint32_t)
623
 
  { return HA_ERR_WRONG_COMMAND; }
624
 
 
625
 
  virtual int discard_or_import_tablespace(bool)
626
 
  { return (errno=HA_ERR_WRONG_COMMAND); }
627
 
 
628
 
  /* 
629
 
    @todo this is just for the HEAP engine, it should
630
 
    be removed at some point in the future (and
631
 
    no new engine should ever use it). Right
632
 
    now HEAP does rely on it, so we cannot remove it.
633
 
  */
 
2107
  virtual int reset_auto_increment(uint64_t value __attribute__((__unused__)))
 
2108
  { return HA_ERR_WRONG_COMMAND; }
 
2109
  virtual int optimize(THD* thd __attribute__((__unused__)),
 
2110
                       HA_CHECK_OPT* check_opt __attribute__((__unused__)))
 
2111
  { return HA_ADMIN_NOT_IMPLEMENTED; }
 
2112
  virtual int analyze(THD* thd __attribute__((__unused__)),
 
2113
                      HA_CHECK_OPT* check_opt __attribute__((__unused__)))
 
2114
  { return HA_ADMIN_NOT_IMPLEMENTED; }
 
2115
  virtual bool check_and_repair(THD *thd __attribute__((__unused__)))
 
2116
  { return TRUE; }
 
2117
  virtual int disable_indexes(uint mode __attribute__((__unused__)))
 
2118
  { return HA_ERR_WRONG_COMMAND; }
 
2119
  virtual int enable_indexes(uint mode __attribute__((__unused__)))
 
2120
  { return HA_ERR_WRONG_COMMAND; }
 
2121
  virtual int discard_or_import_tablespace(my_bool discard __attribute__((__unused__)))
 
2122
  { return (my_errno=HA_ERR_WRONG_COMMAND); }
 
2123
  virtual void prepare_for_alter(void) { return; }
634
2124
  virtual void drop_table(const char *name);
 
2125
  virtual int create(const char *name __attribute__((__unused__)),
 
2126
                     TABLE *form __attribute__((__unused__)),
 
2127
                     HA_CREATE_INFO *info __attribute__((__unused__)))=0;
 
2128
 
 
2129
  virtual int create_handler_files(const char *name __attribute__((__unused__)),
 
2130
                                   const char *old_name __attribute__((__unused__)),
 
2131
                                   int action_flag __attribute__((__unused__)),
 
2132
                                   HA_CREATE_INFO *info __attribute__((__unused__)))
 
2133
  { return FALSE; }
 
2134
};
 
2135
 
 
2136
 
 
2137
 
 
2138
/**
 
2139
  A Disk-Sweep MRR interface implementation
 
2140
 
 
2141
  This implementation makes range (and, in the future, 'ref') scans to read
 
2142
  table rows in disk sweeps. 
 
2143
  
 
2144
  Currently it is used by MyISAM and InnoDB. Potentially it can be used with
 
2145
  any table handler that has non-clustered indexes and on-disk rows.
 
2146
*/
 
2147
 
 
2148
class DsMrr_impl
 
2149
{
 
2150
public:
 
2151
  typedef void (handler::*range_check_toggle_func_t)(bool on);
 
2152
 
 
2153
  DsMrr_impl()
 
2154
    : h2(NULL) {};
 
2155
 
 
2156
  handler *h; /* The "owner" handler object. It is used for scanning the index */
 
2157
  TABLE *table; /* Always equal to h->table */
 
2158
private:
 
2159
  /*
 
2160
    Secondary handler object. It is used to retrieve full table rows by
 
2161
    calling rnd_pos().
 
2162
  */
 
2163
  handler *h2;
 
2164
 
 
2165
  /* Buffer to store rowids, or (rowid, range_id) pairs */
 
2166
  uchar *rowids_buf;
 
2167
  uchar *rowids_buf_cur;   /* Current position when reading/writing */
 
2168
  uchar *rowids_buf_last;  /* When reading: end of used buffer space */
 
2169
  uchar *rowids_buf_end;   /* End of the buffer */
 
2170
 
 
2171
  bool dsmrr_eof; /* TRUE <=> We have reached EOF when reading index tuples */
 
2172
 
 
2173
  /* TRUE <=> need range association, buffer holds {rowid, range_id} pairs */
 
2174
  bool is_mrr_assoc;
 
2175
 
 
2176
  bool use_default_impl; /* TRUE <=> shortcut all calls to default MRR impl */
 
2177
public:
 
2178
  void init(handler *h_arg, TABLE *table_arg)
 
2179
  {
 
2180
    h= h_arg; 
 
2181
    table= table_arg;
 
2182
  }
 
2183
  int dsmrr_init(handler *h, KEY *key, RANGE_SEQ_IF *seq_funcs, 
 
2184
                 void *seq_init_param, uint n_ranges, uint mode, 
 
2185
                 HANDLER_BUFFER *buf);
 
2186
  void dsmrr_close();
 
2187
  int dsmrr_fill_buffer(handler *h);
 
2188
  int dsmrr_next(handler *h, char **range_info);
 
2189
 
 
2190
  int dsmrr_info(uint keyno, uint n_ranges, uint keys, uint *bufsz,
 
2191
                 uint *flags, COST_VECT *cost);
 
2192
 
 
2193
  ha_rows dsmrr_info_const(uint keyno, RANGE_SEQ_IF *seq, 
 
2194
                            void *seq_init_param, uint n_ranges, uint *bufsz,
 
2195
                            uint *flags, COST_VECT *cost);
 
2196
private:
 
2197
  bool key_uses_partial_cols(uint keyno);
 
2198
  bool choose_mrr_impl(uint keyno, ha_rows rows, uint *flags, uint *bufsz, 
 
2199
                       COST_VECT *cost);
 
2200
  bool get_disk_sweep_mrr_cost(uint keynr, ha_rows rows, uint flags, 
 
2201
                               uint *buffer_size, COST_VECT *cost);
635
2202
};
636
2203
 
637
2204
extern const char *ha_row_type[];
 
2205
extern const char *tx_isolation_names[];
 
2206
extern const char *binlog_format_names[];
 
2207
extern TYPELIB tx_isolation_typelib;
 
2208
extern TYPELIB myisam_stats_method_typelib;
 
2209
extern uint32_t total_ha, total_ha_2pc;
 
2210
 
 
2211
       /* Wrapper functions */
 
2212
#define ha_commit(thd) (ha_commit_trans((thd), TRUE))
 
2213
#define ha_rollback(thd) (ha_rollback_trans((thd), TRUE))
 
2214
 
 
2215
/* lookups */
 
2216
handlerton *ha_default_handlerton(THD *thd);
 
2217
plugin_ref ha_resolve_by_name(THD *thd, const LEX_STRING *name);
 
2218
plugin_ref ha_lock_engine(THD *thd, handlerton *hton);
 
2219
handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type);
 
2220
handler *get_new_handler(TABLE_SHARE *share, MEM_ROOT *alloc,
 
2221
                         handlerton *db_type);
 
2222
handlerton *ha_checktype(THD *thd, enum legacy_db_type database_type,
 
2223
                          bool no_substitute, bool report_error);
 
2224
 
 
2225
 
 
2226
static inline enum legacy_db_type ha_legacy_type(const handlerton *db_type)
 
2227
{
 
2228
  return (db_type == NULL) ? DB_TYPE_UNKNOWN : db_type->db_type;
 
2229
}
 
2230
 
 
2231
static inline const char *ha_resolve_storage_engine_name(const handlerton *db_type)
 
2232
{
 
2233
  return db_type == NULL ? "UNKNOWN" : hton2plugin[db_type->slot]->name.str;
 
2234
}
 
2235
 
 
2236
static inline bool ha_check_storage_engine_flag(const handlerton *db_type, uint32 flag)
 
2237
{
 
2238
  return db_type == NULL ? FALSE : test(db_type->flags & flag);
 
2239
}
 
2240
 
 
2241
static inline bool ha_storage_engine_is_enabled(const handlerton *db_type)
 
2242
{
 
2243
  return (db_type && db_type->create) ?
 
2244
         (db_type->state == SHOW_OPTION_YES) : FALSE;
 
2245
}
638
2246
 
639
2247
/* basic stuff */
640
 
void ha_init_errors(void);
641
 
 
642
 
class SortField;
643
 
SortField *make_unireg_sortorder(Order *order, uint32_t *length,
644
 
                                 SortField *sortorder);
645
 
int setup_order(Session *session, Item **ref_pointer_array, TableList *tables,
646
 
                List<Item> &fields, List <Item> &all_fields, Order *order);
647
 
int setup_group(Session *session, Item **ref_pointer_array, TableList *tables,
648
 
                List<Item> &fields, List<Item> &all_fields, Order *order,
649
 
                bool *hidden_group_fields);
650
 
bool fix_inner_refs(Session *session, List<Item> &all_fields, Select_Lex *select,
651
 
                    Item **ref_pointer_array);
652
 
 
653
 
bool handle_select(Session *session, LEX *lex, select_result *result,
654
 
                   uint64_t setup_tables_done_option);
655
 
void free_underlaid_joins(Session *session, Select_Lex *select);
656
 
 
657
 
bool mysql_handle_derived(LEX *lex, bool (*processor)(Session *session,
658
 
                                                      LEX *lex,
659
 
                                                      TableList *table));
660
 
bool mysql_derived_prepare(Session *session, LEX *lex, TableList *t);
661
 
bool mysql_derived_filling(Session *session, LEX *lex, TableList *t);
662
 
int prepare_create_field(CreateField *sql_field,
663
 
                         uint32_t *blob_columns,
664
 
                         int *timestamps, int *timestamps_with_niladic);
665
 
 
666
 
bool mysql_create_table(Session *session,
667
 
                        const TableIdentifier &identifier,
668
 
                        HA_CREATE_INFO *create_info,
669
 
                        message::Table &table_proto,
670
 
                        AlterInfo *alter_info,
671
 
                        bool tmp_table, uint32_t select_field_count,
672
 
                        bool is_if_not_exists);
673
 
 
674
 
bool mysql_create_table_no_lock(Session *session,
675
 
                                const TableIdentifier &identifier,
676
 
                                HA_CREATE_INFO *create_info,
677
 
                                message::Table &table_proto,
678
 
                                AlterInfo *alter_info,
679
 
                                bool tmp_table, uint32_t select_field_count,
680
 
                                bool is_if_not_exists);
681
 
 
682
 
bool mysql_create_like_table(Session* session,
683
 
                             const TableIdentifier &destination_identifier,
684
 
                             TableList* table, TableList* src_table,
685
 
                             message::Table &create_table_proto,
686
 
                             bool is_if_not_exists,
687
 
                             bool is_engine_set);
688
 
 
689
 
bool mysql_rename_table(Session &session,
690
 
                        plugin::StorageEngine *base,
691
 
                        const TableIdentifier &old_identifier,
692
 
                        const TableIdentifier &new_identifier);
693
 
 
694
 
bool mysql_prepare_update(Session *session, TableList *table_list,
695
 
                          Item **conds, uint32_t order_num, Order *order);
696
 
int mysql_update(Session *session,TableList *tables,List<Item> &fields,
697
 
                 List<Item> &values,COND *conds,
698
 
                 uint32_t order_num, Order *order, ha_rows limit,
699
 
                 enum enum_duplicates handle_duplicates, bool ignore);
700
 
bool mysql_prepare_insert(Session *session, TableList *table_list, Table *table,
701
 
                          List<Item> &fields, List_item *values,
702
 
                          List<Item> &update_fields,
703
 
                          List<Item> &update_values, enum_duplicates duplic,
704
 
                          COND **where, bool select_insert,
705
 
                          bool check_fields, bool abort_on_warning);
706
 
bool mysql_insert(Session *session,TableList *table,List<Item> &fields,
707
 
                  List<List_item> &values, List<Item> &update_fields,
708
 
                  List<Item> &update_values, enum_duplicates flag,
709
 
                  bool ignore);
710
 
int check_that_all_fields_are_given_values(Session *session, Table *entry,
711
 
                                           TableList *table_list);
712
 
int mysql_prepare_delete(Session *session, TableList *table_list, Item **conds);
713
 
bool mysql_delete(Session *session, TableList *table_list, COND *conds,
714
 
                  SQL_LIST *order, ha_rows rows, uint64_t options,
715
 
                  bool reset_auto_increment);
716
 
bool mysql_truncate(Session& session, TableList *table_list);
717
 
TableShare *get_table_share(Session *session, TableList *table_list, char *key,
718
 
                             uint32_t key_length, uint32_t db_flags, int *error);
719
 
TableShare *get_cached_table_share(const char *db, const char *table_name);
720
 
bool reopen_name_locked_table(Session* session, TableList* table_list, bool link_in);
721
 
bool reopen_tables(Session *session,bool get_locks,bool in_refresh);
722
 
void close_handle_and_leave_table_as_lock(Table *table);
723
 
bool wait_for_tables(Session *session);
724
 
bool table_is_used(Table *table, bool wait_for_name_lock);
725
 
Table *drop_locked_tables(Session *session, const drizzled::TableIdentifier &identifier);
726
 
void abort_locked_tables(Session *session, const drizzled::TableIdentifier &identifier);
727
 
extern Field *not_found_field;
728
 
extern Field *view_ref_found;
729
 
 
730
 
Field *
731
 
find_field_in_tables(Session *session, Item_ident *item,
732
 
                     TableList *first_table, TableList *last_table,
733
 
                     Item **ref, find_item_error_report_type report_error,
734
 
                     bool register_tree_change);
735
 
Field *
736
 
find_field_in_table_ref(Session *session, TableList *table_list,
737
 
                        const char *name, uint32_t length,
738
 
                        const char *item_name, const char *db_name,
739
 
                        const char *table_name, Item **ref,
740
 
                        bool allow_rowid,
741
 
                        uint32_t *cached_field_index_ptr,
742
 
                        bool register_tree_change, TableList **actual_table);
743
 
Field *
744
 
find_field_in_table(Session *session, Table *table, const char *name, uint32_t length,
745
 
                    bool allow_rowid, uint32_t *cached_field_index_ptr);
746
 
 
747
 
} /* namespace drizzled */
748
 
 
749
 
#endif /* DRIZZLED_CURSOR_H */
 
2248
int ha_init_errors(void);
 
2249
int ha_init(void);
 
2250
int ha_end(void);
 
2251
int ha_initialize_handlerton(st_plugin_int *plugin);
 
2252
int ha_finalize_handlerton(st_plugin_int *plugin);
 
2253
 
 
2254
TYPELIB *ha_known_exts(void);
 
2255
int ha_panic(enum ha_panic_function flag);
 
2256
void ha_close_connection(THD* thd);
 
2257
bool ha_flush_logs(handlerton *db_type);
 
2258
void ha_drop_database(char* path);
 
2259
int ha_create_table(THD *thd, const char *path,
 
2260
                    const char *db, const char *table_name,
 
2261
                    HA_CREATE_INFO *create_info,
 
2262
                    bool update_create_info);
 
2263
int ha_delete_table(THD *thd, handlerton *db_type, const char *path,
 
2264
                    const char *db, const char *alias, bool generate_warning);
 
2265
 
 
2266
/* statistics and info */
 
2267
bool ha_show_status(THD *thd, handlerton *db_type, enum ha_stat_type stat);
 
2268
 
 
2269
/* discovery */
 
2270
int ha_create_table_from_engine(THD* thd, const char *db, const char *name);
 
2271
int ha_discover(THD* thd, const char* dbname, const char* name,
 
2272
                uchar** frmblob, size_t* frmlen);
 
2273
int ha_find_files(THD *thd,const char *db,const char *path,
 
2274
                  const char *wild, bool dir, List<LEX_STRING>* files);
 
2275
int ha_table_exists_in_engine(THD* thd, const char* db, const char* name);
 
2276
 
 
2277
/* key cache */
 
2278
extern "C" int ha_init_key_cache(const char *name, KEY_CACHE *key_cache);
 
2279
int ha_resize_key_cache(KEY_CACHE *key_cache);
 
2280
int ha_change_key_cache_param(KEY_CACHE *key_cache);
 
2281
int ha_change_key_cache(KEY_CACHE *old_key_cache, KEY_CACHE *new_key_cache);
 
2282
int ha_end_key_cache(KEY_CACHE *key_cache);
 
2283
 
 
2284
/* report to InnoDB that control passes to the client */
 
2285
int ha_release_temporary_latches(THD *thd);
 
2286
 
 
2287
/* transactions: interface to handlerton functions */
 
2288
int ha_start_consistent_snapshot(THD *thd);
 
2289
int ha_commit_or_rollback_by_xid(XID *xid, bool commit);
 
2290
int ha_commit_one_phase(THD *thd, bool all);
 
2291
int ha_rollback_trans(THD *thd, bool all);
 
2292
int ha_prepare(THD *thd);
 
2293
int ha_recover(HASH *commit_list);
 
2294
 
 
2295
/* transactions: these functions never call handlerton functions directly */
 
2296
int ha_commit_trans(THD *thd, bool all);
 
2297
int ha_autocommit_or_rollback(THD *thd, int error);
 
2298
int ha_enable_transaction(THD *thd, bool on);
 
2299
 
 
2300
/* savepoints */
 
2301
int ha_rollback_to_savepoint(THD *thd, SAVEPOINT *sv);
 
2302
int ha_savepoint(THD *thd, SAVEPOINT *sv);
 
2303
int ha_release_savepoint(THD *thd, SAVEPOINT *sv);
 
2304
 
 
2305
/* these are called by storage engines */
 
2306
void trans_register_ha(THD *thd, bool all, handlerton *ht);
 
2307
 
 
2308
/*
 
2309
  Storage engine has to assume the transaction will end up with 2pc if
 
2310
   - there is more than one 2pc-capable storage engine available
 
2311
   - in the current transaction 2pc was not disabled yet
 
2312
*/
 
2313
#define trans_need_2pc(thd, all)                   ((total_ha_2pc > 1) && \
 
2314
        !((all ? &thd->transaction.all : &thd->transaction.stmt)->no_2pc))
 
2315
 
 
2316
#ifdef HAVE_NDB_BINLOG
 
2317
int ha_reset_logs(THD *thd);
 
2318
int ha_binlog_index_purge_file(THD *thd, const char *file);
 
2319
void ha_reset_slave(THD *thd);
 
2320
void ha_binlog_log_query(THD *thd, handlerton *db_type,
 
2321
                         enum_binlog_command binlog_command,
 
2322
                         const char *query, uint query_length,
 
2323
                         const char *db, const char *table_name);
 
2324
void ha_binlog_wait(THD *thd);
 
2325
int ha_binlog_end(THD *thd);
 
2326
#else
 
2327
#define ha_reset_logs(a) do {} while (0)
 
2328
#define ha_binlog_index_purge_file(a,b) do {} while (0)
 
2329
#define ha_reset_slave(a) do {} while (0)
 
2330
#define ha_binlog_log_query(a,b,c,d,e,f,g) do {} while (0)
 
2331
#define ha_binlog_wait(a) do {} while (0)
 
2332
#define ha_binlog_end(a)  do {} while (0)
 
2333
#endif