Skip to content

Commit 12d6f89

Browse files
committed
MDEV-6393: ANALYZE SELECT crashes ... Don't try printing EXPLAIN if we had an error.
1 parent b7d10e5 commit 12d6f89

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

mysql-test/r/analyze_stmt.result

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,21 @@ select * from t1;
197197
a b
198198
6 6
199199
drop table t0, t1;
200+
#
201+
# MDEV-6393: ANALYZE SELECT crashes in Explain_query::print_explain with a non-existing column
202+
#
203+
create table t1 (i int);
204+
insert into t1 values (1),(2);
205+
analyze select a from t1;
206+
ERROR 42S22: Unknown column 'a' in 'field list'
207+
analyze delete from t1 where a=2;
208+
ERROR 42S22: Unknown column 'a' in 'where clause'
209+
analyze update t1 set a=2;
210+
ERROR 42S22: Unknown column 'a' in 'field list'
211+
create table t2 like t1;
212+
insert into t2 select * from t1;
213+
analyze update t2,t1 set t2.i=5 where t2.a=t1.a;
214+
ERROR 42S22: Unknown column 't2.a' in 'where clause'
215+
analyze delete t1 from t2,t1 where t2.a=t1.a;
216+
ERROR 42S22: Unknown column 't2.a' in 'where clause'
217+
drop table t1,t2;

mysql-test/t/analyze_stmt.test

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,28 @@ select * from t1;
146146

147147
drop table t0, t1;
148148

149+
--echo #
150+
--echo # MDEV-6393: ANALYZE SELECT crashes in Explain_query::print_explain with a non-existing column
151+
--echo #
152+
create table t1 (i int);
153+
insert into t1 values (1),(2);
154+
--error ER_BAD_FIELD_ERROR
155+
analyze select a from t1;
156+
157+
--error ER_BAD_FIELD_ERROR
158+
analyze delete from t1 where a=2;
159+
160+
--error ER_BAD_FIELD_ERROR
161+
analyze update t1 set a=2;
162+
163+
create table t2 like t1;
164+
insert into t2 select * from t1;
165+
166+
--error ER_BAD_FIELD_ERROR
167+
analyze update t2,t1 set t2.i=5 where t2.a=t1.a;
168+
169+
--error ER_BAD_FIELD_ERROR
170+
analyze delete t1 from t2,t1 where t2.a=t1.a;
171+
172+
drop table t1,t2;
173+

sql/sql_parse.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5282,7 +5282,8 @@ static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables)
52825282
return 1;
52835283
delete thd->protocol;
52845284
thd->protocol= save_protocol;
5285-
thd->lex->explain->send_explain(thd);
5285+
if (!res)
5286+
thd->lex->explain->send_explain(thd);
52865287

52875288
if (result != lex->result)
52885289
delete result;

0 commit comments

Comments
 (0)