summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/select.result13
-rw-r--r--mysql-test/t/select.test14
-rw-r--r--sql/item.cc2
3 files changed, 28 insertions, 1 deletions
diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result
index 0771c7fb370..09c7d1b329d 100644
--- a/mysql-test/r/select.result
+++ b/mysql-test/r/select.result
@@ -4373,6 +4373,19 @@ f3 f4 count
1 abc 1
1 def 2
drop table t1, t2, t3;
+CREATE TABLE t1 (a INT KEY, b INT);
+INSERT INTO t1 VALUES (1,1), (2,2), (3,3), (4,4);
+EXPLAIN EXTENDED SELECT a, b FROM t1 WHERE a > 1 AND a = b LIMIT 2;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 100.00 Using where
+Warnings:
+Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((`test`.`t1`.`b` = `test`.`t1`.`a`) and (`test`.`t1`.`a` > 1)) limit 2
+EXPLAIN EXTENDED SELECT a, b FROM t1 WHERE a > 1 AND b = a LIMIT 2;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 100.00 Using where
+Warnings:
+Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((`test`.`t1`.`a` = `test`.`t1`.`b`) and (`test`.`t1`.`a` > 1)) limit 2
+DROP TABLE t1;
End of 5.0 tests
create table t1(a INT, KEY (a));
INSERT INTO t1 VALUES (1),(2),(3),(4),(5);
diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test
index 8981ddbe2e4..715bdf0e667 100644
--- a/mysql-test/t/select.test
+++ b/mysql-test/t/select.test
@@ -3726,6 +3726,20 @@ cr.f4 = cr2.f4
GROUP BY a.f3, cr.f4;
drop table t1, t2, t3;
+
+
+#
+# Bug #40925: Equality propagation takes non indexed attribute
+#
+
+CREATE TABLE t1 (a INT KEY, b INT);
+INSERT INTO t1 VALUES (1,1), (2,2), (3,3), (4,4);
+
+EXPLAIN EXTENDED SELECT a, b FROM t1 WHERE a > 1 AND a = b LIMIT 2;
+EXPLAIN EXTENDED SELECT a, b FROM t1 WHERE a > 1 AND b = a LIMIT 2;
+
+DROP TABLE t1;
+
--echo End of 5.0 tests
#
diff --git a/sql/item.cc b/sql/item.cc
index 180ce4f4702..d1418b9a137 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -4468,7 +4468,7 @@ Item *Item_field::replace_equal_field(uchar *arg)
return const_item;
}
Item_field *subst= item_equal->get_first();
- if (subst && !field->eq(subst->field))
+ if (subst && field->table != subst->field->table && !field->eq(subst->field))
return subst;
}
return this;