~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/handler.h

enable remaining subselect tests, merge with latest from the trunk

Show diffs side-by-side

added added

removed removed

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