2001-09-28 07:05:54 +02:00
drop table if exists t1;
CREATE TABLE t1 (id CHAR(12) not null, PRIMARY KEY (id));
insert into t1 values ('000000000001'),('000000000002');
explain select * from t1 where id=000000000001;
2002-09-26 22:08:22 +02:00
id select_type table type possible_keys key key_len ref rows Extra
2002-11-21 14:56:48 +01:00
1 SIMPLE t1 index PRIMARY PRIMARY 12 NULL 2 Using where; Using index
2001-09-28 07:05:54 +02:00
select * from t1 where id=000000000001;
2000-12-28 02:56:38 +01:00
id
000000000001
2001-09-28 07:05:54 +02:00
delete from t1 where id=000000000002;
select * from t1;
2000-12-28 02:56:38 +01:00
id
000000000001
2001-09-28 07:05:54 +02:00
drop table t1;
2004-03-26 15:14:39 +01:00
SELECT 'a' = 'a ';
'a' = 'a '
1
SELECT 'a\0' < 'a';
'a\0' < 'a'
1
SELECT 'a\0' < 'a ';
'a\0' < 'a '
1
SELECT 'a\t' < 'a';
'a\t' < 'a'
1
SELECT 'a\t' < 'a ';
'a\t' < 'a '
1
CREATE TABLE t1 (a char(10) not null);
INSERT INTO t1 VALUES ('a'),('a\0'),('a\t'),('a ');
SELECT hex(a),STRCMP(a,'a'), STRCMP(a,'a ') FROM t1;
hex(a) STRCMP(a,'a') STRCMP(a,'a ')
61 0 0
6100 -1 -1
6109 -1 -1
61 0 0
DROP TABLE t1;
2005-01-29 02:18:35 +01:00
SELECT CHAR(31) = '', '' = CHAR(31);
CHAR(31) = '' '' = CHAR(31)
0 0
2005-02-01 15:27:08 +01:00
SELECT CHAR(30) = '', '' = CHAR(30);
CHAR(30) = '' '' = CHAR(30)
0 0
2006-08-15 09:13:17 +02:00
create table t1 (a tinyint(1),b binary(1));
insert into t1 values (0x01,0x01);
select * from t1 where a=b;
a b
2006-11-28 14:44:11 +01:00
Warnings:
2022-07-06 13:42:21 +02:00
Warning 1292 Truncated incorrect DECIMAL value: '\x01'
2006-08-15 09:13:17 +02:00
select * from t1 where a=b and b=0x01;
a b
2006-11-28 14:44:11 +01:00
Warnings:
2022-07-06 13:42:21 +02:00
Warning 1292 Truncated incorrect DECIMAL value: '\x01'
2006-08-15 09:13:17 +02:00
drop table if exists t1;
2008-02-15 14:47:32 +01:00
CREATE TABLE t1 (b int(2) zerofill, c int(2) zerofill);
INSERT INTO t1 (b,c) VALUES (1,2), (1,1), (2,2);
SELECT CONCAT(b,c), CONCAT(b,c) = '0101' FROM t1;
CONCAT(b,c) CONCAT(b,c) = '0101'
0102 0
0101 1
0202 0
EXPLAIN EXTENDED SELECT b,c FROM t1 WHERE b = 1 AND CONCAT(b,c) = '0101';
2008-02-16 10:11:13 +01:00
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where
2008-02-15 14:47:32 +01:00
Warnings:
2016-11-27 19:50:10 +01:00
Note 1003 select `test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where `test`.`t1`.`b` = 1 and concat(`test`.`t1`.`b`,`test`.`t1`.`c`) = '0101'
2008-02-15 14:47:32 +01:00
SELECT b,c FROM t1 WHERE b = 1 AND CONCAT(b,c) = '0101';
b c
01 01
CREATE TABLE t2 (a int);
INSERT INTO t2 VALUES (1),(2);
SELECT a,
(SELECT COUNT(*) FROM t1
WHERE b = t2.a AND CONCAT(b,c) = CONCAT('0',t2.a,'01')) x
FROM t2 ORDER BY a;
a x
1 1
2 0
EXPLAIN EXTENDED
SELECT a,
(SELECT COUNT(*) FROM t1
WHERE b = t2.a AND CONCAT(b,c) = CONCAT('0',t2.a,'01')) x
FROM t2 ORDER BY a;
2008-02-16 10:11:13 +01:00
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using filesort
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
2008-02-15 14:47:32 +01:00
Warnings:
Note 1276 Field or reference 'test.t2.a' of SELECT #2 was resolved in SELECT #1
Note 1276 Field or reference 'test.t2.a' of SELECT #2 was resolved in SELECT #1
2017-01-22 12:31:32 +01:00
Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,<expr_cache><`test`.`t2`.`a`>((/* select#2 */ select count(0) from `test`.`t1` where `test`.`t1`.`b` = `test`.`t2`.`a` and concat(`test`.`t1`.`b`,`test`.`t1`.`c`) = concat('0',`test`.`t2`.`a`,'01'))) AS `x` from `test`.`t2` order by `test`.`t2`.`a`
2008-02-15 14:47:32 +01:00
DROP TABLE t1,t2;
2008-09-18 14:55:36 +02:00
CREATE TABLE t1 (a TIMESTAMP);
INSERT INTO t1 VALUES (NOW()),(NOW()),(NOW());
SELECT * FROM t1 WHERE a > '2008-01-01' AND a = '0000-00-00';
a
DROP TABLE t1;
2008-02-15 14:47:32 +01:00
End of 5.0 tests
2012-06-21 17:47:13 +02:00
CREATE TABLE t1(a INT ZEROFILL);
SELECT 1 FROM t1 WHERE t1.a IN (1, t1.a) AND t1.a=2;
1
DROP TABLE t1;
2019-09-22 03:08:48 +02:00
CREATE TABLE t1 (a char(2), index (a));
insert into t1 values ("aa"),("bb");
select * from t1 where a="aa";
a
aa
select * from t1 where a="aaa";
a
select * from t1 where a="aa ";
a
aa
select * from t1 where a>="aaa";
a
bb
explain select * from t1 where a="aaa";
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref a a 3 const 1 Using where; Using index
explain select * from t1 where a="aa ";
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref a a 3 const 1 Using where; Using index
drop table t1;