summaryrefslogtreecommitdiff
path: root/mysql-test/r
diff options
context:
space:
mode:
authorunknown <gkodinov/kgeorge@macbook.gmz>2007-01-05 14:02:50 +0200
committerunknown <gkodinov/kgeorge@macbook.gmz>2007-01-05 14:02:50 +0200
commit42e31f7a45413b685c4332ced1d983ccfda29d25 (patch)
treec950f88f3dfc18f002d2a0caa214ca6301358cd1 /mysql-test/r
parent5df7d39e520e6b23ca2b63c0aae211fe201c4f02 (diff)
downloadmariadb-git-42e31f7a45413b685c4332ced1d983ccfda29d25.tar.gz
Bug #15881: cast problems
The optimizer removes expressions from GROUP BY/DISTINCT if they happen to participate in a <expression> = <const> predicates of the WHERE clause (the idea being that if it's always equal to a constant it can't have multiple values). However for predicates where the expression and the constant item are of different result type this is not valid (e.g. a string column compared to 0). Fixed by additional check of the result types of the expression and the constant and if they differ the expression don't get removed from the group by list. mysql-test/r/distinct.result: Bug #15881: cast problems - test case mysql-test/t/distinct.test: Bug #15881: cast problems - test case sql/sql_select.cc: Bug #15881: cast problems - can't use <expr>=<const> to remove GROUP BY/DISTINCT cols if they're not of the same type.
Diffstat (limited to 'mysql-test/r')
-rw-r--r--mysql-test/r/distinct.result37
1 files changed, 37 insertions, 0 deletions
diff --git a/mysql-test/r/distinct.result b/mysql-test/r/distinct.result
index 86ab2141e2d..32151305698 100644
--- a/mysql-test/r/distinct.result
+++ b/mysql-test/r/distinct.result
@@ -607,3 +607,40 @@ id select_type table type possible_keys key key_len ref rows Extra
SELECT DISTINCT a,a FROM t1 WHERE b < 12 ORDER BY a;
a a
DROP TABLE t1;
+CREATE TABLE t1 (a CHAR(1));
+INSERT INTO t1 VALUES('A'), (0);
+SELECT a FROM t1 WHERE a=0;
+a
+A
+0
+Warnings:
+Warning 1292 Truncated incorrect DOUBLE value: 'A'
+SELECT DISTINCT a FROM t1 WHERE a=0;
+a
+A
+0
+Warnings:
+Warning 1292 Truncated incorrect DOUBLE value: 'A'
+DROP TABLE t1;
+CREATE TABLE t1 (a DATE);
+INSERT INTO t1 VALUES ('1972-07-29'), ('1972-02-06');
+EXPLAIN SELECT (SELECT DISTINCT a FROM t1 WHERE a = '2002-08-03');
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used
+2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where
+EXPLAIN SELECT (SELECT DISTINCT ADDDATE(a,1) FROM t1
+WHERE ADDDATE(a,1) = '2002-08-03');
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used
+2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where; Using temporary
+CREATE TABLE t2 (a CHAR(5) CHARACTER SET latin1 COLLATE latin1_general_ci);
+INSERT INTO t2 VALUES (0xf6);
+INSERT INTO t2 VALUES ('oe');
+SELECT COUNT(*) FROM (SELECT DISTINCT a FROM t2) dt;
+COUNT(*)
+2
+SELECT COUNT(*) FROM
+(SELECT DISTINCT a FROM t2 WHERE a='oe' COLLATE latin1_german2_ci) dt;
+COUNT(*)
+2
+DROP TABLE t1, t2;