From 6b4e18db079afec8b1d041731e8ccd065434d75e Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 20 May 2003 17:09:53 +0300 Subject: [PATCH] do not find keys in external fields (bug 446 related) sql/sql_select.cc: do not find keys in external fields --- sql/sql_select.cc | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 85ebb9f207f..494366d1995 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1929,7 +1929,10 @@ add_key_fields(JOIN_TAB *stat,KEY_FIELD **key_fields,uint *and_level, case Item_func::OPTIMIZE_NONE: break; case Item_func::OPTIMIZE_KEY: - if (cond_func->key_item()->real_item()->type() == Item::FIELD_ITEM) + if (cond_func->key_item()->real_item()->type() == Item::FIELD_ITEM && + // field from outer query can't be used as key + !((Item_field*) (cond_func->key_item()->real_item())) + ->depended_from) add_key_field(key_fields,*and_level, ((Item_field*) (cond_func->key_item()->real_item())) ->field, @@ -1940,7 +1943,10 @@ add_key_fields(JOIN_TAB *stat,KEY_FIELD **key_fields,uint *and_level, bool equal_func=(cond_func->functype() == Item_func::EQ_FUNC || cond_func->functype() == Item_func::EQUAL_FUNC); - if (cond_func->arguments()[0]->real_item()->type() == Item::FIELD_ITEM) + if (cond_func->arguments()[0]->real_item()->type() == Item::FIELD_ITEM && + // field from outer query can't be used as key + !((Item_field*) (cond_func->arguments()[0]->real_item())) + ->depended_from) { add_key_field(key_fields,*and_level, ((Item_field*) (cond_func->arguments()[0])->real_item()) @@ -1949,7 +1955,10 @@ add_key_fields(JOIN_TAB *stat,KEY_FIELD **key_fields,uint *and_level, (cond_func->arguments()[1]),usable_tables); } if (cond_func->arguments()[1]->real_item()->type() == Item::FIELD_ITEM && - cond_func->functype() != Item_func::LIKE_FUNC) + cond_func->functype() != Item_func::LIKE_FUNC && + // field from outer query can't be used as key + !((Item_field*) (cond_func->arguments()[1]->real_item())) + ->depended_from) { add_key_field(key_fields,*and_level, ((Item_field*) (cond_func->arguments()[1])->real_item()) @@ -1961,7 +1970,10 @@ add_key_fields(JOIN_TAB *stat,KEY_FIELD **key_fields,uint *and_level, } case Item_func::OPTIMIZE_NULL: /* column_name IS [NOT] NULL */ - if (cond_func->arguments()[0]->real_item()->type() == Item::FIELD_ITEM) + if (cond_func->arguments()[0]->real_item()->type() == Item::FIELD_ITEM && + // field from outer query can't be used as key + !((Item_field*) (cond_func->arguments()[0]->real_item())) + ->depended_from) { add_key_field(key_fields,*and_level, ((Item_field*) (cond_func->arguments()[0])->real_item())