From 1efa3714aa404354c1879edb1a2cd049656cc782 Mon Sep 17 00:00:00 2001 From: "msvensson@neptunus.(none)" <> Date: Thu, 1 Sep 2005 11:36:42 +0200 Subject: [PATCH 1/2] Bug10213 mysqldump crashes when dumping VIEWs - Added testcase for this bug - Check if compact view format can be used - Clean up mysqld_show_create --- mysql-test/r/mysqldump.result | 51 +++++++++++++++++++++++++++- mysql-test/t/mysqldump.test | 64 ++++++++++++++++++++++++++++++++++- sql/item.cc | 8 +++-- sql/sql_select.cc | 21 +++++++++--- sql/sql_show.cc | 48 +++++++++++++++++--------- sql/table.h | 1 + 6 files changed, 169 insertions(+), 24 deletions(-) diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index f73c9b223fd..080bc4d1e0f 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -1,6 +1,7 @@ DROP TABLE IF EXISTS t1, `"t"1`, t1aa, t2, t2aa; drop database if exists mysqldump_test_db; -drop view if exists v1; +drop database if exists db1; +drop view if exists v1, v2; CREATE TABLE t1(a int); INSERT INTO t1 VALUES (1), (2); @@ -1422,3 +1423,51 @@ UNLOCK TABLES; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; DROP TABLE t1; +create database db1; +use db1; +CREATE TABLE t2 ( +a varchar(30) default NULL, +KEY a (a(5)) +); +INSERT INTO t2 VALUES ('alfred'); +INSERT INTO t2 VALUES ('angie'); +INSERT INTO t2 VALUES ('bingo'); +INSERT INTO t2 VALUES ('waffle'); +INSERT INTO t2 VALUES ('lemon'); +create view v2 as select * from t2 where a like 'a%' with check option; + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; +DROP TABLE IF EXISTS `t2`; +CREATE TABLE `t2` ( + `a` varchar(30) default NULL, + KEY `a` (`a`(5)) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + + +/*!40000 ALTER TABLE `t2` DISABLE KEYS */; +LOCK TABLES `t2` WRITE; +INSERT INTO `t2` VALUES ('alfred'),('angie'),('bingo'),('waffle'),('lemon'); +UNLOCK TABLES; +/*!40000 ALTER TABLE `t2` ENABLE KEYS */; +DROP TABLE IF EXISTS `v2`; +DROP VIEW IF EXISTS `v2`; +CREATE ALGORITHM=UNDEFINED VIEW `db1`.`v2` AS select `db1`.`t2`.`a` AS `a` from `db1`.`t2` where (`db1`.`t2`.`a` like _latin1'a%') WITH CASCADED CHECK OPTION; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +drop table t2; +drop view v2; +drop database db1; diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index 7a39fbdf5f6..dddec18f081 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -4,7 +4,9 @@ --disable_warnings DROP TABLE IF EXISTS t1, `"t"1`, t1aa, t2, t2aa; drop database if exists mysqldump_test_db; -drop view if exists v1; +drop database if exists db1; +drop database if exists db2; +drop view if exists v1, v2; --enable_warnings # XML output @@ -563,3 +565,63 @@ CREATE TABLE t1 (a int); INSERT INTO t1 VALUES (1),(2),(3); --exec $MYSQL_DUMP --add-drop-database --skip-comments --databases test DROP TABLE t1; + + +# +# Bug #10213 mysqldump crashes when dumping VIEWs(on MacOS X) +# + +create database db1; +use db1; + +CREATE TABLE t2 ( + a varchar(30) default NULL, + KEY a (a(5)) +); + +INSERT INTO t2 VALUES ('alfred'); +INSERT INTO t2 VALUES ('angie'); +INSERT INTO t2 VALUES ('bingo'); +INSERT INTO t2 VALUES ('waffle'); +INSERT INTO t2 VALUES ('lemon'); +create view v2 as select * from t2 where a like 'a%' with check option; +--exec $MYSQL_DUMP --skip-comments db1 +drop table t2; +drop view v2; +drop database db1; + +# +# Bug 10713 mysqldump includes database in create view and referenced tables +# + +# create table and views in testdb2 +create database db2; +use db2; +create table t1 (a int); +create table t2 (a int, b varchar(10), primary key(a)); +insert into t2 values (1, "on"), (2, "off"), (10, "pol"), (12, "meg"); +insert into t1 values (289), (298), (234), (456), (789); +create view v1 as select * from t2; +create view v2 as select * from t1; + +# dump tables and view from db2 +--exec $MYSQL_DUMP db2 +--exec $MYSQL_DUMP db2 > var/tmp/bug10713.sql + +# drop the db, tables and views +drop table t1, t2; +drop view v1, v2; +drop database db2; + +# create db1 and reload dump +create database db1; +use db1; +--exec $MYSQL db1 < var/tmp/bug10713.sql + +# check that all tables and views could be created +show tables; +#select * from t2 order by a; + +#drop table t1, t2; +#drop view t1, t2; +drop database db1; diff --git a/sql/item.cc b/sql/item.cc index 680b771f908..ce1222b1325 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1137,8 +1137,12 @@ void Item_ident::print(String *str) } if (db_name && db_name[0] && !alias_name_used) { - append_identifier(thd, str, d_name, strlen(d_name)); - str->append('.'); + if (!(cached_table && cached_table->belong_to_view && + cached_table->belong_to_view->compact_view_format)) + { + append_identifier(thd, str, d_name, strlen(d_name)); + str->append('.'); + } append_identifier(thd, str, t_name, strlen(t_name)); str->append('.'); append_identifier(thd, str, field_name, strlen(field_name)); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 099b7857af8..3ec2979de45 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -13673,13 +13673,20 @@ void st_table_list::print(THD *thd, String *str) const char *cmp_name; // Name to compare with alias if (view_name.str) { - append_identifier(thd, str, view_db.str, view_db.length); - str->append('.'); + // A view + + if (!(belong_to_view && + belong_to_view->compact_view_format)) + { + append_identifier(thd, str, view_db.str, view_db.length); + str->append('.'); + } append_identifier(thd, str, view_name.str, view_name.length); cmp_name= view_name.str; } else if (derived) { + // A derived table str->append('('); derived->print(str); str->append(')'); @@ -13687,8 +13694,14 @@ void st_table_list::print(THD *thd, String *str) } else { - append_identifier(thd, str, db, db_length); - str->append('.'); + // A normal table + + if (!(belong_to_view && + belong_to_view->compact_view_format)) + { + append_identifier(thd, str, db, db_length); + str->append('.'); + } if (schema_table) { append_identifier(thd, str, schema_table_name, diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 68c6d1a8030..268a94cf318 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -339,7 +339,6 @@ mysql_find_files(THD *thd,List *files, const char *db,const char *path, bool mysqld_show_create(THD *thd, TABLE_LIST *table_list) { - TABLE *table; Protocol *protocol= thd->protocol; char buff[2048]; String buffer(buff, sizeof(buff), system_charset_info); @@ -349,9 +348,8 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list) /* Only one table for now, but VIEW can involve several tables */ if (open_normal_and_derived_tables(thd, table_list)) - { DBUG_RETURN(TRUE); - } + /* TODO: add environment variables show when it become possible */ if (thd->lex->only_view && !table_list->view) { @@ -360,8 +358,7 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list) DBUG_RETURN(TRUE); } - table= table_list->table; - + buffer.length(0); if ((table_list->view ? view_store_create_info(thd, table_list, &buffer) : store_create_info(thd, table_list, &buffer))) @@ -386,22 +383,15 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list) Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) DBUG_RETURN(TRUE); protocol->prepare_for_resend(); - buffer.length(0); if (table_list->view) - { protocol->store(table_list->view_name.str, system_charset_info); - if (view_store_create_info(thd, table_list, &buffer)) - DBUG_RETURN(TRUE); - } else { if (table_list->schema_table) protocol->store(table_list->schema_table->table_name, system_charset_info); else - protocol->store(table->alias, system_charset_info); - if (store_create_info(thd, table_list, &buffer)) - DBUG_RETURN(TRUE); + protocol->store(table_list->table->alias, system_charset_info); } protocol->store(buffer.ptr(), buffer.length(), buffer.charset()); @@ -1037,6 +1027,29 @@ view_store_create_info(THD *thd, TABLE_LIST *table, String *buff) MODE_DB2 | MODE_MAXDB | MODE_ANSI)) != 0; + /* + Compact output format for view can be used + - if user has db of this view as current db + - if this view only references table inside it's own db + */ + if(strcmp(thd->db, table->view_db.str)) + table->compact_view_format= FALSE; + else + { + table->compact_view_format= TRUE; + TABLE_LIST *tbl; + for (tbl= thd->lex->query_tables; + tbl; + tbl= tbl->next_global) + { + if (strcmp(table->view_db.str, tbl->view ? tbl->view_db.str :tbl->db)!= 0) + { + table->compact_view_format= FALSE; + break; + } + } + } + buff->append("CREATE ", 7); if (!foreign_db_mode) { @@ -1057,11 +1070,14 @@ view_store_create_info(THD *thd, TABLE_LIST *table, String *buff) } } buff->append("VIEW ", 5); - append_identifier(thd, buff, table->view_db.str, table->view_db.length); - buff->append('.'); + if (!table->compact_view_format) + { + append_identifier(thd, buff, table->view_db.str, table->view_db.length); + buff->append('.'); + } append_identifier(thd, buff, table->view_name.str, table->view_name.length); buff->append(" AS ", 4); - buff->append(table->query.str, table->query.length); + table->view->unit.print(buff); if (table->with_check != VIEW_CHECK_NONE) { if (table->with_check == VIEW_CHECK_LOCAL) diff --git a/sql/table.h b/sql/table.h index 8bc4e01852f..54f7a5e3233 100644 --- a/sql/table.h +++ b/sql/table.h @@ -437,6 +437,7 @@ typedef struct st_table_list /* TRUE if this merged view contain auto_increment field */ bool contain_auto_increment; bool multitable_view; /* TRUE iff this is multitable view */ + bool compact_view_format; /* Use compact format for SHOW CREATE VIEW */ /* FRMTYPE_ERROR if any type is acceptable */ enum frm_type_enum required_type; char timestamp_buffer[20]; /* buffer for timestamp (19+1) */ From 8a296476c0c210bc9d64a3118eed3291ac12e9c9 Mon Sep 17 00:00:00 2001 From: "msvensson@neptunus.(none)" <> Date: Tue, 13 Sep 2005 12:43:43 +0200 Subject: [PATCH 2/2] BUG#10713 mysqldump includes database in create view and referenced tables - Update test results - Updates after review --- mysql-test/r/func_in.result | 2 +- mysql-test/r/lowercase_view.result | 6 ++-- mysql-test/r/mysqldump.result | 43 +++++++++++++++++++++++++---- mysql-test/r/sql_mode.result | 4 +-- mysql-test/r/temp_table.result | 2 +- mysql-test/r/view.result | 44 +++++++++++++++--------------- mysql-test/t/mysqldump.test | 8 ++---- sql/sql_show.cc | 4 +-- 8 files changed, 72 insertions(+), 41 deletions(-) diff --git a/mysql-test/r/func_in.result b/mysql-test/r/func_in.result index b0c0178328e..c8890313d80 100644 --- a/mysql-test/r/func_in.result +++ b/mysql-test/r/func_in.result @@ -209,7 +209,7 @@ a CREATE VIEW v1 AS SELECT * FROM t1 WHERE a NOT IN (45); SHOW CREATE VIEW v1; View Create View -v1 CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` <> 45) +v1 CREATE ALGORITHM=UNDEFINED VIEW `v1` AS select `t1`.`a` AS `a` from `t1` where (`t1`.`a` <> 45) SELECT * FROM v1; a 44 diff --git a/mysql-test/r/lowercase_view.result b/mysql-test/r/lowercase_view.result index 1baf3246c13..f4d61e9f560 100644 --- a/mysql-test/r/lowercase_view.result +++ b/mysql-test/r/lowercase_view.result @@ -7,7 +7,7 @@ create table TaB (Field int); create view ViE as select * from TAb; show create table VIe; View Create View -vie CREATE ALGORITHM=UNDEFINED VIEW `mysqltest`.`vie` AS select `mysqltest`.`tab`.`Field` AS `Field` from `mysqltest`.`tab` +vie CREATE ALGORITHM=UNDEFINED VIEW `vie` AS select `tab`.`Field` AS `Field` from `tab` drop database MySQLTest; use test; create table t1Aa (col1 int); @@ -119,7 +119,7 @@ create table t1Aa (col1 int); create view v1Aa as select col1 from t1Aa as AaA; show create view v1AA; View Create View -v1aa CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1aa` AS select `aaa`.`col1` AS `col1` from `test`.`t1aa` `AaA` +v1aa CREATE ALGORITHM=UNDEFINED VIEW `v1aa` AS select `aaa`.`col1` AS `col1` from `t1aa` `AaA` drop view v1AA; select Aaa.col1 from t1Aa as AaA; col1 @@ -128,6 +128,6 @@ drop view v1AA; create view v1Aa as select AaA.col1 from t1Aa as AaA; show create view v1AA; View Create View -v1aa CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1aa` AS select `aaa`.`col1` AS `col1` from `test`.`t1aa` `AaA` +v1aa CREATE ALGORITHM=UNDEFINED VIEW `v1aa` AS select `aaa`.`col1` AS `col1` from `t1aa` `AaA` drop view v1AA; drop table t1Aa; diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index 3fe537a986f..2cbceae86b3 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -1,6 +1,7 @@ DROP TABLE IF EXISTS t1, `"t"1`, t1aa, t2, t2aa; drop database if exists mysqldump_test_db; drop database if exists db1; +drop database if exists db2; drop view if exists v1, v2, v3; CREATE TABLE t1(a int); INSERT INTO t1 VALUES (1), (2); @@ -1390,8 +1391,13 @@ INSERT INTO `t2` VALUES ('alfred'),('angie'),('bingo'),('waffle'),('lemon'); UNLOCK TABLES; /*!40000 ALTER TABLE `t2` ENABLE KEYS */; DROP TABLE IF EXISTS `v2`; -DROP VIEW IF EXISTS `v2`; -CREATE ALGORITHM=UNDEFINED VIEW `db1`.`v2` AS select `db1`.`t2`.`a` AS `a` from `db1`.`t2` where (`db1`.`t2`.`a` like _latin1'a%') WITH CASCADED CHECK OPTION; +/*!50001 DROP VIEW IF EXISTS `v2`*/; +/*!50001 CREATE TABLE `v2` ( + `a` varchar(30) default NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1*/; +/*!50001 DROP TABLE IF EXISTS `v2`*/; +/*!50001 DROP VIEW IF EXISTS `v2`*/; +/*!50001 CREATE ALGORITHM=UNDEFINED VIEW `v2` AS select `t2`.`a` AS `a` from `t2` where (`t2`.`a` like _latin1'a%') WITH CASCADED CHECK OPTION*/; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; @@ -1404,6 +1410,33 @@ CREATE ALGORITHM=UNDEFINED VIEW `db1`.`v2` AS select `db1`.`t2`.`a` AS `a` from drop table t2; drop view v2; drop database db1; +create database db2; +use db2; +create table t1 (a int); +create table t2 (a int, b varchar(10), primary key(a)); +insert into t2 values (1, "on"), (2, "off"), (10, "pol"), (12, "meg"); +insert into t1 values (289), (298), (234), (456), (789); +create view v1 as select * from t2; +create view v2 as select * from t1; +drop table t1, t2; +drop view v1, v2; +drop database db2; +create database db1; +use db1; +show tables; +Tables_in_db1 +t1 +t2 +v1 +v2 +select * from t2 order by a; +a b +1 on +2 off +10 pol +12 meg +drop table t1, t2; +drop database db1; CREATE DATABASE mysqldump_test_db; USE mysqldump_test_db; CREATE TABLE t1 ( a INT ); @@ -1598,7 +1631,7 @@ DROP TABLE IF EXISTS `v1`; ) ENGINE=MyISAM DEFAULT CHARSET=latin1*/; /*!50001 DROP TABLE IF EXISTS `v1`*/; /*!50001 DROP VIEW IF EXISTS `v1`*/; -/*!50001 CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select `test`.`t1`.`a` AS `a` from `test`.`t1`*/; +/*!50001 CREATE ALGORITHM=UNDEFINED VIEW `v1` AS select `t1`.`a` AS `a` from `t1`*/; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; @@ -1650,7 +1683,7 @@ DROP TABLE IF EXISTS `v2`; ) ENGINE=MyISAM DEFAULT CHARSET=latin1*/; /*!50001 DROP TABLE IF EXISTS `v2`*/; /*!50001 DROP VIEW IF EXISTS `v2`*/; -/*!50001 CREATE ALGORITHM=UNDEFINED VIEW `mysqldump_test_db`.`v2` AS select `mysqldump_test_db`.`t2`.`a` AS `a` from `mysqldump_test_db`.`t2` where (`mysqldump_test_db`.`t2`.`a` like _latin1'a%') WITH CASCADED CHECK OPTION*/; +/*!50001 CREATE ALGORITHM=UNDEFINED VIEW `v2` AS select `t2`.`a` AS `a` from `t2` where (`t2`.`a` like _latin1'a%') WITH CASCADED CHECK OPTION*/; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; @@ -1714,7 +1747,7 @@ v2 VIEW v3 VIEW show create view v1; View Create View -v1 CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select `v3`.`a` AS `a`,`v3`.`b` AS `b`,`v3`.`c` AS `c` from `test`.`v3` where (`v3`.`b` in (1,2,3,4,5,6,7)) +v1 CREATE ALGORITHM=UNDEFINED VIEW `v1` AS select `v3`.`a` AS `a`,`v3`.`b` AS `b`,`v3`.`c` AS `c` from `v3` where (`v3`.`b` in (1,2,3,4,5,6,7)) select * from v1; a b c 1 2 one diff --git a/mysql-test/r/sql_mode.result b/mysql-test/r/sql_mode.result index 084b257b699..33ab83bbd11 100644 --- a/mysql-test/r/sql_mode.result +++ b/mysql-test/r/sql_mode.result @@ -449,11 +449,11 @@ create table t2 (a int); create view v1 as select a from t1; show create view v1; View Create View -v1 CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select `test`.`t1`.`a` AS `a` from `test`.`t1` +v1 CREATE ALGORITHM=UNDEFINED VIEW `v1` AS select `t1`.`a` AS `a` from `t1` SET @@SQL_MODE='ANSI_QUOTES'; show create view v1; View Create View -v1 CREATE ALGORITHM=UNDEFINED VIEW "test"."v1" AS select "test"."t1"."a" AS "a" from "test"."t1" +v1 CREATE ALGORITHM=UNDEFINED VIEW "v1" AS select "t1"."a" AS "a" from "t1" create view v2 as select a from t2 where a in (select a from v1); drop view v2, v1; drop table t1, t2; diff --git a/mysql-test/r/temp_table.result b/mysql-test/r/temp_table.result index 1b7e3927adb..23d4f2a79b6 100644 --- a/mysql-test/r/temp_table.result +++ b/mysql-test/r/temp_table.result @@ -111,7 +111,7 @@ t1 CREATE TEMPORARY TABLE `t1` ( ) ENGINE=MyISAM DEFAULT CHARSET=latin1 show create view t1; View Create View -t1 CREATE ALGORITHM=UNDEFINED VIEW `test`.`t1` AS select _latin1'This is view' AS `A` +t1 CREATE ALGORITHM=UNDEFINED VIEW `t1` AS select _latin1'This is view' AS `A` drop view t1; select * from t1; A diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 558977a6d2d..8978d5b753c 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -32,10 +32,10 @@ c 11 show create table v1; View Create View -v1 CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select (`test`.`t1`.`b` + 1) AS `c` from `test`.`t1` +v1 CREATE ALGORITHM=UNDEFINED VIEW `v1` AS select (`t1`.`b` + 1) AS `c` from `t1` show create view v1; View Create View -v1 CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select (`test`.`t1`.`b` + 1) AS `c` from `test`.`t1` +v1 CREATE ALGORITHM=UNDEFINED VIEW `v1` AS select (`t1`.`b` + 1) AS `c` from `t1` show create view t1; ERROR HY000: 'test.t1' is not VIEW drop table t1; @@ -55,7 +55,7 @@ Note 1003 select (`test`.`t1`.`b` + 1) AS `c` from `test`.`t1` create algorithm=temptable view v2 (c) as select b+1 from t1; show create view v2; View Create View -v2 CREATE ALGORITHM=TEMPTABLE VIEW `test`.`v2` AS select (`test`.`t1`.`b` + 1) AS `c` from `test`.`t1` +v2 CREATE ALGORITHM=TEMPTABLE VIEW `v2` AS select (`t1`.`b` + 1) AS `c` from `t1` select c from v2; c 3 @@ -550,7 +550,7 @@ create table t1 ("a*b" int); create view v1 as select "a*b" from t1; show create view v1; View Create View -v1 CREATE VIEW "test"."v1" AS select "test"."t1"."a*b" AS "a*b" from "test"."t1" +v1 CREATE VIEW "v1" AS select "t1"."a*b" AS "a*b" from "t1" drop view v1; drop table t1; set sql_mode=default; @@ -657,7 +657,7 @@ drop table t1; CREATE VIEW v1 (f1,f2,f3,f4) AS SELECT connection_id(), pi(), current_user(), version(); SHOW CREATE VIEW v1; View Create View -v1 CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select sql_no_cache connection_id() AS `f1`,pi() AS `f2`,current_user() AS `f3`,version() AS `f4` +v1 CREATE ALGORITHM=UNDEFINED VIEW `v1` AS select sql_no_cache connection_id() AS `f1`,pi() AS `f2`,current_user() AS `f3`,version() AS `f4` drop view v1; create table t1 (s1 int); create table t2 (s2 int); @@ -691,13 +691,13 @@ create view v1 as select a from t1; create view v2 as select a from t2 where a in (select a from v1); show create view v2; View Create View -v2 CREATE ALGORITHM=UNDEFINED VIEW `test`.`v2` AS select `test`.`t2`.`a` AS `a` from `test`.`t2` where `a` in (select `v1`.`a` AS `a` from `test`.`v1`) +v2 CREATE ALGORITHM=UNDEFINED VIEW `v2` AS select `t2`.`a` AS `a` from `t2` where `a` in (select `v1`.`a` AS `a` from `v1`) drop view v2, v1; drop table t1, t2; CREATE VIEW `v 1` AS select 5 AS `5`; show create view `v 1`; View Create View -v 1 CREATE ALGORITHM=UNDEFINED VIEW `test`.`v 1` AS select 5 AS `5` +v 1 CREATE ALGORITHM=UNDEFINED VIEW `v 1` AS select 5 AS `5` drop view `v 1`; create database mysqltest; create table mysqltest.t1 (a int, b int); @@ -765,14 +765,14 @@ a b 1 1 show create view v3; View Create View -v3 CREATE ALGORITHM=UNDEFINED VIEW `test`.`v3` AS select `v1`.`col1` AS `a`,`v2`.`col1` AS `b` from (`test`.`v1` join `test`.`v2`) where (`v1`.`col1` = `v2`.`col1`) +v3 CREATE ALGORITHM=UNDEFINED VIEW `v3` AS select `v1`.`col1` AS `a`,`v2`.`col1` AS `b` from (`v1` join `v2`) where (`v1`.`col1` = `v2`.`col1`) drop view v3, v2, v1; drop table t2, t1; create function `f``1` () returns int return 5; create view v1 as select test.`f``1` (); show create view v1; View Create View -v1 CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select sql_no_cache `test`.`f``1`() AS `test.``f````1`` ()` +v1 CREATE ALGORITHM=UNDEFINED VIEW `v1` AS select sql_no_cache `test`.`f``1`() AS `test.``f````1`` ()` select * from v1; test.`f``1` () 5 @@ -789,10 +789,10 @@ create table t2 (col1 char collate latin1_german2_ci); create view v2 as select col1 collate latin1_german1_ci from t2; show create view v2; View Create View -v2 CREATE ALGORITHM=UNDEFINED VIEW `test`.`v2` AS select (`test`.`t2`.`col1` collate latin1_german1_ci) AS `col1 collate latin1_german1_ci` from `test`.`t2` +v2 CREATE ALGORITHM=UNDEFINED VIEW `v2` AS select (`t2`.`col1` collate latin1_german1_ci) AS `col1 collate latin1_german1_ci` from `t2` show create view v2; View Create View -v2 CREATE ALGORITHM=UNDEFINED VIEW `test`.`v2` AS select (`test`.`t2`.`col1` collate latin1_german1_ci) AS `col1 collate latin1_german1_ci` from `test`.`t2` +v2 CREATE ALGORITHM=UNDEFINED VIEW `v2` AS select (`t2`.`col1` collate latin1_german1_ci) AS `col1 collate latin1_german1_ci` from `t2` drop view v2; drop table t2; create table t1 (a int); @@ -819,7 +819,7 @@ drop table t1; create view v1 as select 99999999999999999999999999999999999999999999999999999 as col1; show create view v1; View Create View -v1 CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select 99999999999999999999999999999999999999999999999999999 AS `col1` +v1 CREATE ALGORITHM=UNDEFINED VIEW `v1` AS select 99999999999999999999999999999999999999999999999999999 AS `col1` drop view v1; create table tü (cü char); create view vü as select cü from tü; @@ -840,7 +840,7 @@ drop table t1; create view v1 as select cast(1 as char(3)); show create view v1; View Create View -v1 CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select cast(1 as char(3) charset latin1) AS `cast(1 as char(3))` +v1 CREATE ALGORITHM=UNDEFINED VIEW `v1` AS select cast(1 as char(3) charset latin1) AS `cast(1 as char(3))` select * from v1; cast(1 as char(3)) 1 @@ -1157,19 +1157,19 @@ create table t1 (a int); create view v1 as select * from t1; show create view v1; View Create View -v1 CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select `test`.`t1`.`a` AS `a` from `test`.`t1` +v1 CREATE ALGORITHM=UNDEFINED VIEW `v1` AS select `t1`.`a` AS `a` from `t1` alter algorithm=undefined view v1 as select * from t1 with check option; show create view v1; View Create View -v1 CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select `test`.`t1`.`a` AS `a` from `test`.`t1` WITH CASCADED CHECK OPTION +v1 CREATE ALGORITHM=UNDEFINED VIEW `v1` AS select `t1`.`a` AS `a` from `t1` WITH CASCADED CHECK OPTION alter algorithm=merge view v1 as select * from t1 with cascaded check option; show create view v1; View Create View -v1 CREATE ALGORITHM=MERGE VIEW `test`.`v1` AS select `test`.`t1`.`a` AS `a` from `test`.`t1` WITH CASCADED CHECK OPTION +v1 CREATE ALGORITHM=MERGE VIEW `v1` AS select `t1`.`a` AS `a` from `t1` WITH CASCADED CHECK OPTION alter algorithm=temptable view v1 as select * from t1; show create view v1; View Create View -v1 CREATE ALGORITHM=TEMPTABLE VIEW `test`.`v1` AS select `test`.`t1`.`a` AS `a` from `test`.`t1` +v1 CREATE ALGORITHM=TEMPTABLE VIEW `v1` AS select `t1`.`a` AS `a` from `t1` drop view v1; drop table t1; create table t1 (s1 int); @@ -1841,24 +1841,24 @@ create table t2 (b timestamp default now()); create view v1 as select a,b,t1.a < now() from t1,t2 where t1.a < now(); SHOW CREATE VIEW v1; View Create View -v1 CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select sql_no_cache `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b`,(`test`.`t1`.`a` < now()) AS `t1.a < now()` from (`test`.`t1` join `test`.`t2`) where (`test`.`t1`.`a` < now()) +v1 CREATE ALGORITHM=UNDEFINED VIEW `v1` AS select sql_no_cache `t1`.`a` AS `a`,`t2`.`b` AS `b`,(`t1`.`a` < now()) AS `t1.a < now()` from (`t1` join `t2`) where (`t1`.`a` < now()) drop view v1; drop table t1, t2; CREATE TABLE t1 ( a varchar(50) ); CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = CURRENT_USER(); SHOW CREATE VIEW v1; View Create View -v1 CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select sql_no_cache `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = current_user()) +v1 CREATE ALGORITHM=UNDEFINED VIEW `v1` AS select sql_no_cache `t1`.`a` AS `a` from `t1` where (`t1`.`a` = current_user()) DROP VIEW v1; CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = VERSION(); SHOW CREATE VIEW v1; View Create View -v1 CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = version()) +v1 CREATE ALGORITHM=UNDEFINED VIEW `v1` AS select `t1`.`a` AS `a` from `t1` where (`t1`.`a` = version()) DROP VIEW v1; CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = DATABASE(); SHOW CREATE VIEW v1; View Create View -v1 CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select sql_no_cache `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = database()) +v1 CREATE ALGORITHM=UNDEFINED VIEW `v1` AS select sql_no_cache `t1`.`a` AS `a` from `t1` where (`t1`.`a` = database()) DROP VIEW v1; DROP TABLE t1; CREATE TABLE t1 (col1 time); @@ -1949,7 +1949,7 @@ create table t1 (s1 int); create view v1 as select var_samp(s1) from t1; show create view v1; View Create View -v1 CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select var_samp(`test`.`t1`.`s1`) AS `var_samp(s1)` from `test`.`t1` +v1 CREATE ALGORITHM=UNDEFINED VIEW `v1` AS select var_samp(`t1`.`s1`) AS `var_samp(s1)` from `t1` drop view v1; drop table t1; set sql_mode='strict_all_tables'; diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index cea5164a646..addb82a08fb 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -576,7 +576,7 @@ drop database db1; # Bug 10713 mysqldump includes database in create view and referenced tables # -# create table and views in testdb2 +# create table and views in db2 create database db2; use db2; create table t1 (a int); @@ -587,7 +587,6 @@ create view v1 as select * from t2; create view v2 as select * from t1; # dump tables and view from db2 ---exec $MYSQL_DUMP db2 --exec $MYSQL_DUMP db2 > var/tmp/bug10713.sql # drop the db, tables and views @@ -602,10 +601,9 @@ use db1; # check that all tables and views could be created show tables; -#select * from t2 order by a; +select * from t2 order by a; -#drop table t1, t2; -#drop view t1, t2; +drop table t1, t2; drop database db1; # # Bug #9558 mysqldump --no-data db t1 t2 format still dumps data diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 2a45be27bdc..fa4b5d314ff 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1050,12 +1050,12 @@ view_store_create_info(THD *thd, TABLE_LIST *table, String *buff) - if user has db of this view as current db - if this view only references table inside it's own db */ - if(strcmp(thd->db, table->view_db.str)) + if (!thd->db || strcmp(thd->db, table->view_db.str)) table->compact_view_format= FALSE; else { - table->compact_view_format= TRUE; TABLE_LIST *tbl; + table->compact_view_format= TRUE; for (tbl= thd->lex->query_tables; tbl; tbl= tbl->next_global)