23
23
#include <drizzled/xid.h>
24
24
#include <drizzled/discrete_interval.h>
25
#include <drizzled/table_identifier.h>
25
#include <drizzled/identifier.h>
26
#include <drizzled/definitions.h>
27
#include <drizzled/key_map.h>
27
29
/* Definitions for parameters to do with Cursor-routines */
48
47
#define HA_MAX_ALTER_FLAGS 40
51
49
typedef std::bitset<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
53
51
extern uint64_t refresh_version; /* Increments on each reload */
56
typedef bool (*qc_engine_callback)(Session *session, char *table_key,
58
uint64_t *engine_data);
61
/* The Cursor for a table type. Will be included in the Table structure */
66
56
class Select_Lex_Unit;
67
struct st_foreign_key_info;
68
typedef struct st_foreign_key_info FOREIGN_KEY_INFO;
72
struct st_table_log_memory_entry;
96
uint32_t calculate_key_len(Table *, uint, const unsigned char *, key_part_map);
98
84
bitmap with first N+1 bits set
99
85
(keypart_map for a key prefix of [0..N] keyparts)
150
136
present, its length is one byte <not-sure> which must be set to 0xFF
151
137
at all times. </not-sure>
153
If the table has columns of type BIT, then certain bits from those columns
154
may be stored in null_bytes as well. Grep around for Field_bit for
157
139
For blob columns (see Field_blob), the record buffer stores length of the
158
140
data, following by memory pointer to the blob data. The pointer is owned
159
141
by the storage engine and is valid until the next operation.
161
143
If a blob column has NULL value, then its length and blob data pointer
162
144
must be set to 0.
165
class Cursor :public memory::SqlAlloc
148
Table &table; /* The current open table */
149
plugin::StorageEngine &engine; /* storage engine of this Cursor */
168
TableShare *table_share; /* The table definition */
169
Table *table; /* The current open table */
171
152
ha_rows estimation_rows_to_insert;
173
plugin::StorageEngine *engine; /* storage engine of this Cursor */
174
155
inline plugin::StorageEngine *getEngine() const /* table_type for handler */
178
159
unsigned char *ref; /* Pointer to current row */
179
160
unsigned char *dup_ref; /* Pointer to duplicate row */
162
TableShare *getShare();
164
Table *getTable() const
181
169
ha_statistics stats;
182
170
/** MultiRangeRead-related members: */
183
171
range_seq_t mrr_iter; /* Interator to traverse the range sequence */
184
172
RANGE_SEQ_IF mrr_funcs; /* Range sequence traversal functions */
185
HANDLER_BUFFER *multi_range_buffer; /* MRR buffer info */
186
174
uint32_t ranges_in_seq; /* Total number of ranges in the traversed sequence */
187
175
/* true <=> source MRR ranges and the output are ordered */
188
176
bool mrr_is_output_sorted;
191
179
bool mrr_have_range;
195
true <=> the engine guarantees that returned records are within the range
198
bool in_range_check_pushed_down;
200
183
/** Current range (the one we're now returning rows from) */
201
184
KEY_MULTI_RANGE mrr_cur_range;
203
186
/** The following are for read_range() */
204
187
key_range save_end_range, *end_range;
205
KEY_PART_INFO *range_key_part;
188
KeyPartInfo *range_key_part;
206
189
int key_compare_result_on_equal;
208
191
uint32_t errkey; /* Last dup key */
243
225
Discrete_interval auto_inc_interval_for_cur_row;
245
Cursor(plugin::StorageEngine &engine_arg, TableShare &share_arg);
227
Cursor(plugin::StorageEngine &engine_arg, Table &share_arg);
246
228
virtual ~Cursor(void);
247
229
virtual Cursor *clone(memory::Root *mem_root);
249
231
/* ha_ methods: pubilc wrappers for private virtual API */
251
int ha_open(Table *table, const char *name, int mode, int test_if_locked);
252
int ha_index_init(uint32_t idx, bool sorted);
254
int ha_rnd_init(bool scan);
233
int ha_open(const TableIdentifier &identifier, int mode, int test_if_locked);
234
int startIndexScan(uint32_t idx, bool sorted);
236
int startTableScan(bool scan);
258
240
/* this is necessary in many places, e.g. in HANDLER command */
262
244
These functions represent the public interface to *users* of the
263
245
Cursor class, hence they are *not* virtual. For the inheritance
264
interface, see the (private) functions write_row(), update_row(),
265
and delete_row() below.
246
interface, see the (private) functions doInsertRecord(), doUpdateRecord(),
247
and doDeleteRecord() below.
267
249
int ha_external_lock(Session *session, int lock_type);
268
int ha_write_row(unsigned char * buf);
269
int ha_update_row(const unsigned char * old_data, unsigned char * new_data);
270
int ha_delete_row(const unsigned char * buf);
250
int insertRecord(unsigned char * buf);
251
int updateRecord(const unsigned char * old_data, unsigned char * new_data);
252
int deleteRecord(const unsigned char * buf);
271
253
void ha_release_auto_increment();
273
255
/** to be actually called to get 'check()' functionality*/
287
269
void adjust_next_insert_id_after_explicit_value(uint64_t nr);
288
270
int update_auto_increment();
289
virtual void change_table_ptr(Table *table_arg, TableShare *share);
291
272
/* Estimates calculation */
292
273
virtual double scan_time(void)
303
284
virtual int multi_range_read_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys,
304
285
uint32_t *bufsz, uint32_t *flags, optimizer::CostVector *cost);
305
286
virtual int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
306
uint32_t n_ranges, uint32_t mode,
307
HANDLER_BUFFER *buf);
287
uint32_t n_ranges, uint32_t mode);
308
288
virtual int multi_range_read_next(char **range_info);
339
319
virtual ha_rows estimate_rows_upper_bound()
340
320
{ return stats.records+EXTRA_RECORDS; }
343
Get the row type from the storage engine. If this method returns
344
ROW_TYPE_NOT_USED, the information in HA_CREATE_INFO should be used.
346
virtual enum row_type get_row_type() const { return ROW_TYPE_NOT_USED; }
348
322
virtual const char *index_type(uint32_t)
349
323
{ assert(0); return "";}
358
332
row if available. If the key value is null, begin at the first key of the
361
virtual int index_read_map(unsigned char * buf, const unsigned char * key,
335
virtual int index_read_map(unsigned char * buf, const unsigned char *key,
362
336
key_part_map keypart_map,
363
337
enum ha_rkey_function find_flag)
365
uint32_t key_len= calculate_key_len(table, active_index, key, keypart_map);
339
uint32_t key_len= calculate_key_len(active_index, keypart_map);
366
340
return index_read(buf, key, key_len, find_flag);
384
358
virtual int index_last(unsigned char *)
385
359
{ return HA_ERR_WRONG_COMMAND; }
386
360
virtual int index_next_same(unsigned char *, const unsigned char *, uint32_t);
363
uint32_t calculate_key_len(uint32_t key_position, key_part_map keypart_map_arg);
389
368
The following functions works like index_read, but it find the last
392
371
virtual int index_read_last_map(unsigned char * buf, const unsigned char * key,
393
372
key_part_map keypart_map)
395
uint32_t key_len= calculate_key_len(table, active_index, key, keypart_map);
374
uint32_t key_len= calculate_key_len(active_index, keypart_map);
396
375
return index_read_last(buf, key, key_len);
398
377
virtual int read_range_first(const key_range *start_key,
400
379
bool eq_range, bool sorted);
401
380
virtual int read_range_next();
402
381
int compare_key(key_range *range);
403
int compare_key2(key_range *range);
404
382
virtual int rnd_next(unsigned char *)=0;
405
383
virtual int rnd_pos(unsigned char *, unsigned char *)=0;
407
One has to use this method when to find
408
random position by record as the plain
409
position() call doesn't work for some
410
handlers for random position.
412
virtual int rnd_pos_by_record(unsigned char *record);
413
384
virtual int read_first_row(unsigned char *buf, uint32_t primary_key);
415
The following function is only needed for tables that may be temporary
418
virtual int restart_rnd_next(unsigned char *, unsigned char *)
419
{ return HA_ERR_WRONG_COMMAND; }
420
385
virtual int rnd_same(unsigned char *, uint32_t)
421
386
{ return HA_ERR_WRONG_COMMAND; }
422
387
virtual ha_rows records_in_range(uint32_t, key_range *, key_range *)
501
464
virtual bool can_switch_engines(void) { return true; }
502
465
/** used in REPLACE; is > 0 if table is referred by a FOREIGN KEY */
503
virtual int get_foreign_key_list(Session *, List<FOREIGN_KEY_INFO> *)
466
virtual int get_foreign_key_list(Session *, List<ForeignKeyInfo> *)
505
468
virtual uint32_t referenced_by_foreign_key() { return 0;}
506
469
virtual void free_foreign_key_create_info(char *) {}
507
/** The following can be called without an open Cursor */
509
virtual int add_index(Table *, KEY *, uint32_t)
510
{ return (HA_ERR_WRONG_COMMAND); }
511
virtual int prepare_drop_index(Table *, uint32_t *, uint32_t)
512
{ return (HA_ERR_WRONG_COMMAND); }
513
virtual int final_drop_index(Table *)
514
{ return (HA_ERR_WRONG_COMMAND); }
516
virtual uint32_t checksum(void) const { return 0; }
519
472
Is not invoked for non-transactional temporary tables.
524
477
@note that one can NOT rely on table->in_use in store_lock(). It may
525
refer to a different thread if called from mysql_lock_abort_for_thread().
478
refer to a different thread if called from abortLockForThread().
527
480
@note If the table is MERGE, store_lock() can return less locks
528
481
than lock_count() claimed. This can happen when the MERGE children
558
511
/* Service methods for use by storage engines. */
559
void ha_statistic_increment(ulong system_status_var::*offset) const;
512
void ha_statistic_increment(uint64_t system_status_var::*offset) const;
560
513
void **ha_data(Session *) const;
561
Session *ha_session(void) const;
564
516
/* Private helpers */
570
522
the corresponding 'ha_*' method above.
573
virtual int open(const char *name, int mode, uint32_t test_if_locked)=0;
574
virtual int index_init(uint32_t idx, bool)
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)
575
528
{ active_index= idx; return 0; }
576
virtual int index_end() { active_index= MAX_KEY; return 0; }
529
virtual int doEndIndexScan() { active_index= MAX_KEY; return 0; }
578
rnd_init() can be called two times without rnd_end() in between
531
doStartTableScan() can be called two times without doEndTableScan() in between
579
532
(it only makes sense if scan=1).
580
533
then the second call should prepare for the new table scan (e.g
581
534
if rnd_init allocates the cursor, second call should position it
582
535
to the start of the table, no need to deallocate and allocate it again
584
virtual int rnd_init(bool scan)= 0;
585
virtual int rnd_end() { return 0; }
586
virtual int write_row(unsigned char *)
588
return HA_ERR_WRONG_COMMAND;
591
virtual int update_row(const unsigned char *, unsigned char *)
593
return HA_ERR_WRONG_COMMAND;
596
virtual int delete_row(const unsigned char *)
537
virtual int doStartTableScan(bool scan)= 0;
538
virtual int doEndTableScan() { return 0; }
539
virtual int doInsertRecord(unsigned char *)
541
return HA_ERR_WRONG_COMMAND;
544
virtual int doUpdateRecord(const unsigned char *, unsigned char *)
546
return HA_ERR_WRONG_COMMAND;
549
virtual int doDeleteRecord(const unsigned char *)
598
551
return HA_ERR_WRONG_COMMAND;
633
virtual void release_auto_increment(void) { return; };
586
virtual void release_auto_increment(void) { return; }
634
587
/** admin commands - called from mysql_admin_table */
635
588
virtual int check(Session *)
636
589
{ return HA_ADMIN_NOT_IMPLEMENTED; }
686
639
/* basic stuff */
687
640
void ha_init_errors(void);
689
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
690
SORT_FIELD *sortorder);
643
SortField *make_unireg_sortorder(Order *order, uint32_t *length,
644
SortField *sortorder);
691
645
int setup_order(Session *session, Item **ref_pointer_array, TableList *tables,
692
List<Item> &fields, List <Item> &all_fields, order_st *order);
646
List<Item> &fields, List <Item> &all_fields, Order *order);
693
647
int setup_group(Session *session, Item **ref_pointer_array, TableList *tables,
694
List<Item> &fields, List<Item> &all_fields, order_st *order,
648
List<Item> &fields, List<Item> &all_fields, Order *order,
695
649
bool *hidden_group_fields);
696
650
bool fix_inner_refs(Session *session, List<Item> &all_fields, Select_Lex *select,
697
651
Item **ref_pointer_array);
732
686
bool is_if_not_exists,
733
687
bool is_engine_set);
735
bool mysql_rename_table(plugin::StorageEngine *base,
689
bool mysql_rename_table(Session &session,
690
plugin::StorageEngine *base,
736
691
TableIdentifier &old_identifier,
737
TableIdentifier &new_identifier,
692
TableIdentifier &new_identifier);
740
694
bool mysql_prepare_update(Session *session, TableList *table_list,
741
Item **conds, uint32_t order_num, order_st *order);
695
Item **conds, uint32_t order_num, Order *order);
742
696
int mysql_update(Session *session,TableList *tables,List<Item> &fields,
743
697
List<Item> &values,COND *conds,
744
uint32_t order_num, order_st *order, ha_rows limit,
698
uint32_t order_num, Order *order, ha_rows limit,
745
699
enum enum_duplicates handle_duplicates, bool ignore);
746
700
bool mysql_prepare_insert(Session *session, TableList *table_list, Table *table,
747
701
List<Item> &fields, List_item *values,
764
718
uint32_t key_length, uint32_t db_flags, int *error);
765
719
TableShare *get_cached_table_share(const char *db, const char *table_name);
766
720
bool reopen_name_locked_table(Session* session, TableList* table_list, bool link_in);
767
Table *table_cache_insert_placeholder(Session *session, const char *key,
768
uint32_t key_length);
769
bool lock_table_name_if_not_cached(Session *session, const char *db,
770
const char *table_name, Table **table);
771
bool reopen_table(Table *table);
772
721
bool reopen_tables(Session *session,bool get_locks,bool in_refresh);
773
void close_data_files_and_morph_locks(Session *session, const char *db,
774
const char *table_name);
775
722
void close_handle_and_leave_table_as_lock(Table *table);
776
723
bool wait_for_tables(Session *session);
777
724
bool table_is_used(Table *table, bool wait_for_name_lock);
778
Table *drop_locked_tables(Session *session,const char *db, const char *table_name);
779
void abort_locked_tables(Session *session,const char *db, const char *table_name);
725
Table *drop_locked_tables(Session *session, const drizzled::TableIdentifier &identifier);
726
void abort_locked_tables(Session *session, const drizzled::TableIdentifier &identifier);
780
727
extern Field *not_found_field;
781
728
extern Field *view_ref_found;