summaryrefslogtreecommitdiff
path: root/sql/item.cc
diff options
context:
space:
mode:
authorunknown <igor@olga.mysql.com>2007-03-11 23:34:40 -0700
committerunknown <igor@olga.mysql.com>2007-03-11 23:34:40 -0700
commit13c05162f34451d19759230e24f81b34034e23b8 (patch)
tree02abad69b98470e037973567d0574730ca30eda8 /sql/item.cc
parent2f774b479b91cb279c42ce7f191a2ce4993f1890 (diff)
downloadmariadb-git-13c05162f34451d19759230e24f81b34034e23b8.tar.gz
Fixed bug #26963: invalid optimization of the pushdown conditions
after single-row table substitution could lead to a wrong result set. The bug happened because the function Item_field::replace_equal_field erroniously assumed that any field included in a multiple equality with a constant has been already substituted for this constant. This not true for fields becoming constant after row substitutions for constant tables. mysql-test/r/select.result: Added a test case for bug #26963. mysql-test/t/select.test: Added a test case for bug #26963. sql/item.cc: Fixed bug #26963: invalid optimization of the pushdown conditions after single-row table substitution could lead to a wrong result set. The bug happened because the function Item_field::replace_equal_field erroneously assumed that any field included in a multiple equality with a constant has been already substituted for this constant. This not true for fields becoming constant after row substitutions for constant tables.
Diffstat (limited to 'sql/item.cc')
-rw-r--r--sql/item.cc15
1 files changed, 13 insertions, 2 deletions
diff --git a/sql/item.cc b/sql/item.cc
index ec33bf1ddc7..11a5039ca19 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -4075,7 +4075,9 @@ bool Item_field::set_no_const_sub(byte *arg)
DESCRIPTION
The function returns a pointer to an item that is taken from
the very beginning of the item_equal list which the Item_field
- object refers to (belongs to).
+ object refers to (belongs to) unless item_equal contains a constant
+ item. In this case the function returns this constant item,
+ (if the substitution does not require conversion).
If the Item_field object does not refer any Item_equal object
'this' is returned
@@ -4084,7 +4086,8 @@ bool Item_field::set_no_const_sub(byte *arg)
of the thransformer method.
RETURN VALUES
- pointer to a replacement Item_field if there is a better equal item;
+ pointer to a replacement Item_field if there is a better equal item or
+ a pointer to a constant equal item;
this - otherwise.
*/
@@ -4092,6 +4095,14 @@ Item *Item_field::replace_equal_field(byte *arg)
{
if (item_equal)
{
+ Item *const_item= item_equal->get_const();
+ if (const_item)
+ {
+ if (cmp_context != (Item_result)-1 &&
+ const_item->cmp_context != cmp_context)
+ return this;
+ return const_item;
+ }
Item_field *subst= item_equal->get_first();
if (subst && !field->eq(subst->field))
return subst;