1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

Merge branch '11.4' into 11.5

This commit is contained in:
Oleksandr Byelkin
2024-05-23 17:01:43 +02:00
1470 changed files with 43538 additions and 14960 deletions

View File

@ -1467,6 +1467,7 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables,
temporary_table_was_dropped= 1;
}
is_temporary= 1;
thd->reset_sp_cache= true;
}
if ((drop_temporary && if_exists) || temporary_table_was_dropped)
@ -1840,8 +1841,11 @@ report_error:
}
DBUG_PRINT("table", ("table: %p s: %p", table->table,
table->table ? table->table->s : NULL));
if (is_temporary_table(table))
thd->reset_sp_cache= true;
}
DEBUG_SYNC(thd, "rm_table_no_locks_before_binlog");
thd->used|= THD::THREAD_SPECIFIC_USED;
error= 0;
@ -4677,6 +4681,7 @@ int create_table_impl(THD *thd,
if (is_trans != NULL)
*is_trans= table->file->has_transactions();
thd->reset_sp_cache= true;
thd->used|= THD::THREAD_SPECIFIC_USED;
create_info->table= table; // Store pointer to table
}
@ -4803,18 +4808,21 @@ int mysql_create_table_no_lock(THD *thd,
#ifdef WITH_WSREP
/** Additional sequence checks for Galera cluster.
@param thd thread handle
@param seq sequence definition
@param thd thread handle
@param seq sequence definition
@param used_engine create used ENGINE=
@retval false success
@retval true failure
*/
bool wsrep_check_sequence(THD* thd, const sequence_definition *seq)
bool wsrep_check_sequence(THD* thd,
const sequence_definition *seq,
const bool used_engine)
{
enum legacy_db_type db_type;
DBUG_ASSERT(WSREP(thd));
if (thd->lex->create_info.used_fields & HA_CREATE_USED_ENGINE)
if (used_engine)
{
db_type= thd->lex->create_info.db_type->db_type;
}
@ -4845,6 +4853,57 @@ bool wsrep_check_sequence(THD* thd, const sequence_definition *seq)
return (false);
}
/** Additional CREATE TABLE/SEQUENCE checks for Galera cluster.
@param thd thread handle
@param wsrep_ctas CREATE TABLE AS SELECT ?
@param used_engine CREATE TABLE ... ENGINE = ?
@param create_info Create information
@retval false Galera cluster does support used clause
@retval true Galera cluster does not support used clause
*/
static
bool wsrep_check_support(THD* thd,
const bool wsrep_ctas,
const bool used_engine,
const HA_CREATE_INFO* create_info)
{
/* CREATE TABLE ... AS SELECT */
if (wsrep_ctas &&
thd->variables.wsrep_trx_fragment_size > 0)
{
my_message(ER_NOT_ALLOWED_COMMAND,
"CREATE TABLE AS SELECT is not supported with streaming replication",
MYF(0));
return true;
}
/* CREATE TABLE .. WITH SYSTEM VERSIONING AS SELECT
is not supported in Galera cluster.
*/
if (wsrep_ctas &&
create_info->versioned())
{
my_error(ER_NOT_SUPPORTED_YET, MYF(0),
"SYSTEM VERSIONING AS SELECT in Galera cluster");
return true;
}
/*
CREATE TABLE ... ENGINE=SEQUENCE is not supported in
Galera cluster.
CREATE SEQUENCE ... ENGINE=xxx Galera cluster supports
only InnoDB-sequences.
*/
if (((used_engine && create_info->db_type &&
(create_info->db_type->db_type == DB_TYPE_SEQUENCE ||
create_info->db_type->db_type >= DB_TYPE_FIRST_DYNAMIC)) ||
thd->lex->sql_command == SQLCOM_CREATE_SEQUENCE) &&
wsrep_check_sequence(thd, create_info->seq_create_info, used_engine))
return true;
return false;
}
#endif /* WITH_WSREP */
/**
@ -4920,15 +4979,6 @@ bool mysql_create_table(THD *thd, TABLE_LIST *create_table,
if (!(thd->variables.option_bits & OPTION_EXPLICIT_DEF_TIMESTAMP))
promote_first_timestamp_column(&alter_info->create_list);
#ifdef WITH_WSREP
if (thd->lex->sql_command == SQLCOM_CREATE_SEQUENCE &&
WSREP(thd) && wsrep_thd_is_local_toi(thd))
{
if (wsrep_check_sequence(thd, create_info->seq_create_info))
DBUG_RETURN(true);
}
#endif /* WITH_WSREP */
/* We can abort create table for any table type */
thd->abort_on_warning= thd->is_strict_mode();
@ -5126,7 +5176,7 @@ static bool make_unique_constraint_name(THD *thd, LEX_CSTRING *name,
if (!check) // Found unique name
{
name->length= ident.length;
name->str= strmake_root(thd->stmt_arena->mem_root, buff, name->length);
name->str= thd->strmake(buff, name->length);
return (name->str == NULL);
}
}
@ -6545,8 +6595,6 @@ static KEY *find_key_ci(const Lex_ident_column &key_name,
@param thd Thread
@param table The original table.
@param varchar Indicates that new definition has new
VARCHAR column.
@param[in/out] ha_alter_info Data structure which already contains
basic information about create options,
field and keys for the new version of
@ -6581,7 +6629,7 @@ static KEY *find_key_ci(const Lex_ident_column &key_name,
@retval false success
*/
static bool fill_alter_inplace_info(THD *thd, TABLE *table, bool varchar,
static bool fill_alter_inplace_info(THD *thd, TABLE *table,
Alter_inplace_info *ha_alter_info)
{
Field **f_ptr, *field;
@ -6631,13 +6679,6 @@ static bool fill_alter_inplace_info(THD *thd, TABLE *table, bool varchar,
if (alter_info->flags & ALTER_CHANGE_COLUMN)
ha_alter_info->handler_flags|= ALTER_COLUMN_DEFAULT;
/*
If we altering table with old VARCHAR fields we will be automatically
upgrading VARCHAR column types.
*/
if (table->s->frm_version < FRM_VER_TRUE_VARCHAR && varchar)
ha_alter_info->handler_flags|= ALTER_STORED_COLUMN_TYPE;
DBUG_PRINT("info", ("handler_flags: %llu", ha_alter_info->handler_flags));
/*
@ -6679,6 +6720,30 @@ static bool fill_alter_inplace_info(THD *thd, TABLE *table, bool varchar,
Check if type of column has changed.
*/
bool is_equal= field->is_equal(*new_field);
if (is_equal)
{
const Type_handler *th= field->type_handler();
if (th != th->type_handler_for_implicit_upgrade())
{
/*
The field data type says it wants upgrade.
This should not be possible:
- if this is a new column definition, e.g. from statements like:
ALTER TABLE t1 ADD a INT;
ALTER TABLE t1 MODIFY a INT;
then it's coming from the parser, which returns
only up-to-date data types.
- if this is an old column definition, e.g. from:
ALTER TABLE t1 COMMENT 'new comment';
it should have ealier called Column_definition_implicit_upgrade(),
which replaces old data types to up-to-date data types.
*/
DBUG_ASSERT(0);
is_equal= false;
}
}
if (!is_equal)
{
if (field->table->file->can_convert_nocopy(*field, *new_field))
@ -7323,14 +7388,28 @@ bool alter_table_manage_keys(TABLE *table, int indexes_were_disabled,
switch (keys_onoff) {
case Alter_info::ENABLE:
DEBUG_SYNC(table->in_use, "alter_table_enable_indexes");
error= table->file->ha_enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
error= table->file->ha_enable_indexes(key_map(table->s->keys), true);
break;
case Alter_info::LEAVE_AS_IS:
if (!indexes_were_disabled)
break;
/* fall through */
case Alter_info::DISABLE:
error= table->file->ha_disable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
{
key_map map= table->s->keys_in_use;
bool do_clear= false;
for (uint i=0; i < table->s->keys; i++)
{
if (!(table->s->key_info[i].flags & HA_NOSAME) &&
i != table->s->next_number_index)
{
map.clear_bit(i);
do_clear= true;
}
}
if (do_clear)
error= table->file->ha_disable_indexes(map, true);
}
}
if (unlikely(error))
@ -9059,7 +9138,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
case Alter_drop::CHECK_CONSTRAINT:
case Alter_drop::PERIOD:
my_error(ER_CANT_DROP_FIELD_OR_KEY, MYF(0), drop->type_name(),
alter_info->drop_list.head()->name.str);
drop->name.str);
goto err;
case Alter_drop::FOREIGN_KEY:
// Leave the DROP FOREIGN KEY names in the alter_info->drop_list.
@ -10158,12 +10237,7 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db,
*/
KEY *key_info;
uint key_count;
/*
Remember if the new definition has new VARCHAR column;
create_info->varchar will be reset in create_table_impl()/
mysql_prepare_create_table().
*/
bool varchar= create_info->varchar, table_creation_was_logged= 0;
bool table_creation_was_logged= 0;
bool binlog_as_create_select= 0, log_if_exists= 0;
uint tables_opened;
handlerton *new_db_type= create_info->db_type, *old_db_type;
@ -10198,6 +10272,7 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db,
TODO: this design is obsolete and will be removed.
*/
int table_kind= check_if_log_table(table_list, FALSE, NullS);
const bool used_engine= create_info->used_fields & HA_CREATE_USED_ENGINE;
if (table_kind)
{
@ -10209,7 +10284,7 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db,
}
/* Disable alter of log tables to unsupported engine */
if ((create_info->used_fields & HA_CREATE_USED_ENGINE) &&
if ((used_engine) &&
(!create_info->db_type || /* unknown engine */
!(create_info->db_type->flags & HTON_SUPPORT_LOG_TABLES)))
{
@ -10317,14 +10392,14 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db,
if we can support implementing storage engine.
*/
if (WSREP(thd) && table && table->s->sequence &&
wsrep_check_sequence(thd, thd->lex->create_info.seq_create_info))
wsrep_check_sequence(thd, create_info->seq_create_info, used_engine))
DBUG_RETURN(TRUE);
if (WSREP(thd) &&
if (WSREP(thd) && table &&
(thd->lex->sql_command == SQLCOM_ALTER_TABLE ||
thd->lex->sql_command == SQLCOM_CREATE_INDEX ||
thd->lex->sql_command == SQLCOM_DROP_INDEX) &&
!wsrep_should_replicate_ddl(thd, table_list->table->s->db_type()))
!wsrep_should_replicate_ddl(thd, table->s->db_type()))
DBUG_RETURN(true);
#endif /* WITH_WSREP */
@ -10817,12 +10892,10 @@ do_continue:;
#endif
#ifdef WITH_WSREP
// ALTER TABLE for sequence object, check can we support it
if (table->s->sequence && WSREP(thd) &&
wsrep_thd_is_local_toi(thd))
{
if (wsrep_check_sequence(thd, create_info->seq_create_info))
wsrep_check_sequence(thd, create_info->seq_create_info, used_engine))
DBUG_RETURN(TRUE);
}
#endif /* WITH_WSREP */
/*
@ -10994,7 +11067,7 @@ do_continue:;
bool use_inplace= true;
/* Fill the Alter_inplace_info structure. */
if (fill_alter_inplace_info(thd, table, varchar, &ha_alter_info))
if (fill_alter_inplace_info(thd, table, &ha_alter_info))
goto err_new_table_cleanup;
alter_ctx.tmp_storage_engine_name_partitioned=
@ -11306,6 +11379,15 @@ do_continue:;
new_table->mark_columns_needed_for_insert();
mysql_bin_log.write_table_map(thd, new_table, 1);
}
/*
if ORDER BY: sorting
always: copying, building indexes.
if online: reading up the binlog (second binlog is being written)
reading up the second binlog under exclusive lock
*/
thd_progress_init(thd, MY_TEST(order) + 2 + 2 * MY_TEST(online));
if (copy_data_between_tables(thd, table, new_table,
ignore,
order_num, order, &copied, &deleted,
@ -11474,6 +11556,8 @@ do_continue:;
NULL);
table_list->table= table= NULL; /* Safety */
thd_progress_end(thd);
DBUG_PRINT("info", ("is_table_renamed: %d engine_changed: %d",
alter_ctx.is_table_renamed(), engine_changed));
@ -11703,6 +11787,8 @@ err_new_table_cleanup:
DBUG_PRINT("error", ("err_new_table_cleanup"));
thd->variables.option_bits&= ~OPTION_BIN_COMMIT_OFF;
thd_progress_end(thd);
/*
No default value was provided for a DATE/DATETIME field, the
current sql_mode doesn't allow the '0000-00-00' value and
@ -11832,7 +11918,7 @@ static int online_alter_read_from_binlog(THD *thd, rpl_group_info *rgi,
IO_CACHE *log_file= log->flip();
thd_progress_report(thd, 0, my_b_write_tell(log_file));
thd_progress_report(thd, 1, MY_MAX(1, my_b_write_tell(log_file)));
Has_default_error_handler hdeh;
thd->push_internal_handler(&hdeh);
@ -11899,14 +11985,6 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
MYSQL_TIME query_start;
DBUG_ENTER("copy_data_between_tables");
/*
if ORDER BY: sorting
always: copying, building indexes.
if online: reading up the binlog (second binlog is being written)
reading up the second binlog under exclusive lock
*/
thd_progress_init(thd, MY_TEST(order) + 2 + 2 * MY_TEST(online));
if (!(copy= new (thd->mem_root) Copy_field[to->s->fields]))
DBUG_RETURN(-1);
@ -12072,6 +12150,7 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
#ifdef HAVE_REPLICATION
if (online)
{
DBUG_ASSERT(from->s->online_alter_binlog == NULL);
from->s->online_alter_binlog= new Cache_flip_event_log();
if (!from->s->online_alter_binlog)
goto err;
@ -12295,7 +12374,7 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
DEBUG_SYNC(thd, "alter_table_online_before_lock");
int lock_error=
thd->mdl_context.upgrade_shared_lock(from->mdl_ticket, MDL_EXCLUSIVE,
thd->mdl_context.upgrade_shared_lock(from->mdl_ticket, MDL_SHARED_NO_WRITE,
(double)thd->variables.lock_wait_timeout);
if (!error)
error= lock_error;
@ -12305,29 +12384,21 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
thd_progress_next_stage(thd);
error= online_alter_read_from_binlog(thd, &rgi, binlog, &found_count);
}
if (error)
from->s->tdc->flush_unused(1); // to free the binlog
/*
We'll do it earlier than usually in mysql_alter_table to handle the
online-related errors more comfortably.
*/
lock_error= thd->mdl_context.upgrade_shared_lock(from->mdl_ticket,
MDL_EXCLUSIVE,
(double)thd->variables.lock_wait_timeout);
if (!error)
error= lock_error;
to->pos_in_table_list= NULL; // Safety
DBUG_ASSERT(thd->lex->sql_command == saved_sql_command);
thd->lex->sql_command= saved_sql_command; // Just in case
}
else if (online) // error was on copy stage
{
/*
We can't free the resources properly now, as we can still be in
non-exclusive state. So this s->online_alter_binlog will be used
until all transactions will release it.
Once the transaction commits, it can release online_alter_binlog
by decreasing ref_count.
online_alter_binlog->ref_count can be reached 0 only once.
Proof:
If share exists, we'll always have ref_count >= 1.
Once it reaches destroy(), nobody can acquire it again,
therefore, only release() is possible at this moment.
*/
from->s->tdc->flush_unused(1); // to free the binlog
}
#endif
if (error > 0 && !from->s->tmp_table)
@ -12342,6 +12413,26 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
if (unlikely(mysql_trans_commit_alter_copy_data(thd)))
error= 1;
if (unlikely(error) && online)
{
/*
We can't free the resources properly now, as we can still be in
non-exclusive state. So this s->online_alter_binlog will be used
until all transactions will release it.
Once the transaction commits, it can release online_alter_binlog
by decreasing ref_count.
online_alter_binlog->ref_count can be reached 0 only once.
Proof:
If share exists, we'll always have ref_count >= 1.
Once it reaches destroy(), nobody can acquire it again,
therefore, only release() is possible at this moment.
Also, this will release the binlog.
*/
from->s->tdc->flush_unused(1);
}
err:
if (bulk_insert_started)
@ -12371,7 +12462,6 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
if (error < 0 && !from->s->tmp_table &&
to->file->extra(HA_EXTRA_PREPARE_FOR_RENAME))
error= 1;
thd_progress_end(thd);
DBUG_RETURN(error > 0 ? -1 : 0);
}
@ -12799,17 +12889,11 @@ bool Sql_cmd_create_table_like::execute(THD *thd)
#endif
#ifdef WITH_WSREP
if (wsrep_ctas)
if (WSREP(thd) &&
wsrep_check_support(thd, wsrep_ctas, used_engine, &create_info))
{
if (thd->variables.wsrep_trx_fragment_size > 0)
{
my_message(
ER_NOT_ALLOWED_COMMAND,
"CREATE TABLE AS SELECT is not supported with streaming replication",
MYF(0));
res= 1;
goto end_with_restore_list;
}
res= 1;
goto end_with_restore_list;
}
#endif /* WITH_WSREP */
@ -12961,6 +13045,7 @@ bool Sql_cmd_create_table_like::execute(THD *thd)
create_table->table_name, create_table->db))
goto end_with_restore_list;
#ifdef WITH_WSREP
/*
In STATEMENT format, we probably have to replicate also temporary
tables, like mysql replication does. Also check if the requested
@ -12969,33 +13054,32 @@ bool Sql_cmd_create_table_like::execute(THD *thd)
if (WSREP(thd))
{
handlerton *orig_ht= create_info.db_type;
if (!check_engine(thd, create_table->db.str,
create_table->table_name.str,
&create_info) &&
(!thd->is_current_stmt_binlog_format_row() ||
!create_info.tmp_table()))
{
#ifdef WITH_WSREP
if (thd->lex->sql_command == SQLCOM_CREATE_SEQUENCE &&
wsrep_check_sequence(thd, lex->create_info.seq_create_info))
wsrep_check_sequence(thd, lex->create_info.seq_create_info, used_engine))
DBUG_RETURN(true);
WSREP_TO_ISOLATION_BEGIN_ALTER(create_table->db.str,
create_table->table_name.str,
first_table, &alter_info, NULL,
&create_info)
{
WSREP_WARN("CREATE TABLE isolation failure");
WSREP_TO_ISOLATION_BEGIN_ALTER(create_table->db.str, create_table->table_name.str,
first_table, &alter_info, NULL, &create_info)
{
WSREP_WARN("CREATE TABLE isolation failure");
res= true;
goto end_with_restore_list;
}
#endif /* WITH_WSREP */
}
}
// check_engine will set db_type to NULL if e.g. TEMPORARY is
// not supported by the storage engine, this case is checked
// again in mysql_create_table
create_info.db_type= orig_ht;
}
#endif /* WITH_WSREP */
/* Regular CREATE TABLE */
res= mysql_create_table(thd, create_table, &create_info, &alter_info);
}