mirror of
https://github.com/MariaDB/server.git
synced 2026-01-06 05:22:24 +03:00
Bug#30310 wrong result on SELECT * FROM INFORMATION_SCHEMA.SCHEMATA WHERE ..
1. added check to fill_schema_schemata() func. if we have db lookup value we should check that db exists 2. added check to get_all_tables() func if we have lookup db name or tables name values we shoud check that these values are not empty strings 3. fixed typo mysql-test/r/information_schema.result: test result mysql-test/t/information_schema.test: test case
This commit is contained in:
@@ -1463,4 +1463,26 @@ where a.table_name='t1' and a.table_schema='test' and b.table_name=a.table_name;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE a ALL NULL TABLE_SCHEMA,TABLE_NAME NULL NULL NULL Using where; Skip_open_table; Scanned 0 databases
|
||||
1 SIMPLE b ALL NULL NULL NULL NULL NULL Using where; Open_frm_only; Scanned all databases; Using join buffer
|
||||
SELECT * FROM INFORMATION_SCHEMA.SCHEMATA
|
||||
WHERE SCHEMA_NAME = 'mysqltest';
|
||||
CATALOG_NAME SCHEMA_NAME DEFAULT_CHARACTER_SET_NAME DEFAULT_COLLATION_NAME SQL_PATH
|
||||
SELECT * FROM INFORMATION_SCHEMA.SCHEMATA
|
||||
WHERE SCHEMA_NAME = '';
|
||||
CATALOG_NAME SCHEMA_NAME DEFAULT_CHARACTER_SET_NAME DEFAULT_COLLATION_NAME SQL_PATH
|
||||
SELECT * FROM INFORMATION_SCHEMA.SCHEMATA
|
||||
WHERE SCHEMA_NAME = 'test';
|
||||
CATALOG_NAME SCHEMA_NAME DEFAULT_CHARACTER_SET_NAME DEFAULT_COLLATION_NAME SQL_PATH
|
||||
NULL test latin1 latin1_swedish_ci NULL
|
||||
select count(*) from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='mysql' AND TABLE_NAME='nonexisting';
|
||||
count(*)
|
||||
0
|
||||
select count(*) from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='mysql' AND TABLE_NAME='';
|
||||
count(*)
|
||||
0
|
||||
select count(*) from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='' AND TABLE_NAME='';
|
||||
count(*)
|
||||
0
|
||||
select count(*) from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='' AND TABLE_NAME='nonexisting';
|
||||
count(*)
|
||||
0
|
||||
End of 5.1 tests.
|
||||
|
||||
@@ -1120,4 +1120,20 @@ explain select b.table_name
|
||||
from information_schema.tables a, information_schema.columns b
|
||||
where a.table_name='t1' and a.table_schema='test' and b.table_name=a.table_name;
|
||||
|
||||
#
|
||||
# Bug#30310 wrong result on SELECT * FROM INFORMATION_SCHEMA.SCHEMATA WHERE ..
|
||||
#
|
||||
SELECT * FROM INFORMATION_SCHEMA.SCHEMATA
|
||||
WHERE SCHEMA_NAME = 'mysqltest';
|
||||
|
||||
SELECT * FROM INFORMATION_SCHEMA.SCHEMATA
|
||||
WHERE SCHEMA_NAME = '';
|
||||
|
||||
SELECT * FROM INFORMATION_SCHEMA.SCHEMATA
|
||||
WHERE SCHEMA_NAME = 'test';
|
||||
|
||||
select count(*) from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='mysql' AND TABLE_NAME='nonexisting';
|
||||
select count(*) from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='mysql' AND TABLE_NAME='';
|
||||
select count(*) from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='' AND TABLE_NAME='';
|
||||
select count(*) from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='' AND TABLE_NAME='nonexisting';
|
||||
--echo End of 5.1 tests.
|
||||
|
||||
@@ -3054,7 +3054,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
|
||||
enum enum_schema_tables schema_table_idx;
|
||||
List<LEX_STRING> db_names;
|
||||
List_iterator_fast<LEX_STRING> it(db_names);
|
||||
COND *partial_cond;
|
||||
COND *partial_cond= 0;
|
||||
uint derived_tables= lex->derived_tables;
|
||||
int error= 1;
|
||||
Open_tables_state open_tables_state_backup;
|
||||
@@ -3093,20 +3093,35 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
|
||||
DBUG_PRINT("INDEX VALUES",("db_name='%s', table_name='%s'",
|
||||
lookup_field_vals.db_value.str,
|
||||
lookup_field_vals.table_value.str));
|
||||
if (lookup_field_vals.db_value.length &&
|
||||
!lookup_field_vals.wild_db_value &&
|
||||
lookup_field_vals.table_value.length &&
|
||||
!lookup_field_vals.wild_table_value)
|
||||
partial_cond= 0;
|
||||
else
|
||||
partial_cond= make_cond_for_info_schema(cond, tables);
|
||||
|
||||
if (lookup_field_vals.db_value.length && !lookup_field_vals.wild_db_value)
|
||||
if (!lookup_field_vals.wild_db_value && !lookup_field_vals.wild_table_value)
|
||||
{
|
||||
/*
|
||||
if lookup value is empty string then
|
||||
it's impossible table name or db name
|
||||
*/
|
||||
if (lookup_field_vals.db_value.str &&
|
||||
!lookup_field_vals.db_value.str[0] ||
|
||||
lookup_field_vals.table_value.str &&
|
||||
!lookup_field_vals.table_value.str[0])
|
||||
{
|
||||
error= 0;
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if (lookup_field_vals.db_value.length &&
|
||||
!lookup_field_vals.wild_db_value)
|
||||
tables->has_db_lookup_value= TRUE;
|
||||
if (lookup_field_vals.table_value.length &&
|
||||
!lookup_field_vals.wild_table_value)
|
||||
tables->has_table_lookup_value= TRUE;
|
||||
|
||||
if (tables->has_db_lookup_value && tables->has_table_lookup_value)
|
||||
partial_cond= 0;
|
||||
else
|
||||
partial_cond= make_cond_for_info_schema(cond, tables);
|
||||
|
||||
tables->table_open_method= table_open_method=
|
||||
get_table_open_method(tables, schema_table, schema_table_idx);
|
||||
|
||||
@@ -3271,7 +3286,7 @@ bool store_schema_shemata(THD* thd, TABLE *table, LEX_STRING *db_name,
|
||||
}
|
||||
|
||||
|
||||
int fill_schema_shemata(THD *thd, TABLE_LIST *tables, COND *cond)
|
||||
int fill_schema_schemata(THD *thd, TABLE_LIST *tables, COND *cond)
|
||||
{
|
||||
/*
|
||||
TODO: fill_schema_shemata() is called when new client is connected.
|
||||
@@ -3297,6 +3312,23 @@ int fill_schema_shemata(THD *thd, TABLE_LIST *tables, COND *cond)
|
||||
&with_i_schema))
|
||||
DBUG_RETURN(1);
|
||||
|
||||
/*
|
||||
If we have lookup db value we should check that the database exists
|
||||
*/
|
||||
if(lookup_field_vals.db_value.str && !lookup_field_vals.wild_db_value)
|
||||
{
|
||||
char path[FN_REFLEN+16];
|
||||
uint path_len;
|
||||
MY_STAT stat_info;
|
||||
if (!lookup_field_vals.db_value.str[0])
|
||||
DBUG_RETURN(0);
|
||||
path_len= build_table_filename(path, sizeof(path),
|
||||
lookup_field_vals.db_value.str, "", "", 0);
|
||||
path[path_len-1]= 0;
|
||||
if (!my_stat(path,&stat_info,MYF(0)))
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
|
||||
List_iterator_fast<LEX_STRING> it(db_names);
|
||||
while ((db_name=it++))
|
||||
{
|
||||
@@ -6449,7 +6481,7 @@ ST_SCHEMA_TABLE schema_tables[]=
|
||||
{"ROUTINES", proc_fields_info, create_schema_table,
|
||||
fill_schema_proc, make_proc_old_format, 0, -1, -1, 0, 0},
|
||||
{"SCHEMATA", schema_fields_info, create_schema_table,
|
||||
fill_schema_shemata, make_schemata_old_format, 0, 1, -1, 0, 0},
|
||||
fill_schema_schemata, make_schemata_old_format, 0, 1, -1, 0, 0},
|
||||
{"SCHEMA_PRIVILEGES", schema_privileges_fields_info, create_schema_table,
|
||||
fill_schema_schema_privileges, 0, 0, -1, -1, 0, 0},
|
||||
{"SESSION_STATUS", variables_fields_info, create_schema_table,
|
||||
|
||||
Reference in New Issue
Block a user