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 /sql | |
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 'sql')
115 files changed, 2165 insertions, 2201 deletions
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index a412a65ccc9..bb344f5a9ee 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -110,7 +110,7 @@ SET (SQL_SOURCE debug_sync.cc sql_repl.cc sql_select.cc sql_show.cc sql_state.c group_by_handler.cc - sql_statistics.cc sql_string.cc + sql_statistics.cc sql_string.cc lex_string.h sql_table.cc sql_test.cc sql_trigger.cc sql_udf.cc sql_union.cc sql_update.cc sql_view.cc strfunc.cc table.cc thr_malloc.cc sql_time.cc tztime.cc unireg.cc item_xmlfunc.cc diff --git a/sql/event_data_objects.cc b/sql/event_data_objects.cc index c85192ee258..3b89a94adc3 100644 --- a/sql/event_data_objects.cc +++ b/sql/event_data_objects.cc @@ -171,11 +171,11 @@ Event_creation_ctx::load_from_db(THD *thd, */ bool -Event_queue_element_for_exec::init(LEX_CSTRING db, LEX_CSTRING n) +Event_queue_element_for_exec::init(const LEX_CSTRING *db, const LEX_CSTRING *n) { - if (!(dbname.str= my_strndup(db.str, dbname.length= db.length, MYF(MY_WME)))) + if (!(dbname.str= my_strndup(db->str, dbname.length= db->length, MYF(MY_WME)))) return TRUE; - if (!(name.str= my_strndup(n.str, name.length= n.length, MYF(MY_WME)))) + if (!(name.str= my_strndup(n->str, name.length= n->length, MYF(MY_WME)))) { my_free(const_cast<char*>(dbname.str)); return TRUE; @@ -1196,7 +1196,7 @@ Event_timed::get_create_event(THD *thd, String *buf) buf->append(STRING_WITH_LEN("CREATE ")); append_definer(thd, buf, &definer_user, &definer_host); buf->append(STRING_WITH_LEN("EVENT ")); - append_identifier(thd, buf, name.str, name.length); + append_identifier(thd, buf, &name); if (expression) { @@ -1274,7 +1274,7 @@ Event_job_data::construct_sp_sql(THD *thd, String *sp_sql) We're using append_identifier here to successfully parse events with reserved names. */ - append_identifier(thd, sp_sql, name.str, name.length); + append_identifier(thd, sp_sql, &name); /* The default SQL security of a stored procedure is DEFINER. We @@ -1311,9 +1311,9 @@ Event_job_data::construct_drop_event_sql(THD *thd, String *sp_sql) sp_sql->length(0); sp_sql->append(C_STRING_WITH_LEN("DROP EVENT ")); - append_identifier(thd, sp_sql, dbname.str, dbname.length); + append_identifier(thd, sp_sql, &dbname); sp_sql->append('.'); - append_identifier(thd, sp_sql, name.str, name.length); + append_identifier(thd, sp_sql, &name); DBUG_RETURN(thd->is_fatal_error); } @@ -1355,7 +1355,7 @@ Event_job_data::execute(THD *thd, bool drop) mysql_change_db will be invoked anyway later, to activate the procedure database before it's executed. */ - thd->set_db(dbname.str, dbname.length); + thd->set_db(&dbname); lex_start(thd); diff --git a/sql/event_data_objects.h b/sql/event_data_objects.h index 884bbd7d701..8afed7df4c9 100644 --- a/sql/event_data_objects.h +++ b/sql/event_data_objects.h @@ -37,7 +37,7 @@ public: ~Event_queue_element_for_exec(); bool - init(LEX_CSTRING dbname, LEX_CSTRING name); + init(const LEX_CSTRING *dbname, const LEX_CSTRING *name); LEX_CSTRING dbname; LEX_CSTRING name; diff --git a/sql/event_db_repository.cc b/sql/event_db_repository.cc index 9d899cb637e..fad53d6dd7a 100644 --- a/sql/event_db_repository.cc +++ b/sql/event_db_repository.cc @@ -164,6 +164,8 @@ const TABLE_FIELD_TYPE event_table_fields[ET_FIELD_COUNT] = } }; +static LEX_CSTRING MYSQL_EVENT_NAME= { STRING_WITH_LEN("event") }; + static const TABLE_FIELD_DEF event_table_def= {ET_FIELD_COUNT, event_table_fields, 0, (uint*) 0}; @@ -538,7 +540,7 @@ Event_db_repository::fill_schema_events(THD *thd, TABLE_LIST *i_s_table, DBUG_ENTER("Event_db_repository::fill_schema_events"); DBUG_PRINT("info",("db=%s", db? db:"(null)")); - event_table.init_one_table("mysql", 5, "event", 5, "event", TL_READ); + event_table.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_EVENT_NAME, 0, TL_READ); if (open_system_tables_for_read(thd, &event_table, &open_tables_backup)) DBUG_RETURN(TRUE); @@ -600,7 +602,7 @@ Event_db_repository::open_event_table(THD *thd, enum thr_lock_type lock_type, TABLE_LIST tables; DBUG_ENTER("Event_db_repository::open_event_table"); - tables.init_one_table("mysql", 5, "event", 5, "event", lock_type); + tables.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_EVENT_NAME, 0, lock_type); if (open_and_lock_tables(thd, &tables, FALSE, MYSQL_LOCK_IGNORE_TIMEOUT)) DBUG_RETURN(TRUE); @@ -1066,7 +1068,7 @@ Event_db_repository::load_named_event(THD *thd, const LEX_CSTRING *dbname, DBUG_PRINT("enter",("thd: %p name: %*s", thd, (int) name->length, name->str)); - event_table.init_one_table("mysql", 5, "event", 5, "event", TL_READ); + event_table.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_EVENT_NAME, 0, TL_READ); /* Reset sql_mode during data dictionary operations. */ thd->variables.sql_mode= 0; @@ -1189,7 +1191,7 @@ Event_db_repository::check_system_tables(THD *thd) DBUG_PRINT("enter", ("thd: %p", thd)); /* Check mysql.db */ - tables.init_one_table("mysql", 5, "db", 2, "db", TL_READ); + tables.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_DB_NAME, 0, TL_READ); if (open_and_lock_tables(thd, &tables, FALSE, MYSQL_LOCK_IGNORE_TIMEOUT)) { @@ -1204,7 +1206,7 @@ Event_db_repository::check_system_tables(THD *thd) close_mysql_tables(thd); } /* Check mysql.user */ - tables.init_one_table("mysql", 5, "user", 4, "user", TL_READ); + tables.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_USER_NAME, 0, TL_READ); if (open_and_lock_tables(thd, &tables, FALSE, MYSQL_LOCK_IGNORE_TIMEOUT)) { @@ -1224,7 +1226,7 @@ Event_db_repository::check_system_tables(THD *thd) close_mysql_tables(thd); } /* Check mysql.event */ - tables.init_one_table("mysql", 5, "event", 5, "event", TL_READ); + tables.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_EVENT_NAME, 0, TL_READ); if (open_and_lock_tables(thd, &tables, FALSE, MYSQL_LOCK_IGNORE_TIMEOUT)) { diff --git a/sql/event_queue.cc b/sql/event_queue.cc index 9e30534dd14..7cc3e50f235 100644 --- a/sql/event_queue.cc +++ b/sql/event_queue.cc @@ -637,7 +637,7 @@ Event_queue::get_top_for_execution_if_time(THD *thd, } if (!(*event_name= new Event_queue_element_for_exec()) || - (*event_name)->init(top->dbname, top->name)) + (*event_name)->init(&top->dbname, &top->name)) { ret= TRUE; break; diff --git a/sql/events.cc b/sql/events.cc index 3ad546217a7..2fbb16861f6 100644 --- a/sql/events.cc +++ b/sql/events.cc @@ -826,12 +826,12 @@ Events::fill_schema_events(THD *thd, TABLE_LIST *tables, COND * /* cond */) */ if (thd->lex->sql_command == SQLCOM_SHOW_EVENTS) { - DBUG_ASSERT(thd->lex->select_lex.db); - if (!is_infoschema_db(thd->lex->select_lex.db) && // There is no events in I_S - check_access(thd, EVENT_ACL, thd->lex->select_lex.db, + DBUG_ASSERT(thd->lex->select_lex.db.str); + if (!is_infoschema_db(&thd->lex->select_lex.db) && // There is no events in I_S + check_access(thd, EVENT_ACL, thd->lex->select_lex.db.str, NULL, NULL, 0, 0)) DBUG_RETURN(1); - db= normalize_db_name(thd->lex->select_lex.db, db_tmp, sizeof(db_tmp)); + db= normalize_db_name(thd->lex->select_lex.db.str, db_tmp, sizeof(db_tmp)); } ret= db_repository->fill_schema_events(thd, tables, db); @@ -1252,7 +1252,7 @@ int wsrep_create_event_query(THD *thd, uchar** buf, size_t* buf_len) if (create_query_string(thd, &log_query)) { WSREP_WARN("events create string failed: schema: %s, query: %s", - (thd->db ? thd->db : "(null)"), thd->query()); + thd->get_db(), thd->query()); return 1; } return wsrep_to_buf_helper(thd, log_query.ptr(), log_query.length(), buf, buf_len); diff --git a/sql/field.cc b/sql/field.cc index 8ac7eeafd5c..82a75e98f46 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -2078,7 +2078,7 @@ bool Field_vers_trx_id::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate, ulonglo push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_VERS_NO_TRX_ID, ER_THD(thd, ER_VERS_NO_TRX_ID), - trx_id); + (longlong) trx_id); return true; } diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 87c056e7bae..b32bdd6c2bd 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -2567,7 +2567,7 @@ int ha_partition::set_up_table_before_create(TABLE *tbl, partition_element *part_elem) { int error= 0; - const char *partition_name; + LEX_CSTRING part_name; THD *thd= ha_thd(); DBUG_ENTER("set_up_table_before_create"); @@ -2577,15 +2577,16 @@ int ha_partition::set_up_table_before_create(TABLE *tbl, DBUG_RETURN(1); tbl->s->max_rows= part_elem->part_max_rows; tbl->s->min_rows= part_elem->part_min_rows; - partition_name= strrchr(partition_name_with_path, FN_LIBCHAR); + part_name.str= strrchr(partition_name_with_path, FN_LIBCHAR)+1; + part_name.length= strlen(part_name.str); if ((part_elem->index_file_name && (error= append_file_to_dir(thd, (const char**)&part_elem->index_file_name, - partition_name+1))) || + &part_name))) || (part_elem->data_file_name && (error= append_file_to_dir(thd, (const char**)&part_elem->data_file_name, - partition_name+1)))) + &part_name)))) { DBUG_RETURN(error); } @@ -10789,10 +10790,8 @@ int ha_partition::check_for_upgrade(HA_CHECK_OPT *check_opt) partition_info::enum_key_algorithm old_algorithm; old_algorithm= m_part_info->key_algorithm; error= HA_ADMIN_FAILED; - append_identifier(ha_thd(), &db_name, table_share->db.str, - table_share->db.length); - append_identifier(ha_thd(), &table_name, table_share->table_name.str, - table_share->table_name.length); + append_identifier(ha_thd(), &db_name, &table_share->db); + append_identifier(ha_thd(), &table_name, &table_share->table_name); if (m_part_info->key_algorithm != partition_info::KEY_ALGORITHM_NONE) { /* diff --git a/sql/handler.cc b/sql/handler.cc index 2218d27e9f9..f03e7848f3c 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -2501,7 +2501,7 @@ const char *get_canonical_filename(handler *file, const char *path, The .frm file will be deleted only if we return 0. */ int ha_delete_table(THD *thd, handlerton *table_type, const char *path, - const char *db, const char *alias, bool generate_warning) + const LEX_CSTRING *db, const LEX_CSTRING *alias, bool generate_warning) { handler *file; char tmp_path[FN_REFLEN]; @@ -2534,12 +2534,9 @@ int ha_delete_table(THD *thd, handlerton *table_type, const char *path, dummy_share.path.str= (char*) path; dummy_share.path.length= strlen(path); dummy_share.normalized_path= dummy_share.path; - dummy_share.db.str= (char*) db; - dummy_share.db.length= strlen(db); - dummy_share.table_name.str= (char*) alias; - dummy_share.table_name.length= strlen(alias); - dummy_table.alias.set(alias, dummy_share.table_name.length, - table_alias_charset); + dummy_share.db= *db; + dummy_share.table_name= *alias; + dummy_table.alias.set(alias->str, alias->length, table_alias_charset); file->change_table_ptr(&dummy_table, &dummy_share); file->print_error(error, MYF(intercept ? ME_JUST_WARNING : 0)); } @@ -4875,7 +4872,6 @@ int ha_create_table(THD *thd, const char *path, TABLE_SHARE share; bool temp_table __attribute__((unused)) = create_info->options & (HA_LEX_CREATE_TMP_TABLE | HA_CREATE_TMP_ALTER); - DBUG_ENTER("ha_create_table"); init_tmp_table_share(thd, &share, db, 0, table_name, path); @@ -4903,7 +4899,7 @@ int ha_create_table(THD *thd, const char *path, share.m_psi= PSI_CALL_get_table_share(temp_table, &share); - if (open_table_from_share(thd, &share, "", 0, READ_ALL, 0, &table, true)) + if (open_table_from_share(thd, &share, &empty_clex_str, 0, READ_ALL, 0, &table, true)) goto err; update_create_info_from_table(create_info, &table); @@ -5214,7 +5210,7 @@ private: *hton will be NULL. */ -bool ha_table_exists(THD *thd, const char *db, const char *table_name, +bool ha_table_exists(THD *thd, const LEX_CSTRING *db, const LEX_CSTRING *table_name, handlerton **hton, bool *is_sequence) { handlerton *dummy; @@ -5229,7 +5225,7 @@ bool ha_table_exists(THD *thd, const char *db, const char *table_name, is_sequence= &dummy2; *is_sequence= 0; - TDC_element *element= tdc_lock_share(thd, db, table_name); + TDC_element *element= tdc_lock_share(thd, db->str, table_name->str); if (element && element != MY_ERRPTR) { if (hton) @@ -5241,8 +5237,8 @@ bool ha_table_exists(THD *thd, const char *db, const char *table_name, char path[FN_REFLEN + 1]; size_t path_len = build_table_filename(path, sizeof(path) - 1, - db, table_name, "", 0); - st_discover_existence_args args= {path, path_len, db, table_name, 0, true}; + db->str, table_name->str, "", 0); + st_discover_existence_args args= {path, path_len, db->str, table_name->str, 0, true}; if (file_ext_exists(path, path_len, reg_ext)) { @@ -5285,14 +5281,12 @@ bool ha_table_exists(THD *thd, const char *db, const char *table_name, { TABLE_LIST table; uint flags = GTS_TABLE | GTS_VIEW; - if (!hton) flags|= GTS_NOLOCK; Table_exists_error_handler no_such_table_handler; thd->push_internal_handler(&no_such_table_handler); - table.init_one_table(db, strlen(db), table_name, strlen(table_name), - table_name, TL_READ); + table.init_one_table(db, table_name, 0, TL_READ); TABLE_SHARE *share= tdc_acquire_share(thd, &table, flags); thd->pop_internal_handler(); @@ -7000,7 +6994,8 @@ bool Table_scope_and_contents_source_st::vers_fix_system_fields( if (!(alter_info->flags & Alter_info::ALTER_ADD_SYSTEM_VERSIONING) && vers_info) { - my_error(ER_MISSING, MYF(0), create_table.table_name, "WITH SYSTEM VERSIONING"); + my_error(ER_MISSING, MYF(0), create_table.table_name.str, + "WITH SYSTEM VERSIONING"); return true; } @@ -7118,15 +7113,16 @@ bool Table_scope_and_contents_source_st::vers_fix_system_fields( vers_cols == 0 && (plain_cols == 0 || !vers_info)) { - my_error(ER_VERS_TABLE_MUST_HAVE_COLUMNS, MYF(0), create_table.table_name); + my_error(ER_VERS_TABLE_MUST_HAVE_COLUMNS, MYF(0), + create_table.table_name.str); return true; } - if (vers_info.check_with_conditions(create_table.table_name)) + if (vers_info.check_with_conditions(create_table.table_name.str)) return true; bool native= vers_native(thd); - if (vers_info.check_sys_fields(create_table.table_name, alter_info, native)) + if (vers_info.check_sys_fields(create_table.table_name.str, alter_info, native)) return true; return false; @@ -7188,7 +7184,8 @@ bool Vers_parse_info::fix_alter_info(THD *thd, Alter_info *alter_info, return true; } - if (alter_info->flags & Alter_info::ALTER_ADD_SYSTEM_VERSIONING && table->versioned()) + if (alter_info->flags & Alter_info::ALTER_ADD_SYSTEM_VERSIONING && + table->versioned()) { my_error(ER_VERS_ALREADY_VERSIONED, MYF(0), table_name); return true; @@ -7397,7 +7394,7 @@ Vers_parse_info::fix_create_like(Alter_info &alter_info, HA_CREATE_INFO &create_ push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR, "System versioning is stripped from temporary `%s.%s`", - table.db, table.table_name); + table.db.str, table.table_name.str); return false; } @@ -7419,8 +7416,8 @@ Vers_parse_info::fix_create_like(Alter_info &alter_info, HA_CREATE_INFO &create_ if (!f_start || !f_end) { - my_error(ER_MISSING, MYF(0), src_table.table_name, - f_start ? "AS ROW END" : "AS ROW START"); + my_error(ER_MISSING, MYF(0), src_table.table_name.str, + f_start ? "AS ROW END" : "AS ROW START"); return true; } @@ -7480,7 +7477,8 @@ bool Vers_parse_info::check_sys_fields(const char *table_name, if (sys_flag & found_flag) { my_error(ER_VERS_DUPLICATE_ROW_START_END, MYF(0), - found_flag & VERS_SYS_START_FLAG ? "START" : "END", f->field_name.str); + found_flag & VERS_SYS_START_FLAG ? "START" : "END", + f->field_name.str); return true; } @@ -7521,10 +7519,10 @@ bool Vers_parse_info::check_sys_fields(const char *table_name, } error: my_error(ER_VERS_FIELD_WRONG_TYPE, MYF(0), f->field_name.str, - found == VERS_TIMESTAMP ? - "TIMESTAMP(6)" : - "BIGINT(20) UNSIGNED", - table_name); + found == VERS_TIMESTAMP ? + "TIMESTAMP(6)" : + "BIGINT(20) UNSIGNED", + table_name); return true; } found= check_unit; @@ -7532,6 +7530,6 @@ bool Vers_parse_info::check_sys_fields(const char *table_name, } my_error(ER_MISSING, MYF(0), table_name, found_flag & VERS_SYS_START_FLAG ? - "ROW END" : found_flag ? "ROW START" : "ROW START/END"); + "ROW END" : found_flag ? "ROW START" : "ROW START/END"); return true; } diff --git a/sql/handler.h b/sql/handler.h index 713ffdd7e4e..8fe42ea210a 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -1813,9 +1813,9 @@ struct Table_scope_and_contents_source_st LEX_CUSTRING tabledef_version; LEX_CSTRING connect_string; LEX_CSTRING comment; + LEX_CSTRING alias; const char *password, *tablespace; const char *data_file_name, *index_file_name; - const char *alias; ulonglong max_rows,min_rows; ulonglong auto_increment_value; ulong table_options; ///< HA_OPTION_ values @@ -4684,7 +4684,7 @@ int ha_create_table(THD *thd, const char *path, const char *db, const char *table_name, HA_CREATE_INFO *create_info, LEX_CUSTRING *frm); int ha_delete_table(THD *thd, handlerton *db_type, const char *path, - const char *db, const char *alias, bool generate_warning); + const LEX_CSTRING *db, const LEX_CSTRING *alias, bool generate_warning); /* statistics and info */ bool ha_show_status(THD *thd, handlerton *db_type, enum ha_stat_type stat); @@ -4722,7 +4722,7 @@ public: int ha_discover_table(THD *thd, TABLE_SHARE *share); int ha_discover_table_names(THD *thd, LEX_CSTRING *db, MY_DIR *dirp, Discovered_table_list *result, bool reusable); -bool ha_table_exists(THD *thd, const char *db, const char *table_name, +bool ha_table_exists(THD *thd, const LEX_CSTRING *db, const LEX_CSTRING *table_name, handlerton **hton= 0, bool *is_sequence= 0); #endif @@ -4773,9 +4773,9 @@ const char *get_canonical_filename(handler *file, const char *path, bool mysql_xa_recover(THD *thd); void commit_checkpoint_notify_ha(handlerton *hton, void *cookie); -inline const char *table_case_name(HA_CREATE_INFO *info, const char *name) +inline const LEX_CSTRING *table_case_name(HA_CREATE_INFO *info, const LEX_CSTRING *name) { - return ((lower_case_table_names == 2 && info->alias) ? info->alias : name); + return ((lower_case_table_names == 2 && info->alias.str) ? &info->alias : name); } typedef bool Log_func(THD*, TABLE*, bool, const uchar*, const uchar*); diff --git a/sql/item.cc b/sql/item.cc index bcea8180e05..c38ebe7e029 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -616,7 +616,7 @@ void Item::print_item_w_name(String *str, enum_query_type query_type) DBUG_ASSERT(name.length == strlen(name.str)); THD *thd= current_thd; str->append(STRING_WITH_LEN(" AS ")); - append_identifier(thd, str, name.str, name.length); + append_identifier(thd, str, &name); } } @@ -762,10 +762,10 @@ Item_ident::Item_ident(THD *thd, Name_resolution_context *context_arg, Item_ident::Item_ident(THD *thd, TABLE_LIST *view_arg, const LEX_CSTRING *field_name_arg) :Item_result_field(thd), orig_db_name(NullS), - orig_table_name(view_arg->table_name), + orig_table_name(view_arg->table_name.str), orig_field_name(*field_name_arg), context(&view_arg->view->select_lex.context), - db_name(NullS), table_name(view_arg->alias), + db_name(NullS), table_name(view_arg->alias.str), field_name(*field_name_arg), alias_name_used(FALSE), cached_field_index(NO_CACHED_FIELD_INDEX), cached_table(NULL), depended_from(NULL), can_be_depended(TRUE) @@ -2770,10 +2770,10 @@ Item_sp::func_name(THD *thd) const qname.length(0); if (m_name->m_explicit_name) { - append_identifier(thd, &qname, m_name->m_db.str, m_name->m_db.length); + append_identifier(thd, &qname, &m_name->m_db); qname.append('.'); } - append_identifier(thd, &qname, m_name->m_name.str, m_name->m_name.length); + append_identifier(thd, &qname, &m_name->m_name); return qname.c_ptr_safe(); } @@ -3279,7 +3279,7 @@ void Item_ident::print(String *str, enum_query_type query_type) bool use_db_name= use_table_name && db_name && db_name[0] && !alias_name_used; if (use_db_name && (query_type & QT_ITEM_IDENT_SKIP_DB_NAMES)) - use_db_name= !thd->db || strcmp(thd->db, db_name); + use_db_name= !thd->db.str || strcmp(thd->db.str, db_name); if (use_db_name) use_db_name= !(cached_table && cached_table->belong_to_view && @@ -3336,7 +3336,7 @@ void Item_ident::print(String *str, enum_query_type query_type) append_identifier(thd, str, t_name, (uint) strlen(t_name)); str->append('.'); } - append_identifier(thd, str, field_name.str, field_name.length); + append_identifier(thd, str, &field_name); } /* ARGSUSED */ @@ -6047,8 +6047,7 @@ bool Item_field::fix_fields(THD *thd, Item **reference) if (select && select->in_tvc) { - my_error(ER_FIELD_REFERENCE_IN_TVC, MYF(0), - full_name(), thd->where); + my_error(ER_FIELD_REFERENCE_IN_TVC, MYF(0), full_name()); return(1); } @@ -8196,8 +8195,7 @@ void Item_ref::print(String *str, enum_query_type query_type) !table_name && name.str && alias_name_used) { THD *thd= current_thd; - append_identifier(thd, str, (*ref)->real_item()->name.str, - (*ref)->real_item()->name.length); + append_identifier(thd, str, &(*ref)->real_item()->name); } else (*ref)->print(str, query_type); diff --git a/sql/item_create.cc b/sql/item_create.cc index d73a5327d25..19a8f2b138e 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -3253,7 +3253,7 @@ Create_qfunc::create_func(THD *thd, LEX_CSTRING *name, List<Item> *item_list) { LEX_CSTRING db; - if (! thd->db && ! thd->lex->sphead) + if (! thd->db.str && ! thd->lex->sphead) { /* The proper error message should be in the lines of: @@ -3271,7 +3271,7 @@ Create_qfunc::create_func(THD *thd, LEX_CSTRING *name, List<Item> *item_list) return NULL; } - if (thd->lex->copy_db_to(&db.str, &db.length)) + if (thd->lex->copy_db_to(&db)) return NULL; return create_with_db(thd, &db, name, false, item_list); diff --git a/sql/item_func.cc b/sql/item_func.cc index 93ddddfde61..67846a90cf4 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -5439,7 +5439,7 @@ bool Item_func_get_user_var::const_item() const void Item_func_get_user_var::print(String *str, enum_query_type query_type) { str->append(STRING_WITH_LEN("@")); - append_identifier(current_thd, str, name.str, name.length); + append_identifier(current_thd, str, &name); } @@ -6410,8 +6410,8 @@ Item_func_sp::fix_fields(THD *thd, Item **ref) whether to return "Access denied" or "Routine does not exist". */ res= sp ? sp->check_execute_access(thd) : - check_routine_access(thd, EXECUTE_ACL, m_name->m_db.str, - m_name->m_name.str, + check_routine_access(thd, EXECUTE_ACL, &m_name->m_db, + &m_name->m_name, &sp_handler_function, false); thd->security_ctx= save_security_ctx; @@ -6629,7 +6629,7 @@ void Item_func_last_value::fix_length_and_dec() void Cursor_ref::print_func(String *str, const char *func_name) { - append_identifier(current_thd, str, m_cursor_name.str, m_cursor_name.length); + append_identifier(current_thd, str, &m_cursor_name); str->append(func_name); } @@ -6751,8 +6751,9 @@ longlong Item_func_nextval::val_int() void Item_func_nextval::print(String *str, enum_query_type query_type) { char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME]; - const char *d_name= table_list->db, *t_name= table_list->table_name; - bool use_db_name= d_name && d_name[0]; + LEX_CSTRING d_name= table_list->db; + LEX_CSTRING t_name= table_list->table_name; + bool use_db_name= d_name.str && d_name.str[0]; THD *thd= current_thd; // Don't trust 'table' str->append(func_name()); @@ -6765,23 +6766,23 @@ void Item_func_nextval::print(String *str, enum_query_type query_type) if (lower_case_table_names > 0) { - strmake(t_name_buff, t_name, MAX_ALIAS_NAME-1); - my_casedn_str(files_charset_info, t_name_buff); - t_name= t_name_buff; + strmake(t_name_buff, t_name.str, MAX_ALIAS_NAME-1); + t_name.length= my_casedn_str(files_charset_info, t_name_buff); + t_name.str= t_name_buff; if (use_db_name) { - strmake(d_name_buff, d_name, MAX_ALIAS_NAME-1); - my_casedn_str(files_charset_info, d_name_buff); - d_name= d_name_buff; + strmake(d_name_buff, d_name.str, MAX_ALIAS_NAME-1); + d_name.length= my_casedn_str(files_charset_info, d_name_buff); + d_name.str= d_name_buff; } } if (use_db_name) { - append_identifier(thd, str, d_name, (uint)strlen(d_name)); + append_identifier(thd, str, &d_name); str->append('.'); } - append_identifier(thd, str, t_name, (uint) strlen(t_name)); + append_identifier(thd, str, &t_name); str->append(')'); } @@ -6874,8 +6875,9 @@ longlong Item_func_setval::val_int() void Item_func_setval::print(String *str, enum_query_type query_type) { char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME]; - const char *d_name= table_list->db, *t_name= table_list->table_name; - bool use_db_name= d_name && d_name[0]; + LEX_CSTRING d_name= table_list->db; + LEX_CSTRING t_name= table_list->table_name; + bool use_db_name= d_name.str && d_name.str[0]; THD *thd= current_thd; // Don't trust 'table' str->append(func_name()); @@ -6888,23 +6890,23 @@ void Item_func_setval::print(String *str, enum_query_type query_type) if (lower_case_table_names > 0) { - strmake(t_name_buff, t_name, MAX_ALIAS_NAME-1); - my_casedn_str(files_charset_info, t_name_buff); - t_name= t_name_buff; + strmake(t_name_buff, t_name.str, MAX_ALIAS_NAME-1); + t_name.length= my_casedn_str(files_charset_info, t_name_buff); + t_name.str= t_name_buff; if (use_db_name) { - strmake(d_name_buff, d_name, MAX_ALIAS_NAME-1); - my_casedn_str(files_charset_info, d_name_buff); - d_name= d_name_buff; + strmake(d_name_buff, d_name.str, MAX_ALIAS_NAME-1); + d_name.length= my_casedn_str(files_charset_info, d_name_buff); + d_name.str= d_name_buff; } } if (use_db_name) { - append_identifier(thd, str, d_name, (uint)strlen(d_name)); + append_identifier(thd, str, &d_name); str->append('.'); } - append_identifier(thd, str, t_name, (uint) strlen(t_name)); + append_identifier(thd, str, &t_name); str->append(','); str->append_longlong(nextval); str->append(','); diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 483a6468c2e..0969af6a267 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -2383,13 +2383,13 @@ String *Item_func_database::val_str(String *str) { DBUG_ASSERT(fixed == 1); THD *thd= current_thd; - if (thd->db == NULL) + if (thd->db.str == NULL) { null_value= 1; return 0; } else - str->copy(thd->db, thd->db_length, system_charset_info); + str->copy(thd->db.str, thd->db.length, system_charset_info); null_value= 0; return str; } diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 6c023ef6640..354fd4cbf1a 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -4937,11 +4937,10 @@ bool subselect_hash_sj_engine::init(List<Item> *tmp_columns, uint subquery_id) DBUG_RETURN(TRUE); char buf[32]; - uint len= my_snprintf(buf, sizeof(buf), "<subquery%u>", subquery_id); - char *name; - if (!(name= (char*)thd->alloc(len + 1))) + LEX_CSTRING name; + name.length= my_snprintf(buf, sizeof(buf), "<subquery%u>", subquery_id); + if (!(name.str= (char*) thd->memdup(buf, name.length + 1))) DBUG_RETURN(TRUE); - memcpy(name, buf, len+1); result_sink->get_tmp_table_param()->materialized_subquery= true; if (item->substype() == Item_subselect::IN_SUBS && @@ -4951,7 +4950,7 @@ bool subselect_hash_sj_engine::init(List<Item> *tmp_columns, uint subquery_id) } if (result_sink->create_result_table(thd, tmp_columns, TRUE, tmp_create_options, - name, TRUE, TRUE, FALSE, 0)) + &name, TRUE, TRUE, FALSE, 0)) DBUG_RETURN(TRUE); tmp_table= result_sink->table; @@ -5037,7 +5036,7 @@ bool subselect_hash_sj_engine::make_semi_join_conds() /* Name resolution context for all tmp_table columns created below. */ Name_resolution_context *context; Item_in_subselect *item_in= (Item_in_subselect *) item; - + LEX_CSTRING table_name; DBUG_ENTER("subselect_hash_sj_engine::make_semi_join_conds"); DBUG_ASSERT(semi_join_conds == NULL); @@ -5047,10 +5046,9 @@ bool subselect_hash_sj_engine::make_semi_join_conds() if (!(tmp_table_ref= (TABLE_LIST*) thd->alloc(sizeof(TABLE_LIST)))) DBUG_RETURN(TRUE); - tmp_table_ref->init_one_table(STRING_WITH_LEN(""), - tmp_table->alias.c_ptr(), - tmp_table->alias.length(), - NULL, TL_READ); + table_name.str= tmp_table->alias.c_ptr(); + table_name.length= tmp_table->alias.length(), + tmp_table_ref->init_one_table(&empty_clex_str, &table_name, NULL, TL_READ); tmp_table_ref->table= tmp_table; context= new Name_resolution_context; diff --git a/sql/item_sum.cc b/sql/item_sum.cc index be9aefa7338..692d6bf9697 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -794,7 +794,7 @@ bool Aggregator_distinct::setup(THD *thd) if (!(table= create_tmp_table(thd, tmp_table_param, list, (ORDER*) 0, 1, 0, (select_lex->options | thd->variables.option_bits), - HA_POS_ERROR, const_cast<char*>("")))) + HA_POS_ERROR, &empty_clex_str))) return TRUE; table->file->extra(HA_EXTRA_NO_ROWS); // Don't update rows table->no_rows=1; @@ -4026,7 +4026,7 @@ bool Item_func_group_concat::setup(THD *thd) (ORDER*) 0, 0, TRUE, (select_lex->options | thd->variables.option_bits), - HA_POS_ERROR, (char*) ""))) + HA_POS_ERROR, &empty_clex_str))) DBUG_RETURN(TRUE); table->file->extra(HA_EXTRA_NO_ROWS); table->no_rows= 1; diff --git a/sql/item_vers.cc b/sql/item_vers.cc index 8aa1321e396..32a6c67f2fe 100644 --- a/sql/item_vers.cc +++ b/sql/item_vers.cc @@ -63,7 +63,7 @@ Item_func_vtq_ts::get_date(MYSQL_TIME *res, ulonglong fuzzy_date) null_value= !trt.query(trx_id); if (null_value) { - my_error(ER_VERS_NO_TRX_ID, MYF(0), trx_id); + my_error(ER_VERS_NO_TRX_ID, MYF(0), (longlong) trx_id); return true; } diff --git a/sql/lex_string.h b/sql/lex_string.h new file mode 100644 index 00000000000..9df84f67b6a --- /dev/null +++ b/sql/lex_string.h @@ -0,0 +1,52 @@ +/* + Copyright (c) 2018, MariaDB Corporation. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + + +#ifndef LEX_STRING_INCLUDED +#define LEX_STRING_INCLUDED + +typedef struct st_mysql_const_lex_string LEX_CSTRING; + +/* Functions to compare if two lex strings are equal */ +inline bool lex_string_cmp(CHARSET_INFO *charset, + const LEX_CSTRING *a, + const LEX_CSTRING *b) +{ + return my_strcasecmp(charset, a->str, b->str); +} + +/* + Compare to LEX_CSTRING's and return 0 if equal +*/ +inline bool cmp(const LEX_CSTRING *a, const LEX_CSTRING *b) +{ + return (a->length != b->length || + memcmp(a->str, b->str, a->length)); +} + +/* + Compare if two LEX_CSTRING are equal. Assumption is that + character set is ASCII (like for plugin names) +*/ +inline bool lex_string_eq(const LEX_CSTRING *a, + const LEX_CSTRING *b) +{ + if (a->length != b->length) + return 1; /* Different */ + return strcasecmp(a->str, b->str) != 0; +} + +#endif /* LEX_STRING_INCLUDED */ diff --git a/sql/lock.cc b/sql/lock.cc index 11cadb528d2..864e9f76293 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -1093,8 +1093,8 @@ void Global_read_lock::unlock_global_read_lock(THD *thd) int ret = wsrep->resync(wsrep); if (ret != WSREP_OK) { - WSREP_WARN("resync failed %d for FTWRL: db: %s, query: %s", ret, - (thd->db ? thd->db : "(null)"), thd->query()); + WSREP_WARN("resync failed %d for FTWRL: db: %s, query: %s", + ret, thd->get_db(), thd->query()); DBUG_VOID_RETURN; } } @@ -1180,7 +1180,7 @@ bool Global_read_lock::make_global_read_lock_block_commit(THD *thd) if (rcode != WSREP_OK) { WSREP_WARN("FTWRL desync failed %d for schema: %s, query: %s", - rcode, (thd->db ? thd->db : "(null)"), thd->query()); + rcode, thd->get_db(), thd->query()); my_message(ER_LOCK_DEADLOCK, "wsrep desync failed for FTWRL", MYF(0)); DBUG_RETURN(TRUE); } diff --git a/sql/log.cc b/sql/log.cc index 742b0a03e90..4521f5bc04e 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -608,19 +608,19 @@ int check_if_log_table(const TABLE_LIST *table, const char *error_msg) { int result= 0; - if (table->db_length == 5 && - !my_strcasecmp(table_alias_charset, table->db, "mysql")) + if (table->db.length == 5 && + !my_strcasecmp(table_alias_charset, table->db.str, "mysql")) { - const char *table_name= table->table_name; + const char *table_name= table->table_name.str; - if (table->table_name_length == 11 && + if (table->table_name.length == 11 && !my_strcasecmp(table_alias_charset, table_name, "general_log")) { result= QUERY_LOG_GENERAL; goto end; } - if (table->table_name_length == 8 && + if (table->table_name.length == 8 && !my_strcasecmp(table_alias_charset, table_name, "slow_log")) { result= QUERY_LOG_SLOW; @@ -716,9 +716,7 @@ bool Log_to_csv_event_handler:: save_thd_options= thd->variables.option_bits; thd->variables.option_bits&= ~OPTION_BIN_LOG; - table_list.init_one_table(MYSQL_SCHEMA_NAME.str, MYSQL_SCHEMA_NAME.length, - GENERAL_LOG_NAME.str, GENERAL_LOG_NAME.length, - GENERAL_LOG_NAME.str, + table_list.init_one_table(&MYSQL_SCHEMA_NAME, &GENERAL_LOG_NAME, 0, TL_WRITE_CONCURRENT_INSERT); /* @@ -881,9 +879,7 @@ bool Log_to_csv_event_handler:: */ save_time_zone_used= thd->time_zone_used; - table_list.init_one_table(MYSQL_SCHEMA_NAME.str, MYSQL_SCHEMA_NAME.length, - SLOW_LOG_NAME.str, SLOW_LOG_NAME.length, - SLOW_LOG_NAME.str, + table_list.init_one_table(&MYSQL_SCHEMA_NAME, &SLOW_LOG_NAME, 0, TL_WRITE_CONCURRENT_INSERT); if (!(table= open_log_table(thd, &table_list, &open_tables_backup))) @@ -937,9 +933,9 @@ bool Log_to_csv_event_handler:: goto err; /* fill database field */ - if (thd->db) + if (thd->db.str) { - if (table->field[6]->store(thd->db, thd->db_length, client_cs)) + if (table->field[6]->store(thd->db.str, thd->db.length, client_cs)) goto err; table->field[6]->set_notnull(); } @@ -1035,9 +1031,7 @@ int Log_to_csv_event_handler:: log_name= &SLOW_LOG_NAME; } - table_list.init_one_table(MYSQL_SCHEMA_NAME.str, MYSQL_SCHEMA_NAME.length, - log_name->str, log_name->length, log_name->str, - TL_WRITE_CONCURRENT_INSERT); + table_list.init_one_table(&MYSQL_SCHEMA_NAME, log_name, 0, TL_WRITE_CONCURRENT_INSERT); table= open_log_table(thd, &table_list, &open_tables_backup); if (table) @@ -2263,8 +2257,7 @@ static int binlog_savepoint_set(handlerton *hton, THD *thd, void *sv) String log_query(buf, sizeof(buf), &my_charset_bin); if (log_query.copy(STRING_WITH_LEN("SAVEPOINT "), &my_charset_bin) || - append_identifier(thd, &log_query, - thd->lex->ident.str, thd->lex->ident.length)) + append_identifier(thd, &log_query, &thd->lex->ident)) DBUG_RETURN(1); int errcode= query_error_code(thd, thd->killed == NOT_KILLED); Query_log_event qinfo(thd, log_query.c_ptr_safe(), log_query.length(), @@ -2306,8 +2299,7 @@ static int binlog_savepoint_rollback(handlerton *hton, THD *thd, void *sv) char buf[1024]; String log_query(buf, sizeof(buf), &my_charset_bin); if (log_query.copy(STRING_WITH_LEN("ROLLBACK TO "), &my_charset_bin) || - append_identifier(thd, &log_query, - thd->lex->ident.str, thd->lex->ident.length)) + append_identifier(thd, &log_query, &thd->lex->ident)) DBUG_RETURN(1); int errcode= query_error_code(thd, thd->killed == NOT_KILLED); Query_log_event qinfo(thd, log_query.ptr(), log_query.length(), @@ -3029,7 +3021,7 @@ bool MYSQL_QUERY_LOG::write(THD *thd, time_t current_time, "# Thread_id: %lu Schema: %s QC_hit: %s\n" "# Query_time: %s Lock_time: %s Rows_sent: %lu Rows_examined: %lu\n" "# Rows_affected: %lu Bytes_sent: %lu\n", - (ulong) thd->thread_id, (thd->db ? thd->db : ""), + (ulong) thd->thread_id, thd->get_db(), ((thd->query_plan_flags & QPLAN_QC) ? "Yes" : "No"), query_time_buff, lock_time_buff, (ulong) thd->get_sent_row_count(), @@ -3085,11 +3077,11 @@ bool MYSQL_QUERY_LOG::write(THD *thd, time_t current_time, goto err; thd->free_items(); } - if (thd->db && strcmp(thd->db, db)) + if (thd->db.str && strcmp(thd->db.str, db)) { // Database changed - if (my_b_printf(&log_file,"use %s;\n",thd->db)) + if (my_b_printf(&log_file,"use %s;\n",thd->db.str)) goto err; - strmov(db,thd->db); + strmov(db,thd->db.str); } if (thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt) { diff --git a/sql/log_event.cc b/sql/log_event.cc index b959b804dea..edfe0197f30 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -4271,7 +4271,7 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg, (suppress_use ? LOG_EVENT_SUPPRESS_USE_F : 0), using_trans), data_buf(0), query(query_arg), catalog(thd_arg->catalog), - db(thd_arg->db), q_len((uint32) query_length), + db(thd_arg->db.str), q_len((uint32) query_length), thread_id(thd_arg->thread_id), /* save the original thread id; we already know the server id */ slave_proxy_id((ulong)thd_arg->variables.pseudo_thread_id), @@ -5353,7 +5353,7 @@ bool test_if_equal_repl_errors(int expected_error, int actual_error) int Query_log_event::do_apply_event(rpl_group_info *rgi, const char *query_arg, uint32 q_len_arg) { - LEX_STRING new_db; + LEX_CSTRING new_db; int expected_error,actual_error= 0; Schema_specification_st db_options; uint64 sub_id= 0; @@ -5374,12 +5374,12 @@ int Query_log_event::do_apply_event(rpl_group_info *rgi, thd->catalog= catalog_len ? (char *) catalog : (char *)""; new_db.length= db_len; new_db.str= (char *) rpl_filter->get_rewrite_db(db, &new_db.length); - thd->set_db(new_db.str, new_db.length); /* allocates a copy of 'db' */ + thd->set_db(&new_db); /* allocates a copy of 'db' */ /* Setting the character set and collation of the current database thd->db. */ - load_db_opt_by_name(thd, thd->db, &db_options); + load_db_opt_by_name(thd, thd->db.str, &db_options); if (db_options.default_table_charset) thd->db_charset= db_options.default_table_charset; thd->variables.auto_increment_increment= auto_increment_increment; @@ -5403,7 +5403,7 @@ int Query_log_event::do_apply_event(rpl_group_info *rgi, ::do_apply_event(), then the companion SET also have so we don't need to reset_one_shot_variables(). */ - if (is_trans_keyword() || rpl_filter->db_ok(thd->db)) + if (is_trans_keyword() || rpl_filter->db_ok(thd->db.str)) { thd->set_time(when, when_sec_part); thd->set_query_and_id((char*)query_arg, q_len_arg, @@ -5571,7 +5571,7 @@ int Query_log_event::do_apply_event(rpl_group_info *rgi, DBUG_ASSERT(thd->m_statement_psi == NULL); thd->m_statement_psi= MYSQL_START_STATEMENT(&thd->m_statement_state, stmt_info_rpl.m_key, - thd->db, thd->db_length, + thd->db.str, thd->db.length, thd->charset()); THD_STAGE_INFO(thd, stage_init); MYSQL_SET_STATEMENT_TEXT(thd->m_statement_psi, thd->query(), thd->query_length()); @@ -5705,7 +5705,7 @@ compare_errors: "Error '%s' on query. Default database: '%s'. Query: '%s'", (actual_error ? thd->get_stmt_da()->message() : "unexpected success or fatal error"), - print_slave_db_safe(thd->db), query_arg); + thd->get_db(), query_arg); thd->is_slave_error= 1; } @@ -5762,7 +5762,7 @@ end: TABLE uses the db.table syntax. */ thd->catalog= 0; - thd->set_db(NULL, 0); /* will free the current database */ + thd->set_db(&null_clex_str); /* will free the current database */ thd->reset_query(); DBUG_PRINT("info", ("end: query= 0")); @@ -7193,14 +7193,14 @@ void Load_log_event::set_fields(const char* affected_db, int Load_log_event::do_apply_event(NET* net, rpl_group_info *rgi, bool use_rli_only_for_errors) { - LEX_STRING new_db; + LEX_CSTRING new_db; Relay_log_info const *rli= rgi->rli; Rpl_filter *rpl_filter= rli->mi->rpl_filter; DBUG_ENTER("Load_log_event::do_apply_event"); new_db.length= db_len; - new_db.str= (char *) rpl_filter->get_rewrite_db(db, &new_db.length); - thd->set_db(new_db.str, new_db.length); + new_db.str= rpl_filter->get_rewrite_db(db, &new_db.length); + thd->set_db(&new_db); DBUG_ASSERT(thd->query() == 0); thd->clear_error(1); @@ -7237,21 +7237,20 @@ int Load_log_event::do_apply_event(NET* net, rpl_group_info *rgi, ::do_apply_event(), then the companion SET also have so we don't need to reset_one_shot_variables(). */ - if (rpl_filter->db_ok(thd->db)) + if (rpl_filter->db_ok(thd->db.str)) { thd->set_time(when, when_sec_part); thd->set_query_id(next_query_id()); thd->get_stmt_da()->opt_clear_warning_info(thd->query_id); TABLE_LIST tables; - tables.init_one_table(thd->strmake(thd->db, thd->db_length), - thd->db_length, - table_name, strlen(table_name), - table_name, TL_WRITE); + LEX_CSTRING db_name= { thd->strmake(thd->db.str, thd->db.length), thd->db.length }; + LEX_CSTRING tbl_name= { table_name, strlen(table_name) }; + tables.init_one_table(&db_name, &tbl_name, 0, TL_WRITE); tables.updating= 1; // the table will be opened in mysql_load - if (rpl_filter->is_on() && !rpl_filter->tables_ok(thd->db, &tables)) + if (rpl_filter->is_on() && !rpl_filter->tables_ok(thd->db.str, &tables)) { // TODO: this is a bug - this needs to be moved to the I/O thread if (net) @@ -7337,7 +7336,7 @@ int Load_log_event::do_apply_event(NET* net, rpl_group_info *rgi, ex.skip_lines = skip_lines; List<Item> field_list; thd->lex->select_lex.context.resolve_in_table_list_only(&tables); - set_fields(tables.db, field_list, &thd->lex->select_lex.context); + set_fields(tables.db.str, field_list, &thd->lex->select_lex.context); thd->variables.pseudo_thread_id= thread_id; if (net) { @@ -7363,7 +7362,7 @@ int Load_log_event::do_apply_event(NET* net, rpl_group_info *rgi, "warning(s). Default database: '%s'", (char*) table_name, log_pos, RPL_LOG_NAME, (ulong) thd->cuted_fields, - print_slave_db_safe(thd->db)); + thd->get_db()); } if (net) net->pkt_nr= thd->net.pkt_nr; @@ -7382,9 +7381,9 @@ int Load_log_event::do_apply_event(NET* net, rpl_group_info *rgi, error: thd->net.vio = 0; - const char *remember_db= thd->db; + const char *remember_db= thd->get_db(); thd->catalog= 0; - thd->set_db(NULL, 0); /* will free the current database */ + thd->set_db(&null_clex_str); /* will free the current database */ thd->reset_query(); thd->get_stmt_da()->set_overwrite_status(true); thd->is_error() ? trans_rollback_stmt(thd) : trans_commit_stmt(thd); @@ -7433,7 +7432,7 @@ error: } rli->report(ERROR_LEVEL, sql_errno, rgi->gtid_info(), "\ Error '%s' running LOAD DATA INFILE on table '%s'. Default database: '%s'", - err, (char*)table_name, print_slave_db_safe(remember_db)); + err, (char*)table_name, remember_db); free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC)); DBUG_RETURN(1); } @@ -7446,7 +7445,7 @@ Error '%s' running LOAD DATA INFILE on table '%s'. Default database: '%s'", "Running LOAD DATA INFILE on table '%-.64s'." " Default database: '%-.64s'", (char*)table_name, - print_slave_db_safe(remember_db)); + remember_db); rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, rgi->gtid_info(), ER_THD(thd, ER_SLAVE_FATAL_ERROR), buf); @@ -12435,7 +12434,7 @@ check_table_map(rpl_group_info *rgi, RPL_TABLE_LIST *table_list) Relay_log_info *rli= rgi->rli; if ((rgi->thd->slave_thread /* filtering is for slave only */ || IF_WSREP((WSREP(rgi->thd) && rgi->thd->wsrep_applier), 0)) && - (!rli->mi->rpl_filter->db_ok(table_list->db) || + (!rli->mi->rpl_filter->db_ok(table_list->db.str) || (rli->mi->rpl_filter->is_on() && !rli->mi->rpl_filter->tables_ok("", table_list)))) res= FILTERED_OUT; else @@ -12447,8 +12446,8 @@ check_table_map(rpl_group_info *rgi, RPL_TABLE_LIST *table_list) if (ptr->table_id == table_list->table_id) { - if (strcmp(ptr->db, table_list->db) || - strcmp(ptr->alias, table_list->table_name) || + if (cmp(&ptr->db, &table_list->db) || + cmp(&ptr->alias, &table_list->table_name) || ptr->lock_type != TL_WRITE) // the ::do_apply_event always sets TL_WRITE res= SAME_ID_MAPPING_DIFFERENT_TABLE; else @@ -12468,7 +12467,7 @@ int Table_map_log_event::do_apply_event(rpl_group_info *rgi) { RPL_TABLE_LIST *table_list; char *db_mem, *tname_mem; - size_t dummy_len; + size_t dummy_len, db_mem_length, tname_mem_length; void *memory; Rpl_filter *filter; Relay_log_info const *rli= rgi->rli; @@ -12486,19 +12485,20 @@ int Table_map_log_event::do_apply_event(rpl_group_info *rgi) /* call from mysql_client_binlog_statement() will not set rli->mi */ filter= rgi->thd->slave_thread ? rli->mi->rpl_filter : global_rpl_filter; - strmov(db_mem, filter->get_rewrite_db(m_dbnam, &dummy_len)); - strmov(tname_mem, m_tblnam); + db_mem_length= strmov(db_mem, filter->get_rewrite_db(m_dbnam, &dummy_len))- db_mem; + tname_mem_length= strmov(tname_mem, m_tblnam)- tname_mem; - table_list->init_one_table(db_mem, strlen(db_mem), - tname_mem, strlen(tname_mem), - tname_mem, TL_WRITE); + LEX_CSTRING tmp_db_name= {db_mem, db_mem_length }; + LEX_CSTRING tmp_tbl_name= {tname_mem, tname_mem_length }; + table_list->init_one_table(&tmp_db_name, &tmp_tbl_name, 0, TL_WRITE); table_list->table_id= DBUG_EVALUATE_IF("inject_tblmap_same_id_maps_diff_table", 0, m_table_id); table_list->updating= 1; table_list->required_type= TABLE_TYPE_NORMAL; - DBUG_PRINT("debug", ("table: %s is mapped to %u", table_list->table_name, - table_list->table_id)); + DBUG_PRINT("debug", ("table: %s is mapped to %u", + table_list->table_name.str, + table_list->table_id)); table_list->master_had_triggers= ((m_flags & TM_BIT_HAS_TRIGGERS_F) ? 1 : 0); DBUG_PRINT("debug", ("table->master_had_triggers=%d", (int)table_list->master_had_triggers)); @@ -13497,7 +13497,7 @@ void issue_long_find_row_warning(Log_event_type type, sql_print_information("The slave is applying a ROW event on behalf of a%s statement " "on table %s and is currently taking a considerable amount " - "of time (%ld seconds). This is due to the fact that it is %s " + "of time (%lld seconds). This is due to the fact that it is %s " "while looking up records to be processed. Consider adding a " "primary key (or unique key) to the table to improve " "performance.", evt_type, table_name, delta, scan_type); diff --git a/sql/log_event.h b/sql/log_event.h index 700301a7f34..ddb1163d56a 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -1253,7 +1253,7 @@ public: #endif /* HAVE_REPLICATION */ virtual const char* get_db() { - return thd ? thd->db : 0; + return thd ? thd->db.str : 0; } #else Log_event() : temp_buf(0), when(0), flags(0) {} diff --git a/sql/mysqld.cc b/sql/mysqld.cc index e870f7afec6..1e23d3eba61 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -1246,7 +1246,7 @@ void net_after_header_psi(struct st_net *net, void *user_data, { thd->m_statement_psi= MYSQL_START_STATEMENT(&thd->m_statement_state, stmt_info_new_packet.m_key, - thd->db, thd->db_length, + thd->get_db(), thd->db.length, thd->charset()); THD_STAGE_INFO(thd, stage_init); diff --git a/sql/mysqld.h b/sql/mysqld.h index 6114c77af6f..3387ae7c458 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -37,7 +37,6 @@ class Time_zone; struct scheduler_functions; -typedef struct st_mysql_const_lex_string LEX_CSTRING; typedef struct st_mysql_show_var SHOW_VAR; #if MAX_INDEXES <= 64 diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index de8fb0fd8b5..8adc685df35 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -1497,6 +1497,7 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred) { TABLE_LIST *outer_tbl= subq_pred->emb_on_expr_nest; TABLE_LIST *wrap_nest; + LEX_CSTRING sj_wrap_name= { STRING_WITH_LEN("(sj-wrap)") }; /* We're dealing with @@ -1522,7 +1523,7 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred) } wrap_nest->embedding= outer_tbl->embedding; wrap_nest->join_list= outer_tbl->join_list; - wrap_nest->alias= (char*) "(sj-wrap)"; + wrap_nest->alias= sj_wrap_name; wrap_nest->nested_join->join_list.empty(); wrap_nest->nested_join->join_list.push_back(outer_tbl, thd->mem_root); @@ -1561,6 +1562,7 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred) TABLE_LIST *sj_nest; NESTED_JOIN *nested_join; + LEX_CSTRING sj_nest_name= { STRING_WITH_LEN("(sj-nest)") }; if (!(sj_nest= alloc_join_nest(thd))) { DBUG_RETURN(TRUE); @@ -1569,7 +1571,7 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred) sj_nest->join_list= emb_join_list; sj_nest->embedding= emb_tbl_nest; - sj_nest->alias= (char*) "(sj-nest)"; + sj_nest->alias= sj_nest_name; sj_nest->sj_subq_pred= subq_pred; sj_nest->original_subq_pred_used_tables= subq_pred->used_tables() | subq_pred->left_expr->used_tables(); @@ -1842,13 +1844,15 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred) const int SUBQERY_TEMPTABLE_NAME_MAX_LEN= 20; -static void create_subquery_temptable_name(char *to, uint number) +static void create_subquery_temptable_name(LEX_STRING *str, uint number) { + char *to= str->str; DBUG_ASSERT(number < 10000); to= strmov(to, "<subquery"); to= int10_to_str((int) number, to, 10); to[0]= '>'; to[1]= 0; + str->length= (size_t) (to - str->str)+1; } @@ -1876,7 +1880,7 @@ static bool convert_subq_to_jtbm(JOIN *parent_join, TABLE_LIST *tl; bool optimization_delayed= TRUE; TABLE_LIST *jtbm; - char *tbl_alias; + LEX_STRING tbl_alias; THD *thd= parent_join->thd; DBUG_ENTER("convert_subq_to_jtbm"); @@ -1885,7 +1889,7 @@ static bool convert_subq_to_jtbm(JOIN *parent_join, *remove_item= TRUE; - if (!(tbl_alias= (char*)thd->calloc(SUBQERY_TEMPTABLE_NAME_MAX_LEN)) || + if (!(tbl_alias.str= (char*)thd->calloc(SUBQERY_TEMPTABLE_NAME_MAX_LEN)) || !(jtbm= alloc_join_nest(thd))) //todo: this is not a join nest! { DBUG_RETURN(TRUE); @@ -1925,9 +1929,10 @@ static bool convert_subq_to_jtbm(JOIN *parent_join, jtbm->jtbm_table_no= parent_join->table_count; - create_subquery_temptable_name(tbl_alias, + create_subquery_temptable_name(&tbl_alias, subq_pred->unit->first_select()->select_number); - jtbm->alias= tbl_alias; + jtbm->alias.str= tbl_alias.str; + jtbm->alias.length= tbl_alias.length; parent_join->table_count++; DBUG_RETURN(thd->is_fatal_error); } @@ -1947,9 +1952,10 @@ static bool convert_subq_to_jtbm(JOIN *parent_join, DBUG_EXECUTE("where", print_where(conds,"SJ-EXPR", QT_ORDINARY);); - create_subquery_temptable_name(tbl_alias, hash_sj_engine->materialize_join-> + create_subquery_temptable_name(&tbl_alias, hash_sj_engine->materialize_join-> select_lex->select_number); - jtbm->alias= tbl_alias; + jtbm->alias.str= tbl_alias.str; + jtbm->alias.length= tbl_alias.length; parent_lex->have_merged_subqueries= TRUE; @@ -3705,6 +3711,7 @@ bool setup_sj_materialization_part1(JOIN_TAB *sjm_tab) sjm->sjm_table_param.init(); sjm->sjm_table_param.bit_fields_as_long= TRUE; SELECT_LEX *subq_select= emb_sj_nest->sj_subq_pred->unit->first_select(); + const LEX_CSTRING sj_materialize_name= { STRING_WITH_LEN("sj-materialize") }; Ref_ptr_array p_items= subq_select->ref_pointer_array; for (uint i= 0; i < subq_select->item_list.elements; i++) sjm->sjm_table_cols.push_back(p_items[i], thd->mem_root); @@ -3718,7 +3725,7 @@ bool setup_sj_materialization_part1(JOIN_TAB *sjm_tab) 1, /*save_sum_fields*/ thd->variables.option_bits | TMP_TABLE_ALL_COLUMNS, HA_POS_ERROR /*rows_limit */, - (char*)"sj-materialize"))) + &sj_materialize_name))) DBUG_RETURN(TRUE); /* purecov: inspected */ sjm->table->map= emb_sj_nest->nested_join->used_tables; sjm->table->file->extra(HA_EXTRA_WRITE_CACHE); @@ -5335,6 +5342,7 @@ TABLE *create_dummy_tmp_table(THD *thd) sjm_table_param.init(); sjm_table_param.field_count= 1; List<Item> sjm_table_cols; + const LEX_CSTRING dummy_name= { STRING_WITH_LEN("dummy") }; Item *column_item= new (thd->mem_root) Item_int(thd, 1); if (!column_item) DBUG_RETURN(NULL); @@ -5347,7 +5355,7 @@ TABLE *create_dummy_tmp_table(THD *thd) thd->variables.option_bits | TMP_TABLE_ALL_COLUMNS, HA_POS_ERROR /*rows_limit */, - (char*)"dummy", TRUE /* Do not open */))) + &dummy_name, TRUE /* Do not open */))) { DBUG_RETURN(NULL); } diff --git a/sql/partition_info.cc b/sql/partition_info.cc index 9a1a5e111a5..636e0db437a 100644 --- a/sql/partition_info.cc +++ b/sql/partition_info.cc @@ -1071,7 +1071,7 @@ public: saved_lock(_thd->lock), saved_mode(_thd->locked_tables_mode), saved_query_tables_own_last(_thd->lex->query_tables_own_last), - table_list(_table, lock_type), + table_list(&_table, lock_type), locked(false) { table.reginfo.lock_type= lock_type; @@ -1246,7 +1246,7 @@ bool partition_info::vers_setup_stats(THD * thd, bool is_create_table_ind) bool error= false; - TABLE_LIST tl(*table, TL_READ); + TABLE_LIST tl(table, TL_READ); MDL_auto_lock mdl_lock(thd, tl); if (mdl_lock.acquire_error()) return true; @@ -2077,8 +2077,8 @@ bool partition_info::check_partition_info(THD *thd, handlerton **eng_type, DBUG_ASSERT(vers_info); if (num_parts < 2 || !vers_info->now_part) { - DBUG_ASSERT(info && info->alias); - my_error(ER_VERS_WRONG_PARTS, MYF(0), info->alias); + DBUG_ASSERT(info && info->alias.str); + my_error(ER_VERS_WRONG_PARTS, MYF(0), info->alias.str); goto end; } DBUG_ASSERT(vers_info->initialized(false)); @@ -2206,7 +2206,7 @@ bool partition_info::check_partition_info(THD *thd, handlerton **eng_type, } if (unlikely(now_parts > 1)) { - my_error(ER_VERS_WRONG_PARTS, MYF(0), info->alias); + my_error(ER_VERS_WRONG_PARTS, MYF(0), info->alias.str); goto end; } @@ -2259,8 +2259,8 @@ void partition_info::print_no_partition_found(TABLE *table_arg, myf errflag) THD *thd= current_thd; bzero(&table_list, sizeof(table_list)); - table_list.db= table_arg->s->db.str; - table_list.table_name= table_arg->s->table_name.str; + table_list.db= table_arg->s->db; + table_list.table_name= table_arg->s->table_name; if (check_single_table_access(thd, SELECT_ACL, &table_list, TRUE)) diff --git a/sql/procedure.cc b/sql/procedure.cc index e4bf589958e..d5b93433f92 100644 --- a/sql/procedure.cc +++ b/sql/procedure.cc @@ -96,7 +96,7 @@ setup_procedure(THD *thd,ORDER *param,select_result *result, DBUG_RETURN(proc); } } - my_error(ER_UNKNOWN_PROCEDURE, MYF(0), (*param->item)->name); + my_error(ER_UNKNOWN_PROCEDURE, MYF(0), (*param->item)->name.str); *error=1; DBUG_RETURN(0); } diff --git a/sql/proxy_protocol.cc b/sql/proxy_protocol.cc index 0309cf42ddf..d77e6ca8d34 100644 --- a/sql/proxy_protocol.cc +++ b/sql/proxy_protocol.cc @@ -13,7 +13,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include <my_global.h> +#include <mariadb.h> #include <mysql.h> #include <mysql_com.h> #include <mysqld_error.h> diff --git a/sql/rpl_filter.cc b/sql/rpl_filter.cc index d09b7aee31c..3fda2761430 100644 --- a/sql/rpl_filter.cc +++ b/sql/rpl_filter.cc @@ -105,9 +105,9 @@ Rpl_filter::tables_ok(const char* db, TABLE_LIST* tables) if (!tables->updating) continue; some_tables_updating= 1; - end= strmov(hash_key, tables->db ? tables->db : db); + end= strmov(hash_key, tables->db.str ? tables->db.str : db); *end++= '.'; - len= (uint) (strmov(end, tables->table_name) - hash_key); + len= (uint) (strmov(end, tables->table_name.str) - hash_key); if (do_table_inited) // if there are any do's { if (my_hash_search(&do_table, (uchar*) hash_key, len)) diff --git a/sql/rpl_gtid.cc b/sql/rpl_gtid.cc index 78e6165a551..1b176d10b4c 100644 --- a/sql/rpl_gtid.cc +++ b/sql/rpl_gtid.cc @@ -28,8 +28,8 @@ #include "slave.h" #include "log_event.h" -const LEX_STRING rpl_gtid_slave_state_table_name= - { C_STRING_WITH_LEN("gtid_slave_pos") }; +const LEX_CSTRING rpl_gtid_slave_state_table_name= + { STRING_WITH_LEN("gtid_slave_pos") }; void @@ -401,10 +401,7 @@ rpl_slave_state::truncate_state_table(THD *thd) int err= 0; tmp_disable_binlog(thd); - tlist.init_one_table(STRING_WITH_LEN("mysql"), - rpl_gtid_slave_state_table_name.str, - rpl_gtid_slave_state_table_name.length, - NULL, TL_WRITE); + tlist.init_one_table(&MYSQL_SCHEMA_NAME, &rpl_gtid_slave_state_table_name, NULL, TL_WRITE); if (!(err= open_and_lock_tables(thd, &tlist, FALSE, 0))) { err= tlist.table->file->ha_truncate(); @@ -655,8 +652,7 @@ rpl_slave_state::record_gtid(THD *thd, const rpl_gtid *gtid, uint64 sub_id, */ suspended_wfc= thd->suspend_subsequent_commits(); thd->lex->reset_n_backup_query_tables_list(&lex_backup); - tlist.init_one_table(STRING_WITH_LEN("mysql"), gtid_pos_table_name.str, - gtid_pos_table_name.length, NULL, TL_WRITE); + tlist.init_one_table(&MYSQL_SCHEMA_NAME, >id_pos_table_name, NULL, TL_WRITE); if ((err= open_and_lock_tables(thd, &tlist, FALSE, 0))) goto end; table_opened= true; diff --git a/sql/rpl_gtid.h b/sql/rpl_gtid.h index d30bfa64b87..604289acd6b 100644 --- a/sql/rpl_gtid.h +++ b/sql/rpl_gtid.h @@ -23,7 +23,7 @@ /* Definitions for MariaDB global transaction ID (GTID). */ -extern const LEX_STRING rpl_gtid_slave_state_table_name; +extern const LEX_CSTRING rpl_gtid_slave_state_table_name; class String; diff --git a/sql/rpl_parallel.cc b/sql/rpl_parallel.cc index dd8d71dd49b..b2b13c5467b 100644 --- a/sql/rpl_parallel.cc +++ b/sql/rpl_parallel.cc @@ -1393,7 +1393,7 @@ handle_rpl_parallel_thread(void *arg) thd->clear_error(); thd->catalog= 0; thd->reset_query(); - thd->reset_db(NULL, 0); + thd->reset_db(&null_clex_str); thd_proc_info(thd, "Slave worker thread exiting"); thd->temporary_tables= 0; diff --git a/sql/rpl_rli.cc b/sql/rpl_rli.cc index e03230081d5..04109ddadb4 100644 --- a/sql/rpl_rli.cc +++ b/sql/rpl_rli.cc @@ -1527,8 +1527,7 @@ scan_one_gtid_slave_pos_table(THD *thd, HASH *hash, DYNAMIC_ARRAY *array, int err= 0; thd->reset_for_next_command(); - tlist.init_one_table(STRING_WITH_LEN("mysql"), tablename->str, - tablename->length, NULL, TL_READ); + tlist.init_one_table(&MYSQL_SCHEMA_NAME, tablename, NULL, TL_READ); if ((err= open_and_lock_tables(thd, &tlist, FALSE, 0))) goto end; table_opened= true; @@ -1642,15 +1641,14 @@ static int scan_all_gtid_slave_pos_table(THD *thd, int (*cb)(THD *, LEX_CSTRING *, void *), void *cb_data) { - static LEX_CSTRING mysql_db_name= {C_STRING_WITH_LEN("mysql")}; char path[FN_REFLEN]; MY_DIR *dirp; thd->reset_for_next_command(); - if (lock_schema_name(thd, mysql_db_name.str)) + if (lock_schema_name(thd, MYSQL_SCHEMA_NAME.str)) return 1; - build_table_filename(path, sizeof(path) - 1, mysql_db_name.str, "", "", 0); + build_table_filename(path, sizeof(path) - 1, MYSQL_SCHEMA_NAME.str, "", "", 0); if (!(dirp= my_dir(path, MYF(MY_DONT_SORT)))) { my_error(ER_FILE_NOT_FOUND, MYF(0), path, my_errno); @@ -1665,7 +1663,7 @@ scan_all_gtid_slave_pos_table(THD *thd, int (*cb)(THD *, LEX_CSTRING *, void *), Discovered_table_list tl(thd, &files); int err; - err= ha_discover_table_names(thd, &mysql_db_name, dirp, &tl, false); + err= ha_discover_table_names(thd, &MYSQL_SCHEMA_NAME, dirp, &tl, false); my_dirend(dirp); close_thread_tables(thd); thd->mdl_context.release_transactional_locks(); @@ -1928,8 +1926,7 @@ find_gtid_pos_tables_cb(THD *thd, LEX_CSTRING *table_name, void *arg) int err; thd->reset_for_next_command(); - tlist.init_one_table(STRING_WITH_LEN("mysql"), table_name->str, - table_name->length, NULL, TL_READ); + tlist.init_one_table(&MYSQL_SCHEMA_NAME, table_name, NULL, TL_READ); if ((err= open_and_lock_tables(thd, &tlist, FALSE, 0))) goto end; table= tlist.table; diff --git a/sql/semisync_master.cc b/sql/semisync_master.cc index 99d8b75ece8..5e83847edf9 100644 --- a/sql/semisync_master.cc +++ b/sql/semisync_master.cc @@ -755,10 +755,10 @@ int Repl_semi_sync_master::dump_start(THD* thd, add_slave(); report_reply_binlog(thd->variables.server_id, log_file + dirname_length(log_file), log_pos); - sql_print_information("Start semi-sync binlog_dump to slave (server_id: %d), " - "pos(%s, %lu", - thd->variables.server_id, log_file, - (unsigned long)log_pos); + sql_print_information("Start semi-sync binlog_dump to slave " + "(server_id: %ld), pos(%s, %lu)", + (long) thd->variables.server_id, log_file, + (ulong) log_pos); return 0; } @@ -768,7 +768,8 @@ void Repl_semi_sync_master::dump_end(THD* thd) if (!thd->semi_sync_slave) return; - sql_print_information("Stop semi-sync binlog_dump to slave (server_id: %d)", thd->variables.server_id); + sql_print_information("Stop semi-sync binlog_dump to slave (server_id: %ld)", + (long) thd->variables.server_id); remove_slave(); ack_receiver.remove_slave(thd); diff --git a/sql/session_tracker.cc b/sql/session_tracker.cc index ff9780a9531..51888913983 100644 --- a/sql/session_tracker.cc +++ b/sql/session_tracker.cc @@ -974,7 +974,7 @@ bool Current_schema_tracker::store(THD *thd, String *buf) It saves length of database name and name of database name + length of saved length of database length. */ - length= db_length= thd->db_length; + length= db_length= thd->db.length; length += net_length_size(length); compile_time_assert(SESSION_TRACK_SCHEMA < 251); @@ -991,7 +991,7 @@ bool Current_schema_tracker::store(THD *thd, String *buf) buf->q_net_store_length(length); /* Length and current schema name */ - buf->q_net_store_data((const uchar *)thd->db, thd->db_length); + buf->q_net_store_data((const uchar *)thd->db.str, thd->db.length); reset(); diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index 384344a0523..03e7b8a1098 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -7877,7 +7877,7 @@ ER_VERS_WRONG_PARTS eng "Wrong partitions for %`s: must have at least one HISTORY and exactly one last CURRENT" ER_VERS_NO_TRX_ID - eng "TRX_ID %lu not found in `mysql.transaction_registry`" + eng "TRX_ID %llu not found in `mysql.transaction_registry`" ER_VERS_ALTER_SYSTEM_FIELD eng "Can not change system versioning field %`s" diff --git a/sql/slave.cc b/sql/slave.cc index b69e92a8363..d969f1c20b8 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -310,9 +310,9 @@ build_gtid_pos_create_query(THD *thd, String *query, { bool err= false; err|= query->append(gtid_pos_table_definition1); - err|= append_identifier(thd, query, table_name->str, table_name->length); + err|= append_identifier(thd, query, table_name); err|= query->append(gtid_pos_table_definition2); - err|= append_identifier(thd, query, engine_name->str, engine_name->length); + err|= append_identifier(thd, query, engine_name); return err; } @@ -331,7 +331,7 @@ gtid_pos_table_creation(THD *thd, plugin_ref engine, LEX_CSTRING *table_name) return 1; } - thd->set_db("mysql", 5); + thd->set_db(&MYSQL_SCHEMA_NAME); thd->clear_error(); ulonglong thd_saved_option= thd->variables.option_bits; /* This query shuold not be binlogged. */ @@ -4945,7 +4945,7 @@ err: } repl_semisync_slave.slave_stop(mi); thd->reset_query(); - thd->reset_db(NULL, 0); + thd->reset_db(&null_clex_str); if (mysql) { /* @@ -5531,7 +5531,7 @@ pthread_handler_t handle_slave_sql(void *arg) */ thd->catalog= 0; thd->reset_query(); - thd->reset_db(NULL, 0); + thd->reset_db(&null_clex_str); if (rli->mi->using_gtid != Master_info::USE_GTID_NO) { ulong domain_count; diff --git a/sql/sp.cc b/sql/sp.cc index 843c40cf2b6..82b6e31b198 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -35,7 +35,6 @@ #include <my_user.h> - sp_cache **Sp_handler_procedure::get_cache(THD *thd) const { return &thd->sp_proc_cache; @@ -455,7 +454,7 @@ TABLE *open_proc_table_for_read(THD *thd, Open_tables_backup *backup) DBUG_ENTER("open_proc_table_for_read"); - table.init_one_table("mysql", 5, "proc", 4, "proc", TL_READ); + table.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_PROC_NAME, NULL, TL_READ); if (open_system_tables_for_read(thd, &table, backup)) DBUG_RETURN(NULL); @@ -490,7 +489,7 @@ static TABLE *open_proc_table_for_update(THD *thd) MDL_savepoint mdl_savepoint= thd->mdl_context.mdl_savepoint(); DBUG_ENTER("open_proc_table_for_update"); - table_list.init_one_table("mysql", 5, "proc", 4, "proc", TL_WRITE); + table_list.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_PROC_NAME, NULL, TL_WRITE); if (!(table= open_system_table_for_update(thd, &table_list))) DBUG_RETURN(NULL); @@ -1919,16 +1918,16 @@ Sp_handler::sp_exist_routines(THD *thd, TABLE_LIST *routines) const sp_name *name; LEX_CSTRING lex_db; LEX_CSTRING lex_name; - thd->make_lex_string(&lex_db, routine->db, strlen(routine->db)); - thd->make_lex_string(&lex_name, routine->table_name, - strlen(routine->table_name)); + thd->make_lex_string(&lex_db, routine->db.str, routine->db.length); + thd->make_lex_string(&lex_name, routine->table_name.str, + routine->table_name.length); name= new sp_name(&lex_db, &lex_name, true); sp_object_found= sp_find_routine(thd, name, false) != NULL; thd->get_stmt_da()->clear_warning_info(thd->query_id); if (! sp_object_found) { my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "FUNCTION or PROCEDURE", - routine->table_name); + routine->table_name.str); DBUG_RETURN(TRUE); } } @@ -2270,6 +2269,8 @@ Sp_handler::show_create_sp(THD *thd, String *buf, { sql_mode_t old_sql_mode= thd->variables.sql_mode; size_t agglen= (chistics.agg_type == GROUP_AGGREGATE)? 10 : 0; + LEX_CSTRING tmp; + /* Make some room to begin with */ if (buf->alloc(100 + db.length + 1 + name.length + params.length + returns.length + @@ -2284,19 +2285,20 @@ Sp_handler::show_create_sp(THD *thd, String *buf, append_definer(thd, buf, &definer.user, &definer.host); if (chistics.agg_type == GROUP_AGGREGATE) buf->append(STRING_WITH_LEN("AGGREGATE ")); - buf->append(type_lex_cstring()); + tmp= type_lex_cstring(); + buf->append(&tmp); buf->append(STRING_WITH_LEN(" ")); if (ddl_options.if_not_exists()) buf->append(STRING_WITH_LEN("IF NOT EXISTS ")); if (db.length > 0) { - append_identifier(thd, buf, db.str, db.length); + append_identifier(thd, buf, &db); buf->append('.'); } - append_identifier(thd, buf, name.str, name.length); + append_identifier(thd, buf, &name); buf->append('('); - buf->append(params); + buf->append(¶ms); buf->append(')'); if (type() == TYPE_ENUM_FUNCTION) { @@ -2304,7 +2306,7 @@ Sp_handler::show_create_sp(THD *thd, String *buf, buf->append(STRING_WITH_LEN(" RETURN ")); else buf->append(STRING_WITH_LEN(" RETURNS ")); - buf->append(returns); + buf->append(&returns); } buf->append('\n'); switch (chistics.daccess) { @@ -2326,7 +2328,7 @@ Sp_handler::show_create_sp(THD *thd, String *buf, buf->append(STRING_WITH_LEN(" DETERMINISTIC\n")); append_suid(buf, chistics.suid); append_comment(buf, chistics.comment); - buf->append(body); + buf->append(&body); thd->variables.sql_mode= old_sql_mode; return false; } diff --git a/sql/sp_head.cc b/sql/sp_head.cc index b30d0954cb2..2387429ea79 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -898,13 +898,13 @@ subst_spvars(THD *thd, sp_instr *instr, LEX_STRING *query_str) <flags> Flags struct */ int buf_len= (qbuf.length() + 1 + QUERY_CACHE_DB_LENGTH_SIZE + - thd->db_length + QUERY_CACHE_FLAGS_SIZE + 1); + thd->db.length + QUERY_CACHE_FLAGS_SIZE + 1); if ((pbuf= (char *) alloc_root(thd->mem_root, buf_len))) { char *ptr= pbuf + qbuf.length(); memcpy(pbuf, qbuf.ptr(), qbuf.length()); *ptr= 0; - int2store(ptr+1, thd->db_length); + int2store(ptr+1, thd->db.length); } else DBUG_RETURN(TRUE); @@ -1403,7 +1403,7 @@ set_routine_security_ctx(THD *thd, sp_head *sp, Security_context **save_ctx) */ if (*save_ctx && check_routine_access(thd, EXECUTE_ACL, - sp->m_db.str, sp->m_name.str, sp->m_handler, false)) + &sp->m_db, &sp->m_name, sp->m_handler, false)) { sp->m_security_ctx.restore_security_context(thd, *save_ctx); *save_ctx= 0; @@ -1418,7 +1418,7 @@ set_routine_security_ctx(THD *thd, sp_head *sp, Security_context **save_ctx) bool sp_head::check_execute_access(THD *thd) const { return check_routine_access(thd, EXECUTE_ACL, - m_db.str, m_name.str, + &m_db, &m_name, m_handler, false); } @@ -1733,9 +1733,9 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount, { binlog_buf.length(0); binlog_buf.append(STRING_WITH_LEN("SELECT ")); - append_identifier(thd, &binlog_buf, m_db.str, m_db.length); + append_identifier(thd, &binlog_buf, &m_db); binlog_buf.append('.'); - append_identifier(thd, &binlog_buf, m_name.str, m_name.length); + append_identifier(thd, &binlog_buf, &m_name); binlog_buf.append('('); for (arg_no= 0; arg_no < argcount; arg_no++) { @@ -2526,8 +2526,10 @@ bool check_show_routine_access(THD *thd, sp_head *sp, bool *full_access) { TABLE_LIST tables; bzero((char*) &tables,sizeof(tables)); - tables.db= (char*) "mysql"; - tables.table_name= tables.alias= (char*) "proc"; + tables.db= MYSQL_SCHEMA_NAME; + tables.table_name= MYSQL_PROC_NAME; + tables.alias= MYSQL_PROC_NAME; + *full_access= ((!check_table_access(thd, SELECT_ACL, &tables, FALSE, 1, TRUE) && (tables.grant.privilege & SELECT_ACL) != 0) || @@ -3356,7 +3358,7 @@ sp_instr_stmt::exec_core(THD *thd, uint *nextp) { MYSQL_QUERY_EXEC_START(thd->query(), thd->thread_id, - (char *) (thd->db ? thd->db : ""), + thd->get_db(), &thd->security_ctx->priv_user[0], (char *)thd->security_ctx->host_or_ip, 3); @@ -4454,12 +4456,12 @@ sp_head::merge_table_list(THD *thd, TABLE_LIST *table, LEX *lex_for_tmp_check) uint temp_table_key_length; tname.length(0); - tname.append(table->db, table->db_length); + tname.append(&table->db); tname.append('\0'); - tname.append(table->table_name, table->table_name_length); + tname.append(&table->table_name); tname.append('\0'); temp_table_key_length= tname.length(); - tname.append(table->alias); + tname.append(&table->alias); tname.append('\0'); /* @@ -4505,8 +4507,8 @@ sp_head::merge_table_list(THD *thd, TABLE_LIST *table, LEX *lex_for_tmp_check) tab->qname.str= (char*) thd->memdup(tname.ptr(), tab->qname.length); if (!tab->qname.str) return FALSE; - tab->table_name_length= table->table_name_length; - tab->db_length= table->db_length; + tab->table_name_length= table->table_name.length; + tab->db_length= table->db.length; tab->lock_type= table->lock_type; tab->lock_count= tab->query_lock_count= 1; tab->trg_event_map= table->trg_event_map; @@ -4563,8 +4565,8 @@ sp_head::add_used_tables_to_table_list(THD *thd, for (i=0 ; i < m_sptabs.records ; i++) { char *tab_buff, *key_buff; - TABLE_LIST *table; SP_TABLE *stab= (SP_TABLE*) my_hash_element(&m_sptabs, i); + LEX_CSTRING db_name; if (stab->temp) continue; @@ -4574,16 +4576,26 @@ sp_head::add_used_tables_to_table_list(THD *thd, stab->qname.length))) DBUG_RETURN(FALSE); + db_name.str= key_buff; + db_name.length= stab->db_length; + + for (uint j= 0; j < stab->lock_count; j++) { - table= (TABLE_LIST *)tab_buff; - table->init_one_table_for_prelocking(key_buff, stab->db_length, - key_buff + stab->db_length + 1, stab->table_name_length, - key_buff + stab->db_length + stab->table_name_length + 2, - stab->lock_type, TABLE_LIST::PRELOCK_ROUTINE, belong_to_view, - stab->trg_event_map, - query_tables_last_ptr); - + TABLE_LIST *table= (TABLE_LIST *)tab_buff; + LEX_CSTRING table_name= { key_buff + stab->db_length + 1, + stab->table_name_length }; + LEX_CSTRING alias= { table_name.str + table_name.length + 1, + strlen(table_name.str + table_name.length + 1) }; + + table->init_one_table_for_prelocking(&db_name, + &table_name, + &alias, + stab->lock_type, + TABLE_LIST::PRELOCK_ROUTINE, + belong_to_view, + stab->trg_event_map, + query_tables_last_ptr); tab_buff+= ALIGN_SIZE(sizeof(TABLE_LIST)); result= TRUE; } @@ -4603,7 +4615,7 @@ sp_head::add_used_tables_to_table_list(THD *thd, TABLE_LIST * sp_add_to_query_tables(THD *thd, LEX *lex, - const char *db, const char *name, + const LEX_CSTRING *db, const LEX_CSTRING *name, thr_lock_type locktype, enum_mdl_type mdl_type) { @@ -4611,15 +4623,15 @@ sp_add_to_query_tables(THD *thd, LEX *lex, if (!(table= (TABLE_LIST *)thd->calloc(sizeof(TABLE_LIST)))) return NULL; - table->db_length= strlen(db); - table->db= thd->strmake(db, table->db_length); - table->table_name_length= strlen(name); - table->table_name= thd->strmake(name, table->table_name_length); - table->alias= thd->strdup(name); + if (!thd->make_lex_string(&table->db, db->str, db->length) || + !thd->make_lex_string(&table->table_name, name->str, name->length) || + !thd->make_lex_string(&table->alias, name->str, name->length)) + return NULL; + table->lock_type= locktype; table->select_lex= lex->current_select; table->cacheable_table= 1; - table->mdl_request.init(MDL_key::TABLE, table->db, table->table_name, + table->mdl_request.init(MDL_key::TABLE, table->db.str, table->table_name.str, mdl_type, MDL_TRANSACTION); lex->add_to_query_tables(table); diff --git a/sql/sp_head.h b/sql/sp_head.h index 539ccf823d1..e89d0d14a95 100644 --- a/sql/sp_head.h +++ b/sql/sp_head.h @@ -1940,7 +1940,7 @@ set_routine_security_ctx(THD *thd, sp_head *sp, Security_context **save_ctx); TABLE_LIST * sp_add_to_query_tables(THD *thd, LEX *lex, - const char *db, const char *name, + const LEX_CSTRING *db, const LEX_CSTRING *name, thr_lock_type locktype, enum_mdl_type mdl_type); diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 3dd27622da8..ac4d1c5cad1 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -859,7 +859,7 @@ class Grant_table_base if (table_exists()) return 0; - my_error(ER_NO_SUCH_TABLE, MYF(0), tl.db, tl.alias); + my_error(ER_NO_SUCH_TABLE, MYF(0), tl.db.str, tl.alias.str); return 1; } @@ -1024,9 +1024,7 @@ class User_table: public Grant_table_base void init(enum thr_lock_type lock_type) { /* We are relying on init_one_table zeroing out the TABLE_LIST structure. */ - tl.init_one_table(C_STRING_WITH_LEN("mysql"), - C_STRING_WITH_LEN("user"), - NULL, lock_type); + tl.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_USER_NAME, NULL, lock_type); Grant_table_base::init(lock_type, false); } @@ -1070,9 +1068,7 @@ class Db_table: public Grant_table_base void init(enum thr_lock_type lock_type) { /* We are relying on init_one_table zeroing out the TABLE_LIST structure. */ - tl.init_one_table(C_STRING_WITH_LEN("mysql"), - C_STRING_WITH_LEN("db"), - NULL, lock_type); + tl.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_DB_NAME, NULL, lock_type); Grant_table_base::init(lock_type, false); } }; @@ -1097,9 +1093,8 @@ class Tables_priv_table: public Grant_table_base void init(enum thr_lock_type lock_type, Grant_table_base *next_table= NULL) { /* We are relying on init_one_table zeroing out the TABLE_LIST structure. */ - tl.init_one_table(C_STRING_WITH_LEN("mysql"), - C_STRING_WITH_LEN("tables_priv"), - NULL, lock_type); + LEX_CSTRING MYSQL_TABLES_PRIV_NAME={STRING_WITH_LEN("tables_priv") }; + tl.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_TABLES_PRIV_NAME, NULL, lock_type); Grant_table_base::init(lock_type, false); } }; @@ -1123,9 +1118,8 @@ class Columns_priv_table: public Grant_table_base void init(enum thr_lock_type lock_type) { /* We are relying on init_one_table zeroing out the TABLE_LIST structure. */ - tl.init_one_table(C_STRING_WITH_LEN("mysql"), - C_STRING_WITH_LEN("columns_priv"), - NULL, lock_type); + LEX_CSTRING MYSQL_COLUMNS_PRIV_NAME={ STRING_WITH_LEN("columns_priv") }; + tl.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_COLUMNS_PRIV_NAME, NULL, lock_type); Grant_table_base::init(lock_type, false); } }; @@ -1144,9 +1138,8 @@ class Host_table: public Grant_table_base void init(enum thr_lock_type lock_type) { /* We are relying on init_one_table zeroing out the TABLE_LIST structure. */ - tl.init_one_table(C_STRING_WITH_LEN("mysql"), - C_STRING_WITH_LEN("host"), - NULL, lock_type); + LEX_CSTRING MYSQL_HOST_NAME={STRING_WITH_LEN("host") }; + tl.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_HOST_NAME, NULL, lock_type); Grant_table_base::init(lock_type, true); } }; @@ -1171,9 +1164,8 @@ class Procs_priv_table: public Grant_table_base void init(enum thr_lock_type lock_type) { /* We are relying on init_one_table zeroing out the TABLE_LIST structure. */ - tl.init_one_table(C_STRING_WITH_LEN("mysql"), - C_STRING_WITH_LEN("procs_priv"), - NULL, lock_type); + LEX_CSTRING MYSQL_PROCS_PRIV_NAME={STRING_WITH_LEN("procs_priv") }; + tl.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_PROCS_PRIV_NAME, NULL, lock_type); Grant_table_base::init(lock_type, true); } }; @@ -1197,9 +1189,8 @@ class Proxies_priv_table: public Grant_table_base void init(enum thr_lock_type lock_type) { /* We are relying on init_one_table zeroing out the TABLE_LIST structure. */ - tl.init_one_table(C_STRING_WITH_LEN("mysql"), - C_STRING_WITH_LEN("proxies_priv"), - NULL, lock_type); + LEX_CSTRING MYSQL_PROXIES_PRIV_NAME={STRING_WITH_LEN("proxies_priv") }; + tl.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_PROXIES_PRIV_NAME, NULL, lock_type); Grant_table_base::init(lock_type, true); } }; @@ -1220,9 +1211,8 @@ class Roles_mapping_table: public Grant_table_base void init(enum thr_lock_type lock_type) { /* We are relying on init_one_table zeroing out the TABLE_LIST structure. */ - tl.init_one_table(C_STRING_WITH_LEN("mysql"), - C_STRING_WITH_LEN("roles_mapping"), - NULL, lock_type); + LEX_CSTRING MYSQL_ROLES_MAPPING_NAME={STRING_WITH_LEN("roles_mapping") }; + tl.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_ROLES_MAPPING_NAME, NULL, lock_type); Grant_table_base::init(lock_type, true); } }; @@ -2691,8 +2681,8 @@ int acl_setrole(THD *thd, const char *rolename, ulonglong access) /* merge the privileges */ Security_context *sctx= thd->security_ctx; sctx->master_access= static_cast<ulong>(access); - if (thd->db) - sctx->db_access= acl_get(sctx->host, sctx->ip, sctx->user, thd->db, FALSE); + if (thd->db.str) + sctx->db_access= acl_get(sctx->host, sctx->ip, sctx->user, thd->db.str, FALSE); if (!strcasecmp(rolename, "NONE")) { @@ -2700,8 +2690,8 @@ int acl_setrole(THD *thd, const char *rolename, ulonglong access) } else { - if (thd->db) - sctx->db_access|= acl_get("", "", rolename, thd->db, FALSE); + if (thd->db.str) + sctx->db_access|= acl_get("", "", rolename, thd->db.str, FALSE); /* mark the current role */ strmake_buf(thd->security_ctx->priv_role, rolename); } @@ -3973,14 +3963,13 @@ static bool test_if_create_new_users(THD *thd) { TABLE_LIST tl; ulong db_access; - tl.init_one_table(C_STRING_WITH_LEN("mysql"), - C_STRING_WITH_LEN("user"), "user", TL_WRITE); + tl.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_USER_NAME, NULL, TL_WRITE); create_new_users= 1; db_access=acl_get(sctx->host, sctx->ip, - sctx->priv_user, tl.db, 0); + sctx->priv_user, tl.db.str, 0); if (sctx->priv_role[0]) - db_access|= acl_get("", "", sctx->priv_role, tl.db, 0); + db_access|= acl_get("", "", sctx->priv_role, tl.db.str, 0); if (!(db_access & INSERT_ACL)) { if (check_grant(thd, INSERT_ACL, &tl, FALSE, UINT_MAX, TRUE)) @@ -6482,7 +6471,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, if (f == (Field*)0) { my_error(ER_BAD_FIELD_ERROR, MYF(0), - column->column.c_ptr(), table_list->alias); + column->column.c_ptr(), table_list->alias.str); DBUG_RETURN(TRUE); } if (f == (Field *)-1) @@ -6495,9 +6484,10 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, { if (!(rights & CREATE_ACL)) { - if (!ha_table_exists(thd, table_list->db, table_list->table_name)) + if (!ha_table_exists(thd, &table_list->db, &table_list->table_name)) { - my_error(ER_NO_SUCH_TABLE, MYF(0), table_list->db, table_list->alias); + my_error(ER_NO_SUCH_TABLE, MYF(0), table_list->db.str, + table_list->alias.str); DBUG_RETURN(TRUE); } } @@ -6508,7 +6498,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, table_list->grant.want_privilege); my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0), command, thd->security_ctx->priv_user, - thd->security_ctx->host_or_ip, table_list->alias); + thd->security_ctx->host_or_ip, table_list->alias.str); DBUG_RETURN(-1); } } @@ -6584,7 +6574,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, if (revoke_grant) { my_error(ER_NONEXISTING_TABLE_GRANT, MYF(0), - Str->user.str, Str->host.str, table_list->table_name); + Str->user.str, Str->host.str, table_list->table_name.str); result= TRUE; continue; } @@ -6751,8 +6741,8 @@ bool mysql_routine_grant(THD *thd, TABLE_LIST *table_list, continue; } - db_name= table_list->db; - table_name= table_list->table_name; + db_name= table_list->db.str; + table_name= table_list->table_name.str; grant_name= routine_hash_search(Str->host.str, NullS, db_name, Str->user.str, table_name, sph, 1); if (!grant_name || !grant_name->init_privs) @@ -8179,13 +8169,13 @@ bool check_grant_routine(THD *thd, ulong want_access, for (table= procs; table; table= table->next_global) { GRANT_NAME *grant_proc; - if ((grant_proc= routine_hash_search(host, sctx->ip, table->db, user, - table->table_name, sph, 0))) + if ((grant_proc= routine_hash_search(host, sctx->ip, table->db.str, user, + table->table_name.str, sph, 0))) table->grant.privilege|= grant_proc->privs; if (role[0]) /* current role set check */ { - if ((grant_proc= routine_hash_search("", NULL, table->db, role, - table->table_name, sph, 0))) + if ((grant_proc= routine_hash_search("", NULL, table->db.str, role, + table->table_name.str, sph, 0))) table->grant.privilege|= grant_proc->privs; } @@ -8204,7 +8194,7 @@ err: char buff[1024]; const char *command=""; if (table) - strxmov(buff, table->db, ".", table->table_name, NullS); + strxmov(buff, table->db.str, ".", table->table_name.str, NullS); if (want_access & EXECUTE_ACL) command= "execute"; else if (want_access & ALTER_PROC_ACL) @@ -8267,7 +8257,7 @@ ulong get_table_grant(THD *thd, TABLE_LIST *table) { ulong privilege; Security_context *sctx= thd->security_ctx; - const char *db = table->db ? table->db : thd->db; + const char *db = table->db.str ? table->db.str : thd->db.str; GRANT_TABLE *grant_table; GRANT_TABLE *grant_table_role= NULL; @@ -8277,10 +8267,10 @@ ulong get_table_grant(THD *thd, TABLE_LIST *table) grant_table_role= NULL; #else grant_table= table_hash_search(sctx->host, sctx->ip, db, sctx->priv_user, - table->table_name, 0); + table->table_name.str, 0); if (sctx->priv_role[0]) grant_table_role= table_hash_search("", "", db, sctx->priv_role, - table->table_name, 0); + table->table_name.str, 0); #endif table->grant.grant_table_user= grant_table; // Remember for column test table->grant.grant_table_role= grant_table_role; @@ -9194,7 +9184,8 @@ static int show_routine_grants(THD* thd, } } global.append(STRING_WITH_LEN(" ON ")); - global.append(sph->type_lex_cstring()); + LEX_CSTRING tmp= sph->type_lex_cstring(); + global.append(&tmp); global.append(' '); append_identifier(thd, &global, grant_proc->db, strlen(grant_proc->db)); @@ -11026,8 +11017,10 @@ bool sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name, bzero((char*)tables, sizeof(TABLE_LIST)); user_list.empty(); - tables->db= (char*)sp_db; - tables->table_name= tables->alias= (char*)sp_name; + tables->db.str= sp_db; + tables->db.length= sp_db ? strlen(sp_db) : 0; + tables->table_name.str= tables->alias.str= sp_name; + tables->table_name.length= tables->alias.length= sp_name ? strlen(sp_name) : 0; thd->make_lex_string(&combo->user, combo->user.str, strlen(combo->user.str)); thd->make_lex_string(&combo->host, combo->host.str, strlen(combo->host.str)); @@ -11826,7 +11819,7 @@ void fill_effective_table_privileges(THD *thd, GRANT_INFO *grant, /* global privileges */ grant->privilege= sctx->master_access; - if (!thd->db || strcmp(db, thd->db)) + if (!thd->db.str || strcmp(db, thd->db.str)) { /* db privileges */ grant->privilege|= acl_get(sctx->host, sctx->ip, sctx->priv_user, db, 0); @@ -12552,7 +12545,7 @@ static bool parse_com_change_user_packet(MPVIO_EXT *mpvio, uint packet_length) connection is closed. We don't want to accidentally free a wrong pointer if connect failed. */ - thd->reset_db(NULL, 0); + thd->reset_db(&null_clex_str); if (!initialized) { @@ -12803,7 +12796,7 @@ static ulong parse_client_handshake_packet(MPVIO_EXT *mpvio, connection is closed. We don't want to accidentally free a wrong pointer if connect failed. */ - thd->reset_db(NULL, 0); + thd->reset_db(&null_clex_str); if (!initialized) { diff --git a/sql/sql_admin.cc b/sql/sql_admin.cc index 4ed8234aa64..6c56e4c1010 100644 --- a/sql/sql_admin.cc +++ b/sql/sql_admin.cc @@ -77,7 +77,7 @@ static int send_check_errmsg(THD *thd, TABLE_LIST* table, { Protocol *protocol= thd->protocol; protocol->prepare_for_resend(); - protocol->store(table->alias, system_charset_info); + protocol->store(table->alias.str, table->alias.length, system_charset_info); protocol->store((char*) operator_name, system_charset_info); protocol->store(STRING_WITH_LEN("error"), system_charset_info); protocol->store(errmsg, system_charset_info); @@ -123,7 +123,7 @@ static int prepare_for_repair(THD *thd, TABLE_LIST *table_list, */ table_list->mdl_request.init(MDL_key::TABLE, - table_list->db, table_list->table_name, + table_list->db.str, table_list->table_name.str, MDL_EXCLUSIVE, MDL_TRANSACTION); if (lock_table_names(thd, table_list, table_list->next_global, @@ -135,7 +135,8 @@ static int prepare_for_repair(THD *thd, TABLE_LIST *table_list, if (share == NULL) DBUG_RETURN(0); // Can't open frm file - if (open_table_from_share(thd, share, "", 0, 0, 0, &tmp_table, FALSE)) + if (open_table_from_share(thd, share, &empty_clex_str, 0, 0, 0, + &tmp_table, FALSE)) { tdc_release_share(share); DBUG_RETURN(0); // Out of memory @@ -218,7 +219,7 @@ static int prepare_for_repair(THD *thd, TABLE_LIST *table_list, "Failed renaming data file"); goto end; } - if (dd_recreate_table(thd, table_list->db, table_list->table_name)) + if (dd_recreate_table(thd, table_list->db.str, table_list->table_name.str)) { error= send_check_errmsg(thd, table_list, "repair", "Failed generating table from .frm file"); @@ -492,13 +493,13 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, for (table= tables; table; table= table->next_local) { char table_name[SAFE_NAME_LEN*2+2]; - const char *db= table->db; + const char *db= table->db.str; bool fatal_error=0; bool open_error; bool collect_eis= FALSE; - DBUG_PRINT("admin", ("table: '%s'.'%s'", table->db, table->table_name)); - strxmov(table_name, db, ".", table->table_name, NullS); + DBUG_PRINT("admin", ("table: '%s'.'%s'", db, table->table_name.str)); + strxmov(table_name, db, ".", table->table_name.str, NullS); thd->open_options|= extra_open_options; table->lock_type= lock_type; /* @@ -547,7 +548,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, close_thread_tables(thd); table->table= NULL; thd->mdl_context.release_transactional_locks(); - table->mdl_request.init(MDL_key::TABLE, table->db, table->table_name, + table->mdl_request.init(MDL_key::TABLE, table->db.str, table->table_name.str, MDL_SHARED_NO_READ_WRITE, MDL_TRANSACTION); } @@ -818,7 +819,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, close_thread_tables(thd); table->table= NULL; thd->mdl_context.release_transactional_locks(); - table->mdl_request.init(MDL_key::TABLE, table->db, table->table_name, + table->mdl_request.init(MDL_key::TABLE, table->db.str, table->table_name.str, MDL_SHARED_NO_READ_WRITE, MDL_TRANSACTION); table->mdl_request.set_type(MDL_SHARED_READ); @@ -1118,11 +1119,11 @@ send_result_message: if (what_to_upgrade) length= my_snprintf(buf, sizeof(buf), ER_THD(thd, ER_TABLE_NEEDS_UPGRADE), - what_to_upgrade, table->table_name); + what_to_upgrade, table->table_name.str); else length= my_snprintf(buf, sizeof(buf), ER_THD(thd, ER_TABLE_NEEDS_REBUILD), - table->table_name); + table->table_name.str); protocol->store(buf, length, system_charset_info); fatal_error=1; break; @@ -1154,7 +1155,7 @@ send_result_message: else if (open_for_modify || fatal_error) { tdc_remove_table(thd, TDC_RT_REMOVE_UNUSED, - table->db, table->table_name, FALSE); + table->db.str, table->table_name.str, FALSE); /* May be something modified. Consequently, we have to invalidate the query cache. diff --git a/sql/sql_alter.cc b/sql/sql_alter.cc index 3d1e4c0fa65..2cc6504d2f3 100644 --- a/sql/sql_alter.cc +++ b/sql/sql_alter.cc @@ -86,8 +86,8 @@ bool Alter_info::set_requested_lock(const LEX_CSTRING *str) Alter_table_ctx::Alter_table_ctx() : datetime_field(NULL), error_if_not_empty(false), tables_opened(0), - db(NULL), table_name(NULL), alias(NULL), - new_db(NULL), new_name(NULL), new_alias(NULL), + db(null_clex_str), table_name(null_clex_str), alias(null_clex_str), + new_db(null_clex_str), new_name(null_clex_str), new_alias(null_clex_str), fk_error_if_delete_row(false), fk_error_id(NULL), fk_error_table(NULL) #ifdef DBUG_ASSERT_EXISTS @@ -103,11 +103,11 @@ Alter_table_ctx::Alter_table_ctx() Alter_table_ctx::Alter_table_ctx(THD *thd, TABLE_LIST *table_list, uint tables_opened_arg, - const char *new_db_arg, - const char *new_name_arg) + const LEX_CSTRING *new_db_arg, + const LEX_CSTRING *new_name_arg) : datetime_field(NULL), error_if_not_empty(false), tables_opened(tables_opened_arg), - new_db(new_db_arg), new_name(new_name_arg), + new_db(*new_db_arg), new_name(*new_name_arg), fk_error_if_delete_row(false), fk_error_id(NULL), fk_error_table(NULL) #ifdef DBUG_ASSERT_EXISTS @@ -123,29 +123,31 @@ Alter_table_ctx::Alter_table_ctx(THD *thd, TABLE_LIST *table_list, table_name= table_list->table_name; alias= (lower_case_table_names == 2) ? table_list->alias : table_name; - if (!new_db || !my_strcasecmp(table_alias_charset, new_db, db)) + if (!new_db.str || !my_strcasecmp(table_alias_charset, new_db.str, db.str)) new_db= db; - if (new_name) + if (new_name.str) { - DBUG_PRINT("info", ("new_db.new_name: '%s'.'%s'", new_db, new_name)); + DBUG_PRINT("info", ("new_db.new_name: '%s'.'%s'", new_db.str, new_name.str)); - if (lower_case_table_names == 1) // Convert new_name/new_alias to lower case + if (lower_case_table_names == 1) // Convert new_name/new_alias to lower { - my_casedn_str(files_charset_info, (char*) new_name); + new_name.length= my_casedn_str(files_charset_info, (char*) new_name.str); new_alias= new_name; } else if (lower_case_table_names == 2) // Convert new_name to lower case { - new_alias= new_alias_buff; - strmov(new_alias_buff, new_name); - my_casedn_str(files_charset_info, (char*) new_name); + new_alias.str= new_alias_buff; + new_alias.length= new_name.length; + strmov(new_alias_buff, new_name.str); + new_name.length= my_casedn_str(files_charset_info, (char*) new_name.str); + } else new_alias= new_name; // LCTN=0 => case sensitive + case preserving if (!is_database_changed() && - !my_strcasecmp(table_alias_charset, new_name, table_name)) + !my_strcasecmp(table_alias_charset, new_name.str, table_name.str)) { /* Source and destination table names are equal: @@ -161,22 +163,23 @@ Alter_table_ctx::Alter_table_ctx(THD *thd, TABLE_LIST *table_list, new_name= table_name; } - my_snprintf(tmp_name, sizeof(tmp_name), "%s-%lx_%llx", tmp_file_prefix, - current_pid, thd->thread_id); + tmp_name.str= tmp_name_buff; + tmp_name.length= my_snprintf(tmp_name_buff, sizeof(tmp_name_buff), "%s-%lx_%llx", + tmp_file_prefix, current_pid, thd->thread_id); /* Safety fix for InnoDB */ if (lower_case_table_names) - my_casedn_str(files_charset_info, tmp_name); + tmp_name.length= my_casedn_str(files_charset_info, tmp_name_buff); if (table_list->table->s->tmp_table == NO_TMP_TABLE) { - build_table_filename(path, sizeof(path) - 1, db, table_name, "", 0); + build_table_filename(path, sizeof(path) - 1, db.str, table_name.str, "", 0); - build_table_filename(new_path, sizeof(new_path) - 1, new_db, new_name, "", 0); + build_table_filename(new_path, sizeof(new_path) - 1, new_db.str, new_name.str, "", 0); build_table_filename(new_filename, sizeof(new_filename) - 1, - new_db, new_name, reg_ext, 0); + new_db.str, new_name.str, reg_ext, 0); - build_table_filename(tmp_path, sizeof(tmp_path) - 1, new_db, tmp_name, "", + build_table_filename(tmp_path, sizeof(tmp_path) - 1, new_db.str, tmp_name.str, "", FN_IS_TMP); } else @@ -227,14 +230,14 @@ bool Sql_cmd_alter_table::execute(THD *thd) priv_needed|= DROP_ACL; /* Must be set in the parser */ - DBUG_ASSERT(select_lex->db); + DBUG_ASSERT(select_lex->db.str); DBUG_ASSERT(!(alter_info.flags & Alter_info::ALTER_EXCHANGE_PARTITION)); DBUG_ASSERT(!(alter_info.flags & Alter_info::ALTER_ADMIN_PARTITION)); - if (check_access(thd, priv_needed, first_table->db, + if (check_access(thd, priv_needed, first_table->db.str, &first_table->grant.privilege, &first_table->grant.m_internal, 0, 0) || - check_access(thd, INSERT_ACL | CREATE_ACL, select_lex->db, + check_access(thd, INSERT_ACL | CREATE_ACL, select_lex->db.str, &priv, NULL, /* Don't use first_tab->grant with sel_lex->db */ 0, 0)) @@ -291,7 +294,7 @@ bool Sql_cmd_alter_table::execute(THD *thd) // Rename of table TABLE_LIST tmp_table; memset(&tmp_table, 0, sizeof(tmp_table)); - tmp_table.table_name= lex->name.str; + tmp_table.table_name= lex->name; tmp_table.db= select_lex->db; tmp_table.grant.privilege= priv; if (check_grant(thd, INSERT_ACL | CREATE_ACL, &tmp_table, FALSE, @@ -316,13 +319,13 @@ bool Sql_cmd_alter_table::execute(THD *thd) if ((!thd->is_current_stmt_binlog_format_row() || !thd->find_temporary_table(first_table))) { - WSREP_TO_ISOLATION_BEGIN(((lex->name.str) ? select_lex->db : NULL), + WSREP_TO_ISOLATION_BEGIN(((lex->name.str) ? select_lex->db.str : NULL), ((lex->name.str) ? lex->name.str : NULL), first_table); } #endif /* WITH_WSREP */ - result= mysql_alter_table(thd, select_lex->db, lex->name.str, + result= mysql_alter_table(thd, &select_lex->db, &lex->name, &create_info, first_table, &alter_info, @@ -346,7 +349,7 @@ bool Sql_cmd_discard_import_tablespace::execute(THD *thd) /* first table of first SELECT_LEX */ TABLE_LIST *table_list= (TABLE_LIST*) select_lex->table_list.first; - if (check_access(thd, ALTER_ACL, table_list->db, + if (check_access(thd, ALTER_ACL, table_list->db.str, &table_list->grant.privilege, &table_list->grant.m_internal, 0, 0)) diff --git a/sql/sql_alter.h b/sql/sql_alter.h index 5478ce74c10..524cff62a12 100644 --- a/sql/sql_alter.h +++ b/sql/sql_alter.h @@ -268,19 +268,19 @@ public: Alter_table_ctx(); Alter_table_ctx(THD *thd, TABLE_LIST *table_list, uint tables_opened_arg, - const char *new_db_arg, const char *new_name_arg); + const LEX_CSTRING *new_db_arg, const LEX_CSTRING *new_name_arg); /** @return true if the table is moved to another database, false otherwise. */ bool is_database_changed() const - { return (new_db != db); }; + { return (new_db.str != db.str); }; /** @return true if the table is renamed, false otherwise. */ bool is_table_renamed() const - { return (is_database_changed() || new_name != table_name); }; + { return (is_database_changed() || new_name.str != table_name.str); }; /** @return filename (including .frm) for the new table. @@ -330,13 +330,14 @@ public: Create_field *datetime_field; bool error_if_not_empty; uint tables_opened; - const char *db; - const char *table_name; - const char *alias; - const char *new_db; - const char *new_name; - const char *new_alias; - char tmp_name[80]; + LEX_CSTRING db; + LEX_CSTRING table_name; + LEX_CSTRING alias; + LEX_CSTRING new_db; + LEX_CSTRING new_name; + LEX_CSTRING new_alias; + LEX_CSTRING tmp_name; + char tmp_buff[80]; /** Indicates that if a row is deleted during copying of data from old version of table to the new version ER_FK_CANNOT_DELETE_PARENT error should be @@ -350,7 +351,8 @@ public: private: char new_filename[FN_REFLEN + 1]; - char new_alias_buff[FN_REFLEN + 1]; + char new_alias_buff[NAME_LEN + 1]; + char tmp_name_buff[NAME_LEN + 1]; char path[FN_REFLEN + 1]; char new_path[FN_REFLEN + 1]; char tmp_path[FN_REFLEN + 1]; diff --git a/sql/sql_audit.cc b/sql/sql_audit.cc index 7c8b355b8d0..793e3a801b3 100644 --- a/sql/sql_audit.cc +++ b/sql/sql_audit.cc @@ -15,6 +15,7 @@ #include "mariadb.h" #include "sql_priv.h" +#include "mysqld.h" #include "sql_audit.h" extern int initialize_audit_plugin(st_plugin_int *plugin); diff --git a/sql/sql_audit.h b/sql/sql_audit.h index 7a11f5aa113..5c66138b466 100644 --- a/sql/sql_audit.h +++ b/sql/sql_audit.h @@ -121,15 +121,13 @@ void mysql_audit_general_log(THD *thd, time_t time, event.general_thread_id= (unsigned long)thd->thread_id; event.general_charset= thd->variables.character_set_client; event.database= thd->db; - event.database_length= (unsigned int)thd->db_length; event.query_id= thd->query_id; } else { event.general_thread_id= 0; event.general_charset= global_system_variables.character_set_client; - event.database= ""; - event.database_length= 0; + event.database= null_clex_str; event.query_id= 0; } @@ -175,7 +173,6 @@ void mysql_audit_general(THD *thd, uint event_subtype, event.general_charset= thd->query_string.charset(); event.general_rows= thd->get_stmt_da()->current_row_for_warning(); event.database= thd->db; - event.database_length= (uint)thd->db_length; event.query_id= thd->query_id; } else @@ -187,8 +184,7 @@ void mysql_audit_general(THD *thd, uint event_subtype, event.general_query_length= 0; event.general_charset= &my_charset_bin; event.general_rows= 0; - event.database= ""; - event.database_length= 0; + event.database= null_clex_str; event.query_id= 0; } @@ -222,7 +218,6 @@ void mysql_audit_notify_connection_connect(THD *thd) event.ip= sctx->ip; event.ip_length= safe_strlen_uint(sctx->ip); event.database= thd->db; - event.database_length= safe_strlen_uint(thd->db); mysql_audit_notify(thd, MYSQL_AUDIT_CONNECTION_CLASS, &event); } @@ -252,7 +247,6 @@ void mysql_audit_notify_connection_disconnect(THD *thd, int errcode) event.ip= sctx->ip; event.ip_length= safe_strlen_uint(sctx->ip) ; event.database= thd->db; - event.database_length= safe_strlen_uint(thd->db); mysql_audit_notify(thd, MYSQL_AUDIT_CONNECTION_CLASS, &event); } @@ -283,7 +277,6 @@ void mysql_audit_notify_connection_change_user(THD *thd) event.ip= sctx->ip; event.ip_length= safe_strlen_uint(sctx->ip); event.database= thd->db; - event.database_length= safe_strlen_uint(thd->db); mysql_audit_notify(thd, MYSQL_AUDIT_CONNECTION_CLASS, &event); } @@ -307,14 +300,10 @@ void mysql_audit_external_lock(THD *thd, TABLE_SHARE *share, int lock) event.proxy_user= sctx->proxy_user; event.host= sctx->host; event.ip= sctx->ip; - event.database= share->db.str; - event.database_length= (unsigned int)share->db.length; - event.table= share->table_name.str; - event.table_length= (unsigned int)share->table_name.length; - event.new_database= 0; - event.new_database_length= 0; - event.new_table= 0; - event.new_table_length= 0; + event.database= share->db; + event.table= share->table_name; + event.new_database= null_clex_str; + event.new_table= null_clex_str; event.query_id= thd->query_id; mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, &event); @@ -341,15 +330,11 @@ void mysql_audit_create_table(TABLE *table) event.proxy_user= sctx->proxy_user; event.host= sctx->host; event.ip= sctx->ip; - event.database= share->db.str; - event.database_length= (unsigned int)share->db.length; - event.table= share->table_name.str; - event.table_length= (unsigned int)share->table_name.length; - event.new_database= 0; - event.new_database_length= 0; - event.new_table= 0; - event.new_table_length= 0; - event.query_id= thd->query_id; + event.database= share->db; + event.table= share->table_name; + event.new_database= null_clex_str; + event.new_table= null_clex_str; + event.query_id= thd->query_id; mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, &event); } @@ -373,23 +358,20 @@ void mysql_audit_drop_table(THD *thd, TABLE_LIST *table) event.proxy_user= sctx->proxy_user; event.host= sctx->host; event.ip= sctx->ip; - event.database= table->db; - event.database_length= (unsigned int)table->db_length; - event.table= table->table_name; - event.table_length= (unsigned int)table->table_name_length; - event.new_database= 0; - event.new_database_length= 0; - event.new_table= 0; - event.new_table_length= 0; - event.query_id= thd->query_id; + event.database= table->db; + event.table= table->table_name; + event.new_database= null_clex_str; + event.new_table= null_clex_str; + event.query_id= thd->query_id; mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, &event); } } static inline -void mysql_audit_rename_table(THD *thd, const char *old_db, const char *old_tb, - const char *new_db, const char *new_tb) +void mysql_audit_rename_table(THD *thd, const LEX_CSTRING *old_db, + const LEX_CSTRING *old_tb, + const LEX_CSTRING *new_db, const LEX_CSTRING *new_tb) { if (mysql_audit_table_enabled()) { @@ -406,14 +388,10 @@ void mysql_audit_rename_table(THD *thd, const char *old_db, const char *old_tb, event.proxy_user= sctx->proxy_user; event.host= sctx->host; event.ip= sctx->ip; - event.database= old_db; - event.database_length= strlen_uint(old_db); - event.table= old_tb; - event.table_length= strlen_uint(old_tb); - event.new_database= new_db; - event.new_database_length= strlen_uint(new_db); - event.new_table= new_tb; - event.new_table_length= strlen_uint(new_tb); + event.database= *old_db; + event.table= *old_tb; + event.new_database= *new_db; + event.new_table= *new_tb; event.query_id= thd->query_id; mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, &event); @@ -439,13 +417,9 @@ void mysql_audit_alter_table(THD *thd, TABLE_LIST *table) event.host= sctx->host; event.ip= sctx->ip; event.database= table->db; - event.database_length= (unsigned int)table->db_length; event.table= table->table_name; - event.table_length= (unsigned int)table->table_name_length; - event.new_database= 0; - event.new_database_length= 0; - event.new_table= 0; - event.new_table_length= 0; + event.new_database= null_clex_str; + event.new_table= null_clex_str; event.query_id= thd->query_id; mysql_audit_notify(thd, MYSQL_AUDIT_TABLE_CLASS, &event); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index bd2bc54efb4..df5e947efa2 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -244,8 +244,9 @@ struct list_open_tables_arg static my_bool list_open_tables_callback(TDC_element *element, list_open_tables_arg *arg) { - char *db= (char*) element->m_key; - char *table_name= (char*) element->m_key + strlen((char*) element->m_key) + 1; + const char *db= (char*) element->m_key; + uint db_length= strlen(db); + const char *table_name= db + db_length + 1; if (arg->db && my_strcasecmp(system_charset_info, arg->db, db)) return FALSE; @@ -253,8 +254,10 @@ static my_bool list_open_tables_callback(TDC_element *element, return FALSE; /* Check if user has SELECT privilege for any column in the table */ - arg->table_list.db= db; - arg->table_list.table_name= table_name; + arg->table_list.db.str= db; + arg->table_list.db.length= db_length; + arg->table_list.table_name.str= table_name; + arg->table_list.table_name.length= strlen(table_name); arg->table_list.grant.privilege= 0; if (check_table_access(arg->thd, SELECT_ACL, &arg->table_list, TRUE, 1, TRUE)) @@ -381,8 +384,8 @@ bool close_cached_tables(THD *thd, TABLE_LIST *tables, for (TABLE_LIST *table= tables; table; table= table->next_local) { /* tdc_remove_table() also sets TABLE_SHARE::version to 0. */ - found|= tdc_remove_table(thd, TDC_RT_REMOVE_UNUSED, table->db, - table->table_name, TRUE); + found|= tdc_remove_table(thd, TDC_RT_REMOVE_UNUSED, table->db.str, + table->table_name.str, TRUE); } if (!found) wait_for_refresh=0; // Nothing to wait for @@ -412,8 +415,8 @@ bool close_cached_tables(THD *thd, TABLE_LIST *tables, table_list= table_list->next_global) { /* A check that the table was locked for write is done by the caller. */ - TABLE *table= find_table_for_mdl_upgrade(thd, table_list->db, - table_list->table_name, TRUE); + TABLE *table= find_table_for_mdl_upgrade(thd, table_list->db.str, + table_list->table_name.str, TRUE); /* May return NULL if this table has already been closed via an alias. */ if (! table) @@ -463,7 +466,7 @@ bool close_cached_tables(THD *thd, TABLE_LIST *tables, { if (thd->killed) break; - if (tdc_wait_for_old_version(thd, table->db, table->table_name, timeout, + if (tdc_wait_for_old_version(thd, table->db.str, table->table_name.str, timeout, MDL_wait_for_subgraph::DEADLOCK_WEIGHT_DDL, refresh_version)) { @@ -530,9 +533,9 @@ static my_bool close_cached_connection_tables_callback( /* close_cached_tables() only uses these elements */ if (!(tmp= (TABLE_LIST*) alloc_root(arg->thd->mem_root, sizeof(TABLE_LIST))) || - !(tmp->db= strdup_root(arg->thd->mem_root, element->share->db.str)) || - !(tmp->table_name= strdup_root(arg->thd->mem_root, - element->share->table_name.str))) + !(arg->thd->make_lex_string(&tmp->db, element->share->db.str, element->share->db.length)) || + !(arg->thd->make_lex_string(&tmp->table_name, element->share->table_name.str, + element->share->table_name.length))) { mysql_mutex_unlock(&element->LOCK_table_share); return TRUE; @@ -919,8 +922,7 @@ void close_thread_table(THD *thd, TABLE **table_ptr) table_name Table name NOTES: - This is called by find_table_in_local_list() and - find_table_in_global_list(). + This is called by find_table_in_global_list(). RETURN VALUES NULL Table not found @@ -929,13 +931,13 @@ void close_thread_table(THD *thd, TABLE **table_ptr) TABLE_LIST *find_table_in_list(TABLE_LIST *table, TABLE_LIST *TABLE_LIST::*link, - const char *db_name, - const char *table_name) + const LEX_CSTRING *db_name, + const LEX_CSTRING *table_name) { for (; table; table= table->*link ) { - if (strcmp(table->db, db_name) == 0 && - strcmp(table->table_name, table_name) == 0) + if (cmp(&table->db, db_name) == 0 && + cmp(&table->table_name, table_name) == 0) break; } return table; @@ -980,9 +982,9 @@ TABLE_LIST* find_dup_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list, bool check_alias) { TABLE_LIST *res; - const char *d_name, *t_name, *t_alias; + LEX_CSTRING *d_name, *t_name, *t_alias; DBUG_ENTER("find_dup_table"); - DBUG_PRINT("enter", ("table alias: %s", table->alias)); + DBUG_PRINT("enter", ("table alias: %s", table->alias.str)); /* If this function called for query which update table (INSERT/UPDATE/...) @@ -1006,12 +1008,12 @@ TABLE_LIST* find_dup_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list, */ DBUG_ASSERT(table); } - d_name= table->db; - t_name= table->table_name; - t_alias= table->alias; + d_name= &table->db; + t_name= &table->table_name; + t_alias= &table->alias; retry: - DBUG_PRINT("info", ("real table: %s.%s", d_name, t_name)); + DBUG_PRINT("info", ("real table: %s.%s", d_name->str, t_name->str)); for (TABLE_LIST *tl= table_list;;) { if (tl && @@ -1039,7 +1041,7 @@ retry: /* Skip if table alias does not match. */ if (check_alias) { - if (my_strcasecmp(table_alias_charset, t_alias, res->alias)) + if (my_strcasecmp(table_alias_charset, t_alias->str, res->alias.str)) goto next; } @@ -1177,21 +1179,21 @@ void update_non_unique_table_error(TABLE_LIST *update, if (update->view == duplicate->view) my_error(!strncmp(operation, "INSERT", 6) ? ER_NON_INSERTABLE_TABLE : ER_NON_UPDATABLE_TABLE, MYF(0), - update->alias, operation); + update->alias.str, operation); else my_error(ER_VIEW_PREVENT_UPDATE, MYF(0), - (duplicate->view ? duplicate->alias : update->alias), - operation, update->alias); + (duplicate->view ? duplicate->alias.str : update->alias.str), + operation, update->alias.str); return; } if (duplicate->view) { - my_error(ER_VIEW_PREVENT_UPDATE, MYF(0), duplicate->alias, operation, - update->alias); + my_error(ER_VIEW_PREVENT_UPDATE, MYF(0), duplicate->alias.str, operation, + update->alias.str); return; } } - my_error(ER_UPDATE_TABLE_USED, MYF(0), update->alias, operation); + my_error(ER_UPDATE_TABLE_USED, MYF(0), update->alias.str, operation); } @@ -1256,8 +1258,8 @@ bool wait_while_table_is_used(THD *thd, TABLE *table, prelocked mode, e.g. if we do CREATE TABLE .. SELECT f1(); */ -void drop_open_table(THD *thd, TABLE *table, const char *db_name, - const char *table_name) +void drop_open_table(THD *thd, TABLE *table, const LEX_CSTRING *db_name, + const LEX_CSTRING *table_name) { DBUG_ENTER("drop_open_table"); if (table->s->tmp_table) @@ -1270,7 +1272,7 @@ void drop_open_table(THD *thd, TABLE *table, const char *db_name, table->file->extra(HA_EXTRA_PREPARE_FOR_DROP); close_thread_table(thd, &thd->open_tables); /* Remove the table share from the table cache. */ - tdc_remove_table(thd, TDC_RT_REMOVE_ALL, db_name, table_name, + tdc_remove_table(thd, TDC_RT_REMOVE_ALL, db_name->str, table_name->str, FALSE); /* Remove the table from the storage engine and rm the .frm. */ quick_rm_table(thd, table_type, db_name, table_name, 0); @@ -1507,7 +1509,7 @@ bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx) TABLE *table; const char *key; uint key_length; - const char *alias= table_list->alias; + const char *alias= table_list->alias.str; uint flags= ot_ctx->get_flags(); MDL_ticket *mdl_ticket; TABLE_SHARE *share; @@ -1628,13 +1630,13 @@ bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx) to deadlocks) it should be disallowed. */ if (thd->mdl_context.is_lock_owner(MDL_key::TABLE, - table_list->db, - table_list->table_name, + table_list->db.str, + table_list->table_name.str, MDL_SHARED)) { char path[FN_REFLEN + 1]; build_table_filename(path, sizeof(path) - 1, - table_list->db, table_list->table_name, reg_ext, 0); + table_list->db.str, table_list->table_name.str, reg_ext, 0); /* Note that we can't be 100% sure that it is a view since it's possible that we either simply have not found unused TABLE @@ -1669,7 +1671,7 @@ bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx) locked tables list was created. */ if (thd->locked_tables_mode == LTM_PRELOCKED) - my_error(ER_NO_SUCH_TABLE, MYF(0), table_list->db, table_list->alias); + my_error(ER_NO_SUCH_TABLE, MYF(0), table_list->db.str, table_list->alias.str); else my_error(ER_TABLE_NOT_LOCKED, MYF(0), alias); DBUG_RETURN(TRUE); @@ -1755,7 +1757,7 @@ bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx) if (table_list->open_strategy == TABLE_LIST::OPEN_IF_EXISTS) { - if (!ha_table_exists(thd, table_list->db, table_list->table_name)) + if (!ha_table_exists(thd, &table_list->db, &table_list->table_name)) DBUG_RETURN(FALSE); } else if (table_list->open_strategy == TABLE_LIST::OPEN_STUB) @@ -1818,7 +1820,8 @@ retry_share: } if (table_list->sequence) { - my_error(ER_NOT_SEQUENCE, MYF(0), table_list->db, table_list->alias); + my_error(ER_NOT_SEQUENCE, MYF(0), table_list->db.str, + table_list->alias.str); goto err_lock; } /* @@ -1865,8 +1868,8 @@ retry_share: bool wait_result; thd->push_internal_handler(&mdl_deadlock_handler); - wait_result= tdc_wait_for_old_version(thd, table_list->db, - table_list->table_name, + wait_result= tdc_wait_for_old_version(thd, table_list->db.str, + table_list->table_name.str, ot_ctx->get_timeout(), mdl_ticket->get_deadlock_weight()); thd->pop_internal_handler(); @@ -1914,7 +1917,7 @@ retry_share: if (!(table=(TABLE*) my_malloc(sizeof(*table),MYF(MY_WME)))) goto err_lock; - error= open_table_from_share(thd, share, alias, + error= open_table_from_share(thd, share, &table_list->alias, HA_OPEN_KEYFILE | HA_TRY_READ_ONLY, EXTRA_RECORD, thd->open_options, table, FALSE, @@ -1983,7 +1986,7 @@ retry_share: #endif if (table_list->sequence && table->s->table_type != TABLE_TYPE_SEQUENCE) { - my_error(ER_NOT_SEQUENCE, MYF(0), table_list->db, table_list->alias); + my_error(ER_NOT_SEQUENCE, MYF(0), table_list->db.str, table_list->alias.str); DBUG_RETURN(true); } @@ -2111,28 +2114,30 @@ Locked_tables_list::init_locked_tables(THD *thd) table= table->next, m_locked_tables_count++) { TABLE_LIST *src_table_list= table->pos_in_table_list; - char *db, *table_name, *alias; - size_t db_len= table->s->db.length; - size_t table_name_len= table->s->table_name.length; - size_t alias_len= table->alias.length(); + LEX_CSTRING db, table_name, alias; + + db.length= table->s->db.length; + table_name.length= table->s->table_name.length; + alias.length= table->alias.length(); TABLE_LIST *dst_table_list; if (! multi_alloc_root(&m_locked_tables_root, &dst_table_list, sizeof(*dst_table_list), - &db, db_len + 1, - &table_name, table_name_len + 1, - &alias, alias_len + 1, + &db.str, (size_t) db.length + 1, + &table_name.str, (size_t) table_name.length + 1, + &alias.str, (size_t) alias.length + 1, NullS)) { reset(); return TRUE; } - memcpy(db, table->s->db.str, db_len + 1); - memcpy(table_name, table->s->table_name.str, table_name_len + 1); - strmake(alias, table->alias.ptr(), alias_len); - dst_table_list->init_one_table(db, db_len, table_name, table_name_len, - alias, table->reginfo.lock_type); + memcpy((char*) db.str, table->s->db.str, db.length + 1); + memcpy((char*) table_name.str, table->s->table_name.str, + table_name.length + 1); + memcpy((char*) alias.str, table->alias.c_ptr(), alias.length + 1); + dst_table_list->init_one_table(&db, &table_name, + &alias, table->reginfo.lock_type); dst_table_list->table= table; dst_table_list->mdl_request.ticket= src_table_list->mdl_request.ticket; @@ -2467,7 +2472,7 @@ bool Locked_tables_list::restore_lock(THD *thd, TABLE_LIST *dst_table_list, { MYSQL_LOCK *merged_lock; DBUG_ENTER("restore_lock"); - DBUG_ASSERT(!strcmp(dst_table_list->table_name, table->s->table_name.str)); + DBUG_ASSERT(!strcmp(dst_table_list->table_name.str, table->s->table_name.str)); /* Ensure we have the memory to add the table back */ if (!(merged_lock= mysql_lock_merge(thd->lock, lock))) @@ -2696,8 +2701,8 @@ ret: static bool open_table_entry_fini(THD *thd, TABLE_SHARE *share, TABLE *entry) { - if (Table_triggers_list::check_n_load(thd, share->db.str, - share->table_name.str, entry, 0)) + if (Table_triggers_list::check_n_load(thd, &share->db, + &share->table_name, entry, 0)) return TRUE; /* @@ -2714,10 +2719,9 @@ static bool open_table_entry_fini(THD *thd, TABLE_SHARE *share, TABLE *entry) query.length(0); query.append("DELETE FROM "); - append_identifier(thd, &query, share->db.str, share->db.length); + append_identifier(thd, &query, &share->db); query.append("."); - append_identifier(thd, &query, share->table_name.str, - share->table_name.length); + append_identifier(thd, &query, &share->table_name); /* we bypass thd->binlog_query() here, @@ -2753,7 +2757,7 @@ static bool auto_repair_table(THD *thd, TABLE_LIST *table_list) DBUG_ASSERT(! share->is_view); - if (open_table_from_share(thd, share, table_list->alias, + if (open_table_from_share(thd, share, &table_list->alias, HA_OPEN_KEYFILE | HA_TRY_READ_ONLY, EXTRA_RECORD, ha_open_options | HA_OPEN_FOR_REPAIR, @@ -2778,7 +2782,7 @@ static bool auto_repair_table(THD *thd, TABLE_LIST *table_list) tdc_release_share(share); /* Remove the repaired share from the table cache. */ tdc_remove_table(thd, TDC_RT_REMOVE_ALL, - table_list->db, table_list->table_name, + table_list->db.str, table_list->table_name.str, FALSE); end_free: my_free(entry); @@ -2881,10 +2885,7 @@ request_backoff_action(enum_open_table_action action_arg, m_failed_table= (TABLE_LIST*) m_thd->alloc(sizeof(TABLE_LIST)); if (m_failed_table == NULL) return TRUE; - m_failed_table->init_one_table(table->db, table->db_length, - table->table_name, - table->table_name_length, - table->alias, TL_WRITE); + m_failed_table->init_one_table(&table->db, &table->table_name, &table->alias, TL_WRITE); m_failed_table->open_strategy= table->open_strategy; m_failed_table->mdl_request.set_type(MDL_EXCLUSIVE); } @@ -2953,8 +2954,8 @@ Open_table_context::recover_from_failed_open() get_timeout(), 0))) break; - tdc_remove_table(m_thd, TDC_RT_REMOVE_ALL, m_failed_table->db, - m_failed_table->table_name, FALSE); + tdc_remove_table(m_thd, TDC_RT_REMOVE_ALL, m_failed_table->db.str, + m_failed_table->table_name.str, FALSE); m_thd->get_stmt_da()->clear_warning_info(m_thd->query_id); m_thd->clear_error(); // Clear error message @@ -2989,8 +2990,8 @@ Open_table_context::recover_from_failed_open() get_timeout(), 0))) break; - tdc_remove_table(m_thd, TDC_RT_REMOVE_ALL, m_failed_table->db, - m_failed_table->table_name, FALSE); + tdc_remove_table(m_thd, TDC_RT_REMOVE_ALL, m_failed_table->db.str, + m_failed_table->table_name.str, FALSE); result= auto_repair_table(m_thd, m_failed_table); /* @@ -3310,10 +3311,8 @@ open_and_process_table(THD *thd, LEX *lex, TABLE_LIST *tables, obtain proper metadata locks and do other necessary steps like stored routine processing. */ - tables->db= tables->view_db.str; - tables->db_length= tables->view_db.length; - tables->table_name= tables->view_name.str; - tables->table_name_length= tables->view_name.length; + tables->db= tables->view_db; + tables->table_name= tables->view_name; } else if (tables->select_lex) { @@ -3370,7 +3369,7 @@ open_and_process_table(THD *thd, LEX *lex, TABLE_LIST *tables, goto end; } DBUG_PRINT("tcache", ("opening table: '%s'.'%s' item: %p", - tables->db, tables->table_name, tables)); //psergey: invalid read of size 1 here + tables->db.str, tables->table_name.str, tables)); (*counter)++; /* @@ -3386,7 +3385,7 @@ open_and_process_table(THD *thd, LEX *lex, TABLE_LIST *tables, DBUG_ASSERT(is_temporary_table(tables) || tables->table->s->sequence); if (tables->sequence && tables->table->s->table_type != TABLE_TYPE_SEQUENCE) { - my_error(ER_NOT_SEQUENCE, MYF(0), tables->db, tables->alias); + my_error(ER_NOT_SEQUENCE, MYF(0), tables->db.str, tables->alias.str); DBUG_RETURN(true); } } @@ -3489,7 +3488,7 @@ open_and_process_table(THD *thd, LEX *lex, TABLE_LIST *tables, if (! ot_ctx->can_recover_from_failed_open() && safe_to_ignore_table) { DBUG_PRINT("info", ("open_table: ignoring table '%s'.'%s'", - tables->db, tables->alias)); + tables->db.str, tables->alias.str)); error= FALSE; } goto end; @@ -3712,7 +3711,7 @@ lock_table_names(THD *thd, const DDL_options_st &options, MDL_request *schema_request= new (thd->mem_root) MDL_request; if (schema_request == NULL) DBUG_RETURN(TRUE); - schema_request->init(MDL_key::SCHEMA, table->db, "", + schema_request->init(MDL_key::SCHEMA, table->db.str, "", MDL_INTENTION_EXCLUSIVE, MDL_TRANSACTION); mdl_requests.push_front(schema_request); @@ -3763,17 +3762,17 @@ lock_table_names(THD *thd, const DDL_options_st &options, We come here in the case of lock timeout when executing CREATE TABLE. Verify that table does exist (it usually does, as we got a lock conflict) */ - if (ha_table_exists(thd, tables_start->db, tables_start->table_name)) + if (ha_table_exists(thd, &tables_start->db, &tables_start->table_name)) { if (options.if_not_exists()) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_TABLE_EXISTS_ERROR, ER_THD(thd, ER_TABLE_EXISTS_ERROR), - tables_start->table_name); + tables_start->table_name.str); } else - my_error(ER_TABLE_EXISTS_ERROR, MYF(0), tables_start->table_name); + my_error(ER_TABLE_EXISTS_ERROR, MYF(0), tables_start->table_name.str); DBUG_RETURN(TRUE); } /* @@ -3847,7 +3846,7 @@ open_tables_check_upgradable_mdl(THD *thd, TABLE_LIST *tables_start, Note that find_table_for_mdl_upgrade() will report an error if no suitable ticket is found. */ - if (!find_table_for_mdl_upgrade(thd, table->db, table->table_name, false)) + if (!find_table_for_mdl_upgrade(thd, table->db.str, table->table_name.str, false)) return TRUE; } @@ -4163,7 +4162,7 @@ restart: (*start)->table && (*start)->table->file->ht == myisam_hton && wsrep_thd_exec_mode(thd) == LOCAL_STATE && - !is_stat_table((*start)->db, (*start)->alias) && + !is_stat_table(&(*start)->db, &(*start)->alias) && thd->get_command() != COM_STMT_PREPARE && ((thd->lex->sql_command == SQLCOM_INSERT || thd->lex->sql_command == SQLCOM_INSERT_SELECT || @@ -4252,8 +4251,8 @@ static bool table_already_fk_prelocked(TABLE_LIST *tl, LEX_CSTRING *db, { if (tl->lock_type >= lock_type && tl->prelocking_placeholder == TABLE_LIST::PRELOCK_FK && - strcmp(tl->db, db->str) == 0 && - strcmp(tl->table_name, table->str) == 0) + strcmp(tl->db.str, db->str) == 0 && + strcmp(tl->table_name.str, table->str) == 0) return true; } return false; @@ -4265,7 +4264,7 @@ static bool internal_table_exists(TABLE_LIST *global_list, { do { - if (global_list->table_name == table_name) + if (global_list->table_name.str == table_name) return 1; } while ((global_list= global_list->next_global)); return 0; @@ -4284,16 +4283,14 @@ add_internal_tables(THD *thd, Query_tables_list *prelocking_ctx, Skip table if already in the list. Can happen with prepared statements */ if (tables->next_local && - internal_table_exists(global_table_list, tables->table_name)) + internal_table_exists(global_table_list, tables->table_name.str)) continue; TABLE_LIST *tl= (TABLE_LIST *) thd->alloc(sizeof(TABLE_LIST)); if (!tl) return TRUE; - tl->init_one_table_for_prelocking(tables->db, - strlen(tables->db), - tables->table_name, - strlen(tables->table_name), + tl->init_one_table_for_prelocking(&tables->db, + &tables->table_name, NULL, tables->lock_type, TABLE_LIST::PRELOCK_NONE, 0, 0, @@ -4389,10 +4386,8 @@ handle_table(THD *thd, Query_tables_list *prelocking_ctx, continue; TABLE_LIST *tl= (TABLE_LIST *) thd->alloc(sizeof(TABLE_LIST)); - tl->init_one_table_for_prelocking(fk->foreign_db->str, - fk->foreign_db->length, - fk->foreign_table->str, - fk->foreign_table->length, + tl->init_one_table_for_prelocking(fk->foreign_db, + fk->foreign_table, NULL, lock_type, TABLE_LIST::PRELOCK_FK, table_list->belong_to_view, op, @@ -5436,7 +5431,7 @@ find_field_in_view(THD *thd, TABLE_LIST *table_list, DBUG_ENTER("find_field_in_view"); DBUG_PRINT("enter", ("view: '%s', field name: '%s', item name: '%s', ref %p", - table_list->alias, name, item_name, ref)); + table_list->alias.str, name, item_name, ref)); Field_iterator_view field_it; field_it.set(table_list); Query_arena *arena= 0, backup; @@ -5704,6 +5699,7 @@ find_field_in_table(THD *thd, TABLE *table, const char *name, uint length, item_name [in] name of item if it will be created (VIEW) db_name [in] optional database name that qualifies the table_name [in] optional table name that qualifies the field + 0 for non-qualified field in natural joins ref [in/out] if 'name' is resolved to a view field, ref is set to point to the found view field check_privileges [in] check privileges @@ -5747,12 +5743,12 @@ find_field_in_table_ref(THD *thd, TABLE_LIST *table_list, { Field *fld; DBUG_ENTER("find_field_in_table_ref"); - DBUG_ASSERT(table_list->alias); + DBUG_ASSERT(table_list->alias.str); DBUG_ASSERT(name); DBUG_ASSERT(item_name); DBUG_PRINT("enter", ("table: '%s' field name: '%s' item name: '%s' ref %p", - table_list->alias, name, item_name, ref)); + table_list->alias.str, name, item_name, ref)); /* Check that the table and database that qualify the current field name @@ -5768,9 +5764,13 @@ find_field_in_table_ref(THD *thd, TABLE_LIST *table_list, inside the view, but we want to search directly in the view columns which are represented as a 'field_translation'. - TODO: Ensure that table_name, db_name and tables->db always points to - something ! + tables->db.str may be 0 if we are preparing a statement + db_name is 0 if item doesn't have a db name + table_name is 0 if item doesn't have a specified table_name */ + if (db_name && !db_name[0]) + db_name= 0; // Simpler test later + if (/* Exclude nested joins. */ (!table_list->nested_join || /* Include merge views and information schema tables. */ @@ -5780,12 +5780,12 @@ find_field_in_table_ref(THD *thd, TABLE_LIST *table_list, to search. */ table_name && table_name[0] && - (my_strcasecmp(table_alias_charset, table_list->alias, table_name) || - (db_name && db_name[0] && (!table_list->db || !table_list->db[0])) || - (db_name && db_name[0] && table_list->db && table_list->db[0] && + (my_strcasecmp(table_alias_charset, table_list->alias.str, table_name) || + (db_name && (!table_list->db.str || !table_list->db.str[0])) || + (db_name && table_list->db.str && table_list->db.str[0] && (table_list->schema_table ? - my_strcasecmp(system_charset_info, db_name, table_list->db) : - strcmp(db_name, table_list->db))))) + my_strcasecmp(system_charset_info, db_name, table_list->db.str) : + strcmp(db_name, table_list->db.str))))) DBUG_RETURN(0); /* @@ -6549,7 +6549,7 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2, DBUG_ENTER("mark_common_columns"); DBUG_PRINT("info", ("operand_1: %s operand_2: %s", - table_ref_1->alias, table_ref_2->alias)); + table_ref_1->alias.str, table_ref_2->alias.str)); *found_using_fields= 0; arena= thd->activate_stmt_arena_if_needed(&backup); @@ -6570,7 +6570,7 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2, is_using_column_1= using_fields && test_if_string_in_list(field_name_1->str, using_fields); DBUG_PRINT ("info", ("field_name_1=%s.%s", - nj_col_1->table_name() ? nj_col_1->table_name() : "", + nj_col_1->safe_table_name(), field_name_1->str)); /* @@ -6589,8 +6589,7 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2, goto err; cur_field_name_2= cur_nj_col_2->name(); DBUG_PRINT ("info", ("cur_field_name_2=%s.%s", - cur_nj_col_2->table_name() ? - cur_nj_col_2->table_name() : "", + cur_nj_col_2->safe_table_name(), cur_field_name_2->str)); /* @@ -6700,11 +6699,9 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2, nj_col_1->is_common= nj_col_2->is_common= TRUE; DBUG_PRINT ("info", ("%s.%s and %s.%s are common", - nj_col_1->table_name() ? - nj_col_1->table_name() : "", + nj_col_1->safe_table_name(), nj_col_1->name()->str, - nj_col_2->table_name() ? - nj_col_2->table_name() : "", + nj_col_2->safe_table_name(), nj_col_2->name()->str)); if (field_1) @@ -7624,7 +7621,7 @@ bool get_key_map_from_key_list(key_map *map, TABLE *table, 0) { my_error(ER_KEY_DOES_NOT_EXITS, MYF(0), name->c_ptr(), - table->pos_in_table_list->alias); + table->pos_in_table_list->alias.str); map->set_all(); return 1; } @@ -7695,8 +7692,8 @@ insert_fields(THD *thd, Name_resolution_context *context, const char *db_name, DBUG_ASSERT(tables->is_leaf_for_name_resolution()); if ((table_name && my_strcasecmp(table_alias_charset, table_name, - tables->alias)) || - (db_name && strcmp(tables->db,db_name))) + tables->alias.str)) || + (db_name && strcmp(tables->db.str, db_name))) continue; #ifndef NO_EMBEDDED_ACCESS_CHECKS @@ -7875,13 +7872,13 @@ insert_fields(THD *thd, Name_resolution_context *context, const char *db_name, */ if (!table_name) my_error(ER_NO_TABLES_USED, MYF(0)); - else if (!db_name && !thd->db) + else if (!db_name && !thd->db.str) my_error(ER_NO_DB_ERROR, MYF(0)); else { char name[FN_REFLEN]; my_snprintf(name, sizeof(name), "%s.%s", - db_name ? db_name : thd->db, table_name); + db_name ? db_name : thd->get_db(), table_name); my_error(ER_BAD_TABLE_ERROR, MYF(0), name); } diff --git a/sql/sql_base.h b/sql/sql_base.h index bf140cb5d17..f2411c8b7ea 100644 --- a/sql/sql_base.h +++ b/sql/sql_base.h @@ -136,8 +136,8 @@ void close_tables_for_reopen(THD *thd, TABLE_LIST **tables, const MDL_savepoint &start_of_statement_svp); TABLE_LIST *find_table_in_list(TABLE_LIST *table, TABLE_LIST *TABLE_LIST::*link, - const char *db_name, - const char *table_name); + const LEX_CSTRING *db_name, + const LEX_CSTRING *table_name); void close_thread_tables(THD *thd); void switch_to_nullable_trigger_fields(List<Item> &items, TABLE *); void switch_defaults_to_nullable_trigger_fields(TABLE *table); @@ -205,8 +205,8 @@ bool setup_tables_and_check_access(THD *thd, bool wait_while_table_is_used(THD *thd, TABLE *table, enum ha_extra_function function); -void drop_open_table(THD *thd, TABLE *table, const char *db_name, - const char *table_name); +void drop_open_table(THD *thd, TABLE *table, const LEX_CSTRING *db_name, + const LEX_CSTRING *table_name); void update_non_unique_table_error(TABLE_LIST *update, const char *operation, TABLE_LIST *duplicate); @@ -344,22 +344,13 @@ inline void setup_table_map(TABLE *table, TABLE_LIST *table_list, uint tablenr) } inline TABLE_LIST *find_table_in_global_list(TABLE_LIST *table, - const char *db_name, - const char *table_name) + LEX_CSTRING *db_name, + LEX_CSTRING *table_name) { return find_table_in_list(table, &TABLE_LIST::next_global, db_name, table_name); } -inline TABLE_LIST *find_table_in_local_list(TABLE_LIST *table, - const char *db_name, - const char *table_name) -{ - return find_table_in_list(table, &TABLE_LIST::next_local, - db_name, table_name); -} - - inline bool setup_fields_with_no_wrap(THD *thd, Ref_ptr_array ref_pointer_array, List<Item> &item, enum_mark_columns mark_used_columns, diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index 766aa8099ba..c340f4afc8b 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -1498,18 +1498,18 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d", query_length= thd->base_query.length(); /* Key is query + database + flag */ - if (thd->db_length) + if (thd->db.length) { memcpy((char*) (query + query_length + 1 + QUERY_CACHE_DB_LENGTH_SIZE), - thd->db, thd->db_length); + thd->db.str, thd->db.length); DBUG_PRINT("qcache", ("database: %s length: %u", - thd->db, (unsigned) thd->db_length)); + thd->db.str, (unsigned) thd->db.length)); } else { DBUG_PRINT("qcache", ("No active database")); } - tot_length= (query_length + thd->db_length + 1 + + tot_length= (query_length + thd->db.length + 1 + QUERY_CACHE_DB_LENGTH_SIZE + QUERY_CACHE_FLAGS_SIZE); /* We should only copy structure (don't use it location directly) @@ -1693,7 +1693,7 @@ size_t build_normalized_name(char *buff, size_t bufflen, In case of -1, no error is sent to the client. *) The buffer must be allocated memory of size: - tot_length= query_length + thd->db_length + 1 + QUERY_CACHE_FLAGS_SIZE; + tot_length= query_length + thd->db.length + 1 + QUERY_CACHE_FLAGS_SIZE; */ int @@ -1852,7 +1852,7 @@ Query_cache::send_result_to_client(THD *thd, char *org_sql, uint query_length) as the previous one. */ size_t db_len= uint2korr(sql_end+1); - if (thd->db_length != db_len) + if (thd->db.length != db_len) { /* We should probably reallocate the buffer in this case, @@ -1886,7 +1886,7 @@ Query_cache::send_result_to_client(THD *thd, char *org_sql, uint query_length) if (found_brace) sql= found_brace; make_base_query(&thd->base_query, sql, (size_t) (sql_end - sql), - thd->db_length + 1 + QUERY_CACHE_DB_LENGTH_SIZE + + thd->db.length + 1 + QUERY_CACHE_DB_LENGTH_SIZE + QUERY_CACHE_FLAGS_SIZE); sql= thd->base_query.ptr(); query_length= thd->base_query.length(); @@ -1898,14 +1898,14 @@ Query_cache::send_result_to_client(THD *thd, char *org_sql, uint query_length) } tot_length= (query_length + 1 + QUERY_CACHE_DB_LENGTH_SIZE + - thd->db_length + QUERY_CACHE_FLAGS_SIZE); + thd->db.length + QUERY_CACHE_FLAGS_SIZE); - if (thd->db_length) + if (thd->db.length) { memcpy((uchar*) sql + query_length + 1 + QUERY_CACHE_DB_LENGTH_SIZE, - thd->db, thd->db_length); + thd->db.str, thd->db.length); DBUG_PRINT("qcache", ("database: '%s' length: %u", - thd->db, (uint) thd->db_length)); + thd->db.str, (uint) thd->db.length)); } else { @@ -2061,14 +2061,17 @@ lookup: } bzero((char*) &table_list,sizeof(table_list)); - table_list.db = table->db(); - table_list.alias= table_list.table_name= table->table(); + table_list.db.str= table->db(); + table_list.db.length= strlen(table_list.db.str); + table_list.alias.str= table_list.table_name.str= table->table(); + table_list.alias.length= table_list.table_name.length= strlen(table->table()); + #ifndef NO_EMBEDDED_ACCESS_CHECKS if (check_table_access(thd,SELECT_ACL,&table_list, FALSE, 1,TRUE)) { DBUG_PRINT("qcache", ("probably no SELECT access to %s.%s => return to normal processing", - table_list.db, table_list.alias)); + table_list.db.str, table_list.alias.str)); unlock(); thd->query_cache_is_applicable= 0; // Query can't be cached thd->lex->safe_to_cache_query= 0; // For prepared statements @@ -2078,7 +2081,7 @@ lookup: if (table_list.grant.want_privilege) { DBUG_PRINT("qcache", ("Need to check column privileges for %s.%s", - table_list.db, table_list.alias)); + table_list.db.str, table_list.alias.str)); BLOCK_UNLOCK_RD(query_block); thd->query_cache_is_applicable= 0; // Query can't be cached thd->lex->safe_to_cache_query= 0; // For prepared statements @@ -2138,7 +2141,7 @@ lookup: } else DBUG_PRINT("qcache", ("handler allow caching %s,%s", - table_list.db, table_list.alias)); + table_list.db.str, table_list.alias.str)); } move_to_query_list_end(query_block); hits++; @@ -3397,7 +3400,7 @@ Query_cache::register_tables_from_list(THD *thd, TABLE_LIST *tables_used, if (!insert_table(thd, tables_used->table->s->table_cache_key.length, tables_used->table->s->table_cache_key.str, (*block_table), - tables_used->db_length, 0, + tables_used->db.length, 0, tables_used->table->file->table_cache_type(), tables_used->callback_func, tables_used->engine_data, @@ -4053,7 +4056,7 @@ Query_cache::process_and_count_tables(THD *thd, TABLE_LIST *tables_used, } if (tables_used->derived) { - DBUG_PRINT("qcache", ("table: %s", tables_used->alias)); + DBUG_PRINT("qcache", ("table: %s", tables_used->alias.str)); table_count--; DBUG_PRINT("qcache", ("derived table skipped")); continue; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 372f2cc9ebb..82d86b9404a 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1475,6 +1475,75 @@ void THD::change_user(void) sp_cache_clear(&sp_func_cache); } +/** + Change default database + + @note This is coded to have as few instructions as possible under + LOCK_thd_data +*/ + +bool THD::set_db(const LEX_CSTRING *new_db) +{ + bool result= 0; + /* + Acquiring mutex LOCK_thd_data as we either free the memory allocated + for the database and reallocating the memory for the new db or memcpy + the new_db to the db. + */ + /* Do not reallocate memory if current chunk is big enough. */ + if (db.str && new_db->str && db.length >= new_db->length) + { + mysql_mutex_lock(&LOCK_thd_data); + db.length= new_db->length; + memcpy((char*) db.str, new_db->str, new_db->length+1); + mysql_mutex_unlock(&LOCK_thd_data); + } + else + { + const char *org_db= db.str; + const char *tmp= NULL; + if (new_db->str) + { + if (!(tmp= my_strndup(new_db->str, new_db->length, MYF(MY_WME | ME_FATALERROR)))) + result= 1; + } + + mysql_mutex_lock(&LOCK_thd_data); + db.str= tmp; + db.length= tmp ? new_db->length : 0; + mysql_mutex_unlock(&LOCK_thd_data); + my_free((char*) org_db); + } + PSI_CALL_set_thread_db(db.str, (int) db.length); + return result; +} + + +/** + Set the current database + + @param new_db a pointer to the new database name. + @param new_db_len length of the new database name. + + @note This operation just sets {db, db_length}. Switching the current + database usually involves other actions, like switching other database + attributes including security context. In the future, this operation + will be made private and more convenient interface will be provided. +*/ + +void THD::reset_db(const LEX_CSTRING *new_db) +{ + if (new_db->str != db.str || new_db->length != db.length) + { + if (db.str != 0) + DBUG_PRINT("QQ", ("Overwriting: %p", db.str)); + mysql_mutex_lock(&LOCK_thd_data); + db= *new_db; + mysql_mutex_unlock(&LOCK_thd_data); + PSI_CALL_set_thread_db(db.str, (int) db.length); + } +} + /* Do operations that may take a long time */ @@ -1553,8 +1622,8 @@ void THD::cleanup(void) void THD::free_connection() { DBUG_ASSERT(free_connection_done == 0); - my_free(db); - db= NULL; + my_free((char*) db.str); + db= null_clex_str; #ifndef EMBEDDED_LIBRARY if (net.vio) vio_delete(net.vio); @@ -3043,8 +3112,7 @@ static File create_file(THD *thd, char *path, sql_exchange *exchange, if (!dirname_length(exchange->file_name)) { - strxnmov(path, FN_REFLEN-1, mysql_real_data_home, thd->db ? thd->db : "", - NullS); + strxnmov(path, FN_REFLEN-1, mysql_real_data_home, thd->get_db(), NullS); (void) fn_format(path, exchange->file_name, path, "", option); } else @@ -3737,10 +3805,9 @@ Statement::Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg, id(id_arg), mark_used_columns(MARK_COLUMNS_READ), lex(lex_arg), - db(NULL), - db_length(0) + db(null_clex_str) { - name.str= NULL; + name= null_clex_str; } @@ -4077,7 +4144,7 @@ bool select_materialize_with_stats:: create_result_table(THD *thd_arg, List<Item> *column_types, bool is_union_distinct, ulonglong options, - const char *table_alias, bool bit_fields_as_long, + const LEX_CSTRING *table_alias, bool bit_fields_as_long, bool create_table, bool keep_row_order, uint hidden) @@ -4088,7 +4155,7 @@ create_result_table(THD *thd_arg, List<Item> *column_types, if (! (table= create_tmp_table(thd_arg, &tmp_table_param, *column_types, (ORDER*) 0, is_union_distinct, 1, - options, HA_POS_ERROR, (char*) table_alias, + options, HA_POS_ERROR, table_alias, !create_table, keep_row_order))) return TRUE; @@ -4663,8 +4730,10 @@ TABLE *open_purge_table(THD *thd, const char *db, size_t dblen, Open_table_context ot_ctx(thd, 0); TABLE_LIST *tl= (TABLE_LIST*)thd->alloc(sizeof(TABLE_LIST)); + LEX_CSTRING db_name= {db, dblen }; + LEX_CSTRING table_name= { tb, tblen }; - tl->init_one_table(db, dblen, tb, tblen, tb, TL_READ); + tl->init_one_table(&db_name, &table_name, 0, TL_READ); tl->i_s_requested_object= OPEN_TABLE_ONLY; bool error= open_table(thd, tl, &ot_ctx); @@ -5057,7 +5126,7 @@ extern "C" void thd_mark_transaction_to_rollback(MYSQL_THD thd, bool all) extern "C" bool thd_binlog_filter_ok(const MYSQL_THD thd) { - return binlog_filter->db_ok(thd->db); + return binlog_filter->db_ok(thd->db.str); } /* @@ -5959,7 +6028,7 @@ int THD::decide_logging_format(TABLE_LIST *tables) */ if (mysql_bin_log.is_open() && (variables.option_bits & OPTION_BIN_LOG) && !(wsrep_binlog_format() == BINLOG_FORMAT_STMT && - !binlog_filter->db_ok(db))) + !binlog_filter->db_ok(db.str))) { if (is_bulk_op()) @@ -6062,7 +6131,7 @@ int THD::decide_logging_format(TABLE_LIST *tables) handler::Table_flags const flags= table->table->file->ha_table_flags(); DBUG_PRINT("info", ("table: %s; ha_table_flags: 0x%llx", - table->table_name, flags)); + table->table_name.str, flags)); if (table->table->s->no_replicate) { @@ -6366,7 +6435,7 @@ int THD::decide_logging_format(TABLE_LIST *tables) if (table->table->file->ht->db_type == DB_TYPE_BLACKHOLE_DB && table->lock_type >= TL_WRITE_ALLOW_WRITE) { - table_names.append(table->table_name); + table_names.append(&table->table_name); table_names.append(","); } } @@ -6398,7 +6467,7 @@ int THD::decide_logging_format(TABLE_LIST *tables) mysql_bin_log.is_open(), (variables.option_bits & OPTION_BIN_LOG), (uint) wsrep_binlog_format(), - binlog_filter->db_ok(db))); + binlog_filter->db_ok(db.str))); #endif DBUG_RETURN(0); diff --git a/sql/sql_class.h b/sql/sql_class.h index c9a790b44db..bb9ff766050 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1142,18 +1142,13 @@ public: /** Name of the current (default) database. - If there is the current (default) database, "db" contains its name. If - there is no current (default) database, "db" is NULL and "db_length" is - 0. In other words, "db", "db_length" must either be NULL, or contain a + If there is the current (default) database, "db.str" contains its name. If + there is no current (default) database, "db.str" is NULL and "db.length" is + 0. In other words, db must either be NULL, or contain a valid database name. - - @note this attribute is set and alloced by the slave SQL thread (for - the THD of that thread); that thread is (and must remain, for now) the - only responsible for freeing this member. */ - char *db; - size_t db_length; + LEX_CSTRING db; /* This is set to 1 of last call to send_result_to_client() was ok */ my_bool query_cache_is_applicable; @@ -2242,7 +2237,7 @@ public: Protects THD data accessed from other threads: - thd->query and thd->query_length (used by SHOW ENGINE INNODB STATUS and SHOW PROCESSLIST - - thd->db and thd->db_length (used in SHOW PROCESSLIST) + - thd->db (used in SHOW PROCESSLIST) Is locked when THD is deleted. */ mysql_mutex_t LOCK_thd_data; @@ -4034,70 +4029,33 @@ public: @retval FALSE Success @retval TRUE Out-of-memory error */ - bool set_db(const char *new_db, size_t new_db_len) - { - /* - Acquiring mutex LOCK_thd_data as we either free the memory allocated - for the database and reallocating the memory for the new db or memcpy - the new_db to the db. - */ - mysql_mutex_lock(&LOCK_thd_data); - /* Do not reallocate memory if current chunk is big enough. */ - if (db && new_db && db_length >= new_db_len) - memcpy(db, new_db, new_db_len+1); - else - { - my_free(db); - if (new_db) - db= my_strndup(new_db, new_db_len, MYF(MY_WME | ME_FATALERROR)); - else - db= NULL; - } - db_length= db ? new_db_len : 0; - bool result= new_db && !db; - mysql_mutex_unlock(&LOCK_thd_data); - if (result) - PSI_CALL_set_thread_db(new_db, (int) new_db_len); - return result; - } + bool set_db(const LEX_CSTRING *new_db); - /** - Set the current database; use shallow copy of C-string. + /** Set the current database, without copying */ + void reset_db(const LEX_CSTRING *new_db); - @param new_db a pointer to the new database name. - @param new_db_len length of the new database name. - - @note This operation just sets {db, db_length}. Switching the current - database usually involves other actions, like switching other database - attributes including security context. In the future, this operation - will be made private and more convenient interface will be provided. - */ - void reset_db(char *new_db, size_t new_db_len) - { - if (new_db != db || new_db_len != db_length) - { - mysql_mutex_lock(&LOCK_thd_data); - db= new_db; - db_length= new_db_len; - mysql_mutex_unlock(&LOCK_thd_data); - PSI_CALL_set_thread_db(new_db, (int) new_db_len); - } - } /* Copy the current database to the argument. Use the current arena to allocate memory for a deep copy: current database may be freed after a statement is parsed but before it's executed. + + Can only be called by owner of thd (no mutex protection) */ - bool copy_db_to(const char **p_db, size_t *p_db_length) + bool copy_db_to(LEX_CSTRING *to) { - if (db == NULL) + if (db.str == NULL) { my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0)); return TRUE; } - *p_db= strmake(db, db_length); - *p_db_length= db_length; - return FALSE; + to->str= strmake(db.str, db.length); + to->length= db.length; + return to->str == NULL; /* True on error */ + } + /* Get db name or "". Use for printing current db */ + const char *get_db() + { + return db.str ? db.str : ""; } thd_scheduler event_scheduler; @@ -4357,7 +4315,7 @@ public: { Security_context *sctx= &main_security_ctx; sql_print_warning(ER_THD(this, ER_NEW_ABORTING_CONNECTION), - thread_id, (db ? db : "unconnected"), + thread_id, (db.str ? db.str : "unconnected"), sctx->user ? sctx->user : "unauthenticated", sctx->host_or_ip, reason); } @@ -4500,8 +4458,8 @@ public: bool open_temporary_tables(TABLE_LIST *tl); bool close_temporary_tables(); - bool rename_temporary_table(TABLE *table, const char *db, - const char *table_name); + bool rename_temporary_table(TABLE *table, const LEX_CSTRING *db, + const LEX_CSTRING *table_name); bool drop_temporary_table(TABLE *table, bool *is_trans, bool delete_table); bool rm_temporary_table(handlerton *hton, const char *path); void mark_tmp_tables_as_free_for_reuse(); @@ -5337,7 +5295,7 @@ public: void cleanup(); virtual bool create_result_table(THD *thd, List<Item> *column_types, bool is_distinct, ulonglong options, - const char *alias, + const LEX_CSTRING *alias, bool bit_fields_as_long, bool create_table, bool keep_row_order, @@ -5371,7 +5329,7 @@ class select_union_recursive :public select_unit int send_data(List<Item> &items); bool create_result_table(THD *thd, List<Item> *column_types, bool is_distinct, ulonglong options, - const char *alias, + const LEX_CSTRING *alias, bool bit_fields_as_long, bool create_table, bool keep_row_order, @@ -5538,7 +5496,7 @@ public: { tmp_table_param.init(); } bool create_result_table(THD *thd, List<Item> *column_types, bool is_distinct, ulonglong options, - const char *alias, + const LEX_CSTRING *alias, bool bit_fields_as_long, bool create_table, bool keep_row_order, @@ -6339,26 +6297,6 @@ public: } }; -/* Functions to compare if two lex strings are equal */ -inline bool lex_string_cmp(CHARSET_INFO *charset, - const LEX_CSTRING *a, - const LEX_CSTRING *b) -{ - return my_strcasecmp(charset, a->str, b->str); -} - -/* - Compare if two LEX_CSTRING are equal. Assumption is that - character set is ASCII (like for plugin names) -*/ -inline bool lex_string_eq(const LEX_CSTRING *a, - const LEX_CSTRING *b) -{ - if (a->length != b->length) - return 1; /* Different */ - return strcasecmp(a->str, b->str) != 0; -} - class Type_holder: public Sql_alloc, public Item_args, public Type_handler_hybrid_field_type, diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index 1e3994dea66..af9e2ad8b24 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -21,6 +21,7 @@ */ #include "mariadb.h" +#include "mysqld.h" #include "sql_priv.h" #ifndef __WIN__ #include <netdb.h> // getservbyname, servent @@ -1264,7 +1265,7 @@ void prepare_new_connection_state(THD* thd) if (packet_length != packet_error) my_error(ER_NEW_ABORTING_CONNECTION, MYF(0), thd->thread_id, - thd->db ? thd->db : "unconnected", + thd->db.str ? thd->db.str : "unconnected", sctx->user ? sctx->user : "unauthenticated", sctx->host_or_ip, "init_connect command failed"); thd->server_status&= ~SERVER_STATUS_CLEAR_SET; diff --git a/sql/sql_cte.cc b/sql/sql_cte.cc index 7da088cdfd5..9ff81a47d32 100644 --- a/sql/sql_cte.cc +++ b/sql/sql_cte.cc @@ -240,7 +240,7 @@ With_element *With_clause::find_table_def(TABLE_LIST *table, with_elem= with_elem->next) { if (my_strcasecmp(system_charset_info, with_elem->query_name->str, - table->table_name) == 0) + table->table_name.str) == 0) { table->set_derived(); return with_elem; diff --git a/sql/sql_cursor.cc b/sql/sql_cursor.cc index 864b64a9f28..b32571b2ed3 100644 --- a/sql/sql_cursor.cc +++ b/sql/sql_cursor.cc @@ -132,7 +132,7 @@ int mysql_open_cursor(THD *thd, select_result *result, MYSQL_QUERY_EXEC_START(thd->query(), thd->thread_id, - (char *) (thd->db ? thd->db : ""), + thd->get_db(), &thd->security_ctx->priv_user[0], (char *) thd->security_ctx->host_or_ip, 2); @@ -440,7 +440,7 @@ bool Select_materialize::send_result_set_metadata(List<Item> &list, uint flags) if (create_result_table(unit->thd, unit->get_column_types(true), FALSE, thd->variables.option_bits | TMP_TABLE_ALL_COLUMNS, - "", FALSE, TRUE, TRUE, 0)) + &empty_clex_str, FALSE, TRUE, TRUE, 0)) return TRUE; materialized_cursor= new (&table->mem_root) diff --git a/sql/sql_db.cc b/sql/sql_db.cc index f568db51b9c..417e3959e85 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -62,7 +62,7 @@ static void mysql_change_db_impl(THD *thd, LEX_CSTRING *new_db_name, ulong new_db_access, CHARSET_INFO *new_db_charset); -static bool mysql_rm_db_internal(THD *thd, const char *db, +static bool mysql_rm_db_internal(THD *thd, const LEX_CSTRING *db, bool if_exists, bool silent); @@ -94,12 +94,12 @@ typedef struct my_dbopt_st */ static inline bool -cmp_db_names(const char *db1_name, - const char *db2_name) +cmp_db_names(LEX_CSTRING *db1_name, const LEX_CSTRING *db2_name) { - return ((!db1_name && !db2_name) || - (db1_name && db2_name && - my_strcasecmp(table_alias_charset, db1_name, db2_name) == 0)); + return (db1_name->length == db2_name->length && + (db1_name->length == 0 || + my_strcasecmp(table_alias_charset, + db1_name->str, db2_name->str) == 0)); } @@ -523,7 +523,7 @@ CHARSET_INFO *get_default_db_collation(THD *thd, const char *db_name) { Schema_specification_st db_info; - if (thd->db != NULL && strcmp(db_name, thd->db) == 0) + if (thd->db.str != NULL && strcmp(db_name, thd->db.str) == 0) return thd->db_charset; load_db_opt_by_name(thd, db_name, &db_info); @@ -566,7 +566,7 @@ CHARSET_INFO *get_default_db_collation(THD *thd, const char *db_name) */ static int -mysql_create_db_internal(THD *thd, const char *db, +mysql_create_db_internal(THD *thd, const LEX_CSTRING *db, const DDL_options_st &options, Schema_specification_st *create_info, bool silent) @@ -579,18 +579,18 @@ mysql_create_db_internal(THD *thd, const char *db, /* do not create 'information_schema' db */ if (is_infoschema_db(db)) { - my_error(ER_DB_CREATE_EXISTS, MYF(0), db); + my_error(ER_DB_CREATE_EXISTS, MYF(0), db->str); DBUG_RETURN(-1); } - char db_tmp[SAFE_NAME_LEN]; - const char *dbnorm= normalize_db_name(db, db_tmp, sizeof(db_tmp)); + char db_tmp[SAFE_NAME_LEN+1]; + const char *dbnorm= normalize_db_name(db->str, db_tmp, sizeof(db_tmp)); if (lock_schema_name(thd, dbnorm)) DBUG_RETURN(-1); /* Check directory */ - path_len= build_table_filename(path, sizeof(path) - 1, db, "", "", 0); + path_len= build_table_filename(path, sizeof(path) - 1, db->str, "", "", 0); path[path_len-1]= 0; // Remove last '/' from path long affected_rows= 1; @@ -618,20 +618,20 @@ mysql_create_db_internal(THD *thd, const char *db, { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_DB_CREATE_EXISTS, ER_THD(thd, ER_DB_CREATE_EXISTS), - db); + db->str); affected_rows= 0; goto not_silent; } else { - my_error(ER_DB_CREATE_EXISTS, MYF(0), db); + my_error(ER_DB_CREATE_EXISTS, MYF(0), db->str); DBUG_RETURN(-1); } if (my_mkdir(path, 0777, MYF(0)) < 0) { - my_error(ER_CANT_CREATE_DB, MYF(0), db, my_errno); + my_error(ER_CANT_CREATE_DB, MYF(0), db->str, my_errno); DBUG_RETURN(-1); } @@ -687,8 +687,8 @@ not_silent: USE sisyfos; # Will give error on slave since # database does not exist. */ - qinfo.db = db; - qinfo.db_len = strlen(db); + qinfo.db = db->str; + qinfo.db_len = db->length; /* These DDL methods and logging are protected with the exclusive @@ -707,7 +707,7 @@ not_silent: /* db-name is already validated when we come here */ static bool -mysql_alter_db_internal(THD *thd, const char *db, +mysql_alter_db_internal(THD *thd, const LEX_CSTRING *db, Schema_specification_st *create_info) { char path[FN_REFLEN+16]; @@ -715,7 +715,7 @@ mysql_alter_db_internal(THD *thd, const char *db, int error= 0; DBUG_ENTER("mysql_alter_db"); - if (lock_schema_name(thd, db)) + if (lock_schema_name(thd, db->str)) DBUG_RETURN(TRUE); /* @@ -723,13 +723,13 @@ mysql_alter_db_internal(THD *thd, const char *db, We pass MY_DB_OPT_FILE as "extension" to avoid "table name to file name" encoding. */ - build_table_filename(path, sizeof(path) - 1, db, "", MY_DB_OPT_FILE, 0); + build_table_filename(path, sizeof(path) - 1, db->str, "", MY_DB_OPT_FILE, 0); if ((error=write_db_opt(thd, path, create_info))) goto exit; /* Change options if current database is being altered. */ - if (thd->db && !strcmp(thd->db,db)) + if (thd->db.str && !cmp(&thd->db, db)) { thd->db_charset= create_info->default_table_charset ? create_info->default_table_charset : @@ -747,8 +747,8 @@ mysql_alter_db_internal(THD *thd, const char *db, database" and not the threads current database, which is the default. */ - qinfo.db = db; - qinfo.db_len = strlen(db); + qinfo.db= db->str; + qinfo.db_len= db->length; /* These DDL methods and logging are protected with the exclusive @@ -764,7 +764,7 @@ exit: } -int mysql_create_db(THD *thd, const char *db, +int mysql_create_db(THD *thd, const LEX_CSTRING *db, const DDL_options_st &options, const Schema_specification_st *create_info) { @@ -777,7 +777,7 @@ int mysql_create_db(THD *thd, const char *db, } -bool mysql_alter_db(THD *thd, const char *db, +bool mysql_alter_db(THD *thd, const LEX_CSTRING *db, const Schema_specification_st *create_info) { /* @@ -805,7 +805,7 @@ bool mysql_alter_db(THD *thd, const char *db, */ static bool -mysql_rm_db_internal(THD *thd, const char *db, bool if_exists, bool silent) +mysql_rm_db_internal(THD *thd, const LEX_CSTRING *db, bool if_exists, bool silent) { ulong deleted_tables= 0; bool error= true, rm_mysql_schema; @@ -817,13 +817,13 @@ mysql_rm_db_internal(THD *thd, const char *db, bool if_exists, bool silent) Drop_table_error_handler err_handler; DBUG_ENTER("mysql_rm_db"); - char db_tmp[SAFE_NAME_LEN]; - const char *dbnorm= normalize_db_name(db, db_tmp, sizeof(db_tmp)); + char db_tmp[SAFE_NAME_LEN+1]; + const char *dbnorm= normalize_db_name(db->str, db_tmp, sizeof(db_tmp)); if (lock_schema_name(thd, dbnorm)) DBUG_RETURN(true); - length= build_table_filename(path, sizeof(path) - 1, db, "", "", 0); + length= build_table_filename(path, sizeof(path) - 1, db->str, "", "", 0); strmov(path+length, MY_DB_OPT_FILE); // Append db option file name del_dbopt(path); // Remove dboption hash entry /* @@ -846,14 +846,14 @@ mysql_rm_db_internal(THD *thd, const char *db, bool if_exists, bool silent) { if (!if_exists) { - my_error(ER_DB_DROP_EXISTS, MYF(0), db); + my_error(ER_DB_DROP_EXISTS, MYF(0), db->str); DBUG_RETURN(true); } else { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_DB_DROP_EXISTS, ER_THD(thd, ER_DB_DROP_EXISTS), - db); + db->str); error= false; goto update_binlog; } @@ -867,7 +867,7 @@ mysql_rm_db_internal(THD *thd, const char *db, bool if_exists, bool silent) This check is only needed if we are dropping the "mysql" database. */ if ((rm_mysql_schema= - (my_strcasecmp(system_charset_info, MYSQL_SCHEMA_NAME.str, db) == 0))) + (my_strcasecmp(system_charset_info, MYSQL_SCHEMA_NAME.str, db->str) == 0))) { for (table= tables; table; table= table->next_local) if (check_if_log_table(table, TRUE, "DROP")) @@ -884,11 +884,9 @@ mysql_rm_db_internal(THD *thd, const char *db, bool if_exists, bool silent) { for (table= tables; table; table= table->next_local) { - LEX_CSTRING db_name= { table->db, table->db_length }; - LEX_CSTRING table_name= { table->table_name, table->table_name_length }; if (table->open_type == OT_BASE_ONLY || !thd->find_temporary_table(table)) - (void) delete_statistics_for_table(thd, &db_name, &table_name); + (void) delete_statistics_for_table(thd, &table->db, &table->table_name); } } @@ -959,8 +957,8 @@ update_binlog: database" and not the threads current database, which is the default. */ - qinfo.db = db; - qinfo.db_len = strlen(db); + qinfo.db = db->str; + qinfo.db_len = db->length; /* These DDL methods and logging are protected with the exclusive @@ -980,13 +978,11 @@ update_binlog: { char *query, *query_pos, *query_end, *query_data_start; TABLE_LIST *tbl; - uint db_len; if (!(query= (char*) thd->alloc(MAX_DROP_TABLE_Q_LEN))) goto exit; /* not much else we can do */ query_pos= query_data_start= strmov(query,"DROP TABLE IF EXISTS "); query_end= query + MAX_DROP_TABLE_Q_LEN; - db_len= strlen(db); for (tbl= tables; tbl; tbl= tbl->next_local) { @@ -994,19 +990,20 @@ update_binlog: char quoted_name[FN_REFLEN+3]; // Only write drop table to the binlog for tables that no longer exist. - if (ha_table_exists(thd, tbl->db, tbl->table_name)) + if (ha_table_exists(thd, &tbl->db, &tbl->table_name)) continue; - my_snprintf(quoted_name, sizeof(quoted_name), quoted_string, - tbl->table_name); - tbl_name_len= strlen(quoted_name) + 1; /* +1 for the comma */ + tbl_name_len= my_snprintf(quoted_name, sizeof(quoted_name), + quoted_string, + tbl->table_name.str); + tbl_name_len++; /* +1 for the comma */ if (query_pos + tbl_name_len + 1 >= query_end) { /* These DDL methods and logging are protected with the exclusive metadata lock on the schema. */ - if (write_to_binlog(thd, query, (uint)(query_pos -1 - query), db, db_len)) + if (write_to_binlog(thd, query, (uint)(query_pos -1 - query), db->str, db->length)) { error= true; goto exit; @@ -1024,7 +1021,7 @@ update_binlog: These DDL methods and logging are protected with the exclusive metadata lock on the schema. */ - if (write_to_binlog(thd, query, (uint)(query_pos -1 - query), db, db_len)) + if (write_to_binlog(thd, query, (uint)(query_pos -1 - query), db->str, db->length)) { error= true; goto exit; @@ -1039,7 +1036,7 @@ exit: SELECT DATABASE() in the future). For this we free() thd->db and set it to 0. */ - if (thd->db && cmp_db_names(thd->db, db) && !error) + if (thd->db.str && cmp_db_names(&thd->db, db) && !error) { mysql_change_db_impl(thd, NULL, 0, thd->variables.collation_server); SESSION_TRACKER_CHANGED(thd, CURRENT_SCHEMA_TRACKER, NULL); @@ -1049,7 +1046,7 @@ exit: } -bool mysql_rm_db(THD *thd, const char *db, bool if_exists) +bool mysql_rm_db(THD *thd, const LEX_CSTRING *db, bool if_exists) { return mysql_rm_db_internal(thd, db, if_exists, false); } @@ -1084,20 +1081,18 @@ static bool find_db_tables_and_rm_known_files(THD *thd, MY_DIR *dirp, if (!table_list) DBUG_RETURN(true); - table_list->db= db.str; - table_list->db_length= db.length; - table_list->table_name= table->str; - table_list->table_name_length= table->length; + table_list->db= db; + table_list->table_name= *table; table_list->open_type= OT_BASE_ONLY; /* To be able to correctly look up the table in the table cache. */ if (lower_case_table_names) - table_list->table_name_length= my_casedn_str(files_charset_info, - (char*) table_list->table_name); + table_list->table_name.length= my_casedn_str(files_charset_info, + (char*) table_list->table_name.str); table_list->alias= table_list->table_name; // If lower_case_table_names=2 - table_list->mdl_request.init(MDL_key::TABLE, table_list->db, - table_list->table_name, MDL_EXCLUSIVE, + table_list->mdl_request.init(MDL_key::TABLE, table_list->db.str, + table_list->table_name.str, MDL_EXCLUSIVE, MDL_TRANSACTION); /* Link into list */ (*tot_list_next_local)= table_list; @@ -1312,16 +1307,16 @@ static void mysql_change_db_impl(THD *thd, sets the new one. */ - thd->set_db(NULL, 0); + thd->set_db(&null_clex_str); } - else if (new_db_name == &INFORMATION_SCHEMA_NAME) + else if (new_db_name->str == INFORMATION_SCHEMA_NAME.str) { /* Here we must use THD::set_db(), because we want to copy INFORMATION_SCHEMA_NAME constant. */ - thd->set_db(INFORMATION_SCHEMA_NAME.str, INFORMATION_SCHEMA_NAME.length); + thd->set_db(&INFORMATION_SCHEMA_NAME); } else { @@ -1330,8 +1325,8 @@ static void mysql_change_db_impl(THD *thd, we just call THD::reset_db(). Since THD::reset_db() does not releases the previous database name, we should do it explicitly. */ - thd->set_db(NULL, 0); - thd->reset_db(const_cast<char*>(new_db_name->str), new_db_name->length); + thd->set_db(&null_clex_str); + thd->reset_db(new_db_name); } /* 2. Update security context. */ @@ -1366,17 +1361,17 @@ static void mysql_change_db_impl(THD *thd, static void backup_current_db_name(THD *thd, LEX_STRING *saved_db_name) { - if (!thd->db) + DBUG_ASSERT(saved_db_name->length >= SAFE_NAME_LEN +1); + if (!thd->db.str) { /* No current (default) database selected. */ - - saved_db_name->str= NULL; + saved_db_name->str= 0; saved_db_name->length= 0; } else { - strmake(saved_db_name->str, thd->db, saved_db_name->length - 1); - saved_db_name->length= thd->db_length; + memcpy(saved_db_name->str, thd->db.str, thd->db.length + 1); + saved_db_name->length= thd->db.length; } } @@ -1479,7 +1474,7 @@ bool mysql_change_db(THD *thd, const LEX_CSTRING *new_db_name, } DBUG_PRINT("enter",("name: '%s'", new_db_name->str)); - if (is_infoschema_db(new_db_name->str, new_db_name->length)) + if (is_infoschema_db(new_db_name)) { /* Switch the current database to INFORMATION_SCHEMA. */ @@ -1630,7 +1625,7 @@ bool mysql_opt_change_db(THD *thd, bool force_switch, bool *cur_db_changed) { - *cur_db_changed= !cmp_db_names(thd->db, new_db_name->str); + *cur_db_changed= !cmp_db_names(&thd->db, new_db_name); if (!*cur_db_changed) return FALSE; @@ -1656,7 +1651,7 @@ bool mysql_opt_change_db(THD *thd, @return 0 on success, 1 on error */ -bool mysql_upgrade_db(THD *thd, LEX_CSTRING *old_db) +bool mysql_upgrade_db(THD *thd, const LEX_CSTRING *old_db) { int error= 0, change_to_newdb= 0; char path[FN_REFLEN+16]; @@ -1691,7 +1686,7 @@ bool mysql_upgrade_db(THD *thd, LEX_CSTRING *old_db) Let's remember if we should do "USE newdb" afterwards. thd->db will be cleared in mysql_rename_db() */ - if (thd->db && !strcmp(thd->db, old_db->str)) + if (thd->db.str && !cmp(&thd->db, old_db)) change_to_newdb= 1; build_table_filename(path, sizeof(path)-1, @@ -1709,7 +1704,7 @@ bool mysql_upgrade_db(THD *thd, LEX_CSTRING *old_db) } /* Step1: Create the new database */ - if ((error= mysql_create_db_internal(thd, new_db.str, + if ((error= mysql_create_db_internal(thd, &new_db, DDL_options(), &create_info, 1))) goto exit; @@ -1833,7 +1828,7 @@ bool mysql_upgrade_db(THD *thd, LEX_CSTRING *old_db) to execute them again. mysql_rm_db() also "unuses" if we drop the current database. */ - error= mysql_rm_db_internal(thd, old_db->str, 0, true); + error= mysql_rm_db_internal(thd, old_db, 0, true); /* Step8: logging */ if (mysql_bin_log.is_open()) diff --git a/sql/sql_db.h b/sql/sql_db.h index a4ada7de6a2..7de6c2a9c99 100644 --- a/sql/sql_db.h +++ b/sql/sql_db.h @@ -20,13 +20,13 @@ class THD; -int mysql_create_db(THD *thd, const char *db, +int mysql_create_db(THD *thd, const LEX_CSTRING *db, const DDL_options_st &options, const Schema_specification_st *create); -bool mysql_alter_db(THD *thd, const char *db, +bool mysql_alter_db(THD *thd, const LEX_CSTRING *db, const Schema_specification_st *create); -bool mysql_rm_db(THD *thd, const char *db, bool if_exists); -bool mysql_upgrade_db(THD *thd, LEX_CSTRING *old_db); +bool mysql_rm_db(THD *thd, const LEX_CSTRING *db, bool if_exists); +bool mysql_upgrade_db(THD *thd, const LEX_CSTRING *old_db); bool mysql_change_db(THD *thd, const LEX_CSTRING *new_db_name, bool force_switch); diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 14d04dcc2ad..48619b9d4fc 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -103,7 +103,7 @@ bool Update_plan::save_explain_data_intern(MEM_ROOT *mem_root, bool is_analyze) { explain->select_type= "SIMPLE"; - explain->table_name.append(table->pos_in_table_list->alias); + explain->table_name.append(&table->pos_in_table_list->alias); explain->impossible_where= false; explain->no_partitions= false; @@ -344,7 +344,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, if (!table_list->single_table_updatable()) { - my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "DELETE"); + my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias.str, "DELETE"); DBUG_RETURN(TRUE); } if (!(table= table_list->table) || !table->is_created()) @@ -961,7 +961,7 @@ l if (!table_list->single_table_updatable() || check_key_in_view(thd, table_list)) { - my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "DELETE"); + my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias.str, "DELETE"); DBUG_RETURN(TRUE); } @@ -1053,7 +1053,7 @@ int mysql_multi_delete_prepare(THD *thd) check_key_in_view(thd, target_tbl->correspondent_table)) { my_error(ER_NON_UPDATABLE_TABLE, MYF(0), - target_tbl->table_name, "DELETE"); + target_tbl->table_name.str, "DELETE"); DBUG_RETURN(TRUE); } /* diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index f9801d2bf36..12f230724fb 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -174,7 +174,7 @@ mysql_handle_single_derived(LEX *lex, TABLE_LIST *derived, uint phases) DBUG_ENTER("mysql_handle_single_derived"); DBUG_PRINT("enter", ("phases: 0x%x allowed: 0x%x alias: '%s'", phases, allowed_phases, - (derived->alias ? derived->alias : "<NULL>"))); + (derived->alias.str ? derived->alias.str : "<NULL>"))); if (!lex->derived_tables) DBUG_RETURN(FALSE); @@ -365,7 +365,7 @@ bool mysql_derived_merge(THD *thd, LEX *lex, TABLE_LIST *derived) Query_arena *arena, backup; DBUG_ENTER("mysql_derived_merge"); DBUG_PRINT("enter", ("Alias: '%s' Unit: %p", - (derived->alias ? derived->alias : "<NULL>"), + (derived->alias.str ? derived->alias.str : "<NULL>"), derived->get_unit())); if (derived->merged) @@ -514,7 +514,7 @@ bool mysql_derived_merge_for_insert(THD *thd, LEX *lex, TABLE_LIST *derived) { DBUG_ENTER("mysql_derived_merge_for_insert"); DBUG_PRINT("enter", ("Alias: '%s' Unit: %p", - (derived->alias ? derived->alias : "<NULL>"), + (derived->alias.str ? derived->alias.str : "<NULL>"), derived->get_unit())); DBUG_PRINT("info", ("merged_for_insert: %d is_materialized_derived: %d " "is_multitable: %d single_table_updatable: %d " @@ -572,7 +572,7 @@ bool mysql_derived_init(THD *thd, LEX *lex, TABLE_LIST *derived) SELECT_LEX_UNIT *unit= derived->get_unit(); DBUG_ENTER("mysql_derived_init"); DBUG_PRINT("enter", ("Alias: '%s' Unit: %p", - (derived->alias ? derived->alias : "<NULL>"), + (derived->alias.str ? derived->alias.str : "<NULL>"), derived->get_unit())); // Skip already prepared views/DT @@ -647,11 +647,10 @@ bool mysql_derived_init(THD *thd, LEX *lex, TABLE_LIST *derived) bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived) { SELECT_LEX_UNIT *unit= derived->get_unit(); - DBUG_ENTER("mysql_derived_prepare"); bool res= FALSE; - DBUG_PRINT("enter", ("Alias: '%s' Unit: %p", - (derived->alias ? derived->alias : "<NULL>"), - unit)); + DBUG_ENTER("mysql_derived_prepare"); + DBUG_PRINT("enter", ("unit: %p table_list: %p alias: '%s'", + unit, derived, derived->alias.str)); if (!unit) DBUG_RETURN(FALSE); @@ -692,7 +691,7 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived) (first_select->options | thd->variables.option_bits | TMP_TABLE_ALL_COLUMNS), - derived->alias, FALSE, FALSE, FALSE, 0); + &derived->alias, FALSE, FALSE, FALSE, 0); thd->create_tmp_table_for_derived= FALSE; if (!res && !derived->table) @@ -785,7 +784,7 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived) (first_select->options | thd->variables.option_bits | TMP_TABLE_ALL_COLUMNS), - derived->alias, + &derived->alias, FALSE, FALSE, FALSE, 0)) { @@ -810,8 +809,8 @@ exit: thd->get_stmt_da()->sql_errno() == ER_SP_DOES_NOT_EXIST)) { thd->clear_error(); - my_error(ER_VIEW_INVALID, MYF(0), derived->db, - derived->table_name); + my_error(ER_VIEW_INVALID, MYF(0), derived->db.str, + derived->table_name.str); } } @@ -881,11 +880,10 @@ bool mysql_derived_optimize(THD *thd, LEX *lex, TABLE_LIST *derived) SELECT_LEX_UNIT *unit= derived->get_unit(); SELECT_LEX *first_select= unit->first_select(); SELECT_LEX *save_current_select= lex->current_select; - bool res= FALSE; DBUG_ENTER("mysql_derived_optimize"); DBUG_PRINT("enter", ("Alias: '%s' Unit: %p", - (derived->alias ? derived->alias : "<NULL>"), + (derived->alias.str ? derived->alias.str : "<NULL>"), derived->get_unit())); lex->current_select= first_select; @@ -966,7 +964,7 @@ bool mysql_derived_create(THD *thd, LEX *lex, TABLE_LIST *derived) { DBUG_ENTER("mysql_derived_create"); DBUG_PRINT("enter", ("Alias: '%s' Unit: %p", - (derived->alias ? derived->alias : "<NULL>"), + (derived->alias.str ? derived->alias.str : "<NULL>"), derived->get_unit())); TABLE *table= derived->table; SELECT_LEX_UNIT *unit= derived->get_unit(); @@ -1067,7 +1065,7 @@ bool mysql_derived_fill(THD *thd, LEX *lex, TABLE_LIST *derived) bool res= FALSE; DBUG_ENTER("mysql_derived_fill"); DBUG_PRINT("enter", ("Alias: '%s' Unit: %p", - (derived->alias ? derived->alias : "<NULL>"), + (derived->alias.str ? derived->alias.str : "<NULL>"), derived->get_unit())); if (unit->executed && !unit->uncacheable && !unit->describe && @@ -1189,7 +1187,7 @@ bool mysql_derived_reinit(THD *thd, LEX *lex, TABLE_LIST *derived) { DBUG_ENTER("mysql_derived_reinit"); DBUG_PRINT("enter", ("Alias: '%s' Unit: %p", - (derived->alias ? derived->alias : "<NULL>"), + (derived->alias.str ? derived->alias.str : "<NULL>"), derived->get_unit())); st_select_lex_unit *unit= derived->get_unit(); diff --git a/sql/sql_expression_cache.cc b/sql/sql_expression_cache.cc index 00f5bfd792f..15c6cc57efb 100644 --- a/sql/sql_expression_cache.cc +++ b/sql/sql_expression_cache.cc @@ -97,6 +97,7 @@ void Expression_cache_tmptable::init() List_iterator<Item> li(items); Item_iterator_list it(li); uint field_counter; + LEX_CSTRING cache_table_name= { STRING_WITH_LEN("subquery-cache-table") }; DBUG_ENTER("Expression_cache_tmptable::init"); DBUG_ASSERT(!inited); inited= TRUE; @@ -124,7 +125,7 @@ void Expression_cache_tmptable::init() TMP_TABLE_ALL_COLUMNS) & ~TMP_TABLE_FORCE_MYISAM), HA_POS_ERROR, - (char *)"subquery-cache-table", + &cache_table_name, TRUE))) { DBUG_PRINT("error", ("create_tmp_table failed, caching switched off")); diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index eecfd5ad0b6..1f52041917e 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -116,7 +116,7 @@ static char *mysql_ha_hash_get_key(SQL_HANDLER *table, size_t *key_len, my_bool first __attribute__((unused))) { *key_len= table->handler_name.length + 1 ; /* include '\0' in comparisons */ - return table->handler_name.str; + return (char*) table->handler_name.str; } @@ -266,7 +266,7 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, SQL_HANDLER *reopen) Query_arena backup_arena; DBUG_ENTER("mysql_ha_open"); DBUG_PRINT("enter",("'%s'.'%s' as '%s' reopen: %d", - tables->db, tables->table_name, tables->alias, + tables->db.str, tables->table_name.str, tables->alias.str, reopen != 0)); if (thd->locked_tables_mode) @@ -298,12 +298,12 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, SQL_HANDLER *reopen) } else if (! reopen) /* Otherwise we have 'tables' already. */ { - if (my_hash_search(&thd->handler_tables_hash, (uchar*) tables->alias, - strlen(tables->alias) + 1)) + if (my_hash_search(&thd->handler_tables_hash, (uchar*) tables->alias.str, + tables->alias.length + 1)) { - DBUG_PRINT("info",("duplicate '%s'", tables->alias)); + DBUG_PRINT("info",("duplicate '%s'", tables->alias.str)); DBUG_PRINT("exit",("ERROR")); - my_error(ER_NONUNIQ_TABLE, MYF(0), tables->alias); + my_error(ER_NONUNIQ_TABLE, MYF(0), tables->alias.str); DBUG_RETURN(TRUE); } } @@ -330,7 +330,7 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, SQL_HANDLER *reopen) right from the start as open_tables() can't handle properly back-off for such locks. */ - tables->mdl_request.init(MDL_key::TABLE, tables->db, tables->table_name, + tables->mdl_request.init(MDL_key::TABLE, tables->db.str, tables->table_name.str, MDL_SHARED_READ, MDL_TRANSACTION); mdl_savepoint= thd->mdl_context.mdl_savepoint(); @@ -384,12 +384,12 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, SQL_HANDLER *reopen) goto err; init_alloc_root(&sql_handler->mem_root, 1024, 0, MYF(MY_THREAD_SPECIFIC)); - sql_handler->db.length= strlen(tables->db); - sql_handler->table_name.length= strlen(tables->table_name); - sql_handler->handler_name.length= strlen(tables->alias); + sql_handler->db.length= tables->db.length; + sql_handler->table_name.length= tables->table_name.length; + sql_handler->handler_name.length= tables->alias.length; if (!(my_multi_malloc(MY_WME, - &sql_handler->db.str, + &sql_handler->base_data, (uint) sql_handler->db.length + 1, &sql_handler->table_name.str, (uint) sql_handler->table_name.length + 1, @@ -397,12 +397,12 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, SQL_HANDLER *reopen) (uint) sql_handler->handler_name.length + 1, NullS))) goto err; - sql_handler->base_data= sql_handler->db.str; // Free this - memcpy(sql_handler->db.str, tables->db, sql_handler->db.length +1); - memcpy(sql_handler->table_name.str, tables->table_name, - sql_handler->table_name.length+1); - memcpy(sql_handler->handler_name.str, tables->alias, - sql_handler->handler_name.length +1); + sql_handler->db.str= sql_handler->base_data; + memcpy((char*) sql_handler->db.str, tables->db.str, tables->db.length +1); + memcpy((char*) sql_handler->table_name.str, tables->table_name.str, + tables->table_name.length+1); + memcpy((char*) sql_handler->handler_name.str, tables->alias.str, + tables->alias.length +1); /* add to hash */ if (my_hash_insert(&thd->handler_tables_hash, (uchar*) sql_handler)) @@ -520,7 +520,7 @@ bool mysql_ha_close(THD *thd, TABLE_LIST *tables) SQL_HANDLER *handler; DBUG_ENTER("mysql_ha_close"); DBUG_PRINT("enter",("'%s'.'%s' as '%s'", - tables->db, tables->table_name, tables->alias)); + tables->db.str, tables->table_name.str, tables->alias.str)); if (thd->locked_tables_mode) { @@ -529,15 +529,15 @@ bool mysql_ha_close(THD *thd, TABLE_LIST *tables) } if ((my_hash_inited(&thd->handler_tables_hash)) && (handler= (SQL_HANDLER*) my_hash_search(&thd->handler_tables_hash, - (uchar*) tables->alias, - strlen(tables->alias) + 1))) + (const uchar*) tables->alias.str, + tables->alias.length + 1))) { mysql_ha_close_table(handler); my_hash_delete(&thd->handler_tables_hash, (uchar*) handler); } else { - my_error(ER_UNKNOWN_TABLE, MYF(0), tables->alias, "HANDLER"); + my_error(ER_UNKNOWN_TABLE, MYF(0), tables->alias.str, "HANDLER"); DBUG_PRINT("exit",("ERROR")); DBUG_RETURN(TRUE); } @@ -564,13 +564,13 @@ bool mysql_ha_close(THD *thd, TABLE_LIST *tables) @return handler */ -SQL_HANDLER *mysql_ha_find_handler(THD *thd, const char *name) +static SQL_HANDLER *mysql_ha_find_handler(THD *thd, const LEX_CSTRING *name) { SQL_HANDLER *handler; if ((my_hash_inited(&thd->handler_tables_hash)) && (handler= (SQL_HANDLER*) my_hash_search(&thd->handler_tables_hash, - (uchar*) name, - strlen(name) + 1))) + (const uchar*) name->str, + name->length + 1))) { DBUG_PRINT("info-in-hash",("'%s'.'%s' as '%s' table: %p", handler->db.str, @@ -580,9 +580,8 @@ SQL_HANDLER *mysql_ha_find_handler(THD *thd, const char *name) { /* The handler table has been closed. Re-open it. */ TABLE_LIST tmp; - tmp.init_one_table(handler->db.str, handler->db.length, - handler->table_name.str, handler->table_name.length, - handler->handler_name.str, TL_READ); + tmp.init_one_table(&handler->db, &handler->table_name, + &handler->handler_name, TL_READ); if (mysql_ha_open(thd, &tmp, handler)) { @@ -593,7 +592,7 @@ SQL_HANDLER *mysql_ha_find_handler(THD *thd, const char *name) } else { - my_error(ER_UNKNOWN_TABLE, MYF(0), name, "HANDLER"); + my_error(ER_UNKNOWN_TABLE, MYF(0), name->str, "HANDLER"); return 0; } return handler; @@ -756,7 +755,7 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables, MDL_deadlock_and_lock_abort_error_handler sql_handler_lock_error; DBUG_ENTER("mysql_ha_read"); DBUG_PRINT("enter",("'%s'.'%s' as '%s'", - tables->db, tables->table_name, tables->alias)); + tables->db.str, tables->table_name.str, tables->alias.str)); if (thd->locked_tables_mode) { @@ -765,7 +764,7 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables, } retry: - if (!(handler= mysql_ha_find_handler(thd, tables->alias))) + if (!(handler= mysql_ha_find_handler(thd, &tables->alias))) goto err0; table= handler->table; @@ -950,7 +949,7 @@ retry: if (error != HA_ERR_RECORD_CHANGED && error != HA_ERR_WRONG_COMMAND) sql_print_error("mysql_ha_read: Got error %d when reading " "table '%s'", - error, tables->table_name); + error, tables->table_name.str); table->file->print_error(error,MYF(0)); table->file->ha_index_or_rnd_end(); goto err; @@ -1007,7 +1006,7 @@ SQL_HANDLER *mysql_ha_read_prepare(THD *thd, TABLE_LIST *tables, { SQL_HANDLER *handler; DBUG_ENTER("mysql_ha_read_prepare"); - if (!(handler= mysql_ha_find_handler(thd, tables->alias))) + if (!(handler= mysql_ha_find_handler(thd, &tables->alias))) DBUG_RETURN(0); tables->table= handler->table; // This is used by fix_fields if (mysql_ha_fix_cond_and_key(handler, mode, keyname, key_expr, cond, 1)) @@ -1043,7 +1042,7 @@ static SQL_HANDLER *mysql_ha_find_match(THD *thd, TABLE_LIST *tables) { if (tables->is_anonymous_derived_table()) continue; - if ((! *tables->db || + if ((! tables->db.str[0] || ! my_strcasecmp(&my_charset_latin1, hash_tables->db.str, tables->get_db_name())) && ! my_strcasecmp(&my_charset_latin1, hash_tables->table_name.str, diff --git a/sql/sql_handler.h b/sql/sql_handler.h index cb1aff1d727..ffefec91fad 100644 --- a/sql/sql_handler.h +++ b/sql/sql_handler.h @@ -31,9 +31,9 @@ public: TABLE *table; List<Item> fields; /* Fields, set on open */ THD *thd; - LEX_STRING handler_name; - LEX_STRING db; - LEX_STRING table_name; + LEX_CSTRING handler_name; + LEX_CSTRING db; + LEX_CSTRING table_name; MEM_ROOT mem_root; MYSQL_LOCK *lock; MDL_request mdl_request; diff --git a/sql/sql_help.cc b/sql/sql_help.cc index 4ccaa6a055f..80ed12b5652 100644 --- a/sql/sql_help.cc +++ b/sql/sql_help.cc @@ -689,20 +689,16 @@ static bool mysqld_help_internal(THD *thd, const char *mask) uint mlen= strlen(mask); size_t i; MEM_ROOT *mem_root= thd->mem_root; + LEX_CSTRING MYSQL_HELP_TOPIC_NAME= {STRING_WITH_LEN("help_topic") }; + LEX_CSTRING MYSQL_HELP_CATEGORY_NAME= {STRING_WITH_LEN("help_category") }; + LEX_CSTRING MYSQL_HELP_RELATION_NAME= {STRING_WITH_LEN("help_relation") }; + LEX_CSTRING MYSQL_HELP_KEYWORD_NAME= {STRING_WITH_LEN("help_keyword") }; DBUG_ENTER("mysqld_help"); - tables[0].init_one_table(C_STRING_WITH_LEN("mysql"), - C_STRING_WITH_LEN("help_topic"), - "help_topic", TL_READ); - tables[1].init_one_table(C_STRING_WITH_LEN("mysql"), - C_STRING_WITH_LEN("help_category"), - "help_category", TL_READ); - tables[2].init_one_table(C_STRING_WITH_LEN("mysql"), - C_STRING_WITH_LEN("help_relation"), - "help_relation", TL_READ); - tables[3].init_one_table(C_STRING_WITH_LEN("mysql"), - C_STRING_WITH_LEN("help_keyword"), - "help_keyword", TL_READ); + tables[0].init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_HELP_TOPIC_NAME, 0, TL_READ); + tables[1].init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_HELP_CATEGORY_NAME, 0, TL_READ); + tables[2].init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_HELP_RELATION_NAME, 0, TL_READ); + tables[3].init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_HELP_KEYWORD_NAME, 0, TL_READ); tables[0].next_global= tables[0].next_local= tables[0].next_name_resolution_table= &tables[1]; tables[1].next_global= tables[1].next_local= diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index cb46b4847bd..b67022d08e6 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -168,9 +168,9 @@ static bool check_view_single_update(List<Item> &fields, List<Item> *values, if (!tbl->single_table_updatable()) { if (insert) - my_error(ER_NON_INSERTABLE_TABLE, MYF(0), view->alias, "INSERT"); + my_error(ER_NON_INSERTABLE_TABLE, MYF(0), view->alias.str, "INSERT"); else - my_error(ER_NON_UPDATABLE_TABLE, MYF(0), view->alias, "UPDATE"); + my_error(ER_NON_UPDATABLE_TABLE, MYF(0), view->alias.str, "UPDATE"); return TRUE; } *map= tables; @@ -210,7 +210,7 @@ static int check_insert_fields(THD *thd, TABLE_LIST *table_list, if (!table_list->single_table_updatable()) { - my_error(ER_NON_INSERTABLE_TABLE, MYF(0), table_list->alias, "INSERT"); + my_error(ER_NON_INSERTABLE_TABLE, MYF(0), table_list->alias.str, "INSERT"); DBUG_RETURN(-1); } @@ -304,7 +304,7 @@ static int check_insert_fields(THD *thd, TABLE_LIST *table_list, (table_list->view && check_view_insertability(thd, table_list))) { - my_error(ER_NON_INSERTABLE_TABLE, MYF(0), table_list->alias, "INSERT"); + my_error(ER_NON_INSERTABLE_TABLE, MYF(0), table_list->alias.str, "INSERT"); DBUG_RETURN(-1); } @@ -742,11 +742,11 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, */ if (table_list->lock_type == TL_WRITE_DELAYED && thd->locked_tables_mode && - find_locked_table(thd->open_tables, table_list->db, - table_list->table_name)) + find_locked_table(thd->open_tables, table_list->db.str, + table_list->table_name.str)) { my_error(ER_DELAYED_INSERT_TABLE_LOCKED, MYF(0), - table_list->table_name); + table_list->table_name.str); DBUG_RETURN(TRUE); } /* @@ -1381,7 +1381,7 @@ static bool mysql_prepare_insert_check_table(THD *thd, TABLE_LIST *table_list, if (!table_list->single_table_updatable()) { - my_error(ER_NON_INSERTABLE_TABLE, MYF(0), table_list->alias, "INSERT"); + my_error(ER_NON_INSERTABLE_TABLE, MYF(0), table_list->alias.str, "INSERT"); DBUG_RETURN(TRUE); } /* @@ -2262,8 +2262,8 @@ Delayed_insert *find_handler(THD *thd, TABLE_LIST *table_list) Delayed_insert *di; while ((di= it++)) { - if (!strcmp(table_list->db, di->table_list.db) && - !strcmp(table_list->table_name, di->table_list.table_name)) + if (!cmp(&table_list->db, &di->table_list.db) && + !cmp(&table_list->table_name, &di->table_list.table_name)) { di->lock(); break; @@ -2327,7 +2327,7 @@ bool delayed_get_table(THD *thd, MDL_request *grl_protection_request, DBUG_ENTER("delayed_get_table"); /* Must be set in the parser */ - DBUG_ASSERT(table_list->db); + DBUG_ASSERT(table_list->db.str); /* Find the thread which handles this table. */ if (!(di= find_handler(thd, table_list))) @@ -2354,11 +2354,12 @@ bool delayed_get_table(THD *thd, MDL_request *grl_protection_request, */ di->thd.variables.binlog_annotate_row_events= 0; - di->thd.set_db(table_list->db, (uint) strlen(table_list->db)); - di->thd.set_query(my_strdup(table_list->table_name, - MYF(MY_WME | ME_FATALERROR)), - 0, system_charset_info); - if (di->thd.db == NULL || di->thd.query() == NULL) + di->thd.set_db(&table_list->db); + di->thd.set_query(my_strndup(table_list->table_name.str, + table_list->table_name.length, + MYF(MY_WME | ME_FATALERROR)), + table_list->table_name.length, system_charset_info); + if (di->thd.db.str == NULL || di->thd.query() == NULL) { /* The error is reported */ delete di; @@ -2366,7 +2367,8 @@ bool delayed_get_table(THD *thd, MDL_request *grl_protection_request, } di->table_list= *table_list; // Needed to open table /* Replace volatile strings with local copies */ - di->table_list.alias= di->table_list.table_name= di->thd.query(); + di->table_list.alias.str= di->table_list.table_name.str= di->thd.query(); + di->table_list.alias.length= di->table_list.table_name.length= di->thd.query_length(); di->table_list.db= di->thd.db; /* We need the tickets so that they can be cloned in handle_delayed_insert */ di->grl_protection.init(MDL_key::GLOBAL, "", "", @@ -2848,7 +2850,7 @@ handle_table(THD *thd, Query_tables_list *prelocking_ctx, if (!(table_list->table->file->ha_table_flags() & HA_CAN_INSERT_DELAYED)) { - my_error(ER_DELAYED_NOT_SUPPORTED, MYF(0), table_list->table_name); + my_error(ER_DELAYED_NOT_SUPPORTED, MYF(0), table_list->table_name.str); return TRUE; } return FALSE; @@ -4219,8 +4221,8 @@ TABLE *select_create::create_table_from_items(THD *thd, open_table(). */ - if (!mysql_create_table_no_lock(thd, create_table->db, - create_table->table_name, + if (!mysql_create_table_no_lock(thd, &create_table->db, + &create_table->table_name, create_info, alter_info, NULL, select_field_count, create_table)) { @@ -4246,8 +4248,8 @@ TABLE *select_create::create_table_from_items(THD *thd, */ if (open_table(thd, create_table, &ot_ctx)) { - quick_rm_table(thd, create_info->db_type, create_table->db, - table_case_name(create_info, create_table->table_name), + quick_rm_table(thd, create_info->db_type, &create_table->db, + table_case_name(create_info, &create_table->table_name), 0); } /* Restore */ @@ -4304,7 +4306,7 @@ TABLE *select_create::create_table_from_items(THD *thd, mysql_unlock_tables(thd, *lock); *lock= 0; } - drop_open_table(thd, table, create_table->db, create_table->table_name); + drop_open_table(thd, table, &create_table->db, &create_table->table_name); DBUG_RETURN(0); /* purecov: end */ } @@ -4692,16 +4694,14 @@ void select_create::abort_result_set() table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY); table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE); table->auto_increment_field_not_null= FALSE; - drop_open_table(thd, table, create_table->db, create_table->table_name); + drop_open_table(thd, table, &create_table->db, &create_table->table_name); table=0; // Safety if (thd->log_current_statement && mysql_bin_log.is_open()) { /* Remove logging of drop, create + insert rows */ binlog_reset_cache(thd); /* Original table was deleted. We have to log it */ - log_drop_table(thd, create_table->db, create_table->db_length, - create_table->table_name, create_table->table_name_length, - tmp_table); + log_drop_table(thd, &create_table->db, &create_table->table_name, tmp_table); } } DBUG_VOID_RETURN; diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 197fe86957c..243a8bf8b3f 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -2282,7 +2282,8 @@ void st_select_lex::init_select() group_list.empty(); if (group_list_ptrs) group_list_ptrs->clear(); - type= db= 0; + type= 0; + db= null_clex_str; having= 0; table_join_options= 0; in_sum_expr= with_wild= 0; @@ -3288,8 +3289,7 @@ uint8 LEX::get_effective_with_check(TABLE_LIST *view) case of success */ -bool -LEX::copy_db_to(const char **p_db, size_t *p_db_length) const +bool LEX::copy_db_to(LEX_CSTRING *to) { if (sphead && sphead->m_name.str) { @@ -3298,12 +3298,10 @@ LEX::copy_db_to(const char **p_db, size_t *p_db_length) const It is safe to assign the string by-pointer, both sphead and its statements reside in the same memory root. */ - *p_db= sphead->m_db.str; - if (p_db_length) - *p_db_length= sphead->m_db.length; + *to= sphead->m_db; return FALSE; } - return thd->copy_db_to(p_db, p_db_length); + return thd->copy_db_to(to); } /** @@ -6033,7 +6031,7 @@ sp_name *LEX::make_sp_name(THD *thd, const LEX_CSTRING *name) sp_name *res; LEX_CSTRING db; if (check_routine_name(name) || - copy_db_to(&db.str, &db.length) || + copy_db_to(&db) || (!(res= new (thd->mem_root) sp_name(&db, name, false)))) return NULL; return res; @@ -7484,18 +7482,16 @@ bool SELECT_LEX::vers_push_field(THD *thd, TABLE_LIST *table, const LEX_CSTRING { DBUG_ASSERT(field_name.str); Item_field *fld= new (thd->mem_root) Item_field(thd, &context, - table->db, table->alias, &field_name); - if (!fld) + table->db.str, table->alias.str, &field_name); + if (!fld || item_list.push_back(fld)) return true; - item_list.push_back(fld); - if (thd->lex->view_list.elements) { - if (LEX_STRING *l= thd->make_lex_string(field_name.str, field_name.length)) - thd->lex->view_list.push_back(l); - else + LEX_CSTRING *l; + if (!(l= thd->make_clex_string(field_name.str, field_name.length))) return true; + thd->lex->view_list.push_back(l); } return false; diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 2f2418c088d..058bd639e44 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -206,7 +206,7 @@ struct LEX_TYPE #ifdef MYSQL_SERVER extern const LEX_STRING empty_lex_str; -extern const LEX_CSTRING empty_clex_str; +extern MYSQL_PLUGIN_IMPORT const LEX_CSTRING empty_clex_str; extern const LEX_CSTRING star_clex_str; extern const LEX_CSTRING param_clex_str; @@ -837,7 +837,7 @@ class st_select_lex: public st_select_lex_node { public: Name_resolution_context context; - const char *db; + LEX_CSTRING db; Item *where, *having; /* WHERE & HAVING clauses */ Item *prep_where; /* saved WHERE clause for prepared statement processing */ Item *prep_having;/* saved HAVING clause for prepared statement processing */ @@ -2754,7 +2754,7 @@ public: List<Item_func_set_user_var> set_var_list; // in-query assignment list List<Item_param> param_list; - List<LEX_STRING> view_list; // view list (list of field names in view) + List<LEX_CSTRING> view_list; // view list (list of field names in view) List<LEX_CSTRING> with_column_list; // list of column names in with_list_element List<LEX_STRING> *column_list; // list of column names (in ANALYZE) List<LEX_STRING> *index_list; // list of index names (in ANALYZE) @@ -3124,7 +3124,7 @@ public: context_stack.pop(); } - bool copy_db_to(const char **p_db, size_t *p_db_length) const; + bool copy_db_to(LEX_CSTRING *to); Name_resolution_context *current_context() { diff --git a/sql/sql_load.cc b/sql/sql_load.cc index 93669554a5a..17e2aca79e4 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -322,13 +322,13 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, killed_state killed_status; bool is_concurrent; #endif - const char *db = table_list->db; // This is never null + const char *db= table_list->db.str; // This is never null /* If path for file is not defined, we will use the current database. If this is not set, we will use the directory where the table to be loaded is located */ - const char *tdb= thd->db ? thd->db : db; // Result is never null + const char *tdb= thd->db.str ? thd->db.str : db; // Result is never null ulong skip_lines= ex->skip_lines; bool transactional_table __attribute__((unused)); DBUG_ENTER("mysql_load"); @@ -379,7 +379,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, !table_list->single_table_updatable() || // and derived tables check_key_in_view(thd, table_list)) { - my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "LOAD"); + my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias.str, "LOAD"); DBUG_RETURN(TRUE); } if (table_list->prepare_where(thd, 0, TRUE) || @@ -398,7 +398,7 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, */ if (unique_table(thd, table_list, table_list->next_global, 0)) { - my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->table_name, + my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->table_name.str, "LOAD DATA"); DBUG_RETURN(TRUE); } @@ -710,8 +710,8 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, writing binary log will be ignored */ if (thd->transaction.stmt.modified_non_trans_table) (void) write_execute_load_query_log_event(thd, ex, - table_list->db, - table_list->table_name, + table_list->db.str, + table_list->table_name.str, is_concurrent, handle_duplicates, ignore, transactional_table, @@ -761,7 +761,8 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, { int errcode= query_error_code(thd, killed_status == NOT_KILLED); error= write_execute_load_query_log_event(thd, ex, - table_list->db, table_list->table_name, + table_list->db.str, + table_list->table_name.str, is_concurrent, handle_duplicates, ignore, transactional_table, @@ -810,7 +811,7 @@ static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex, List<Item> fv; Item *item, *val; int n; - const char *tdb= (thd->db != NULL ? thd->db : db_arg); + const char *tdb= (thd->db.str != NULL ? thd->db.str : db_arg); const char *qualify_db= NULL; char command_buffer[1024]; String query_str(command_buffer, sizeof(command_buffer), @@ -826,7 +827,7 @@ static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex, lle.set_fname_outside_temp_buf(ex->file_name, strlen(ex->file_name)); query_str.length(0); - if (!thd->db || strcmp(db_arg, thd->db)) + if (!thd->db.str || strcmp(db_arg, thd->db.str)) { /* If used database differs from table's database, @@ -853,7 +854,7 @@ static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex, if (n++) query_str.append(", "); if (item->real_type() == Item::FIELD_ITEM) - append_identifier(thd, &query_str, item->name.str, item->name.length); + append_identifier(thd, &query_str, &item->name); else { /* Actually Item_user_var_as_out_param despite claiming STRING_ITEM. */ @@ -877,7 +878,7 @@ static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex, val= lv++; if (n++) query_str.append(STRING_WITH_LEN(", ")); - append_identifier(thd, &query_str, item->name.str, item->name.length); + append_identifier(thd, &query_str, &item->name); query_str.append(&val->name); } } @@ -966,7 +967,7 @@ read_fixed_length(THD *thd, COPY_INFO &info, TABLE_LIST *table_list, */ while ((sql_field= (Item_field*) it++)) { - Field *field= sql_field->field; + Field *field= sql_field->field; table->auto_increment_field_not_null= auto_increment_field_not_null; /* No fields specified in fields_vars list can be null in this format. diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 3b9ceea9da5..a0169953df6 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -403,7 +403,7 @@ inline bool all_tables_not_ok(THD *thd, TABLE_LIST *tables) { Rpl_filter *rpl_filter= thd->system_thread_info.rpl_sql_info->rpl_filter; return rpl_filter->is_on() && tables && !thd->spcont && - !rpl_filter->tables_ok(thd->db, tables); + !rpl_filter->tables_ok(thd->db.str, tables); } #endif @@ -412,7 +412,7 @@ static bool some_non_temp_table_to_be_updated(THD *thd, TABLE_LIST *tables) { for (TABLE_LIST *table= tables; table; table= table->next_global) { - DBUG_ASSERT(table->db && table->table_name); + DBUG_ASSERT(table->db.str && table->table_name.str); if (table->updating && !thd->find_tmp_table_share(table)) return 1; } @@ -1015,7 +1015,7 @@ static void handle_bootstrap_impl(THD *thd) } query= (char *) thd->memdup_w_gap(buffer, length + 1, - thd->db_length + 1 + + thd->db.length + 1 + QUERY_CACHE_DB_LENGTH_SIZE + QUERY_CACHE_FLAGS_SIZE); size_t db_len= 0; @@ -1670,7 +1670,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, break; if (!mysql_change_db(thd, &tmp, FALSE)) { - general_log_write(thd, command, thd->db, thd->db_length); + general_log_write(thd, command, thd->db.str, thd->db.length); my_ok(thd); } break; @@ -1703,8 +1703,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, /* acl_authenticate() takes the data from net->read_pos */ net->read_pos= (uchar*)packet; - uint save_db_length= thd->db_length; - char *save_db= thd->db; + LEX_CSTRING save_db= thd->db; USER_CONN *save_user_connect= thd->user_connect; Security_context save_security_ctx= *thd->security_ctx; CHARSET_INFO *save_character_set_client= @@ -1740,7 +1739,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, if (thd->user_connect) decrease_user_connections(thd->user_connect); thd->user_connect= save_user_connect; - thd->reset_db(save_db, save_db_length); + thd->reset_db(&save_db); thd->update_charset(save_character_set_client, save_collation_connection, save_character_set_results); thd->failed_com_change_user++; @@ -1753,7 +1752,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, if (save_user_connect) decrease_user_connections(save_user_connect); #endif /* NO_EMBEDDED_ACCESS_CHECKS */ - my_free(save_db); + my_free((char*) save_db.str); my_free(const_cast<char*>(save_security_ctx.user)); } break; @@ -1802,7 +1801,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, if (alloc_query(thd, packet, packet_length)) break; // fatal error is set MYSQL_QUERY_START(thd->query(), thd->thread_id, - (char *) (thd->db ? thd->db : ""), + thd->get_db(), &thd->security_ctx->priv_user[0], (char *) thd->security_ctx->host_or_ip); char *packet_end= thd->query() + thd->query_length(); @@ -1880,7 +1879,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, /* DTRACE begin */ MYSQL_QUERY_START(beginning_of_next_stmt, thd->thread_id, - (char *) (thd->db ? thd->db : ""), + thd->get_db(), &thd->security_ctx->priv_user[0], (char *) thd->security_ctx->host_or_ip); @@ -1889,7 +1888,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, thd->m_statement_psi= MYSQL_START_STATEMENT(&thd->m_statement_state, com_statement_info[command].m_key, - thd->db, thd->db_length, + thd->db.str, thd->db.length, thd->charset()); THD_STAGE_INFO(thd, stage_init); MYSQL_SET_STATEMENT_TEXT(thd->m_statement_psi, beginning_of_next_stmt, @@ -1939,7 +1938,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, MDL_savepoint mdl_savepoint= thd->mdl_context.mdl_savepoint(); status_var_increment(thd->status_var.com_stat[SQLCOM_SHOW_FIELDS]); - if (thd->copy_db_to(&db.str, &db.length)) + if (thd->copy_db_to(&db)) break; /* We have name + wildcard in packet, separated by endzero @@ -1979,8 +1978,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, table_name.length= my_casedn_str(files_charset_info, table_name.str); db.length= my_casedn_str(files_charset_info, (char*) db.str); } - table_list.init_one_table(db.str, db.length, table_name.str, - table_name.length, table_name.str, TL_READ); + table_list.init_one_table(&db, (LEX_CSTRING*) &table_name, 0, TL_READ); /* Init TABLE_LIST members necessary when the undelrying table is view. @@ -1991,9 +1989,9 @@ bool dispatch_command(enum enum_server_command command, THD *thd, &table_list.next_local); thd->lex->add_to_query_tables(&table_list); - if (is_infoschema_db(table_list.db, table_list.db_length)) + if (is_infoschema_db(&table_list.db)) { - ST_SCHEMA_TABLE *schema_table= find_schema_table(thd, table_list.alias); + ST_SCHEMA_TABLE *schema_table= find_schema_table(thd, &table_list.alias); if (schema_table) table_list.schema_table= schema_table; } @@ -2002,7 +2000,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd, if (!(fields= (char *) thd->memdup(packet, query_length + 1))) break; thd->set_query(fields, query_length); - general_log_print(thd, command, "%s %s", table_list.table_name, fields); + general_log_print(thd, command, "%s %s", table_list.table_name.str, + fields); if (thd->open_temporary_tables(&table_list)) break; @@ -2549,27 +2548,23 @@ int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident, DBUG_RETURN(1); #else { - LEX_STRING db; - size_t dummy; - if (lex->select_lex.db == NULL && - lex->copy_db_to(&lex->select_lex.db, &dummy)) + if (lex->select_lex.db.str == NULL && + lex->copy_db_to(&lex->select_lex.db)) { DBUG_RETURN(1); } schema_select_lex= new (thd->mem_root) SELECT_LEX(); schema_select_lex->table_list.first= NULL; if (lower_case_table_names == 1) - lex->select_lex.db= thd->strdup(lex->select_lex.db); + lex->select_lex.db.str= thd->strdup(lex->select_lex.db.str); schema_select_lex->db= lex->select_lex.db; /* check_db_name() may change db.str if lower_case_table_names == 1, but that's ok as the db is allocted above in this case. */ - db.str= (char*) lex->select_lex.db; - db.length= strlen(db.str); - if (check_db_name(&db)) + if (check_db_name((LEX_STRING*) &lex->select_lex.db)) { - my_error(ER_WRONG_DB_NAME, MYF(0), db.str); + my_error(ER_WRONG_DB_NAME, MYF(0), lex->select_lex.db.str); DBUG_RETURN(1); } break; @@ -2660,7 +2655,7 @@ bool alloc_query(THD *thd, const char *packet, uint packet_length) */ if (! (query= (char*) thd->memdup_w_gap(packet, packet_length, - 1 + thd->db_length + + 1 + thd->db.length + QUERY_CACHE_DB_LENGTH_SIZE + QUERY_CACHE_FLAGS_SIZE))) return TRUE; @@ -2670,7 +2665,7 @@ bool alloc_query(THD *thd, const char *packet, uint packet_length) also store this length, in case current database is changed during execution. We might need to reallocate the 'query' buffer */ - int2store(query + packet_length + 1, thd->db_length); + int2store(query + packet_length + 1, thd->db.length); thd->set_query(query, packet_length); @@ -2963,8 +2958,8 @@ static int mysql_create_routine(THD *thd, LEX *lex) /* Checking the drop permissions if CREATE OR REPLACE is used */ if (lex->create_info.or_replace()) { - if (check_routine_access(thd, ALTER_PROC_ACL, lex->sphead->m_db.str, - lex->sphead->m_name.str, + if (check_routine_access(thd, ALTER_PROC_ACL, &lex->sphead->m_db, + &lex->sphead->m_name, Sp_handler::handler(lex->sql_command), 0)) return true; } @@ -3033,7 +3028,7 @@ static int mysql_create_routine(THD *thd, LEX *lex) if (sp_automatic_privileges && !opt_noacl && check_routine_access(thd, DEFAULT_CREATE_PROC_ACLS, - lex->sphead->m_db.str, name->str, + &lex->sphead->m_db, name, Sp_handler::handler(lex->sql_command), 1)) { if (sp_grant_privileges(thd, lex->sphead->m_db.str, name->str, @@ -3134,8 +3129,8 @@ bool Sql_cmd_call::execute(THD *thd) If the routine is not found, let's still check EXECUTE_ACL to decide whether to return "Access denied" or "Routine does not exist". */ - if (check_routine_access(thd, EXECUTE_ACL, m_name->m_db.str, - m_name->m_name.str, + if (check_routine_access(thd, EXECUTE_ACL, &m_name->m_db, + &m_name->m_name, &sp_handler_procedure, false)) return true; @@ -3869,7 +3864,7 @@ mysql_execute_command(THD *thd) case SQLCOM_ASSIGN_TO_KEYCACHE: { DBUG_ASSERT(first_table == all_tables && first_table != 0); - if (check_access(thd, INDEX_ACL, first_table->db, + if (check_access(thd, INDEX_ACL, first_table->db.str, &first_table->grant.privilege, &first_table->grant.m_internal, 0, 0)) @@ -3880,7 +3875,7 @@ mysql_execute_command(THD *thd) case SQLCOM_PRELOAD_KEYS: { DBUG_ASSERT(first_table == all_tables && first_table != 0); - if (check_access(thd, INDEX_ACL, first_table->db, + if (check_access(thd, INDEX_ACL, first_table->db.str, &first_table->grant.privilege, &first_table->grant.m_internal, 0, 0)) @@ -4043,9 +4038,9 @@ mysql_execute_command(THD *thd) /* Fix names if symlinked or relocated tables */ if (append_file_to_dir(thd, &create_info.data_file_name, - create_table->table_name) || + &create_table->table_name) || append_file_to_dir(thd, &create_info.index_file_name, - create_table->table_name)) + &create_table->table_name)) goto end_with_restore_list; /* @@ -4158,8 +4153,8 @@ mysql_execute_command(THD *thd) */ if (create_info.used_fields & HA_CREATE_USED_UNION) { - my_error(ER_WRONG_OBJECT, MYF(0), create_table->db, - create_table->table_name, "BASE TABLE"); + my_error(ER_WRONG_OBJECT, MYF(0), create_table->db.str, + create_table->table_name.str, "BASE TABLE"); res= 1; goto end_with_restore_list; } @@ -4250,12 +4245,12 @@ mysql_execute_command(THD *thd) engine is allowed/supported. */ if (WSREP(thd) && - !check_engine(thd, create_table->db, create_table->table_name, + !check_engine(thd, create_table->db.str, create_table->table_name.str, &create_info) && (!thd->is_current_stmt_binlog_format_row() || !create_info.tmp_table())) { - WSREP_TO_ISOLATION_BEGIN(create_table->db, create_table->table_name, NULL); + WSREP_TO_ISOLATION_BEGIN(create_table->db.str, create_table->table_name.str, NULL); } /* Regular CREATE TABLE */ res= mysql_create_table(thd, create_table, &create_info, &alter_info); @@ -4300,7 +4295,7 @@ end_with_restore_list: DBUG_ASSERT(first_table == all_tables && first_table != 0); if (check_one_table_access(thd, INDEX_ACL, all_tables)) goto error; /* purecov: inspected */ - WSREP_TO_ISOLATION_BEGIN(first_table->db, first_table->table_name, NULL); + WSREP_TO_ISOLATION_BEGIN(first_table->db.str, first_table->table_name.str, NULL); /* Currently CREATE INDEX or DROP INDEX cause a full table rebuild and thus classify as slow administrative statements just like @@ -4313,7 +4308,7 @@ end_with_restore_list: create_info.row_type= ROW_TYPE_NOT_USED; create_info.default_table_charset= thd->variables.collation_database; - res= mysql_alter_table(thd, first_table->db, first_table->table_name, + res= mysql_alter_table(thd, &first_table->db, &first_table->table_name, &create_info, first_table, &alter_info, 0, (ORDER*) 0, 0); break; @@ -4468,7 +4463,7 @@ end_with_restore_list: DBUG_PRINT("debug", ("lex->only_view: %d, table: %s.%s", lex->table_type == TABLE_TYPE_VIEW, - first_table->db, first_table->table_name)); + first_table->db.str, first_table->table_name.str)); if (lex->table_type == TABLE_TYPE_VIEW) { if (check_table_access(thd, SELECT_ACL, first_table, FALSE, 1, FALSE)) @@ -4476,7 +4471,7 @@ end_with_restore_list: DBUG_PRINT("debug", ("check_table_access failed")); my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0), "SHOW", thd->security_ctx->priv_user, - thd->security_ctx->host_or_ip, first_table->alias); + thd->security_ctx->host_or_ip, first_table->alias.str); goto error; } DBUG_PRINT("debug", ("check_table_access succeeded")); @@ -4505,7 +4500,7 @@ end_with_restore_list: { my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0), "SHOW", thd->security_ctx->priv_user, - thd->security_ctx->host_or_ip, first_table->alias); + thd->security_ctx->host_or_ip, first_table->alias.str); goto error; } } @@ -4753,7 +4748,7 @@ end_with_restore_list: if (WSREP(thd) && thd->wsrep_consistency_check == CONSISTENCY_CHECK_DECLARED) { thd->wsrep_consistency_check = CONSISTENCY_CHECK_RUNNING; - WSREP_TO_ISOLATION_BEGIN(first_table->db, first_table->table_name, NULL); + WSREP_TO_ISOLATION_BEGIN(first_table->db.str, first_table->table_name.str, NULL); } #endif /* WITH_WSREP */ @@ -5077,9 +5072,7 @@ end_with_restore_list: #endif case SQLCOM_CHANGE_DB: { - LEX_CSTRING db_str= { (char *) select_lex->db, strlen(select_lex->db) }; - - if (!mysql_change_db(thd, &db_str, FALSE)) + if (!mysql_change_db(thd, &select_lex->db, FALSE)) my_ok(thd); break; @@ -5206,7 +5199,7 @@ end_with_restore_list: &lex->name)) break; WSREP_TO_ISOLATION_BEGIN(lex->name.str, NULL, NULL); - res= mysql_create_db(thd, lex->name.str, + res= mysql_create_db(thd, &lex->name, lex->create_info, &lex->create_info); break; } @@ -5215,7 +5208,7 @@ end_with_restore_list: if (prepare_db_action(thd, DROP_ACL, &lex->name)) break; WSREP_TO_ISOLATION_BEGIN(lex->name.str, NULL, NULL); - res= mysql_rm_db(thd, lex->name.str, lex->if_exists()); + res= mysql_rm_db(thd, &lex->name, lex->if_exists()); break; } case SQLCOM_ALTER_DB_UPGRADE: @@ -5258,7 +5251,7 @@ end_with_restore_list: if (prepare_db_action(thd, ALTER_ACL, db)) break; WSREP_TO_ISOLATION_BEGIN(db->str, NULL, NULL); - res= mysql_alter_db(thd, db->str, &lex->create_info); + res= mysql_alter_db(thd, db, &lex->create_info); break; } case SQLCOM_SHOW_CREATE_DB: @@ -5418,7 +5411,7 @@ end_with_restore_list: { if (lex->type != TYPE_ENUM_PROXY && check_access(thd, lex->grant | lex->grant_tot_col | GRANT_ACL, - first_table ? first_table->db : select_lex->db, + first_table ? first_table->db.str : select_lex->db.str, first_table ? &first_table->grant.privilege : NULL, first_table ? &first_table->grant.m_internal : NULL, first_table ? 0 : 1, 0)) @@ -5499,7 +5492,7 @@ end_with_restore_list: { WSREP_TO_ISOLATION_BEGIN(WSREP_MYSQL_DB, NULL, NULL); /* Conditionally writes to binlog */ - res= mysql_grant(thd, select_lex->db, lex->users_list, lex->grant, + res= mysql_grant(thd, select_lex->db.str, lex->users_list, lex->grant, lex->sql_command == SQLCOM_REVOKE, lex->type == TYPE_ENUM_PROXY); } @@ -5884,8 +5877,8 @@ end_with_restore_list: { int sp_result; const Sp_handler *sph= Sp_handler::handler(lex->sql_command); - if (check_routine_access(thd, ALTER_PROC_ACL, lex->spname->m_db.str, - lex->spname->m_name.str, sph, 0)) + if (check_routine_access(thd, ALTER_PROC_ACL, &lex->spname->m_db, + &lex->spname->m_name, sph, 0)) goto error; /* @@ -5958,10 +5951,8 @@ end_with_restore_list: int sp_result; const Sp_handler *sph= Sp_handler::handler(lex->sql_command); - const char *db= lex->spname->m_db.str; - const char *name= lex->spname->m_name.str; - if (check_routine_access(thd, ALTER_PROC_ACL, db, name, + if (check_routine_access(thd, ALTER_PROC_ACL, &lex->spname->m_db, &lex->spname->m_name, Sp_handler::handler(lex->sql_command), 0)) goto error; WSREP_TO_ISOLATION_BEGIN(WSREP_MYSQL_DB, NULL, NULL); @@ -5990,7 +5981,7 @@ end_with_restore_list: if (sp_result != SP_KEY_NOT_FOUND && sp_automatic_privileges && !opt_noacl && - sp_revoke_privileges(thd, db, name, + sp_revoke_privileges(thd, lex->spname->m_db.str, lex->spname->m_name.str, Sp_handler::handler(lex->sql_command))) { push_warning(thd, Sql_condition::WARN_LEVEL_WARN, @@ -6587,11 +6578,11 @@ static bool check_rename_table(THD *thd, TABLE_LIST *first_table, TABLE_LIST *table; for (table= first_table; table; table= table->next_local->next_local) { - if (check_access(thd, ALTER_ACL | DROP_ACL, table->db, + if (check_access(thd, ALTER_ACL | DROP_ACL, table->db.str, &table->grant.privilege, &table->grant.m_internal, 0, 0) || - check_access(thd, INSERT_ACL | CREATE_ACL, table->next_local->db, + check_access(thd, INSERT_ACL | CREATE_ACL, table->next_local->db.str, &table->next_local->grant.privilege, &table->next_local->grant.m_internal, 0, 0)) @@ -6681,7 +6672,7 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, /* check access may be called twice in a row. Don't change to same stage */ if (thd->proc_info != stage_checking_permissions.m_name) THD_STAGE_INFO(thd, stage_checking_permissions); - if ((!db || !db[0]) && !thd->db && !dont_check_global_grants) + if ((!db || !db[0]) && !thd->db.str && !dont_check_global_grants) { DBUG_PRINT("error",("No database")); if (!no_errors) @@ -6737,7 +6728,7 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, */ if (!(sctx->master_access & SELECT_ACL)) { - if (db && (!thd->db || db_is_pattern || strcmp(db, thd->db))) + if (db && (!thd->db.str || db_is_pattern || strcmp(db, thd->db.str))) { db_access= acl_get(sctx->host, sctx->ip, sctx->priv_user, db, db_is_pattern); @@ -6786,7 +6777,7 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, DBUG_RETURN(FALSE); } - if (db && (!thd->db || db_is_pattern || strcmp(db,thd->db))) + if (db && (!thd->db.str || db_is_pattern || strcmp(db, thd->db.str))) { db_access= acl_get(sctx->host, sctx->ip, sctx->priv_user, db, db_is_pattern); @@ -6841,8 +6832,8 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, status_var_increment(thd->status_var.access_denied_errors); my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), sctx->priv_user, sctx->priv_host, - (db ? db : (thd->db ? - thd->db : + (db ? db : (thd->db.str ? + thd->db.str : "unknown"))); } DBUG_RETURN(TRUE); @@ -6880,7 +6871,7 @@ bool check_single_table_access(THD *thd, ulong privilege, !all_tables->schema_table) db_name= all_tables->view_db.str; else - db_name= all_tables->db; + db_name= all_tables->db.str; if (check_access(thd, privilege, db_name, &all_tables->grant.privilege, @@ -6969,7 +6960,7 @@ static bool check_show_access(THD *thd, TABLE_LIST *table) case SCH_TRIGGERS: case SCH_EVENTS: { - const char *dst_db_name= table->schema_select_lex->db; + const char *dst_db_name= table->schema_select_lex->db.str; DBUG_ASSERT(dst_db_name); @@ -7004,7 +6995,7 @@ static bool check_show_access(THD *thd, TABLE_LIST *table) if (thd->open_temporary_tables(dst_table)) return TRUE; - if (check_access(thd, SELECT_ACL, dst_table->db, + if (check_access(thd, SELECT_ACL, dst_table->db.str, &dst_table->grant.privilege, &dst_table->grant.m_internal, FALSE, FALSE)) @@ -7140,15 +7131,15 @@ deny: bool -check_routine_access(THD *thd, ulong want_access, const char *db, - const char *name, +check_routine_access(THD *thd, ulong want_access, const LEX_CSTRING *db, + const LEX_CSTRING *name, const Sp_handler *sph, bool no_errors) { TABLE_LIST tables[1]; bzero((char *)tables, sizeof(TABLE_LIST)); - tables->db= db; - tables->table_name= tables->alias= name; + tables->db= *db; + tables->table_name= tables->alias= *name; /* The following test is just a shortcut for check_access() (to avoid @@ -7165,7 +7156,7 @@ check_routine_access(THD *thd, ulong want_access, const char *db, DBUG_ASSERT((want_access & CREATE_PROC_ACL) == 0); if ((thd->security_ctx->master_access & want_access) == want_access) tables->grant.privilege= want_access; - else if (check_access(thd, want_access, db, + else if (check_access(thd, want_access, db->str, &tables->grant.privilege, &tables->grant.m_internal, 0, no_errors)) @@ -7232,7 +7223,7 @@ bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table) { if (access & want_access) { - if (!check_access(thd, access, table->db, + if (!check_access(thd, access, table->db.str, &table->grant.privilege, &table->grant.m_internal, 0, 1) && @@ -7345,7 +7336,7 @@ bool check_fk_parent_table_access(THD *thd, } else { - if (!thd->db) + if (!thd->db.str) { DBUG_ASSERT(create_db); db_name.length= strlen(create_db); @@ -7362,7 +7353,7 @@ bool check_fk_parent_table_access(THD *thd, } else { - if (thd->lex->copy_db_to(&db_name.str, &db_name.length)) + if (thd->lex->copy_db_to(&db_name)) return true; else is_qualified_table_name= false; @@ -7379,9 +7370,7 @@ bool check_fk_parent_table_access(THD *thd, db_name.length= my_casedn_str(files_charset_info, (char*) db_name.str); } - parent_table.init_one_table(db_name.str, db_name.length, - table_name.str, table_name.length, - table_name.str, TL_IGNORE); + parent_table.init_one_table(&db_name, &table_name, 0, TL_IGNORE); /* Check if user has any of the "privileges" at table level on @@ -7980,7 +7969,7 @@ void mysql_parse(THD *thd, char *rawbuf, uint length, lex->set_trg_event_type_for_tables(); MYSQL_QUERY_EXEC_START(thd->query(), thd->thread_id, - (char *) (thd->db ? thd->db : ""), + thd->get_db(), &thd->security_ctx->priv_user[0], (char *) thd->security_ctx->host_or_ip, 0); @@ -8132,13 +8121,14 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, { register TABLE_LIST *ptr; TABLE_LIST *UNINIT_VAR(previous_table_ref); /* The table preceding the current one. */ - const char *alias_str; + LEX_CSTRING alias_str; LEX *lex= thd->lex; DBUG_ENTER("add_table_to_list"); if (!table) DBUG_RETURN(0); // End of memory - alias_str= alias ? alias->str : table->table.str; + alias_str= alias ? *alias : table->table; + DBUG_ASSERT(alias_str.str); if (!MY_TEST(table_options & TL_OPTION_ALIAS) && check_table_name(table->table.str, table->table.length, FALSE)) { @@ -8153,7 +8143,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, DBUG_RETURN(0); } - if (!alias) /* Alias is case sensitive */ + if (!alias) /* Alias is case sensitive */ { if (table->sel) { @@ -8161,7 +8151,8 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, ER_THD(thd, ER_DERIVED_MUST_HAVE_ALIAS), MYF(0)); DBUG_RETURN(0); } - if (!(alias_str= (char*) thd->memdup(alias_str,table->table.length+1))) + /* alias_str points to table->table; Let's make a copy */ + if (!(alias_str.str= (char*) thd->memdup(alias_str.str, alias_str.length+1))) DBUG_RETURN(0); } if (!(ptr = (TABLE_LIST *) thd->calloc(sizeof(TABLE_LIST)))) @@ -8169,10 +8160,9 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, if (table->db.str) { ptr->is_fqtn= TRUE; - ptr->db= table->db.str; - ptr->db_length= table->db.length; + ptr->db= table->db; } - else if (lex->copy_db_to(&ptr->db, &ptr->db_length)) + else if (lex->copy_db_to(&ptr->db)) DBUG_RETURN(0); else ptr->is_fqtn= FALSE; @@ -8184,12 +8174,11 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, if (table->table.length) table->table.length= my_casedn_str(files_charset_info, (char*) table->table.str); - if (ptr->db_length && ptr->db != any_db) - ptr->db_length= my_casedn_str(files_charset_info, (char*) ptr->db); + if (ptr->db.length && ptr->db.str != any_db) + ptr->db.length= my_casedn_str(files_charset_info, (char*) ptr->db.str); } - ptr->table_name=table->table.str; - ptr->table_name_length=table->table.length; + ptr->table_name= table->table; ptr->lock_type= lock_type; ptr->updating= MY_TEST(table_options & TL_OPTION_UPDATING); /* TODO: remove TL_OPTION_FORCE_INDEX as it looks like it's not used */ @@ -8197,7 +8186,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, ptr->ignore_leaves= MY_TEST(table_options & TL_OPTION_IGNORE_LEAVES); ptr->sequence= MY_TEST(table_options & TL_OPTION_SEQUENCE); ptr->derived= table->sel; - if (!ptr->derived && is_infoschema_db(ptr->db, ptr->db_length)) + if (!ptr->derived && is_infoschema_db(&ptr->db)) { ST_SCHEMA_TABLE *schema_table; if (ptr->updating && @@ -8211,7 +8200,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, INFORMATION_SCHEMA_NAME.str); DBUG_RETURN(0); } - schema_table= find_schema_table(thd, ptr->table_name); + schema_table= find_schema_table(thd, &ptr->table_name); if (!schema_table || (schema_table->hidden && ((sql_command_flags[lex->sql_command] & CF_STATUS_COMMAND) == 0 || @@ -8222,7 +8211,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, lex->sql_command == SQLCOM_SHOW_KEYS))) { my_error(ER_UNKNOWN_TABLE, MYF(0), - ptr->table_name, INFORMATION_SCHEMA_NAME.str); + ptr->table_name.str, INFORMATION_SCHEMA_NAME.str); DBUG_RETURN(0); } ptr->schema_table_name= ptr->table_name; @@ -8246,10 +8235,10 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, tables ; tables=tables->next_local) { - if (!my_strcasecmp(table_alias_charset, alias_str, tables->alias) && - !strcmp(ptr->db, tables->db) && ! tables->sequence) + if (!my_strcasecmp(table_alias_charset, alias_str.str, tables->alias.str) && + !cmp(&ptr->db, &tables->db) && ! tables->sequence) { - my_error(ER_NONUNIQ_TABLE, MYF(0), alias_str); /* purecov: tested */ + my_error(ER_NONUNIQ_TABLE, MYF(0), alias_str.str); /* purecov: tested */ DBUG_RETURN(0); /* purecov: tested */ } } @@ -8295,7 +8284,8 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd, // Pure table aliases do not need to be locked: if (!MY_TEST(table_options & TL_OPTION_ALIAS)) { - ptr->mdl_request.init(MDL_key::TABLE, ptr->db, ptr->table_name, mdl_type, + ptr->mdl_request.init(MDL_key::TABLE, ptr->db.str, ptr->table_name.str, + mdl_type, MDL_TRANSACTION); } DBUG_RETURN(ptr); @@ -8336,7 +8326,8 @@ bool st_select_lex::init_nested_join(THD *thd) join_list->push_front(ptr, thd->mem_root); ptr->embedding= embedding; ptr->join_list= join_list; - ptr->alias= (char*) "(nested_join)"; + ptr->alias.str="(nested_join)"; + ptr->alias.length= sizeof("(nested_join)")-1; embedding= ptr; join_list= &nested_join->join_list; join_list->empty(); @@ -8416,7 +8407,8 @@ TABLE_LIST *st_select_lex::nest_last_join(THD *thd) ptr->embedding= embedding; ptr->join_list= join_list; - ptr->alias= (char*) "(nest_last_join)"; + ptr->alias.str= "(nest_last_join)"; + ptr->alias.length= sizeof("(nest_last_join)")-1; embedded_list= &nested_join->join_list; embedded_list->empty(); @@ -9017,14 +9009,14 @@ void sql_kill_user(THD *thd, LEX_USER *user, killed_state state) /** If pointer is not a null pointer, append filename to it. */ bool append_file_to_dir(THD *thd, const char **filename_ptr, - const char *table_name) + const LEX_CSTRING *table_name) { char buff[FN_REFLEN],*ptr, *end; if (!*filename_ptr) return 0; // nothing to do /* Check that the filename is not too long and it's a hard path */ - if (strlen(*filename_ptr)+strlen(table_name) >= FN_REFLEN-1 || + if (strlen(*filename_ptr)+table_name->length >= FN_REFLEN-1 || !test_if_hard_path(*filename_ptr)) { my_error(ER_WRONG_TABLE_NAME, MYF(0), *filename_ptr); @@ -9033,10 +9025,10 @@ bool append_file_to_dir(THD *thd, const char **filename_ptr, /* Fix is using unix filename format on dos */ strmov(buff,*filename_ptr); end=convert_dirname(buff, *filename_ptr, NullS); - if (!(ptr= (char*) thd->alloc((size_t) (end-buff) + strlen(table_name)+1))) + if (!(ptr= (char*) thd->alloc((size_t) (end-buff) + table_name->length + 1))) return 1; // End of memory *filename_ptr=ptr; - strxmov(ptr,buff,table_name,NullS); + strxmov(ptr,buff,table_name->str,NullS); return 0; } @@ -9171,12 +9163,12 @@ bool multi_update_precheck(THD *thd, TABLE_LIST *tables) continue; if (table->derived) table->grant.privilege= SELECT_ACL; - else if ((check_access(thd, UPDATE_ACL, table->db, + else if ((check_access(thd, UPDATE_ACL, table->db.str, &table->grant.privilege, &table->grant.m_internal, 0, 1) || check_grant(thd, UPDATE_ACL, table, FALSE, 1, TRUE)) && - (check_access(thd, SELECT_ACL, table->db, + (check_access(thd, SELECT_ACL, table->db.str, &table->grant.privilege, &table->grant.m_internal, 0, 0) || @@ -9196,7 +9188,7 @@ bool multi_update_precheck(THD *thd, TABLE_LIST *tables) { if (!table->table_in_first_from_clause) { - if (check_access(thd, SELECT_ACL, table->db, + if (check_access(thd, SELECT_ACL, table->db.str, &table->grant.privilege, &table->grant.m_internal, 0, 0) || @@ -9294,25 +9286,25 @@ static TABLE_LIST *multi_delete_table_match(LEX *lex, TABLE_LIST *tbl, for (TABLE_LIST *elem= tables; elem; elem= elem->next_local) { - int cmp; + int res; if (tbl->is_fqtn && elem->is_alias) continue; /* no match */ if (tbl->is_fqtn && elem->is_fqtn) - cmp= my_strcasecmp(table_alias_charset, tbl->table_name, elem->table_name) || - strcmp(tbl->db, elem->db); + res= (my_strcasecmp(table_alias_charset, tbl->table_name.str, elem->table_name.str) || + cmp(&tbl->db, &elem->db)); else if (elem->is_alias) - cmp= my_strcasecmp(table_alias_charset, tbl->alias, elem->alias); + res= my_strcasecmp(table_alias_charset, tbl->alias.str, elem->alias.str); else - cmp= my_strcasecmp(table_alias_charset, tbl->table_name, elem->table_name) || - strcmp(tbl->db, elem->db); + res= (my_strcasecmp(table_alias_charset, tbl->table_name.str, elem->table_name.str) || + cmp(&tbl->db, &elem->db)); - if (cmp) + if (res) continue; if (match) { - my_error(ER_NONUNIQ_TABLE, MYF(0), elem->alias); + my_error(ER_NONUNIQ_TABLE, MYF(0), elem->alias.str); DBUG_RETURN(NULL); } @@ -9320,7 +9312,7 @@ static TABLE_LIST *multi_delete_table_match(LEX *lex, TABLE_LIST *tbl, } if (!match) - my_error(ER_UNKNOWN_TABLE, MYF(0), tbl->table_name, "MULTI DELETE"); + my_error(ER_UNKNOWN_TABLE, MYF(0), tbl->table_name.str, "MULTI DELETE"); DBUG_RETURN(match); } @@ -9355,10 +9347,7 @@ bool multi_delete_set_locks_and_link_aux_tables(LEX *lex) if (!walk) DBUG_RETURN(TRUE); if (!walk->derived) - { target_tbl->table_name= walk->table_name; - target_tbl->table_name_length= walk->table_name_length; - } walk->updating= target_tbl->updating; walk->lock_type= target_tbl->lock_type; /* We can assume that tables to be deleted from are locked for write. */ @@ -9524,7 +9513,7 @@ bool create_table_precheck(THD *thd, TABLE_LIST *tables, if (lex->create_info.or_replace() && !lex->tmp_table()) want_priv|= DROP_ACL; - if (check_access(thd, want_priv, create_table->db, + if (check_access(thd, want_priv, create_table->db.str, &create_table->grant.privilege, &create_table->grant.m_internal, 0, 0)) @@ -9591,7 +9580,8 @@ bool create_table_precheck(THD *thd, TABLE_LIST *tables, goto err; } - if (check_fk_parent_table_access(thd, &lex->create_info, &lex->alter_info, create_table->db)) + if (check_fk_parent_table_access(thd, &lex->create_info, &lex->alter_info, + create_table->db.str)) goto err; error= FALSE; diff --git a/sql/sql_parse.h b/sql/sql_parse.h index b0371a2cb81..9c5deaf34c3 100644 --- a/sql/sql_parse.h +++ b/sql/sql_parse.h @@ -107,9 +107,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, bool is_com_multi, bool is_next_command); void log_slow_statement(THD *thd); bool append_file_to_dir(THD *thd, const char **filename_ptr, - const char *table_name); -bool append_file_to_dir(THD *thd, const char **filename_ptr, - const char *table_name); + const LEX_CSTRING *table_name); void execute_init_command(THD *thd, LEX_STRING *init_command, mysql_rwlock_t *var_lock); bool add_to_list(THD *thd, SQL_I_List<ORDER> &list, Item *group, bool asc); @@ -149,8 +147,9 @@ inline bool check_identifier_name(LEX_CSTRING *str) bool check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *tables); bool check_single_table_access(THD *thd, ulong privilege, TABLE_LIST *tables, bool no_errors); -bool check_routine_access(THD *thd,ulong want_access,const char *db, - const char *name, +bool check_routine_access(THD *thd,ulong want_access, + const LEX_CSTRING *db, + const LEX_CSTRING *name, const Sp_handler *sph, bool no_errors); bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table); bool check_some_routine_access(THD *thd, const char *db, const char *name, @@ -165,8 +164,9 @@ inline bool check_one_table_access(THD *thd, ulong privilege, TABLE_LIST *tables inline bool check_single_table_access(THD *thd, ulong privilege, TABLE_LIST *tables, bool no_errors) { return false; } -inline bool check_routine_access(THD *thd,ulong want_access, const char *db, - const char *name, +inline bool check_routine_access(THD *thd,ulong want_access, + const LEX_CSTRING *db, + const LEX_CSTRING *name, const Sp_handler *sph, bool no_errors) { return false; } inline bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table) diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 0249fa1694e..09b6331986e 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -4604,8 +4604,8 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info, object to allow fast_alter_partition_table to perform the changes. */ DBUG_ASSERT(thd->mdl_context.is_lock_owner(MDL_key::TABLE, - alter_ctx->db, - alter_ctx->table_name, + alter_ctx->db.str, + alter_ctx->table_name.str, MDL_INTENTION_EXCLUSIVE)); tab_part_info= table->part_info; @@ -5680,7 +5680,7 @@ static bool mysql_change_partitions(ALTER_PARTITION_PARAM_TYPE *lpt) THD *thd= lpt->thd; DBUG_ENTER("mysql_change_partitions"); - build_table_filename(path, sizeof(path) - 1, lpt->db, lpt->table_name, "", 0); + build_table_filename(path, sizeof(path) - 1, lpt->db.str, lpt->table_name.str, "", 0); if(mysql_trans_prepare_alter_copy_data(thd)) DBUG_RETURN(TRUE); @@ -5726,7 +5726,7 @@ static bool mysql_rename_partitions(ALTER_PARTITION_PARAM_TYPE *lpt) int error; DBUG_ENTER("mysql_rename_partitions"); - build_table_filename(path, sizeof(path) - 1, lpt->db, lpt->table_name, "", 0); + build_table_filename(path, sizeof(path) - 1, lpt->db.str, lpt->table_name.str, "", 0); if ((error= lpt->table->file->ha_rename_partitions(path))) { if (error != 1) @@ -5772,7 +5772,7 @@ static bool mysql_drop_partitions(ALTER_PARTITION_PARAM_TYPE *lpt) lpt->table->s->table_name.str, MDL_EXCLUSIVE)); - build_table_filename(path, sizeof(path) - 1, lpt->db, lpt->table_name, "", 0); + build_table_filename(path, sizeof(path) - 1, lpt->db.str, lpt->table_name.str, "", 0); if ((error= lpt->table->file->ha_drop_partitions(path))) { lpt->table->file->print_error(error, MYF(0)); @@ -6169,8 +6169,7 @@ static bool write_log_rename_frm(ALTER_PARTITION_PARAM_TYPE *lpt) DBUG_ENTER("write_log_rename_frm"); part_info->first_log_entry= NULL; - build_table_filename(path, sizeof(path) - 1, lpt->db, - lpt->table_name, "", 0); + build_table_filename(path, sizeof(path) - 1, lpt->db.str, lpt->table_name.str, "", 0); build_table_shadow_filename(shadow_path, sizeof(shadow_path) - 1, lpt); mysql_mutex_lock(&LOCK_gdl); if (write_log_replace_delete_frm(lpt, 0UL, shadow_path, path, TRUE)) @@ -6221,8 +6220,7 @@ static bool write_log_drop_partition(ALTER_PARTITION_PARAM_TYPE *lpt) DBUG_ENTER("write_log_drop_partition"); part_info->first_log_entry= NULL; - build_table_filename(path, sizeof(path) - 1, lpt->db, - lpt->table_name, "", 0); + build_table_filename(path, sizeof(path) - 1, lpt->db.str, lpt->table_name.str, "", 0); build_table_shadow_filename(tmp_path, sizeof(tmp_path) - 1, lpt); mysql_mutex_lock(&LOCK_gdl); if (write_log_dropped_partitions(lpt, &next_entry, (const char*)path, @@ -6280,8 +6278,7 @@ static bool write_log_add_change_partition(ALTER_PARTITION_PARAM_TYPE *lpt) DBUG_ASSERT(old_first_log_entry); DBUG_ENTER("write_log_add_change_partition"); - build_table_filename(path, sizeof(path) - 1, lpt->db, - lpt->table_name, "", 0); + build_table_filename(path, sizeof(path) - 1, lpt->db.str, lpt->table_name.str, "", 0); build_table_shadow_filename(tmp_path, sizeof(tmp_path) - 1, lpt); mysql_mutex_lock(&LOCK_gdl); @@ -6349,8 +6346,7 @@ static bool write_log_final_change_partition(ALTER_PARTITION_PARAM_TYPE *lpt) Replace the revert operations with forced retry operations. */ part_info->first_log_entry= NULL; - build_table_filename(path, sizeof(path) - 1, lpt->db, - lpt->table_name, "", 0); + build_table_filename(path, sizeof(path) - 1, lpt->db.str, lpt->table_name.str, "", 0); build_table_shadow_filename(shadow_path, sizeof(shadow_path) - 1, lpt); mysql_mutex_lock(&LOCK_gdl); if (write_log_changed_partitions(lpt, &next_entry, (const char*)path)) @@ -6535,8 +6531,8 @@ void handle_alter_part_error(ALTER_PARTITION_PARAM_TYPE *lpt, Better to do that here, than leave the cleaning up to others. Aquire EXCLUSIVE mdl lock if not already aquired. */ - if (!thd->mdl_context.is_lock_owner(MDL_key::TABLE, lpt->db, - lpt->table_name, + if (!thd->mdl_context.is_lock_owner(MDL_key::TABLE, lpt->db.str, + lpt->table_name.str, MDL_EXCLUSIVE)) { if (wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN)) @@ -6733,8 +6729,8 @@ uint fast_alter_partition_table(THD *thd, TABLE *table, Alter_info *alter_info, HA_CREATE_INFO *create_info, TABLE_LIST *table_list, - const char *db, - const char *table_name) + const LEX_CSTRING *db, + const LEX_CSTRING *table_name) { /* Set-up struct used to write frm files */ partition_info *part_info; @@ -6757,8 +6753,8 @@ uint fast_alter_partition_table(THD *thd, TABLE *table, lpt->table= table; lpt->key_info_buffer= 0; lpt->key_count= 0; - lpt->db= db; - lpt->table_name= table_name; + lpt->db= *db; + lpt->table_name= *table_name; lpt->copied= 0; lpt->deleted= 0; lpt->pack_frm_data= NULL; diff --git a/sql/sql_partition.h b/sql/sql_partition.h index 626ceee3f13..a5b502b37c9 100644 --- a/sql/sql_partition.h +++ b/sql/sql_partition.h @@ -57,8 +57,8 @@ typedef struct st_lock_param_type Alter_info *alter_info; TABLE *table; KEY *key_info_buffer; - const char *db; - const char *table_name; + LEX_CSTRING db; + LEX_CSTRING table_name; uchar *pack_frm_data; uint key_count; uint db_options; @@ -267,8 +267,8 @@ uint fast_alter_partition_table(THD *thd, TABLE *table, Alter_info *alter_info, HA_CREATE_INFO *create_info, TABLE_LIST *table_list, - const char *db, - const char *table_name); + const LEX_CSTRING *db, + const LEX_CSTRING *table_name); bool set_part_state(Alter_info *alter_info, partition_info *tab_part_info, enum partition_state part_state); uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info, diff --git a/sql/sql_partition_admin.cc b/sql/sql_partition_admin.cc index 4fb1891baab..2e998878351 100644 --- a/sql/sql_partition_admin.cc +++ b/sql/sql_partition_admin.cc @@ -71,15 +71,15 @@ bool Sql_cmd_alter_table_exchange_partition::execute(THD *thd) DBUG_RETURN(TRUE); /* Must be set in the parser */ - DBUG_ASSERT(select_lex->db); + DBUG_ASSERT(select_lex->db.str); /* also check the table to be exchanged with the partition */ DBUG_ASSERT(alter_info.flags & Alter_info::ALTER_EXCHANGE_PARTITION); - if (check_access(thd, priv_needed, first_table->db, + if (check_access(thd, priv_needed, first_table->db.str, &first_table->grant.privilege, &first_table->grant.m_internal, 0, 0) || - check_access(thd, priv_needed, first_table->next_local->db, + check_access(thd, priv_needed, first_table->next_local->db.str, &first_table->next_local->grant.privilege, &first_table->next_local->grant.m_internal, 0, 0)) @@ -552,13 +552,13 @@ bool Sql_cmd_alter_table_exchange_partition:: /* Will append the partition name later in part_info->get_part_elem() */ part_file_name_len= build_table_filename(part_file_name, sizeof(part_file_name), - table_list->db, - table_list->table_name, + table_list->db.str, + table_list->table_name.str, "", 0); build_table_filename(swap_file_name, sizeof(swap_file_name), - swap_table_list->db, - swap_table_list->table_name, + swap_table_list->db.str, + swap_table_list->table_name.str, "", 0); /* create a unique temp name #sqlx-nnnn_nnnn, x for eXchange */ my_snprintf(temp_name, sizeof(temp_name), "%sx-%lx_%llx", @@ -566,7 +566,7 @@ bool Sql_cmd_alter_table_exchange_partition:: if (lower_case_table_names) my_casedn_str(files_charset_info, temp_name); build_table_filename(temp_file_name, sizeof(temp_file_name), - table_list->next_local->db, + table_list->next_local->db.str, temp_name, "", FN_IS_TMP); if (!(part_elem= part_table->part_info->get_part_elem(partition_name, @@ -768,7 +768,7 @@ bool Sql_cmd_alter_table_truncate_partition::execute(THD *thd) (!thd->is_current_stmt_binlog_format_row() || !thd->find_temporary_table(first_table)) && wsrep_to_isolation_begin( - thd, first_table->db, first_table->table_name, NULL) + thd, first_table->db.str, first_table->table_name.str, NULL) ) { WSREP_WARN("ALTER TABLE TRUNCATE PARTITION isolation failure"); @@ -818,8 +818,8 @@ bool Sql_cmd_alter_table_truncate_partition::execute(THD *thd) if (thd->mdl_context.upgrade_shared_lock(ticket, MDL_EXCLUSIVE, timeout)) DBUG_RETURN(TRUE); - tdc_remove_table(thd, TDC_RT_REMOVE_NOT_OWN, first_table->db, - first_table->table_name, FALSE); + tdc_remove_table(thd, TDC_RT_REMOVE_NOT_OWN, first_table->db.str, + first_table->table_name.str, FALSE); partition= (ha_partition*) first_table->table->file; /* Invoke the handler method responsible for truncating the partition. */ diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 0429a2ad6c2..18e16a2947a 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -66,6 +66,8 @@ char *opt_plugin_dir_ptr; char opt_plugin_dir[FN_REFLEN]; ulong plugin_maturity; +static LEX_CSTRING MYSQL_PLUGIN_NAME= {STRING_WITH_LEN("plugin") }; + /* not really needed now, this map will become essential when we add more maturity levels. We cannot change existing maturity constants, @@ -1817,11 +1819,9 @@ static void plugin_load(MEM_ROOT *tmp_root) new_thd->thread_stack= (char*) &tables; new_thd->store_globals(); - new_thd->db= my_strdup("mysql", MYF(0)); - new_thd->db_length= 5; + new_thd->db= MYSQL_SCHEMA_NAME; bzero((char*) &new_thd->net, sizeof(new_thd->net)); - tables.init_one_table(STRING_WITH_LEN("mysql"), STRING_WITH_LEN("plugin"), - "plugin", TL_READ); + tables.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_PLUGIN_NAME, 0, TL_READ); tables.open_strategy= TABLE_LIST::OPEN_NORMAL; result= open_and_lock_tables(new_thd, &tables, FALSE, MYSQL_LOCK_IGNORE_TIMEOUT); @@ -1875,6 +1875,7 @@ static void plugin_load(MEM_ROOT *tmp_root) table->m_needs_reopen= TRUE; // Force close to free memory close_mysql_tables(new_thd); end: + new_thd->db= null_clex_str; // Avoid free on thd->db delete new_thd; DBUG_VOID_RETURN; } @@ -2169,7 +2170,7 @@ bool mysql_install_plugin(THD *thd, const LEX_CSTRING *name, { MYSQL_AUDIT_GENERAL_CLASSMASK }; DBUG_ENTER("mysql_install_plugin"); - tables.init_one_table("mysql", 5, "plugin", 6, "plugin", TL_WRITE); + tables.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_PLUGIN_NAME, 0, TL_WRITE); if (!opt_noacl && check_table_access(thd, INSERT_ACL, &tables, FALSE, 1, FALSE)) DBUG_RETURN(TRUE); @@ -2312,7 +2313,7 @@ bool mysql_uninstall_plugin(THD *thd, const LEX_CSTRING *name, { MYSQL_AUDIT_GENERAL_CLASSMASK }; DBUG_ENTER("mysql_uninstall_plugin"); - tables.init_one_table("mysql", 5, "plugin", 6, "plugin", TL_WRITE); + tables.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_PLUGIN_NAME, 0, TL_WRITE); if (!opt_noacl && check_table_access(thd, DELETE_ACL, &tables, FALSE, 1, FALSE)) DBUG_RETURN(TRUE); diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 0c99a271d4d..06ce5187f04 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -229,7 +229,7 @@ private: MEM_ROOT main_mem_root; sql_mode_t m_sql_mode; private: - bool set_db(const char *db, uint db_length); + bool set_db(const LEX_CSTRING *db); bool set_parameters(String *expanded_query, uchar *packet, uchar *packet_end); bool execute(String *expanded_query, bool open_cursor); @@ -1306,7 +1306,7 @@ static bool mysql_test_insert(Prepared_statement *stmt, { my_error(ER_DELAYED_NOT_SUPPORTED, MYF(0), (table_list->view ? table_list->view_name.str : - table_list->table_name)); + table_list->table_name.str)); goto error; } while ((values= its++)) @@ -1390,7 +1390,7 @@ static int mysql_test_update(Prepared_statement *stmt, if (!table_list->single_table_updatable()) { - my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "UPDATE"); + my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias.str, "UPDATE"); goto error; } @@ -1468,7 +1468,7 @@ static bool mysql_test_delete(Prepared_statement *stmt, if (!table_list->single_table_updatable()) { - my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "DELETE"); + my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias.str, "DELETE"); goto error; } if (!table_list->table || !table_list->table->is_created()) @@ -3817,24 +3817,22 @@ bool Prepared_statement::set_name(LEX_CSTRING *name_arg) a prepared statement since it affects execution environment: privileges, @@character_set_database, and other. - @return Returns an error if out of memory. + @return 1 if out of memory. */ bool -Prepared_statement::set_db(const char *db_arg, uint db_length_arg) +Prepared_statement::set_db(const LEX_CSTRING *db_arg) { /* Remember the current database. */ - if (db_arg && db_length_arg) + if (db_arg->length) { - db= this->strmake(db_arg, db_length_arg); - db_length= db_length_arg; + if (!(db.str= this->strmake(db_arg->str, db_arg->length))) + return 1; + db.length= db_arg->length; } else - { - db= NULL; - db_length= 0; - } - return db_arg != NULL && db == NULL; + db= null_clex_str; + return 0; } /************************************************************************** @@ -3882,7 +3880,7 @@ bool Prepared_statement::prepare(const char *packet, uint packet_len) if (! (lex= new (mem_root) st_lex_local)) DBUG_RETURN(TRUE); - if (set_db(thd->db, thd->db_length)) + if (set_db(&thd->db)) DBUG_RETURN(TRUE); /* @@ -4460,7 +4458,7 @@ Prepared_statement::reprepare() char saved_cur_db_name_buf[SAFE_NAME_LEN+1]; LEX_STRING saved_cur_db_name= { saved_cur_db_name_buf, sizeof(saved_cur_db_name_buf) }; - LEX_CSTRING stmt_db_name= { db, db_length }; + LEX_CSTRING stmt_db_name= db; bool cur_db_changed; bool error; @@ -4583,8 +4581,7 @@ Prepared_statement::swap_prepared_statement(Prepared_statement *copy) /* Swap names, the old name is allocated in the wrong memory root */ swap_variables(LEX_CSTRING, name, copy->name); /* Ditto */ - swap_variables(char *, db, copy->db); - swap_variables(size_t, db_length, copy->db_length); + swap_variables(LEX_CSTRING, db, copy->db); DBUG_ASSERT(param_count == copy->param_count); DBUG_ASSERT(thd == copy->thd); @@ -4626,7 +4623,7 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor) { saved_cur_db_name_buf, sizeof(saved_cur_db_name_buf) }; bool cur_db_changed; - LEX_CSTRING stmt_db_name= { db, db_length }; + LEX_CSTRING stmt_db_name= db; status_var_increment(thd->status_var.com_stmt_execute); @@ -4727,7 +4724,7 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor) PSI_statement_locker *parent_locker; MYSQL_QUERY_EXEC_START(thd->query(), thd->thread_id, - (char *) (thd->db ? thd->db : ""), + thd->get_db(), &thd->security_ctx->priv_user[0], (char *) thd->security_ctx->host_or_ip, 1); diff --git a/sql/sql_reload.cc b/sql/sql_reload.cc index 93db089b24a..b8f0023eefb 100644 --- a/sql/sql_reload.cc +++ b/sql/sql_reload.cc @@ -289,7 +289,7 @@ bool reload_acl_and_cache(THD *thd, unsigned long long options, if (tables) { for (TABLE_LIST *t= tables; t; t= t->next_local) - if (!find_table_for_mdl_upgrade(thd, t->db, t->table_name, false)) + if (!find_table_for_mdl_upgrade(thd, t->db.str, t->table_name.str, false)) return 1; } else @@ -412,11 +412,11 @@ bool reload_acl_and_cache(THD *thd, unsigned long long options, reset_mqh((LEX_USER *) NULL, 0); /* purecov: inspected */ if (options & REFRESH_GENERIC) { - List_iterator_fast<LEX_STRING> li(thd->lex->view_list); - LEX_STRING *ls; + List_iterator_fast<LEX_CSTRING> li(thd->lex->view_list); + LEX_CSTRING *ls; while ((ls= li++)) { - ST_SCHEMA_TABLE *table= find_schema_table(thd, ls->str); + ST_SCHEMA_TABLE *table= find_schema_table(thd, ls); if (table->reset_table()) result= 1; } @@ -540,8 +540,8 @@ bool flush_tables_with_read_lock(THD *thd, TABLE_LIST *all_tables) { /* Request removal of table from cache. */ tdc_remove_table(thd, TDC_RT_REMOVE_UNUSED, - table_list->db, - table_list->table_name, FALSE); + table_list->db.str, + table_list->table_name.str, FALSE); /* Reset ticket to satisfy asserts in open_tables(). */ table_list->mdl_request.ticket= NULL; } @@ -573,7 +573,7 @@ bool flush_tables_with_read_lock(THD *thd, TABLE_LIST *all_tables) if (!(table_list->table->file->ha_table_flags() & HA_CAN_EXPORT)) { my_error(ER_ILLEGAL_HA, MYF(0),table_list->table->file->table_type(), - table_list->db, table_list->table_name); + table_list->db.str, table_list->table_name.str); goto error_reset_bits; } } diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc index 31cc6bcdd31..fa0fa3f0ea5 100644 --- a/sql/sql_rename.cc +++ b/sql/sql_rename.cc @@ -34,8 +34,8 @@ static TABLE_LIST *rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error); -static bool do_rename(THD *thd, TABLE_LIST *ren_table, const char *new_db, - const char *new_table_name, const char *new_table_alias, +static bool do_rename(THD *thd, TABLE_LIST *ren_table, const LEX_CSTRING *new_db, + const LEX_CSTRING *new_table_name, const LEX_CSTRING *new_table_alias, bool skip_error); static TABLE_LIST *reverse_table_list(TABLE_LIST *table_list); @@ -104,8 +104,9 @@ bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent) Two renames of "log_table TO" w/o rename "TO log_table" in between. */ - my_error(ER_CANT_RENAME_LOG_TABLE, MYF(0), ren_table->table_name, - ren_table->table_name); + my_error(ER_CANT_RENAME_LOG_TABLE, MYF(0), + ren_table->table_name.str, + ren_table->table_name.str); goto err; } } @@ -117,14 +118,15 @@ bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent) Attempt to rename a table TO log_table w/o renaming log_table TO some table. */ - my_error(ER_CANT_RENAME_LOG_TABLE, MYF(0), ren_table->table_name, - ren_table->table_name); + my_error(ER_CANT_RENAME_LOG_TABLE, MYF(0), + ren_table->table_name.str, + ren_table->table_name.str); goto err; } else { /* save the name of the log table to report an error */ - rename_log_table[log_table_rename]= ren_table->table_name; + rename_log_table[log_table_rename]= ren_table->table_name.str; } } } @@ -216,21 +218,21 @@ static bool do_rename_temporary(THD *thd, TABLE_LIST *ren_table, TABLE_LIST *new_table, bool skip_error) { - const char *new_alias; + LEX_CSTRING *new_alias; DBUG_ENTER("do_rename_temporary"); - new_alias= (lower_case_table_names == 2) ? new_table->alias : - new_table->table_name; + new_alias= (lower_case_table_names == 2) ? &new_table->alias : + &new_table->table_name; if (is_temporary_table(new_table)) { - my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias); + my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias->str); DBUG_RETURN(1); // This can't be skipped } DBUG_RETURN(thd->rename_temporary_table(ren_table->table, - new_table->db, new_alias)); + &new_table->db, new_alias)); } @@ -255,67 +257,62 @@ do_rename_temporary(THD *thd, TABLE_LIST *ren_table, TABLE_LIST *new_table, */ static bool -do_rename(THD *thd, TABLE_LIST *ren_table, const char *new_db, - const char *new_table_name, const char *new_table_alias, +do_rename(THD *thd, TABLE_LIST *ren_table, const LEX_CSTRING *new_db, + const LEX_CSTRING *new_table_name, const LEX_CSTRING *new_table_alias, bool skip_error) { int rc= 1; handlerton *hton; - const char *new_alias, *old_alias; + LEX_CSTRING old_alias, new_alias; DBUG_ENTER("do_rename"); if (lower_case_table_names == 2) { old_alias= ren_table->alias; - new_alias= new_table_alias; + new_alias= *new_table_alias; } else { old_alias= ren_table->table_name; - new_alias= new_table_name; + new_alias= *new_table_name; } - DBUG_ASSERT(new_alias); + DBUG_ASSERT(new_alias.str); - if (ha_table_exists(thd, new_db, new_alias)) + if (ha_table_exists(thd, new_db, &new_alias)) { - my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias); + my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias.str); DBUG_RETURN(1); // This can't be skipped } - if (ha_table_exists(thd, ren_table->db, old_alias, &hton) && hton) + if (ha_table_exists(thd, &ren_table->db, &old_alias, &hton) && hton) { DBUG_ASSERT(!thd->locked_tables_mode); tdc_remove_table(thd, TDC_RT_REMOVE_ALL, - ren_table->db, ren_table->table_name, false); + ren_table->db.str, ren_table->table_name.str, false); if (hton != view_pseudo_hton) { - if (!(rc= mysql_rename_table(hton, ren_table->db, old_alias, - new_db, new_alias, 0))) + if (!(rc= mysql_rename_table(hton, &ren_table->db, &old_alias, + new_db, &new_alias, 0))) { - LEX_CSTRING db_name= { ren_table->db, ren_table->db_length }; - LEX_CSTRING table_name= { ren_table->table_name, - ren_table->table_name_length }; - LEX_CSTRING new_table= { new_alias, strlen(new_alias) }; - LEX_CSTRING new_db_name= { new_db, strlen(new_db)}; - (void) rename_table_in_stat_tables(thd, &db_name, &table_name, - &new_db_name, &new_table); + (void) rename_table_in_stat_tables(thd, &ren_table->db, + &ren_table->table_name, + new_db, &new_alias); VTMD_rename vtmd(*ren_table); if (thd->variables.vers_alter_history == VERS_ALTER_HISTORY_SURVIVE) { - rc= vtmd.try_rename(thd, new_db_name, new_table); + rc= vtmd.try_rename(thd, new_db->str, new_alias.str); if (rc) goto revert_table_name; } - rc= Table_triggers_list::change_table_name(thd, ren_table->db, - old_alias, - ren_table->table_name, - new_db, - new_alias); - if (rc) + if ((rc= Table_triggers_list::change_table_name(thd, &ren_table->db, + &old_alias, + &ren_table->table_name, + new_db, + &new_alias))) { if (thd->variables.vers_alter_history == VERS_ALTER_HISTORY_SURVIVE) - vtmd.revert_rename(thd, new_db_name); + vtmd.revert_rename(thd, new_db->str); revert_table_name: /* We've succeeded in renaming table's .frm and in updating @@ -323,8 +320,8 @@ revert_table_name: triggers appropriately. So let us revert operations on .frm and handler's data and report about failure to rename table. */ - (void) mysql_rename_table(hton, new_db, new_alias, - ren_table->db, old_alias, NO_FK_CHECKS); + (void) mysql_rename_table(hton, new_db, &new_alias, + &ren_table->db, &old_alias, NO_FK_CHECKS); } } } @@ -336,15 +333,15 @@ revert_table_name: because a view has valid internal db&table names in this case. */ if (thd->lex->sql_command != SQLCOM_ALTER_DB_UPGRADE && - strcmp(ren_table->db, new_db)) - my_error(ER_FORBID_SCHEMA_CHANGE, MYF(0), ren_table->db, new_db); + cmp(&ren_table->db, new_db)) + my_error(ER_FORBID_SCHEMA_CHANGE, MYF(0), ren_table->db.str, new_db->str); else - rc= mysql_rename_view(thd, new_db, new_alias, ren_table); + rc= mysql_rename_view(thd, new_db, &new_alias, ren_table); } } else { - my_error(ER_NO_SUCH_TABLE, MYF(0), ren_table->db, old_alias); + my_error(ER_NO_SUCH_TABLE, MYF(0), ren_table->db.str, old_alias.str); } if (rc && !skip_error) DBUG_RETURN(1); @@ -390,8 +387,8 @@ rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error) if (is_temporary_table(ren_table) ? do_rename_temporary(thd, ren_table, new_table, skip_error) : - do_rename(thd, ren_table, new_table->db, new_table->table_name, - new_table->alias, skip_error)) + do_rename(thd, ren_table, &new_table->db, &new_table->table_name, + &new_table->alias, skip_error)) DBUG_RETURN(ren_table); } DBUG_RETURN(0); diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index e4a39401b04..6e6b9b58ad2 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -4265,7 +4265,7 @@ int log_loaded_block(IO_CACHE* file, uchar *Buffer, size_t Count) lf_info->last_pos_in_file= my_b_get_pos_in_file(file); if (lf_info->wrote_create_file) { - Append_block_log_event a(lf_info->thd, lf_info->thd->db, buffer, + Append_block_log_event a(lf_info->thd, lf_info->thd->db.str, buffer, MY_MIN(block_len, max_event_size), lf_info->log_delayed); if (mysql_bin_log.write(&a)) @@ -4273,7 +4273,7 @@ int log_loaded_block(IO_CACHE* file, uchar *Buffer, size_t Count) } else { - Begin_load_query_log_event b(lf_info->thd, lf_info->thd->db, + Begin_load_query_log_event b(lf_info->thd, lf_info->thd->db.str, buffer, MY_MIN(block_len, max_event_size), lf_info->log_delayed); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index bd9da10e4b1..b19cfefb3e3 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -753,7 +753,7 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables, COND **where_expr else if (table->vers_conditions.user_defined() && (table->is_non_derived() || !table->vers_conditions.used)) { - my_error(ER_VERS_NOT_VERSIONED, MYF(0), table->alias); + my_error(ER_VERS_NOT_VERSIONED, MYF(0), table->alias.str); DBUG_RETURN(-1); } } @@ -807,7 +807,7 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables, COND **where_expr { #define PART_VERS_ERR_MSG "%s PARTITION (%s)" char buf[NAME_LEN*2 + sizeof(PART_VERS_ERR_MSG)]; - my_snprintf(buf, sizeof(buf), PART_VERS_ERR_MSG, table->alias, + my_snprintf(buf, sizeof(buf), PART_VERS_ERR_MSG, table->alias.str, table->partition_names->head()->c_ptr()); my_error(ER_VERS_NOT_VERSIONED, MYF(0), buf); DBUG_RETURN(-1); @@ -848,9 +848,9 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables, COND **where_expr const LEX_CSTRING *fend= &table->table->vers_end_field()->field_name; Item *row_start= - newx Item_field(thd, &this->context, table->db, table->alias, fstart); + newx Item_field(thd, &this->context, table->db.str, table->alias.str, fstart); Item *row_end= - newx Item_field(thd, &this->context, table->db, table->alias, fend); + newx Item_field(thd, &this->context, table->db.str, table->alias.str, fend); bool tmp_from_ib= table->table->s->table_category == TABLE_CATEGORY_TEMPORARY && @@ -867,7 +867,7 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables, COND **where_expr if (timestamps_only && (vers_conditions.unit_start == VERS_TRX_ID || vers_conditions.unit_end == VERS_TRX_ID)) { - my_error(ER_VERS_ENGINE_UNSUPPORTED, MYF(0), table->table_name); + my_error(ER_VERS_ENGINE_UNSUPPORTED, MYF(0), table->table_name.str); DBUG_RETURN(-1); } } @@ -2870,7 +2870,7 @@ bool JOIN::make_aggr_tables_info() all_fields, NULL, query.distinct, TRUE, select_options, HA_POS_ERROR, - "", !need_tmp, + &empty_clex_str, !need_tmp, query.order_by || query.group_by); if (!table) DBUG_RETURN(1); @@ -3373,7 +3373,7 @@ JOIN::create_postjoin_aggr_table(JOIN_TAB *tab, List<Item> *table_fields, TABLE* table= create_tmp_table(thd, tab->tmp_table_param, *table_fields, table_group, distinct, save_sum_fields, select_options, table_rows_limit, - "", true, keep_row_order); + &empty_clex_str, true, keep_row_order); if (!table) DBUG_RETURN(true); tmp_table_param.using_outer_summary_function= @@ -17039,7 +17039,7 @@ TABLE * create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields, ORDER *group, bool distinct, bool save_sum_fields, ulonglong select_options, ha_rows rows_limit, - const char *table_alias, bool do_not_open, + const LEX_CSTRING *table_alias, bool do_not_open, bool keep_row_order) { MEM_ROOT *mem_root_save, own_root; @@ -17076,7 +17076,7 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields, DBUG_ENTER("create_tmp_table"); DBUG_PRINT("enter", ("table_alias: '%s' distinct: %d save_sum_fields: %d " - "rows_limit: %lu group: %d", table_alias, + "rows_limit: %lu group: %d", table_alias->str, (int) distinct, (int) save_sum_fields, (ulong) rows_limit, MY_TEST(group))); @@ -17192,7 +17192,7 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields, thd->mem_root= &table->mem_root; table->field=reg_field; - table->alias.set(table_alias, strlen(table_alias), table_alias_charset); + table->alias.set(table_alias->str, table_alias->length, table_alias_charset); table->reginfo.lock_type=TL_WRITE; /* Will be updated */ table->map=1; @@ -25007,7 +25007,7 @@ bool JOIN_TAB::save_explain_data(Explain_table_access *eta, } } } - eta->table_name.copy(real_table->alias, strlen(real_table->alias), cs); + eta->table_name.copy(real_table->alias.str, real_table->alias.length, cs); } /* "partitions" column */ @@ -25333,7 +25333,7 @@ bool JOIN_TAB::save_explain_data(Explain_table_access *eta, eta->firstmatch_table_name.append(namebuf, len); } else - eta->firstmatch_table_name.append(prev_table->pos_in_table_list->alias); + eta->firstmatch_table_name.append(&prev_table->pos_in_table_list->alias); } } @@ -25932,8 +25932,8 @@ Index_hint::print(THD *thd, String *str) strlen(primary_key_name))) str->append(primary_key_name); else - append_identifier(thd, str, key_name.str, key_name.length); - } + append_identifier(thd, str, &key_name); +} str->append(')'); } @@ -25989,10 +25989,10 @@ void TABLE_LIST::print(THD *thd, table_map eliminated_tables, String *str, if (!(belong_to_view && belong_to_view->compact_view_format)) { - append_identifier(thd, str, view_db.str, view_db.length); + append_identifier(thd, str, &view_db); str->append('.'); } - append_identifier(thd, str, view_name.str, view_name.length); + append_identifier(thd, str, &view_name); cmp_name= view_name.str; } else if (derived) @@ -26007,8 +26007,8 @@ void TABLE_LIST::print(THD *thd, table_map eliminated_tables, String *str, } else { - append_identifier(thd, str, table_name, table_name_length); - cmp_name= table_name; + append_identifier(thd, str, &table_name); + cmp_name= table_name.str; } } else @@ -26018,19 +26018,18 @@ void TABLE_LIST::print(THD *thd, table_map eliminated_tables, String *str, if (!(belong_to_view && belong_to_view->compact_view_format)) { - append_identifier(thd, str, db, db_length); + append_identifier(thd, str, &db); str->append('.'); } if (schema_table) { - append_identifier(thd, str, schema_table_name, - strlen(schema_table_name)); - cmp_name= schema_table_name; + append_identifier(thd, str, &schema_table_name); + cmp_name= schema_table_name.str; } else { - append_identifier(thd, str, table_name, table_name_length); - cmp_name= table_name; + append_identifier(thd, str, &table_name); + cmp_name= table_name.str; } #ifdef WITH_PARTITION_STORAGE_ENGINE if (partition_names && partition_names->elements) @@ -26054,23 +26053,23 @@ void TABLE_LIST::print(THD *thd, table_map eliminated_tables, String *str, // versioning conditions are already unwrapped to WHERE clause str->append(" FOR SYSTEM_TIME ALL"); } - if (my_strcasecmp(table_alias_charset, cmp_name, alias)) + if (my_strcasecmp(table_alias_charset, cmp_name, alias.str)) { char t_alias_buff[MAX_ALIAS_NAME]; - const char *t_alias= alias; + LEX_CSTRING t_alias= alias; str->append(' '); if (lower_case_table_names== 1) { - if (alias && alias[0]) + if (alias.str && alias.str[0]) { - strmov(t_alias_buff, alias); - my_casedn_str(files_charset_info, t_alias_buff); - t_alias= t_alias_buff; + strmov(t_alias_buff, alias.str); + t_alias.length= my_casedn_str(files_charset_info, t_alias_buff); + t_alias.str= t_alias_buff; } } - append_identifier(thd, str, t_alias, strlen(t_alias)); + append_identifier(thd, str, &t_alias); } if (index_hints) diff --git a/sql/sql_select.h b/sql/sql_select.h index 0ae6d20a6e6..08ad7fa9464 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -2377,7 +2377,7 @@ int append_possible_keys(MEM_ROOT *alloc, String_list &list, TABLE *table, TABLE *create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields, ORDER *group, bool distinct, bool save_sum_fields, ulonglong select_options, ha_rows rows_limit, - const char* alias, bool do_not_open=FALSE, + const LEX_CSTRING *alias, bool do_not_open=FALSE, bool keep_row_order= FALSE); void free_tmp_table(THD *thd, TABLE *entry); bool create_internal_tmp_table_from_heap(THD *thd, TABLE *table, diff --git a/sql/sql_sequence.cc b/sql/sql_sequence.cc index de4cd3522a5..8fd5bfe371c 100644 --- a/sql/sql_sequence.cc +++ b/sql/sql_sequence.cc @@ -220,8 +220,8 @@ bool check_sequence_fields(LEX *lex, List<Create_field> *fields) err: my_error(ER_SEQUENCE_INVALID_TABLE_STRUCTURE, MYF(0), - lex->select_lex.table_list.first->db, - lex->select_lex.table_list.first->table_name, reason); + lex->select_lex.table_list.first->db.str, + lex->select_lex.table_list.first->table_name.str, reason); DBUG_RETURN(TRUE); } @@ -843,7 +843,7 @@ bool Sql_cmd_alter_sequence::execute(THD *thd) No_such_table_error_handler no_such_table_handler; DBUG_ENTER("Sql_cmd_alter_sequence::execute"); - if (check_access(thd, ALTER_ACL, first_table->db, + if (check_access(thd, ALTER_ACL, first_table->db.str, &first_table->grant.privilege, &first_table->grant.m_internal, 0, 0)) @@ -865,9 +865,9 @@ bool Sql_cmd_alter_sequence::execute(THD *thd) if (trapped_errors) { StringBuffer<FN_REFLEN> tbl_name; - tbl_name.append(first_table->db); + tbl_name.append(&first_table->db); tbl_name.append('.'); - tbl_name.append(first_table->table_name); + tbl_name.append(&first_table->table_name); push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_UNKNOWN_SEQUENCES, ER_THD(thd, ER_UNKNOWN_SEQUENCES), @@ -909,8 +909,8 @@ bool Sql_cmd_alter_sequence::execute(THD *thd) if (new_seq->check_and_adjust(0)) { my_error(ER_SEQUENCE_INVALID_DATA, MYF(0), - first_table->db, - first_table->table_name); + first_table->db.str, + first_table->table_name.str); error= 1; goto end; } diff --git a/sql/sql_servers.cc b/sql/sql_servers.cc index 30b2e11139b..599073f0adf 100644 --- a/sql/sql_servers.cc +++ b/sql/sql_servers.cc @@ -54,6 +54,8 @@ static HASH servers_cache; static MEM_ROOT mem; static mysql_rwlock_t THR_LOCK_servers; +static LEX_CSTRING MYSQL_SERVERS_NAME= {STRING_WITH_LEN("servers") }; + static bool get_server_from_table_to_cache(TABLE *table); @@ -251,7 +253,7 @@ bool servers_reload(THD *thd) DBUG_PRINT("info", ("locking servers_cache")); mysql_rwlock_wrlock(&THR_LOCK_servers); - tables[0].init_one_table("mysql", 5, "servers", 7, "servers", TL_READ); + tables[0].init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_SERVERS_NAME, 0, TL_READ); if (open_and_lock_tables(thd, tables, FALSE, MYSQL_LOCK_IGNORE_TIMEOUT)) { @@ -383,10 +385,9 @@ insert_server(THD *thd, FOREIGN_SERVER *server) int error= -1; TABLE_LIST tables; TABLE *table; - DBUG_ENTER("insert_server"); - tables.init_one_table("mysql", 5, "servers", 7, "servers", TL_WRITE); + tables.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_SERVERS_NAME, 0, TL_WRITE); /* need to open before acquiring THR_LOCK_plugin or it will deadlock */ if (! (table= open_ltable(thd, &tables, TL_WRITE, MYSQL_LOCK_IGNORE_TIMEOUT))) @@ -603,7 +604,7 @@ static int drop_server_internal(THD *thd, LEX_SERVER_OPTIONS *server_options) DBUG_PRINT("info", ("server name server->server_name %s", server_options->server_name.str)); - tables.init_one_table("mysql", 5, "servers", 7, "servers", TL_WRITE); + tables.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_SERVERS_NAME, 0, TL_WRITE); /* hit the memory hit first */ if ((error= delete_server_record_in_cache(server_options))) @@ -734,8 +735,7 @@ int update_server(THD *thd, FOREIGN_SERVER *existing, FOREIGN_SERVER *altered) TABLE_LIST tables; DBUG_ENTER("update_server"); - tables.init_one_table("mysql", 5, "servers", 7, "servers", - TL_WRITE); + tables.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_SERVERS_NAME, 0, TL_WRITE); if (!(table= open_ltable(thd, &tables, TL_WRITE, MYSQL_LOCK_IGNORE_TIMEOUT))) { diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 19053d6c311..812fbeaea4e 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1247,8 +1247,8 @@ mysqld_show_create_get_fields(THD *thd, TABLE_LIST *table_list, bool error= TRUE; MEM_ROOT *mem_root= thd->mem_root; DBUG_ENTER("mysqld_show_create_get_fields"); - DBUG_PRINT("enter",("db: %s table: %s",table_list->db, - table_list->table_name)); + DBUG_PRINT("enter",("db: %s table: %s",table_list->db.str, + table_list->table_name.str)); /* We want to preserve the tree for views. */ thd->lex->context_analysis_only|= CONTEXT_ANALYSIS_ONLY_VIEW; @@ -1276,14 +1276,14 @@ mysqld_show_create_get_fields(THD *thd, TABLE_LIST *table_list, if (thd->lex->table_type == TABLE_TYPE_VIEW && !table_list->view) { my_error(ER_WRONG_OBJECT, MYF(0), - table_list->db, table_list->table_name, "VIEW"); + table_list->db.str, table_list->table_name.str, "VIEW"); goto exit; } else if (thd->lex->table_type == TABLE_TYPE_SEQUENCE && table_list->table->s->table_type != TABLE_TYPE_SEQUENCE) { my_error(ER_NOT_SEQUENCE, MYF(0), - table_list->db, table_list->table_name); + table_list->db.str, table_list->table_name.str); goto exit; } @@ -1359,8 +1359,8 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list) List<Item> field_list; bool error= TRUE; DBUG_ENTER("mysqld_show_create"); - DBUG_PRINT("enter",("db: %s table: %s",table_list->db, - table_list->table_name)); + DBUG_PRINT("enter",("db: %s table: %s",table_list->db.str, + table_list->table_name.str)); /* Metadata locks taken during SHOW CREATE should be released when @@ -1392,8 +1392,7 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list) else { if (table_list->schema_table) - protocol->store(table_list->schema_table->table_name, - system_charset_info); + protocol->store(table_list->schema_table->table_name, system_charset_info); else protocol->store(table_list->table->alias.c_ptr(), system_charset_info); } @@ -1481,7 +1480,7 @@ bool mysqld_show_create_db(THD *thd, LEX_CSTRING *dbname, DBUG_RETURN(TRUE); } #endif - if (is_infoschema_db(dbname->str)) + if (is_infoschema_db(dbname)) { *dbname= INFORMATION_SCHEMA_NAME; create.default_table_charset= system_charset_info; @@ -1510,7 +1509,7 @@ bool mysqld_show_create_db(THD *thd, LEX_CSTRING *dbname, buffer.append(STRING_WITH_LEN("CREATE DATABASE ")); if (options.if_not_exists()) buffer.append(STRING_WITH_LEN("/*!32312 IF NOT EXISTS*/ ")); - append_identifier(thd, &buffer, dbname->str, dbname->length); + append_identifier(thd, &buffer, dbname); if (create.default_table_charset) { @@ -1545,7 +1544,7 @@ mysqld_list_fields(THD *thd, TABLE_LIST *table_list, const char *wild) TABLE *table; MEM_ROOT *mem_root= thd->mem_root; DBUG_ENTER("mysqld_list_fields"); - DBUG_PRINT("enter",("table: %s",table_list->table_name)); + DBUG_PRINT("enter",("table: %s", table_list->table_name.str)); if (open_normal_and_derived_tables(thd, table_list, MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL, @@ -1885,7 +1884,7 @@ static void append_create_options(THD *thd, String *packet, DBUG_ASSERT(opt->value.str); packet->append(' '); - append_identifier(thd, packet, opt->name.str, opt->name.length); + append_identifier(thd, packet, &opt->name); packet->append('='); if (opt->quoted_value) append_unescaped(packet, opt->value.str, opt->value.length); @@ -2099,7 +2098,7 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet, { List<Item> field_list; char tmp[MAX_FIELD_WIDTH], *for_str, def_value_buf[MAX_FIELD_WIDTH]; - const char *alias; + LEX_CSTRING alias; String type; String def_value; Field **ptr,*field; @@ -2145,15 +2144,19 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet, if (create_info_arg && create_info_arg->if_not_exists()) packet->append(STRING_WITH_LEN("IF NOT EXISTS ")); if (table_list->schema_table) - alias= table_list->schema_table->table_name; + { + alias.str= table_list->schema_table->table_name; + alias.length= strlen(alias.str); + } else { if (lower_case_table_names == 2 || table_list->vers_force_alias) - alias= table->alias.c_ptr(); - else { - alias= share->table_name.str; + alias.str= table->alias.c_ptr(); + alias.length= table->alias.length(); } + else + alias= share->table_name; } /* @@ -2167,14 +2170,14 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet, { const LEX_CSTRING *const db= table_list->schema_table ? &INFORMATION_SCHEMA_NAME : &table->s->db; - if (!thd->db || strcmp(db->str, thd->db)) + if (!thd->db.str || cmp(db, &thd->db)) { - append_identifier(thd, packet, db->str, db->length); + append_identifier(thd, packet, db); packet->append(STRING_WITH_LEN(".")); } } - append_identifier(thd, packet, alias, strlen(alias)); + append_identifier(thd, packet, &alias); packet->append(STRING_WITH_LEN(" (\n")); /* We need this to get default values from the table @@ -2196,8 +2199,7 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet, not_the_first_field= true; packet->append(STRING_WITH_LEN(" ")); - append_identifier(thd,packet,field->field_name.str, - field->field_name.length); + append_identifier(thd, packet, &field->field_name); packet->append(' '); type.set(tmp, sizeof(tmp), system_charset_info); @@ -2330,7 +2332,7 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet, packet->append(STRING_WITH_LEN("KEY ")); if (!found_primary) - append_identifier(thd, packet, key_info->name.str, key_info->name.length); + append_identifier(thd, packet, &key_info->name); packet->append(STRING_WITH_LEN(" (")); @@ -2344,8 +2346,7 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet, packet->append(','); if (key_part->field) - append_identifier(thd,packet, key_part->field->field_name.str, - key_part->field->field_name.length); + append_identifier(thd, packet, &key_part->field->field_name); if (key_part->field && (key_part->length != table->field[key_part->fieldnr-1]->key_length() && @@ -2361,7 +2362,7 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet, { LEX_CSTRING *parser_name= plugin_name(key_info->parser); packet->append(STRING_WITH_LEN(" /*!50100 WITH PARSER ")); - append_identifier(thd, packet, parser_name->str, parser_name->length); + append_identifier(thd, packet, parser_name); packet->append(STRING_WITH_LEN(" */ ")); } append_create_options(thd, packet, key_info->option_list, check_options, @@ -2413,10 +2414,10 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet, check->print(&str); packet->append(STRING_WITH_LEN(",\n ")); - if (check->name.length) + if (check->name.str) { packet->append(STRING_WITH_LEN("CONSTRAINT ")); - append_identifier(thd, packet, check->name.str, check->name.length); + append_identifier(thd, packet, &check->name); } packet->append(STRING_WITH_LEN(" CHECK (")); packet->append(str); @@ -2560,11 +2561,11 @@ void append_definer(THD *thd, String *buffer, const LEX_CSTRING *definer_user, const LEX_CSTRING *definer_host) { buffer->append(STRING_WITH_LEN("DEFINER=")); - append_identifier(thd, buffer, definer_user->str, definer_user->length); + append_identifier(thd, buffer, definer_user); if (definer_host->str && definer_host->str[0]) { buffer->append('@'); - append_identifier(thd, buffer, definer_host->str, definer_host->length); + append_identifier(thd, buffer, definer_host); } buffer->append(' '); } @@ -2580,7 +2581,7 @@ static int show_create_view(THD *thd, TABLE_LIST *table, String *buff) MODE_MAXDB | MODE_ANSI)) != 0; - if (!thd->db || strcmp(thd->db, table->view_db.str)) + if (!thd->db.str || cmp(&thd->db, &table->view_db)) /* print compact view name if the view belongs to the current database */ @@ -2597,7 +2598,7 @@ static int show_create_view(THD *thd, TABLE_LIST *table, String *buff) tbl; tbl= tbl->next_global) { - if (strcmp(table->view_db.str, tbl->view ? tbl->view_db.str :tbl->db)!= 0) + if (cmp(&table->view_db, tbl->view ? &tbl->view_db : &tbl->db)) { table->compact_view_format= FALSE; break; @@ -2613,10 +2614,10 @@ static int show_create_view(THD *thd, TABLE_LIST *table, String *buff) buff->append(STRING_WITH_LEN("VIEW ")); if (!compact_view_name) { - append_identifier(thd, buff, table->view_db.str, table->view_db.length); + append_identifier(thd, buff, &table->view_db); buff->append('.'); } - append_identifier(thd, buff, table->view_name.str, table->view_name.length); + append_identifier(thd, buff, &table->view_name); buff->append(STRING_WITH_LEN(" AS ")); /* @@ -2659,7 +2660,7 @@ static int show_create_sequence(THD *thd, TABLE_LIST *table_list, alias= table->s->table_name; packet->append(STRING_WITH_LEN("CREATE SEQUENCE ")); - append_identifier(thd, packet, alias.str, alias.length); + append_identifier(thd, packet, &alias); packet->append(STRING_WITH_LEN(" start with ")); packet->append_longlong(seq->start); packet->append(STRING_WITH_LEN(" minvalue ")); @@ -2833,8 +2834,9 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) The following variables are only safe to access under a lock */ - if ((thd_info->db= tmp->db)) // Safe test - thd_info->db= thd->strdup(thd_info->db); + thd_info->db= 0; + if (tmp->db.str) + thd_info->db= thd->strmake(tmp->db.str, tmp->db.length); if (tmp->query()) { @@ -3194,7 +3196,7 @@ int fill_schema_processlist(THD* thd, TABLE_LIST* tables, COND* cond) while ((tmp= it++)) { Security_context *tmp_sctx= tmp->security_ctx; - const char *val, *db; + const char *val; ulonglong max_counter; bool got_thd_data; @@ -3226,9 +3228,9 @@ int fill_schema_processlist(THD* thd, TABLE_LIST* tables, COND* cond) if ((got_thd_data= !trylock_short(&tmp->LOCK_thd_data))) { /* DB */ - if ((db= tmp->db)) + if (tmp->db.str) { - table->field[3]->store(db, strlen(db), cs); + table->field[3]->store(tmp->db.str, tmp->db.length, cs); table->field[3]->set_notnull(); } } @@ -4143,7 +4145,7 @@ bool get_lookup_field_values(THD *thd, COND *cond, TABLE_LIST *tables, case SQLCOM_SHOW_TRIGGERS: case SQLCOM_SHOW_EVENTS: thd->make_lex_string(&lookup_field_values->db_value, - lex->select_lex.db, strlen(lex->select_lex.db)); + lex->select_lex.db.str, lex->select_lex.db.length); if (wild) { thd->make_lex_string(&lookup_field_values->table_value, @@ -4241,8 +4243,7 @@ static int make_db_list(THD *thd, Dynamic_array<LEX_CSTRING*> *files, return 0; } - if (is_infoschema_db(lookup_field_vals->db_value.str, - lookup_field_vals->db_value.length)) + if (is_infoschema_db(&lookup_field_vals->db_value)) { if (files->append_val(&INFORMATION_SCHEMA_NAME)) return 1; @@ -4385,7 +4386,7 @@ make_table_name_list(THD *thd, Dynamic_array<LEX_CSTRING*> *table_names, { LEX_CSTRING *name; ST_SCHEMA_TABLE *schema_table= - find_schema_table(thd, lookup_field_vals->table_value.str); + find_schema_table(thd, &lookup_field_vals->table_value); if (schema_table && !schema_table->hidden) { if (!(name= thd->make_clex_string(schema_table->table_name, @@ -4665,8 +4666,7 @@ static int fill_schema_table_names(THD *thd, TABLE_LIST *tables, CHARSET_INFO *cs= system_charset_info; handlerton *hton; bool is_sequence; - if (ha_table_exists(thd, db_name->str, table_name->str, &hton, - &is_sequence)) + if (ha_table_exists(thd, db_name, table_name, &hton, &is_sequence)) { if (hton == view_pseudo_hton) table->field[3]->store(STRING_WITH_LEN("VIEW"), cs); @@ -4768,7 +4768,7 @@ try_acquire_high_prio_shared_mdl_lock(THD *thd, TABLE_LIST *table, bool can_deadlock) { bool error; - table->mdl_request.init(MDL_key::TABLE, table->db, table->table_name, + table->mdl_request.init(MDL_key::TABLE, table->db.str, table->table_name.str, MDL_SHARED_HIGH_PRIO, MDL_TRANSACTION); if (can_deadlock) @@ -4847,15 +4847,15 @@ static int fill_schema_table_from_frm(THD *thd, TABLE *table, */ strmov(db_name_buff, db_name->str); strmov(table_name_buff, table_name->str); - my_casedn_str(files_charset_info, db_name_buff); - my_casedn_str(files_charset_info, table_name_buff); - table_list.db= db_name_buff; - table_list.table_name= table_name_buff; + table_list.db.length= my_casedn_str(files_charset_info, db_name_buff); + table_list.table_name.length= my_casedn_str(files_charset_info, table_name_buff); + table_list.db.str= db_name_buff; + table_list.table_name.str= table_name_buff; } else { - table_list.table_name= table_name->str; - table_list.db= db_name->str; + table_list.table_name= *table_name; + table_list.db= *db_name; } /* @@ -4885,15 +4885,15 @@ static int fill_schema_table_from_frm(THD *thd, TABLE *table, push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARN_I_S_SKIPPED_TABLE, ER_THD(thd, ER_WARN_I_S_SKIPPED_TABLE), - table_list.db, table_list.table_name); + table_list.db.str, table_list.table_name.str); return 0; } if (schema_table->i_s_requested_object & OPEN_TRIGGER_ONLY) { init_sql_alloc(&tbl.mem_root, TABLE_ALLOC_BLOCK_SIZE, 0, MYF(0)); - if (!Table_triggers_list::check_n_load(thd, db_name->str, - table_name->str, &tbl, 1)) + if (!Table_triggers_list::check_n_load(thd, db_name, + table_name, &tbl, 1)) { table_list.table= &tbl; res= schema_table->process_table(thd, &table_list, table, @@ -4950,7 +4950,7 @@ static int fill_schema_table_from_frm(THD *thd, TABLE *table, goto end_share; } - if (!open_table_from_share(thd, share, table_name->str, 0, + if (!open_table_from_share(thd, share, table_name, 0, (EXTRA_RECORD | OPEN_FRM_FILE_ONLY), thd->open_options, &tbl, FALSE)) { @@ -5143,17 +5143,10 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) */ if (lsel && lsel->table_list.first) { - LEX_CSTRING db_name, table_name; - - db_name.str= lsel->table_list.first->db; - db_name.length= lsel->table_list.first->db_length; - - table_name.str= lsel->table_list.first->table_name; - table_name.length= lsel->table_list.first->table_name_length; - error= fill_schema_table_by_open(thd, thd->mem_root, TRUE, table, schema_table, - &db_name, &table_name, + &lsel->table_list.first->db, + &lsel->table_list.first->table_name, &open_tables_state_backup, can_deadlock); goto err; @@ -5215,10 +5208,8 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) #ifndef NO_EMBEDDED_ACCESS_CHECKS if (!(thd->col_access & TABLE_ACLS)) { - table_acl_check.db= db_name->str; - table_acl_check.db_length= db_name->length; - table_acl_check.table_name= table_name->str; - table_acl_check.table_name_length= table_name->length; + table_acl_check.db= *db_name; + table_acl_check.table_name= *table_name; table_acl_check.grant.privilege= thd->col_access; if (check_grant(thd, TABLE_ACLS, &table_acl_check, TRUE, 1, TRUE)) continue; @@ -6432,10 +6423,9 @@ int fill_schema_proc(THD *thd, TABLE_LIST *tables, COND *cond) thd->security_ctx->priv_host, NullS); /* We use this TABLE_LIST instance only for checking of privileges. */ bzero((char*) &proc_tables,sizeof(proc_tables)); - proc_tables.db= (char*) "mysql"; - proc_tables.db_length= 5; - proc_tables.table_name= proc_tables.alias= (char*) "proc"; - proc_tables.table_name_length= 4; + proc_tables.db= MYSQL_SCHEMA_NAME; + proc_tables.table_name= MYSQL_PROC_NAME; + proc_tables.alias= MYSQL_PROC_NAME; proc_tables.lock_type= TL_READ; full_access= !check_table_access(thd, SELECT_ACL, &proc_tables, FALSE, 1, TRUE); @@ -7663,7 +7653,7 @@ int fill_open_tables(THD *thd, TABLE_LIST *tables, COND *cond) TABLE *table= tables->table; CHARSET_INFO *cs= system_charset_info; OPEN_TABLE_LIST *open_list; - if (!(open_list=list_open_tables(thd,thd->lex->select_lex.db, wild)) + if (!(open_list=list_open_tables(thd,thd->lex->select_lex.db.str, wild)) && thd->is_fatal_error) DBUG_RETURN(1); @@ -7883,7 +7873,8 @@ static my_bool find_schema_table_in_plugin(THD *thd, plugin_ref plugin, if (!my_strcasecmp(system_charset_info, schema_table->table_name, - table_name)) { + table_name)) + { my_plugin_lock(thd, plugin); p_schema_table->schema_table= schema_table; DBUG_RETURN(1); @@ -7894,7 +7885,7 @@ static my_bool find_schema_table_in_plugin(THD *thd, plugin_ref plugin, /* - Find schema_tables elment by name + Find schema_tables element by name SYNOPSIS find_schema_table() @@ -7906,7 +7897,7 @@ static my_bool find_schema_table_in_plugin(THD *thd, plugin_ref plugin, # pointer to 'schema_tables' element */ -ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name, +ST_SCHEMA_TABLE *find_schema_table(THD *thd, const LEX_CSTRING *table_name, bool *in_plugin) { schema_table_ref schema_table_a; @@ -7918,12 +7909,12 @@ ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name, { if (!my_strcasecmp(system_charset_info, schema_table->table_name, - table_name)) + table_name->str)) DBUG_RETURN(schema_table); } *in_plugin= true; - schema_table_a.table_name= table_name; + schema_table_a.table_name= table_name->str; if (plugin_foreach(thd, find_schema_table_in_plugin, MYSQL_INFORMATION_SCHEMA_PLUGIN, &schema_table_a)) DBUG_RETURN(schema_table_a.schema_table); @@ -8084,7 +8075,7 @@ TABLE *create_schema_table(THD *thd, TABLE_LIST *table_list) field_list, (ORDER*) 0, 0, 0, (select_lex->options | thd->variables.option_bits | TMP_TABLE_ALL_COLUMNS), HA_POS_ERROR, - table_list->alias, false, keep_row_order))) + &table_list->alias, false, keep_row_order))) DBUG_RETURN(0); my_bitmap_map* bitmaps= (my_bitmap_map*) thd->alloc(bitmap_buffer_size(field_count)); @@ -8182,7 +8173,7 @@ int make_table_names_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table) buffer.length(0); buffer.append(field_info->old_name); - buffer.append(lex->select_lex.db); + buffer.append(&lex->select_lex.db); if (lex->wild && lex->wild->ptr()) { buffer.append(STRING_WITH_LEN(" (")); @@ -8324,12 +8315,11 @@ int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list) views working correctly */ - if (table_list->schema_table_name) + if (table_list->schema_table_name.str) table->alias_name_used= my_strcasecmp(table_alias_charset, - table_list->schema_table_name, - table_list->alias); - table_list->table_name= table->s->table_name.str; - table_list->table_name_length= table->s->table_name.length; + table_list->schema_table_name.str, + table_list->alias.str); + table_list->table_name= table->s->table_name; table_list->table= table; table->next= thd->derived_tables; thd->derived_tables= table; @@ -9946,12 +9936,12 @@ static TABLE_LIST *get_trigger_table(THD *thd, const sp_name *trg_name) { char trn_path_buff[FN_REFLEN]; - LEX_STRING trn_path= { trn_path_buff, 0 }; + LEX_CSTRING trn_path= { trn_path_buff, 0 }; LEX_CSTRING db; LEX_CSTRING tbl_name; TABLE_LIST *table; - build_trn_path(thd, trg_name, &trn_path); + build_trn_path(thd, trg_name, (LEX_STRING*) &trn_path); if (check_trn_exists(&trn_path)) { @@ -9959,8 +9949,7 @@ TABLE_LIST *get_trigger_table(THD *thd, const sp_name *trg_name) return NULL; } - if (load_table_name_for_trigger(thd, trg_name, (LEX_CSTRING*) &trn_path, - &tbl_name)) + if (load_table_name_for_trigger(thd, trg_name, &trn_path, &tbl_name)) return NULL; /* We need to reset statement table list to be PS/SP friendly. */ @@ -9978,8 +9967,7 @@ TABLE_LIST *get_trigger_table(THD *thd, const sp_name *trg_name) if (db.str == NULL || tbl_name.str == NULL) return NULL; - table->init_one_table(db.str, db.length, tbl_name.str, tbl_name.length, - tbl_name.str, TL_IGNORE); + table->init_one_table(&db, &tbl_name, 0, TL_IGNORE); return table; } @@ -10027,7 +10015,7 @@ bool show_create_trigger(THD *thd, const sp_name *trg_name) { my_error(ER_TRG_CANT_OPEN_TABLE, MYF(0), (const char *) trg_name->m_db.str, - (const char *) lst->table_name); + (const char *) lst->table_name.str); goto exit; @@ -10048,8 +10036,7 @@ bool show_create_trigger(THD *thd, const sp_name *trg_name) { my_error(ER_TRG_CORRUPTED_FILE, MYF(0), (const char *) trg_name->m_db.str, - (const char *) lst->table_name); - + (const char *) lst->table_name.str); goto exit; } diff --git a/sql/sql_show.h b/sql/sql_show.h index ac13099ca48..2715e0405bd 100644 --- a/sql/sql_show.h +++ b/sql/sql_show.h @@ -84,6 +84,10 @@ int copy_event_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table); bool append_identifier(THD *thd, String *packet, const char *name, uint length); +static inline bool append_identifier(THD *thd, String *packet, const LEX_CSTRING *name) +{ + return append_identifier(thd, packet, name->str, name->length); +} void mysqld_list_fields(THD *thd,TABLE_LIST *table, const char *wild); int mysqld_dump_create_info(THD *thd, TABLE_LIST *table_list, int fd); bool mysqld_show_create_get_fields(THD *thd, TABLE_LIST *table_list, @@ -118,8 +122,9 @@ bool schema_table_store_record(THD *thd, TABLE *table); void initialize_information_schema_acl(); COND *make_cond_for_info_schema(THD *thd, COND *cond, TABLE_LIST *table); -ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name, bool *in_plugin); -static inline ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name) +ST_SCHEMA_TABLE *find_schema_table(THD *thd, const LEX_CSTRING *table_name, + bool *in_plugin); +static inline ST_SCHEMA_TABLE *find_schema_table(THD *thd, const LEX_CSTRING *table_name) { bool unused; return find_schema_table(thd, table_name, &unused); } ST_SCHEMA_TABLE *get_schema_table(enum enum_schema_tables schema_table_idx); diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc index 2cb47634fe4..abe17bea955 100644 --- a/sql/sql_statistics.cc +++ b/sql/sql_statistics.cc @@ -65,16 +65,13 @@ static const uint STATISTICS_TABLES= 3; The names of the statistical tables in this array must correspond the definitions of the tables in the file ../scripts/mysql_system_tables.sql */ -static const LEX_STRING stat_table_name[STATISTICS_TABLES]= +static const LEX_CSTRING stat_table_name[STATISTICS_TABLES]= { - { C_STRING_WITH_LEN("table_stats") }, - { C_STRING_WITH_LEN("column_stats") }, - { C_STRING_WITH_LEN("index_stats") } + { STRING_WITH_LEN("table_stats") }, + { STRING_WITH_LEN("column_stats") }, + { STRING_WITH_LEN("index_stats") } }; -/* Name of database to which the statistical tables belong */ -static const LEX_STRING stat_tables_db_name= { C_STRING_WITH_LEN("mysql") }; - /** @details @@ -93,10 +90,9 @@ inline void init_table_list_for_stat_tables(TABLE_LIST *tables, bool for_write) for (i= 0; i < STATISTICS_TABLES; i++) { - tables[i].db= stat_tables_db_name.str; - tables[i].db_length= stat_tables_db_name.length; - tables[i].alias= tables[i].table_name= stat_table_name[i].str; - tables[i].table_name_length= stat_table_name[i].length; + tables[i].db= MYSQL_SCHEMA_NAME; + tables[i].table_name= stat_table_name[i]; + tables[i].alias= stat_table_name[i]; tables[i].lock_type= for_write ? TL_WRITE : TL_READ; if (i < STATISTICS_TABLES - 1) tables[i].next_global= tables[i].next_local= @@ -115,17 +111,16 @@ inline void init_table_list_for_stat_tables(TABLE_LIST *tables, bool for_write) otherwise it is set to TL_WRITE. */ -static -inline void init_table_list_for_single_stat_table(TABLE_LIST *tbl, - const LEX_STRING *stat_tab_name, - bool for_write) +static inline +void init_table_list_for_single_stat_table(TABLE_LIST *tbl, + const LEX_CSTRING *stat_tab_name, + bool for_write) { memset((char *) tbl, 0, sizeof(TABLE_LIST)); - tbl->db= stat_tables_db_name.str; - tbl->db_length= stat_tables_db_name.length; - tbl->alias= tbl->table_name= stat_tab_name->str; - tbl->table_name_length= stat_tab_name->length; + tbl->db= MYSQL_SCHEMA_NAME; + tbl->table_name= *stat_tab_name; + tbl->alias= *stat_tab_name; tbl->lock_type= for_write ? TL_WRITE : TL_READ; } @@ -294,7 +289,7 @@ inline int open_stat_tables(THD *thd, TABLE_LIST *tables, */ static inline int open_single_stat_table(THD *thd, TABLE_LIST *table, - const LEX_STRING *stat_tab_name, + const LEX_CSTRING *stat_tab_name, Open_tables_backup *backup, bool for_write) { @@ -472,8 +467,8 @@ protected: /* Table for which statistical data is read / updated */ 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' */ + const LEX_CSTRING *db_name; /* Name of the database containing 'table' */ + const LEX_CSTRING *table_name; /* Name of the table 'table' */ void store_record_for_update() { @@ -528,12 +523,10 @@ public: by the database name 'db' and the table name 'tab'. */ - Stat_table(TABLE *stat, LEX_CSTRING *db, LEX_CSTRING *tab) - :stat_table(stat), table_share(NULL) + Stat_table(TABLE *stat, const LEX_CSTRING *db, const LEX_CSTRING *tab) + :stat_table(stat), table_share(NULL),db_name(db), table_name(tab) { common_init_stat_table(); - db_name= db; - table_name= tab; } @@ -553,7 +546,7 @@ public: The method is called by the update_table_name_key_parts function. */ - virtual void change_full_table_name(LEX_CSTRING *db, LEX_CSTRING *tab)= 0; + virtual void change_full_table_name(const LEX_CSTRING *db, const LEX_CSTRING *tab)= 0; /** @@ -709,7 +702,7 @@ public: to store the new names in the record buffer used for updates. */ - bool update_table_name_key_parts(LEX_CSTRING *db, LEX_CSTRING *tab) + bool update_table_name_key_parts(const LEX_CSTRING *db, const LEX_CSTRING *tab) { store_record_for_update(); change_full_table_name(db, tab); @@ -771,7 +764,7 @@ private: table_name_field= stat_table->field[TABLE_STAT_TABLE_NAME]; } - void change_full_table_name(LEX_CSTRING *db, LEX_CSTRING *tab) + void change_full_table_name(const LEX_CSTRING *db, const 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); @@ -801,7 +794,7 @@ public: from the database 'db'. */ - Table_stat(TABLE *stat, LEX_CSTRING *db, LEX_CSTRING *tab) + Table_stat(TABLE *stat, const LEX_CSTRING *db, const LEX_CSTRING *tab) :Stat_table(stat, db, tab) { common_init_table_stat(); @@ -915,7 +908,7 @@ private: column_name_field= stat_table->field[COLUMN_STAT_COLUMN_NAME]; } - void change_full_table_name(LEX_CSTRING *db, LEX_CSTRING *tab) + void change_full_table_name(const LEX_CSTRING *db, const 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); @@ -945,7 +938,7 @@ public: from the database 'db'. */ - Column_stat(TABLE *stat, LEX_CSTRING *db, LEX_CSTRING *tab) + Column_stat(TABLE *stat, const LEX_CSTRING *db, const LEX_CSTRING *tab) :Stat_table(stat, db, tab) { common_init_column_stat_table(); @@ -1250,7 +1243,7 @@ private: prefix_arity_field= stat_table->field[INDEX_STAT_PREFIX_ARITY]; } - void change_full_table_name(LEX_CSTRING *db, LEX_CSTRING *tab) + void change_full_table_name(const LEX_CSTRING *db, const 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); @@ -1282,7 +1275,7 @@ public: from the database 'db'. */ - Index_stat(TABLE *stat, LEX_CSTRING *db, LEX_CSTRING *tab) + Index_stat(TABLE *stat, const LEX_CSTRING *db, const LEX_CSTRING *tab) :Stat_table(stat, db, tab) { common_init_index_stat_table(); @@ -3526,8 +3519,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_CSTRING *db, LEX_CSTRING *tab, - LEX_CSTRING *new_db, LEX_CSTRING *new_tab) +int rename_table_in_stat_tables(THD *thd, const LEX_CSTRING *db, const LEX_CSTRING *tab, + const LEX_CSTRING *new_db, const LEX_CSTRING *new_tab) { int err; enum_binlog_format save_binlog_format; @@ -3535,7 +3528,6 @@ int rename_table_in_stat_tables(THD *thd, LEX_CSTRING *db, LEX_CSTRING *tab, TABLE_LIST tables[STATISTICS_TABLES]; Open_tables_backup open_tables_backup; int rc= 0; - DBUG_ENTER("rename_table_in_stat_tables"); if (open_stat_tables(thd, tables, &open_tables_backup, TRUE)) @@ -3984,18 +3976,17 @@ double Histogram::point_selectivity(double pos, double avg_sel) /* Check whether the table is one of the persistent statistical tables. */ -bool is_stat_table(const char *db, const char *table) +bool is_stat_table(const LEX_CSTRING *db, LEX_CSTRING *table) { - DBUG_ASSERT(db && table); + DBUG_ASSERT(db->str && table->str); - if (!memcmp(db, stat_tables_db_name.str, stat_tables_db_name.length)) + if (!cmp(db, &MYSQL_SCHEMA_NAME)) { for (uint i= 0; i < STATISTICS_TABLES; i ++) { - if (!memcmp(table, stat_table_name[i].str, stat_table_name[i].length)) + if (cmp(table, &stat_table_name[i]) == 0) return true; } } return false; } - diff --git a/sql/sql_statistics.h b/sql/sql_statistics.h index eb59b149753..7ec742b70db 100644 --- a/sql/sql_statistics.h +++ b/sql/sql_statistics.h @@ -98,8 +98,8 @@ int delete_statistics_for_table(THD *thd, LEX_CSTRING *db, LEX_CSTRING *tab); int delete_statistics_for_column(THD *thd, TABLE *tab, Field *col); int delete_statistics_for_index(THD *thd, TABLE *tab, KEY *key_info, bool ext_prefixes_only); -int rename_table_in_stat_tables(THD *thd, LEX_CSTRING *db, LEX_CSTRING *tab, - LEX_CSTRING *new_db, LEX_CSTRING *new_tab); +int rename_table_in_stat_tables(THD *thd, const LEX_CSTRING *db, const LEX_CSTRING *tab, + const LEX_CSTRING *new_db, const LEX_CSTRING *new_tab); int rename_column_in_stat_tables(THD *thd, TABLE *tab, Field *col, const char *new_name); void set_statistics_for_table(THD *thd, TABLE *table); @@ -110,7 +110,7 @@ double get_column_range_cardinality(Field *field, key_range *min_endp, key_range *max_endp, uint range_flag); -bool is_stat_table(const char *db, const char *table); +bool is_stat_table(const LEX_CSTRING *db, LEX_CSTRING *table); class Histogram { @@ -255,18 +255,6 @@ public: class Columns_statistics; class Index_statistics; -static inline -int rename_table_in_stat_tables(THD *thd, const char *db, const char *tab, - const char *new_db, const char *new_tab) -{ - LEX_CSTRING od= { db, strlen(db) }; - LEX_CSTRING ot= { tab, strlen(tab) }; - LEX_CSTRING nd= { new_db, strlen(new_db) }; - LEX_CSTRING nt= { new_tab, strlen(new_tab) }; - return rename_table_in_stat_tables(thd, &od, &ot, &nd, &nt); -} - - /* Statistical data on a table */ class Table_statistics diff --git a/sql/sql_table.cc b/sql/sql_table.cc index dc0accad799..63b6530b92f 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1768,9 +1768,10 @@ uint build_table_shadow_filename(char *buff, size_t bufflen, ALTER_PARTITION_PARAM_TYPE *lpt) { char tmp_name[FN_REFLEN]; - my_snprintf (tmp_name, sizeof (tmp_name), "%s-%s", tmp_file_prefix, - lpt->table_name); - return build_table_filename(buff, bufflen, lpt->db, tmp_name, "", FN_IS_TMP); + my_snprintf(tmp_name, sizeof (tmp_name), "%s-%s", tmp_file_prefix, + lpt->table_name.str); + return build_table_filename(buff, bufflen, lpt->db.str, tmp_name, "", + FN_IS_TMP); } @@ -1852,7 +1853,7 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags) #endif /* Write shadow frm file */ lpt->create_info->table_options= lpt->db_options; - LEX_CUSTRING frm= build_frm_image(lpt->thd, lpt->table_name, + LEX_CUSTRING frm= build_frm_image(lpt->thd, &lpt->table_name, lpt->create_info, lpt->alter_info->create_list, lpt->key_count, lpt->key_info_buffer, @@ -1863,7 +1864,7 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags) goto end; } - int error= writefrm(shadow_path, lpt->db, lpt->table_name, + int error= writefrm(shadow_path, lpt->db.str, lpt->table_name.str, lpt->create_info->tmp_table(), frm.str, frm.length); my_free(const_cast<uchar*>(frm.str)); @@ -1883,8 +1884,8 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags) /* Build frm file name */ - build_table_filename(path, sizeof(path) - 1, lpt->db, - lpt->table_name, "", 0); + build_table_filename(path, sizeof(path) - 1, lpt->db.str, + lpt->table_name.str, "", 0); strxnmov(frm_name, sizeof(frm_name), path, reg_ext, NullS); /* When we are changing to use new frm file we need to ensure that we @@ -2047,8 +2048,8 @@ bool mysql_rm_table(THD *thd,TABLE_LIST *tables, bool if_exists, { for (table= tables; table; table= table->next_local) { - LEX_CSTRING db_name= { table->db, table->db_length }; - LEX_CSTRING table_name= { table->table_name, table->table_name_length }; + LEX_CSTRING db_name= table->db; + LEX_CSTRING table_name= table->table_name; if (table->open_type == OT_BASE_ONLY || !thd->find_temporary_table(table)) (void) delete_statistics_for_table(thd, &db_name, &table_name); @@ -2110,8 +2111,8 @@ bool mysql_rm_table(THD *thd,TABLE_LIST *tables, bool if_exists, by parser) it is safe to cache pointer to the TABLE instances in its elements. */ - table->table= find_table_for_mdl_upgrade(thd, table->db, - table->table_name, false); + table->table= find_table_for_mdl_upgrade(thd, table->db.str, + table->table_name.str, false); if (!table->table) DBUG_RETURN(true); table->mdl_request.ticket= table->table->mdl_ticket; @@ -2218,7 +2219,7 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, { TABLE_LIST *table; char path[FN_REFLEN + 1], wrong_tables_buff[160]; - const char *alias= NULL; + LEX_CSTRING alias= null_clex_str; String wrong_tables(wrong_tables_buff, sizeof(wrong_tables_buff)-1, system_charset_info); uint path_length= 0, errors= 0; @@ -2309,13 +2310,12 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, { bool is_trans= 0; bool table_creation_was_logged= 1; - const char *db= table->db; - size_t db_length= table->db_length; + LEX_CSTRING db= table->db; handlerton *table_type= 0; VTMD_drop vtmd(*table); DBUG_PRINT("table", ("table_l: '%s'.'%s' table: %p s: %p", - table->db, table->table_name, table->table, + table->db.str, table->table_name.str, table->table, table->table ? table->table->s : NULL)); /* @@ -2374,14 +2374,13 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, thd->db is NULL or 'IF EXISTS' clause is present in 'DROP TEMPORARY' query. */ - if (thd->db == NULL || strcmp(db,thd->db) != 0 - || is_drop_tmp_if_exists_added ) + if (thd->db.str == NULL || cmp(&db, &thd->db) || + is_drop_tmp_if_exists_added ) { - append_identifier(thd, built_ptr_query, db, db_length); + append_identifier(thd, built_ptr_query, &db); built_ptr_query->append("."); } - append_identifier(thd, built_ptr_query, table->table_name, - table->table_name_length); + append_identifier(thd, built_ptr_query, &table->table_name); built_ptr_query->append(","); } /* @@ -2395,13 +2394,13 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, { non_temp_tables_count++; - DBUG_ASSERT(thd->mdl_context.is_lock_owner(MDL_key::TABLE, table->db, - table->table_name, + DBUG_ASSERT(thd->mdl_context.is_lock_owner(MDL_key::TABLE, table->db.str, + table->table_name.str, MDL_SHARED)); alias= (lower_case_table_names == 2) ? table->alias : table->table_name; /* remove .frm file and engine files */ - path_length= build_table_filename(path, sizeof(path) - 1, db, alias, + path_length= build_table_filename(path, sizeof(path) - 1, db.str, alias.str, reg_ext, 0); /* @@ -2423,21 +2422,20 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, Don't write the database name if it is the current one (or if thd->db is NULL). */ - if (thd->db == NULL || strcmp(db,thd->db) != 0) + if (thd->db.str == NULL || cmp(&db, &thd->db) != 0) { - append_identifier(thd, &built_query, db, db_length); + append_identifier(thd, &built_query, &db); built_query.append("."); } - append_identifier(thd, &built_query, table->table_name, - table->table_name_length); + append_identifier(thd, &built_query, &table->table_name); built_query.append(","); } } DEBUG_SYNC(thd, "rm_table_no_locks_before_delete_table"); error= 0; if (drop_temporary || - (ha_table_exists(thd, db, alias, &table_type, &is_sequence) == 0 && + (ha_table_exists(thd, &db, &alias, &table_type, &is_sequence) == 0 && table_type == 0) || (!drop_view && (was_view= (table_type == view_pseudo_hton))) || (drop_sequence && !is_sequence)) @@ -2457,9 +2455,9 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, ER_BAD_TABLE_ERROR); String tbl_name(buff, sizeof(buff), system_charset_info); tbl_name.length(0); - tbl_name.append(db); + tbl_name.append(&db); tbl_name.append('.'); - tbl_name.append(table->table_name); + tbl_name.append(&table->table_name); push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, err, ER_THD(thd, err), tbl_name.c_ptr_safe()); @@ -2501,12 +2499,12 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, table->table= 0; } else - tdc_remove_table(thd, TDC_RT_REMOVE_ALL, table->db, table->table_name, + tdc_remove_table(thd, TDC_RT_REMOVE_ALL, table->db.str, table->table_name.str, false); /* Check that we have an exclusive lock on the table to be dropped. */ - DBUG_ASSERT(thd->mdl_context.is_lock_owner(MDL_key::TABLE, table->db, - table->table_name, + DBUG_ASSERT(thd->mdl_context.is_lock_owner(MDL_key::TABLE, table->db.str, + table->table_name.str, MDL_EXCLUSIVE)); // Remove extension for delete @@ -2522,14 +2520,18 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, goto non_tmp_err; if (!vtmd.exists) goto drop_table; - error= mysql_rename_table(table_type, table->db, table->table_name, - table->db, vtmd.archive_name(thd), NO_FK_CHECKS); + { + const char *name= vtmd.archive_name(thd); + LEX_CSTRING new_name= { name, strlen(name) }; + error= mysql_rename_table(table_type, &table->db, &table->table_name, + &table->db, &new_name, NO_FK_CHECKS); + } } else { - drop_table: - error= ha_delete_table(thd, table_type, path, db, table->table_name, - !dont_log_query); + drop_table: + error= ha_delete_table(thd, table_type, path, &db, &table->table_name, + !dont_log_query); if (!error) { /* Delete the table definition file */ @@ -2560,7 +2562,7 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, { non_tmp_table_deleted= TRUE; trigger_drop_error= - Table_triggers_list::drop_all_triggers(thd, db, table->table_name); + Table_triggers_list::drop_all_triggers(thd, &db, &table->table_name); } if (trigger_drop_error || @@ -2580,23 +2582,28 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, error= vtmd.update(thd); thd->lex->sql_command= sql_command; if (error) - mysql_rename_table(table_type, table->db, vtmd.archive_name(), - table->db, table->table_name, NO_FK_CHECKS); + { + LEX_CSTRING archive_name; + archive_name.str= vtmd.archive_name(); + archive_name.length= strlen(archive_name.str); + mysql_rename_table(table_type, &table->db, &archive_name, + &table->db, &table->table_name, NO_FK_CHECKS); + } } if (error) { if (wrong_tables.length()) wrong_tables.append(','); - wrong_tables.append(db); + wrong_tables.append(&db); wrong_tables.append('.'); - wrong_tables.append(table->table_name); + wrong_tables.append(&table->table_name); errors++; } else { - PSI_CALL_drop_table_share(false, table->db, table->db_length, - table->table_name, table->table_name_length); + PSI_CALL_drop_table_share(false, table->db.str, table->db.length, + table->table_name.str, table->table_name.length); mysql_audit_drop_table(thd, table); } @@ -2749,8 +2756,8 @@ end: when the original table was dropped but we could not create the new one. */ -bool log_drop_table(THD *thd, const char *db_name, size_t db_name_length, - const char *table_name, size_t table_name_length, +bool log_drop_table(THD *thd, const LEX_CSTRING *db_name, + const LEX_CSTRING *table_name, bool temporary_table) { char buff[NAME_LEN*2 + 80]; @@ -2766,9 +2773,9 @@ bool log_drop_table(THD *thd, const char *db_name, size_t db_name_length, if (temporary_table) query.append(STRING_WITH_LEN("TEMPORARY ")); query.append(STRING_WITH_LEN("TABLE IF EXISTS ")); - append_identifier(thd, &query, db_name, db_name_length); + append_identifier(thd, &query, db_name); query.append("."); - append_identifier(thd, &query, table_name, table_name_length); + append_identifier(thd, &query, table_name); query.append(STRING_WITH_LEN("/* Generated to handle " "failed CREATE OR REPLACE */")); error= thd->binlog_query(THD::STMT_QUERY_TYPE, @@ -2791,8 +2798,8 @@ bool log_drop_table(THD *thd, const char *db_name, size_t db_name_length, @return False in case of success, True otherwise. */ -bool quick_rm_table(THD *thd, handlerton *base, const char *db, - const char *table_name, uint flags, const char *table_path) +bool quick_rm_table(THD *thd, handlerton *base, const LEX_CSTRING *db, + const LEX_CSTRING *table_name, uint flags, const char *table_path) { char path[FN_REFLEN + 1]; bool error= 0; @@ -2800,7 +2807,7 @@ bool quick_rm_table(THD *thd, handlerton *base, const char *db, size_t path_length= table_path ? (strxnmov(path, sizeof(path) - 1, table_path, reg_ext, NullS) - path) : - build_table_filename(path, sizeof(path)-1, db, table_name, reg_ext, flags); + build_table_filename(path, sizeof(path)-1, db->str, table_name->str, reg_ext, flags); if (mysql_file_delete(key_file_frm, path, MYF(0))) error= 1; /* purecov: inspected */ path[path_length - reg_ext_length]= '\0'; // Remove reg_ext @@ -2817,8 +2824,8 @@ bool quick_rm_table(THD *thd, handlerton *base, const char *db, if (likely(error == 0)) { - PSI_CALL_drop_table_share(flags & FN_IS_TMP, db, strlen(db), - table_name, strlen(table_name)); + PSI_CALL_drop_table_share(flags & FN_IS_TMP, db->str, db->length, + table_name->str, table_name->length); } DBUG_RETURN(error); @@ -4353,7 +4360,7 @@ bool validate_comment_length(THD *thd, LEX_CSTRING *comment, size_t max_len, static void set_table_default_charset(THD *thd, HA_CREATE_INFO *create_info, - const char *db) + const LEX_CSTRING *db) { /* If the table character set was not given explicitly, @@ -4364,7 +4371,7 @@ static void set_table_default_charset(THD *thd, { Schema_specification_st db_info; - load_db_opt_by_name(thd, db, &db_info); + load_db_opt_by_name(thd, db->str, &db_info); create_info->default_table_charset= db_info.default_table_charset; } @@ -4492,7 +4499,7 @@ vers_prepare_keys(THD *thd, } handler *mysql_create_frm_image(THD *thd, - const char *db, const char *table_name, + const LEX_CSTRING *db, const LEX_CSTRING *table_name, HA_CREATE_INFO *create_info, Alter_info *alter_info, int create_table_mode, KEY **key_info, @@ -4509,7 +4516,7 @@ handler *mysql_create_frm_image(THD *thd, DBUG_RETURN(NULL); } - set_table_default_charset(thd, create_info, (char*) db); + set_table_default_charset(thd, create_info, db); db_options= create_info->table_options_with_row_type(); @@ -4792,8 +4799,9 @@ err: static int create_table_impl(THD *thd, - const char *orig_db, const char *orig_table_name, - const char *db, const char *table_name, + const LEX_CSTRING *orig_db, + const LEX_CSTRING *orig_table_name, + const LEX_CSTRING *db, const LEX_CSTRING *table_name, const char *path, const DDL_options_st options, HA_CREATE_INFO *create_info, @@ -4804,14 +4812,14 @@ int create_table_impl(THD *thd, uint *key_count, LEX_CUSTRING *frm) { - const char *alias; + LEX_CSTRING *alias; handler *file= 0; int error= 1; bool frm_only= create_table_mode == C_ALTER_TABLE_FRM_ONLY; bool internal_tmp_table= create_table_mode == C_ALTER_TABLE || frm_only; DBUG_ENTER("mysql_create_table_no_lock"); DBUG_PRINT("enter", ("db: '%s' table: '%s' tmp: %d path: %s", - db, table_name, internal_tmp_table, path)); + db->str, table_name->str, internal_tmp_table, path)); if (thd->variables.sql_mode & MODE_NO_DIR_IN_CREATE) { @@ -4833,7 +4841,7 @@ int create_table_impl(THD *thd, check_partition_dirs(thd->lex->part_info)) goto err; - alias= table_case_name(create_info, table_name); + alias= const_cast<LEX_CSTRING*>(table_case_name(create_info, table_name)); /* Check if table exists */ if (create_info->tmp_table()) @@ -4842,7 +4850,7 @@ int create_table_impl(THD *thd, If a table exists, it must have been pre-opened. Try looking for one in-use in THD::all_temp_tables list of TABLE_SHAREs. */ - TABLE *tmp_table= thd->find_temporary_table(db, table_name); + TABLE *tmp_table= thd->find_temporary_table(db->str, table_name->str); if (tmp_table) { @@ -4860,7 +4868,7 @@ int create_table_impl(THD *thd, goto warn; else { - my_error(ER_TABLE_EXISTS_ERROR, MYF(0), alias); + my_error(ER_TABLE_EXISTS_ERROR, MYF(0), alias->str); goto err; } /* @@ -4882,9 +4890,7 @@ int create_table_impl(THD *thd, if (options.or_replace()) { TABLE_LIST table_list; - table_list.init_one_table(db, strlen(db), table_name, - strlen(table_name), table_name, - TL_WRITE_ALLOW_WRITE); + table_list.init_one_table(db, table_name, 0, TL_WRITE_ALLOW_WRITE); table_list.table= create_info->table; if (check_if_log_table(&table_list, TRUE, "CREATE OR REPLACE")) @@ -4919,7 +4925,7 @@ int create_table_impl(THD *thd, goto warn; else { - my_error(ER_TABLE_EXISTS_ERROR, MYF(0), table_name); + my_error(ER_TABLE_EXISTS_ERROR, MYF(0), table_name->str); goto err; } } @@ -4927,7 +4933,7 @@ int create_table_impl(THD *thd, THD_STAGE_INFO(thd, stage_creating_table); - if (check_engine(thd, orig_db, orig_table_name, create_info)) + if (check_engine(thd, orig_db->str, orig_table_name->str, create_info)) goto err; if (create_table_mode == C_ASSISTED_DISCOVERY) @@ -4947,7 +4953,7 @@ int create_table_impl(THD *thd, goto err; } - init_tmp_table_share(thd, &share, db, 0, table_name, path); + init_tmp_table_share(thd, &share, db->str, 0, table_name->str, path); /* prepare everything for discovery */ share.field= &no_fields; @@ -4984,7 +4990,7 @@ int create_table_impl(THD *thd, key_count, frm); if (!file) goto err; - if (rea_create_table(thd, frm, path, db, table_name, create_info, + if (rea_create_table(thd, frm, path, db->str, table_name->str, create_info, file, frm_only)) goto err; } @@ -4993,7 +4999,8 @@ int create_table_impl(THD *thd, if (!frm_only && create_info->tmp_table()) { TABLE *table= thd->create_and_open_tmp_table(create_info->db_type, frm, - path, db, table_name, true, + path, db->str, + table_name->str, true, false); if (!table) @@ -5024,11 +5031,11 @@ int create_table_impl(THD *thd, TABLE table; TABLE_SHARE share; - init_tmp_table_share(thd, &share, db, 0, table_name, path); + init_tmp_table_share(thd, &share, db->str, 0, table_name->str, path); bool result= (open_table_def(thd, &share, GTS_TABLE) || - open_table_from_share(thd, &share, "", 0, (uint) READ_ALL, - 0, &table, true)); + open_table_from_share(thd, &share, &empty_clex_str, 0, + (uint) READ_ALL, 0, &table, true)); if (!result) (void) closefrm(&table); @@ -5057,7 +5064,7 @@ warn: push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_TABLE_EXISTS_ERROR, ER_THD(thd, ER_TABLE_EXISTS_ERROR), - alias); + alias->str); goto err; } @@ -5067,7 +5074,8 @@ warn: */ int mysql_create_table_no_lock(THD *thd, - const char *db, const char *table_name, + const LEX_CSTRING *db, + const LEX_CSTRING *table_name, Table_specification_st *create_info, Alter_info *alter_info, bool *is_trans, int create_table_mode, @@ -5084,9 +5092,8 @@ int mysql_create_table_no_lock(THD *thd, else { int length; - const char *alias= table_case_name(create_info, table_name); - length= build_table_filename(path, sizeof(path) - 1, db, alias, - "", 0); + const LEX_CSTRING *alias= table_case_name(create_info, table_name); + length= build_table_filename(path, sizeof(path) - 1, db->str, alias->str, "", 0); // Check if we hit FN_REFLEN bytes along with file extension. if (length+reg_ext_length > FN_REFLEN) { @@ -5129,8 +5136,6 @@ bool mysql_create_table(THD *thd, TABLE_LIST *create_table, Table_specification_st *create_info, Alter_info *alter_info) { - const char *db= create_table->db; - const char *table_name= create_table->table_name; bool is_trans= FALSE; bool result; int create_table_mode; @@ -5172,7 +5177,9 @@ bool mysql_create_table(THD *thd, TABLE_LIST *create_table, if (!opt_explicit_defaults_for_timestamp) promote_first_timestamp_column(&alter_info->create_list); - if (mysql_create_table_no_lock(thd, db, table_name, create_info, alter_info, + if (mysql_create_table_no_lock(thd, &create_table->db, + &create_table->table_name, create_info, + alter_info, &is_trans, create_table_mode, create_table) > 0) { @@ -5457,9 +5464,9 @@ err: */ bool -mysql_rename_table(handlerton *base, const char *old_db, - const char *old_name, const char *new_db, - const char *new_name, uint flags) +mysql_rename_table(handlerton *base, const LEX_CSTRING *old_db, + const LEX_CSTRING *old_name, const LEX_CSTRING *new_db, + const LEX_CSTRING *new_name, uint flags) { THD *thd= current_thd; char from[FN_REFLEN + 1], to[FN_REFLEN + 1], @@ -5473,7 +5480,7 @@ mysql_rename_table(handlerton *base, const char *old_db, DBUG_ENTER("mysql_rename_table"); DBUG_ASSERT(base); DBUG_PRINT("enter", ("old: '%s'.'%s' new: '%s'.'%s'", - old_db, old_name, new_db, new_name)); + old_db->str, old_name->str, new_db->str, new_name->str)); // Temporarily disable foreign key checks if (flags & NO_FK_CHECKS) @@ -5481,9 +5488,9 @@ mysql_rename_table(handlerton *base, const char *old_db, file= get_new_handler((TABLE_SHARE*) 0, thd->mem_root, base); - build_table_filename(from, sizeof(from) - 1, old_db, old_name, "", + build_table_filename(from, sizeof(from) - 1, old_db->str, old_name->str, "", flags & FN_FROM_IS_TMP); - length= build_table_filename(to, sizeof(to) - 1, new_db, new_name, "", + length= build_table_filename(to, sizeof(to) - 1, new_db->str, new_name->str, "", flags & FN_TO_IS_TMP); // Check if we hit FN_REFLEN bytes along with file extension. if (length+reg_ext_length > FN_REFLEN) @@ -5500,18 +5507,18 @@ mysql_rename_table(handlerton *base, const char *old_db, if (lower_case_table_names == 2 && file && !(file->ha_table_flags() & HA_FILE_BASED)) { - strmov(tmp_name, old_name); + strmov(tmp_name, old_name->str); my_casedn_str(files_charset_info, tmp_name); - strmov(tmp_db_name, old_db); + strmov(tmp_db_name, old_db->str); my_casedn_str(files_charset_info, tmp_db_name); build_table_filename(lc_from, sizeof(lc_from) - 1, tmp_db_name, tmp_name, "", flags & FN_FROM_IS_TMP); from_base= lc_from; - strmov(tmp_name, new_name); + strmov(tmp_name, new_name->str); my_casedn_str(files_charset_info, tmp_name); - strmov(tmp_db_name, new_db); + strmov(tmp_db_name, new_db->str); my_casedn_str(files_charset_info, tmp_db_name); build_table_filename(lc_to, sizeof(lc_to) - 1, tmp_db_name, tmp_name, "", @@ -5554,8 +5561,8 @@ mysql_rename_table(handlerton *base, const char *old_db, if (likely(error == 0)) { PSI_CALL_drop_table_share(flags & FN_FROM_IS_TMP, - old_db, strlen(old_db), - old_name, strlen(old_name)); + old_db->str, old_db->length, + old_name->str, old_name->length); } // Restore options bits to the original value @@ -5690,7 +5697,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, pos_in_locked_tables= local_create_info.table->pos_in_locked_tables; res= ((create_res= - mysql_create_table_no_lock(thd, table->db, table->table_name, + mysql_create_table_no_lock(thd, &table->db, &table->table_name, &local_create_info, &local_alter_info, &is_trans, C_ORDINARY_CREATE, table)) > 0); @@ -5733,8 +5740,8 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, non-temporary table. */ DBUG_ASSERT((create_info->tmp_table()) || - thd->mdl_context.is_lock_owner(MDL_key::TABLE, table->db, - table->table_name, + thd->mdl_context.is_lock_owner(MDL_key::TABLE, table->db.str, + table->table_name.str, MDL_EXCLUSIVE)); } @@ -5891,9 +5898,7 @@ err: Table was not deleted. Original table was deleted. We have to log it. */ - log_drop_table(thd, table->db, table->db_length, - table->table_name, table->table_name_length, - create_info->tmp_table()); + log_drop_table(thd, &table->db, &table->table_name, create_info->tmp_table()); } else if (write_bin_log(thd, res ? FALSE : TRUE, thd->query(), thd->query_length(), is_trans)) @@ -7678,13 +7683,13 @@ static bool mysql_inplace_alter_table(THD *thd, Replace the old .FRM with the new .FRM, but keep the old name for now. Rename to the new name (if needed) will be handled separately below. */ - if (mysql_rename_table(db_type, alter_ctx->new_db, alter_ctx->tmp_name, - alter_ctx->db, alter_ctx->alias, + if (mysql_rename_table(db_type, &alter_ctx->new_db, &alter_ctx->tmp_name, + &alter_ctx->db, &alter_ctx->alias, FN_FROM_IS_TMP | NO_HA_TABLE)) { // Since changes were done in-place, we can't revert them. (void) quick_rm_table(thd, db_type, - alter_ctx->new_db, alter_ctx->tmp_name, + &alter_ctx->new_db, &alter_ctx->tmp_name, FN_IS_TMP | NO_HA_TABLE); DBUG_RETURN(true); } @@ -7712,10 +7717,10 @@ static bool mysql_inplace_alter_table(THD *thd, { // Remove TABLE and TABLE_SHARE for old name from TDC. tdc_remove_table(thd, TDC_RT_REMOVE_ALL, - alter_ctx->db, alter_ctx->table_name, false); + alter_ctx->db.str, alter_ctx->table_name.str, false); - if (mysql_rename_table(db_type, alter_ctx->db, alter_ctx->table_name, - alter_ctx->new_db, alter_ctx->new_alias, 0)) + if (mysql_rename_table(db_type, &alter_ctx->db, &alter_ctx->table_name, + &alter_ctx->new_db, &alter_ctx->new_alias, 0)) { /* If the rename fails we will still have a working table @@ -7724,23 +7729,23 @@ static bool mysql_inplace_alter_table(THD *thd, DBUG_RETURN(true); } if (Table_triggers_list::change_table_name(thd, - alter_ctx->db, - alter_ctx->alias, - alter_ctx->table_name, - alter_ctx->new_db, - alter_ctx->new_alias)) + &alter_ctx->db, + &alter_ctx->alias, + &alter_ctx->table_name, + &alter_ctx->new_db, + &alter_ctx->new_alias)) { /* If the rename of trigger files fails, try to rename the table back so we at least have matching table and trigger files. */ (void) mysql_rename_table(db_type, - alter_ctx->new_db, alter_ctx->new_alias, - alter_ctx->db, alter_ctx->alias, NO_FK_CHECKS); + &alter_ctx->new_db, &alter_ctx->new_alias, + &alter_ctx->db, &alter_ctx->alias, NO_FK_CHECKS); DBUG_RETURN(true); } - rename_table_in_stat_tables(thd, alter_ctx->db,alter_ctx->alias, - alter_ctx->new_db, alter_ctx->new_alias); + rename_table_in_stat_tables(thd, &alter_ctx->db, &alter_ctx->alias, + &alter_ctx->new_db, &alter_ctx->new_alias); } DBUG_RETURN(false); @@ -7764,8 +7769,8 @@ static bool mysql_inplace_alter_table(THD *thd, } thd->drop_temporary_table(altered_table, NULL, false); // Delete temporary .frm/.par - (void) quick_rm_table(thd, create_info->db_type, alter_ctx->new_db, - alter_ctx->tmp_name, FN_IS_TMP | NO_HA_TABLE); + (void) quick_rm_table(thd, create_info->db_type, &alter_ctx->new_db, + &alter_ctx->tmp_name, FN_IS_TMP | NO_HA_TABLE); DBUG_RETURN(true); } @@ -8126,7 +8131,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, { if (def->real_field_type() == MYSQL_TYPE_BLOB) { - my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0), def->change); + my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0), def->change.str); goto err; } if ((def->default_value= alter->default_value)) // Use new default @@ -8689,9 +8694,9 @@ static bool fk_prepare_copy_alter_table(THD *thd, TABLE *table, StringBuffer<NAME_LEN*2+2> buff(system_charset_info); LEX_CSTRING *db= f_key->foreign_db, *tbl= f_key->foreign_table; - append_identifier(thd, &buff, db->str, db->length); + append_identifier(thd, &buff, db); buff.append('.'); - append_identifier(thd, &buff, tbl->str,tbl->length); + append_identifier(thd, &buff, tbl); my_error(ER_FK_COLUMN_CANNOT_DROP_CHILD, MYF(0), bad_column_name, f_key->foreign_id->str, buff.c_ptr()); DBUG_RETURN(true); @@ -8807,8 +8812,8 @@ simple_tmp_rename_or_index_change(THD *thd, TABLE_LIST *table_list, back to the original name (unlike the case for non-temporary tables), as it was an allocation error and the table was not renamed. */ - error= thd->rename_temporary_table(table, alter_ctx->new_db, - alter_ctx->new_alias); + error= thd->rename_temporary_table(table, &alter_ctx->new_db, + &alter_ctx->new_alias); } if (!error) @@ -8887,41 +8892,37 @@ simple_rename_or_index_change(THD *thd, TABLE_LIST *table_list, */ if (wait_while_table_is_used(thd, table, extra_func)) DBUG_RETURN(true); - close_all_tables_for_name(thd, table->s, HA_EXTRA_PREPARE_FOR_RENAME, NULL); - - LEX_CSTRING old_db_name= { alter_ctx->db, strlen(alter_ctx->db) }; - LEX_CSTRING old_table_name= - { alter_ctx->table_name, strlen(alter_ctx->table_name) }; - LEX_CSTRING new_db_name= { alter_ctx->new_db, strlen(alter_ctx->new_db) }; - LEX_CSTRING new_table_name= - { alter_ctx->new_alias, strlen(alter_ctx->new_alias) }; - (void) rename_table_in_stat_tables(thd, &old_db_name, &old_table_name, - &new_db_name, &new_table_name); - - if (mysql_rename_table(old_db_type, alter_ctx->db, alter_ctx->table_name, - alter_ctx->new_db, alter_ctx->new_alias, 0)) + close_all_tables_for_name(thd, table->s, HA_EXTRA_PREPARE_FOR_RENAME, + NULL); + + (void) rename_table_in_stat_tables(thd, &alter_ctx->db, + &alter_ctx->table_name, + &alter_ctx->new_db, + &alter_ctx->new_alias); + + if (mysql_rename_table(old_db_type, &alter_ctx->db, &alter_ctx->table_name, + &alter_ctx->new_db, &alter_ctx->new_alias, 0)) error= -1; else { VTMD_rename vtmd(*table_list); if (thd->variables.vers_alter_history == VERS_ALTER_HISTORY_SURVIVE && - vtmd.try_rename(thd, new_db_name, new_table_name)) - { + vtmd.try_rename(thd, alter_ctx->new_db.str, alter_ctx->new_alias.str)) goto revert_table_name; - } - else if (Table_triggers_list::change_table_name(thd, - alter_ctx->db, - alter_ctx->alias, - alter_ctx->table_name, - alter_ctx->new_db, - alter_ctx->new_alias)) + + if (Table_triggers_list::change_table_name(thd, + &alter_ctx->db, + &alter_ctx->alias, + &alter_ctx->table_name, + &alter_ctx->new_db, + &alter_ctx->new_alias)) { if (thd->variables.vers_alter_history == VERS_ALTER_HISTORY_SURVIVE) - vtmd.revert_rename(thd, new_db_name); -revert_table_name: + vtmd.revert_rename(thd, alter_ctx->new_db.str); + revert_table_name: (void) mysql_rename_table(old_db_type, - alter_ctx->new_db, alter_ctx->new_alias, - alter_ctx->db, alter_ctx->table_name, + &alter_ctx->new_db, &alter_ctx->new_alias, + &alter_ctx->db, &alter_ctx->table_name, NO_FK_CHECKS); error= -1; } @@ -8993,7 +8994,7 @@ revert_table_name: based on information about the table changes from fill_alter_inplace_info(). */ -bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, +bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db, const LEX_CSTRING *new_name, HA_CREATE_INFO *create_info, TABLE_LIST *table_list, Alter_info *alter_info, @@ -9069,8 +9070,8 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, (ha_check_storage_engine_flag(hton1, HTON_NATIVE_SYS_VERSIONING) || ha_check_storage_engine_flag(hton2, HTON_NATIVE_SYS_VERSIONING))) { - my_error(ER_VERS_ALTER_ENGINE_PROHIBITED, MYF(0), table_list->db, - table_list->table_name); + my_error(ER_VERS_ALTER_ENGINE_PROHIBITED, MYF(0), table_list->db.str, + table_list->table_name.str); DBUG_RETURN(true); } } @@ -9081,7 +9082,8 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, } else if (vers_data_mod && thd->variables.vers_alter_history == VERS_ALTER_HISTORY_ERROR) { - my_error(ER_VERS_ALTER_NOT_ALLOWED, MYF(0), table_list->db, table_list->table_name); + my_error(ER_VERS_ALTER_NOT_ALLOWED, MYF(0), + table_list->db.str, table_list->table_name.str); DBUG_RETURN(true); } } @@ -9154,9 +9156,9 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, If such table exists, there must be a corresponding TABLE_SHARE in THD::all_temp_tables list. */ - if (thd->find_tmp_table_share(alter_ctx.new_db, alter_ctx.new_name)) + if (thd->find_tmp_table_share(alter_ctx.new_db.str, alter_ctx.new_name.str)) { - my_error(ER_TABLE_EXISTS_ERROR, MYF(0), alter_ctx.new_alias); + my_error(ER_TABLE_EXISTS_ERROR, MYF(0), alter_ctx.new_alias.str); DBUG_RETURN(true); } } @@ -9166,7 +9168,7 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, MDL_request target_db_mdl_request; target_mdl_request.init(MDL_key::TABLE, - alter_ctx.new_db, alter_ctx.new_name, + alter_ctx.new_db.str, alter_ctx.new_name.str, MDL_EXCLUSIVE, MDL_TRANSACTION); mdl_requests.push_front(&target_mdl_request); @@ -9177,7 +9179,7 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, */ if (alter_ctx.is_database_changed()) { - target_db_mdl_request.init(MDL_key::SCHEMA, alter_ctx.new_db, "", + target_db_mdl_request.init(MDL_key::SCHEMA, alter_ctx.new_db.str, "", MDL_INTENTION_EXCLUSIVE, MDL_TRANSACTION); mdl_requests.push_front(&target_db_mdl_request); @@ -9200,10 +9202,10 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, Table maybe does not exist, but we got an exclusive lock on the name, now we can safely try to find out for sure. */ - if (ha_table_exists(thd, alter_ctx.new_db, alter_ctx.new_name)) + if (ha_table_exists(thd, &alter_ctx.new_db, &alter_ctx.new_name)) { /* Table will be closed in do_command() */ - my_error(ER_TABLE_EXISTS_ERROR, MYF(0), alter_ctx.new_alias); + my_error(ER_TABLE_EXISTS_ERROR, MYF(0), alter_ctx.new_alias.str); DBUG_RETURN(true); } } @@ -9229,7 +9231,7 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, create_info->db_type= table->s->db_type(); } - if (check_engine(thd, alter_ctx.new_db, alter_ctx.new_name, create_info)) + if (check_engine(thd, alter_ctx.new_db.str, alter_ctx.new_name.str, create_info)) DBUG_RETURN(true); if (create_info->vers_info.fix_alter_info(thd, alter_info, create_info, table)) @@ -9254,7 +9256,7 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, till this point for the alter operation. */ if ((alter_info->flags & Alter_info::ADD_FOREIGN_KEY) && - check_fk_parent_table_access(thd, create_info, alter_info, new_db)) + check_fk_parent_table_access(thd, create_info, alter_info, new_db->str)) DBUG_RETURN(true); /* @@ -9280,7 +9282,7 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, { DBUG_PRINT("info", ("doesn't support alter")); my_error(ER_ILLEGAL_HA, MYF(0), hton_name(table->s->db_type())->str, - alter_ctx.db, alter_ctx.table_name); + alter_ctx.db.str, alter_ctx.table_name.str); DBUG_RETURN(true); } @@ -9289,7 +9291,7 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, { DBUG_PRINT("info", ("doesn't support alter")); my_error(ER_ILLEGAL_HA, MYF(0), hton_name(create_info->db_type)->str, - alter_ctx.new_db, alter_ctx.new_name); + alter_ctx.new_db.str, alter_ctx.new_name.str); DBUG_RETURN(true); } @@ -9307,10 +9309,10 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, */ if (alter_info->flags == 0) { - my_snprintf(alter_ctx.tmp_name, sizeof(alter_ctx.tmp_name), + my_snprintf(alter_ctx.tmp_buff, sizeof(alter_ctx.tmp_buff), ER_THD(thd, ER_INSERT_INFO), 0L, 0L, thd->get_stmt_da()->current_statement_warn_count()); - my_ok(thd, 0L, 0L, alter_ctx.tmp_name); + my_ok(thd, 0L, 0L, alter_ctx.tmp_buff); /* We don't replicate alter table statement on temporary tables */ if (table->s->tmp_table == NO_TMP_TABLE || @@ -9378,7 +9380,7 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, DBUG_RETURN(true); } - set_table_default_charset(thd, create_info, alter_ctx.db); + set_table_default_charset(thd, create_info, &alter_ctx.db); if (!opt_explicit_defaults_for_timestamp) promote_first_timestamp_column(&alter_info->create_list); @@ -9427,8 +9429,8 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, // In-place execution of ALTER TABLE for partitioning. DBUG_RETURN(fast_alter_partition_table(thd, table, alter_info, create_info, table_list, - alter_ctx.db, - alter_ctx.table_name)); + &alter_ctx.db, + &alter_ctx.table_name)); } #endif @@ -9515,7 +9517,7 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, if (create_info->index_file_name) { /* Fix index_file_name to have 'tmp_name' as basename */ - strmov(index_file, alter_ctx.tmp_name); + strmov(index_file, alter_ctx.tmp_name.str); create_info->index_file_name=fn_same(index_file, create_info->index_file_name, 1); @@ -9523,7 +9525,7 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, if (create_info->data_file_name) { /* Fix data_file_name to have 'tmp_name' as basename */ - strmov(data_file, alter_ctx.tmp_name); + strmov(data_file, alter_ctx.tmp_name.str); create_info->data_file_name=fn_same(data_file, create_info->data_file_name, 1); @@ -9560,8 +9562,8 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, tmp_disable_binlog(thd); create_info->options|=HA_CREATE_TMP_ALTER; error= create_table_impl(thd, - alter_ctx.db, alter_ctx.table_name, - alter_ctx.new_db, alter_ctx.tmp_name, + &alter_ctx.db, &alter_ctx.table_name, + &alter_ctx.new_db, &alter_ctx.tmp_name, alter_ctx.get_tmp_path(), thd->lex->create_info, create_info, alter_info, C_ALTER_TABLE_FRM_ONLY, NULL, @@ -9619,7 +9621,8 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, if (!(altered_table= thd->create_and_open_tmp_table(new_db_type, &frm, alter_ctx.get_tmp_path(), - alter_ctx.new_db, alter_ctx.tmp_name, + alter_ctx.new_db.str, + alter_ctx.tmp_name.str, false, true))) goto err_new_table_cleanup; @@ -9770,7 +9773,7 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, goto err_new_table_cleanup; if (ha_create_table(thd, alter_ctx.get_tmp_path(), - alter_ctx.new_db, alter_ctx.tmp_name, + alter_ctx.new_db.str, alter_ctx.tmp_name.str, create_info, &frm)) goto err_new_table_cleanup; @@ -9782,7 +9785,8 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, TABLE *tmp_table= thd->create_and_open_tmp_table(new_db_type, &frm, alter_ctx.get_tmp_path(), - alter_ctx.new_db, alter_ctx.tmp_name, + alter_ctx.new_db.str, + alter_ctx.tmp_name.str, true, true); if (!tmp_table) { @@ -9797,9 +9801,7 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, if (table->s->tmp_table != NO_TMP_TABLE) { TABLE_LIST tbl; - tbl.init_one_table(alter_ctx.new_db, strlen(alter_ctx.new_db), - alter_ctx.tmp_name, strlen(alter_ctx.tmp_name), - alter_ctx.tmp_name, TL_READ_NO_INSERT); + tbl.init_one_table(&alter_ctx.new_db, &alter_ctx.tmp_name, 0, TL_READ_NO_INSERT); /* Table can be found in the list of open tables in THD::all_temp_tables list. @@ -9816,7 +9818,8 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, new_table= thd->create_and_open_tmp_table(new_db_type, &frm, alter_ctx.get_tmp_path(), - alter_ctx.new_db, alter_ctx.tmp_name, + alter_ctx.new_db.str, + alter_ctx.tmp_name.str, true, true); } if (!new_table) @@ -9896,8 +9899,8 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, /* Remove link to old table and rename the new one */ thd->drop_temporary_table(table, NULL, true); /* Should pass the 'new_name' as we store table name in the cache */ - if (thd->rename_temporary_table(new_table, alter_ctx.new_db, - alter_ctx.new_name)) + if (thd->rename_temporary_table(new_table, &alter_ctx.new_db, + &alter_ctx.new_name)) goto err_new_table_cleanup; /* We don't replicate alter table statement on temporary tables */ if (!thd->is_current_stmt_binlog_format_row() && @@ -9951,37 +9954,43 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, Rename the old table to temporary name to have a backup in case anything goes wrong while renaming the new table. */ - char backup_name[FN_LEN]; + char backup_name_buff[FN_LEN]; + LEX_CSTRING backup_name; + backup_name.str= backup_name_buff; + if (vers_survival_mod) - VTMD_table::archive_name(thd, alter_ctx.table_name, backup_name, - sizeof(backup_name)); + { + VTMD_table::archive_name(thd, alter_ctx.table_name.str, backup_name_buff, + sizeof(backup_name_buff)); + backup_name.length= strlen(backup_name_buff); + } else - my_snprintf(backup_name, sizeof(backup_name), "%s2-%lx-%lx", - tmp_file_prefix, current_pid, thd->thread_id); - + backup_name.length= my_snprintf(backup_name_buff, sizeof(backup_name_buff), + "%s2-%lx-%lx", tmp_file_prefix, + current_pid, (long) thd->thread_id); if (lower_case_table_names) - my_casedn_str(files_charset_info, backup_name); - if (mysql_rename_table(old_db_type, alter_ctx.db, alter_ctx.table_name, - alter_ctx.db, backup_name, FN_TO_IS_TMP)) + my_casedn_str(files_charset_info, backup_name_buff); + if (mysql_rename_table(old_db_type, &alter_ctx.db, &alter_ctx.table_name, + &alter_ctx.db, &backup_name, FN_TO_IS_TMP)) { // Rename to temporary name failed, delete the new table, abort ALTER. - (void) quick_rm_table(thd, new_db_type, alter_ctx.new_db, - alter_ctx.tmp_name, FN_IS_TMP); + (void) quick_rm_table(thd, new_db_type, &alter_ctx.new_db, + &alter_ctx.tmp_name, FN_IS_TMP); goto err_with_mdl; } // Rename the new table to the correct name. - if (mysql_rename_table(new_db_type, alter_ctx.new_db, alter_ctx.tmp_name, - alter_ctx.new_db, alter_ctx.new_alias, + if (mysql_rename_table(new_db_type, &alter_ctx.new_db, &alter_ctx.tmp_name, + &alter_ctx.new_db, &alter_ctx.new_alias, FN_FROM_IS_TMP)) { // Rename failed, delete the temporary table. - (void) quick_rm_table(thd, new_db_type, alter_ctx.new_db, - alter_ctx.tmp_name, FN_IS_TMP); + (void) quick_rm_table(thd, new_db_type, &alter_ctx.new_db, + &alter_ctx.tmp_name, FN_IS_TMP); // Restore the backup of the original table to the old name. - (void) mysql_rename_table(old_db_type, alter_ctx.db, backup_name, - alter_ctx.db, alter_ctx.alias, + (void) mysql_rename_table(old_db_type, &alter_ctx.db, &backup_name, + &alter_ctx.db, &alter_ctx.alias, FN_FROM_IS_TMP | NO_FK_CHECKS); goto err_with_mdl; } @@ -9991,8 +10000,8 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, DBUG_ASSERT(alter_info && table_list); VTMD_rename vtmd(*table_list); bool rc= alter_info->flags & Alter_info::ALTER_RENAME ? - vtmd.try_rename(thd, alter_ctx.new_db, alter_ctx.new_alias, backup_name) : - vtmd.update(thd, backup_name); + vtmd.try_rename(thd, alter_ctx.new_db.str, alter_ctx.new_alias.str, backup_name.str) : + vtmd.update(thd, backup_name.str); if (rc) goto err_after_rename; } @@ -10001,29 +10010,29 @@ bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, if (alter_ctx.is_table_renamed()) { if (Table_triggers_list::change_table_name(thd, - alter_ctx.db, - alter_ctx.alias, - alter_ctx.table_name, - alter_ctx.new_db, - alter_ctx.new_alias)) + &alter_ctx.db, + &alter_ctx.alias, + &alter_ctx.table_name, + &alter_ctx.new_db, + &alter_ctx.new_alias)) { err_after_rename: // Rename succeeded, delete the new table. (void) quick_rm_table(thd, new_db_type, - alter_ctx.new_db, alter_ctx.new_alias, 0); + &alter_ctx.new_db, &alter_ctx.new_alias, 0); // Restore the backup of the original table to the old name. - (void) mysql_rename_table(old_db_type, alter_ctx.db, backup_name, - alter_ctx.db, alter_ctx.alias, + (void) mysql_rename_table(old_db_type, &alter_ctx.db, &backup_name, + &alter_ctx.db, &alter_ctx.alias, FN_FROM_IS_TMP | NO_FK_CHECKS); goto err_with_mdl; } - rename_table_in_stat_tables(thd, alter_ctx.db,alter_ctx.alias, - alter_ctx.new_db, alter_ctx.new_alias); + rename_table_in_stat_tables(thd, &alter_ctx.db, &alter_ctx.alias, + &alter_ctx.new_db, &alter_ctx.new_alias); } // ALTER TABLE succeeded, delete the backup of the old table. if (!(vers_survival_mod && new_versioned) && - quick_rm_table(thd, old_db_type, alter_ctx.db, backup_name, FN_IS_TMP)) + quick_rm_table(thd, old_db_type, &alter_ctx.db, &backup_name, FN_IS_TMP)) { /* The fact that deletion of the backup failed is not critical @@ -10061,11 +10070,11 @@ end_inplace: } end_temporary: - my_snprintf(alter_ctx.tmp_name, sizeof(alter_ctx.tmp_name), + my_snprintf(alter_ctx.tmp_buff, sizeof(alter_ctx.tmp_buff), ER_THD(thd, ER_INSERT_INFO), (ulong) (copied + deleted), (ulong) deleted, (ulong) thd->get_stmt_da()->current_statement_warn_count()); - my_ok(thd, copied + deleted, 0L, alter_ctx.tmp_name); + my_ok(thd, copied + deleted, 0L, alter_ctx.tmp_buff); DBUG_RETURN(false); err_new_table_cleanup: @@ -10076,7 +10085,7 @@ err_new_table_cleanup: } else (void) quick_rm_table(thd, new_db_type, - alter_ctx.new_db, alter_ctx.tmp_name, + &alter_ctx.new_db, &alter_ctx.tmp_name, (FN_IS_TMP | (no_ha_table ? NO_HA_TABLE : 0)), alter_ctx.get_tmp_path()); @@ -10297,8 +10306,8 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to, { bzero((char *) &tables, sizeof(tables)); tables.table= from; - tables.alias= tables.table_name= from->s->table_name.str; - tables.db= from->s->db.str; + tables.alias= tables.table_name= from->s->table_name; + tables.db= from->s->db; THD_STAGE_INFO(thd, stage_sorting); Filesort_tracker dummy_tracker(false); @@ -10587,7 +10596,7 @@ bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list, bool table_copy) thd->prepare_logs_for_admin_command(); - bool res= mysql_alter_table(thd, NullS, NullS, &create_info, + bool res= mysql_alter_table(thd, &null_clex_str, &null_clex_str, &create_info, table_list, &alter_info, 0, (ORDER *) 0, 0); table_list->next_global= next_table; @@ -10650,7 +10659,7 @@ bool mysql_checksum_table(THD *thd, TABLE_LIST *tables, TABLE *t; TABLE_LIST *save_next_global; - strxmov(table_name, table->db ,".", table->table_name, NullS); + strxmov(table_name, table->db.str ,".", table->table_name.str, NullS); /* Remember old 'next' pointer and break the list. */ save_next_global= table->next_global; diff --git a/sql/sql_table.h b/sql/sql_table.h index e45ddef6548..27f649e6dc7 100644 --- a/sql/sql_table.h +++ b/sql/sql_table.h @@ -191,14 +191,15 @@ bool mysql_create_table(THD *thd, TABLE_LIST *create_table, #define C_ALTER_TABLE_FRM_ONLY -2 #define C_ASSISTED_DISCOVERY -3 -int mysql_create_table_no_lock(THD *thd, const char *db, - const char *table_name, +int mysql_create_table_no_lock(THD *thd, const LEX_CSTRING *db, + const LEX_CSTRING *table_name, Table_specification_st *create_info, Alter_info *alter_info, bool *is_trans, int create_table_mode, TABLE_LIST *table); handler *mysql_create_frm_image(THD *thd, - const char *db, const char *table_name, + const LEX_CSTRING *db, + const LEX_CSTRING *table_name, HA_CREATE_INFO *create_info, Alter_info *alter_info, int create_table_mode, @@ -216,7 +217,7 @@ bool mysql_prepare_alter_table(THD *thd, TABLE *table, Alter_table_ctx *alter_ctx); bool mysql_trans_prepare_alter_copy_data(THD *thd); bool mysql_trans_commit_alter_copy_data(THD *thd); -bool mysql_alter_table(THD *thd, const char *new_db, const char *new_name, +bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db, const LEX_CSTRING *new_name, HA_CREATE_INFO *create_info, TABLE_LIST *table_list, Alter_info *alter_info, @@ -229,9 +230,9 @@ bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list, bool table_copy); bool mysql_create_like_table(THD *thd, TABLE_LIST *table, TABLE_LIST *src_table, Table_specification_st *create_info); -bool mysql_rename_table(handlerton *base, const char *old_db, - const char * old_name, const char *new_db, - const char * new_name, uint flags); +bool mysql_rename_table(handlerton *base, const LEX_CSTRING *old_db, + const LEX_CSTRING *old_name, const LEX_CSTRING *new_db, + const LEX_CSTRING *new_name, uint flags); bool mysql_backup_table(THD* thd, TABLE_LIST* table_list); bool mysql_restore_table(THD* thd, TABLE_LIST* table_list); @@ -244,11 +245,10 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, bool drop_temporary, bool drop_view, bool drop_sequence, bool log_query, bool dont_free_locks); -bool log_drop_table(THD *thd, const char *db_name, size_t db_name_length, - const char *table_name, size_t table_name_length, - bool temporary_table); -bool quick_rm_table(THD *thd, handlerton *base, const char *db, - const char *table_name, uint flags, +bool log_drop_table(THD *thd, const LEX_CSTRING *db_name, + const LEX_CSTRING *table_name, bool temporary_table); +bool quick_rm_table(THD *thd, handlerton *base, const LEX_CSTRING *db, + const LEX_CSTRING *table_name, uint flags, const char *table_path=0); void close_cached_table(THD *thd, TABLE *table); void sp_prepare_create_field(THD *thd, Column_definition *sql_field); diff --git a/sql/sql_time.cc b/sql/sql_time.cc index 276540e9dba..567739243ff 100644 --- a/sql/sql_time.cc +++ b/sql/sql_time.cc @@ -759,7 +759,7 @@ DATE_TIME_FORMAT !parse_date_time_format(format_type, format_str, format_length, &tmp)) { - tmp.format.str= (char*) format_str; + tmp.format.str= format_str; tmp.format.length= format_length; return date_time_format_copy((THD *)0, &tmp); } @@ -787,6 +787,7 @@ DATE_TIME_FORMAT *date_time_format_copy(THD *thd, DATE_TIME_FORMAT *format) { DATE_TIME_FORMAT *new_format; ulong length= sizeof(*format) + format->format.length + 1; + char *format_pos; if (thd) new_format= (DATE_TIME_FORMAT *) thd->alloc(length); @@ -795,14 +796,13 @@ DATE_TIME_FORMAT *date_time_format_copy(THD *thd, DATE_TIME_FORMAT *format) if (new_format) { /* Put format string after current pos */ - new_format->format.str= (char*) (new_format+1); + new_format->format.str= format_pos= (char*) (new_format+1); memcpy((char*) new_format->positions, (char*) format->positions, sizeof(format->positions)); new_format->time_separator= format->time_separator; /* We make the string null terminated for easy printf in SHOW VARIABLES */ - memcpy((char*) new_format->format.str, format->format.str, - format->format.length); - new_format->format.str[format->format.length]= 0; + memcpy(format_pos, format->format.str, format->format.length); + format_pos[format->format.length]= 0; new_format->format.length= format->format.length; } return new_format; diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index 63323ea386c..2e1154077b7 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -421,7 +421,7 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) need second part of condition below, since check_access() function also checks that db is specified. */ - if (!thd->lex->spname->m_db.length || (create && !tables->db_length)) + if (!thd->lex->spname->m_db.length || (create && !tables->db.length)) { my_error(ER_NO_DB_ERROR, MYF(0)); DBUG_RETURN(TRUE); @@ -430,7 +430,7 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) /* We don't allow creating triggers on tables in the 'mysql' schema */ - if (create && !my_strcasecmp(system_charset_info, "mysql", tables->db)) + if (create && !my_strcasecmp(system_charset_info, "mysql", tables->db.str)) { my_error(ER_NO_TRIGGERS_ON_SYSTEM_SCHEMA, MYF(0)); DBUG_RETURN(TRUE); @@ -522,7 +522,7 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) /* We do not allow creation of triggers on temporary tables. */ if (create && thd->find_tmp_table_share(tables)) { - my_error(ER_TRG_ON_VIEW_OR_TEMP_TABLE, MYF(0), tables->alias); + my_error(ER_TRG_ON_VIEW_OR_TEMP_TABLE, MYF(0), tables->alias.str); goto end; } @@ -540,8 +540,8 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) if (thd->locked_tables_mode) { /* Under LOCK TABLES we must only accept write locked tables. */ - if (!(tables->table= find_table_for_mdl_upgrade(thd, tables->db, - tables->table_name, + if (!(tables->table= find_table_for_mdl_upgrade(thd, tables->db.str, + tables->table_name.str, FALSE))) goto end; } @@ -682,7 +682,7 @@ static void build_trig_stmt_query(THD *thd, TABLE_LIST *tables, /* Create statement for binary logging */ - stmt_definition.str= (char*) lex->stmt_definition_begin; + stmt_definition.str= lex->stmt_definition_begin; stmt_definition.length= (lex->stmt_definition_end - lex->stmt_definition_begin); original_length= stmt_definition.length; @@ -755,8 +755,7 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables, DBUG_RETURN(true); /* Trigger must be in the same schema as target table. */ - if (lex_string_cmp(table_alias_charset, &table->s->db, - &lex->spname->m_db)) + if (lex_string_cmp(table_alias_charset, &table->s->db, &lex->spname->m_db)) { my_error(ER_TRG_IN_WRONG_SCHEMA, MYF(0)); DBUG_RETURN(true); @@ -814,11 +813,11 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables, versions */ file.length= build_table_filename(file_buff, FN_REFLEN - 1, - tables->db, tables->table_name, + tables->db.str, tables->table_name.str, TRG_EXT, 0); file.str= file_buff; trigname_file.length= build_table_filename(trigname_buff, FN_REFLEN-1, - tables->db, + tables->db.str, lex->spname->m_name.str, TRN_EXT, 0); trigname_file.str= trigname_buff; @@ -839,7 +838,7 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables, } else if (lex->create_info.if_not_exists()) { - strxnmov(trigname_buff, sizeof(trigname_buff) - 1, tables->db, ".", + strxnmov(trigname_buff, sizeof(trigname_buff) - 1, tables->db.str, ".", lex->spname->m_name.str, NullS); push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_TRG_ALREADY_EXISTS, @@ -858,15 +857,14 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables, } else { - strxnmov(trigname_buff, sizeof(trigname_buff) - 1, tables->db, ".", + strxnmov(trigname_buff, sizeof(trigname_buff) - 1, tables->db.str, ".", lex->spname->m_name.str, NullS); my_error(ER_TRG_ALREADY_EXISTS, MYF(0), trigname_buff); DBUG_RETURN(true); } } - trigname.trigger_table.str= tables->table_name; - trigname.trigger_table.length= tables->table_name_length; + trigname.trigger_table= tables->table_name; /* We are not using lex->sphead here as an argument to Trigger() as we are @@ -901,7 +899,7 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables, lex_string_set(&trigger->connection_cl_name, thd->variables.collation_connection->name); lex_string_set(&trigger->db_cl_name, - get_default_db_collation(thd, tables->db)->name); + get_default_db_collation(thd, tables->db.str)->name); /* Add trigger in it's correct place */ add_trigger(lex->trg_chistics.event, @@ -1009,10 +1007,10 @@ bool Trigger::add_to_file_list(void* param_arg) True error */ -static bool rm_trigger_file(char *path, const char *db, - const char *table_name) +static bool rm_trigger_file(char *path, const LEX_CSTRING *db, + const LEX_CSTRING *table_name) { - build_table_filename(path, FN_REFLEN-1, db, table_name, TRG_EXT, 0); + build_table_filename(path, FN_REFLEN-1, db->str, table_name->str, TRG_EXT, 0); return mysql_file_delete(key_file_trg, path, MYF(MY_WME)); } @@ -1031,10 +1029,10 @@ static bool rm_trigger_file(char *path, const char *db, True error */ -static bool rm_trigname_file(char *path, const char *db, - const char *trigger_name) +static bool rm_trigname_file(char *path, const LEX_CSTRING *db, + const LEX_CSTRING *trigger_name) { - build_table_filename(path, FN_REFLEN - 1, db, trigger_name, TRN_EXT, 0); + build_table_filename(path, FN_REFLEN - 1, db->str, trigger_name->str, TRN_EXT, 0); return mysql_file_delete(key_file_trn, path, MYF(MY_WME)); } @@ -1052,8 +1050,8 @@ static bool rm_trigname_file(char *path, const char *db, TRUE Error */ -bool Table_triggers_list::save_trigger_file(THD *thd, const char *db, - const char *table_name) +bool Table_triggers_list::save_trigger_file(THD *thd, const LEX_CSTRING *db, + const LEX_CSTRING *table_name) { char file_buff[FN_REFLEN]; LEX_CSTRING file; @@ -1061,7 +1059,7 @@ bool Table_triggers_list::save_trigger_file(THD *thd, const char *db, if (create_lists_needed_for_files(thd->mem_root)) return true; - file.length= build_table_filename(file_buff, FN_REFLEN - 1, db, table_name, + file.length= build_table_filename(file_buff, FN_REFLEN - 1, db->str, table_name->str, TRG_EXT, 0); file.str= file_buff; return sql_create_definition_file(NULL, &file, &triggers_file_type, @@ -1153,16 +1151,16 @@ bool Table_triggers_list::drop_trigger(THD *thd, TABLE_LIST *tables, parse_file.cc functionality (because we will need it elsewhere). */ - if (rm_trigger_file(path, tables->db, tables->table_name)) + if (rm_trigger_file(path, &tables->db, &tables->table_name)) return 1; } else { - if (save_trigger_file(thd, tables->db, tables->table_name)) + if (save_trigger_file(thd, &tables->db, &tables->table_name)) return 1; } - if (rm_trigname_file(path, tables->db, sp_name->str)) + if (rm_trigname_file(path, &tables->db, sp_name)) return 1; delete trigger; @@ -1301,18 +1299,18 @@ bool Table_triggers_list::prepare_record_accessors(TABLE *table) True error */ -bool Table_triggers_list::check_n_load(THD *thd, const char *db, - const char *table_name, TABLE *table, +bool Table_triggers_list::check_n_load(THD *thd, const LEX_CSTRING *db, + const LEX_CSTRING *table_name, TABLE *table, bool names_only) { char path_buff[FN_REFLEN]; LEX_CSTRING path; File_parser *parser; - LEX_STRING save_db; + LEX_CSTRING save_db; DBUG_ENTER("Table_triggers_list::check_n_load"); path.length= build_table_filename(path_buff, FN_REFLEN - 1, - db, table_name, TRG_EXT, 0); + db->str, table_name->str, TRG_EXT, 0); path.str= path_buff; // QQ: should we analyze errno somehow ? @@ -1351,8 +1349,8 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db, push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_TRG_NO_CREATION_CTX, ER_THD(thd, ER_TRG_NO_CREATION_CTX), - (const char*) db, - (const char*) table_name); + db->str, + table_name->str); } table->triggers= trigger_list; @@ -1370,9 +1368,8 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db, thd->lex= &lex; - save_db.str= thd->db; - save_db.length= thd->db_length; - thd->reset_db((char*) db, strlen(db)); + save_db= thd->db; + thd->reset_db(db); while ((trg_create_str= it++)) { sp_head *sp; @@ -1400,8 +1397,8 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db, if (!trigger_list->client_cs_names.is_empty()) creation_ctx= Trigger_creation_ctx::create(thd, - db, - table_name, + db->str, + table_name->str, it_client_cs_name++, it_connection_cl_name++, it_db_cl_name++); @@ -1510,8 +1507,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db, push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_TRG_NO_DEFINER, ER_THD(thd, ER_TRG_NO_DEFINER), - (const char*) db, - (const char*) sp->m_name.str); + db->str, sp->m_name.str); /* Set definer to the '' to correct displaying in the information @@ -1547,12 +1543,12 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db, */ char fname[SAFE_NAME_LEN + 1]; - DBUG_ASSERT((!my_strcasecmp(table_alias_charset, lex.query_tables->db, db) || - (check_n_cut_mysql50_prefix(db, fname, sizeof(fname)) && - !my_strcasecmp(table_alias_charset, lex.query_tables->db, fname)))); - DBUG_ASSERT((!my_strcasecmp(table_alias_charset, lex.query_tables->table_name, table_name) || - (check_n_cut_mysql50_prefix(table_name, fname, sizeof(fname)) && - !my_strcasecmp(table_alias_charset, lex.query_tables->table_name, fname)))); + DBUG_ASSERT((!my_strcasecmp(table_alias_charset, lex.query_tables->db.str, db->str) || + (check_n_cut_mysql50_prefix(db->str, fname, sizeof(fname)) && + !my_strcasecmp(table_alias_charset, lex.query_tables->db.str, fname)))); + DBUG_ASSERT((!my_strcasecmp(table_alias_charset, lex.query_tables->table_name.str, table_name->str) || + (check_n_cut_mysql50_prefix(table_name->str, fname, sizeof(fname)) && + !my_strcasecmp(table_alias_charset, lex.query_tables->table_name.str, fname)))); #endif if (names_only) { @@ -1585,7 +1581,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db, lex_end(&lex); } - thd->reset_db(save_db.str, save_db.length); + thd->reset_db(&save_db); thd->lex= old_lex; thd->spcont= save_spcont; thd->variables.sql_mode= save_sql_mode; @@ -1602,8 +1598,8 @@ err_with_lex_cleanup: thd->lex= old_lex; thd->spcont= save_spcont; thd->variables.sql_mode= save_sql_mode; - thd->reset_db(save_db.str, save_db.length); - /* Fall through to error */ + thd->reset_db(&save_db); + /* Fall trough to error */ } } @@ -1615,7 +1611,7 @@ error: be merged into .FRM anyway. */ my_error(ER_WRONG_OBJECT, MYF(0), - table_name, TRG_EXT + 1, "TRIGGER"); + table_name->str, TRG_EXT + 1, "TRIGGER"); } DBUG_RETURN(1); } @@ -1670,8 +1666,8 @@ void Table_triggers_list::add_trigger(trg_event_type event, /** Obtains and returns trigger metadata. - @param thd current thread context @param trigger_stmt returns statement of trigger + @param body returns body of trigger @param definer returns definer/creator of trigger. The caller is responsible to allocate enough space for storing definer information. @@ -1735,12 +1731,12 @@ bool add_table_for_trigger(THD *thd, { LEX *lex= thd->lex; char trn_path_buff[FN_REFLEN]; - LEX_STRING trn_path= { trn_path_buff, 0 }; + LEX_CSTRING trn_path= { trn_path_buff, 0 }; LEX_CSTRING tbl_name= null_clex_str; DBUG_ENTER("add_table_for_trigger"); - build_trn_path(thd, trg_name, &trn_path); + build_trn_path(thd, trg_name, (LEX_STRING*) &trn_path); if (check_trn_exists(&trn_path)) { @@ -1760,12 +1756,11 @@ bool add_table_for_trigger(THD *thd, DBUG_RETURN(TRUE); } - if (load_table_name_for_trigger(thd, trg_name, (LEX_CSTRING*) &trn_path, - &tbl_name)) + if (load_table_name_for_trigger(thd, trg_name, &trn_path, &tbl_name)) DBUG_RETURN(TRUE); - *table= sp_add_to_query_tables(thd, lex, trg_name->m_db.str, - tbl_name.str, TL_IGNORE, + *table= sp_add_to_query_tables(thd, lex, &trg_name->m_db, + &tbl_name, TL_IGNORE, MDL_SHARED_NO_WRITE); DBUG_RETURN(*table ? FALSE : TRUE); @@ -1785,8 +1780,8 @@ bool add_table_for_trigger(THD *thd, True error */ -bool Table_triggers_list::drop_all_triggers(THD *thd, const char *db, - const char *name) +bool Table_triggers_list::drop_all_triggers(THD *thd, const LEX_CSTRING *db, + const LEX_CSTRING *name) { TABLE table; char path[FN_REFLEN]; @@ -1818,7 +1813,7 @@ bool Table_triggers_list::drop_all_triggers(THD *thd, const char *db, Such triggers have zero-length name and are skipped here. */ if (trigger->name.length && - rm_trigname_file(path, db, trigger->name.str)) + rm_trigname_file(path, db, &trigger->name)) { /* Instead of immediately bailing out with error if we were unable @@ -1858,26 +1853,27 @@ end: struct change_table_name_param { THD *thd; - const char *old_db_name; - const char *new_db_name; + LEX_CSTRING *old_db_name; + LEX_CSTRING *new_db_name; LEX_CSTRING *new_table_name; Trigger *stopper; }; bool -Table_triggers_list::change_table_name_in_triggers(THD *thd, - const char *old_db_name, - const char *new_db_name, - LEX_CSTRING *old_table_name, - LEX_CSTRING *new_table_name) +Table_triggers_list:: +change_table_name_in_triggers(THD *thd, + const LEX_CSTRING *old_db_name, + const LEX_CSTRING *new_db_name, + const LEX_CSTRING *old_table_name, + const LEX_CSTRING *new_table_name) { struct change_table_name_param param; sql_mode_t save_sql_mode= thd->variables.sql_mode; char path_buff[FN_REFLEN]; param.thd= thd; - param.new_table_name= new_table_name; + param.new_table_name= const_cast<LEX_CSTRING*>(new_table_name); for_all_triggers(&Trigger::change_table_name, ¶m); @@ -1886,12 +1882,12 @@ Table_triggers_list::change_table_name_in_triggers(THD *thd, if (thd->is_fatal_error) return TRUE; /* OOM */ - if (save_trigger_file(thd, new_db_name, new_table_name->str)) + if (save_trigger_file(thd, new_db_name, new_table_name)) return TRUE; - if (rm_trigger_file(path_buff, old_db_name, old_table_name->str)) + if (rm_trigger_file(path_buff, old_db_name, old_table_name)) { - (void) rm_trigger_file(path_buff, new_db_name, new_table_name->str); + (void) rm_trigger_file(path_buff, new_db_name, new_table_name); return TRUE; } return FALSE; @@ -1919,7 +1915,7 @@ bool Trigger::change_table_name(void* param_arg) buff.append(def->str, before_on_len); buff.append(STRING_WITH_LEN("ON ")); - append_identifier(thd, &buff, new_table_name->str, new_table_name->length); + append_identifier(thd, &buff, new_table_name); buff.append(STRING_WITH_LEN(" ")); on_q_table_name_len= buff.length() - before_on_len; buff.append(on_table_name.str + on_table_name.length, @@ -1956,15 +1952,16 @@ bool Trigger::change_table_name(void* param_arg) */ Trigger * -Table_triggers_list::change_table_name_in_trignames(const char *old_db_name, - const char *new_db_name, - LEX_CSTRING *new_table_name, - Trigger *trigger) +Table_triggers_list:: +change_table_name_in_trignames(const LEX_CSTRING *old_db_name, + const LEX_CSTRING *new_db_name, + const LEX_CSTRING *new_table_name, + Trigger *trigger) { struct change_table_name_param param; - param.old_db_name= old_db_name; - param.new_db_name= new_db_name; - param.new_table_name= new_table_name; + param.old_db_name= const_cast<LEX_CSTRING*>(old_db_name); + param.new_db_name= const_cast<LEX_CSTRING*>(new_db_name); + param.new_table_name= const_cast<LEX_CSTRING*>(new_table_name); param.stopper= trigger; return for_all_triggers(&Trigger::change_on_table_name, ¶m); @@ -1983,7 +1980,7 @@ bool Trigger::change_on_table_name(void* param_arg) return 0; // Stop processing trigname_file.length= build_table_filename(trigname_buff, FN_REFLEN-1, - param->new_db_name, name.str, + param->new_db_name->str, name.str, TRN_EXT, 0); trigname_file.str= trigname_buff; @@ -1999,9 +1996,9 @@ bool Trigger::change_on_table_name(void* param_arg) /* Remove stale .TRN file in case of database upgrade */ if (param->old_db_name) { - if (rm_trigname_file(trigname_buff, param->old_db_name, name.str)) + if (rm_trigname_file(trigname_buff, param->old_db_name, &name)) { - (void) rm_trigname_file(trigname_buff, param->new_db_name, name.str); + (void) rm_trigname_file(trigname_buff, param->new_db_name, &name); return 1; } } @@ -2030,11 +2027,11 @@ bool Trigger::change_on_table_name(void* param_arg) @retval TRUE Error */ -bool Table_triggers_list::change_table_name(THD *thd, const char *db, - const char *old_alias, - const char *old_table, - const char *new_db, - const char *new_table) +bool Table_triggers_list::change_table_name(THD *thd, const LEX_CSTRING *db, + const LEX_CSTRING *old_alias, + const LEX_CSTRING *old_table, + const LEX_CSTRING *new_db, + const LEX_CSTRING *new_table) { TABLE table; bool result= 0; @@ -2049,11 +2046,12 @@ bool Table_triggers_list::change_table_name(THD *thd, const char *db, This method interfaces the mysql server code protected by an exclusive metadata lock. */ - DBUG_ASSERT(thd->mdl_context.is_lock_owner(MDL_key::TABLE, db, old_table, + DBUG_ASSERT(thd->mdl_context.is_lock_owner(MDL_key::TABLE, db->str, + old_table->str, MDL_EXCLUSIVE)); - DBUG_ASSERT(my_strcasecmp(table_alias_charset, db, new_db) || - my_strcasecmp(table_alias_charset, old_alias, new_table)); + DBUG_ASSERT(my_strcasecmp(table_alias_charset, db->str, new_db->str) || + my_strcasecmp(table_alias_charset, old_alias->str, new_table->str)); if (Table_triggers_list::check_n_load(thd, db, old_table, &table, TRUE)) { @@ -2067,8 +2065,6 @@ bool Table_triggers_list::change_table_name(THD *thd, const char *db, result= 1; goto end; } - LEX_CSTRING old_table_name= { (char *) old_alias, strlen(old_alias) }; - LEX_CSTRING new_table_name= { (char *) new_table, strlen(new_table) }; /* Since triggers should be in the same schema as their subject tables moving table with them between two schemas raises too many questions. @@ -2079,11 +2075,11 @@ bool Table_triggers_list::change_table_name(THD *thd, const char *db, we will be given table name with "#mysql50#" prefix To remove this prefix we use check_n_cut_mysql50_prefix(). */ - if (my_strcasecmp(table_alias_charset, db, new_db)) + if (my_strcasecmp(table_alias_charset, db->str, new_db->str)) { char dbname[SAFE_NAME_LEN + 1]; - if (check_n_cut_mysql50_prefix(db, dbname, sizeof(dbname)) && - !my_strcasecmp(table_alias_charset, dbname, new_db)) + if (check_n_cut_mysql50_prefix(db->str, dbname, sizeof(dbname)) && + !my_strcasecmp(table_alias_charset, dbname, new_db->str)) { upgrading50to51= TRUE; } @@ -2095,15 +2091,15 @@ bool Table_triggers_list::change_table_name(THD *thd, const char *db, } } if (table.triggers->change_table_name_in_triggers(thd, db, new_db, - &old_table_name, - &new_table_name)) + old_alias, + new_table)) { result= 1; goto end; } if ((err_trigger= table.triggers-> change_table_name_in_trignames( upgrading50to51 ? db : NULL, - new_db, &new_table_name, 0))) + new_db, new_table, 0))) { /* If we were unable to update one of .TRN files properly we will @@ -2113,10 +2109,10 @@ bool Table_triggers_list::change_table_name(THD *thd, const char *db, */ (void) table.triggers->change_table_name_in_trignames( upgrading50to51 ? new_db : NULL, db, - &old_table_name, err_trigger); + old_alias, err_trigger); (void) table.triggers->change_table_name_in_triggers( thd, db, new_db, - &new_table_name, &old_table_name); + new_table, old_alias); result= 1; goto end; } @@ -2458,7 +2454,7 @@ void build_trn_path(THD *thd, const sp_name *trg_name, LEX_STRING *trn_path) @retval FALSE if TRN-file exists. */ -bool check_trn_exists(const LEX_STRING *trn_path) +bool check_trn_exists(const LEX_CSTRING *trn_path) { return access(trn_path->str, F_OK) != 0; } diff --git a/sql/sql_trigger.h b/sql/sql_trigger.h index 6c02afdb89c..0fddb94fde1 100644 --- a/sql/sql_trigger.h +++ b/sql/sql_trigger.h @@ -223,17 +223,17 @@ public: bool old_row_is_record1); void empty_lists(); bool create_lists_needed_for_files(MEM_ROOT *root); - bool save_trigger_file(THD *thd, const char *db, const char *table_name); + bool save_trigger_file(THD *thd, const LEX_CSTRING *db, const LEX_CSTRING *table_name); - static bool check_n_load(THD *thd, const char *db, const char *table_name, + static bool check_n_load(THD *thd, const LEX_CSTRING *db, const LEX_CSTRING *table_name, TABLE *table, bool names_only); - static bool drop_all_triggers(THD *thd, const char *db, - const char *table_name); - static bool change_table_name(THD *thd, const char *db, - const char *old_alias, - const char *old_table, - const char *new_db, - const char *new_table); + static bool drop_all_triggers(THD *thd, const LEX_CSTRING *db, + const LEX_CSTRING *table_name); + static bool change_table_name(THD *thd, const LEX_CSTRING *db, + const LEX_CSTRING *old_alias, + const LEX_CSTRING *old_table, + const LEX_CSTRING *new_db, + const LEX_CSTRING *new_table); void add_trigger(trg_event_type event_type, trg_action_time_type action_time, trigger_order_type ordering_clause, @@ -286,15 +286,15 @@ public: private: bool prepare_record_accessors(TABLE *table); - Trigger *change_table_name_in_trignames(const char *old_db_name, - const char *new_db_name, - LEX_CSTRING *new_table_name, + Trigger *change_table_name_in_trignames(const LEX_CSTRING *old_db_name, + const LEX_CSTRING *new_db_name, + const LEX_CSTRING *new_table_name, Trigger *trigger); bool change_table_name_in_triggers(THD *thd, - const char *old_db_name, - const char *new_db_name, - LEX_CSTRING *old_table_name, - LEX_CSTRING *new_table_name); + const LEX_CSTRING *old_db_name, + const LEX_CSTRING *new_db_name, + const LEX_CSTRING *old_table_name, + const LEX_CSTRING *new_table_name); bool check_for_broken_triggers() { @@ -314,7 +314,7 @@ bool add_table_for_trigger(THD *thd, void build_trn_path(THD *thd, const sp_name *trg_name, LEX_STRING *trn_path); -bool check_trn_exists(const LEX_STRING *trn_path); +bool check_trn_exists(const LEX_CSTRING *trn_path); bool load_table_name_for_trigger(THD *thd, const sp_name *trg_name, diff --git a/sql/sql_truncate.cc b/sql/sql_truncate.cc index bd3f1fdc111..2ddb4bc042c 100644 --- a/sql/sql_truncate.cc +++ b/sql/sql_truncate.cc @@ -48,7 +48,7 @@ static bool fk_info_append_fields(THD *thd, String *str, while ((field= it++)) { - res|= append_identifier(thd, str, field->str, field->length); + res|= append_identifier(thd, str, field); res|= str->append(", "); } @@ -80,22 +80,17 @@ static const char *fk_info_str(THD *thd, FOREIGN_KEY_INFO *fk_info) `db`.`tbl`, CONSTRAINT `id` FOREIGN KEY (`fk`) REFERENCES `db`.`tbl` (`fk`) */ - res|= append_identifier(thd, &str, fk_info->foreign_db->str, - fk_info->foreign_db->length); + res|= append_identifier(thd, &str, fk_info->foreign_db); res|= str.append("."); - res|= append_identifier(thd, &str, fk_info->foreign_table->str, - fk_info->foreign_table->length); + res|= append_identifier(thd, &str, fk_info->foreign_table); res|= str.append(", CONSTRAINT "); - res|= append_identifier(thd, &str, fk_info->foreign_id->str, - fk_info->foreign_id->length); + res|= append_identifier(thd, &str, fk_info->foreign_id); res|= str.append(" FOREIGN KEY ("); res|= fk_info_append_fields(thd, &str, &fk_info->foreign_fields); res|= str.append(") REFERENCES "); - res|= append_identifier(thd, &str, fk_info->referenced_db->str, - fk_info->referenced_db->length); + res|= append_identifier(thd, &str, fk_info->referenced_db); res|= str.append("."); - res|= append_identifier(thd, &str, fk_info->referenced_table->str, - fk_info->referenced_table->length); + res|= append_identifier(thd, &str, fk_info->referenced_table); res|= str.append(" ("); res|= fk_info_append_fields(thd, &str, &fk_info->referenced_fields); res|= str.append(')'); @@ -303,8 +298,8 @@ bool Sql_cmd_truncate_table::lock_table(THD *thd, TABLE_LIST *table_ref, */ if (thd->locked_tables_mode) { - if (!(table= find_table_for_mdl_upgrade(thd, table_ref->db, - table_ref->table_name, FALSE))) + if (!(table= find_table_for_mdl_upgrade(thd, table_ref->db.str, + table_ref->table_name.str, FALSE))) DBUG_RETURN(TRUE); *hton_can_recreate= ha_check_storage_engine_flag(table->s->db_type(), @@ -322,11 +317,12 @@ bool Sql_cmd_truncate_table::lock_table(THD *thd, TABLE_LIST *table_ref, thd->variables.lock_wait_timeout, 0)) DBUG_RETURN(TRUE); - if (!ha_table_exists(thd, table_ref->db, table_ref->table_name, + if (!ha_table_exists(thd, &table_ref->db, &table_ref->table_name, &hton, &is_sequence) || hton == view_pseudo_hton) { - my_error(ER_NO_SUCH_TABLE, MYF(0), table_ref->db, table_ref->table_name); + my_error(ER_NO_SUCH_TABLE, MYF(0), table_ref->db.str, + table_ref->table_name.str); DBUG_RETURN(TRUE); } @@ -364,8 +360,8 @@ bool Sql_cmd_truncate_table::lock_table(THD *thd, TABLE_LIST *table_ref, else { /* Table is already locked exclusively. Remove cached instances. */ - tdc_remove_table(thd, TDC_RT_REMOVE_ALL, table_ref->db, - table_ref->table_name, FALSE); + tdc_remove_table(thd, TDC_RT_REMOVE_ALL, table_ref->db.str, + table_ref->table_name.str, FALSE); } DBUG_RETURN(FALSE); @@ -418,7 +414,7 @@ bool Sql_cmd_truncate_table::truncate_table(THD *thd, TABLE_LIST *table_ref) bool hton_can_recreate; if (WSREP(thd) && - wsrep_to_isolation_begin(thd, table_ref->db, table_ref->table_name, 0)) + wsrep_to_isolation_begin(thd, table_ref->db.str, table_ref->table_name.str, 0)) DBUG_RETURN(TRUE); if (lock_table(thd, table_ref, &hton_can_recreate)) DBUG_RETURN(TRUE); @@ -429,7 +425,7 @@ bool Sql_cmd_truncate_table::truncate_table(THD *thd, TABLE_LIST *table_ref) The storage engine can truncate the table by creating an empty table with the same structure. */ - error= dd_recreate_table(thd, table_ref->db, table_ref->table_name); + error= dd_recreate_table(thd, table_ref->db.str, table_ref->table_name.str); if (thd->locked_tables_mode && thd->locked_tables_list.reopen_tables(thd)) thd->locked_tables_list.unlink_all_closed_tables(thd, NULL, 0); diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc index 7b2d041a094..ecf05d86193 100644 --- a/sql/sql_udf.cc +++ b/sql/sql_udf.cc @@ -52,7 +52,7 @@ static bool initialized = 0; static MEM_ROOT mem; static HASH udf_hash; static mysql_rwlock_t THR_LOCK_udf; - +static LEX_CSTRING MYSQL_FUNC_NAME= {STRING_WITH_LEN("func") }; static udf_func *add_udf(LEX_CSTRING *name, Item_result ret, const char *dl, Item_udftype typ); @@ -142,7 +142,6 @@ void udf_init() TABLE *table; int error; DBUG_ENTER("ufd_init"); - char db[]= "mysql"; /* A subject to casednstr, can't be constant */ if (initialized || opt_noacl) DBUG_VOID_RETURN; @@ -167,9 +166,9 @@ void udf_init() initialized = 1; new_thd->thread_stack= (char*) &new_thd; new_thd->store_globals(); - new_thd->set_db(db, sizeof(db)-1); + new_thd->set_db(&MYSQL_SCHEMA_NAME); - tables.init_one_table(db, sizeof(db)-1, "func", 4, "func", TL_READ); + tables.init_one_table(&new_thd->db, &MYSQL_FUNC_NAME, 0, TL_READ); if (open_and_lock_tables(new_thd, &tables, FALSE, MYSQL_LOCK_IGNORE_TIMEOUT)) { @@ -504,8 +503,7 @@ int mysql_create_function(THD *thd,udf_func *udf) if (check_ident_length(&udf->name)) DBUG_RETURN(1); - tables.init_one_table(STRING_WITH_LEN("mysql"), STRING_WITH_LEN("func"), - "func", TL_WRITE); + tables.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_FUNC_NAME, 0, TL_WRITE); table= open_ltable(thd, &tables, TL_WRITE, MYSQL_LOCK_IGNORE_TIMEOUT); mysql_rwlock_wrlock(&THR_LOCK_udf); @@ -623,8 +621,7 @@ int mysql_drop_function(THD *thd, const LEX_CSTRING *udf_name) DBUG_RETURN(1); } - tables.init_one_table(STRING_WITH_LEN("mysql"), STRING_WITH_LEN("func"), - "func", TL_WRITE); + tables.init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_FUNC_NAME, 0, TL_WRITE); table= open_ltable(thd, &tables, TL_WRITE, MYSQL_LOCK_IGNORE_TIMEOUT); mysql_rwlock_wrlock(&THR_LOCK_udf); diff --git a/sql/sql_union.cc b/sql/sql_union.cc index f18d30a45c0..3be9dc4feb9 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -363,7 +363,7 @@ bool select_unit::flush() bool select_unit::create_result_table(THD *thd_arg, List<Item> *column_types, bool is_union_distinct, ulonglong options, - const char *alias, + const LEX_CSTRING *alias, bool bit_fields_as_long, bool create_table, bool keep_row_order, uint hidden) @@ -397,7 +397,7 @@ select_union_recursive::create_result_table(THD *thd_arg, List<Item> *column_types, bool is_union_distinct, ulonglong options, - const char *alias, + const LEX_CSTRING *alias, bool bit_fields_as_long, bool create_table, bool keep_row_order, @@ -405,14 +405,14 @@ select_union_recursive::create_result_table(THD *thd_arg, { if (select_unit::create_result_table(thd_arg, column_types, is_union_distinct, options, - "", bit_fields_as_long, + &empty_clex_str, bit_fields_as_long, create_table, keep_row_order, hidden)) return true; if (! (incr_table= create_tmp_table(thd_arg, &tmp_table_param, *column_types, (ORDER*) 0, false, 1, - options, HA_POS_ERROR, "", + options, HA_POS_ERROR, &empty_clex_str, !create_table, keep_row_order))) return true; @@ -1010,7 +1010,7 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result, goto err; if (union_result->create_result_table(thd, &types, MY_TEST(union_distinct), - create_options, derived->alias, + create_options, &derived->alias, false, instantiate_tmp_table, false, 0)) @@ -1132,7 +1132,7 @@ cont: bool error= union_result->create_result_table(thd, &types, MY_TEST(union_distinct), - create_options, "", false, + create_options, &empty_clex_str, false, instantiate_tmp_table, false, hidden); if (intersect_mark) @@ -1147,8 +1147,10 @@ cont: save_maybe_null= result_table_list.maybe_null_exec; } bzero((char*) &result_table_list, sizeof(result_table_list)); - result_table_list.db= (char*) ""; - result_table_list.table_name= result_table_list.alias= (char*) "union"; + result_table_list.db.str= (char*) ""; + result_table_list.db.length= 0; + result_table_list.table_name.str= result_table_list.alias.str= "union"; + result_table_list.table_name.length= result_table_list.alias.length= sizeof("union")-1; result_table_list.table= table= union_result->table; if (fake_select_lex && !fake_select_lex->first_cond_optimization) { diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 7b4938fc8c4..fa47a3593d1 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -341,7 +341,7 @@ int mysql_update(THD *thd, if (!table_list->single_table_updatable()) { - my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "UPDATE"); + my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias.str, "UPDATE"); DBUG_RETURN(1); } query_plan.updating_a_view= MY_TEST(table_list->view); @@ -380,7 +380,7 @@ int mysql_update(THD *thd, bool has_vers_fields= check_has_vers_fields(table, fields); if (check_key_in_view(thd, table_list)) { - my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "UPDATE"); + my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias.str, "UPDATE"); DBUG_RETURN(1); } @@ -1365,8 +1365,8 @@ bool unsafe_key_update(List<TABLE_LIST> leaves, table_map tables_for_update) { // Partitioned key is updated my_error(ER_MULTI_UPDATE_KEY_CONFLICT, MYF(0), - tl->top_table()->alias, - tl2->top_table()->alias); + tl->top_table()->alias.str, + tl2->top_table()->alias.str); return true; } @@ -1384,8 +1384,8 @@ bool unsafe_key_update(List<TABLE_LIST> leaves, table_map tables_for_update) { // Clustered primary key is updated my_error(ER_MULTI_UPDATE_KEY_CONFLICT, MYF(0), - tl->top_table()->alias, - tl2->top_table()->alias); + tl->top_table()->alias.str, + tl2->top_table()->alias.str); return true; } } @@ -1587,12 +1587,12 @@ int mysql_multi_update_prepare(THD *thd) if (!tl->single_table_updatable() || check_key_in_view(thd, tl)) { my_error(ER_NON_UPDATABLE_TABLE, MYF(0), - tl->top_table()->alias, "UPDATE"); + tl->top_table()->alias.str, "UPDATE"); DBUG_RETURN(TRUE); } DBUG_PRINT("info",("setting table `%s` for update", - tl->top_table()->alias)); + tl->top_table()->alias.str)); /* If table will be updated we should not downgrade lock for it and leave it as is. @@ -1600,7 +1600,7 @@ int mysql_multi_update_prepare(THD *thd) } else { - DBUG_PRINT("info",("setting table `%s` for read-only", tl->alias)); + DBUG_PRINT("info",("setting table `%s` for read-only", tl->alias.str)); /* If we are using the binary log, we need TL_READ_NO_INSERT to get correct order of statements. Otherwise, we use a TL_READ lock to @@ -1681,7 +1681,7 @@ int mysql_multi_update_prepare(THD *thd) (SELECT_ACL & ~tlist->grant.privilege); table->grant.want_privilege= (SELECT_ACL & ~table->grant.privilege); } - DBUG_PRINT("info", ("table: %s want_privilege: %u", tl->alias, + DBUG_PRINT("info", ("table: %s want_privilege: %u", tl->alias.str, (uint) table->grant.want_privilege)); } /* @@ -2176,7 +2176,7 @@ loop_end: thd->variables.big_tables= FALSE; tmp_tables[cnt]=create_tmp_table(thd, tmp_param, temp_fields, (ORDER*) &group, 0, 0, - TMP_TABLE_ALL_COLUMNS, HA_POS_ERROR, ""); + TMP_TABLE_ALL_COLUMNS, HA_POS_ERROR, &empty_clex_str); thd->variables.big_tables= save_big_tables; if (!tmp_tables[cnt]) DBUG_RETURN(1); diff --git a/sql/sql_view.cc b/sql/sql_view.cc index c36c1fa2a93..fc73906366a 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -273,13 +273,13 @@ bool create_view_precheck(THD *thd, TABLE_LIST *tables, TABLE_LIST *view, checked that we have not more privileges on correspondent column of view table (i.e. user will not get some privileges by view creation) */ - if ((check_access(thd, CREATE_VIEW_ACL, view->db, + if ((check_access(thd, CREATE_VIEW_ACL, view->db.str, &view->grant.privilege, &view->grant.m_internal, 0, 0) || check_grant(thd, CREATE_VIEW_ACL, view, FALSE, 1, FALSE)) || (mode != VIEW_CREATE_NEW && - (check_access(thd, DROP_ACL, view->db, + (check_access(thd, DROP_ACL, view->db.str, &view->grant.privilege, &view->grant.m_internal, 0, 0) || @@ -298,7 +298,7 @@ bool create_view_precheck(THD *thd, TABLE_LIST *tables, TABLE_LIST *view, { my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0), "ANY", thd->security_ctx->priv_user, - thd->security_ctx->priv_host, tbl->table_name); + thd->security_ctx->priv_host, tbl->table_name.str); goto err; } /* @@ -319,8 +319,7 @@ bool create_view_precheck(THD *thd, TABLE_LIST *tables, TABLE_LIST *view, tbl->table_name will be correct name of table because VIEWs are not opened yet. */ - fill_effective_table_privileges(thd, &tbl->grant, tbl->db, - tbl->table_name); + fill_effective_table_privileges(thd, &tbl->grant, tbl->db.str, tbl->table_name.str); } } @@ -331,7 +330,7 @@ bool create_view_precheck(THD *thd, TABLE_LIST *tables, TABLE_LIST *view, { if (!tbl->table_in_first_from_clause) { - if (check_access(thd, SELECT_ACL, tbl->db, + if (check_access(thd, SELECT_ACL, tbl->db.str, &tbl->grant.privilege, &tbl->grant.m_internal, 0, 0) || @@ -457,9 +456,9 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, view= lex->unlink_first_table(&link_to_local); - if (check_db_dir_existence(view->db)) + if (check_db_dir_existence(view->db.str)) { - my_error(ER_BAD_DB_ERROR, MYF(0), view->db); + my_error(ER_BAD_DB_ERROR, MYF(0), view->db.str); res= TRUE; goto err; } @@ -495,8 +494,8 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, { /* is this table view and the same view which we creates now? */ if (tbl->view && - strcmp(tbl->view_db.str, view->db) == 0 && - strcmp(tbl->view_name.str, view->table_name) == 0) + cmp(&tbl->view_db, &view->db) == 0 && + cmp(&tbl->view_name, &view->table_name) == 0) { my_error(ER_NO_SUCH_TABLE, MYF(0), tbl->view_db.str, tbl->view_name.str); res= TRUE; @@ -516,7 +515,7 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, if (tbl->table->s->tmp_table != NO_TMP_TABLE && !tbl->view && !tbl->schema_table) { - my_error(ER_VIEW_SELECT_TMPTABLE, MYF(0), tbl->alias); + my_error(ER_VIEW_SELECT_TMPTABLE, MYF(0), tbl->alias.str); res= TRUE; goto err; } @@ -545,9 +544,9 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, if (lex->view_list.elements) { List_iterator_fast<Item> it(select_lex->item_list); - List_iterator_fast<LEX_STRING> nm(lex->view_list); + List_iterator_fast<LEX_CSTRING> nm(lex->view_list); Item *item; - LEX_STRING *name; + LEX_CSTRING *name; if (lex->view_list.elements != select_lex->item_list.elements) { @@ -577,8 +576,8 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, Compare/check grants on view with grants of underlying tables */ - fill_effective_table_privileges(thd, &view->grant, view->db, - view->table_name); + fill_effective_table_privileges(thd, &view->grant, view->db.str, + view->table_name.str); /* Make sure that the current user does not have more column-level privileges @@ -597,14 +596,14 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, for (sl= select_lex; sl; sl= sl->next_select()) { - DBUG_ASSERT(view->db); /* Must be set in the parser */ + DBUG_ASSERT(view->db.str); /* Must be set in the parser */ List_iterator_fast<Item> it(sl->item_list); Item *item; while ((item= it++)) { Item_field *fld= item->field_for_view_update(); - uint priv= (get_column_grant(thd, &view->grant, view->db, - view->table_name, item->name.str) & + uint priv= (get_column_grant(thd, &view->grant, view->db.str, + view->table_name.str, item->name.str) & VIEW_ANY_ACL); if (!fld) @@ -631,7 +630,7 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, my_error(ER_COLUMNACCESS_DENIED_ERROR, MYF(0), "create view", thd->security_ctx->priv_user, thd->security_ctx->priv_host, report_item->name.str, - view->table_name); + view->table_name.str); res= TRUE; goto err; } @@ -647,7 +646,7 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, */ if (!res) - tdc_remove_table(thd, TDC_RT_REMOVE_ALL, view->db, view->table_name, false); + tdc_remove_table(thd, TDC_RT_REMOVE_ALL, view->db.str, view->table_name.str, false); if (!res && mysql_bin_log.is_open()) { @@ -667,30 +666,29 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, buff.append(STRING_WITH_LEN("IF NOT EXISTS ")); /* Test if user supplied a db (ie: we did not use thd->db) */ - if (views->db && views->db[0] && - (thd->db == NULL || strcmp(views->db, thd->db))) + if (views->db.str && views->db.str[0] && + (thd->db.str == NULL || cmp(&views->db, &thd->db))) { - append_identifier(thd, &buff, views->db, - views->db_length); + append_identifier(thd, &buff, &views->db); buff.append('.'); } - append_identifier(thd, &buff, views->table_name, - views->table_name_length); + append_identifier(thd, &buff, &views->table_name); if (lex->view_list.elements) { - List_iterator_fast<LEX_STRING> names(lex->view_list); - LEX_STRING *name; + List_iterator_fast<LEX_CSTRING> names(lex->view_list); + LEX_CSTRING *name; int i; for (i= 0; (name= names++); i++) { buff.append(i ? ", " : "("); - append_identifier(thd, &buff, name->str, name->length); + append_identifier(thd, &buff, name); } buff.append(')'); } buff.append(STRING_WITH_LEN(" AS ")); - buff.append(&views->source); + /* views->source doesn't end with \0 */ + buff.append(views->source.str, views->source.length); int errcode= query_error_code(thd, TRUE); /* @@ -733,11 +731,11 @@ static void make_view_filename(LEX_CSTRING *dir, char *dir_buff, { /* print file name */ dir->length= build_table_filename(dir_buff, dir_buff_len - 1, - view->db, "", "", 0); + view->db.str, "", "", 0); dir->str= dir_buff; path->length= build_table_filename(path_buff, path_buff_len - 1, - view->db, view->table_name, reg_ext, 0); + view->db.str, view->table_name.str, reg_ext, 0); path->str= path_buff; file->str= path->str + dir->length; @@ -850,11 +848,12 @@ int mariadb_fix_view(THD *thd, TABLE_LIST *view, bool wrong_checksum, (uchar*)view, view_parameters)) { sql_print_error("View '%-.192s'.'%-.192s': algorithm swap error.", - view->db, view->table_name); + view->db.str, view->table_name.str); DBUG_RETURN(HA_ADMIN_INTERNAL_ERROR); } sql_print_information("View %`s.%`s: the version is set to %llu%s%s", - view->db, view->table_name, view->mariadb_version, + view->db.str, view->table_name.str, + view->mariadb_version, (wrong_checksum ? ", checksum corrected" : ""), (swap_alg ? ((view->algorithm == VIEW_ALGORITHM_MERGE) ? @@ -1034,19 +1033,19 @@ loop_out: fn_format(path_buff, file.str, dir.str, "", MY_UNPACK_FILENAME); path.length= strlen(path_buff); - if (ha_table_exists(thd, view->db, view->table_name)) + if (ha_table_exists(thd, &view->db, &view->table_name)) { if (lex->create_info.if_not_exists()) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_TABLE_EXISTS_ERROR, ER_THD(thd, ER_TABLE_EXISTS_ERROR), - view->table_name); + view->table_name.str); DBUG_RETURN(0); } else if (mode == VIEW_CREATE_NEW) { - my_error(ER_TABLE_EXISTS_ERROR, MYF(0), view->alias); + my_error(ER_TABLE_EXISTS_ERROR, MYF(0), view->alias.str); error= -1; goto err; } @@ -1059,7 +1058,8 @@ loop_out: if (!parser->ok() || !is_equal(&view_type, parser->type())) { - my_error(ER_WRONG_OBJECT, MYF(0), view->db, view->table_name, "VIEW"); + my_error(ER_WRONG_OBJECT, MYF(0), view->db.str, view->table_name.str, + "VIEW"); error= -1; goto err; } @@ -1073,7 +1073,7 @@ loop_out: { if (mode == VIEW_ALTER) { - my_error(ER_NO_SUCH_TABLE, MYF(0), view->db, view->alias); + my_error(ER_NO_SUCH_TABLE, MYF(0), view->db.str, view->alias.str); error= -1; goto err; } @@ -1117,8 +1117,8 @@ loop_out: !lex->select_lex.master_unit()->is_unit_op() && !(lex->select_lex.table_list.first)->next_local && find_table_in_global_list(lex->query_tables->next_global, - lex->query_tables->db, - lex->query_tables->table_name)) + &lex->query_tables->db, + &lex->query_tables->table_name)) { view->updatable_view= 0; } @@ -1126,7 +1126,7 @@ loop_out: if (view->with_check != VIEW_CHECK_NONE && !view->updatable_view) { - my_error(ER_VIEW_NONUPD_CHECK, MYF(0), view->db, view->table_name); + my_error(ER_VIEW_NONUPD_CHECK, MYF(0), view->db.str, view->table_name.str); error= -1; goto err; } @@ -1170,7 +1170,7 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table, bool result, view_is_mergeable; TABLE_LIST *UNINIT_VAR(view_main_select_tables); DBUG_ENTER("mysql_make_view"); - DBUG_PRINT("info", ("table: %p (%s)", table, table->table_name)); + DBUG_PRINT("info", ("table: %p (%s)", table, table->table_name.str)); if (table->required_type == TABLE_TYPE_NORMAL) { @@ -1216,7 +1216,7 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table, if (table->index_hints && table->index_hints->elements) { my_error(ER_KEY_DOES_NOT_EXITS, MYF(0), - table->index_hints->head()->key_name.str, table->table_name); + table->index_hints->head()->key_name.str, table->table_name.str); DBUG_RETURN(TRUE); } @@ -1225,12 +1225,12 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table, precedent; precedent= precedent->referencing_view) { - if (precedent->view_name.length == table->table_name_length && - precedent->view_db.length == table->db_length && + if (precedent->view_name.length == table->table_name.length && + precedent->view_db.length == table->db.length && my_strcasecmp(system_charset_info, - precedent->view_name.str, table->table_name) == 0 && + precedent->view_name.str, table->table_name.str) == 0 && my_strcasecmp(system_charset_info, - precedent->view_db.str, table->db) == 0) + precedent->view_db.str, table->db.str) == 0) { my_error(ER_VIEW_RECURSIVE, MYF(0), top_view->view_db.str, top_view->view_name.str); @@ -1274,7 +1274,7 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table, !table->definer.host.length); push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_VIEW_FRM_NO_USER, ER_THD(thd, ER_VIEW_FRM_NO_USER), - table->db, table->table_name); + table->db.str, table->table_name.str); get_default_definer(thd, &table->definer, false); } @@ -1304,10 +1304,8 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table, Save VIEW parameters, which will be wiped out by derived table processing */ - table->view_db.str= table->db; - table->view_db.length= table->db_length; - table->view_name.str= table->table_name; - table->view_name.length= table->table_name_length; + table->view_db= table->db; + table->view_name= table->table_name; /* We don't invalidate a prepared statement when a view changes, or when someone creates a temporary table. @@ -1708,7 +1706,7 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table, push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_VIEW_ORDERBY_IGNORED, ER_THD(thd, ER_VIEW_ORDERBY_IGNORED), - table->db, table->table_name); + table->db.str, table->table_name.str); } } /* @@ -1811,12 +1809,13 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) { bool not_exist; build_table_filename(path, sizeof(path) - 1, - view->db, view->table_name, reg_ext, 0); + view->db.str, view->table_name.str, reg_ext, 0); if ((not_exist= my_access(path, F_OK)) || !dd_frm_is_view(thd, path)) { char name[FN_REFLEN]; - my_snprintf(name, sizeof(name), "%s.%s", view->db, view->table_name); + my_snprintf(name, sizeof(name), "%s.%s", view->db.str, + view->table_name.str); if (thd->lex->if_exists()) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, @@ -1835,8 +1834,8 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) { if (!wrong_object_name) { - wrong_object_db= view->db; - wrong_object_name= view->table_name; + wrong_object_db= view->db.str; + wrong_object_name= view->table_name.str; } } continue; @@ -1850,7 +1849,7 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) For a view, there is a TABLE_SHARE object. Remove it from the table definition cache, in case the view was cached. */ - tdc_remove_table(thd, TDC_RT_REMOVE_ALL, view->db, view->table_name, + tdc_remove_table(thd, TDC_RT_REMOVE_ALL, view->db.str, view->table_name.str, FALSE); query_cache_invalidate3(thd, view, 0); sp_cache_invalidate(); @@ -2053,7 +2052,7 @@ bool insert_view_fields(THD *thd, List<Item> *list, TABLE_LIST *view) } else { - my_error(ER_NON_INSERTABLE_TABLE, MYF(0), view->alias, "INSERT"); + my_error(ER_NON_INSERTABLE_TABLE, MYF(0), view->alias.str, "INSERT"); DBUG_RETURN(TRUE); } } @@ -2155,8 +2154,8 @@ int view_repair(THD *thd, TABLE_LIST *view, HA_CHECK_OPT *check_opt) */ bool mysql_rename_view(THD *thd, - const char *new_db, - const char *new_name, + const LEX_CSTRING *new_db, + const LEX_CSTRING *new_name, TABLE_LIST *view) { LEX_CSTRING pathstr; @@ -2167,7 +2166,7 @@ mysql_rename_view(THD *thd, pathstr.str= (char *) path_buff; pathstr.length= build_table_filename(path_buff, sizeof(path_buff) - 1, - view->db, view->table_name, + view->db.str, view->table_name.str, reg_ext, 0); if ((parser= sql_parse_prepare(&pathstr, thd->mem_root, 1)) && @@ -2194,16 +2193,17 @@ mysql_rename_view(THD *thd, goto err; /* rename view and it's backups */ - if (rename_in_schema_file(thd, view->db, view->table_name, new_db, new_name)) + if (rename_in_schema_file(thd, view->db.str, view->table_name.str, + new_db->str, new_name->str)) goto err; dir.str= dir_buff; dir.length= build_table_filename(dir_buff, sizeof(dir_buff) - 1, - new_db, "", "", 0); + new_db->str, "", "", 0); pathstr.str= path_buff; pathstr.length= build_table_filename(path_buff, sizeof(path_buff) - 1, - new_db, new_name, reg_ext, 0); + new_db->str, new_name->str, reg_ext, 0); file.str= pathstr.str + dir.length; file.length= pathstr.length - dir.length; @@ -2212,7 +2212,8 @@ mysql_rename_view(THD *thd, (uchar*)&view_def, view_parameters)) { /* restore renamed view in case of error */ - rename_in_schema_file(thd, new_db, new_name, view->db, view->table_name); + rename_in_schema_file(thd, new_db->str, new_name->str, view->db.str, + view->table_name.str); goto err; } } else diff --git a/sql/sql_view.h b/sql/sql_view.h index ff94d2de935..08d79b8e4a5 100644 --- a/sql/sql_view.h +++ b/sql/sql_view.h @@ -53,7 +53,7 @@ extern TYPELIB updatable_views_with_limit_typelib; bool check_duplicate_names(THD *thd, List<Item>& item_list, bool gen_unique_view_names); -bool mysql_rename_view(THD *thd, const char *new_db, const char *new_name, +bool mysql_rename_view(THD *thd, const LEX_CSTRING *new_db, const LEX_CSTRING *new_name, TABLE_LIST *view); void make_valid_column_names(THD *thd, List<Item> &item_list); diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 889b16c83d9..bd2e9019241 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -2590,8 +2590,8 @@ create: if (lex->create_info.seq_create_info->check_and_adjust(1)) { my_error(ER_SEQUENCE_INVALID_DATA, MYF(0), - lex->select_lex.table_list.first->db, - lex->select_lex.table_list.first->table_name); + lex->select_lex.table_list.first->db.str, + lex->select_lex.table_list.first->table_name.str); MYSQL_YYABORT; } @@ -3081,7 +3081,7 @@ clear_privileges: lex->columns.empty(); lex->grant= lex->grant_tot_col= 0; lex->all_privileges= 0; - lex->select_lex.db= 0; + lex->select_lex.db= null_clex_str; lex->ssl_type= SSL_TYPE_NOT_SPECIFIED; lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0; bzero((char *)&(lex->mqh),sizeof(lex->mqh)); @@ -5440,7 +5440,8 @@ opt_part_values: MYSQL_YYABORT; if (part_info->part_type == VERSIONING_PARTITION) my_yyabort_error((ER_VERS_WRONG_PARTS, MYF(0), - lex->create_last_non_select_table->table_name)); + lex->create_last_non_select_table-> + table_name.str)); } else part_info->part_type= HASH_PARTITION; @@ -5486,10 +5487,11 @@ opt_part_values: else { DBUG_ASSERT(Lex->create_last_non_select_table); - DBUG_ASSERT(Lex->create_last_non_select_table->table_name); + DBUG_ASSERT(Lex->create_last_non_select_table->table_name.str); // FIXME: other ALTER commands? my_yyabort_error((ER_VERS_WRONG_PARTS, MYF(0), - Lex->create_last_non_select_table->table_name)); + Lex->create_last_non_select_table-> + table_name.str)); } elem->type(partition_element::CURRENT); DBUG_ASSERT(part_info->vers_info); @@ -5518,8 +5520,10 @@ opt_part_values: if (part_info->vers_info->now_part) { DBUG_ASSERT(Lex->create_last_non_select_table); - DBUG_ASSERT(Lex->create_last_non_select_table->table_name); - my_yyabort_error((ER_VERS_WRONG_PARTS, MYF(0), Lex->create_last_non_select_table->table_name)); + DBUG_ASSERT(Lex->create_last_non_select_table->table_name.str); + my_yyabort_error((ER_VERS_WRONG_PARTS, MYF(0), + Lex->create_last_non_select_table-> + table_name.str)); } elem->type(partition_element::HISTORY); if (part_info->init_column_part(thd)) @@ -5840,7 +5844,8 @@ opt_versioning_interval: part_info->vers_set_interval(interval)) { my_error(ER_PART_WRONG_VALUE, MYF(0), - Lex->create_last_non_select_table->table_name, "INTERVAL"); + Lex->create_last_non_select_table->table_name.str, + "INTERVAL"); MYSQL_YYABORT; } } @@ -5855,7 +5860,8 @@ opt_versioning_limit: if (part_info->vers_set_limit($2)) { my_error(ER_PART_WRONG_VALUE, MYF(0), - Lex->create_last_non_select_table->table_name, "LIMIT"); + Lex->create_last_non_select_table->table_name.str, + "LIMIT"); MYSQL_YYABORT; } } @@ -7638,8 +7644,7 @@ alter: LEX *lex=Lex; lex->sql_command=SQLCOM_ALTER_DB; lex->name= $3; - if (lex->name.str == NULL && - lex->copy_db_to(&lex->name.str, &lex->name.length)) + if (lex->name.str == NULL && lex->copy_db_to(&lex->name)) MYSQL_YYABORT; } | ALTER DATABASE ident UPGRADE_SYM DATA_SYM DIRECTORY_SYM NAME_SYM @@ -7942,10 +7947,9 @@ alter_commands: WITH TABLE_SYM table_ident have_partitioning { LEX *lex= thd->lex; - size_t dummy; - lex->select_lex.db=$6->db.str; - if (lex->select_lex.db == NULL && - lex->copy_db_to(&lex->select_lex.db, &dummy)) + lex->select_lex.db= $6->db; + if (lex->select_lex.db.str == NULL && + lex->copy_db_to(&lex->select_lex.db)) { MYSQL_YYABORT; } @@ -8199,10 +8203,9 @@ alter_list_item: | RENAME opt_to table_ident { LEX *lex=Lex; - size_t dummy; - lex->select_lex.db=$3->db.str; - if (lex->select_lex.db == NULL && - lex->copy_db_to(&lex->select_lex.db, &dummy)) + lex->select_lex.db= $3->db; + if (lex->select_lex.db.str == NULL && + lex->copy_db_to(&lex->select_lex.db)) { MYSQL_YYABORT; } @@ -12965,7 +12968,7 @@ drop: sp_name *spname; if (lex->sphead) my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "FUNCTION")); - if (thd->db && lex->copy_db_to(&db.str, &db.length)) + if (thd->db.str && lex->copy_db_to(&db)) MYSQL_YYABORT; lex->set_command(SQLCOM_DROP_FUNCTION, $3); spname= new (thd->mem_root) sp_name(&db, &$4, false); @@ -13344,7 +13347,7 @@ update: { /* it is single table update and it is update of derived table */ my_error(ER_NON_UPDATABLE_TABLE, MYF(0), - lex->select_lex.get_table_list()->alias, "UPDATE"); + lex->select_lex.get_table_list()->alias.str, "UPDATE"); MYSQL_YYABORT; } /* @@ -13640,7 +13643,7 @@ show_param: { LEX *lex= Lex; lex->sql_command= SQLCOM_SHOW_TABLES; - lex->select_lex.db= $3.str; + lex->select_lex.db= $3; if (prepare_schema_table(thd, lex, 0, SCH_TABLE_NAMES)) MYSQL_YYABORT; } @@ -13648,7 +13651,7 @@ show_param: { LEX *lex= Lex; lex->sql_command= SQLCOM_SHOW_TRIGGERS; - lex->select_lex.db= $3.str; + lex->select_lex.db= $3; if (prepare_schema_table(thd, lex, 0, SCH_TRIGGERS)) MYSQL_YYABORT; } @@ -13656,7 +13659,7 @@ show_param: { LEX *lex= Lex; lex->sql_command= SQLCOM_SHOW_EVENTS; - lex->select_lex.db= $2.str; + lex->select_lex.db= $2; if (prepare_schema_table(thd, lex, 0, SCH_EVENTS)) MYSQL_YYABORT; } @@ -13664,7 +13667,7 @@ show_param: { LEX *lex= Lex; lex->sql_command= SQLCOM_SHOW_TABLE_STATUS; - lex->select_lex.db= $3.str; + lex->select_lex.db= $3; if (prepare_schema_table(thd, lex, 0, SCH_TABLES)) MYSQL_YYABORT; } @@ -13672,7 +13675,7 @@ show_param: { LEX *lex= Lex; lex->sql_command= SQLCOM_SHOW_OPEN_TABLES; - lex->select_lex.db= $3.str; + lex->select_lex.db= $3; if (prepare_schema_table(thd, lex, 0, SCH_OPEN_TABLES)) MYSQL_YYABORT; } @@ -13958,7 +13961,7 @@ show_param: LEX *lex= Lex; bool in_plugin; lex->sql_command= SQLCOM_SHOW_GENERIC; - ST_SCHEMA_TABLE *table= find_schema_table(thd, $1.str, &in_plugin); + ST_SCHEMA_TABLE *table= find_schema_table(thd, &$1, &in_plugin); if (!table || !table->old_format || !in_plugin) { thd->parse_error(ER_SYNTAX_ERROR, $2); @@ -14045,7 +14048,7 @@ describe: mysql_init_select(lex); lex->current_select->parsing_place= SELECT_LIST; lex->sql_command= SQLCOM_SHOW_FIELDS; - lex->select_lex.db= 0; + lex->select_lex.db= null_clex_str; lex->verbose= 0; if (prepare_schema_table(thd, lex, $2, SCH_COLUMNS)) MYSQL_YYABORT; @@ -14098,7 +14101,8 @@ opt_format_json: else if (!my_strcasecmp(system_charset_info, $3.str, "TRADITIONAL")) DBUG_ASSERT(Lex->explain_json==false); else - my_yyabort_error((ER_UNKNOWN_EXPLAIN_FORMAT, MYF(0), $3.str)); + my_yyabort_error((ER_UNKNOWN_EXPLAIN_FORMAT, MYF(0), "JSON", + $3.str)); } ; @@ -14231,14 +14235,14 @@ flush_option: | IDENT_sys remember_tok_start { Lex->type|= REFRESH_GENERIC; - ST_SCHEMA_TABLE *table= find_schema_table(thd, $1.str); + ST_SCHEMA_TABLE *table= find_schema_table(thd, &$1); if (!table || !table->reset_table) { thd->parse_error(ER_SYNTAX_ERROR, $2); MYSQL_YYABORT; } - Lex->view_list.push_back((LEX_STRING*) - thd->memdup(&$1, sizeof(LEX_STRING)), + Lex->view_list.push_back((LEX_CSTRING*) + thd->memdup(&$1, sizeof(LEX_CSTRING)), thd->mem_root); } ; @@ -14397,7 +14401,7 @@ use: { LEX *lex=Lex; lex->sql_command=SQLCOM_CHANGE_DB; - lex->select_lex.db= $2.str; + lex->select_lex.db= $2; } ; @@ -15007,17 +15011,17 @@ field_ident: | ident '.' ident '.' ident { TABLE_LIST *table= Select->table_list.first; - if (my_strcasecmp(table_alias_charset, $1.str, table->db)) + if (my_strcasecmp(table_alias_charset, $1.str, table->db.str)) my_yyabort_error((ER_WRONG_DB_NAME, MYF(0), $1.str)); if (my_strcasecmp(table_alias_charset, $3.str, - table->table_name)) + table->table_name.str)) my_yyabort_error((ER_WRONG_TABLE_NAME, MYF(0), $3.str)); $$=$5; } | ident '.' ident { TABLE_LIST *table= Select->table_list.first; - if (my_strcasecmp(table_alias_charset, $1.str, table->alias)) + if (my_strcasecmp(table_alias_charset, $1.str, table->alias.str)) my_yyabort_error((ER_WRONG_TABLE_NAME, MYF(0), $1.str)); $$=$3; } @@ -16585,8 +16589,7 @@ grant_ident: '*' { LEX *lex= Lex; - size_t dummy; - if (lex->copy_db_to(&lex->current_select->db, &dummy)) + if (lex->copy_db_to(&lex->current_select->db)) MYSQL_YYABORT; if (lex->grant == GLOBAL_ACLS) lex->grant = DB_ACLS & ~GRANT_ACL; @@ -16596,7 +16599,7 @@ grant_ident: | ident '.' '*' { LEX *lex= Lex; - lex->current_select->db = $1.str; + lex->current_select->db= $1; if (lex->grant == GLOBAL_ACLS) lex->grant = DB_ACLS & ~GRANT_ACL; else if (lex->columns.elements) @@ -16605,7 +16608,7 @@ grant_ident: | '*' '.' '*' { LEX *lex= Lex; - lex->current_select->db = NULL; + lex->current_select->db= null_clex_str; if (lex->grant == GLOBAL_ACLS) lex->grant= GLOBAL_ACLS & ~GRANT_ACL; else if (lex->columns.elements) @@ -17223,14 +17226,14 @@ view_list_opt: view_list: ident { - Lex->view_list.push_back((LEX_STRING*) - thd->memdup(&$1, sizeof(LEX_STRING)), + Lex->view_list.push_back((LEX_CSTRING*) + thd->memdup(&$1, sizeof(LEX_CSTRING)), thd->mem_root); } | view_list ',' ident { - Lex->view_list.push_back((LEX_STRING*) - thd->memdup(&$3, sizeof(LEX_STRING)), + Lex->view_list.push_back((LEX_CSTRING*) + thd->memdup(&$3, sizeof(LEX_CSTRING)), thd->mem_root); } ; @@ -17509,7 +17512,8 @@ opt_format_xid: $$= false; else { - my_yyabort_error((ER_UNKNOWN_EXPLAIN_FORMAT, MYF(0), "XA RECOVER", $3.str)); + my_yyabort_error((ER_UNKNOWN_EXPLAIN_FORMAT, MYF(0), + "XA RECOVER", $3.str)); $$= false; } } diff --git a/sql/sql_yacc_ora.yy b/sql/sql_yacc_ora.yy index da1faf14553..a9593937464 100644 --- a/sql/sql_yacc_ora.yy +++ b/sql/sql_yacc_ora.yy @@ -1979,8 +1979,8 @@ create: if (lex->create_info.seq_create_info->check_and_adjust(1)) { my_error(ER_SEQUENCE_INVALID_DATA, MYF(0), - lex->select_lex.table_list.first->db, - lex->select_lex.table_list.first->table_name); + lex->select_lex.table_list.first->db.str, + lex->select_lex.table_list.first->table_name.str); MYSQL_YYABORT; } @@ -2438,7 +2438,7 @@ clear_privileges: lex->columns.empty(); lex->grant= lex->grant_tot_col= 0; lex->all_privileges= 0; - lex->select_lex.db= 0; + lex->select_lex.db= null_clex_str; lex->ssl_type= SSL_TYPE_NOT_SPECIFIED; lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0; bzero((char *)&(lex->mqh),sizeof(lex->mqh)); @@ -7191,8 +7191,7 @@ alter: LEX *lex=Lex; lex->sql_command=SQLCOM_ALTER_DB; lex->name= $3; - if (lex->name.str == NULL && - lex->copy_db_to(&lex->name.str, &lex->name.length)) + if (lex->name.str == NULL && lex->copy_db_to(&lex->name)) MYSQL_YYABORT; } | ALTER DATABASE ident UPGRADE_SYM DATA_SYM DIRECTORY_SYM NAME_SYM @@ -7495,10 +7494,9 @@ alter_commands: WITH TABLE_SYM table_ident have_partitioning { LEX *lex= thd->lex; - size_t dummy; - lex->select_lex.db=$6->db.str; - if (lex->select_lex.db == NULL && - lex->copy_db_to(&lex->select_lex.db, &dummy)) + lex->select_lex.db= $6->db; + if (lex->select_lex.db.str == NULL && + lex->copy_db_to(&lex->select_lex.db)) { MYSQL_YYABORT; } @@ -7748,10 +7746,9 @@ alter_list_item: | RENAME opt_to table_ident { LEX *lex=Lex; - size_t dummy; - lex->select_lex.db=$3->db.str; - if (lex->select_lex.db == NULL && - lex->copy_db_to(&lex->select_lex.db, &dummy)) + lex->select_lex.db= $3->db; + if (lex->select_lex.db.str == NULL && + lex->copy_db_to(&lex->select_lex.db)) { MYSQL_YYABORT; } @@ -12450,7 +12447,7 @@ drop: sp_name *spname; if (lex->sphead) my_yyabort_error((ER_SP_NO_DROP_SP, MYF(0), "FUNCTION")); - if (thd->db && lex->copy_db_to(&db.str, &db.length)) + if (thd->db.str && lex->copy_db_to(&db)) MYSQL_YYABORT; lex->set_command(SQLCOM_DROP_FUNCTION, $3); spname= new (thd->mem_root) sp_name(&db, &$4, false); @@ -12829,7 +12826,7 @@ update: { /* it is single table update and it is update of derived table */ my_error(ER_NON_UPDATABLE_TABLE, MYF(0), - lex->select_lex.get_table_list()->alias, "UPDATE"); + lex->select_lex.get_table_list()->alias.str, "UPDATE"); MYSQL_YYABORT; } /* @@ -13108,7 +13105,7 @@ show_param: { LEX *lex= Lex; lex->sql_command= SQLCOM_SHOW_TABLES; - lex->select_lex.db= $3.str; + lex->select_lex.db= $3; if (prepare_schema_table(thd, lex, 0, SCH_TABLE_NAMES)) MYSQL_YYABORT; } @@ -13116,7 +13113,7 @@ show_param: { LEX *lex= Lex; lex->sql_command= SQLCOM_SHOW_TRIGGERS; - lex->select_lex.db= $3.str; + lex->select_lex.db= $3; if (prepare_schema_table(thd, lex, 0, SCH_TRIGGERS)) MYSQL_YYABORT; } @@ -13124,7 +13121,7 @@ show_param: { LEX *lex= Lex; lex->sql_command= SQLCOM_SHOW_EVENTS; - lex->select_lex.db= $2.str; + lex->select_lex.db= $2; if (prepare_schema_table(thd, lex, 0, SCH_EVENTS)) MYSQL_YYABORT; } @@ -13132,7 +13129,7 @@ show_param: { LEX *lex= Lex; lex->sql_command= SQLCOM_SHOW_TABLE_STATUS; - lex->select_lex.db= $3.str; + lex->select_lex.db= $3; if (prepare_schema_table(thd, lex, 0, SCH_TABLES)) MYSQL_YYABORT; } @@ -13140,7 +13137,7 @@ show_param: { LEX *lex= Lex; lex->sql_command= SQLCOM_SHOW_OPEN_TABLES; - lex->select_lex.db= $3.str; + lex->select_lex.db= $3; if (prepare_schema_table(thd, lex, 0, SCH_OPEN_TABLES)) MYSQL_YYABORT; } @@ -13418,7 +13415,7 @@ show_param: LEX *lex= Lex; bool in_plugin; lex->sql_command= SQLCOM_SHOW_GENERIC; - ST_SCHEMA_TABLE *table= find_schema_table(thd, $1.str, &in_plugin); + ST_SCHEMA_TABLE *table= find_schema_table(thd, &$1, &in_plugin); if (!table || !table->old_format || !in_plugin) { thd->parse_error(ER_SYNTAX_ERROR, $2); @@ -13505,7 +13502,7 @@ describe: mysql_init_select(lex); lex->current_select->parsing_place= SELECT_LIST; lex->sql_command= SQLCOM_SHOW_FIELDS; - lex->select_lex.db= 0; + lex->select_lex.db= null_clex_str; lex->verbose= 0; if (prepare_schema_table(thd, lex, $2, SCH_COLUMNS)) MYSQL_YYABORT; @@ -13558,7 +13555,8 @@ opt_format_json: else if (!my_strcasecmp(system_charset_info, $3.str, "TRADITIONAL")) DBUG_ASSERT(Lex->explain_json==false); else - my_yyabort_error((ER_UNKNOWN_EXPLAIN_FORMAT, MYF(0), $3.str)); + my_yyabort_error((ER_UNKNOWN_EXPLAIN_FORMAT, MYF(0), "JSON", + $3.str)); } ; @@ -13691,14 +13689,14 @@ flush_option: | IDENT_sys remember_tok_start { Lex->type|= REFRESH_GENERIC; - ST_SCHEMA_TABLE *table= find_schema_table(thd, $1.str); + ST_SCHEMA_TABLE *table= find_schema_table(thd, &$1); if (!table || !table->reset_table) { thd->parse_error(ER_SYNTAX_ERROR, $2); MYSQL_YYABORT; } - Lex->view_list.push_back((LEX_STRING*) - thd->memdup(&$1, sizeof(LEX_STRING)), + Lex->view_list.push_back((LEX_CSTRING*) + thd->memdup(&$1, sizeof(LEX_CSTRING)), thd->mem_root); } ; @@ -13839,7 +13837,7 @@ use: { LEX *lex=Lex; lex->sql_command=SQLCOM_CHANGE_DB; - lex->select_lex.db= $2.str; + lex->select_lex.db= $2; } ; @@ -14478,17 +14476,17 @@ field_ident: | ident '.' ident '.' ident { TABLE_LIST *table= Select->table_list.first; - if (my_strcasecmp(table_alias_charset, $1.str, table->db)) + if (my_strcasecmp(table_alias_charset, $1.str, table->db.str)) my_yyabort_error((ER_WRONG_DB_NAME, MYF(0), $1.str)); if (my_strcasecmp(table_alias_charset, $3.str, - table->table_name)) + table->table_name.str)) my_yyabort_error((ER_WRONG_TABLE_NAME, MYF(0), $3.str)); $$=$5; } | ident '.' ident { TABLE_LIST *table= Select->table_list.first; - if (my_strcasecmp(table_alias_charset, $1.str, table->alias)) + if (my_strcasecmp(table_alias_charset, $1.str, table->alias.str)) my_yyabort_error((ER_WRONG_TABLE_NAME, MYF(0), $1.str)); $$=$3; } @@ -16166,8 +16164,7 @@ grant_ident: '*' { LEX *lex= Lex; - size_t dummy; - if (lex->copy_db_to(&lex->current_select->db, &dummy)) + if (lex->copy_db_to(&lex->current_select->db)) MYSQL_YYABORT; if (lex->grant == GLOBAL_ACLS) lex->grant = DB_ACLS & ~GRANT_ACL; @@ -16177,7 +16174,7 @@ grant_ident: | ident '.' '*' { LEX *lex= Lex; - lex->current_select->db = $1.str; + lex->current_select->db= $1; if (lex->grant == GLOBAL_ACLS) lex->grant = DB_ACLS & ~GRANT_ACL; else if (lex->columns.elements) @@ -16186,7 +16183,7 @@ grant_ident: | '*' '.' '*' { LEX *lex= Lex; - lex->current_select->db = NULL; + lex->current_select->db= null_clex_str; if (lex->grant == GLOBAL_ACLS) lex->grant= GLOBAL_ACLS & ~GRANT_ACL; else if (lex->columns.elements) @@ -16770,14 +16767,14 @@ view_list_opt: view_list: ident { - Lex->view_list.push_back((LEX_STRING*) - thd->memdup(&$1, sizeof(LEX_STRING)), + Lex->view_list.push_back((LEX_CSTRING*) + thd->memdup(&$1, sizeof(LEX_CSTRING)), thd->mem_root); } | view_list ',' ident { - Lex->view_list.push_back((LEX_STRING*) - thd->memdup(&$3, sizeof(LEX_STRING)), + Lex->view_list.push_back((LEX_CSTRING*) + thd->memdup(&$3, sizeof(LEX_CSTRING)), thd->mem_root); } ; diff --git a/sql/structs.h b/sql/structs.h index 793be462b26..4a66ac63d23 100644 --- a/sql/structs.h +++ b/sql/structs.h @@ -39,7 +39,7 @@ typedef struct st_date_time_format { uchar positions[8]; char time_separator; /* Separator between hour and minute */ uint flag; /* For future */ - LEX_STRING format; + LEX_CSTRING format; } DATE_TIME_FORMAT; diff --git a/sql/table.cc b/sql/table.cc index 10d1d737222..6b29ea73d17 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -69,6 +69,9 @@ LEX_CSTRING GENERAL_LOG_NAME= {STRING_WITH_LEN("general_log")}; LEX_CSTRING SLOW_LOG_NAME= {STRING_WITH_LEN("slow_log")}; LEX_CSTRING TRANSACTION_REG_NAME= {STRING_WITH_LEN("transaction_registry")}; +LEX_CSTRING MYSQL_USER_NAME= {STRING_WITH_LEN("user")}; +LEX_CSTRING MYSQL_DB_NAME= {STRING_WITH_LEN("db")}; +LEX_CSTRING MYSQL_PROC_NAME= {STRING_WITH_LEN("proc")}; /* Keyword added as a prefix when parsing the defining expression for a @@ -163,8 +166,8 @@ View_creation_ctx * View_creation_ctx::create(THD *thd, push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_VIEW_NO_CREATION_CTX, ER_THD(thd, ER_VIEW_NO_CREATION_CTX), - (const char *) view->db, - (const char *) view->table_name); + view->db.str, + view->table_name.str); ctx->m_client_cs= system_charset_info; ctx->m_connection_cl= system_charset_info; @@ -189,16 +192,16 @@ View_creation_ctx * View_creation_ctx::create(THD *thd, { sql_print_warning("View '%s'.'%s': there is unknown charset/collation " "names (client: '%s'; connection: '%s').", - (const char *) view->db, - (const char *) view->table_name, + view->db.str, + view->table_name.str, (const char *) view->view_client_cs_name.str, (const char *) view->view_connection_cl_name.str); push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_VIEW_INVALID_CREATION_CTX, ER_THD(thd, ER_VIEW_INVALID_CREATION_CTX), - (const char *) view->db, - (const char *) view->table_name); + view->db.str, + view->table_name.str); } return ctx; @@ -246,7 +249,7 @@ TABLE_CATEGORY get_table_category(const LEX_CSTRING *db, DBUG_ASSERT(db != NULL); DBUG_ASSERT(name != NULL); - if (is_infoschema_db(db->str, db->length)) + if (is_infoschema_db(db)) return TABLE_CATEGORY_INFORMATION; if (lex_string_eq(&PERFORMANCE_SCHEMA_DB_NAME, db) == 0) @@ -2741,7 +2744,7 @@ int TABLE_SHARE::init_from_sql_statement_string(THD *thd, bool write, uint unused2; handlerton *hton= plugin_hton(db_plugin); LEX_CUSTRING frm= {0,0}; - LEX_STRING db_backup= { thd->db, thd->db_length }; + LEX_CSTRING db_backup= thd->db; DBUG_ENTER("TABLE_SHARE::init_from_sql_statement_string"); /* @@ -2768,7 +2771,7 @@ int TABLE_SHARE::init_from_sql_statement_string(THD *thd, bool write, else thd->set_n_backup_active_arena(arena, &backup); - thd->reset_db((char*) db.str, db.length); + thd->reset_db(&db); lex_start(thd); if ((error= parse_sql(thd, & parser_state, NULL) || @@ -2781,7 +2784,7 @@ int TABLE_SHARE::init_from_sql_statement_string(THD *thd, bool write, thd->lex->create_info.tabledef_version= tabledef_version; promote_first_timestamp_column(&thd->lex->alter_info.create_list); - file= mysql_create_frm_image(thd, db.str, table_name.str, + file= mysql_create_frm_image(thd, &db, &table_name, &thd->lex->create_info, &thd->lex->alter_info, C_ORDINARY_CREATE, &unused1, &unused2, &frm); error|= file == 0; @@ -2797,7 +2800,7 @@ int TABLE_SHARE::init_from_sql_statement_string(THD *thd, bool write, ret: my_free(const_cast<uchar*>(frm.str)); lex_end(thd->lex); - thd->reset_db(db_backup.str, db_backup.length); + thd->reset_db(&db_backup); thd->lex= old_lex; if (arena) thd->restore_active_arena(arena, &backup); @@ -3116,7 +3119,7 @@ static bool check_vcol_forward_refs(Field *field, Virtual_column_info *vcol) */ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share, - const char *alias, uint db_stat, uint prgflag, + const LEX_CSTRING *alias, uint db_stat, uint prgflag, uint ha_open_flags, TABLE *outparam, bool is_create_table, List<String> *partitions_to_open) { @@ -3148,7 +3151,7 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share, } init_sql_alloc(&outparam->mem_root, TABLE_ALLOC_BLOCK_SIZE, 0, MYF(0)); - if (outparam->alias.copy(alias, strlen(alias), table_alias_charset)) + if (outparam->alias.copy(alias->str, alias->length, table_alias_charset)) goto err; outparam->quick_keys.init(); outparam->covering_keys.init(); @@ -4607,10 +4610,10 @@ void TABLE::init(THD *thd, TABLE_LIST *tl) if (thd->lex->need_correct_ident()) alias_name_used= my_strcasecmp(table_alias_charset, s->table_name.str, - tl->alias); + tl->alias.str); /* Fix alias if table name changes. */ - if (strcmp(alias.c_ptr(), tl->alias)) - alias.copy(tl->alias, strlen(tl->alias), alias.charset()); + if (strcmp(alias.c_ptr(), tl->alias.str)) + alias.copy(tl->alias.str, tl->alias.length, alias.charset()); tablenr= thd->current_tablenr++; used_fields= 0; @@ -4762,7 +4765,7 @@ bool TABLE_LIST::create_field_translation(THD *thd) bool res= FALSE; DBUG_ENTER("TABLE_LIST::create_field_translation"); DBUG_PRINT("enter", ("Alias: '%s' Unit: %p", - (alias ? alias : "<NULL>"), + (alias.str ? alias.str : "<NULL>"), get_unit())); if (thd->stmt_arena->is_conventional() || @@ -5011,7 +5014,7 @@ merge_on_conds(THD *thd, TABLE_LIST *table, bool is_cascaded) DBUG_ENTER("merge_on_conds"); Item *cond= NULL; - DBUG_PRINT("info", ("alias: %s", table->alias)); + DBUG_PRINT("info", ("alias: %s", table->alias.str)); if (table->on_expr) cond= table->on_expr->copy_andor_structure(thd); if (!table->view) @@ -5239,9 +5242,9 @@ int TABLE_LIST::view_check_option(THD *thd, bool ignore_failure) { TABLE_LIST *main_view= top_table(); const char *name_db= (main_view->view ? main_view->view_db.str : - main_view->db); + main_view->db.str); const char *name_table= (main_view->view ? main_view->view_name.str : - main_view->table_name); + main_view->table_name.str); my_error(ER_VIEW_CHECK_FAILED, MYF(ignore_failure ? ME_JUST_WARNING : 0), name_db, name_table); return ignore_failure ? VIEW_CHECK_SKIP : VIEW_CHECK_ERROR; @@ -5541,7 +5544,7 @@ void TABLE_LIST::register_want_access(ulong want_access) bool TABLE_LIST::prepare_view_security_context(THD *thd) { DBUG_ENTER("TABLE_LIST::prepare_view_security_context"); - DBUG_PRINT("enter", ("table: %s", alias)); + DBUG_PRINT("enter", ("table: %s", alias.str)); DBUG_ASSERT(!prelocking_placeholder && view); if (view_suid) @@ -5549,7 +5552,7 @@ bool TABLE_LIST::prepare_view_security_context(THD *thd) DBUG_PRINT("info", ("This table is suid view => load contest")); DBUG_ASSERT(view && view_sctx); if (acl_getroot(view_sctx, definer.user.str, definer.host.str, - definer.host.str, thd->db)) + definer.host.str, thd->db.str)) { if ((thd->lex->sql_command == SQLCOM_SHOW_CREATE) || (thd->lex->sql_command == SQLCOM_SHOW_FIELDS)) @@ -5614,7 +5617,7 @@ Security_context *TABLE_LIST::find_view_security_context(THD *thd) if (upper_view) { DBUG_PRINT("info", ("Securety context of view %s will be used", - upper_view->alias)); + upper_view->alias.str)); sctx= upper_view->view_sctx; DBUG_ASSERT(sctx); } @@ -5663,8 +5666,8 @@ bool TABLE_LIST::prepare_security(THD *thd) } else { - local_db= tbl->db; - local_table_name= tbl->table_name; + local_db= tbl->db.str; + local_table_name= tbl->table_name.str; } fill_effective_table_privileges(thd, &tbl->grant, local_db, local_table_name); @@ -5815,30 +5818,29 @@ Field *Natural_join_column::field() } -const char *Natural_join_column::table_name() +const char *Natural_join_column::safe_table_name() { DBUG_ASSERT(table_ref); - return table_ref->alias; + return table_ref->alias.str ? table_ref->alias.str : ""; } -const char *Natural_join_column::db_name() +const char *Natural_join_column::safe_db_name() { if (view_field) - return table_ref->view_db.str; + return table_ref->view_db.str ? table_ref->view_db.str : ""; /* Test that TABLE_LIST::db is the same as TABLE_SHARE::db to ensure consistency. An exception are I_S schema tables, which are inconsistent in this respect. */ - DBUG_ASSERT(!strcmp(table_ref->db, - table_ref->table->s->db.str) || + DBUG_ASSERT(!cmp(&table_ref->db, + &table_ref->table->s->db) || (table_ref->schema_table && - is_infoschema_db(table_ref->table->s->db.str, - table_ref->table->s->db.length)) || - table_ref->is_materialized_derived()); - return table_ref->db; + is_infoschema_db(&table_ref->table->s->db)) || + table_ref->is_materialized_derived()); + return table_ref->db.str ? table_ref->db.str : ""; } @@ -5939,7 +5941,7 @@ Item *create_view_field(THD *thd, TABLE_LIST *view, Item **field_ref, Name_resolution_context *context= view->view ? &view->view->select_lex.context : &thd->lex->select_lex.context; Item *item= (new (thd->mem_root) - Item_direct_view_ref(thd, context, field_ref, view->alias, + Item_direct_view_ref(thd, context, field_ref, view->alias.str, name, view)); /* Force creation of nullable item for the result tmp table for outer joined @@ -6003,7 +6005,7 @@ void Field_iterator_table_ref::set_field_iterator() table_ref->table->s->fields)))); field_it= &natural_join_it; DBUG_PRINT("info",("field_it for '%s' is Field_iterator_natural_join", - table_ref->alias)); + table_ref->alias.str)); } /* This is a merge view, so use field_translation. */ else if (table_ref->field_translation) @@ -6011,7 +6013,7 @@ void Field_iterator_table_ref::set_field_iterator() DBUG_ASSERT(table_ref->is_merged_derived()); field_it= &view_field_it; DBUG_PRINT("info", ("field_it for '%s' is Field_iterator_view", - table_ref->alias)); + table_ref->alias.str)); } /* This is a base table or stored view. */ else @@ -6019,7 +6021,7 @@ void Field_iterator_table_ref::set_field_iterator() DBUG_ASSERT(table_ref->table || table_ref->view); field_it= &table_field_it; DBUG_PRINT("info", ("field_it for '%s' is Field_iterator_table", - table_ref->alias)); + table_ref->alias.str)); } field_it->set(table_ref); DBUG_VOID_RETURN; @@ -6061,11 +6063,11 @@ const char *Field_iterator_table_ref::get_table_name() if (table_ref->is_derived()) return table_ref->table->s->table_name.str; else if (table_ref->is_natural_join) - return natural_join_it.column_ref()->table_name(); + return natural_join_it.column_ref()->safe_table_name(); - DBUG_ASSERT(!strcmp(table_ref->table_name, + DBUG_ASSERT(!strcmp(table_ref->table_name.str, table_ref->table->s->table_name.str)); - return table_ref->table_name; + return table_ref->table_name.str; } @@ -6074,19 +6076,18 @@ const char *Field_iterator_table_ref::get_db_name() if (table_ref->view) return table_ref->view_db.str; else if (table_ref->is_natural_join) - return natural_join_it.column_ref()->db_name(); + return natural_join_it.column_ref()->safe_db_name(); /* Test that TABLE_LIST::db is the same as TABLE_SHARE::db to ensure consistency. An exception are I_S schema tables, which are inconsistent in this respect. */ - DBUG_ASSERT(!strcmp(table_ref->db, table_ref->table->s->db.str) || + DBUG_ASSERT(!cmp(&table_ref->db, &table_ref->table->s->db) || (table_ref->schema_table && - is_infoschema_db(table_ref->table->s->db.str, - table_ref->table->s->db.length))); + is_infoschema_db(&table_ref->table->s->db))); - return table_ref->db; + return table_ref->db.str; } @@ -7409,7 +7410,7 @@ bool TABLE_LIST::process_index_hints(TABLE *tbl) (pos= find_type(&tbl->s->keynames, hint->key_name.str, hint->key_name.length, 1)) <= 0) { - my_error(ER_KEY_DOES_NOT_EXITS, MYF(0), hint->key_name.str, alias); + my_error(ER_KEY_DOES_NOT_EXITS, MYF(0), hint->key_name.str, alias.str); return 1; } @@ -7509,7 +7510,7 @@ void init_mdl_requests(TABLE_LIST *table_list) { for ( ; table_list ; table_list= table_list->next_global) table_list->mdl_request.init(MDL_key::TABLE, - table_list->db, table_list->table_name, + table_list->db.str, table_list->table_name.str, table_list->lock_type >= TL_WRITE_ALLOW_WRITE ? MDL_SHARED_WRITE : MDL_SHARED_READ, MDL_TRANSACTION); @@ -7817,12 +7818,13 @@ bool TABLE_LIST::vers_vtmd_name(String& out) const { static const char *vtmd_suffix= "_vtmd"; static const size_t vtmd_suffix_len= strlen(vtmd_suffix); - if (table_name_length > NAME_CHAR_LEN - vtmd_suffix_len) + if (table_name.length > NAME_CHAR_LEN - vtmd_suffix_len) { - my_printf_error(ER_VERS_VTMD_ERROR, "Table name is longer than %d characters", MYF(0), int(NAME_CHAR_LEN - vtmd_suffix_len)); + my_printf_error(ER_VERS_VTMD_ERROR, "Table name is longer than %d characters", MYF(0), + int(NAME_CHAR_LEN - vtmd_suffix_len)); return true; } - out.set(table_name, table_name_length, table_alias_charset); + out.set(table_name.str, table_name.length, table_alias_charset); if (out.append(vtmd_suffix, vtmd_suffix_len + 1)) { my_message(ER_VERS_VTMD_ERROR, "Failed allocate VTMD name", MYF(0)); @@ -8597,9 +8599,8 @@ enum TR_table::enabled TR_table::use_transaction_registry= TR_table::MAYBE; TR_table::TR_table(THD* _thd, bool rw) : thd(_thd), open_tables_backup(NULL) { - init_one_table(LEX_STRING_WITH_LEN(MYSQL_SCHEMA_NAME), - LEX_STRING_WITH_LEN(TRANSACTION_REG_NAME), - TRANSACTION_REG_NAME.str, rw ? TL_WRITE : TL_READ); + init_one_table(&MYSQL_SCHEMA_NAME, &TRANSACTION_REG_NAME, + NULL, rw ? TL_WRITE : TL_READ); } bool TR_table::open() @@ -8807,12 +8808,14 @@ void TR_table::warn_schema_incorrect(const char *reason) { if (MYSQL_VERSION_ID == table->s->mysql_version) { - sql_print_error("%`s.%`s schema is incorrect: %s.", db, table_name, reason); + sql_print_error("%`s.%`s schema is incorrect: %s.", + db.str, table_name.str, reason); } else { sql_print_error("%`s.%`s schema is incorrect: %s. Created with MariaDB %d, " - "now running %d.", db, table_name, reason, MYSQL_VERSION_ID, + "now running %d.", + db.str, table_name.str, reason, MYSQL_VERSION_ID, static_cast<int>(table->s->mysql_version)); } } @@ -8821,7 +8824,8 @@ bool TR_table::check(bool error) { if (error) { - sql_print_warning("%`s.%`s does not exist (open failed).", db, table_name); + sql_print_warning("%`s.%`s does not exist (open failed).", db.str, + table_name.str); return true; } diff --git a/sql/table.h b/sql/table.h index 173bb49bc2b..7e57cb55471 100644 --- a/sql/table.h +++ b/sql/table.h @@ -22,6 +22,7 @@ #include "mdl.h" #include "datadict.h" #include "sql_string.h" /* String */ +#include "lex_string.h" #ifndef MYSQL_CLIENT @@ -1697,7 +1698,7 @@ typedef class Item COND; typedef struct st_schema_table { - const char* table_name; + const char *table_name; ST_FIELD_INFO *fields_info; /* for FLUSH table_name */ int (*reset_table) (); @@ -1819,8 +1820,8 @@ public: LEX_CSTRING *name(); Item *create_item(THD *thd); Field *field(); - const char *table_name(); - const char *db_name(); + const char *safe_table_name(); + const char *safe_db_name(); GRANT_INFO *grant(); }; @@ -1934,49 +1935,44 @@ struct TABLE_LIST Prepare TABLE_LIST that consists of one table instance to use in open_and_lock_tables */ - inline void init_one_table(const char *db_name_arg, - size_t db_length_arg, - const char *table_name_arg, - size_t table_name_length_arg, - const char *alias_arg, - enum thr_lock_type lock_type_arg) +inline void init_one_table(const LEX_CSTRING *db_arg, + const LEX_CSTRING *table_name_arg, + const LEX_CSTRING *alias_arg, + enum thr_lock_type lock_type_arg) { bzero((char*) this, sizeof(*this)); - db= (char*) db_name_arg; - db_length= db_length_arg; - table_name= (char*) table_name_arg; - table_name_length= table_name_length_arg; - alias= (char*) (alias_arg ? alias_arg : table_name_arg); + DBUG_ASSERT(!db_arg->str || strlen(db_arg->str) == db_arg->length); + DBUG_ASSERT(!table_name_arg->str || strlen(table_name_arg->str) == table_name_arg->length); + DBUG_ASSERT(!alias_arg || strlen(alias_arg->str) == alias_arg->length); + db= *db_arg; + table_name= *table_name_arg; + alias= (alias_arg ? *alias_arg : *table_name_arg); lock_type= lock_type_arg; - mdl_request.init(MDL_key::TABLE, db, table_name, + mdl_request.init(MDL_key::TABLE, db.str, table_name.str, (lock_type >= TL_WRITE_ALLOW_WRITE) ? MDL_SHARED_WRITE : MDL_SHARED_READ, MDL_TRANSACTION); } - TABLE_LIST(TABLE &_table, thr_lock_type lock_type) + TABLE_LIST(TABLE *table_arg, thr_lock_type lock_type) { - DBUG_ASSERT(_table.s); - init_one_table( - LEX_STRING_WITH_LEN(_table.s->db), - LEX_STRING_WITH_LEN(_table.s->table_name), - _table.s->table_name.str, lock_type); - table= &_table; + DBUG_ASSERT(table_arg->s); + init_one_table(&table_arg->s->db, &table_arg->s->table_name, + NULL, lock_type); + table= table_arg; } - inline void init_one_table_for_prelocking(const char *db_name_arg, - size_t db_length_arg, - const char *table_name_arg, - size_t table_name_length_arg, - const char *alias_arg, - enum thr_lock_type lock_type_arg, - prelocking_types prelocking_type, - TABLE_LIST *belong_to_view_arg, - uint8 trg_event_map_arg, - TABLE_LIST ***last_ptr) + inline void init_one_table_for_prelocking(const LEX_CSTRING *db_arg, + const LEX_CSTRING *table_name_arg, + const LEX_CSTRING *alias_arg, + enum thr_lock_type lock_type_arg, + prelocking_types prelocking_type, + TABLE_LIST *belong_to_view_arg, + uint8 trg_event_map_arg, + TABLE_LIST ***last_ptr) + { - init_one_table(db_name_arg, db_length_arg, table_name_arg, - table_name_length_arg, alias_arg, lock_type_arg); + init_one_table(db_arg, table_name_arg, alias_arg, lock_type_arg); cacheable_table= 1; prelocking_placeholder= prelocking_type; open_type= (prelocking_type == PRELOCK_ROUTINE ? @@ -1998,7 +1994,10 @@ struct TABLE_LIST TABLE_LIST *next_local; /* link in a global list of all queries tables */ TABLE_LIST *next_global, **prev_global; - const char *db, *alias, *table_name, *schema_table_name; + LEX_CSTRING db; + LEX_CSTRING table_name; + LEX_CSTRING schema_table_name; + LEX_CSTRING alias; const char *option; /* Used by cache index */ Item *on_expr; /* Used with outer join */ @@ -2232,8 +2231,6 @@ struct TABLE_LIST thr_lock_type lock_type; uint outer_join; /* Which join type */ uint shared; /* Used in multi-upd */ - size_t db_length; - size_t table_name_length; bool updatable; /* VIEW/TABLE can be updated now */ bool straight; /* optimize with prev table */ bool updating; /* for replicate-do/ignore table */ @@ -2331,7 +2328,7 @@ struct TABLE_LIST View definition (SELECT-statement) in the UTF-form. */ - LEX_STRING view_body_utf8; + LEX_CSTRING view_body_utf8; /* End of view definition context. */ @@ -2526,7 +2523,7 @@ struct TABLE_LIST { DBUG_ENTER("set_merged_derived"); DBUG_PRINT("enter", ("Alias: '%s' Unit: %p", - (alias ? alias : "<NULL>"), + (alias.str ? alias.str : "<NULL>"), get_unit())); derived_type= ((derived_type & DTYPE_MASK) | DTYPE_TABLE | DTYPE_MERGE); @@ -2541,7 +2538,7 @@ struct TABLE_LIST { DBUG_ENTER("set_materialized_derived"); DBUG_PRINT("enter", ("Alias: '%s' Unit: %p", - (alias ? alias : "<NULL>"), + (alias.str ? alias.str : "<NULL>"), get_unit())); derived_type= ((derived_type & (derived ? DTYPE_MASK : DTYPE_VIEW)) | DTYPE_TABLE | DTYPE_MATERIALIZE); @@ -2570,7 +2567,7 @@ struct TABLE_LIST @brief Returns the name of the database that the referenced table belongs to. */ - const char *get_db_name() const { return view != NULL ? view_db.str : db; } + const char *get_db_name() const { return view != NULL ? view_db.str : db.str; } /** @brief Returns the name of the table that this TABLE_LIST represents. @@ -2578,7 +2575,7 @@ struct TABLE_LIST @details The unqualified table name or view name for a table or view, respectively. */ - const char *get_table_name() const { return view != NULL ? view_name.str : table_name; } + const char *get_table_name() const { return view != NULL ? view_name.str : table_name.str; } bool is_active_sjm(); bool is_jtbm() { return MY_TEST(jtbm_subselect != NULL); } st_select_lex_unit *get_unit(); @@ -2883,7 +2880,7 @@ size_t max_row_length(TABLE *table, const uchar *data); void init_mdl_requests(TABLE_LIST *table_list); enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share, - const char *alias, uint db_stat, uint prgflag, + const LEX_CSTRING *alias, uint db_stat, uint prgflag, uint ha_open_flags, TABLE *outparam, bool is_create_table, List<String> *partitions_to_open= NULL); @@ -2945,20 +2942,16 @@ extern LEX_CSTRING TRANSACTION_REG_NAME; extern LEX_CSTRING INFORMATION_SCHEMA_NAME; extern LEX_CSTRING MYSQL_SCHEMA_NAME; -inline bool is_infoschema_db(const char *name, size_t len) -{ - return (INFORMATION_SCHEMA_NAME.length == len && - !my_strcasecmp(system_charset_info, - INFORMATION_SCHEMA_NAME.str, name)); -} +/* table names */ +extern LEX_CSTRING MYSQL_USER_NAME, MYSQL_DB_NAME, MYSQL_PROC_NAME; -inline bool is_infoschema_db(const char *name) +inline bool is_infoschema_db(const LEX_CSTRING *name) { - return !my_strcasecmp(system_charset_info, - INFORMATION_SCHEMA_NAME.str, name); + return (INFORMATION_SCHEMA_NAME.length == name->length && + !my_strcasecmp(system_charset_info, + INFORMATION_SCHEMA_NAME.str, name->str)); } - inline void mark_as_null_row(TABLE *table) { table->null_row=1; @@ -2976,6 +2969,7 @@ class Open_tables_backup; transaction-related data which is used for transaction order resolution. When versioned table marks its records lifetime with transaction IDs, TRT is used to get their actual timestamps. */ + class TR_table: public TABLE_LIST { THD *thd; @@ -3103,9 +3097,7 @@ public: } bool operator== (const TABLE_LIST &subj) const { - if (0 != strcmp(db, subj.db)) - return false; - return (0 == strcmp(table_name, subj.table_name)); + return (!cmp(&db, &subj.db) && !cmp(&table_name, &subj.table_name)); } bool operator!= (const TABLE_LIST &subj) const { diff --git a/sql/table_cache.cc b/sql/table_cache.cc index f55e24f3b04..ba7047773b9 100644 --- a/sql/table_cache.cc +++ b/sql/table_cache.cc @@ -827,7 +827,7 @@ retry: lf_hash_search_unpin(thd->tdc_hash_pins); DBUG_ASSERT(element); - if (!(share= alloc_table_share(tl->db, tl->table_name, key, key_length))) + if (!(share= alloc_table_share(tl->db.str, tl->table_name.str, key, key_length))) { lf_hash_delete(&tdc_hash, thd->tdc_hash_pins, key, key_length); DBUG_RETURN(0); diff --git a/sql/temporary_tables.cc b/sql/temporary_tables.cc index a5088a012ae..9be9468fd74 100644 --- a/sql/temporary_tables.cc +++ b/sql/temporary_tables.cc @@ -328,7 +328,7 @@ TMP_TABLE_SHARE *THD::find_tmp_table_share(const char *key, uint key_length) bool THD::open_temporary_table(TABLE_LIST *tl) { DBUG_ENTER("THD::open_temporary_table"); - DBUG_PRINT("enter", ("table: '%s'.'%s'", tl->db, tl->table_name)); + DBUG_PRINT("enter", ("table: '%s'.'%s'", tl->db.str, tl->table_name.str)); TMP_TABLE_SHARE *share; TABLE *table= NULL; @@ -391,7 +391,7 @@ bool THD::open_temporary_table(TABLE_LIST *tl) if (tl->open_type == OT_TEMPORARY_ONLY && tl->open_strategy == TABLE_LIST::OPEN_NORMAL) { - my_error(ER_NO_SUCH_TABLE, MYF(0), tl->db, tl->table_name); + my_error(ER_NO_SUCH_TABLE, MYF(0), tl->db.str, tl->table_name.str); DBUG_RETURN(true); } DBUG_RETURN(false); @@ -544,25 +544,21 @@ bool THD::close_temporary_tables() true Error */ bool THD::rename_temporary_table(TABLE *table, - const char *db, - const char *table_name) + const LEX_CSTRING *db, + const LEX_CSTRING *table_name) { - DBUG_ENTER("THD::rename_temporary_table"); - char *key; uint key_length; - TABLE_SHARE *share= table->s; + DBUG_ENTER("THD::rename_temporary_table"); if (!(key= (char *) alloc_root(&share->mem_root, MAX_DBKEY_LENGTH))) - { DBUG_RETURN(true); - } /* Temporary tables are renamed by simply changing their table definition key. */ - key_length= create_tmp_table_def_key(key, db, table_name); + key_length= create_tmp_table_def_key(key, db->str, table_name->str); share->set_table_cache_key(key, key_length); DBUG_RETURN(false); @@ -1102,19 +1098,20 @@ done: Failure NULL */ TABLE *THD::open_temporary_table(TMP_TABLE_SHARE *share, - const char *alias, + const char *alias_arg, bool open_in_engine) { + TABLE *table; + LEX_CSTRING alias= {alias_arg, strlen(alias_arg) }; DBUG_ENTER("THD::open_temporary_table"); - TABLE *table; if (!(table= (TABLE *) my_malloc(sizeof(TABLE), MYF(MY_WME)))) { DBUG_RETURN(NULL); /* Out of memory */ } - if (open_table_from_share(this, share, alias, + if (open_table_from_share(this, share, &alias, open_in_engine ? (uint)HA_OPEN_KEYFILE : 0, EXTRA_RECORD, (ha_open_options | @@ -1379,8 +1376,7 @@ bool THD::log_events_and_free_tmp_shares() We are going to add ` around the table names and possible more due to special characters. */ - append_identifier(this, &s_query, share->table_name.str, - share->table_name.length); + append_identifier(this, &s_query, &share->table_name); s_query.append(','); rm_temporary_table(share->db_type(), share->path.str); free_table_share(share); diff --git a/sql/tztime.cc b/sql/tztime.cc index 4581461f8b3..4a3119befd1 100644 --- a/sql/tztime.cc +++ b/sql/tztime.cc @@ -1476,7 +1476,7 @@ static bool time_zone_tables_exist= 1; for dynamical loading of time zone descriptions. */ -static const LEX_STRING tz_tables_names[MY_TZ_TABLES_COUNT]= +static const LEX_CSTRING tz_tables_names[MY_TZ_TABLES_COUNT]= { { C_STRING_WITH_LEN("time_zone_name")}, { C_STRING_WITH_LEN("time_zone")}, @@ -1484,11 +1484,6 @@ static const LEX_STRING tz_tables_names[MY_TZ_TABLES_COUNT]= { C_STRING_WITH_LEN("time_zone_transition")} }; -/* Name of database to which those tables belong. */ - -static const LEX_STRING tz_tables_db_name= { C_STRING_WITH_LEN("mysql")}; - - class Tz_names_entry: public Sql_alloc { public: @@ -1540,10 +1535,8 @@ tz_init_table_list(TABLE_LIST *tz_tabs) for (int i= 0; i < MY_TZ_TABLES_COUNT; i++) { - tz_tabs[i].alias= tz_tabs[i].table_name= tz_tables_names[i].str; - tz_tabs[i].table_name_length= tz_tables_names[i].length; - tz_tabs[i].db= tz_tables_db_name.str; - tz_tabs[i].db_length= tz_tables_db_name.length; + tz_tabs[i].alias= tz_tabs[i].table_name= tz_tables_names[i]; + tz_tabs[i].db= MYSQL_SCHEMA_NAME; tz_tabs[i].lock_type= TL_READ; if (i != MY_TZ_TABLES_COUNT - 1) @@ -1606,9 +1599,9 @@ my_tz_init(THD *org_thd, const char *default_tzname, my_bool bootstrap) THD *thd; TABLE_LIST tz_tables[1+MY_TZ_TABLES_COUNT]; TABLE *table; + const LEX_CSTRING tmp_table_name= { STRING_WITH_LEN("time_zone_leap_second") }; Tz_names_entry *tmp_tzname; my_bool return_val= 1; - char db[]= "mysql"; int res; DBUG_ENTER("my_tz_init"); @@ -1669,13 +1662,10 @@ my_tz_init(THD *org_thd, const char *default_tzname, my_bool bootstrap) leap seconds shared by all time zones. */ - thd->set_db(db, sizeof(db)-1); + thd->set_db(&MYSQL_SCHEMA_NAME); bzero((char*) &tz_tables[0], sizeof(TABLE_LIST)); - tz_tables[0].alias= tz_tables[0].table_name= - (char*)"time_zone_leap_second"; - tz_tables[0].table_name_length= 21; - tz_tables[0].db= db; - tz_tables[0].db_length= sizeof(db)-1; + tz_tables[0].alias= tz_tables[0].table_name= tmp_table_name; + tz_tables[0].db= MYSQL_SCHEMA_NAME; tz_tables[0].lock_type= TL_READ; tz_init_table_list(tz_tables+1); diff --git a/sql/unireg.cc b/sql/unireg.cc index 251d48f2d96..cbab0b3533b 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -164,7 +164,7 @@ bool has_extra2_field_flags(List<Create_field> &create_fields) or null LEX_CUSTRING (str==0) in case of an error. */ -LEX_CUSTRING build_frm_image(THD *thd, const char *table, +LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING *table, HA_CREATE_INFO *create_info, List<Create_field> &create_fields, uint keys, KEY *key_info, handler *db_file) @@ -237,7 +237,7 @@ LEX_CUSTRING build_frm_image(THD *thd, const char *table, DBUG_PRINT("info", ("Options length: %u", options_len)); if (validate_comment_length(thd, &create_info->comment, TABLE_COMMENT_MAXLEN, - ER_TOO_LONG_TABLE_COMMENT, table)) + ER_TOO_LONG_TABLE_COMMENT, table->str)) DBUG_RETURN(frm); /* If table comment is longer than TABLE_COMMENT_INLINE_MAXLEN bytes, @@ -317,7 +317,7 @@ LEX_CUSTRING build_frm_image(THD *thd, const char *table, if (frm.length > FRM_MAX_SIZE || create_info->expression_length > UINT_MAX32) { - my_error(ER_TABLE_DEFINITION_TOO_BIG, MYF(0), table); + my_error(ER_TABLE_DEFINITION_TOO_BIG, MYF(0), table->str); DBUG_RETURN(frm); } diff --git a/sql/unireg.h b/sql/unireg.h index 6d49b1d5092..dfabc71aa0f 100644 --- a/sql/unireg.h +++ b/sql/unireg.h @@ -49,9 +49,11 @@ #define DEFAULT_ERRMSGS my_default_lc_messages->errmsgs->errmsgs #define CURRENT_THD_ERRMSGS (current_thd)->variables.errmsgs +#ifndef mysqld_error_find_printf_error_used #define ER_DEFAULT(X) DEFAULT_ERRMSGS[((X)-ER_ERROR_FIRST) / ERRORS_PER_RANGE][(X)% ERRORS_PER_RANGE] #define ER_THD(thd,X) ((thd)->variables.errmsgs[((X)-ER_ERROR_FIRST) / ERRORS_PER_RANGE][(X) % ERRORS_PER_RANGE]) #define ER(X) ER_THD(current_thd, (X)) +#endif #define ER_THD_OR_DEFAULT(thd,X) ((thd) ? ER_THD(thd, (X)) : ER_DEFAULT(X)) #define ME_INFO (ME_HOLDTANG | ME_NOREFRESH) @@ -190,7 +192,7 @@ int rea_create_table(THD *thd, LEX_CUSTRING *frm, const char *path, const char *db, const char *table_name, HA_CREATE_INFO *create_info, handler *file, bool no_ha_create_table); -LEX_CUSTRING build_frm_image(THD *thd, const char *table, +LEX_CUSTRING build_frm_image(THD *thd, const LEX_CSTRING *table, HA_CREATE_INFO *create_info, List<Create_field> &create_fields, uint keys, KEY *key_info, handler *db_file); diff --git a/sql/vers_string.h b/sql/vers_string.h index 6d501e1b81c..756aea82794 100644 --- a/sql/vers_string.h +++ b/sql/vers_string.h @@ -1,3 +1,19 @@ +/* + Copyright (c) 2018, MariaDB Corporation. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + #ifndef VERS_STRING_INCLUDED #define VERS_STRING_INCLUDED @@ -126,8 +142,7 @@ 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 - +#define DB_WITH_LEN(X) (X).db.str, (X).db.length +#define TABLE_NAME_WITH_LEN(X) (X).table_name.str, (X).table_name.length #endif // VERS_STRING_INCLUDED diff --git a/sql/vers_utils.h b/sql/vers_utils.h index b9b93856ea6..52d01e36e8c 100644 --- a/sql/vers_utils.h +++ b/sql/vers_utils.h @@ -28,7 +28,7 @@ public: if (error) return; - table.mdl_request.init(MDL_key::TABLE, table.db, table.table_name, MDL_EXCLUSIVE, MDL_EXPLICIT); + table.mdl_request.init(MDL_key::TABLE, table.db.str, table.table_name.str, MDL_EXCLUSIVE, MDL_EXPLICIT); error= thd->mdl_context.acquire_lock(&table.mdl_request, thd->variables.lock_wait_timeout); thd->mdl_context.release_lock(protection_request.ticket); } diff --git a/sql/vtmd.cc b/sql/vtmd.cc index a78fdd75a2a..4ee43d61111 100644 --- a/sql/vtmd.cc +++ b/sql/vtmd.cc @@ -21,17 +21,11 @@ VTMD_table::create(THD *thd) TABLE_LIST src_table, table; create_info.init(DDL_options_st::OPT_LIKE); create_info.options|= HA_VTMD; - create_info.alias= vtmd_name; - table.init_one_table( - DB_WITH_LEN(about), - XSTRING_WITH_LEN(vtmd_name), - vtmd_name, - TL_READ); - src_table.init_one_table( - LEX_STRING_WITH_LEN(MYSQL_SCHEMA_NAME), - XSTRING_WITH_LEN(VERS_VTMD_TEMPLATE), - VERS_VTMD_TEMPLATE, - TL_READ); + create_info.alias.str= vtmd_name.ptr(); + create_info.alias.length= vtmd_name.length(); + table.init_one_table(&about.db, &create_info.alias, NULL, TL_READ); + src_table.init_one_table(&MYSQL_SCHEMA_NAME, &VERS_VTMD_TEMPLATE, + &VERS_VTMD_TEMPLATE, TL_READ); Query_tables_backup backup(thd); thd->lex->add_to_query_tables(&src_table); @@ -97,17 +91,16 @@ VTMD_table::open(THD *thd, Local_da &local_da, bool *created) while (true) // max 2 iterations { - vtmd.init_one_table( - DB_WITH_LEN(about), - XSTRING_WITH_LEN(vtmd_name), - vtmd_name, - TL_WRITE_CONCURRENT_INSERT); + LEX_CSTRING table_name= { vtmd_name.ptr(), vtmd_name.length() }; + vtmd.init_one_table(&about.db, &table_name, NULL, + TL_WRITE_CONCURRENT_INSERT); TABLE *res= open_log_table(thd, &vtmd, &open_tables_backup); if (res) return false; - if (created && !*created && local_da.is_error() && local_da.sql_errno() == ER_NO_SUCH_TABLE) + if (created && !*created && local_da.is_error() && + local_da.sql_errno() == ER_NO_SUCH_TABLE) { local_da.reset_diagnostics_area(); if (create(thd)) @@ -201,7 +194,7 @@ VTMD_table::update(THD *thd, const char* archive_name) DBUG_ASSERT(thd->lex->sql_command == SQLCOM_ALTER_TABLE); ulonglong row_end= (ulonglong) vtmd.table->vers_start_field()->val_int(); store_record(vtmd.table, record[1]); - vtmd.table->field[FLD_NAME]->store(TABLE_NAME_WITH_LEN(about), system_charset_info); + vtmd.table->field[FLD_NAME]->store(about.table_name.str, about.table_name.length, system_charset_info); vtmd.table->field[FLD_NAME]->set_notnull(); vtmd.table->field[FLD_ARCHIVE_NAME]->set_null(); error= vtmd.table->file->ha_update_row(vtmd.table->record[1], vtmd.table->record[0]); @@ -232,14 +225,19 @@ VTMD_table::update(THD *thd, const char* archive_name) } // if (archive_name) else { - vtmd.table->field[FLD_NAME]->store(TABLE_NAME_WITH_LEN(about), system_charset_info); + vtmd.table->field[FLD_NAME]->store(about.table_name.str, + about.table_name.length, + system_charset_info); vtmd.table->field[FLD_NAME]->set_notnull(); - error= vtmd.table->file->ha_update_row(vtmd.table->record[1], vtmd.table->record[0]); + error= vtmd.table->file->ha_update_row(vtmd.table->record[1], + vtmd.table->record[0]); } } // if (found) else { - vtmd.table->field[FLD_NAME]->store(TABLE_NAME_WITH_LEN(about), system_charset_info); + vtmd.table->field[FLD_NAME]->store(about.table_name.str, + about.table_name.length, + system_charset_info); vtmd.table->field[FLD_NAME]->set_notnull(); vtmd.table->mark_columns_needed_for_insert(); // not needed? error= vtmd.table->file->ha_write_row(vtmd.table->record[0]); @@ -274,11 +272,6 @@ open_error: bool VTMD_rename::move_archives(THD *thd, LString &new_db) { - vtmd.init_one_table( - DB_WITH_LEN(about), - XSTRING_WITH_LEN(vtmd_name), - vtmd_name, - TL_READ); int error; bool rc= false; SString_fs archive; @@ -287,6 +280,9 @@ VTMD_rename::move_archives(THD *thd, LString &new_db) Open_tables_backup open_tables_backup; key_buf_t key; + LEX_CSTRING table_name= { vtmd_name.ptr(), vtmd_name.length() }; + vtmd.init_one_table(&about.db, &table_name, NULL, TL_READ); + TABLE *res= open_log_table(thd, &vtmd, &open_tables_backup); if (!res) return true; @@ -356,41 +352,37 @@ bool VTMD_rename::move_table(THD *thd, SString_fs &table_name, LString &new_db) { handlerton *table_hton= NULL; - if (!ha_table_exists(thd, about.db, table_name, &table_hton) || !table_hton) + LEX_CSTRING tbl_name= { table_name.ptr(), table_name.length() }; + LEX_CSTRING db_name= { new_db.ptr(), new_db.length() }; + if (!ha_table_exists(thd, &about.db, &tbl_name, &table_hton) || !table_hton) { - push_warning_printf( - thd, Sql_condition::WARN_LEVEL_WARN, - ER_VERS_VTMD_ERROR, - "`%s.%s` archive doesn't exist", - about.db, table_name.ptr()); + push_warning_printf( thd, Sql_condition::WARN_LEVEL_WARN, + ER_VERS_VTMD_ERROR, + "`%s.%s` archive doesn't exist", + about.db.str, tbl_name.str); return false; } - if (ha_table_exists(thd, new_db, table_name)) + if (ha_table_exists(thd, &db_name, &tbl_name)) { - my_printf_error(ER_VERS_VTMD_ERROR, "`%s.%s` archive already exists!", MYF(0), - new_db.ptr(), table_name.ptr()); + my_printf_error(ER_VERS_VTMD_ERROR, "`%s.%s` archive already exists!", + MYF(0), + db_name.str, tbl_name.str); return true; } TABLE_LIST tl; - tl.init_one_table( - DB_WITH_LEN(about), - XSTRING_WITH_LEN(table_name), - table_name, - TL_WRITE_ONLY); + tl.init_one_table(&about.db, &tbl_name, NULL, TL_WRITE_ONLY); tl.mdl_request.set_type(MDL_EXCLUSIVE); mysql_ha_rm_tables(thd, &tl); if (lock_table_names(thd, &tl, 0, thd->variables.lock_wait_timeout, 0)) return true; - tdc_remove_table(thd, TDC_RT_REMOVE_ALL, about.db, table_name, false); + tdc_remove_table(thd, TDC_RT_REMOVE_ALL, about.db.str, table_name, false); - bool rc= mysql_rename_table( - table_hton, - about.db, table_name, - new_db, table_name, - NO_FK_CHECKS); + bool rc= mysql_rename_table(table_hton, + &about.db, &tbl_name, &db_name, &tbl_name, + NO_FK_CHECKS); if (!rc) query_cache_invalidate3(thd, &tl, 0); @@ -406,27 +398,29 @@ VTMD_rename::try_rename(THD *thd, LString new_db, LString new_alias, const char if (check_exists(thd)) return true; - new_table.init_one_table( - XSTRING_WITH_LEN(new_db), - XSTRING_WITH_LEN(new_alias), - new_alias, TL_READ); + LEX_CSTRING new_db_name= { XSTRING_WITH_LEN(new_db) }; + LEX_CSTRING new_tbl_name= { XSTRING_WITH_LEN(new_alias) }; + + new_table.init_one_table(&new_db_name, &new_tbl_name, NULL, TL_READ); if (new_table.vers_vtmd_name(vtmd_new_name)) return true; - if (ha_table_exists(thd, new_db, vtmd_new_name)) + LEX_CSTRING new_name= { vtmd_new_name.ptr(), vtmd_new_name.length() }; + + if (ha_table_exists(thd, &new_db_name, &new_name)) { if (exists) { - my_printf_error(ER_VERS_VTMD_ERROR, "`%s.%s` table already exists!", MYF(0), - new_db.ptr(), vtmd_new_name.ptr()); + my_printf_error(ER_VERS_VTMD_ERROR, "`%s.%s` table already exists!", + MYF(0), + new_db_name.str, new_name.str); return true; } - push_warning_printf( - thd, Sql_condition::WARN_LEVEL_WARN, - ER_VERS_VTMD_ERROR, - "`%s.%s` table already exists!", - new_db.ptr(), vtmd_new_name.ptr()); + push_warning_printf( thd, Sql_condition::WARN_LEVEL_WARN, + ER_VERS_VTMD_ERROR, + "`%s.%s` table already exists!", + new_db_name.str, new_name.str); return false; } @@ -443,27 +437,24 @@ VTMD_rename::try_rename(THD *thd, LString new_db, LString new_alias, const char } TABLE_LIST vtmd_tl; - vtmd_tl.init_one_table( - DB_WITH_LEN(about), - XSTRING_WITH_LEN(vtmd_name), - vtmd_name, - TL_WRITE_ONLY); + LEX_CSTRING table_name= { vtmd_name.ptr(), vtmd_name.length() }; + vtmd_tl.init_one_table(&about.db, &table_name, NULL, TL_WRITE_ONLY); vtmd_tl.mdl_request.set_type(MDL_EXCLUSIVE); mysql_ha_rm_tables(thd, &vtmd_tl); if (lock_table_names(thd, &vtmd_tl, 0, thd->variables.lock_wait_timeout, 0)) return true; - tdc_remove_table(thd, TDC_RT_REMOVE_ALL, about.db, vtmd_name, false); + tdc_remove_table(thd, TDC_RT_REMOVE_ALL, about.db.str, vtmd_name, false); if (local_da.is_error()) // just safety check return true; - bool rc= mysql_rename_table(hton, - about.db, vtmd_name, - new_db, vtmd_new_name, - NO_FK_CHECKS); + bool rc= mysql_rename_table(hton, &about.db, &table_name, + &new_db_name, &new_name, + NO_FK_CHECKS); if (!rc) { query_cache_invalidate3(thd, &vtmd_tl, 0); - if (same_db || archive_name || new_alias != LString(TABLE_NAME_WITH_LEN(about))) + if (same_db || archive_name || + new_alias != LString(TABLE_NAME_WITH_LEN(about))) { local_da.finish(); VTMD_table new_vtmd(new_table); @@ -480,22 +471,20 @@ VTMD_rename::revert_rename(THD *thd, LString new_db) Local_da local_da(thd, ER_VERS_VTMD_ERROR); TABLE_LIST vtmd_tl; - vtmd_tl.init_one_table( - DB_WITH_LEN(about), - XSTRING_WITH_LEN(vtmd_new_name), - vtmd_new_name, - TL_WRITE_ONLY); + LEX_CSTRING new_name= { XSTRING_WITH_LEN(vtmd_new_name) }; + LEX_CSTRING v_name= { XSTRING_WITH_LEN(vtmd_name) }; + LEX_CSTRING new_db_name= { XSTRING_WITH_LEN(new_db) }; + + vtmd_tl.init_one_table(&about.db, &new_name, NULL, TL_WRITE_ONLY); vtmd_tl.mdl_request.set_type(MDL_EXCLUSIVE); mysql_ha_rm_tables(thd, &vtmd_tl); if (lock_table_names(thd, &vtmd_tl, 0, thd->variables.lock_wait_timeout, 0)) return true; tdc_remove_table(thd, TDC_RT_REMOVE_ALL, new_db, vtmd_new_name, false); - bool rc= mysql_rename_table( - hton, - new_db, vtmd_new_name, - new_db, vtmd_name, - NO_FK_CHECKS); + bool rc= mysql_rename_table(hton, &new_db_name, &new_name, + &new_db_name, &v_name, + NO_FK_CHECKS); if (!rc) query_cache_invalidate3(thd, &vtmd_tl, 0); @@ -511,9 +500,9 @@ VTMD_table::archive_name( size_t new_name_size) { const MYSQL_TIME now= thd->query_start_TIME(); - my_snprintf(new_name, new_name_size, "%s_%04d%02d%02d_%02d%02d%02d_%06d", + my_snprintf(new_name, new_name_size, "%s_%04d%02d%02d_%02d%02d%02d_%06lu", table_name, now.year, now.month, now.day, now.hour, now.minute, - now.second, now.second_part); + now.second, (ulong) now.second_part); } bool @@ -563,7 +552,7 @@ VTMD_table::find_archive_name(THD *thd, String &out) } if (error < 0) - my_error(ER_NO_SUCH_TABLE, MYF(0), about.db, about.alias); + my_error(ER_NO_SUCH_TABLE, MYF(0), about.db.str, about.alias.str); loc_err: end_read_record(&info); @@ -603,11 +592,10 @@ VTMD_table::get_archive_tables(THD *thd, const char *db, size_t db_length, for (uint i= 0; i < vtmd_tables.elements(); i++) { LEX_CSTRING table_name= *vtmd_tables.at(i); - Open_tables_backup open_tables_backup; TABLE_LIST table_list; - table_list.init_one_table(db, db_length, LEX_STRING_WITH_LEN(table_name), - table_name.str, TL_READ); + LEX_CSTRING db_name= {db, db_length}; + table_list.init_one_table(&db_name, &table_name, NULL, TL_READ); TABLE *table= open_log_table(thd, &table_list, &open_tables_backup); if (!table || !table->vers_vtmd()) @@ -679,10 +667,10 @@ bool VTMD_table::setup_select(THD* thd) if (archive_name.length() == 0) return false; - about.table_name= (char *) thd->memdup(archive_name.c_ptr_safe(), archive_name.length() + 1); - about.table_name_length= archive_name.length(); + thd->make_lex_string(&about.table_name, archive_name.ptr(), + archive_name.length()); DBUG_ASSERT(!about.mdl_request.ticket); - about.mdl_request.init(MDL_key::TABLE, about.db, about.table_name, + about.mdl_request.init(MDL_key::TABLE, about.db.str, about.table_name.str, about.mdl_request.type, about.mdl_request.duration); about.vers_force_alias= true; // Since we modified SELECT_LEX::table_list, we need to invalidate current SP diff --git a/sql/vtmd.h b/sql/vtmd.h index 29657ece0f4..ea5450a8841 100644 --- a/sql/vtmd.h +++ b/sql/vtmd.h @@ -92,7 +92,7 @@ public: static void archive_name(THD *thd, const char *table_name, char *new_name, size_t new_name_size); void archive_name(THD *thd, char *new_name, size_t new_name_size) { - archive_name(thd, about.table_name, new_name, new_name_size); + archive_name(thd, about.table_name.str, new_name, new_name_size); } bool find_archive_name(THD *thd, String &out); @@ -170,15 +170,18 @@ inline bool VTMD_exists::check_exists(THD *thd) { + LEX_CSTRING name; if (about.vers_vtmd_name(vtmd_name)) return true; - exists= ha_table_exists(thd, about.db, vtmd_name, &hton); + name.str= vtmd_name.ptr(); + name.length= vtmd_name.length(); + exists= ha_table_exists(thd, &about.db, &name, &hton); if (exists && !hton) { my_printf_error(ER_VERS_VTMD_ERROR, "`%s.%s` handlerton empty!", MYF(0), - about.db, vtmd_name.ptr()); + about.db.str, vtmd_name.ptr()); return true; } return false; diff --git a/sql/wsrep_binlog.cc b/sql/wsrep_binlog.cc index bddbbb95f4d..4efd6703d03 100644 --- a/sql/wsrep_binlog.cc +++ b/sql/wsrep_binlog.cc @@ -31,13 +31,13 @@ int wsrep_write_cache_buf(IO_CACHE *cache, uchar **buf, size_t *buf_len) { *buf= NULL; *buf_len= 0; - my_off_t const saved_pos(my_b_tell(cache)); + DBUG_ENTER("wsrep_write_cache_buf"); if (reinit_io_cache(cache, READ_CACHE, 0, 0, 0)) { WSREP_ERROR("failed to initialize io-cache"); - return ER_ERROR_ON_WRITE; + DBUG_RETURN(ER_ERROR_ON_WRITE); } uint length = my_b_bytes_in_cache(cache); @@ -86,7 +86,7 @@ int wsrep_write_cache_buf(IO_CACHE *cache, uchar **buf, size_t *buf_len) goto cleanup; } - return 0; + DBUG_RETURN(0); error: if (reinit_io_cache(cache, WRITE_CACHE, saved_pos, 0, 0)) @@ -97,7 +97,7 @@ cleanup: my_free(*buf); *buf= NULL; *buf_len= 0; - return ER_ERROR_ON_WRITE; + DBUG_RETURN(ER_ERROR_ON_WRITE); } #define STACK_SIZE 4096 /* 4K - for buffer preallocated on the stack: @@ -121,6 +121,7 @@ wsrep_append_data(wsrep_t* const wsrep, struct wsrep_buf const buff = { data, len }; wsrep_status_t const rc(wsrep->append_data(wsrep, ws, &buff, 1, WSREP_DATA_ORDERED, true)); + DBUG_DUMP("buff", (uchar*) data, len); if (rc != WSREP_OK) { WSREP_WARN("append_data() returned %d", rc); @@ -144,11 +145,12 @@ static int wsrep_write_cache_once(wsrep_t* const wsrep, size_t* const len) { my_off_t const saved_pos(my_b_tell(cache)); + DBUG_ENTER("wsrep_write_cache_once"); if (reinit_io_cache(cache, READ_CACHE, 0, 0, 0)) { WSREP_ERROR("failed to initialize io-cache"); - return ER_ERROR_ON_WRITE; + DBUG_RETURN(ER_ERROR_ON_WRITE); } int err(WSREP_OK); @@ -230,7 +232,7 @@ cleanup: } my_free(heap_buf); - return err; + DBUG_RETURN(err); } /* @@ -247,11 +249,12 @@ static int wsrep_write_cache_inc(wsrep_t* const wsrep, size_t* const len) { my_off_t const saved_pos(my_b_tell(cache)); + DBUG_ENTER("wsrep_write_cache_inc"); if (reinit_io_cache(cache, READ_CACHE, 0, 0, 0)) { WSREP_ERROR("failed to initialize io-cache"); - return WSREP_TRX_ERROR; + DBUG_RETURN(WSREP_TRX_ERROR); } int err(WSREP_OK); @@ -295,7 +298,7 @@ cleanup: WSREP_ERROR("failed to reinitialize io-cache"); } - return err; + DBUG_RETURN(err); } /* diff --git a/sql/wsrep_hton.cc b/sql/wsrep_hton.cc index 837996bbd5d..8044b7a3548 100644 --- a/sql/wsrep_hton.cc +++ b/sql/wsrep_hton.cc @@ -258,8 +258,7 @@ static int wsrep_rollback(handlerton *hton, THD *thd, bool all) { DBUG_PRINT("wsrep", ("setting rollback fail")); WSREP_ERROR("settting rollback fail: thd: %llu, schema: %s, SQL: %s", - (long long)thd->real_id, (thd->db ? thd->db : "(null)"), - thd->query()); + (long long)thd->real_id, thd->get_db(), thd->query()); } wsrep_cleanup_transaction(thd); } @@ -300,7 +299,7 @@ int wsrep_commit(handlerton *hton, THD *thd, bool all) { DBUG_PRINT("wsrep", ("setting rollback fail")); WSREP_ERROR("settting rollback fail: thd: %llu, schema: %s, SQL: %s", - (long long)thd->real_id, (thd->db ? thd->db : "(null)"), + (long long)thd->real_id, thd->get_db(), thd->query()); } } @@ -374,6 +373,11 @@ wsrep_run_wsrep_commit(THD *thd, bool all) mysql_mutex_lock(&LOCK_wsrep_replaying); + DBUG_PRINT("info", ("wsrep_replaying: %d wsrep_conflict_state: %d killed: %d shutdown_in_progress: %d", + (int) wsrep_replaying, (int) thd->wsrep_conflict_state, + (int) thd->killed, + (int) shutdown_in_progress)); + while (wsrep_replaying > 0 && thd->wsrep_conflict_state == NO_CONFLICT && thd->killed == NOT_KILLED && @@ -437,6 +441,9 @@ wsrep_run_wsrep_commit(THD *thd, bool all) } } + DBUG_PRINT("info", ("rcode: %d wsrep_conflict_state: %d", + rcode, thd->wsrep_conflict_state)); + if (data_len == 0) { if (thd->get_stmt_da()->is_ok() && @@ -468,7 +475,7 @@ wsrep_run_wsrep_commit(THD *thd, bool all) "QUERY: %s\n" " => Skipping replication", (longlong) thd->thread_id, data_len, - (thd->db ? thd->db : "(null)"), thd->query()); + thd->get_db(), thd->query()); rcode = WSREP_TRX_FAIL; } else if (!rcode) @@ -482,10 +489,12 @@ wsrep_run_wsrep_commit(THD *thd, bool all) 0ULL : WSREP_FLAG_PA_UNSAFE), &thd->wsrep_trx_meta); + DBUG_PRINT("info", ("rcode after pre_commit: %d", rcode)); + if (rcode == WSREP_TRX_MISSING) { WSREP_WARN("Transaction missing in provider, thd: %lld schema: %s SQL: %s", (longlong) thd->thread_id, - (thd->db ? thd->db : "(null)"), thd->query()); + thd->get_db(), thd->query()); rcode = WSREP_TRX_FAIL; } else if (rcode == WSREP_BF_ABORT) { WSREP_DEBUG("thd: %lld seqno: %lld BF aborted by provider, will replay", @@ -512,6 +521,9 @@ wsrep_run_wsrep_commit(THD *thd, bool all) DEBUG_SYNC(thd, "wsrep_after_replication"); + DBUG_PRINT("info", ("rcode: %d wsrep_conflict_state: %d", + rcode, thd->wsrep_conflict_state)); + switch(rcode) { case 0: /* diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc index 54313281625..8c238578e3d 100644 --- a/sql/wsrep_mysqld.cc +++ b/sql/wsrep_mysqld.cc @@ -1176,7 +1176,7 @@ static bool wsrep_prepare_keys_for_isolation(THD* thd, } ka->keys[ka->keys_len].key_parts_num= 2; ++ka->keys_len; - if (!wsrep_prepare_key_for_isolation(table->db, table->table_name, + if (!wsrep_prepare_key_for_isolation(table->db.str, table->table_name.str, (wsrep_buf_t*)ka->keys[ka->keys_len - 1].key_parts, &ka->keys[ka->keys_len - 1].key_parts_num)) { @@ -1318,7 +1318,7 @@ static int wsrep_alter_event_query(THD *thd, uchar** buf, size_t* buf_len) if (wsrep_alter_query_string(thd, &log_query)) { WSREP_WARN("events alter string failed: schema: %s, query: %s", - (thd->db ? thd->db : "(null)"), thd->query()); + thd->get_db(), thd->query()); return 1; } return wsrep_to_buf_helper(thd, log_query.ptr(), log_query.length(), buf, buf_len); @@ -1370,25 +1370,23 @@ create_view_query(THD *thd, uchar** buf, size_t* buf_len) view_store_options(thd, views, &buff); buff.append(STRING_WITH_LEN("VIEW ")); /* Test if user supplied a db (ie: we did not use thd->db) */ - if (views->db && views->db[0] && - (thd->db == NULL || strcmp(views->db, thd->db))) + if (views->db.str && views->db.str[0] && + (thd->db.str == NULL || cmp(&views->db, &thd->db))) { - append_identifier(thd, &buff, views->db, - views->db_length); + append_identifier(thd, &buff, &views->db); buff.append('.'); } - append_identifier(thd, &buff, views->table_name, - views->table_name_length); + append_identifier(thd, &buff, &views->table_name); if (lex->view_list.elements) { - List_iterator_fast<LEX_STRING> names(lex->view_list); - LEX_STRING *name; + List_iterator_fast<LEX_CSTRING> names(lex->view_list); + LEX_CSTRING *name; int i; for (i= 0; (name= names++); i++) { buff.append(i ? ", " : "("); - append_identifier(thd, &buff, name->str, name->length); + append_identifier(thd, &buff, name); } buff.append(')'); } @@ -1474,7 +1472,7 @@ static bool wsrep_can_run_in_toi(THD *thd, const char *db, const char *table, { for (TABLE_LIST* table= first_table; table; table= table->next_global) { - if (!thd->find_temporary_table(table->db, table->table_name)) + if (!thd->find_temporary_table(table->db.str, table->table_name.str)) { return true; } @@ -1558,7 +1556,7 @@ static int wsrep_TOI_begin(THD *thd, const char *db_, const char *table_, WSREP_WARN("TO isolation failed for: %d, schema: %s, sql: %s. Check wsrep " "connection state and retry the query.", ret, - (thd->db ? thd->db : "(null)"), + thd->get_db(), (thd->query()) ? thd->query() : "void"); my_message(ER_LOCK_DEADLOCK, "WSREP replication failed. Check " "your wsrep connection state and retry the query.", MYF(0)); @@ -1594,7 +1592,7 @@ static void wsrep_TOI_end(THD *thd) { else { WSREP_WARN("TO isolation end failed for: %d, schema: %s, sql: %s", ret, - (thd->db ? thd->db : "(null)"), + thd->get_db(), (thd->query()) ? thd->query() : "void"); } } @@ -1609,7 +1607,7 @@ static int wsrep_RSU_begin(THD *thd, const char *db_, const char *table_) if (ret != WSREP_OK) { WSREP_WARN("RSU desync failed %d for schema: %s, query: %s", - ret, (thd->db ? thd->db : "(null)"), thd->query()); + ret, thd->get_db(), thd->query()); my_error(ER_LOCK_DEADLOCK, MYF(0)); return(ret); } @@ -1622,8 +1620,7 @@ static int wsrep_RSU_begin(THD *thd, const char *db_, const char *table_) { /* no can do, bail out from DDL */ WSREP_WARN("RSU failed due to pending transactions, schema: %s, query %s", - (thd->db ? thd->db : "(null)"), - thd->query()); + thd->get_db(), thd->query()); mysql_mutex_lock(&LOCK_wsrep_replaying); wsrep_replaying--; mysql_mutex_unlock(&LOCK_wsrep_replaying); @@ -1632,7 +1629,7 @@ static int wsrep_RSU_begin(THD *thd, const char *db_, const char *table_) if (ret != WSREP_OK) { WSREP_WARN("resync failed %d for schema: %s, query: %s", - ret, (thd->db ? thd->db : "(null)"), thd->query()); + ret, thd->get_db(), thd->query()); } my_error(ER_LOCK_DEADLOCK, MYF(0)); @@ -1643,8 +1640,7 @@ static int wsrep_RSU_begin(THD *thd, const char *db_, const char *table_) if (seqno == WSREP_SEQNO_UNDEFINED) { WSREP_WARN("pause failed %lld for schema: %s, query: %s", (long long)seqno, - (thd->db ? thd->db : "(null)"), - thd->query()); + thd->get_db(), thd->query()); return(1); } WSREP_DEBUG("paused at %lld", (long long)seqno); @@ -1667,15 +1663,14 @@ static void wsrep_RSU_end(THD *thd) if (ret != WSREP_OK) { WSREP_WARN("resume failed %d for schema: %s, query: %s", ret, - (thd->db ? thd->db : "(null)"), - thd->query()); + thd->get_db(), thd->query()); } ret = wsrep->resync(wsrep); if (ret != WSREP_OK) { WSREP_WARN("resync failed %d for schema: %s, query: %s", ret, - (thd->db ? thd->db : "(null)"), thd->query()); + thd->get_db(), thd->query()); return; } @@ -1698,9 +1693,7 @@ int wsrep_to_isolation_begin(THD *thd, const char *db_, const char *table_, if (thd->wsrep_conflict_state == MUST_ABORT) { WSREP_INFO("thread: %lld schema: %s query: %s has been aborted due to multi-master conflict", - (longlong) thd->thread_id, - (thd->db ? thd->db : "(null)"), - thd->query()); + (longlong) thd->thread_id, thd->get_db(), thd->query()); mysql_mutex_unlock(&thd->LOCK_wsrep_thd); return WSREP_TRX_FAIL; } @@ -2339,7 +2332,7 @@ static int wsrep_create_sp(THD *thd, uchar** buf, size_t* buf_len) saved_mode)) { WSREP_WARN("SP create string failed: schema: %s, query: %s", - (thd->db ? thd->db : "(null)"), thd->query()); + thd->get_db(), thd->query()); return 1; } @@ -2585,8 +2578,8 @@ bool wsrep_create_like_table(THD* thd, TABLE_LIST* table, } else if (!(thd->find_temporary_table(src_table))) { - /* this is straight CREATE TABLE LIKE... eith no tmp tables */ - WSREP_TO_ISOLATION_BEGIN(table->db, table->table_name, NULL); + /* this is straight CREATE TABLE LIKE... with no tmp tables */ + WSREP_TO_ISOLATION_BEGIN(table->db.str, table->table_name.str, NULL); } else { @@ -2609,7 +2602,7 @@ bool wsrep_create_like_table(THD* thd, TABLE_LIST* table, thd->wsrep_TOI_pre_query= query.ptr(); thd->wsrep_TOI_pre_query_len= query.length(); - WSREP_TO_ISOLATION_BEGIN(table->db, table->table_name, NULL); + WSREP_TO_ISOLATION_BEGIN(table->db.str, table->table_name.str, NULL); thd->wsrep_TOI_pre_query= NULL; thd->wsrep_TOI_pre_query_len= 0; diff --git a/sql/wsrep_mysqld.h b/sql/wsrep_mysqld.h index bed9b0dca48..6ad13cd6f6a 100644 --- a/sql/wsrep_mysqld.h +++ b/sql/wsrep_mysqld.h @@ -48,7 +48,7 @@ struct wsrep_thd_shadow { enum wsrep_exec_mode wsrep_exec_mode; Vio *vio; ulong tx_isolation; - char *db; + const char *db; size_t db_length; my_hrtime_t user_time; longlong row_count_func; diff --git a/sql/wsrep_thd.cc b/sql/wsrep_thd.cc index 32b812a9bb2..e8dda53c95f 100644 --- a/sql/wsrep_thd.cc +++ b/sql/wsrep_thd.cc @@ -164,22 +164,23 @@ static void wsrep_prepare_bf_thd(THD *thd, struct wsrep_thd_shadow* shadow) thd->variables.tx_isolation = ISO_READ_COMMITTED; thd->tx_isolation = ISO_READ_COMMITTED; - shadow->db = thd->db; - shadow->db_length = thd->db_length; + shadow->db = thd->db.str; + shadow->db_length = thd->db.length; shadow->user_time = thd->user_time; shadow->row_count_func= thd->get_row_count_func(); - thd->reset_db(NULL, 0); + thd->reset_db(&null_clex_str); } static void wsrep_return_from_bf_mode(THD *thd, struct wsrep_thd_shadow* shadow) { + LEX_CSTRING db= {shadow->db, shadow->db_length }; thd->variables.option_bits = shadow->options; thd->server_status = shadow->server_status; thd->wsrep_exec_mode = shadow->wsrep_exec_mode; thd->net.vio = shadow->vio; thd->variables.tx_isolation = shadow->tx_isolation; thd->user_time = shadow->user_time; - thd->reset_db(shadow->db, shadow->db_length); + thd->reset_db(&db); delete thd->system_thread_info.rpl_sql_info; delete thd->wsrep_rgi->rli->mi; @@ -322,8 +323,7 @@ void wsrep_replay_transaction(THD *thd) break; default: WSREP_ERROR("trx_replay failed for: %d, schema: %s, query: %s", - rcode, - (thd->db ? thd->db : "(null)"), + rcode, thd->get_db(), thd->query() ? thd->query() : "void"); /* we're now in inconsistent state, must abort */ diff --git a/sql/wsrep_var.cc b/sql/wsrep_var.cc index 34c5865548c..c54a5481187 100644 --- a/sql/wsrep_var.cc +++ b/sql/wsrep_var.cc @@ -605,9 +605,8 @@ bool wsrep_desync_check (sys_var *self, THD* thd, set_var* var) if (new_wsrep_desync) { ret = wsrep->desync (wsrep); if (ret != WSREP_OK) { - WSREP_WARN ("SET desync failed %d for schema: %s, query: %s", ret, - (thd->db ? thd->db : "(null)"), - thd->query()); + WSREP_WARN ("SET desync failed %d for schema: %s, query: %s", + ret, thd->get_db(), thd->query()); my_error (ER_CANNOT_USER, MYF(0), "'desync'", thd->query()); return true; } @@ -615,8 +614,7 @@ bool wsrep_desync_check (sys_var *self, THD* thd, set_var* var) ret = wsrep->resync (wsrep); if (ret != WSREP_OK) { WSREP_WARN ("SET resync failed %d for schema: %s, query: %s", ret, - (thd->db ? thd->db : "(null)"), - thd->query()); + thd->get_db(), thd->query()); my_error (ER_CANNOT_USER, MYF(0), "'resync'", thd->query()); return true; } |