23
23
#include <drizzled/xid.h>
24
24
#include <drizzled/discrete_interval.h>
25
#include <drizzled/identifier.h>
26
#include <drizzled/definitions.h>
27
#include <drizzled/key_map.h>
28
#include <drizzled/error_t.h>
30
26
/* Definitions for parameters to do with Cursor-routines */
32
#include <drizzled/thr_lock.h>
28
#include <mysys/thr_lock.h>
29
#include <mysys/hash.h>
30
#include <drizzled/sql_string.h>
33
31
#include <drizzled/sql_list.h>
32
#include <drizzled/plugin/storage_engine.h>
34
33
#include <drizzled/handler_structs.h>
35
34
#include <drizzled/ha_statistics.h>
36
35
#include <drizzled/atomics.h>
38
#include <drizzled/message/table.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/cursor.h>
41
45
#include <algorithm>
43
#include "drizzled/visibility.h"
48
47
#define HA_MAX_ALTER_FLAGS 40
50
50
typedef std::bitset<HA_MAX_ALTER_FLAGS> HA_ALTER_FLAGS;
52
extern uint64_t refresh_version; /* Increments on each reload */
55
typedef bool (*qc_engine_callback)(Session *session, char *table_key,
57
uint64_t *engine_data);
60
/* The Cursor for a table type. Will be included in the Table structure */
65
class Select_Lex_Unit;
66
struct st_foreign_key_info;
67
typedef struct st_foreign_key_info FOREIGN_KEY_INFO;
71
struct st_table_log_memory_entry;
59
class Select_Lex_Unit;
64
76
class select_result;
80
typedef struct st_sort_field SORT_FIELD;
68
82
typedef List<Item> List_item;
84
typedef struct st_savepoint SAVEPOINT;
85
extern uint32_t savepoint_alloc_size;
69
86
extern KEY_CREATE_INFO default_key_create_info;
71
88
/* Forward declaration for condition pushdown to storage engine */
72
89
typedef class Item COND;
74
typedef struct system_status_var system_status_var;
76
namespace optimizer { class CostVector; }
77
namespace plugin { class StorageEngine; }
91
typedef struct system_status_var SSV;
95
uint32_t calculate_key_len(Table *, uint, const unsigned char *, key_part_map);
80
97
bitmap with first N+1 bits set
81
98
(keypart_map for a key prefix of [0..N] keyparts)
230
233
Discrete_interval auto_inc_interval_for_cur_row;
232
Cursor(plugin::StorageEngine &engine_arg, Table &share_arg);
235
Cursor(drizzled::plugin::StorageEngine &engine_arg, TableShare &share_arg)
236
:table_share(&share_arg), table(0),
237
estimation_rows_to_insert(0), engine(&engine_arg),
238
ref(0), in_range_check_pushed_down(false),
239
key_used_on_scan(MAX_KEY), active_index(MAX_KEY),
240
ref_length(sizeof(my_off_t)),
242
locked(false), implicit_emptied(0),
243
next_insert_id(0), insert_id_for_cur_row(0)
233
245
virtual ~Cursor(void);
234
virtual Cursor *clone(memory::Root *mem_root);
246
virtual Cursor *clone(MEM_ROOT *mem_root);
236
248
/* ha_ methods: pubilc wrappers for private virtual API */
238
int ha_open(const identifier::Table &identifier, int mode, int test_if_locked);
239
int startIndexScan(uint32_t idx, bool sorted) __attribute__ ((warn_unused_result));
241
int startTableScan(bool scan) __attribute__ ((warn_unused_result));
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);
245
257
/* this is necessary in many places, e.g. in HANDLER command */
246
258
int ha_index_or_rnd_end();
259
drizzled::plugin::StorageEngine::Table_flags ha_table_flags() const;
249
262
These functions represent the public interface to *users* of the
250
263
Cursor class, hence they are *not* virtual. For the inheritance
251
interface, see the (private) functions doInsertRecord(), doUpdateRecord(),
252
and doDeleteRecord() below.
264
interface, see the (private) functions write_row(), update_row(),
265
and delete_row() below.
254
267
int ha_external_lock(Session *session, int lock_type);
255
int insertRecord(unsigned char * buf) __attribute__ ((warn_unused_result));
256
int updateRecord(const unsigned char * old_data, unsigned char * new_data) __attribute__ ((warn_unused_result));
257
int deleteRecord(const unsigned char * buf) __attribute__ ((warn_unused_result));
268
int ha_write_row(unsigned char * buf);
269
int ha_update_row(const unsigned char * old_data, unsigned char * new_data);
270
int ha_delete_row(const unsigned char * buf);
258
271
void ha_release_auto_increment();
260
273
/** to be actually called to get 'check()' functionality*/
642
772
extern const char *ha_row_type[];
773
extern const char *tx_isolation_names[];
774
extern const char *binlog_format_names[];
775
extern TYPELIB tx_isolation_typelib;
776
extern uint32_t total_ha, total_ha_2pc;
778
/* Wrapper functions */
779
#define ha_commit(session) (ha_commit_trans((session), true))
780
#define ha_rollback(session) (ha_rollback_trans((session), true))
644
782
/* basic stuff */
645
void ha_init_errors(void);
648
SortField *make_unireg_sortorder(Order *order, uint32_t *length,
649
SortField *sortorder);
783
int ha_init_errors(void);
787
/* transactions: interface to plugin::StorageEngine functions */
788
int ha_commit_one_phase(Session *session, bool all);
789
int ha_rollback_trans(Session *session, bool all);
791
/* transactions: these functions never call plugin::StorageEngine functions directly */
792
int ha_commit_trans(Session *session, bool all);
793
int ha_autocommit_or_rollback(Session *session, int error);
794
int ha_enable_transaction(Session *session, bool on);
797
int ha_rollback_to_savepoint(Session *session, SAVEPOINT *sv);
798
int ha_savepoint(Session *session, SAVEPOINT *sv);
799
int ha_release_savepoint(Session *session, SAVEPOINT *sv);
801
/* these are called by storage engines */
802
void trans_register_ha(Session *session, bool all, drizzled::plugin::StorageEngine *engine);
804
uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length);
805
bool tablename_to_filename(const char *from, char *to, size_t to_length);
809
Storage engine has to assume the transaction will end up with 2pc if
810
- there is more than one 2pc-capable storage engine available
811
- in the current transaction 2pc was not disabled yet
813
#define trans_need_2pc(session, all) ((total_ha_2pc > 1) && \
814
!((all ? &session->transaction.all : &session->transaction.stmt)->no_2pc))
817
bool mysql_xa_recover(Session *session);
819
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
820
SORT_FIELD *sortorder);
650
821
int setup_order(Session *session, Item **ref_pointer_array, TableList *tables,
651
List<Item> &fields, List <Item> &all_fields, Order *order);
822
List<Item> &fields, List <Item> &all_fields, order_st *order);
652
823
int setup_group(Session *session, Item **ref_pointer_array, TableList *tables,
653
List<Item> &fields, List<Item> &all_fields, Order *order,
824
List<Item> &fields, List<Item> &all_fields, order_st *order,
654
825
bool *hidden_group_fields);
655
826
bool fix_inner_refs(Session *session, List<Item> &all_fields, Select_Lex *select,
656
827
Item **ref_pointer_array);
658
829
bool handle_select(Session *session, LEX *lex, select_result *result,
659
830
uint64_t setup_tables_done_option);
831
bool mysql_select(Session *session, Item ***rref_pointer_array,
832
TableList *tables, uint32_t wild_num, List<Item> &list,
833
COND *conds, uint32_t og_num, order_st *order, order_st *group,
834
Item *having, uint64_t select_type,
835
select_result *result, Select_Lex_Unit *unit,
836
Select_Lex *select_lex);
660
837
void free_underlaid_joins(Session *session, Select_Lex *select);
838
bool mysql_explain_union(Session *session, Select_Lex_Unit *unit,
839
select_result *result);
840
int mysql_explain_select(Session *session, Select_Lex *sl, char const *type,
841
select_result *result);
662
bool handle_derived(LEX *lex, bool (*processor)(Session *session,
843
bool mysql_handle_derived(LEX *lex, bool (*processor)(Session *session,
664
845
TableList *table));
665
bool derived_prepare(Session *session, LEX *lex, TableList *t);
666
bool derived_filling(Session *session, LEX *lex, TableList *t);
846
bool mysql_derived_prepare(Session *session, LEX *lex, TableList *t);
847
bool mysql_derived_filling(Session *session, LEX *lex, TableList *t);
667
848
int prepare_create_field(CreateField *sql_field,
668
849
uint32_t *blob_columns,
669
int *timestamps, int *timestamps_with_niladic);
671
bool create_table(Session *session,
672
const identifier::Table &identifier,
673
HA_CREATE_INFO *create_info,
674
message::Table &table_proto,
675
AlterInfo *alter_info,
676
bool tmp_table, uint32_t select_field_count,
677
bool is_if_not_exists);
679
bool create_table_no_lock(Session *session,
680
const identifier::Table &identifier,
681
HA_CREATE_INFO *create_info,
682
message::Table &table_proto,
683
AlterInfo *alter_info,
684
bool tmp_table, uint32_t select_field_count,
685
bool is_if_not_exists);
687
bool create_like_table(Session* session,
688
identifier::Table::const_reference destination_identifier,
689
identifier::Table::const_reference source_identifier,
690
message::Table &create_table_proto,
691
bool is_if_not_exists,
694
bool rename_table(Session &session,
695
plugin::StorageEngine *base,
696
const identifier::Table &old_identifier,
697
const identifier::Table &new_identifier);
699
bool prepare_update(Session *session, TableList *table_list,
700
Item **conds, uint32_t order_num, Order *order);
701
int update_query(Session *session,TableList *tables,List<Item> &fields,
850
int *timestamps, int *timestamps_with_niladic,
851
int64_t table_flags);
853
bool mysql_create_table(Session *session,const char *db, const char *table_name,
854
HA_CREATE_INFO *create_info,
855
drizzled::message::Table *table_proto,
856
AlterInfo *alter_info,
857
bool tmp_table, uint32_t select_field_count,
858
bool is_if_not_exists);
860
bool mysql_create_table_no_lock(Session *session, const char *db,
861
const char *table_name,
862
HA_CREATE_INFO *create_info,
863
drizzled::message::Table *table_proto,
864
AlterInfo *alter_info,
865
bool tmp_table, uint32_t select_field_count,
866
bool is_if_not_exists);
868
bool mysql_recreate_table(Session *session, TableList *table_list);
870
bool mysql_create_like_table(Session* session, TableList* table, TableList* src_table,
871
drizzled::message::Table& create_table_proto,
872
drizzled::plugin::StorageEngine*,
873
bool is_if_not_exists,
876
bool mysql_rename_table(drizzled::plugin::StorageEngine *base, const char *old_db,
877
const char * old_name, const char *new_db,
878
const char * new_name, uint32_t flags);
880
bool mysql_prepare_update(Session *session, TableList *table_list,
881
Item **conds, uint32_t order_num, order_st *order);
882
int mysql_update(Session *session,TableList *tables,List<Item> &fields,
702
883
List<Item> &values,COND *conds,
703
uint32_t order_num, Order *order, ha_rows limit,
884
uint32_t order_num, order_st *order, ha_rows limit,
704
885
enum enum_duplicates handle_duplicates, bool ignore);
705
bool prepare_insert(Session *session, TableList *table_list, Table *table,
886
bool mysql_prepare_insert(Session *session, TableList *table_list, Table *table,
706
887
List<Item> &fields, List_item *values,
707
888
List<Item> &update_fields,
708
889
List<Item> &update_values, enum_duplicates duplic,
709
890
COND **where, bool select_insert,
710
891
bool check_fields, bool abort_on_warning);
711
bool insert_query(Session *session,TableList *table,List<Item> &fields,
892
bool mysql_insert(Session *session,TableList *table,List<Item> &fields,
712
893
List<List_item> &values, List<Item> &update_fields,
713
894
List<Item> &update_values, enum_duplicates flag,
715
896
int check_that_all_fields_are_given_values(Session *session, Table *entry,
716
897
TableList *table_list);
717
int prepare_delete(Session *session, TableList *table_list, Item **conds);
718
bool delete_query(Session *session, TableList *table_list, COND *conds,
898
int mysql_prepare_delete(Session *session, TableList *table_list, Item **conds);
899
bool mysql_delete(Session *session, TableList *table_list, COND *conds,
719
900
SQL_LIST *order, ha_rows rows, uint64_t options,
720
901
bool reset_auto_increment);
721
bool truncate(Session& session, TableList *table_list);
902
bool mysql_truncate(Session& session, TableList *table_list);
722
903
TableShare *get_table_share(Session *session, TableList *table_list, char *key,
723
904
uint32_t key_length, uint32_t db_flags, int *error);
724
905
TableShare *get_cached_table_share(const char *db, const char *table_name);
725
906
bool reopen_name_locked_table(Session* session, TableList* table_list, bool link_in);
907
Table *table_cache_insert_placeholder(Session *session, const char *key,
908
uint32_t key_length);
909
bool lock_table_name_if_not_cached(Session *session, const char *db,
910
const char *table_name, Table **table);
911
bool reopen_table(Table *table);
726
912
bool reopen_tables(Session *session,bool get_locks,bool in_refresh);
913
void close_data_files_and_morph_locks(Session *session, const char *db,
914
const char *table_name);
727
915
void close_handle_and_leave_table_as_lock(Table *table);
728
916
bool wait_for_tables(Session *session);
729
917
bool table_is_used(Table *table, bool wait_for_name_lock);
730
Table *drop_locked_tables(Session *session, const drizzled::identifier::Table &identifier);
731
void abort_locked_tables(Session *session, const drizzled::identifier::Table &identifier);
918
Table *drop_locked_tables(Session *session,const char *db, const char *table_name);
919
void abort_locked_tables(Session *session,const char *db, const char *table_name);
732
920
extern Field *not_found_field;
733
921
extern Field *view_ref_found;