1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

Main patch MDEV-27896 Wrong result upon COLLATE latin1_bin CHARACTER SET latin1 on the table or the database level

Also fixes
MDEV-27782 Wrong columns when using table level `CHARACTER SET utf8mb4 COLLATE DEFAULT`
MDEV-28644 Unexpected error on ALTER TABLE t1 CONVERT TO CHARACTER SET utf8mb3, DEFAULT CHARACTER SET utf8mb4
This commit is contained in:
Alexander Barkov
2022-05-17 12:52:23 +04:00
parent 89adedcb9f
commit 208addf484
25 changed files with 3255 additions and 206 deletions

View File

@ -43,9 +43,7 @@
// mysql_alter_db,
// check_db_dir_existence,
// my_dbopt_cleanup
#include "sql_table.h" // mysql_create_like_table,
// mysql_create_table,
// mysql_alter_table,
#include "sql_table.h" // mysql_alter_table,
// mysql_backup_table,
// mysql_restore_table
#include "sql_reload.h" // reload_acl_and_cache
@ -4190,7 +4188,7 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt)
*/
{
/* Prepare stack copies to be re-execution safe */
HA_CREATE_INFO create_info;
Table_specification_st create_info;
Alter_info alter_info(lex->alter_info, thd->mem_root);
if (unlikely(thd->is_fatal_error)) /* out of memory creating alter_info */
@ -4200,10 +4198,9 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt)
if (check_one_table_access(thd, INDEX_ACL, all_tables))
goto error; /* purecov: inspected */
bzero((char*) &create_info, sizeof(create_info));
create_info.init();
create_info.db_type= 0;
create_info.row_type= ROW_TYPE_NOT_USED;
create_info.default_table_charset= thd->variables.collation_database;
create_info.alter_info= &alter_info;
WSREP_TO_ISOLATION_BEGIN(first_table->db.str, first_table->table_name.str, NULL);
@ -5162,6 +5159,10 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt)
&lex->name))
break;
if ((res= lex->create_info.resolve_to_charset_collation_context(thd,
thd->charset_collation_context_create_db())))
break;
WSREP_TO_ISOLATION_BEGIN(lex->name.str, NULL, NULL);
res= mysql_create_db(thd, &lex->name,
@ -5223,6 +5224,10 @@ mysql_execute_command(THD *thd, bool is_called_from_prepared_stmt)
if (prepare_db_action(thd, ALTER_ACL, db))
break;
if ((res= lex->create_info.resolve_to_charset_collation_context(thd,
thd->charset_collation_context_alter_db(lex->name.str))))
break;
WSREP_TO_ISOLATION_BEGIN(db->str, NULL, NULL);
res= mysql_alter_db(thd, db, &lex->create_info);
@ -10472,40 +10477,6 @@ bool parse_sql(THD *thd, Parser_state *parser_state,
*/
/**
Check and merge "CHARACTER SET cs [ COLLATE cl ]" clause
@param cs character set pointer.
@param cl collation pointer.
Check if collation "cl" is applicable to character set "cs".
If "cl" is NULL (e.g. when COLLATE clause is not specified),
then simply "cs" is returned.
@return Error status.
@retval NULL, if "cl" is not applicable to "cs".
@retval pointer to merged CHARSET_INFO on success.
*/
CHARSET_INFO*
merge_charset_and_collation(CHARSET_INFO *cs, CHARSET_INFO *cl)
{
if (cl)
{
if (!my_charset_same(cs, cl))
{
my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0), cl->coll_name.str,
cs->cs_name.str);
return NULL;
}
return cl;
}
return cs;
}
void LEX::mark_first_table_as_inserting()
{
TABLE_LIST *t= first_select_lex()->table_list.first;