From c80f766ea21578b7399bda9a7d7843f737408019 Mon Sep 17 00:00:00 2001 From: "bell@sanja.is.com.ua" <> Date: Sun, 26 Jan 2003 21:13:37 +0200 Subject: [PATCH] removed switching off static table optimization for subselects (SCRUM , pre-commit to be able merge with temporary table fix) --- sql/item.cc | 2 +- sql/item.h | 14 ++++++++++---- sql/item_cmpfunc.cc | 8 ++++++++ sql/sql_select.cc | 17 +++++------------ 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/sql/item.cc b/sql/item.cc index c6cce9a5b48..fa75819605f 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -261,7 +261,7 @@ table_map Item_field::used_tables() const { if (field->table->const_table) return 0; // const item - return field->table->map; + return (depended_from? RAND_TABLE_BIT : field->table->map); } diff --git a/sql/item.h b/sql/item.h index 3decdc388eb..eeda219200b 100644 --- a/sql/item.h +++ b/sql/item.h @@ -666,7 +666,12 @@ public: class Item_cache: public Item { + table_map used_table_map; public: + Item_cache(): used_table_map(0) {fixed= 1; null_value= 1;} + + void set_used_tables(table_map map) { used_table_map= map; } + virtual bool allocate(uint i) { return 0; }; virtual bool setup(Item *) { return 0; }; virtual void store(Item *)= 0; @@ -677,13 +682,14 @@ public: } enum Type type() const { return CACHE_ITEM; } static Item_cache* get_cache(Item_result type); + table_map used_tables() const { return used_table_map; } }; class Item_cache_int: public Item_cache { longlong value; public: - Item_cache_int() { fixed= 1; null_value= 1; } + Item_cache_int(): Item_cache() {} void store(Item *item) { @@ -700,7 +706,7 @@ class Item_cache_real: public Item_cache { double value; public: - Item_cache_real() { fixed= 1; null_value= 1; } + Item_cache_real(): Item_cache() {} void store(Item *item) { @@ -722,7 +728,7 @@ class Item_cache_str: public Item_cache char buffer[80]; String *value; public: - Item_cache_str() { fixed= 1; null_value= 1; } + Item_cache_str(): Item_cache() { } void store(Item *item); double val(); @@ -737,7 +743,7 @@ class Item_cache_row: public Item_cache Item_cache **values; uint item_count; public: - Item_cache_row(): values(0), item_count(2) { fixed= 1; null_value= 1; } + Item_cache_row(): Item_cache(), values(0), item_count(2) {} /* 'allocate' used only in row transformer, to preallocate space for row diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 94423642fa5..f37509f89b5 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -290,6 +290,14 @@ bool Item_in_optimizer::fix_fields(THD *thd, struct st_table_list *tables, if (!cache && !(cache= Item_cache::get_cache(args[0]->result_type()))) return 1; cache->setup(args[0]); + if (cache->cols() == 1) + cache->set_used_tables(RAND_TABLE_BIT); + else + { + uint n= cache->cols(); + for (uint i= 0; i < n; i++) + ((Item_cache *)cache->el(i))->set_used_tables(RAND_TABLE_BIT); + } if (args[1]->fix_fields(thd, tables, args)) return 1; Item_in_subselect * sub= (Item_in_subselect *)args[1]; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index ae45f96fbe8..74d08daf8db 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -442,16 +442,6 @@ JOIN::optimize() thd->fatal_error) DBUG_RETURN(1); - if (select_lex->dependent) - { - /* - Just remove all const-table optimization in case of depended query - TODO: optimize - */ - const_table_map= 0; - const_tables= 0; - found_const_table_map= 0; - } thd->proc_info= "preparing"; if (result->initialize_tables(this)) { @@ -4681,8 +4671,11 @@ do_select(JOIN *join,List *fields,TABLE *table,Procedure *procedure) join->send_records=0; if (join->tables == join->const_tables) { - if (!(error=(*end_select)(join,join_tab,0)) || error == -3) - error=(*end_select)(join,join_tab,1); + if (!join->select_lex->dependent || + ((!join->conds || join->conds->val_int()) && + (!join->having || join->having->val_int()))) + if (!(error=(*end_select)(join,join_tab,0)) || error == -3) + error=(*end_select)(join,join_tab,1); } else {