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
#include <drizzled/atomics.h>
24
#include <drizzled/definitions.h>
23
#include <drizzled/xid.h>
25
24
#include <drizzled/discrete_interval.h>
26
#include <drizzled/error_t.h>
26
/* Definitions for parameters to do with handler-routines */
28
#include <mysys/thr_lock.h>
29
#include <mysys/hash.h>
30
#include <drizzled/sql_string.h>
31
#include <drizzled/sql_list.h>
32
#include <drizzled/plugin/storage_engine.h>
33
#include <drizzled/handler_structs.h>
27
34
#include <drizzled/ha_statistics.h>
28
#include <drizzled/handler_structs.h>
29
#include <drizzled/identifier.h>
30
#include <drizzled/key_map.h>
31
#include <drizzled/message/table.h>
32
#include <drizzled/sql_list.h>
33
#include <drizzled/thr_lock.h>
34
#include <drizzled/xid.h>
35
#include <drizzled/atomics.h>
37
#include <drizzled/message/table.pb.h>
39
/* Bits to show what an alter table will do */
40
#include <drizzled/sql_bitmap.h>
42
#include <drizzled/handler.h>
37
45
#include <algorithm>
39
#include <drizzled/visibility.h>
44
47
#define HA_MAX_ALTER_FLAGS 40
46
48
typedef std::bitset<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
50
extern drizzled::atomic<uint32_t> refresh_version; /* Increments on each reload */
53
typedef bool (*qc_engine_callback)(Session *session, char *table_key,
55
uint64_t *engine_data);
58
/* The handler for a table type. Will be included in the Table structure */
63
class Select_Lex_Unit;
64
struct st_foreign_key_info;
65
typedef struct st_foreign_key_info FOREIGN_KEY_INFO;
69
struct st_table_log_memory_entry;
55
class Select_Lex_Unit;
60
74
class select_result;
78
typedef struct st_sort_field SORT_FIELD;
64
80
typedef List<Item> List_item;
82
typedef struct st_savepoint SAVEPOINT;
83
extern uint32_t savepoint_alloc_size;
65
84
extern KEY_CREATE_INFO default_key_create_info;
67
86
/* Forward declaration for condition pushdown to storage engine */
68
87
typedef class Item COND;
70
typedef struct system_status_var system_status_var;
72
namespace optimizer { class CostVector; }
73
namespace plugin { class StorageEngine; }
89
typedef struct system_status_var SSV;
93
uint32_t calculate_key_len(Table *, uint, const unsigned char *, key_part_map);
76
95
bitmap with first N+1 bits set
77
96
(keypart_map for a key prefix of [0..N] keyparts)
226
235
Discrete_interval auto_inc_interval_for_cur_row;
228
Cursor(plugin::StorageEngine &engine_arg, Table &share_arg);
229
virtual ~Cursor(void);
230
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();
232
255
/* ha_ methods: pubilc wrappers for private virtual API */
234
int ha_open(const identifier::Table &identifier, int mode, int test_if_locked);
235
int startIndexScan(uint32_t idx, bool sorted) __attribute__ ((warn_unused_result));
237
int startTableScan(bool scan) __attribute__ ((warn_unused_result));
257
int ha_open(Table *table, const char *name, int mode, int test_if_locked);
258
int ha_index_init(uint32_t idx, bool sorted);
260
int ha_rnd_init(bool scan);
241
264
/* this is necessary in many places, e.g. in HANDLER command */
242
265
int ha_index_or_rnd_end();
266
Table_flags ha_table_flags() const;
245
269
These functions represent the public interface to *users* of the
246
Cursor class, hence they are *not* virtual. For the inheritance
247
interface, see the (private) functions doInsertRecord(), doUpdateRecord(),
248
and doDeleteRecord() below.
270
handler class, hence they are *not* virtual. For the inheritance
271
interface, see the (private) functions write_row(), update_row(),
272
and delete_row() below.
250
274
int ha_external_lock(Session *session, int lock_type);
251
int insertRecord(unsigned char * buf) __attribute__ ((warn_unused_result));
252
int updateRecord(const unsigned char * old_data, unsigned char * new_data) __attribute__ ((warn_unused_result));
253
int deleteRecord(const unsigned char * buf) __attribute__ ((warn_unused_result));
275
int ha_write_row(unsigned char * buf);
276
int ha_update_row(const unsigned char * old_data, unsigned char * new_data);
277
int ha_delete_row(const unsigned char * buf);
254
278
void ha_release_auto_increment();
256
280
/** to be actually called to get 'check()' functionality*/
614
775
virtual int reset_auto_increment(uint64_t)
615
776
{ return HA_ERR_WRONG_COMMAND; }
617
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 *)
618
780
{ return HA_ADMIN_NOT_IMPLEMENTED; }
620
782
virtual int disable_indexes(uint32_t)
621
783
{ return HA_ERR_WRONG_COMMAND; }
623
784
virtual int enable_indexes(uint32_t)
624
785
{ return HA_ERR_WRONG_COMMAND; }
626
786
virtual int discard_or_import_tablespace(bool)
627
{ return (errno=HA_ERR_WRONG_COMMAND); }
630
@todo this is just for the HEAP engine, it should
631
be removed at some point in the future (and
632
no new engine should ever use it). Right
633
now HEAP does rely on it, so we cannot remove it.
787
{ return (my_errno=HA_ERR_WRONG_COMMAND); }
635
788
virtual void drop_table(const char *name);
638
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))
640
801
/* basic stuff */
641
void ha_init_errors(void);
644
SortField *make_unireg_sortorder(Order *order, uint32_t *length,
645
SortField *sortorder);
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);
864
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
865
SORT_FIELD *sortorder);
646
866
int setup_order(Session *session, Item **ref_pointer_array, TableList *tables,
647
List<Item> &fields, List <Item> &all_fields, Order *order);
867
List<Item> &fields, List <Item> &all_fields, order_st *order);
648
868
int setup_group(Session *session, Item **ref_pointer_array, TableList *tables,
649
List<Item> &fields, List<Item> &all_fields, Order *order,
869
List<Item> &fields, List<Item> &all_fields, order_st *order,
650
870
bool *hidden_group_fields);
651
871
bool fix_inner_refs(Session *session, List<Item> &all_fields, Select_Lex *select,
652
872
Item **ref_pointer_array);
654
874
bool handle_select(Session *session, LEX *lex, select_result *result,
655
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);
656
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);
658
bool handle_derived(LEX *lex, bool (*processor)(Session *session,
888
bool mysql_handle_derived(LEX *lex, bool (*processor)(Session *session,
660
890
TableList *table));
661
bool derived_prepare(Session *session, LEX *lex, TableList *t);
662
bool derived_filling(Session *session, LEX *lex, TableList *t);
891
bool mysql_derived_prepare(Session *session, LEX *lex, TableList *t);
892
bool mysql_derived_filling(Session *session, LEX *lex, TableList *t);
893
void sp_prepare_create_field(Session *session, CreateField *sql_field);
663
894
int prepare_create_field(CreateField *sql_field,
664
895
uint32_t *blob_columns,
665
int *timestamps, int *timestamps_with_niladic);
667
bool create_table(Session *session,
668
const identifier::Table &identifier,
669
HA_CREATE_INFO *create_info,
670
message::Table &table_proto,
671
AlterInfo *alter_info,
672
bool tmp_table, uint32_t select_field_count,
673
bool is_if_not_exists);
675
bool create_table_no_lock(Session *session,
676
const identifier::Table &identifier,
677
HA_CREATE_INFO *create_info,
678
message::Table &table_proto,
679
AlterInfo *alter_info,
680
bool tmp_table, uint32_t select_field_count,
681
bool is_if_not_exists);
683
bool create_like_table(Session* session,
684
identifier::Table::const_reference destination_identifier,
685
identifier::Table::const_reference source_identifier,
686
message::Table &create_table_proto,
687
bool is_if_not_exists,
690
bool rename_table(Session &session,
691
plugin::StorageEngine *base,
692
const identifier::Table &old_identifier,
693
const identifier::Table &new_identifier);
695
bool prepare_update(Session *session, TableList *table_list,
696
Item **conds, uint32_t order_num, Order *order);
697
int update_query(Session *session,TableList *tables,List<Item> &fields,
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,
899
HA_CREATE_INFO *create_info,
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,
905
HA_CREATE_INFO *create_info,
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);
917
bool mysql_prepare_update(Session *session, TableList *table_list,
918
Item **conds, uint32_t order_num, order_st *order);
919
int mysql_update(Session *session,TableList *tables,List<Item> &fields,
698
920
List<Item> &values,COND *conds,
699
uint32_t order_num, Order *order, ha_rows limit,
921
uint32_t order_num, order_st *order, ha_rows limit,
700
922
enum enum_duplicates handle_duplicates, bool ignore);
701
bool prepare_insert(Session *session, TableList *table_list, Table *table,
923
bool mysql_prepare_insert(Session *session, TableList *table_list, Table *table,
702
924
List<Item> &fields, List_item *values,
703
925
List<Item> &update_fields,
704
926
List<Item> &update_values, enum_duplicates duplic,
705
927
COND **where, bool select_insert,
706
928
bool check_fields, bool abort_on_warning);
707
bool insert_query(Session *session,TableList *table,List<Item> &fields,
929
bool mysql_insert(Session *session,TableList *table,List<Item> &fields,
708
930
List<List_item> &values, List<Item> &update_fields,
709
931
List<Item> &update_values, enum_duplicates flag,
711
933
int check_that_all_fields_are_given_values(Session *session, Table *entry,
712
934
TableList *table_list);
713
int prepare_delete(Session *session, TableList *table_list, Item **conds);
714
bool delete_query(Session *session, TableList *table_list, COND *conds,
935
int mysql_prepare_delete(Session *session, TableList *table_list, Item **conds);
936
bool mysql_delete(Session *session, TableList *table_list, COND *conds,
715
937
SQL_LIST *order, ha_rows rows, uint64_t options,
716
938
bool reset_auto_increment);
717
bool truncate(Session& session, TableList *table_list);
939
bool mysql_truncate(Session *session, TableList *table_list, bool dont_send_ok);
718
940
TableShare *get_table_share(Session *session, TableList *table_list, char *key,
719
941
uint32_t key_length, uint32_t db_flags, int *error);
720
942
TableShare *get_cached_table_share(const char *db, const char *table_name);
721
943
bool reopen_name_locked_table(Session* session, TableList* table_list, bool link_in);
944
Table *table_cache_insert_placeholder(Session *session, const char *key,
945
uint32_t key_length);
946
bool lock_table_name_if_not_cached(Session *session, const char *db,
947
const char *table_name, Table **table);
948
bool reopen_table(Table *table);
722
949
bool reopen_tables(Session *session,bool get_locks,bool in_refresh);
950
void close_data_files_and_morph_locks(Session *session, const char *db,
951
const char *table_name);
723
952
void close_handle_and_leave_table_as_lock(Table *table);
724
953
bool wait_for_tables(Session *session);
725
954
bool table_is_used(Table *table, bool wait_for_name_lock);
726
Table *drop_locked_tables(Session *session, const drizzled::identifier::Table &identifier);
727
void abort_locked_tables(Session *session, const drizzled::identifier::Table &identifier);
955
Table *drop_locked_tables(Session *session,const char *db, const char *table_name);
956
void abort_locked_tables(Session *session,const char *db, const char *table_name);
728
957
extern Field *not_found_field;
729
958
extern Field *view_ref_found;