23
23
#include <drizzled/xid.h>
24
24
#include <drizzled/discrete_interval.h>
25
#include <drizzled/table_identifier.h>
25
#include <drizzled/identifier.h>
27
27
/* Definitions for parameters to do with Cursor-routines */
50
48
#define HA_MAX_ALTER_FLAGS 40
53
50
typedef std::bitset<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
55
52
extern uint64_t refresh_version; /* Increments on each reload */
58
typedef bool (*qc_engine_callback)(Session *session, char *table_key,
60
uint64_t *engine_data);
63
/* The Cursor for a table type. Will be included in the Table structure */
68
57
class Select_Lex_Unit;
69
struct st_foreign_key_info;
70
typedef struct st_foreign_key_info FOREIGN_KEY_INFO;
74
struct st_table_log_memory_entry;
91
77
typedef struct system_status_var system_status_var;
95
uint32_t calculate_key_len(Table *, uint, const unsigned char *, key_part_map);
97
85
bitmap with first N+1 bits set
98
86
(keypart_map for a key prefix of [0..N] keyparts)
149
137
present, its length is one byte <not-sure> which must be set to 0xFF
150
138
at all times. </not-sure>
152
If the table has columns of type BIT, then certain bits from those columns
153
may be stored in null_bytes as well. Grep around for Field_bit for
156
140
For blob columns (see Field_blob), the record buffer stores length of the
157
141
data, following by memory pointer to the blob data. The pointer is owned
158
142
by the storage engine and is valid until the next operation.
160
144
If a blob column has NULL value, then its length and blob data pointer
161
145
must be set to 0.
164
class Cursor :public memory::SqlAlloc
167
150
TableShare *table_share; /* The table definition */
168
151
Table *table; /* The current open table */
170
153
ha_rows estimation_rows_to_insert;
172
154
plugin::StorageEngine *engine; /* storage engine of this Cursor */
173
156
inline plugin::StorageEngine *getEngine() const /* table_type for handler */
177
160
unsigned char *ref; /* Pointer to current row */
178
161
unsigned char *dup_ref; /* Pointer to duplicate row */
163
TableShare *getShare() const
180
168
ha_statistics stats;
181
169
/** MultiRangeRead-related members: */
182
170
range_seq_t mrr_iter; /* Interator to traverse the range sequence */
183
171
RANGE_SEQ_IF mrr_funcs; /* Range sequence traversal functions */
184
HANDLER_BUFFER *multi_range_buffer; /* MRR buffer info */
185
173
uint32_t ranges_in_seq; /* Total number of ranges in the traversed sequence */
186
174
/* true <=> source MRR ranges and the output are ordered */
187
175
bool mrr_is_output_sorted;
190
178
bool mrr_have_range;
194
true <=> the engine guarantees that returned records are within the range
197
bool in_range_check_pushed_down;
199
182
/** Current range (the one we're now returning rows from) */
200
183
KEY_MULTI_RANGE mrr_cur_range;
202
185
/** The following are for read_range() */
203
186
key_range save_end_range, *end_range;
204
KEY_PART_INFO *range_key_part;
187
KeyPartInfo *range_key_part;
205
188
int key_compare_result_on_equal;
207
190
uint32_t errkey; /* Last dup key */
248
230
/* ha_ methods: pubilc wrappers for private virtual API */
250
int ha_open(Table *table, const char *name, int mode, int test_if_locked);
251
int ha_index_init(uint32_t idx, bool sorted);
253
int ha_rnd_init(bool scan);
232
int ha_open(const TableIdentifier &identifier, Table *table, int mode, int test_if_locked);
233
int startIndexScan(uint32_t idx, bool sorted);
235
int startTableScan(bool scan);
257
239
/* this is necessary in many places, e.g. in HANDLER command */
261
243
These functions represent the public interface to *users* of the
262
244
Cursor class, hence they are *not* virtual. For the inheritance
263
interface, see the (private) functions write_row(), update_row(),
264
and delete_row() below.
245
interface, see the (private) functions doInsertRecord(), doUpdateRecord(),
246
and doDeleteRecord() below.
266
248
int ha_external_lock(Session *session, int lock_type);
267
int ha_write_row(unsigned char * buf);
268
int ha_update_row(const unsigned char * old_data, unsigned char * new_data);
269
int ha_delete_row(const unsigned char * buf);
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);
270
252
void ha_release_auto_increment();
272
254
/** to be actually called to get 'check()' functionality*/
298
280
virtual ha_rows multi_range_read_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
299
281
void *seq_init_param,
300
282
uint32_t n_ranges, uint32_t *bufsz,
301
uint32_t *flags, COST_VECT *cost);
283
uint32_t *flags, optimizer::CostVector *cost);
302
284
virtual int multi_range_read_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys,
303
uint32_t *bufsz, uint32_t *flags, COST_VECT *cost);
285
uint32_t *bufsz, uint32_t *flags, optimizer::CostVector *cost);
304
286
virtual int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
305
uint32_t n_ranges, uint32_t mode,
306
HANDLER_BUFFER *buf);
287
uint32_t n_ranges, uint32_t mode);
307
288
virtual int multi_range_read_next(char **range_info);
338
319
virtual ha_rows estimate_rows_upper_bound()
339
320
{ return stats.records+EXTRA_RECORDS; }
342
Get the row type from the storage engine. If this method returns
343
ROW_TYPE_NOT_USED, the information in HA_CREATE_INFO should be used.
345
virtual enum row_type get_row_type() const { return ROW_TYPE_NOT_USED; }
347
322
virtual const char *index_type(uint32_t)
348
323
{ assert(0); return "";}
357
332
row if available. If the key value is null, begin at the first key of the
360
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,
361
336
key_part_map keypart_map,
362
337
enum ha_rkey_function find_flag)
364
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);
365
340
return index_read(buf, key, key_len, find_flag);
383
358
virtual int index_last(unsigned char *)
384
359
{ return HA_ERR_WRONG_COMMAND; }
385
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);
388
368
The following functions works like index_read, but it find the last
391
371
virtual int index_read_last_map(unsigned char * buf, const unsigned char * key,
392
372
key_part_map keypart_map)
394
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);
395
375
return index_read_last(buf, key, key_len);
397
377
virtual int read_range_first(const key_range *start_key,
399
379
bool eq_range, bool sorted);
400
380
virtual int read_range_next();
401
381
int compare_key(key_range *range);
402
int compare_key2(key_range *range);
403
382
virtual int rnd_next(unsigned char *)=0;
404
383
virtual int rnd_pos(unsigned char *, unsigned char *)=0;
406
One has to use this method when to find
407
random position by record as the plain
408
position() call doesn't work for some
409
handlers for random position.
411
virtual int rnd_pos_by_record(unsigned char *record);
412
384
virtual int read_first_row(unsigned char *buf, uint32_t primary_key);
414
The following function is only needed for tables that may be temporary
417
virtual int restart_rnd_next(unsigned char *, unsigned char *)
418
{ return HA_ERR_WRONG_COMMAND; }
419
385
virtual int rnd_same(unsigned char *, uint32_t)
420
386
{ return HA_ERR_WRONG_COMMAND; }
421
387
virtual ha_rows records_in_range(uint32_t, key_range *, key_range *)
453
419
virtual void get_auto_increment(uint64_t offset, uint64_t increment,
454
420
uint64_t nb_desired_values,
455
421
uint64_t *first_value,
456
uint64_t *nb_reserved_values);
422
uint64_t *nb_reserved_values)= 0;
457
424
void set_next_insert_id(uint64_t id)
459
426
next_insert_id= id;
499
464
virtual bool can_switch_engines(void) { return true; }
500
465
/** used in REPLACE; is > 0 if table is referred by a FOREIGN KEY */
501
virtual int get_foreign_key_list(Session *, List<FOREIGN_KEY_INFO> *)
466
virtual int get_foreign_key_list(Session *, List<ForeignKeyInfo> *)
503
468
virtual uint32_t referenced_by_foreign_key() { return 0;}
504
469
virtual void free_foreign_key_create_info(char *) {}
505
/** The following can be called without an open Cursor */
507
virtual int add_index(Table *, KEY *, uint32_t)
508
{ return (HA_ERR_WRONG_COMMAND); }
509
virtual int prepare_drop_index(Table *, uint32_t *, uint32_t)
510
{ return (HA_ERR_WRONG_COMMAND); }
511
virtual int final_drop_index(Table *)
512
{ return (HA_ERR_WRONG_COMMAND); }
514
virtual uint32_t checksum(void) const { return 0; }
517
472
Is not invoked for non-transactional temporary tables.
556
511
/* Service methods for use by storage engines. */
557
void ha_statistic_increment(ulong system_status_var::*offset) const;
512
void ha_statistic_increment(uint64_t system_status_var::*offset) const;
558
513
void **ha_data(Session *) const;
559
Session *ha_session(void) const;
562
516
/* Private helpers */
568
522
the corresponding 'ha_*' method above.
571
virtual int open(const char *name, int mode, uint32_t test_if_locked)=0;
572
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)
573
528
{ active_index= idx; return 0; }
574
virtual int index_end() { active_index= MAX_KEY; return 0; }
529
virtual int doEndIndexScan() { active_index= MAX_KEY; return 0; }
576
rnd_init() can be called two times without rnd_end() in between
531
doStartTableScan() can be called two times without doEndTableScan() in between
577
532
(it only makes sense if scan=1).
578
533
then the second call should prepare for the new table scan (e.g
579
534
if rnd_init allocates the cursor, second call should position it
580
535
to the start of the table, no need to deallocate and allocate it again
582
virtual int rnd_init(bool scan)= 0;
583
virtual int rnd_end() { return 0; }
584
virtual int write_row(unsigned char *)
586
return HA_ERR_WRONG_COMMAND;
589
virtual int update_row(const unsigned char *, unsigned char *)
591
return HA_ERR_WRONG_COMMAND;
594
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 *)
596
551
return HA_ERR_WRONG_COMMAND;
682
637
extern const char *ha_row_type[];
684
639
/* basic stuff */
685
int ha_init_errors(void);
640
void ha_init_errors(void);
688
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
689
SORT_FIELD *sortorder);
643
SortField *make_unireg_sortorder(order_st *order, uint32_t *length,
644
SortField *sortorder);
690
645
int setup_order(Session *session, Item **ref_pointer_array, TableList *tables,
691
646
List<Item> &fields, List <Item> &all_fields, order_st *order);
692
647
int setup_group(Session *session, Item **ref_pointer_array, TableList *tables,
721
676
HA_CREATE_INFO *create_info,
722
677
message::Table &table_proto,
723
678
AlterInfo *alter_info,
725
uint32_t select_field_count,
679
bool tmp_table, uint32_t select_field_count,
726
680
bool is_if_not_exists);
728
682
bool mysql_create_like_table(Session* session,
732
686
bool is_if_not_exists,
733
687
bool is_engine_set);
735
bool mysql_rename_table(plugin::StorageEngine *base, const char *old_db,
736
const char * old_name, const char *new_db,
737
const char * new_name, uint32_t flags);
689
bool mysql_rename_table(Session &session,
690
plugin::StorageEngine *base,
691
TableIdentifier &old_identifier,
692
TableIdentifier &new_identifier);
739
694
bool mysql_prepare_update(Session *session, TableList *table_list,
740
695
Item **conds, uint32_t order_num, order_st *order);
763
718
uint32_t key_length, uint32_t db_flags, int *error);
764
719
TableShare *get_cached_table_share(const char *db, const char *table_name);
765
720
bool reopen_name_locked_table(Session* session, TableList* table_list, bool link_in);
766
Table *table_cache_insert_placeholder(Session *session, const char *key,
767
uint32_t key_length);
768
bool lock_table_name_if_not_cached(Session *session, const char *db,
769
const char *table_name, Table **table);
770
bool reopen_table(Table *table);
771
721
bool reopen_tables(Session *session,bool get_locks,bool in_refresh);
772
void close_data_files_and_morph_locks(Session *session, const char *db,
773
const char *table_name);
774
722
void close_handle_and_leave_table_as_lock(Table *table);
775
723
bool wait_for_tables(Session *session);
776
724
bool table_is_used(Table *table, bool wait_for_name_lock);
777
Table *drop_locked_tables(Session *session,const char *db, const char *table_name);
778
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);
779
727
extern Field *not_found_field;
780
728
extern Field *view_ref_found;