Manual merge from mysql-trunk-merge.

This commit is contained in:
Alexander Nozdrin 2009-11-05 23:28:35 +03:00
commit f620cae974
32 changed files with 187 additions and 157 deletions

View File

@ -1435,7 +1435,7 @@ Event_job_data::execute(THD *thd, bool drop)
thd->set_query(sp_sql.c_ptr_safe(), sp_sql.length()); thd->set_query(sp_sql.c_ptr_safe(), sp_sql.length());
{ {
Parser_state parser_state(thd, thd->query, thd->query_length); Parser_state parser_state(thd, thd->query(), thd->query_length());
lex_start(thd); lex_start(thd);
if (parse_sql(thd, & parser_state, creation_ctx)) if (parse_sql(thd, & parser_state, creation_ctx))

View File

@ -465,7 +465,7 @@ Events::create_event(THD *thd, Event_parse_data *parse_data,
if (!dropped) if (!dropped)
{ {
/* Binlog the create event. */ /* Binlog the create event. */
DBUG_ASSERT(thd->query && thd->query_length); DBUG_ASSERT(thd->query() && thd->query_length());
String log_query; String log_query;
if (create_query_string(thd, &log_query)) if (create_query_string(thd, &log_query))
{ {
@ -595,8 +595,8 @@ Events::update_event(THD *thd, Event_parse_data *parse_data,
event_queue->update_event(thd, parse_data->dbname, parse_data->name, event_queue->update_event(thd, parse_data->dbname, parse_data->name,
new_element); new_element);
/* Binlog the alter event. */ /* Binlog the alter event. */
DBUG_ASSERT(thd->query && thd->query_length); DBUG_ASSERT(thd->query() && thd->query_length());
write_bin_log(thd, TRUE, thd->query, thd->query_length); write_bin_log(thd, TRUE, thd->query(), thd->query_length());
} }
} }
pthread_mutex_unlock(&LOCK_event_metadata); pthread_mutex_unlock(&LOCK_event_metadata);
@ -670,8 +670,8 @@ Events::drop_event(THD *thd, LEX_STRING dbname, LEX_STRING name, bool if_exists)
if (event_queue) if (event_queue)
event_queue->drop_event(thd, dbname, name); event_queue->drop_event(thd, dbname, name);
/* Binlog the drop event. */ /* Binlog the drop event. */
DBUG_ASSERT(thd->query && thd->query_length); DBUG_ASSERT(thd->query() && thd->query_length());
write_bin_log(thd, TRUE, thd->query, thd->query_length); write_bin_log(thd, TRUE, thd->query(), thd->query_length());
} }
pthread_mutex_unlock(&LOCK_event_metadata); pthread_mutex_unlock(&LOCK_event_metadata);
DBUG_RETURN(ret); DBUG_RETURN(ret);

View File

@ -5580,7 +5580,7 @@ int ha_ndbcluster::create(const char *name,
if (share && !do_event_op) if (share && !do_event_op)
share->flags|= NSF_NO_BINLOG; share->flags|= NSF_NO_BINLOG;
ndbcluster_log_schema_op(thd, share, ndbcluster_log_schema_op(thd, share,
thd->query, thd->query_length, thd->query(), thd->query_length(),
share->db, share->table_name, share->db, share->table_name,
m_table->getObjectId(), m_table->getObjectId(),
m_table->getObjectVersion(), m_table->getObjectVersion(),
@ -6022,7 +6022,8 @@ int ha_ndbcluster::rename_table(const char *from, const char *to)
*/ */
if (!is_old_table_tmpfile) if (!is_old_table_tmpfile)
ndbcluster_log_schema_op(current_thd, share, ndbcluster_log_schema_op(current_thd, share,
current_thd->query, current_thd->query_length, current_thd->query(),
current_thd->query_length(),
old_dbname, m_tabname, old_dbname, m_tabname,
ndb_table_id, ndb_table_version, ndb_table_id, ndb_table_version,
SOT_RENAME_TABLE, SOT_RENAME_TABLE,
@ -6217,7 +6218,7 @@ retry_temporary_error1:
current_thd->lex->sql_command != SQLCOM_TRUNCATE) current_thd->lex->sql_command != SQLCOM_TRUNCATE)
{ {
ndbcluster_log_schema_op(thd, share, ndbcluster_log_schema_op(thd, share,
thd->query, thd->query_length, thd->query(), thd->query_length(),
share->db, share->table_name, share->db, share->table_name,
ndb_table_id, ndb_table_version, ndb_table_id, ndb_table_version,
SOT_DROP_TABLE, 0, 0, 1); SOT_DROP_TABLE, 0, 0, 1);
@ -6939,7 +6940,7 @@ static void ndbcluster_drop_database(handlerton *hton, char *path)
THD *thd= current_thd; THD *thd= current_thd;
ha_ndbcluster::set_dbname(path, db); ha_ndbcluster::set_dbname(path, db);
ndbcluster_log_schema_op(thd, 0, ndbcluster_log_schema_op(thd, 0,
thd->query, thd->query_length, thd->query(), thd->query_length(),
db, "", 0, 0, SOT_DROP_DB, 0, 0, 0); db, "", 0, 0, SOT_DROP_DB, 0, 0, 0);
#endif #endif
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
@ -10348,13 +10349,13 @@ int ndbcluster_alter_tablespace(handlerton *hton,
#ifdef HAVE_NDB_BINLOG #ifdef HAVE_NDB_BINLOG
if (is_tablespace) if (is_tablespace)
ndbcluster_log_schema_op(thd, 0, ndbcluster_log_schema_op(thd, 0,
thd->query, thd->query_length, thd->query(), thd->query_length(),
"", alter_info->tablespace_name, "", alter_info->tablespace_name,
0, 0, 0, 0,
SOT_TABLESPACE, 0, 0, 0); SOT_TABLESPACE, 0, 0, 0);
else else
ndbcluster_log_schema_op(thd, 0, ndbcluster_log_schema_op(thd, 0,
thd->query, thd->query_length, thd->query(), thd->query_length(),
"", alter_info->logfile_group_name, "", alter_info->logfile_group_name,
0, 0, 0, 0,
SOT_LOGFILE_GROUP, 0, 0, 0); SOT_LOGFILE_GROUP, 0, 0, 0);

View File

@ -241,8 +241,8 @@ static void dbug_print_table(const char *info, TABLE *table)
static void run_query(THD *thd, char *buf, char *end, static void run_query(THD *thd, char *buf, char *end,
const int *no_print_error, my_bool disable_binlog) const int *no_print_error, my_bool disable_binlog)
{ {
ulong save_thd_query_length= thd->query_length; ulong save_thd_query_length= thd->query_length();
char *save_thd_query= thd->query; char *save_thd_query= thd->query();
ulong save_thread_id= thd->variables.pseudo_thread_id; ulong save_thread_id= thd->variables.pseudo_thread_id;
struct system_status_var save_thd_status_var= thd->status_var; struct system_status_var save_thd_status_var= thd->status_var;
THD_TRANS save_thd_transaction_all= thd->transaction.all; THD_TRANS save_thd_transaction_all= thd->transaction.all;
@ -259,12 +259,12 @@ static void run_query(THD *thd, char *buf, char *end,
if (disable_binlog) if (disable_binlog)
thd->options&= ~OPTION_BIN_LOG; thd->options&= ~OPTION_BIN_LOG;
DBUG_PRINT("query", ("%s", thd->query)); DBUG_PRINT("query", ("%s", thd->query()));
DBUG_ASSERT(!thd->in_sub_stmt); DBUG_ASSERT(!thd->in_sub_stmt);
DBUG_ASSERT(!thd->prelocked_mode); DBUG_ASSERT(!thd->prelocked_mode);
mysql_parse(thd, thd->query, thd->query_length, &found_semicolon); mysql_parse(thd, thd->query(), thd->query_length(), &found_semicolon);
if (no_print_error && thd->is_slave_error) if (no_print_error && thd->is_slave_error)
{ {

View File

@ -1730,7 +1730,7 @@ static int binlog_savepoint_set(handlerton *hton, THD *thd, void *sv)
int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED); int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
int const error= int const error=
thd->binlog_query(THD::STMT_QUERY_TYPE, thd->binlog_query(THD::STMT_QUERY_TYPE,
thd->query, thd->query_length, TRUE, FALSE, errcode); thd->query(), thd->query_length(), TRUE, FALSE, errcode);
DBUG_RETURN(error); DBUG_RETURN(error);
} }
@ -1749,7 +1749,7 @@ static int binlog_savepoint_rollback(handlerton *hton, THD *thd, void *sv)
int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED); int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
int error= int error=
thd->binlog_query(THD::STMT_QUERY_TYPE, thd->binlog_query(THD::STMT_QUERY_TYPE,
thd->query, thd->query_length, TRUE, FALSE, errcode); thd->query(), thd->query_length(), TRUE, FALSE, errcode);
DBUG_RETURN(error); DBUG_RETURN(error);
} }
binlog_trans_log_truncate(thd, *(my_off_t*)sv); binlog_trans_log_truncate(thd, *(my_off_t*)sv);

View File

@ -3060,7 +3060,7 @@ int Query_log_event::do_apply_event(Relay_log_info const *rli,
thd->query_id = next_query_id(); thd->query_id = next_query_id();
VOID(pthread_mutex_unlock(&LOCK_thread_count)); VOID(pthread_mutex_unlock(&LOCK_thread_count));
thd->variables.pseudo_thread_id= thread_id; // for temp tables thd->variables.pseudo_thread_id= thread_id; // for temp tables
DBUG_PRINT("query",("%s",thd->query)); DBUG_PRINT("query",("%s", thd->query()));
if (ignored_error_code((expected_error= error_code)) || if (ignored_error_code((expected_error= error_code)) ||
!unexpected_error_code(expected_error)) !unexpected_error_code(expected_error))
@ -3154,7 +3154,7 @@ int Query_log_event::do_apply_event(Relay_log_info const *rli,
/* Execute the query (note that we bypass dispatch_command()) */ /* Execute the query (note that we bypass dispatch_command()) */
const char* found_semicolon= NULL; const char* found_semicolon= NULL;
mysql_parse(thd, thd->query, thd->query_length, &found_semicolon); mysql_parse(thd, thd->query(), thd->query_length(), &found_semicolon);
log_slow_statement(thd); log_slow_statement(thd);
} }
else else
@ -3166,7 +3166,7 @@ int Query_log_event::do_apply_event(Relay_log_info const *rli,
we exit gracefully; otherwise we warn about the bad error and tell DBA we exit gracefully; otherwise we warn about the bad error and tell DBA
to check/fix it. to check/fix it.
*/ */
if (mysql_test_parse_for_slave(thd, thd->query, thd->query_length)) if (mysql_test_parse_for_slave(thd, thd->query(), thd->query_length()))
clear_all_errors(thd, const_cast<Relay_log_info*>(rli)); /* Can ignore query */ clear_all_errors(thd, const_cast<Relay_log_info*>(rli)); /* Can ignore query */
else else
{ {
@ -3176,7 +3176,7 @@ Query partially completed on the master (error on master: %d) \
and was aborted. There is a chance that your master is inconsistent at this \ and was aborted. There is a chance that your master is inconsistent at this \
point. If you are sure that your master is ok, run this query manually on the \ point. If you are sure that your master is ok, run this query manually on the \
slave and then restart the slave with SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; \ slave and then restart the slave with SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; \
START SLAVE; . Query: '%s'", expected_error, thd->query); START SLAVE; . Query: '%s'", expected_error, thd->query());
thd->is_slave_error= 1; thd->is_slave_error= 1;
} }
goto end; goto end;
@ -3184,7 +3184,7 @@ START SLAVE; . Query: '%s'", expected_error, thd->query);
/* If the query was not ignored, it is printed to the general log */ /* If the query was not ignored, it is printed to the general log */
if (!thd->is_error() || thd->stmt_da->sql_errno() != ER_SLAVE_IGNORED_TABLE) if (!thd->is_error() || thd->stmt_da->sql_errno() != ER_SLAVE_IGNORED_TABLE)
general_log_write(thd, COM_QUERY, thd->query, thd->query_length); general_log_write(thd, COM_QUERY, thd->query(), thd->query_length());
compare_errors: compare_errors:
@ -4531,8 +4531,8 @@ int Load_log_event::do_apply_event(NET* net, Relay_log_info const *rli,
new_db.length= db_len; new_db.length= db_len;
new_db.str= (char *) rpl_filter->get_rewrite_db(db, &new_db.length); new_db.str= (char *) rpl_filter->get_rewrite_db(db, &new_db.length);
thd->set_db(new_db.str, new_db.length); thd->set_db(new_db.str, new_db.length);
DBUG_ASSERT(thd->query == 0); DBUG_ASSERT(thd->query() == 0);
thd->query_length= 0; // Should not be needed thd->set_query_inner(NULL, 0); // Should not be needed
thd->is_slave_error= 0; thd->is_slave_error= 0;
clear_all_errors(thd, const_cast<Relay_log_info*>(rli)); clear_all_errors(thd, const_cast<Relay_log_info*>(rli));

View File

@ -2526,7 +2526,7 @@ terribly wrong...\n");
} }
fprintf(stderr, "Trying to get some variables.\n\ fprintf(stderr, "Trying to get some variables.\n\
Some pointers may be invalid and cause the dump to abort...\n"); Some pointers may be invalid and cause the dump to abort...\n");
my_safe_print_str("thd->query", thd->query, 1024); my_safe_print_str("thd->query", thd->query(), 1024);
fprintf(stderr, "thd->thread_id=%lu\n", (ulong) thd->thread_id); fprintf(stderr, "thd->thread_id=%lu\n", (ulong) thd->thread_id);
fprintf(stderr, "thd->killed=%s\n", kreason); fprintf(stderr, "thd->killed=%s\n", kreason);
} }

View File

@ -1552,7 +1552,8 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db,
thd->db = (char*)db; thd->db = (char*)db;
DBUG_ASSERT(thd->db != 0); DBUG_ASSERT(thd->db != 0);
thd->db_length= strlen(thd->db); thd->db_length= strlen(thd->db);
mysql_parse(thd, thd->query, packet_len, &found_semicolon); // run create table /* run create table */
mysql_parse(thd, thd->query(), packet_len, &found_semicolon);
thd->db = save_db; // leave things the way the were before thd->db = save_db; // leave things the way the were before
thd->db_length= save_db_length; thd->db_length= save_db_length;
thd->options = save_options; thd->options = save_options;

View File

@ -1005,7 +1005,7 @@ sp_drop_routine(THD *thd, int type, sp_name *name)
if (ret == SP_OK) if (ret == SP_OK)
{ {
write_bin_log(thd, TRUE, thd->query, thd->query_length); write_bin_log(thd, TRUE, thd->query(), thd->query_length());
sp_cache_invalidate(); sp_cache_invalidate();
} }
@ -1075,7 +1075,7 @@ sp_update_routine(THD *thd, int type, sp_name *name, st_sp_chistics *chistics)
if (ret == SP_OK) if (ret == SP_OK)
{ {
write_bin_log(thd, TRUE, thd->query, thd->query_length); write_bin_log(thd, TRUE, thd->query(), thd->query_length());
sp_cache_invalidate(); sp_cache_invalidate();
} }

View File

@ -2859,8 +2859,8 @@ sp_instr_stmt::execute(THD *thd, uint *nextp)
DBUG_ENTER("sp_instr_stmt::execute"); DBUG_ENTER("sp_instr_stmt::execute");
DBUG_PRINT("info", ("command: %d", m_lex_keeper.sql_command())); DBUG_PRINT("info", ("command: %d", m_lex_keeper.sql_command()));
query= thd->query; query= thd->query();
query_length= thd->query_length; query_length= thd->query_length();
#if defined(ENABLED_PROFILING) #if defined(ENABLED_PROFILING)
/* This s-p instr is profilable and will be captured. */ /* This s-p instr is profilable and will be captured. */
thd->profiling.set_query_source(m_query.str, m_query.length); thd->profiling.set_query_source(m_query.str, m_query.length);
@ -2873,10 +2873,11 @@ sp_instr_stmt::execute(THD *thd, uint *nextp)
queries with SP vars can't be cached) queries with SP vars can't be cached)
*/ */
if (unlikely((thd->options & OPTION_LOG_OFF)==0)) if (unlikely((thd->options & OPTION_LOG_OFF)==0))
general_log_write(thd, COM_QUERY, thd->query, thd->query_length); general_log_write(thd, COM_QUERY, thd->query(), thd->query_length());
if (query_cache_send_result_to_client(thd, if (query_cache_send_result_to_client(thd,
thd->query, thd->query_length) <= 0) thd->query(),
thd->query_length()) <= 0)
{ {
res= m_lex_keeper.reset_lex_and_exec_core(thd, nextp, FALSE, this); res= m_lex_keeper.reset_lex_and_exec_core(thd, nextp, FALSE, this);

View File

@ -3187,7 +3187,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list,
if (!result) /* success */ if (!result) /* success */
{ {
write_bin_log(thd, TRUE, thd->query, thd->query_length); write_bin_log(thd, TRUE, thd->query(), thd->query_length());
} }
rw_unlock(&LOCK_grant); rw_unlock(&LOCK_grant);
@ -3352,7 +3352,7 @@ bool mysql_routine_grant(THD *thd, TABLE_LIST *table_list, bool is_proc,
if (write_to_binlog) if (write_to_binlog)
{ {
write_bin_log(thd, TRUE, thd->query, thd->query_length); write_bin_log(thd, TRUE, thd->query(), thd->query_length());
} }
rw_unlock(&LOCK_grant); rw_unlock(&LOCK_grant);
@ -3464,7 +3464,7 @@ bool mysql_grant(THD *thd, const char *db, List <LEX_USER> &list,
if (!result) if (!result)
{ {
write_bin_log(thd, TRUE, thd->query, thd->query_length); write_bin_log(thd, TRUE, thd->query(), thd->query_length());
} }
rw_unlock(&LOCK_grant); rw_unlock(&LOCK_grant);
@ -5776,7 +5776,7 @@ bool mysql_create_user(THD *thd, List <LEX_USER> &list)
my_error(ER_CANNOT_USER, MYF(0), "CREATE USER", wrong_users.c_ptr_safe()); my_error(ER_CANNOT_USER, MYF(0), "CREATE USER", wrong_users.c_ptr_safe());
if (some_users_created) if (some_users_created)
write_bin_log(thd, FALSE, thd->query, thd->query_length); write_bin_log(thd, FALSE, thd->query(), thd->query_length());
rw_unlock(&LOCK_grant); rw_unlock(&LOCK_grant);
close_thread_tables(thd); close_thread_tables(thd);
@ -5849,7 +5849,7 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list)
my_error(ER_CANNOT_USER, MYF(0), "DROP USER", wrong_users.c_ptr_safe()); my_error(ER_CANNOT_USER, MYF(0), "DROP USER", wrong_users.c_ptr_safe());
if (some_users_deleted) if (some_users_deleted)
write_bin_log(thd, FALSE, thd->query, thd->query_length); write_bin_log(thd, FALSE, thd->query(), thd->query_length());
rw_unlock(&LOCK_grant); rw_unlock(&LOCK_grant);
close_thread_tables(thd); close_thread_tables(thd);
@ -5934,7 +5934,7 @@ bool mysql_rename_user(THD *thd, List <LEX_USER> &list)
my_error(ER_CANNOT_USER, MYF(0), "RENAME USER", wrong_users.c_ptr_safe()); my_error(ER_CANNOT_USER, MYF(0), "RENAME USER", wrong_users.c_ptr_safe());
if (some_users_renamed && mysql_bin_log.is_open()) if (some_users_renamed && mysql_bin_log.is_open())
write_bin_log(thd, FALSE, thd->query, thd->query_length); write_bin_log(thd, FALSE, thd->query(), thd->query_length());
rw_unlock(&LOCK_grant); rw_unlock(&LOCK_grant);
close_thread_tables(thd); close_thread_tables(thd);
@ -6116,7 +6116,7 @@ bool mysql_revoke_all(THD *thd, List <LEX_USER> &list)
VOID(pthread_mutex_unlock(&acl_cache->lock)); VOID(pthread_mutex_unlock(&acl_cache->lock));
write_bin_log(thd, FALSE, thd->query, thd->query_length); write_bin_log(thd, FALSE, thd->query(), thd->query_length());
rw_unlock(&LOCK_grant); rw_unlock(&LOCK_grant);
close_thread_tables(thd); close_thread_tables(thd);

View File

@ -1140,8 +1140,8 @@ void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used)
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
uint8 tables_type= 0; uint8 tables_type= 0;
if ((local_tables= is_cacheable(thd, thd->query_length, if ((local_tables= is_cacheable(thd, thd->query_length(),
thd->query, thd->lex, tables_used, thd->query(), thd->lex, tables_used,
&tables_type))) &tables_type)))
{ {
NET *net= &thd->net; NET *net= &thd->net;
@ -1233,7 +1233,8 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d",
/* Key is query + database + flag */ /* Key is query + database + flag */
if (thd->db_length) if (thd->db_length)
{ {
memcpy(thd->query+thd->query_length+1, thd->db, thd->db_length); memcpy(thd->query() + thd->query_length() + 1, thd->db,
thd->db_length);
DBUG_PRINT("qcache", ("database: %s length: %u", DBUG_PRINT("qcache", ("database: %s length: %u",
thd->db, (unsigned) thd->db_length)); thd->db, (unsigned) thd->db_length));
} }
@ -1241,24 +1242,24 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d",
{ {
DBUG_PRINT("qcache", ("No active database")); DBUG_PRINT("qcache", ("No active database"));
} }
tot_length= thd->query_length + thd->db_length + 1 + tot_length= thd->query_length() + thd->db_length + 1 +
QUERY_CACHE_FLAGS_SIZE; QUERY_CACHE_FLAGS_SIZE;
/* /*
We should only copy structure (don't use it location directly) We should only copy structure (don't use it location directly)
because of alignment issue because of alignment issue
*/ */
memcpy((void *)(thd->query + (tot_length - QUERY_CACHE_FLAGS_SIZE)), memcpy((void*) (thd->query() + (tot_length - QUERY_CACHE_FLAGS_SIZE)),
&flags, QUERY_CACHE_FLAGS_SIZE); &flags, QUERY_CACHE_FLAGS_SIZE);
/* Check if another thread is processing the same query? */ /* Check if another thread is processing the same query? */
Query_cache_block *competitor = (Query_cache_block *) Query_cache_block *competitor = (Query_cache_block *)
my_hash_search(&queries, (uchar*) thd->query, tot_length); my_hash_search(&queries, (uchar*) thd->query(), tot_length);
DBUG_PRINT("qcache", ("competitor 0x%lx", (ulong) competitor)); DBUG_PRINT("qcache", ("competitor 0x%lx", (ulong) competitor));
if (competitor == 0) if (competitor == 0)
{ {
/* Query is not in cache and no one is working with it; Store it */ /* Query is not in cache and no one is working with it; Store it */
Query_cache_block *query_block; Query_cache_block *query_block;
query_block= write_block_data(tot_length, (uchar*) thd->query, query_block= write_block_data(tot_length, (uchar*) thd->query(),
ALIGN_SIZE(sizeof(Query_cache_query)), ALIGN_SIZE(sizeof(Query_cache_query)),
Query_cache_block::QUERY, local_tables); Query_cache_block::QUERY, local_tables);
if (query_block != 0) if (query_block != 0)

View File

@ -401,14 +401,14 @@ char *thd_security_context(THD *thd, char *buffer, unsigned int length,
str.append(proc_info); str.append(proc_info);
} }
if (thd->query) if (thd->query())
{ {
if (max_query_len < 1) if (max_query_len < 1)
len= thd->query_length; len= thd->query_length();
else else
len= min(thd->query_length, max_query_len); len= min(thd->query_length(), max_query_len);
str.append('\n'); str.append('\n');
str.append(thd->query, len); str.append(thd->query(), len);
} }
if (str.c_ptr_safe() == buffer) if (str.c_ptr_safe() == buffer)
return buffer; return buffer;
@ -2515,12 +2515,12 @@ Statement::Statement(LEX *lex_arg, MEM_ROOT *mem_root_arg,
id(id_arg), id(id_arg),
mark_used_columns(MARK_COLUMNS_READ), mark_used_columns(MARK_COLUMNS_READ),
lex(lex_arg), lex(lex_arg),
query(0),
query_length(0),
cursor(0), cursor(0),
db(NULL), db(NULL),
db_length(0) db_length(0)
{ {
query_string.length= 0;
query_string.str= NULL;
name.str= NULL; name.str= NULL;
} }
@ -2536,8 +2536,7 @@ void Statement::set_statement(Statement *stmt)
id= stmt->id; id= stmt->id;
mark_used_columns= stmt->mark_used_columns; mark_used_columns= stmt->mark_used_columns;
lex= stmt->lex; lex= stmt->lex;
query= stmt->query; query_string= stmt->query_string;
query_length= stmt->query_length;
cursor= stmt->cursor; cursor= stmt->cursor;
} }
@ -2561,6 +2560,15 @@ void Statement::restore_backup_statement(Statement *stmt, Statement *backup)
} }
/** Assign a new value to thd->query. */
void Statement::set_query_inner(char *query_arg, uint32 query_length_arg)
{
query_string.str= query_arg;
query_string.length= query_length_arg;
}
void THD::end_statement() void THD::end_statement()
{ {
/* Cleanup SQL processing state to reuse this statement in next query. */ /* Cleanup SQL processing state to reuse this statement in next query. */
@ -3074,9 +3082,24 @@ extern "C" struct charset_info_st *thd_charset(MYSQL_THD thd)
return(thd->charset()); return(thd->charset());
} }
/**
OBSOLETE : there's no way to ensure the string is null terminated.
Use thd_query_string instead()
*/
extern "C" char **thd_query(MYSQL_THD thd) extern "C" char **thd_query(MYSQL_THD thd)
{ {
return(&thd->query); return(&thd->query_string.str);
}
/**
Get the current query string for the thread.
@param The MySQL internal thread pointer
@return query string and length. May be non-null-terminated.
*/
extern "C" LEX_STRING * thd_query_string (MYSQL_THD thd)
{
return(&thd->query_string);
} }
extern "C" int thd_slave_thread(const MYSQL_THD thd) extern "C" int thd_slave_thread(const MYSQL_THD thd)
@ -3255,8 +3278,7 @@ void THD::set_statement(Statement *stmt)
void THD::set_query(char *query_arg, uint32 query_length_arg) void THD::set_query(char *query_arg, uint32 query_length_arg)
{ {
pthread_mutex_lock(&LOCK_thd_data); pthread_mutex_lock(&LOCK_thd_data);
query= query_arg; set_query_inner(query_arg, query_length_arg);
query_length= query_length_arg;
pthread_mutex_unlock(&LOCK_thd_data); pthread_mutex_unlock(&LOCK_thd_data);
} }

View File

@ -676,10 +676,13 @@ public:
This printing is needed at least in SHOW PROCESSLIST and SHOW This printing is needed at least in SHOW PROCESSLIST and SHOW
ENGINE INNODB STATUS. ENGINE INNODB STATUS.
*/ */
char *query; LEX_STRING query_string;
uint32 query_length; // current query length
Server_side_cursor *cursor; Server_side_cursor *cursor;
inline char *query() { return query_string.str; }
inline uint32 query_length() { return query_string.length; }
void set_query_inner(char *query_arg, uint32 query_length_arg);
/** /**
Name of the current (default) database. Name of the current (default) database.

View File

@ -704,7 +704,7 @@ not_silent:
char *query; char *query;
uint query_length; uint query_length;
if (!thd->query) // Only in replication if (!thd->query()) // Only in replication
{ {
query= tmp_query; query= tmp_query;
query_length= (uint) (strxmov(tmp_query,"create database `", query_length= (uint) (strxmov(tmp_query,"create database `",
@ -712,8 +712,8 @@ not_silent:
} }
else else
{ {
query= thd->query; query= thd->query();
query_length= thd->query_length; query_length= thd->query_length();
} }
ha_binlog_log_query(thd, 0, LOGCOM_CREATE_DB, ha_binlog_log_query(thd, 0, LOGCOM_CREATE_DB,
@ -806,13 +806,13 @@ bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create_info)
} }
ha_binlog_log_query(thd, 0, LOGCOM_ALTER_DB, ha_binlog_log_query(thd, 0, LOGCOM_ALTER_DB,
thd->query, thd->query_length, thd->query(), thd->query_length(),
db, ""); db, "");
if (mysql_bin_log.is_open()) if (mysql_bin_log.is_open())
{ {
int errcode= query_error_code(thd, TRUE); int errcode= query_error_code(thd, TRUE);
Query_log_event qinfo(thd, thd->query, thd->query_length, 0, Query_log_event qinfo(thd, thd->query(), thd->query_length(), 0,
/* suppress_use */ TRUE, errcode); /* suppress_use */ TRUE, errcode);
/* /*
@ -949,7 +949,7 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
{ {
const char *query; const char *query;
ulong query_length; ulong query_length;
if (!thd->query) if (!thd->query())
{ {
/* The client used the old obsolete mysql_drop_db() call */ /* The client used the old obsolete mysql_drop_db() call */
query= path; query= path;
@ -958,8 +958,8 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
} }
else else
{ {
query =thd->query; query= thd->query();
query_length= thd->query_length; query_length= thd->query_length();
} }
if (mysql_bin_log.is_open()) if (mysql_bin_log.is_open())
{ {
@ -1965,7 +1965,7 @@ bool mysql_upgrade_db(THD *thd, LEX_STRING *old_db)
if (mysql_bin_log.is_open()) if (mysql_bin_log.is_open())
{ {
int errcode= query_error_code(thd, TRUE); int errcode= query_error_code(thd, TRUE);
Query_log_event qinfo(thd, thd->query, thd->query_length, Query_log_event qinfo(thd, thd->query(), thd->query_length(),
0, TRUE, errcode); 0, TRUE, errcode);
thd->clear_error(); thd->clear_error();
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);

View File

@ -413,7 +413,7 @@ cleanup:
therefore be treated as a DDL. therefore be treated as a DDL.
*/ */
int log_result= thd->binlog_query(query_type, int log_result= thd->binlog_query(query_type,
thd->query, thd->query_length, thd->query(), thd->query_length(),
is_trans, FALSE, errcode); is_trans, FALSE, errcode);
if (log_result) if (log_result)
@ -850,7 +850,7 @@ void multi_delete::abort()
{ {
int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED); int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
thd->binlog_query(THD::ROW_QUERY_TYPE, thd->binlog_query(THD::ROW_QUERY_TYPE,
thd->query, thd->query_length, thd->query(), thd->query_length(),
transactional_tables, FALSE, errcode); transactional_tables, FALSE, errcode);
} }
thd->transaction.all.modified_non_trans_table= true; thd->transaction.all.modified_non_trans_table= true;
@ -1024,7 +1024,7 @@ bool multi_delete::send_eof()
else else
errcode= query_error_code(thd, killed_status == THD::NOT_KILLED); errcode= query_error_code(thd, killed_status == THD::NOT_KILLED);
if (thd->binlog_query(THD::ROW_QUERY_TYPE, if (thd->binlog_query(THD::ROW_QUERY_TYPE,
thd->query, thd->query_length, thd->query(), thd->query_length(),
transactional_tables, FALSE, errcode) && transactional_tables, FALSE, errcode) &&
!normal_tables) !normal_tables)
{ {
@ -1181,7 +1181,7 @@ end:
TRUNCATE must always be statement-based binlogged (not row-based) so TRUNCATE must always be statement-based binlogged (not row-based) so
we don't test current_stmt_binlog_row_based. we don't test current_stmt_binlog_row_based.
*/ */
write_bin_log(thd, TRUE, thd->query, thd->query_length); write_bin_log(thd, TRUE, thd->query(), thd->query_length());
my_ok(thd); // This should return record count my_ok(thd); // This should return record count
} }
VOID(pthread_mutex_lock(&LOCK_open)); VOID(pthread_mutex_lock(&LOCK_open));

View File

@ -585,7 +585,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
Name_resolution_context *context; Name_resolution_context *context;
Name_resolution_context_state ctx_state; Name_resolution_context_state ctx_state;
#ifndef EMBEDDED_LIBRARY #ifndef EMBEDDED_LIBRARY
char *query= thd->query; char *query= thd->query();
/* /*
log_on is about delayed inserts only. log_on is about delayed inserts only.
By default, both logs are enabled (this won't cause problems if the server By default, both logs are enabled (this won't cause problems if the server
@ -819,7 +819,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
#ifndef EMBEDDED_LIBRARY #ifndef EMBEDDED_LIBRARY
if (lock_type == TL_WRITE_DELAYED) if (lock_type == TL_WRITE_DELAYED)
{ {
LEX_STRING const st_query = { query, thd->query_length }; LEX_STRING const st_query = { query, thd->query_length() };
error=write_delayed(thd, table, duplic, st_query, ignore, log_on); error=write_delayed(thd, table, duplic, st_query, ignore, log_on);
query=0; query=0;
} }
@ -912,7 +912,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
*/ */
DBUG_ASSERT(thd->killed != THD::KILL_BAD_DATA || error > 0); DBUG_ASSERT(thd->killed != THD::KILL_BAD_DATA || error > 0);
if (thd->binlog_query(THD::ROW_QUERY_TYPE, if (thd->binlog_query(THD::ROW_QUERY_TYPE,
thd->query, thd->query_length, thd->query(), thd->query_length(),
transactional_table, FALSE, transactional_table, FALSE,
errcode)) errcode))
{ {
@ -1785,7 +1785,7 @@ public:
pthread_cond_destroy(&cond); pthread_cond_destroy(&cond);
pthread_cond_destroy(&cond_client); pthread_cond_destroy(&cond_client);
thd.unlink(); // Must be unlinked under lock thd.unlink(); // Must be unlinked under lock
x_free(thd.query); x_free(thd.query());
thd.security_ctx->user= thd.security_ctx->host=0; thd.security_ctx->user= thd.security_ctx->host=0;
thread_count--; thread_count--;
delayed_insert_threads--; delayed_insert_threads--;
@ -1931,7 +1931,7 @@ bool delayed_get_table(THD *thd, TABLE_LIST *table_list)
pthread_mutex_unlock(&LOCK_thread_count); pthread_mutex_unlock(&LOCK_thread_count);
di->thd.set_db(table_list->db, (uint) strlen(table_list->db)); 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)), 0); di->thd.set_query(my_strdup(table_list->table_name, MYF(MY_WME)), 0);
if (di->thd.db == NULL || di->thd.query == NULL) if (di->thd.db == NULL || di->thd.query() == NULL)
{ {
/* The error is reported */ /* The error is reported */
delete di; delete di;
@ -1940,7 +1940,7 @@ bool delayed_get_table(THD *thd, TABLE_LIST *table_list)
} }
di->table_list= *table_list; // Needed to open table di->table_list= *table_list; // Needed to open table
/* Replace volatile strings with local copies */ /* Replace volatile strings with local copies */
di->table_list.alias= di->table_list.table_name= di->thd.query; di->table_list.alias= di->table_list.table_name= di->thd.query();
di->table_list.db= di->thd.db; di->table_list.db= di->thd.db;
di->lock(); di->lock();
pthread_mutex_lock(&di->mutex); pthread_mutex_lock(&di->mutex);
@ -3273,7 +3273,7 @@ bool select_insert::send_eof()
else else
errcode= query_error_code(thd, killed_status == THD::NOT_KILLED); errcode= query_error_code(thd, killed_status == THD::NOT_KILLED);
thd->binlog_query(THD::ROW_QUERY_TYPE, thd->binlog_query(THD::ROW_QUERY_TYPE,
thd->query, thd->query_length, thd->query(), thd->query_length(),
trans_table, FALSE, errcode); trans_table, FALSE, errcode);
} }
table->file->ha_release_auto_increment(); table->file->ha_release_auto_increment();
@ -3345,7 +3345,8 @@ void select_insert::abort() {
if (mysql_bin_log.is_open()) if (mysql_bin_log.is_open())
{ {
int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED); int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
thd->binlog_query(THD::ROW_QUERY_TYPE, thd->query, thd->query_length, thd->binlog_query(THD::ROW_QUERY_TYPE, thd->query(),
thd->query_length(),
transactional_table, FALSE, errcode); transactional_table, FALSE, errcode);
} }
if (!thd->current_stmt_binlog_row_based && !can_rollback_data()) if (!thd->current_stmt_binlog_row_based && !can_rollback_data())

View File

@ -692,13 +692,12 @@ static bool write_execute_load_query_log_event(THD *thd, sql_exchange* ex,
strcpy(end, p); strcpy(end, p);
end += pl; end += pl;
thd->query_length= end - load_data_query; thd->set_query_inner(load_data_query, end - load_data_query);
thd->query= load_data_query;
Execute_load_query_log_event Execute_load_query_log_event
e(thd, thd->query, thd->query_length, e(thd, thd->query(), thd->query_length(),
(uint) ((char*)fname_start - (char*)thd->query - 1), (uint) ((char*) fname_start - (char*) thd->query() - 1),
(uint) ((char*)fname_end - (char*)thd->query), (uint) ((char*) fname_end - (char*) thd->query()),
(duplicates == DUP_REPLACE) ? LOAD_DUP_REPLACE : (duplicates == DUP_REPLACE) ? LOAD_DUP_REPLACE :
(ignore ? LOAD_DUP_IGNORE : LOAD_DUP_ERROR), (ignore ? LOAD_DUP_IGNORE : LOAD_DUP_ERROR),
transactional_table, FALSE, errcode); transactional_table, FALSE, errcode);

View File

@ -478,10 +478,10 @@ static void handle_bootstrap_impl(THD *thd)
thd->db_length + 1 + thd->db_length + 1 +
QUERY_CACHE_FLAGS_SIZE); QUERY_CACHE_FLAGS_SIZE);
thd->set_query(query, length); thd->set_query(query, length);
DBUG_PRINT("query",("%-.4096s",thd->query)); DBUG_PRINT("query",("%-.4096s",thd->query()));
#if defined(ENABLED_PROFILING) #if defined(ENABLED_PROFILING)
thd->profiling.start_new_query(); thd->profiling.start_new_query();
thd->profiling.set_query_source(thd->query, length); thd->profiling.set_query_source(thd->query(), length);
#endif #endif
/* /*
@ -490,7 +490,7 @@ static void handle_bootstrap_impl(THD *thd)
*/ */
thd->query_id=next_query_id(); thd->query_id=next_query_id();
thd->set_time(); thd->set_time();
mysql_parse(thd, thd->query, length, & found_semicolon); mysql_parse(thd, thd->query(), length, & found_semicolon);
close_thread_tables(thd); // Free tables close_thread_tables(thd); // Free tables
bootstrap_error= thd->is_error(); bootstrap_error= thd->is_error();
@ -1217,20 +1217,20 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
(char *) (thd->db ? thd->db : ""), (char *) (thd->db ? thd->db : ""),
thd->security_ctx->priv_user, thd->security_ctx->priv_user,
(char *) thd->security_ctx->host_or_ip); (char *) thd->security_ctx->host_or_ip);
char *packet_end= thd->query + thd->query_length; char *packet_end= thd->query() + thd->query_length();
/* 'b' stands for 'buffer' parameter', special for 'my_snprintf' */ /* 'b' stands for 'buffer' parameter', special for 'my_snprintf' */
const char* end_of_stmt= NULL; const char* end_of_stmt= NULL;
general_log_write(thd, command, thd->query, thd->query_length); general_log_write(thd, command, thd->query(), thd->query_length());
DBUG_PRINT("query",("%-.4096s",thd->query)); DBUG_PRINT("query",("%-.4096s",thd->query()));
#if defined(ENABLED_PROFILING) #if defined(ENABLED_PROFILING)
thd->profiling.set_query_source(thd->query, thd->query_length); thd->profiling.set_query_source(thd->query(), thd->query_length());
#endif #endif
if (!(specialflag & SPECIAL_NO_PRIOR)) if (!(specialflag & SPECIAL_NO_PRIOR))
my_pthread_setprio(pthread_self(),QUERY_PRIOR); my_pthread_setprio(pthread_self(),QUERY_PRIOR);
mysql_parse(thd, thd->query, thd->query_length, &end_of_stmt); mysql_parse(thd, thd->query(), thd->query_length(), &end_of_stmt);
while (!thd->killed && (end_of_stmt != NULL) && ! thd->is_error()) while (!thd->killed && (end_of_stmt != NULL) && ! thd->is_error())
{ {
@ -1694,7 +1694,8 @@ void log_slow_statement(THD *thd)
{ {
thd_proc_info(thd, "logging slow query"); thd_proc_info(thd, "logging slow query");
thd->status_var.long_query_count++; thd->status_var.long_query_count++;
slow_log_print(thd, thd->query, thd->query_length, end_utime_of_query); slow_log_print(thd, thd->query(), thd->query_length(),
end_utime_of_query);
} }
} }
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
@ -3084,7 +3085,7 @@ end_with_restore_list:
/* /*
Presumably, REPAIR and binlog writing doesn't require synchronization Presumably, REPAIR and binlog writing doesn't require synchronization
*/ */
write_bin_log(thd, TRUE, thd->query, thd->query_length); write_bin_log(thd, TRUE, thd->query(), thd->query_length());
} }
select_lex->table_list.first= (uchar*) first_table; select_lex->table_list.first= (uchar*) first_table;
lex->query_tables=all_tables; lex->query_tables=all_tables;
@ -3116,7 +3117,7 @@ end_with_restore_list:
/* /*
Presumably, ANALYZE and binlog writing doesn't require synchronization Presumably, ANALYZE and binlog writing doesn't require synchronization
*/ */
write_bin_log(thd, TRUE, thd->query, thd->query_length); write_bin_log(thd, TRUE, thd->query(), thd->query_length());
} }
select_lex->table_list.first= (uchar*) first_table; select_lex->table_list.first= (uchar*) first_table;
lex->query_tables=all_tables; lex->query_tables=all_tables;
@ -3139,7 +3140,7 @@ end_with_restore_list:
/* /*
Presumably, OPTIMIZE and binlog writing doesn't require synchronization Presumably, OPTIMIZE and binlog writing doesn't require synchronization
*/ */
write_bin_log(thd, TRUE, thd->query, thd->query_length); write_bin_log(thd, TRUE, thd->query(), thd->query_length());
} }
select_lex->table_list.first= (uchar*) first_table; select_lex->table_list.first= (uchar*) first_table;
lex->query_tables=all_tables; lex->query_tables=all_tables;
@ -4121,7 +4122,7 @@ end_with_restore_list:
*/ */
if (!lex->no_write_to_binlog && write_to_binlog) if (!lex->no_write_to_binlog && write_to_binlog)
{ {
write_bin_log(thd, FALSE, thd->query, thd->query_length); write_bin_log(thd, FALSE, thd->query(), thd->query_length());
} }
my_ok(thd); my_ok(thd);
} }
@ -4693,7 +4694,7 @@ create_sp_error:
case SP_KEY_NOT_FOUND: case SP_KEY_NOT_FOUND:
if (lex->drop_if_exists) if (lex->drop_if_exists)
{ {
write_bin_log(thd, TRUE, thd->query, thd->query_length); write_bin_log(thd, TRUE, thd->query(), thd->query_length());
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST), ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST),
SP_COM_STRING(lex), lex->spname->m_name.str); SP_COM_STRING(lex), lex->spname->m_name.str);
@ -6184,9 +6185,10 @@ void mysql_parse(THD *thd, const char *inBuf, uint length,
PROCESSLIST. PROCESSLIST.
Note that we don't need LOCK_thread_count to modify query_length. Note that we don't need LOCK_thread_count to modify query_length.
*/ */
if (*found_semicolon && if (*found_semicolon && (ulong) (*found_semicolon - thd->query()))
(thd->query_length= (ulong)(*found_semicolon - thd->query))) thd->set_query_inner(thd->query(),
thd->query_length--; (uint32) (*found_semicolon -
thd->query() - 1));
/* Actually execute the query */ /* Actually execute the query */
if (*found_semicolon) if (*found_semicolon)
{ {

View File

@ -4342,7 +4342,7 @@ static int fast_end_partition(THD *thd, ulonglong copied,
if ((!is_empty) && (!written_bin_log) && if ((!is_empty) && (!written_bin_log) &&
(!thd->lex->no_write_to_binlog)) (!thd->lex->no_write_to_binlog))
write_bin_log(thd, FALSE, thd->query, thd->query_length); write_bin_log(thd, FALSE, thd->query(), thd->query_length());
my_snprintf(tmp_name, sizeof(tmp_name), ER(ER_INSERT_INFO), my_snprintf(tmp_name, sizeof(tmp_name), ER(ER_INSERT_INFO),
(ulong) (copied + deleted), (ulong) (copied + deleted),
@ -6574,7 +6574,7 @@ uint fast_alter_partition_table(THD *thd, TABLE *table,
ERROR_INJECT_CRASH("crash_drop_partition_5") || ERROR_INJECT_CRASH("crash_drop_partition_5") ||
((!thd->lex->no_write_to_binlog) && ((!thd->lex->no_write_to_binlog) &&
(write_bin_log(thd, FALSE, (write_bin_log(thd, FALSE,
thd->query, thd->query_length), FALSE)) || thd->query(), thd->query_length()), FALSE)) ||
ERROR_INJECT_CRASH("crash_drop_partition_6") || ERROR_INJECT_CRASH("crash_drop_partition_6") ||
((frm_install= TRUE), FALSE) || ((frm_install= TRUE), FALSE) ||
mysql_write_frm(lpt, WFRM_INSTALL_SHADOW) || mysql_write_frm(lpt, WFRM_INSTALL_SHADOW) ||
@ -6641,7 +6641,7 @@ uint fast_alter_partition_table(THD *thd, TABLE *table,
ERROR_INJECT_CRASH("crash_add_partition_5") || ERROR_INJECT_CRASH("crash_add_partition_5") ||
((!thd->lex->no_write_to_binlog) && ((!thd->lex->no_write_to_binlog) &&
(write_bin_log(thd, FALSE, (write_bin_log(thd, FALSE,
thd->query, thd->query_length), FALSE)) || thd->query(), thd->query_length()), FALSE)) ||
ERROR_INJECT_CRASH("crash_add_partition_6") || ERROR_INJECT_CRASH("crash_add_partition_6") ||
write_log_rename_frm(lpt) || write_log_rename_frm(lpt) ||
(not_completed= FALSE) || (not_completed= FALSE) ||
@ -6731,7 +6731,7 @@ uint fast_alter_partition_table(THD *thd, TABLE *table,
ERROR_INJECT_CRASH("crash_change_partition_6") || ERROR_INJECT_CRASH("crash_change_partition_6") ||
((!thd->lex->no_write_to_binlog) && ((!thd->lex->no_write_to_binlog) &&
(write_bin_log(thd, FALSE, (write_bin_log(thd, FALSE,
thd->query, thd->query_length), FALSE)) || thd->query(), thd->query_length()), FALSE)) ||
ERROR_INJECT_CRASH("crash_change_partition_7") || ERROR_INJECT_CRASH("crash_change_partition_7") ||
mysql_write_frm(lpt, WFRM_INSTALL_SHADOW) || mysql_write_frm(lpt, WFRM_INSTALL_SHADOW) ||
ERROR_INJECT_CRASH("crash_change_partition_8") || ERROR_INJECT_CRASH("crash_change_partition_8") ||

View File

@ -827,7 +827,7 @@ static bool insert_params_with_log(Prepared_statement *stmt, uchar *null_array,
const String *res; const String *res;
DBUG_ENTER("insert_params_with_log"); DBUG_ENTER("insert_params_with_log");
if (query->copy(stmt->query, stmt->query_length, default_charset_info)) if (query->copy(stmt->query(), stmt->query_length(), default_charset_info))
DBUG_RETURN(1); DBUG_RETURN(1);
for (Item_param **it= begin; it < end; ++it) for (Item_param **it= begin; it < end; ++it)
@ -989,7 +989,7 @@ static bool emb_insert_params_with_log(Prepared_statement *stmt,
DBUG_ENTER("emb_insert_params_with_log"); DBUG_ENTER("emb_insert_params_with_log");
if (query->copy(stmt->query, stmt->query_length, default_charset_info)) if (query->copy(stmt->query(), stmt->query_length(), default_charset_info))
DBUG_RETURN(1); DBUG_RETURN(1);
for (; it < end; ++it, ++client_param) for (; it < end; ++it, ++client_param)
@ -1140,7 +1140,7 @@ static bool insert_params_from_vars_with_log(Prepared_statement *stmt,
DBUG_ENTER("insert_params_from_vars"); DBUG_ENTER("insert_params_from_vars");
if (query->copy(stmt->query, stmt->query_length, default_charset_info)) if (query->copy(stmt->query(), stmt->query_length(), default_charset_info))
DBUG_RETURN(1); DBUG_RETURN(1);
for (Item_param **it= begin; it < end; ++it) for (Item_param **it= begin; it < end; ++it)
@ -2504,9 +2504,9 @@ void mysqld_stmt_execute(THD *thd, char *packet_arg, uint packet_length)
} }
#if defined(ENABLED_PROFILING) #if defined(ENABLED_PROFILING)
thd->profiling.set_query_source(stmt->query, stmt->query_length); thd->profiling.set_query_source(stmt->query(), stmt->query_length());
#endif #endif
DBUG_PRINT("exec_query", ("%s", stmt->query)); DBUG_PRINT("exec_query", ("%s", stmt->query()));
DBUG_PRINT("info",("stmt: 0x%lx", (long) stmt)); DBUG_PRINT("info",("stmt: 0x%lx", (long) stmt));
sp_cache_flush_obsolete(&thd->sp_proc_cache); sp_cache_flush_obsolete(&thd->sp_proc_cache);
@ -2924,7 +2924,7 @@ Execute_sql_statement::execute_server_code(THD *thd)
if (alloc_query(thd, m_sql_text.str, m_sql_text.length)) if (alloc_query(thd, m_sql_text.str, m_sql_text.length))
return TRUE; return TRUE;
Parser_state parser_state(thd, thd->query, thd->query_length); Parser_state parser_state(thd, thd->query(), thd->query_length());
parser_state.m_lip.multi_statements= FALSE; parser_state.m_lip.multi_statements= FALSE;
lex_start(thd); lex_start(thd);
@ -2947,7 +2947,7 @@ Execute_sql_statement::execute_server_code(THD *thd)
/* report error issued during command execution */ /* report error issued during command execution */
if (error == 0 && thd->spcont == NULL) if (error == 0 && thd->spcont == NULL)
general_log_write(thd, COM_STMT_EXECUTE, general_log_write(thd, COM_STMT_EXECUTE,
thd->query, thd->query_length); thd->query(), thd->query_length());
end: end:
lex_end(thd->lex); lex_end(thd->lex);
@ -3164,7 +3164,7 @@ bool Prepared_statement::prepare(const char *packet, uint packet_len)
old_stmt_arena= thd->stmt_arena; old_stmt_arena= thd->stmt_arena;
thd->stmt_arena= this; thd->stmt_arena= this;
Parser_state parser_state(thd, thd->query, thd->query_length); Parser_state parser_state(thd, thd->query(), thd->query_length());
parser_state.m_lip.stmt_prepare_mode= TRUE; parser_state.m_lip.stmt_prepare_mode= TRUE;
parser_state.m_lip.multi_statements= FALSE; parser_state.m_lip.multi_statements= FALSE;
lex_start(thd); lex_start(thd);
@ -3254,7 +3254,7 @@ bool Prepared_statement::prepare(const char *packet, uint packet_len)
the general log. the general log.
*/ */
if (thd->spcont == NULL) if (thd->spcont == NULL)
general_log_write(thd, COM_STMT_PREPARE, query, query_length); general_log_write(thd, COM_STMT_PREPARE, query(), query_length());
} }
DBUG_RETURN(error); DBUG_RETURN(error);
} }
@ -3484,7 +3484,7 @@ Prepared_statement::reprepare()
return TRUE; return TRUE;
error= ((name.str && copy.set_name(&name)) || error= ((name.str && copy.set_name(&name)) ||
copy.prepare(query, query_length) || copy.prepare(query(), query_length()) ||
validate_metadata(&copy)); validate_metadata(&copy));
if (cur_db_changed) if (cur_db_changed)
@ -3722,8 +3722,7 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor)
to point at it even after we restore from backup. This is ok, as to point at it even after we restore from backup. This is ok, as
expanded query was allocated in thd->mem_root. expanded query was allocated in thd->mem_root.
*/ */
stmt_backup.query= thd->query; stmt_backup.set_query_inner(thd->query(), thd->query_length());
stmt_backup.query_length= thd->query_length;
/* /*
At first execution of prepared statement we may perform logical At first execution of prepared statement we may perform logical
@ -3748,8 +3747,8 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor)
Note that multi-statements cannot exist here (they are not supported in Note that multi-statements cannot exist here (they are not supported in
prepared statements). prepared statements).
*/ */
if (query_cache_send_result_to_client(thd, thd->query, if (query_cache_send_result_to_client(thd, thd->query(),
thd->query_length) <= 0) thd->query_length()) <= 0)
{ {
MYSQL_QUERY_EXEC_START(thd->query, MYSQL_QUERY_EXEC_START(thd->query,
thd->thread_id, thd->thread_id,
@ -3810,7 +3809,7 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor)
the general log. the general log.
*/ */
if (error == 0 && thd->spcont == NULL) if (error == 0 && thd->spcont == NULL)
general_log_write(thd, COM_STMT_EXECUTE, thd->query, thd->query_length); general_log_write(thd, COM_STMT_EXECUTE, thd->query(), thd->query_length());
error: error:
flags&= ~ (uint) IS_IN_USE; flags&= ~ (uint) IS_IN_USE;

View File

@ -177,7 +177,7 @@ bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent)
/* Lets hope this doesn't fail as the result will be messy */ /* Lets hope this doesn't fail as the result will be messy */
if (!silent && !error) if (!silent && !error)
{ {
write_bin_log(thd, TRUE, thd->query, thd->query_length); write_bin_log(thd, TRUE, thd->query(), thd->query_length());
my_ok(thd); my_ok(thd);
} }

View File

@ -1787,10 +1787,10 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose)
thd_info->query=0; thd_info->query=0;
/* Lock THD mutex that protects its data when looking at it. */ /* Lock THD mutex that protects its data when looking at it. */
pthread_mutex_lock(&tmp->LOCK_thd_data); pthread_mutex_lock(&tmp->LOCK_thd_data);
if (tmp->query) if (tmp->query())
{ {
uint length= min(max_query_length, tmp->query_length); uint length= min(max_query_length, tmp->query_length());
thd_info->query=(char*) thd->strmake(tmp->query,length); thd_info->query= (char*) thd->strmake(tmp->query(),length);
} }
pthread_mutex_unlock(&tmp->LOCK_thd_data); pthread_mutex_unlock(&tmp->LOCK_thd_data);
thread_infos.append(thd_info); thread_infos.append(thd_info);
@ -1915,11 +1915,11 @@ int fill_schema_processlist(THD* thd, TABLE_LIST* tables, COND* cond)
pthread_mutex_unlock(&mysys_var->mutex); pthread_mutex_unlock(&mysys_var->mutex);
/* INFO */ /* INFO */
if (tmp->query) if (tmp->query())
{ {
table->field[7]->store(tmp->query, table->field[7]->store(tmp->query(),
min(PROCESS_LIST_INFO_WIDTH, min(PROCESS_LIST_INFO_WIDTH,
tmp->query_length), cs); tmp->query_length()), cs);
table->field[7]->set_notnull(); table->field[7]->set_notnull();
} }

View File

@ -2099,7 +2099,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
tables). In this case, we can write the original query into tables). In this case, we can write the original query into
the binary log. the binary log.
*/ */
write_bin_log(thd, !error, thd->query, thd->query_length); write_bin_log(thd, !error, thd->query(), thd->query_length());
} }
else if (thd->current_stmt_binlog_row_based && else if (thd->current_stmt_binlog_row_based &&
tmp_table_deleted) tmp_table_deleted)
@ -3596,7 +3596,7 @@ static inline void write_create_table_bin_log(THD *thd,
(!thd->current_stmt_binlog_row_based || (!thd->current_stmt_binlog_row_based ||
(thd->current_stmt_binlog_row_based && (thd->current_stmt_binlog_row_based &&
!(create_info->options & HA_LEX_CREATE_TMP_TABLE)))) !(create_info->options & HA_LEX_CREATE_TMP_TABLE))))
write_bin_log(thd, TRUE, thd->query, thd->query_length); write_bin_log(thd, TRUE, thd->query(), thd->query_length());
} }
@ -5473,14 +5473,14 @@ binlog:
write_bin_log(thd, TRUE, query.ptr(), query.length()); write_bin_log(thd, TRUE, query.ptr(), query.length());
} }
else // Case 1 else // Case 1
write_bin_log(thd, TRUE, thd->query, thd->query_length); write_bin_log(thd, TRUE, thd->query(), thd->query_length());
} }
/* /*
Case 3 and 4 does nothing under RBR Case 3 and 4 does nothing under RBR
*/ */
} }
else else
write_bin_log(thd, TRUE, thd->query, thd->query_length); write_bin_log(thd, TRUE, thd->query(), thd->query_length());
res= FALSE; res= FALSE;
@ -5568,7 +5568,7 @@ mysql_discard_or_import_tablespace(THD *thd,
error=1; error=1;
if (error) if (error)
goto err; goto err;
write_bin_log(thd, FALSE, thd->query, thd->query_length); write_bin_log(thd, FALSE, thd->query(), thd->query_length());
err: err:
ha_autocommit_or_rollback(thd, error); ha_autocommit_or_rollback(thd, error);
@ -6578,7 +6578,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
if (mysql_bin_log.is_open()) if (mysql_bin_log.is_open())
{ {
thd->clear_error(); thd->clear_error();
Query_log_event qinfo(thd, thd->query, thd->query_length, Query_log_event qinfo(thd, thd->query(), thd->query_length(),
0, FALSE, 0); 0, FALSE, 0);
mysql_bin_log.write(&qinfo); mysql_bin_log.write(&qinfo);
} }
@ -6832,7 +6832,7 @@ view_err:
if (!error) if (!error)
{ {
write_bin_log(thd, TRUE, thd->query, thd->query_length); write_bin_log(thd, TRUE, thd->query(), thd->query_length());
my_ok(thd); my_ok(thd);
} }
else if (error > 0) else if (error > 0)
@ -7322,7 +7322,7 @@ view_err:
goto err1; goto err1;
/* We don't replicate alter table statement on temporary tables */ /* We don't replicate alter table statement on temporary tables */
if (!thd->current_stmt_binlog_row_based) if (!thd->current_stmt_binlog_row_based)
write_bin_log(thd, TRUE, thd->query, thd->query_length); write_bin_log(thd, TRUE, thd->query(), thd->query_length());
goto end_temporary; goto end_temporary;
} }
@ -7479,13 +7479,13 @@ view_err:
DBUG_EXECUTE_IF("sleep_alter_before_main_binlog", my_sleep(6000000);); DBUG_EXECUTE_IF("sleep_alter_before_main_binlog", my_sleep(6000000););
ha_binlog_log_query(thd, create_info->db_type, LOGCOM_ALTER_TABLE, ha_binlog_log_query(thd, create_info->db_type, LOGCOM_ALTER_TABLE,
thd->query, thd->query_length, thd->query(), thd->query_length(),
db, table_name); db, table_name);
DBUG_ASSERT(!(mysql_bin_log.is_open() && DBUG_ASSERT(!(mysql_bin_log.is_open() &&
thd->current_stmt_binlog_row_based && thd->current_stmt_binlog_row_based &&
(create_info->options & HA_LEX_CREATE_TMP_TABLE))); (create_info->options & HA_LEX_CREATE_TMP_TABLE)));
write_bin_log(thd, TRUE, thd->query, thd->query_length); write_bin_log(thd, TRUE, thd->query(), thd->query_length());
if (ha_check_storage_engine_flag(old_db_type, HTON_FLUSH_AFTER_RENAME)) if (ha_check_storage_engine_flag(old_db_type, HTON_FLUSH_AFTER_RENAME))
{ {

View File

@ -66,6 +66,6 @@ int mysql_alter_tablespace(THD *thd, st_alter_tablespace *ts_info)
ha_resolve_storage_engine_name(hton), ha_resolve_storage_engine_name(hton),
"TABLESPACE or LOGFILE GROUP"); "TABLESPACE or LOGFILE GROUP");
} }
write_bin_log(thd, FALSE, thd->query, thd->query_length); write_bin_log(thd, FALSE, thd->query(), thd->query_length());
DBUG_RETURN(FALSE); DBUG_RETURN(FALSE);
} }

View File

@ -409,7 +409,7 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
*/ */
result= FALSE; result= FALSE;
/* Still, we need to log the query ... */ /* Still, we need to log the query ... */
stmt_query.append(thd->query, thd->query_length); stmt_query.append(thd->query(), thd->query_length());
goto end; goto end;
} }
} }
@ -918,7 +918,7 @@ bool Table_triggers_list::drop_trigger(THD *thd, TABLE_LIST *tables,
List_iterator<LEX_STRING> it_connection_cl_name(connection_cl_names); List_iterator<LEX_STRING> it_connection_cl_name(connection_cl_names);
List_iterator<LEX_STRING> it_db_cl_name(db_cl_names); List_iterator<LEX_STRING> it_db_cl_name(db_cl_names);
stmt_query->append(thd->query, thd->query_length); stmt_query->append(thd->query(), thd->query_length());
while ((name= it_name++)) while ((name= it_name++))
{ {

View File

@ -506,7 +506,7 @@ int mysql_create_function(THD *thd,udf_func *udf)
rw_unlock(&THR_LOCK_udf); rw_unlock(&THR_LOCK_udf);
/* Binlog the create function. */ /* Binlog the create function. */
write_bin_log(thd, TRUE, thd->query, thd->query_length); write_bin_log(thd, TRUE, thd->query(), thd->query_length());
DBUG_RETURN(0); DBUG_RETURN(0);
@ -581,7 +581,7 @@ int mysql_drop_function(THD *thd,const LEX_STRING *udf_name)
rw_unlock(&THR_LOCK_udf); rw_unlock(&THR_LOCK_udf);
/* Binlog the drop function. */ /* Binlog the drop function. */
write_bin_log(thd, TRUE, thd->query, thd->query_length); write_bin_log(thd, TRUE, thd->query(), thd->query_length());
DBUG_RETURN(0); DBUG_RETURN(0);
err: err:

View File

@ -812,7 +812,7 @@ int mysql_update(THD *thd,
errcode= query_error_code(thd, killed_status == THD::NOT_KILLED); errcode= query_error_code(thd, killed_status == THD::NOT_KILLED);
if (thd->binlog_query(THD::ROW_QUERY_TYPE, if (thd->binlog_query(THD::ROW_QUERY_TYPE,
thd->query, thd->query_length, thd->query(), thd->query_length(),
transactional_table, FALSE, errcode)) transactional_table, FALSE, errcode))
{ {
error=1; // Rollback update error=1; // Rollback update
@ -1867,7 +1867,7 @@ void multi_update::abort()
*/ */
int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED); int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
thd->binlog_query(THD::ROW_QUERY_TYPE, thd->binlog_query(THD::ROW_QUERY_TYPE,
thd->query, thd->query_length, thd->query(), thd->query_length(),
transactional_tables, FALSE, errcode); transactional_tables, FALSE, errcode);
} }
thd->transaction.all.modified_non_trans_table= TRUE; thd->transaction.all.modified_non_trans_table= TRUE;
@ -2100,7 +2100,7 @@ bool multi_update::send_eof()
else else
errcode= query_error_code(thd, killed_status == THD::NOT_KILLED); errcode= query_error_code(thd, killed_status == THD::NOT_KILLED);
if (thd->binlog_query(THD::ROW_QUERY_TYPE, if (thd->binlog_query(THD::ROW_QUERY_TYPE,
thd->query, thd->query_length, thd->query(), thd->query_length(),
transactional_tables, FALSE, errcode)) transactional_tables, FALSE, errcode))
{ {
local_error= 1; // Rollback update local_error= 1; // Rollback update

View File

@ -1653,7 +1653,7 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
/* if something goes wrong, bin-log with possible error code, /* if something goes wrong, bin-log with possible error code,
otherwise bin-log with error code cleared. otherwise bin-log with error code cleared.
*/ */
write_bin_log(thd, !something_wrong, thd->query, thd->query_length); write_bin_log(thd, !something_wrong, thd->query(), thd->query_length());
} }
VOID(pthread_mutex_unlock(&LOCK_open)); VOID(pthread_mutex_unlock(&LOCK_open));

View File

@ -11100,7 +11100,7 @@ param_marker:
my_error(ER_VIEW_SELECT_VARIABLE, MYF(0)); my_error(ER_VIEW_SELECT_VARIABLE, MYF(0));
MYSQL_YYABORT; MYSQL_YYABORT;
} }
item= new (thd->mem_root) Item_param((uint) (lip->get_tok_start() - thd->query)); item= new (thd->mem_root) Item_param((uint) (lip->get_tok_start() - thd->query()));
if (!($$= item) || lex->param_list.push_back(item)) if (!($$= item) || lex->param_list.push_back(item))
{ {
my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0)); my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));

View File

@ -106,7 +106,7 @@ int ha_blackhole::update_row(const uchar *old_data, uchar *new_data)
{ {
DBUG_ENTER("ha_blackhole::update_row"); DBUG_ENTER("ha_blackhole::update_row");
THD *thd= ha_thd(); THD *thd= ha_thd();
if (thd->system_thread == SYSTEM_THREAD_SLAVE_SQL && thd->query == NULL) if (thd->system_thread == SYSTEM_THREAD_SLAVE_SQL && thd->query() == NULL)
DBUG_RETURN(0); DBUG_RETURN(0);
DBUG_RETURN(HA_ERR_WRONG_COMMAND); DBUG_RETURN(HA_ERR_WRONG_COMMAND);
} }
@ -115,7 +115,7 @@ int ha_blackhole::delete_row(const uchar *buf)
{ {
DBUG_ENTER("ha_blackhole::delete_row"); DBUG_ENTER("ha_blackhole::delete_row");
THD *thd= ha_thd(); THD *thd= ha_thd();
if (thd->system_thread == SYSTEM_THREAD_SLAVE_SQL && thd->query == NULL) if (thd->system_thread == SYSTEM_THREAD_SLAVE_SQL && thd->query() == NULL)
DBUG_RETURN(0); DBUG_RETURN(0);
DBUG_RETURN(HA_ERR_WRONG_COMMAND); DBUG_RETURN(HA_ERR_WRONG_COMMAND);
} }
@ -134,7 +134,7 @@ int ha_blackhole::rnd_next(uchar *buf)
MYSQL_READ_ROW_START(table_share->db.str, table_share->table_name.str, MYSQL_READ_ROW_START(table_share->db.str, table_share->table_name.str,
TRUE); TRUE);
THD *thd= ha_thd(); THD *thd= ha_thd();
if (thd->system_thread == SYSTEM_THREAD_SLAVE_SQL && thd->query == NULL) if (thd->system_thread == SYSTEM_THREAD_SLAVE_SQL && thd->query() == NULL)
rc= 0; rc= 0;
else else
rc= HA_ERR_END_OF_FILE; rc= HA_ERR_END_OF_FILE;
@ -224,7 +224,7 @@ int ha_blackhole::index_read_map(uchar * buf, const uchar * key,
DBUG_ENTER("ha_blackhole::index_read"); DBUG_ENTER("ha_blackhole::index_read");
MYSQL_INDEX_READ_ROW_START(table_share->db.str, table_share->table_name.str); MYSQL_INDEX_READ_ROW_START(table_share->db.str, table_share->table_name.str);
THD *thd= ha_thd(); THD *thd= ha_thd();
if (thd->system_thread == SYSTEM_THREAD_SLAVE_SQL && thd->query == NULL) if (thd->system_thread == SYSTEM_THREAD_SLAVE_SQL && thd->query() == NULL)
rc= 0; rc= 0;
else else
rc= HA_ERR_END_OF_FILE; rc= HA_ERR_END_OF_FILE;
@ -241,7 +241,7 @@ int ha_blackhole::index_read_idx_map(uchar * buf, uint idx, const uchar * key,
DBUG_ENTER("ha_blackhole::index_read_idx"); DBUG_ENTER("ha_blackhole::index_read_idx");
MYSQL_INDEX_READ_ROW_START(table_share->db.str, table_share->table_name.str); MYSQL_INDEX_READ_ROW_START(table_share->db.str, table_share->table_name.str);
THD *thd= ha_thd(); THD *thd= ha_thd();
if (thd->system_thread == SYSTEM_THREAD_SLAVE_SQL && thd->query == NULL) if (thd->system_thread == SYSTEM_THREAD_SLAVE_SQL && thd->query() == NULL)
rc= 0; rc= 0;
else else
rc= HA_ERR_END_OF_FILE; rc= HA_ERR_END_OF_FILE;
@ -257,7 +257,7 @@ int ha_blackhole::index_read_last_map(uchar * buf, const uchar * key,
DBUG_ENTER("ha_blackhole::index_read_last"); DBUG_ENTER("ha_blackhole::index_read_last");
MYSQL_INDEX_READ_ROW_START(table_share->db.str, table_share->table_name.str); MYSQL_INDEX_READ_ROW_START(table_share->db.str, table_share->table_name.str);
THD *thd= ha_thd(); THD *thd= ha_thd();
if (thd->system_thread == SYSTEM_THREAD_SLAVE_SQL && thd->query == NULL) if (thd->system_thread == SYSTEM_THREAD_SLAVE_SQL && thd->query() == NULL)
rc= 0; rc= 0;
else else
rc= HA_ERR_END_OF_FILE; rc= HA_ERR_END_OF_FILE;

View File

@ -1595,8 +1595,8 @@ bool ha_myisam::check_and_repair(THD *thd)
check_opt.flags|=T_QUICK; check_opt.flags|=T_QUICK;
sql_print_warning("Checking table: '%s'",table->s->path.str); sql_print_warning("Checking table: '%s'",table->s->path.str);
old_query= thd->query; old_query= thd->query();
old_query_length= thd->query_length; old_query_length= thd->query_length();
thd->set_query(table->s->table_name.str, thd->set_query(table->s->table_name.str,
(uint) table->s->table_name.length); (uint) table->s->table_name.length);