mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Merge mysql-next-mr (revno 2936) --> mysql-next-mr-marc
This commit is contained in:
106
sql/sql_table.cc
106
sql/sql_table.cc
@ -1735,9 +1735,10 @@ end:
|
||||
file
|
||||
*/
|
||||
|
||||
void write_bin_log(THD *thd, bool clear_error,
|
||||
char const *query, ulong query_length)
|
||||
int write_bin_log(THD *thd, bool clear_error,
|
||||
char const *query, ulong query_length)
|
||||
{
|
||||
int error= 0;
|
||||
if (mysql_bin_log.is_open())
|
||||
{
|
||||
int errcode= 0;
|
||||
@ -1745,9 +1746,10 @@ void write_bin_log(THD *thd, bool clear_error,
|
||||
thd->clear_error();
|
||||
else
|
||||
errcode= query_error_code(thd, TRUE);
|
||||
thd->binlog_query(THD::STMT_QUERY_TYPE,
|
||||
query, query_length, FALSE, FALSE, errcode);
|
||||
error= thd->binlog_query(THD::STMT_QUERY_TYPE,
|
||||
query, query_length, FALSE, FALSE, errcode);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
@ -2096,7 +2098,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
|
||||
tables). In this case, we can write the original query into
|
||||
the binary log.
|
||||
*/
|
||||
write_bin_log(thd, !error, thd->query(), thd->query_length());
|
||||
error |= write_bin_log(thd, !error, thd->query(), thd->query_length());
|
||||
}
|
||||
else if (thd->current_stmt_binlog_row_based &&
|
||||
tmp_table_deleted)
|
||||
@ -2118,7 +2120,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
|
||||
*/
|
||||
built_query.chop(); // Chop of the last comma
|
||||
built_query.append(" /* generated by server */");
|
||||
write_bin_log(thd, !error, built_query.ptr(), built_query.length());
|
||||
error|= write_bin_log(thd, !error, built_query.ptr(), built_query.length());
|
||||
}
|
||||
|
||||
/*
|
||||
@ -2137,7 +2139,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
|
||||
*/
|
||||
built_tmp_query.chop(); // Chop of the last comma
|
||||
built_tmp_query.append(" /* generated by server */");
|
||||
write_bin_log(thd, !error, built_tmp_query.ptr(), built_tmp_query.length());
|
||||
error|= write_bin_log(thd, !error, built_tmp_query.ptr(), built_tmp_query.length());
|
||||
}
|
||||
}
|
||||
|
||||
@ -3578,9 +3580,9 @@ void sp_prepare_create_field(THD *thd, Create_field *sql_field)
|
||||
RETURN VALUES
|
||||
NONE
|
||||
*/
|
||||
static inline void write_create_table_bin_log(THD *thd,
|
||||
const HA_CREATE_INFO *create_info,
|
||||
bool internal_tmp_table)
|
||||
static inline int write_create_table_bin_log(THD *thd,
|
||||
const HA_CREATE_INFO *create_info,
|
||||
bool internal_tmp_table)
|
||||
{
|
||||
/*
|
||||
Don't write statement if:
|
||||
@ -3593,7 +3595,8 @@ static inline void write_create_table_bin_log(THD *thd,
|
||||
(!thd->current_stmt_binlog_row_based ||
|
||||
(thd->current_stmt_binlog_row_based &&
|
||||
!(create_info->options & HA_LEX_CREATE_TMP_TABLE))))
|
||||
write_bin_log(thd, TRUE, thd->query(), thd->query_length());
|
||||
return write_bin_log(thd, TRUE, thd->query(), thd->query_length());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -3862,8 +3865,7 @@ bool mysql_create_table_no_lock(THD *thd,
|
||||
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
|
||||
ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
|
||||
alias);
|
||||
error= 0;
|
||||
write_create_table_bin_log(thd, create_info, internal_tmp_table);
|
||||
error= write_create_table_bin_log(thd, create_info, internal_tmp_table);
|
||||
goto err;
|
||||
}
|
||||
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), alias);
|
||||
@ -4012,8 +4014,7 @@ bool mysql_create_table_no_lock(THD *thd,
|
||||
thd->thread_specific_used= TRUE;
|
||||
}
|
||||
|
||||
write_create_table_bin_log(thd, create_info, internal_tmp_table);
|
||||
error= FALSE;
|
||||
error= write_create_table_bin_log(thd, create_info, internal_tmp_table);
|
||||
unlock_and_end:
|
||||
mysql_mutex_unlock(&LOCK_open);
|
||||
|
||||
@ -4028,7 +4029,7 @@ warn:
|
||||
ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
|
||||
alias);
|
||||
create_info->table_existed= 1; // Mark that table existed
|
||||
write_create_table_bin_log(thd, create_info, internal_tmp_table);
|
||||
error= write_create_table_bin_log(thd, create_info, internal_tmp_table);
|
||||
goto unlock_and_end;
|
||||
}
|
||||
|
||||
@ -5405,17 +5406,19 @@ binlog:
|
||||
create_info, FALSE /* show_database */);
|
||||
|
||||
DBUG_ASSERT(result == 0); // store_create_info() always return 0
|
||||
write_bin_log(thd, TRUE, query.ptr(), query.length());
|
||||
if (write_bin_log(thd, TRUE, query.ptr(), query.length()))
|
||||
goto err;
|
||||
}
|
||||
else // Case 1
|
||||
write_bin_log(thd, TRUE, thd->query(), thd->query_length());
|
||||
if (write_bin_log(thd, TRUE, thd->query(), thd->query_length()))
|
||||
goto err;
|
||||
}
|
||||
/*
|
||||
Case 3 and 4 does nothing under RBR
|
||||
*/
|
||||
}
|
||||
else
|
||||
write_bin_log(thd, TRUE, thd->query(), thd->query_length());
|
||||
else if (write_bin_log(thd, TRUE, thd->query(), thd->query_length()))
|
||||
goto err;
|
||||
|
||||
res= FALSE;
|
||||
|
||||
@ -5503,7 +5506,7 @@ mysql_discard_or_import_tablespace(THD *thd,
|
||||
error=1;
|
||||
if (error)
|
||||
goto err;
|
||||
write_bin_log(thd, FALSE, thd->query(), thd->query_length());
|
||||
error= write_bin_log(thd, FALSE, thd->query(), thd->query_length());
|
||||
|
||||
err:
|
||||
ha_autocommit_or_rollback(thd, error);
|
||||
@ -5910,6 +5913,35 @@ bool alter_table_manage_keys(TABLE *table, int indexes_were_disabled,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
maximum possible length for certain blob types.
|
||||
|
||||
@param[in] type Blob type (e.g. MYSQL_TYPE_TINY_BLOB)
|
||||
|
||||
@return
|
||||
length
|
||||
*/
|
||||
|
||||
static uint
|
||||
blob_length_by_type(enum_field_types type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case MYSQL_TYPE_TINY_BLOB:
|
||||
return 255;
|
||||
case MYSQL_TYPE_BLOB:
|
||||
return 65535;
|
||||
case MYSQL_TYPE_MEDIUM_BLOB:
|
||||
return 16777215;
|
||||
case MYSQL_TYPE_LONG_BLOB:
|
||||
return 4294967295U;
|
||||
default:
|
||||
DBUG_ASSERT(0); // we should never go here
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Prepare column and key definitions for CREATE TABLE in ALTER TABLE.
|
||||
|
||||
@ -6205,6 +6237,14 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
|
||||
|
||||
BLOBs may have cfield->length == 0, which is why we test it before
|
||||
checking whether cfield->length < key_part_length (in chars).
|
||||
|
||||
In case of TEXTs we check the data type maximum length *in bytes*
|
||||
to key part length measured *in characters* (i.e. key_part_length
|
||||
devided to mbmaxlen). This is because it's OK to have:
|
||||
CREATE TABLE t1 (a tinytext, key(a(254)) character set utf8);
|
||||
In case of this example:
|
||||
- data type maximum length is 255.
|
||||
- key_part_length is 1016 (=254*4, where 4 is mbmaxlen)
|
||||
*/
|
||||
if (!Field::type_can_have_key_part(cfield->field->type()) ||
|
||||
!Field::type_can_have_key_part(cfield->sql_type) ||
|
||||
@ -6212,8 +6252,11 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
|
||||
(key_info->flags & HA_SPATIAL) ||
|
||||
(cfield->field->field_length == key_part_length &&
|
||||
!f_is_blob(key_part->key_type)) ||
|
||||
(cfield->length && (cfield->length < key_part_length /
|
||||
key_part->field->charset()->mbmaxlen)))
|
||||
(cfield->length && (((cfield->sql_type >= MYSQL_TYPE_TINY_BLOB &&
|
||||
cfield->sql_type <= MYSQL_TYPE_BLOB) ?
|
||||
blob_length_by_type(cfield->sql_type) :
|
||||
cfield->length) <
|
||||
key_part_length / key_part->field->charset()->mbmaxlen)))
|
||||
key_part_length= 0; // Use whole field
|
||||
}
|
||||
key_part_length /= key_part->field->charset()->mbmaxlen;
|
||||
@ -6515,11 +6558,13 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
|
||||
thd->clear_error();
|
||||
Query_log_event qinfo(thd, thd->query(), thd->query_length(),
|
||||
0, FALSE, 0);
|
||||
mysql_bin_log.write(&qinfo);
|
||||
if (error= mysql_bin_log.write(&qinfo))
|
||||
goto view_err_unlock;
|
||||
}
|
||||
my_ok(thd);
|
||||
}
|
||||
|
||||
view_err_unlock:
|
||||
unlock_table_names(thd, table_list, (TABLE_LIST*) 0);
|
||||
|
||||
view_err:
|
||||
@ -6767,8 +6812,9 @@ view_err:
|
||||
|
||||
if (!error)
|
||||
{
|
||||
write_bin_log(thd, TRUE, thd->query(), thd->query_length());
|
||||
my_ok(thd);
|
||||
error= write_bin_log(thd, TRUE, thd->query(), thd->query_length());
|
||||
if (!error)
|
||||
my_ok(thd);
|
||||
}
|
||||
else if (error > 0)
|
||||
{
|
||||
@ -7256,8 +7302,9 @@ view_err:
|
||||
if (rename_temporary_table(thd, new_table, new_db, new_name))
|
||||
goto err1;
|
||||
/* We don't replicate alter table statement on temporary tables */
|
||||
if (!thd->current_stmt_binlog_row_based)
|
||||
write_bin_log(thd, TRUE, thd->query(), thd->query_length());
|
||||
if (!thd->current_stmt_binlog_row_based &&
|
||||
write_bin_log(thd, TRUE, thd->query(), thd->query_length()))
|
||||
DBUG_RETURN(TRUE);
|
||||
goto end_temporary;
|
||||
}
|
||||
|
||||
@ -7420,7 +7467,8 @@ view_err:
|
||||
DBUG_ASSERT(!(mysql_bin_log.is_open() &&
|
||||
thd->current_stmt_binlog_row_based &&
|
||||
(create_info->options & HA_LEX_CREATE_TMP_TABLE)));
|
||||
write_bin_log(thd, TRUE, thd->query(), thd->query_length());
|
||||
if (write_bin_log(thd, TRUE, thd->query(), thd->query_length()))
|
||||
DBUG_RETURN(TRUE);
|
||||
|
||||
if (ha_check_storage_engine_flag(old_db_type, HTON_FLUSH_AFTER_RENAME))
|
||||
{
|
||||
|
Reference in New Issue
Block a user