diff options
-rw-r--r-- | mysql-test/r/subselect.result | 1 | ||||
-rw-r--r-- | sql/item_func.cc | 7 | ||||
-rw-r--r-- | sql/item_func.h | 1 | ||||
-rw-r--r-- | sql/sql_select.cc | 5 |
4 files changed, 10 insertions, 4 deletions
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 7d2a4343f3f..d4cc9c3192a 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -1637,4 +1637,3 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used 2 UNCACHEABLE SUBQUERY t1 system NULL NULL NULL NULL 1 drop table t1; - diff --git a/sql/item_func.cc b/sql/item_func.cc index 276dbfe1956..ae7a53951b1 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -959,7 +959,6 @@ double Item_func_round::val() return tmp2; } - void Item_func_rand::fix_length_and_dec() { decimals=NOT_FIXED_DEC; @@ -990,6 +989,12 @@ void Item_func_rand::fix_length_and_dec() } } +void Item_func_rand::update_used_tables() +{ + Item_real_func::update_used_tables(); + used_tables_cache|= RAND_TABLE_BIT; +} + double Item_func_rand::val() { diff --git a/sql/item_func.h b/sql/item_func.h index 0071b3c5495..c3fd3a19298 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -512,6 +512,7 @@ public: double val(); const char *func_name() const { return "rand"; } bool const_item() const { return 0; } + void update_used_tables(); void fix_length_and_dec(); }; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index bb9223aef22..462a3a7b8cb 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -585,8 +585,9 @@ JOIN::optimize() } if (const_table_map != found_const_table_map && !(select_options & SELECT_DESCRIBE) && - !((conds->used_tables() & RAND_TABLE_BIT) && - select_lex->master_unit() != &thd->lex->unit))// not upper level SELECT + (!conds || + !(conds->used_tables() & RAND_TABLE_BIT) || + select_lex->master_unit() == &thd->lex->unit)) // upper level SELECT { zero_result_cause= "no matching row in const table"; DBUG_PRINT("error",("Error: %s", zero_result_cause)); |