diff options
-rw-r--r-- | mysql-test/r/view.result | 19 | ||||
-rw-r--r-- | mysql-test/t/view.test | 14 | ||||
-rw-r--r-- | sql/handler.h | 1 | ||||
-rw-r--r-- | sql/share/errmsg.txt | 2 | ||||
-rw-r--r-- | sql/sql_table.cc | 33 |
5 files changed, 59 insertions, 10 deletions
diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index a74feb4de17..9b434ebe9f4 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -2335,3 +2335,22 @@ f1 group_concat(f2 order by f2 desc) 1 3,2,1 drop view v1,v2; drop table t1; +CREATE TABLE t1(id INT); +CREATE VIEW v1 AS SELECT id FROM t1; +OPTIMIZE TABLE v1; +Table Op Msg_type Msg_text +test.v1 optimize note You cannot apply optimize to a view +ANALYZE TABLE v1; +Table Op Msg_type Msg_text +test.v1 analyze note You cannot apply analyze to a view +REPAIR TABLE v1; +Table Op Msg_type Msg_text +test.v1 repair note You cannot apply repair to a view +DROP TABLE t1; +OPTIMIZE TABLE v1; +Table Op Msg_type Msg_text +test.v1 optimize note You cannot apply optimize to a view +Warnings: +Error 1146 Table 'test.t1' doesn't exist +Error 1356 View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them +DROP VIEW v1; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 0bd0e572193..e919a4832a2 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -2200,3 +2200,17 @@ select * from v1; select * from v2; drop view v1,v2; drop table t1; +# Bug #14540: OPTIMIZE, ANALYZE, REPAIR applied to not a view +# + +CREATE TABLE t1(id INT); +CREATE VIEW v1 AS SELECT id FROM t1; + +OPTIMIZE TABLE v1; +ANALYZE TABLE v1; +REPAIR TABLE v1; + +DROP TABLE t1; +OPTIMIZE TABLE v1; + +DROP VIEW v1; diff --git a/sql/handler.h b/sql/handler.h index e16c428954c..e317f95b990 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -45,6 +45,7 @@ #define HA_ADMIN_REJECT -6 #define HA_ADMIN_TRY_ALTER -7 #define HA_ADMIN_WRONG_CHECKSUM -8 +#define HA_ADMIN_NOT_BASE_TABLE -9 /* Bits in table_flags() to show what database can do */ diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt index f85bda90e81..24e1d4b6b81 100644 --- a/sql/share/errmsg.txt +++ b/sql/share/errmsg.txt @@ -5421,3 +5421,5 @@ ER_NO_REFERENCED_ROW_2 23000 eng "Cannot add or update a child row: a foreign key constraint fails (%.192s)" ER_SP_BAD_VAR_SHADOW 42000 eng "Variable '%-.64s' must be quoted with `...`, or renamed" +ER_CHECK_NOT_BASE_TABLE 42000 + eng "You cannot apply %s to a view" diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 94c2f0d5585..b339e6a81e9 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2196,7 +2196,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, /* if view are unsupported */ if (table->view && view_operator_func == NULL) { - result_code= HA_ADMIN_NOT_IMPLEMENTED; + result_code= HA_ADMIN_NOT_BASE_TABLE; goto send_result; } thd->open_options&= ~extra_open_options; @@ -2331,6 +2331,16 @@ send_result_message: } break; + case HA_ADMIN_NOT_BASE_TABLE: + { + char buf[ERRMSGSIZE+20]; + uint length= my_snprintf(buf, ERRMSGSIZE, + ER(ER_CHECK_NOT_BASE_TABLE), operator_name); + protocol->store("note", 4, system_charset_info); + protocol->store(buf, length, system_charset_info); + } + break; + case HA_ADMIN_OK: protocol->store("status", 6, system_charset_info); protocol->store("OK",2, system_charset_info); @@ -2431,16 +2441,19 @@ send_result_message: break; } } - if (fatal_error) - table->table->s->version=0; // Force close of table - else if (open_for_modify) + if (table->table) { - pthread_mutex_lock(&LOCK_open); - remove_table_from_cache(thd, table->table->s->db, - table->table->s->table_name, RTFC_NO_FLAG); - pthread_mutex_unlock(&LOCK_open); - /* May be something modified consequently we have to invalidate cache */ - query_cache_invalidate3(thd, table->table, 0); + if (fatal_error) + table->table->s->version=0; // Force close of table + else if (open_for_modify) + { + pthread_mutex_lock(&LOCK_open); + remove_table_from_cache(thd, table->table->s->db, + table->table->s->table_name, RTFC_NO_FLAG); + pthread_mutex_unlock(&LOCK_open); + /* Something may be modified, that's why we have to invalidate cache */ + query_cache_invalidate3(thd, table->table, 0); + } } close_thread_tables(thd); table->table=0; // For query cache |