Commit 64a5fab0 authored by Alexander Barkov's avatar Alexander Barkov

Step#1 MDEV-27896 Wrong result upon `COLLATE latin1_bin CHARACTER SET latin1`...

Step#1 MDEV-27896 Wrong result upon `COLLATE latin1_bin CHARACTER SET latin1` on the table or the database level

- Adding data type aliases:
  using Lex_column_charset_collation_attrs_st = Lex_charset_collation_st;
  using Lex_column_charset_collation_attrs = Lex_charset_collation;

  and using them all around the code (except lex_charset.*)
  instead of the original names.

- Renaming Lex_field_type_st::lex_charset_collation()
  to charset_collation_attrs()

- Renaming Column_definition::set_lex_charset_collation()
  to set_charset_collation_attrs()

- Renaming Column_definition::lex_charset_collation()
  to charset_collation_attrs()

Rationale:

The name "Lex_charset_collation" was a not very good name.
It does not tell details about its properties:
1. if the charset is optional (yes)
2. if the collation is optional (yes)
3. if the charset can be exact (yes) or context (no)
4. if the collation can be: exact (yes) or context (yes)
5. if the clauses can be repeated multiple times (yes)

We'll need a few new data types soon with different properties.
For example, to fix MDEV-27896 and MDEV-27782, we'll need a new
data type which is very like Lex_charset_collation, but additionally
supports CHARACTER SET DEFAULT (which is allowed on table and database level,
but is not allowed on the column level yet), i.e. with:
  "the charset can be exact (yes) or context (yes)" in N3.

So we'll have to rename Lex_charset_collation to something else,
e.g.: Lex_exact_charset_extended_collation_attrs,
and add a new data type:
e.g. Lex_extended_charset_extended_collation_attrs

Also, we'll possibly allow CHARACTER SET DEFAULT at the column level for
consistency with other places. So the storge on the column level can change:
- from Lex_exact_charset_extended_collation_attrs
- to   Lex_extended_charset_extended_collation_attrs

Adding the aliases introduces a convenient abstraction against
upcoming renames and c++ data type changes.
parent 92702430
...@@ -5501,7 +5501,8 @@ class Column_definition: public Sql_alloc, ...@@ -5501,7 +5501,8 @@ class Column_definition: public Sql_alloc,
bool check_vcol_for_key(THD *thd) const; bool check_vcol_for_key(THD *thd) const;
void set_lex_charset_collation(const Lex_charset_collation_st &lc) void set_charset_collation_attrs(const
Lex_column_charset_collation_attrs_st &lc)
{ {
charset= lc.charset_collation(); charset= lc.charset_collation();
if (lc.is_contextually_typed_collation()) if (lc.is_contextually_typed_collation())
...@@ -5509,7 +5510,7 @@ class Column_definition: public Sql_alloc, ...@@ -5509,7 +5510,7 @@ class Column_definition: public Sql_alloc,
else else
flags&= ~CONTEXT_COLLATION_FLAG; flags&= ~CONTEXT_COLLATION_FLAG;
} }
Lex_charset_collation lex_charset_collation() const Lex_column_charset_collation_attrs charset_collation_attrs() const
{ {
return Lex_charset_collation( return Lex_charset_collation(
charset, charset,
......
...@@ -3773,7 +3773,7 @@ struct Lex_cast_type_st: public Lex_length_and_dec_st ...@@ -3773,7 +3773,7 @@ struct Lex_cast_type_st: public Lex_length_and_dec_st
} }
bool set(const Type_handler *handler, bool set(const Type_handler *handler,
const Lex_length_and_dec_st & length_and_dec, const Lex_length_and_dec_st & length_and_dec,
const Lex_charset_collation_st &cscl, const Lex_column_charset_collation_attrs_st &cscl,
CHARSET_INFO *defcs) CHARSET_INFO *defcs)
{ {
CHARSET_INFO *tmp= cscl.resolved_to_character_set(defcs); CHARSET_INFO *tmp= cscl.resolved_to_character_set(defcs);
......
...@@ -874,7 +874,7 @@ int Json_table_column::set(THD *thd, enum_type ctype, const LEX_CSTRING &path, ...@@ -874,7 +874,7 @@ int Json_table_column::set(THD *thd, enum_type ctype, const LEX_CSTRING &path,
int Json_table_column::set(THD *thd, enum_type ctype, const LEX_CSTRING &path, int Json_table_column::set(THD *thd, enum_type ctype, const LEX_CSTRING &path,
const Lex_charset_collation_st &cl) const Lex_column_charset_collation_attrs_st &cl)
{ {
if (cl.is_empty() || cl.is_contextually_typed_collate_default()) if (cl.is_empty() || cl.is_contextually_typed_collate_default())
return set(thd, ctype, path, nullptr); return set(thd, ctype, path, nullptr);
......
...@@ -161,7 +161,7 @@ class Json_table_column : public Sql_alloc ...@@ -161,7 +161,7 @@ class Json_table_column : public Sql_alloc
} }
int set(THD *thd, enum_type ctype, const LEX_CSTRING &path, CHARSET_INFO *cs); int set(THD *thd, enum_type ctype, const LEX_CSTRING &path, CHARSET_INFO *cs);
int set(THD *thd, enum_type ctype, const LEX_CSTRING &path, int set(THD *thd, enum_type ctype, const LEX_CSTRING &path,
const Lex_charset_collation_st &cl); const Lex_column_charset_collation_attrs_st &cl);
Json_table_column(Create_field *f, Json_table_nested_path *nest) : Json_table_column(Create_field *f, Json_table_nested_path *nest) :
m_field(f), m_nest(nest), m_explicit_cs(NULL) m_field(f), m_nest(nest), m_explicit_cs(NULL)
{ {
......
...@@ -196,4 +196,8 @@ class Lex_charset_collation: public Lex_charset_collation_st ...@@ -196,4 +196,8 @@ class Lex_charset_collation: public Lex_charset_collation_st
}; };
using Lex_column_charset_collation_attrs_st = Lex_charset_collation_st;
using Lex_column_charset_collation_attrs = Lex_charset_collation;
#endif // LEX_CHARSET_INCLUDED #endif // LEX_CHARSET_INCLUDED
...@@ -2202,7 +2202,7 @@ bool check_duplicates_in_interval(const char *set_or_name, ...@@ -2202,7 +2202,7 @@ bool check_duplicates_in_interval(const char *set_or_name,
bool Column_definition:: bool Column_definition::
prepare_charset_for_string(const Column_derived_attributes *dattr) prepare_charset_for_string(const Column_derived_attributes *dattr)
{ {
CHARSET_INFO *tmp= lex_charset_collation(). CHARSET_INFO *tmp= charset_collation_attrs().
resolved_to_character_set(dattr->charset()); resolved_to_character_set(dattr->charset());
if (!tmp) if (!tmp)
return true; return true;
......
...@@ -2715,7 +2715,7 @@ Type_handler::Column_definition_set_attributes(THD *thd, ...@@ -2715,7 +2715,7 @@ Type_handler::Column_definition_set_attributes(THD *thd,
column_definition_type_t type) column_definition_type_t type)
const const
{ {
def->set_lex_charset_collation(attr.lex_charset_collation()); def->set_charset_collation_attrs(attr.charset_collation_attrs());
def->set_length_and_dec(attr); def->set_length_and_dec(attr);
return false; return false;
} }
......
...@@ -5789,10 +5789,10 @@ field_type_or_serial: ...@@ -5789,10 +5789,10 @@ field_type_or_serial:
} }
field_def field_def
{ {
Lex_charset_collation tmp= $1.lex_charset_collation(); Lex_charset_collation tmp= $1.charset_collation_attrs();
if (tmp.merge_charset_clause_and_collate_clause($3)) if (tmp.merge_charset_clause_and_collate_clause($3))
MYSQL_YYABORT; MYSQL_YYABORT;
Lex->last_field->set_lex_charset_collation(tmp); Lex->last_field->set_charset_collation_attrs(tmp);
} }
| SERIAL_SYM | SERIAL_SYM
{ {
...@@ -11358,7 +11358,7 @@ json_table_column_type: ...@@ -11358,7 +11358,7 @@ json_table_column_type:
COLUMN_DEFINITION_TABLE_FIELD); COLUMN_DEFINITION_TABLE_FIELD);
if (Lex->json_table->m_cur_json_table_column-> if (Lex->json_table->m_cur_json_table_column->
set(thd, Json_table_column::PATH, $3, set(thd, Json_table_column::PATH, $3,
$1.lex_charset_collation())) $1.charset_collation_attrs()))
{ {
MYSQL_YYABORT; MYSQL_YYABORT;
} }
...@@ -11369,7 +11369,7 @@ json_table_column_type: ...@@ -11369,7 +11369,7 @@ json_table_column_type:
COLUMN_DEFINITION_TABLE_FIELD); COLUMN_DEFINITION_TABLE_FIELD);
if (Lex->json_table->m_cur_json_table_column-> if (Lex->json_table->m_cur_json_table_column->
set(thd, Json_table_column::EXISTS_PATH, $4, set(thd, Json_table_column::EXISTS_PATH, $4,
$1.lex_charset_collation())) $1.charset_collation_attrs()))
MYSQL_YYABORT; MYSQL_YYABORT;
} }
; ;
......
...@@ -699,14 +699,15 @@ struct Lex_field_type_st: public Lex_length_and_dec_st ...@@ -699,14 +699,15 @@ struct Lex_field_type_st: public Lex_length_and_dec_st
} }
void set(const Type_handler *handler, void set(const Type_handler *handler,
const Lex_length_and_dec_st &length_and_dec, const Lex_length_and_dec_st &length_and_dec,
const Lex_charset_collation_st &coll) const Lex_column_charset_collation_attrs_st &coll)
{ {
m_handler= handler; m_handler= handler;
m_ci= coll.charset_collation(); m_ci= coll.charset_collation();
Lex_length_and_dec_st::operator=(length_and_dec); Lex_length_and_dec_st::operator=(length_and_dec);
m_collation_type= ((uint8) coll.type()) & 0x3; m_collation_type= ((uint8) coll.type()) & 0x3;
} }
void set(const Type_handler *handler, const Lex_charset_collation_st &coll) void set(const Type_handler *handler,
const Lex_column_charset_collation_attrs_st &coll)
{ {
m_handler= handler; m_handler= handler;
m_ci= coll.charset_collation(); m_ci= coll.charset_collation();
...@@ -734,10 +735,10 @@ struct Lex_field_type_st: public Lex_length_and_dec_st ...@@ -734,10 +735,10 @@ struct Lex_field_type_st: public Lex_length_and_dec_st
} }
const Type_handler *type_handler() const { return m_handler; } const Type_handler *type_handler() const { return m_handler; }
CHARSET_INFO *charset_collation() const { return m_ci; } CHARSET_INFO *charset_collation() const { return m_ci; }
Lex_charset_collation lex_charset_collation() const Lex_column_charset_collation_attrs charset_collation_attrs() const
{ {
return Lex_charset_collation(m_ci, return Lex_column_charset_collation_attrs(m_ci,
(Lex_charset_collation_st::Type) (Lex_column_charset_collation_attrs_st::Type)
m_collation_type); m_collation_type);
} }
}; };
...@@ -768,7 +769,7 @@ struct Lex_dyncol_type_st: public Lex_length_and_dec_st ...@@ -768,7 +769,7 @@ struct Lex_dyncol_type_st: public Lex_length_and_dec_st
m_ci= cs; m_ci= cs;
Lex_length_and_dec_st::reset(); Lex_length_and_dec_st::reset();
} }
bool set(int type, const Lex_charset_collation_st &collation, bool set(int type, const Lex_column_charset_collation_attrs_st &collation,
CHARSET_INFO *charset) CHARSET_INFO *charset)
{ {
CHARSET_INFO *tmp= collation.resolved_to_character_set(charset); CHARSET_INFO *tmp= collation.resolved_to_character_set(charset);
......
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