143
160
If a blob column has NULL value, then its length and blob data pointer
144
161
must be set to 0.
164
class Cursor :public memory::SqlAlloc
148
Table &table; /* The current open table */
149
plugin::StorageEngine &engine; /* storage engine of this Cursor */
167
TableShare *table_share; /* The table definition */
168
Table *table; /* The current open table */
152
170
ha_rows estimation_rows_to_insert;
172
plugin::StorageEngine *engine; /* storage engine of this Cursor */
155
173
inline plugin::StorageEngine *getEngine() const /* table_type for handler */
159
177
unsigned char *ref; /* Pointer to current row */
160
178
unsigned char *dup_ref; /* Pointer to duplicate row */
162
TableShare *getShare();
164
Table *getTable() const
169
180
ha_statistics stats;
170
181
/** MultiRangeRead-related members: */
171
182
range_seq_t mrr_iter; /* Interator to traverse the range sequence */
172
183
RANGE_SEQ_IF mrr_funcs; /* Range sequence traversal functions */
184
HANDLER_BUFFER *multi_range_buffer; /* MRR buffer info */
174
185
uint32_t ranges_in_seq; /* Total number of ranges in the traversed sequence */
175
186
/* true <=> source MRR ranges and the output are ordered */
176
187
bool mrr_is_output_sorted;
179
190
bool mrr_have_range;
194
true <=> the engine guarantees that returned records are within the range
197
bool in_range_check_pushed_down;
183
199
/** Current range (the one we're now returning rows from) */
184
200
KEY_MULTI_RANGE mrr_cur_range;
186
202
/** The following are for read_range() */
187
203
key_range save_end_range, *end_range;
188
KeyPartInfo *range_key_part;
204
KEY_PART_INFO *range_key_part;
189
205
int key_compare_result_on_equal;
191
207
uint32_t errkey; /* Last dup key */
225
237
Discrete_interval auto_inc_interval_for_cur_row;
227
Cursor(plugin::StorageEngine &engine_arg, Table &share_arg);
239
Cursor(plugin::StorageEngine &engine_arg, TableShare &share_arg);
228
240
virtual ~Cursor(void);
229
241
virtual Cursor *clone(memory::Root *mem_root);
231
243
/* ha_ methods: pubilc wrappers for private virtual API */
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);
245
int ha_open(Table *table, const char *name, int mode, int test_if_locked);
246
int ha_index_init(uint32_t idx, bool sorted);
248
int ha_rnd_init(bool scan);
240
252
/* this is necessary in many places, e.g. in HANDLER command */
244
256
These functions represent the public interface to *users* of the
245
257
Cursor class, hence they are *not* virtual. For the inheritance
246
interface, see the (private) functions doInsertRecord(), doUpdateRecord(),
247
and doDeleteRecord() below.
258
interface, see the (private) functions write_row(), update_row(),
259
and delete_row() below.
249
261
int ha_external_lock(Session *session, int lock_type);
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);
262
int ha_write_row(unsigned char * buf);
263
int ha_update_row(const unsigned char * old_data, unsigned char * new_data);
264
int ha_delete_row(const unsigned char * buf);
253
265
void ha_release_auto_increment();
255
267
/** to be actually called to get 'check()' functionality*/
280
293
virtual ha_rows multi_range_read_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
281
294
void *seq_init_param,
282
295
uint32_t n_ranges, uint32_t *bufsz,
283
uint32_t *flags, optimizer::CostVector *cost);
296
uint32_t *flags, COST_VECT *cost);
284
297
virtual int multi_range_read_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys,
285
uint32_t *bufsz, uint32_t *flags, optimizer::CostVector *cost);
298
uint32_t *bufsz, uint32_t *flags, COST_VECT *cost);
286
299
virtual int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
287
uint32_t n_ranges, uint32_t mode);
300
uint32_t n_ranges, uint32_t mode,
301
HANDLER_BUFFER *buf);
288
302
virtual int multi_range_read_next(char **range_info);
332
350
row if available. If the key value is null, begin at the first key of the
335
virtual int index_read_map(unsigned char * buf, const unsigned char *key,
353
virtual int index_read_map(unsigned char * buf, const unsigned char * key,
336
354
key_part_map keypart_map,
337
355
enum ha_rkey_function find_flag)
339
uint32_t key_len= calculate_key_len(active_index, keypart_map);
357
uint32_t key_len= calculate_key_len(table, active_index, key, keypart_map);
340
358
return index_read(buf, key, key_len, find_flag);
371
384
virtual int index_read_last_map(unsigned char * buf, const unsigned char * key,
372
385
key_part_map keypart_map)
374
uint32_t key_len= calculate_key_len(active_index, keypart_map);
387
uint32_t key_len= calculate_key_len(table, active_index, key, keypart_map);
375
388
return index_read_last(buf, key, key_len);
377
390
virtual int read_range_first(const key_range *start_key,
379
392
bool eq_range, bool sorted);
380
393
virtual int read_range_next();
381
394
int compare_key(key_range *range);
395
int compare_key2(key_range *range);
382
396
virtual int rnd_next(unsigned char *)=0;
383
397
virtual int rnd_pos(unsigned char *, unsigned char *)=0;
399
One has to use this method when to find
400
random position by record as the plain
401
position() call doesn't work for some
402
handlers for random position.
404
virtual int rnd_pos_by_record(unsigned char *record);
384
405
virtual int read_first_row(unsigned char *buf, uint32_t primary_key);
407
The following function is only needed for tables that may be temporary
410
virtual int restart_rnd_next(unsigned char *, unsigned char *)
411
{ return HA_ERR_WRONG_COMMAND; }
385
412
virtual int rnd_same(unsigned char *, uint32_t)
386
413
{ return HA_ERR_WRONG_COMMAND; }
387
414
virtual ha_rows records_in_range(uint32_t, key_range *, key_range *)
417
444
virtual void try_semi_consistent_read(bool) {}
418
445
virtual void unlock_row(void) {}
446
virtual int start_stmt(Session *, thr_lock_type)
419
448
virtual void get_auto_increment(uint64_t offset, uint64_t increment,
420
449
uint64_t nb_desired_values,
421
450
uint64_t *first_value,
422
uint64_t *nb_reserved_values)= 0;
451
uint64_t *nb_reserved_values);
424
452
void set_next_insert_id(uint64_t id)
426
454
next_insert_id= id;
464
494
virtual bool can_switch_engines(void) { return true; }
465
495
/** used in REPLACE; is > 0 if table is referred by a FOREIGN KEY */
466
virtual int get_foreign_key_list(Session *, List<ForeignKeyInfo> *)
496
virtual int get_foreign_key_list(Session *, List<FOREIGN_KEY_INFO> *)
468
498
virtual uint32_t referenced_by_foreign_key() { return 0;}
469
499
virtual void free_foreign_key_create_info(char *) {}
500
/** The following can be called without an open Cursor */
502
virtual int add_index(Table *, KEY *, uint32_t)
503
{ return (HA_ERR_WRONG_COMMAND); }
504
virtual int prepare_drop_index(Table *, uint32_t *, uint32_t)
505
{ return (HA_ERR_WRONG_COMMAND); }
506
virtual int final_drop_index(Table *)
507
{ return (HA_ERR_WRONG_COMMAND); }
509
virtual uint32_t checksum(void) const { return 0; }
472
512
Is not invoked for non-transactional temporary tables.
522
563
the corresponding 'ha_*' method above.
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)
566
virtual int open(const char *name, int mode, uint32_t test_if_locked)=0;
567
virtual int index_init(uint32_t idx, bool)
528
568
{ active_index= idx; return 0; }
529
virtual int doEndIndexScan() { active_index= MAX_KEY; return 0; }
569
virtual int index_end() { active_index= MAX_KEY; return 0; }
531
doStartTableScan() can be called two times without doEndTableScan() in between
571
rnd_init() can be called two times without rnd_end() in between
532
572
(it only makes sense if scan=1).
533
573
then the second call should prepare for the new table scan (e.g
534
574
if rnd_init allocates the cursor, second call should position it
535
575
to the start of the table, no need to deallocate and allocate it again
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 *)
577
virtual int rnd_init(bool scan)= 0;
578
virtual int rnd_end() { return 0; }
579
virtual int write_row(unsigned char *)
581
return HA_ERR_WRONG_COMMAND;
584
virtual int update_row(const unsigned char *, unsigned char *)
586
return HA_ERR_WRONG_COMMAND;
589
virtual int delete_row(const unsigned char *)
551
591
return HA_ERR_WRONG_COMMAND;
637
677
extern const char *ha_row_type[];
678
extern const char *binlog_format_names[];
679
extern uint32_t total_ha, total_ha_2pc;
639
681
/* basic stuff */
640
void ha_init_errors(void);
643
SortField *make_unireg_sortorder(Order *order, uint32_t *length,
644
SortField *sortorder);
682
int ha_init_errors(void);
686
uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length);
687
bool tablename_to_filename(const char *from, char *to, size_t to_length);
691
Storage engine has to assume the transaction will end up with 2pc if
692
- there is more than one 2pc-capable storage engine available
693
- in the current transaction 2pc was not disabled yet
695
#define trans_need_2pc(session, all) ((total_ha_2pc > 1) && \
696
!((all ? &session->transaction.all : &session->transaction.stmt)->no_2pc))
699
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
700
SORT_FIELD *sortorder);
645
701
int setup_order(Session *session, Item **ref_pointer_array, TableList *tables,
646
List<Item> &fields, List <Item> &all_fields, Order *order);
702
List<Item> &fields, List <Item> &all_fields, order_st *order);
647
703
int setup_group(Session *session, Item **ref_pointer_array, TableList *tables,
648
List<Item> &fields, List<Item> &all_fields, Order *order,
704
List<Item> &fields, List<Item> &all_fields, order_st *order,
649
705
bool *hidden_group_fields);
650
706
bool fix_inner_refs(Session *session, List<Item> &all_fields, Select_Lex *select,
651
707
Item **ref_pointer_array);
664
720
int *timestamps, int *timestamps_with_niladic);
666
722
bool mysql_create_table(Session *session,
667
const TableIdentifier &identifier,
723
TableIdentifier &identifier,
668
724
HA_CREATE_INFO *create_info,
669
message::Table &table_proto,
725
message::Table *table_proto,
670
726
AlterInfo *alter_info,
671
727
bool tmp_table, uint32_t select_field_count,
672
728
bool is_if_not_exists);
674
730
bool mysql_create_table_no_lock(Session *session,
675
const TableIdentifier &identifier,
731
TableIdentifier &identifier,
676
732
HA_CREATE_INFO *create_info,
677
message::Table &table_proto,
733
message::Table *table_proto,
678
734
AlterInfo *alter_info,
679
bool tmp_table, uint32_t select_field_count,
736
uint32_t select_field_count,
680
737
bool is_if_not_exists);
682
bool mysql_create_like_table(Session* session,
683
const TableIdentifier &destination_identifier,
684
TableList* table, TableList* src_table,
685
message::Table &create_table_proto,
739
bool mysql_create_like_table(Session* session, TableList* table, TableList* src_table,
740
message::Table& create_table_proto,
741
plugin::StorageEngine*,
686
742
bool is_if_not_exists,
687
743
bool is_engine_set);
689
bool mysql_rename_table(Session &session,
690
plugin::StorageEngine *base,
691
const TableIdentifier &old_identifier,
692
const TableIdentifier &new_identifier);
745
bool mysql_rename_table(plugin::StorageEngine *base, const char *old_db,
746
const char * old_name, const char *new_db,
747
const char * new_name, uint32_t flags);
694
749
bool mysql_prepare_update(Session *session, TableList *table_list,
695
Item **conds, uint32_t order_num, Order *order);
750
Item **conds, uint32_t order_num, order_st *order);
696
751
int mysql_update(Session *session,TableList *tables,List<Item> &fields,
697
752
List<Item> &values,COND *conds,
698
uint32_t order_num, Order *order, ha_rows limit,
753
uint32_t order_num, order_st *order, ha_rows limit,
699
754
enum enum_duplicates handle_duplicates, bool ignore);
700
755
bool mysql_prepare_insert(Session *session, TableList *table_list, Table *table,
701
756
List<Item> &fields, List_item *values,
718
773
uint32_t key_length, uint32_t db_flags, int *error);
719
774
TableShare *get_cached_table_share(const char *db, const char *table_name);
720
775
bool reopen_name_locked_table(Session* session, TableList* table_list, bool link_in);
776
Table *table_cache_insert_placeholder(Session *session, const char *key,
777
uint32_t key_length);
778
bool lock_table_name_if_not_cached(Session *session, const char *db,
779
const char *table_name, Table **table);
780
bool reopen_table(Table *table);
721
781
bool reopen_tables(Session *session,bool get_locks,bool in_refresh);
782
void close_data_files_and_morph_locks(Session *session, const char *db,
783
const char *table_name);
722
784
void close_handle_and_leave_table_as_lock(Table *table);
723
785
bool wait_for_tables(Session *session);
724
786
bool table_is_used(Table *table, bool wait_for_name_lock);
725
Table *drop_locked_tables(Session *session, const drizzled::TableIdentifier &identifier);
726
void abort_locked_tables(Session *session, const drizzled::TableIdentifier &identifier);
787
Table *drop_locked_tables(Session *session,const char *db, const char *table_name);
788
void abort_locked_tables(Session *session,const char *db, const char *table_name);
727
789
extern Field *not_found_field;
728
790
extern Field *view_ref_found;