diff options
author | Alexander Barkov <bar@mariadb.com> | 2022-05-17 12:52:23 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2022-05-24 09:36:15 +0400 |
commit | 208addf48444c0a36a2cc16cd2558ae694e905d5 (patch) | |
tree | c2aebdda04bcae22ff6924187fcecf7c5d653336 /sql/table.cc | |
parent | 89adedcb9f0a45483b9917e93310241a4976d4c2 (diff) | |
download | mariadb-git-208addf48444c0a36a2cc16cd2558ae694e905d5.tar.gz |
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
Diffstat (limited to 'sql/table.cc')
-rw-r--r-- | sql/table.cc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/sql/table.cc b/sql/table.cc index 91aeb6523a3..f0d51495953 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -45,6 +45,7 @@ #include "ha_sequence.h" #include "sql_show.h" #include "opt_trace.h" +#include "sql_db.h" // get_default_db_collation /* For MySQL 5.7 virtual fields */ #define MYSQL57_GENERATED_FIELD 128 @@ -3503,6 +3504,19 @@ int TABLE_SHARE::init_from_sql_statement_string(THD *thd, bool write, else thd->set_n_backup_active_arena(arena, &backup); + /* + THD::reset_db() does not set THD::db_charset, + so it keeps pointing to the character set and collation + of the current database, rather than the database of the + new initialized table. After reset_db() the result of + get_default_db_collation() can be wrong. The latter is + used inside charset_collation_context_create_table_in_db(). + Let's initialize ctx before calling reset_db(). + This makes sure the db.opt file to be loaded properly when needed. + */ + Charset_collation_context + ctx(thd->charset_collation_context_create_table_in_db(db.str)); + thd->reset_db(&db); lex_start(thd); @@ -3510,6 +3524,9 @@ int TABLE_SHARE::init_from_sql_statement_string(THD *thd, bool write, sql_unusable_for_discovery(thd, hton, sql_copy)))) goto ret; + if (thd->lex->create_info.resolve_to_charset_collation_context(thd, ctx)) + DBUG_RETURN(true); + thd->lex->create_info.db_type= hton; #ifdef WITH_PARTITION_STORAGE_ENGINE thd->work_part_info= 0; // For partitioning |