diff options
author | bell@sanja.is.com.ua <> | 2003-10-17 00:36:01 +0300 |
---|---|---|
committer | bell@sanja.is.com.ua <> | 2003-10-17 00:36:01 +0300 |
commit | b9dccb34ddcf8c528c48103d01885de8e8fd9d84 (patch) | |
tree | 2ebdddfb2ccf3da4a7ef04c84e28d2af0546fecc /sql/item_subselect.cc | |
parent | 6ad94a6d57add4103990d2b3a2b7e6dd0bc9fccd (diff) | |
download | mariadb-git-b9dccb34ddcf8c528c48103d01885de8e8fd9d84.tar.gz |
fixed support of used_tables() and const_item() in subqueries
(BUG#1444)
Diffstat (limited to 'sql/item_subselect.cc')
-rw-r--r-- | sql/item_subselect.cc | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 5e0221ad6c7..4ad49ebec74 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -36,7 +36,8 @@ inline Item * and_items(Item* cond, Item *item) Item_subselect::Item_subselect(): Item_result_field(), engine_owner(1), value_assigned(0), substitution(0), - engine(0), have_to_be_excluded(0), engine_changed(0) + engine(0), used_tables_cache(0), have_to_be_excluded(0), + const_item_cache(1), engine_changed(0) { reset(); /* @@ -146,12 +147,27 @@ void Item_subselect::fix_length_and_dec() engine->fix_length_and_dec(0); } -inline table_map Item_subselect::used_tables() const +table_map Item_subselect::used_tables() const { - return (table_map) (engine->dependent() ? 1L : + return (table_map) (engine->dependent() ? used_tables_cache : (engine->uncacheable() ? RAND_TABLE_BIT : 0L)); } +bool Item_subselect::const_item() const +{ + return engine->uncacheable()? 0 : const_item_cache; +} + +void Item_subselect::update_used_tables() +{ + if (!engine->uncacheable()) + { + // did all used tables become ststic? + if ((used_tables_cache & ~engine->upper_select_const_tables()) == 0) + const_item_cache= 1; + } +} + Item_singlerow_subselect::Item_singlerow_subselect(st_select_lex *select_lex) :Item_subselect(), value(0) { @@ -1138,3 +1154,29 @@ void subselect_uniquesubquery_engine::exclude() //this never should be called DBUG_ASSERT(0); } + + +table_map subselect_engine::calc_const_tables(TABLE_LIST *table) +{ + table_map map= 0; + for(; table; table= table->next) + { + TABLE *tbl= table->table; + if (tbl && tbl->const_table) + map|= tbl->map; + } + return map; +} + + +table_map subselect_single_select_engine::upper_select_const_tables() +{ + return calc_const_tables((TABLE_LIST *) select_lex->outer_select()-> + table_list.first); +} + +table_map subselect_union_engine::upper_select_const_tables() +{ + return calc_const_tables((TABLE_LIST *) unit->outer_select()-> + table_list.first); +} |