summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <igor@olga.mysql.com>2006-07-24 19:05:46 -0700
committerunknown <igor@olga.mysql.com>2006-07-24 19:05:46 -0700
commitd64f605e48d42bc9a8fa33e206e427eab69b1a24 (patch)
tree194a76db647be171789dfeb4337ae020da046cc7
parent800b160031066ccb31bd0efab42b522b3e42b7dd (diff)
downloadmariadb-git-d64f605e48d42bc9a8fa33e206e427eab69b1a24.tar.gz
Fixed bug #21231: wrong results for a simple query with a
a non-correlated single-row subquery over information schema. The function get_all_tables filling all information schema tables reset lex->sql_command to SQLCOM_SHOW_FIELDS. After this the function could evaluate partial conditions related to some columns. If these conditions contained a subquery over information schema it led to a wrong evaluation and a wrong result set. This bug was already fixed in 5.1. This patch follows the way how it was done in 5.1 where the value of lex->sql_command is set to SQLCOM_SHOW_FIELDS in get_all_tables only for the calls of the function open_normal_and_derived_tables and is restored after these calls. mysql-test/r/information_schema.result: Added a test case for bug #21231. mysql-test/t/information_schema.test: Added a test case for bug #21231.
-rw-r--r--mysql-test/r/information_schema.result8
-rw-r--r--mysql-test/t/information_schema.test10
-rw-r--r--sql/sql_show.cc16
3 files changed, 28 insertions, 6 deletions
diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result
index 3b3669119d5..652af1c8387 100644
--- a/mysql-test/r/information_schema.result
+++ b/mysql-test/r/information_schema.result
@@ -1232,3 +1232,11 @@ TABLE_PRIVILEGES TABLE_SCHEMA
TRIGGERS TRIGGER_SCHEMA
USER_PRIVILEGES GRANTEE
VIEWS TABLE_SCHEMA
+SELECT MAX(table_name) FROM information_schema.tables;
+MAX(table_name)
+VIEWS
+SELECT table_name from information_schema.tables
+WHERE table_name=(SELECT MAX(table_name)
+FROM information_schema.tables);
+table_name
+VIEWS
diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test
index b49ec9e2f31..9e5dac8b853 100644
--- a/mysql-test/t/information_schema.test
+++ b/mysql-test/t/information_schema.test
@@ -920,4 +920,14 @@ SELECT t.table_name, c1.column_name
c2.column_name LIKE '%SCHEMA%'
);
+#
+# 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);
+
# End of 5.0 tests.
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index e2adefb0ca9..e22873dad9a 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -2116,12 +2116,6 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
LINT_INIT(end);
LINT_INIT(len);
- /*
- Let us set fake sql_command so views won't try to merge
- themselves into main statement.
- */
- lex->sql_command= SQLCOM_SHOW_FIELDS;
-
lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
/*
@@ -2144,8 +2138,16 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
I_S tables will be done.
*/
thd->temporary_tables= open_tables_state_backup.temporary_tables;
+ /*
+ Let us set fake sql_command so views won't try to merge
+ themselves into main statement. If we don't do this,
+ SELECT * from information_schema.xxxx will cause problems.
+ SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()'
+ */
+ lex->sql_command= SQLCOM_SHOW_FIELDS;
res= open_normal_and_derived_tables(thd, show_table_list,
MYSQL_LOCK_IGNORE_FLUSH);
+ lex->sql_command= save_sql_command;
/*
get_all_tables() returns 1 on failure and 0 on success thus
return only these and not the result code of ::process_table()
@@ -2267,8 +2269,10 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
TABLE_LIST *show_table_list= (TABLE_LIST*) sel.table_list.first;
lex->all_selects_list= &sel;
lex->derived_tables= 0;
+ lex->sql_command= SQLCOM_SHOW_FIELDS;
res= open_normal_and_derived_tables(thd, show_table_list,
MYSQL_LOCK_IGNORE_FLUSH);
+ lex->sql_command= save_sql_command;
/*
We should use show_table_list->alias instead of
show_table_list->table_name because table_name