From 63e56390a3f1a4f80642932a790ab74f28de8010 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Thu, 10 Sep 2009 03:18:29 -0600 Subject: WL#2110 (SIGNAL) WL#2265 (RESIGNAL) Manual merge of SIGNAL and RESIGNAL to mysql-trunk-signal, plus required dependencies. --- sql/sql_class.h | 351 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 180 insertions(+), 171 deletions(-) (limited to 'sql/sql_class.h') diff --git a/sql/sql_class.h b/sql/sql_class.h index a8fe3227aeb..d7814fcb03f 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1,4 +1,4 @@ -/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc. +/* Copyright (C) 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -265,6 +265,41 @@ public: LEX_COLUMN (const String& x,const uint& y ): column (x),rights (y) {} }; +/* SIGNAL / RESIGNAL / GET DIAGNOSTICS */ + +/** + This enumeration list all the condition item names of a condition in the + SQL condition area. +*/ +typedef enum enum_diag_condition_item_name +{ + /* + Conditions that can be set by the user (SIGNAL/RESIGNAL), + and by the server implementation. + */ + + DIAG_CLASS_ORIGIN= 0, + FIRST_DIAG_SET_PROPERTY= DIAG_CLASS_ORIGIN, + DIAG_SUBCLASS_ORIGIN= 1, + DIAG_CONSTRAINT_CATALOG= 2, + DIAG_CONSTRAINT_SCHEMA= 3, + DIAG_CONSTRAINT_NAME= 4, + DIAG_CATALOG_NAME= 5, + DIAG_SCHEMA_NAME= 6, + DIAG_TABLE_NAME= 7, + DIAG_COLUMN_NAME= 8, + DIAG_CURSOR_NAME= 9, + DIAG_MESSAGE_TEXT= 10, + DIAG_MYSQL_ERRNO= 11, + LAST_DIAG_SET_PROPERTY= DIAG_MYSQL_ERRNO +} Diag_condition_item_name; + +/** + Name of each diagnostic condition item. + This array is indexed by Diag_condition_item_name. +*/ +extern const LEX_STRING Diag_condition_item_names[]; + #include "sql_lex.h" /* Must be here */ class Delayed_insert; @@ -1038,12 +1073,12 @@ protected: public: /** - Handle an error condition. + Handle a sql condition. This method can be implemented by a subclass to achieve any of the following: - - mask an error internally, prevent exposing it to the user, - - mask an error and throw another one instead. - When this method returns true, the error condition is considered + - mask a warning/error internally, prevent exposing it to the user, + - mask a warning/error and throw another one instead. + When this method returns true, the sql condition is considered 'handled', and will not be propagated to upper layers. It is the responsability of the code installing an internal handler to then check for trapped conditions, and implement logic to recover @@ -1057,15 +1092,17 @@ public: before removing it from the exception stack with THD::pop_internal_handler(). - @param sql_errno the error number - @param level the error level @param thd the calling thread - @return true if the error is handled + @param cond the condition raised. + @return true if the condition is handled */ - virtual bool handle_error(uint sql_errno, - const char *message, - MYSQL_ERROR::enum_warning_level level, - THD *thd) = 0; + virtual bool handle_condition(THD *thd, + uint sql_errno, + const char* sqlstate, + MYSQL_ERROR::enum_warning_level level, + const char* msg, + MYSQL_ERROR ** cond_hdl) = 0; + private: Internal_error_handler *m_prev_internal_handler; friend class THD; @@ -1080,10 +1117,12 @@ private: class Dummy_error_handler : public Internal_error_handler { public: - bool handle_error(uint sql_errno, - const char *message, - MYSQL_ERROR::enum_warning_level level, - THD *thd) + bool handle_condition(THD *thd, + uint sql_errno, + const char* sqlstate, + MYSQL_ERROR::enum_warning_level level, + const char* msg, + MYSQL_ERROR ** cond_hdl) { /* Ignore error */ return TRUE; @@ -1091,123 +1130,6 @@ public: }; -/** - Stores status of the currently executed statement. - Cleared at the beginning of the statement, and then - can hold either OK, ERROR, or EOF status. - Can not be assigned twice per statement. -*/ - -class Diagnostics_area -{ -public: - enum enum_diagnostics_status - { - /** The area is cleared at start of a statement. */ - DA_EMPTY= 0, - /** Set whenever one calls my_ok(). */ - DA_OK, - /** Set whenever one calls my_eof(). */ - DA_EOF, - /** Set whenever one calls my_error() or my_message(). */ - DA_ERROR, - /** Set in case of a custom response, such as one from COM_STMT_PREPARE. */ - DA_DISABLED - }; - /** True if status information is sent to the client. */ - bool is_sent; - /** Set to make set_error_status after set_{ok,eof}_status possible. */ - bool can_overwrite_status; - - void set_ok_status(THD *thd, ha_rows affected_rows_arg, - ulonglong last_insert_id_arg, - const char *message); - void set_eof_status(THD *thd); - void set_error_status(THD *thd, uint sql_errno_arg, const char *message_arg); - - void disable_status(); - - void reset_diagnostics_area(); - - bool is_set() const { return m_status != DA_EMPTY; } - bool is_error() const { return m_status == DA_ERROR; } - bool is_eof() const { return m_status == DA_EOF; } - bool is_ok() const { return m_status == DA_OK; } - bool is_disabled() const { return m_status == DA_DISABLED; } - enum_diagnostics_status status() const { return m_status; } - - const char *message() const - { DBUG_ASSERT(m_status == DA_ERROR || m_status == DA_OK); return m_message; } - - uint sql_errno() const - { DBUG_ASSERT(m_status == DA_ERROR); return m_sql_errno; } - - uint server_status() const - { - DBUG_ASSERT(m_status == DA_OK || m_status == DA_EOF); - return m_server_status; - } - - ha_rows affected_rows() const - { DBUG_ASSERT(m_status == DA_OK); return m_affected_rows; } - - ulonglong last_insert_id() const - { DBUG_ASSERT(m_status == DA_OK); return m_last_insert_id; } - - uint total_warn_count() const - { - DBUG_ASSERT(m_status == DA_OK || m_status == DA_EOF); - return m_total_warn_count; - } - - Diagnostics_area() { reset_diagnostics_area(); } - -private: - /** Message buffer. Can be used by OK or ERROR status. */ - char m_message[MYSQL_ERRMSG_SIZE]; - /** - SQL error number. One of ER_ codes from share/errmsg.txt. - Set by set_error_status. - */ - uint m_sql_errno; - - /** - Copied from thd->server_status when the diagnostics area is assigned. - We need this member as some places in the code use the following pattern: - thd->server_status|= ... - my_eof(thd); - thd->server_status&= ~... - Assigned by OK, EOF or ERROR. - */ - uint m_server_status; - /** - The number of rows affected by the last statement. This is - semantically close to thd->row_count_func, but has a different - life cycle. thd->row_count_func stores the value returned by - function ROW_COUNT() and is cleared only by statements that - update its value, such as INSERT, UPDATE, DELETE and few others. - This member is cleared at the beginning of the next statement. - - We could possibly merge the two, but life cycle of thd->row_count_func - can not be changed. - */ - ha_rows m_affected_rows; - /** - Similarly to the previous member, this is a replacement of - thd->first_successful_insert_id_in_prev_stmt, which is used - to implement LAST_INSERT_ID(). - */ - ulonglong m_last_insert_id; - /** The total number of warnings. */ - uint m_total_warn_count; - enum_diagnostics_status m_status; - /** - @todo: the following THD members belong here: - - warn_list, warn_count, - */ -}; - - /** Storage engine specific thread local data. */ @@ -1234,6 +1156,7 @@ struct Ha_data Ha_data() :ha_ptr(NULL) {} }; +extern "C" void my_message_sql(uint error, const char *str, myf MyFlags); /** @class THD @@ -1276,7 +1199,6 @@ public: struct st_mysql_stmt *current_stmt; #endif NET net; // client connection descriptor - MEM_ROOT warn_root; // For warnings and errors Protocol *protocol; // Current protocol Protocol_text protocol_text; // Normal protocol Protocol_binary protocol_binary; // Binary protocol @@ -1692,16 +1614,8 @@ public: table_map used_tables; USER_CONN *user_connect; CHARSET_INFO *db_charset; - /* - FIXME: this, and some other variables like 'count_cuted_fields' - maybe should be statement/cursor local, that is, moved to Statement - class. With current implementation warnings produced in each prepared - statement/cursor settle here. - */ - List warn_list; - uint warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_END]; - uint total_warn_count; - Diagnostics_area main_da; + Warning_info *warning_info; + Diagnostics_area *stmt_da; #if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER) PROFILING profiling; #endif @@ -1714,7 +1628,7 @@ public: from table are necessary for this select, to check if it's necessary to update auto-updatable fields (like auto_increment and timestamp). */ - query_id_t query_id, warn_id; + query_id_t query_id; ulong col_access; #ifdef ERROR_INJECT_SUPPORT @@ -1723,11 +1637,6 @@ public: /* Statement id is thread-wide. This counter is used to generate ids */ ulong statement_id_counter; ulong rand_saved_seed1, rand_saved_seed2; - /* - Row counter, mainly for errors and warnings. Not increased in - create_sort_index(); may differ from examined_row_count. - */ - ulong row_count; pthread_t real_id; /* For debugging */ my_thread_id thread_id; uint tmp_table, global_read_lock; @@ -2031,8 +1940,8 @@ public: inline void clear_error() { DBUG_ENTER("clear_error"); - if (main_da.is_error()) - main_da.reset_diagnostics_area(); + if (stmt_da->is_error()) + stmt_da->reset_diagnostics_area(); is_slave_error= 0; DBUG_VOID_RETURN; } @@ -2064,7 +1973,7 @@ public: To raise this flag, use my_error(). */ - inline bool is_error() const { return main_da.is_error(); } + inline bool is_error() const { return stmt_da->is_error(); } inline CHARSET_INFO *charset() { return variables.character_set_client; } void update_charset(); @@ -2260,19 +2169,107 @@ public: void push_internal_handler(Internal_error_handler *handler); /** - Handle an error condition. - @param sql_errno the error number - @param level the error level - @return true if the error is handled - */ - virtual bool handle_error(uint sql_errno, const char *message, - MYSQL_ERROR::enum_warning_level level); + Handle a sql condition. + @param sql_errno the condition error number + @param sqlstate the condition sqlstate + @param level the condition level + @param msg the condition message text + @param[out] cond_hdl the sql condition raised, if any + @return true if the condition is handled + */ + virtual bool handle_condition(uint sql_errno, + const char* sqlstate, + MYSQL_ERROR::enum_warning_level level, + const char* msg, + MYSQL_ERROR ** cond_hdl); /** Remove the error handler last pushed. */ void pop_internal_handler(); + /** + Raise an exception condition. + @param code the MYSQL_ERRNO error code of the error + */ + void raise_error(uint code); + + /** + Raise an exception condition, with a formatted message. + @param code the MYSQL_ERRNO error code of the error + */ + void raise_error_printf(uint code, ...); + + /** + Raise a completion condition (warning). + @param code the MYSQL_ERRNO error code of the warning + */ + void raise_warning(uint code); + + /** + Raise a completion condition (warning), with a formatted message. + @param code the MYSQL_ERRNO error code of the warning + */ + void raise_warning_printf(uint code, ...); + + /** + Raise a completion condition (note), with a fixed message. + @param code the MYSQL_ERRNO error code of the note + */ + void raise_note(uint code); + + /** + Raise an completion condition (note), with a formatted message. + @param code the MYSQL_ERRNO error code of the note + */ + void raise_note_printf(uint code, ...); + +private: + /* + Only the implementation of the SIGNAL and RESIGNAL statements + is permitted to raise SQL conditions in a generic way, + or to raise them by bypassing handlers (RESIGNAL). + To raise a SQL condition, the code should use the public + raise_error() or raise_warning() methods provided by class THD. + */ + friend class Signal_common; + friend class Signal_statement; + friend class Resignal_statement; + friend void push_warning(THD*, MYSQL_ERROR::enum_warning_level, uint, const char*); + friend void my_message_sql(uint, const char *, myf); + + /** + Raise a generic SQL condition. + @param sql_errno the condition error number + @param sqlstate the condition SQLSTATE + @param level the condition level + @param msg the condition message text + @return The condition raised, or NULL + */ + MYSQL_ERROR* + raise_condition(uint sql_errno, + const char* sqlstate, + MYSQL_ERROR::enum_warning_level level, + const char* msg); + + /** + Raise a generic SQL condition, without activation any SQL condition + handlers. + This method is necessary to support the RESIGNAL statement, + which is allowed to bypass SQL exception handlers. + @param sql_errno the condition error number + @param sqlstate the condition SQLSTATE + @param level the condition level + @param msg the condition message text + @return The condition raised, or NULL + */ + MYSQL_ERROR* + raise_condition_no_handler(uint sql_errno, + const char* sqlstate, + MYSQL_ERROR::enum_warning_level level, + const char* msg); + +public: /** Overloaded to guard query/query_length fields */ virtual void set_statement(Statement *stmt); @@ -2300,25 +2297,27 @@ private: tree itself is reused between executions and thus is stored elsewhere. */ MEM_ROOT main_mem_root; + Warning_info main_warning_info; + Diagnostics_area main_da; }; -/** A short cut for thd->main_da.set_ok_status(). */ +/** A short cut for thd->stmt_da->set_ok_status(). */ inline void -my_ok(THD *thd, ha_rows affected_rows= 0, ulonglong id= 0, +my_ok(THD *thd, ulonglong affected_rows= 0, ulonglong id= 0, const char *message= NULL) { - thd->main_da.set_ok_status(thd, affected_rows, id, message); + thd->stmt_da->set_ok_status(thd, affected_rows, id, message); } -/** A short cut for thd->main_da.set_eof_status(). */ +/** A short cut for thd->stmt_da->set_eof_status(). */ inline void my_eof(THD *thd) { - thd->main_da.set_eof_status(thd); + thd->stmt_da->set_eof_status(thd); } #define tmp_disable_binlog(A) \ @@ -2986,11 +2985,11 @@ public: /* Bits in sql_command_flags */ -#define CF_CHANGES_DATA 1 -#define CF_HAS_ROW_COUNT 2 -#define CF_STATUS_COMMAND 4 -#define CF_SHOW_TABLE_COMMAND 8 -#define CF_WRITE_LOGS_COMMAND 16 +#define CF_CHANGES_DATA (1U << 0) +#define CF_HAS_ROW_COUNT (1U << 1) +#define CF_STATUS_COMMAND (1U << 2) +#define CF_SHOW_TABLE_COMMAND (1U << 3) +#define CF_WRITE_LOGS_COMMAND (1U << 4) /** Must be set for SQL statements that may contain Item expressions and/or use joins and tables. @@ -3004,7 +3003,17 @@ public: reprepare. Consequently, complex item expressions and joins are currently prohibited in these statements. */ -#define CF_REEXECUTION_FRAGILE 32 +#define CF_REEXECUTION_FRAGILE (1U << 5) + +/** + Diagnostic statement. + Diagnostic statements: + - SHOW WARNING + - SHOW ERROR + - GET DIAGNOSTICS (WL#2111) + do not modify the diagnostics area during execution. +*/ +#define CF_DIAGNOSTIC_STMT (1U << 8) /* Functions in sql_class.cc */ -- cgit v1.2.1 From d47710c8dccd295428fa7547720f4a5d7311c413 Mon Sep 17 00:00:00 2001 From: Mats Kindahl Date: Wed, 23 Sep 2009 23:32:31 +0200 Subject: WL#5016: Fix header file include guards Adding header include file guards to files that are missing such. --- sql/sql_class.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'sql/sql_class.h') diff --git a/sql/sql_class.h b/sql/sql_class.h index f52d5fae76f..49f9bc3fd5e 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -14,6 +14,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifndef SQL_CLASS_INCLUDED +#define SQL_CLASS_INCLUDED + /* Classes in mysql */ #ifdef USE_PRAGMA_INTERFACE @@ -3003,3 +3006,4 @@ void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var, void mark_transaction_to_rollback(THD *thd, bool all); #endif /* MYSQL_SERVER */ +#endif /* SQL_CLASS_INCLUDED */ -- cgit v1.2.1 From 623ed58cfda0aef6b6bf545a4200357a58a8a4cc Mon Sep 17 00:00:00 2001 From: He Zhenxing Date: Sat, 26 Sep 2009 12:49:49 +0800 Subject: Backporting WL#4398 WL#1720 Backporting BUG#44058 BUG#42244 BUG#45672 BUG#45673 Backporting BUG#45819 BUG#45973 BUG#39012 --- sql/sql_class.h | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) (limited to 'sql/sql_class.h') diff --git a/sql/sql_class.h b/sql/sql_class.h index f52d5fae76f..3d7ff0ca0a1 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -22,6 +22,7 @@ #include "log.h" #include "rpl_tblmap.h" +#include "replication.h" /** An interface that is used to take an action when @@ -1940,27 +1941,11 @@ public: inline const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t* mutex, const char* msg) { - const char* old_msg = proc_info; - safe_mutex_assert_owner(mutex); - mysys_var->current_mutex = mutex; - mysys_var->current_cond = cond; - proc_info = msg; - return old_msg; + return thd_enter_cond(this, cond, mutex, msg); } inline void exit_cond(const char* old_msg) { - /* - Putting the mutex unlock in exit_cond() ensures that - mysys_var->current_mutex is always unlocked _before_ mysys_var->mutex is - locked (if that would not be the case, you'll get a deadlock if someone - does a THD::awake() on you). - */ - pthread_mutex_unlock(mysys_var->current_mutex); - pthread_mutex_lock(&mysys_var->mutex); - mysys_var->current_mutex = 0; - mysys_var->current_cond = 0; - proc_info = old_msg; - pthread_mutex_unlock(&mysys_var->mutex); + thd_exit_cond(this, old_msg); } inline time_t query_start() { query_start_used=1; return start_time; } inline void set_time() -- cgit v1.2.1 From 2118bd104c4dd7c2aab0b80fa7053d8a491a90c4 Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Mon, 28 Sep 2009 10:21:25 +0300 Subject: Ported WL#3220 to mysql-next-mr. --- sql/sql_class.h | 1 + 1 file changed, 1 insertion(+) (limited to 'sql/sql_class.h') diff --git a/sql/sql_class.h b/sql/sql_class.h index e845b5a727c..4874801e380 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -54,6 +54,7 @@ class Reprepare_observer { public: + Reprepare_observer() {} /** Check if a change of metadata is OK. In future the signature of this method may be extended to accept the old -- cgit v1.2.1 From b7f887652b22d49574860d6948e67f0ea7a83294 Mon Sep 17 00:00:00 2001 From: Alfranio Correia Date: Tue, 29 Sep 2009 14:55:36 +0100 Subject: WL#4828 and BUG#45747 NOTE: Backporting the patch to next-mr. WL#4828 Augment DBUG_ENTER/DBUG_EXIT to crash MySQL in different functions ------- The assessment of the replication code in the presence of faults is extremely import to increase reliability. In particular, one needs to know if servers will either correctly recovery or print out appropriate error messages thus avoiding unexpected problems in a production environment. In order to accomplish this, the current patch refactories the debug macros already provided in the source code and introduces three new macros that allows to inject faults, specifically crashes, while entering or exiting a function or method. For instance, to crash a server while returning from the init_slave function (see module sql/slave.cc), one needs to do what follows: 1 - Modify the source replacing DBUG_RETURN by DBUG_CRASH_RETURN; DBUG_CRASH_RETURN(0); 2 - Use the debug variable to activate dbug instructions: SET SESSION debug="+d,init_slave_crash_return"; The new macros are briefly described below: DBUG_CRASH_ENTER (function) is equivalent to DBUG_ENTER which registers the beginning of a function but in addition to it allows for crashing the server while entering the function if the appropriate dbug instruction is activate. In this case, the dbug instruction should be "+d,function_crash_enter". DBUG_CRASH_RETURN (value) is equivalent to DBUG_RETURN which notifies the end of a function but in addition to it allows for crashing the server while returning from the function if the appropriate dbug instruction is activate. In this case, the dbug instruction should be "+d,function_crash_return". Note that "function" should be the same string used by either the DBUG_ENTER or DBUG_CRASH_ENTER. DBUG_CRASH_VOID_RETURN (value) is equivalent to DBUG_VOID_RETURN which notifies the end of a function but in addition to it allows for crashing the server while returning from the function if the appropriate dbug instruction is activate. In this case, the dbug instruction should be "+d,function_crash_return". Note that "function" should be the same string used by either the DBUG_ENTER or DBUG_CRASH_ENTER. To inject other faults, for instance, wrong return values, one should rely on the macros already available. The current patch also removes a set of macros that were either not being used or were redundant as other macros could be used to provide the same feature. In the future, we also consider dynamic instrumentation of the code. BUG#45747 DBUG_CRASH_* is not setting the strict option --------- When combining DBUG_CRASH_* with "--debug=d:t:i:A,file" the server crashes due to a call to the abort function in the DBUG_CRASH_* macro althought the appropriate keyword has not been set. --- sql/sql_class.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'sql/sql_class.h') diff --git a/sql/sql_class.h b/sql/sql_class.h index 49f9bc3fd5e..47b51559ed1 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1720,9 +1720,6 @@ public: query_id_t query_id, warn_id; ulong col_access; -#ifdef ERROR_INJECT_SUPPORT - ulong error_inject_value; -#endif /* Statement id is thread-wide. This counter is used to generate ids */ ulong statement_id_counter; ulong rand_saved_seed1, rand_saved_seed2; -- cgit v1.2.1 From 0da357645c41867552481b18b7de12806f743fe0 Mon Sep 17 00:00:00 2001 From: Jon Olav Hauglid Date: Fri, 9 Oct 2009 15:59:25 +0200 Subject: Bug #44651 "have_community_features" variable should be renamed "have_profiling" 1) Renamed have_community_features server system variable to have_profiling. 2) Removed eable-community-features configure option and ENABLE_COMMUNITY_FEATURES macro. 3) Removed COMMUNITY_SERVER macro and replaced its usage by ENABLED_PROFILING. Only --enable-profiling is now needed to enable profiling. It was the only existing "community feature", so there was no need for both configure options. Using --enable-community-features will give a warning message since it no longer exists. --- sql/sql_class.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sql/sql_class.h') diff --git a/sql/sql_class.h b/sql/sql_class.h index 4874801e380..310623c0d5c 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1644,7 +1644,7 @@ public: CHARSET_INFO *db_charset; Warning_info *warning_info; Diagnostics_area *stmt_da; -#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER) +#if defined(ENABLED_PROFILING) PROFILING profiling; #endif -- cgit v1.2.1 From c0221b0e95019ede5753302fac13934aaa55c3ba Mon Sep 17 00:00:00 2001 From: Dmitry Lenev Date: Fri, 9 Oct 2009 18:29:51 +0400 Subject: This patch is prerequisite for the 2nd milestone of WL#148 "Foreign keys" storing and restoring information about foreign keys in the .FRM files and properly displaying it in SHOW CREATE TABLE output and I_S tables. The idea of this patch is to change type of Key_part_spec::field_name and Key::name to LEX_STRING in order to avoid extra strlen() calls during semantic analysis and statement execution, particularly, in code to be implemented on the 2nd milestone of WL#148. Note that since we are not using LEX_STRING everywhere yet (e.g. in Create_field and KEY) and we want to limit scope of our changes we have to do strlen() in places where we create Key and Key_part_spec instances from objects using plain (char*) for strings. These calls will go away during the process of further (char*) -> LEX_STRING refactoring. We have introduced these changes in 6.0 and backported them to 5.5 tree to make people aware of these changes as early as possible and to simplify merges with mysql-fk and mysql-6.1-fk trees. No test case is needed since this patch does not introduce any user visible changes. sql/sql_class.cc: Key_part_spec::field_name is now LEX_STRING. Adjusted code accordingly. sql/sql_class.h: Changed type of Key_part_spec::field_name and Key::name to LEX_STRING in order to avoid extra strlen() calls in code responsible for semantic analysis and statement execution (e.g. in future code responsible for saving/restoring info about foreign keys). sql/sql_lex.cc: Moved null_lex_str from sql_yacc.yy to sql_lex.cc and added its declaration to sql_lex.h to make it accessible in other SQL-layer modules (e.g. sql_parse.cc). sql/sql_lex.h: Made null_lex_str accessible from outside of sql_lex.cc. sql/sql_parse.cc: Key_part_spec::field_name and Key::name are now LEX_STRING. Adjusted code accordingly. sql/sql_table.cc: Adjusted code to accomodate change of type to LEX_STRING for Key_part_spec::field_name and Key::name. sql/sql_yacc.yy: Now Key::name and Key_part_spec::field_name are LEX_STRINGs. Adjusted grammar to be able properly initialize them. This should allow us to save on some strlen() calls during later stages of statement execution. --- sql/sql_class.h | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'sql/sql_class.h') diff --git a/sql/sql_class.h b/sql/sql_class.h index 310623c0d5c..4dea3acc5e7 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -145,9 +145,14 @@ typedef struct st_copy_info { class Key_part_spec :public Sql_alloc { public: - const char *field_name; + LEX_STRING field_name; uint length; - Key_part_spec(const char *name,uint len=0) :field_name(name), length(len) {} + Key_part_spec(const LEX_STRING &name, uint len) + : field_name(name), length(len) + {} + Key_part_spec(const char *name, const size_t name_len, uint len) + : length(len) + { field_name.str= (char *)name; field_name.length= name_len; } bool operator==(const Key_part_spec& other) const; /** Construct a copy of this Key_part_spec. field_name is copied @@ -200,15 +205,24 @@ public: enum Keytype type; KEY_CREATE_INFO key_create_info; List columns; - const char *name; + LEX_STRING name; bool generated; - Key(enum Keytype type_par, const char *name_arg, + Key(enum Keytype type_par, const LEX_STRING &name_arg, KEY_CREATE_INFO *key_info_arg, bool generated_arg, List &cols) :type(type_par), key_create_info(*key_info_arg), columns(cols), name(name_arg), generated(generated_arg) {} + Key(enum Keytype type_par, const char *name_arg, size_t name_len_arg, + KEY_CREATE_INFO *key_info_arg, bool generated_arg, + List &cols) + :type(type_par), key_create_info(*key_info_arg), columns(cols), + generated(generated_arg) + { + name.str= (char *)name_arg; + name.length= name_len_arg; + } Key(const Key &rhs, MEM_ROOT *mem_root); virtual ~Key() {} /* Equality comparison of keys (ignoring name) */ @@ -233,7 +247,7 @@ public: Table_ident *ref_table; List ref_columns; uint delete_opt, update_opt, match_opt; - Foreign_key(const char *name_arg, List &cols, + Foreign_key(const LEX_STRING &name_arg, List &cols, Table_ident *table, List &ref_cols, uint delete_opt_arg, uint update_opt_arg, uint match_opt_arg) :Key(FOREIGN_KEY, name_arg, &default_key_create_info, 0, cols), -- cgit v1.2.1 From 93c885bd36569b5b2bd7c85e497ecf9830e848de Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Mon, 12 Oct 2009 11:22:53 +0500 Subject: WL#1397 convert XML -> SQL --- sql/sql_class.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'sql/sql_class.h') diff --git a/sql/sql_class.h b/sql/sql_class.h index 4874801e380..5dcf3fdaad0 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -89,6 +89,7 @@ enum enum_slave_exec_mode { SLAVE_EXEC_MODE_STRICT, SLAVE_EXEC_MODE_LAST_BIT}; enum enum_mark_columns { MARK_COLUMNS_NONE, MARK_COLUMNS_READ, MARK_COLUMNS_WRITE}; +enum enum_filetype { FILETYPE_CSV, FILETYPE_XML }; extern char internal_table_name[2]; extern char empty_c_string[1]; @@ -2364,13 +2365,15 @@ my_eof(THD *thd) class sql_exchange :public Sql_alloc { public: + enum enum_filetype filetype; /* load XML, Added by Arnold & Erik */ char *file_name; String *field_term,*enclosed,*line_term,*line_start,*escaped; bool opt_enclosed; bool dumpfile; ulong skip_lines; CHARSET_INFO *cs; - sql_exchange(char *name,bool dumpfile_flag); + sql_exchange(char *name, bool dumpfile_flag, + enum_filetype filetype_arg= FILETYPE_CSV); bool escaped_given(void); }; -- cgit v1.2.1 From 99420dd913333cf7bb109e9c5d71d2daf66e3dca Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Tue, 13 Oct 2009 22:18:48 +0400 Subject: Introduce thd->query_cache_tls (thread local storage for query cache). We need more than one pointer in a thread to represent the query cache and net->query_cache_query can not be used any more (due to ABI compatibility issues and to different life time of NET and THD). This is a backport of the following patch from 6.0: ---------------------------------------------------------- revno: 2476.1157.2 committer: kostja@bodhi.(none) timestamp: Sat 2007-06-16 13:29:24 +0400 include/mysql.h.pp: Update the ABI (NET::query_cache_query is now unused). include/mysql_com.h: NET::query_cache_query is now unused. sql/mysql_priv.h: Update signatures of ex-functios now member functions. sql/sql_cache.cc: Introduce THD::query_cache_tls. sql/sql_cache.h: Introduce THD::query_cache_tls. sql/sql_class.cc: Introduce THD::query_cache_tls. sql/sql_class.h: Introduce THD::query_cache_tls. sql/sql_parse.cc: Use THD::query_cache_tls. sql/sql_select.cc: Use THD::query_cache_tls. --- sql/sql_class.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'sql/sql_class.h') diff --git a/sql/sql_class.h b/sql/sql_class.h index 4dea3acc5e7..76602e00074 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -315,6 +315,27 @@ typedef enum enum_diag_condition_item_name */ extern const LEX_STRING Diag_condition_item_names[]; +/** + Query_cache_tls -- query cache thread local data. +*/ + +class Query_cache_block; + +struct Query_cache_tls +{ + /* + 'first_query_block' should be accessed only via query cache + functions and methods to maintain proper locking. + */ + Query_cache_block *first_query_block; + void set_first_query_block(Query_cache_block *first_query_block_arg) + { + first_query_block= first_query_block_arg; + } + + Query_cache_tls() :first_query_block(NULL) {} +}; + #include "sql_lex.h" /* Must be here */ class Delayed_insert; @@ -1239,6 +1260,9 @@ public: fields then. */ struct st_mysql_stmt *current_stmt; +#endif +#ifdef HAVE_QUERY_CACHE + Query_cache_tls query_cache_tls; #endif NET net; // client connection descriptor Protocol *protocol; // Current protocol -- cgit v1.2.1 From 9b41c7532d18b04d2f430932ad916886c77fbff6 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Wed, 14 Oct 2009 20:37:38 +0400 Subject: Backport of: ---------------------------------------------------------- revno: 2617.22.5 committer: Konstantin Osipov branch nick: mysql-6.0-runtime timestamp: Tue 2009-01-27 05:08:48 +0300 message: Remove non-prefixed use of HASH. Always use my_hash_init(), my_hash_inited(), my_hash_search(), my_hash_element(), my_hash_delete(), my_hash_free() rather than non-prefixed counterparts (hash_init(), etc). Remove the backward-compatible defines. --- sql/sql_class.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'sql/sql_class.h') diff --git a/sql/sql_class.h b/sql/sql_class.h index 76602e00074..cd063b1db3a 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -772,8 +772,8 @@ public: Statement *find_by_name(LEX_STRING *name) { Statement *stmt; - stmt= (Statement*)hash_search(&names_hash, (uchar*)name->str, - name->length); + stmt= (Statement*)my_hash_search(&names_hash, (uchar*)name->str, + name->length); return stmt; } @@ -782,7 +782,7 @@ public: if (last_found_statement == 0 || id != last_found_statement->id) { Statement *stmt; - stmt= (Statement *) hash_search(&st_hash, (uchar *) &id, sizeof(id)); + stmt= (Statement *) my_hash_search(&st_hash, (uchar *) &id, sizeof(id)); if (stmt && stmt->name.str) return NULL; last_found_statement= stmt; -- cgit v1.2.1 From d8c3f2263f3deaadff957a0047460e8058cffccf Mon Sep 17 00:00:00 2001 From: Sergey Glukhov Date: Thu, 15 Oct 2009 17:23:43 +0500 Subject: WL#751 Error message construction, backport --- sql/sql_class.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sql/sql_class.h') diff --git a/sql/sql_class.h b/sql/sql_class.h index 5dcf3fdaad0..0c337ac4207 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -425,6 +425,8 @@ struct system_variables CHARSET_INFO *collation_database; CHARSET_INFO *collation_connection; + /* Error messages */ + MY_LOCALE *lc_messages; /* Locale Support */ MY_LOCALE *lc_time_names; -- cgit v1.2.1 From 38b403bae322fee3dadedb1cffaff13e6c1e724c Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Fri, 16 Oct 2009 15:39:57 +0400 Subject: Fix a windows build failure (next-mr-runtime). sql/sql_cache.cc: Use my_hash_init() on Windows as well. sql/sql_class.h: Use struct Query_cache_block (not class) for forward declaration, realing the code to match 6.0 alignment. --- sql/sql_class.h | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'sql/sql_class.h') diff --git a/sql/sql_class.h b/sql/sql_class.h index cd063b1db3a..558de19b7af 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -280,6 +280,27 @@ public: LEX_COLUMN (const String& x,const uint& y ): column (x),rights (y) {} }; +/** + Query_cache_tls -- query cache thread local data. +*/ + +struct Query_cache_block; + +struct Query_cache_tls +{ + /* + 'first_query_block' should be accessed only via query cache + functions and methods to maintain proper locking. + */ + Query_cache_block *first_query_block; + void set_first_query_block(Query_cache_block *first_query_block_arg) + { + first_query_block= first_query_block_arg; + } + + Query_cache_tls() :first_query_block(NULL) {} +}; + /* SIGNAL / RESIGNAL / GET DIAGNOSTICS */ /** @@ -315,27 +336,6 @@ typedef enum enum_diag_condition_item_name */ extern const LEX_STRING Diag_condition_item_names[]; -/** - Query_cache_tls -- query cache thread local data. -*/ - -class Query_cache_block; - -struct Query_cache_tls -{ - /* - 'first_query_block' should be accessed only via query cache - functions and methods to maintain proper locking. - */ - Query_cache_block *first_query_block; - void set_first_query_block(Query_cache_block *first_query_block_arg) - { - first_query_block= first_query_block_arg; - } - - Query_cache_tls() :first_query_block(NULL) {} -}; - #include "sql_lex.h" /* Must be here */ class Delayed_insert; -- cgit v1.2.1 From 8ec23470f14323bb85220bae42d154681a4be7f3 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Thu, 22 Oct 2009 00:02:06 +0400 Subject: Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1, 2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29, 2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and some other minor revisions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch implements: WL#4264 "Backup: Stabilize Service Interface" -- all the server prerequisites except si_objects.{h,cc} themselves (they can be just copied over, when needed). WL#4435: Support OUT-parameters in prepared statements. (and all issues in the initial patches for these two tasks, that were discovered in pushbuild and during testing). Bug#39519: mysql_stmt_close() should flush all data associated with the statement. After execution of a prepared statement, send OUT parameters of the invoked stored procedure, if any, to the client. When using the binary protocol, send the parameters in an additional result set over the wire. When using the text protocol, assign out parameters to the user variables from the CALL(@var1, @var2, ...) specification. The following refactoring has been made: - Protocol::send_fields() was renamed to Protocol::send_result_set_metadata(); - A new Protocol::send_result_set_row() was introduced to incapsulate common functionality for sending row data. - Signature of Protocol::prepare_for_send() was changed: this operation does not need a list of items, the number of items is fully sufficient. The following backward incompatible changes have been made: - CLIENT_MULTI_RESULTS is now enabled by default in the client; - CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client. include/mysql.h: Add a new flag to MYSQL_METHODS::flush_use_result function pointer. This flag determines if all results should be flushed or only the first one: - if flush_all_results is TRUE, then cli_flush_use_result() will read/flush all pending results. I.e. it will read all packets while server status attribute indicates that there are more results. This is a new semantic, required to fix the bug. - if flush_all_results is FALSE, the old sematic is preserved -- i.e. cli_flush_use_result() reads data until first EOF-packet. include/mysql.h.pp: Update the ABI with new calls (compatible changes). include/mysql_com.h: Add CLIENT_PS_OUT_PARAMS -- a client capability indicating that the client supportsю libmysql/libmysql.c: Add mysql_stmt_next_result() -- analogue of mysql_next_result() for binary protocol. Fix a minor bug in alloc_fields() -- not all members were copied over, and some only shallow-copied (catalog). Flush all results in mysql_stmt_close() (Bug#39519). libmysqld/lib_sql.cc: Rename send_fields() -> send_result_set_metadata(). Refactoring: change prepare_for_send() so that it accepts only what it really needs -- a number of elements in the list. mysql-test/r/ps.result: Update results: WL#4435. mysql-test/t/ps.test: WL#4435: A test case for an SQL-part of the problem. sql-common/client.c: Bug#39519. Implement new functionality in cli_flush_use_result(): if flush_all_delete is TRUE, then it should read/flush all pending results. sql/Makefile.am: Add a new header sql_prepare.h to the list of build headers. sql/events.cc: Rename: Protocol::send_fields() -> Protocol::send_result_set_metadata(). sql/handler.cc: Rename: Protocol::send_fields() -> Protocol::send_result_set_metadata(). sql/mysql_priv.h: Move sql_prepare.cc-specific declarations to a new header - sql_prepare.h. sql/procedure.h: Rename: Protocol::send_fields() -> Protocol::send_result_set_metadata(). sql/protocol.cc: Move the logic responsible for sending of one result set row to the Protocol class. Define a template for end-of-statement action. Refactoring: change prepare_for_send() so that it accepts only what it really needs -- a number of elements in the list. Rename send_fields() to send_result_set_metadata(). sql/protocol.h: Update with new declarations (WL#4435). Rename send_fields() -> send_result_set_metadata(). prepare_for_send() only needs the number of columns to send, and doesn't use the item list - update signature to require only what's needed. Add a new protocol type -- Protocol_local. sql/repl_failsafe.cc: Rename: Protocol::send_fields() -> Protocol::send_result_set_metadata(). sql/slave.cc: Rename: Protocol::send_fields() -> Protocol::send_result_set_metadata(). sql/sql_acl.cc: Rename: Protocol::send_fields() -> Protocol::send_result_set_metadata(). sql/sql_base.cc: Include sql_prepare.h (for Reprepare_observer). sql/sql_cache.cc: Extend the query cache flags block to be able to store a numeric id for the result format, not just a flag binary/non-binary. sql/sql_class.cc: Update to use the rename of Protocol::send_fields() to Protocol::send_result_set_metadata(). Use Protocol::send_one_result_set_row(). sql/sql_class.h: Move the declaration of Reprepare_observer to the new header - sql_prepare.h. Update to the new signature of class Protocol::send_fields(). sql/sql_connect.cc: Use a protocol template method instead of raw NET layer API at the end of a statement. sql/sql_cursor.cc: Rename: Protocol::send_fields() -> Protocol::send_result_set_metadata(). sql/sql_error.cc: Rename: Protocol::send_fields() -> Protocol::send_result_set_metadata(). sql/sql_handler.cc: Rename: Protocol::send_fields() -> Protocol::send_result_set_metadata(). Use new method Protocol::send_one_result_set_row(). sql/sql_help.cc: Rename: Protocol::send_fields() -> Protocol::send_result_set_metadata(). sql/sql_lex.cc: Initialize multi_statements variable. Add a handy constant for empty lex string. sql/sql_lex.h: Add a separate member for a standalone parsing option - multi-statements support. sql/sql_list.cc: sql_list.h is a standalone header now, no need to include mysql_priv.h. sql/sql_list.h: Make sql_list.h a stand-alone header. sql/sql_parse.cc: Include sql_prepare.h for prepared statements- related declarations. Use a new Protocol template method to end each statement (send OK, EOF or ERROR to the client). sql/sql_prepare.cc: Implement Execute Direct API (WL#4264), currently unused. It will be used by the service interface (Backup). Use a new header - sql_prepare.h. Add support for OUT parameters in the binary and text protocol (prepared statements only). sql/sql_prepare.h: Add a new header to contain (for now) all prepared statement- external related declarations. sql/sql_profile.cc: Rename: Protocol::send_fields() -> Protocol::send_result_set_metadata(). sql/sql_repl.cc: Rename: Protocol::send_fields() -> Protocol::send_result_set_metadata(). sql/sql_select.cc: Rename: Protocol::send_fields() -> Protocol::send_result_set_metadata(). sql/sql_show.cc: Rename: Protocol::send_fields() -> Protocol::send_result_set_metadata(). sql/sql_string.h: Add a way to convert a String to LEX_STRING. sql/sql_table.cc: Rename: Protocol::send_fields() -> Protocol::send_result_set_metadata(). sql/sql_update.cc: Remove an extraneous my_error(). The error is already reported in update_non_unique_table_error(). sql/sql_yacc.yy: Support for multi-statements is an independent property of parsing, not derived from the protocol type. tests/mysql_client_test.c: Add tests for WL#4435 (binary protocol). --- sql/sql_class.h | 52 ++++------------------------------------------------ 1 file changed, 4 insertions(+), 48 deletions(-) (limited to 'sql/sql_class.h') diff --git a/sql/sql_class.h b/sql/sql_class.h index 558de19b7af..5b367bec55a 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -23,52 +23,8 @@ #include "log.h" #include "rpl_tblmap.h" -/** - An interface that is used to take an action when - the locking module notices that a table version has changed - since the last execution. "Table" here may refer to any kind of - table -- a base table, a temporary table, a view or an - information schema table. - - When we open and lock tables for execution of a prepared - statement, we must verify that they did not change - since statement prepare. If some table did change, the statement - parse tree *may* be no longer valid, e.g. in case it contains - optimizations that depend on table metadata. - - This class provides an interface (a method) that is - invoked when such a situation takes place. - The implementation of the method simply reports an error, but - the exact details depend on the nature of the SQL statement. - - At most 1 instance of this class is active at a time, in which - case THD::m_reprepare_observer is not NULL. - - @sa check_and_update_table_version() for details of the - version tracking algorithm - - @sa Open_tables_state::m_reprepare_observer for the life cycle - of metadata observers. -*/ - -class Reprepare_observer -{ -public: - Reprepare_observer() {} - /** - Check if a change of metadata is OK. In future - the signature of this method may be extended to accept the old - and the new versions, but since currently the check is very - simple, we only need the THD to report an error. - */ - bool report_error(THD *thd); - bool is_invalidated() const { return m_invalidated; } - void reset_reprepare_observer() { m_invalidated= FALSE; } -private: - bool m_invalidated; -}; - +class Reprepare_observer; class Relay_log_info; class Query_log_event; @@ -2441,7 +2397,7 @@ public: */ virtual uint field_count(List &fields) const { return fields.elements; } - virtual bool send_fields(List &list, uint flags)=0; + virtual bool send_result_set_metadata(List &list, uint flags)=0; virtual bool send_data(List &items)=0; virtual bool initialize_tables (JOIN *join=0) { return 0; } virtual void send_error(uint errcode,const char *err); @@ -2486,7 +2442,7 @@ class select_result_interceptor: public select_result public: select_result_interceptor() {} /* Remove gcc warning */ uint field_count(List &fields) const { return 0; } - bool send_fields(List &fields, uint flag) { return FALSE; } + bool send_result_set_metadata(List &fields, uint flag) { return FALSE; } }; @@ -2499,7 +2455,7 @@ class select_send :public select_result { bool is_result_set_started; public: select_send() :is_result_set_started(FALSE) {} - bool send_fields(List &list, uint flags); + bool send_result_set_metadata(List &list, uint flags); bool send_data(List &items); bool send_eof(); virtual bool check_simple_select() const { return FALSE; } -- cgit v1.2.1 From 3d23068f3a1430d5849ede3f886e7356040bc146 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 2 Nov 2009 21:05:42 +0100 Subject: WL#4903 Plugin Service API part I (mysql-next-mr backport) --- sql/sql_class.h | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'sql/sql_class.h') diff --git a/sql/sql_class.h b/sql/sql_class.h index aaa959feae9..3f40195ba5b 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -25,7 +25,6 @@ #include "log.h" #include "rpl_tblmap.h" -#include "replication.h" /** An interface that is used to take an action when @@ -1886,11 +1885,28 @@ public: inline const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t* mutex, const char* msg) { - return thd_enter_cond(this, cond, mutex, msg); + const char* old_msg = proc_info; + safe_mutex_assert_owner(mutex); + mysys_var->current_mutex = mutex; + mysys_var->current_cond = cond; + proc_info = msg; + return old_msg; } inline void exit_cond(const char* old_msg) { - thd_exit_cond(this, old_msg); + /* + Putting the mutex unlock in thd->exit_cond() ensures that + mysys_var->current_mutex is always unlocked _before_ mysys_var->mutex is + locked (if that would not be the case, you'll get a deadlock if someone + does a THD::awake() on you). + */ + pthread_mutex_unlock(mysys_var->current_mutex); + pthread_mutex_lock(&mysys_var->mutex); + mysys_var->current_mutex = 0; + mysys_var->current_cond = 0; + proc_info = old_msg; + pthread_mutex_unlock(&mysys_var->mutex); + return; } inline time_t query_start() { query_start_used=1; return start_time; } inline void set_time() -- cgit v1.2.1