Skip to content

Commit c59b131

Browse files
author
Sergey Glukhov
committed
Bug#13358379 EXPLAIN SELECT ... PROCEDURE ANALYZE CRASHES THE SERVER
Problem: code which is realted to PROCEDURE resultpreparation is missing in JOIN::explain(). Fix: code which is related to PROCEDURE result preparation is moved into JOIN::prepare_result.
1 parent 345ff38 commit c59b131

File tree

4 files changed

+34
-18
lines changed

4 files changed

+34
-18
lines changed

mysql-test/r/func_analyse.result

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,11 @@ test.t1 analyze status OK
163163
SELECT f1,f2 FROM t1 A WHERE f1 BETWEEN 0 AND 1;
164164
f1 f2
165165
drop table t1;
166+
#
167+
# Bug #13358379 EXPLAIN SELECT ... PROCEDURE ANALYZE CRASHES THE SERVER
168+
#
169+
CREATE TABLE t1 (i INT);
170+
EXPLAIN SELECT * FROM t1 PROCEDURE ANALYSE();
171+
id select_type table type possible_keys key key_len ref rows Extra
172+
1 SIMPLE t1 ALL NULL NULL NULL NULL 1
173+
DROP TABLE t1;

mysql-test/t/func_analyse.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,11 @@ ANALYZE TABLE t1;
180180
SELECT f1,f2 FROM t1 A WHERE f1 BETWEEN 0 AND 1;
181181

182182
drop table t1;
183+
184+
--echo #
185+
--echo # Bug #13358379 EXPLAIN SELECT ... PROCEDURE ANALYZE CRASHES THE SERVER
186+
--echo #
187+
188+
CREATE TABLE t1 (i INT);
189+
EXPLAIN SELECT * FROM t1 PROCEDURE ANALYSE();
190+
DROP TABLE t1;

sql/sql_select.cc

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,7 +2921,7 @@ disable_sorted_access(JOIN_TAB* join_tab)
29212921
FALSE Ok
29222922
*/
29232923

2924-
bool JOIN::prepare_result()
2924+
bool JOIN::prepare_result(List<Item> **columns_list)
29252925
{
29262926
DBUG_ENTER("JOIN::prepare_result");
29272927

@@ -2936,6 +2936,19 @@ bool JOIN::prepare_result()
29362936
get_schema_tables_result(this, PROCESSED_BY_JOIN_EXEC))
29372937
goto err;
29382938

2939+
if (procedure)
2940+
{
2941+
procedure_fields_list= fields_list;
2942+
if (procedure->change_columns(procedure_fields_list) ||
2943+
result->prepare(procedure_fields_list, unit))
2944+
{
2945+
thd->set_examined_row_count(0);
2946+
thd->limit_found_rows= 0;
2947+
goto err;
2948+
}
2949+
*columns_list= &procedure_fields_list;
2950+
}
2951+
29392952
DBUG_RETURN(FALSE);
29402953

29412954
err:
@@ -2956,12 +2969,12 @@ JOIN::explain()
29562969
Opt_trace_object trace_exec(trace, "join_explain");
29572970
trace_exec.add_select_number(select_lex->select_number);
29582971
Opt_trace_array trace_steps(trace, "steps");
2959-
2972+
List<Item> *columns_list= &fields_list;
29602973
DBUG_ENTER("JOIN::explain");
29612974

29622975
THD_STAGE_INFO(thd, stage_explaining);
29632976

2964-
if (prepare_result())
2977+
if (prepare_result(&columns_list))
29652978
DBUG_VOID_RETURN;
29662979

29672980
if (!tables_list && (tables || !select_lex->with_sum_func))
@@ -3048,22 +3061,9 @@ JOIN::exec()
30483061

30493062
THD_STAGE_INFO(thd, stage_executing);
30503063

3051-
if (prepare_result())
3064+
if (prepare_result(&columns_list))
30523065
DBUG_VOID_RETURN;
30533066

3054-
if (procedure)
3055-
{
3056-
procedure_fields_list= fields_list;
3057-
if (procedure->change_columns(procedure_fields_list) ||
3058-
result->prepare(procedure_fields_list, unit))
3059-
{
3060-
thd->set_examined_row_count(0);
3061-
thd->limit_found_rows= 0;
3062-
DBUG_VOID_RETURN;
3063-
}
3064-
columns_list= &procedure_fields_list;
3065-
}
3066-
30673067
if (!tables_list && (tables || !select_lex->with_sum_func))
30683068
{ // Only test of functions
30693069
if (result->send_result_set_metadata(*columns_list,

sql/sql_select.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2066,7 +2066,7 @@ class JOIN :public Sql_alloc
20662066
int optimize();
20672067
void reset();
20682068
void exec();
2069-
bool prepare_result();
2069+
bool prepare_result(List<Item> **columns_list);
20702070
void explain();
20712071
bool destroy();
20722072
void restore_tmp();

0 commit comments

Comments
 (0)