~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/handler.h

  • Committer: Stewart Smith
  • Date: 2008-11-21 16:06:07 UTC
  • mto: This revision was merged to the branch mainline in revision 593.
  • Revision ID: stewart@flamingspork.com-20081121160607-n6gdlt013spuo54r
remove mysql_frm_type
and fix engines to return correct value from delete_table when table doesn't exist.
(it should be ENOENT).

Also fix up some tests that manipulated frm files by hand. These tests are no longer valid and will need to be rewritten in the not too distant future.

Show diffs side-by-side

added added

removed removed

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