List:Commits« Previous MessageNext Message »
From:Georgi Kodinov Date:October 13 2009 4:19pm
Subject:bzr commit into mysql-5.1-bugteam branch (joro:3156) Bug#40877
View as plain text  
#At file:///home/kgeorge/mysql/work/B40877-5.1-bugteam/ based on revid:mattias.jonsson@stripped

 3156 Georgi Kodinov	2009-10-13
      Bug #40877: multi statement execution fails in 5.1.30
      
      Implemented the server infrastructure for the fix:
      
      1. Added a function LEX_STRING *thd_query_string(THD) to return
      a LEX_STRING structure instead of char *.
      This is the function that must be called in innodb instead of 
      thd_query()
      
      2. Did some encapsulation in THD : aggregated thd_query and 
      thd_query_length into a LEX_STRING and made accessor and mutator 
      methods for easy code updating. 
      
      3. Updated the server code to use the new methods where applicable.

    modified:
      sql/event_data_objects.cc
      sql/events.cc
      sql/ha_ndbcluster.cc
      sql/ha_ndbcluster_binlog.cc
      sql/log.cc
      sql/log_event.cc
      sql/mysqld.cc
      sql/slave.cc
      sql/sp.cc
      sql/sp_head.cc
      sql/sql_acl.cc
      sql/sql_cache.cc
      sql/sql_class.cc
      sql/sql_class.h
      sql/sql_db.cc
      sql/sql_delete.cc
      sql/sql_insert.cc
      sql/sql_load.cc
      sql/sql_parse.cc
      sql/sql_partition.cc
      sql/sql_prepare.cc
      sql/sql_rename.cc
      sql/sql_show.cc
      sql/sql_table.cc
      sql/sql_tablespace.cc
      sql/sql_trigger.cc
      sql/sql_udf.cc
      sql/sql_update.cc
      sql/sql_view.cc
      sql/sql_yacc.yy
      storage/blackhole/ha_blackhole.cc
      storage/myisam/ha_myisam.cc
=== modified file 'sql/event_data_objects.cc'
--- a/sql/event_data_objects.cc	2009-07-24 16:04:55 +0000
+++ b/sql/event_data_objects.cc	2009-10-13 16:19:50 +0000
@@ -1433,7 +1433,7 @@ Event_job_data::execute(THD *thd, bool d
   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);
 
     if (parse_sql(thd, & parser_state, creation_ctx))

=== modified file 'sql/events.cc'
--- a/sql/events.cc	2009-08-29 08:52:22 +0000
+++ b/sql/events.cc	2009-10-13 16:19:50 +0000
@@ -465,7 +465,7 @@ Events::create_event(THD *thd, Event_par
     if (!dropped)
     {
       /* Binlog the create event. */
-      DBUG_ASSERT(thd->query && thd->query_length);
+      DBUG_ASSERT(thd->query() && thd->query_length());
       String log_query;
       if (create_query_string(thd, &log_query))
       {
@@ -595,8 +595,8 @@ Events::update_event(THD *thd, Event_par
         event_queue->update_event(thd, parse_data->dbname, parse_data->name,
                                   new_element);
       /* Binlog the alter event. */
-      DBUG_ASSERT(thd->query && thd->query_length);
-      write_bin_log(thd, TRUE, thd->query, thd->query_length);
+      DBUG_ASSERT(thd->query() && thd->query_length());
+      write_bin_log(thd, TRUE, thd->query(), thd->query_length());
     }
   }
   pthread_mutex_unlock(&LOCK_event_metadata);
@@ -670,8 +670,8 @@ Events::drop_event(THD *thd, LEX_STRING 
     if (event_queue)
       event_queue->drop_event(thd, dbname, name);
     /* Binlog the drop event. */
-    DBUG_ASSERT(thd->query && thd->query_length);
-    write_bin_log(thd, TRUE, thd->query, thd->query_length);
+    DBUG_ASSERT(thd->query() && thd->query_length());
+    write_bin_log(thd, TRUE, thd->query(), thd->query_length());
   }
   pthread_mutex_unlock(&LOCK_event_metadata);
   DBUG_RETURN(ret);

=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc	2009-09-23 13:10:23 +0000
+++ b/sql/ha_ndbcluster.cc	2009-10-13 16:19:50 +0000
@@ -5525,7 +5525,7 @@ int ha_ndbcluster::create(const char *na
       if (share && !do_event_op)
         share->flags|= NSF_NO_BINLOG;
       ndbcluster_log_schema_op(thd, share,
-                               thd->query, thd->query_length,
+                               thd->query(), thd->query_length(),
                                share->db, share->table_name,
                                m_table->getObjectId(),
                                m_table->getObjectVersion(),
@@ -5967,7 +5967,8 @@ int ha_ndbcluster::rename_table(const ch
     */
     if (!is_old_table_tmpfile)
       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,
                                ndb_table_id, ndb_table_version,
                                SOT_RENAME_TABLE,
@@ -6162,7 +6163,7 @@ retry_temporary_error1:
       current_thd->lex->sql_command != SQLCOM_TRUNCATE)
   {
     ndbcluster_log_schema_op(thd, share,
-                             thd->query, thd->query_length,
+                             thd->query(), thd->query_length(),
                              share->db, share->table_name,
                              ndb_table_id, ndb_table_version,
                              SOT_DROP_TABLE, 0, 0, 1);
@@ -6884,7 +6885,7 @@ static void ndbcluster_drop_database(han
   THD *thd= current_thd;
   ha_ndbcluster::set_dbname(path, db);
   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);
 #endif
   DBUG_VOID_RETURN;
@@ -10251,13 +10252,13 @@ int ndbcluster_alter_tablespace(handlert
 #ifdef HAVE_NDB_BINLOG
   if (is_tablespace)
     ndbcluster_log_schema_op(thd, 0,
-                             thd->query, thd->query_length,
+                             thd->query(), thd->query_length(),
                              "", alter_info->tablespace_name,
                              0, 0,
                              SOT_TABLESPACE, 0, 0, 0);
   else
     ndbcluster_log_schema_op(thd, 0,
-                             thd->query, thd->query_length,
+                             thd->query(), thd->query_length(),
                              "", alter_info->logfile_group_name,
                              0, 0,
                              SOT_LOGFILE_GROUP, 0, 0, 0);

=== modified file 'sql/ha_ndbcluster_binlog.cc'
--- a/sql/ha_ndbcluster_binlog.cc	2009-09-23 13:10:23 +0000
+++ b/sql/ha_ndbcluster_binlog.cc	2009-10-13 16:19:50 +0000
@@ -241,8 +241,8 @@ static void dbug_print_table(const char 
 static void run_query(THD *thd, char *buf, char *end,
                       const int *no_print_error, my_bool disable_binlog)
 {
-  ulong save_thd_query_length= thd->query_length;
-  char *save_thd_query= thd->query;
+  ulong save_thd_query_length= thd->query_length();
+  char *save_thd_query= thd->query();
   ulong save_thread_id= thd->variables.pseudo_thread_id;
   struct system_status_var save_thd_status_var= thd->status_var;
   THD_TRANS save_thd_transaction_all= thd->transaction.all;
@@ -259,12 +259,12 @@ static void run_query(THD *thd, char *bu
   if (disable_binlog)
     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->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)
   {

=== modified file 'sql/log.cc'
--- a/sql/log.cc	2009-10-06 00:54:00 +0000
+++ b/sql/log.cc	2009-10-13 16:19:50 +0000
@@ -1717,7 +1717,7 @@ static int binlog_savepoint_set(handlert
   int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
   int const error=
     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);
 }
 
@@ -1736,7 +1736,7 @@ static int binlog_savepoint_rollback(han
     int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
     int error=
       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);
   }
   binlog_trans_log_truncate(thd, *(my_off_t*)sv);

=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	2009-09-29 13:08:18 +0000
+++ b/sql/log_event.cc	2009-10-13 16:19:50 +0000
@@ -3039,7 +3039,7 @@ int Query_log_event::do_apply_event(Rela
     thd->query_id = next_query_id();
     VOID(pthread_mutex_unlock(&LOCK_thread_count));
     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)) ||
 	!unexpected_error_code(expected_error))
@@ -3133,7 +3133,7 @@ int Query_log_event::do_apply_event(Rela
       
       /* Execute the query (note that we bypass dispatch_command()) */
       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);
     }
     else
@@ -3145,7 +3145,7 @@ int Query_log_event::do_apply_event(Rela
         we exit gracefully; otherwise we warn about the bad error and tell DBA
         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 */
       else
       {
@@ -3155,7 +3155,7 @@ Query partially completed on the master 
 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 \
 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;
       }
       goto end;
@@ -3163,7 +3163,7 @@ START SLAVE; . Query: '%s'", expected_er
 
     /* If the query was not ignored, it is printed to the general log */
     if (!thd->is_error() || thd->main_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:
 
@@ -4489,8 +4489,8 @@ int Load_log_event::do_apply_event(NET* 
   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);
-  DBUG_ASSERT(thd->query == 0);
-  thd->query_length= 0;                         // Should not be needed
+  DBUG_ASSERT(thd->query() == 0);
+  thd->set_query_inner (NULL, 0);              // Should not be needed
   thd->is_slave_error= 0;
   clear_all_errors(thd, const_cast<Relay_log_info*>(rli));
 

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2009-09-29 15:38:40 +0000
+++ b/sql/mysqld.cc	2009-10-13 16:19:50 +0000
@@ -2520,7 +2520,7 @@ terribly wrong...\n");  
     }
     fprintf(stderr, "Trying to get some variables.\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->killed=%s\n", kreason);
   }

=== modified file 'sql/slave.cc'
--- a/sql/slave.cc	2009-09-30 22:25:06 +0000
+++ b/sql/slave.cc	2009-10-13 16:19:50 +0000
@@ -1288,7 +1288,7 @@ static int create_table_from_dump(THD* t
   thd->db = (char*)db;
   DBUG_ASSERT(thd->db != 0);
   thd->db_length= strlen(thd->db);
-  mysql_parse(thd, thd->query, packet_len, &found_semicolon); // run create table
+  mysql_parse(thd, thd->query(), packet_len, &found_semicolon); // run create table
   thd->db = save_db;            // leave things the way the were before
   thd->db_length= save_db_length;
   thd->options = save_options;

=== modified file 'sql/sp.cc'
--- a/sql/sp.cc	2009-07-28 22:39:58 +0000
+++ b/sql/sp.cc	2009-10-13 16:19:50 +0000
@@ -997,7 +997,7 @@ sp_drop_routine(THD *thd, int type, sp_n
 
   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();
   }
 
@@ -1067,7 +1067,7 @@ sp_update_routine(THD *thd, int type, sp
 
   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();
   }
 

=== modified file 'sql/sp_head.cc'
--- a/sql/sp_head.cc	2009-07-29 20:07:08 +0000
+++ b/sql/sp_head.cc	2009-10-13 16:19:50 +0000
@@ -2826,8 +2826,8 @@ sp_instr_stmt::execute(THD *thd, uint *n
   DBUG_ENTER("sp_instr_stmt::execute");
   DBUG_PRINT("info", ("command: %d", m_lex_keeper.sql_command()));
 
-  query= thd->query;
-  query_length= thd->query_length;
+  query= thd->query();
+  query_length= thd->query_length();
 #if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
   /* This s-p instr is profilable and will be captured. */
   thd->profiling.set_query_source(m_query.str, m_query.length);
@@ -2840,10 +2840,11 @@ sp_instr_stmt::execute(THD *thd, uint *n
       queries with SP vars can't be cached)
     */
     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,
-					  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);
 

=== modified file 'sql/sql_acl.cc'
--- a/sql/sql_acl.cc	2009-09-28 11:25:47 +0000
+++ b/sql/sql_acl.cc	2009-10-13 16:19:50 +0000
@@ -3184,7 +3184,7 @@ int mysql_table_grant(THD *thd, TABLE_LI
 
   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);
@@ -3349,7 +3349,7 @@ bool mysql_routine_grant(THD *thd, TABLE
 
   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);
@@ -3461,7 +3461,7 @@ bool mysql_grant(THD *thd, const char *d
 
   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);
@@ -5663,7 +5663,7 @@ bool mysql_create_user(THD *thd, List <L
     my_error(ER_CANNOT_USER, MYF(0), "CREATE USER", wrong_users.c_ptr_safe());
 
   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);
   close_thread_tables(thd);
@@ -5736,7 +5736,7 @@ bool mysql_drop_user(THD *thd, List <LEX
     my_error(ER_CANNOT_USER, MYF(0), "DROP USER", wrong_users.c_ptr_safe());
 
   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);
   close_thread_tables(thd);
@@ -5821,7 +5821,7 @@ bool mysql_rename_user(THD *thd, List <L
     my_error(ER_CANNOT_USER, MYF(0), "RENAME USER", wrong_users.c_ptr_safe());
   
   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);
   close_thread_tables(thd);
@@ -6003,7 +6003,7 @@ bool mysql_revoke_all(THD *thd,  List <L
 
   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);
   close_thread_tables(thd);

=== modified file 'sql/sql_cache.cc'
--- a/sql/sql_cache.cc	2009-09-23 13:21:29 +0000
+++ b/sql/sql_cache.cc	2009-10-13 16:19:50 +0000
@@ -1119,8 +1119,8 @@ void Query_cache::store_query(THD *thd, 
     DBUG_VOID_RETURN;
   uint8 tables_type= 0;
 
-  if ((local_tables= is_cacheable(thd, thd->query_length,
-				  thd->query, thd->lex, tables_used,
+  if ((local_tables= is_cacheable(thd, thd->query_length(),
+				  thd->query(), thd->lex, tables_used,
 				  &tables_type)))
   {
     NET *net= &thd->net;
@@ -1210,7 +1210,7 @@ def_week_frmt: %lu, in_trans: %d, autoco
     /* Key is query + database + flag */
     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",
 			    thd->db, (unsigned) thd->db_length)); 
     }
@@ -1218,24 +1218,24 @@ def_week_frmt: %lu, in_trans: %d, autoco
     {
       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;
     /*
       We should only copy structure (don't use it location directly)
       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);
 
     /* Check if another thread is processing the same query? */
     Query_cache_block *competitor = (Query_cache_block *)
-      hash_search(&queries, (uchar*) thd->query, tot_length);
+      hash_search(&queries, (uchar*) thd->query(), tot_length);
     DBUG_PRINT("qcache", ("competitor 0x%lx", (ulong) competitor));
     if (competitor == 0)
     {
       /* Query is not in cache and no one is working with it; Store it */
       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)),
 				    Query_cache_block::QUERY, local_tables);
       if (query_block != 0)

=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc	2009-09-29 15:38:40 +0000
+++ b/sql/sql_class.cc	2009-10-13 16:19:50 +0000
@@ -376,14 +376,14 @@ char *thd_security_context(THD *thd, cha
     str.append(proc_info);
   }
 
-  if (thd->query)
+  if (thd->query())
   {
     if (max_query_len < 1)
-      len= thd->query_length;
+      len= thd->query_length();
     else
-      len= min(thd->query_length, max_query_len);
+      len= min(thd->query_length(), max_query_len);
     str.append('\n');
-    str.append(thd->query, len);
+    str.append(thd->query(), len);
   }
   if (str.c_ptr_safe() == buffer)
     return buffer;
@@ -2434,12 +2434,12 @@ Statement::Statement(LEX *lex_arg, MEM_R
   id(id_arg),
   mark_used_columns(MARK_COLUMNS_READ),
   lex(lex_arg),
-  query(0),
-  query_length(0),
   cursor(0),
   db(NULL),
   db_length(0)
 {
+  query_string.length= 0;
+  query_string.str= NULL;
   name.str= NULL;
 }
 
@@ -2455,8 +2455,7 @@ void Statement::set_statement(Statement 
   id=             stmt->id;
   mark_used_columns=   stmt->mark_used_columns;
   lex=            stmt->lex;
-  query=          stmt->query;
-  query_length=   stmt->query_length;
+  query_string=   stmt->query_string;
   cursor=         stmt->cursor;
 }
 
@@ -2480,6 +2479,15 @@ void Statement::restore_backup_statement
 }
 
 
+/** 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()
 {
   /* Cleanup SQL processing state to reuse this statement in next query. */
@@ -2993,9 +3001,24 @@ extern "C" struct charset_info_st *thd_c
   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)
 {
-  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)
@@ -3174,8 +3197,7 @@ void THD::set_statement(Statement *stmt)
 void THD::set_query(char *query_arg, uint32 query_length_arg)
 {
   pthread_mutex_lock(&LOCK_thd_data);
-  query= query_arg;
-  query_length= query_length_arg;
+  set_query_inner(query_arg, query_length_arg);
   pthread_mutex_unlock(&LOCK_thd_data);
 }
 

=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h	2009-10-01 13:54:11 +0000
+++ b/sql/sql_class.h	2009-10-13 16:19:50 +0000
@@ -642,10 +642,13 @@ public:
     This printing is needed at least in SHOW PROCESSLIST and SHOW
     ENGINE INNODB STATUS.
   */
-  char *query;
-  uint32 query_length;                          // current query length
+  LEX_STRING query_string;
   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.
 

=== modified file 'sql/sql_db.cc'
--- a/sql/sql_db.cc	2009-09-23 13:21:29 +0000
+++ b/sql/sql_db.cc	2009-10-13 16:19:50 +0000
@@ -703,7 +703,7 @@ not_silent:
     char *query;
     uint query_length;
 
-    if (!thd->query)				// Only in replication
+    if (!thd->query())				// Only in replication
     {
       query= 	     tmp_query;
       query_length= (uint) (strxmov(tmp_query,"create database `",
@@ -711,8 +711,8 @@ not_silent:
     }
     else
     {
-      query= 	    thd->query;
-      query_length= thd->query_length;
+      query= 	    thd->query();
+      query_length= thd->query_length();
     }
 
     ha_binlog_log_query(thd, 0, LOGCOM_CREATE_DB,
@@ -805,13 +805,13 @@ bool mysql_alter_db(THD *thd, const char
   }
 
   ha_binlog_log_query(thd, 0, LOGCOM_ALTER_DB,
-                      thd->query, thd->query_length,
+                      thd->query(), thd->query_length(),
                       db, "");
 
   if (mysql_bin_log.is_open())
   {
     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);
 
     /*
@@ -948,7 +948,7 @@ bool mysql_rm_db(THD *thd,char *db,bool 
   {
     const char *query;
     ulong query_length;
-    if (!thd->query)
+    if (!thd->query())
     {
       /* The client used the old obsolete mysql_drop_db() call */
       query= path;
@@ -957,8 +957,8 @@ bool mysql_rm_db(THD *thd,char *db,bool 
     }
     else
     {
-      query =thd->query;
-      query_length= thd->query_length;
+      query =thd->query();
+      query_length= thd->query_length();
     }
     if (mysql_bin_log.is_open())
     {
@@ -1964,7 +1964,7 @@ bool mysql_upgrade_db(THD *thd, LEX_STRI
   if (mysql_bin_log.is_open())
   {
     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);
     thd->clear_error();
     mysql_bin_log.write(&qinfo);

=== modified file 'sql/sql_delete.cc'
--- a/sql/sql_delete.cc	2009-09-28 10:48:52 +0000
+++ b/sql/sql_delete.cc	2009-10-13 16:19:50 +0000
@@ -413,7 +413,7 @@ cleanup:
         therefore be treated as a DDL.
       */
       int log_result= thd->binlog_query(query_type,
-                                        thd->query, thd->query_length,
+                                        thd->query(), thd->query_length(),
                                         is_trans, FALSE, errcode);
 
       if (log_result)
@@ -850,7 +850,7 @@ void multi_delete::abort()
     {
       int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
       thd->binlog_query(THD::ROW_QUERY_TYPE,
-                        thd->query, thd->query_length,
+                        thd->query(), thd->query_length(),
                         transactional_tables, FALSE, errcode);
     }
     thd->transaction.all.modified_non_trans_table= true;
@@ -1024,7 +1024,7 @@ bool multi_delete::send_eof()
       else
         errcode= query_error_code(thd, killed_status == THD::NOT_KILLED);
       if (thd->binlog_query(THD::ROW_QUERY_TYPE,
-                            thd->query, thd->query_length,
+                            thd->query(), thd->query_length(),
                             transactional_tables, FALSE, errcode) &&
           !normal_tables)
       {
@@ -1166,7 +1166,7 @@ end:
         TRUNCATE must always be statement-based binlogged (not row-based) so
         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
     }
     VOID(pthread_mutex_lock(&LOCK_open));

=== modified file 'sql/sql_insert.cc'
--- a/sql/sql_insert.cc	2009-09-10 07:40:57 +0000
+++ b/sql/sql_insert.cc	2009-10-13 16:19:50 +0000
@@ -567,7 +567,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *t
   Name_resolution_context *context;
   Name_resolution_context_state ctx_state;
 #ifndef EMBEDDED_LIBRARY
-  char *query= thd->query;
+  char *query= thd->query();
   /*
     log_on is about delayed inserts only.
     By default, both logs are enabled (this won't cause problems if the server
@@ -801,7 +801,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *t
 #ifndef EMBEDDED_LIBRARY
     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);
       query=0;
     }
@@ -894,7 +894,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *t
 	*/
 	DBUG_ASSERT(thd->killed != THD::KILL_BAD_DATA || error > 0);
 	if (thd->binlog_query(THD::ROW_QUERY_TYPE,
-			      thd->query, thd->query_length,
+			      thd->query(), thd->query_length(),
 			      transactional_table, FALSE,
 			      errcode))
         {
@@ -1764,7 +1764,7 @@ public:
     pthread_cond_destroy(&cond);
     pthread_cond_destroy(&cond_client);
     thd.unlink();				// Must be unlinked under lock
-    x_free(thd.query);
+    x_free(thd.query());
     thd.security_ctx->user= thd.security_ctx->host=0;
     thread_count--;
     delayed_insert_threads--;
@@ -1910,7 +1910,7 @@ bool delayed_get_table(THD *thd, TABLE_L
       pthread_mutex_unlock(&LOCK_thread_count);
       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);
-      if (di->thd.db == NULL || di->thd.query == NULL)
+      if (di->thd.db == NULL || di->thd.query() == NULL)
       {
         /* The error is reported */
 	delete di;
@@ -1919,7 +1919,7 @@ bool delayed_get_table(THD *thd, TABLE_L
       }
       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= di->table_list.table_name= di->thd.query();
       di->table_list.db= di->thd.db;
       di->lock();
       pthread_mutex_lock(&di->mutex);
@@ -3250,7 +3250,7 @@ bool select_insert::send_eof()
     else
       errcode= query_error_code(thd, killed_status == THD::NOT_KILLED);
     thd->binlog_query(THD::ROW_QUERY_TYPE,
-                      thd->query, thd->query_length,
+                      thd->query(), thd->query_length(),
                       trans_table, FALSE, errcode);
   }
   table->file->ha_release_auto_increment();
@@ -3320,7 +3320,8 @@ void select_insert::abort() {
         if (mysql_bin_log.is_open())
         {
           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);
         }
         if (!thd->current_stmt_binlog_row_based && !can_rollback_data())

=== modified file 'sql/sql_load.cc'
--- a/sql/sql_load.cc	2009-09-28 12:41:10 +0000
+++ b/sql/sql_load.cc	2009-10-13 16:19:50 +0000
@@ -654,13 +654,12 @@ static bool write_execute_load_query_log
   strcpy(end, p);
   end += pl;
 
-  thd->query_length= end - load_data_query;
-  thd->query= load_data_query;
+  thd->set_query_inner (load_data_query, end - load_data_query);
 
   Execute_load_query_log_event
-    e(thd, thd->query, thd->query_length,
-      (uint) ((char*)fname_start - (char*)thd->query - 1),
-      (uint) ((char*)fname_end - (char*)thd->query),
+    e(thd, thd->query(), thd->query_length(),
+      (uint) ((char*)fname_start - (char*)thd->query() - 1),
+      (uint) ((char*)fname_end - (char*)thd->query()),
       (duplicates == DUP_REPLACE) ? LOAD_DUP_REPLACE :
       (ignore ? LOAD_DUP_IGNORE : LOAD_DUP_ERROR),
       transactional_table, FALSE, errcode);

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2009-10-07 15:03:42 +0000
+++ b/sql/sql_parse.cc	2009-10-13 16:19:50 +0000
@@ -477,10 +477,10 @@ static void handle_bootstrap_impl(THD *t
                                       thd->db_length + 1 +
                                       QUERY_CACHE_FLAGS_SIZE);
     thd->set_query(query, length);
-    DBUG_PRINT("query",("%-.4096s",thd->query));
+    DBUG_PRINT("query",("%-.4096s",thd->query()));
 #if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
     thd->profiling.start_new_query();
-    thd->profiling.set_query_source(thd->query, length);
+    thd->profiling.set_query_source(thd->query(), length);
 #endif
 
     /*
@@ -489,7 +489,7 @@ static void handle_bootstrap_impl(THD *t
     */
     thd->query_id=next_query_id();
     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
 
     bootstrap_error= thd->is_error();
@@ -1208,20 +1208,20 @@ bool dispatch_command(enum enum_server_c
   {
     if (alloc_query(thd, packet, packet_length))
       break;					// fatal error is set
-    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' */
     const char* end_of_stmt= NULL;
 
-    general_log_write(thd, command, thd->query, thd->query_length);
-    DBUG_PRINT("query",("%-.4096s",thd->query));
+    general_log_write(thd, command, thd->query(), thd->query_length());
+    DBUG_PRINT("query",("%-.4096s",thd->query()));
 #if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
-    thd->profiling.set_query_source(thd->query, thd->query_length);
+    thd->profiling.set_query_source(thd->query(), thd->query_length());
 #endif
 
     if (!(specialflag & SPECIAL_NO_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())
     {
@@ -1664,7 +1664,8 @@ void log_slow_statement(THD *thd)
     {
       thd_proc_info(thd, "logging slow query");
       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;
@@ -2975,7 +2976,7 @@ end_with_restore_list:
       /*
         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;
     lex->query_tables=all_tables;
@@ -3007,7 +3008,7 @@ end_with_restore_list:
       /*
         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;
     lex->query_tables=all_tables;
@@ -3030,7 +3031,7 @@ end_with_restore_list:
       /*
         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;
     lex->query_tables=all_tables;
@@ -3982,7 +3983,7 @@ end_with_restore_list:
       */
       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);
     } 
@@ -4559,7 +4560,7 @@ create_sp_error:
       case SP_KEY_NOT_FOUND:
 	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,
 			      ER_SP_DOES_NOT_EXIST, ER(ER_SP_DOES_NOT_EXIST),
 			      SP_COM_STRING(lex), lex->spname->m_name.str);
@@ -5950,9 +5951,9 @@ void mysql_parse(THD *thd, const char *i
             PROCESSLIST.
             Note that we don't need LOCK_thread_count to modify query_length.
           */
-          if (*found_semicolon &&
-              (thd->query_length= (ulong)(*found_semicolon - thd->query)))
-            thd->query_length--;
+          if (*found_semicolon && (ulong)(*found_semicolon - thd->query()))
+            thd->set_query_inner (thd->query(),
+                                  (uint32)(*found_semicolon - thd->query() - 1));
           /* Actually execute the query */
           if (*found_semicolon)
           {

=== modified file 'sql/sql_partition.cc'
--- a/sql/sql_partition.cc	2009-09-23 13:21:29 +0000
+++ b/sql/sql_partition.cc	2009-10-13 16:19:50 +0000
@@ -4077,7 +4077,7 @@ static int fast_end_partition(THD *thd, 
 
   if ((!is_empty) && (!written_bin_log) &&
       (!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),
               (ulong) (copied + deleted),
@@ -6235,7 +6235,7 @@ uint fast_alter_partition_table(THD *thd
         ERROR_INJECT_CRASH("crash_drop_partition_5") ||
         ((!thd->lex->no_write_to_binlog) &&
          (write_bin_log(thd, FALSE,
-                        thd->query, thd->query_length), FALSE)) ||
+                        thd->query(), thd->query_length()), FALSE)) ||
         ERROR_INJECT_CRASH("crash_drop_partition_6") ||
         ((frm_install= TRUE), FALSE) ||
         mysql_write_frm(lpt, WFRM_INSTALL_SHADOW) ||
@@ -6302,7 +6302,7 @@ uint fast_alter_partition_table(THD *thd
         ERROR_INJECT_CRASH("crash_add_partition_5") ||
         ((!thd->lex->no_write_to_binlog) &&
          (write_bin_log(thd, FALSE,
-                        thd->query, thd->query_length), FALSE)) ||
+                        thd->query(), thd->query_length()), FALSE)) ||
         ERROR_INJECT_CRASH("crash_add_partition_6") ||
         write_log_rename_frm(lpt) ||
         (not_completed= FALSE) ||
@@ -6392,7 +6392,7 @@ uint fast_alter_partition_table(THD *thd
         ERROR_INJECT_CRASH("crash_change_partition_6") ||
         ((!thd->lex->no_write_to_binlog) &&
          (write_bin_log(thd, FALSE,
-                        thd->query, thd->query_length), FALSE)) ||
+                        thd->query(), thd->query_length()), FALSE)) ||
         ERROR_INJECT_CRASH("crash_change_partition_7") ||
         mysql_write_frm(lpt, WFRM_INSTALL_SHADOW) ||
         ERROR_INJECT_CRASH("crash_change_partition_8") ||

=== modified file 'sql/sql_prepare.cc'
--- a/sql/sql_prepare.cc	2009-08-28 16:21:54 +0000
+++ b/sql/sql_prepare.cc	2009-10-13 16:19:50 +0000
@@ -752,7 +752,7 @@ static bool insert_params_with_log(Prepa
   const String *res;
   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);
 
   for (Item_param **it= begin; it < end; ++it)
@@ -914,7 +914,7 @@ static bool emb_insert_params_with_log(P
 
   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);
 
   for (; it < end; ++it, ++client_param)
@@ -1065,7 +1065,7 @@ static bool insert_params_from_vars_with
 
   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);
 
   for (Item_param **it= begin; it < end; ++it)
@@ -2457,9 +2457,9 @@ void mysqld_stmt_execute(THD *thd, char 
   }
 
 #if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
-  thd->profiling.set_query_source(stmt->query, stmt->query_length);
+  thd->profiling.set_query_source(stmt->query(), stmt->query_length());
 #endif
-  DBUG_PRINT("exec_query", ("%s", stmt->query));
+  DBUG_PRINT("exec_query", ("%s", stmt->query()));
   DBUG_PRINT("info",("stmt: 0x%lx", (long) stmt));
 
   sp_cache_flush_obsolete(&thd->sp_proc_cache);
@@ -3029,7 +3029,7 @@ bool Prepared_statement::prepare(const c
   old_stmt_arena= thd->stmt_arena;
   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;
   lex_start(thd);
 
@@ -3118,7 +3118,7 @@ bool Prepared_statement::prepare(const c
       the general log.
     */
     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);
 }
@@ -3309,7 +3309,7 @@ Prepared_statement::reprepare()
     return TRUE;
 
   error= ((name.str && copy.set_name(&name)) ||
-          copy.prepare(query, query_length) ||
+          copy.prepare(query(), query_length()) ||
           validate_metadata(&copy));
 
   if (cur_db_changed)
@@ -3547,8 +3547,7 @@ bool Prepared_statement::execute(String 
     to point at it even after we restore from backup. This is ok, as
     expanded query was allocated in thd->mem_root.
   */
-  stmt_backup.query= thd->query;
-  stmt_backup.query_length= thd->query_length;
+  stmt_backup.set_query_inner (thd->query(), thd->query_length());
 
   /*
     At first execution of prepared statement we may perform logical
@@ -3573,8 +3572,8 @@ bool Prepared_statement::execute(String 
       Note that multi-statements cannot exist here (they are not supported in
       prepared statements).
     */
-    if (query_cache_send_result_to_client(thd, thd->query,
-                                          thd->query_length) <= 0)
+    if (query_cache_send_result_to_client(thd, thd->query(),
+                                          thd->query_length()) <= 0)
     {
       error= mysql_execute_command(thd);
     }
@@ -3619,7 +3618,7 @@ bool Prepared_statement::execute(String 
     the general log.
   */
   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:
   flags&= ~ (uint) IS_IN_USE;

=== modified file 'sql/sql_rename.cc'
--- a/sql/sql_rename.cc	2009-06-19 08:24:43 +0000
+++ b/sql/sql_rename.cc	2009-10-13 16:19:50 +0000
@@ -177,7 +177,7 @@ bool mysql_rename_tables(THD *thd, TABLE
   /* Lets hope this doesn't fail as the result will be messy */ 
   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);
   }
 

=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc	2009-09-30 07:31:20 +0000
+++ b/sql/sql_show.cc	2009-10-13 16:19:50 +0000
@@ -1864,10 +1864,10 @@ void mysqld_list_processes(THD *thd,cons
         thd_info->query=0;
         /* Lock THD mutex that protects its data when looking at it. */
         pthread_mutex_lock(&tmp->LOCK_thd_data);
-        if (tmp->query)
+        if (tmp->query())
         {
-          uint length= min(max_query_length, tmp->query_length);
-          thd_info->query=(char*) thd->strmake(tmp->query,length);
+          uint length= min(max_query_length, tmp->query_length());
+          thd_info->query=(char*) thd->strmake(tmp->query(),length);
         }
         pthread_mutex_unlock(&tmp->LOCK_thd_data);
         thread_infos.append(thd_info);
@@ -1992,11 +1992,11 @@ int fill_schema_processlist(THD* thd, TA
         pthread_mutex_unlock(&mysys_var->mutex);
 
       /* INFO */
-      if (tmp->query)
+      if (tmp->query())
       {
-        table->field[7]->store(tmp->query,
+        table->field[7]->store(tmp->query(),
                                min(PROCESS_LIST_INFO_WIDTH,
-                                   tmp->query_length), cs);
+                                   tmp->query_length()), cs);
         table->field[7]->set_notnull();
       }
 

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2009-09-29 08:12:04 +0000
+++ b/sql/sql_table.cc	2009-10-13 16:19:50 +0000
@@ -2089,7 +2089,7 @@ int mysql_rm_table_part2(THD *thd, TABLE
           tables).  In this case, we can write the original query into
           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 &&
                tmp_table_deleted)
@@ -3554,7 +3554,7 @@ static inline void write_create_table_bi
       (!thd->current_stmt_binlog_row_based ||
        (thd->current_stmt_binlog_row_based &&
         !(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());
 }
 
 
@@ -5427,14 +5427,14 @@ binlog:
         write_bin_log(thd, TRUE, query.ptr(), query.length());
       }
       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
     */
   }
   else
-    write_bin_log(thd, TRUE, thd->query, thd->query_length);
+    write_bin_log(thd, TRUE, thd->query(), thd->query_length());
 
   res= FALSE;
 
@@ -5522,7 +5522,7 @@ mysql_discard_or_import_tablespace(THD *
     error=1;
   if (error)
     goto err;
-  write_bin_log(thd, FALSE, thd->query, thd->query_length);
+  write_bin_log(thd, FALSE, thd->query(), thd->query_length());
 
 err:
   ha_autocommit_or_rollback(thd, error);
@@ -6531,7 +6531,7 @@ bool mysql_alter_table(THD *thd,char *ne
       if (mysql_bin_log.is_open())
       {
         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);
         mysql_bin_log.write(&qinfo);
       }
@@ -6785,7 +6785,7 @@ view_err:
 
     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);
     }
     else if (error > 0)
@@ -7275,7 +7275,7 @@ view_err:
       goto err1;
     /* We don't replicate alter table statement on temporary tables */
     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;
   }
 
@@ -7432,13 +7432,13 @@ view_err:
   DBUG_EXECUTE_IF("sleep_alter_before_main_binlog", my_sleep(6000000););
 
   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);
 
   DBUG_ASSERT(!(mysql_bin_log.is_open() &&
                 thd->current_stmt_binlog_row_based &&
                 (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))
   {

=== modified file 'sql/sql_tablespace.cc'
--- a/sql/sql_tablespace.cc	2007-06-19 11:27:53 +0000
+++ b/sql/sql_tablespace.cc	2009-10-13 16:19:50 +0000
@@ -66,6 +66,6 @@ int mysql_alter_tablespace(THD *thd, st_
                         ha_resolve_storage_engine_name(hton),
                         "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);
 }

=== modified file 'sql/sql_trigger.cc'
--- a/sql/sql_trigger.cc	2009-06-17 14:56:44 +0000
+++ b/sql/sql_trigger.cc	2009-10-13 16:19:50 +0000
@@ -409,7 +409,7 @@ bool mysql_create_or_drop_trigger(THD *t
       */
       result= FALSE;
       /* 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;
     }
   }
@@ -918,7 +918,7 @@ bool Table_triggers_list::drop_trigger(T
   List_iterator<LEX_STRING> it_connection_cl_name(connection_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++))
   {

=== modified file 'sql/sql_udf.cc'
--- a/sql/sql_udf.cc	2009-05-15 12:57:51 +0000
+++ b/sql/sql_udf.cc	2009-10-13 16:19:50 +0000
@@ -506,7 +506,7 @@ int mysql_create_function(THD *thd,udf_f
   rw_unlock(&THR_LOCK_udf);
 
   /* 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);
 
@@ -581,7 +581,7 @@ int mysql_drop_function(THD *thd,const L
   rw_unlock(&THR_LOCK_udf);
 
   /* 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);
  err:

=== modified file 'sql/sql_update.cc'
--- a/sql/sql_update.cc	2009-08-28 16:21:54 +0000
+++ b/sql/sql_update.cc	2009-10-13 16:19:50 +0000
@@ -810,7 +810,7 @@ int mysql_update(THD *thd,
         errcode= query_error_code(thd, killed_status == THD::NOT_KILLED);
 
       if (thd->binlog_query(THD::ROW_QUERY_TYPE,
-                            thd->query, thd->query_length,
+                            thd->query(), thd->query_length(),
                             transactional_table, FALSE, errcode))
       {
         error=1;				// Rollback update
@@ -1860,7 +1860,7 @@ void multi_update::abort()
       */
       int errcode= query_error_code(thd, thd->killed == THD::NOT_KILLED);
       thd->binlog_query(THD::ROW_QUERY_TYPE,
-                        thd->query, thd->query_length,
+                        thd->query(), thd->query_length(),
                         transactional_tables, FALSE, errcode);
     }
     thd->transaction.all.modified_non_trans_table= TRUE;
@@ -2093,7 +2093,7 @@ bool multi_update::send_eof()
       else
         errcode= query_error_code(thd, killed_status == THD::NOT_KILLED);
       if (thd->binlog_query(THD::ROW_QUERY_TYPE,
-                            thd->query, thd->query_length,
+                            thd->query(), thd->query_length(),
                             transactional_tables, FALSE, errcode))
       {
 	local_error= 1;				// Rollback update

=== modified file 'sql/sql_view.cc'
--- a/sql/sql_view.cc	2009-08-28 16:21:54 +0000
+++ b/sql/sql_view.cc	2009-10-13 16:19:50 +0000
@@ -1652,7 +1652,7 @@ bool mysql_drop_view(THD *thd, TABLE_LIS
     /* if something goes wrong, bin-log with possible error code,
        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));

=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy	2009-09-30 19:37:52 +0000
+++ b/sql/sql_yacc.yy	2009-10-13 16:19:50 +0000
@@ -10724,7 +10724,7 @@ param_marker:
               my_error(ER_VIEW_SELECT_VARIABLE, MYF(0));
               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))
             {
               my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));

=== modified file 'storage/blackhole/ha_blackhole.cc'
--- a/storage/blackhole/ha_blackhole.cc	2008-11-10 20:21:49 +0000
+++ b/storage/blackhole/ha_blackhole.cc	2009-10-13 16:19:50 +0000
@@ -105,7 +105,7 @@ int ha_blackhole::update_row(const uchar
 {
   DBUG_ENTER("ha_blackhole::update_row");
   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(HA_ERR_WRONG_COMMAND);
 }
@@ -114,7 +114,7 @@ int ha_blackhole::delete_row(const uchar
 {
   DBUG_ENTER("ha_blackhole::delete_row");
   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(HA_ERR_WRONG_COMMAND);
 }
@@ -130,7 +130,7 @@ int ha_blackhole::rnd_next(uchar *buf)
 {
   DBUG_ENTER("ha_blackhole::rnd_next");
   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(HA_ERR_END_OF_FILE);
 }
@@ -212,7 +212,7 @@ int ha_blackhole::index_read_map(uchar *
 {
   DBUG_ENTER("ha_blackhole::index_read");
   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(HA_ERR_END_OF_FILE);
 }
@@ -224,7 +224,7 @@ int ha_blackhole::index_read_idx_map(uch
 {
   DBUG_ENTER("ha_blackhole::index_read_idx");
   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(HA_ERR_END_OF_FILE);
 }
@@ -235,7 +235,7 @@ int ha_blackhole::index_read_last_map(uc
 {
   DBUG_ENTER("ha_blackhole::index_read_last");
   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(HA_ERR_END_OF_FILE);
 }

=== modified file 'storage/myisam/ha_myisam.cc'
--- a/storage/myisam/ha_myisam.cc	2009-09-09 15:13:13 +0000
+++ b/storage/myisam/ha_myisam.cc	2009-10-13 16:19:50 +0000
@@ -1610,8 +1610,8 @@ bool ha_myisam::check_and_repair(THD *th
     check_opt.flags|=T_QUICK;
   sql_print_warning("Checking table:   '%s'",table->s->path.str);
 
-  old_query= thd->query;
-  old_query_length= thd->query_length;
+  old_query= thd->query();
+  old_query_length= thd->query_length();
   thd->set_query(table->s->table_name.str,
                  (uint) table->s->table_name.length);
 


Attachment: [text/bzr-bundle] bzr/joro@sun.com-20091013161950-ulcglrwadvjtspgh.bundle
Thread
bzr commit into mysql-5.1-bugteam branch (joro:3156) Bug#40877Georgi Kodinov13 Oct
  • Re: bzr commit into mysql-5.1-bugteam branch (joro:3156) Bug#40877Sergey Vojtovich14 Oct
  • Re: bzr commit into mysql-5.1-bugteam branch (joro:3156) Bug#40877Sergey Vojtovich16 Oct