diff options
author | Monty <monty@mariadb.org> | 2018-01-07 18:03:44 +0200 |
---|---|---|
committer | Monty <monty@mariadb.org> | 2018-01-30 21:33:55 +0200 |
commit | a7e352b54ddfaf91c92951d605cb02a4ffd2676b (patch) | |
tree | dc76f140342938ed2a0fe0e005100402762d5308 /plugin | |
parent | 921c5e931452301a09c84c53ffe35b81e6a1c71a (diff) | |
download | mariadb-git-a7e352b54ddfaf91c92951d605cb02a4ffd2676b.tar.gz |
Changed database, tablename and alias to be LEX_CSTRING
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 "")
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/audit_null/audit_null.c | 4 | ||||
-rw-r--r-- | plugin/feedback/feedback.cc | 2 | ||||
-rw-r--r-- | plugin/feedback/sender_thread.cc | 11 | ||||
-rw-r--r-- | plugin/handler_socket/handlersocket/database.cpp | 11 | ||||
-rw-r--r-- | plugin/server_audit/server_audit.c | 38 | ||||
-rw-r--r-- | plugin/userstat/index_stats.cc | 25 | ||||
-rw-r--r-- | plugin/userstat/table_stats.cc | 8 |
7 files changed, 49 insertions, 50 deletions
diff --git a/plugin/audit_null/audit_null.c b/plugin/audit_null/audit_null.c index 2747063670c..0f4efc25ef3 100644 --- a/plugin/audit_null/audit_null.c +++ b/plugin/audit_null/audit_null.c @@ -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; @@ -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); } } diff --git a/plugin/feedback/feedback.cc b/plugin/feedback/feedback.cc index 8ed6ef64b0c..826a929643d 100644 --- a/plugin/feedback/feedback.cc +++ b/plugin/feedback/feedback.cc @@ -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; diff --git a/plugin/feedback/sender_thread.cc b/plugin/feedback/sender_thread.cc index bcd10f6713f..0463a70a383 100644 --- a/plugin/feedback/sender_thread.cc +++ b/plugin/feedback/sender_thread.cc @@ -105,8 +105,7 @@ 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; @@ -114,11 +113,9 @@ static int prepare_for_fill(TABLE_LIST *tables) 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) diff --git a/plugin/handler_socket/handlersocket/database.cpp b/plugin/handler_socket/handlersocket/database.cpp index b21d58d243b..a76428b29d3 100644 --- a/plugin/handler_socket/handlersocket/database.cpp +++ b/plugin/handler_socket/handlersocket/database.cpp @@ -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); @@ -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); diff --git a/plugin/server_audit/server_audit.c b/plugin/server_audit/server_audit.c index 6b0443344e9..38046de61f9 100644 --- a/plugin/server_audit/server_audit.c +++ b/plugin/server_audit/server_audit.c @@ -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), @@ -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), @@ -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); } @@ -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); } @@ -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); } @@ -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); @@ -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) { @@ -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); @@ -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; @@ -2145,8 +2145,8 @@ 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) { @@ -2154,8 +2154,8 @@ static void auditing_v8(MYSQL_THD thd, struct mysql_event_general_v8 *ev_v8) 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__ diff --git a/plugin/userstat/index_stats.cc b/plugin/userstat/index_stats.cc index 87e6da63e38..0528507c50e 100644 --- a/plugin/userstat/index_stats.cc +++ b/plugin/userstat/index_stats.cc @@ -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); diff --git a/plugin/userstat/table_stats.cc b/plugin/userstat/table_stats.cc index 7b522a388d7..3119e516e06 100644 --- a/plugin/userstat/table_stats.cc +++ b/plugin/userstat/table_stats.cc @@ -26,10 +26,12 @@ static int table_stats_fill(THD *thd, TABLE_LIST *tables, COND *cond) table_name_length= strlen(table_stats->table + schema_length + 1); bzero((char*) &tmp_table,sizeof(tmp_table)); - tmp_table.db= table_stats->table; - tmp_table.table_name= end_of_schema+1; + tmp_table.db.str= table_stats->table; + tmp_table.db.length= schema_length; + tmp_table.table_name.str= end_of_schema+1; + tmp_table.table_name.length= table_name_length; 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)) |