Skip to content

Commit

Permalink
Changed database, tablename and alias to be LEX_CSTRING
Browse files Browse the repository at this point in the history
This was done in, among other things:
- thd->db and thd->db_length
- TABLE_LIST tablename, db, alias and schema_name
- Audit plugin database name
- lex->db
- All db and table names in Alter_table_ctx
- st_select_lex db

Other things:
- Changed a lot of functions to take const LEX_CSTRING* as argument
  for db, table_name and alias. See init_one_table() as an example.
- Changed some function arguments from LEX_CSTRING to const LEX_CSTRING
- Changed some lists from LEX_STRING to LEX_CSTRING
- threads_mysql.result changed because process list_db wasn't always
  correctly updated
- New append_identifier() function that takes LEX_CSTRING* as arguments
- Added new element tmp_buff to Alter_table_ctx to separate temp name
  handling from temporary space
- Ensure we store the length after my_casedn_str() of table/db names
- Removed not used version of rename_table_in_stat_tables()
- Changed Natural_join_column::table_name and db_name() to never return
  NULL (used for print)
- thd->get_db() now returns db as a printable string (thd->db.str or "")
  • Loading branch information
montywi committed Jan 30, 2018
1 parent 921c5e9 commit a7e352b
Show file tree
Hide file tree
Showing 145 changed files with 2,363 additions and 2,409 deletions.
2 changes: 2 additions & 0 deletions extra/comp_err.c
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,7 @@ static struct errors *generate_empty_message(uint d_code, my_bool skip)
new_error->d_code= d_code;
new_error->sql_code1= empty_string;
new_error->sql_code2= empty_string;
new_error->next_error= 0;

message.text= 0; /* If skip set, don't generate a text */

Expand Down Expand Up @@ -998,6 +999,7 @@ static struct errors *parse_error_string(char *str, int er_count)
MYF(MY_WME))))
DBUG_RETURN(0);

new_error->next_error= 0;
if (my_init_dynamic_array(&new_error->msg, sizeof(struct message), 0, 0, MYF(0)))
DBUG_RETURN(0); /* OOM: Fatal error */

Expand Down
20 changes: 7 additions & 13 deletions include/mysql/plugin_audit.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ struct mysql_event_general
unsigned long long general_rows;
/* Added in version 0x302 */
unsigned long long query_id;
const char *database;
unsigned int database_length;
MYSQL_CONST_LEX_STRING database;
};


Expand Down Expand Up @@ -101,8 +100,7 @@ struct mysql_event_connection
unsigned int host_length;
const char *ip;
unsigned int ip_length;
const char *database;
unsigned int database_length;
MYSQL_CONST_LEX_STRING database;
};

/*
Expand Down Expand Up @@ -137,17 +135,13 @@ struct mysql_event_table
const char *proxy_user;
const char *host;
const char *ip;
const char *database;
unsigned int database_length;
const char *table;
unsigned int table_length;
MYSQL_CONST_LEX_STRING database;
MYSQL_CONST_LEX_STRING table;
/* for MYSQL_AUDIT_TABLE_RENAME */
MYSQL_CONST_LEX_STRING new_database;
MYSQL_CONST_LEX_STRING new_table;
/* for MYSQL_AUDIT_TABLE_LOCK, true if read-only, false if read/write */
int read_only;
/* for MYSQL_AUDIT_TABLE_RENAME */
const char *new_database;
unsigned int new_database_length;
const char *new_table;
unsigned int new_table_length;
/* Added in version 0x302 */
unsigned long long query_id;
};
Expand Down
18 changes: 6 additions & 12 deletions include/mysql/plugin_audit.h.pp
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,7 @@
unsigned long long general_time;
unsigned long long general_rows;
unsigned long long query_id;
const char *database;
unsigned int database_length;
MYSQL_CONST_LEX_STRING database;
};
struct mysql_event_connection
{
Expand All @@ -563,8 +562,7 @@
unsigned int host_length;
const char *ip;
unsigned int ip_length;
const char *database;
unsigned int database_length;
MYSQL_CONST_LEX_STRING database;
};
struct mysql_event_table
{
Expand All @@ -577,15 +575,11 @@
const char *proxy_user;
const char *host;
const char *ip;
const char *database;
unsigned int database_length;
const char *table;
unsigned int table_length;
MYSQL_CONST_LEX_STRING database;
MYSQL_CONST_LEX_STRING table;
MYSQL_CONST_LEX_STRING new_database;
MYSQL_CONST_LEX_STRING new_table;
int read_only;
const char *new_database;
unsigned int new_database_length;
const char *new_table;
unsigned int new_table_length;
unsigned long long query_id;
};
struct st_mysql_audit
Expand Down
5 changes: 3 additions & 2 deletions include/mysql/service_my_print_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ extern struct my_print_error_service_st {
#define my_printv_error(A,B,C,D) my_print_error_service->my_printv_error_func(A,B,C,D)

#else

#ifndef MY_ERROR_DEFINED
extern void my_error(unsigned int nr, unsigned long MyFlags, ...);
extern void my_printf_error(unsigned int my_err, const char *format, unsigned long MyFlags, ...);
extern void my_printv_error(unsigned int error, const char *format, unsigned long MyFlags,va_list ap);
#endif
#endif /* MY_ERROR_DEFINED */
#endif /* MYSQL_DYNAMIC_PLUGIN */

#ifdef __cplusplus
}
Expand Down
3 changes: 1 addition & 2 deletions libmysqld/lib_sql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,7 @@ void *create_embedded_thd(int client_flag)
thd->client_capabilities= client_flag;
thd->real_id= pthread_self();

thd->db= NULL;
thd->db_length= 0;
thd->db= null_clex_str;
#ifndef NO_EMBEDDED_ACCESS_CHECKS
thd->security_ctx->db_access= DB_ACLS;
thd->security_ctx->master_access= ~NO_ACCESS;
Expand Down
1 change: 1 addition & 0 deletions mysql-test/suite/innodb/r/instant_alter_crash.result
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
FLUSH TABLES;
#
# MDEV-11369: Instant ADD COLUMN for InnoDB
#
Expand Down
2 changes: 2 additions & 0 deletions mysql-test/suite/innodb/t/instant_alter_crash.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
--source include/have_debug.inc
--source include/have_debug_sync.inc

FLUSH TABLES;

let INNODB_PAGE_SIZE=`select @@innodb_page_size`;
let MYSQLD_DATADIR=`select @@datadir`;

Expand Down
4 changes: 2 additions & 2 deletions mysql-test/suite/perfschema/r/threads_mysql.result
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ name thread/sql/main
type BACKGROUND
processlist_user NULL
processlist_host NULL
processlist_db NULL
processlist_db mysql
processlist_command NULL
processlist_info NULL
unified_parent_thread_id NULL
Expand Down Expand Up @@ -99,7 +99,7 @@ name thread/sql/event_worker
type FOREGROUND
processlist_user root
processlist_host localhost
processlist_db NULL
processlist_db test
processlist_command Sleep
processlist_info SELECT SLEEP(3)
unified_parent_thread_id unified parent_thread_id
Expand Down
4 changes: 2 additions & 2 deletions plugin/audit_null/audit_null.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static void audit_null_notify(MYSQL_THD thd __attribute__((unused)),
break;
case MYSQL_AUDIT_TABLE_RENAME:
snprintf(buf, sizeof(buf), "rename to %s.%s",
event_table->new_database, event_table->new_table);
event_table->new_database.str, event_table->new_table.str);
buf[sizeof(buf)-1]= 0;
op= buf;
break;
Expand All @@ -154,7 +154,7 @@ static void audit_null_notify(MYSQL_THD thd __attribute__((unused)),
fprintf(f, "%s[%s] @ %s [%s]\t%s.%s : %s\n",
event_table->priv_user, event_table->user,
event_table->host, ip,
event_table->database, event_table->table, op);
event_table->database.str, event_table->table.str, op);
}
}

Expand Down
2 changes: 1 addition & 1 deletion plugin/feedback/feedback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static COND* make_cond(THD *thd, TABLE_LIST *tables, LEX_STRING *filter)
{
Item_cond_or *res= NULL;
Name_resolution_context nrc;
const char *db= tables->db, *table= tables->alias;
const char *db= tables->db.str, *table= tables->alias.str;
LEX_CSTRING *field= &tables->table->field[0]->field_name;
CHARSET_INFO *cs= &my_charset_latin1;

Expand Down
11 changes: 4 additions & 7 deletions plugin/feedback/sender_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,17 @@ static int prepare_for_fill(TABLE_LIST *tables)
thd->set_time();
thd->init_for_queries();
thd->real_id= pthread_self();
thd->db= NULL;
thd->db_length= 0;
thd->db= null_clex_str;
thd->security_ctx->host_or_ip= "";
thd->security_ctx->db_access= DB_ACLS;
thd->security_ctx->master_access= ~NO_ACCESS;
bzero((char*) &thd->net, sizeof(thd->net));
lex_start(thd);
mysql_init_select(thd->lex);

tables->init_one_table(INFORMATION_SCHEMA_NAME.str,
INFORMATION_SCHEMA_NAME.length,
i_s_feedback->table_name,
strlen(i_s_feedback->table_name),
0, TL_READ);
LEX_CSTRING tbl_name= {i_s_feedback->table_name, strlen(i_s_feedback->table_name) };

tables->init_one_table(&INFORMATION_SCHEMA_NAME, &tbl_name, 0, TL_READ);
tables->schema_table= i_s_feedback;
tables->table= create_schema_table(thd, tables);
if (!tables->table)
Expand Down
11 changes: 6 additions & 5 deletions plugin/handler_socket/handlersocket/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ dbcontext::init_thread(const void *stack_bottom, volatile int& shutdown_flag)
#else
thd->options |= OPTION_BIN_LOG;
#endif
safeFree(thd->db);
thd->db = 0;
thd->db = my_strdup("handlersocket", MYF(0));
safeFree((char*) thd->db.str);
thd->db.str= my_strdup("handlersocket", MYF(0));
thd->db.length= sizeof("handlersocket")-1;
}
thd->variables.option_bits |= OPTION_TABLE_LOCK;
my_pthread_setspecific_ptr(THR_THD, thd);
Expand Down Expand Up @@ -1005,8 +1005,9 @@ dbcontext::cmd_open(dbcallback_i& cb, const cmd_open_args& arg)
bool refresh = true;
const thr_lock_type lock_type = for_write_flag ? TL_WRITE : TL_READ;
#if MYSQL_VERSION_ID >= 50505
tables.init_one_table(arg.dbn, strlen(arg.dbn), arg.tbl, strlen(arg.tbl),
arg.tbl, lock_type);
LEX_CSTRING db_name= { arg.dbn, strlen(arg.dbn) };
LEX_CSTRING tbl_name= { arg.tbl, strlen(arg.tbl) };
tables.init_one_table(&db_name, &tbl_name, 0, lock_type);
tables.mdl_request.init(MDL_key::TABLE, arg.dbn, arg.tbl,
for_write_flag ? MDL_SHARED_WRITE : MDL_SHARED_READ, MDL_TRANSACTION);
Open_table_context ot_act(thd, 0);
Expand Down
38 changes: 19 additions & 19 deletions plugin/server_audit/server_audit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,7 @@ static void setup_connection_connect(struct connection_info *cn,
cn->log_always= 0;
cn->thread_id= event->thread_id;
get_str_n(cn->db, &cn->db_length, sizeof(cn->db),
event->database, event->database_length);
event->database.str, event->database.length);
get_str_n(cn->user, &cn->user_length, sizeof(cn->db),
event->user, event->user_length);
get_str_n(cn->host, &cn->host_length, sizeof(cn->host),
Expand Down Expand Up @@ -1176,7 +1176,7 @@ static void setup_connection_table(struct connection_info *cn,
cn->log_always= 0;
cn->query_length= 0;
get_str_n(cn->db, &cn->db_length, sizeof(cn->db),
event->database, event->database_length);
event->database.str, event->database.length);
get_str_n(cn->user, &cn->user_length, sizeof(cn->db),
event->user, SAFE_STRLEN(event->user));
get_str_n(cn->host, &cn->host_length, sizeof(cn->host),
Expand Down Expand Up @@ -1324,7 +1324,7 @@ static int log_connection_event(const struct mysql_event_connection *event,
event->ip, event->ip_length,
event->thread_id, 0, type);
csize+= my_snprintf(message+csize, sizeof(message) - 1 - csize,
",%.*s,,%d", event->database_length, event->database, event->status);
",%.*s,,%d", event->database.length, event->database.str, event->status);
message[csize]= '\n';
return write_log(message, csize + 1);
}
Expand Down Expand Up @@ -1742,8 +1742,8 @@ static int log_table(const struct connection_info *cn,
event->ip, (unsigned int)SAFE_STRLEN(event->ip),
event->thread_id, cn->query_id, type);
csize+= my_snprintf(message+csize, sizeof(message) - 1 - csize,
",%.*s,%.*s,",event->database_length, event->database,
event->table_length, event->table);
",%.*s,%.*s,",event->database.length, event->database.str,
event->table.length, event->table.str);
message[csize]= '\n';
return write_log(message, csize + 1);
}
Expand All @@ -1764,10 +1764,10 @@ static int log_rename(const struct connection_info *cn,
event->ip, (unsigned int)SAFE_STRLEN(event->ip),
event->thread_id, cn->query_id, "RENAME");
csize+= my_snprintf(message+csize, sizeof(message) - 1 - csize,
",%.*s,%.*s|%.*s.%.*s,",event->database_length, event->database,
event->table_length, event->table,
event->new_database_length, event->new_database,
event->new_table_length, event->new_table);
",%.*s,%.*s|%.*s.%.*s,",event->database.length, event->database.str,
event->table.length, event->table.str,
event->new_database.length, event->new_database.str,
event->new_table.length, event->new_table.str);
message[csize]= '\n';
return write_log(message, csize + 1);
}
Expand Down Expand Up @@ -1832,7 +1832,7 @@ static void update_connection_info(struct connection_info *cn,
/* Change DB */
if (mysql_57_started)
get_str_n(cn->db, &cn->db_length, sizeof(cn->db),
event->database, event->database_length);
event->database.str, event->database.length);
else
get_str_n(cn->db, &cn->db_length, sizeof(cn->db),
event->general_query, event->general_query_length);
Expand All @@ -1858,9 +1858,9 @@ static void update_connection_info(struct connection_info *cn,
if (ci_needs_setup(cn))
setup_connection_query(cn, event);

if (mode == 0 && cn->db_length == 0 && event->database_length > 0)
if (mode == 0 && cn->db_length == 0 && event->database.length > 0)
get_str_n(cn->db, &cn->db_length, sizeof(cn->db),
event->database, event->database_length);
event->database.str, event->database.length);

if (event->general_error_code == 0)
{
Expand All @@ -1875,7 +1875,7 @@ static void update_connection_info(struct connection_info *cn,
event->general_query + 4, event->general_query_length - 4);
else
get_str_n(cn->db, &cn->db_length, sizeof(cn->db),
event->database, event->database_length);
event->database.str, event->database.length);
}
}
update_general_user(cn, event);
Expand Down Expand Up @@ -1916,9 +1916,9 @@ static void update_connection_info(struct connection_info *cn,
event->ip, SAFE_STRLEN(event->ip));
}

if (cn->db_length == 0 && event->database_length != 0)
if (cn->db_length == 0 && event->database.length != 0)
get_str_n(cn->db, &cn->db_length, sizeof(cn->db),
event->database, event->database_length);
event->database.str, event->database.length);

if (mode == 0)
cn->query_id= event->query_id;
Expand Down Expand Up @@ -2145,17 +2145,17 @@ static void auditing_v8(MYSQL_THD thd, struct mysql_event_general_v8 *ev_v8)
event.general_charset= ev_v8->general_charset;
event.general_time= ev_v8->general_time;
event.general_rows= ev_v8->general_rows;
event.database= 0;
event.database_length= 0;
event.database.str= 0;
event.database.length= 0;

if (event.general_query_length > 0)
{
event.event_subclass= MYSQL_AUDIT_GENERAL_STATUS;
event.general_command= "Query";
event.general_command_length= 5;
#ifdef __linux__
event.database= *(char **) (((char *) thd) + db_off);
event.database_length= *(size_t *) (((char *) thd) + db_len_off);
event.database.str= *(char **) (((char *) thd) + db_off);
event.database.length= *(size_t *) (((char *) thd) + db_len_off);
#endif /*__linux*/
}
#ifdef __linux__
Expand Down
25 changes: 12 additions & 13 deletions plugin/userstat/index_stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,26 @@ static int index_stats_fill(THD *thd, TABLE_LIST *tables, COND *cond)
INDEX_STATS *index_stats =
(INDEX_STATS*) my_hash_element(&global_index_stats, i);
TABLE_LIST tmp_table;
char *index_name;
size_t schema_name_length, table_name_length, index_name_length;
const char *index_name;
size_t index_name_length;

bzero((char*) &tmp_table,sizeof(tmp_table));
tmp_table.db= index_stats->index;
tmp_table.table_name= strend(index_stats->index)+1;
tmp_table.db.str= index_stats->index;
tmp_table.db.length= strlen(index_stats->index);
tmp_table.table_name.str= index_stats->index + tmp_table.db.length + 1;
tmp_table.table_name.length= strlen(tmp_table.table_name.str);
tmp_table.grant.privilege= 0;
if (check_access(thd, SELECT_ACL, tmp_table.db,
if (check_access(thd, SELECT_ACL, tmp_table.db.str,
&tmp_table.grant.privilege, NULL, 0, 1) ||
check_grant(thd, SELECT_ACL, &tmp_table, 1, UINT_MAX, 1))
continue;

index_name= strend(tmp_table.table_name)+1;
schema_name_length= (tmp_table.table_name - index_stats->index) -1;
table_name_length= (index_name - tmp_table.table_name)-1;
index_name_length= (index_stats->index_name_length - schema_name_length -
table_name_length - 3);
index_name= tmp_table.table_name.str + tmp_table.table_name.length + 1;
index_name_length= (index_stats->index_name_length - tmp_table.db.length -
tmp_table.table_name.length - 3);

table->field[0]->store(tmp_table.db, (uint)schema_name_length,
system_charset_info);
table->field[1]->store(tmp_table.table_name, (uint) table_name_length,
table->field[0]->store(tmp_table.db.str, tmp_table.db.length, system_charset_info);
table->field[1]->store(tmp_table.table_name.str, tmp_table.table_name.length,
system_charset_info);
table->field[2]->store(index_name, (uint) index_name_length, system_charset_info);
table->field[3]->store((longlong)index_stats->rows_read, TRUE);
Expand Down
Loading

0 comments on commit a7e352b

Please sign in to comment.