diff options
author | Kentoku SHIBA <kentokushiba@gmail.com> | 2014-03-25 04:26:48 +0900 |
---|---|---|
committer | Kentoku SHIBA <kentokushiba@gmail.com> | 2014-03-25 04:26:48 +0900 |
commit | ad54787d55831bc4921526467e4f1e7d3a52ea19 (patch) | |
tree | ce6c1f6c9cd95e9a6b08919a4bb380ba7326e2e2 /storage | |
parent | b5ebf1e29bd253672e2c3fa8f7ce7e0416fdf48c (diff) | |
download | mariadb-git-ad54787d55831bc4921526467e4f1e7d3a52ea19.tar.gz |
append group by for no order by
Diffstat (limited to 'storage')
-rw-r--r-- | storage/spider/ha_spider.cc | 72 | ||||
-rw-r--r-- | storage/spider/ha_spider.h | 7 | ||||
-rw-r--r-- | storage/spider/spd_db_handlersocket.cc | 13 | ||||
-rw-r--r-- | storage/spider/spd_db_handlersocket.h | 7 | ||||
-rw-r--r-- | storage/spider/spd_db_include.h | 7 | ||||
-rw-r--r-- | storage/spider/spd_db_mysql.cc | 77 | ||||
-rw-r--r-- | storage/spider/spd_db_mysql.h | 5 | ||||
-rw-r--r-- | storage/spider/spd_db_oracle.cc | 75 | ||||
-rw-r--r-- | storage/spider/spd_db_oracle.h | 5 | ||||
-rw-r--r-- | storage/spider/spd_trx.cc | 2 |
10 files changed, 230 insertions, 40 deletions
diff --git a/storage/spider/ha_spider.cc b/storage/spider/ha_spider.cc index 134ae372c8a..db540572462 100644 --- a/storage/spider/ha_spider.cc +++ b/storage/spider/ha_spider.cc @@ -7136,12 +7136,21 @@ int ha_spider::rnd_next_internal( DBUG_RETURN(HA_ERR_OUT_OF_MEM); set_order_pos_sql(SPIDER_SQL_TYPE_SELECT_SQL); - if ( - result_list.direct_order_limit && - (error_num = append_key_order_for_direct_order_limit_with_alias_sql_part( - NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL)) - ) - DBUG_RETURN(error_num); + if (result_list.direct_order_limit) + { + if ((error_num = + append_key_order_for_direct_order_limit_with_alias_sql_part( + NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } +#ifdef HANDLER_HAS_DIRECT_AGGREGATE + else if (result_list.direct_aggregate) + { + if ((error_num = + append_group_by_sql_part(NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } +#endif result_list.desc_flg = FALSE; result_list.sorted = FALSE; result_list.key_info = NULL; @@ -7708,16 +7717,23 @@ int ha_spider::ft_read_internal( result_list.limit_num = result_list.internal_limit >= result_list.split_read ? result_list.split_read : result_list.internal_limit; - if ( - (error_num = spider_db_append_match_where(this)) || - ( - result_list.direct_order_limit && - (error_num = - append_key_order_for_direct_order_limit_with_alias_sql_part(NULL, 0, - SPIDER_SQL_TYPE_SELECT_SQL)) - ) - ) + if ((error_num = spider_db_append_match_where(this))) DBUG_RETURN(error_num); + if (result_list.direct_order_limit) + { + if ((error_num = + append_key_order_for_direct_order_limit_with_alias_sql_part(NULL, 0, + SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } +#ifdef HANDLER_HAS_DIRECT_AGGREGATE + else if (result_list.direct_aggregate) + { + if ((error_num = + append_group_by_sql_part(NULL, 0, SPIDER_SQL_TYPE_SELECT_SQL))) + DBUG_RETURN(error_num); + } +#endif if (sql_kinds & SPIDER_SQL_KIND_SQL) { if ((error_num = append_limit_sql_part( @@ -13113,6 +13129,32 @@ void ha_spider::set_order_to_pos_sql( DBUG_VOID_RETURN; } +#ifdef HANDLER_HAS_DIRECT_AGGREGATE +int ha_spider::append_group_by_sql_part( + const char *alias, + uint alias_length, + ulong sql_type +) { + int error_num; + uint roop_count, dbton_id; + spider_db_handler *dbton_hdl; + DBUG_ENTER("ha_spider::append_group_by_sql_part"); + for (roop_count = 0; roop_count < share->use_sql_dbton_count; roop_count++) + { + dbton_id = share->use_sql_dbton_ids[roop_count]; + dbton_hdl = dbton_handler[dbton_id]; + if ( + dbton_hdl->first_link_idx >= 0 && + (error_num = dbton_hdl->append_group_by_part( + alias, alias_length, sql_type)) + ) { + DBUG_RETURN(error_num); + } + } + DBUG_RETURN(0); +} +#endif + int ha_spider::append_key_order_for_merge_with_alias_sql_part( const char *alias, uint alias_length, diff --git a/storage/spider/ha_spider.h b/storage/spider/ha_spider.h index 4d1f6067bdc..60cab6d3ed0 100644 --- a/storage/spider/ha_spider.h +++ b/storage/spider/ha_spider.h @@ -944,6 +944,13 @@ public: void set_order_to_pos_sql( ulong sql_type ); +#ifdef HANDLER_HAS_DIRECT_AGGREGATE + int append_group_by_sql_part( + const char *alias, + uint alias_length, + ulong sql_type + ); +#endif int append_key_order_for_merge_with_alias_sql_part( const char *alias, uint alias_length, diff --git a/storage/spider/spd_db_handlersocket.cc b/storage/spider/spd_db_handlersocket.cc index 0bc4442e87a..4fb2f8be6ea 100644 --- a/storage/spider/spd_db_handlersocket.cc +++ b/storage/spider/spd_db_handlersocket.cc @@ -4448,6 +4448,19 @@ void spider_handlersocket_handler::set_order_to_pos( DBUG_VOID_RETURN; } +#ifdef HANDLER_HAS_DIRECT_AGGREGATE +int spider_handlersocket_handler::append_group_by_part( + const char *alias, + uint alias_length, + ulong sql_type +) { + DBUG_ENTER("spider_handlersocket_handler::append_group_by_part"); + DBUG_PRINT("info",("spider this=%p", this)); + DBUG_ASSERT(0); + DBUG_RETURN(0); +} +#endif + int spider_handlersocket_handler::append_key_order_for_merge_with_alias_part( const char *alias, uint alias_length, diff --git a/storage/spider/spd_db_handlersocket.h b/storage/spider/spd_db_handlersocket.h index 79ecd87ecb7..c0863348e24 100644 --- a/storage/spider/spd_db_handlersocket.h +++ b/storage/spider/spd_db_handlersocket.h @@ -671,6 +671,13 @@ public: void set_order_to_pos( ulong sql_type ); +#ifdef HANDLER_HAS_DIRECT_AGGREGATE + int append_group_by_part( + const char *alias, + uint alias_length, + ulong sql_type + ); +#endif int append_key_order_for_merge_with_alias_part( const char *alias, uint alias_length, diff --git a/storage/spider/spd_db_include.h b/storage/spider/spd_db_include.h index 218358c631d..6a5b4ac9e0f 100644 --- a/storage/spider/spd_db_include.h +++ b/storage/spider/spd_db_include.h @@ -1154,6 +1154,13 @@ public: virtual void set_order_to_pos( ulong sql_type ) = 0; +#ifdef HANDLER_HAS_DIRECT_AGGREGATE + virtual int append_group_by_part( + const char *alias, + uint alias_length, + ulong sql_type + ) = 0; +#endif virtual int append_key_order_for_merge_with_alias_part( const char *alias, uint alias_length, diff --git a/storage/spider/spd_db_mysql.cc b/storage/spider/spd_db_mysql.cc index 481e87a2421..3cb744e6f85 100644 --- a/storage/spider/spd_db_mysql.cc +++ b/storage/spider/spd_db_mysql.cc @@ -4970,14 +4970,24 @@ int spider_mysql_handler::append_tmp_table_and_sql_for_bka( table_dot_aliases, table_dot_alias_lengths)) || (error_num = append_condition_part( SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN, - SPIDER_SQL_TYPE_SELECT_SQL, FALSE)) || - ( - spider->result_list.direct_order_limit && - (error_num = append_key_order_for_direct_order_limit_with_alias(&sql, - SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN)) - ) + SPIDER_SQL_TYPE_SELECT_SQL, FALSE)) ) DBUG_RETURN(error_num); + if (spider->result_list.direct_order_limit) + { + if ((error_num = append_key_order_for_direct_order_limit_with_alias(&sql, + SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN))) + DBUG_RETURN(error_num); + } +#ifdef HANDLER_HAS_DIRECT_AGGREGATE + else if (spider->result_list.direct_aggregate) + { + if ((error_num = + append_group_by(&sql, SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN))) + DBUG_RETURN(error_num); + } +#endif + DBUG_RETURN(0); } @@ -5184,14 +5194,26 @@ int spider_mysql_handler::append_union_table_and_sql_for_bka( table_dot_aliases, table_dot_alias_lengths)) || (error_num = append_condition_part( SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN, - SPIDER_SQL_TYPE_TMP_SQL, FALSE)) || - ( - spider->result_list.direct_order_limit && - (error_num = append_key_order_for_direct_order_limit_with_alias(&tmp_sql, - SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN)) - ) + SPIDER_SQL_TYPE_TMP_SQL, FALSE)) ) DBUG_RETURN(error_num); + if (spider->result_list.direct_order_limit) + { + if ((error_num = + append_key_order_for_direct_order_limit_with_alias(&tmp_sql, + SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN)) + ) + DBUG_RETURN(error_num); + } +#ifdef HANDLER_HAS_DIRECT_AGGREGATE + else if (spider->result_list.direct_aggregate) + { + if ((error_num = + append_group_by(&tmp_sql, SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN))) + DBUG_RETURN(error_num); + } +#endif + DBUG_RETURN(0); } @@ -7245,6 +7267,37 @@ void spider_mysql_handler::set_order_to_pos( } #ifdef HANDLER_HAS_DIRECT_AGGREGATE +int spider_mysql_handler::append_group_by_part( + const char *alias, + uint alias_length, + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_mysql_handler::append_group_by_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + case SPIDER_SQL_TYPE_TMP_SQL: + str = &sql; + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + str = &update_sql; + break; + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_group_by(str, alias, alias_length); + DBUG_RETURN(error_num); +} + int spider_mysql_handler::append_group_by( spider_string *str, const char *alias, diff --git a/storage/spider/spd_db_mysql.h b/storage/spider/spd_db_mysql.h index 63f9e4228c9..07f8e265471 100644 --- a/storage/spider/spd_db_mysql.h +++ b/storage/spider/spd_db_mysql.h @@ -877,6 +877,11 @@ public: ulong sql_type ); #ifdef HANDLER_HAS_DIRECT_AGGREGATE + int append_group_by_part( + const char *alias, + uint alias_length, + ulong sql_type + ); int append_group_by( spider_string *str, const char *alias, diff --git a/storage/spider/spd_db_oracle.cc b/storage/spider/spd_db_oracle.cc index 9bb4b3db874..7a4ff1decaa 100644 --- a/storage/spider/spd_db_oracle.cc +++ b/storage/spider/spd_db_oracle.cc @@ -5047,14 +5047,24 @@ int spider_oracle_handler::append_tmp_table_and_sql_for_bka( table_dot_aliases, table_dot_alias_lengths)) || (error_num = append_condition_part( SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN, - SPIDER_SQL_TYPE_SELECT_SQL, FALSE)) || - ( - spider->result_list.direct_order_limit && - (error_num = append_key_order_for_direct_order_limit_with_alias(&sql, - SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN)) - ) + SPIDER_SQL_TYPE_SELECT_SQL, FALSE)) ) DBUG_RETURN(error_num); + if (spider->result_list.direct_order_limit) + { + if ((error_num = append_key_order_for_direct_order_limit_with_alias(&sql, + SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN))) + DBUG_RETURN(error_num); + } +#ifdef HANDLER_HAS_DIRECT_AGGREGATE + else if (spider->result_list.direct_aggregate) + { + if ((error_num = + append_group_by(&sql, SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN))) + DBUG_RETURN(error_num); + } +#endif + DBUG_RETURN(0); } @@ -5257,14 +5267,24 @@ int spider_oracle_handler::append_union_table_and_sql_for_bka( table_dot_aliases, table_dot_alias_lengths)) || (error_num = append_condition_part( SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN, - SPIDER_SQL_TYPE_TMP_SQL, FALSE)) || - ( - spider->result_list.direct_order_limit && - (error_num = append_key_order_for_direct_order_limit_with_alias(&tmp_sql, - SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN)) - ) + SPIDER_SQL_TYPE_TMP_SQL, FALSE)) ) DBUG_RETURN(error_num); + if (spider->result_list.direct_order_limit) + { + if ((error_num = append_key_order_for_direct_order_limit_with_alias( + &tmp_sql, SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN))) + DBUG_RETURN(error_num); + } +#ifdef HANDLER_HAS_DIRECT_AGGREGATE + else if (spider->result_list.direct_aggregate) + { + if ((error_num = + append_group_by(&tmp_sql, SPIDER_SQL_B_DOT_STR, SPIDER_SQL_B_DOT_LEN))) + DBUG_RETURN(error_num); + } +#endif + DBUG_RETURN(0); } @@ -7272,6 +7292,37 @@ void spider_oracle_handler::set_order_to_pos( } #ifdef HANDLER_HAS_DIRECT_AGGREGATE +int spider_oracle_handler::append_group_by_part( + const char *alias, + uint alias_length, + ulong sql_type +) { + int error_num; + spider_string *str; + DBUG_ENTER("spider_oracle_handler::append_group_by_part"); + DBUG_PRINT("info",("spider this=%p", this)); + switch (sql_type) + { + case SPIDER_SQL_TYPE_SELECT_SQL: + case SPIDER_SQL_TYPE_TMP_SQL: + str = &sql; + break; + case SPIDER_SQL_TYPE_INSERT_SQL: + case SPIDER_SQL_TYPE_UPDATE_SQL: + case SPIDER_SQL_TYPE_DELETE_SQL: + case SPIDER_SQL_TYPE_BULK_UPDATE_SQL: + str = &update_sql; + break; + case SPIDER_SQL_TYPE_HANDLER: + str = &ha_sql; + break; + default: + DBUG_RETURN(0); + } + error_num = append_group_by(str, alias, alias_length); + DBUG_RETURN(error_num); +} + int spider_oracle_handler::append_group_by( spider_string *str, const char *alias, diff --git a/storage/spider/spd_db_oracle.h b/storage/spider/spd_db_oracle.h index a4dfe4761ca..700ee10935c 100644 --- a/storage/spider/spd_db_oracle.h +++ b/storage/spider/spd_db_oracle.h @@ -960,6 +960,11 @@ public: ulong sql_type ); #ifdef HANDLER_HAS_DIRECT_AGGREGATE + int append_group_by_part( + const char *alias, + uint alias_length, + ulong sql_type + ); int append_group_by( spider_string *str, const char *alias, diff --git a/storage/spider/spd_trx.cc b/storage/spider/spd_trx.cc index 0ae1c69c926..129d9fd1d63 100644 --- a/storage/spider/spd_trx.cc +++ b/storage/spider/spd_trx.cc @@ -1638,7 +1638,7 @@ int spider_internal_start_trx( if ( !trx->trx_xa && trx->internal_xa && - !trx->trx_consistent_snapshot || trx->internal_xa_snapshot == 3 + (!trx->trx_consistent_snapshot || trx->internal_xa_snapshot == 3) ) { trx->trx_xa = TRUE; trx->xid.formatID = 1; |