5.1-bugteam->5.5-bugteam merge

This commit is contained in:
Sergey Glukhov 2010-12-14 13:46:00 +03:00
commit a2aa73d92a
24 changed files with 153 additions and 83 deletions

View file

@ -400,4 +400,15 @@ SELECT 0 FROM
(SELECT 0) t61; (SELECT 0) t61;
0 0
0 0
#
# A nested materialized derived table is used before being populated.
# (addon for bug#19077)
#
CREATE TABLE t1 (i INT, j BIGINT);
INSERT INTO t1 VALUES (1, 2), (2, 2), (3, 2);
SELECT * FROM (SELECT MIN(i) FROM t1
WHERE j = SUBSTRING('12', (SELECT * FROM (SELECT MIN(j) FROM t1) t2))) t3;
MIN(i)
1
DROP TABLE t1;
# End of 5.0 tests # End of 5.0 tests

View file

@ -669,4 +669,15 @@ Error 1242 Subquery returns more than 1 row
Error 1242 Subquery returns more than 1 row Error 1242 Subquery returns more than 1 row
DROP TABLE t1, t2, t3; DROP TABLE t1, t2, t3;
SET SESSION sql_safe_updates = DEFAULT; SET SESSION sql_safe_updates = DEFAULT;
#
# Bug#52157 various crashes and assertions with multi-table update, stored function
#
CREATE FUNCTION f1 () RETURNS BLOB RETURN 1;
CREATE TABLE t1 (f1 DATE);
INSERT INTO t1 VALUES('2001-01-01');
UPDATE (SELECT 1 FROM t1 WHERE f1 = (SELECT f1() FROM t1)) x, t1 SET f1 = 1;
Warnings:
Warning 1292 Truncated incorrect datetime value: '1'
DROP FUNCTION f1;
DROP TABLE t1;
end of tests end of tests

View file

@ -3999,6 +3999,19 @@ CREATE VIEW v1 AS SELECT 1 from t1
WHERE t1.b <=> (SELECT a FROM t1 WHERE a < SOME(SELECT '1')); WHERE t1.b <=> (SELECT a FROM t1 WHERE a < SOME(SELECT '1'));
DROP VIEW v1; DROP VIEW v1;
DROP TABLE t1; DROP TABLE t1;
#
# Bug#57703 create view cause Assertion failed: 0, file .\item_subselect.cc, line 846
#
CREATE TABLE t1(a int);
CREATE VIEW v1 AS SELECT 1 FROM t1 GROUP BY
SUBSTRING(1 FROM (SELECT 3 FROM t1 WHERE a >= ANY(SELECT 1)));
DROP VIEW v1;
DROP TABLE t1;
#
# Bug#57352 valgrind warnings when creating view
#
CREATE VIEW v1 AS SELECT 1 IN (1 LIKE 2,0) AS f;
DROP VIEW v1;
# ----------------------------------------------------------------- # -----------------------------------------------------------------
# -- End of 5.1 tests. # -- End of 5.1 tests.
# ----------------------------------------------------------------- # -----------------------------------------------------------------

View file

@ -74,3 +74,11 @@ a b
4 14 4 14
5 15 5 15
drop table bug38999_1,bug38999_2; drop table bug38999_1,bug38999_2;
#
# Bug#54475 improper error handling causes cascading crashing failures in innodb/ndb
#
CREATE TABLE t1(f1 INT) ENGINE=INNODB;
INSERT INTO t1 VALUES(1);
UPDATE (SELECT ((SELECT 1 FROM t1), 1) FROM t1 WHERE (SELECT 1 FROM t1)) x, (SELECT 1) AS d SET d.f1 = 1;
ERROR 21000: Operand should contain 1 column(s)
DROP TABLE t1;

View file

@ -27,3 +27,12 @@ select * from bug38999_1;
select * from bug38999_2; select * from bug38999_2;
drop table bug38999_1,bug38999_2; drop table bug38999_1,bug38999_2;
--echo #
--echo # Bug#54475 improper error handling causes cascading crashing failures in innodb/ndb
--echo #
CREATE TABLE t1(f1 INT) ENGINE=INNODB;
INSERT INTO t1 VALUES(1);
--error ER_OPERAND_COLUMNS
UPDATE (SELECT ((SELECT 1 FROM t1), 1) FROM t1 WHERE (SELECT 1 FROM t1)) x, (SELECT 1) AS d SET d.f1 = 1;
DROP TABLE t1;

View file

@ -301,4 +301,15 @@ SELECT 0 FROM
(SELECT 0) t56, (SELECT 0) t57, (SELECT 0) t58, (SELECT 0) t59, (SELECT 0) t60, (SELECT 0) t56, (SELECT 0) t57, (SELECT 0) t58, (SELECT 0) t59, (SELECT 0) t60,
(SELECT 0) t61; # 61 == MAX_TABLES (SELECT 0) t61; # 61 == MAX_TABLES
--echo #
--echo # A nested materialized derived table is used before being populated.
--echo # (addon for bug#19077)
--echo #
CREATE TABLE t1 (i INT, j BIGINT);
INSERT INTO t1 VALUES (1, 2), (2, 2), (3, 2);
SELECT * FROM (SELECT MIN(i) FROM t1
WHERE j = SUBSTRING('12', (SELECT * FROM (SELECT MIN(j) FROM t1) t2))) t3;
DROP TABLE t1;
--echo # End of 5.0 tests --echo # End of 5.0 tests

View file

@ -672,4 +672,15 @@ SET t3.a = 0;
DROP TABLE t1, t2, t3; DROP TABLE t1, t2, t3;
SET SESSION sql_safe_updates = DEFAULT; SET SESSION sql_safe_updates = DEFAULT;
--echo #
--echo # Bug#52157 various crashes and assertions with multi-table update, stored function
--echo #
CREATE FUNCTION f1 () RETURNS BLOB RETURN 1;
CREATE TABLE t1 (f1 DATE);
INSERT INTO t1 VALUES('2001-01-01');
UPDATE (SELECT 1 FROM t1 WHERE f1 = (SELECT f1() FROM t1)) x, t1 SET f1 = 1;
DROP FUNCTION f1;
DROP TABLE t1;
--echo end of tests --echo end of tests

View file

@ -3963,6 +3963,22 @@ WHERE t1.b <=> (SELECT a FROM t1 WHERE a < SOME(SELECT '1'));
DROP VIEW v1; DROP VIEW v1;
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # Bug#57703 create view cause Assertion failed: 0, file .\item_subselect.cc, line 846
--echo #
CREATE TABLE t1(a int);
CREATE VIEW v1 AS SELECT 1 FROM t1 GROUP BY
SUBSTRING(1 FROM (SELECT 3 FROM t1 WHERE a >= ANY(SELECT 1)));
DROP VIEW v1;
DROP TABLE t1;
--echo #
--echo # Bug#57352 valgrind warnings when creating view
--echo #
CREATE VIEW v1 AS SELECT 1 IN (1 LIKE 2,0) AS f;
DROP VIEW v1;
--echo # ----------------------------------------------------------------- --echo # -----------------------------------------------------------------
--echo # -- End of 5.1 tests. --echo # -- End of 5.1 tests.
--echo # ----------------------------------------------------------------- --echo # -----------------------------------------------------------------

View file

@ -1812,16 +1812,7 @@ bool agg_item_set_converter(DTCollation &coll, const char *fname,
if (!(conv= (*arg)->safe_charset_converter(coll.collation)) && if (!(conv= (*arg)->safe_charset_converter(coll.collation)) &&
((*arg)->collation.repertoire == MY_REPERTOIRE_ASCII)) ((*arg)->collation.repertoire == MY_REPERTOIRE_ASCII))
{ conv= new Item_func_conv_charset(*arg, coll.collation, 1);
/*
We should disable const subselect item evaluation because
subselect transformation does not happen in view_prepare_mode
and thus val_...() methods can not be called for const items.
*/
bool resolve_const= ((*arg)->type() == Item::SUBSELECT_ITEM &&
thd->lex->view_prepare_mode) ? FALSE : TRUE;
conv= new Item_func_conv_charset(*arg, coll.collation, resolve_const);
}
if (!conv) if (!conv)
{ {

View file

@ -403,7 +403,7 @@ static bool convert_constant_item(THD *thd, Item_field *field_item,
Field *field= field_item->field; Field *field= field_item->field;
int result= 0; int result= 0;
if (!(*item)->with_subselect && (*item)->const_item()) if ((*item)->const_item())
{ {
TABLE *table= field->table; TABLE *table= field->table;
ulonglong orig_sql_mode= thd->variables.sql_mode; ulonglong orig_sql_mode= thd->variables.sql_mode;
@ -499,7 +499,7 @@ void Item_bool_func2::fix_length_and_dec()
} }
thd= current_thd; thd= current_thd;
if (!thd->is_context_analysis_only()) if (!thd->lex->is_ps_or_view_context_analysis())
{ {
if (args[0]->real_item()->type() == FIELD_ITEM) if (args[0]->real_item()->type() == FIELD_ITEM)
{ {
@ -803,7 +803,7 @@ Arg_comparator::can_compare_as_dates(Item *a, Item *b, ulonglong *const_value)
confuse storage engines since in context analysis mode tables confuse storage engines since in context analysis mode tables
aren't locked. aren't locked.
*/ */
if (!thd->is_context_analysis_only() && if (!thd->lex->is_ps_or_view_context_analysis() &&
cmp_type != CMP_DATE_WITH_DATE && str_arg->const_item() && cmp_type != CMP_DATE_WITH_DATE && str_arg->const_item() &&
(str_arg->type() != Item::FUNC_ITEM || (str_arg->type() != Item::FUNC_ITEM ||
((Item_func*)str_arg)->functype() != Item_func::GUSERVAR_FUNC)) ((Item_func*)str_arg)->functype() != Item_func::GUSERVAR_FUNC))
@ -1036,7 +1036,7 @@ Item** Arg_comparator::cache_converted_constant(THD *thd_arg, Item **value,
Item_result type) Item_result type)
{ {
/* Don't need cache if doing context analysis only. */ /* Don't need cache if doing context analysis only. */
if (!thd_arg->is_context_analysis_only() && if (!thd->lex->is_ps_or_view_context_analysis() &&
(*value)->const_item() && type != (*value)->result_type()) (*value)->const_item() && type != (*value)->result_type())
{ {
Item_cache *cache= Item_cache::get_cache(*value, type); Item_cache *cache= Item_cache::get_cache(*value, type);
@ -4714,7 +4714,7 @@ bool Item_func_like::fix_fields(THD *thd, Item **ref)
return TRUE; return TRUE;
} }
if (escape_item->const_item() && !thd->lex->view_prepare_mode) if (escape_item->const_item())
{ {
/* If we are on execution stage */ /* If we are on execution stage */
String *escape_str= escape_item->val_str(&cmp.value1); String *escape_str= escape_item->val_str(&cmp.value1);

View file

@ -6492,7 +6492,7 @@ Item_func_sp::fix_fields(THD *thd, Item **ref)
if (res) if (res)
DBUG_RETURN(res); DBUG_RETURN(res);
if (thd->lex->view_prepare_mode) if (thd->lex->context_analysis_only & CONTEXT_ANALYSIS_ONLY_VIEW)
{ {
/* /*
Here we check privileges of the stored routine only during view Here we check privileges of the stored routine only during view

View file

@ -80,12 +80,8 @@ bool Item_row::fix_fields(THD *thd, Item **ref)
used_tables_cache |= item->used_tables(); used_tables_cache |= item->used_tables();
const_item_cache&= item->const_item() && !with_null; const_item_cache&= item->const_item() && !with_null;
not_null_tables_cache|= item->not_null_tables(); not_null_tables_cache|= item->not_null_tables();
/*
Some subqueries transformations aren't done in the view_prepare_mode thus if (const_item_cache)
is_null() will fail. So we skip is_null() calculation for CREATE VIEW as
not necessary.
*/
if (const_item_cache && !thd->lex->view_prepare_mode)
{ {
if (item->cols() > 1) if (item->cols() > 1)
with_null|= item->null_inside(); with_null|= item->null_inside();

View file

@ -131,20 +131,6 @@ void Item_subselect::cleanup()
} }
/*
We cannot use generic Item::safe_charset_converter() because
Subselect transformation does not happen in view_prepare_mode
and thus we can not evaluate val_...() for const items.
*/
Item *Item_subselect::safe_charset_converter(CHARSET_INFO *tocs)
{
Item_func_conv_charset *conv=
new Item_func_conv_charset(this, tocs, thd->lex->view_prepare_mode ? 0 : 1);
return conv->safe ? conv : NULL;
}
void Item_singlerow_subselect::cleanup() void Item_singlerow_subselect::cleanup()
{ {
DBUG_ENTER("Item_singlerow_subselect::cleanup"); DBUG_ENTER("Item_singlerow_subselect::cleanup");
@ -279,6 +265,7 @@ bool Item_subselect::exec()
if (thd->is_error() || thd->killed) if (thd->is_error() || thd->killed)
return 1; return 1;
DBUG_ASSERT(!thd->lex->context_analysis_only);
/* /*
Simulate a failure in sub-query execution. Used to test e.g. Simulate a failure in sub-query execution. Used to test e.g.
out of memory or query being killed conditions. out of memory or query being killed conditions.
@ -315,7 +302,7 @@ table_map Item_subselect::used_tables() const
bool Item_subselect::const_item() const bool Item_subselect::const_item() const
{ {
return const_item_cache; return thd->lex->context_analysis_only ? FALSE : const_item_cache;
} }
Item *Item_subselect::get_tmp_table_item(THD *thd_arg) Item *Item_subselect::get_tmp_table_item(THD *thd_arg)
@ -1646,7 +1633,8 @@ bool Item_in_subselect::fix_fields(THD *thd_arg, Item **ref)
{ {
bool result = 0; bool result = 0;
if (thd_arg->lex->view_prepare_mode && left_expr && !left_expr->fixed) if ((thd_arg->lex->context_analysis_only & CONTEXT_ANALYSIS_ONLY_VIEW) &&
left_expr && !left_expr->fixed)
result = left_expr->fix_fields(thd_arg, &left_expr); result = left_expr->fix_fields(thd_arg, &left_expr);
return result || Item_subselect::fix_fields(thd_arg, ref); return result || Item_subselect::fix_fields(thd_arg, ref);

View file

@ -138,7 +138,6 @@ public:
virtual void reset_value_registration() {} virtual void reset_value_registration() {}
enum_parsing_place place() { return parsing_place; } enum_parsing_place place() { return parsing_place; }
bool walk(Item_processor processor, bool walk_subquery, uchar *arg); bool walk(Item_processor processor, bool walk_subquery, uchar *arg);
Item *safe_charset_converter(CHARSET_INFO *tocs);
/** /**
Get the SELECT_LEX structure associated with this Item. Get the SELECT_LEX structure associated with this Item.

View file

@ -2503,8 +2503,6 @@ public:
(variables.sql_mode & MODE_STRICT_ALL_TABLES))); (variables.sql_mode & MODE_STRICT_ALL_TABLES)));
} }
void set_status_var_init(); void set_status_var_init();
bool is_context_analysis_only()
{ return stmt_arena->is_stmt_prepare() || lex->view_prepare_mode; }
void reset_n_backup_open_tables_state(Open_tables_backup *backup); void reset_n_backup_open_tables_state(Open_tables_backup *backup);
void restore_backup_open_tables_state(Open_tables_backup *backup); void restore_backup_open_tables_state(Open_tables_backup *backup);
void reset_sub_statement_state(Sub_statement_state *backup, uint new_state); void reset_sub_statement_state(Sub_statement_state *backup, uint new_state);

View file

@ -151,10 +151,11 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *orig_table_list)
if (!(derived_result= new select_union)) if (!(derived_result= new select_union))
DBUG_RETURN(TRUE); // out of memory DBUG_RETURN(TRUE); // out of memory
lex->context_analysis_only|= CONTEXT_ANALYSIS_ONLY_DERIVED;
// st_select_lex_unit::prepare correctly work for single select // st_select_lex_unit::prepare correctly work for single select
if ((res= unit->prepare(thd, derived_result, 0))) if ((res= unit->prepare(thd, derived_result, 0)))
goto exit; goto exit;
lex->context_analysis_only&= ~CONTEXT_ANALYSIS_ONLY_DERIVED;
if ((res= check_duplicate_names(unit->types, 0))) if ((res= check_duplicate_names(unit->types, 0)))
goto exit; goto exit;

View file

@ -383,7 +383,7 @@ void lex_start(THD *thd)
lex->select_lex.group_list.empty(); lex->select_lex.group_list.empty();
lex->describe= 0; lex->describe= 0;
lex->subqueries= FALSE; lex->subqueries= FALSE;
lex->view_prepare_mode= FALSE; lex->context_analysis_only= 0;
lex->derived_tables= 0; lex->derived_tables= 0;
lex->safe_to_cache_query= 1; lex->safe_to_cache_query= 1;
lex->leaf_tables_insert= 0; lex->leaf_tables_insert= 0;

View file

@ -2286,19 +2286,12 @@ struct LEX: public Query_tables_list
uint8 derived_tables; uint8 derived_tables;
uint8 create_view_algorithm; uint8 create_view_algorithm;
uint8 create_view_check; uint8 create_view_check;
uint8 context_analysis_only;
bool drop_if_exists, drop_temporary, local_file, one_shot_set; bool drop_if_exists, drop_temporary, local_file, one_shot_set;
bool autocommit; bool autocommit;
bool verbose, no_write_to_binlog; bool verbose, no_write_to_binlog;
enum enum_yes_no_unknown tx_chain, tx_release; enum enum_yes_no_unknown tx_chain, tx_release;
/*
Special JOIN::prepare mode: changing of query is prohibited.
When creating a view, we need to just check its syntax omitting
any optimizations: afterwards definition of the view will be
reconstructed by means of ::print() methods and written to
to an .frm file. We need this definition to stay untouched.
*/
bool view_prepare_mode;
bool safe_to_cache_query; bool safe_to_cache_query;
bool subqueries, ignore; bool subqueries, ignore;
st_parsing_options parsing_options; st_parsing_options parsing_options;
@ -2403,6 +2396,13 @@ struct LEX: public Query_tables_list
delete_dynamic(&plugins); delete_dynamic(&plugins);
} }
inline bool is_ps_or_view_context_analysis()
{
return (context_analysis_only &
(CONTEXT_ANALYSIS_ONLY_PREPARE |
CONTEXT_ANALYSIS_ONLY_VIEW));
}
inline void uncacheable(uint8 cause) inline void uncacheable(uint8 cause)
{ {
safe_to_cache_query= 0; safe_to_cache_query= 0;

View file

@ -5295,13 +5295,6 @@ mysql_new_select(LEX *lex, bool move_down)
DBUG_RETURN(1); DBUG_RETURN(1);
} }
select_lex->nest_level= lex->nest_level; select_lex->nest_level= lex->nest_level;
/*
Don't evaluate this subquery during statement prepare even if
it's a constant one. The flag is switched off in the end of
mysqld_stmt_prepare.
*/
if (thd->stmt_arena->is_stmt_prepare())
select_lex->uncacheable|= UNCACHEABLE_PREPARE;
if (move_down) if (move_down)
{ {
SELECT_LEX_UNIT *unit; SELECT_LEX_UNIT *unit;

View file

@ -1780,7 +1780,7 @@ static bool mysql_test_create_view(Prepared_statement *stmt)
if (open_normal_and_derived_tables(thd, tables, MYSQL_OPEN_FORCE_SHARED_MDL)) if (open_normal_and_derived_tables(thd, tables, MYSQL_OPEN_FORCE_SHARED_MDL))
goto err; goto err;
lex->view_prepare_mode= 1; lex->context_analysis_only|= CONTEXT_ANALYSIS_ONLY_VIEW;
res= select_like_stmt_test(stmt, 0, 0); res= select_like_stmt_test(stmt, 0, 0);
err: err:
@ -2292,19 +2292,6 @@ end:
} }
/** Init PS/SP specific parse tree members. */
static void init_stmt_after_parse(LEX *lex)
{
SELECT_LEX *sl= lex->all_selects_list;
/*
Switch off a temporary flag that prevents evaluation of
subqueries in statement prepare.
*/
for (; sl; sl= sl->next_select_in_list())
sl->uncacheable&= ~UNCACHEABLE_PREPARE;
}
/** /**
SQLCOM_PREPARE implementation. SQLCOM_PREPARE implementation.
@ -3223,6 +3210,7 @@ bool Prepared_statement::prepare(const char *packet, uint packet_len)
parser_state.m_lip.multi_statements= FALSE; parser_state.m_lip.multi_statements= FALSE;
lex_start(thd); lex_start(thd);
lex->context_analysis_only|= CONTEXT_ANALYSIS_ONLY_PREPARE;
error= parse_sql(thd, & parser_state, NULL) || error= parse_sql(thd, & parser_state, NULL) ||
thd->is_error() || thd->is_error() ||
@ -3283,7 +3271,7 @@ bool Prepared_statement::prepare(const char *packet, uint packet_len)
if (error == 0) if (error == 0)
{ {
setup_set_params(); setup_set_params();
init_stmt_after_parse(lex); lex->context_analysis_only&= ~CONTEXT_ANALYSIS_ONLY_PREPARE;
state= Query_arena::PREPARED; state= Query_arena::PREPARED;
flags&= ~ (uint) IS_IN_USE; flags&= ~ (uint) IS_IN_USE;

View file

@ -182,17 +182,42 @@
*/ */
/*
Flags below are set when we perform
context analysis of the statement and make
subqueries non-const. It prevents subquery
evaluation at context analysis stage.
*/
/*
Don't evaluate this subquery during statement prepare even if
it's a constant one. The flag is switched off in the end of
mysqld_stmt_prepare.
*/
#define CONTEXT_ANALYSIS_ONLY_PREPARE 1
/*
Special JOIN::prepare mode: changing of query is prohibited.
When creating a view, we need to just check its syntax omitting
any optimizations: afterwards definition of the view will be
reconstructed by means of ::print() methods and written to
to an .frm file. We need this definition to stay untouched.
*/
#define CONTEXT_ANALYSIS_ONLY_VIEW 2
/*
Don't evaluate this subquery during derived table prepare even if
it's a constant one.
*/
#define CONTEXT_ANALYSIS_ONLY_DERIVED 4
// uncachable cause // uncachable cause
#define UNCACHEABLE_DEPENDENT 1 #define UNCACHEABLE_DEPENDENT 1
#define UNCACHEABLE_RAND 2 #define UNCACHEABLE_RAND 2
#define UNCACHEABLE_SIDEEFFECT 4 #define UNCACHEABLE_SIDEEFFECT 4
/// forcing to save JOIN for explain /// forcing to save JOIN for explain
#define UNCACHEABLE_EXPLAIN 8 #define UNCACHEABLE_EXPLAIN 8
/** Don't evaluate subqueries in prepare even if they're not correlated */
#define UNCACHEABLE_PREPARE 16
/* For uncorrelated SELECT in an UNION with some correlated SELECTs */ /* For uncorrelated SELECT in an UNION with some correlated SELECTs */
#define UNCACHEABLE_UNITED 32 #define UNCACHEABLE_UNITED 16
#define UNCACHEABLE_CHECKOPTION 64 #define UNCACHEABLE_CHECKOPTION 32
/* Used to check GROUP BY list in the MODE_ONLY_FULL_GROUP_BY mode */ /* Used to check GROUP BY list in the MODE_ONLY_FULL_GROUP_BY mode */
#define UNDEF_POS (-1) #define UNDEF_POS (-1)

View file

@ -567,7 +567,8 @@ JOIN::prepare(Item ***rref_pointer_array,
thd->lex->allow_sum_func= save_allow_sum_func; thd->lex->allow_sum_func= save_allow_sum_func;
} }
if (!thd->lex->view_prepare_mode && !(select_options & SELECT_DESCRIBE)) if (!(thd->lex->context_analysis_only & CONTEXT_ANALYSIS_ONLY_VIEW) &&
!(select_options & SELECT_DESCRIBE))
{ {
Item_subselect *subselect; Item_subselect *subselect;
/* Is it subselect? */ /* Is it subselect? */

View file

@ -674,7 +674,7 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list)
MDL_savepoint mdl_savepoint= thd->mdl_context.mdl_savepoint(); MDL_savepoint mdl_savepoint= thd->mdl_context.mdl_savepoint();
/* We want to preserve the tree for views. */ /* We want to preserve the tree for views. */
thd->lex->view_prepare_mode= TRUE; thd->lex->context_analysis_only|= CONTEXT_ANALYSIS_ONLY_VIEW;
{ {
Show_create_error_handler view_error_suppressor(thd, table_list); Show_create_error_handler view_error_suppressor(thd, table_list);
@ -3435,7 +3435,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
uint derived_tables= lex->derived_tables; uint derived_tables= lex->derived_tables;
int error= 1; int error= 1;
Open_tables_backup open_tables_state_backup; Open_tables_backup open_tables_state_backup;
bool save_view_prepare_mode= lex->view_prepare_mode; uint8 save_context_analysis_only= lex->context_analysis_only;
Query_tables_list query_tables_list_backup; Query_tables_list query_tables_list_backup;
#ifndef NO_EMBEDDED_ACCESS_CHECKS #ifndef NO_EMBEDDED_ACCESS_CHECKS
Security_context *sctx= thd->security_ctx; Security_context *sctx= thd->security_ctx;
@ -3455,7 +3455,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
*/ */
can_deadlock= thd->mdl_context.has_locks(); can_deadlock= thd->mdl_context.has_locks();
lex->view_prepare_mode= TRUE; lex->context_analysis_only|= CONTEXT_ANALYSIS_ONLY_VIEW;
lex->reset_n_backup_query_tables_list(&query_tables_list_backup); lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
/* /*
Restore Query_tables_list::sql_command value, which was reset Restore Query_tables_list::sql_command value, which was reset
@ -3685,7 +3685,7 @@ err:
lex->restore_backup_query_tables_list(&query_tables_list_backup); lex->restore_backup_query_tables_list(&query_tables_list_backup);
lex->derived_tables= derived_tables; lex->derived_tables= derived_tables;
lex->all_selects_list= old_all_select_lex; lex->all_selects_list= old_all_select_lex;
lex->view_prepare_mode= save_view_prepare_mode; lex->context_analysis_only= save_context_analysis_only;
DBUG_RETURN(error); DBUG_RETURN(error);
} }

View file

@ -550,7 +550,7 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
} }
/* prepare select to resolve all fields */ /* prepare select to resolve all fields */
lex->view_prepare_mode= 1; lex->context_analysis_only|= CONTEXT_ANALYSIS_ONLY_VIEW;
if (unit->prepare(thd, 0, 0)) if (unit->prepare(thd, 0, 0))
{ {
/* /*