Commit 4a499d8b authored by Oleksandr Byelkin's avatar Oleksandr Byelkin

MDEV-15703 Crash in EXECUTE IMMEDIATE 'CREATE OR REPLACE TABLE t1 (a INT DEFAULT ?)' USING DEFAULT

10.4 version: check evaluablity on Field::make_empty_rec_store_default_value

10.2 version changed with ASSERTS.
parent 41221091
......@@ -5489,6 +5489,14 @@ ERROR HY000: Default/ignore value is not supported for such parameter usage
EXECUTE IMMEDIATE 'SHOW DATABASES WHERE ?' USING 0;
Database
#
# MDEV-15703: Crash in EXECUTE IMMEDIATE
# 'CREATE OR REPLACE TABLE t1 (a INT DEFAULT ?)' USING DEFAULT
#
EXECUTE IMMEDIATE 'CREATE TABLE t1 (a INT DEFAULT ?)' USING IGNORE;
ERROR HY000: Default/ignore value is not supported for such parameter usage
EXECUTE IMMEDIATE 'CREATE TABLE t1 (a INT DEFAULT ?)' USING DEFAULT;
ERROR HY000: Default/ignore value is not supported for such parameter usage
#
# End of 10.2 tests
#
#
......
......@@ -4931,6 +4931,17 @@ DROP TABLE t1;
EXECUTE IMMEDIATE 'SHOW DATABASES WHERE ?' USING DEFAULT;
EXECUTE IMMEDIATE 'SHOW DATABASES WHERE ?' USING 0;
--echo #
--echo # MDEV-15703: Crash in EXECUTE IMMEDIATE
--echo # 'CREATE OR REPLACE TABLE t1 (a INT DEFAULT ?)' USING DEFAULT
--echo #
--error ER_INVALID_DEFAULT_PARAM
EXECUTE IMMEDIATE 'CREATE TABLE t1 (a INT DEFAULT ?)' USING IGNORE;
--error ER_INVALID_DEFAULT_PARAM
EXECUTE IMMEDIATE 'CREATE TABLE t1 (a INT DEFAULT ?)' USING DEFAULT;
--echo #
--echo # End of 10.2 tests
--echo #
......
......@@ -1427,6 +1427,8 @@ bool Field::check_vcol_sql_mode_dependency(THD *thd, vcol_init_mode mode) const
bool Field::make_empty_rec_store_default_value(THD *thd, Item *item)
{
DBUG_ASSERT(!(flags & BLOB_FLAG));
if (item->check_is_evaluable_expression_or_error())
return 1;
int res= item->save_in_field(this, true);
return res != 0 && res != 3;
}
......@@ -11284,6 +11286,14 @@ bool Field::save_in_field_default_value(bool view_error_processing)
if (vers_sys_field())
return false;
if (table->pos_in_table_list == NULL) // table is not opened (CREATE TABLE)
{
DBUG_ASSERT(0); // shoud not be possible
my_message(ER_INVALID_DEFAULT_PARAM,
ER_THD(thd, ER_INVALID_DEFAULT_PARAM), MYF(0));
return false;
}
if (unlikely(flags & NO_DEFAULT_VALUE_FLAG &&
real_type() != MYSQL_TYPE_ENUM))
{
......@@ -11323,12 +11333,25 @@ bool Field::save_in_field_default_value(bool view_error_processing)
bool Field::save_in_field_ignore_value(bool view_error_processing)
{
enum_sql_command com= table->in_use->lex->sql_command;
bool top_level= table->pos_in_table_list &&
table->pos_in_table_list->select_lex &&
table->pos_in_table_list->select_lex->is_top_level_select();
// All insert-like commands
if (com == SQLCOM_INSERT || com == SQLCOM_REPLACE ||
com == SQLCOM_INSERT_SELECT || com == SQLCOM_REPLACE_SELECT ||
com == SQLCOM_LOAD)
return save_in_field_default_value(view_error_processing);
return 0; // ignore
if (top_level)
{
if (com == SQLCOM_INSERT || com == SQLCOM_REPLACE ||
com == SQLCOM_INSERT_SELECT || com == SQLCOM_REPLACE_SELECT ||
com == SQLCOM_LOAD)
return save_in_field_default_value(view_error_processing);
if (com == SQLCOM_UPDATE || com == SQLCOM_UPDATE_MULTI)
return 0; // ignore
}
DBUG_ASSERT(0); // shoud not be possible
my_message(ER_INVALID_DEFAULT_PARAM,
ER_THD(table->in_use, ER_INVALID_DEFAULT_PARAM), MYF(0));
return false;
}
......
......@@ -1432,6 +1432,10 @@ class st_select_lex: public st_select_lex_node
{
return (select_number == 1) && !is_part_of_union();
}
bool is_top_level_select()
{
return master_unit()->get_master() == NULL;
}
bool optimize_unflattened_subqueries(bool const_only);
/* Set the EXPLAIN type for this subquery. */
void set_explain_type(bool on_the_fly);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment