Comment 9 for bug 612894

Revision history for this message
Oleksandr "Sanja" Byelkin (sanja-byelkin) wrote :

For simple subqueries the problem hidden by the subquery evaluation mechanism which return NULL if theer was no resulte at all, because of thie queries like:

SELECT t1.col_int_nokey, (select max(t2.col_int_key2) from t2 where t1.col_int_nokey) from t1;

works correctly with min/max optimisation in opt_sum.cc. It do not works for outer join which alwats return result.

Also the problem visible without subqueries, lets take impossible where with random function in it (which should return NULL but retuirn 0):
+SELECT MIN( SUBQUERY1_t1 .`col_int_key` )
+FROM t2 SUBQUERY1_t1 JOIN ( t2 SUBQUERY1_t2 JOIN t1 SUBQUERY1_t3 ON SUBQUERY1_t2 .`pk` ) ON SUBQUERY1_t3 .`col_varchar_nokey` = SUBQUERY1_t2 .`col_varchar_key`
+WHERE rand()*0 != 0;
+MIN( SUBQUERY1_t1 .`col_int_key` )
+0
+select rand()*0 != 0;
+rand()*0 != 0
+0

the way to solve the problem I see in the fact that such MAX/MIN has only two possible results:
1)calculated by optimizer constant
2)NULL if the WHERE clause return FALSE