~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>
844 by Brian Aker
Added drizzled/discrete_interval.h
24
#include <drizzled/discrete_interval.h>
520.4.31 by Monty Taylor
Removed server_id from common_includes.
25
1 by brian
clean slate
26
/* Definitions for parameters to do with handler-routines */
27
992.1.25 by Monty Taylor
Moved myisam to new plugin system.
28
#include <plugin/myisam/keycache.h>
520.6.4 by Monty Taylor
Moved thr_lock.h out of common_includes.
29
#include <mysys/thr_lock.h>
520.8.3 by Monty Taylor
Moved hash back to mysys.
30
#include <mysys/hash.h>
520.8.5 by Monty Taylor
Removed sql_string and sql_list from common_includes.
31
#include <drizzled/sql_string.h>
32
#include <drizzled/sql_list.h>
960.2.23 by Monty Taylor
Moved handlerton to plugin/storage_engine.h.
33
#include <drizzled/plugin/storage_engine.h>
575.1.3 by Monty Taylor
Moved some stuff out of handler.h.
34
#include <drizzled/handler_structs.h>
35
#include <drizzled/ha_statistics.h>
1046.1.8 by Brian Aker
Remove race condition around refresh (aka... multi-thread writeable global
36
#include <drizzled/atomics.h>
520.6.4 by Monty Taylor
Moved thr_lock.h out of common_includes.
37
1008.3.20 by Stewart Smith
Put table_name into table proto in parser, and use that when creating table proto file.
38
#include <drizzled/message/table.pb.h>
39
520.6.4 by Monty Taylor
Moved thr_lock.h out of common_includes.
40
/* Bits to show what an alter table will do */
41
#include <drizzled/sql_bitmap.h>
982.1.9 by Padraig O'Sullivan
Changed HA_ALTER_FLAGS to be of type std::bitset instead of being of type
42
1067.4.4 by Nathan Williams
The rest of the files in the drizzled directory were purged of the cmin macro and replace with std::min (except for the definition in globals.h and 1 usage in stacktrace.cc).
43
#include <bitset>
44
#include <algorithm>
1005.2.6 by Monty Taylor
Re-added bitset<> as a replacement for Bitmap<>
45
520.6.4 by Monty Taylor
Moved thr_lock.h out of common_includes.
46
#define HA_MAX_ALTER_FLAGS 40
1005.2.6 by Monty Taylor
Re-added bitset<> as a replacement for Bitmap<>
47
typedef std::bitset<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
1 by brian
clean slate
48
1046.1.8 by Brian Aker
Remove race condition around refresh (aka... multi-thread writeable global
49
extern drizzled::atomic<uint32_t> refresh_version;  /* Increments on each reload */
50
1 by brian
clean slate
51
520.1.22 by Brian Aker
Second pass of thd cleanup
52
typedef bool (*qc_engine_callback)(Session *session, char *table_key,
482 by Brian Aker
Remove uint.
53
                                      uint32_t key_length,
243.1.1 by Jay Pipes
* Pulled Object_creation_ctx and Default_creation_ctx out of mysql_priv.h
54
                                      uint64_t *engine_data);
55
1 by brian
clean slate
56
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
57
/* The handler for a table type.  Will be included in the Table structure */
1 by brian
clean slate
58
327.1.1 by Brian Aker
First pass in encapsulating table (it is now an object, no longer a structure).
59
class Table;
561.1.3 by Monty Taylor
Split some more things out of common_includes.h.
60
class TableList;
1000.1.3 by Brian Aker
Renamed TABLE_SHARE to TableShare
61
class TableShare;
848 by Brian Aker
typdef class removal (just... use the name of the class).
62
class Select_Lex_Unit;
1 by brian
clean slate
63
struct st_foreign_key_info;
64
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.
65
struct order_st;
1 by brian
clean slate
66
67
class Item;
68
struct st_table_log_memory_entry;
69
575.4.7 by Monty Taylor
More header cleanup.
70
class LEX;
846 by Brian Aker
Removing on typedeffed class.
71
class Select_Lex;
575.4.7 by Monty Taylor
More header cleanup.
72
class Alter_info;
73
class select_result;
1052.2.3 by Nathan Williams
No actual code changes. Changed Create_field to CreateField to be consistent with coding standards.
74
class CreateField;
575.4.7 by Monty Taylor
More header cleanup.
75
class sys_var_str;
76
class Item_ident;
77
typedef struct st_sort_field SORT_FIELD;
78
79
typedef List<Item> List_item;
80
1 by brian
clean slate
81
typedef struct st_savepoint SAVEPOINT;
61 by Brian Aker
Conversion of handler type.
82
extern uint32_t savepoint_alloc_size;
1 by brian
clean slate
83
extern KEY_CREATE_INFO default_key_create_info;
84
85
/* Forward declaration for condition pushdown to storage engine */
86
typedef class Item COND;
87
88
typedef struct system_status_var SSV;
89
575.1.3 by Monty Taylor
Moved some stuff out of handler.h.
90
class COST_VECT;
91
482 by Brian Aker
Remove uint.
92
uint32_t calculate_key_len(Table *, uint, const unsigned char *, key_part_map);
1 by brian
clean slate
93
/*
94
  bitmap with first N+1 bits set
95
  (keypart_map for a key prefix of [0..N] keyparts)
96
*/
575.1.3 by Monty Taylor
Moved some stuff out of handler.h.
97
template<class T>
98
inline key_part_map make_keypart_map(T a)
99
{
100
  return (((key_part_map)2 << a) - 1);
101
}
102
1 by brian
clean slate
103
/*
104
  bitmap with first N bits set
105
  (keypart_map for a key prefix of [0..N-1] keyparts)
106
*/
575.1.3 by Monty Taylor
Moved some stuff out of handler.h.
107
template<class T>
108
inline key_part_map make_prev_keypart_map(T a)
109
{
110
  return (((key_part_map)1 << a) - 1);
111
}
1 by brian
clean slate
112
113
/**
114
  The handler class is the interface for dynamically loadable
115
  storage engines. Do not add ifdefs and take care when adding or
116
  changing virtual functions to avoid vtable confusion
117
118
  Functions in this class accept and return table columns data. Two data
119
  representation formats are used:
120
  1. TableRecordFormat - Used to pass [partial] table records to/from
121
     storage engine
122
123
  2. KeyTupleFormat - used to pass index search tuples (aka "keys") to
124
     storage engine. See opt_range.cc for description of this format.
125
126
  TableRecordFormat
127
  =================
128
  [Warning: this description is work in progress and may be incomplete]
129
  The table record is stored in a fixed-size buffer:
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
130
1 by brian
clean slate
131
    record: null_bytes, column1_data, column2_data, ...
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
132
133
  The offsets of the parts of the buffer are also fixed: every column has
1 by brian
clean slate
134
  an offset to its column{i}_data, and if it is nullable it also has its own
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
135
  bit in null_bytes.
1 by brian
clean slate
136
137
  The record buffer only includes data about columns that are marked in the
138
  relevant column set (table->read_set and/or table->write_set, depending on
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
139
  the situation).
1 by brian
clean slate
140
  <not-sure>It could be that it is required that null bits of non-present
141
  columns are set to 1</not-sure>
142
143
  VARIOUS EXCEPTIONS AND SPECIAL CASES
144
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
145
  f the table has no nullable columns, then null_bytes is still
146
  present, its length is one byte <not-sure> which must be set to 0xFF
1 by brian
clean slate
147
  at all times. </not-sure>
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
148
1 by brian
clean slate
149
  If the table has columns of type BIT, then certain bits from those columns
150
  may be stored in null_bytes as well. Grep around for Field_bit for
151
  details.
152
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
153
  For blob columns (see Field_blob), the record buffer stores length of the
154
  data, following by memory pointer to the blob data. The pointer is owned
1 by brian
clean slate
155
  by the storage engine and is valid until the next operation.
156
157
  If a blob column has NULL value, then its length and blob data pointer
158
  must be set to 0.
159
*/
160
161
class handler :public Sql_alloc
162
{
163
public:
164
  typedef uint64_t Table_flags;
796 by Brian Aker
Test case fixes + TABLE_CACHE to class (will rename in manner which is NOT
165
1 by brian
clean slate
166
protected:
1000.1.3 by Brian Aker
Renamed TABLE_SHARE to TableShare
167
  TableShare *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).
168
  Table *table;               /* The current open table */
1 by brian
clean slate
169
  Table_flags cached_table_flags;       /* Set on init() and open() */
170
171
  ha_rows estimation_rows_to_insert;
172
public:
960.2.37 by Monty Taylor
More naming fixes.
173
  StorageEngine *engine;      /* storage engine of this handler */
174
  unsigned char *ref;		  		/* Pointer to current row */
481 by Brian Aker
Remove all of uchar.
175
  unsigned char *dup_ref;			/* Pointer to duplicate row */
1 by brian
clean slate
176
177
  ha_statistics stats;
178
  /** MultiRangeRead-related members: */
179
  range_seq_t mrr_iter;    /* Interator to traverse the range sequence */
180
  RANGE_SEQ_IF mrr_funcs;  /* Range sequence traversal functions */
181
  HANDLER_BUFFER *multi_range_buffer; /* MRR buffer info */
482 by Brian Aker
Remove uint.
182
  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
183
  /* true <=> source MRR ranges and the output are ordered */
1 by brian
clean slate
184
  bool mrr_is_output_sorted;
185
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
186
  /** true <=> we're currently traversing a range in mrr_cur_range. */
1 by brian
clean slate
187
  bool mrr_have_range;
1030.1.1 by Brian Aker
Straighten out structures (remove some some dead bits).
188
189
  bool eq_range;
190
  /*
191
    true <=> the engine guarantees that returned records are within the range
192
    being scanned.
193
  */
194
  bool in_range_check_pushed_down;
195
1 by brian
clean slate
196
  /** Current range (the one we're now returning rows from) */
197
  KEY_MULTI_RANGE mrr_cur_range;
198
199
  /** The following are for read_range() */
200
  key_range save_end_range, *end_range;
201
  KEY_PART_INFO *range_key_part;
202
  int key_compare_result_on_equal;
203
482 by Brian Aker
Remove uint.
204
  uint32_t errkey;				/* Last dup key */
205
  uint32_t key_used_on_scan;
206
  uint32_t active_index;
1 by brian
clean slate
207
  /** Length of ref (1-8 or the clustered key length) */
482 by Brian Aker
Remove uint.
208
  uint32_t ref_length;
1 by brian
clean slate
209
  enum {NONE=0, INDEX, RND} inited;
210
  bool locked;
211
  bool implicit_emptied;                /* Can be !=0 only if HEAP */
212
  const Item *pushed_cond;
213
214
  Item *pushed_idx_cond;
482 by Brian Aker
Remove uint.
215
  uint32_t pushed_idx_cond_keyno;  /* The index which the above condition is for */
1 by brian
clean slate
216
217
  /**
218
    next_insert_id is the next value which should be inserted into the
219
    auto_increment column: in a inserting-multi-row statement (like INSERT
220
    SELECT), for the first row where the autoinc value is not specified by the
221
    statement, get_auto_increment() called and asked to generate a value,
222
    next_insert_id is set to the next value, then for all other rows
223
    next_insert_id is used (and increased each time) without calling
224
    get_auto_increment().
225
  */
226
  uint64_t next_insert_id;
227
  /**
228
    insert id for the current row (*autogenerated*; if not
229
    autogenerated, it's 0).
230
    At first successful insertion, this variable is stored into
520.1.21 by Brian Aker
THD -> Session rename
231
    Session::first_successful_insert_id_in_cur_stmt.
1 by brian
clean slate
232
  */
233
  uint64_t insert_id_for_cur_row;
234
  /**
235
    Interval returned by get_auto_increment() and being consumed by the
236
    inserter.
237
  */
238
  Discrete_interval auto_inc_interval_for_cur_row;
239
1000.1.3 by Brian Aker
Renamed TABLE_SHARE to TableShare
240
  handler(StorageEngine *engine_arg, TableShare *share_arg)
1 by brian
clean slate
241
    :table_share(share_arg), table(0),
960.2.37 by Monty Taylor
More naming fixes.
242
    estimation_rows_to_insert(0), engine(engine_arg),
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
243
    ref(0), in_range_check_pushed_down(false),
1 by brian
clean slate
244
    key_used_on_scan(MAX_KEY), active_index(MAX_KEY),
245
    ref_length(sizeof(my_off_t)),
137 by Brian Aker
Removed dead FT bits. Small refactoring in sql_plugin.cc
246
    inited(NONE),
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
247
    locked(false), implicit_emptied(0),
1 by brian
clean slate
248
    pushed_cond(0), pushed_idx_cond(NULL), pushed_idx_cond_keyno(MAX_KEY),
249
    next_insert_id(0), insert_id_for_cur_row(0)
250
    {}
1022.2.29 by Monty Taylor
Fixed some no-inline warnings.
251
  virtual ~handler(void);
1 by brian
clean slate
252
  virtual handler *clone(MEM_ROOT *mem_root);
253
  /** This is called after create to allow us to set up cached variables */
254
  void init()
255
  {
256
    cached_table_flags= table_flags();
257
  }
575.1.4 by Monty Taylor
Moved implementation of some methods into handler.cc from handler.h.
258
1 by brian
clean slate
259
  /* ha_ methods: pubilc wrappers for private virtual API */
260
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
261
  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.
262
  int ha_index_init(uint32_t idx, bool sorted);
263
  int ha_index_end();
264
  int ha_rnd_init(bool scan);
265
  int ha_rnd_end();
1 by brian
clean slate
266
  int ha_reset();
575.1.4 by Monty Taylor
Moved implementation of some methods into handler.cc from handler.h.
267
1 by brian
clean slate
268
  /* 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.
269
  int ha_index_or_rnd_end();
270
  Table_flags ha_table_flags() const;
271
1 by brian
clean slate
272
  /**
273
    These functions represent the public interface to *users* of the
274
    handler class, hence they are *not* virtual. For the inheritance
275
    interface, see the (private) functions write_row(), update_row(),
276
    and delete_row() below.
277
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
278
  int ha_external_lock(Session *session, int lock_type);
481 by Brian Aker
Remove all of uchar.
279
  int ha_write_row(unsigned char * buf);
280
  int ha_update_row(const unsigned char * old_data, unsigned char * new_data);
281
  int ha_delete_row(const unsigned char * buf);
1 by brian
clean slate
282
  void ha_release_auto_increment();
283
284
  /** to be actually called to get 'check()' functionality*/
520.1.22 by Brian Aker
Second pass of thd cleanup
285
  int ha_check(Session *session, HA_CHECK_OPT *check_opt);
1063.1.1 by Stewart Smith
remove REPAIR TABLE. Is very useful to have, but should be implemented in a much different way (or external to server).
286
575.1.4 by Monty Taylor
Moved implementation of some methods into handler.cc from handler.h.
287
  void ha_start_bulk_insert(ha_rows rows);
288
  int ha_end_bulk_insert();
481 by Brian Aker
Remove all of uchar.
289
  int ha_bulk_update_row(const unsigned char *old_data, unsigned char *new_data,
482 by Brian Aker
Remove uint.
290
                         uint32_t *dup_key_found);
1 by brian
clean slate
291
  int ha_delete_all_rows();
292
  int ha_reset_auto_increment(uint64_t value);
520.1.22 by Brian Aker
Second pass of thd cleanup
293
  int ha_optimize(Session* session, HA_CHECK_OPT* check_opt);
294
  int ha_analyze(Session* session, HA_CHECK_OPT* check_opt);
1063.3.1 by Stewart Smith
remove ha_check_and_repair. Engines should take care of this themselves.
295
482 by Brian Aker
Remove uint.
296
  int ha_disable_indexes(uint32_t mode);
297
  int ha_enable_indexes(uint32_t mode);
200 by Brian Aker
my_bool from handler and set_var
298
  int ha_discard_or_import_tablespace(bool discard);
1 by brian
clean slate
299
  void ha_prepare_for_alter();
300
  void ha_drop_table(const char *name);
301
302
  void adjust_next_insert_id_after_explicit_value(uint64_t nr);
303
  int update_auto_increment();
482 by Brian Aker
Remove uint.
304
  void print_keydup_error(uint32_t key_nr, const char *msg);
1 by brian
clean slate
305
  virtual void print_error(int error, myf errflag);
306
  virtual bool get_error_message(int error, String *buf);
482 by Brian Aker
Remove uint.
307
  uint32_t get_dup_key(int error);
1000.1.3 by Brian Aker
Renamed TABLE_SHARE to TableShare
308
  virtual void change_table_ptr(Table *table_arg, TableShare *share);
575.1.4 by Monty Taylor
Moved implementation of some methods into handler.cc from handler.h.
309
1 by brian
clean slate
310
  /* Estimates calculation */
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
311
  virtual double scan_time(void)
151 by Brian Aker
Ulonglong to uint64_t
312
  { return uint64_t2double(stats.data_file_length) / IO_SIZE + 2; }
645 by Brian Aker
Cleanup unused attribute
313
  virtual double read_time(uint32_t, uint32_t ranges, ha_rows rows)
1 by brian
clean slate
314
  { return rows2double(ranges+rows); }
315
482 by Brian Aker
Remove uint.
316
  virtual double index_only_read_time(uint32_t keynr, double records);
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
317
482 by Brian Aker
Remove uint.
318
  virtual ha_rows multi_range_read_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
319
                                              void *seq_init_param,
482 by Brian Aker
Remove uint.
320
                                              uint32_t n_ranges, uint32_t *bufsz,
321
                                              uint32_t *flags, COST_VECT *cost);
322
  virtual int multi_range_read_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys,
323
                                    uint32_t *bufsz, uint32_t *flags, COST_VECT *cost);
1 by brian
clean slate
324
  virtual int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
482 by Brian Aker
Remove uint.
325
                                    uint32_t n_ranges, uint32_t mode,
1 by brian
clean slate
326
                                    HANDLER_BUFFER *buf);
327
  virtual int multi_range_read_next(char **range_info);
328
329
575.1.4 by Monty Taylor
Moved implementation of some methods into handler.cc from handler.h.
330
  virtual const key_map *keys_to_use_for_scanning();
331
  bool has_transactions();
1 by brian
clean slate
332
333
  /**
334
    This method is used to analyse the error to see whether the error
335
    is ignorable or not, certain handlers can have more error that are
336
    ignorable than others. E.g. the partition handler can get inserts
337
    into a range where there is no partition and this is an ignorable
338
    error.
339
    HA_ERR_FOUND_DUP_UNIQUE is a special case in MyISAM that means the
340
    same thing as HA_ERR_FOUND_DUP_KEY but can in some cases lead to
341
    a slightly different error message.
342
  */
575.1.4 by Monty Taylor
Moved implementation of some methods into handler.cc from handler.h.
343
  virtual bool is_fatal_error(int error, uint32_t flags);
1 by brian
clean slate
344
345
  /**
346
    Number of rows in table. It will only be called if
347
    (table_flags() & (HA_HAS_RECORDS | HA_STATS_RECORDS_IS_EXACT)) != 0
348
  */
575.1.5 by Monty Taylor
Moved stuff to handlerton.cc
349
  virtual ha_rows records();
1 by brian
clean slate
350
  /**
351
    Return upper bound of current number of records in the table
352
    (max. of how many records one will retrieve when doing a full table scan)
353
    If upper bound is not known, HA_POS_ERROR should be returned as a max
354
    possible upper bound.
355
  */
356
  virtual ha_rows estimate_rows_upper_bound()
357
  { return stats.records+EXTRA_RECORDS; }
358
359
  /**
360
    Get the row type from the storage engine.  If this method returns
361
    ROW_TYPE_NOT_USED, the information in HA_CREATE_INFO should be used.
362
  */
363
  virtual enum row_type get_row_type() const { return ROW_TYPE_NOT_USED; }
364
645 by Brian Aker
Cleanup unused attribute
365
  virtual const char *index_type(uint32_t)
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
366
  { assert(0); return "";}
1 by brian
clean slate
367
368
482 by Brian Aker
Remove uint.
369
  uint32_t get_index(void) const { return active_index; }
1 by brian
clean slate
370
  virtual int close(void)=0;
371
372
  /**
373
    @retval  0   Bulk update used by handler
374
    @retval  1   Bulk update not used, normal operation used
375
  */
376
  virtual bool start_bulk_update() { return 1; }
377
  /**
378
    @retval  0   Bulk delete used by handler
379
    @retval  1   Bulk delete not used, normal operation used
380
  */
381
  virtual bool start_bulk_delete() { return 1; }
382
  /**
383
    After this call all outstanding updates must be performed. The number
384
    of duplicate key errors are reported in the duplicate key parameter.
385
    It is allowed to continue to the batched update after this call, the
386
    handler has to wait until end_bulk_update with changing state.
387
388
    @param    dup_key_found       Number of duplicate keys found
389
390
    @retval  0           Success
391
    @retval  >0          Error code
392
  */
645 by Brian Aker
Cleanup unused attribute
393
  virtual int exec_bulk_update(uint32_t *)
1 by brian
clean slate
394
  {
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
395
    assert(false);
1 by brian
clean slate
396
    return HA_ERR_WRONG_COMMAND;
397
  }
398
  /**
399
    Perform any needed clean-up, no outstanding updates are there at the
400
    moment.
401
  */
402
  virtual void end_bulk_update() { return; }
403
  /**
404
    Execute all outstanding deletes and close down the bulk delete.
405
406
    @retval 0             Success
407
    @retval >0            Error code
408
  */
409
  virtual int end_bulk_delete()
410
  {
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
411
    assert(false);
1 by brian
clean slate
412
    return HA_ERR_WRONG_COMMAND;
413
  }
414
  /**
415
     @brief
416
     Positions an index cursor to the index specified in the handle. Fetches the
417
     row if available. If the key value is null, begin at the first key of the
418
     index.
419
  */
481 by Brian Aker
Remove all of uchar.
420
  virtual int index_read_map(unsigned char * buf, const unsigned char * key,
1 by brian
clean slate
421
                             key_part_map keypart_map,
422
                             enum ha_rkey_function find_flag)
423
  {
482 by Brian Aker
Remove uint.
424
    uint32_t key_len= calculate_key_len(table, active_index, key, keypart_map);
1 by brian
clean slate
425
    return  index_read(buf, key, key_len, find_flag);
426
  }
427
  /**
428
     @brief
429
     Positions an index cursor to the index specified in the handle. Fetches the
430
     row if available. If the key value is null, begin at the first key of the
431
     index.
432
  */
656.1.1 by Monty Taylor
OOOh doggie. Got rid of my_alloca.
433
  virtual int index_read_idx_map(unsigned char * buf, uint32_t index,
434
                                 const unsigned char * key,
1 by brian
clean slate
435
                                 key_part_map keypart_map,
436
                                 enum ha_rkey_function find_flag);
645 by Brian Aker
Cleanup unused attribute
437
  virtual int index_next(unsigned char *)
438
   { return  HA_ERR_WRONG_COMMAND; }
439
  virtual int index_prev(unsigned char *)
440
   { return  HA_ERR_WRONG_COMMAND; }
441
  virtual int index_first(unsigned char *)
442
   { return  HA_ERR_WRONG_COMMAND; }
443
  virtual int index_last(unsigned char *)
444
   { return  HA_ERR_WRONG_COMMAND; }
445
  virtual int index_next_same(unsigned char *, const unsigned char *, uint32_t);
1 by brian
clean slate
446
  /**
447
     @brief
448
     The following functions works like index_read, but it find the last
449
     row with the current key value or prefix.
450
  */
481 by Brian Aker
Remove all of uchar.
451
  virtual int index_read_last_map(unsigned char * buf, const unsigned char * key,
1 by brian
clean slate
452
                                  key_part_map keypart_map)
453
  {
482 by Brian Aker
Remove uint.
454
    uint32_t key_len= calculate_key_len(table, active_index, key, keypart_map);
1 by brian
clean slate
455
    return index_read_last(buf, key, key_len);
456
  }
457
  virtual int read_range_first(const key_range *start_key,
458
                               const key_range *end_key,
459
                               bool eq_range, bool sorted);
460
  virtual int read_range_next();
461
  int compare_key(key_range *range);
462
  int compare_key2(key_range *range);
645 by Brian Aker
Cleanup unused attribute
463
  virtual int rnd_next(unsigned char *)=0;
464
  virtual int rnd_pos(unsigned char *, unsigned char *)=0;
1 by brian
clean slate
465
  /**
466
    One has to use this method when to find
467
    random position by record as the plain
468
    position() call doesn't work for some
469
    handlers for random position.
470
  */
481 by Brian Aker
Remove all of uchar.
471
  virtual int rnd_pos_by_record(unsigned char *record);
482 by Brian Aker
Remove uint.
472
  virtual int read_first_row(unsigned char *buf, uint32_t primary_key);
1 by brian
clean slate
473
  /**
474
    The following function is only needed for tables that may be temporary
475
    tables during joins.
476
  */
645 by Brian Aker
Cleanup unused attribute
477
  virtual int restart_rnd_next(unsigned char *, unsigned char *)
478
    { return HA_ERR_WRONG_COMMAND; }
479
  virtual int rnd_same(unsigned char *, uint32_t)
480
    { return HA_ERR_WRONG_COMMAND; }
481
  virtual ha_rows records_in_range(uint32_t, key_range *, key_range *)
1 by brian
clean slate
482
    { return (ha_rows) 10; }
481 by Brian Aker
Remove all of uchar.
483
  virtual void position(const unsigned char *record)=0;
895 by Brian Aker
Completion (?) of uint conversion.
484
  virtual int info(uint32_t)=0; // see my_base.h for full description
645 by Brian Aker
Cleanup unused attribute
485
  virtual uint32_t calculate_key_hash_value(Field **)
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
486
  { assert(0); return 0; }
645 by Brian Aker
Cleanup unused attribute
487
  virtual int extra(enum ha_extra_function)
1 by brian
clean slate
488
  { return 0; }
645 by Brian Aker
Cleanup unused attribute
489
  virtual int extra_opt(enum ha_extra_function operation, uint32_t)
1 by brian
clean slate
490
  { return extra(operation); }
491
492
  /**
493
    In an UPDATE or DELETE, if the row under the cursor was locked by another
494
    transaction, and the engine used an optimistic read of the last
495
    committed row value under the cursor, then the engine returns 1 from this
496
    function. MySQL must NOT try to update this optimistic value. If the
497
    optimistic value does not match the WHERE condition, MySQL can decide to
498
    skip over this row. Currently only works for InnoDB. This can be used to
499
    avoid unnecessary lock waits.
500
501
    If this method returns nonzero, it will also signal the storage
502
    engine that the next read will be a locking re-read of the row.
503
  */
504
  virtual bool was_semi_consistent_read() { return 0; }
505
  /**
506
    Tell the engine whether it should avoid unnecessary lock waits.
507
    If yes, in an UPDATE or DELETE, if the row under the cursor was locked
508
    by another transaction, the engine may try an optimistic read of
509
    the last committed row value under the cursor.
510
  */
511
  virtual void try_semi_consistent_read(bool) {}
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
512
  virtual void unlock_row(void) {}
645 by Brian Aker
Cleanup unused attribute
513
  virtual int start_stmt(Session *, thr_lock_type)
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
514
  {return 0;}
1 by brian
clean slate
515
  virtual void get_auto_increment(uint64_t offset, uint64_t increment,
516
                                  uint64_t nb_desired_values,
517
                                  uint64_t *first_value,
518
                                  uint64_t *nb_reserved_values);
519
  void set_next_insert_id(uint64_t id)
520
  {
521
    next_insert_id= id;
522
  }
523
  void restore_auto_increment(uint64_t prev_insert_id)
524
  {
525
    /*
526
      Insertion of a row failed, re-use the lastly generated auto_increment
527
      id, for the next row. This is achieved by resetting next_insert_id to
528
      what it was before the failed insertion (that old value is provided by
529
      the caller). If that value was 0, it was the first row of the INSERT;
530
      then if insert_id_for_cur_row contains 0 it means no id was generated
531
      for this first row, so no id was generated since the INSERT started, so
532
      we should set next_insert_id to 0; if insert_id_for_cur_row is not 0, it
533
      is the generated id of the first and failed row, so we use it.
534
    */
535
    next_insert_id= (prev_insert_id > 0) ? prev_insert_id :
536
      insert_id_for_cur_row;
537
  }
538
645 by Brian Aker
Cleanup unused attribute
539
  virtual void update_create_info(HA_CREATE_INFO *) {}
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
540
  int check_old_types(void);
645 by Brian Aker
Cleanup unused attribute
541
  virtual int assign_to_keycache(Session*, HA_CHECK_OPT *)
1 by brian
clean slate
542
  { return HA_ADMIN_NOT_IMPLEMENTED; }
543
  /* end of the list of admin commands */
544
545
  virtual int indexes_are_disabled(void) {return 0;}
546
  virtual char *update_table_comment(const char * comment)
547
  { return (char*) comment;}
645 by Brian Aker
Cleanup unused attribute
548
  virtual void append_create_info(String *)
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
549
  {}
1 by brian
clean slate
550
  /**
551
      If index == MAX_KEY then a check for table is made and if index <
552
      MAX_KEY then a check is made if the table has foreign keys and if
553
      a foreign key uses this index (and thus the index cannot be dropped).
554
555
    @param  index            Index to check if foreign key uses it
556
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
557
    @retval   true            Foreign key defined on table or index
558
    @retval   false           No foreign key defined
1 by brian
clean slate
559
  */
645 by Brian Aker
Cleanup unused attribute
560
  virtual bool is_fk_defined_on_table_or_index(uint32_t)
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
561
  { return false; }
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
562
  virtual char* get_foreign_key_create_info(void)
1019.1.6 by Brian Aker
A number of random cleanups.
563
  { return NULL;}  /* gets foreign key create string from InnoDB */
1008.3.25 by Stewart Smith
slight semantic improvement in handler::can_switch_engines
564
  /** used in ALTER Table; if changing storage engine is allowed.
565
      e.g. not be allowed if table has foreign key constraints in engine.
566
   */
567
  virtual bool can_switch_engines(void) { return true; }
1 by brian
clean slate
568
  /** used in REPLACE; is > 0 if table is referred by a FOREIGN KEY */
645 by Brian Aker
Cleanup unused attribute
569
  virtual int get_foreign_key_list(Session *, List<FOREIGN_KEY_INFO> *)
1 by brian
clean slate
570
  { return 0; }
482 by Brian Aker
Remove uint.
571
  virtual uint32_t referenced_by_foreign_key() { return 0;}
1 by brian
clean slate
572
  virtual void init_table_handle_for_HANDLER()
573
  { return; }       /* prepare InnoDB for HANDLER */
645 by Brian Aker
Cleanup unused attribute
574
  virtual void free_foreign_key_create_info(char *) {}
1 by brian
clean slate
575
  /** The following can be called without an open handler */
1008.3.26 by Stewart Smith
remove handler::table_type() as same information can be retrieved from handler::engine->getName()
576
482 by Brian Aker
Remove uint.
577
  virtual uint32_t index_flags(uint32_t idx, uint32_t part, bool all_parts) const =0;
1 by brian
clean slate
578
645 by Brian Aker
Cleanup unused attribute
579
  virtual int add_index(Table *, KEY *, uint32_t)
580
  { return (HA_ERR_WRONG_COMMAND); }
581
  virtual int prepare_drop_index(Table *, uint32_t *, uint32_t)
582
  { return (HA_ERR_WRONG_COMMAND); }
583
  virtual int final_drop_index(Table *)
1 by brian
clean slate
584
  { return (HA_ERR_WRONG_COMMAND); }
585
482 by Brian Aker
Remove uint.
586
  uint32_t max_record_length() const
1067.4.4 by Nathan Williams
The rest of the files in the drizzled directory were purged of the cmin macro and replace with std::min (except for the definition in globals.h and 1 usage in stacktrace.cc).
587
  { return std::min((unsigned int)HA_MAX_REC_LENGTH, max_supported_record_length()); }
482 by Brian Aker
Remove uint.
588
  uint32_t max_keys() const
1067.4.4 by Nathan Williams
The rest of the files in the drizzled directory were purged of the cmin macro and replace with std::min (except for the definition in globals.h and 1 usage in stacktrace.cc).
589
  { return std::min((unsigned int)MAX_KEY, max_supported_keys()); }
482 by Brian Aker
Remove uint.
590
  uint32_t max_key_parts() const
1067.4.4 by Nathan Williams
The rest of the files in the drizzled directory were purged of the cmin macro and replace with std::min (except for the definition in globals.h and 1 usage in stacktrace.cc).
591
  { return std::min((unsigned int)MAX_REF_PARTS, max_supported_key_parts()); }
482 by Brian Aker
Remove uint.
592
  uint32_t max_key_length() const
1067.4.4 by Nathan Williams
The rest of the files in the drizzled directory were purged of the cmin macro and replace with std::min (except for the definition in globals.h and 1 usage in stacktrace.cc).
593
  { return std::min((unsigned int)MAX_KEY_LENGTH, max_supported_key_length()); }
482 by Brian Aker
Remove uint.
594
  uint32_t max_key_part_length(void) const
1067.4.4 by Nathan Williams
The rest of the files in the drizzled directory were purged of the cmin macro and replace with std::min (except for the definition in globals.h and 1 usage in stacktrace.cc).
595
  { return std::min((unsigned int)MAX_KEY_LENGTH, max_supported_key_part_length()); }
1 by brian
clean slate
596
482 by Brian Aker
Remove uint.
597
  virtual uint32_t max_supported_record_length(void) const
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
598
  { return HA_MAX_REC_LENGTH; }
482 by Brian Aker
Remove uint.
599
  virtual uint32_t max_supported_keys(void) const { return 0; }
600
  virtual uint32_t max_supported_key_parts(void) const { return MAX_REF_PARTS; }
601
  virtual uint32_t max_supported_key_length(void) const { return MAX_KEY_LENGTH; }
602
  virtual uint32_t max_supported_key_part_length(void) const { return 255; }
1 by brian
clean slate
603
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
604
  virtual bool low_byte_first(void) const { return 1; }
482 by Brian Aker
Remove uint.
605
  virtual uint32_t checksum(void) const { return 0; }
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
606
  virtual bool is_crashed(void) const  { return 0; }
607
  virtual bool auto_repair(void) const { return 0; }
1 by brian
clean slate
608
609
  /**
610
    Is not invoked for non-transactional temporary tables.
611
612
    @note store_lock() can return more than one lock if the table is MERGE
613
    or partitioned.
614
615
    @note that one can NOT rely on table->in_use in store_lock().  It may
616
    refer to a different thread if called from mysql_lock_abort_for_thread().
617
618
    @note If the table is MERGE, store_lock() can return less locks
619
    than lock_count() claimed. This can happen when the MERGE children
620
    are not attached when this is called from another thread.
621
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
622
  virtual THR_LOCK_DATA **store_lock(Session *session,
1 by brian
clean slate
623
                                     THR_LOCK_DATA **to,
624
                                     enum thr_lock_type lock_type)=0;
625
626
 /*
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
627
   @retval true   Primary key (if there is one) is clustered
1 by brian
clean slate
628
                  key covering all fields
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
629
   @retval false  otherwise
1 by brian
clean slate
630
 */
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
631
 virtual bool primary_key_is_clustered() { return false; }
481 by Brian Aker
Remove all of uchar.
632
 virtual int cmp_ref(const unsigned char *ref1, const unsigned char *ref2)
1 by brian
clean slate
633
 {
634
   return memcmp(ref1, ref2, ref_length);
635
 }
636
637
 /*
638
   Condition pushdown to storage engines
639
 */
640
641
 /**
642
   Push condition down to the table handler.
643
644
   @param  cond   Condition to be pushed. The condition tree must not be
645
                  modified by the by the caller.
646
647
   @return
648
     The 'remainder' condition that caller must use to filter out records.
649
     NULL means the handler will not return rows that do not match the
650
     passed condition.
651
652
   @note
653
   The pushed conditions form a stack (from which one can remove the
654
   last pushed condition using cond_pop).
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
655
   The table handler filters out rows using (pushed_cond1 AND pushed_cond2
1 by brian
clean slate
656
   AND ... AND pushed_condN)
657
   or less restrictive condition, depending on handler's capabilities.
658
659
   handler->ha_reset() call empties the condition stack.
660
   Calls to rnd_init/rnd_end, index_init/index_end etc do not affect the
661
   condition stack.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
662
 */
1 by brian
clean slate
663
 virtual const COND *cond_push(const COND *cond) { return cond; }
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
664
1 by brian
clean slate
665
 /**
666
   Pop the top condition from the condition stack of the handler instance.
667
668
   Pops the top if condition stack, if stack is not empty.
669
 */
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
670
 virtual void cond_pop(void) { return; }
1 by brian
clean slate
671
645 by Brian Aker
Cleanup unused attribute
672
 virtual Item *idx_cond_push(uint32_t, Item *idx_cond)
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
673
 { return idx_cond; }
1 by brian
clean slate
674
675
  /**
676
    Lock table.
677
520.1.22 by Brian Aker
Second pass of thd cleanup
678
    @param    session                     Thread handle
1 by brian
clean slate
679
    @param    lock_type               HA_LOCK_IN_SHARE_MODE     (F_RDLCK)
680
                                      HA_LOCK_IN_EXCLUSIVE_MODE (F_WRLCK)
681
    @param    lock_timeout            -1 default timeout
682
                                      0  no wait
683
                                      >0 wait timeout in milliseconds.
684
685
   @note
686
      lock_timeout >0 is not used by MySQL currently. If the storage
687
      engine does not support NOWAIT (lock_timeout == 0) it should
688
      return an error. But if it does not support WAIT X (lock_timeout
689
      >0) it should treat it as lock_timeout == -1 and wait a default
690
      (or even hard-coded) timeout.
691
692
    @retval HA_ERR_WRONG_COMMAND      Storage engine does not support
693
                                      lock_table()
694
    @retval HA_ERR_UNSUPPORTED        Storage engine does not support NOWAIT
695
    @retval HA_ERR_LOCK_WAIT_TIMEOUT  Lock request timed out or
696
                                      lock conflict with NOWAIT option
697
    @retval HA_ERR_LOCK_DEADLOCK      Deadlock detected
698
  */
645 by Brian Aker
Cleanup unused attribute
699
  virtual int lock_table(Session *, int, int)
1 by brian
clean slate
700
  {
701
    return HA_ERR_WRONG_COMMAND;
702
  }
703
704
protected:
705
  /* Service methods for use by storage engines. */
706
  void ha_statistic_increment(ulong SSV::*offset) const;
520.1.21 by Brian Aker
THD -> Session rename
707
  void **ha_data(Session *) const;
520.1.22 by Brian Aker
Second pass of thd cleanup
708
  Session *ha_session(void) const;
1 by brian
clean slate
709
710
private:
711
  /* Private helpers */
712
  inline void mark_trx_read_write();
713
private:
714
  /*
715
    Low-level primitives for storage engines.  These should be
716
    overridden by the storage engine class. To call these methods, use
717
    the corresponding 'ha_*' method above.
718
  */
719
482 by Brian Aker
Remove uint.
720
  virtual int open(const char *name, int mode, uint32_t test_if_locked)=0;
645 by Brian Aker
Cleanup unused attribute
721
  virtual int index_init(uint32_t idx, bool)
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
722
  { active_index= idx; return 0; }
1 by brian
clean slate
723
  virtual int index_end() { active_index= MAX_KEY; return 0; }
724
  /**
725
    rnd_init() can be called two times without rnd_end() in between
726
    (it only makes sense if scan=1).
727
    then the second call should prepare for the new table scan (e.g
728
    if rnd_init allocates the cursor, second call should position it
729
    to the start of the table, no need to deallocate and allocate it again
730
  */
731
  virtual int rnd_init(bool scan)= 0;
732
  virtual int rnd_end() { return 0; }
645 by Brian Aker
Cleanup unused attribute
733
  virtual int write_row(unsigned char *)
734
  {
735
    return HA_ERR_WRONG_COMMAND;
736
  }
737
738
  virtual int update_row(const unsigned char *, unsigned char *)
739
  {
740
    return HA_ERR_WRONG_COMMAND;
741
  }
742
743
  virtual int delete_row(const unsigned char *)
1 by brian
clean slate
744
  {
745
    return HA_ERR_WRONG_COMMAND;
746
  }
747
  /**
748
    Reset state of file to after 'open'.
749
    This function is called after every statement for all tables used
750
    by that statement.
751
  */
752
  virtual int reset() { return 0; }
753
  virtual Table_flags table_flags(void) const= 0;
754
755
  /**
756
    Is not invoked for non-transactional temporary tables.
757
758
    Tells the storage engine that we intend to read or write data
759
    from the table. This call is prefixed with a call to handler::store_lock()
760
    and is invoked only for those handler instances that stored the lock.
761
762
    Calls to rnd_init/index_init are prefixed with this call. When table
763
    IO is complete, we call external_lock(F_UNLCK).
764
    A storage engine writer should expect that each call to
765
    ::external_lock(F_[RD|WR]LOCK is followed by a call to
766
    ::external_lock(F_UNLCK). If it is not, it is a bug in MySQL.
767
768
    The name and signature originate from the first implementation
769
    in MyISAM, which would call fcntl to set/clear an advisory
770
    lock on the data file in this method.
771
772
    @param   lock_type    F_RDLCK, F_WRLCK, F_UNLCK
773
774
    @return  non-0 in case of failure, 0 in case of success.
775
    When lock_type is F_UNLCK, the return value is ignored.
776
  */
645 by Brian Aker
Cleanup unused attribute
777
  virtual int external_lock(Session *, int)
1 by brian
clean slate
778
  {
779
    return 0;
780
  }
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
781
  virtual void release_auto_increment(void) { return; };
1 by brian
clean slate
782
  /** admin commands - called from mysql_admin_table */
645 by Brian Aker
Cleanup unused attribute
783
  virtual int check_for_upgrade(HA_CHECK_OPT *)
1 by brian
clean slate
784
  { return 0; }
645 by Brian Aker
Cleanup unused attribute
785
  virtual int check(Session *, HA_CHECK_OPT *)
1 by brian
clean slate
786
  { return HA_ADMIN_NOT_IMPLEMENTED; }
787
645 by Brian Aker
Cleanup unused attribute
788
  virtual void start_bulk_insert(ha_rows)
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
789
  {}
790
  virtual int end_bulk_insert(void) { return 0; }
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
791
  virtual int index_read(unsigned char *, const unsigned char *,
645 by Brian Aker
Cleanup unused attribute
792
                         uint32_t, enum ha_rkey_function)
1 by brian
clean slate
793
   { return  HA_ERR_WRONG_COMMAND; }
645 by Brian Aker
Cleanup unused attribute
794
  virtual int index_read_last(unsigned char *, const unsigned char *, uint32_t)
1 by brian
clean slate
795
   { return (my_errno= HA_ERR_WRONG_COMMAND); }
796
  /**
797
    This method is similar to update_row, however the handler doesn't need
798
    to execute the updates at this point in time. The handler can be certain
799
    that another call to bulk_update_row will occur OR a call to
800
    exec_bulk_update before the set of updates in this query is concluded.
801
802
    @param    old_data       Old record
803
    @param    new_data       New record
804
    @param    dup_key_found  Number of duplicate keys found
805
806
    @retval  0   Bulk delete used by handler
807
    @retval  1   Bulk delete not used, normal operation used
808
  */
645 by Brian Aker
Cleanup unused attribute
809
  virtual int bulk_update_row(const unsigned char *, unsigned char *, uint32_t *)
1 by brian
clean slate
810
  {
51.1.77 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
811
    assert(false);
1 by brian
clean slate
812
    return HA_ERR_WRONG_COMMAND;
813
  }
814
  /**
815
    This is called to delete all rows in a table
816
    If the handler don't support this, then this function will
817
    return HA_ERR_WRONG_COMMAND and MySQL will delete the rows one
818
    by one.
819
  */
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
820
  virtual int delete_all_rows(void)
1 by brian
clean slate
821
  { return (my_errno=HA_ERR_WRONG_COMMAND); }
822
  /**
823
    Reset the auto-increment counter to the given value, i.e. the next row
824
    inserted will get the given value. This is called e.g. after TRUNCATE
825
    is emulated by doing a 'DELETE FROM t'. HA_ERR_WRONG_COMMAND is
826
    returned by storage engines that don't support this operation.
827
  */
645 by Brian Aker
Cleanup unused attribute
828
  virtual int reset_auto_increment(uint64_t)
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
829
  { return HA_ERR_WRONG_COMMAND; }
645 by Brian Aker
Cleanup unused attribute
830
  virtual int optimize(Session *, HA_CHECK_OPT *)
831
  { return HA_ADMIN_NOT_IMPLEMENTED; }
832
  virtual int analyze(Session *, HA_CHECK_OPT *)
833
  { return HA_ADMIN_NOT_IMPLEMENTED; }
1063.3.1 by Stewart Smith
remove ha_check_and_repair. Engines should take care of this themselves.
834
645 by Brian Aker
Cleanup unused attribute
835
  virtual int disable_indexes(uint32_t)
836
  { return HA_ERR_WRONG_COMMAND; }
837
  virtual int enable_indexes(uint32_t)
838
  { return HA_ERR_WRONG_COMMAND; }
839
  virtual int discard_or_import_tablespace(bool)
1 by brian
clean slate
840
  { return (my_errno=HA_ERR_WRONG_COMMAND); }
53.2.32 by Monty Taylor
First large swath at getting handler stuff clean.
841
  virtual void prepare_for_alter(void) { return; }
1 by brian
clean slate
842
  virtual void drop_table(const char *name);
843
};
844
845
extern const char *ha_row_type[];
846
extern const char *tx_isolation_names[];
847
extern const char *binlog_format_names[];
848
extern TYPELIB tx_isolation_typelib;
849
extern TYPELIB myisam_stats_method_typelib;
61 by Brian Aker
Conversion of handler type.
850
extern uint32_t total_ha, total_ha_2pc;
1 by brian
clean slate
851
852
       /* Wrapper functions */
520.1.22 by Brian Aker
Second pass of thd cleanup
853
#define ha_commit(session) (ha_commit_trans((session), true))
854
#define ha_rollback(session) (ha_rollback_trans((session), true))
1 by brian
clean slate
855
856
/* basic stuff */
857
int ha_init_errors(void);
858
int ha_init(void);
859
int ha_end(void);
971.1.52 by Monty Taylor
Did the finalizers. Renamed plugin_registry.
860
971.1.46 by Monty Taylor
Made plugin registration go through Plugin_registry.
861
void add_storage_engine(StorageEngine *engine);
971.1.52 by Monty Taylor
Did the finalizers. Renamed plugin_registry.
862
void remove_storage_engine(StorageEngine *engine);
1 by brian
clean slate
863
520.1.22 by Brian Aker
Second pass of thd cleanup
864
void ha_close_connection(Session* session);
960.2.24 by Monty Taylor
Changed handlerton to StorageEngine.
865
bool ha_flush_logs(StorageEngine *db_type);
1 by brian
clean slate
866
void ha_drop_database(char* path);
520.1.22 by Brian Aker
Second pass of thd cleanup
867
int ha_create_table(Session *session, const char *path,
1 by brian
clean slate
868
                    const char *db, const char *table_name,
869
                    HA_CREATE_INFO *create_info,
1067.1.8 by Stewart Smith
start passing down table proto to createTable. This enables future code cleanup, including fixing ARCHIVE embedding table definition and table proto in parser
870
                    bool update_create_info,
871
                    drizzled::message::Table *table_proto);
590.1.7 by Stewart Smith
remove mysql_frm_type
872
int ha_delete_table(Session *session, const char *path,
1 by brian
clean slate
873
                    const char *db, const char *alias, bool generate_warning);
874
875
/* statistics and info */
960.2.24 by Monty Taylor
Changed handlerton to StorageEngine.
876
bool ha_show_status(Session *session, StorageEngine *db_type, enum ha_stat_type stat);
1 by brian
clean slate
877
520.1.22 by Brian Aker
Second pass of thd cleanup
878
int ha_find_files(Session *session,const char *db,const char *path,
1 by brian
clean slate
879
                  const char *wild, bool dir, List<LEX_STRING>* files);
880
881
/* key cache */
882
extern "C" int ha_init_key_cache(const char *name, KEY_CACHE *key_cache);
883
int ha_resize_key_cache(KEY_CACHE *key_cache);
884
int ha_change_key_cache_param(KEY_CACHE *key_cache);
885
int ha_change_key_cache(KEY_CACHE *old_key_cache, KEY_CACHE *new_key_cache);
886
int ha_end_key_cache(KEY_CACHE *key_cache);
887
888
/* report to InnoDB that control passes to the client */
520.1.22 by Brian Aker
Second pass of thd cleanup
889
int ha_release_temporary_latches(Session *session);
1 by brian
clean slate
890
960.2.24 by Monty Taylor
Changed handlerton to StorageEngine.
891
/* transactions: interface to StorageEngine functions */
520.1.22 by Brian Aker
Second pass of thd cleanup
892
int ha_start_consistent_snapshot(Session *session);
1 by brian
clean slate
893
int ha_commit_or_rollback_by_xid(XID *xid, bool commit);
520.1.22 by Brian Aker
Second pass of thd cleanup
894
int ha_commit_one_phase(Session *session, bool all);
895
int ha_rollback_trans(Session *session, bool all);
1 by brian
clean slate
896
int ha_recover(HASH *commit_list);
897
960.2.24 by Monty Taylor
Changed handlerton to StorageEngine.
898
/* transactions: these functions never call StorageEngine functions directly */
520.1.22 by Brian Aker
Second pass of thd cleanup
899
int ha_commit_trans(Session *session, bool all);
900
int ha_autocommit_or_rollback(Session *session, int error);
901
int ha_enable_transaction(Session *session, bool on);
1 by brian
clean slate
902
903
/* savepoints */
520.1.22 by Brian Aker
Second pass of thd cleanup
904
int ha_rollback_to_savepoint(Session *session, SAVEPOINT *sv);
905
int ha_savepoint(Session *session, SAVEPOINT *sv);
906
int ha_release_savepoint(Session *session, SAVEPOINT *sv);
1 by brian
clean slate
907
908
/* these are called by storage engines */
960.2.37 by Monty Taylor
More naming fixes.
909
void trans_register_ha(Session *session, bool all, StorageEngine *engine);
1 by brian
clean slate
910
520.6.7 by Monty Taylor
Moved a bunch of crap out of common_includes.
911
uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length);
1054.2.20 by Monty Taylor
Made tablename_to_filename available across the server now.
912
bool tablename_to_filename(const char *from, char *to, size_t to_length);
520.6.7 by Monty Taylor
Moved a bunch of crap out of common_includes.
913
914
575.1.3 by Monty Taylor
Moved some stuff out of handler.h.
915
bool mysql_ha_open(Session *session, TableList *tables, bool reopen);
916
bool mysql_ha_close(Session *session, TableList *tables);
917
bool mysql_ha_read(Session *, TableList *,enum enum_ha_read_modes,char *,
918
                   List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows);
919
void mysql_ha_flush(Session *session);
920
void mysql_ha_rm_tables(Session *session, TableList *tables, bool is_locked);
921
void mysql_ha_cleanup(Session *session);
922
1 by brian
clean slate
923
/*
924
  Storage engine has to assume the transaction will end up with 2pc if
925
   - there is more than one 2pc-capable storage engine available
926
   - in the current transaction 2pc was not disabled yet
927
*/
520.1.22 by Brian Aker
Second pass of thd cleanup
928
#define trans_need_2pc(session, all)                   ((total_ha_2pc > 1) && \
929
        !((all ? &session->transaction.all : &session->transaction.stmt)->no_2pc))
520.6.4 by Monty Taylor
Moved thr_lock.h out of common_includes.
930
575.4.7 by Monty Taylor
More header cleanup.
931
932
bool mysql_xa_recover(Session *session);
933
934
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
935
                                   SORT_FIELD *sortorder);
936
int setup_order(Session *session, Item **ref_pointer_array, TableList *tables,
937
                List<Item> &fields, List <Item> &all_fields, order_st *order);
938
int setup_group(Session *session, Item **ref_pointer_array, TableList *tables,
939
                List<Item> &fields, List<Item> &all_fields, order_st *order,
940
                bool *hidden_group_fields);
846 by Brian Aker
Removing on typedeffed class.
941
bool fix_inner_refs(Session *session, List<Item> &all_fields, Select_Lex *select,
575.4.7 by Monty Taylor
More header cleanup.
942
                    Item **ref_pointer_array);
943
944
bool handle_select(Session *session, LEX *lex, select_result *result,
892.2.2 by Monty Taylor
More solaris warnings.
945
                   uint64_t setup_tables_done_option);
575.4.7 by Monty Taylor
More header cleanup.
946
bool mysql_select(Session *session, Item ***rref_pointer_array,
947
                  TableList *tables, uint32_t wild_num,  List<Item> &list,
948
                  COND *conds, uint32_t og_num, order_st *order, order_st *group,
923.1.10 by Brian Aker
Remove dead code around old procedures.
949
                  Item *having, uint64_t select_type,
848 by Brian Aker
typdef class removal (just... use the name of the class).
950
                  select_result *result, Select_Lex_Unit *unit,
846 by Brian Aker
Removing on typedeffed class.
951
                  Select_Lex *select_lex);
952
void free_underlaid_joins(Session *session, Select_Lex *select);
848 by Brian Aker
typdef class removal (just... use the name of the class).
953
bool mysql_explain_union(Session *session, Select_Lex_Unit *unit,
575.4.7 by Monty Taylor
More header cleanup.
954
                         select_result *result);
846 by Brian Aker
Removing on typedeffed class.
955
int mysql_explain_select(Session *session, Select_Lex *sl, char const *type,
575.4.7 by Monty Taylor
More header cleanup.
956
                         select_result *result);
1008.3.22 by Stewart Smith
s/mysql_union/drizzle_union/
957
575.4.7 by Monty Taylor
More header cleanup.
958
bool mysql_handle_derived(LEX *lex, bool (*processor)(Session *session,
959
                                                      LEX *lex,
960
                                                      TableList *table));
961
bool mysql_derived_prepare(Session *session, LEX *lex, TableList *t);
962
bool mysql_derived_filling(Session *session, LEX *lex, TableList *t);
1052.2.3 by Nathan Williams
No actual code changes. Changed Create_field to CreateField to be consistent with coding standards.
963
void sp_prepare_create_field(Session *session, CreateField *sql_field);
964
int prepare_create_field(CreateField *sql_field,
575.4.7 by Monty Taylor
More header cleanup.
965
                         uint32_t *blob_columns,
966
                         int *timestamps, int *timestamps_with_niladic,
967
                         int64_t table_flags);
968
bool mysql_create_table(Session *session,const char *db, const char *table_name,
969
                        HA_CREATE_INFO *create_info,
1008.3.20 by Stewart Smith
Put table_name into table proto in parser, and use that when creating table proto file.
970
                        drizzled::message::Table *table_proto,
575.4.7 by Monty Taylor
More header cleanup.
971
                        Alter_info *alter_info,
972
                        bool tmp_table, uint32_t select_field_count);
973
bool mysql_create_table_no_lock(Session *session, const char *db,
974
                                const char *table_name,
975
                                HA_CREATE_INFO *create_info,
1008.3.20 by Stewart Smith
Put table_name into table proto in parser, and use that when creating table proto file.
976
                                drizzled::message::Table *table_proto,
575.4.7 by Monty Taylor
More header cleanup.
977
                                Alter_info *alter_info,
1039.1.11 by Brian Aker
Refactor function to make sense.
978
                                bool tmp_table, uint32_t select_field_count);
575.4.7 by Monty Taylor
More header cleanup.
979
980
bool mysql_alter_table(Session *session, char *new_db, char *new_name,
981
                       HA_CREATE_INFO *create_info,
982
                       TableList *table_list,
983
                       Alter_info *alter_info,
984
                       uint32_t order_num, order_st *order, bool ignore);
985
bool mysql_recreate_table(Session *session, TableList *table_list);
986
bool mysql_create_like_table(Session *session, TableList *table,
987
                             TableList *src_table,
988
                             HA_CREATE_INFO *create_info);
960.2.24 by Monty Taylor
Changed handlerton to StorageEngine.
989
bool mysql_rename_table(StorageEngine *base, const char *old_db,
575.4.7 by Monty Taylor
More header cleanup.
990
                        const char * old_name, const char *new_db,
991
                        const char * new_name, uint32_t flags);
992
bool mysql_prepare_update(Session *session, TableList *table_list,
993
                          Item **conds, uint32_t order_num, order_st *order);
994
int mysql_update(Session *session,TableList *tables,List<Item> &fields,
995
                 List<Item> &values,COND *conds,
996
                 uint32_t order_num, order_st *order, ha_rows limit,
997
                 enum enum_duplicates handle_duplicates, bool ignore);
998
bool mysql_multi_update(Session *session, TableList *table_list,
999
                        List<Item> *fields, List<Item> *values,
1000
                        COND *conds, uint64_t options,
1001
                        enum enum_duplicates handle_duplicates, bool ignore,
848 by Brian Aker
typdef class removal (just... use the name of the class).
1002
                        Select_Lex_Unit *unit, Select_Lex *select_lex);
575.4.7 by Monty Taylor
More header cleanup.
1003
bool mysql_prepare_insert(Session *session, TableList *table_list, Table *table,
1004
                          List<Item> &fields, List_item *values,
1005
                          List<Item> &update_fields,
1006
                          List<Item> &update_values, enum_duplicates duplic,
1007
                          COND **where, bool select_insert,
1008
                          bool check_fields, bool abort_on_warning);
1009
bool mysql_insert(Session *session,TableList *table,List<Item> &fields,
1010
                  List<List_item> &values, List<Item> &update_fields,
1011
                  List<Item> &update_values, enum_duplicates flag,
1012
                  bool ignore);
1013
int check_that_all_fields_are_given_values(Session *session, Table *entry,
1014
                                           TableList *table_list);
1015
int mysql_prepare_delete(Session *session, TableList *table_list, Item **conds);
1016
bool mysql_delete(Session *session, TableList *table_list, COND *conds,
1017
                  SQL_LIST *order, ha_rows rows, uint64_t options,
1018
                  bool reset_auto_increment);
1019
bool mysql_truncate(Session *session, TableList *table_list, bool dont_send_ok);
1000.1.3 by Brian Aker
Renamed TABLE_SHARE to TableShare
1020
TableShare *get_table_share(Session *session, TableList *table_list, char *key,
575.4.7 by Monty Taylor
More header cleanup.
1021
                             uint32_t key_length, uint32_t db_flags, int *error);
1000.1.3 by Brian Aker
Renamed TABLE_SHARE to TableShare
1022
TableShare *get_cached_table_share(const char *db, const char *table_name);
1046.1.9 by Brian Aker
Remove caller that wasn't correctly locking, and reverted code to 5.1
1023
Table *open_ltable(Session *session, TableList *table_list, thr_lock_type update);
575.4.7 by Monty Taylor
More header cleanup.
1024
Table *open_table(Session *session, TableList *table_list, bool *refresh, uint32_t flags);
1025
bool name_lock_locked_table(Session *session, TableList *tables);
1026
bool reopen_name_locked_table(Session* session, TableList* table_list, bool link_in);
1027
Table *table_cache_insert_placeholder(Session *session, const char *key,
1028
                                      uint32_t key_length);
1029
bool lock_table_name_if_not_cached(Session *session, const char *db,
1030
                                   const char *table_name, Table **table);
1031
Table *find_locked_table(Session *session, const char *db,const char *table_name);
1032
void detach_merge_children(Table *table, bool clear_refs);
1033
bool fix_merge_after_open(TableList *old_child_list, TableList **old_last,
1034
                          TableList *new_child_list, TableList **new_last);
1035
bool reopen_table(Table *table);
1036
bool reopen_tables(Session *session,bool get_locks,bool in_refresh);
1037
void close_data_files_and_morph_locks(Session *session, const char *db,
1038
                                      const char *table_name);
1039
void close_handle_and_leave_table_as_lock(Table *table);
1000.1.3 by Brian Aker
Renamed TABLE_SHARE to TableShare
1040
bool open_new_frm(Session *session, TableShare *share, const char *alias,
575.4.7 by Monty Taylor
More header cleanup.
1041
                  uint32_t db_stat, uint32_t prgflag,
1042
                  uint32_t ha_open_flags, Table *outparam,
1043
                  TableList *table_desc, MEM_ROOT *mem_root);
1044
bool wait_for_tables(Session *session);
1045
bool table_is_used(Table *table, bool wait_for_name_lock);
1046
Table *drop_locked_tables(Session *session,const char *db, const char *table_name);
1047
void abort_locked_tables(Session *session,const char *db, const char *table_name);
1048
extern Field *not_found_field;
1049
extern Field *view_ref_found;
1050
1051
Field *
1052
find_field_in_tables(Session *session, Item_ident *item,
1053
                     TableList *first_table, TableList *last_table,
1054
                     Item **ref, find_item_error_report_type report_error,
1055
                     bool check_privileges, bool register_tree_change);
1056
Field *
1057
find_field_in_table_ref(Session *session, TableList *table_list,
1058
                        const char *name, uint32_t length,
1059
                        const char *item_name, const char *db_name,
1060
                        const char *table_name, Item **ref,
1061
                        bool check_privileges, bool allow_rowid,
1062
                        uint32_t *cached_field_index_ptr,
1063
                        bool register_tree_change, TableList **actual_table);
1064
Field *
1065
find_field_in_table(Session *session, Table *table, const char *name, uint32_t length,
1066
                    bool allow_rowid, uint32_t *cached_field_index_ptr);
1067
Field *
1068
find_field_in_table_sef(Table *table, const char *name);
1069
int update_virtual_fields_marked_for_write(Table *table,
1070
                                           bool ignore_stored=true);
1071
1072
520.6.4 by Monty Taylor
Moved thr_lock.h out of common_includes.
1073
#endif /* DRIZZLED_HANDLER_H */