mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
new show create view output
mysqldump view support (BUG#4972) workaround to allow view work after LOCK TABLES
This commit is contained in:
@ -105,6 +105,8 @@ static uint opt_protocol= 0;
|
||||
static char *default_charset= (char*) MYSQL_UNIVERSAL_CLIENT_CHARSET;
|
||||
static CHARSET_INFO *charset_info= &my_charset_latin1;
|
||||
const char *default_dbug_option="d:t:o,/tmp/mysqldump.trace";
|
||||
/* do we met VIEWs during tables scaning */
|
||||
my_bool was_views= 0;
|
||||
|
||||
const char *compatible_mode_names[]=
|
||||
{
|
||||
@ -333,6 +335,8 @@ static int dump_databases(char **);
|
||||
static int dump_all_databases();
|
||||
static char *quote_name(const char *name, char *buff, my_bool force);
|
||||
static const char *check_if_ignore_table(const char *table_name);
|
||||
static my_bool getViewStructure(char *table, char* db);
|
||||
static my_bool dump_all_views_in_db(char *database);
|
||||
|
||||
#include <help_start.h>
|
||||
|
||||
@ -964,6 +968,7 @@ static uint getTableStructure(char *table, char* db)
|
||||
{
|
||||
/* Make an sql-file, if path was given iow. option -T was given */
|
||||
char buff[20+FN_REFLEN];
|
||||
MYSQL_FIELD *field;
|
||||
|
||||
sprintf(buff,"show create table %s", result_table);
|
||||
if (mysql_query(sock, buff))
|
||||
@ -999,8 +1004,16 @@ static uint getTableStructure(char *table, char* db)
|
||||
check_io(sql_file);
|
||||
}
|
||||
|
||||
tableRes=mysql_store_result(sock);
|
||||
row=mysql_fetch_row(tableRes);
|
||||
tableRes= mysql_store_result(sock);
|
||||
field= mysql_fetch_field_direct(tableRes, 0);
|
||||
if (strcmp(field->name, "View") == 0)
|
||||
{
|
||||
if (verbose)
|
||||
fprintf(stderr, "-- It's a view, skipped\n");
|
||||
was_views= 1;
|
||||
DBUG_RETURN(0)
|
||||
}
|
||||
row= mysql_fetch_row(tableRes);
|
||||
fprintf(sql_file, "%s;\n", row[1]);
|
||||
check_io(sql_file);
|
||||
mysql_free_result(tableRes);
|
||||
@ -1752,6 +1765,21 @@ static int dump_all_databases()
|
||||
if (dump_all_tables_in_db(row[0]))
|
||||
result=1;
|
||||
}
|
||||
if (was_views)
|
||||
{
|
||||
if (mysql_query(sock, "SHOW DATABASES") ||
|
||||
!(tableres = mysql_store_result(sock)))
|
||||
{
|
||||
my_printf_error(0, "Error: Couldn't execute 'SHOW DATABASES': %s",
|
||||
MYF(0), mysql_error(sock));
|
||||
return 1;
|
||||
}
|
||||
while ((row = mysql_fetch_row(tableres)))
|
||||
{
|
||||
if (dump_all_views_in_db(row[0]))
|
||||
result=1;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/* dump_all_databases */
|
||||
@ -1760,11 +1788,20 @@ static int dump_all_databases()
|
||||
static int dump_databases(char **db_names)
|
||||
{
|
||||
int result=0;
|
||||
for ( ; *db_names ; db_names++)
|
||||
char **db;
|
||||
for (db= db_names ; *db ; db++)
|
||||
{
|
||||
if (dump_all_tables_in_db(*db_names))
|
||||
if (dump_all_tables_in_db(*db))
|
||||
result=1;
|
||||
}
|
||||
if (!result && was_views)
|
||||
{
|
||||
for (db= db_names ; *db ; db++)
|
||||
{
|
||||
if (dump_all_views_in_db(*db))
|
||||
result=1;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} /* dump_databases */
|
||||
|
||||
@ -1872,11 +1909,64 @@ static int dump_all_tables_in_db(char *database)
|
||||
return 0;
|
||||
} /* dump_all_tables_in_db */
|
||||
|
||||
/*
|
||||
dump structure of views of database
|
||||
|
||||
SYNOPSIS
|
||||
dump_all_views_in_db()
|
||||
database database name
|
||||
|
||||
RETURN
|
||||
0 OK
|
||||
1 ERROR
|
||||
*/
|
||||
|
||||
static my_bool dump_all_views_in_db(char *database)
|
||||
{
|
||||
char *table;
|
||||
uint numrows;
|
||||
char table_buff[NAME_LEN*2+3];
|
||||
|
||||
if (init_dumping(database))
|
||||
return 1;
|
||||
if (opt_xml)
|
||||
print_xml_tag1(md_result_file, "", "database name=", database, "\n");
|
||||
if (lock_tables)
|
||||
{
|
||||
DYNAMIC_STRING query;
|
||||
init_dynamic_string(&query, "LOCK TABLES ", 256, 1024);
|
||||
for (numrows= 0 ; (table= getTableName(1)); numrows++)
|
||||
{
|
||||
dynstr_append(&query, quote_name(table, table_buff, 1));
|
||||
dynstr_append(&query, " READ /*!32311 LOCAL */,");
|
||||
}
|
||||
if (numrows && mysql_real_query(sock, query.str, query.length-1))
|
||||
DBerror(sock, "when using LOCK TABLES");
|
||||
/* We shall continue here, if --force was given */
|
||||
dynstr_free(&query);
|
||||
}
|
||||
if (flush_logs)
|
||||
{
|
||||
if (mysql_refresh(sock, REFRESH_LOG))
|
||||
DBerror(sock, "when doing refresh");
|
||||
/* We shall continue here, if --force was given */
|
||||
}
|
||||
while ((table= getTableName(0)))
|
||||
getViewStructure(table, database);
|
||||
if (opt_xml)
|
||||
{
|
||||
fputs("</database>\n", md_result_file);
|
||||
check_io(md_result_file);
|
||||
}
|
||||
if (lock_tables)
|
||||
mysql_query(sock,"UNLOCK TABLES");
|
||||
return 0;
|
||||
} /* dump_all_tables_in_db */
|
||||
|
||||
static int dump_selected_tables(char *db, char **table_names, int tables)
|
||||
{
|
||||
uint numrows;
|
||||
int i;
|
||||
char table_buff[NAME_LEN*+3];
|
||||
|
||||
if (init_dumping(db))
|
||||
@ -1884,7 +1974,6 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
|
||||
if (lock_tables)
|
||||
{
|
||||
DYNAMIC_STRING query;
|
||||
int i;
|
||||
|
||||
init_dynamic_string(&query, "LOCK TABLES ", 256, 1024);
|
||||
for (i=0 ; i < tables ; i++)
|
||||
@ -1905,11 +1994,16 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
|
||||
}
|
||||
if (opt_xml)
|
||||
print_xml_tag1(md_result_file, "", "database name=", db, "\n");
|
||||
for (; tables > 0 ; tables-- , table_names++)
|
||||
for (i=0 ; i < tables ; i++)
|
||||
{
|
||||
numrows = getTableStructure(*table_names, db);
|
||||
numrows = getTableStructure(table_names[i], db);
|
||||
if (!dFlag && numrows > 0)
|
||||
dumpTable(numrows, *table_names);
|
||||
dumpTable(numrows, table_names[i]);
|
||||
}
|
||||
if (was_views)
|
||||
{
|
||||
for (i=0 ; i < tables ; i++)
|
||||
getViewStructure(table_names[i], db);
|
||||
}
|
||||
if (opt_xml)
|
||||
{
|
||||
@ -2048,6 +2142,100 @@ static const char *check_if_ignore_table(const char *table_name)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Getting VIEW structure
|
||||
|
||||
SYNOPSIS
|
||||
getViewStructure()
|
||||
table view name
|
||||
db db name
|
||||
|
||||
RETURN
|
||||
0 OK
|
||||
1 ERROR
|
||||
*/
|
||||
|
||||
static my_bool getViewStructure(char *table, char* db)
|
||||
{
|
||||
MYSQL_RES *tableRes;
|
||||
MYSQL_ROW row;
|
||||
MYSQL_FIELD *field;
|
||||
char *result_table, *opt_quoted_table;
|
||||
char table_buff[NAME_LEN*2+3];
|
||||
char table_buff2[NAME_LEN*2+3];
|
||||
char buff[20+FN_REFLEN];
|
||||
FILE *sql_file = md_result_file;
|
||||
DBUG_ENTER("getViewStructure");
|
||||
|
||||
if (tFlag)
|
||||
DBUG_RETURN(0);
|
||||
|
||||
if (verbose)
|
||||
fprintf(stderr, "-- Retrieving view structure for table %s...\n", table);
|
||||
|
||||
sprintf(insert_pat,"SET OPTION SQL_QUOTE_SHOW_CREATE=%d",
|
||||
(opt_quoted || opt_keywords));
|
||||
result_table= quote_name(table, table_buff, 1);
|
||||
opt_quoted_table= quote_name(table, table_buff2, 0);
|
||||
|
||||
sprintf(buff,"show create table %s", result_table);
|
||||
if (mysql_query(sock, buff))
|
||||
{
|
||||
fprintf(stderr, "%s: Can't get CREATE TABLE for view %s (%s)\n",
|
||||
my_progname, result_table, mysql_error(sock));
|
||||
safe_exit(EX_MYSQLERR);
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
|
||||
if (path)
|
||||
{
|
||||
char filename[FN_REFLEN], tmp_path[FN_REFLEN];
|
||||
convert_dirname(tmp_path,path,NullS);
|
||||
sql_file= my_fopen(fn_format(filename, table, tmp_path, ".sql", 4),
|
||||
O_WRONLY, MYF(MY_WME));
|
||||
if (!sql_file) /* If file couldn't be opened */
|
||||
{
|
||||
safe_exit(EX_MYSQLERR);
|
||||
DBUG_RETURN(1);
|
||||
}
|
||||
write_header(sql_file, db);
|
||||
}
|
||||
tableRes= mysql_store_result(sock);
|
||||
field= mysql_fetch_field_direct(tableRes, 0);
|
||||
if (strcmp(field->name, "View") != 0)
|
||||
{
|
||||
if (verbose)
|
||||
fprintf(stderr, "-- It's base table, skipped\n");
|
||||
DBUG_RETURN(0)
|
||||
}
|
||||
|
||||
if (!opt_xml && opt_comments)
|
||||
{
|
||||
fprintf(sql_file, "\n--\n-- View structure for view %s\n--\n\n",
|
||||
result_table);
|
||||
check_io(sql_file);
|
||||
}
|
||||
if (opt_drop)
|
||||
{
|
||||
fprintf(sql_file, "DROP VIEW IF EXISTS %s;\n", opt_quoted_table);
|
||||
check_io(sql_file);
|
||||
}
|
||||
|
||||
row= mysql_fetch_row(tableRes);
|
||||
fprintf(sql_file, "%s;\n", row[1]);
|
||||
check_io(sql_file);
|
||||
mysql_free_result(tableRes);
|
||||
|
||||
if (sql_file != md_result_file)
|
||||
{
|
||||
fputs("\n", sql_file);
|
||||
write_footer(sql_file);
|
||||
my_fclose(sql_file, MYF(MY_WME));
|
||||
}
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
MYSQL_ROW row;
|
||||
|
@ -6,7 +6,7 @@ use MySQLTest;
|
||||
create table TaB (Field int);
|
||||
create view ViE as select * from TAb;
|
||||
show create table VIe;
|
||||
Table Create Table
|
||||
View Create View
|
||||
vie CREATE VIEW `mysqltest`.`vie` AS select `mysqltest`.`tab`.`Field` AS `Field` from `mysqltest`.`tab`
|
||||
drop database MySQLTest;
|
||||
use test;
|
||||
|
@ -31,10 +31,10 @@ c
|
||||
6
|
||||
11
|
||||
show create table v1;
|
||||
Table Create Table
|
||||
View Create View
|
||||
v1 CREATE VIEW `test`.`v1` AS select (`test`.`t1`.`b` + 1) AS `c` from `test`.`t1`
|
||||
show create view v1;
|
||||
Table Create Table
|
||||
View Create View
|
||||
v1 CREATE VIEW `test`.`v1` AS select (`test`.`t1`.`b` + 1) AS `c` from `test`.`t1`
|
||||
show create view t1;
|
||||
ERROR HY000: 'test.t1' is not VIEW
|
||||
@ -53,8 +53,8 @@ id select_type table type possible_keys key key_len ref rows Extra
|
||||
Warnings:
|
||||
Note 1003 select (`test`.`t1`.`b` + 1) AS `c` from `test`.`v1`
|
||||
create algorithm=temptable view v2 (c) as select b+1 from t1;
|
||||
show create table v2;
|
||||
Table Create Table
|
||||
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`
|
||||
select c from v2;
|
||||
c
|
||||
@ -286,66 +286,66 @@ c bigint(20) YES NULL
|
||||
d bigint(20) YES NULL
|
||||
explain select c from mysqltest.v1;
|
||||
ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
|
||||
show create table mysqltest.v1;
|
||||
show create view mysqltest.v1;
|
||||
ERROR 42000: show create view command denied to user 'mysqltest_1'@'localhost' for table 'v1'
|
||||
explain select c from mysqltest.v2;
|
||||
ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
|
||||
show create table mysqltest.v2;
|
||||
show create view mysqltest.v2;
|
||||
ERROR 42000: show create view command denied to user 'mysqltest_1'@'localhost' for table 'v2'
|
||||
explain select c from mysqltest.v3;
|
||||
ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
|
||||
show create table mysqltest.v3;
|
||||
show create view mysqltest.v3;
|
||||
ERROR 42000: show create view command denied to user 'mysqltest_1'@'localhost' for table 'v3'
|
||||
explain select c from mysqltest.v4;
|
||||
ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
|
||||
show create table mysqltest.v4;
|
||||
show create view mysqltest.v4;
|
||||
ERROR 42000: show create view command denied to user 'mysqltest_1'@'localhost' for table 'v4'
|
||||
grant select on mysqltest.t1 to mysqltest_1@localhost;
|
||||
explain select c from mysqltest.v1;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY t1 system NULL NULL NULL NULL 0 const row not found
|
||||
show create table mysqltest.v1;
|
||||
show create view mysqltest.v1;
|
||||
ERROR 42000: show create view command denied to user 'mysqltest_1'@'localhost' for table 'v1'
|
||||
explain select c from mysqltest.v2;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY <derived2> system NULL NULL NULL NULL 0 const row not found
|
||||
2 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table
|
||||
show create table mysqltest.v2;
|
||||
show create view mysqltest.v2;
|
||||
ERROR 42000: show create view command denied to user 'mysqltest_1'@'localhost' for table 'v2'
|
||||
explain select c from mysqltest.v3;
|
||||
ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
|
||||
show create table mysqltest.v3;
|
||||
show create view mysqltest.v3;
|
||||
ERROR 42000: show create view command denied to user 'mysqltest_1'@'localhost' for table 'v3'
|
||||
explain select c from mysqltest.v4;
|
||||
ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
|
||||
show create table mysqltest.v4;
|
||||
show create view mysqltest.v4;
|
||||
ERROR 42000: show create view command denied to user 'mysqltest_1'@'localhost' for table 'v4'
|
||||
grant show view on mysqltest.* to mysqltest_1@localhost;
|
||||
explain select c from mysqltest.v1;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY t1 system NULL NULL NULL NULL 0 const row not found
|
||||
show create table mysqltest.v1;
|
||||
Table Create Table
|
||||
show create view mysqltest.v1;
|
||||
View Create View
|
||||
v1 CREATE VIEW `mysqltest`.`v1` AS select (`mysqltest`.`t1`.`a` + 1) AS `c`,(`mysqltest`.`t1`.`b` + 1) AS `d` from `mysqltest`.`t1`
|
||||
explain select c from mysqltest.v2;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY <derived2> system NULL NULL NULL NULL 0 const row not found
|
||||
2 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table
|
||||
show create table mysqltest.v2;
|
||||
Table Create Table
|
||||
show create view mysqltest.v2;
|
||||
View Create View
|
||||
v2 CREATE ALGORITHM=TEMPTABLE VIEW `mysqltest`.`v2` AS select (`mysqltest`.`t1`.`a` + 1) AS `c`,(`mysqltest`.`t1`.`b` + 1) AS `d` from `mysqltest`.`t1`
|
||||
explain select c from mysqltest.v3;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY t2 system NULL NULL NULL NULL 0 const row not found
|
||||
show create table mysqltest.v3;
|
||||
Table Create Table
|
||||
show create view mysqltest.v3;
|
||||
View Create View
|
||||
v3 CREATE VIEW `mysqltest`.`v3` AS select (`mysqltest`.`t2`.`a` + 1) AS `c`,(`mysqltest`.`t2`.`b` + 1) AS `d` from `mysqltest`.`t2`
|
||||
explain select c from mysqltest.v4;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY <derived2> system NULL NULL NULL NULL 0 const row not found
|
||||
2 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table
|
||||
show create table mysqltest.v4;
|
||||
Table Create Table
|
||||
show create view mysqltest.v4;
|
||||
View Create View
|
||||
v4 CREATE ALGORITHM=TEMPTABLE VIEW `mysqltest`.`v4` AS select (`mysqltest`.`t2`.`a` + 1) AS `c`,(`mysqltest`.`t2`.`b` + 1) AS `d` from `mysqltest`.`t2`
|
||||
revoke all privileges on mysqltest.* from mysqltest_1@localhost;
|
||||
delete from mysql.user where user='mysqltest_1';
|
||||
@ -946,7 +946,7 @@ set sql_mode='ansi';
|
||||
create table t1 ("a*b" int);
|
||||
create view v1 as select "a*b" from t1;
|
||||
show create view v1;
|
||||
Table Create Table
|
||||
View Create View
|
||||
v1 CREATE VIEW "test"."v1" AS select `test`.`t1`.`a*b` AS `a*b` from `test`.`t1`
|
||||
drop view v1;
|
||||
drop table t1;
|
||||
@ -1054,7 +1054,7 @@ drop view v1;
|
||||
drop table t1;
|
||||
CREATE VIEW v1 (f1,f2,f3,f4) AS SELECT connection_id(), pi(), current_user(), version();
|
||||
SHOW CREATE VIEW v1;
|
||||
Table Create Table
|
||||
View Create View
|
||||
v1 CREATE VIEW `test`.`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);
|
||||
@ -1088,13 +1088,13 @@ create table t2 (a int);
|
||||
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;
|
||||
Table Create Table
|
||||
View Create View
|
||||
v2 CREATE VIEW `test`.`v2` AS select `test`.`t2`.`a` AS `a` from `test`.`t2` where `a` in (select `v1`.`a` AS `a` from `test`.`v1`)
|
||||
drop view v2, v1;
|
||||
drop table t1, t2;
|
||||
CREATE VIEW `v 1` AS select 5 AS `5`;
|
||||
show create view `v 1`;
|
||||
Table Create Table
|
||||
View Create View
|
||||
v 1 CREATE VIEW `test`.`v 1` AS select 5 AS `5`
|
||||
drop view `v 1`;
|
||||
create database mysqltest;
|
||||
@ -1162,14 +1162,14 @@ select * from v3;
|
||||
a b
|
||||
1 1
|
||||
show create view v3;
|
||||
Table Create Table
|
||||
View Create View
|
||||
v3 CREATE VIEW `test`.`v3` AS select `v1`.`col1` AS `a`,`v2`.`col1` AS `b` from `test`.`v1` join `test`.`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;
|
||||
Table Create Table
|
||||
View Create View
|
||||
v1 CREATE VIEW `test`.`v1` AS select `test`.`f``1`() AS `test.``f````1`` ()`
|
||||
select * from v1;
|
||||
test.`f``1` ()
|
||||
@ -1186,10 +1186,10 @@ drop function x;
|
||||
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;
|
||||
Table Create Table
|
||||
View Create View
|
||||
v2 CREATE VIEW `test`.`v2` AS select (`test`.`t2`.`col1` collate latin1_german1_ci) AS `col1 collate latin1_german1_ci` from `test`.`t2`
|
||||
show create view v2;
|
||||
Table Create Table
|
||||
View Create View
|
||||
v2 CREATE VIEW `test`.`v2` AS select (`test`.`t2`.`col1` collate latin1_german1_ci) AS `col1 collate latin1_german1_ci` from `test`.`t2`
|
||||
drop view v2;
|
||||
drop table t2;
|
||||
@ -1220,7 +1220,7 @@ drop view v1;
|
||||
drop table t1;
|
||||
create view v1 as select 99999999999999999999999999999999999999999999999999999 as col1;
|
||||
show create view v1;
|
||||
Table Create Table
|
||||
View Create View
|
||||
v1 CREATE VIEW `test`.`v1` AS select 99999999999999999999999999999999999999999999999999999 AS `col1`
|
||||
drop view v1;
|
||||
create table t<> (c<> char);
|
||||
@ -1241,7 +1241,7 @@ drop view v1;
|
||||
drop table t1;
|
||||
create view v1 as select cast(1 as char(3));
|
||||
show create view v1;
|
||||
Table Create Table
|
||||
View Create View
|
||||
v1 CREATE VIEW `test`.`v1` AS select cast(1 as char(3) charset latin1) AS `cast(1 as char(3))`
|
||||
select * from v1;
|
||||
cast(1 as char(3))
|
||||
@ -1311,7 +1311,7 @@ a a a
|
||||
3 2 3
|
||||
3 3 3
|
||||
drop view v1;
|
||||
drop table t1;
|
||||
drop table t1, t2;
|
||||
create table t1 (s1 char);
|
||||
create view v1 as select s1 collate latin1_german1_ci as s1 from t1;
|
||||
insert into v1 values ('a');
|
||||
@ -1328,3 +1328,13 @@ s1
|
||||
c
|
||||
drop view v1;
|
||||
drop table t1;
|
||||
create table t1 (a int);
|
||||
create table t2 (a int);
|
||||
create view v1 as select * from t1;
|
||||
lock tables t1 read, v1 read;
|
||||
select * from v1;
|
||||
a
|
||||
select * from t2;
|
||||
ERROR HY000: Table 't2' was not locked with LOCK TABLES
|
||||
drop view v1;
|
||||
drop table t1, t2;
|
||||
|
@ -55,7 +55,7 @@ select v1.b from v1;
|
||||
# view with different algorithms (explain out put are differ)
|
||||
explain extended select c from v1;
|
||||
create algorithm=temptable view v2 (c) as select b+1 from t1;
|
||||
show create table v2;
|
||||
show create view v2;
|
||||
select c from v2;
|
||||
explain extended select c from v2;
|
||||
|
||||
@ -268,19 +268,19 @@ show columns from mysqltest.v2;
|
||||
-- error 1345
|
||||
explain select c from mysqltest.v1;
|
||||
-- error 1142
|
||||
show create table mysqltest.v1;
|
||||
show create view mysqltest.v1;
|
||||
-- error 1345
|
||||
explain select c from mysqltest.v2;
|
||||
-- error 1142
|
||||
show create table mysqltest.v2;
|
||||
show create view mysqltest.v2;
|
||||
-- error 1345
|
||||
explain select c from mysqltest.v3;
|
||||
-- error 1142
|
||||
show create table mysqltest.v3;
|
||||
show create view mysqltest.v3;
|
||||
-- error 1345
|
||||
explain select c from mysqltest.v4;
|
||||
-- error 1142
|
||||
show create table mysqltest.v4;
|
||||
show create view mysqltest.v4;
|
||||
|
||||
# allow to see one of underlaing table
|
||||
connection root;
|
||||
@ -289,32 +289,32 @@ connection user1;
|
||||
# EXPLAIN of view on above table works
|
||||
explain select c from mysqltest.v1;
|
||||
-- error 1142
|
||||
show create table mysqltest.v1;
|
||||
show create view mysqltest.v1;
|
||||
explain select c from mysqltest.v2;
|
||||
-- error 1142
|
||||
show create table mysqltest.v2;
|
||||
show create view mysqltest.v2;
|
||||
# but other EXPLAINs do not
|
||||
-- error 1345
|
||||
explain select c from mysqltest.v3;
|
||||
-- error 1142
|
||||
show create table mysqltest.v3;
|
||||
show create view mysqltest.v3;
|
||||
-- error 1345
|
||||
explain select c from mysqltest.v4;
|
||||
-- error 1142
|
||||
show create table mysqltest.v4;
|
||||
show create view mysqltest.v4;
|
||||
|
||||
# allow to see any view in mysqltest database
|
||||
connection root;
|
||||
grant show view on mysqltest.* to mysqltest_1@localhost;
|
||||
connection user1;
|
||||
explain select c from mysqltest.v1;
|
||||
show create table mysqltest.v1;
|
||||
show create view mysqltest.v1;
|
||||
explain select c from mysqltest.v2;
|
||||
show create table mysqltest.v2;
|
||||
show create view mysqltest.v2;
|
||||
explain select c from mysqltest.v3;
|
||||
show create table mysqltest.v3;
|
||||
show create view mysqltest.v3;
|
||||
explain select c from mysqltest.v4;
|
||||
show create table mysqltest.v4;
|
||||
show create view mysqltest.v4;
|
||||
|
||||
connection root;
|
||||
revoke all privileges on mysqltest.* from mysqltest_1@localhost;
|
||||
@ -1280,7 +1280,7 @@ create view v1 as select a from t1 where a > 1;
|
||||
select * from t1 left join (t2 as t, v1) on v1.a=t1.a;
|
||||
select * from t1 left join (t2 as t, t2) on t2.a=t1.a;
|
||||
drop view v1;
|
||||
drop table t1;
|
||||
drop table t1, t2;
|
||||
|
||||
#
|
||||
# Collation with view update
|
||||
@ -1295,3 +1295,16 @@ update v1,t1 set v1.s1='c' where t1.s1=v1.s1;
|
||||
select * from v1;
|
||||
drop view v1;
|
||||
drop table t1;
|
||||
|
||||
#
|
||||
# test view with LOCK TABLES (work around)
|
||||
#
|
||||
create table t1 (a int);
|
||||
create table t2 (a int);
|
||||
create view v1 as select * from t1;
|
||||
lock tables t1 read, v1 read;
|
||||
select * from v1;
|
||||
-- error 1100
|
||||
select * from t2;
|
||||
drop view v1;
|
||||
drop table t1, t2;
|
||||
|
@ -906,6 +906,36 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
|
||||
goto reset;
|
||||
}
|
||||
}
|
||||
/*
|
||||
is it view?
|
||||
(it is work around to allow to open view with locked tables,
|
||||
real fix will be made after definition cache will be made)
|
||||
*/
|
||||
{
|
||||
char path[FN_REFLEN];
|
||||
strxnmov(path, FN_REFLEN, mysql_data_home, "/", table_list->db, "/",
|
||||
table_list->real_name, reg_ext, NullS);
|
||||
(void) unpack_filename(path, path);
|
||||
if (mysql_frm_type(path) == FRMTYPE_VIEW)
|
||||
{
|
||||
VOID(pthread_mutex_lock(&LOCK_open));
|
||||
if (open_unireg_entry(thd, table, table_list->db,
|
||||
table_list->real_name,
|
||||
alias, table_list, mem_root))
|
||||
{
|
||||
table->next=table->prev=table;
|
||||
free_cache_entry(table);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBUG_ASSERT(table_list->view);
|
||||
my_free((gptr)table, MYF(0));
|
||||
VOID(pthread_mutex_unlock(&LOCK_open));
|
||||
DBUG_RETURN(0); // VIEW
|
||||
}
|
||||
VOID(pthread_mutex_unlock(&LOCK_open));
|
||||
}
|
||||
}
|
||||
my_printf_error(ER_TABLE_NOT_LOCKED,ER(ER_TABLE_NOT_LOCKED),MYF(0),alias);
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
|
@ -879,6 +879,7 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list)
|
||||
table_list->real_name, "VIEW");
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
|
||||
table= table_list->table;
|
||||
|
||||
if ((table_list->view ?
|
||||
@ -887,10 +888,19 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list)
|
||||
DBUG_RETURN(-1);
|
||||
|
||||
List<Item> field_list;
|
||||
if (table_list->view)
|
||||
{
|
||||
field_list.push_back(new Item_empty_string("View",NAME_LEN));
|
||||
field_list.push_back(new Item_empty_string("Create View",
|
||||
max(buffer.length(),1024)));
|
||||
}
|
||||
else
|
||||
{
|
||||
field_list.push_back(new Item_empty_string("Table",NAME_LEN));
|
||||
// 1024 is for not to confuse old clients
|
||||
field_list.push_back(new Item_empty_string("Create Table",
|
||||
max(buffer.length(),1024)));
|
||||
}
|
||||
|
||||
if (protocol->send_fields(&field_list,
|
||||
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
|
||||
|
Reference in New Issue
Block a user