mirror of
https://github.com/MariaDB/server.git
synced 2025-08-07 00:04:31 +03:00
new method to detect commands where all VIEWs should be temporary tables (BUG#4803)
mysql-test/r/view.result: Showing VIEW with VIEWs in subquery mysql-test/t/view.test: Showing VIEW with VIEWs in subquery sql/sql_lex.cc: new method to detect commands where all VIEWs should be temporary tables sql/sql_lex.h: new method to detect commands where all VIEWs should be temporary tables sql/sql_view.cc: new method to detect commands where all VIEWs should be temporary tables debug output added
This commit is contained in:
@@ -1083,3 +1083,12 @@ count(*)
|
|||||||
2
|
2
|
||||||
drop view v1;
|
drop view v1;
|
||||||
drop table t1;
|
drop table t1;
|
||||||
|
create table t1 (a int);
|
||||||
|
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
|
||||||
|
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;
|
||||||
|
@@ -1027,3 +1027,14 @@ insert into t1 values (null);
|
|||||||
select * from v1;
|
select * from v1;
|
||||||
drop view v1;
|
drop view v1;
|
||||||
drop table t1;
|
drop table t1;
|
||||||
|
|
||||||
|
#
|
||||||
|
# Showing VIEW with VIEWs in subquery
|
||||||
|
#
|
||||||
|
create table t1 (a int);
|
||||||
|
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;
|
||||||
|
drop view v2, v1;
|
||||||
|
drop table t1, t2;
|
||||||
|
@@ -1546,7 +1546,7 @@ bool st_lex::can_be_merged()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
check if command can use VIEW with MERGE algorithm
|
check if command can use VIEW with MERGE algorithm (for top VIEWs)
|
||||||
|
|
||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
st_lex::can_use_merged()
|
st_lex::can_use_merged()
|
||||||
@@ -1576,6 +1576,29 @@ bool st_lex::can_use_merged()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
check if command can't use merged views in any part of command
|
||||||
|
|
||||||
|
SYNOPSIS
|
||||||
|
st_lex::can_not_use_merged()
|
||||||
|
|
||||||
|
RETURN
|
||||||
|
FALSE - command can't use merged VIEWs
|
||||||
|
TRUE - VIEWs with MERGE algorithms can be used
|
||||||
|
*/
|
||||||
|
|
||||||
|
bool st_lex::can_not_use_merged()
|
||||||
|
{
|
||||||
|
switch (sql_command)
|
||||||
|
{
|
||||||
|
case SQLCOM_CREATE_VIEW:
|
||||||
|
case SQLCOM_SHOW_CREATE:
|
||||||
|
return TRUE;
|
||||||
|
default:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Detect that we need only table structure of derived table/view
|
Detect that we need only table structure of derived table/view
|
||||||
|
|
||||||
|
@@ -749,6 +749,7 @@ typedef struct st_lex
|
|||||||
|
|
||||||
bool can_be_merged();
|
bool can_be_merged();
|
||||||
bool can_use_merged();
|
bool can_use_merged();
|
||||||
|
bool can_not_use_merged();
|
||||||
bool only_view_structure();
|
bool only_view_structure();
|
||||||
} LEX;
|
} LEX;
|
||||||
|
|
||||||
|
@@ -659,7 +659,8 @@ mysql_make_view(File_parser *parser, TABLE_LIST *table)
|
|||||||
if (table->algorithm != VIEW_ALGORITHM_TMEPTABLE &&
|
if (table->algorithm != VIEW_ALGORITHM_TMEPTABLE &&
|
||||||
lex->can_be_merged() &&
|
lex->can_be_merged() &&
|
||||||
(table->select_lex->master_unit() != &old_lex->unit ||
|
(table->select_lex->master_unit() != &old_lex->unit ||
|
||||||
old_lex->can_use_merged()))
|
old_lex->can_use_merged()) &&
|
||||||
|
!old_lex->can_not_use_merged())
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
TODO: support multi tables substitutions
|
TODO: support multi tables substitutions
|
||||||
@@ -672,6 +673,7 @@ mysql_make_view(File_parser *parser, TABLE_LIST *table)
|
|||||||
DBUG_ASSERT(view_table != 0);
|
DBUG_ASSERT(view_table != 0);
|
||||||
|
|
||||||
table->effective_algorithm= VIEW_ALGORITHM_MERGE;
|
table->effective_algorithm= VIEW_ALGORITHM_MERGE;
|
||||||
|
DBUG_PRINT("info", ("algorithm: MERGE"));
|
||||||
table->updatable= (table->updatable_view != 0);
|
table->updatable= (table->updatable_view != 0);
|
||||||
|
|
||||||
if (old_next)
|
if (old_next)
|
||||||
@@ -701,6 +703,7 @@ mysql_make_view(File_parser *parser, TABLE_LIST *table)
|
|||||||
}
|
}
|
||||||
|
|
||||||
table->effective_algorithm= VIEW_ALGORITHM_TMEPTABLE;
|
table->effective_algorithm= VIEW_ALGORITHM_TMEPTABLE;
|
||||||
|
DBUG_PRINT("info", ("algorithm: TEMPORARY TABLE"));
|
||||||
lex->select_lex.linkage= DERIVED_TABLE_TYPE;
|
lex->select_lex.linkage= DERIVED_TABLE_TYPE;
|
||||||
table->updatable= 0;
|
table->updatable= 0;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user