From 55390725600c749c749381d45aa4c42af65d9c6e Mon Sep 17 00:00:00 2001 From: Sergey Glukhov Date: Thu, 23 Sep 2010 10:43:51 +0400 Subject: Bug#54494 crash with explain extended and prepared statements In case of outer join and emtpy WHERE conditon 'always true' condition is created for WHERE clasue. Later in mysql_select() original SELECT_LEX WHERE condition is overwritten with created cond. However SELECT_LEX condition is also used as inital condition in mysql_select()->JOIN::prepare(). On second execution of PS modified SELECT_LEX condition is taken and it leads to crash. The fix is to restore original SELECT_LEX condition (set to NULL if original cond is NULL) in reinit_stmt_before_use(). HAVING clause is fixed too for safety reason (no test case as I did not manage to think out appropriate example). --- sql/sql_prepare.cc | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'sql/sql_prepare.cc') diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index d6eb90a57be..5ba375f9710 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -2362,11 +2362,15 @@ void reinit_stmt_before_use(THD *thd, LEX *lex) sl->where= sl->prep_where->copy_andor_structure(thd); sl->where->cleanup(); } + else + sl->where= NULL; if (sl->prep_having) { sl->having= sl->prep_having->copy_andor_structure(thd); sl->having->cleanup(); } + else + sl->having= NULL; DBUG_ASSERT(sl->join == 0); ORDER *order; /* Fix GROUP list */ -- cgit v1.2.1