~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/handler.h

  • Committer: Jim Winstead
  • Date: 2008-07-19 02:56:45 UTC
  • mto: (202.1.8 codestyle)
  • mto: This revision was merged to the branch mainline in revision 207.
  • Revision ID: jimw@mysql.com-20080719025645-w2pwytebgzusjzjb
Various fixes to enable compilation on Mac OS X, and remove the glib dependency.
Temporarily disables tab-completion in the drizzle client until an appropriate
autoconf check can be added/enabled.

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