summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Midenkov <midenok@gmail.com>2017-06-22 23:09:34 +0300
committerAleksey Midenkov <midenok@gmail.com>2017-06-23 12:02:06 +0300
commit07ff0e1202fbc521c476080eb2cd9fed544dc959 (patch)
treedaee63c20df217adbc6433ff5134e12bd1d5c399
parent670b7f5fd4a4cdf82493fec56ddc6fa5de80ba90 (diff)
downloadmariadb-git-07ff0e1202fbc521c476080eb2cd9fed544dc959.tar.gz
SQL: start_end_t members as LEX_CSTRING
-rw-r--r--sql/handler.cc59
-rw-r--r--sql/handler.h23
-rw-r--r--sql/sql_table.cc8
-rw-r--r--sql/sql_yacc.yy18
-rw-r--r--sql/unireg.cc4
-rw-r--r--sql/vers_string.h131
-rw-r--r--sql/vers_utils.h99
-rw-r--r--sql/vtmd.cc2
8 files changed, 176 insertions, 168 deletions
diff --git a/sql/handler.cc b/sql/handler.cc
index 8ec9feab7c5..32d5c5fd2db 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -6584,13 +6584,12 @@ int del_global_index_stat(THD *thd, TABLE* table, KEY* key_info)
bool Vers_parse_info::is_trx_start(const char *name) const
{
DBUG_ASSERT(name);
- return generated_as_row.start &&
- !strcmp(generated_as_row.start->c_ptr(), name);
+ return generated_as_row.start && generated_as_row.start == LString_i(name);
}
bool Vers_parse_info::is_trx_end(const char *name) const
{
DBUG_ASSERT(name);
- return generated_as_row.end && !strcmp(generated_as_row.end->c_ptr(), name);
+ return generated_as_row.end && generated_as_row.end == LString_i(name);
}
bool Vers_parse_info::is_trx_start(const Create_field &f) const
{
@@ -6601,14 +6600,9 @@ bool Vers_parse_info::is_trx_end(const Create_field &f) const
return f.flags & VERS_SYS_END_FLAG;
}
-static bool create_string(MEM_ROOT *mem_root, String **s, const char *value)
-{
- *s= new (mem_root) String(value, system_charset_info);
- return *s == NULL;
-}
static bool vers_create_sys_field(THD *thd, const char *field_name,
- Alter_info *alter_info, String **s,
+ Alter_info *alter_info,
int flags,
bool integer_fields)
{
@@ -6635,9 +6629,6 @@ static bool vers_create_sys_field(THD *thd, const char *field_name,
if (f->check(thd))
return true;
- if (create_string(thd->mem_root, s, field_name))
- return true;
-
alter_info->create_list.push_back(f);
return false;
}
@@ -6652,19 +6643,18 @@ bool Vers_parse_info::fix_implicit(THD *thd, Alter_info *alter_info,
alter_info->flags|= Alter_info::ALTER_ADD_COLUMN;
- static const char * sys_trx_start= "sys_trx_start";
- static const char * sys_trx_end= "sys_trx_end";
+ static const LString sys_trx_start= "sys_trx_start";
+ static const LString sys_trx_end= "sys_trx_end";
+
+ period_for_system_time= start_end_t(sys_trx_start, sys_trx_end);
+ generated_as_row= period_for_system_time;
return vers_create_sys_field(thd, sys_trx_start, alter_info,
- &generated_as_row.start, VERS_SYS_START_FLAG,
+ VERS_SYS_START_FLAG,
integer_fields) ||
vers_create_sys_field(thd, sys_trx_end, alter_info,
- &generated_as_row.end, VERS_SYS_END_FLAG,
- integer_fields) ||
- create_string(thd->mem_root, &period_for_system_time.start,
- sys_trx_start) ||
- create_string(thd->mem_root, &period_for_system_time.end,
- sys_trx_end);
+ VERS_SYS_END_FLAG,
+ integer_fields);
}
bool Vers_parse_info::check_and_fix_implicit(
@@ -6731,7 +6721,7 @@ bool Vers_parse_info::check_and_fix_implicit(
return true;
}
orig_table= f->field->orig_table;
- generated_as_row.start= new (thd->mem_root) String(f->field_name, system_charset_info);
+ generated_as_row.start= f->field_name;
period_for_system_time.start= generated_as_row.start;
}
continue;
@@ -6746,7 +6736,7 @@ bool Vers_parse_info::check_and_fix_implicit(
goto err_different_tables;
}
orig_table= f->field->orig_table;
- generated_as_row.end= new (thd->mem_root) String(f->field_name, system_charset_info);
+ generated_as_row.end= f->field_name;
period_for_system_time.end= generated_as_row.end;
}
continue;
@@ -6866,11 +6856,8 @@ bool Vers_parse_info::check_and_fix_alter(THD *thd, Alter_info *alter_info,
const char *end= share->vers_end_field()->field_name;
DBUG_ASSERT(start && end);
- if (create_string(thd->mem_root, &generated_as_row.start, start) ||
- create_string(thd->mem_root, &generated_as_row.end, end) ||
- create_string(thd->mem_root, &period_for_system_time.start, start) ||
- create_string(thd->mem_root, &period_for_system_time.end, end))
- return true;
+ generated_as_row= start_end_t(start, end);
+ period_for_system_time= generated_as_row;
if (alter_info->create_list.elements)
{
@@ -6935,14 +6922,8 @@ bool Vers_parse_info::fix_create_like(THD *thd, Alter_info *alter_info,
return true;
}
- if (create_string(thd->mem_root, &generated_as_row.start, f_start->field_name) ||
- create_string(thd->mem_root, &period_for_system_time.start, f_start->field_name) ||
- create_string(thd->mem_root, &generated_as_row.end, f_end->field_name) ||
- create_string(thd->mem_root, &period_for_system_time.end, f_end->field_name))
- {
- sql_print_error("Failed to allocate memory for Vers_parse_info::fix_create_like()");
- return true;
- }
+ generated_as_row= start_end_t(f_start->field_name, f_end->field_name);
+ period_for_system_time= generated_as_row;
create_info->options|= HA_VERSIONED_TABLE;
return false;
@@ -6972,16 +6953,14 @@ bool Vers_parse_info::check_with_conditions(const char *table_name) const
return true;
}
- if (my_strcasecmp(system_charset_info, generated_as_row.start->c_ptr(),
- period_for_system_time.start->c_ptr()))
+ if (generated_as_row.start != period_for_system_time.start)
{
my_error(ER_VERS_WRONG_PARAMS, MYF(0), table_name,
"'PERIOD FOR SYSTEM_TIME' and 'GENERATED AS ROW START' mismatch");
return true;
}
- if (my_strcasecmp(system_charset_info, generated_as_row.end->c_ptr(),
- period_for_system_time.end->c_ptr()))
+ if (generated_as_row.end != period_for_system_time.end)
{
my_error(ER_VERS_WRONG_PARAMS, MYF(0), table_name,
"'PERIOD FOR SYSTEM_TIME' and 'GENERATED AS ROW END' mismatch");
diff --git a/sql/handler.h b/sql/handler.h
index 6f65853256c..9c2b1bcf209 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -36,6 +36,7 @@
#include "sql_array.h" /* Dynamic_array<> */
#include "mdl.h"
#include "vtq.h"
+#include "vers_string.h"
#include "sql_analyze_stmt.h" // for Exec_time_tracker
@@ -1684,17 +1685,19 @@ struct Vers_parse_info
struct start_end_t
{
- start_end_t() :
- start(NULL),
- end(NULL) {}
- String *start;
- String *end;
+ start_end_t()
+ {}
+ start_end_t(const char* _start, const char* _end) :
+ start(_start),
+ end(_end) {}
+ LString_i start;
+ LString_i end;
};
start_end_t period_for_system_time;
start_end_t generated_as_row;
- void set_period_for_system_time(String *start, String *end)
+ void set_period_for_system_time(LString start, LString end)
{
period_for_system_time.start = start;
period_for_system_time.end = end;
@@ -1713,10 +1716,10 @@ private:
has_unversioned_fields ||
declared_with_system_versioning ||
declared_without_system_versioning ||
- period_for_system_time.start ||
- period_for_system_time.end ||
- generated_as_row.start ||
- generated_as_row.end;
+ period_for_system_time.start.str ||
+ period_for_system_time.end.str ||
+ generated_as_row.start.str ||
+ generated_as_row.end.str;
}
bool check_with_conditions(const char *table_name) const;
bool check_generated_type(const char *table_name, Alter_info *alter_info,
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 7aeb1854e24..4c1ab495651 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -4326,9 +4326,9 @@ vers_prepare_keys(THD *thd,
{
DBUG_ASSERT(create_info->versioned());
- const char *row_start_field= create_info->vers_info.generated_as_row.start->c_ptr();
+ const char *row_start_field= create_info->vers_info.generated_as_row.start;
DBUG_ASSERT(row_start_field);
- const char *row_end_field= create_info->vers_info.generated_as_row.end->c_ptr();
+ const char *row_end_field= create_info->vers_info.generated_as_row.end;
DBUG_ASSERT(row_end_field);
List_iterator<Key> key_it(alter_info->key_list);
@@ -4354,10 +4354,8 @@ vers_prepare_keys(THD *thd,
if (key_part)
continue; // Key already contains Sys_start or Sys_end
- const LEX_STRING &lex_sys_end=
- create_info->vers_info.generated_as_row.end->lex_string();
Key_part_spec *key_part_sys_end_col=
- new(thd->mem_root) Key_part_spec(lex_sys_end, 0);
+ new(thd->mem_root) Key_part_spec(create_info->vers_info.generated_as_row.end, 0);
key->columns.push_back(key_part_sys_end_col);
}
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index ec09803a46e..73860aadca5 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -1622,6 +1622,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
opt_constraint constraint opt_ident
sp_decl_ident
sp_block_label
+ period_for_system_time_column_id
%type <lex_string_with_metadata>
TEXT_STRING
@@ -1651,7 +1652,6 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%type <string>
text_string hex_or_bin_String opt_gconcat_separator
- period_for_system_time_column_id
%type <field_type> int_type real_type
@@ -6167,7 +6167,7 @@ period_for_system_time:
PERIOD_SYM FOR_SYSTEM_TIME_SYM '(' period_for_system_time_column_id ',' period_for_system_time_column_id ')'
{
Vers_parse_info &info= Lex->vers_get_info();
- if (!my_strcasecmp(system_charset_info, $4->c_ptr(), $6->c_ptr()))
+ if (!my_strcasecmp(system_charset_info, $4.str, $6.str))
{
my_yyabort_error((ER_VERS_WRONG_PARAMS, MYF(0),
Lex->create_last_non_select_table->table_name,
@@ -6284,14 +6284,10 @@ field_def:
{
LEX *lex= Lex;
Vers_parse_info &info= lex->vers_get_info();
- String *field_name= new (thd->mem_root)
- String((const char*)lex->last_field->field_name, system_charset_info);
- if (!field_name)
- MYSQL_YYABORT;
-
+ const char *field_name= lex->last_field->field_name;
const char *table_name= lex->create_last_non_select_table->table_name;
- String **p= NULL;
+ LString_i *p;
const char* err;
switch ($4)
{
@@ -6310,6 +6306,7 @@ field_def:
MYSQL_YYABORT;
break;
}
+ DBUG_ASSERT(p);
if (*p)
{
my_yyabort_error((ER_VERS_WRONG_PARAMS, MYF(0), table_name, err));
@@ -16237,10 +16234,7 @@ column_list:
period_for_system_time_column_id:
ident
{
- String *new_str= new (thd->mem_root) String((const char*) $1.str,$1.length,system_charset_info);
- if (new_str == NULL)
- MYSQL_YYABORT;
- $$= new_str;
+ $$= $1;
}
;
diff --git a/sql/unireg.cc b/sql/unireg.cc
index cffc98d2e35..7a5aadb1c22 100644
--- a/sql/unireg.cc
+++ b/sql/unireg.cc
@@ -101,8 +101,8 @@ vers_get_field(HA_CREATE_INFO *create_info, List<Create_field> &create_fields, b
const char *row_field =
row_start ?
- create_info->vers_info.generated_as_row.start->c_ptr() :
- create_info->vers_info.generated_as_row.end->c_ptr();
+ create_info->vers_info.generated_as_row.start :
+ create_info->vers_info.generated_as_row.end;
DBUG_ASSERT(row_field);
for (unsigned field_no = 0; (sql_field = it++); ++field_no)
diff --git a/sql/vers_string.h b/sql/vers_string.h
new file mode 100644
index 00000000000..ddd691276db
--- /dev/null
+++ b/sql/vers_string.h
@@ -0,0 +1,131 @@
+#ifndef VERS_STRING_INCLUDED
+#define VERS_STRING_INCLUDED
+
+struct Compare_strncmp
+{
+ int operator()(const LEX_CSTRING& a, const LEX_CSTRING& b) const
+ {
+ return strncmp(a.str, b.str, a.length);
+ }
+ static CHARSET_INFO* charset()
+ {
+ return system_charset_info;
+ }
+};
+
+template <CHARSET_INFO* &CS= system_charset_info>
+struct Compare_my_strcasecmp
+{
+ int operator()(const LEX_CSTRING& a, const LEX_CSTRING& b) const
+ {
+ DBUG_ASSERT(a.str[a.length] == 0 && b.str[b.length] == 0);
+ return my_strcasecmp(CS, a.str, b.str);
+ }
+ static CHARSET_INFO* charset()
+ {
+ return CS;
+ }
+};
+
+typedef Compare_my_strcasecmp<files_charset_info> Compare_fs;
+typedef Compare_my_strcasecmp<table_alias_charset> Compare_t;
+
+template <class Storage= LEX_CSTRING>
+struct LEX_STRING_u : public Storage
+{
+ LEX_STRING_u()
+ {
+ Storage::str= NULL;
+ Storage::length= 0;
+ }
+ LEX_STRING_u(const char *_str, uint32 _len, CHARSET_INFO *)
+ {
+ Storage::str= _str;
+ Storage::length= _len;
+ }
+ uint32 length() const
+ {
+ return Storage::length;
+ }
+ const char *ptr() const
+ {
+ return Storage::str;
+ }
+ void set(const char *_str, uint32 _len, CHARSET_INFO *)
+ {
+ Storage::str= _str;
+ Storage::length= _len;
+ }
+ const LEX_CSTRING& lex_cstring() const
+ {
+ return *this;
+ }
+};
+
+template <class Compare= Compare_strncmp, class Storage= LEX_STRING_u<> >
+struct XString : public Storage
+{
+public:
+ XString() {}
+ XString(const char *_str, size_t _len) :
+ Storage(_str, _len, Compare::charset())
+ {
+ }
+ XString(LEX_STRING& src) :
+ Storage(src.str, src.length, Compare::charset())
+ {
+ }
+ XString(const char *_str) :
+ Storage(_str, strlen(_str), Compare::charset())
+ {
+ }
+ XString& operator= (const char *_str)
+ {
+ DBUG_ASSERT(_str);
+ Storage::set(_str, strlen(_str), Compare::charset());
+ return *this;
+ }
+ bool operator== (const XString& b) const
+ {
+ return Storage::length() == b.length() && 0 == Compare()(this->lex_cstring(), b.lex_cstring());
+ }
+ bool operator!= (const XString& b) const
+ {
+ return !(*this == b);
+ }
+ operator const char* () const
+ {
+ return Storage::ptr();
+ }
+ 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
+ {
+ return Storage::ptr() != NULL;
+ }
+};
+
+typedef XString<> LString;
+typedef XString<Compare_fs> LString_fs;
+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 DB_WITH_LEN(X) (X).db, (X).db_length
+#define TABLE_NAME_WITH_LEN(X) (X).table_name, (X).table_name_length
+
+
+#endif // VERS_STRING_INCLUDED
diff --git a/sql/vers_utils.h b/sql/vers_utils.h
index ee08fcbb2bc..948139bfa9b 100644
--- a/sql/vers_utils.h
+++ b/sql/vers_utils.h
@@ -3,6 +3,7 @@
#include "table.h"
#include "sql_class.h"
+#include "vers_string.h"
class MDL_auto_lock
{
@@ -30,104 +31,6 @@ public:
bool acquire_error() const { return error; }
};
-struct Compare_strncmp
-{
- int operator()(const LEX_STRING& a, const LEX_STRING& b) const
- {
- return strncmp(a.str, b.str, a.length);
- }
- static CHARSET_INFO* charset()
- {
- return system_charset_info;
- }
-};
-
-template <CHARSET_INFO* &CS= system_charset_info>
-struct Compare_my_strcasecmp
-{
- int operator()(const LEX_STRING& a, const LEX_STRING& b) const
- {
- DBUG_ASSERT(a.str[a.length] == 0 && b.str[b.length] == 0);
- return my_strcasecmp(CS, a.str, b.str);
- }
- static CHARSET_INFO* charset()
- {
- return CS;
- }
-};
-
-typedef Compare_my_strcasecmp<files_charset_info> Compare_fs;
-typedef Compare_my_strcasecmp<table_alias_charset> Compare_t;
-
-struct LEX_STRING_u : public LEX_STRING
-{
- LEX_STRING_u()
- {
- str= NULL;
- LEX_STRING::length= 0;
- }
- LEX_STRING_u(const char *_str, uint32 _len, CHARSET_INFO *)
- {
- str= const_cast<char *>(_str);
- LEX_STRING::length= _len;
- }
- uint32 length() const
- {
- return LEX_STRING::length;
- }
- const char *ptr() const
- {
- return LEX_STRING::str;
- }
- const LEX_STRING& lex_string() const
- {
- return *this;
- }
-};
-
-template <class Compare= Compare_strncmp, class Storage= LEX_STRING_u>
-struct XString : public Storage
-{
-public:
- XString() {}
- XString(char *_str, size_t _len) :
- Storage(_str, _len, Compare::charset())
- {
- }
- XString(LEX_STRING& src) :
- Storage(src.str, src.length, Compare::charset())
- {
- }
- XString(char *_str) :
- Storage(_str, strlen(_str), Compare::charset())
- {
- }
- bool operator== (const XString& b) const
- {
- return Storage::length() == b.length() && 0 == Compare()(this->lex_string(), b.lex_string());
- }
- bool operator!= (const XString& b) const
- {
- return !(*this == b);
- }
- operator const char* () const
- {
- return Storage::ptr();
- }
-};
-
-typedef XString<> LString;
-typedef XString<Compare_fs> LString_fs;
-
-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 DB_WITH_LEN(X) (X).db, (X).db_length
-#define TABLE_NAME_WITH_LEN(X) (X).table_name, (X).table_name_length
-
class Local_da : public Diagnostics_area
{
diff --git a/sql/vtmd.cc b/sql/vtmd.cc
index 65620bd2cb0..83a6fb512ef 100644
--- a/sql/vtmd.cc
+++ b/sql/vtmd.cc
@@ -416,7 +416,7 @@ VTMD_rename::try_rename(THD *thd, LString new_db, LString new_alias, const char
return false;
bool same_db= true;
- if (LString_fs(DB_WITH_LEN(about)) != new_db)
+ if (LString_fs(DB_WITH_LEN(about)) != LString_fs(new_db))
{
// Move archives before VTMD so if the operation is interrupted, it could be continued.
if (move_archives(thd, new_db))