1set @name="This is a very long string, that mustn't find room in a system field like Table_name. Thus it should be cut by the actual size of the field. So we can use this string to find out the actual length of the field and to use it in any compare queries";
2SET sql_mode = 'NO_ENGINE_SUBSTITUTION';
3Warnings:
4Warning	3090	Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release.
5create table test_db select * from mysql.db;
6delete from test_db;
7insert into test_db (Host,Db,User) values (@name,@name,@name);
8create table test_user select * from mysql.user;
9delete from test_user;
10insert into test_user (Host,User) values (@name,@name);
11create table test_func select * from mysql.func;
12delete from test_func;
13insert into test_func (name) values (@name);
14create table test_tables_priv select * from mysql.tables_priv;
15delete from test_tables_priv;
16insert into test_tables_priv (Host,Db,User,Table_name) values (@name,@name,@name,@name);
17create table test_columns_priv select * from mysql.columns_priv;
18delete from test_columns_priv;
19insert into test_columns_priv (Host,Db,User,Table_name,Column_name) values (@name,@name,@name,@name,@name);
20select
21if(isnull(test_db.Host),'WRONG!!!','ok') as test_db_Host,
22if(isnull(test_user.Host),'WRONG!!!','ok') as test_user_Host,
23if(isnull(test_tables_priv.Host),'WRONG!!!','ok') as test_tables_priv_Host,
24if(isnull(test_columns_priv.Host),'WRONG!!!','ok') as test_columns_priv_Host
25from      test_db
26left join test_user         on test_db.Host=test_user.Host
27left join test_tables_priv  on test_db.Host=test_tables_priv.Host
28left join test_columns_priv on test_db.Host=test_columns_priv.Host;
29test_db_Host	test_user_Host	test_tables_priv_Host	test_columns_priv_Host
30ok	ok	ok	ok
31select
32if(isnull(test_db.Db),'WRONG!!!','ok') as test_db_Db,
33if(isnull(test_tables_priv.Db),'WRONG!!!','ok') as test_tables_priv_Db,
34if(isnull(test_columns_priv.Db),'WRONG!!!','ok') as est_columns_priv_Db
35from      test_db
36left join test_tables_priv  on test_db.Db=test_tables_priv.Db
37left join test_columns_priv on test_db.Db=test_columns_priv.Db;
38test_db_Db	test_tables_priv_Db	est_columns_priv_Db
39ok	ok	ok
40select
41if(isnull(test_db.User),'WRONG!!!','ok') as test_db_User,
42if(isnull(test_user.User),'WRONG!!!','ok') as test_user_User,
43if(isnull(test_tables_priv.User),'WRONG!!!','ok') as test_tables_priv_User,
44if(isnull(test_columns_priv.User),'WRONG!!!','ok') as test_columns_priv_User
45from      test_db
46left join test_user         on test_db.User=test_user.User
47left join test_tables_priv  on test_db.User=test_tables_priv.User
48left join test_columns_priv on test_db.User=test_columns_priv.User;
49test_db_User	test_user_User	test_tables_priv_User	test_columns_priv_User
50ok	ok	ok	ok
51select
52if(isnull(test_tables_priv.User),'WRONG!!!','ok') as test_tables_priv_User,
53if(isnull(test_columns_priv.User),'WRONG!!!','ok') as test_columns_priv_User
54from      test_tables_priv
55left join test_columns_priv on test_tables_priv.Table_name=test_columns_priv.Table_name;
56test_tables_priv_User	test_columns_priv_User
57ok	ok
58drop table test_columns_priv;
59drop table test_tables_priv;
60drop table test_func;
61drop table test_user;
62drop table test_db;
63SET sql_mode = default;
64