From fa776a6f6752b0b23fc89e0fd9887c747de0766b Mon Sep 17 00:00:00 2001 From: "gluh@eagle.intranet.mysql.r18.ru" <> Date: Tue, 24 Jan 2006 15:59:08 +0400 Subject: [PATCH 1/2] Fix for bug#15851 Unlistable directories yield no info from information_schema to skip directories which are not allowed for read --- mysql-test/r/information_schema.result | 5 +++++ mysql-test/t/information_schema.test | 10 ++++++++++ mysys/my_lib.c | 2 ++ 3 files changed, 17 insertions(+) diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result index e7d82f48691..074b68881af 100644 --- a/mysql-test/r/information_schema.result +++ b/mysql-test/r/information_schema.result @@ -1084,3 +1084,8 @@ DROP TABLE t1; DROP VIEW v1; DROP FUNCTION func1; DROP FUNCTION func2; +create database mysqltest; +create table mysqltest.t1(a int); +select table_schema from information_schema.tables where table_schema='mysqltest'; +table_schema +drop database mysqltest; diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test index f835a7148a2..323c6b37059 100644 --- a/mysql-test/t/information_schema.test +++ b/mysql-test/t/information_schema.test @@ -790,3 +790,13 @@ DROP TABLE t1; DROP VIEW v1; DROP FUNCTION func1; DROP FUNCTION func2; + +# +# Bug #15851 Unlistable directories yield no info from information_schema +# +create database mysqltest; +create table mysqltest.t1(a int); +--exec chmod -r $MYSQL_TEST_DIR/var/master-data/mysqltest +select table_schema from information_schema.tables where table_schema='mysqltest'; +--exec chmod +r $MYSQL_TEST_DIR/var/master-data/mysqltest +drop database mysqltest; diff --git a/mysys/my_lib.c b/mysys/my_lib.c index 1908c70f407..4ca343064d3 100644 --- a/mysys/my_lib.c +++ b/mysys/my_lib.c @@ -170,6 +170,8 @@ MY_DIR *my_dir(const char *path, myf MyFlags) bzero(finfo.mystat, sizeof(MY_STAT)); VOID(strmov(tmp_file,dp->d_name)); VOID(my_stat(tmp_path, finfo.mystat, MyFlags)); + if (!(finfo.mystat->st_mode & MY_S_IREAD)) + continue; } else finfo.mystat= NULL; From b4f7c9bbd53c4934f98cd5a7c3b492d82a997e64 Mon Sep 17 00:00:00 2001 From: "gluh@eagle.intranet.mysql.r18.ru" <> Date: Tue, 24 Jan 2006 16:48:19 +0400 Subject: [PATCH 2/2] Fix for bug#15307 GROUP_CONCAT() with ORDER BY returns empty set on information_schema(2nd ver) Fill schema tables with data before filesort if it's necessary --- mysql-test/r/information_schema.result | 8 ++++++++ mysql-test/t/information_schema.test | 9 +++++++++ sql/sql_prepare.cc | 2 ++ sql/sql_select.cc | 6 ++++++ sql/sql_show.cc | 12 +++++++++++- sql/table.h | 1 + 6 files changed, 37 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result index 074b68881af..08d698092e2 100644 --- a/mysql-test/r/information_schema.result +++ b/mysql-test/r/information_schema.result @@ -1089,3 +1089,11 @@ create table mysqltest.t1(a int); select table_schema from information_schema.tables where table_schema='mysqltest'; table_schema drop database mysqltest; +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; +column_type group_concat(table_schema, '.', table_name) num +varchar(20) information_schema.COLUMNS 1 +varchar(7) information_schema.ROUTINES,information_schema.VIEWS 2 diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test index 323c6b37059..85d56bfc78b 100644 --- a/mysql-test/t/information_schema.test +++ b/mysql-test/t/information_schema.test @@ -800,3 +800,12 @@ create table mysqltest.t1(a int); select table_schema from information_schema.tables where table_schema='mysqltest'; --exec chmod +r $MYSQL_TEST_DIR/var/master-data/mysqltest drop database mysqltest; + +# +# 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; diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index ffbbf0c6476..68f033f78fe 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -2111,6 +2111,8 @@ void reinit_stmt_before_use(THD *thd, LEX *lex) were closed in the end of previous prepare or execute call. */ tables->table= 0; + /* Reset is_schema_table_processed value(needed for I_S tables */ + tables->is_schema_table_processed= FALSE; if (tables->prep_on_expr) { diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 1037f490397..95da0e6263a 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -11582,6 +11582,12 @@ create_sort_index(THD *thd, JOIN *join, ORDER *order, goto err; } } + + /* Fill schema tables with data before filesort if it's necessary */ + if ((join->select_lex->options & OPTION_SCHEMA_TABLE) && + get_schema_tables_result(join)) + goto err; + if (table->s->tmp_table) table->file->info(HA_STATUS_VARIABLE); // Get record count table->sort.found_records=filesort(thd, table,sortorder, length, diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 17a8c846944..1f776d815df 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -3845,7 +3845,16 @@ bool get_schema_tables_result(JOIN *join) TABLE_LIST *table_list= tab->table->pos_in_table_list; if (table_list->schema_table && thd->fill_derived_tables()) { - if (&lex->unit != lex->current_select->master_unit()) // is subselect + bool is_subselect= (&lex->unit != lex->current_select->master_unit()); + /* + The schema table is already processed and + the statement is not a subselect. + So we don't need to handle this table again. + */ + if (table_list->is_schema_table_processed && !is_subselect) + continue; + + if (is_subselect) // is subselect { table_list->table->file->extra(HA_EXTRA_RESET_STATE); table_list->table->file->delete_all_rows(); @@ -3858,6 +3867,7 @@ bool get_schema_tables_result(JOIN *join) if (table_list->schema_table->fill_table(thd, table_list, tab->select_cond)) result= 1; + table_list->is_schema_table_processed= TRUE; } } thd->no_warnings_for_error= 0; diff --git a/sql/table.h b/sql/table.h index ce0616a6833..947316e253f 100644 --- a/sql/table.h +++ b/sql/table.h @@ -515,6 +515,7 @@ typedef struct st_table_list st_select_lex_unit *derived; /* SELECT_LEX_UNIT of derived table */ ST_SCHEMA_TABLE *schema_table; /* Information_schema table */ st_select_lex *schema_select_lex; + bool is_schema_table_processed; /* True when the view field translation table is used to convert schema table fields for backwards compatibility with SHOW command.