diff options
Diffstat (limited to 'storage/spider/spd_db_include.h')
-rw-r--r-- | storage/spider/spd_db_include.h | 344 |
1 files changed, 316 insertions, 28 deletions
diff --git a/storage/spider/spd_db_include.h b/storage/spider/spd_db_include.h index 56bc2ccad42..2913f911587 100644 --- a/storage/spider/spd_db_include.h +++ b/storage/spider/spd_db_include.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2008-2014 Kentoku Shiba +/* Copyright (C) 2008-2017 Kentoku Shiba This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -11,15 +11,29 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "hs_compat.h" #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) #include "hstcpcli.hpp" #endif +#define SPIDER_DBTON_SIZE 15 + #define SPIDER_DB_WRAPPER_MYSQL "mysql" +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100204 +#define PLUGIN_VAR_CAN_MEMALLOC +/* +#define ITEM_FUNC_CASE_PARAMS_ARE_PUBLIC +#define HASH_UPDATE_WITH_HASH_VALUE +*/ +#else +#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS +#define HANDLER_HAS_DIRECT_UPDATE_ROWS_WITH_HS +#endif +#endif + #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 #define SPIDER_HAS_DISCOVER_TABLE_STRUCTURE #define SPIDER_HAS_APPEND_FOR_SINGLE_QUOTE @@ -31,7 +45,6 @@ #endif #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100007 -#define SPIDER_HAS_DISCOVER_TABLE_STRUCTURE_COMMENT #define SPIDER_ITEM_HAS_CMP_TYPE #endif @@ -47,6 +60,14 @@ #endif #endif +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100108 +#define SPIDER_HAS_GROUP_BY_HANDLER +#endif + +#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100200 +#define SPIDER_ORDER_HAS_ENUM_ORDER +#endif + #if defined(MARIADB_BASE_VERSION) #define SPIDER_ITEM_GEOFUNC_NAME_HAS_MBR #define SPIDER_HANDLER_AUTO_REPAIR_HAS_ERROR @@ -182,32 +203,32 @@ typedef st_spider_result SPIDER_RESULT; #define SPIDER_SQL_LCL_NAME_QUOTE_STR "`" #define SPIDER_SQL_LCL_NAME_QUOTE_LEN (sizeof(SPIDER_SQL_LCL_NAME_QUOTE_STR) - 1) -#define SPIDER_CONN_KIND_MYSQL (1U << 0) +#define SPIDER_CONN_KIND_MYSQL (1 << 0) #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) -#define SPIDER_CONN_KIND_HS_READ (1U << 2) -#define SPIDER_CONN_KIND_HS_WRITE (1U << 3) +#define SPIDER_CONN_KIND_HS_READ (1 << 2) +#define SPIDER_CONN_KIND_HS_WRITE (1 << 3) #endif -#define SPIDER_SQL_KIND_SQL (1U << 0) -#define SPIDER_SQL_KIND_HANDLER (1U << 1) +#define SPIDER_SQL_KIND_SQL (1 << 0) +#define SPIDER_SQL_KIND_HANDLER (1 << 1) #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) -#define SPIDER_SQL_KIND_HS (1U << 2) +#define SPIDER_SQL_KIND_HS (1 << 2) #endif -#define SPIDER_SQL_TYPE_SELECT_SQL (1U << 0) -#define SPIDER_SQL_TYPE_INSERT_SQL (1U << 1) -#define SPIDER_SQL_TYPE_UPDATE_SQL (1U << 2) -#define SPIDER_SQL_TYPE_DELETE_SQL (1U << 3) -#define SPIDER_SQL_TYPE_BULK_UPDATE_SQL (1U << 4) -#define SPIDER_SQL_TYPE_TMP_SQL (1U << 5) -#define SPIDER_SQL_TYPE_DROP_TMP_TABLE_SQL (1U << 6) -#define SPIDER_SQL_TYPE_OTHER_SQL (1U << 7) -#define SPIDER_SQL_TYPE_HANDLER (1U << 8) -#define SPIDER_SQL_TYPE_SELECT_HS (1U << 9) -#define SPIDER_SQL_TYPE_INSERT_HS (1U << 10) -#define SPIDER_SQL_TYPE_UPDATE_HS (1U << 11) -#define SPIDER_SQL_TYPE_DELETE_HS (1U << 12) -#define SPIDER_SQL_TYPE_OTHER_HS (1U << 13) +#define SPIDER_SQL_TYPE_SELECT_SQL (1 << 0) +#define SPIDER_SQL_TYPE_INSERT_SQL (1 << 1) +#define SPIDER_SQL_TYPE_UPDATE_SQL (1 << 2) +#define SPIDER_SQL_TYPE_DELETE_SQL (1 << 3) +#define SPIDER_SQL_TYPE_BULK_UPDATE_SQL (1 << 4) +#define SPIDER_SQL_TYPE_TMP_SQL (1 << 5) +#define SPIDER_SQL_TYPE_DROP_TMP_TABLE_SQL (1 << 6) +#define SPIDER_SQL_TYPE_OTHER_SQL (1 << 7) +#define SPIDER_SQL_TYPE_HANDLER (1 << 8) +#define SPIDER_SQL_TYPE_SELECT_HS (1 << 9) +#define SPIDER_SQL_TYPE_INSERT_HS (1 << 10) +#define SPIDER_SQL_TYPE_UPDATE_HS (1 << 11) +#define SPIDER_SQL_TYPE_DELETE_HS (1 << 12) +#define SPIDER_SQL_TYPE_OTHER_HS (1 << 13) enum spider_bulk_upd_start { SPD_BU_NOT_START, @@ -531,6 +552,169 @@ public: bool is_ascii() const; }; +typedef struct spider_table_link_idx_holder SPIDER_TABLE_LINK_IDX_HOLDER; +typedef struct spider_table_holder SPIDER_TABLE_HOLDER; + +typedef struct spider_link_idx_holder +{ + spider_table_link_idx_holder *table_link_idx_holder; + int link_idx; + int link_status; + spider_link_idx_holder *next_table; + spider_link_idx_holder *next; +} SPIDER_LINK_IDX_HOLDER; + +typedef struct spider_link_idx_chain +{ + SPIDER_CONN *conn; + spider_link_idx_holder *link_idx_holder; + spider_link_idx_holder *current_link_idx_holder; + int link_status; + spider_link_idx_chain *next; +} SPIDER_LINK_IDX_CHAIN; + +typedef struct spider_table_link_idx_holder +{ + spider_table_holder *table_holder; + spider_link_idx_holder *first_link_idx_holder; + spider_link_idx_holder *last_link_idx_holder; + spider_link_idx_holder *current_link_idx_holder; + uint link_idx_holder_count; +} SPIDER_TABLE_LINK_IDX_HOLDER; + +typedef struct spider_conn_holder +{ + SPIDER_CONN *conn; + spider_table_link_idx_holder *table_link_idx_holder; + uint link_idx_holder_count_max; + bool checked_for_same_conn; + long access_balance; + spider_conn_holder *prev; + spider_conn_holder *next; +} SPIDER_CONN_HOLDER; + +typedef struct spider_table_holder +{ + TABLE *table; + ha_spider *spider; + spider_string *alias; +} SPIDER_TABLE_HOLDER; + +typedef struct spider_field_holder +{ + Field *field; + ha_spider *spider; + spider_string *alias; + spider_field_holder *next; +} SPIDER_FIELD_HOLDER; + +typedef struct spider_field_chain +{ + spider_field_holder *field_holder; + spider_field_chain *next; +} SPIDER_FIELD_CHAIN; + +class spider_fields +{ + uint dbton_count; + uint current_dbton_num; + uint dbton_ids[SPIDER_DBTON_SIZE]; + uint table_count; + uint current_table_num; + SPIDER_TABLE_HOLDER *table_holder; + SPIDER_LINK_IDX_CHAIN *first_link_idx_chain; + SPIDER_LINK_IDX_CHAIN *last_link_idx_chain; + SPIDER_LINK_IDX_CHAIN *current_link_idx_chain; + SPIDER_LINK_IDX_CHAIN *first_ok_link_idx_chain; + SPIDER_CONN_HOLDER *first_conn_holder; + SPIDER_CONN_HOLDER *last_conn_holder; + SPIDER_CONN_HOLDER *current_conn_holder; + SPIDER_FIELD_HOLDER *first_field_holder; + SPIDER_FIELD_HOLDER *last_field_holder; + SPIDER_FIELD_HOLDER *current_field_holder; + SPIDER_FIELD_CHAIN *first_field_chain; + SPIDER_FIELD_CHAIN *last_field_chain; + SPIDER_FIELD_CHAIN *current_field_chain; + Field **first_field_ptr; + Field **current_field_ptr; +public: + spider_fields(); + virtual ~spider_fields(); + void add_dbton_id( + uint dbton_id_arg + ); + void set_pos_to_first_dbton_id(); + uint get_next_dbton_id(); + int make_link_idx_chain( + int link_status + ); + SPIDER_LINK_IDX_CHAIN *create_link_idx_chain(); + void set_pos_to_first_link_idx_chain(); + SPIDER_LINK_IDX_CHAIN *get_next_link_idx_chain(); + SPIDER_LINK_IDX_HOLDER *get_dup_link_idx_holder( + SPIDER_TABLE_LINK_IDX_HOLDER *table_link_idx_holder, + SPIDER_LINK_IDX_HOLDER *current + ); + bool check_link_ok_chain(); + bool is_first_link_ok_chain( + SPIDER_LINK_IDX_CHAIN *link_idx_chain_arg + ); + int get_ok_link_idx(); + void set_first_link_idx(); + int add_link_idx( + SPIDER_CONN_HOLDER *conn_holder_arg, + ha_spider *spider_arg, + int link_idx + ); + SPIDER_LINK_IDX_HOLDER *create_link_idx_holder(); + void set_pos_to_first_table_on_link_idx_chain( + SPIDER_LINK_IDX_CHAIN *link_idx_chain_arg + ); + SPIDER_LINK_IDX_HOLDER *get_next_table_on_link_idx_chain( + SPIDER_LINK_IDX_CHAIN *link_idx_chain_arg + ); + SPIDER_CONN_HOLDER *add_conn( + SPIDER_CONN *conn_arg, + long access_balance + ); + SPIDER_CONN_HOLDER *create_conn_holder(); + void set_pos_to_first_conn_holder(); + SPIDER_CONN_HOLDER *get_next_conn_holder(); + bool has_conn_holder(); + void clear_conn_holder_from_conn(); + bool check_conn_same_conn( + SPIDER_CONN *conn_arg + ); + bool remove_conn_if_not_checked(); + void check_support_dbton( + uchar *dbton_bitmap + ); + void choose_a_conn(); + void free_conn_holder( + SPIDER_CONN_HOLDER *conn_holder_arg + ); + SPIDER_TABLE_HOLDER *add_table( + ha_spider *spider_arg + ); + int create_table_holder( + uint table_count_arg + ); + void set_pos_to_first_table_holder(); + SPIDER_TABLE_HOLDER *get_next_table_holder(); + int add_field(Field *field_arg); + SPIDER_FIELD_HOLDER *create_field_holder(); + void set_pos_to_first_field_holder(); + SPIDER_FIELD_HOLDER *get_next_field_holder(); + SPIDER_FIELD_CHAIN *create_field_chain(); + void set_pos_to_first_field_chain(); + SPIDER_FIELD_CHAIN *get_next_field_chain(); + void set_field_ptr(Field **field_arg); + Field **get_next_field_ptr(); + int ping_table_mon_from_table( + SPIDER_LINK_IDX_CHAIN *link_idx_chain + ); +}; + #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) #define SPIDER_HS_UINT32_INFO dena::uint32_info #define SPIDER_HS_STRING_REF dena::string_ref @@ -681,7 +865,9 @@ public: ha_spider *spider, spider_string *str, const char *alias, - uint alias_length + uint alias_length, + bool use_fields, + spider_fields *fields ) = 0; #ifdef HANDLER_HAS_DIRECT_AGGREGATE virtual int open_item_sum_func( @@ -689,13 +875,32 @@ public: ha_spider *spider, spider_string *str, const char *alias, - uint alias_length + uint alias_length, + bool use_fields, + spider_fields *fields ) = 0; #endif virtual int append_escaped_util( spider_string *to, String *from ) = 0; +#ifdef SPIDER_HAS_GROUP_BY_HANDLER + virtual int append_from_and_tables( + spider_fields *fields, + spider_string *str + ) = 0; + virtual int reappend_tables( + spider_fields *fields, + SPIDER_LINK_IDX_CHAIN *link_idx_chain, + spider_string *str + ) = 0; + virtual int append_where( + spider_string *str + ) = 0; + virtual int append_having( + spider_string *str + ) = 0; +#endif }; class spider_db_row @@ -745,9 +950,12 @@ public: class spider_db_result { +protected: + SPIDER_DB_CONN *db_conn; public: uint dbton_id; - spider_db_result(uint in_dbton_id) : dbton_id(in_dbton_id) {} + spider_db_result(SPIDER_DB_CONN *in_db_conn, uint in_dbton_id) : + db_conn(in_db_conn), dbton_id(in_dbton_id) {} virtual ~spider_db_result() {} virtual bool has_result() = 0; virtual void free_result() = 0; @@ -922,6 +1130,17 @@ public: Time_zone *time_zone, int *need_mon ) = 0; + virtual int show_master_status( + SPIDER_TRX *trx, + SPIDER_SHARE *share, + int all_link_idx, + int *need_mon, + TABLE *table, + spider_string *str, + int mode, + SPIDER_DB_RESULT **res1, + SPIDER_DB_RESULT **res2 + ) = 0; #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) virtual int append_sql( char *sql, @@ -1041,10 +1260,18 @@ public: ha_spider *spider; spider_db_share *db_share; int first_link_idx; +#ifdef SPIDER_HAS_GROUP_BY_HANDLER + SPIDER_LINK_IDX_CHAIN *link_idx_chain; +#endif spider_db_handler(ha_spider *spider, spider_db_share *db_share) : spider(spider), db_share(db_share), first_link_idx(-1) {} virtual ~spider_db_handler() {} virtual int init() = 0; + virtual int append_index_hint( + spider_string *str, + int link_idx, + ulong sql_type + ) = 0; virtual int append_table_name_with_adjusting( spider_string *str, int link_idx, @@ -1104,6 +1331,10 @@ public: virtual int append_select_part( ulong sql_type ) = 0; + virtual int append_select( + spider_string *str, + ulong sql_type + ) = 0; virtual int append_table_select_part( ulong sql_type ) = 0; @@ -1280,7 +1511,7 @@ public: int link_idx ) = 0; virtual bool is_sole_projection_field( - uint16 field_index + uint16 field_index ) = 0; virtual bool is_bulk_insert_exec_period( bool bulk_end @@ -1342,6 +1573,13 @@ public: virtual bool need_lock_before_set_sql_for_exec( ulong sql_type ) = 0; +#ifdef SPIDER_HAS_GROUP_BY_HANDLER + virtual int set_sql_for_exec( + ulong sql_type, + int link_idx, + SPIDER_LINK_IDX_CHAIN *link_idx_chain + ) = 0; +#endif virtual int set_sql_for_exec( ulong sql_type, int link_idx @@ -1452,6 +1690,54 @@ public: int link_idx, ulong sql_type ) = 0; +#ifdef SPIDER_HAS_GROUP_BY_HANDLER + virtual int append_from_and_tables_part( + spider_fields *fields, + ulong sql_type + ) = 0; + virtual int reappend_tables_part( + spider_fields *fields, + ulong sql_type + ) = 0; + virtual int append_where_part( + ulong sql_type + ) = 0; + virtual int append_having_part( + ulong sql_type + ) = 0; + virtual int append_item_type_part( + Item *item, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields, + ulong sql_type + ) = 0; + virtual int append_list_item_select_part( + List<Item> *select, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields, + ulong sql_type + ) = 0; + virtual int append_group_by_part( + ORDER *order, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields, + ulong sql_type + ) = 0; + virtual int append_order_by_part( + ORDER *order, + const char *alias, + uint alias_length, + bool use_fields, + spider_fields *fields, + ulong sql_type + ) = 0; +#endif }; class spider_db_copy_table @@ -1539,9 +1825,9 @@ typedef struct st_spider_dbton spider_db_copy_table *(*create_db_copy_table)( spider_db_share *db_share); SPIDER_DB_CONN *(*create_db_conn)(SPIDER_CONN *conn); + bool (*support_direct_join)(); spider_db_util *db_util; } SPIDER_DBTON; -#define SPIDER_DBTON_SIZE 15 typedef struct st_spider_position { @@ -1661,6 +1947,8 @@ typedef struct st_spider_result_list spider_bulk_upd_start bulk_update_start; bool check_direct_order_limit; bool direct_order_limit; + /* the limit_offeset, without where condition */ + bool direct_limit_offset; bool direct_distinct; #ifdef HANDLER_HAS_DIRECT_AGGREGATE bool direct_aggregate; |