information_schema.test 28.4 KB
Newer Older
1
# This test  uses grants, which can't get tested for embedded server
2
-- source include/not_embedded.inc
3 4 5 6

# Test for information_schema.schemata &
# show databases

7
--disable_warnings
8 9
DROP TABLE IF EXISTS t0,t1,t2,t3,t4,t5;
DROP VIEW IF EXISTS v1;
10 11 12
--enable_warnings


13
show variables where variable_name like "skip_show_database";
14 15
grant select, update, execute on test.* to mysqltest_2@localhost;
grant select, update on test.* to mysqltest_1@localhost;
16 17 18
create user mysqltest_3@localhost;
create user mysqltest_3;

19 20 21 22 23

select * from information_schema.SCHEMATA where schema_name > 'm';
select schema_name from information_schema.schemata;
show databases like 't%';
show databases;
24
show databases where `database` = 't%';
25 26 27 28

# Test for information_schema.tables &
# show tables

29 30
create database mysqltest;
create table mysqltest.t1(a int, b VARCHAR(30), KEY string_data (b));
31 32
create table test.t2(a int);
create table t3(a int, KEY a_data (a));
33
create table mysqltest.t4(a int);
34 35
create table t5 (id int auto_increment primary key);
insert into t5 values (10);
36 37
create view v1 (c) as select table_name from information_schema.TABLES;
select * from v1;
38 39 40 41 42

select c,table_name from v1 
inner join information_schema.TABLES v2 on (v1.c=v2.table_name)
where v1.c like "t%";

43 44 45 46 47 48 49 50 51
select c,table_name from v1 
left join information_schema.TABLES v2 on (v1.c=v2.table_name)
where v1.c like "t%";

select c, v2.table_name from v1
right join information_schema.TABLES v2 on (v1.c=v2.table_name)
where v1.c like "t%";

select table_name from information_schema.TABLES
52
where table_schema = "mysqltest" and table_name like "t%";
53

54
select * from information_schema.STATISTICS where TABLE_SCHEMA = "mysqltest";
55
show keys from t3 where Key_name = "a_data";
56 57

show tables like 't%';
58
--replace_column 8 # 12 # 13 #
59 60 61 62 63 64
show table status;
show full columns from t3 like "a%";
show full columns from mysql.db like "Insert%";
show full columns from v1;
select * from information_schema.COLUMNS where table_name="t1"
and column_name= "a";
65 66
show columns from mysqltest.t1 where field like "%a%";

67
create view mysqltest.v1 (c) as select a from mysqltest.t1;
68
grant select (a) on mysqltest.t1 to mysqltest_2@localhost;
69
grant select on mysqltest.v1 to mysqltest_3;
70 71 72 73 74
connect (user3,localhost,mysqltest_2,,);
connection user3;
select table_name, column_name, privileges from information_schema.columns 
where table_schema = 'mysqltest' and table_name = 't1';
show columns from mysqltest.t1;
75 76 77 78
connect (user4,localhost,mysqltest_3,,mysqltest);
connection user4;
select table_name, column_name, privileges from information_schema.columns
where table_schema = 'mysqltest' and table_name = 'v1';
79
connection default;
80

81
drop view v1, mysqltest.v1;
82
drop tables mysqltest.t4, mysqltest.t1, t2, t3, t5;
83
drop database mysqltest;
84 85 86 87 88 89 90

# Test for information_schema.CHARACTER_SETS &
# SHOW CHARACTER SET

select * from information_schema.CHARACTER_SETS
where CHARACTER_SET_NAME like 'latin1%';
SHOW CHARACTER SET LIKE 'latin1%';
91
SHOW CHARACTER SET WHERE charset like 'latin1%';
92 93 94 95

# Test for information_schema.COLLATIONS &
# SHOW COLLATION

96
--replace_column 5 #
97 98
select * from information_schema.COLLATIONS
where COLLATION_NAME like 'latin1%';
99
--replace_column 5 #
100
SHOW COLLATION LIKE 'latin1%';
101
--replace_column 5 #
102
SHOW COLLATION WHERE collation like 'latin1%';
103 104 105 106 107 108 109

select * from information_schema.COLLATION_CHARACTER_SET_APPLICABILITY
where COLLATION_NAME like 'latin1%';

# Test for information_schema.ROUTINES &
#

110 111 112 113 114 115
--disable_warnings
drop procedure if exists sel2;
drop function if exists sub1;
drop function if exists sub2;
--enable_warnings

116 117 118 119 120 121 122 123 124 125
create function sub1(i int) returns int
  return i+1;
delimiter |;
create procedure sel2()
begin
  select * from t1;
  select * from t2;
end|
delimiter ;|

126 127 128 129 130 131
#
# Bug#7222 information_schema: errors in "routines"
#
select parameter_style, sql_data_access, dtd_identifier 
from information_schema.routines;

132 133 134 135 136 137 138 139 140 141 142 143 144
--replace_column 5 # 6 #
show procedure status;
--replace_column 5 # 6 #
show function status;
select a.ROUTINE_NAME from information_schema.ROUTINES a,
information_schema.SCHEMATA b where
a.ROUTINE_SCHEMA = b.SCHEMA_NAME;
--replace_column 3 #
explain select a.ROUTINE_NAME from information_schema.ROUTINES a,
information_schema.SCHEMATA b where
a.ROUTINE_SCHEMA = b.SCHEMA_NAME;

select a.ROUTINE_NAME, b.name from information_schema.ROUTINES a,
145
mysql.proc b where a.ROUTINE_NAME = convert(b.name using utf8) order by 1;
146 147
select count(*) from information_schema.ROUTINES;

148 149 150 151 152
create view v1 as select routine_schema, routine_name from information_schema.routines 
order by routine_schema, routine_name;
select * from v1;
drop view v1;

153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
connect (user1,localhost,mysqltest_1,,);
connection user1;
select ROUTINE_NAME, ROUTINE_DEFINITION from information_schema.ROUTINES;
--error 1305
show create function sub1;
connection user3;
select ROUTINE_NAME, ROUTINE_DEFINITION from information_schema.ROUTINES;
connection default;
grant all privileges on test.* to mysqltest_1@localhost;
connect (user2,localhost,mysqltest_1,,);
connection user2;
select ROUTINE_NAME, ROUTINE_DEFINITION from information_schema.ROUTINES;
create function sub2(i int) returns int
  return i+1;
select ROUTINE_NAME, ROUTINE_DEFINITION from information_schema.ROUTINES;
show create procedure sel2;
show create function sub1;
show create function sub2;
171 172
--replace_column 5 # 6 #
show function status like "sub2";
173 174 175 176 177
connection default;
disconnect user1;
drop function sub2;
show create procedure sel2;

178 179 180
#
# Test for views
#
181
create view v0 (c) as select schema_name from information_schema.schemata;
182 183 184
select * from v0;
--replace_column 3 #
explain select * from v0;
185
create view v1 (c) as select table_name from information_schema.tables
186 187
where table_name="v1";
select * from v1;
188
create view v2 (c) as select column_name from information_schema.columns
189 190
where table_name="v2";
select * from v2;
191
create view v3 (c) as select CHARACTER_SET_NAME from information_schema.character_sets
192 193
where CHARACTER_SET_NAME like "latin1%";
select * from v3;
194
create view v4 (c) as select COLLATION_NAME from information_schema.collations
195 196 197
where COLLATION_NAME like "latin1%";
select * from v4;
show keys from v4;
198
select * from information_schema.views where TABLE_NAME like "v%";
199 200 201 202 203 204 205 206 207 208 209 210 211
drop view v0, v1, v2, v3, v4;

#
# Test for privileges tables
#
create table t1 (a int);
grant select,update,insert on t1 to mysqltest_1@localhost;
grant select (a), update (a),insert(a), references(a) on t1 to mysqltest_1@localhost;
grant all on test.* to mysqltest_1@localhost with grant option;
select * from information_schema.USER_PRIVILEGES where grantee like '%mysqltest_1%';
select * from information_schema.SCHEMA_PRIVILEGES where grantee like '%mysqltest_1%';
select * from information_schema.TABLE_PRIVILEGES where grantee like '%mysqltest_1%';
select * from information_schema.COLUMN_PRIVILEGES where grantee like '%mysqltest_1%';
212 213 214 215
delete from mysql.user where user like 'mysqltest%';
delete from mysql.db where user like 'mysqltest%';
delete from mysql.tables_priv where user like 'mysqltest%';
delete from mysql.columns_priv where user like 'mysqltest%';
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
flush privileges;
drop table t1;


#
# Test for KEY_COLUMN_USAGE & TABLE_CONSTRAINTS tables
#

create table t1 (a int null, primary key(a));
alter table t1 add constraint constraint_1 unique (a);
alter table t1 add constraint unique key_1(a);
alter table t1 add constraint constraint_2 unique key_2(a);
show create table t1;
select * from information_schema.TABLE_CONSTRAINTS where
TABLE_SCHEMA= "test";
select * from information_schema.KEY_COLUMN_USAGE where
TABLE_SCHEMA= "test";

234
connection user2;
235 236 237
select table_name from information_schema.TABLES where table_schema like "test%";
select table_name,column_name from information_schema.COLUMNS where table_schema like "test%";
select ROUTINE_NAME from information_schema.ROUTINES;
238
disconnect user2;
239 240 241 242 243
connection default;
delete from mysql.user where user='mysqltest_1';
drop table t1;
drop procedure sel2;
drop function sub1;
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260

create table t1(a int);
create view v1 (c) as select a from t1 with check option;
create view v2 (c) as select a from t1 WITH LOCAL CHECK OPTION;
create view v3 (c) as select a from t1 WITH CASCADED CHECK OPTION;
select * from information_schema.views;
grant select (a) on test.t1 to joe@localhost with grant option;
select * from INFORMATION_SCHEMA.COLUMN_PRIVILEGES;
select * from INFORMATION_SCHEMA.TABLE_PRIVILEGES;
drop view v1, v2, v3;
drop table t1;
delete from mysql.user where user='joe';
delete from mysql.db where user='joe';
delete from mysql.tables_priv where user='joe';
delete from mysql.columns_priv where user='joe';
flush privileges;

261 262
# QQ This results in NULLs instead of the version numbers when
# QQ a LOCK TABLES is in effect when selecting from
263 264
# QQ information_schema.tables.

265
--disable_parsing # until bug is fixed
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
delimiter //;
create procedure px5 ()
begin
declare v int;
declare c cursor for select version from
information_schema.tables where table_schema <> 'information_schema';
open c;
fetch c into v;
select v;
close c;
end;//

call px5()//
call px5()//
delimiter ;//
select sql_mode from information_schema.ROUTINES;
drop procedure px5;
--enable_parsing
284

285 286 287 288
create table t1 (a int not null auto_increment,b int, primary key (a));
insert into t1 values (1,1),(NULL,3),(NULL,4);
select AUTO_INCREMENT from information_schema.tables where table_name = 't1';
drop table t1;
289 290 291 292 293 294 295 296

create table t1 (s1 int);
insert into t1 values (0),(9),(0);
select s1 from t1 where s1 in (select version from
information_schema.tables) union select version from
information_schema.tables;
drop table t1;

297
SHOW CREATE TABLE INFORMATION_SCHEMA.character_sets;
298
set names latin2;
299
SHOW CREATE TABLE INFORMATION_SCHEMA.character_sets;
300 301 302 303 304 305 306
set names latin1;

create table t1 select * from information_schema.CHARACTER_SETS
where CHARACTER_SET_NAME like "latin1";
select * from t1;
alter table t1 default character set utf8;
show create table t1;
307
drop table t1;
308

309 310 311 312 313 314 315 316 317
create view v1 as select * from information_schema.TABLES;
drop view v1;
create table t1(a NUMERIC(5,3), b NUMERIC(5,1), c float(5,2),
 d NUMERIC(6,4), e float, f DECIMAL(6,3), g int(11), h DOUBLE(10,3),
 i DOUBLE);
select COLUMN_NAME,COLUMN_TYPE, CHARACTER_MAXIMUM_LENGTH, 
 CHARACTER_OCTET_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE
from information_schema.columns where table_name= 't1';
drop table t1;
318 319 320 321 322 323 324 325 326 327 328 329 330

create table t115 as select table_name, column_name, column_type
from information_schema.columns where table_name = 'proc';
select * from t115;
drop table t115;

delimiter //;
create procedure p108 () begin declare c cursor for select data_type
from information_schema.columns;  open c; open c; end;//
--error 1325
call p108()//
delimiter ;//
drop procedure p108;
331 332 333 334 335 336 337 338 339 340 341 342 343

create view v1 as select A1.table_name from information_schema.TABLES A1
where table_name= "user";
select * from v1;
drop view v1;

create view vo as select 'a' union select 'a';  
show index from vo;
select * from information_schema.TABLE_CONSTRAINTS where
TABLE_NAME= "vo";
select * from information_schema.KEY_COLUMN_USAGE where
TABLE_NAME= "vo"; 
drop view vo;
344 345 346 347

select TABLE_NAME,TABLE_TYPE,ENGINE
from information_schema.tables 
where table_schema='information_schema' limit 2;
348
show tables from information_schema like "T%";
349

350
--error 1044
351 352 353 354 355 356 357 358 359
create database information_schema;
use information_schema;
show full tables like "T%";
--error 1109
create table t1(a int);
use test;
show tables;
use information_schema;
show tables like "T%";
360

361 362 363 364 365 366 367
#
# Bug#7210: information_schema: can't access when table-name = reserved word
#
select table_name from tables where table_name='user';
select column_name, privileges from columns
where table_name='user' and column_name like '%o%';

368 369
#
# Bug#7212: information_schema: "Can't find file" errors if storage engine gone
370
# Bug#7211: information_schema: crash if bad view
371 372 373 374 375
#
use test;
create function sub1(i int) returns int
  return i+1;
create table t1(f1 int);
376 377
create view v2 (c) as select f1 from t1;
create view v3 (c) as select sub1(1);
378 379 380
create table t4(f1 int, KEY f1_key (f1));
drop table t1;
drop function sub1;
381 382 383 384
select table_name from information_schema.views
where table_schema='test';
select table_name from information_schema.views
where table_schema='test';
385 386 387 388 389
select column_name from information_schema.columns
where table_schema='test';
select index_name from information_schema.statistics where table_schema='test';
select constraint_name from information_schema.table_constraints
where table_schema='test';
390 391
show create view v2;
show create table v3;
392 393
drop view v2;
drop view v3;
394
drop table t4;
395 396 397 398 399 400

#
# Bug#7213: information_schema: redundant non-standard TABLE_NAMES table
#
--error 1109
select * from information_schema.table_names;
401 402 403 404 405 406 407 408

#
# Bug#2719 information_schema: errors in "columns"
#
select column_type from information_schema.columns
where table_schema="information_schema" and table_name="COLUMNS" and
(column_name="character_set_name" or column_name="collation_name");

409 410 411 412 413 414 415
#
# Bug#2718 information_schema: errors in "tables"
#
select TABLE_ROWS from information_schema.tables where 
table_schema="information_schema" and table_name="COLUMNS";
select table_type from information_schema.tables
where table_schema="mysql" and table_name="user";
416 417 418 419

# test for 'show open tables ... where'
show open tables where `table` like "user";
# test for 'show status ... where'
420
show status where variable_name like "%database%";
421
# test for 'show variables ... where'
422
show variables where variable_name like "skip_show_databas";
423 424 425 426

#
# Bug #7981:SHOW GLOBAL STATUS crashes server
#
427 428
# We don't actually care about the value, just that it doesn't crash.
--replace_column 2 #
429
show global status like "Threads_running";
430 431 432 433 434 435 436 437 438 439 440

#
# Bug #7915  crash,JOIN VIEW, subquery, 
# SELECT .. FROM INFORMATION_SCHEMA.COLUMNS
#
create table t1(f1 int);
create table t2(f2 int);
create view v1 as select * from t1, t2;
set @got_val= (select count(*) from information_schema.columns);
drop view v1;
drop table t1, t2;
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458

#
# Bug #7476: crash on SELECT * FROM INFORMATION_SCHEMA.TABLES
#

CREATE TABLE t_crashme ( f1 BIGINT);
CREATE VIEW a1 (t_CRASHME) AS SELECT f1 FROM t_crashme GROUP BY f1;
CREATE VIEW a2 AS SELECT t_CRASHME FROM a1;
let $tab_count= 65;
--disable_query_log
while ($tab_count)
{
     EVAL CREATE TABLE t_$tab_count (f1 BIGINT);
     dec $tab_count ;
}
--disable_result_log
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES;
--enable_result_log
459
SELECT count(*) FROM INFORMATION_SCHEMA.TABLES;
460 461 462 463 464 465 466 467 468
let $tab_count= 65;
while ($tab_count)
{
     EVAL DROP TABLE t_$tab_count;
     dec $tab_count ;
}
--enable_query_log
drop view a2, a1;
drop table t_crashme;
469 470 471 472 473 474 475 476 477 478

#
# Bug #7215  information_schema: columns are longtext instead of varchar
# Bug #7217  information_schema: columns are varbinary() instead of timestamp
#
select table_schema,table_name, column_name from
information_schema.columns 
where data_type = 'longtext';
select table_name, column_name, data_type from information_schema.columns
where data_type = 'datetime';
479 480 481 482 483 484 485 486 487

#
# Bug #8164  subquery with INFORMATION_SCHEMA.COLUMNS, 100 % CPU
#
SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES A
WHERE NOT EXISTS 
(SELECT * FROM INFORMATION_SCHEMA.COLUMNS B
  WHERE A.TABLE_SCHEMA = B.TABLE_SCHEMA
  AND A.TABLE_NAME = B.TABLE_NAME);
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505

#
# Bug #9344  INFORMATION_SCHEMA, wrong content, numeric columns
#

create table t1
( x_bigint BIGINT,
  x_integer INTEGER,
  x_smallint SMALLINT,
  x_decimal DECIMAL(5,3),
  x_numeric NUMERIC(5,3),
  x_real REAL,
  x_float FLOAT,
  x_double_precision DOUBLE PRECISION );
SELECT COLUMN_NAME, CHARACTER_MAXIMUM_LENGTH, CHARACTER_OCTET_LENGTH
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME= 't1';
drop table t1;
506 507 508 509 510

#
# Bug#10261  INFORMATION_SCHEMA.COLUMNS, incomplete result for non root user
#

511
grant select on test.* to mysqltest_4@localhost;
512 513
connect (user10261,localhost,mysqltest_4,,);
connection user10261;
514 515 516 517
SELECT TABLE_NAME, COLUMN_NAME, PRIVILEGES FROM INFORMATION_SCHEMA.COLUMNS 
where COLUMN_NAME='TABLE_NAME';
connection default;
delete from mysql.user where user='mysqltest_4';
518
delete from mysql.db where user='mysqltest_4';
519
flush privileges;
gluh@mysql.com's avatar
gluh@mysql.com committed
520 521 522

#
# Bug #9404  information_schema: Weird error messages
523 524 525
# with SELECT SUM() ... GROUP BY queries
#
SELECT table_schema, count(*) FROM information_schema.TABLES GROUP BY TABLE_SCHEMA;
gluh@mysql.com's avatar
gluh@mysql.com committed
526

527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561

#
# TRIGGERS table test
#
create table t1 (i int, j int);

delimiter |;
create trigger trg1 before insert on t1 for each row
begin
  if new.j > 10 then
    set new.j := 10;
  end if;
end|
create trigger trg2 before update on t1 for each row
begin
  if old.i % 2 = 0 then
    set new.j := -1;
  end if;
end|
create trigger trg3 after update on t1 for each row
begin
  if new.j = -1 then
    set @fired:= "Yes";
  end if;
end|
delimiter ;|
show triggers;
select * from information_schema.triggers;

drop trigger trg1;
drop trigger trg2;
drop trigger trg3;
drop table t1;


562 563 564 565 566 567 568 569 570 571 572 573
#
# Bug #10964  Information Schema:Authorization check on privilege tables is improper
#

create database mysqltest;
create table mysqltest.t1 (f1 int, f2 int);
create table mysqltest.t2 (f1 int);
grant select (f1) on mysqltest.t1 to user1@localhost;
grant select on mysqltest.t2 to user2@localhost;
grant select on mysqltest.* to user3@localhost;
grant select on *.* to user4@localhost;

574 575 576
connect (con1,localhost,user1,,mysqltest);
connect (con2,localhost,user2,,mysqltest);
connect (con3,localhost,user3,,mysqltest);
577 578
connect (con4,localhost,user4,,);
connection con1;
579 580 581 582
select * from information_schema.column_privileges order by grantee;
select * from information_schema.table_privileges order by grantee;
select * from information_schema.schema_privileges order by grantee;
select * from information_schema.user_privileges order by grantee;
583 584
show grants;
connection con2;
585 586 587 588
select * from information_schema.column_privileges order by grantee;
select * from information_schema.table_privileges order by grantee;
select * from information_schema.schema_privileges order by grantee;
select * from information_schema.user_privileges order by grantee;
589 590
show grants;
connection con3;
591 592 593 594
select * from information_schema.column_privileges order by grantee;
select * from information_schema.table_privileges order by grantee;
select * from information_schema.schema_privileges order by grantee;
select * from information_schema.user_privileges order by grantee;
595 596
show grants;
connection con4;
597 598 599 600 601 602 603 604
select * from information_schema.column_privileges where grantee like '%user%'
order by grantee;
select * from information_schema.table_privileges where grantee like '%user%'
order by grantee;
select * from information_schema.schema_privileges where grantee like '%user%'
order by grantee;
select * from information_schema.user_privileges where grantee like '%user%'
order by grantee;
605 606 607 608 609
show grants;
connection default;
drop user user1@localhost, user2@localhost, user3@localhost, user4@localhost;
use test;
drop database mysqltest;
610 611 612 613

#
# Bug #11055 information_schema: routines.sql_data_access has wrong value
#
614 615 616 617 618
--disable_warnings
drop procedure if exists p1;
drop procedure if exists p2;
--enable_warnings

619 620 621 622 623 624
create procedure p1 () modifies sql data set @a = 5;
create procedure p2 () set @a = 5;
select sql_data_access from information_schema.routines
where specific_name like 'p%';
drop procedure p1;
drop procedure p2;
625 626 627 628 629

#
# Bug #9434 SHOW CREATE DATABASE information_schema;
#
show create database information_schema;
630 631 632

#
# Bug #11057 information_schema: columns table has some questionable contents
aivanov@mysql.com's avatar
aivanov@mysql.com committed
633
# Bug #12301 information_schema: NUMERIC_SCALE must be 0 for integer columns
634 635 636 637 638 639 640 641 642 643 644 645 646
#
create table t1(f1 LONGBLOB, f2 LONGTEXT);
select column_name,data_type,CHARACTER_OCTET_LENGTH,
       CHARACTER_MAXIMUM_LENGTH
from information_schema.columns
where table_name='t1';
drop table t1;
create table t1(f1 tinyint, f2 SMALLINT, f3 mediumint, f4 int,
                f5 BIGINT, f6 BIT, f7 bit(64));
select column_name, NUMERIC_PRECISION, NUMERIC_SCALE
from information_schema.columns
where table_name='t1';
drop table t1;
647 648 649 650 651 652 653 654 655 656 657

#
# Bug #12127 triggers do not show in info_schema before they are used if set to the database
#
create table t1 (f1 integer);
create trigger tr1 after insert on t1 for each row set @test_var=42;
use information_schema;
select trigger_schema, trigger_name from triggers where
trigger_name='tr1';
use test;
drop table t1;
acurtis@xiphis.org's avatar
acurtis@xiphis.org committed
658 659 660 661 662 663 664 665 666

#
# Bug#12518 COLUMN_DEFAULT has wrong value if NOT NULL is set
#
create table t1 (a int not null, b int);
use information_schema;
select column_name, column_default from columns
  where table_schema='test' and table_name='t1';
use test;
667
show columns from t1;
acurtis@xiphis.org's avatar
acurtis@xiphis.org committed
668
drop table t1;
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
669 670 671 672 673 674 675 676 677 678 679 680 681 682

#
# Bug #12636: SHOW TABLE STATUS with where condition containing a subquery
#             over information schema
#

CREATE TABLE t1 (a int);
CREATE TABLE t2 (b int);

--replace_column 8 # 12 # 13 #
SHOW TABLE STATUS FROM test
  WHERE name IN ( SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
                    WHERE TABLE_SCHEMA='test' AND TABLE_TYPE='BASE TABLE');

683 684 685 686 687 688 689 690 691 692 693 694 695
DROP TABLE t1,t2;

#
# Bug #12905 show fields from view behaving erratically with current database
#
create table t1(f1 int);
create view v1 (c) as select f1 from t1;
connect (con5,localhost,root,,*NO-ONE*);
select database();
show fields from test.v1;
connection default;
drop view v1;
drop table t1;
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731

#
# Bug #9846 Inappropriate error displayed while dropping table from 'INFORMATION_SCHEMA'
#
--error 1044
alter database information_schema;
--error 1044
drop database information_schema;
--error 1044
drop table information_schema.tables;
--error 1044
alter table information_schema.tables;
#
# Bug #9683 INFORMATION_SCH: Creation of temporary table allowed in Information_schema DB
#
use information_schema;
--error 1044
create temporary table schemata(f1 char(10));
#
# Bug #10708 SP's can use INFORMATION_SCHEMA as ROUTINE_SCHEMA
#
delimiter |;
--error 1044
CREATE PROCEDURE p1 ()
BEGIN
  SELECT 'foo' FROM DUAL;
END |
delimiter ;|
select  ROUTINE_NAME from routines;
#
# Bug #10734 Grant of privileges other than 'select' and 'create view' should fail on schema
#
--error 1044
grant all on information_schema.* to 'user1'@'localhost';
--error 1044
grant select on information_schema.* to 'user1'@'localhost';
732 733 734 735 736 737 738 739 740 741 742 743

#
# Bug#14089 FROM list subquery always fails when information_schema is current database
#
use test;
create table t1(id int);
insert into t1(id) values (1);
select 1 from (select 1 from test.t1) a;
use information_schema;
select 1 from (select 1 from test.t1) a;
use test;
drop table t1;
744

745 746 747 748 749 750 751 752 753
#
# Bug#14476 `information_schema`.`TABLES`.`TABLE_TYPE` with empty value
#
create table t1 (f1 int(11));
create view v1 as select * from t1;
drop table t1;
select table_type from information_schema.tables
where table_name="v1";
drop view v1;
754 755 756 757 758 759 760 761 762 763 764

#
# Bug #14387 SHOW COLUMNS doesn't work on temporary tables
# Bug #15224 SHOW INDEX from temporary table doesn't work
# Bug #12770 DESC cannot display the info. about temporary table
#
create temporary table t1(f1 int, index(f1));
show columns from t1;
describe t1;
show indexes from t1;
drop table t1;
765 766 767 768 769 770 771 772

#
# Bug#14271 I_S: columns has no size for (var)binary columns
#
create table t1(f1 binary(32), f2 varbinary(64));
select character_maximum_length, character_octet_length
from information_schema.columns where table_name='t1';
drop table t1;
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795

#
# Bug#15533 crash, information_schema, function, view
#
CREATE TABLE t1 (f1 BIGINT, f2 VARCHAR(20), f3 BIGINT);
INSERT INTO t1 SET f1 = 1, f2 = 'Schoenenbourg', f3 = 1;

CREATE FUNCTION func2() RETURNS BIGINT RETURN 1;

delimiter //;
CREATE FUNCTION func1() RETURNS BIGINT
BEGIN
  RETURN ( SELECT COUNT(*) FROM INFORMATION_SCHEMA.VIEWS);
END//
delimiter ;//

CREATE VIEW v1 AS SELECT 1 FROM t1
                    WHERE f3 = (SELECT func2 ());
SELECT func1();
DROP TABLE t1;
DROP VIEW v1;
DROP FUNCTION func1;
DROP FUNCTION func2;
796

797 798 799 800 801 802 803 804 805

#
# Bug#15307 GROUP_CONCAT() with ORDER BY returns empty set on information_schema
#
select column_type, group_concat(table_schema, '.', table_name), count(*) as num
from information_schema.columns where
table_schema='information_schema' and
(column_type = 'varchar(7)' or column_type = 'varchar(20)')
group by column_type order by num;
806 807 808 809 810 811 812 813 814

#
# Bug#19236 bad COLUMNS.CHARACTER_MAXIMUM_LENGHT and CHARACTER_OCTET_LENGTH
#
create table t1(f1 char(1) not null, f2 char(9) not null)
default character set utf8;
select CHARACTER_MAXIMUM_LENGTH, CHARACTER_OCTET_LENGTH from
information_schema.columns where table_schema='test' and table_name = 't1';
drop table t1;
815 816 817 818 819 820 821 822 823 824 825

#
# Bug#18177 any access to INFORMATION_SCHEMA.ROUTINES crashes
#
use mysql;
INSERT INTO `proc` VALUES ('test','','PROCEDURE','','SQL','CONTAINS_SQL',
'NO','DEFINER','','','BEGIN\r\n  \r\nEND','root@%','2006-03-02 18:40:03',
'2006-03-02 18:40:03','','');
select routine_name from information_schema.routines;
delete from proc where name='';
use test;
826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844

#
# Bug#16681 information_schema shows forbidden VIEW details
#
grant select on test.* to mysqltest_1@localhost;
create table t1 (id int);
create view v1 as select * from t1;
create definer = mysqltest_1@localhost
sql security definer view v2 as select 1;

connect (con16681,localhost,mysqltest_1,,test);
connection con16681;

select * from information_schema.views
where table_name='v1' or table_name='v2';
connection default;
drop view v1, v2;
drop table t1;
drop user mysqltest_1@localhost;
845 846 847 848 849 850 851 852 853 854

#
# Bug#19599 duplication of information_schema column value in a CONCAT expr with user var
#
set @a:= '.';
create table t1(f1 char(5));
create table t2(f1 char(5));
select concat(@a, table_name), @a, table_name
from information_schema.tables where table_schema = 'test';
drop table t1,t2;
855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889


#
# Bug#20230: routine_definition is not null
#
--disable_warnings
DROP PROCEDURE IF EXISTS p1;
DROP FUNCTION IF EXISTS f1;
--enable_warnings

CREATE PROCEDURE p1() SET @a= 1;
CREATE FUNCTION f1() RETURNS INT RETURN @a + 1;
CREATE USER mysql_bug20230@localhost;
GRANT EXECUTE ON PROCEDURE p1 TO mysql_bug20230@localhost;
GRANT EXECUTE ON FUNCTION f1 TO mysql_bug20230@localhost;

SELECT ROUTINE_NAME, ROUTINE_DEFINITION FROM INFORMATION_SCHEMA.ROUTINES;
SHOW CREATE PROCEDURE p1;
SHOW CREATE FUNCTION f1;

connect (conn1, localhost, mysql_bug20230,,);

SELECT ROUTINE_NAME, ROUTINE_DEFINITION FROM INFORMATION_SCHEMA.ROUTINES;
SHOW CREATE PROCEDURE p1;
SHOW CREATE FUNCTION f1;
CALL p1();
SELECT f1();

disconnect conn1;
connection default;

DROP FUNCTION f1;
DROP PROCEDURE p1;
DROP USER mysql_bug20230@localhost;

890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922
#
# Bug#18925: subqueries with MIN/MAX functions on INFORMARTION_SCHEMA 
#

SELECT t.table_name, c1.column_name
  FROM information_schema.tables t
       INNER JOIN
       information_schema.columns c1
       ON t.table_schema = c1.table_schema AND
          t.table_name = c1.table_name
  WHERE t.table_schema = 'information_schema' AND
        c1.ordinal_position =
        ( SELECT COALESCE(MIN(c2.ordinal_position),1)
            FROM information_schema.columns c2
            WHERE c2.table_schema = t.table_schema AND
                  c2.table_name = t.table_name AND
                  c2.column_name LIKE '%SCHEMA%'
        );
SELECT t.table_name, c1.column_name
  FROM information_schema.tables t
       INNER JOIN
       information_schema.columns c1
       ON t.table_schema = c1.table_schema AND
          t.table_name = c1.table_name
  WHERE t.table_schema = 'information_schema' AND
        c1.ordinal_position =
        ( SELECT COALESCE(MIN(c2.ordinal_position),1)
            FROM information_schema.columns c2
            WHERE c2.table_schema = 'information_schema' AND
                  c2.table_name = t.table_name AND
                  c2.column_name LIKE '%SCHEMA%'
        );

923 924 925 926 927 928 929 930 931 932
#
# Bug#21231: query with a simple non-correlated subquery over
#            INFORMARTION_SCHEMA.TABLES 
#

SELECT MAX(table_name) FROM information_schema.tables;
SELECT table_name from information_schema.tables
  WHERE table_name=(SELECT MAX(table_name)
                      FROM information_schema.tables);

933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975
#
# Bug #23037: Bug in field "Default" of query "SHOW COLUMNS FROM table"
#
# Note, MyISAM/InnoDB can't take more that 65532 chars, because the row
# size is limited to 65535 bytes (BLOBs not counted)
#
--disable_warnings
DROP TABLE IF EXISTS bug23037;
DROP FUNCTION IF EXISTS get_value;
--enable_warnings
--disable_query_log
DELIMITER |;
CREATE FUNCTION get_value()
  RETURNS TEXT
  DETERMINISTIC
BEGIN
  DECLARE col1, col2, col3, col4, col6 CHAR(255);
  DECLARE default_val VARCHAR(65532);
  DECLARE done INT DEFAULT 0;
  DECLARE cur1 CURSOR FOR SHOW COLUMNS FROM bug23037;
  DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
  OPEN cur1;
  FETCH cur1 INTO col1, col2, col3, col4, default_val, col6;
  CLOSE cur1;
  RETURN default_val;
end|
DELIMITER ;|

let $body=`SELECT REPEAT('A', 65532)`;
eval CREATE TABLE bug23037(fld1 VARCHAR(65532) CHARACTER SET latin1 DEFAULT "$body");
--enable_query_log

SELECT COLUMN_NAME, MD5(COLUMN_DEFAULT), LENGTH(COLUMN_DEFAULT) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='bug23037';

SELECT MD5(get_value());

SELECT COLUMN_NAME, MD5(COLUMN_DEFAULT), LENGTH(COLUMN_DEFAULT), COLUMN_DEFAULT=get_value() FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='bug23037';

DROP TABLE bug23037;
DROP FUNCTION get_value;



976
# End of 5.0 tests.