summaryrefslogtreecommitdiff
path: root/sql/item_subselect.cc
diff options
context:
space:
mode:
authorEvgeny Potemkin <epotemkin@mysql.com>2009-07-16 19:43:46 +0400
committerEvgeny Potemkin <epotemkin@mysql.com>2009-07-16 19:43:46 +0400
commit63e6a59d7398673c32a00ed163f76420a85120dd (patch)
tree70f908568600351a2f29c48fc9e45f808edc942a /sql/item_subselect.cc
parent924c8c5bfbc346de72d27a06fa5d6cb87b471c08 (diff)
downloadmariadb-git-63e6a59d7398673c32a00ed163f76420a85120dd.tar.gz
Bug#46051: Incorrectly market field caused wrong result.
In a subselect all fields from outer selects are marked as dependent on selects they are belong to. In some cases optimizer substitutes it for an equivalent expression. For example "a_field IN (SELECT outer_field)" is substituted with "a_field = outer_field". As we moved the outer_field to the upper select it's not really outer anymore. But it was left marked as outer. If exists an index over a_field optimizer choose wrong execution plan and thus return wrong result. Now the Item_in_subselect::single_value_transformer function removes dependent marking from fields when a subselect is optimized away. mysql-test/r/subselect.result: Added a test case for the bug#46051. mysql-test/t/subselect.test: Added a test case for the bug#46051. sql/item_subselect.cc: Bug#46051: Incorrectly market field caused wrong result. Now the Item_in_subselect::single_value_transformer function removes dependent marking from fields when a subselect is optimized away.
Diffstat (limited to 'sql/item_subselect.cc')
-rw-r--r--sql/item_subselect.cc4
1 files changed, 4 insertions, 0 deletions
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 13eeba3ea27..805669b3cfa 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -1145,6 +1145,10 @@ Item_in_subselect::single_value_transformer(JOIN *join,
else
{
// it is single select without tables => possible optimization
+ // remove the dependence mark since the item is moved to upper
+ // select and is not outer anymore.
+ item->walk(&Item::remove_dependence_processor,
+ (byte *) select_lex->outer_select());
item= func->create(left_expr, item);
// fix_field of item will be done in time of substituting
substitution= item;