1# This test can't be run with running server (--extern) as this uses 2# load_file() on a file in the tree. 3# 4--source include/have_innodb.inc 5 6# 7# Basic cleanup 8# 9--disable_warnings 10drop table if exists t1,t2,t3,t4,t5,t6,t7; 11--enable_warnings 12 13 14# 15# Check syntax for creating BLOB/TEXT 16# 17 18CREATE TABLE t1 (a blob, b text, c blob(250), d text(70000), e text(70000000)); 19show columns from t1; 20# PS doesn't give errors on prepare yet 21SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR 22CREATE TABLE t2 (a char(255), b varbinary(70000), c varchar(70000000)); 23SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR 24CREATE TABLE t4 (c varchar(65530) character set utf8 not null); 25show columns from t2; 26create table t3 (a long, b long byte); 27show create TABLE t3; 28show create TABLE t4; 29drop table t1,t2,t3,t4; 30 31# 32# Check errors with blob 33# 34 35--error 1074 36CREATE TABLE t1 (a char(257) default "hello"); 37--error 1074 38CREATE TABLE t2 (a char(256)); 39SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR 40CREATE TABLE t1 (a varchar(70000) default "hello"); 41SHOW CREATE TABLE t1; 42CREATE TABLE t2 (a blob default "hello"); 43SHOW CREATE TABLE t2; 44 45drop table t1,t2; 46 47# 48# test of full join with blob 49# 50 51create table t1 (nr int(5) not null auto_increment,b blob,str char(10), primary key (nr)); 52insert into t1 values (null,"a","A"); 53insert into t1 values (null,"bbb","BBB"); 54insert into t1 values (null,"ccc","CCC"); 55select last_insert_id(); 56select * from t1,t1 as t2; 57 58drop table t1; 59 60# 61# Test of changing TEXT column 62# 63 64create table t1 (a text); 65insert into t1 values ('where'); 66update t1 set a='Where'; 67select * from t1; 68drop table t1; 69 70# 71# test of blob, text, char and varbinary 72# 73create table t1 (t text,c char(10),b blob, d varbinary(10)); 74insert into t1 values (NULL,NULL,NULL,NULL); 75insert into t1 values ("","","",""); 76insert into t1 values ("hello","hello","hello","hello"); 77insert into t1 values ("HELLO","HELLO","HELLO","HELLO"); 78insert into t1 values ("HELLO MY","HELLO MY","HELLO MY","HELLO MY"); 79insert into t1 values ("a","a","a","a"); 80insert into t1 values (1,1,1,1); 81insert into t1 values (NULL,NULL,NULL,NULL); 82update t1 set c="",b=null where c="1"; 83 84lock tables t1 READ; 85# We mask out the Privileges column because it differs for embedded server 86--replace_column 8 # 87show full fields from t1; 88lock tables t1 WRITE; 89--replace_column 8 # 90show full fields from t1; 91unlock tables; 92 93select t from t1 where t like "hello"; 94select c from t1 where c like "hello"; 95select b from t1 where b like "hello"; 96select d from t1 where d like "hello"; 97select c from t1 having c like "hello"; 98select d from t1 having d like "hello"; 99select t from t1 where t like "%HELLO%"; 100select c from t1 where c like "%HELLO%"; 101select b from t1 where b like "%HELLO%"; 102select d from t1 where d like "%HELLO%"; 103select c from t1 having c like "%HELLO%"; 104select d from t1 having d like "%HELLO%"; 105select d from t1 having d like "%HE%LLO%"; 106select t from t1 order by t; 107select c from t1 order by c; 108select b from t1 order by b; 109select d from t1 order by d; 110select distinct t from t1; 111select distinct b from t1; 112select distinct t from t1 order by t; 113select distinct b from t1 order by b; 114select t from t1 group by t; 115select b from t1 group by b; 116set tmp_memory_table_size=0; # force on-disk tmp table 117select distinct t from t1; 118select distinct b from t1; 119select distinct t from t1 order by t; 120select distinct b from t1 order by b; 121select distinct c from t1; 122select distinct d from t1; 123select distinct c from t1 order by c; 124select distinct d from t1 order by d; 125select c from t1 group by c; 126select d from t1 group by d; 127set tmp_memory_table_size=default; 128select distinct * from t1; 129select t,count(*) from t1 group by t; 130select b,count(*) from t1 group by b; 131select c,count(*) from t1 group by c; 132select d,count(*) from t1 group by d; 133drop table t1; 134 135create table t1 (a text, key (a(2100))); # key is auto-truncated 136show create table t1; 137drop table t1; 138 139# 140# Test of join with blobs and min 141# 142 143CREATE TABLE t1 ( 144 t1_id bigint(21) NOT NULL auto_increment, 145 _field_72 varchar(128) DEFAULT '' NOT NULL, 146 _field_95 varchar(32), 147 _field_115 tinyint(4) DEFAULT '0' NOT NULL, 148 _field_122 tinyint(4) DEFAULT '0' NOT NULL, 149 _field_126 tinyint(4), 150 _field_134 tinyint(4), 151 PRIMARY KEY (t1_id), 152 UNIQUE _field_72 (_field_72), 153 KEY _field_115 (_field_115), 154 KEY _field_122 (_field_122) 155); 156 157 158INSERT INTO t1 VALUES (1,'admin','21232f297a57a5a743894a0e4a801fc3',0,1,NULL,NULL); 159INSERT INTO t1 VALUES (2,'hroberts','7415275a8c95952901e42b13a6b78566',0,1,NULL,NULL); 160INSERT INTO t1 VALUES (3,'guest','d41d8cd98f00b204e9800998ecf8427e',1,0,NULL,NULL); 161 162 163CREATE TABLE t2 ( 164 seq_0_id bigint(21) DEFAULT '0' NOT NULL, 165 seq_1_id bigint(21) DEFAULT '0' NOT NULL, 166 PRIMARY KEY (seq_0_id,seq_1_id) 167); 168 169 170INSERT INTO t2 VALUES (1,1); 171INSERT INTO t2 VALUES (2,1); 172INSERT INTO t2 VALUES (2,2); 173 174CREATE TABLE t3 ( 175 t3_id bigint(21) NOT NULL auto_increment, 176 _field_131 varchar(128), 177 _field_133 tinyint(4) DEFAULT '0' NOT NULL, 178 _field_135 datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, 179 _field_137 tinyint(4), 180 _field_139 datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, 181 _field_140 blob, 182 _field_142 tinyint(4) DEFAULT '0' NOT NULL, 183 _field_145 tinyint(4) DEFAULT '0' NOT NULL, 184 _field_148 tinyint(4) DEFAULT '0' NOT NULL, 185 PRIMARY KEY (t3_id), 186 KEY _field_133 (_field_133), 187 KEY _field_135 (_field_135), 188 KEY _field_139 (_field_139), 189 KEY _field_142 (_field_142), 190 KEY _field_145 (_field_145), 191 KEY _field_148 (_field_148) 192); 193 194 195INSERT INTO t3 VALUES (1,'test job 1',0,'0000-00-00 00:00:00',0,'1999-02-25 22:43:32','test\r\njob\r\n1',0,0,0); 196INSERT INTO t3 VALUES (2,'test job 2',0,'0000-00-00 00:00:00',0,'1999-02-26 21:08:04','',0,0,0); 197 198 199CREATE TABLE t4 ( 200 seq_0_id bigint(21) DEFAULT '0' NOT NULL, 201 seq_1_id bigint(21) DEFAULT '0' NOT NULL, 202 PRIMARY KEY (seq_0_id,seq_1_id) 203); 204 205 206INSERT INTO t4 VALUES (1,1); 207INSERT INTO t4 VALUES (2,1); 208 209CREATE TABLE t5 ( 210 t5_id bigint(21) NOT NULL auto_increment, 211 _field_149 tinyint(4), 212 _field_156 varchar(128) DEFAULT '' NOT NULL, 213 _field_157 varchar(128) DEFAULT '' NOT NULL, 214 _field_158 varchar(128) DEFAULT '' NOT NULL, 215 _field_159 varchar(128) DEFAULT '' NOT NULL, 216 _field_160 varchar(128) DEFAULT '' NOT NULL, 217 _field_161 varchar(128) DEFAULT '' NOT NULL, 218 PRIMARY KEY (t5_id), 219 KEY _field_156 (_field_156), 220 KEY _field_157 (_field_157), 221 KEY _field_158 (_field_158), 222 KEY _field_159 (_field_159), 223 KEY _field_160 (_field_160), 224 KEY _field_161 (_field_161) 225); 226 227 228INSERT INTO t5 VALUES (1,0,'tomato','','','','',''); 229INSERT INTO t5 VALUES (2,0,'cilantro','','','','',''); 230 231CREATE TABLE t6 ( 232 seq_0_id bigint(21) DEFAULT '0' NOT NULL, 233 seq_1_id bigint(21) DEFAULT '0' NOT NULL, 234 PRIMARY KEY (seq_0_id,seq_1_id) 235); 236 237INSERT INTO t6 VALUES (1,1); 238INSERT INTO t6 VALUES (1,2); 239INSERT INTO t6 VALUES (2,2); 240 241CREATE TABLE t7 ( 242 t7_id bigint(21) NOT NULL auto_increment, 243 _field_143 tinyint(4), 244 _field_165 varchar(32), 245 _field_166 smallint(6) DEFAULT '0' NOT NULL, 246 PRIMARY KEY (t7_id), 247 KEY _field_166 (_field_166) 248); 249 250 251INSERT INTO t7 VALUES (1,0,'High',1); 252INSERT INTO t7 VALUES (2,0,'Medium',2); 253INSERT INTO t7 VALUES (3,0,'Low',3); 254 255select replace(t3._field_140, "\r","^M"),t3_id,min(t3._field_131), min(t3._field_135), min(t3._field_139), min(t3._field_137), min(link_alias_142._field_165), min(link_alias_133._field_72), min(t3._field_145), min(link_alias_148._field_156), replace(min(t3._field_140), "\r","^M"),t3.t3_id from t3 left join t4 on t4.seq_0_id = t3.t3_id left join t7 link_alias_142 on t4.seq_1_id = link_alias_142.t7_id left join t6 on t6.seq_0_id = t3.t3_id left join t1 link_alias_133 on t6.seq_1_id = link_alias_133.t1_id left join t2 on t2.seq_0_id = t3.t3_id left join t5 link_alias_148 on t2.seq_1_id = link_alias_148.t5_id where t3.t3_id in (1) group by t3.t3_id order by link_alias_142._field_166, _field_139, link_alias_133._field_72, _field_135, link_alias_148._field_156; 256 257drop table t1,t2,t3,t4,t5,t6,t7; 258 259# 260# Test of reverse with empty blob 261# 262 263create table t1 (a blob); 264insert into t1 values ("empty"),(""); 265select a,reverse(a) from t1; 266drop table t1; 267 268# 269# Test of BLOB:s with NULL keys. 270# 271 272create table t1 (a blob, key (a(10))); 273insert into t1 values ("bye"),("hello"),("hello"),("hello word"); 274select * from t1 where a like "hello%"; 275drop table t1; 276 277# 278# Test of found bug in group on text key 279# 280 281CREATE TABLE t1 ( 282 f1 int(11) DEFAULT '0' NOT NULL, 283 f2 varchar(16) DEFAULT '' NOT NULL, 284 f5 text, 285 KEY index_name (f1,f2,f5(16)) 286 ); 287INSERT INTO t1 VALUES (0,'traktor','1111111111111'); 288INSERT INTO t1 VALUES (1,'traktor','1111111111111111111111111'); 289select count(*) from t1 where f2='traktor'; 290drop table t1; 291 292# 293# Test of found bug when blob is first key part 294# 295 296create table t1 (foobar tinyblob not null, boggle smallint not null, key (foobar(32), boggle)); 297insert into t1 values ('fish', 10),('bear', 20); 298select foobar, boggle from t1 where foobar = 'fish'; 299select foobar, boggle from t1 where foobar = 'fish' and boggle = 10; 300drop table t1; 301 302# 303# Bug when blob is updated 304# 305 306create table t1 (id integer auto_increment unique,imagem LONGBLOB not null default ''); 307insert into t1 (id) values (1); 308# We have to clean up the path in the results for safe comparison 309eval select 310 charset(load_file('../../std_data/words.dat')), 311 collation(load_file('../../std_data/words.dat')), 312 coercibility(load_file('../../std_data/words.dat')); 313--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR 314eval explain extended select 315 charset(load_file('$MYSQLTEST_VARDIR/std_data/words.dat')), 316 collation(load_file('$MYSQLTEST_VARDIR/std_data/words.dat')), 317 coercibility(load_file('$MYSQLTEST_VARDIR/std_data/words.dat')); 318--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR 319eval update t1 set imagem=load_file('$MYSQLTEST_VARDIR/std_data/words.dat') where id=1; 320select if(imagem is null, "ERROR", "OK"),length(imagem) from t1 where id = 1; 321drop table t1; 322--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR 323eval create table t1 select load_file('$MYSQLTEST_VARDIR/std_data/words.dat') l; 324# We mask out the Privileges column because it differs for embedded server 325--replace_column 8 # 326show full fields from t1; 327drop table t1; 328 329# 330# Test blob's with end space (Bug #1651) 331# This is a bit changed since we now have true varchar 332# 333 334create table t1 (id integer primary key auto_increment, txt text not null, unique index txt_index (txt (20))); 335--error ER_DUP_ENTRY 336insert into t1 (txt) values ('Chevy'), ('Chevy '); 337--error ER_DUP_ENTRY 338insert into t1 (txt) values ('Chevy'), ('CHEVY'); 339alter table t1 drop index txt_index, add index txt_index (txt(20)); 340insert into t1 (txt) values ('Chevy '); 341select * from t1 where txt='Chevy'; 342select * from t1 where txt='Chevy '; 343select * from t1 where txt='Chevy ' or txt='Chevy'; 344select * from t1 where txt='Chevy' or txt='Chevy '; 345select * from t1 where id='1' or id='2'; 346insert into t1 (txt) values('Ford'); 347select * from t1 where txt='Chevy' or txt='Chevy ' or txt='Ford'; 348select * from t1 where txt='Chevy' or txt='Chevy '; 349select * from t1 where txt='Chevy' or txt='Chevy ' or txt=' Chevy'; 350select * from t1 where txt in ('Chevy ','Chevy'); 351select * from t1 where txt in ('Chevy'); 352select * from t1 where txt between 'Chevy' and 'Chevy'; 353select * from t1 where txt between 'Chevy' and 'Chevy' or txt='Chevy '; 354select * from t1 where txt between 'Chevy' and 'Chevy '; 355select * from t1 where txt < 'Chevy '; 356select * from t1 where txt <= 'Chevy'; 357select * from t1 where txt > 'Chevy'; 358select * from t1 where txt >= 'Chevy'; 359drop table t1; 360 361create table t1 (id integer primary key auto_increment, txt text, index txt_index (txt (20))); 362insert into t1 (txt) values 363 ('Chevy'), ('Chevy '), (NULL), ('Honda'), ('Subaru'), ('Honda'); 364select * from t1 where txt='Chevy' or txt is NULL; 365explain select * from t1 where txt='Chevy' or txt is NULL; 366explain select * from t1 FORCE INDEX (`txt_index`) where txt='Chevy' or txt is NULL; 367select * from t1 where txt='Chevy '; 368select * from t1 where txt='Chevy ' or txt='Chevy'; 369select * from t1 where txt='Chevy' or txt='Chevy '; 370select * from t1 where id='1' or id='2'; 371insert into t1 (txt) values('Ford'); 372select * from t1 where txt='Chevy' or txt='Chevy ' or txt='Ford'; 373select * from t1 where txt='Chevy' or txt='Chevy '; 374select * from t1 where txt='Chevy' or txt='Chevy ' or txt=' Chevy'; 375select * from t1 where txt in ('Chevy ','Chevy'); 376select * from t1 where txt in ('Chevy'); 377select * from t1 where txt between 'Chevy' and 'Chevy'; 378select * from t1 where txt between 'Chevy' and 'Chevy' or txt='Chevy '; 379select * from t1 where txt between 'Chevy' and 'Chevy '; 380select * from t1 where txt < 'Chevy '; 381select * from t1 where txt < 'Chevy ' or txt is NULL; 382select * from t1 where txt <= 'Chevy'; 383select * from t1 where txt > 'Chevy'; 384select * from t1 where txt >= 'Chevy'; 385alter table t1 modify column txt blob; 386explain select * from t1 where txt='Chevy' or txt is NULL; 387select * from t1 where txt='Chevy' or txt is NULL; 388explain select * from t1 where txt='Chevy' or txt is NULL order by txt; 389select * from t1 where txt='Chevy' or txt is NULL order by txt; 390drop table t1; 391 392CREATE TABLE t1 ( i int(11) NOT NULL default '0', c text NOT NULL, d varchar(1) NOT NULL DEFAULT ' ', PRIMARY KEY (i), KEY (c(1),d)); 393INSERT t1 (i, c) VALUES (1,''),(2,''),(3,'asdfh'),(4,''); 394select max(i) from t1 where c = ''; 395drop table t1; 396 397# End of 4.1 tests 398 399# 400# Bug#11657: Creation of secondary index fails 401# 402create table t1 (a int, b int, c tinyblob, d int, e int); 403alter table t1 add primary key (a,b,c(255),d); 404alter table t1 add key (a,b,d,e); 405show create table t1; 406drop table t1; 407 408# 409# Test that blob's and varbinary are sorted according to length 410# 411 412CREATE table t1 (a blob); 413insert into t1 values ('b'),('a\0'),('a'),('a '),('aa'),(NULL); 414select hex(a) from t1 order by a; 415select hex(concat(a,'\0')) as b from t1 order by concat(a,'\0'); 416alter table t1 modify a varbinary(5); 417select hex(a) from t1 order by a; 418select hex(concat(a,'\0')) as b from t1 order by concat(a,'\0'); 419alter table t1 modify a char(5); 420select hex(a) from t1 order by a; 421select hex(concat(a,'\0')) as b from t1 order by concat(a,'\0'); 422alter table t1 modify a binary(5); 423select hex(a) from t1 order by a; 424select hex(concat(a,'\0')) as b from t1 order by concat(a,'\0'); 425drop table t1; 426 427# 428# Bug #19489: Inconsistent support for DEFAULT in TEXT columns 429# 430create table t1 (a text default ''); 431show create table t1; 432insert into t1 values (default); 433select * from t1; 434drop table t1; 435set @@sql_mode='TRADITIONAL'; 436create table t1 (a text default ''); 437show create table t1; 438drop table t1; 439set @@sql_mode=''; 440 441# 442# Bug #32282: TEXT silently truncates when value is exactly 65536 bytes 443# 444 445CREATE TABLE t (c TEXT CHARSET ASCII); 446INSERT INTO t (c) VALUES (REPEAT('1',65537)); 447INSERT INTO t (c) VALUES (REPEAT('2',65536)); 448INSERT INTO t (c) VALUES (REPEAT('3',65535)); 449SELECT LENGTH(c), CHAR_LENGTH(c) FROM t; 450DROP TABLE t; 451# Bug#15776: 32-bit signed int used for length of blob 452# """LONGBLOB: A BLOB column with a maximum length of 4,294,967,295 or 4GB.""" 453# 454# Conditions should be in this order: 455# A size is not in the allowed bounds. 456# If the type is char-ish AND size is within the max blob size: 457# raise ER_TOO_BIG_FIELDLENGTH (suggest using BLOB) 458# If size is too small: 459# raise ER_PARSE_ERROR 460# raise ER_TOO_BIG_DISPLAYWIDTH 461 462# BLOB and TEXT types 463--disable_warnings 464drop table if exists b15776; 465--enable_warnings 466create table b15776 (data blob(2147483647)); 467drop table b15776; 468--error ER_PARSE_ERROR 469create table b15776 (data blob(-1)); 470create table b15776 (data blob(2147483648)); 471drop table b15776; 472create table b15776 (data blob(4294967294)); 473drop table b15776; 474create table b15776 (data blob(4294967295)); 475drop table b15776; 476--error ER_TOO_BIG_DISPLAYWIDTH 477create table b15776 (data blob(4294967296)); 478 479CREATE TABLE b15776 (a blob(2147483647), b blob(2147483648), c blob(4294967295), a1 text(2147483647), b1 text(2147483648), c1 text(4294967295) ); 480show columns from b15776; 481drop table b15776; 482 483--error ER_TOO_BIG_DISPLAYWIDTH 484CREATE TABLE b15776 (a blob(4294967296)); 485--error ER_TOO_BIG_DISPLAYWIDTH 486CREATE TABLE b15776 (a text(4294967296)); 487--error ER_TOO_BIG_DISPLAYWIDTH 488CREATE TABLE b15776 (a blob(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)); 489--error ER_TOO_BIG_DISPLAYWIDTH 490CREATE TABLE b15776 (a text(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)); 491 492# Int types 493# "Another extension is supported by MySQL for optionally specifying the 494# display width of integer data types in parentheses following the base keyword 495# for the type (for example, INT(4)). This optional display width is used to 496# display integer values having a width less than the width specified for the 497# column by left-padding them with spaces." § Numeric Types 498CREATE TABLE b15776 (a int(0)); # 0 is special case, means default size 499INSERT INTO b15776 values (NULL), (1), (42), (654); 500SELECT * from b15776 ORDER BY a; 501DROP TABLE b15776; 502--error ER_PARSE_ERROR 503CREATE TABLE b15776 (a int(-1)); 504CREATE TABLE b15776 (a int(255)); 505DROP TABLE b15776; 506--error ER_TOO_BIG_DISPLAYWIDTH 507CREATE TABLE b15776 (a int(256)); 508--error ER_PARSE_ERROR 509CREATE TABLE b15776 (data blob(-1)); 510 511# Char types 512# Recommend BLOB 513--error ER_TOO_BIG_FIELDLENGTH 514CREATE TABLE b15776 (a char(2147483647)); 515--error ER_TOO_BIG_FIELDLENGTH 516CREATE TABLE b15776 (a char(2147483648)); 517--error ER_TOO_BIG_FIELDLENGTH 518CREATE TABLE b15776 (a char(4294967295)); 519# Even BLOB won't hold 520--error ER_TOO_BIG_FIELDLENGTH 521CREATE TABLE b15776 (a char(4294967296)); 522 523 524# Other numeric-ish types 525## For year, widths not "2" or "4" are silently rewritten to "4". But 526## When we complain about it, we say that the max is 255. We may be 527## talking about different things. It's confusing. 528--replace_result 4294967295 ? 0 ? 529CREATE TABLE b15776 (a year(4294967295)); 530INSERT INTO b15776 VALUES (42); 531SELECT * FROM b15776; 532DROP TABLE b15776; 533CREATE TABLE b15776 (a year(4294967296)); 534SHOW CREATE TABLE b15776; 535DROP TABLE b15776; 536CREATE TABLE b15776 (a year(0)); # 0 is special case, means default size 537DROP TABLE b15776; 538--error ER_PARSE_ERROR 539CREATE TABLE b15776 (a year(-2)); 540 541## For timestamp, we silently rewrite widths to 14 or 19. 542--error ER_TOO_BIG_PRECISION 543CREATE TABLE b15776 (a timestamp(4294967294)); 544--error ER_TOO_BIG_PRECISION 545CREATE TABLE b15776 (a timestamp(4294967295)); 546--error ER_TOO_BIG_PRECISION 547CREATE TABLE b15776 (a timestamp(4294967296)); 548--error ER_PARSE_ERROR 549CREATE TABLE b15776 (a timestamp(-1)); 550--error ER_PARSE_ERROR 551CREATE TABLE b15776 (a timestamp(-2)); 552 553# We've already tested the case, but this should visually show that 554# widths that are too large to be interpreted cause DISPLAYWIDTH errors. 555--error ER_TOO_BIG_DISPLAYWIDTH 556CREATE TABLE b15776 (a int(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)); 557--error ER_TOO_BIG_FIELDLENGTH 558CREATE TABLE b15776 (a char(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)); 559CREATE TABLE b15776 (a year(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)); 560SHOW CREATE TABLE b15776; 561DROP TABLE b15776; 562 563## Do not select, too much memory needed. 564CREATE TABLE b15776 select cast(null as char(4294967295)); 565show columns from b15776; 566drop table b15776; 567CREATE TABLE b15776 select cast(null as nchar(4294967295)); 568show columns from b15776; 569drop table b15776; 570CREATE TABLE b15776 select cast(null as binary(4294967295)); 571show columns from b15776; 572drop table b15776; 573 574explain select cast(1 as char(4294967295)); 575explain select cast(1 as nchar(4294967295)); 576explain select cast(1 as binary(4294967295)); 577 578--error ER_TOO_BIG_DISPLAYWIDTH 579explain select cast(1 as char(4294967296)); 580--error ER_TOO_BIG_DISPLAYWIDTH 581explain select cast(1 as nchar(4294967296)); 582--error ER_TOO_BIG_DISPLAYWIDTH 583explain select cast(1 as binary(4294967296)); 584 585--error ER_PARSE_ERROR 586explain select cast(1 as decimal(-1)); 587explain select cast(1 as decimal(64, 30)); 588# It's not as important which errors are raised for these, since the 589# limit is nowhere near 2**32. We may fix these eventually to take 590# 4294967295 and still reject it because it's greater than 64 or 30, 591# but that's not a high priority and the parser needn't worry about 592# such a weird case. 593--error ER_TOO_BIG_SCALE,ER_PARSE_ERROR 594explain select cast(1 as decimal(64, 999999999999999999999999999999)); 595--error ER_TOO_BIG_PRECISION,ER_PARSE_ERROR 596explain select cast(1 as decimal(4294967296)); 597--error ER_TOO_BIG_PRECISION,ER_PARSE_ERROR 598explain select cast(1 as decimal(999999999999999999999999999999999999)); 599 600explain select convert(1, char(4294967295)); 601--error ER_TOO_BIG_DISPLAYWIDTH 602explain select convert(1, char(4294967296)); 603--error ER_TOO_BIG_DISPLAYWIDTH 604explain select convert(1, char(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)); 605explain select convert(1, nchar(4294967295)); 606--error ER_TOO_BIG_DISPLAYWIDTH 607explain select convert(1, nchar(4294967296)); 608--error ER_TOO_BIG_DISPLAYWIDTH 609explain select convert(1, nchar(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)); 610explain select convert(1, binary(4294967295)); 611--error ER_TOO_BIG_DISPLAYWIDTH 612explain select convert(1, binary(4294967296)); 613--error ER_TOO_BIG_DISPLAYWIDTH 614explain select convert(1, binary(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)); 615 616--echo End of 5.0 tests 617 618# 619# Bug #33969: Updating a text field via a left join 620# 621 622CREATE TABLE t1(id INT NOT NULL); 623CREATE TABLE t2(id INT NOT NULL, c TEXT NOT NULL); 624 625INSERT INTO t1 VALUES (1); 626INSERT INTO t2 VALUES (1, ''); 627 628UPDATE t2 SET c = REPEAT('1', 70000); 629SELECT LENGTH(c) FROM t2; 630 631UPDATE t1 LEFT JOIN t2 USING(id) SET t2.c = REPEAT('1', 70000) WHERE t1.id = 1; 632SELECT LENGTH(c) FROM t2; 633 634DROP TABLE t1, t2; 635 636--echo # Bug #52160: crash and inconsistent results when grouping 637--echo # by a function and column 638 639CREATE FUNCTION f1() RETURNS TINYBLOB RETURN 1; 640 641CREATE TABLE t1(a CHAR(1)); 642INSERT INTO t1 VALUES ('0'), ('0'); 643 644SELECT COUNT(*) FROM t1 GROUP BY f1(), a; 645 646DROP FUNCTION f1; 647DROP TABLE t1; 648 649--echo End of 5.1 tests 650 651--echo # 652--echo # Start of 5.5 tests 653--echo # 654 655# 656# Problem when comparing blobs #778901 657# 658 659CREATE TABLE t1 ( f1 blob, f2 blob ); 660INSERT INTO t1 VALUES ('',''); 661SELECT f1,f2,"found row" FROM t1 WHERE f1 = f2 ; 662DROP TABLE t1; 663 664--echo # 665--echo # MDEV-9319 ALTER from a bigger to a smaller blob type truncates too much data 666--echo # 667CREATE TABLE t1 (a MEDIUMBLOB); 668INSERT INTO t1 VALUES (REPEAT(0x61,128000)); 669SELECT LENGTH(a) FROM t1; 670ALTER TABLE t1 MODIFY a BLOB; 671SELECT LENGTH(a) FROM t1; 672DROP TABLE t1; 673 674CREATE TABLE t1 (a BLOB); 675INSERT INTO t1 VALUES (REPEAT(0x61,65000)); 676SELECT LENGTH(a) FROM t1; 677ALTER TABLE t1 MODIFY a TINYBLOB; 678SELECT LENGTH(a) FROM t1; 679DROP TABLE t1; 680 681--echo # 682--echo # End of 5.5 tests 683--echo # 684 685 686--echo # 687--echo # Start of 10.2 test 688--echo # 689 690--echo # 691--echo # MDEV-12809 Bad column type created for TEXT(1431655798) CHARACTER SET utf8 692--echo # 693 694CREATE TABLE t1 (a TEXT(1431655798) CHARACTER SET utf8); 695SHOW CREATE TABLE t1; 696DROP TABLE t1; 697 698# ALTER SET DEFAULT 699create table t1 (a int); 700alter table t1 add column b blob, alter column b set default "foo"; 701show create table t1; 702drop table t1; 703 704--echo # 705--echo # End of 10.2 test 706--echo # 707 708 709--echo # 710--echo # Start of 10.4 test 711--echo # 712 713--echo # 714--echo # MDEV-19317 TEXT column accepts too long literals as a default value 715--echo # 716 717EXECUTE IMMEDIATE 'CREATE OR REPLACE TABLE t1 (a TINYTEXT DEFAULT ?)' USING REPEAT('a', 255); 718INSERT INTO t1 VALUES (); 719SELECT LENGTH(a), LENGTH(DEFAULT(a)) FROM t1; 720DROP TABLE t1; 721 722--error ER_INVALID_DEFAULT 723EXECUTE IMMEDIATE 'CREATE OR REPLACE TABLE t1 (a TINYTEXT DEFAULT ?)' USING REPEAT('a', 256); 724 725--error ER_INVALID_DEFAULT 726CREATE OR REPLACE TABLE t1 (a TINYTEXT DEFAULT 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'); 727 728 729EXECUTE IMMEDIATE 'CREATE OR REPLACE TABLE t1 (a TEXT DEFAULT ?)' USING REPEAT('a', 256); 730INSERT INTO t1 VALUES (); 731SELECT LENGTH(a), LENGTH(DEFAULT(a)) FROM t1; 732DROP TABLE t1; 733 734CREATE OR REPLACE TABLE t1 (a TEXT DEFAULT 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'); 735INSERT INTO t1 VALUES (); 736SELECT LENGTH(a), LENGTH(DEFAULT(a)) FROM t1; 737DROP TABLE t1; 738 739--echo # 740--echo # ASAN heap-use-after-free in my_hash_sort_bin or ER_KEY_NOT_FOUND 741--echo # upon INSERT into table with long unique blob 742--echo # 743 744# Note that this test worked with myisam as it caches blobs differently than 745# InnoDB 746 747SET @save_sql_mode=@@sql_mode; 748SET SQL_MODE='STRICT_ALL_TABLES'; 749 750CREATE TABLE t1 (a INT, b BLOB) ENGINE=innodb; 751INSERT INTO t1 VALUES (1,'foo'),(2,'bar'); 752CREATE TABLE t2 (c BIT, d BLOB, UNIQUE(d)) ENGINE=innodb; 753--error ER_DATA_TOO_LONG 754INSERT INTO t2 SELECT * FROM t1; 755select * from t2; 756DROP TABLE t1, t2; 757SET @@sql_mode=@save_sql_mode; 758 759--echo # 760--echo # End of 10.4 test 761--echo # 762