mariadb/mysql-test/main/func_isnull.result

131 lines
4.7 KiB
Text
Raw Normal View History

drop table if exists t1;
create table t1 (id int auto_increment primary key not null, mydate date not null);
insert into t1 values (0,"2002-05-01"),(0,"2002-05-01"),(0,"2002-05-01");
flush tables;
select * from t1 where isnull(to_days(mydate));
id mydate
drop table t1;
#
# Bug#53933 crash when using uncacheable subquery in the having clause of outer query
#
CREATE TABLE t1 (f1 INT);
INSERT INTO t1 VALUES (0),(0);
SELECT ISNULL((SELECT GET_LOCK('Bug#53933', 0) FROM t1 GROUP BY f1)) AS f2
FROM t1 GROUP BY f1 HAVING f2 = f2;
f2
0
SELECT RELEASE_LOCK('Bug#53933');
RELEASE_LOCK('Bug#53933')
1
DROP TABLE t1;
End of 5.0 tests
Bug#41371 Select returns 1 row with condition "col is not null and col is null" For application compatibility reasons MySQL converts "<autoincrement_column> IS NULL" predicates to "<autoincrement_column> = LAST_INSERT_ID()" in the first SELECT following an INSERT regardless of whether they're top level predicates or not. This causes wrong and obscure results when these predicates are combined with others on the same columns. Fixed by only doing the transformation on a single top-level predicate if a special SQL mode is turned on (sql_auto_is_null). Also made sql_auto_is_null off by default. per-file comments: mysql-test/r/func_isnull.result Bug#41371 Select returns 1 row with condition "col is not null and col is null" test result updated mysql-test/t/func_isnull.test Bug#41371 Select returns 1 row with condition "col is not null and col is null" test case added sql/mysqld.cc Bug#41371 Select returns 1 row with condition "col is not null and col is null" sql_auto_is_null now is OFF by default. sql/sql_select.cc Bug#41371 Select returns 1 row with condition "col is not null and col is null" remove_eq_conds() split in two parts - one only checks the upper condition, the req_remove_eq_conds() recursively checks all the condition tree. mysql-test/extra/rpl_tests/rpl_insert_id.test Bug#41371 Select returns 1 row with condition "col is not null and col is null" test fixed (set the sql_auto_is_null variable) mysql-test/r/mysqlbinlog.result Bug#41371 Select returns 1 row with condition "col is not null and col is null" result updated mysql-test/r/mysqlbinlog2.result Bug#41371 Select returns 1 row with condition "col is not null and col is null" result updated mysql-test/r/odbc.result Bug#41371 Select returns 1 row with condition "col is not null and col is null" result updated mysql-test/r/query_cache.result Bug#41371 Select returns 1 row with condition "col is not null and col is null" result updated mysql-test/r/user_var-binlog.result Bug#41371 Select returns 1 row with condition "col is not null and col is null" result updated mysql-test/suite/binlog/r/binlog_row_ctype_ucs.result Bug#41371 Select returns 1 row with condition "col is not null and col is null" result updated mysql-test/suite/binlog/r/binlog_stm_ctype_ucs.result Bug#41371 Select returns 1 row with condition "col is not null and col is null" result updated mysql-test/suite/rpl/r/rpl_insert_id.result Bug#41371 Select returns 1 row with condition "col is not null and col is null" result updated mysql-test/suite/rpl/r/rpl_row_mysqlbinlog.result Bug#41371 Select returns 1 row with condition "col is not null and col is null" result updated mysql-test/suite/rpl/r/rpl_sp.result Bug#41371 Select returns 1 row with condition "col is not null and col is null" result updated mysql-test/t/odbc.test Bug#41371 Select returns 1 row with condition "col is not null and col is null" test fixed (set the sql_auto_is_null variable)
2009-11-03 14:54:41 +01:00
CREATE TABLE t1 (id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, PRIMARY KEY(id));
INSERT INTO t1( id ) VALUES ( NULL );
SELECT t1.id FROM t1 WHERE (id is not null and id is null );
id
DROP TABLE t1;
# End of 5.1 tests
#
# MDEV-14911: IS NULL for field from mergeable view
#
CREATE TABLE t1 (d1 datetime NOT NULL);
INSERT INTO t1 VALUES
('0000-00-00 00:00:00'), ('0000-00-00 00:00:00'), ('1979-09-03 20:49:36');
SELECT * FROM t1;
d1
0000-00-00 00:00:00
0000-00-00 00:00:00
1979-09-03 20:49:36
SELECT * FROM t1 WHERE d1 IS NULL;
d1
0000-00-00 00:00:00
0000-00-00 00:00:00
EXPLAIN EXTENDED SELECT * FROM t1 WHERE d1 IS NULL;
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
Warnings:
2018-02-06 14:50:50 +01:00
Note 1003 select `test`.`t1`.`d1` AS `d1` from `test`.`t1` where `test`.`t1`.`d1` = 0
SELECT count(*) FROM t1 WHERE d1 IS NULL;
count(*)
2
CREATE VIEW v1 AS (SELECT * FROM t1);
SELECT * FROM v1;
d1
0000-00-00 00:00:00
0000-00-00 00:00:00
1979-09-03 20:49:36
SELECT * FROM v1 WHERE d1 IS NULL;
d1
0000-00-00 00:00:00
0000-00-00 00:00:00
EXPLAIN EXTENDED SELECT * FROM v1 WHERE d1 IS NULL;
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
Warnings:
2018-02-06 14:50:50 +01:00
Note 1003 select `test`.`t1`.`d1` AS `d1` from `test`.`t1` where `test`.`t1`.`d1` = 0
SELECT count(*) FROM v1 WHERE d1 IS NULL;
count(*)
2
SET @save_optimizer_switch=@@optimizer_switch;
SET SESSION optimizer_switch='derived_merge=off';
SELECT count(*) FROM ( SELECT * FROM t1 ) AS a1 WHERE d1 IS NULL;
count(*)
2
SET SESSION optimizer_switch='derived_merge=on';
SELECT count(*) FROM ( SELECT * FROM t1 ) AS a1 WHERE d1 IS NULL;
count(*)
2
SET optimizer_switch=@save_optimizer_switch;
CREATE TABLE t2 (d1 datetime NOT NULL);
INSERT INTO t2 VALUES
('1980-09-03 20:49:36'), ('0000-00-00 00:00:00'), ('1979-09-03 20:49:36');
SELECT * FROM t2 LEFT JOIN t1 ON t2.d1=t1.d1 WHERE t1.d1 IS NULL;
d1 d1
0000-00-00 00:00:00 0000-00-00 00:00:00
0000-00-00 00:00:00 0000-00-00 00:00:00
1980-09-03 20:49:36 NULL
EXPLAIN EXTENDED
SELECT * FROM t2 LEFT JOIN t1 ON t2.d1=t1.d1 WHERE t1.d1 IS NULL;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
2018-02-06 14:50:50 +01:00
Note 1003 select `test`.`t2`.`d1` AS `d1`,`test`.`t1`.`d1` AS `d1` from `test`.`t2` left join `test`.`t1` on(`test`.`t1`.`d1` = `test`.`t2`.`d1`) where `test`.`t1`.`d1` = 0 or `test`.`t1`.`d1` is null
SELECT * FROM t2 LEFT JOIN v1 ON t2.d1=v1.d1 WHERE v1.d1 IS NULL;
d1 d1
0000-00-00 00:00:00 0000-00-00 00:00:00
0000-00-00 00:00:00 0000-00-00 00:00:00
1980-09-03 20:49:36 NULL
EXPLAIN EXTENDED
SELECT * FROM t2 LEFT JOIN v1 ON t2.d1=v1.d1 WHERE v1.d1 IS NULL;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
2018-02-06 14:50:50 +01:00
Note 1003 select `test`.`t2`.`d1` AS `d1`,`test`.`t1`.`d1` AS `d1` from `test`.`t2` left join (`test`.`t1`) on(`test`.`t1`.`d1` = `test`.`t2`.`d1`) where `test`.`t1`.`d1` = 0 or `test`.`t1`.`d1` is null
DROP VIEW v1;
DROP TABLE t1,t2;
#
# MDEV-15475: Assertion `!table || (!table->read_set ||
# bitmap_is_set(table->read_set, field_index))'
# failed on EXPLAIN EXTENDED with constant table and view
#
CREATE TABLE t1 (pk INT PRIMARY KEY) ENGINE=MyISAM;
CREATE VIEW v1 AS SELECT * FROM t1;
INSERT INTO t1 VALUES (1);
EXPLAIN EXTENDED SELECT ISNULL(pk) FROM v1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 system NULL NULL NULL NULL 1 100.00
Warnings:
2018-08-21 14:20:34 +02:00
Note 1003 select /*always not null*/ 1 is null AS `ISNULL(pk)` from dual
EXPLAIN EXTENDED SELECT IFNULL(pk,0) FROM v1;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 system NULL NULL NULL NULL 1 100.00
Warnings:
Note 1003 select ifnull(1,0) AS `IFNULL(pk,0)` from dual
DROP VIEW v1;
DROP TABLE t1;
#
# End of 5.5 tests
#