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.cc144
1 files changed, 97 insertions, 47 deletions
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 7a777ba2bbd..7c00ac6d1c9 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -470,6 +470,46 @@ end:
}
+/**
+ @brief Check access privs for a MERGE table and fix children lock types.
+
+ @param[in] thd thread handle
+ @param[in] db database name
+ @param[in,out] table_list list of child tables (merge_list)
+ lock_type and optionally db set per table
+
+ @return status
+ @retval 0 OK
+ @retval != 0 Error
+
+ @detail
+ This function is used for write access to MERGE tables only
+ (CREATE TABLE, ALTER TABLE ... UNION=(...)). Set TL_WRITE for
+ every child. Set 'db' for every child if not present.
+*/
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
+static bool check_merge_table_access(THD *thd, char *db,
+ TABLE_LIST *table_list)
+{
+ int error= 0;
+
+ if (table_list)
+ {
+ /* Check that all tables use the current database */
+ TABLE_LIST *tlist;
+
+ for (tlist= table_list; tlist; tlist= tlist->next_local)
+ {
+ if (!tlist->db || !tlist->db[0])
+ tlist->db= db; /* purecov: inspected */
+ }
+ error= check_table_access(thd, SELECT_ACL | UPDATE_ACL | DELETE_ACL,
+ table_list,0);
+ }
+ return error;
+}
+#endif
+
/* This works because items are allocated with sql_alloc() */
void free_items(Item *item)
@@ -748,12 +788,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
NET *net= &thd->net;
bool error= 0;
DBUG_ENTER("dispatch_command");
-
- if (thd->killed == THD::KILL_QUERY || thd->killed == THD::KILL_BAD_DATA)
- {
- thd->killed= THD::NOT_KILLED;
- thd->mysys_var->abort= 0;
- }
+ DBUG_PRINT("info",("packet: '%*.s'; command: %d", packet_length, packet, command));
thd->command=command;
/*
@@ -2076,7 +2111,16 @@ mysql_execute_command(THD *thd)
if (check_global_access(thd, SUPER_ACL | REPL_CLIENT_ACL))
goto error;
pthread_mutex_lock(&LOCK_active_mi);
- res = show_master_info(thd,active_mi);
+ if (active_mi != NULL)
+ {
+ res = show_master_info(thd, active_mi);
+ }
+ else
+ {
+ push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
+ "the master info structure does not exist");
+ send_ok(thd);
+ }
pthread_mutex_unlock(&LOCK_active_mi);
break;
}
@@ -2250,6 +2294,19 @@ mysql_execute_command(THD *thd)
select_lex->options|= SELECT_NO_UNLOCK;
unit->set_limit(select_lex);
+ /*
+ Disable non-empty MERGE tables with CREATE...SELECT. Too
+ complicated. See Bug #26379. Empty MERGE tables are read-only
+ and don't allow CREATE...SELECT anyway.
+ */
+ if (create_info.used_fields & HA_CREATE_USED_UNION)
+ {
+ my_error(ER_WRONG_OBJECT, MYF(0), create_table->db,
+ create_table->table_name, "BASE TABLE");
+ res= 1;
+ goto end_with_restore_list;
+ }
+
if (!(create_info.options & HA_LEX_CREATE_TMP_TABLE))
{
lex->link_first_table_back(create_table, link_to_local);
@@ -2931,6 +2988,13 @@ end_with_restore_list:
SELECT_NO_JOIN_CACHE | SELECT_NO_UNLOCK |
OPTION_SETUP_TABLES_DONE,
del_result, unit, select_lex);
+ res|= thd->net.report_error;
+ if (unlikely(res))
+ {
+ /* If we had a another error reported earlier then this will be ignored */
+ del_result->send_error(ER_UNKNOWN_ERROR, "Execution of the query failed");
+ del_result->abort();
+ }
delete del_result;
}
else
@@ -5072,26 +5136,6 @@ bool check_some_access(THD *thd, ulong want_access, TABLE_LIST *table)
DBUG_RETURN(1);
}
-
-bool check_merge_table_access(THD *thd, char *db,
- TABLE_LIST *table_list)
-{
- int error=0;
- if (table_list)
- {
- /* Check that all tables use the current database */
- TABLE_LIST *tmp;
- for (tmp= table_list; tmp; tmp= tmp->next_local)
- {
- if (!tmp->db || !tmp->db[0])
- tmp->db=db;
- }
- error=check_table_access(thd, SELECT_ACL | UPDATE_ACL | DELETE_ACL,
- table_list,0);
- }
- return error;
-}
-
#endif /*NO_EMBEDDED_ACCESS_CHECKS*/
/****************************************************************************
@@ -6271,24 +6315,23 @@ void add_join_natural(TABLE_LIST *a, TABLE_LIST *b, List<String> *using_fields,
}
-/*
- Reload/resets privileges and the different caches.
-
- SYNOPSIS
- reload_acl_and_cache()
- thd Thread handler (can be NULL!)
- options What should be reset/reloaded (tables, privileges,
- slave...)
- tables Tables to flush (if any)
- write_to_binlog Depending on 'options', it may be very bad to write the
- query to the binlog (e.g. FLUSH SLAVE); this is a
- pointer where reload_acl_and_cache() will put 0 if
- it thinks we really should not write to the binlog.
- Otherwise it will put 1.
-
- RETURN
- 0 ok
- !=0 error. thd->killed or thd->is_error() is set
+/**
+ @brief Reload/resets privileges and the different caches.
+
+ @param thd Thread handler (can be NULL!)
+ @param options What should be reset/reloaded (tables, privileges, slave...)
+ @param tables Tables to flush (if any)
+ @param write_to_binlog True if we can write to the binlog.
+
+ @note Depending on 'options', it may be very bad to write the
+ query to the binlog (e.g. FLUSH SLAVE); this is a
+ pointer where reload_acl_and_cache() will put 0 if
+ it thinks we really should not write to the binlog.
+ Otherwise it will put 1.
+
+ @return Error status code
+ @retval 0 Ok
+ @retval !=0 Error; thd->killed is set or thd->is_error() is true
*/
bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables,
@@ -6392,7 +6435,7 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables,
for (; lock_p < end_p; lock_p++)
{
- if ((*lock_p)->type == TL_WRITE)
+ if ((*lock_p)->type >= TL_WRITE_ALLOW_WRITE)
{
my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0));
return 1;
@@ -6962,8 +7005,15 @@ bool create_table_precheck(THD *thd, TABLE_LIST *tables,
bool error= TRUE; // Error message is given
DBUG_ENTER("create_table_precheck");
+ /*
+ Require CREATE [TEMPORARY] privilege on new table; for
+ CREATE TABLE ... SELECT, also require INSERT.
+ */
+
want_priv= ((lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) ?
- CREATE_TMP_ACL : CREATE_ACL);
+ CREATE_TMP_ACL : CREATE_ACL) |
+ (select_lex->item_list.elements ? INSERT_ACL : 0);
+
if (check_access(thd, want_priv, create_table->db,
&create_table->grant.privilege, 0, 0,
test(create_table->schema_table)) ||