summaryrefslogtreecommitdiff
path: root/sql/sql_parse.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_parse.cc')
-rw-r--r--sql/sql_parse.cc142
1 files changed, 36 insertions, 106 deletions
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 2a46656e8d2..3a107c2296c 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -1168,7 +1168,14 @@ pthread_handler_t handle_one_connection(void *arg)
{
execute_init_command(thd, &sys_init_connect, &LOCK_sys_init_connect);
if (thd->query_error)
+ {
thd->killed= THD::KILL_CONNECTION;
+ sql_print_warning(ER(ER_NEW_ABORTING_CONNECTION),
+ thd->thread_id,(thd->db ? thd->db : "unconnected"),
+ sctx->user ? sctx->user : "unauthenticated",
+ sctx->host_or_ip, "init_connect command failed");
+ sql_print_warning("%s", net->last_error);
+ }
thd->proc_info=0;
thd->set_time();
thd->init_for_queries();
@@ -2159,9 +2166,11 @@ void log_slow_statement(THD *thd)
if ((ulong) (thd->start_time - thd->time_after_lock) >
thd->variables.long_query_time ||
- ((thd->server_status &
+ (thd->server_status &
(SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED)) &&
- (specialflag & SPECIAL_LOG_QUERIES_NOT_USING_INDEXES)))
+ (specialflag & SPECIAL_LOG_QUERIES_NOT_USING_INDEXES) &&
+ /* == SQLCOM_END unless this is a SHOW command */
+ thd->lex->orig_sql_command == SQLCOM_END)
{
thd->status_var.long_query_count++;
mysql_slow_log.write(thd, thd->query, thd->query_length, start_of_query);
@@ -3203,6 +3212,7 @@ end_with_restore_list:
/* ! we write after unlocking the table */
if (!res && !lex->no_write_to_binlog)
{
+ /* Presumably, REPAIR and binlog writing doesn't require synchronization */
if (mysql_bin_log.is_open())
{
thd->clear_error(); // No binlog error generated
@@ -3237,6 +3247,7 @@ end_with_restore_list:
/* ! we write after unlocking the table */
if (!res && !lex->no_write_to_binlog)
{
+ /* Presumably, ANALYZE and binlog writing doesn't require synchronization */
if (mysql_bin_log.is_open())
{
thd->clear_error(); // No binlog error generated
@@ -3262,6 +3273,7 @@ end_with_restore_list:
/* ! we write after unlocking the table */
if (!res && !lex->no_write_to_binlog)
{
+ /* Presumably, OPTIMIZE and binlog writing doesn't require synchronization */
if (mysql_bin_log.is_open())
{
thd->clear_error(); // No binlog error generated
@@ -3563,6 +3575,7 @@ end_with_restore_list:
/* So that DROP TEMPORARY TABLE gets to binlog at commit/rollback */
thd->options|= OPTION_STATUS_NO_TRANS_UPDATE;
}
+ /* DDL and binlog write order protected by LOCK_open */
res= mysql_rm_table(thd, first_table, lex->drop_if_exists,
lex->drop_temporary);
}
@@ -3851,15 +3864,9 @@ end_with_restore_list:
break;
if (end_active_trans(thd))
goto error;
+ /* Conditionally writes to binlog */
if (!(res= mysql_create_user(thd, lex->users_list)))
- {
- if (mysql_bin_log.is_open())
- {
- Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
- mysql_bin_log.write(&qinfo);
- }
send_ok(thd);
- }
break;
}
case SQLCOM_DROP_USER:
@@ -3869,15 +3876,9 @@ end_with_restore_list:
break;
if (end_active_trans(thd))
goto error;
+ /* Conditionally writes to binlog */
if (!(res= mysql_drop_user(thd, lex->users_list)))
- {
- if (mysql_bin_log.is_open())
- {
- Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
- mysql_bin_log.write(&qinfo);
- }
send_ok(thd);
- }
break;
}
case SQLCOM_RENAME_USER:
@@ -3887,15 +3888,9 @@ end_with_restore_list:
break;
if (end_active_trans(thd))
goto error;
+ /* Conditionally writes to binlog */
if (!(res= mysql_rename_user(thd, lex->users_list)))
- {
- if (mysql_bin_log.is_open())
- {
- Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
- mysql_bin_log.write(&qinfo);
- }
send_ok(thd);
- }
break;
}
case SQLCOM_REVOKE_ALL:
@@ -3903,15 +3898,9 @@ end_with_restore_list:
if (check_access(thd, UPDATE_ACL, "mysql", 0, 1, 1, 0) &&
check_global_access(thd,CREATE_USER_ACL))
break;
+ /* Conditionally writes to binlog */
if (!(res = mysql_revoke_all(thd, lex->users_list)))
- {
- if (mysql_bin_log.is_open())
- {
- Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
- mysql_bin_log.write(&qinfo);
- }
send_ok(thd);
- }
break;
}
case SQLCOM_REVOKE:
@@ -3970,6 +3959,7 @@ end_with_restore_list:
check_grant_routine(thd, grants | GRANT_ACL, all_tables,
lex->type == TYPE_ENUM_PROCEDURE, 0))
goto error;
+ /* Conditionally writes to binlog */
res= mysql_routine_grant(thd, all_tables,
lex->type == TYPE_ENUM_PROCEDURE,
lex->users_list, grants,
@@ -3982,16 +3972,11 @@ end_with_restore_list:
GRANT_ACL),
all_tables, 0, UINT_MAX, 0))
goto error;
+ /* Conditionally writes to binlog */
res= mysql_table_grant(thd, all_tables, lex->users_list,
lex->columns, lex->grant,
lex->sql_command == SQLCOM_REVOKE);
}
- if (!res && mysql_bin_log.is_open())
- {
- thd->clear_error();
- Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
- mysql_bin_log.write(&qinfo);
- }
}
else
{
@@ -4002,16 +3987,11 @@ end_with_restore_list:
goto error;
}
else
+ /* Conditionally writes to binlog */
res = mysql_grant(thd, select_lex->db, lex->users_list, lex->grant,
lex->sql_command == SQLCOM_REVOKE);
if (!res)
{
- if (mysql_bin_log.is_open())
- {
- thd->clear_error();
- Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
- mysql_bin_log.write(&qinfo);
- }
if (lex->sql_command == SQLCOM_GRANT)
{
List_iterator <LEX_USER> str_list(lex->users_list);
@@ -4049,6 +4029,7 @@ end_with_restore_list:
We WANT to write and we CAN write.
! we write after unlocking the table.
*/
+ /* Presumably, RESET and binlog writing doesn't require synchronization */
if (!lex->no_write_to_binlog && write_to_binlog)
{
if (mysql_bin_log.is_open())
@@ -4569,20 +4550,16 @@ end_with_restore_list:
already puts on CREATE FUNCTION.
*/
if (lex->sql_command == SQLCOM_ALTER_PROCEDURE)
+ /* Conditionally writes to binlog */
result= sp_update_procedure(thd, lex->spname, &lex->sp_chistics);
else
+ /* Conditionally writes to binlog */
result= sp_update_function(thd, lex->spname, &lex->sp_chistics);
}
}
switch (result)
{
case SP_OK:
- if (mysql_bin_log.is_open())
- {
- thd->clear_error();
- Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
- mysql_bin_log.write(&qinfo);
- }
send_ok(thd);
break;
case SP_KEY_NOT_FOUND:
@@ -4627,9 +4604,11 @@ end_with_restore_list:
}
#endif
if (lex->sql_command == SQLCOM_DROP_PROCEDURE)
- result= sp_drop_procedure(thd, lex->spname);
+ /* Conditionally writes to binlog */
+ result= sp_drop_procedure(thd, lex->spname); /* Conditionally writes to binlog */
else
- result= sp_drop_function(thd, lex->spname);
+ /* Conditionally writes to binlog */
+ result= sp_drop_function(thd, lex->spname); /* Conditionally writes to binlog */
}
else
{
@@ -4642,6 +4621,8 @@ end_with_restore_list:
{
if (check_access(thd, DELETE_ACL, "mysql", 0, 1, 0, 0))
goto error;
+
+ /* Does NOT write to binlog */
if (!(res = mysql_drop_function(thd, &lex->spname->m_name)))
{
send_ok(thd);
@@ -4662,12 +4643,6 @@ end_with_restore_list:
switch (result)
{
case SP_OK:
- if (mysql_bin_log.is_open())
- {
- thd->clear_error();
- Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
- mysql_bin_log.write(&qinfo);
- }
send_ok(thd);
break;
case SP_KEY_NOT_FOUND:
@@ -4764,49 +4739,7 @@ end_with_restore_list:
if (end_active_trans(thd))
goto error;
- if (!(res= mysql_create_view(thd, thd->lex->create_view_mode)) &&
- mysql_bin_log.is_open())
- {
- String buff;
- const LEX_STRING command[3]=
- {{(char *)STRING_WITH_LEN("CREATE ")},
- {(char *)STRING_WITH_LEN("ALTER ")},
- {(char *)STRING_WITH_LEN("CREATE OR REPLACE ")}};
- thd->clear_error();
-
- buff.append(command[thd->lex->create_view_mode].str,
- command[thd->lex->create_view_mode].length);
- view_store_options(thd, first_table, &buff);
- buff.append(STRING_WITH_LEN("VIEW "));
- /* Test if user supplied a db (ie: we did not use thd->db) */
- if (first_table->db && first_table->db[0] &&
- (thd->db == NULL || strcmp(first_table->db, thd->db)))
- {
- append_identifier(thd, &buff, first_table->db,
- first_table->db_length);
- buff.append('.');
- }
- append_identifier(thd, &buff, first_table->table_name,
- first_table->table_name_length);
- if (lex->view_list.elements)
- {
- List_iterator_fast<LEX_STRING> names(lex->view_list);
- LEX_STRING *name;
- int i;
-
- for (i= 0; name= names++; i++)
- {
- buff.append(i ? ", " : "(");
- append_identifier(thd, &buff, name->str, name->length);
- }
- buff.append(')');
- }
- buff.append(STRING_WITH_LEN(" AS "));
- buff.append(first_table->source.str, first_table->source.length);
-
- Query_log_event qinfo(thd, buff.ptr(), buff.length(), 0, FALSE);
- mysql_bin_log.write(&qinfo);
- }
+ res= mysql_create_view(thd, first_table, thd->lex->create_view_mode);
break;
}
case SQLCOM_DROP_VIEW:
@@ -4814,13 +4747,8 @@ end_with_restore_list:
if (check_table_access(thd, DROP_ACL, all_tables, 0) ||
end_active_trans(thd))
goto error;
- if (!(res= mysql_drop_view(thd, first_table, thd->lex->drop_mode)) &&
- mysql_bin_log.is_open())
- {
- thd->clear_error();
- Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
- mysql_bin_log.write(&qinfo);
- }
+ /* Conditionally writes to binlog. */
+ res= mysql_drop_view(thd, first_table, thd->lex->drop_mode);
break;
}
case SQLCOM_CREATE_TRIGGER:
@@ -4828,6 +4756,7 @@ end_with_restore_list:
if (end_active_trans(thd))
goto error;
+ /* Conditionally writes to binlog. */
res= mysql_create_or_drop_trigger(thd, all_tables, 1);
/* We don't care about trigger body after this point */
@@ -4840,6 +4769,7 @@ end_with_restore_list:
if (end_active_trans(thd))
goto error;
+ /* Conditionally writes to binlog. */
res= mysql_create_or_drop_trigger(thd, all_tables, 0);
break;
}