diff --git a/plugins/shard/shard-plugin.c b/plugins/shard/shard-plugin.c index 776d2d1..bb1a50d 100644 --- a/plugins/shard/shard-plugin.c +++ b/plugins/shard/shard-plugin.c @@ -392,7 +392,8 @@ explain_shard_sql(network_mysqld_con *con, sharding_plan_t *plan) rv = sharding_parse_groups(con->client->default_db, st->sql_context, &(con->srv->query_stats), con->key, plan); - con->modified_sql = sharding_modify_sql(st->sql_context, &(con->hav_condi), con->srv->is_groupby_need_reconstruct); + con->modified_sql = sharding_modify_sql(st->sql_context, &(con->hav_condi), + con->srv->is_groupby_need_reconstruct, plan->groups->len); if (con->modified_sql) { sharding_plan_set_modified_sql(plan, con->modified_sql); } @@ -725,7 +726,8 @@ proxy_parse_query(network_mysqld_con *con) static int wrap_check_sql(network_mysqld_con *con, struct sql_context_t *sql_context) { - con->modified_sql = sharding_modify_sql(sql_context, &(con->hav_condi), con->srv->is_groupby_need_reconstruct); + con->modified_sql = sharding_modify_sql(sql_context, &(con->hav_condi), + con->srv->is_groupby_need_reconstruct, con->sharding_plan->groups->len); if (con->modified_sql) { g_message("orig_sql: %s", con->orig_sql->str); g_message("modified: %s", con->modified_sql->str); diff --git a/plugins/shard/sharding-parser.c b/plugins/shard/sharding-parser.c index 251b335..d6d9336 100644 --- a/plugins/shard/sharding-parser.c +++ b/plugins/shard/sharding-parser.c @@ -169,7 +169,7 @@ prepare_for_sql_modify_orderby(sql_select_t *select) } GString * -sharding_modify_sql(sql_context_t *context, having_condition_t *hav_condi, int is_groupby_need_reconstruct) +sharding_modify_sql(sql_context_t *context, having_condition_t *hav_condi, int is_groupby_need_reconstruct, int groups) { if (context->stmt_type == STMT_SELECT && context->sql_statement) { sql_select_t *select = context->sql_statement; @@ -206,7 +206,7 @@ sharding_modify_sql(sql_context_t *context, having_condition_t *hav_condi, int i guint64 orig_limit = 0; /* (LIMIT a, b) ==> (LIMIT 0, a+b) */ - if (select->offset && select->offset->num_value > 0 && select->limit) { + if (groups > 1 && select->offset && select->offset->num_value > 0 && select->limit) { prepare_for_sql_modify_limit(select, &orig_limit, &orig_offset); need_reconstruct = TRUE; } diff --git a/plugins/shard/sharding-parser.h b/plugins/shard/sharding-parser.h index ef39498..6afa93c 100644 --- a/plugins/shard/sharding-parser.h +++ b/plugins/shard/sharding-parser.h @@ -39,7 +39,7 @@ NETWORK_API int sharding_parse_groups(GString *, sql_context_t *, query_stats_t *, guint64, sharding_plan_t *); -NETWORK_API GString *sharding_modify_sql(sql_context_t *, having_condition_t *, int); +NETWORK_API GString *sharding_modify_sql(sql_context_t *, having_condition_t *, int, int); NETWORK_API void sharding_filter_sql(sql_context_t *);