17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#ifndef DRIZZLED_CURSOR_H
21
#define DRIZZLED_CURSOR_H
20
#ifndef DRIZZLED_HANDLER_H
21
#define DRIZZLED_HANDLER_H
23
23
#include <drizzled/xid.h>
24
24
#include <drizzled/discrete_interval.h>
25
#include <drizzled/table_identifier.h>
27
/* Definitions for parameters to do with Cursor-routines */
29
#include <drizzled/thr_lock.h>
26
/* Definitions for parameters to do with handler-routines */
28
#include <mysys/thr_lock.h>
29
#include <mysys/hash.h>
30
30
#include <drizzled/sql_string.h>
31
31
#include <drizzled/sql_list.h>
32
32
#include <drizzled/plugin/storage_engine.h>
243
235
Discrete_interval auto_inc_interval_for_cur_row;
245
Cursor(plugin::StorageEngine &engine_arg, TableShare &share_arg);
246
virtual ~Cursor(void);
247
virtual Cursor *clone(memory::Root *mem_root);
237
handler(StorageEngine *engine_arg, TableShare *share_arg)
238
:table_share(share_arg), table(0),
239
estimation_rows_to_insert(0), engine(engine_arg),
240
ref(0), in_range_check_pushed_down(false),
241
key_used_on_scan(MAX_KEY), active_index(MAX_KEY),
242
ref_length(sizeof(my_off_t)),
244
locked(false), implicit_emptied(0),
245
next_insert_id(0), insert_id_for_cur_row(0)
247
virtual ~handler(void);
248
virtual handler *clone(MEM_ROOT *mem_root);
249
/** This is called after create to allow us to set up cached variables */
252
cached_table_flags= table_flags();
249
255
/* ha_ methods: pubilc wrappers for private virtual API */
276
283
void ha_start_bulk_insert(ha_rows rows);
277
284
int ha_end_bulk_insert();
285
int ha_bulk_update_row(const unsigned char *old_data, unsigned char *new_data,
286
uint32_t *dup_key_found);
278
287
int ha_delete_all_rows();
279
288
int ha_reset_auto_increment(uint64_t value);
289
int ha_optimize(Session* session, HA_CHECK_OPT* check_opt);
280
290
int ha_analyze(Session* session, HA_CHECK_OPT* check_opt);
282
292
int ha_disable_indexes(uint32_t mode);
283
293
int ha_enable_indexes(uint32_t mode);
284
294
int ha_discard_or_import_tablespace(bool discard);
285
void closeMarkForDelete(const char *name);
295
void ha_drop_table(const char *name);
287
297
void adjust_next_insert_id_after_explicit_value(uint64_t nr);
288
298
int update_auto_increment();
299
void print_keydup_error(uint32_t key_nr, const char *msg);
300
virtual void print_error(int error, myf errflag);
301
virtual bool get_error_message(int error, String *buf);
302
uint32_t get_dup_key(int error);
289
303
virtual void change_table_ptr(Table *table_arg, TableShare *share);
291
305
/* Estimates calculation */
299
313
virtual ha_rows multi_range_read_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
300
314
void *seq_init_param,
301
315
uint32_t n_ranges, uint32_t *bufsz,
302
uint32_t *flags, optimizer::CostVector *cost);
316
uint32_t *flags, COST_VECT *cost);
303
317
virtual int multi_range_read_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys,
304
uint32_t *bufsz, uint32_t *flags, optimizer::CostVector *cost);
318
uint32_t *bufsz, uint32_t *flags, COST_VECT *cost);
305
319
virtual int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
306
320
uint32_t n_ranges, uint32_t mode,
307
321
HANDLER_BUFFER *buf);
353
365
virtual int close(void)=0;
368
@retval 0 Bulk update used by handler
369
@retval 1 Bulk update not used, normal operation used
371
virtual bool start_bulk_update() { return 1; }
373
@retval 0 Bulk delete used by handler
374
@retval 1 Bulk delete not used, normal operation used
376
virtual bool start_bulk_delete() { return 1; }
378
After this call all outstanding updates must be performed. The number
379
of duplicate key errors are reported in the duplicate key parameter.
380
It is allowed to continue to the batched update after this call, the
381
handler has to wait until end_bulk_update with changing state.
383
@param dup_key_found Number of duplicate keys found
386
@retval >0 Error code
388
virtual int exec_bulk_update(uint32_t *)
391
return HA_ERR_WRONG_COMMAND;
394
Perform any needed clean-up, no outstanding updates are there at the
397
virtual void end_bulk_update() { return; }
399
Execute all outstanding deletes and close down the bulk delete.
402
@retval >0 Error code
404
virtual int end_bulk_delete()
407
return HA_ERR_WRONG_COMMAND;
357
411
Positions an index cursor to the index specified in the handle. Fetches the
358
412
row if available. If the key value is null, begin at the first key of the
513
570
virtual int final_drop_index(Table *)
514
571
{ return (HA_ERR_WRONG_COMMAND); }
573
uint32_t max_record_length() const
574
{ return std::min((unsigned int)HA_MAX_REC_LENGTH, max_supported_record_length()); }
575
uint32_t max_keys() const
576
{ return std::min((unsigned int)MAX_KEY, max_supported_keys()); }
577
uint32_t max_key_parts() const
578
{ return std::min((unsigned int)MAX_REF_PARTS, max_supported_key_parts()); }
579
uint32_t max_key_length() const
580
{ return std::min((unsigned int)MAX_KEY_LENGTH, max_supported_key_length()); }
581
uint32_t max_key_part_length(void) const
582
{ return std::min((unsigned int)MAX_KEY_LENGTH, max_supported_key_part_length()); }
584
virtual uint32_t max_supported_record_length(void) const
585
{ return HA_MAX_REC_LENGTH; }
586
virtual uint32_t max_supported_keys(void) const { return 0; }
587
virtual uint32_t max_supported_key_parts(void) const { return MAX_REF_PARTS; }
588
virtual uint32_t max_supported_key_length(void) const { return MAX_KEY_LENGTH; }
589
virtual uint32_t max_supported_key_part_length(void) const { return 255; }
591
virtual bool low_byte_first(void) const { return 1; }
516
592
virtual uint32_t checksum(void) const { return 0; }
593
virtual bool is_crashed(void) const { return 0; }
594
virtual bool auto_repair(void) const { return 0; }
519
597
Is not invoked for non-transactional temporary tables.
548
621
return memcmp(ref1, ref2, ref_length);
551
virtual bool isOrdered(void)
627
@param session Thread handle
628
@param lock_type HA_LOCK_IN_SHARE_MODE (F_RDLCK)
629
HA_LOCK_IN_EXCLUSIVE_MODE (F_WRLCK)
630
@param lock_timeout -1 default timeout
632
>0 wait timeout in milliseconds.
635
lock_timeout >0 is not used by MySQL currently. If the storage
636
engine does not support NOWAIT (lock_timeout == 0) it should
637
return an error. But if it does not support WAIT X (lock_timeout
638
>0) it should treat it as lock_timeout == -1 and wait a default
639
(or even hard-coded) timeout.
641
@retval HA_ERR_WRONG_COMMAND Storage engine does not support
643
@retval HA_ERR_UNSUPPORTED Storage engine does not support NOWAIT
644
@retval HA_ERR_LOCK_WAIT_TIMEOUT Lock request timed out or
645
lock conflict with NOWAIT option
646
@retval HA_ERR_LOCK_DEADLOCK Deadlock detected
648
virtual int lock_table(Session *, int, int)
650
return HA_ERR_WRONG_COMMAND;
558
654
/* Service methods for use by storage engines. */
559
void ha_statistic_increment(ulong system_status_var::*offset) const;
655
void ha_statistic_increment(ulong SSV::*offset) const;
560
656
void **ha_data(Session *) const;
561
657
Session *ha_session(void) const;
564
660
/* Private helpers */
565
inline void setTransactionReadWrite();
661
inline void mark_trx_read_write();
568
664
Low-level primitives for storage engines. These should be
642
739
uint32_t, enum ha_rkey_function)
643
740
{ return HA_ERR_WRONG_COMMAND; }
644
741
virtual int index_read_last(unsigned char *, const unsigned char *, uint32_t)
645
{ return (errno= HA_ERR_WRONG_COMMAND); }
742
{ return (my_errno= HA_ERR_WRONG_COMMAND); }
744
This method is similar to update_row, however the handler doesn't need
745
to execute the updates at this point in time. The handler can be certain
746
that another call to bulk_update_row will occur OR a call to
747
exec_bulk_update before the set of updates in this query is concluded.
749
@param old_data Old record
750
@param new_data New record
751
@param dup_key_found Number of duplicate keys found
753
@retval 0 Bulk delete used by handler
754
@retval 1 Bulk delete not used, normal operation used
756
virtual int bulk_update_row(const unsigned char *, unsigned char *, uint32_t *)
759
return HA_ERR_WRONG_COMMAND;
647
762
This is called to delete all rows in a table
648
If the Cursor don't support this, then this function will
763
If the handler don't support this, then this function will
649
764
return HA_ERR_WRONG_COMMAND and MySQL will delete the rows one
652
767
virtual int delete_all_rows(void)
653
{ return (errno=HA_ERR_WRONG_COMMAND); }
768
{ return (my_errno=HA_ERR_WRONG_COMMAND); }
655
770
Reset the auto-increment counter to the given value, i.e. the next row
656
771
inserted will get the given value. This is called e.g. after TRUNCATE
660
775
virtual int reset_auto_increment(uint64_t)
661
776
{ return HA_ERR_WRONG_COMMAND; }
663
virtual int analyze(Session *)
777
virtual int optimize(Session *, HA_CHECK_OPT *)
778
{ return HA_ADMIN_NOT_IMPLEMENTED; }
779
virtual int analyze(Session *, HA_CHECK_OPT *)
664
780
{ return HA_ADMIN_NOT_IMPLEMENTED; }
666
782
virtual int disable_indexes(uint32_t)
667
783
{ return HA_ERR_WRONG_COMMAND; }
669
784
virtual int enable_indexes(uint32_t)
670
785
{ return HA_ERR_WRONG_COMMAND; }
672
786
virtual int discard_or_import_tablespace(bool)
673
{ return (errno=HA_ERR_WRONG_COMMAND); }
676
@todo this is just for the HEAP engine, it should
677
be removed at some point in the future (and
678
no new engine should ever use it). Right
679
now HEAP does rely on it, so we cannot remove it.
787
{ return (my_errno=HA_ERR_WRONG_COMMAND); }
681
788
virtual void drop_table(const char *name);
684
791
extern const char *ha_row_type[];
792
extern const char *tx_isolation_names[];
793
extern const char *binlog_format_names[];
794
extern TYPELIB tx_isolation_typelib;
795
extern uint32_t total_ha, total_ha_2pc;
797
/* Wrapper functions */
798
#define ha_commit(session) (ha_commit_trans((session), true))
799
#define ha_rollback(session) (ha_rollback_trans((session), true))
686
801
/* basic stuff */
687
void ha_init_errors(void);
802
int ha_init_errors(void);
806
void add_storage_engine(StorageEngine *engine);
807
void remove_storage_engine(StorageEngine *engine);
809
void ha_close_connection(Session* session);
810
bool ha_flush_logs(StorageEngine *db_type);
811
void ha_drop_database(char* path);
812
int ha_create_table(Session *session, const char *path,
813
const char *db, const char *table_name,
814
HA_CREATE_INFO *create_info,
815
bool update_create_info,
816
drizzled::message::Table *table_proto);
817
int ha_delete_table(Session *session, const char *path,
818
const char *db, const char *alias, bool generate_warning);
820
/* statistics and info */
821
bool ha_show_status(Session *session, StorageEngine *db_type, enum ha_stat_type stat);
823
int ha_find_files(Session *session,const char *db,const char *path,
824
const char *wild, bool dir, List<LEX_STRING>* files);
826
/* report to InnoDB that control passes to the client */
827
int ha_release_temporary_latches(Session *session);
829
/* transactions: interface to StorageEngine functions */
830
int ha_start_consistent_snapshot(Session *session);
831
int ha_commit_or_rollback_by_xid(XID *xid, bool commit);
832
int ha_commit_one_phase(Session *session, bool all);
833
int ha_rollback_trans(Session *session, bool all);
834
int ha_recover(HASH *commit_list);
836
/* transactions: these functions never call StorageEngine functions directly */
837
int ha_commit_trans(Session *session, bool all);
838
int ha_autocommit_or_rollback(Session *session, int error);
839
int ha_enable_transaction(Session *session, bool on);
842
int ha_rollback_to_savepoint(Session *session, SAVEPOINT *sv);
843
int ha_savepoint(Session *session, SAVEPOINT *sv);
844
int ha_release_savepoint(Session *session, SAVEPOINT *sv);
846
/* these are called by storage engines */
847
void trans_register_ha(Session *session, bool all, StorageEngine *engine);
849
uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length);
850
bool tablename_to_filename(const char *from, char *to, size_t to_length);
854
Storage engine has to assume the transaction will end up with 2pc if
855
- there is more than one 2pc-capable storage engine available
856
- in the current transaction 2pc was not disabled yet
858
#define trans_need_2pc(session, all) ((total_ha_2pc > 1) && \
859
!((all ? &session->transaction.all : &session->transaction.stmt)->no_2pc))
862
bool mysql_xa_recover(Session *session);
689
864
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
690
865
SORT_FIELD *sortorder);
699
874
bool handle_select(Session *session, LEX *lex, select_result *result,
700
875
uint64_t setup_tables_done_option);
876
bool mysql_select(Session *session, Item ***rref_pointer_array,
877
TableList *tables, uint32_t wild_num, List<Item> &list,
878
COND *conds, uint32_t og_num, order_st *order, order_st *group,
879
Item *having, uint64_t select_type,
880
select_result *result, Select_Lex_Unit *unit,
881
Select_Lex *select_lex);
701
882
void free_underlaid_joins(Session *session, Select_Lex *select);
883
bool mysql_explain_union(Session *session, Select_Lex_Unit *unit,
884
select_result *result);
885
int mysql_explain_select(Session *session, Select_Lex *sl, char const *type,
886
select_result *result);
703
888
bool mysql_handle_derived(LEX *lex, bool (*processor)(Session *session,
705
890
TableList *table));
706
891
bool mysql_derived_prepare(Session *session, LEX *lex, TableList *t);
707
892
bool mysql_derived_filling(Session *session, LEX *lex, TableList *t);
893
void sp_prepare_create_field(Session *session, CreateField *sql_field);
708
894
int prepare_create_field(CreateField *sql_field,
709
895
uint32_t *blob_columns,
710
int *timestamps, int *timestamps_with_niladic);
712
bool mysql_create_table(Session *session,
713
TableIdentifier &identifier,
896
int *timestamps, int *timestamps_with_niladic,
897
int64_t table_flags);
898
bool mysql_create_table(Session *session,const char *db, const char *table_name,
714
899
HA_CREATE_INFO *create_info,
715
message::Table &table_proto,
716
AlterInfo *alter_info,
717
bool tmp_table, uint32_t select_field_count,
718
bool is_if_not_exists);
720
bool mysql_create_table_no_lock(Session *session,
721
TableIdentifier &identifier,
900
drizzled::message::Table *table_proto,
901
Alter_info *alter_info,
902
bool tmp_table, uint32_t select_field_count);
903
bool mysql_create_table_no_lock(Session *session, const char *db,
904
const char *table_name,
722
905
HA_CREATE_INFO *create_info,
723
message::Table &table_proto,
724
AlterInfo *alter_info,
725
bool tmp_table, uint32_t select_field_count,
726
bool is_if_not_exists);
728
bool mysql_create_like_table(Session* session,
729
TableIdentifier &destination_identifier,
730
TableList* table, TableList* src_table,
731
message::Table &create_table_proto,
732
bool is_if_not_exists,
735
bool mysql_rename_table(plugin::StorageEngine *base,
736
TableIdentifier &old_identifier,
737
TableIdentifier &new_identifier,
906
drizzled::message::Table *table_proto,
907
Alter_info *alter_info,
908
bool tmp_table, uint32_t select_field_count);
910
bool mysql_recreate_table(Session *session, TableList *table_list);
911
bool mysql_create_like_table(Session *session, TableList *table,
912
TableList *src_table,
913
HA_CREATE_INFO *create_info);
914
bool mysql_rename_table(StorageEngine *base, const char *old_db,
915
const char * old_name, const char *new_db,
916
const char * new_name, uint32_t flags);
740
917
bool mysql_prepare_update(Session *session, TableList *table_list,
741
918
Item **conds, uint32_t order_num, order_st *order);
742
919
int mysql_update(Session *session,TableList *tables,List<Item> &fields,
759
936
bool mysql_delete(Session *session, TableList *table_list, COND *conds,
760
937
SQL_LIST *order, ha_rows rows, uint64_t options,
761
938
bool reset_auto_increment);
762
bool mysql_truncate(Session& session, TableList *table_list);
939
bool mysql_truncate(Session *session, TableList *table_list, bool dont_send_ok);
763
940
TableShare *get_table_share(Session *session, TableList *table_list, char *key,
764
941
uint32_t key_length, uint32_t db_flags, int *error);
765
942
TableShare *get_cached_table_share(const char *db, const char *table_name);