diff --git a/mysql-test/extra/rpl_tests/rpl_extraMaster_Col.test b/mysql-test/extra/rpl_tests/rpl_extraMaster_Col.test index efca53d5698..5abd04b98ef 100644 --- a/mysql-test/extra/rpl_tests/rpl_extraMaster_Col.test +++ b/mysql-test/extra/rpl_tests/rpl_extraMaster_Col.test @@ -419,7 +419,7 @@ connection master; update t31 set f5=555555555555555 where f3=6; update t31 set f2=2 where f3=2; update t31 set f1=NULL where f3=1; - update t31 set f3=NULL, f27=NULL, f35='f35 new value' where f3=3; + update t31 set f3=0, f27=NULL, f35='f35 new value' where f3=3; --echo --echo ** Delete from Master ** diff --git a/mysql-test/include/mix1.inc b/mysql-test/include/mix1.inc index 3005e67935b..703dfa44df0 100644 --- a/mysql-test/include/mix1.inc +++ b/mysql-test/include/mix1.inc @@ -723,20 +723,6 @@ set @@sort_buffer_size=default; DROP TABLE t1,t2; -# -# Bug #32815: query with ORDER BY and a possible ref_or_null access -# - -CREATE TABLE t1 (id int, type char(6), d int, INDEX idx(id,d)) ENGINE=InnoDB; -INSERT INTO t1 VALUES - (191, 'member', 1), (NULL, 'member', 3), (NULL, 'member', 4), (201, 'member', 2); - -EXPLAIN SELECT * FROM t1 WHERE id=191 OR id IS NULL ORDER BY d; -SELECT * FROM t1 WHERE id=191 OR id IS NULL ORDER BY d; - -DROP TABLE t1; - - # Test of behaviour with CREATE ... SELECT # @@ -1091,6 +1077,19 @@ desc t1; show create table t1; drop table t1; +# +# Bug #32815: query with ORDER BY and a possible ref_or_null access +# + +CREATE TABLE t1 (id int, type char(6), d int, INDEX idx(id,d)) ENGINE=InnoDB; +INSERT INTO t1 VALUES + (191, 'member', 1), (NULL, 'member', 3), (NULL, 'member', 4), (201, 'member', 2); + +EXPLAIN SELECT * FROM t1 WHERE id=191 OR id IS NULL ORDER BY d; +SELECT * FROM t1 WHERE id=191 OR id IS NULL ORDER BY d; + +DROP TABLE t1; + --echo End of 5.0 tests # Fix for BUG#19243 "wrong LAST_INSERT_ID() after ON DUPLICATE KEY @@ -1383,4 +1382,32 @@ create table t1 (a int auto_increment primary key) engine=innodb; alter table t1 order by a; drop table t1; +# +# Bug #33697: ORDER BY primary key DESC vs. ref access + filesort +# (reproduced only with InnoDB tables) +# + +CREATE TABLE t1 + (vid integer NOT NULL, + tid integer NOT NULL, + idx integer NOT NULL, + name varchar(128) NOT NULL, + type varchar(128) NULL, + PRIMARY KEY(idx, vid, tid), + UNIQUE(vid, tid, name) +) ENGINE=InnoDB; + +INSERT INTO t1 VALUES + (1,1,1,'pk',NULL),(2,1,1,'pk',NULL),(3,1,1,'pk',NULL),(4,1,1,'c1',NULL), + (5,1,1,'pk',NULL),(1,1,2,'c1',NULL),(2,1,2,'c1',NULL),(3,1,2,'c1',NULL), + (4,1,2,'c2',NULL),(5,1,2,'c1',NULL),(2,1,3,'c2',NULL),(3,1,3,'c2',NULL), + (4,1,3,'pk',NULL),(5,1,3,'c2',NULL), + (2,1,4,'c_extra',NULL),(3,1,4,'c_extra',NULL); + +EXPLAIN SELECT * FROM t1 WHERE tid = 1 AND vid = 3 ORDER BY idx DESC; + +SELECT * FROM t1 WHERE tid = 1 AND vid = 3 ORDER BY idx DESC; + +DROP TABLE t1; + --echo End of 5.1 tests diff --git a/mysql-test/include/ps_modify.inc b/mysql-test/include/ps_modify.inc index f66f888261d..4cde18b97d1 100644 --- a/mysql-test/include/ps_modify.inc +++ b/mysql-test/include/ps_modify.inc @@ -108,6 +108,7 @@ execute stmt1 using @arg00, @arg01; select a,b from t1 where a=@arg00; set @arg00=NULL; set @arg01=2; +--error 1048 execute stmt1 using @arg00, @arg01; select a,b from t1 order by a; set @arg00=0; diff --git a/mysql-test/r/auto_increment.result b/mysql-test/r/auto_increment.result index 54c2df34a7f..bc9daf43f14 100644 --- a/mysql-test/r/auto_increment.result +++ b/mysql-test/r/auto_increment.result @@ -231,8 +231,7 @@ a b 204 7 delete from t1 where a=0; update t1 set a=NULL where b=6; -Warnings: -Warning 1048 Column 'a' cannot be null +ERROR 23000: Column 'a' cannot be null update t1 set a=300 where b=7; SET SQL_MODE=''; insert into t1(a,b)values(NULL,8); @@ -247,7 +246,7 @@ a b 1 1 200 2 201 4 -0 6 +203 6 300 7 301 8 400 9 @@ -263,6 +262,7 @@ a b 1 1 200 2 201 4 +203 6 300 7 301 8 400 9 @@ -273,20 +273,20 @@ a b 405 14 delete from t1 where a=0; update t1 set a=NULL where b=13; -Warnings: -Warning 1048 Column 'a' cannot be null +ERROR 23000: Column 'a' cannot be null update t1 set a=500 where b=14; select * from t1 order by b; a b 1 1 200 2 201 4 +203 6 300 7 301 8 400 9 401 10 402 11 -0 13 +404 13 500 14 drop table t1; create table t1 (a bigint); diff --git a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result index 1472fdfdd7a..268f290ddca 100644 --- a/mysql-test/r/group_by.result +++ b/mysql-test/r/group_by.result @@ -1478,3 +1478,39 @@ NULL 1 2 DROP TABLE t1; +CREATE TABLE t1 ( a INT, b INT ); +SELECT b c, (SELECT a FROM t1 WHERE b = c) +FROM t1; +c (SELECT a FROM t1 WHERE b = c) +SELECT b c, (SELECT a FROM t1 WHERE b = c) +FROM t1 +HAVING b = 10; +c (SELECT a FROM t1 WHERE b = c) +SELECT MAX(b) c, (SELECT a FROM t1 WHERE b = c) +FROM t1 +HAVING b = 10; +ERROR 42S22: Reference 'c' not supported (reference to group function) +SET @old_sql_mode = @@sql_mode; +SET @@sql_mode='ONLY_FULL_GROUP_BY'; +SELECT b c, (SELECT a FROM t1 WHERE b = c) +FROM t1; +c (SELECT a FROM t1 WHERE b = c) +SELECT b c, (SELECT a FROM t1 WHERE b = c) +FROM t1 +HAVING b = 10; +ERROR 42000: non-grouping field 'b' is used in HAVING clause +SELECT MAX(b) c, (SELECT a FROM t1 WHERE b = c) +FROM t1 +HAVING b = 10; +ERROR 42S22: Reference 'c' not supported (reference to group function) +INSERT INTO t1 VALUES (1, 1); +SELECT b c, (SELECT a FROM t1 WHERE b = c) +FROM t1; +c (SELECT a FROM t1 WHERE b = c) +1 1 +INSERT INTO t1 VALUES (2, 1); +SELECT b c, (SELECT a FROM t1 WHERE b = c) +FROM t1; +ERROR 21000: Subquery returns more than 1 row +DROP TABLE t1; +SET @@sql_mode = @old_sql_mode; diff --git a/mysql-test/r/innodb_mysql.result b/mysql-test/r/innodb_mysql.result index 87cf1acc10c..e9f00a667c0 100644 --- a/mysql-test/r/innodb_mysql.result +++ b/mysql-test/r/innodb_mysql.result @@ -1349,7 +1349,7 @@ INSERT INTO t1 VALUES (191, 'member', 1), (NULL, 'member', 3), (NULL, 'member', 4), (201, 'member', 2); EXPLAIN SELECT * FROM t1 WHERE id=191 OR id IS NULL ORDER BY d; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL idx NULL NULL NULL 3 Using where; Using filesort +1 SIMPLE t1 ALL idx NULL NULL NULL 4 Using where; Using filesort SELECT * FROM t1 WHERE id=191 OR id IS NULL ORDER BY d; id type d 191 member 1 @@ -1609,4 +1609,29 @@ alter table t1 order by a; Warnings: Warning 1105 ORDER BY ignored as there is a user-defined clustered index in the table 't1' drop table t1; +CREATE TABLE t1 +(vid integer NOT NULL, +tid integer NOT NULL, +idx integer NOT NULL, +name varchar(128) NOT NULL, +type varchar(128) NULL, +PRIMARY KEY(idx, vid, tid), +UNIQUE(vid, tid, name) +) ENGINE=InnoDB; +INSERT INTO t1 VALUES +(1,1,1,'pk',NULL),(2,1,1,'pk',NULL),(3,1,1,'pk',NULL),(4,1,1,'c1',NULL), +(5,1,1,'pk',NULL),(1,1,2,'c1',NULL),(2,1,2,'c1',NULL),(3,1,2,'c1',NULL), +(4,1,2,'c2',NULL),(5,1,2,'c1',NULL),(2,1,3,'c2',NULL),(3,1,3,'c2',NULL), +(4,1,3,'pk',NULL),(5,1,3,'c2',NULL), +(2,1,4,'c_extra',NULL),(3,1,4,'c_extra',NULL); +EXPLAIN SELECT * FROM t1 WHERE tid = 1 AND vid = 3 ORDER BY idx DESC; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index vid PRIMARY 12 NULL 16 Using where +SELECT * FROM t1 WHERE tid = 1 AND vid = 3 ORDER BY idx DESC; +vid tid idx name type +3 1 4 c_extra NULL +3 1 3 c2 NULL +3 1 2 c1 NULL +3 1 1 pk NULL +DROP TABLE t1; End of 5.1 tests diff --git a/mysql-test/r/null.result b/mysql-test/r/null.result index 345c9b07b98..5a2ebc37cc8 100644 --- a/mysql-test/r/null.result +++ b/mysql-test/r/null.result @@ -93,11 +93,9 @@ INSERT INTO t1 SET a = "", d= "2003-01-14 03:54:55"; Warnings: Warning 1265 Data truncated for column 'd' at row 1 UPDATE t1 SET d=1/NULL; -Warnings: -Warning 1265 Data truncated for column 'd' at row 1 +ERROR 23000: Column 'd' cannot be null UPDATE t1 SET d=NULL; -Warnings: -Warning 1048 Column 'd' cannot be null +ERROR 23000: Column 'd' cannot be null INSERT INTO t1 (a) values (null); ERROR 23000: Column 'a' cannot be null INSERT INTO t1 (a) values (1/null); @@ -132,7 +130,7 @@ Warning 1048 Column 'd' cannot be null Warning 1048 Column 'd' cannot be null select * from t1; a b c d - 0 0000-00-00 00:00:00 0 + 0 0000-00-00 00:00:00 2003 0 0000-00-00 00:00:00 0 0 0000-00-00 00:00:00 0 0 0000-00-00 00:00:00 0 diff --git a/mysql-test/r/ps_2myisam.result b/mysql-test/r/ps_2myisam.result index fbc6781e5e7..06bfd78a351 100644 --- a/mysql-test/r/ps_2myisam.result +++ b/mysql-test/r/ps_2myisam.result @@ -1303,12 +1303,11 @@ a b set @arg00=NULL; set @arg01=2; execute stmt1 using @arg00, @arg01; -Warnings: -Warning 1048 Column 'a' cannot be null +ERROR 23000: Column 'a' cannot be null select a,b from t1 order by a; a b -0 two 1 one +2 two 3 three 4 four set @arg00=0; diff --git a/mysql-test/r/ps_3innodb.result b/mysql-test/r/ps_3innodb.result index fcd0b5de9a0..f56b1d37a2c 100644 --- a/mysql-test/r/ps_3innodb.result +++ b/mysql-test/r/ps_3innodb.result @@ -1286,12 +1286,11 @@ a b set @arg00=NULL; set @arg01=2; execute stmt1 using @arg00, @arg01; -Warnings: -Warning 1048 Column 'a' cannot be null +ERROR 23000: Column 'a' cannot be null select a,b from t1 order by a; a b -0 two 1 one +2 two 3 three 4 four set @arg00=0; diff --git a/mysql-test/r/ps_4heap.result b/mysql-test/r/ps_4heap.result index 862c0ff75c1..0c643facf72 100644 --- a/mysql-test/r/ps_4heap.result +++ b/mysql-test/r/ps_4heap.result @@ -1287,12 +1287,11 @@ a b set @arg00=NULL; set @arg01=2; execute stmt1 using @arg00, @arg01; -Warnings: -Warning 1048 Column 'a' cannot be null +ERROR 23000: Column 'a' cannot be null select a,b from t1 order by a; a b -0 two 1 one +2 two 3 three 4 four set @arg00=0; diff --git a/mysql-test/r/ps_5merge.result b/mysql-test/r/ps_5merge.result index 51393cc8bc3..bd3cd4ac1fc 100644 --- a/mysql-test/r/ps_5merge.result +++ b/mysql-test/r/ps_5merge.result @@ -1329,12 +1329,11 @@ a b set @arg00=NULL; set @arg01=2; execute stmt1 using @arg00, @arg01; -Warnings: -Warning 1048 Column 'a' cannot be null +ERROR 23000: Column 'a' cannot be null select a,b from t1 order by a; a b -0 two 1 one +2 two 3 three 4 four set @arg00=0; @@ -4351,12 +4350,11 @@ a b set @arg00=NULL; set @arg01=2; execute stmt1 using @arg00, @arg01; -Warnings: -Warning 1048 Column 'a' cannot be null +ERROR 23000: Column 'a' cannot be null select a,b from t1 order by a; a b -0 two 1 one +2 two 3 three 4 four set @arg00=0; diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 762457d57a6..20d44933128 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -4291,6 +4291,54 @@ select count(*) from t1 where f12 = count(*) 3 drop table t1,t2; +CREATE TABLE t4 ( +f7 varchar(32) collate utf8_bin NOT NULL default '', +f10 varchar(32) collate utf8_bin default NULL, +PRIMARY KEY (f7) +); +INSERT INTO t4 VALUES(1,1), (2,null); +CREATE TABLE t2 ( +f4 varchar(32) collate utf8_bin NOT NULL default '', +f2 varchar(50) collate utf8_bin default NULL, +f3 varchar(10) collate utf8_bin default NULL, +PRIMARY KEY (f4), +UNIQUE KEY uk1 (f2) +); +INSERT INTO t2 VALUES(1,1,null), (2,2,null); +CREATE TABLE t1 ( +f8 varchar(32) collate utf8_bin NOT NULL default '', +f1 varchar(10) collate utf8_bin default NULL, +f9 varchar(32) collate utf8_bin default NULL, +PRIMARY KEY (f8) +); +INSERT INTO t1 VALUES (1,'P',1), (2,'P',1), (3,'R',2); +CREATE TABLE t3 ( +f6 varchar(32) collate utf8_bin NOT NULL default '', +f5 varchar(50) collate utf8_bin default NULL, +PRIMARY KEY (f6) +); +INSERT INTO t3 VALUES (1,null), (2,null); +SELECT +IF(t1.f1 = 'R', a1.f2, t2.f2) AS a4, +IF(t1.f1 = 'R', a1.f3, t2.f3) AS f3, +SUM( +IF( +(SELECT VPC.f2 +FROM t2 VPC, t4 a2, t2 a3 +WHERE +VPC.f4 = a2.f10 AND a3.f2 = a4 +LIMIT 1) IS NULL, +0, +t3.f5 +) +) AS a6 +FROM +t2, t3, t1 JOIN t2 a1 ON t1.f9 = a1.f4 +GROUP BY a4; +a4 f3 a6 +1 NULL NULL +2 NULL NULL +DROP TABLE t1, t2, t3, t4; End of 5.0 tests. CREATE TABLE t1 (a int, b int); INSERT INTO t1 VALUES (2,22),(1,11),(2,22); diff --git a/mysql-test/r/type_decimal.result b/mysql-test/r/type_decimal.result index a25ffc4c6fc..3e5f6a9b504 100644 --- a/mysql-test/r/type_decimal.result +++ b/mysql-test/r/type_decimal.result @@ -794,7 +794,7 @@ dps tinyint(3) unsigned default NULL INSERT INTO t1 VALUES (1.1325,3); SELECT ROUND(qty,3), dps, ROUND(qty,dps) FROM t1; ROUND(qty,3) dps ROUND(qty,dps) -1.133 3 1.133 +1.133 3 1.133000 DROP TABLE t1; SELECT 1 % .123456789123456789123456789123456789123456789123456789123456789123456789123456789 AS '%'; % @@ -885,4 +885,65 @@ c 1000 1234567890 DROP TABLE t1, t2, t3, t4; +CREATE TABLE t1( a DECIMAL(4, 3), b INT ); +INSERT INTO t1 VALUES ( 1, 5 ), ( 2, 4 ), ( 3, 3 ), ( 4, 2 ), ( 5, 1 ); +SELECT a, b, ROUND( a, b ) AS c FROM t1 ORDER BY c; +a b c +1.000 5 1.000 +2.000 4 2.000 +3.000 3 3.000 +4.000 2 4.000 +5.000 1 5.000 +SELECT a, b, ROUND( a, b ) AS c FROM t1 ORDER BY c DESC; +a b c +5.000 1 5.000 +4.000 2 4.000 +3.000 3 3.000 +2.000 4 2.000 +1.000 5 1.000 +CREATE TABLE t2 ( a INT, b INT, c DECIMAL(5, 4) ); +INSERT INTO t2 VALUES ( 0, 1, 1.2345 ), ( 1, 2, 1.2345 ), +( 3, 3, 1.2345 ), ( 2, 4, 1.2345 ); +SELECT a, b, MAX(ROUND(c, a)) +FROM t2 +GROUP BY a, b +ORDER BY b; +a b MAX(ROUND(c, a)) +0 1 1.0000 +1 2 1.2000 +3 3 1.2350 +2 4 1.2300 +SELECT a, b, ROUND(c, a) +FROM t2; +a b ROUND(c, a) +0 1 1.0000 +1 2 1.2000 +3 3 1.2350 +2 4 1.2300 +CREATE TABLE t3( a INT, b DECIMAL(6, 3) ); +INSERT INTO t3 VALUES( 0, 1.5 ); +SELECT ROUND( b, a ) FROM t3; +ROUND( b, a ) +2.000 +CREATE TABLE t4( a INT, b DECIMAL( 12, 0) ); +INSERT INTO t4 VALUES( -9, 1.5e9 ); +SELECT ROUND( b, a ) FROM t4; +ROUND( b, a ) +2000000000 +CREATE TABLE t5( a INT, b DECIMAL( 13, 12 ) ); +INSERT INTO t5 VALUES( 0, 1.5 ); +INSERT INTO t5 VALUES( 9, 1.5e-9 ); +SELECT ROUND( b, a ) FROM t5; +ROUND( b, a ) +2.000000000000 +0.000000002000 +CREATE TABLE t6( a INT ); +INSERT INTO t6 VALUES( 6 / 8 ); +SELECT * FROM t6; +a +1 +SELECT ROUND(20061108085411.000002); +ROUND(20061108085411.000002) +20061108085411 +DROP TABLE t1, t2, t3, t4, t5, t6; End of 5.0 tests diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 2971af7347d..09b997797b4 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -3597,6 +3597,22 @@ DROP VIEW v1; DROP VIEW v2; DROP VIEW v3; DROP TABLE t1; +# +# Bug#29477: Not all fields of the target table were checked to have +# a default value when inserting into a view. +# +create table t1(f1 int, f2 int not null); +create view v1 as select f1 from t1; +insert into v1 values(1); +Warnings: +Warning 1423 Field of view 'test.v1' underlying table doesn't have a default value +set @old_mode=@@sql_mode; +set @@sql_mode=traditional; +insert into v1 values(1); +ERROR HY000: Field of view 'test.v1' underlying table doesn't have a default value +set @@sql_mode=@old_mode; +drop view v1; +drop table t1; End of 5.0 tests. DROP DATABASE IF EXISTS `d-1`; CREATE DATABASE `d-1`; diff --git a/mysql-test/r/warnings.result b/mysql-test/r/warnings.result index 2929328a9b1..249cd583345 100644 --- a/mysql-test/r/warnings.result +++ b/mysql-test/r/warnings.result @@ -98,8 +98,7 @@ Warning 1265 Data truncated for column 'c' at row 1 Warning 1265 Data truncated for column 'c' at row 2 alter table t1 add d char(2); update t1 set a=NULL where a=10; -Warnings: -Warning 1048 Column 'a' cannot be null +ERROR 23000: Column 'a' cannot be null update t1 set c='mysql ab' where c='test'; Warnings: Warning 1265 Data truncated for column 'c' at row 4 diff --git a/mysql-test/suite/ndb/r/ps_7ndb.result b/mysql-test/suite/ndb/r/ps_7ndb.result index 6e2e61bbc5e..3cbc1a0e76f 100644 --- a/mysql-test/suite/ndb/r/ps_7ndb.result +++ b/mysql-test/suite/ndb/r/ps_7ndb.result @@ -1286,12 +1286,11 @@ a b set @arg00=NULL; set @arg01=2; execute stmt1 using @arg00, @arg01; -Warnings: -Warning 1048 Column 'a' cannot be null +ERROR 23000: Column 'a' cannot be null select a,b from t1 order by a; a b -0 two 1 one +2 two 3 three 4 four set @arg00=0; diff --git a/mysql-test/suite/rpl/r/rpl_extraColmaster_innodb.result b/mysql-test/suite/rpl/r/rpl_extraColmaster_innodb.result index ad67f96db71..86648ba12c3 100644 --- a/mysql-test/suite/rpl/r/rpl_extraColmaster_innodb.result +++ b/mysql-test/suite/rpl/r/rpl_extraColmaster_innodb.result @@ -454,9 +454,7 @@ f1 f2 f3 f4 update t31 set f5=555555555555555 where f3=6; update t31 set f2=2 where f3=2; update t31 set f1=NULL where f3=1; -update t31 set f3=NULL, f27=NULL, f35='f35 new value' where f3=3; -Warnings: -Warning 1048 Column 'f3' cannot be null +update t31 set f3=0, f27=NULL, f35='f35 new value' where f3=3; ** Delete from Master ** @@ -1595,9 +1593,7 @@ f1 f2 f3 f4 update t31 set f5=555555555555555 where f3=6; update t31 set f2=2 where f3=2; update t31 set f1=NULL where f3=1; -update t31 set f3=NULL, f27=NULL, f35='f35 new value' where f3=3; -Warnings: -Warning 1048 Column 'f3' cannot be null +update t31 set f3=0, f27=NULL, f35='f35 new value' where f3=3; ** Delete from Master ** @@ -2736,9 +2732,7 @@ f1 f2 f3 f4 update t31 set f5=555555555555555 where f3=6; update t31 set f2=2 where f3=2; update t31 set f1=NULL where f3=1; -update t31 set f3=NULL, f27=NULL, f35='f35 new value' where f3=3; -Warnings: -Warning 1048 Column 'f3' cannot be null +update t31 set f3=0, f27=NULL, f35='f35 new value' where f3=3; ** Delete from Master ** diff --git a/mysql-test/suite/rpl/r/rpl_extraColmaster_myisam.result b/mysql-test/suite/rpl/r/rpl_extraColmaster_myisam.result index 8859a8e24e3..96d4ca237d1 100644 --- a/mysql-test/suite/rpl/r/rpl_extraColmaster_myisam.result +++ b/mysql-test/suite/rpl/r/rpl_extraColmaster_myisam.result @@ -454,9 +454,7 @@ f1 f2 f3 f4 update t31 set f5=555555555555555 where f3=6; update t31 set f2=2 where f3=2; update t31 set f1=NULL where f3=1; -update t31 set f3=NULL, f27=NULL, f35='f35 new value' where f3=3; -Warnings: -Warning 1048 Column 'f3' cannot be null +update t31 set f3=0, f27=NULL, f35='f35 new value' where f3=3; ** Delete from Master ** @@ -1595,9 +1593,7 @@ f1 f2 f3 f4 update t31 set f5=555555555555555 where f3=6; update t31 set f2=2 where f3=2; update t31 set f1=NULL where f3=1; -update t31 set f3=NULL, f27=NULL, f35='f35 new value' where f3=3; -Warnings: -Warning 1048 Column 'f3' cannot be null +update t31 set f3=0, f27=NULL, f35='f35 new value' where f3=3; ** Delete from Master ** @@ -2736,9 +2732,7 @@ f1 f2 f3 f4 update t31 set f5=555555555555555 where f3=6; update t31 set f2=2 where f3=2; update t31 set f1=NULL where f3=1; -update t31 set f3=NULL, f27=NULL, f35='f35 new value' where f3=3; -Warnings: -Warning 1048 Column 'f3' cannot be null +update t31 set f3=0, f27=NULL, f35='f35 new value' where f3=3; ** Delete from Master ** diff --git a/mysql-test/suite/rpl/t/rpl_err_ignoredtable.test b/mysql-test/suite/rpl/t/rpl_err_ignoredtable.test index 4e06a6a7096..a36cfb11dae 100644 --- a/mysql-test/suite/rpl/t/rpl_err_ignoredtable.test +++ b/mysql-test/suite/rpl/t/rpl_err_ignoredtable.test @@ -49,7 +49,7 @@ kill @id; drop table t2,t3; insert into t4 values (3),(4); connection master; ---error 0,1053,2013 +--error 0,1053,2013,1048 reap; connection master1; save_master_pos; diff --git a/mysql-test/t/auto_increment.test b/mysql-test/t/auto_increment.test index 99e9b783d55..ff92c743960 100644 --- a/mysql-test/t/auto_increment.test +++ b/mysql-test/t/auto_increment.test @@ -149,6 +149,7 @@ delete from t1 where a=0; update t1 set a=0 where b=5; select * from t1 order by b; delete from t1 where a=0; +--error 1048 update t1 set a=NULL where b=6; update t1 set a=300 where b=7; SET SQL_MODE=''; @@ -164,6 +165,7 @@ delete from t1 where a=0; update t1 set a=0 where b=12; select * from t1 order by b; delete from t1 where a=0; +--error 1048 update t1 set a=NULL where b=13; update t1 set a=500 where b=14; select * from t1 order by b; diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test index 94c2b463aaa..3211db5d6ed 100644 --- a/mysql-test/t/group_by.test +++ b/mysql-test/t/group_by.test @@ -789,8 +789,6 @@ select t1.f1,t.* from t1, t1 t group by 1; drop table t1; SET SQL_MODE = ''; -# - # # Bug #32202: ORDER BY not working with GROUP BY # @@ -824,6 +822,7 @@ SELECT * FROM t1 GROUP BY c2 ORDER BY c2 DESC, c1 DESC; DROP TABLE t1; + --echo End of 5.0 tests # Bug #21174: Index degrades sort performance and # optimizer does not honor IGNORE INDEX. @@ -946,3 +945,51 @@ EXPLAIN SELECT b from t2 GROUP BY b; SELECT b from t2 GROUP BY b; DROP TABLE t1; + +# +# Bug #31797: error while parsing subqueries -- WHERE is parsed as HAVING +# +CREATE TABLE t1 ( a INT, b INT ); + +SELECT b c, (SELECT a FROM t1 WHERE b = c) +FROM t1; + +SELECT b c, (SELECT a FROM t1 WHERE b = c) +FROM t1 +HAVING b = 10; + +--error ER_ILLEGAL_REFERENCE +SELECT MAX(b) c, (SELECT a FROM t1 WHERE b = c) +FROM t1 +HAVING b = 10; + +SET @old_sql_mode = @@sql_mode; +SET @@sql_mode='ONLY_FULL_GROUP_BY'; + +SELECT b c, (SELECT a FROM t1 WHERE b = c) +FROM t1; + +--error ER_NON_GROUPING_FIELD_USED +SELECT b c, (SELECT a FROM t1 WHERE b = c) +FROM t1 +HAVING b = 10; + +--error ER_ILLEGAL_REFERENCE +SELECT MAX(b) c, (SELECT a FROM t1 WHERE b = c) +FROM t1 +HAVING b = 10; + +INSERT INTO t1 VALUES (1, 1); +SELECT b c, (SELECT a FROM t1 WHERE b = c) +FROM t1; + +INSERT INTO t1 VALUES (2, 1); +--error ER_SUBQUERY_NO_1_ROW +SELECT b c, (SELECT a FROM t1 WHERE b = c) +FROM t1; + +DROP TABLE t1; +SET @@sql_mode = @old_sql_mode; + + + diff --git a/mysql-test/t/null.test b/mysql-test/t/null.test index 2878b54c357..ddf6b8870fa 100644 --- a/mysql-test/t/null.test +++ b/mysql-test/t/null.test @@ -61,7 +61,9 @@ drop table t1; # CREATE TABLE t1 (a varchar(16) NOT NULL default '', b smallint(6) NOT NULL default 0, c datetime NOT NULL default '0000-00-00 00:00:00', d smallint(6) NOT NULL default 0); INSERT INTO t1 SET a = "", d= "2003-01-14 03:54:55"; +--error 1048 UPDATE t1 SET d=1/NULL; +--error 1048 UPDATE t1 SET d=NULL; --error 1048 INSERT INTO t1 (a) values (null); diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index ad940f3f5ad..c86b0fefbdc 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -3159,6 +3159,60 @@ select count(*) from t1 where f12 = drop table t1,t2; +# +# BUG#33794 "MySQL crashes executing specific query on specific dump" +# +CREATE TABLE t4 ( + f7 varchar(32) collate utf8_bin NOT NULL default '', + f10 varchar(32) collate utf8_bin default NULL, + PRIMARY KEY (f7) +); +INSERT INTO t4 VALUES(1,1), (2,null); + +CREATE TABLE t2 ( + f4 varchar(32) collate utf8_bin NOT NULL default '', + f2 varchar(50) collate utf8_bin default NULL, + f3 varchar(10) collate utf8_bin default NULL, + PRIMARY KEY (f4), + UNIQUE KEY uk1 (f2) +); +INSERT INTO t2 VALUES(1,1,null), (2,2,null); + +CREATE TABLE t1 ( + f8 varchar(32) collate utf8_bin NOT NULL default '', + f1 varchar(10) collate utf8_bin default NULL, + f9 varchar(32) collate utf8_bin default NULL, + PRIMARY KEY (f8) +); +INSERT INTO t1 VALUES (1,'P',1), (2,'P',1), (3,'R',2); + +CREATE TABLE t3 ( + f6 varchar(32) collate utf8_bin NOT NULL default '', + f5 varchar(50) collate utf8_bin default NULL, + PRIMARY KEY (f6) +); +INSERT INTO t3 VALUES (1,null), (2,null); + +SELECT + IF(t1.f1 = 'R', a1.f2, t2.f2) AS a4, + IF(t1.f1 = 'R', a1.f3, t2.f3) AS f3, + SUM( + IF( + (SELECT VPC.f2 + FROM t2 VPC, t4 a2, t2 a3 + WHERE + VPC.f4 = a2.f10 AND a3.f2 = a4 + LIMIT 1) IS NULL, + 0, + t3.f5 + ) + ) AS a6 +FROM + t2, t3, t1 JOIN t2 a1 ON t1.f9 = a1.f4 +GROUP BY a4; + +DROP TABLE t1, t2, t3, t4; + --echo End of 5.0 tests. # @@ -3194,3 +3248,4 @@ CREATE TABLE t1 (s1 char(1)); INSERT INTO t1 VALUES ('a'); SELECT * FROM t1 WHERE _utf8'a' = ANY (SELECT s1 FROM t1); DROP TABLE t1; + diff --git a/mysql-test/t/type_decimal.test b/mysql-test/t/type_decimal.test index 807d1e6b01e..6841b3cdd68 100644 --- a/mysql-test/t/type_decimal.test +++ b/mysql-test/t/type_decimal.test @@ -478,4 +478,47 @@ select round(a,b) as c from t1 order by c; DROP TABLE t1, t2, t3, t4; +# +# Bug #33143: Incorrect ORDER BY for ROUND()/TRUNCATE() result +# + +CREATE TABLE t1( a DECIMAL(4, 3), b INT ); +INSERT INTO t1 VALUES ( 1, 5 ), ( 2, 4 ), ( 3, 3 ), ( 4, 2 ), ( 5, 1 ); +SELECT a, b, ROUND( a, b ) AS c FROM t1 ORDER BY c; +SELECT a, b, ROUND( a, b ) AS c FROM t1 ORDER BY c DESC; + +CREATE TABLE t2 ( a INT, b INT, c DECIMAL(5, 4) ); + +INSERT INTO t2 VALUES ( 0, 1, 1.2345 ), ( 1, 2, 1.2345 ), + ( 3, 3, 1.2345 ), ( 2, 4, 1.2345 ); + +SELECT a, b, MAX(ROUND(c, a)) +FROM t2 +GROUP BY a, b +ORDER BY b; + +SELECT a, b, ROUND(c, a) +FROM t2; + +CREATE TABLE t3( a INT, b DECIMAL(6, 3) ); +INSERT INTO t3 VALUES( 0, 1.5 ); +SELECT ROUND( b, a ) FROM t3; + +CREATE TABLE t4( a INT, b DECIMAL( 12, 0) ); +INSERT INTO t4 VALUES( -9, 1.5e9 ); +SELECT ROUND( b, a ) FROM t4; + +CREATE TABLE t5( a INT, b DECIMAL( 13, 12 ) ); +INSERT INTO t5 VALUES( 0, 1.5 ); +INSERT INTO t5 VALUES( 9, 1.5e-9 ); +SELECT ROUND( b, a ) FROM t5; + +CREATE TABLE t6( a INT ); +INSERT INTO t6 VALUES( 6 / 8 ); +SELECT * FROM t6; + +SELECT ROUND(20061108085411.000002); + +DROP TABLE t1, t2, t3, t4, t5, t6; + --echo End of 5.0 tests diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 7f769c50449..58ef9c1eff1 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -3453,6 +3453,20 @@ DROP VIEW v2; DROP VIEW v3; DROP TABLE t1; +--echo # +--echo # Bug#29477: Not all fields of the target table were checked to have +--echo # a default value when inserting into a view. +--echo # +create table t1(f1 int, f2 int not null); +create view v1 as select f1 from t1; +insert into v1 values(1); +set @old_mode=@@sql_mode; +set @@sql_mode=traditional; +--error ER_NO_DEFAULT_FOR_VIEW_FIELD +insert into v1 values(1); +set @@sql_mode=@old_mode; +drop view v1; +drop table t1; --echo End of 5.0 tests. diff --git a/mysql-test/t/warnings.test b/mysql-test/t/warnings.test index b5bae109f5f..d0eaaf1a764 100644 --- a/mysql-test/t/warnings.test +++ b/mysql-test/t/warnings.test @@ -65,6 +65,7 @@ create table t1(a tinyint NOT NULL, b tinyint unsigned, c char(5)); insert into t1 values(NULL,100,'mysql'),(10,-1,'mysql ab'),(500,256,'open source'),(20,NULL,'test'); alter table t1 modify c char(4); alter table t1 add d char(2); +--error 1048 update t1 set a=NULL where a=10; update t1 set c='mysql ab' where c='test'; update t1 set d=c; diff --git a/sql/item.cc b/sql/item.cc index 922c3b7a976..34f6eb9dc61 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -3408,7 +3408,7 @@ static Item** find_field_in_group_list(Item *find_item, ORDER *group_list) resolve_ref_in_select_and_group() thd current thread ref column reference being resolved - select the sub-select that ref is resolved against + select the select that ref is resolved against DESCRIPTION Resolve a column reference (usually inside a HAVING clause) against the @@ -3479,6 +3479,7 @@ resolve_ref_in_select_and_group(THD *thd, Item_ident *ref, SELECT_LEX *select) } if (thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY && + select->having_fix_field && select_ref != not_found_item && !group_by_ref) { /* diff --git a/sql/item_func.cc b/sql/item_func.cc index bdd600c3fc9..8fd6f0966ad 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -2006,7 +2006,7 @@ void Item_func_round::fix_length_and_dec() int length_increase= ((decimals_delta <= 0) || truncate) ? 0:1; precision-= decimals_delta - length_increase; - decimals= decimals_to_set; + decimals= min(decimals_to_set, DECIMAL_MAX_SCALE); max_length= my_decimal_precision_to_length(precision, decimals, unsigned_flag); break; @@ -2105,18 +2105,18 @@ my_decimal *Item_func_round::decimal_op(my_decimal *decimal_value) { my_decimal val, *value= args[0]->val_decimal(&val); longlong dec= args[1]->val_int(); - if (dec > 0 || (dec < 0 && args[1]->unsigned_flag)) - { + if (dec >= 0 || args[1]->unsigned_flag) dec= min((ulonglong) dec, decimals); - decimals= (uint8) dec; // to get correct output - } else if (dec < INT_MIN) dec= INT_MIN; if (!(null_value= (args[0]->null_value || args[1]->null_value || my_decimal_round(E_DEC_FATAL_ERROR, value, (int) dec, - truncate, decimal_value) > 1))) + truncate, decimal_value) > 1))) + { + decimal_value->frac= decimals; return decimal_value; + } return 0; } diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 1dd915fb9b6..1aa12e83126 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -619,7 +619,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, if (mysql_prepare_insert(thd, table_list, table, fields, values, update_fields, update_values, duplic, &unused_conds, FALSE, - (fields.elements || !value_count), + (fields.elements || !value_count || + table_list->view != 0), !ignore && (thd->variables.sql_mode & (MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES)))) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 8f9562eb5e2..ef9f9fd4359 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -5552,7 +5552,8 @@ get_store_key(THD *thd, KEYUSE *keyuse, table_map used_tables, (keyuse->val->type() == Item::REF_ITEM && ((Item_ref*)keyuse->val)->ref_type() == Item_ref::OUTER_REF && (*(Item_ref**)((Item_ref*)keyuse->val)->ref)->ref_type() == - Item_ref::DIRECT_REF) ) + Item_ref::DIRECT_REF && + keyuse->val->real_item()->type() == Item::FIELD_ITEM)) return new store_key_field(thd, key_part->field, key_buff + maybe_null, @@ -13122,7 +13123,8 @@ check_reverse_order: select->quick=tmp; } } - else if (tab->ref.key >= 0 && tab->ref.key_parts <= used_key_parts) + else if (tab->type != JT_NEXT && + tab->ref.key >= 0 && tab->ref.key_parts <= used_key_parts) { /* SELECT * FROM t1 WHERE a=1 ORDER BY a DESC,b DESC diff --git a/sql/sql_update.cc b/sql/sql_update.cc index e2dfd89aa32..ed066b89ae3 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -526,7 +526,9 @@ int mysql_update(THD *thd, init_read_record(&info,thd,table,select,0,1); updated= found= 0; - thd->count_cuted_fields= CHECK_FIELD_WARN; /* calc cuted fields */ + /* Generate an error when trying to set a NOT NULL field to NULL. */ + thd->count_cuted_fields= ignore ? CHECK_FIELD_WARN + : CHECK_FIELD_ERROR_FOR_NULL; thd->cuted_fields=0L; thd->proc_info="Updating"; diff --git a/strings/decimal.c b/strings/decimal.c index f457014b2b1..0559dd97613 100644 --- a/strings/decimal.c +++ b/strings/decimal.c @@ -1601,9 +1601,21 @@ decimal_round(decimal_t *from, decimal_t *to, int scale, x+=10; *buf1=powers10[pos]*(x-y); } - if (frac0 < 0) + /* + In case we're rounding e.g. 1.5e9 to 2.0e9, the decimal_digit_t's inside + the buffer are as follows. + + Before <1, 5e8> + After <2, 5e8> + + Hence we need to set the 2nd field to 0. + The same holds if we round 1.5e-9 to 2e-9. + */ + if (frac0 < frac1) { - dec1 *end=to->buf+intg0, *buf=buf1+1; + dec1 *buf= to->buf + ((scale == 0 && intg0 == 0) ? 1 : intg0 + frac0); + dec1 *end= to->buf + len; + while (buf < end) *buf++=0; } diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index 9284b2182b1..3776be79399 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -15674,7 +15674,7 @@ static void test_mysql_insert_id() myquery(rc); res= mysql_insert_id(mysql); DIE_UNLESS(res == 0); - rc= mysql_query(mysql, "update t2 set f1=NULL where f1=14"); + rc= mysql_query(mysql, "update t2 set f1=0 where f1=14"); myquery(rc); res= mysql_insert_id(mysql); DIE_UNLESS(res == 0);