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";
2create table test_db select * from mysql.db;
3delete from test_db;
4insert ignore into test_db (Host,Db,User) values (@name,@name,@name);
5create table test_user select * from mysql.user;
6delete from test_user;
7insert ignore into test_user (Host,User) values (@name,@name);
8create table test_func select * from mysql.func;
9delete from test_func;
10insert ignore into test_func (name) values (@name);
11create table test_tables_priv select * from mysql.tables_priv;
12delete from test_tables_priv;
13insert ignore into test_tables_priv (Host,Db,User,Table_name) values (@name,@name,@name,@name);
14create table test_columns_priv select * from mysql.columns_priv;
15delete from test_columns_priv;
16insert ignore into test_columns_priv (Host,Db,User,Table_name,Column_name) values (@name,@name,@name,@name,@name);
17select
18if(isnull(test_db.Host),'WRONG!!!','ok') as test_db_Host,
19if(isnull(test_user.Host),'WRONG!!!','ok') as test_user_Host,
20if(isnull(test_tables_priv.Host),'WRONG!!!','ok') as test_tables_priv_Host,
21if(isnull(test_columns_priv.Host),'WRONG!!!','ok') as test_columns_priv_Host
22from      test_db
23left join test_user         on test_db.Host=test_user.Host
24left join test_tables_priv  on test_db.Host=test_tables_priv.Host
25left join test_columns_priv on test_db.Host=test_columns_priv.Host;
26test_db_Host	test_user_Host	test_tables_priv_Host	test_columns_priv_Host
27ok	ok	ok	ok
28select
29if(isnull(test_db.Db),'WRONG!!!','ok') as test_db_Db,
30if(isnull(test_tables_priv.Db),'WRONG!!!','ok') as test_tables_priv_Db,
31if(isnull(test_columns_priv.Db),'WRONG!!!','ok') as est_columns_priv_Db
32from      test_db
33left join test_tables_priv  on test_db.Db=test_tables_priv.Db
34left join test_columns_priv on test_db.Db=test_columns_priv.Db;
35test_db_Db	test_tables_priv_Db	est_columns_priv_Db
36ok	ok	ok
37select
38if(isnull(test_db.User),'WRONG!!!','ok') as test_db_User,
39if(isnull(test_user.User),'WRONG!!!','ok') as test_user_User,
40if(isnull(test_tables_priv.User),'WRONG!!!','ok') as test_tables_priv_User,
41if(isnull(test_columns_priv.User),'WRONG!!!','ok') as test_columns_priv_User
42from      test_db
43left join test_user         on test_db.User=test_user.User
44left join test_tables_priv  on test_db.User=test_tables_priv.User
45left join test_columns_priv on test_db.User=test_columns_priv.User;
46test_db_User	test_user_User	test_tables_priv_User	test_columns_priv_User
47ok	ok	ok	ok
48select
49if(isnull(test_tables_priv.User),'WRONG!!!','ok') as test_tables_priv_User,
50if(isnull(test_columns_priv.User),'WRONG!!!','ok') as test_columns_priv_User
51from      test_tables_priv
52left join test_columns_priv on test_tables_priv.Table_name=test_columns_priv.Table_name;
53test_tables_priv_User	test_columns_priv_User
54ok	ok
55drop table test_columns_priv;
56drop table test_tables_priv;
57drop table test_func;
58drop table test_user;
59drop table test_db;
60