From 7f940251be6be308603625c0a26cc81889d9bc34 Mon Sep 17 00:00:00 2001 From: lazio579 Date: Fri, 18 Jan 2019 18:29:12 +0800 Subject: [PATCH] Fix some memory leaks and shard explain problems for partition mode --- plugins/shard/shard-plugin.c | 7 ++++++- plugins/shard/sharding-parser.c | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/shard/shard-plugin.c b/plugins/shard/shard-plugin.c index d78d80c..e043132 100644 --- a/plugins/shard/shard-plugin.c +++ b/plugins/shard/shard-plugin.c @@ -377,7 +377,7 @@ mysqld_con_send_sequence(network_mysqld_con *con) } static const GString * -sharding_get_sql(network_mysqld_con *con, const GString *group) +sharding_get_sql(network_mysqld_con *con, GString *group) { if (!con->srv->is_partition_mode || con->sharding_plan->is_sql_rewrite_completely) { return sharding_plan_get_sql(con->sharding_plan, group); @@ -396,6 +396,7 @@ sharding_get_sql(network_mysqld_con *con, const GString *group) GString *new_sql = sharding_modify_sql(context, &(con->hav_condi), con->srv->is_groupby_need_reconstruct, con->srv->is_partition_mode, con->sharding_plan->groups->len); if (new_sql) { + sharding_plan_add_group_sql(con->sharding_plan, group, new_sql); g_message("%s: new sql:%s for con:%p", G_STRLOC, new_sql->str, con); } else { new_sql = con->orig_sql; @@ -442,6 +443,10 @@ explain_shard_sql(network_mysqld_con *con, sharding_plan_t *plan) static void proxy_generate_shard_explain_packet(network_mysqld_con *con) { + if (con->sharding_plan) { + sharding_plan_free(con->sharding_plan); + g_message(G_STRLOC ": shard plan is not empty:%s", con->orig_sql->str); + } sharding_plan_t *plan = sharding_plan_new(con->orig_sql); plan->is_partition_mode = con->srv->is_partition_mode; if (explain_shard_sql(con, plan) != 0) { diff --git a/plugins/shard/sharding-parser.c b/plugins/shard/sharding-parser.c index adef080..e13f14a 100644 --- a/plugins/shard/sharding-parser.c +++ b/plugins/shard/sharding-parser.c @@ -216,6 +216,7 @@ modify_select(sql_context_t *context, having_condition_t *hav_condi, int is_grou if (select->flags & SF_REWRITE_ORDERBY) { prepare_for_sql_modify_orderby(select); + select->flags = select->flags ^ SF_REWRITE_ORDERBY; need_reconstruct = TRUE; } @@ -1585,7 +1586,6 @@ routing_delete(sql_context_t *context, sql_delete_t *delete, if (plan->is_partition_mode) { context->sql_needs_reconstruct = 1; } - table->groups = g_ptr_array_new(); plan->table_type = SHARDED_TABLE; if (!delete->where_clause) { shard_conf_get_table_groups(groups, db, table->table_name);