~drizzle-trunk/drizzle/development

390.1.2 by Monty Taylor
Fixed copyright headers in drizzled/
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
 */
1 by brian
clean slate
19
520.6.4 by Monty Taylor
Moved thr_lock.h out of common_includes.
20
#ifndef DRIZZLED_HANDLER_H
21
#define DRIZZLED_HANDLER_H
1 by brian
clean slate
22
520.4.31 by Monty Taylor
Removed server_id from common_includes.
23
#include <drizzled/xid.h>
24
1 by brian
clean slate
25
/* Definitions for parameters to do with handler-routines */
26
212.4.2 by Monty Taylor
Fixed the includes in places to make the myisam header file move work.
27
#include <storage/myisam/keycache.h>
520.6.4 by Monty Taylor
Moved thr_lock.h out of common_includes.
28
#include <mysys/thr_lock.h>
520.8.3 by Monty Taylor
Moved hash back to mysys.
29
#include <mysys/hash.h>
520.8.5 by Monty Taylor
Removed sql_string and sql_list from common_includes.
30
#include <drizzled/sql_string.h>
31
#include <drizzled/sql_list.h>
575.1.3 by Monty Taylor
Moved some stuff out of handler.h.
32
#include <drizzled/handlerton.h>
33
#include <drizzled/handler_structs.h>
34
#include <drizzled/ha_statistics.h>
520.6.4 by Monty Taylor
Moved thr_lock.h out of common_includes.
35
36
/* Bits to show what an alter table will do */
37
#include <drizzled/sql_bitmap.h>
38
39
#define HA_MAX_ALTER_FLAGS 40
40
typedef Bitmap<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
1 by brian
clean slate
41
42
520.1.22 by Brian Aker
Second pass of thd cleanup
43
typedef bool (*qc_engine_callback)(Session *session, char *table_key,
482 by Brian Aker
Remove uint.
44
                                      uint32_t key_length,
243.1.1 by Jay Pipes
* Pulled Object_creation_ctx and Default_creation_ctx out of mysql_priv.h
45
                                      uint64_t *engine_data);
46
1 by brian
clean slate
47
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
48
/* The handler for a table type.  Will be included in the Table structure */
1 by brian
clean slate
49
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
50
class Table;
561.1.3 by Monty Taylor
Split some more things out of common_includes.h.
51
class TableList;
1 by brian
clean slate
52
typedef struct st_table_share TABLE_SHARE;
53
struct st_foreign_key_info;
54
typedef struct st_foreign_key_info FOREIGN_KEY_INFO;
584.1.13 by Monty Taylor
Split out a little more code. Removed table_list.h from common_includes.
55
struct order_st;
1 by brian
clean slate
56
57
class Item;
58
struct st_table_log_memory_entry;
59
575.4.7 by Monty Taylor
More header cleanup.
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;
71
1 by brian
clean slate
72
typedef struct st_savepoint SAVEPOINT;
61 by Brian Aker
Conversion of handler type.
73
extern uint32_t savepoint_alloc_size;
1 by brian
clean slate
74
extern KEY_CREATE_INFO default_key_create_info;
75
76
/* Forward declaration for condition pushdown to storage engine */
77
typedef class Item COND;
78
79
typedef struct system_status_var SSV;
80
575.1.3 by Monty Taylor
Moved some stuff out of handler.h.
81
class COST_VECT;
82
482 by Brian Aker
Remove uint.
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);
1 by brian
clean slate
85
482 by Brian Aker
Remove uint.
86
uint32_t calculate_key_len(Table *, uint, const unsigned char *, key_part_map);
1 by brian
clean slate
87
/*
88
  bitmap with first N+1 bits set
89
  (keypart_map for a key prefix of [0..N] keyparts)
90
*/
575.1.3 by Monty Taylor
Moved some stuff out of handler.h.
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
1 by brian
clean slate
97
/*
98
  bitmap with first N bits set
99
  (keypart_map for a key prefix of [0..N-1] keyparts)
100
*/
575.1.3 by Monty Taylor
Moved some stuff out of handler.h.
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
}
1 by brian
clean slate
106
107
/**
108
  The handler class is the interface for dynamically loadable
109
  storage engines. Do not add ifdefs and take care when adding or
110
  changing virtual functions to avoid vtable confusion
111
112
  Functions in this class accept and return table columns data. Two data
113
  representation formats are used:
114
  1. TableRecordFormat - Used to pass [partial] table records to/from
115
     storage engine
116
117
  2. KeyTupleFormat - used to pass index search tuples (aka "keys") to
118
     storage engine. See opt_range.cc for description of this format.
119
120
  TableRecordFormat
121
  =================
122
  [Warning: this description is work in progress and may be incomplete]
123
  The table record is stored in a fixed-size buffer:
124
   
125
    record: null_bytes, column1_data, column2_data, ...
126
  
127
  The offsets of the parts of the buffer are also fixed: every column has 
128
  an offset to its column{i}_data, and if it is nullable it also has its own
129
  bit in null_bytes. 
130
131
  The record buffer only includes data about columns that are marked in the
132
  relevant column set (table->read_set and/or table->write_set, depending on
133
  the situation). 
134
  <not-sure>It could be that it is required that null bits of non-present
135
  columns are set to 1</not-sure>
136
137
  VARIOUS EXCEPTIONS AND SPECIAL CASES
138
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 
141
  at all times. </not-sure>
142
  
143
  If the table has columns of type BIT, then certain bits from those columns
144
  may be stored in null_bytes as well. Grep around for Field_bit for
145
  details.
146
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 
149
  by the storage engine and is valid until the next operation.
150
151
  If a blob column has NULL value, then its length and blob data pointer
152
  must be set to 0.
153
*/
154
155
class handler :public Sql_alloc
156
{
157
public:
158
  typedef uint64_t Table_flags;
159
protected:
160
  struct st_table_share *table_share;   /* The table definition */
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
161
  Table *table;               /* The current open table */
1 by brian
clean slate
162
  Table_flags cached_table_flags;       /* Set on init() and open() */
163
164
  ha_rows estimation_rows_to_insert;
165
public:
166
  handlerton *ht;                 /* storage engine of this handler */
481 by Brian Aker
Remove all of uchar.
167
  unsigned char *ref;				/* Pointer to current row */
168
  unsigned char *dup_ref;			/* Pointer to duplicate row */
1 by brian
clean slate
169
170
  ha_statistics stats;
171
  /** MultiRangeRead-related members: */
172
  range_seq_t mrr_iter;    /* Interator to traverse the range sequence */
173
  RANGE_SEQ_IF mrr_funcs;  /* Range sequence traversal functions */
174
  HANDLER_BUFFER *multi_range_buffer; /* MRR buffer info */
482 by Brian Aker
Remove uint.
175
  uint32_t ranges_in_seq; /* Total number of ranges in the traversed sequence */
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
176
  /* true <=> source MRR ranges and the output are ordered */
1 by brian
clean slate
177
  bool mrr_is_output_sorted;
178
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
179
  /** true <=> we're currently traversing a range in mrr_cur_range. */
1 by brian
clean slate
180
  bool mrr_have_range;
181
  /** Current range (the one we're now returning rows from) */
182
  KEY_MULTI_RANGE mrr_cur_range;
183
184
  /** The following are for read_range() */
185
  key_range save_end_range, *end_range;
186
  KEY_PART_INFO *range_key_part;
187
  int key_compare_result_on_equal;
188
  bool eq_range;
189
  /* 
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
190
    true <=> the engine guarantees that returned records are within the range
1 by brian
clean slate
191
    being scanned.
192
  */
193
  bool in_range_check_pushed_down;
194
482 by Brian Aker
Remove uint.
195
  uint32_t errkey;				/* Last dup key */
196
  uint32_t key_used_on_scan;
197
  uint32_t active_index;
1 by brian
clean slate
198
  /** Length of ref (1-8 or the clustered key length) */
482 by Brian Aker
Remove uint.
199
  uint32_t ref_length;
1 by brian
clean slate
200
  enum {NONE=0, INDEX, RND} inited;
201
  bool locked;
202
  bool implicit_emptied;                /* Can be !=0 only if HEAP */
203
  const Item *pushed_cond;
204
205
  Item *pushed_idx_cond;
482 by Brian Aker
Remove uint.
206
  uint32_t pushed_idx_cond_keyno;  /* The index which the above condition is for */
1 by brian
clean slate
207
208
  /**
209
    next_insert_id is the next value which should be inserted into the
210
    auto_increment column: in a inserting-multi-row statement (like INSERT
211
    SELECT), for the first row where the autoinc value is not specified by the
212
    statement, get_auto_increment() called and asked to generate a value,
213
    next_insert_id is set to the next value, then for all other rows
214
    next_insert_id is used (and increased each time) without calling
215
    get_auto_increment().
216
  */
217
  uint64_t next_insert_id;
218
  /**
219
    insert id for the current row (*autogenerated*; if not
220
    autogenerated, it's 0).
221
    At first successful insertion, this variable is stored into
520.1.21 by Brian Aker
THD -> Session rename
222
    Session::first_successful_insert_id_in_cur_stmt.
1 by brian
clean slate
223
  */
224
  uint64_t insert_id_for_cur_row;
225
  /**
226
    Interval returned by get_auto_increment() and being consumed by the
227
    inserter.
228
  */
229
  Discrete_interval auto_inc_interval_for_cur_row;
230
231
  handler(handlerton *ht_arg, TABLE_SHARE *share_arg)
232
    :table_share(share_arg), table(0),
233
    estimation_rows_to_insert(0), ht(ht_arg),
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
234
    ref(0), in_range_check_pushed_down(false),
1 by brian
clean slate
235
    key_used_on_scan(MAX_KEY), active_index(MAX_KEY),
236
    ref_length(sizeof(my_off_t)),
137 by Brian Aker
Removed dead FT bits. Small refactoring in sql_plugin.cc
237
    inited(NONE),
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
238
    locked(false), implicit_emptied(0),
1 by brian
clean slate
239
    pushed_cond(0), pushed_idx_cond(NULL), pushed_idx_cond_keyno(MAX_KEY),
240
    next_insert_id(0), insert_id_for_cur_row(0)
241
    {}
242
  virtual ~handler(void)
243
  {
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
244
    assert(locked == false);
245
    /* TODO: assert(inited == NONE); */
1 by brian
clean slate
246
  }
247
  virtual handler *clone(MEM_ROOT *mem_root);
248
  /** This is called after create to allow us to set up cached variables */
249
  void init()
250
  {
251
    cached_table_flags= table_flags();
252
  }
575.1.4 by Monty Taylor
Moved implementation of some methods into handler.cc from handler.h.
253
1 by brian
clean slate
254
  /* ha_ methods: pubilc wrappers for private virtual API */
255
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
256
  int ha_open(Table *table, const char *name, int mode, int test_if_locked);
575.1.4 by Monty Taylor
Moved implementation of some methods into handler.cc from handler.h.
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();
1 by brian
clean slate
261
  int ha_reset();
575.1.4 by Monty Taylor
Moved implementation of some methods into handler.cc from handler.h.
262
1 by brian
clean slate
263
  /* this is necessary in many places, e.g. in HANDLER command */
575.1.4 by Monty Taylor
Moved implementation of some methods into handler.cc from handler.h.
264
  int ha_index_or_rnd_end();
265
  Table_flags ha_table_flags() const;
266
1 by brian
clean slate
267
  /**
268
    These functions represent the public interface to *users* of the
269
    handler class, hence they are *not* virtual. For the inheritance
270
    interface, see the (private) functions write_row(), update_row(),
271
    and delete_row() below.
272
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
273
  int ha_external_lock(Session *session, int lock_type);
481 by Brian Aker
Remove all of uchar.
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);
1 by brian
clean slate
277
  void ha_release_auto_increment();
278
279
  int ha_check_for_upgrade(HA_CHECK_OPT *check_opt);
280
  /** to be actually called to get 'check()' functionality*/
520.1.22 by Brian Aker
Second pass of thd cleanup
281
  int ha_check(Session *session, HA_CHECK_OPT *check_opt);
282
  int ha_repair(Session* session, HA_CHECK_OPT* check_opt);
575.1.4 by Monty Taylor
Moved implementation of some methods into handler.cc from handler.h.
283
  void ha_start_bulk_insert(ha_rows rows);
284
  int ha_end_bulk_insert();
481 by Brian Aker
Remove all of uchar.
285
  int ha_bulk_update_row(const unsigned char *old_data, unsigned char *new_data,
482 by Brian Aker
Remove uint.
286
                         uint32_t *dup_key_found);
1 by brian
clean slate
287
  int ha_delete_all_rows();
288
  int ha_reset_auto_increment(uint64_t value);
520.1.22 by Brian Aker
Second pass of thd cleanup
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);
482 by Brian Aker
Remove uint.
292
  int ha_disable_indexes(uint32_t mode);
293
  int ha_enable_indexes(uint32_t mode);
200 by Brian Aker
my_bool from handler and set_var
294
  int ha_discard_or_import_tablespace(bool discard);
1 by brian
clean slate
295
  void ha_prepare_for_alter();
296
  int ha_rename_table(const char *from, const char *to);
297
  int ha_delete_table(const char *name);
298
  void ha_drop_table(const char *name);
299
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
300
  int ha_create(const char *name, Table *form, HA_CREATE_INFO *info);
1 by brian
clean slate
301
302
  int ha_create_handler_files(const char *name, const char *old_name,
303
                              int action_flag, HA_CREATE_INFO *info);
304
305
  void adjust_next_insert_id_after_explicit_value(uint64_t nr);
306
  int update_auto_increment();
482 by Brian Aker
Remove uint.
307
  void print_keydup_error(uint32_t key_nr, const char *msg);
1 by brian
clean slate
308
  virtual void print_error(int error, myf errflag);
309
  virtual bool get_error_message(int error, String *buf);
482 by Brian Aker
Remove uint.
310
  uint32_t get_dup_key(int error);
575.1.4 by Monty Taylor
Moved implementation of some methods into handler.cc from handler.h.
311
  virtual void change_table_ptr(Table *table_arg, TABLE_SHARE *share);
312
1 by brian
clean slate
313
  /* Estimates calculation */
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
314
  virtual double scan_time(void)
151 by Brian Aker
Ulonglong to uint64_t
315
  { return uint64_t2double(stats.data_file_length) / IO_SIZE + 2; }
645 by Brian Aker
Cleanup unused attribute
316
  virtual double read_time(uint32_t, uint32_t ranges, ha_rows rows)
1 by brian
clean slate
317
  { return rows2double(ranges+rows); }
318
482 by Brian Aker
Remove uint.
319
  virtual double index_only_read_time(uint32_t keynr, double records);
1 by brian
clean slate
320
  
482 by Brian Aker
Remove uint.
321
  virtual ha_rows multi_range_read_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
1 by brian
clean slate
322
                                              void *seq_init_param, 
482 by Brian Aker
Remove uint.
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);
1 by brian
clean slate
327
  virtual int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
482 by Brian Aker
Remove uint.
328
                                    uint32_t n_ranges, uint32_t mode,
1 by brian
clean slate
329
                                    HANDLER_BUFFER *buf);
330
  virtual int multi_range_read_next(char **range_info);
331
332
575.1.4 by Monty Taylor
Moved implementation of some methods into handler.cc from handler.h.
333
  virtual const key_map *keys_to_use_for_scanning();
334
  bool has_transactions();
482 by Brian Aker
Remove uint.
335
  virtual uint32_t extra_rec_buf_length() const { return 0; }
1 by brian
clean slate
336
337
  /**
338
    This method is used to analyse the error to see whether the error
339
    is ignorable or not, certain handlers can have more error that are
340
    ignorable than others. E.g. the partition handler can get inserts
341
    into a range where there is no partition and this is an ignorable
342
    error.
343
    HA_ERR_FOUND_DUP_UNIQUE is a special case in MyISAM that means the
344
    same thing as HA_ERR_FOUND_DUP_KEY but can in some cases lead to
345
    a slightly different error message.
346
  */
575.1.4 by Monty Taylor
Moved implementation of some methods into handler.cc from handler.h.
347
  virtual bool is_fatal_error(int error, uint32_t flags);
1 by brian
clean slate
348
349
  /**
350
    Number of rows in table. It will only be called if
351
    (table_flags() & (HA_HAS_RECORDS | HA_STATS_RECORDS_IS_EXACT)) != 0
352
  */
575.1.5 by Monty Taylor
Moved stuff to handlerton.cc
353
  virtual ha_rows records();
1 by brian
clean slate
354
  /**
355
    Return upper bound of current number of records in the table
356
    (max. of how many records one will retrieve when doing a full table scan)
357
    If upper bound is not known, HA_POS_ERROR should be returned as a max
358
    possible upper bound.
359
  */
360
  virtual ha_rows estimate_rows_upper_bound()
361
  { return stats.records+EXTRA_RECORDS; }
362
363
  /**
364
    Get the row type from the storage engine.  If this method returns
365
    ROW_TYPE_NOT_USED, the information in HA_CREATE_INFO should be used.
366
  */
367
  virtual enum row_type get_row_type() const { return ROW_TYPE_NOT_USED; }
368
645 by Brian Aker
Cleanup unused attribute
369
  virtual const char *index_type(uint32_t)
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
370
  { assert(0); return "";}
1 by brian
clean slate
371
372
373
  /**
374
    Signal that the table->read_set and table->write_set table maps changed
375
    The handler is allowed to set additional bits in the above map in this
376
    call. Normally the handler should ignore all calls until we have done
377
    a ha_rnd_init() or ha_index_init(), write_row(), update_row or delete_row()
378
    as there may be several calls to this routine.
379
  */
380
  virtual void column_bitmaps_signal();
482 by Brian Aker
Remove uint.
381
  uint32_t get_index(void) const { return active_index; }
1 by brian
clean slate
382
  virtual int close(void)=0;
383
384
  /**
385
    @retval  0   Bulk update used by handler
386
    @retval  1   Bulk update not used, normal operation used
387
  */
388
  virtual bool start_bulk_update() { return 1; }
389
  /**
390
    @retval  0   Bulk delete used by handler
391
    @retval  1   Bulk delete not used, normal operation used
392
  */
393
  virtual bool start_bulk_delete() { return 1; }
394
  /**
395
    After this call all outstanding updates must be performed. The number
396
    of duplicate key errors are reported in the duplicate key parameter.
397
    It is allowed to continue to the batched update after this call, the
398
    handler has to wait until end_bulk_update with changing state.
399
400
    @param    dup_key_found       Number of duplicate keys found
401
402
    @retval  0           Success
403
    @retval  >0          Error code
404
  */
645 by Brian Aker
Cleanup unused attribute
405
  virtual int exec_bulk_update(uint32_t *)
1 by brian
clean slate
406
  {
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
407
    assert(false);
1 by brian
clean slate
408
    return HA_ERR_WRONG_COMMAND;
409
  }
410
  /**
411
    Perform any needed clean-up, no outstanding updates are there at the
412
    moment.
413
  */
414
  virtual void end_bulk_update() { return; }
415
  /**
416
    Execute all outstanding deletes and close down the bulk delete.
417
418
    @retval 0             Success
419
    @retval >0            Error code
420
  */
421
  virtual int end_bulk_delete()
422
  {
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
423
    assert(false);
1 by brian
clean slate
424
    return HA_ERR_WRONG_COMMAND;
425
  }
426
  /**
427
     @brief
428
     Positions an index cursor to the index specified in the handle. Fetches the
429
     row if available. If the key value is null, begin at the first key of the
430
     index.
431
  */
481 by Brian Aker
Remove all of uchar.
432
  virtual int index_read_map(unsigned char * buf, const unsigned char * key,
1 by brian
clean slate
433
                             key_part_map keypart_map,
434
                             enum ha_rkey_function find_flag)
435
  {
482 by Brian Aker
Remove uint.
436
    uint32_t key_len= calculate_key_len(table, active_index, key, keypart_map);
1 by brian
clean slate
437
    return  index_read(buf, key, key_len, find_flag);
438
  }
439
  /**
440
     @brief
441
     Positions an index cursor to the index specified in the handle. Fetches the
442
     row if available. If the key value is null, begin at the first key of the
443
     index.
444
  */
482 by Brian Aker
Remove uint.
445
  virtual int index_read_idx_map(unsigned char * buf, uint32_t index, const unsigned char * key,
1 by brian
clean slate
446
                                 key_part_map keypart_map,
447
                                 enum ha_rkey_function find_flag);
645 by Brian Aker
Cleanup unused attribute
448
  virtual int index_next(unsigned char *)
449
   { return  HA_ERR_WRONG_COMMAND; }
450
  virtual int index_prev(unsigned char *)
451
   { return  HA_ERR_WRONG_COMMAND; }
452
  virtual int index_first(unsigned char *)
453
   { return  HA_ERR_WRONG_COMMAND; }
454
  virtual int index_last(unsigned char *)
455
   { return  HA_ERR_WRONG_COMMAND; }
456
  virtual int index_next_same(unsigned char *, const unsigned char *, uint32_t);
1 by brian
clean slate
457
  /**
458
     @brief
459
     The following functions works like index_read, but it find the last
460
     row with the current key value or prefix.
461
  */
481 by Brian Aker
Remove all of uchar.
462
  virtual int index_read_last_map(unsigned char * buf, const unsigned char * key,
1 by brian
clean slate
463
                                  key_part_map keypart_map)
464
  {
482 by Brian Aker
Remove uint.
465
    uint32_t key_len= calculate_key_len(table, active_index, key, keypart_map);
1 by brian
clean slate
466
    return index_read_last(buf, key, key_len);
467
  }
468
  virtual int read_range_first(const key_range *start_key,
469
                               const key_range *end_key,
470
                               bool eq_range, bool sorted);
471
  virtual int read_range_next();
472
  int compare_key(key_range *range);
473
  int compare_key2(key_range *range);
645 by Brian Aker
Cleanup unused attribute
474
  virtual int rnd_next(unsigned char *)=0;
475
  virtual int rnd_pos(unsigned char *, unsigned char *)=0;
1 by brian
clean slate
476
  /**
477
    One has to use this method when to find
478
    random position by record as the plain
479
    position() call doesn't work for some
480
    handlers for random position.
481
  */
481 by Brian Aker
Remove all of uchar.
482
  virtual int rnd_pos_by_record(unsigned char *record);
482 by Brian Aker
Remove uint.
483
  virtual int read_first_row(unsigned char *buf, uint32_t primary_key);
1 by brian
clean slate
484
  /**
485
    The following function is only needed for tables that may be temporary
486
    tables during joins.
487
  */
645 by Brian Aker
Cleanup unused attribute
488
  virtual int restart_rnd_next(unsigned char *, unsigned char *)
489
    { return HA_ERR_WRONG_COMMAND; }
490
  virtual int rnd_same(unsigned char *, uint32_t)
491
    { return HA_ERR_WRONG_COMMAND; }
492
  virtual ha_rows records_in_range(uint32_t, key_range *, key_range *)
1 by brian
clean slate
493
    { return (ha_rows) 10; }
481 by Brian Aker
Remove all of uchar.
494
  virtual void position(const unsigned char *record)=0;
1 by brian
clean slate
495
  virtual int info(uint)=0; // see my_base.h for full description
645 by Brian Aker
Cleanup unused attribute
496
  virtual uint32_t calculate_key_hash_value(Field **)
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
497
  { assert(0); return 0; }
645 by Brian Aker
Cleanup unused attribute
498
  virtual int extra(enum ha_extra_function)
1 by brian
clean slate
499
  { return 0; }
645 by Brian Aker
Cleanup unused attribute
500
  virtual int extra_opt(enum ha_extra_function operation, uint32_t)
1 by brian
clean slate
501
  { return extra(operation); }
502
503
  /**
504
    In an UPDATE or DELETE, if the row under the cursor was locked by another
505
    transaction, and the engine used an optimistic read of the last
506
    committed row value under the cursor, then the engine returns 1 from this
507
    function. MySQL must NOT try to update this optimistic value. If the
508
    optimistic value does not match the WHERE condition, MySQL can decide to
509
    skip over this row. Currently only works for InnoDB. This can be used to
510
    avoid unnecessary lock waits.
511
512
    If this method returns nonzero, it will also signal the storage
513
    engine that the next read will be a locking re-read of the row.
514
  */
515
  virtual bool was_semi_consistent_read() { return 0; }
516
  /**
517
    Tell the engine whether it should avoid unnecessary lock waits.
518
    If yes, in an UPDATE or DELETE, if the row under the cursor was locked
519
    by another transaction, the engine may try an optimistic read of
520
    the last committed row value under the cursor.
521
  */
522
  virtual void try_semi_consistent_read(bool) {}
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
523
  virtual void unlock_row(void) {}
645 by Brian Aker
Cleanup unused attribute
524
  virtual int start_stmt(Session *, thr_lock_type)
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
525
  {return 0;}
1 by brian
clean slate
526
  virtual void get_auto_increment(uint64_t offset, uint64_t increment,
527
                                  uint64_t nb_desired_values,
528
                                  uint64_t *first_value,
529
                                  uint64_t *nb_reserved_values);
530
  void set_next_insert_id(uint64_t id)
531
  {
532
    next_insert_id= id;
533
  }
534
  void restore_auto_increment(uint64_t prev_insert_id)
535
  {
536
    /*
537
      Insertion of a row failed, re-use the lastly generated auto_increment
538
      id, for the next row. This is achieved by resetting next_insert_id to
539
      what it was before the failed insertion (that old value is provided by
540
      the caller). If that value was 0, it was the first row of the INSERT;
541
      then if insert_id_for_cur_row contains 0 it means no id was generated
542
      for this first row, so no id was generated since the INSERT started, so
543
      we should set next_insert_id to 0; if insert_id_for_cur_row is not 0, it
544
      is the generated id of the first and failed row, so we use it.
545
    */
546
    next_insert_id= (prev_insert_id > 0) ? prev_insert_id :
547
      insert_id_for_cur_row;
548
  }
549
645 by Brian Aker
Cleanup unused attribute
550
  virtual void update_create_info(HA_CREATE_INFO *) {}
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
551
  int check_old_types(void);
645 by Brian Aker
Cleanup unused attribute
552
  virtual int assign_to_keycache(Session*, HA_CHECK_OPT *)
1 by brian
clean slate
553
  { return HA_ADMIN_NOT_IMPLEMENTED; }
554
  /* end of the list of admin commands */
555
556
  virtual int indexes_are_disabled(void) {return 0;}
557
  virtual char *update_table_comment(const char * comment)
558
  { return (char*) comment;}
645 by Brian Aker
Cleanup unused attribute
559
  virtual void append_create_info(String *)
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
560
  {}
1 by brian
clean slate
561
  /**
562
      If index == MAX_KEY then a check for table is made and if index <
563
      MAX_KEY then a check is made if the table has foreign keys and if
564
      a foreign key uses this index (and thus the index cannot be dropped).
565
566
    @param  index            Index to check if foreign key uses it
567
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
568
    @retval   true            Foreign key defined on table or index
569
    @retval   false           No foreign key defined
1 by brian
clean slate
570
  */
645 by Brian Aker
Cleanup unused attribute
571
  virtual bool is_fk_defined_on_table_or_index(uint32_t)
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
572
  { return false; }
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
573
  virtual char* get_foreign_key_create_info(void)
1 by brian
clean slate
574
  { return(NULL);}  /* gets foreign key create string from InnoDB */
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
575
  /** used in ALTER Table; 1 if changing storage engine is allowed */
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
576
  virtual bool can_switch_engines(void) { return 1; }
1 by brian
clean slate
577
  /** used in REPLACE; is > 0 if table is referred by a FOREIGN KEY */
645 by Brian Aker
Cleanup unused attribute
578
  virtual int get_foreign_key_list(Session *, List<FOREIGN_KEY_INFO> *)
1 by brian
clean slate
579
  { return 0; }
482 by Brian Aker
Remove uint.
580
  virtual uint32_t referenced_by_foreign_key() { return 0;}
1 by brian
clean slate
581
  virtual void init_table_handle_for_HANDLER()
582
  { return; }       /* prepare InnoDB for HANDLER */
645 by Brian Aker
Cleanup unused attribute
583
  virtual void free_foreign_key_create_info(char *) {}
1 by brian
clean slate
584
  /** The following can be called without an open handler */
585
  virtual const char *table_type() const =0;
586
  /**
587
    If frm_error() is called then we will use this to find out what file
588
    extentions exist for the storage engine. This is also used by the default
589
    rename_table and delete_table method in handler.cc.
590
591
    For engines that have two file name extentions (separate meta/index file
592
    and data file), the order of elements is relevant. First element of engine
593
    file name extentions array should be meta/index file extention. Second
594
    element - data file extention. This order is assumed by
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
595
    prepare_for_repair() when REPAIR Table ... USE_FRM is issued.
1 by brian
clean slate
596
  */
597
  virtual const char **bas_ext() const =0;
598
645 by Brian Aker
Cleanup unused attribute
599
  virtual int get_default_no_partitions(HA_CREATE_INFO *) { return 1;}
600
  virtual bool get_no_parts(const char *, uint32_t *no_parts)
1 by brian
clean slate
601
  {
602
    *no_parts= 0;
603
    return 0;
604
  }
605
482 by Brian Aker
Remove uint.
606
  virtual uint32_t index_flags(uint32_t idx, uint32_t part, bool all_parts) const =0;
1 by brian
clean slate
607
645 by Brian Aker
Cleanup unused attribute
608
  virtual int add_index(Table *, KEY *, uint32_t)
609
  { return (HA_ERR_WRONG_COMMAND); }
610
  virtual int prepare_drop_index(Table *, uint32_t *, uint32_t)
611
  { return (HA_ERR_WRONG_COMMAND); }
612
  virtual int final_drop_index(Table *)
1 by brian
clean slate
613
  { return (HA_ERR_WRONG_COMMAND); }
614
482 by Brian Aker
Remove uint.
615
  uint32_t max_record_length() const
398.1.4 by Monty Taylor
Renamed max/min.
616
  { return cmin((unsigned int)HA_MAX_REC_LENGTH, max_supported_record_length()); }
482 by Brian Aker
Remove uint.
617
  uint32_t max_keys() const
398.1.4 by Monty Taylor
Renamed max/min.
618
  { return cmin((unsigned int)MAX_KEY, max_supported_keys()); }
482 by Brian Aker
Remove uint.
619
  uint32_t max_key_parts() const
398.1.4 by Monty Taylor
Renamed max/min.
620
  { return cmin((unsigned int)MAX_REF_PARTS, max_supported_key_parts()); }
482 by Brian Aker
Remove uint.
621
  uint32_t max_key_length() const
398.1.4 by Monty Taylor
Renamed max/min.
622
  { return cmin((unsigned int)MAX_KEY_LENGTH, max_supported_key_length()); }
482 by Brian Aker
Remove uint.
623
  uint32_t max_key_part_length(void) const
398.1.4 by Monty Taylor
Renamed max/min.
624
  { return cmin((unsigned int)MAX_KEY_LENGTH, max_supported_key_part_length()); }
1 by brian
clean slate
625
482 by Brian Aker
Remove uint.
626
  virtual uint32_t max_supported_record_length(void) const
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
627
  { return HA_MAX_REC_LENGTH; }
482 by Brian Aker
Remove uint.
628
  virtual uint32_t max_supported_keys(void) const { return 0; }
629
  virtual uint32_t max_supported_key_parts(void) const { return MAX_REF_PARTS; }
630
  virtual uint32_t max_supported_key_length(void) const { return MAX_KEY_LENGTH; }
631
  virtual uint32_t max_supported_key_part_length(void) const { return 255; }
645 by Brian Aker
Cleanup unused attribute
632
  virtual uint32_t min_record_length(uint32_t) const
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
633
  { return 1; }
1 by brian
clean slate
634
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
635
  virtual bool low_byte_first(void) const { return 1; }
482 by Brian Aker
Remove uint.
636
  virtual uint32_t checksum(void) const { return 0; }
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
637
  virtual bool is_crashed(void) const  { return 0; }
638
  virtual bool auto_repair(void) const { return 0; }
1 by brian
clean slate
639
640
641
#define CHF_CREATE_FLAG 0
642
#define CHF_DELETE_FLAG 1
643
#define CHF_RENAME_FLAG 2
644
645
646
  /**
647
    @note lock_count() can return > 1 if the table is MERGE or partitioned.
648
  */
482 by Brian Aker
Remove uint.
649
  virtual uint32_t lock_count(void) const { return 1; }
1 by brian
clean slate
650
  /**
651
    Is not invoked for non-transactional temporary tables.
652
653
    @note store_lock() can return more than one lock if the table is MERGE
654
    or partitioned.
655
656
    @note that one can NOT rely on table->in_use in store_lock().  It may
657
    refer to a different thread if called from mysql_lock_abort_for_thread().
658
659
    @note If the table is MERGE, store_lock() can return less locks
660
    than lock_count() claimed. This can happen when the MERGE children
661
    are not attached when this is called from another thread.
662
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
663
  virtual THR_LOCK_DATA **store_lock(Session *session,
1 by brian
clean slate
664
                                     THR_LOCK_DATA **to,
665
                                     enum thr_lock_type lock_type)=0;
666
667
  /** Type of table for caching query */
206 by Brian Aker
Removed final uint dead types.
668
  virtual uint8_t table_cache_type() { return HA_CACHE_TBL_NONTRANSACT; }
1 by brian
clean slate
669
670
671
  /**
672
    @brief Register a named table with a call back function to the query cache.
673
520.1.22 by Brian Aker
Second pass of thd cleanup
674
    @param session The thread handle
1 by brian
clean slate
675
    @param table_key A pointer to the table name in the table cache
676
    @param key_length The length of the table name
677
    @param[out] engine_callback The pointer to the storage engine call back
678
      function
679
    @param[out] engine_data Storage engine specific data which could be
680
      anything
681
682
    This method offers the storage engine, the possibility to store a reference
683
    to a table name which is going to be used with query cache. 
684
    The method is called each time a statement is written to the cache and can
685
    be used to verify if a specific statement is cachable. It also offers
686
    the possibility to register a generic (but static) call back function which
687
    is called each time a statement is matched against the query cache.
688
689
    @note If engine_data supplied with this function is different from
690
      engine_data supplied with the callback function, and the callback returns
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
691
      false, a table invalidation on the current table will occur.
1 by brian
clean slate
692
693
    @return Upon success the engine_callback will point to the storage engine
694
      call back function, if any, and engine_data will point to any storage
695
      engine data used in the specific implementation.
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
696
      @retval true Success
697
      @retval false The specified table or current statement should not be
1 by brian
clean slate
698
        cached
699
  */
700
200 by Brian Aker
my_bool from handler and set_var
701
  virtual bool
645 by Brian Aker
Cleanup unused attribute
702
    register_query_cache_table(Session *, char *, uint32_t,
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
703
                               qc_engine_callback *engine_callback,
645 by Brian Aker
Cleanup unused attribute
704
                               uint64_t *)
1 by brian
clean slate
705
  {
706
    *engine_callback= 0;
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
707
    return true;
1 by brian
clean slate
708
  }
709
710
711
 /*
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
712
   @retval true   Primary key (if there is one) is clustered
1 by brian
clean slate
713
                  key covering all fields
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
714
   @retval false  otherwise
1 by brian
clean slate
715
 */
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
716
 virtual bool primary_key_is_clustered() { return false; }
481 by Brian Aker
Remove all of uchar.
717
 virtual int cmp_ref(const unsigned char *ref1, const unsigned char *ref2)
1 by brian
clean slate
718
 {
719
   return memcmp(ref1, ref2, ref_length);
720
 }
721
722
 /*
723
   Condition pushdown to storage engines
724
 */
725
726
 /**
727
   Push condition down to the table handler.
728
729
   @param  cond   Condition to be pushed. The condition tree must not be
730
                  modified by the by the caller.
731
732
   @return
733
     The 'remainder' condition that caller must use to filter out records.
734
     NULL means the handler will not return rows that do not match the
735
     passed condition.
736
737
   @note
738
   The pushed conditions form a stack (from which one can remove the
739
   last pushed condition using cond_pop).
740
   The table handler filters out rows using (pushed_cond1 AND pushed_cond2 
741
   AND ... AND pushed_condN)
742
   or less restrictive condition, depending on handler's capabilities.
743
744
   handler->ha_reset() call empties the condition stack.
745
   Calls to rnd_init/rnd_end, index_init/index_end etc do not affect the
746
   condition stack.
747
 */ 
748
 virtual const COND *cond_push(const COND *cond) { return cond; }
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
749
1 by brian
clean slate
750
 /**
751
   Pop the top condition from the condition stack of the handler instance.
752
753
   Pops the top if condition stack, if stack is not empty.
754
 */
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
755
 virtual void cond_pop(void) { return; }
1 by brian
clean slate
756
645 by Brian Aker
Cleanup unused attribute
757
 virtual Item *idx_cond_push(uint32_t, Item *idx_cond)
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
758
 { return idx_cond; }
1 by brian
clean slate
759
760
 /*
761
    Part of old fast alter table, to be depricated
762
  */
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
763
 virtual bool
645 by Brian Aker
Cleanup unused attribute
764
   check_if_incompatible_data(HA_CREATE_INFO *, uint32_t)
1 by brian
clean slate
765
 { return COMPATIBLE_DATA_NO; }
766
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
767
 /* On-line ALTER Table interface */
1 by brian
clean slate
768
769
 /**
770
    Check if a storage engine supports a particular alter table on-line
771
772
    @param    altered_table     A temporary table show what table is to
773
                                change to
774
    @param    create_info       Information from the parsing phase about new
775
                                table properties.
776
    @param    alter_flags       Bitmask that shows what will be changed
777
    @param    table_changes     Shows if table layout has changed (for
778
                                backwards compatibility with
779
                                check_if_incompatible_data
780
781
    @retval   HA_ALTER_ERROR                Unexpected error
782
    @retval   HA_ALTER_SUPPORTED_WAIT_LOCK  Supported, but requires DDL lock
783
    @retval   HA_ALTER_SUPPORTED_NO_LOCK    Supported
784
    @retval   HA_ALTER_NOT_SUPPORTED        Not supported
785
786
    @note
787
      The default implementation is implemented to support fast
788
      alter table (storage engines that support some changes by
789
      just changing the frm file) without any change in the handler
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
790
      implementation.
1 by brian
clean slate
791
 */
645 by Brian Aker
Cleanup unused attribute
792
 virtual int check_if_supported_alter(Table *, HA_CREATE_INFO *create_info,
793
                                      HA_ALTER_FLAGS * alter_flags, uint32_t table_changes)
1 by brian
clean slate
794
 {
795
   if (this->check_if_incompatible_data(create_info, table_changes)
796
       == COMPATIBLE_DATA_NO)
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
797
     return(HA_ALTER_NOT_SUPPORTED);
383.7.1 by Andrey Zhakov
Initial submit of code and tests
798
   else if ((*alter_flags & HA_ALTER_STORED_VCOL).is_set())
799
     return(HA_ALTER_NOT_SUPPORTED);
1 by brian
clean slate
800
   else
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
801
     return(HA_ALTER_SUPPORTED_WAIT_LOCK);
1 by brian
clean slate
802
 }
803
 /**
804
   Tell storage engine to prepare for the on-line alter table (pre-alter)
805
520.1.22 by Brian Aker
Second pass of thd cleanup
806
   @param     session               The thread handle
1 by brian
clean slate
807
   @param     altered_table     A temporary table show what table is to
808
                                change to
809
   @param     alter_info        Storage place for data used during phase1
810
                                and phase2
811
   @param     alter_flags       Bitmask that shows what will be changed
812
813
   @retval   0      OK
814
   @retval   error  error code passed from storage engine
815
 */
645 by Brian Aker
Cleanup unused attribute
816
 virtual int alter_table_phase1(Session *, Table *, HA_CREATE_INFO *, HA_ALTER_INFO *,
817
                                HA_ALTER_FLAGS *)
1 by brian
clean slate
818
 {
819
   return HA_ERR_UNSUPPORTED;
820
 }
821
 /**
822
    Tell storage engine to perform the on-line alter table (alter)
823
520.1.22 by Brian Aker
Second pass of thd cleanup
824
    @param    session               The thread handle
1 by brian
clean slate
825
    @param    altered_table     A temporary table show what table is to
826
                                change to
827
    @param    alter_info        Storage place for data used during phase1
828
                                and phase2
829
    @param    alter_flags       Bitmask that shows what will be changed
830
831
    @retval  0      OK
832
    @retval  error  error code passed from storage engine
833
834
    @note
835
      If check_if_supported_alter returns HA_ALTER_SUPPORTED_WAIT_LOCK
836
      this call is to be wrapped with a DDL lock. This is currently NOT
837
      supported.
838
 */
645 by Brian Aker
Cleanup unused attribute
839
 virtual int alter_table_phase2(Session *, Table *, HA_CREATE_INFO *, HA_ALTER_INFO *,
840
                                HA_ALTER_FLAGS *)
1 by brian
clean slate
841
 {
842
   return HA_ERR_UNSUPPORTED;
843
 }
844
 /**
845
    Tell storage engine that changed frm file is now on disk and table
846
    has been re-opened (post-alter)
847
520.1.22 by Brian Aker
Second pass of thd cleanup
848
    @param    session               The thread handle
1 by brian
clean slate
849
    @param    table             The altered table, re-opened
850
 */
645 by Brian Aker
Cleanup unused attribute
851
 virtual int alter_table_phase3(Session *, Table *)
1 by brian
clean slate
852
 {
853
   return HA_ERR_UNSUPPORTED;
854
 }
855
856
  /**
857
    use_hidden_primary_key() is called in case of an update/delete when
858
    (table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
859
    but we don't have a primary key
860
  */
861
  virtual void use_hidden_primary_key();
862
863
  /**
864
    Lock table.
865
520.1.22 by Brian Aker
Second pass of thd cleanup
866
    @param    session                     Thread handle
1 by brian
clean slate
867
    @param    lock_type               HA_LOCK_IN_SHARE_MODE     (F_RDLCK)
868
                                      HA_LOCK_IN_EXCLUSIVE_MODE (F_WRLCK)
869
    @param    lock_timeout            -1 default timeout
870
                                      0  no wait
871
                                      >0 wait timeout in milliseconds.
872
873
   @note
874
      lock_timeout >0 is not used by MySQL currently. If the storage
875
      engine does not support NOWAIT (lock_timeout == 0) it should
876
      return an error. But if it does not support WAIT X (lock_timeout
877
      >0) it should treat it as lock_timeout == -1 and wait a default
878
      (or even hard-coded) timeout.
879
880
    @retval HA_ERR_WRONG_COMMAND      Storage engine does not support
881
                                      lock_table()
882
    @retval HA_ERR_UNSUPPORTED        Storage engine does not support NOWAIT
883
    @retval HA_ERR_LOCK_WAIT_TIMEOUT  Lock request timed out or
884
                                      lock conflict with NOWAIT option
885
    @retval HA_ERR_LOCK_DEADLOCK      Deadlock detected
886
  */
645 by Brian Aker
Cleanup unused attribute
887
  virtual int lock_table(Session *, int, int)
1 by brian
clean slate
888
  {
889
    return HA_ERR_WRONG_COMMAND;
890
  }
383.7.1 by Andrey Zhakov
Initial submit of code and tests
891
  /*
892
    This procedure defines if the storage engine supports virtual columns.
893
    Default false means "not supported".
894
  */
895
  virtual bool check_if_supported_virtual_columns(void) 
896
  { return false; }
1 by brian
clean slate
897
898
protected:
899
  /* Service methods for use by storage engines. */
900
  void ha_statistic_increment(ulong SSV::*offset) const;
520.1.21 by Brian Aker
THD -> Session rename
901
  void **ha_data(Session *) const;
520.1.22 by Brian Aker
Second pass of thd cleanup
902
  Session *ha_session(void) const;
1 by brian
clean slate
903
904
  /**
905
    Default rename_table() and delete_table() rename/delete files with a
906
    given name and extensions from bas_ext().
907
908
    These methods can be overridden, but their default implementation
909
    provide useful functionality.
910
  */
911
  virtual int rename_table(const char *from, const char *to);
912
  /**
913
    Delete a table in the engine. Called for base as well as temporary
914
    tables.
915
  */
916
  virtual int delete_table(const char *name);
917
918
private:
919
  /* Private helpers */
920
  inline void mark_trx_read_write();
921
private:
922
  /*
923
    Low-level primitives for storage engines.  These should be
924
    overridden by the storage engine class. To call these methods, use
925
    the corresponding 'ha_*' method above.
926
  */
927
482 by Brian Aker
Remove uint.
928
  virtual int open(const char *name, int mode, uint32_t test_if_locked)=0;
645 by Brian Aker
Cleanup unused attribute
929
  virtual int index_init(uint32_t idx, bool)
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
930
  { active_index= idx; return 0; }
1 by brian
clean slate
931
  virtual int index_end() { active_index= MAX_KEY; return 0; }
932
  /**
933
    rnd_init() can be called two times without rnd_end() in between
934
    (it only makes sense if scan=1).
935
    then the second call should prepare for the new table scan (e.g
936
    if rnd_init allocates the cursor, second call should position it
937
    to the start of the table, no need to deallocate and allocate it again
938
  */
939
  virtual int rnd_init(bool scan)= 0;
940
  virtual int rnd_end() { return 0; }
645 by Brian Aker
Cleanup unused attribute
941
  virtual int write_row(unsigned char *)
942
  {
943
    return HA_ERR_WRONG_COMMAND;
944
  }
945
946
  virtual int update_row(const unsigned char *, unsigned char *)
947
  {
948
    return HA_ERR_WRONG_COMMAND;
949
  }
950
951
  virtual int delete_row(const unsigned char *)
1 by brian
clean slate
952
  {
953
    return HA_ERR_WRONG_COMMAND;
954
  }
955
  /**
956
    Reset state of file to after 'open'.
957
    This function is called after every statement for all tables used
958
    by that statement.
959
  */
960
  virtual int reset() { return 0; }
961
  virtual Table_flags table_flags(void) const= 0;
962
963
  /**
964
    Is not invoked for non-transactional temporary tables.
965
966
    Tells the storage engine that we intend to read or write data
967
    from the table. This call is prefixed with a call to handler::store_lock()
968
    and is invoked only for those handler instances that stored the lock.
969
970
    Calls to rnd_init/index_init are prefixed with this call. When table
971
    IO is complete, we call external_lock(F_UNLCK).
972
    A storage engine writer should expect that each call to
973
    ::external_lock(F_[RD|WR]LOCK is followed by a call to
974
    ::external_lock(F_UNLCK). If it is not, it is a bug in MySQL.
975
976
    The name and signature originate from the first implementation
977
    in MyISAM, which would call fcntl to set/clear an advisory
978
    lock on the data file in this method.
979
980
    @param   lock_type    F_RDLCK, F_WRLCK, F_UNLCK
981
982
    @return  non-0 in case of failure, 0 in case of success.
983
    When lock_type is F_UNLCK, the return value is ignored.
984
  */
645 by Brian Aker
Cleanup unused attribute
985
  virtual int external_lock(Session *, int)
1 by brian
clean slate
986
  {
987
    return 0;
988
  }
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
989
  virtual void release_auto_increment(void) { return; };
1 by brian
clean slate
990
  /** admin commands - called from mysql_admin_table */
645 by Brian Aker
Cleanup unused attribute
991
  virtual int check_for_upgrade(HA_CHECK_OPT *)
1 by brian
clean slate
992
  { return 0; }
645 by Brian Aker
Cleanup unused attribute
993
  virtual int check(Session *, HA_CHECK_OPT *)
1 by brian
clean slate
994
  { return HA_ADMIN_NOT_IMPLEMENTED; }
995
996
  /**
997
     In this method check_opt can be modified
998
     to specify CHECK option to use to call check()
999
     upon the table.
1000
  */
645 by Brian Aker
Cleanup unused attribute
1001
  virtual int repair(Session *, HA_CHECK_OPT *)
1 by brian
clean slate
1002
  { return HA_ADMIN_NOT_IMPLEMENTED; }
645 by Brian Aker
Cleanup unused attribute
1003
  virtual void start_bulk_insert(ha_rows)
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
1004
  {}
1005
  virtual int end_bulk_insert(void) { return 0; }
645 by Brian Aker
Cleanup unused attribute
1006
  virtual int index_read(unsigned char *, const unsigned char *, 
1007
                         uint32_t, enum ha_rkey_function)
1 by brian
clean slate
1008
   { return  HA_ERR_WRONG_COMMAND; }
645 by Brian Aker
Cleanup unused attribute
1009
  virtual int index_read_last(unsigned char *, const unsigned char *, uint32_t)
1 by brian
clean slate
1010
   { return (my_errno= HA_ERR_WRONG_COMMAND); }
1011
  /**
1012
    This method is similar to update_row, however the handler doesn't need
1013
    to execute the updates at this point in time. The handler can be certain
1014
    that another call to bulk_update_row will occur OR a call to
1015
    exec_bulk_update before the set of updates in this query is concluded.
1016
1017
    @param    old_data       Old record
1018
    @param    new_data       New record
1019
    @param    dup_key_found  Number of duplicate keys found
1020
1021
    @retval  0   Bulk delete used by handler
1022
    @retval  1   Bulk delete not used, normal operation used
1023
  */
645 by Brian Aker
Cleanup unused attribute
1024
  virtual int bulk_update_row(const unsigned char *, unsigned char *, uint32_t *)
1 by brian
clean slate
1025
  {
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
1026
    assert(false);
1 by brian
clean slate
1027
    return HA_ERR_WRONG_COMMAND;
1028
  }
1029
  /**
1030
    This is called to delete all rows in a table
1031
    If the handler don't support this, then this function will
1032
    return HA_ERR_WRONG_COMMAND and MySQL will delete the rows one
1033
    by one.
1034
  */
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
1035
  virtual int delete_all_rows(void)
1 by brian
clean slate
1036
  { return (my_errno=HA_ERR_WRONG_COMMAND); }
1037
  /**
1038
    Reset the auto-increment counter to the given value, i.e. the next row
1039
    inserted will get the given value. This is called e.g. after TRUNCATE
1040
    is emulated by doing a 'DELETE FROM t'. HA_ERR_WRONG_COMMAND is
1041
    returned by storage engines that don't support this operation.
1042
  */
645 by Brian Aker
Cleanup unused attribute
1043
  virtual int reset_auto_increment(uint64_t)
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
1044
  { return HA_ERR_WRONG_COMMAND; }
645 by Brian Aker
Cleanup unused attribute
1045
  virtual int optimize(Session *, HA_CHECK_OPT *)
1046
  { return HA_ADMIN_NOT_IMPLEMENTED; }
1047
  virtual int analyze(Session *, HA_CHECK_OPT *)
1048
  { return HA_ADMIN_NOT_IMPLEMENTED; }
1049
  virtual bool check_and_repair(Session *)
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
1050
  { return true; }
645 by Brian Aker
Cleanup unused attribute
1051
  virtual int disable_indexes(uint32_t)
1052
  { return HA_ERR_WRONG_COMMAND; }
1053
  virtual int enable_indexes(uint32_t)
1054
  { return HA_ERR_WRONG_COMMAND; }
1055
  virtual int discard_or_import_tablespace(bool)
1 by brian
clean slate
1056
  { return (my_errno=HA_ERR_WRONG_COMMAND); }
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
1057
  virtual void prepare_for_alter(void) { return; }
1 by brian
clean slate
1058
  virtual void drop_table(const char *name);
645 by Brian Aker
Cleanup unused attribute
1059
  virtual int create(const char *, Table *, HA_CREATE_INFO *)=0;
1 by brian
clean slate
1060
645 by Brian Aker
Cleanup unused attribute
1061
  virtual int create_handler_files(const char *, const char *, int, HA_CREATE_INFO *)
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
1062
  { return false; }
1 by brian
clean slate
1063
};
1064
1065
1066
1067
/**
1068
  A Disk-Sweep MRR interface implementation
1069
1070
  This implementation makes range (and, in the future, 'ref') scans to read
1071
  table rows in disk sweeps. 
1072
  
1073
  Currently it is used by MyISAM and InnoDB. Potentially it can be used with
1074
  any table handler that has non-clustered indexes and on-disk rows.
1075
*/
1076
1077
class DsMrr_impl
1078
{
1079
public:
1080
  typedef void (handler::*range_check_toggle_func_t)(bool on);
1081
1082
  DsMrr_impl()
1083
    : h2(NULL) {};
1084
1085
  handler *h; /* The "owner" handler object. It is used for scanning the index */
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
1086
  Table *table; /* Always equal to h->table */
1 by brian
clean slate
1087
private:
1088
  /*
1089
    Secondary handler object. It is used to retrieve full table rows by
1090
    calling rnd_pos().
1091
  */
1092
  handler *h2;
1093
1094
  /* Buffer to store rowids, or (rowid, range_id) pairs */
481 by Brian Aker
Remove all of uchar.
1095
  unsigned char *rowids_buf;
1096
  unsigned char *rowids_buf_cur;   /* Current position when reading/writing */
1097
  unsigned char *rowids_buf_last;  /* When reading: end of used buffer space */
1098
  unsigned char *rowids_buf_end;   /* End of the buffer */
1 by brian
clean slate
1099
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
1100
  bool dsmrr_eof; /* true <=> We have reached EOF when reading index tuples */
1 by brian
clean slate
1101
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
1102
  /* true <=> need range association, buffer holds {rowid, range_id} pairs */
1 by brian
clean slate
1103
  bool is_mrr_assoc;
1104
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
1105
  bool use_default_impl; /* true <=> shortcut all calls to default MRR impl */
1 by brian
clean slate
1106
public:
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
1107
  void init(handler *h_arg, Table *table_arg)
1 by brian
clean slate
1108
  {
1109
    h= h_arg; 
1110
    table= table_arg;
1111
  }
1112
  int dsmrr_init(handler *h, KEY *key, RANGE_SEQ_IF *seq_funcs, 
482 by Brian Aker
Remove uint.
1113
                 void *seq_init_param, uint32_t n_ranges, uint32_t mode, 
1 by brian
clean slate
1114
                 HANDLER_BUFFER *buf);
1115
  void dsmrr_close();
1116
  int dsmrr_fill_buffer(handler *h);
1117
  int dsmrr_next(handler *h, char **range_info);
1118
482 by Brian Aker
Remove uint.
1119
  int dsmrr_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys, uint32_t *bufsz,
1120
                 uint32_t *flags, COST_VECT *cost);
1 by brian
clean slate
1121
482 by Brian Aker
Remove uint.
1122
  ha_rows dsmrr_info_const(uint32_t keyno, RANGE_SEQ_IF *seq, 
1123
                            void *seq_init_param, uint32_t n_ranges, uint32_t *bufsz,
1124
                            uint32_t *flags, COST_VECT *cost);
1 by brian
clean slate
1125
private:
482 by Brian Aker
Remove uint.
1126
  bool key_uses_partial_cols(uint32_t keyno);
1127
  bool choose_mrr_impl(uint32_t keyno, ha_rows rows, uint32_t *flags, uint32_t *bufsz, 
1 by brian
clean slate
1128
                       COST_VECT *cost);
482 by Brian Aker
Remove uint.
1129
  bool get_disk_sweep_mrr_cost(uint32_t keynr, ha_rows rows, uint32_t flags, 
1130
                               uint32_t *buffer_size, COST_VECT *cost);
1 by brian
clean slate
1131
};
1132
1133
extern const char *ha_row_type[];
1134
extern const char *tx_isolation_names[];
1135
extern const char *binlog_format_names[];
1136
extern TYPELIB tx_isolation_typelib;
1137
extern TYPELIB myisam_stats_method_typelib;
61 by Brian Aker
Conversion of handler type.
1138
extern uint32_t total_ha, total_ha_2pc;
1 by brian
clean slate
1139
1140
       /* Wrapper functions */
520.1.22 by Brian Aker
Second pass of thd cleanup
1141
#define ha_commit(session) (ha_commit_trans((session), true))
1142
#define ha_rollback(session) (ha_rollback_trans((session), true))
1 by brian
clean slate
1143
1144
/* basic stuff */
1145
int ha_init_errors(void);
1146
int ha_init(void);
1147
int ha_end(void);
1148
int ha_initialize_handlerton(st_plugin_int *plugin);
1149
int ha_finalize_handlerton(st_plugin_int *plugin);
1150
1151
TYPELIB *ha_known_exts(void);
520.1.22 by Brian Aker
Second pass of thd cleanup
1152
void ha_close_connection(Session* session);
1 by brian
clean slate
1153
bool ha_flush_logs(handlerton *db_type);
1154
void ha_drop_database(char* path);
520.1.22 by Brian Aker
Second pass of thd cleanup
1155
int ha_create_table(Session *session, const char *path,
1 by brian
clean slate
1156
                    const char *db, const char *table_name,
1157
                    HA_CREATE_INFO *create_info,
1158
                    bool update_create_info);
590.1.7 by Stewart Smith
remove mysql_frm_type
1159
int ha_delete_table(Session *session, const char *path,
1 by brian
clean slate
1160
                    const char *db, const char *alias, bool generate_warning);
1161
1162
/* statistics and info */
520.1.22 by Brian Aker
Second pass of thd cleanup
1163
bool ha_show_status(Session *session, handlerton *db_type, enum ha_stat_type stat);
1 by brian
clean slate
1164
1165
/* discovery */
520.1.22 by Brian Aker
Second pass of thd cleanup
1166
int ha_create_table_from_engine(Session* session, const char *db, const char *name);
1167
int ha_discover(Session* session, const char* dbname, const char* name,
481 by Brian Aker
Remove all of uchar.
1168
                unsigned char** frmblob, size_t* frmlen);
520.1.22 by Brian Aker
Second pass of thd cleanup
1169
int ha_find_files(Session *session,const char *db,const char *path,
1 by brian
clean slate
1170
                  const char *wild, bool dir, List<LEX_STRING>* files);
520.1.22 by Brian Aker
Second pass of thd cleanup
1171
int ha_table_exists_in_engine(Session* session, const char* db, const char* name);
1 by brian
clean slate
1172
1173
/* key cache */
1174
extern "C" int ha_init_key_cache(const char *name, KEY_CACHE *key_cache);
1175
int ha_resize_key_cache(KEY_CACHE *key_cache);
1176
int ha_change_key_cache_param(KEY_CACHE *key_cache);
1177
int ha_change_key_cache(KEY_CACHE *old_key_cache, KEY_CACHE *new_key_cache);
1178
int ha_end_key_cache(KEY_CACHE *key_cache);
1179
1180
/* report to InnoDB that control passes to the client */
520.1.22 by Brian Aker
Second pass of thd cleanup
1181
int ha_release_temporary_latches(Session *session);
1 by brian
clean slate
1182
1183
/* transactions: interface to handlerton functions */
520.1.22 by Brian Aker
Second pass of thd cleanup
1184
int ha_start_consistent_snapshot(Session *session);
1 by brian
clean slate
1185
int ha_commit_or_rollback_by_xid(XID *xid, bool commit);
520.1.22 by Brian Aker
Second pass of thd cleanup
1186
int ha_commit_one_phase(Session *session, bool all);
1187
int ha_rollback_trans(Session *session, bool all);
1188
int ha_prepare(Session *session);
1 by brian
clean slate
1189
int ha_recover(HASH *commit_list);
1190
1191
/* transactions: these functions never call handlerton functions directly */
520.1.22 by Brian Aker
Second pass of thd cleanup
1192
int ha_commit_trans(Session *session, bool all);
1193
int ha_autocommit_or_rollback(Session *session, int error);
1194
int ha_enable_transaction(Session *session, bool on);
1 by brian
clean slate
1195
1196
/* savepoints */
520.1.22 by Brian Aker
Second pass of thd cleanup
1197
int ha_rollback_to_savepoint(Session *session, SAVEPOINT *sv);
1198
int ha_savepoint(Session *session, SAVEPOINT *sv);
1199
int ha_release_savepoint(Session *session, SAVEPOINT *sv);
1 by brian
clean slate
1200
1201
/* these are called by storage engines */
520.1.22 by Brian Aker
Second pass of thd cleanup
1202
void trans_register_ha(Session *session, bool all, handlerton *ht);
1 by brian
clean slate
1203
520.6.7 by Monty Taylor
Moved a bunch of crap out of common_includes.
1204
void table_case_convert(char * name, uint32_t length);
1205
const char *table_case_name(HA_CREATE_INFO *info, const char *name);
1206
1207
extern char reg_ext[FN_EXTLEN];
1208
extern uint32_t reg_ext_length;
1209
extern ulong specialflag;
1210
extern uint32_t lower_case_table_names;
1211
uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length);
1212
uint32_t tablename_to_filename(const char *from, char *to, uint32_t to_length);
1213
1214
575.1.3 by Monty Taylor
Moved some stuff out of handler.h.
1215
bool mysql_ha_open(Session *session, TableList *tables, bool reopen);
1216
bool mysql_ha_close(Session *session, TableList *tables);
1217
bool mysql_ha_read(Session *, TableList *,enum enum_ha_read_modes,char *,
1218
                   List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows);
1219
void mysql_ha_flush(Session *session);
1220
void mysql_ha_rm_tables(Session *session, TableList *tables, bool is_locked);
1221
void mysql_ha_cleanup(Session *session);
1222
1 by brian
clean slate
1223
/*
1224
  Storage engine has to assume the transaction will end up with 2pc if
1225
   - there is more than one 2pc-capable storage engine available
1226
   - in the current transaction 2pc was not disabled yet
1227
*/
520.1.22 by Brian Aker
Second pass of thd cleanup
1228
#define trans_need_2pc(session, all)                   ((total_ha_2pc > 1) && \
1229
        !((all ? &session->transaction.all : &session->transaction.stmt)->no_2pc))
520.6.4 by Monty Taylor
Moved thr_lock.h out of common_includes.
1230
575.4.7 by Monty Taylor
More header cleanup.
1231
1232
bool mysql_xa_recover(Session *session);
1233
1234
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
1235
                                   SORT_FIELD *sortorder);
1236
int setup_order(Session *session, Item **ref_pointer_array, TableList *tables,
1237
                List<Item> &fields, List <Item> &all_fields, order_st *order);
1238
int setup_group(Session *session, Item **ref_pointer_array, TableList *tables,
1239
                List<Item> &fields, List<Item> &all_fields, order_st *order,
1240
                bool *hidden_group_fields);
1241
bool fix_inner_refs(Session *session, List<Item> &all_fields, SELECT_LEX *select,
1242
                    Item **ref_pointer_array);
1243
1244
bool handle_select(Session *session, LEX *lex, select_result *result,
1245
                   ulong setup_tables_done_option);
1246
bool mysql_select(Session *session, Item ***rref_pointer_array,
1247
                  TableList *tables, uint32_t wild_num,  List<Item> &list,
1248
                  COND *conds, uint32_t og_num, order_st *order, order_st *group,
1249
                  Item *having, order_st *proc_param, uint64_t select_type,
1250
                  select_result *result, SELECT_LEX_UNIT *unit,
1251
                  SELECT_LEX *select_lex);
1252
void free_underlaid_joins(Session *session, SELECT_LEX *select);
1253
bool mysql_explain_union(Session *session, SELECT_LEX_UNIT *unit,
1254
                         select_result *result);
1255
int mysql_explain_select(Session *session, SELECT_LEX *sl, char const *type,
1256
                         select_result *result);
1257
bool mysql_union(Session *session, LEX *lex, select_result *result,
1258
                 SELECT_LEX_UNIT *unit, ulong setup_tables_done_option);
1259
bool mysql_handle_derived(LEX *lex, bool (*processor)(Session *session,
1260
                                                      LEX *lex,
1261
                                                      TableList *table));
1262
bool mysql_derived_prepare(Session *session, LEX *lex, TableList *t);
1263
bool mysql_derived_filling(Session *session, LEX *lex, TableList *t);
1264
void sp_prepare_create_field(Session *session, Create_field *sql_field);
1265
int prepare_create_field(Create_field *sql_field,
1266
                         uint32_t *blob_columns,
1267
                         int *timestamps, int *timestamps_with_niladic,
1268
                         int64_t table_flags);
1269
bool mysql_create_table(Session *session,const char *db, const char *table_name,
1270
                        HA_CREATE_INFO *create_info,
1271
                        Alter_info *alter_info,
1272
                        bool tmp_table, uint32_t select_field_count);
1273
bool mysql_create_table_no_lock(Session *session, const char *db,
1274
                                const char *table_name,
1275
                                HA_CREATE_INFO *create_info,
1276
                                Alter_info *alter_info,
1277
                                bool tmp_table, uint32_t select_field_count,
1278
                                bool lock_open_lock);
1279
1280
bool mysql_alter_table(Session *session, char *new_db, char *new_name,
1281
                       HA_CREATE_INFO *create_info,
1282
                       TableList *table_list,
1283
                       Alter_info *alter_info,
1284
                       uint32_t order_num, order_st *order, bool ignore);
1285
bool mysql_recreate_table(Session *session, TableList *table_list);
1286
bool mysql_create_like_table(Session *session, TableList *table,
1287
                             TableList *src_table,
1288
                             HA_CREATE_INFO *create_info);
1289
bool mysql_rename_table(handlerton *base, const char *old_db,
1290
                        const char * old_name, const char *new_db,
1291
                        const char * new_name, uint32_t flags);
1292
bool mysql_prepare_update(Session *session, TableList *table_list,
1293
                          Item **conds, uint32_t order_num, order_st *order);
1294
int mysql_update(Session *session,TableList *tables,List<Item> &fields,
1295
                 List<Item> &values,COND *conds,
1296
                 uint32_t order_num, order_st *order, ha_rows limit,
1297
                 enum enum_duplicates handle_duplicates, bool ignore);
1298
bool mysql_multi_update(Session *session, TableList *table_list,
1299
                        List<Item> *fields, List<Item> *values,
1300
                        COND *conds, uint64_t options,
1301
                        enum enum_duplicates handle_duplicates, bool ignore,
1302
                        SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex);
1303
bool mysql_prepare_insert(Session *session, TableList *table_list, Table *table,
1304
                          List<Item> &fields, List_item *values,
1305
                          List<Item> &update_fields,
1306
                          List<Item> &update_values, enum_duplicates duplic,
1307
                          COND **where, bool select_insert,
1308
                          bool check_fields, bool abort_on_warning);
1309
bool mysql_insert(Session *session,TableList *table,List<Item> &fields,
1310
                  List<List_item> &values, List<Item> &update_fields,
1311
                  List<Item> &update_values, enum_duplicates flag,
1312
                  bool ignore);
1313
int check_that_all_fields_are_given_values(Session *session, Table *entry,
1314
                                           TableList *table_list);
1315
void prepare_triggers_for_insert_stmt(Table *table);
1316
int mysql_prepare_delete(Session *session, TableList *table_list, Item **conds);
1317
bool mysql_delete(Session *session, TableList *table_list, COND *conds,
1318
                  SQL_LIST *order, ha_rows rows, uint64_t options,
1319
                  bool reset_auto_increment);
1320
bool mysql_truncate(Session *session, TableList *table_list, bool dont_send_ok);
1321
uint32_t create_table_def_key(Session *session, char *key, TableList *table_list,
1322
                              bool tmp_table);
1323
TABLE_SHARE *get_table_share(Session *session, TableList *table_list, char *key,
1324
                             uint32_t key_length, uint32_t db_flags, int *error);
1325
void release_table_share(TABLE_SHARE *share, enum release_type type);
1326
TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name);
1327
Table *open_ltable(Session *session, TableList *table_list, thr_lock_type update,
1328
                   uint32_t lock_flags);
1329
Table *open_table(Session *session, TableList *table_list, bool *refresh, uint32_t flags);
1330
bool name_lock_locked_table(Session *session, TableList *tables);
1331
bool reopen_name_locked_table(Session* session, TableList* table_list, bool link_in);
1332
Table *table_cache_insert_placeholder(Session *session, const char *key,
1333
                                      uint32_t key_length);
1334
bool lock_table_name_if_not_cached(Session *session, const char *db,
1335
                                   const char *table_name, Table **table);
1336
Table *find_locked_table(Session *session, const char *db,const char *table_name);
1337
void detach_merge_children(Table *table, bool clear_refs);
1338
bool fix_merge_after_open(TableList *old_child_list, TableList **old_last,
1339
                          TableList *new_child_list, TableList **new_last);
1340
bool reopen_table(Table *table);
1341
bool reopen_tables(Session *session,bool get_locks,bool in_refresh);
1342
void close_data_files_and_morph_locks(Session *session, const char *db,
1343
                                      const char *table_name);
1344
void close_handle_and_leave_table_as_lock(Table *table);
1345
bool open_new_frm(Session *session, TABLE_SHARE *share, const char *alias,
1346
                  uint32_t db_stat, uint32_t prgflag,
1347
                  uint32_t ha_open_flags, Table *outparam,
1348
                  TableList *table_desc, MEM_ROOT *mem_root);
1349
bool wait_for_tables(Session *session);
1350
bool table_is_used(Table *table, bool wait_for_name_lock);
1351
Table *drop_locked_tables(Session *session,const char *db, const char *table_name);
1352
void abort_locked_tables(Session *session,const char *db, const char *table_name);
1353
void execute_init_command(Session *session, sys_var_str *init_command_var,
658 by Brian Aker
Part removal of my_pthread.h
1354
                          pthread_rwlock_t *var_mutex);
575.4.7 by Monty Taylor
More header cleanup.
1355
extern Field *not_found_field;
1356
extern Field *view_ref_found;
1357
1358
Field *
1359
find_field_in_tables(Session *session, Item_ident *item,
1360
                     TableList *first_table, TableList *last_table,
1361
                     Item **ref, find_item_error_report_type report_error,
1362
                     bool check_privileges, bool register_tree_change);
1363
Field *
1364
find_field_in_table_ref(Session *session, TableList *table_list,
1365
                        const char *name, uint32_t length,
1366
                        const char *item_name, const char *db_name,
1367
                        const char *table_name, Item **ref,
1368
                        bool check_privileges, bool allow_rowid,
1369
                        uint32_t *cached_field_index_ptr,
1370
                        bool register_tree_change, TableList **actual_table);
1371
Field *
1372
find_field_in_table(Session *session, Table *table, const char *name, uint32_t length,
1373
                    bool allow_rowid, uint32_t *cached_field_index_ptr);
1374
Field *
1375
find_field_in_table_sef(Table *table, const char *name);
1376
int update_virtual_fields_marked_for_write(Table *table,
1377
                                           bool ignore_stored=true);
1378
1379
520.6.4 by Monty Taylor
Moved thr_lock.h out of common_includes.
1380
#endif /* DRIZZLED_HANDLER_H */