cleanup: versioning style fixes

rename LString/XString classes, remove unused ones
This commit is contained in:
Sergei Golubchik 2018-04-24 13:19:44 +02:00
parent 531acda484
commit b1a6d2826a
14 changed files with 101 additions and 142 deletions

View File

@ -4514,7 +4514,7 @@ int ha_partition::delete_row(const uchar *buf)
or last historical partition, but DELETE HISTORY can delete from any or last historical partition, but DELETE HISTORY can delete from any
historical partition. So, skip the check in this case. historical partition. So, skip the check in this case.
*/ */
if (!thd->lex->vers_conditions) // if not DELETE HISTORY if (!thd->lex->vers_conditions.is_set()) // if not DELETE HISTORY
{ {
uint32 part_id; uint32 part_id;
error= get_part_for_buf(buf, m_rec0, m_part_info, &part_id); error= get_part_for_buf(buf, m_rec0, m_part_info, &part_id);

View File

@ -4767,7 +4767,8 @@ void handler::update_global_table_stats()
if (rows_read + rows_changed == 0) if (rows_read + rows_changed == 0)
return; // Nothing to update. return; // Nothing to update.
DBUG_ASSERT(table->s && table->s->table_cache_key.str); DBUG_ASSERT(table->s);
DBUG_ASSERT(table->s->table_cache_key.str);
mysql_mutex_lock(&LOCK_global_table_stats); mysql_mutex_lock(&LOCK_global_table_stats);
/* Gets the global table stats, creating one if necessary. */ /* Gets the global table stats, creating one if necessary. */
@ -6371,7 +6372,8 @@ void handler::use_hidden_primary_key()
Handler_share *handler::get_ha_share_ptr() Handler_share *handler::get_ha_share_ptr()
{ {
DBUG_ENTER("handler::get_ha_share_ptr"); DBUG_ENTER("handler::get_ha_share_ptr");
DBUG_ASSERT(ha_share && table_share); DBUG_ASSERT(ha_share);
DBUG_ASSERT(table_share);
#ifndef DBUG_OFF #ifndef DBUG_OFF
if (table_share->tmp_table == NO_TMP_TABLE) if (table_share->tmp_table == NO_TMP_TABLE)
@ -6882,8 +6884,8 @@ static bool vers_create_sys_field(THD *thd, const char *field_name,
return false; return false;
} }
const LString_i Vers_parse_info::default_start= "row_start"; const Lex_ident Vers_parse_info::default_start= "row_start";
const LString_i Vers_parse_info::default_end= "row_end"; const Lex_ident Vers_parse_info::default_end= "row_end";
bool Vers_parse_info::fix_implicit(THD *thd, Alter_info *alter_info) bool Vers_parse_info::fix_implicit(THD *thd, Alter_info *alter_info)
{ {
@ -7077,10 +7079,12 @@ bool Vers_parse_info::fix_alter_info(THD *thd, Alter_info *alter_info,
// copy info from existing table // copy info from existing table
create_info->options|= HA_VERSIONED_TABLE; create_info->options|= HA_VERSIONED_TABLE;
DBUG_ASSERT(share->vers_start_field() && share->vers_end_field()); DBUG_ASSERT(share->vers_start_field());
LString_i start(share->vers_start_field()->field_name); DBUG_ASSERT(share->vers_end_field());
LString_i end(share->vers_end_field()->field_name); Lex_ident start(share->vers_start_field()->field_name);
DBUG_ASSERT(start.ptr() && end.ptr()); Lex_ident end(share->vers_end_field()->field_name);
DBUG_ASSERT(start.str);
DBUG_ASSERT(end.str);
as_row= start_end_t(start, end); as_row= start_end_t(start, end);
system_time= as_row; system_time= as_row;
@ -7184,8 +7188,8 @@ bool Vers_parse_info::need_check(const Alter_info *alter_info) const
alter_info->flags & ALTER_DROP_SYSTEM_VERSIONING || *this; alter_info->flags & ALTER_DROP_SYSTEM_VERSIONING || *this;
} }
bool Vers_parse_info::check_conditions(const LString &table_name, bool Vers_parse_info::check_conditions(const Lex_table_name &table_name,
const LString &db) const const Lex_table_name &db) const
{ {
if (!as_row.start || !as_row.end) if (!as_row.start || !as_row.end)
{ {
@ -7215,7 +7219,8 @@ bool Vers_parse_info::check_conditions(const LString &table_name,
return false; return false;
} }
bool Vers_parse_info::check_sys_fields(const LString &table_name, const LString &db, bool Vers_parse_info::check_sys_fields(const Lex_table_name &table_name,
const Lex_table_name &db,
Alter_info *alter_info, bool native) Alter_info *alter_info, bool native)
{ {
if (check_conditions(table_name, db)) if (check_conditions(table_name, db))

View File

@ -1922,15 +1922,15 @@ struct Vers_parse_info
start_end_t(LEX_CSTRING _start, LEX_CSTRING _end) : start_end_t(LEX_CSTRING _start, LEX_CSTRING _end) :
start(_start), start(_start),
end(_end) {} end(_end) {}
LString_i start; Lex_ident start;
LString_i end; Lex_ident end;
}; };
start_end_t system_time; start_end_t system_time;
start_end_t as_row; start_end_t as_row;
vers_sys_type_t check_unit; vers_sys_type_t check_unit;
void set_system_time(LString start, LString end) void set_system_time(Lex_ident start, Lex_ident end)
{ {
system_time.start= start; system_time.start= start;
system_time.end= end; system_time.end= end;
@ -1958,16 +1958,18 @@ protected:
return as_row.start || as_row.end || system_time.start || system_time.end; return as_row.start || as_row.end || system_time.start || system_time.end;
} }
bool need_check(const Alter_info *alter_info) const; bool need_check(const Alter_info *alter_info) const;
bool check_conditions(const LString &table_name, const LString &db) const; bool check_conditions(const Lex_table_name &table_name,
const Lex_table_name &db) const;
public: public:
static const LString_i default_start; static const Lex_ident default_start;
static const LString_i default_end; static const Lex_ident default_end;
bool fix_alter_info(THD *thd, Alter_info *alter_info, bool fix_alter_info(THD *thd, Alter_info *alter_info,
HA_CREATE_INFO *create_info, TABLE *table); HA_CREATE_INFO *create_info, TABLE *table);
bool fix_create_like(Alter_info &alter_info, HA_CREATE_INFO &create_info, bool fix_create_like(Alter_info &alter_info, HA_CREATE_INFO &create_info,
TABLE_LIST &src_table, TABLE_LIST &table); TABLE_LIST &src_table, TABLE_LIST &table);
bool check_sys_fields(const LString &table_name, const LString &db, bool check_sys_fields(const Lex_table_name &table_name,
const Lex_table_name &db,
Alter_info *alter_info, bool native); Alter_info *alter_info, bool native);
/** /**

View File

@ -199,8 +199,8 @@ uint get_table_def_key(const TABLE_LIST *table_list, const char **key)
from key used by MDL subsystem. from key used by MDL subsystem.
*/ */
DBUG_ASSERT(!strcmp(table_list->get_db_name(), DBUG_ASSERT(!strcmp(table_list->get_db_name(),
table_list->mdl_request.key.db_name()) && table_list->mdl_request.key.db_name()));
!strcmp(table_list->get_table_name(), DBUG_ASSERT(!strcmp(table_list->get_table_name(),
table_list->mdl_request.key.name())); table_list->mdl_request.key.name()));
*key= (const char*)table_list->mdl_request.key.ptr() + 1; *key= (const char*)table_list->mdl_request.key.ptr() + 1;

View File

@ -305,7 +305,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
THD_STAGE_INFO(thd, stage_init_update); THD_STAGE_INFO(thd, stage_init_update);
bool truncate_history= table_list->vers_conditions; bool truncate_history= table_list->vers_conditions.is_set();
if (truncate_history) if (truncate_history)
{ {
if (table_list->is_view_or_derived()) if (table_list->is_view_or_derived())
@ -941,7 +941,7 @@ int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list,
select_lex->leaf_tables, FALSE, select_lex->leaf_tables, FALSE,
DELETE_ACL, SELECT_ACL, TRUE)) DELETE_ACL, SELECT_ACL, TRUE))
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
if (table_list->vers_conditions) if (table_list->vers_conditions.is_set())
{ {
if (table_list->is_view()) if (table_list->is_view())
{ {

View File

@ -9419,7 +9419,7 @@ bool update_precheck(THD *thd, TABLE_LIST *tables)
bool delete_precheck(THD *thd, TABLE_LIST *tables) bool delete_precheck(THD *thd, TABLE_LIST *tables)
{ {
DBUG_ENTER("delete_precheck"); DBUG_ENTER("delete_precheck");
if (tables->vers_conditions) if (tables->vers_conditions.is_set())
{ {
if (check_one_table_access(thd, DELETE_HISTORY_ACL, tables)) if (check_one_table_access(thd, DELETE_HISTORY_ACL, tables))
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);

View File

@ -693,7 +693,7 @@ bool vers_select_conds_t::init_from_sysvar(THD *thd)
return false; return false;
} }
void vers_select_conds_t::print(String *str, enum_query_type query_type) void vers_select_conds_t::print(String *str, enum_query_type query_type) const
{ {
switch (type) { switch (type) {
case SYSTEM_TIME_UNSPECIFIED: case SYSTEM_TIME_UNSPECIFIED:
@ -765,14 +765,14 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables)
{ {
TABLE_LIST* derived= master_unit()->derived; TABLE_LIST* derived= master_unit()->derived;
// inner SELECT may not be a derived table (derived == NULL) // inner SELECT may not be a derived table (derived == NULL)
while (derived && outer_slex && !derived->vers_conditions) while (derived && outer_slex && !derived->vers_conditions.is_set())
{ {
derived= outer_slex->master_unit()->derived; derived= outer_slex->master_unit()->derived;
outer_slex= outer_slex->outer_select(); outer_slex= outer_slex->outer_select();
} }
if (derived && outer_slex) if (derived && outer_slex)
{ {
DBUG_ASSERT(derived->vers_conditions); DBUG_ASSERT(derived->vers_conditions.is_set());
outer_table= derived; outer_table= derived;
} }
} }
@ -791,7 +791,7 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables)
*/ */
if (table->partition_names && table->table->part_info->vers_info) if (table->partition_names && table->table->part_info->vers_info)
{ {
if (vers_conditions) if (vers_conditions.is_set())
{ {
#define PART_VERS_ERR_MSG "%s PARTITION (%s)" #define PART_VERS_ERR_MSG "%s PARTITION (%s)"
char buf[NAME_LEN*2 + sizeof(PART_VERS_ERR_MSG)]; char buf[NAME_LEN*2 + sizeof(PART_VERS_ERR_MSG)];
@ -805,7 +805,7 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables)
} }
#endif #endif
if (outer_table && !vers_conditions) if (outer_table && !vers_conditions.is_set())
{ {
// propagate system_time from nearest outer SELECT_LEX // propagate system_time from nearest outer SELECT_LEX
vers_conditions= outer_table->vers_conditions; vers_conditions= outer_table->vers_conditions;
@ -813,15 +813,15 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables)
} }
// propagate system_time from sysvar // propagate system_time from sysvar
if (!vers_conditions) if (!vers_conditions.is_set())
{ {
if (vers_conditions.init_from_sysvar(thd)) if (vers_conditions.init_from_sysvar(thd))
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
if (vers_conditions) if (vers_conditions.is_set())
{ {
if (vers_conditions == SYSTEM_TIME_ALL) if (vers_conditions.type == SYSTEM_TIME_ALL)
continue; continue;
lock_type= TL_READ; // ignore TL_WRITE, history is immutable anyway lock_type= TL_READ; // ignore TL_WRITE, history is immutable anyway
@ -837,7 +837,7 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables)
bool timestamps_only= table->table->versioned(VERS_TIMESTAMP); bool timestamps_only= table->table->versioned(VERS_TIMESTAMP);
if (vers_conditions) if (vers_conditions.is_set())
{ {
/* TODO: do resolve fix_length_and_dec(), fix_fields(). This requires /* TODO: do resolve fix_length_and_dec(), fix_fields(). This requires
storing vers_conditions as Item and make some magic related to storing vers_conditions as Item and make some magic related to

View File

@ -990,7 +990,7 @@ bool st_select_lex_unit::prepare(TABLE_LIST *derived_arg,
{ {
if (!with_element->is_anchor(sl)) if (!with_element->is_anchor(sl))
sl->uncacheable|= UNCACHEABLE_UNITED; sl->uncacheable|= UNCACHEABLE_UNITED;
if(!is_rec_result_table_created && if (!is_rec_result_table_created &&
(!sl->next_select() || (!sl->next_select() ||
sl->next_select() == with_element->first_recursive)) sl->next_select() == with_element->first_recursive))
{ {

View File

@ -609,7 +609,7 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
if (!fld) if (!fld)
continue; continue;
TABLE_SHARE *s= fld->field->table->s; TABLE_SHARE *s= fld->field->table->s;
const LString_i field_name= fld->field->field_name; const Lex_ident field_name= fld->field->field_name;
if (s->tmp_table || if (s->tmp_table ||
(s->versioned && (s->versioned &&
(field_name.streq(s->vers_start_field()->field_name) || (field_name.streq(s->vers_start_field()->field_name) ||
@ -2040,7 +2040,7 @@ bool insert_view_fields(THD *thd, List<Item> *list, TABLE_LIST *view)
if ((fld= entry->item->field_for_view_update())) if ((fld= entry->item->field_for_view_update()))
{ {
TABLE_SHARE *s= fld->context->table_list->table->s; TABLE_SHARE *s= fld->context->table_list->table->s;
LString_i field_name= fld->field_name; Lex_ident field_name= fld->field_name;
if (s->versioned && if (s->versioned &&
(field_name.streq(s->vers_start_field()->field_name) || (field_name.streq(s->vers_start_field()->field_name) ||
field_name.streq(s->vers_end_field()->field_name))) field_name.streq(s->vers_end_field()->field_name)))

View File

@ -6628,7 +6628,7 @@ field_def:
Vers_parse_info &info= lex->vers_get_info(); Vers_parse_info &info= lex->vers_get_info();
const LEX_CSTRING &field_name= lex->last_field->field_name; const LEX_CSTRING &field_name= lex->last_field->field_name;
LString_i *p; Lex_ident *p;
switch ($4) switch ($4)
{ {
case 1: case 1:

View File

@ -8881,7 +8881,7 @@ void vers_select_conds_t::resolve_units(bool timestamps_only)
end.resolve_unit(timestamps_only); end.resolve_unit(timestamps_only);
} }
bool vers_select_conds_t::eq(const vers_select_conds_t &conds) bool vers_select_conds_t::eq(const vers_select_conds_t &conds) const
{ {
if (type != conds.type) if (type != conds.type)
return false; return false;
@ -8923,13 +8923,13 @@ void Vers_history_point::fix_item()
} }
bool Vers_history_point::eq(const vers_history_point_t &point) bool Vers_history_point::eq(const vers_history_point_t &point) const
{ {
return unit == point.unit && item->eq(point.item, false); return unit == point.unit && item->eq(point.item, false);
} }
void Vers_history_point::print(String *str, enum_query_type query_type, void Vers_history_point::print(String *str, enum_query_type query_type,
const char *prefix, size_t plen) const char *prefix, size_t plen) const
{ {
const static LEX_CSTRING unit_type[]= const static LEX_CSTRING unit_type[]=
{ {

View File

@ -1827,9 +1827,9 @@ public:
fix_item(); fix_item();
} }
void empty() { unit= VERS_UNDEFINED; item= NULL; } void empty() { unit= VERS_UNDEFINED; item= NULL; }
void print(String *str, enum_query_type, const char *prefix, size_t plen); void print(String *str, enum_query_type, const char *prefix, size_t plen) const;
void resolve_unit(bool timestamps_only); void resolve_unit(bool timestamps_only);
bool eq(const vers_history_point_t &point); bool eq(const vers_history_point_t &point) const;
}; };
struct vers_select_conds_t struct vers_select_conds_t
@ -1858,19 +1858,11 @@ struct vers_select_conds_t
end= _end; end= _end;
} }
void print(String *str, enum_query_type query_type); void print(String *str, enum_query_type query_type) const;
bool init_from_sysvar(THD *thd); bool init_from_sysvar(THD *thd);
bool operator== (vers_system_time_t b) bool is_set() const
{
return type == b;
}
bool operator!= (vers_system_time_t b)
{
return type != b;
}
operator bool() const
{ {
return type != SYSTEM_TIME_UNSPECIFIED; return type != SYSTEM_TIME_UNSPECIFIED;
} }
@ -1879,7 +1871,7 @@ struct vers_select_conds_t
{ {
return !from_query && type != SYSTEM_TIME_UNSPECIFIED; return !from_query && type != SYSTEM_TIME_UNSPECIFIED;
} }
bool eq(const vers_select_conds_t &conds); bool eq(const vers_select_conds_t &conds) const;
}; };
/* /*

View File

@ -118,7 +118,7 @@ vers_get_field(HA_CREATE_INFO *create_info, List<Create_field> &create_fields, b
List_iterator<Create_field> it(create_fields); List_iterator<Create_field> it(create_fields);
Create_field *sql_field = NULL; Create_field *sql_field = NULL;
const LString_i row_field= row_start ? create_info->vers_info.as_row.start const Lex_ident row_field= row_start ? create_info->vers_info.as_row.start
: create_info->vers_info.as_row.end; : create_info->vers_info.as_row.end;
DBUG_ASSERT(row_field); DBUG_ASSERT(row_field);

View File

@ -17,125 +17,85 @@
#ifndef VERS_STRING_INCLUDED #ifndef VERS_STRING_INCLUDED
#define VERS_STRING_INCLUDED #define VERS_STRING_INCLUDED
struct Compare_strncmp /*
LEX_CSTRING with comparison semantics.
*/
// db and table names: case sensitive (or insensitive) in table_alias_charset
struct Compare_table_names
{ {
int operator()(const LEX_CSTRING& a, const LEX_CSTRING& b) const int operator()(const LEX_CSTRING& a, const LEX_CSTRING& b) const
{ {
return strncmp(a.str, b.str, a.length); DBUG_ASSERT(a.str[a.length] == 0);
} DBUG_ASSERT(b.str[b.length] == 0);
static CHARSET_INFO* charset() return my_strnncoll(table_alias_charset,
{ (uchar*)a.str, a.length,
return system_charset_info; (uchar*)b.str, b.length);
} }
}; };
template <CHARSET_INFO* &CS= system_charset_info> // column names and other identifiers: case insensitive in system_charset_info
struct Compare_my_strcasecmp struct Compare_identifiers
{ {
int operator()(const LEX_CSTRING& a, const LEX_CSTRING& b) const int operator()(const LEX_CSTRING& a, const LEX_CSTRING& b) const
{ {
DBUG_ASSERT(a.str[a.length] == 0 && b.str[b.length] == 0); DBUG_ASSERT(a.str[a.length] == 0);
return my_strcasecmp(CS, a.str, b.str); DBUG_ASSERT(b.str[b.length] == 0);
} return my_strcasecmp(system_charset_info, a.str, b.str);
static CHARSET_INFO* charset()
{
return CS;
} }
}; };
typedef Compare_my_strcasecmp<files_charset_info> Compare_fs; class Lex_cstring : public LEX_CSTRING
typedef Compare_my_strcasecmp<table_alias_charset> Compare_t;
template <class Storage= LEX_CSTRING>
struct LEX_STRING_u : public Storage
{ {
LEX_STRING_u() public:
Lex_cstring()
{ {
Storage::str= NULL; str= NULL;
Storage::length= 0; length= 0;
} }
LEX_STRING_u(const char *_str, size_t _len, CHARSET_INFO *) Lex_cstring(const char *_str, size_t _len)
{ {
Storage::str= _str; str= _str;
Storage::length= _len; length= _len;
} }
uint32 length() const void set(const char *_str, size_t _len)
{ {
return (uint32)Storage::length; str= _str;
} length= _len;
const char *ptr() const
{
return Storage::str;
}
void set(const char *_str, size_t _len, CHARSET_INFO *)
{
Storage::str= _str;
Storage::length= _len;
}
const LEX_CSTRING& lex_cstring() const
{
return *this;
}
const LEX_STRING& lex_string() const
{
return *(LEX_STRING *)this;
} }
}; };
template <class Compare= Compare_strncmp, class Storage= LEX_STRING_u<> > template <class Compare>
struct XString : public Storage struct Lex_cstring_with_compare : public Lex_cstring
{ {
public: public:
XString() {} Lex_cstring_with_compare() {}
XString(const char *_str, size_t _len) : Lex_cstring_with_compare(const char *_str, size_t _len) :
Storage(_str, _len, Compare::charset()) Lex_cstring(_str, _len)
{ }
Lex_cstring_with_compare(const LEX_STRING src) :
Lex_cstring(src.str, src.length)
{ }
Lex_cstring_with_compare(const LEX_CSTRING src) : Lex_cstring(src.str, src.length)
{ }
Lex_cstring_with_compare(const char *_str) : Lex_cstring(_str, strlen(_str))
{ }
bool streq(const Lex_cstring_with_compare& b) const
{ {
} return Lex_cstring::length == b.length && 0 == Compare()(*this, b);
XString(const LEX_STRING src) :
Storage(src.str, src.length, Compare::charset())
{
}
XString(const LEX_CSTRING src) :
Storage(src.str, src.length, Compare::charset())
{
}
XString(const char *_str) :
Storage(_str, strlen(_str), Compare::charset())
{
}
bool streq(const XString& b) const
{
return Storage::length() == b.length() && 0 == Compare()(this->lex_cstring(), b.lex_cstring());
} }
operator const char* () const operator const char* () const
{ {
return Storage::ptr(); return str;
}
operator LEX_CSTRING& () const
{
return this->lex_cstring();
}
operator LEX_STRING () const
{
LEX_STRING res;
res.str= const_cast<char *>(this->ptr());
res.length= this->length();
return res;
} }
operator bool () const operator bool () const
{ {
return Storage::ptr() != NULL; return str != NULL;
} }
}; };
typedef XString<> LString; typedef Lex_cstring_with_compare<Compare_identifiers> Lex_ident;
typedef XString<Compare_fs> LString_fs; typedef Lex_cstring_with_compare<Compare_table_names> Lex_table_name;
typedef XString<Compare_my_strcasecmp<> > LString_i;
typedef XString<Compare_strncmp, String> SString;
typedef XString<Compare_fs, String> SString_fs;
typedef XString<Compare_t, String> SString_t;
#define XSTRING_WITH_LEN(X) (X).ptr(), (X).length() #define XSTRING_WITH_LEN(X) (X).ptr(), (X).length()
#define DB_WITH_LEN(X) (X).db.str, (X).db.length #define DB_WITH_LEN(X) (X).db.str, (X).db.length