summaryrefslogtreecommitdiff
path: root/sql/sql_class.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_class.cc')
-rw-r--r--sql/sql_class.cc129
1 files changed, 81 insertions, 48 deletions
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 7b7d34c6bc0..a5f69d63ad0 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -336,24 +336,9 @@ ulong get_max_connections(void)
extern "C" int mysql_tmpfile(const char *prefix)
{
char filename[FN_REFLEN];
- File fd = create_temp_file(filename, mysql_tmpdir, prefix,
-#ifdef __WIN__
- O_BINARY | O_TRUNC | O_SEQUENTIAL |
- O_SHORT_LIVED |
-#endif /* __WIN__ */
- O_CREAT | O_EXCL | O_RDWR | O_TEMPORARY,
- MYF(MY_WME));
- if (fd >= 0) {
-#ifndef __WIN__
- /*
- This can be removed once the following bug is fixed:
- Bug #28903 create_temp_file() doesn't honor O_TEMPORARY option
- (file not removed) (Unix)
- */
- unlink(filename);
-#endif /* !__WIN__ */
- }
-
+ File fd= create_temp_file(filename, mysql_tmpdir, prefix,
+ O_BINARY | O_SEQUENTIAL,
+ MYF(MY_WME | MY_TEMPORARY));
return fd;
}
@@ -770,6 +755,7 @@ THD::THD(my_thread_id id, bool is_wsrep_applier, bool skip_global_sys_var_lock)
THD *old_THR_THD= current_thd;
set_current_thd(this);
status_var.local_memory_used= sizeof(THD);
+ status_var.max_local_memory_used= status_var.local_memory_used;
status_var.global_memory_used= 0;
variables.pseudo_thread_id= thread_id;
variables.max_mem_used= global_system_variables.max_mem_used;
@@ -819,7 +805,6 @@ THD::THD(my_thread_id id, bool is_wsrep_applier, bool skip_global_sys_var_lock)
statement_id_counter= 0UL;
// Must be reset to handle error with THD's created for init of mysqld
lex->current_select= 0;
- stmt_lex= 0;
start_utime= utime_after_query= 0;
system_time.start.val= system_time.sec= system_time.sec_part= 0;
utime_after_lock= 0L;
@@ -880,7 +865,6 @@ THD::THD(my_thread_id id, bool is_wsrep_applier, bool skip_global_sys_var_lock)
*scramble= '\0';
#ifdef WITH_WSREP
- mysql_mutex_init(key_LOCK_wsrep_thd, &LOCK_wsrep_thd, MY_MUTEX_INIT_FAST);
wsrep_ws_handle.trx_id = WSREP_UNDEFINED_TRX_ID;
wsrep_ws_handle.opaque = NULL;
wsrep_retry_counter = 0;
@@ -1173,8 +1157,8 @@ Sql_condition* THD::raise_condition(uint sql_errno,
require memory allocation and therefore might fail. Non fatal out of
memory errors can occur if raised by SIGNAL/RESIGNAL statement.
*/
- if (!(is_fatal_error && (sql_errno == EE_OUTOFMEMORY ||
- sql_errno == ER_OUTOFMEMORY)))
+ if (likely(!(is_fatal_error && (sql_errno == EE_OUTOFMEMORY ||
+ sql_errno == ER_OUTOFMEMORY))))
{
cond= da->push_warning(this, sql_errno, sqlstate, level, ucid, msg);
}
@@ -1317,6 +1301,7 @@ void THD::init(bool skip_lock)
reset_current_stmt_binlog_format_row();
reset_binlog_local_stmt_filter();
set_status_var_init();
+ status_var.max_local_memory_used= status_var.local_memory_used;
bzero((char *) &org_status_var, sizeof(org_status_var));
status_in_global= 0;
start_bytes_received= 0;
@@ -1716,9 +1701,6 @@ THD::~THD()
mysql_mutex_unlock(&LOCK_thd_kill);
#ifdef WITH_WSREP
- mysql_mutex_lock(&LOCK_wsrep_thd);
- mysql_mutex_unlock(&LOCK_wsrep_thd);
- mysql_mutex_destroy(&LOCK_wsrep_thd);
delete wsrep_rgi;
#endif
if (!free_connection_done)
@@ -2376,12 +2358,12 @@ bool THD::convert_string(LEX_STRING *to, CHARSET_INFO *to_cs,
DBUG_ENTER("THD::convert_string");
size_t new_length= to_cs->mbmaxlen * from_length;
uint errors;
- if (alloc_lex_string(to, new_length + 1))
+ if (unlikely(alloc_lex_string(to, new_length + 1)))
DBUG_RETURN(true); // EOM
to->length= copy_and_convert((char*) to->str, new_length, to_cs,
from, from_length, from_cs, &errors);
to->str[to->length]= 0; // Safety
- if (errors && lex->parse_vcol_expr)
+ if (unlikely(errors) && lex->parse_vcol_expr)
{
my_error(ER_BAD_DATA, MYF(0),
ErrConvString(from, from_length, from_cs).ptr(),
@@ -2483,7 +2465,8 @@ bool THD::copy_with_error(CHARSET_INFO *dstcs, LEX_STRING *dst,
bool THD::convert_string(String *s, CHARSET_INFO *from_cs, CHARSET_INFO *to_cs)
{
uint dummy_errors;
- if (convert_buffer.copy(s->ptr(), s->length(), from_cs, to_cs, &dummy_errors))
+ if (unlikely(convert_buffer.copy(s->ptr(), s->length(), from_cs, to_cs,
+ &dummy_errors)))
return TRUE;
/* If convert_buffer >> s copying is more efficient long term */
if (convert_buffer.alloced_length() >= convert_buffer.length() * 2 ||
@@ -2496,6 +2479,39 @@ bool THD::convert_string(String *s, CHARSET_INFO *from_cs, CHARSET_INFO *to_cs)
}
+bool THD::check_string_for_wellformedness(const char *str,
+ size_t length,
+ CHARSET_INFO *cs) const
+{
+ DBUG_ASSERT(charset_is_system_charset);
+ size_t wlen= Well_formed_prefix(cs, str, length).length();
+ if (wlen < length)
+ {
+ ErrConvString err(str, length, &my_charset_bin);
+ my_error(ER_INVALID_CHARACTER_STRING, MYF(0), cs->csname, err.ptr());
+ return true;
+ }
+ return false;
+}
+
+
+bool THD::to_ident_sys_alloc(Lex_ident_sys_st *to, const Lex_ident_cli_st *ident)
+{
+ if (ident->is_quoted())
+ {
+ LEX_CSTRING unquoted;
+ if (quote_unescape(&unquoted, ident, ident->quote()))
+ return true;
+ return charset_is_system_charset ?
+ to->copy_sys(this, &unquoted) :
+ to->convert(this, &unquoted, charset());
+ }
+ return charset_is_system_charset ?
+ to->copy_sys(this, ident) :
+ to->copy_or_convert(this, ident, charset());
+}
+
+
Item_basic_constant *
THD::make_string_literal(const char *str, size_t length, uint repertoire)
{
@@ -2657,18 +2673,31 @@ CHANGED_TABLE_LIST* THD::changed_table_dup(const char *key, size_t key_length)
}
-int THD::send_explain_fields(select_result *result, uint8 explain_flags, bool is_analyze)
+void THD::prepare_explain_fields(select_result *result,
+ List<Item> *field_list,
+ uint8 explain_flags,
+ bool is_analyze)
{
- List<Item> field_list;
if (lex->explain_json)
- make_explain_json_field_list(field_list, is_analyze);
+ make_explain_json_field_list(*field_list, is_analyze);
else
- make_explain_field_list(field_list, explain_flags, is_analyze);
+ make_explain_field_list(*field_list, explain_flags, is_analyze);
+
+ result->prepare(*field_list, NULL);
+}
+
- result->prepare(field_list, NULL);
- return (result->send_result_set_metadata(field_list,
- Protocol::SEND_NUM_ROWS |
- Protocol::SEND_EOF));
+int THD::send_explain_fields(select_result *result,
+ uint8 explain_flags,
+ bool is_analyze)
+{
+ List<Item> field_list;
+ int rc;
+ prepare_explain_fields(result, &field_list, explain_flags, is_analyze);
+ rc= result->send_result_set_metadata(field_list,
+ Protocol::SEND_NUM_ROWS |
+ Protocol::SEND_EOF);
+ return(rc);
}
@@ -3015,7 +3044,7 @@ bool select_send::send_eof()
Don't send EOF if we're in error condition (which implies we've already
sent or are sending an error)
*/
- if (thd->is_error())
+ if (unlikely(thd->is_error()))
return TRUE;
::my_eof(thd);
is_result_set_started= 0;
@@ -3030,10 +3059,11 @@ bool select_send::send_eof()
bool select_to_file::send_eof()
{
int error= MY_TEST(end_io_cache(&cache));
- if (mysql_file_close(file, MYF(MY_WME)) || thd->is_error())
+ if (unlikely(mysql_file_close(file, MYF(MY_WME))) ||
+ unlikely(thd->is_error()))
error= true;
- if (!error && !suppress_my_ok)
+ if (likely(!error) && !suppress_my_ok)
{
::my_ok(thd,row_count);
}
@@ -3295,7 +3325,7 @@ int select_export::send_data(List<Item> &items)
res->charset(),
res->ptr(), res->length());
error_pos= copier.most_important_error_pos();
- if (error_pos)
+ if (unlikely(error_pos))
{
char printable_buff[32];
convert_to_printable(printable_buff, sizeof(printable_buff),
@@ -3814,7 +3844,7 @@ void Statement::set_statement(Statement *stmt)
{
id= stmt->id;
column_usage= stmt->column_usage;
- stmt_lex= lex= stmt->lex;
+ lex= stmt->lex;
query_string= stmt->query_string;
}
@@ -4131,7 +4161,7 @@ bool select_dumpvar::send_eof()
Don't send EOF if we're in error condition (which implies we've already
sent or are sending an error)
*/
- if (thd->is_error())
+ if (unlikely(thd->is_error()))
return true;
if (!suppress_my_ok)
@@ -4267,9 +4297,8 @@ void thd_increment_bytes_sent(void *thd, size_t length)
}
}
-my_bool thd_net_is_killed()
+my_bool thd_net_is_killed(THD *thd)
{
- THD *thd= current_thd;
return thd && thd->killed ? 1 : 0;
}
@@ -4737,7 +4766,7 @@ TABLE *open_purge_table(THD *thd, const char *db, size_t dblen,
/* we don't recover here */
DBUG_ASSERT(!error || !ot_ctx.can_recover_from_failed_open());
- if (error)
+ if (unlikely(error))
close_thread_tables(thd);
DBUG_RETURN(error ? NULL : tl->table);
@@ -6359,7 +6388,8 @@ int THD::decide_logging_format(TABLE_LIST *tables)
clear_binlog_local_stmt_filter();
}
- if (error) {
+ if (unlikely(error))
+ {
DBUG_PRINT("info", ("decision: no logging since an error was generated"));
DBUG_RETURN(-1);
}
@@ -7201,8 +7231,11 @@ int THD::binlog_query(THD::enum_binlog_query_type qtype, char const *query_arg,
top-most close_thread_tables().
*/
if (this->locked_tables_mode <= LTM_LOCK_TABLES)
- if (int error= binlog_flush_pending_rows_event(TRUE, is_trans))
+ {
+ int error;
+ if (unlikely(error= binlog_flush_pending_rows_event(TRUE, is_trans)))
DBUG_RETURN(error);
+ }
/*
Warnings for unsafe statements logged in statement format are
@@ -7470,7 +7503,7 @@ wait_for_commit::wait_for_prior_commit2(THD *thd)
thd->ENTER_COND(&COND_wait_commit, &LOCK_wait_commit,
&stage_waiting_for_prior_transaction_to_commit,
&old_stage);
- while ((loc_waitee= this->waitee) && !thd->check_killed())
+ while ((loc_waitee= this->waitee) && likely(!thd->check_killed()))
mysql_cond_wait(&COND_wait_commit, &LOCK_wait_commit);
if (!loc_waitee)
{