summaryrefslogtreecommitdiff
path: root/sql/sql_prepare.cc
diff options
context:
space:
mode:
authorunknown <igor@rurik.mysql.com>2006-01-31 21:48:32 -0800
committerunknown <igor@rurik.mysql.com>2006-01-31 21:48:32 -0800
commita400e7feb97945db310a6a31ecb0e882bc01b1a5 (patch)
tree8bf7ac2e42e3520d4fd076d65f554cba3db5c654 /sql/sql_prepare.cc
parent97deac8b8c4651536978c7f5ec7bcb1463ac4868 (diff)
downloadmariadb-git-a400e7feb97945db310a6a31ecb0e882bc01b1a5.tar.gz
FIxed bug #14927.
A query with a group by and having clauses could return a wrong result set if the having condition contained a constant conjunct evaluated to FALSE. It happened because the pushdown condition for table with grouping columns lost its constant conjuncts. Pushdown conditions are always built by the function make_cond_for_table that ignores constant conjuncts. This is apparently not correct when constant false conjuncts are present. mysql-test/r/having.result: Added A test case for bug #14927. mysql-test/t/having.test: Added A test case for bug #14927. sql/sql_lex.cc: Fixed bug #14927. Initialized fields for having conditions in st_select_lex::init_query(). sql/sql_lex.h: Fixed bug #14927. Added a field to restore having condititions for execution in SP and PS. sql/sql_prepare.cc: Fixed bug #14927. Added code to restore havinf conditions for execution in SP and PS. sql/sql_select.cc: Fixed bug #14927. Performed evaluation of constant expressions in having clauses. If the having condition contains a constant conjunct that is always false an empty result set is returned after the optimization phase. In this case the corresponding EXPLAIN command now returns "Impossible HAVING" in the last column.
Diffstat (limited to 'sql/sql_prepare.cc')
-rw-r--r--sql/sql_prepare.cc10
1 files changed, 8 insertions, 2 deletions
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 8a50d0bd50e..ec5fa92f689 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -1665,10 +1665,11 @@ int mysql_stmt_prepare(THD *thd, char *packet, uint packet_length,
for (; sl; sl= sl->next_select_in_list())
{
/*
- Save WHERE clause pointers, because they may be changed
+ Save WHERE, HAVING clause pointers, because they may be changed
during query optimisation.
*/
sl->prep_where= sl->where;
+ sl->prep_having= sl->having;
/*
Switch off a temporary flag that prevents evaluation of
subqueries in statement prepare.
@@ -1694,13 +1695,18 @@ static void reset_stmt_for_execute(Prepared_statement *stmt)
/* remove option which was put by mysql_explain_union() */
sl->options&= ~SELECT_DESCRIBE;
/*
- Copy WHERE clause pointers to avoid damaging they by optimisation
+ Copy WHERE, HAVING clause pointers to avoid damaging they by optimisation
*/
if (sl->prep_where)
{
sl->where= sl->prep_where->copy_andor_structure(thd);
sl->where->cleanup();
}
+ if (sl->prep_having)
+ {
+ sl->having= sl->prep_having->copy_andor_structure(thd);
+ sl->having->cleanup();
+ }
DBUG_ASSERT(sl->join == 0);
ORDER *order;
/* Fix GROUP list */