Commit 0ad00c66 authored by Monty's avatar Monty

Fix for MySQL bug #77448 Inconsistent handling of RAND() in WHERE and HAVING

Problem was that for queries of type:

select rand() r, rand()  p, rand() = rand() from a having r = p

The optimizer thought that r = p was same as rand() = rand() and this would always be true.

The problem was that when testing if two expressions are equal, we didn't take into account no determinstic functions.

The fix is to not compare non deterministic functions as equal.
parent 872a953b
......@@ -480,7 +480,11 @@ bool Item_func::eq(const Item *item, bool binary_cmp) const
/* Assume we don't have rtti */
if (this == item)
return 1;
if (item->type() != FUNC_ITEM)
/*
Ensure that we are comparing two functions and that the function
is deterministic.
*/
if (item->type() != FUNC_ITEM || (used_tables() & RAND_TABLE_BIT))
return 0;
Item_func *item_func=(Item_func*) item;
Item_func::Functype func_type;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment