1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

Changing field::field_name and Item::name to LEX_CSTRING

Benefits of this patch:
- Removed a lot of calls to strlen(), especially for field_string
- Strings generated by parser are now const strings, less chance of
  accidently changing a string
- Removed a lot of calls with LEX_STRING as parameter (changed to pointer)
- More uniform code
- Item::name_length was not kept up to date. Now fixed
- Several bugs found and fixed (Access to null pointers,
  access of freed memory, wrong arguments to printf like functions)
- Removed a lot of casts from (const char*) to (char*)

Changes:
- This caused some ABI changes
  - lex_string_set now uses LEX_CSTRING
  - Some fucntions are now taking const char* instead of char*
- Create_field::change and after changed to LEX_CSTRING
- handler::connect_string, comment and engine_name() changed to LEX_CSTRING
- Checked printf() related calls to find bugs. Found and fixed several
  errors in old code.
- A lot of changes from LEX_STRING to LEX_CSTRING, especially related to
  parsing and events.
- Some changes from LEX_STRING and LEX_STRING & to LEX_CSTRING*
- Some changes for char* to const char*
- Added printf argument checking for my_snprintf()
- Introduced null_clex_str, star_clex_string, temp_lex_str to simplify
  code
- Added item_empty_name and item_used_name to be able to distingush between
  items that was given an empty name and items that was not given a name
  This is used in sql_yacc.yy to know when to give an item a name.
- select table_name."*' is not anymore same as table_name.*
- removed not used function Item::rename()
- Added comparision of item->name_length before some calls to
  my_strcasecmp() to speed up comparison
- Moved Item_sp_variable::make_field() from item.h to item.cc
- Some minimal code changes to avoid copying to const char *
- Fixed wrong error message in wsrep_mysql_parse()
- Fixed wrong code in find_field_in_natural_join() where real_item() was
  set when it shouldn't
- ER_ERROR_ON_RENAME was used with extra arguments.
- Removed some (wrong) ER_OUTOFMEMORY, as alloc_root will already
  give the error.

TODO:
- Check possible unsafe casts in plugin/auth_examples/qa_auth_interface.c
- Change code to not modify LEX_CSTRING for database name
  (as part of lower_case_table_names)
This commit is contained in:
Monty
2017-04-23 19:39:57 +03:00
parent cba84469eb
commit 5a759d31f7
233 changed files with 4155 additions and 3794 deletions

View File

@ -471,9 +471,9 @@ protected:
/* Table for which statistical data is read / updated */
TABLE *table;
TABLE_SHARE *table_share; /* Table share for 'table */
LEX_STRING *db_name; /* Name of the database containing 'table' */
LEX_STRING *table_name; /* Name of the table 'table' */
TABLE_SHARE *table_share; /* Table share for 'table */
LEX_CSTRING *db_name; /* Name of the database containing 'table' */
LEX_CSTRING *table_name; /* Name of the table 'table' */
void store_record_for_update()
{
@ -528,7 +528,7 @@ public:
by the database name 'db' and the table name 'tab'.
*/
Stat_table(TABLE *stat, LEX_STRING *db, LEX_STRING *tab)
Stat_table(TABLE *stat, LEX_CSTRING *db, LEX_CSTRING *tab)
:stat_table(stat), table_share(NULL)
{
common_init_stat_table();
@ -553,7 +553,7 @@ public:
The method is called by the update_table_name_key_parts function.
*/
virtual void change_full_table_name(LEX_STRING *db, LEX_STRING *tab)= 0;
virtual void change_full_table_name(LEX_CSTRING *db, LEX_CSTRING *tab)= 0;
/**
@ -703,7 +703,7 @@ public:
to store the new names in the record buffer used for updates.
*/
bool update_table_name_key_parts(LEX_STRING *db, LEX_STRING *tab)
bool update_table_name_key_parts(LEX_CSTRING *db, LEX_CSTRING *tab)
{
store_record_for_update();
change_full_table_name(db, tab);
@ -765,7 +765,7 @@ private:
table_name_field= stat_table->field[TABLE_STAT_TABLE_NAME];
}
void change_full_table_name(LEX_STRING *db, LEX_STRING *tab)
void change_full_table_name(LEX_CSTRING *db, LEX_CSTRING *tab)
{
db_name_field->store(db->str, db->length, system_charset_info);
table_name_field->store(tab->str, tab->length, system_charset_info);
@ -795,7 +795,7 @@ public:
from the database 'db'.
*/
Table_stat(TABLE *stat, LEX_STRING *db, LEX_STRING *tab)
Table_stat(TABLE *stat, LEX_CSTRING *db, LEX_CSTRING *tab)
:Stat_table(stat, db, tab)
{
common_init_table_stat();
@ -909,7 +909,7 @@ private:
column_name_field= stat_table->field[COLUMN_STAT_COLUMN_NAME];
}
void change_full_table_name(LEX_STRING *db, LEX_STRING *tab)
void change_full_table_name(LEX_CSTRING *db, LEX_CSTRING *tab)
{
db_name_field->store(db->str, db->length, system_charset_info);
table_name_field->store(tab->str, tab->length, system_charset_info);
@ -939,7 +939,7 @@ public:
from the database 'db'.
*/
Column_stat(TABLE *stat, LEX_STRING *db, LEX_STRING *tab)
Column_stat(TABLE *stat, LEX_CSTRING *db, LEX_CSTRING *tab)
:Stat_table(stat, db, tab)
{
common_init_column_stat_table();
@ -983,8 +983,7 @@ public:
void set_key_fields(Field *col)
{
set_full_table_name();
const char *column_name= col->field_name;
column_name_field->store(column_name, strlen(column_name),
column_name_field->store(col->field_name.str, col->field_name.length,
system_charset_info);
table_field= col;
}
@ -1245,7 +1244,7 @@ private:
prefix_arity_field= stat_table->field[INDEX_STAT_PREFIX_ARITY];
}
void change_full_table_name(LEX_STRING *db, LEX_STRING *tab)
void change_full_table_name(LEX_CSTRING *db, LEX_CSTRING *tab)
{
db_name_field->store(db->str, db->length, system_charset_info);
table_name_field->store(tab->str, tab->length, system_charset_info);
@ -1277,7 +1276,7 @@ public:
from the database 'db'.
*/
Index_stat(TABLE *stat, LEX_STRING *db, LEX_STRING *tab)
Index_stat(TABLE *stat, LEX_CSTRING *db, LEX_CSTRING *tab)
:Stat_table(stat, db, tab)
{
common_init_index_stat_table();
@ -1320,7 +1319,7 @@ public:
void set_index_prefix_key_fields(KEY *index_info)
{
set_full_table_name();
char *index_name= index_info->name;
const char *index_name= index_info->name;
index_name_field->store(index_name, strlen(index_name),
system_charset_info);
table_key_info= index_info;
@ -1961,7 +1960,7 @@ void create_min_max_statistical_fields_for_table(TABLE *table)
for (uint i=0; i < 2; i++, record+= rec_buff_length)
{
for (Field **field_ptr= table->field; *field_ptr; field_ptr++)
for (Field **field_ptr= table->field; *field_ptr; field_ptr++)
{
Field *fld;
Field *table_field= *field_ptr;
@ -2030,7 +2029,7 @@ void create_min_max_statistical_fields_for_table_share(THD *thd,
for (uint i=0; i < 2; i++, record+= rec_buff_length)
{
for (Field **field_ptr= table_share->field; *field_ptr; field_ptr++)
for (Field **field_ptr= table_share->field; *field_ptr; field_ptr++)
{
Field *fld;
Field *table_field= *field_ptr;
@ -2493,7 +2492,7 @@ bool Column_statistics_collected::add(ha_rows rowno)
set_not_null(COLUMN_STAT_MIN_VALUE);
if (max_value && column->update_max(max_value, rowno == nulls))
set_not_null(COLUMN_STAT_MAX_VALUE);
if (count_distinct)
if (count_distinct)
err= count_distinct->add();
}
return err;
@ -3283,7 +3282,7 @@ int read_statistics_for_tables_if_needed(THD *thd, TABLE_LIST *tables)
The function is called when executing the statement DROP TABLE 'tab'.
*/
int delete_statistics_for_table(THD *thd, LEX_STRING *db, LEX_STRING *tab)
int delete_statistics_for_table(THD *thd, LEX_CSTRING *db, LEX_CSTRING *tab)
{
int err;
enum_binlog_format save_binlog_format;
@ -3521,8 +3520,8 @@ int delete_statistics_for_index(THD *thd, TABLE *tab, KEY *key_info,
The function is called when executing any statement that renames a table
*/
int rename_table_in_stat_tables(THD *thd, LEX_STRING *db, LEX_STRING *tab,
LEX_STRING *new_db, LEX_STRING *new_tab)
int rename_table_in_stat_tables(THD *thd, LEX_CSTRING *db, LEX_CSTRING *tab,
LEX_CSTRING *new_db, LEX_CSTRING *new_tab)
{
int err;
enum_binlog_format save_binlog_format;