548
637
return memcmp(ref1, ref2, ref_length);
551
virtual bool isOrdered(void)
641
Condition pushdown to storage engines
645
Push condition down to the table handler.
647
@param cond Condition to be pushed. The condition tree must not be
648
modified by the by the caller.
651
The 'remainder' condition that caller must use to filter out records.
652
NULL means the handler will not return rows that do not match the
656
The pushed conditions form a stack (from which one can remove the
657
last pushed condition using cond_pop).
658
The table handler filters out rows using (pushed_cond1 AND pushed_cond2
659
AND ... AND pushed_condN)
660
or less restrictive condition, depending on handler's capabilities.
662
handler->ha_reset() call empties the condition stack.
663
Calls to rnd_init/rnd_end, index_init/index_end etc do not affect the
666
virtual const COND *cond_push(const COND *cond) { return cond; }
669
Pop the top condition from the condition stack of the handler instance.
671
Pops the top if condition stack, if stack is not empty.
673
virtual void cond_pop(void) { return; }
675
virtual Item *idx_cond_push(uint32_t, Item *idx_cond)
681
@param session Thread handle
682
@param lock_type HA_LOCK_IN_SHARE_MODE (F_RDLCK)
683
HA_LOCK_IN_EXCLUSIVE_MODE (F_WRLCK)
684
@param lock_timeout -1 default timeout
686
>0 wait timeout in milliseconds.
689
lock_timeout >0 is not used by MySQL currently. If the storage
690
engine does not support NOWAIT (lock_timeout == 0) it should
691
return an error. But if it does not support WAIT X (lock_timeout
692
>0) it should treat it as lock_timeout == -1 and wait a default
693
(or even hard-coded) timeout.
695
@retval HA_ERR_WRONG_COMMAND Storage engine does not support
697
@retval HA_ERR_UNSUPPORTED Storage engine does not support NOWAIT
698
@retval HA_ERR_LOCK_WAIT_TIMEOUT Lock request timed out or
699
lock conflict with NOWAIT option
700
@retval HA_ERR_LOCK_DEADLOCK Deadlock detected
702
virtual int lock_table(Session *, int, int)
704
return HA_ERR_WRONG_COMMAND;
558
708
/* Service methods for use by storage engines. */
559
void ha_statistic_increment(ulong system_status_var::*offset) const;
709
void ha_statistic_increment(ulong SSV::*offset) const;
560
710
void **ha_data(Session *) const;
561
711
Session *ha_session(void) const;
564
714
/* Private helpers */
565
inline void setTransactionReadWrite();
715
inline void mark_trx_read_write();
568
718
Low-level primitives for storage engines. These should be
642
795
uint32_t, enum ha_rkey_function)
643
796
{ return HA_ERR_WRONG_COMMAND; }
644
797
virtual int index_read_last(unsigned char *, const unsigned char *, uint32_t)
645
{ return (errno= HA_ERR_WRONG_COMMAND); }
798
{ return (my_errno= HA_ERR_WRONG_COMMAND); }
800
This method is similar to update_row, however the handler doesn't need
801
to execute the updates at this point in time. The handler can be certain
802
that another call to bulk_update_row will occur OR a call to
803
exec_bulk_update before the set of updates in this query is concluded.
805
@param old_data Old record
806
@param new_data New record
807
@param dup_key_found Number of duplicate keys found
809
@retval 0 Bulk delete used by handler
810
@retval 1 Bulk delete not used, normal operation used
812
virtual int bulk_update_row(const unsigned char *, unsigned char *, uint32_t *)
815
return HA_ERR_WRONG_COMMAND;
647
818
This is called to delete all rows in a table
648
If the Cursor don't support this, then this function will
819
If the handler don't support this, then this function will
649
820
return HA_ERR_WRONG_COMMAND and MySQL will delete the rows one
652
823
virtual int delete_all_rows(void)
653
{ return (errno=HA_ERR_WRONG_COMMAND); }
824
{ return (my_errno=HA_ERR_WRONG_COMMAND); }
655
826
Reset the auto-increment counter to the given value, i.e. the next row
656
827
inserted will get the given value. This is called e.g. after TRUNCATE
660
831
virtual int reset_auto_increment(uint64_t)
661
832
{ return HA_ERR_WRONG_COMMAND; }
663
virtual int analyze(Session *)
833
virtual int optimize(Session *, HA_CHECK_OPT *)
834
{ return HA_ADMIN_NOT_IMPLEMENTED; }
835
virtual int analyze(Session *, HA_CHECK_OPT *)
664
836
{ return HA_ADMIN_NOT_IMPLEMENTED; }
666
838
virtual int disable_indexes(uint32_t)
667
839
{ return HA_ERR_WRONG_COMMAND; }
669
840
virtual int enable_indexes(uint32_t)
670
841
{ return HA_ERR_WRONG_COMMAND; }
672
842
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.
843
{ return (my_errno=HA_ERR_WRONG_COMMAND); }
844
virtual void prepare_for_alter(void) { return; }
681
845
virtual void drop_table(const char *name);
851
A Disk-Sweep MRR interface implementation
853
This implementation makes range (and, in the future, 'ref') scans to read
854
table rows in disk sweeps.
856
Currently it is used by MyISAM and InnoDB. Potentially it can be used with
857
any table handler that has non-clustered indexes and on-disk rows.
863
typedef void (handler::*range_check_toggle_func_t)(bool on);
868
handler *h; /* The "owner" handler object. It is used for scanning the index */
869
Table *table; /* Always equal to h->table */
872
Secondary handler object. It is used to retrieve full table rows by
877
/* Buffer to store rowids, or (rowid, range_id) pairs */
878
unsigned char *rowids_buf;
879
unsigned char *rowids_buf_cur; /* Current position when reading/writing */
880
unsigned char *rowids_buf_last; /* When reading: end of used buffer space */
881
unsigned char *rowids_buf_end; /* End of the buffer */
883
bool dsmrr_eof; /* true <=> We have reached EOF when reading index tuples */
885
/* true <=> need range association, buffer holds {rowid, range_id} pairs */
888
bool use_default_impl; /* true <=> shortcut all calls to default MRR impl */
890
void init(handler *h_arg, Table *table_arg)
895
int dsmrr_init(handler *h, KEY *key, RANGE_SEQ_IF *seq_funcs,
896
void *seq_init_param, uint32_t n_ranges, uint32_t mode,
897
HANDLER_BUFFER *buf);
899
int dsmrr_fill_buffer(handler *h);
900
int dsmrr_next(handler *h, char **range_info);
902
int dsmrr_info(uint32_t keyno, uint32_t n_ranges, uint32_t keys, uint32_t *bufsz,
903
uint32_t *flags, COST_VECT *cost);
905
ha_rows dsmrr_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
906
void *seq_init_param, uint32_t n_ranges, uint32_t *bufsz,
907
uint32_t *flags, COST_VECT *cost);
909
bool key_uses_partial_cols(uint32_t keyno);
910
bool choose_mrr_impl(uint32_t keyno, ha_rows rows, uint32_t *flags, uint32_t *bufsz,
912
bool get_disk_sweep_mrr_cost(uint32_t keynr, ha_rows rows, uint32_t flags,
913
uint32_t *buffer_size, COST_VECT *cost);
684
916
extern const char *ha_row_type[];
917
extern const char *tx_isolation_names[];
918
extern const char *binlog_format_names[];
919
extern TYPELIB tx_isolation_typelib;
920
extern TYPELIB myisam_stats_method_typelib;
921
extern uint32_t total_ha, total_ha_2pc;
923
/* Wrapper functions */
924
#define ha_commit(session) (ha_commit_trans((session), true))
925
#define ha_rollback(session) (ha_rollback_trans((session), true))
686
927
/* basic stuff */
687
void ha_init_errors(void);
928
int ha_init_errors(void);
932
void add_storage_engine(StorageEngine *engine);
933
void remove_storage_engine(StorageEngine *engine);
935
void ha_close_connection(Session* session);
936
bool ha_flush_logs(StorageEngine *db_type);
937
void ha_drop_database(char* path);
938
int ha_create_table(Session *session, const char *path,
939
const char *db, const char *table_name,
940
HA_CREATE_INFO *create_info,
941
bool update_create_info);
942
int ha_delete_table(Session *session, const char *path,
943
const char *db, const char *alias, bool generate_warning);
945
/* statistics and info */
946
bool ha_show_status(Session *session, StorageEngine *db_type, enum ha_stat_type stat);
948
int ha_find_files(Session *session,const char *db,const char *path,
949
const char *wild, bool dir, List<LEX_STRING>* files);
950
int ha_table_exists_in_engine(Session* session, const char* db, const char* name, StorageEngine **engine= NULL);
953
extern "C" int ha_init_key_cache(const char *name, KEY_CACHE *key_cache);
954
int ha_resize_key_cache(KEY_CACHE *key_cache);
955
int ha_change_key_cache_param(KEY_CACHE *key_cache);
956
int ha_change_key_cache(KEY_CACHE *old_key_cache, KEY_CACHE *new_key_cache);
957
int ha_end_key_cache(KEY_CACHE *key_cache);
959
/* report to InnoDB that control passes to the client */
960
int ha_release_temporary_latches(Session *session);
962
/* transactions: interface to StorageEngine functions */
963
int ha_start_consistent_snapshot(Session *session);
964
int ha_commit_or_rollback_by_xid(XID *xid, bool commit);
965
int ha_commit_one_phase(Session *session, bool all);
966
int ha_rollback_trans(Session *session, bool all);
967
int ha_recover(HASH *commit_list);
969
/* transactions: these functions never call StorageEngine functions directly */
970
int ha_commit_trans(Session *session, bool all);
971
int ha_autocommit_or_rollback(Session *session, int error);
972
int ha_enable_transaction(Session *session, bool on);
975
int ha_rollback_to_savepoint(Session *session, SAVEPOINT *sv);
976
int ha_savepoint(Session *session, SAVEPOINT *sv);
977
int ha_release_savepoint(Session *session, SAVEPOINT *sv);
979
/* these are called by storage engines */
980
void trans_register_ha(Session *session, bool all, StorageEngine *engine);
982
uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length);
983
bool tablename_to_filename(const char *from, char *to, size_t to_length);
986
bool mysql_ha_open(Session *session, TableList *tables, bool reopen);
987
bool mysql_ha_close(Session *session, TableList *tables);
988
bool mysql_ha_read(Session *, TableList *,enum enum_ha_read_modes,char *,
989
List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows);
990
void mysql_ha_flush(Session *session);
991
void mysql_ha_rm_tables(Session *session, TableList *tables, bool is_locked);
992
void mysql_ha_cleanup(Session *session);
995
Storage engine has to assume the transaction will end up with 2pc if
996
- there is more than one 2pc-capable storage engine available
997
- in the current transaction 2pc was not disabled yet
999
#define trans_need_2pc(session, all) ((total_ha_2pc > 1) && \
1000
!((all ? &session->transaction.all : &session->transaction.stmt)->no_2pc))
1003
bool mysql_xa_recover(Session *session);
689
1005
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
690
1006
SORT_FIELD *sortorder);
699
1015
bool handle_select(Session *session, LEX *lex, select_result *result,
700
1016
uint64_t setup_tables_done_option);
1017
bool mysql_select(Session *session, Item ***rref_pointer_array,
1018
TableList *tables, uint32_t wild_num, List<Item> &list,
1019
COND *conds, uint32_t og_num, order_st *order, order_st *group,
1020
Item *having, uint64_t select_type,
1021
select_result *result, Select_Lex_Unit *unit,
1022
Select_Lex *select_lex);
701
1023
void free_underlaid_joins(Session *session, Select_Lex *select);
1024
bool mysql_explain_union(Session *session, Select_Lex_Unit *unit,
1025
select_result *result);
1026
int mysql_explain_select(Session *session, Select_Lex *sl, char const *type,
1027
select_result *result);
703
1029
bool mysql_handle_derived(LEX *lex, bool (*processor)(Session *session,
705
1031
TableList *table));
706
1032
bool mysql_derived_prepare(Session *session, LEX *lex, TableList *t);
707
1033
bool mysql_derived_filling(Session *session, LEX *lex, TableList *t);
1034
void sp_prepare_create_field(Session *session, CreateField *sql_field);
708
1035
int prepare_create_field(CreateField *sql_field,
709
1036
uint32_t *blob_columns,
710
int *timestamps, int *timestamps_with_niladic);
712
bool mysql_create_table(Session *session,
713
TableIdentifier &identifier,
1037
int *timestamps, int *timestamps_with_niladic,
1038
int64_t table_flags);
1039
bool mysql_create_table(Session *session,const char *db, const char *table_name,
714
1040
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,
1041
drizzled::message::Table *table_proto,
1042
Alter_info *alter_info,
1043
bool tmp_table, uint32_t select_field_count);
1044
bool mysql_create_table_no_lock(Session *session, const char *db,
1045
const char *table_name,
722
1046
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,
1047
drizzled::message::Table *table_proto,
1048
Alter_info *alter_info,
1049
bool tmp_table, uint32_t select_field_count);
1051
bool mysql_alter_table(Session *session, char *new_db, char *new_name,
1052
HA_CREATE_INFO *create_info,
1053
TableList *table_list,
1054
Alter_info *alter_info,
1055
uint32_t order_num, order_st *order, bool ignore);
1056
bool mysql_recreate_table(Session *session, TableList *table_list);
1057
bool mysql_create_like_table(Session *session, TableList *table,
1058
TableList *src_table,
1059
HA_CREATE_INFO *create_info);
1060
bool mysql_rename_table(StorageEngine *base, const char *old_db,
1061
const char * old_name, const char *new_db,
1062
const char * new_name, uint32_t flags);
740
1063
bool mysql_prepare_update(Session *session, TableList *table_list,
741
1064
Item **conds, uint32_t order_num, order_st *order);
742
1065
int mysql_update(Session *session,TableList *tables,List<Item> &fields,
743
1066
List<Item> &values,COND *conds,
744
1067
uint32_t order_num, order_st *order, ha_rows limit,
745
1068
enum enum_duplicates handle_duplicates, bool ignore);
1069
bool mysql_multi_update(Session *session, TableList *table_list,
1070
List<Item> *fields, List<Item> *values,
1071
COND *conds, uint64_t options,
1072
enum enum_duplicates handle_duplicates, bool ignore,
1073
Select_Lex_Unit *unit, Select_Lex *select_lex);
746
1074
bool mysql_prepare_insert(Session *session, TableList *table_list, Table *table,
747
1075
List<Item> &fields, List_item *values,
748
1076
List<Item> &update_fields,
759
1087
bool mysql_delete(Session *session, TableList *table_list, COND *conds,
760
1088
SQL_LIST *order, ha_rows rows, uint64_t options,
761
1089
bool reset_auto_increment);
762
bool mysql_truncate(Session& session, TableList *table_list);
1090
bool mysql_truncate(Session *session, TableList *table_list, bool dont_send_ok);
763
1091
TableShare *get_table_share(Session *session, TableList *table_list, char *key,
764
1092
uint32_t key_length, uint32_t db_flags, int *error);
765
1093
TableShare *get_cached_table_share(const char *db, const char *table_name);
1094
Table *open_ltable(Session *session, TableList *table_list, thr_lock_type update);
1095
Table *open_table(Session *session, TableList *table_list, bool *refresh, uint32_t flags);
1096
bool name_lock_locked_table(Session *session, TableList *tables);
766
1097
bool reopen_name_locked_table(Session* session, TableList* table_list, bool link_in);
767
1098
Table *table_cache_insert_placeholder(Session *session, const char *key,
768
1099
uint32_t key_length);
769
1100
bool lock_table_name_if_not_cached(Session *session, const char *db,
770
1101
const char *table_name, Table **table);
1102
Table *find_locked_table(Session *session, const char *db,const char *table_name);
1103
void detach_merge_children(Table *table, bool clear_refs);
1104
bool fix_merge_after_open(TableList *old_child_list, TableList **old_last,
1105
TableList *new_child_list, TableList **new_last);
771
1106
bool reopen_table(Table *table);
772
1107
bool reopen_tables(Session *session,bool get_locks,bool in_refresh);
773
1108
void close_data_files_and_morph_locks(Session *session, const char *db,
774
1109
const char *table_name);
775
1110
void close_handle_and_leave_table_as_lock(Table *table);
1111
bool open_new_frm(Session *session, TableShare *share, const char *alias,
1112
uint32_t db_stat, uint32_t prgflag,
1113
uint32_t ha_open_flags, Table *outparam,
1114
TableList *table_desc, MEM_ROOT *mem_root);
776
1115
bool wait_for_tables(Session *session);
777
1116
bool table_is_used(Table *table, bool wait_for_name_lock);
778
1117
Table *drop_locked_tables(Session *session,const char *db, const char *table_name);
784
1123
find_field_in_tables(Session *session, Item_ident *item,
785
1124
TableList *first_table, TableList *last_table,
786
1125
Item **ref, find_item_error_report_type report_error,
787
bool register_tree_change);
1126
bool check_privileges, bool register_tree_change);
789
1128
find_field_in_table_ref(Session *session, TableList *table_list,
790
1129
const char *name, uint32_t length,
791
1130
const char *item_name, const char *db_name,
792
1131
const char *table_name, Item **ref,
1132
bool check_privileges, bool allow_rowid,
794
1133
uint32_t *cached_field_index_ptr,
795
1134
bool register_tree_change, TableList **actual_table);
797
1136
find_field_in_table(Session *session, Table *table, const char *name, uint32_t length,
798
1137
bool allow_rowid, uint32_t *cached_field_index_ptr);
800
} /* namespace drizzled */
802
#endif /* DRIZZLED_CURSOR_H */
1139
find_field_in_table_sef(Table *table, const char *name);
1140
int update_virtual_fields_marked_for_write(Table *table,
1141
bool ignore_stored=true);
1144
#endif /* DRIZZLED_HANDLER_H */