summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2019-03-15 20:00:28 +0100
committerSergei Golubchik <serg@mariadb.org>2019-03-15 21:00:41 +0100
commit0508d327aef520d3131ff8a85ed610337149fffc (patch)
tree7e04769f49b4aded9053adcad442fe00eb487d98 /sql
parentbb8c82c66abddf796e8d44f817518e5ab38ae6e4 (diff)
parent34db9958e28c325b0f708f78b7ff029de810d5ea (diff)
downloadmariadb-git-0508d327aef520d3131ff8a85ed610337149fffc.tar.gz
Merge branch '10.1' into 10.2
Diffstat (limited to 'sql')
-rw-r--r--sql/debug_sync.cc6
-rw-r--r--sql/encryption.cc15
-rw-r--r--sql/handler.h2
-rw-r--r--sql/item.cc5
-rw-r--r--sql/item_timefunc.cc18
-rw-r--r--sql/log_slow.h1
-rw-r--r--sql/mdl.h10
-rw-r--r--sql/mysqld.cc2
-rw-r--r--sql/opt_range.cc16
-rw-r--r--sql/partition_info.cc9
-rw-r--r--sql/protocol.h67
-rw-r--r--sql/sql_acl.cc113
-rw-r--r--sql/sql_acl.h2
-rw-r--r--sql/sql_admin.h8
-rw-r--r--sql/sql_alter.cc10
-rw-r--r--sql/sql_alter.h2
-rw-r--r--sql/sql_analyse.cc4
-rw-r--r--sql/sql_analyse.h5
-rw-r--r--sql/sql_class.cc28
-rw-r--r--sql/sql_class.h23
-rw-r--r--sql/sql_cmd.h15
-rw-r--r--sql/sql_handler.cc7
-rw-r--r--sql/sql_insert.cc6
-rw-r--r--sql/sql_lex.cc13
-rw-r--r--sql/sql_parse.cc148
-rw-r--r--sql/sql_prepare.cc41
-rw-r--r--sql/sql_priv.h6
-rw-r--r--sql/sql_select.cc4
-rw-r--r--sql/sql_select.h1
-rw-r--r--sql/sql_show.cc51
-rw-r--r--sql/sql_trigger.cc4
-rw-r--r--sql/sql_union.cc27
-rw-r--r--sql/sql_view.cc25
-rw-r--r--sql/sql_yacc.yy5
-rw-r--r--sql/table.h15
-rw-r--r--sql/tztime.cc11
36 files changed, 358 insertions, 367 deletions
diff --git a/sql/debug_sync.cc b/sql/debug_sync.cc
index 6b09978d128..2d34322c59e 100644
--- a/sql/debug_sync.cc
+++ b/sql/debug_sync.cc
@@ -584,7 +584,7 @@ static void debug_sync_remove_action(st_debug_sync_control *ds_control,
memmove(save_action, action, sizeof(st_debug_sync_action));
/* Move actions down. */
- memmove(ds_control->ds_action + dsp_idx,
+ memmove((void*)(ds_control->ds_action + dsp_idx),
ds_control->ds_action + dsp_idx + 1,
(ds_control->ds_active - dsp_idx) *
sizeof(st_debug_sync_action));
@@ -595,8 +595,8 @@ static void debug_sync_remove_action(st_debug_sync_control *ds_control,
produced by the shift. Again do not use an assignment operator to
avoid string allocation/copy.
*/
- memmove(ds_control->ds_action + ds_control->ds_active, save_action,
- sizeof(st_debug_sync_action));
+ memmove((void*)(ds_control->ds_action + ds_control->ds_active),
+ save_action, sizeof(st_debug_sync_action));
}
DBUG_VOID_RETURN;
diff --git a/sql/encryption.cc b/sql/encryption.cc
index 52eab262570..e5b54633066 100644
--- a/sql/encryption.cc
+++ b/sql/encryption.cc
@@ -25,6 +25,10 @@ struct encryption_service_st encryption_handler;
extern "C" {
+uint no_get_key(uint, uint, uchar*, uint*)
+{
+ return ENCRYPTION_KEY_VERSION_INVALID;
+}
uint no_key(uint)
{
return ENCRYPTION_KEY_VERSION_INVALID;
@@ -47,6 +51,11 @@ static unsigned int get_length(unsigned int slen, unsigned int key_id,
return my_aes_get_size(MY_AES_CBC, slen);
}
+uint ctx_size(unsigned int, unsigned int)
+{
+ return MY_AES_CTX_SIZE;
+}
+
} /* extern "C" */
int initialize_encryption_plugin(st_plugin_int *plugin)
@@ -72,8 +81,7 @@ int initialize_encryption_plugin(st_plugin_int *plugin)
if (handle->crypt_ctx_size)
encryption_handler.encryption_ctx_size_func= handle->crypt_ctx_size;
else
- encryption_handler.encryption_ctx_size_func=
- (uint (*)(unsigned int, unsigned int))my_aes_ctx_size;
+ encryption_handler.encryption_ctx_size_func= ctx_size;
encryption_handler.encryption_ctx_init_func=
handle->crypt_ctx_init ? handle->crypt_ctx_init : ctx_init;
@@ -102,8 +110,7 @@ int finalize_encryption_plugin(st_plugin_int *plugin)
if (used)
{
- encryption_handler.encryption_key_get_func=
- (uint (*)(uint, uint, uchar*, uint*))no_key;
+ encryption_handler.encryption_key_get_func= no_get_key;
encryption_handler.encryption_key_get_latest_version_func= no_key;
encryption_handler.encryption_ctx_size_func= zero_size;
}
diff --git a/sql/handler.h b/sql/handler.h
index 229197a2c78..848c9956868 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -1686,7 +1686,6 @@ struct Table_scope_and_contents_source_st
uint options; /* OR of HA_CREATE_ options */
uint merge_insert_method;
uint extra_size; /* length of extra data segment */
- SQL_I_List<TABLE_LIST> merge_list;
handlerton *db_type;
/**
Row type of the table definition.
@@ -1717,6 +1716,7 @@ struct Table_scope_and_contents_source_st
TABLE_LIST *pos_in_locked_tables;
MDL_ticket *mdl_ticket;
bool table_was_deleted;
+ TABLE_LIST *merge_list;
void init()
{
diff --git a/sql/item.cc b/sql/item.cc
index 6c9496c9393..6c605dba776 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -10437,7 +10437,10 @@ bool Item_type_holder::join_types(THD *thd, Item *item)
break;
}
default:
- max_length= MY_MAX(max_length, display_length(item));
+ if (real_field_type() == MYSQL_TYPE_YEAR)
+ max_length= MY_MAX(max_length, item->max_length);
+ else
+ max_length= MY_MAX(max_length, display_length(item));
};
maybe_null|= item->maybe_null;
get_full_info(item);
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index 82dbca5b23c..23d9c3d2f04 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -455,7 +455,7 @@ err:
Create a formated date/time value in a string.
*/
-static bool make_date_time(DATE_TIME_FORMAT *format, MYSQL_TIME *l_time,
+static bool make_date_time(const LEX_CSTRING &format, MYSQL_TIME *l_time,
timestamp_type type, MY_LOCALE *locale, String *str)
{
char intbuff[15];
@@ -469,7 +469,7 @@ static bool make_date_time(DATE_TIME_FORMAT *format, MYSQL_TIME *l_time,
if (l_time->neg)
str->append('-');
- end= (ptr= format->format.str) + format->format.length;
+ end= (ptr= format.str) + format.length;
for (; ptr != end ; ptr++)
{
if (*ptr != '%' || ptr+1 == end)
@@ -589,7 +589,7 @@ static bool make_date_time(DATE_TIME_FORMAT *format, MYSQL_TIME *l_time,
str->append_with_prefill(intbuff, length, 2, '0');
break;
case 'j':
- if (type == MYSQL_TIMESTAMP_TIME)
+ if (type == MYSQL_TIMESTAMP_TIME || !l_time->month || !l_time->year)
return 1;
length= (uint) (int10_to_str(calc_daynr(l_time->year,l_time->month,
l_time->day) -
@@ -2012,6 +2012,7 @@ uint Item_func_date_format::format_length(const String *format)
String *Item_func_date_format::val_str(String *str)
{
+ StringBuffer<64> format_buffer;
String *format;
MYSQL_TIME l_time;
uint size;
@@ -2021,7 +2022,7 @@ String *Item_func_date_format::val_str(String *str)
if (get_arg0_date(&l_time, is_time_flag))
return 0;
- if (!(format = args[1]->val_str(str)) || !format->length())
+ if (!(format= args[1]->val_str(&format_buffer)) || !format->length())
goto null_date;
if (fixed_length)
@@ -2032,18 +2033,13 @@ String *Item_func_date_format::val_str(String *str)
if (size < MAX_DATE_STRING_REP_LENGTH)
size= MAX_DATE_STRING_REP_LENGTH;
- if (format == str)
- str= &value; // Save result here
+ DBUG_ASSERT(format != str);
if (str->alloc(size))
goto null_date;
- DATE_TIME_FORMAT date_time_format;
- date_time_format.format.str= (char*) format->ptr();
- date_time_format.format.length= format->length();
-
/* Create the result string */
str->set_charset(collation.collation);
- if (!make_date_time(&date_time_format, &l_time,
+ if (!make_date_time(format->lex_cstring(), &l_time,
is_time_format ? MYSQL_TIMESTAMP_TIME :
MYSQL_TIMESTAMP_DATE,
locale, str))
diff --git a/sql/log_slow.h b/sql/log_slow.h
index c52722f0cd7..9811d298335 100644
--- a/sql/log_slow.h
+++ b/sql/log_slow.h
@@ -34,4 +34,5 @@
#define QPLAN_FILESORT_PRIORITY_QUEUE (1U << 9)
/* ... */
+#define QPLAN_STATUS (1UL << 31) /* not in the slow_log_filter */
#define QPLAN_MAX (1UL << 31) /* reserved as placeholder */
diff --git a/sql/mdl.h b/sql/mdl.h
index 2aeaef89f26..b76d70763e7 100644
--- a/sql/mdl.h
+++ b/sql/mdl.h
@@ -469,6 +469,16 @@ public:
DBUG_ASSERT(ticket == NULL);
type= type_arg;
}
+ void move_from(MDL_request &from)
+ {
+ type= from.type;
+ duration= from.duration;
+ ticket= from.ticket;
+ next_in_list= from.next_in_list;
+ prev_in_list= from.prev_in_list;
+ key.mdl_key_init(&from.key);
+ from.ticket= NULL; // that's what "move" means
+ }
/**
Is this a request for a lock which allow data to be updated?
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 1352bb64be8..b985607eeb1 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -9613,7 +9613,7 @@ static int get_options(int *argc_ptr, char ***argv_ptr)
global_system_variables.binlog_format= BINLOG_FORMAT_ROW;
}
- if (!opt_bootstrap && WSREP_PROVIDER_EXISTS &&
+ if (!opt_bootstrap && WSREP_PROVIDER_EXISTS && WSREP_ON &&
global_system_variables.binlog_format != BINLOG_FORMAT_ROW)
{
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index 72ba95e30d1..da5e9707595 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -1342,8 +1342,7 @@ QUICK_RANGE_SELECT::~QUICK_RANGE_SELECT()
- Use rowids from unique to run a disk-ordered sweep
*/
-QUICK_INDEX_SORT_SELECT::QUICK_INDEX_SORT_SELECT(THD *thd_param,
- TABLE *table)
+QUICK_INDEX_SORT_SELECT::QUICK_INDEX_SORT_SELECT(THD *thd_param, TABLE *table)
:unique(NULL), pk_quick_select(NULL), thd(thd_param)
{
DBUG_ENTER("QUICK_INDEX_SORT_SELECT::QUICK_INDEX_SORT_SELECT");
@@ -5100,6 +5099,16 @@ typedef struct st_partial_index_intersect_info
key_map filtered_scans; /* scans to be filtered by cpk conditions */
MY_BITMAP *intersect_fields; /* bitmap of fields used in intersection */
+
+ void init()
+ {
+ common_info= NULL;
+ intersect_fields= NULL;
+ records_sent_to_unique= records= length= in_memory= use_cpk_filter= 0;
+ cost= index_read_cost= in_memory_cost= 0.0;
+ filtered_scans.init();
+ filtered_scans.clear_all();
+ }
} PARTIAL_INDEX_INTERSECT_INFO;
@@ -5236,8 +5245,7 @@ bool prepare_search_best_index_intersect(PARAM *param,
if (!n_index_scans)
return 1;
- bzero(init, sizeof(*init));
- init->filtered_scans.init();
+ init->init();
init->common_info= common;
init->cost= cutoff_cost;
diff --git a/sql/partition_info.cc b/sql/partition_info.cc
index d7aec8fd451..3d10166b3d8 100644
--- a/sql/partition_info.cc
+++ b/sql/partition_info.cc
@@ -63,7 +63,7 @@ partition_info *partition_info::get_clone(THD *thd)
mem_alloc_error(sizeof(partition_element));
DBUG_RETURN(NULL);
}
- memcpy(part_clone, part, sizeof(partition_element));
+ *part_clone= *part;
part_clone->subpartitions.empty();
while ((subpart= (subpart_it++)))
{
@@ -73,7 +73,7 @@ partition_info *partition_info::get_clone(THD *thd)
mem_alloc_error(sizeof(partition_element));
DBUG_RETURN(NULL);
}
- memcpy(subpart_clone, subpart, sizeof(partition_element));
+ *subpart_clone= *subpart;
part_clone->subpartitions.push_back(subpart_clone, mem_root);
}
clone->partitions.push_back(part_clone, mem_root);
@@ -1627,12 +1627,11 @@ void partition_info::print_no_partition_found(TABLE *table_arg, myf errflag)
TABLE_LIST table_list;
THD *thd= current_thd;
- bzero(&table_list, sizeof(table_list));
+ table_list.reset();
table_list.db= table_arg->s->db.str;
table_list.table_name= table_arg->s->table_name.str;
- if (check_single_table_access(thd,
- SELECT_ACL, &table_list, TRUE))
+ if (check_single_table_access(thd, SELECT_ACL, &table_list, TRUE))
{
my_message(ER_NO_PARTITION_FOR_GIVEN_VALUE,
ER_THD(thd, ER_NO_PARTITION_FOR_GIVEN_VALUE_SILENT), errflag);
diff --git a/sql/protocol.h b/sql/protocol.h
index 6397e3dd5e6..1a6cb3bdc3c 100644
--- a/sql/protocol.h
+++ b/sql/protocol.h
@@ -230,60 +230,29 @@ class Protocol_discard : public Protocol_text
{
public:
Protocol_discard(THD *thd_arg) : Protocol_text(thd_arg) {}
- /* The real writing is done only in write() */
- virtual bool write() { return 0; }
- virtual bool send_result_set_metadata(List<Item> *list, uint flags)
- {
- // Don't pas Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF flags
- return Protocol_text::send_result_set_metadata(list, 0);
- }
-
- // send_error is intentionally not overloaded.
- virtual bool send_eof(uint server_status, uint statement_warn_count)
- {
- return 0;
- }
-
- void prepare_for_resend()
- {
-#ifndef DBUG_OFF
- field_pos= 0;
-#endif
- }
+ bool write() { return 0; }
+ bool send_result_set_metadata(List<Item> *, uint) { return 0; }
+ bool send_eof(uint, uint) { return 0; }
+ void prepare_for_resend() { IF_DBUG(field_pos= 0,); }
/*
Provide dummy overrides for any storage methods so that we
avoid allocating and copying of data
*/
- virtual bool store_null()
- { return false; }
- virtual bool store_tiny(longlong from)
- { return false; }
- virtual bool store_short(longlong from)
- { return false; }
- virtual bool store_long(longlong from)
- { return false; }
- virtual bool store_longlong(longlong from, bool unsigned_flag)
- { return false; }
- virtual bool store_decimal(const my_decimal *)
- { return false; }
- virtual bool store(const char *from, size_t length, CHARSET_INFO *cs)
- { return false; }
- virtual bool store(const char *from, size_t length,
- CHARSET_INFO *fromcs, CHARSET_INFO *tocs)
- { return false; }
- virtual bool store(MYSQL_TIME *time, int decimals)
- { return false; }
- virtual bool store_date(MYSQL_TIME *time)
- { return false; }
- virtual bool store_time(MYSQL_TIME *time, int decimals)
- { return false; }
- virtual bool store(float nr, uint32 decimals, String *buffer)
- { return false; }
- virtual bool store(double from, uint32 decimals, String *buffer)
- { return false; }
- virtual bool store(Field *field)
- { return false; }
+ bool store_null() { return false; }
+ bool store_tiny(longlong) { return false; }
+ bool store_short(longlong) { return false; }
+ bool store_long(longlong) { return false; }
+ bool store_longlong(longlong, bool) { return false; }
+ bool store_decimal(const my_decimal *) { return false; }
+ bool store(const char *, size_t, CHARSET_INFO *) { return false; }
+ bool store(const char *, size_t, CHARSET_INFO *, CHARSET_INFO *) { return false; }
+ bool store(MYSQL_TIME *, int) { return false; }
+ bool store_date(MYSQL_TIME *) { return false; }
+ bool store_time(MYSQL_TIME *, int) { return false; }
+ bool store(float, uint32, String *) { return false; }
+ bool store(double, uint32, String *) { return false; }
+ bool store(Field *) { return false; }
};
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc
index 537dcc77c8c..1d1cca0568e 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -8500,70 +8500,17 @@ static bool print_grants_for_role(THD *thd, ACL_ROLE * role)
}
-/** checks privileges for SHOW GRANTS and SHOW CREATE USER
-
- @note that in case of SHOW CREATE USER the parser guarantees
- that a role can never happen here, so *rolename will never
- be assigned to
-*/
-static bool check_show_access(THD *thd, LEX_USER *lex_user, char **username,
- char **hostname, char **rolename)
-{
- DBUG_ENTER("check_show_access");
-
- if (lex_user->user.str == current_user.str)
- {
- *username= thd->security_ctx->priv_user;
- *hostname= thd->security_ctx->priv_host;
- }
- else if (lex_user->user.str == current_role.str)
- {
- *rolename= thd->security_ctx->priv_role;
- }
- else if (lex_user->user.str == current_user_and_current_role.str)
- {
- *username= thd->security_ctx->priv_user;
- *hostname= thd->security_ctx->priv_host;
- *rolename= thd->security_ctx->priv_role;
- }
- else
- {
- Security_context *sctx= thd->security_ctx;
- bool do_check_access;
-
- lex_user= get_current_user(thd, lex_user);
- if (!lex_user)
- DBUG_RETURN(TRUE);
-
- if (lex_user->is_role())
- {
- *rolename= lex_user->user.str;
- do_check_access= strcmp(*rolename, sctx->priv_role);
- }
- else
- {
- *username= lex_user->user.str;
- *hostname= lex_user->host.str;
- do_check_access= strcmp(*username, sctx->priv_user) ||
- strcmp(*hostname, sctx->priv_host);
- }
-
- if (do_check_access && check_access(thd, SELECT_ACL, "mysql", 0, 0, 1, 0))
- DBUG_RETURN(TRUE);
- }
- DBUG_RETURN(FALSE);
-}
bool mysql_show_create_user(THD *thd, LEX_USER *lex_user)
{
- char *username= NULL, *hostname= NULL;
+ const char *username= NULL, *hostname= NULL;
char buff[1024]; //Show create user should not take more than 1024 bytes.
Protocol *protocol= thd->protocol;
bool error= false;
ACL_USER *acl_user;
DBUG_ENTER("mysql_show_create_user");
- if (check_show_access(thd, lex_user, &username, &hostname, NULL))
+ if (get_show_user(thd, lex_user, &username, &hostname, NULL))
DBUG_RETURN(TRUE);
List<Item> field_list;
@@ -8635,6 +8582,57 @@ void mysql_show_grants_get_fields(THD *thd, List<Item> *fields,
fields->push_back(field, thd->mem_root);
}
+/** checks privileges for SHOW GRANTS and SHOW CREATE USER
+
+ @note that in case of SHOW CREATE USER the parser guarantees
+ that a role can never happen here, so *rolename will never
+ be assigned to
+*/
+bool get_show_user(THD *thd, LEX_USER *lex_user, const char **username,
+ const char **hostname, const char **rolename)
+{
+ if (lex_user->user.str == current_user.str)
+ {
+ *username= thd->security_ctx->priv_user;
+ *hostname= thd->security_ctx->priv_host;
+ return 0;
+ }
+ if (lex_user->user.str == current_role.str)
+ {
+ *rolename= thd->security_ctx->priv_role;
+ return 0;
+ }
+ if (lex_user->user.str == current_user_and_current_role.str)
+ {
+ *username= thd->security_ctx->priv_user;
+ *hostname= thd->security_ctx->priv_host;
+ *rolename= thd->security_ctx->priv_role;
+ return 0;
+ }
+
+ Security_context *sctx= thd->security_ctx;
+ bool do_check_access;
+
+ if (!(lex_user= get_current_user(thd, lex_user)))
+ return 1;
+
+ if (lex_user->is_role())
+ {
+ *rolename= lex_user->user.str;
+ do_check_access= strcmp(*rolename, sctx->priv_role);
+ }
+ else
+ {
+ *username= lex_user->user.str;
+ *hostname= lex_user->host.str;
+ do_check_access= strcmp(*username, sctx->priv_user) ||
+ strcmp(*hostname, sctx->priv_host);
+ }
+
+ if (do_check_access && check_access(thd, SELECT_ACL, "mysql", 0, 0, 1, 0))
+ return 1;
+ return 0;
+}
/*
SHOW GRANTS; Send grants for a user to the client
@@ -8650,7 +8648,7 @@ bool mysql_show_grants(THD *thd, LEX_USER *lex_user)
ACL_ROLE *acl_role= NULL;
char buff[1024];
Protocol *protocol= thd->protocol;
- char *username= NULL, *hostname= NULL, *rolename= NULL;
+ const char *username= NULL, *hostname= NULL, *rolename= NULL;
DBUG_ENTER("mysql_show_grants");
if (!initialized)
@@ -8659,8 +8657,9 @@ bool mysql_show_grants(THD *thd, LEX_USER *lex_user)
DBUG_RETURN(TRUE);
}
- if (check_show_access(thd, lex_user, &username, &hostname, &rolename))
+ if (get_show_user(thd, lex_user, &username, &hostname, &rolename))
DBUG_RETURN(TRUE);
+
DBUG_ASSERT(rolename || username);
List<Item> field_list;
diff --git a/sql/sql_acl.h b/sql/sql_acl.h
index aeda2696894..a4182a4d300 100644
--- a/sql/sql_acl.h
+++ b/sql/sql_acl.h
@@ -246,6 +246,8 @@ ulong get_table_grant(THD *thd, TABLE_LIST *table);
ulong get_column_grant(THD *thd, GRANT_INFO *grant,
const char *db_name, const char *table_name,
const char *field_name);
+bool get_show_user(THD *thd, LEX_USER *lex_user, const char **username,
+ const char **hostname, const char **rolename);
void mysql_show_grants_get_fields(THD *thd, List<Item> *fields,
const char *name);
bool mysql_show_grants(THD *thd, LEX_USER *user);
diff --git a/sql/sql_admin.h b/sql/sql_admin.h
index ce7308434c5..96594fad0cb 100644
--- a/sql/sql_admin.h
+++ b/sql/sql_admin.h
@@ -28,7 +28,7 @@ int reassign_keycache_tables(THD* thd, KEY_CACHE *src_cache,
/**
Sql_cmd_analyze_table represents the ANALYZE TABLE statement.
*/
-class Sql_cmd_analyze_table : public Sql_cmd_admin
+class Sql_cmd_analyze_table : public Sql_cmd
{
public:
/**
@@ -53,7 +53,7 @@ public:
/**
Sql_cmd_check_table represents the CHECK TABLE statement.
*/
-class Sql_cmd_check_table : public Sql_cmd_admin
+class Sql_cmd_check_table : public Sql_cmd
{
public:
/**
@@ -77,7 +77,7 @@ public:
/**
Sql_cmd_optimize_table represents the OPTIMIZE TABLE statement.
*/
-class Sql_cmd_optimize_table : public Sql_cmd_admin
+class Sql_cmd_optimize_table : public Sql_cmd
{
public:
/**
@@ -102,7 +102,7 @@ public:
/**
Sql_cmd_repair_table represents the REPAIR TABLE statement.
*/
-class Sql_cmd_repair_table : public Sql_cmd_admin
+class Sql_cmd_repair_table : public Sql_cmd
{
public:
/**
diff --git a/sql/sql_alter.cc b/sql/sql_alter.cc
index 23522795cdc..f6db1847063 100644
--- a/sql/sql_alter.cc
+++ b/sql/sql_alter.cc
@@ -234,7 +234,7 @@ bool Sql_cmd_alter_table::execute(THD *thd)
DBUG_RETURN(TRUE); /* purecov: inspected */
/* If it is a merge table, check privileges for merge children. */
- if (create_info.merge_list.first)
+ if (create_info.merge_list)
{
/*
The user must have (SELECT_ACL | UPDATE_ACL | DELETE_ACL) on the
@@ -272,7 +272,7 @@ bool Sql_cmd_alter_table::execute(THD *thd)
*/
if (check_table_access(thd, SELECT_ACL | UPDATE_ACL | DELETE_ACL,
- create_info.merge_list.first, FALSE, UINT_MAX, FALSE))
+ create_info.merge_list, FALSE, UINT_MAX, FALSE))
DBUG_RETURN(TRUE);
}
@@ -283,9 +283,9 @@ bool Sql_cmd_alter_table::execute(THD *thd)
{
// Rename of table
TABLE_LIST tmp_table;
- memset(&tmp_table, 0, sizeof(tmp_table));
- tmp_table.table_name= lex->name.str;
- tmp_table.db= select_lex->db;
+ tmp_table.init_one_table(select_lex->db, strlen(select_lex->db),
+ lex->name.str, lex->name.length,
+ lex->name.str, TL_IGNORE);
tmp_table.grant.privilege= priv;
if (check_grant(thd, INSERT_ACL | CREATE_ACL, &tmp_table, FALSE,
UINT_MAX, FALSE))
diff --git a/sql/sql_alter.h b/sql/sql_alter.h
index 9114c4bd075..e33efc9476f 100644
--- a/sql/sql_alter.h
+++ b/sql/sql_alter.h
@@ -370,7 +370,7 @@ private:
statements.
@todo move Alter_info and other ALTER generic structures from Lex here.
*/
-class Sql_cmd_common_alter_table : public Sql_cmd_admin
+class Sql_cmd_common_alter_table : public Sql_cmd
{
protected:
/**
diff --git a/sql/sql_analyse.cc b/sql/sql_analyse.cc
index 91a80c552cb..8b3e945e891 100644
--- a/sql/sql_analyse.cc
+++ b/sql/sql_analyse.cc
@@ -298,9 +298,9 @@ bool get_ev_num_info(EV_NUM_INFO *ev_info, NUM_INFO *info, const char *num)
} // get_ev_num_info
-void free_string(String *s)
+void free_string(void* str, TREE_FREE, void*)
{
- s->free();
+ ((String*)str)->free();
}
diff --git a/sql/sql_analyse.h b/sql/sql_analyse.h
index 820877f2a69..738737f0edc 100644
--- a/sql/sql_analyse.h
+++ b/sql/sql_analyse.h
@@ -68,7 +68,7 @@ int compare_ulonglong2(void* cmp_arg __attribute__((unused)),
int compare_decimal2(int* len, const char *s, const char *t);
Procedure *proc_analyse_init(THD *thd, ORDER *param, select_result *result,
List<Item> &field_list);
-void free_string(String*);
+void free_string(void* str, TREE_FREE, void*);
class analyse;
class field_info :public Sql_alloc
@@ -121,8 +121,7 @@ public:
must_be_blob(0), was_zero_fill(0),
was_maybe_zerofill(0), can_be_still_num(1)
{ init_tree(&tree, 0, 0, sizeof(String), (qsort_cmp2) sortcmp2,
- (tree_element_free) free_string, NULL,
- MYF(MY_THREAD_SPECIFIC)); };
+ free_string, NULL, MYF(MY_THREAD_SPECIFIC)); };
void add();
void get_opt_type(String*, ha_rows);
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 6592dcd8f6f..d6aa6456710 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -2370,18 +2370,28 @@ CHANGED_TABLE_LIST* THD::changed_table_dup(const char *key, long key_length)
}
-int THD::send_explain_fields(select_result *result, uint8 explain_flags, bool is_analyze)
+int 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);
+
+ return 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;
+ rc= prepare_explain_fields(result, &field_list, explain_flags, is_analyze) ||
+ result->send_result_set_metadata(field_list, Protocol::SEND_NUM_ROWS |
+ Protocol::SEND_EOF);
+ return rc;
}
@@ -2456,7 +2466,7 @@ void THD::make_explain_field_list(List<Item> &field_list, uint8 explain_flags,
if (is_analyze)
{
field_list.push_back(item= new (mem_root)
- Item_float(this, "r_rows", 0.1234, 10, 4),
+ Item_float(this, "r_rows", 0.1234, 2, 4),
mem_root);
item->maybe_null=1;
}
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 7e05274cf06..d701d4cb46c 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -3523,6 +3523,8 @@ public:
void add_changed_table(TABLE *table);
void add_changed_table(const char *key, long key_length);
CHANGED_TABLE_LIST * changed_table_dup(const char *key, long key_length);
+ int prepare_explain_fields(select_result *result, List<Item> *field_list,
+ uint8 explain_flags, bool is_analyze);
int send_explain_fields(select_result *result, uint8 explain_flags,
bool is_analyze);
void make_explain_field_list(List<Item> &field_list, uint8 explain_flags,
@@ -4588,6 +4590,7 @@ public:
virtual ~select_result_sink() {};
};
+class select_result_interceptor;
/*
Interface for sending tabular data, together with some other stuff:
@@ -4680,11 +4683,10 @@ public:
/*
This returns
- - FALSE if the class sends output row to the client
- - TRUE if the output is set elsewhere (a file, @variable, or table).
- Currently all intercepting classes derive from select_result_interceptor.
+ - NULL if the class sends output row to the client
+ - this if the output is set elsewhere (a file, @variable, or table).
*/
- virtual bool is_result_interceptor()=0;
+ virtual select_result_interceptor *result_interceptor()=0;
};
@@ -4752,7 +4754,7 @@ public:
} /* Remove gcc warning */
uint field_count(List<Item> &fields) const { return 0; }
bool send_result_set_metadata(List<Item> &fields, uint flag) { return FALSE; }
- bool is_result_interceptor() { return true; }
+ select_result_interceptor *result_interceptor() { return this; }
/*
Instruct the object to not call my_ok(). Client output will be handled
@@ -4780,7 +4782,7 @@ public:
virtual bool check_simple_select() const { return FALSE; }
void abort_result_set();
virtual void cleanup();
- bool is_result_interceptor() { return false; }
+ select_result_interceptor *result_interceptor() { return NULL; }
};
@@ -5735,13 +5737,18 @@ public:
#define CF_UPDATES_DATA (1U << 18)
/**
+ Not logged into slow log as "admin commands"
+*/
+#define CF_ADMIN_COMMAND (1U << 19)
+
+/**
SP Bulk execution safe
*/
-#define CF_SP_BULK_SAFE (1U << 19)
+#define CF_SP_BULK_SAFE (1U << 20)
/**
SP Bulk execution optimized
*/
-#define CF_SP_BULK_OPTIMIZED (1U << 20)
+#define CF_SP_BULK_OPTIMIZED (1U << 21)
/* Bits in server_command_flags */
diff --git a/sql/sql_cmd.h b/sql/sql_cmd.h
index d6220f9ee44..e33f8e443dc 100644
--- a/sql/sql_cmd.h
+++ b/sql/sql_cmd.h
@@ -148,8 +148,6 @@ public:
*/
virtual bool execute(THD *thd) = 0;
- virtual bool log_slow_enabled_statement(const THD *thd) const;
-
protected:
Sql_cmd()
{}
@@ -166,17 +164,4 @@ protected:
}
};
-
-class Sql_cmd_admin: public Sql_cmd
-{
-public:
- Sql_cmd_admin()
- {}
- ~Sql_cmd_admin()
- {}
- bool log_slow_enabled_statement(const THD *thd) const;
-};
-
-
-
#endif // SQL_CMD_INCLUDED
diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc
index 4c98c9cefdb..e908e703bdd 100644
--- a/sql/sql_handler.cc
+++ b/sql/sql_handler.cc
@@ -358,8 +358,6 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, SQL_HANDLER *reopen)
sql_handler->reset();
}
sql_handler->table= table;
- memcpy(&sql_handler->mdl_request, &tables->mdl_request,
- sizeof(tables->mdl_request));
if (!(sql_handler->lock= get_lock_data(thd, &sql_handler->table, 1,
GET_LOCK_STORE_LOCKS)))
@@ -373,6 +371,8 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, SQL_HANDLER *reopen)
if (error)
goto err;
+ sql_handler->mdl_request.move_from(tables->mdl_request);
+
/* Always read all columns */
table->read_set= &table->s->all_set;
if (table->vcol_set)
@@ -401,9 +401,6 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, SQL_HANDLER *reopen)
*/
table->open_by_handler= 1;
- /* Safety, cleanup the pointer to satisfy MDL assertions. */
- tables->mdl_request.ticket= NULL;
-
if (! reopen)
my_ok(thd);
DBUG_PRINT("exit",("OK"));
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 307473cecbd..c623336fdba 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -4381,14 +4381,12 @@ select_create::binlog_show_create_table(TABLE **tables, uint count)
DBUG_ASSERT(thd->is_current_stmt_binlog_format_row());
DBUG_ASSERT(tables && *tables && count > 0);
- char buf[2048];
- String query(buf, sizeof(buf), system_charset_info);
+ StringBuffer<2048> query(system_charset_info);
int result;
TABLE_LIST tmp_table_list;
- memset(&tmp_table_list, 0, sizeof(tmp_table_list));
+ tmp_table_list.reset();
tmp_table_list.table = *tables;
- query.length(0); // Have to zero it since constructor doesn't
result= show_create_table(thd, &tmp_table_list, &query,
create_info, WITH_DB_NAME);
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 399e189a8d0..53056d220b8 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -4838,19 +4838,6 @@ bool LEX::is_partition_management() const
}
-bool Sql_cmd::log_slow_enabled_statement(const THD *thd) const
-{
- return global_system_variables.sql_log_slow && thd->variables.sql_log_slow;
-}
-
-
-bool Sql_cmd_admin::log_slow_enabled_statement(const THD *thd) const
-{
- return opt_log_slow_admin_statements &&
- Sql_cmd::log_slow_enabled_statement(thd);
-}
-
-
#ifdef MYSQL_SERVER
uint binlog_unsafe_map[256];
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 1d5de9dc276..d2dde1277a1 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -546,10 +546,11 @@ void init_update_queries(void)
sql_command_flags[SQLCOM_CREATE_TABLE]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE |
CF_AUTO_COMMIT_TRANS | CF_REPORT_PROGRESS |
CF_CAN_GENERATE_ROW_EVENTS;
- sql_command_flags[SQLCOM_CREATE_INDEX]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS | CF_REPORT_PROGRESS;
+ sql_command_flags[SQLCOM_CREATE_INDEX]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS |
+ CF_REPORT_PROGRESS | CF_ADMIN_COMMAND;
sql_command_flags[SQLCOM_ALTER_TABLE]= CF_CHANGES_DATA | CF_WRITE_LOGS_COMMAND |
CF_AUTO_COMMIT_TRANS | CF_REPORT_PROGRESS |
- CF_INSERTS_DATA;
+ CF_INSERTS_DATA | CF_ADMIN_COMMAND;
sql_command_flags[SQLCOM_TRUNCATE]= CF_CHANGES_DATA | CF_WRITE_LOGS_COMMAND |
CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_DROP_TABLE]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
@@ -560,8 +561,10 @@ void init_update_queries(void)
sql_command_flags[SQLCOM_DROP_DB]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_ALTER_DB_UPGRADE]= CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_ALTER_DB]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
- sql_command_flags[SQLCOM_RENAME_TABLE]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
- sql_command_flags[SQLCOM_DROP_INDEX]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS | CF_REPORT_PROGRESS;
+ sql_command_flags[SQLCOM_RENAME_TABLE]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS |
+ CF_ADMIN_COMMAND;
+ sql_command_flags[SQLCOM_DROP_INDEX]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS |
+ CF_REPORT_PROGRESS | CF_ADMIN_COMMAND;
sql_command_flags[SQLCOM_CREATE_VIEW]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE |
CF_AUTO_COMMIT_TRANS;
sql_command_flags[SQLCOM_DROP_VIEW]= CF_CHANGES_DATA | CF_AUTO_COMMIT_TRANS;
@@ -735,10 +738,14 @@ void init_update_queries(void)
The following admin table operations are allowed
on log tables.
*/
- sql_command_flags[SQLCOM_REPAIR]= CF_WRITE_LOGS_COMMAND | CF_AUTO_COMMIT_TRANS | CF_REPORT_PROGRESS;
- sql_command_flags[SQLCOM_OPTIMIZE]|= CF_WRITE_LOGS_COMMAND | CF_AUTO_COMMIT_TRANS | CF_REPORT_PROGRESS;
- sql_command_flags[SQLCOM_ANALYZE]= CF_WRITE_LOGS_COMMAND | CF_AUTO_COMMIT_TRANS | CF_REPORT_PROGRESS;
- sql_command_flags[SQLCOM_CHECK]= CF_WRITE_LOGS_COMMAND | CF_AUTO_COMMIT_TRANS | CF_REPORT_PROGRESS;
+ sql_command_flags[SQLCOM_REPAIR]= CF_WRITE_LOGS_COMMAND | CF_AUTO_COMMIT_TRANS |
+ CF_REPORT_PROGRESS | CF_ADMIN_COMMAND;
+ sql_command_flags[SQLCOM_OPTIMIZE]|= CF_WRITE_LOGS_COMMAND | CF_AUTO_COMMIT_TRANS |
+ CF_REPORT_PROGRESS | CF_ADMIN_COMMAND;
+ sql_command_flags[SQLCOM_ANALYZE]= CF_WRITE_LOGS_COMMAND | CF_AUTO_COMMIT_TRANS |
+ CF_REPORT_PROGRESS | CF_ADMIN_COMMAND;
+ sql_command_flags[SQLCOM_CHECK]= CF_WRITE_LOGS_COMMAND | CF_AUTO_COMMIT_TRANS |
+ CF_REPORT_PROGRESS | CF_ADMIN_COMMAND;
sql_command_flags[SQLCOM_CHECKSUM]= CF_REPORT_PROGRESS;
sql_command_flags[SQLCOM_CREATE_USER]|= CF_AUTO_COMMIT_TRANS;
@@ -1612,10 +1619,6 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
m_key);
thd->set_command(command);
- /*
- Commands which always take a long time are logged into
- the slow log only if opt_log_slow_admin_statements is set.
- */
thd->enable_slow_log= true;
thd->query_plan_flags= QPLAN_INIT;
thd->lex->sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */
@@ -2062,7 +2065,6 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
status_var_increment(thd->status_var.com_other);
- thd->enable_slow_log&= opt_log_slow_admin_statements;
thd->query_plan_flags|= QPLAN_ADMIN;
if (check_global_access(thd, REPL_SLAVE_ACL))
break;
@@ -2449,31 +2451,6 @@ com_multi_end:
}
-static bool log_slow_enabled_statement(const THD *thd)
-{
- /*
- TODO-10.4: Add classes Sql_cmd_create_index and Sql_cmd_drop_index
- for symmetry with other admin commands, so these statements can be
- handled by this command:
- */
- if (thd->lex->m_sql_cmd)
- return thd->lex->m_sql_cmd->log_slow_enabled_statement(thd);
-
- /*
- Currently CREATE INDEX or DROP INDEX cause a full table rebuild
- and thus classify as slow administrative statements just like
- ALTER TABLE.
- */
- if ((thd->lex->sql_command == SQLCOM_CREATE_INDEX ||
- thd->lex->sql_command == SQLCOM_DROP_INDEX) &&
- !opt_log_slow_admin_statements)
- return true;
-
- return global_system_variables.sql_log_slow &&
- thd->variables.sql_log_slow;
-}
-
-
/*
@note
This function must call delete_explain_query().
@@ -2502,16 +2479,27 @@ void log_slow_statement(THD *thd)
if (!thd->enable_slow_log)
goto end; // E.g. SP statement
+ DBUG_EXECUTE_IF("simulate_slow_query",
+ thd->server_status|= SERVER_QUERY_WAS_SLOW;);
+
if (((thd->server_status & SERVER_QUERY_WAS_SLOW) ||
((thd->server_status &
(SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED)) &&
opt_log_queries_not_using_indexes &&
- !(sql_command_flags[thd->lex->sql_command] & CF_STATUS_COMMAND))) &&
+ !(thd->query_plan_flags & QPLAN_STATUS))) &&
thd->get_examined_row_count() >= thd->variables.min_examined_row_limit)
{
thd->status_var.long_query_count++;
- if (!log_slow_enabled_statement(thd))
+ /*
+ until opt_log_slow_admin_statements is removed, it
+ duplicates slow_log_filter=admin
+ */
+ if ((thd->query_plan_flags & QPLAN_ADMIN) &&
+ !opt_log_slow_admin_statements)
+ goto end;
+
+ if (!global_system_variables.sql_log_slow || !thd->variables.sql_log_slow)
goto end;
/*
@@ -3448,6 +3436,11 @@ mysql_execute_command(THD *thd)
goto error;
}
+ if (sql_command_flags[lex->sql_command] & CF_STATUS_COMMAND)
+ thd->query_plan_flags|= QPLAN_STATUS;
+ if (sql_command_flags[lex->sql_command] & CF_ADMIN_COMMAND)
+ thd->query_plan_flags|= QPLAN_ADMIN;
+
/* Start timeouts */
thd->set_query_timer();
@@ -3510,12 +3503,14 @@ mysql_execute_command(THD *thd)
case SQLCOM_SHOW_PROFILE:
case SQLCOM_SELECT:
{
-#ifdef WITH_WSREP
if (lex->sql_command == SQLCOM_SELECT)
- WSREP_SYNC_WAIT(thd, WSREP_SYNC_WAIT_BEFORE_READ)
+ WSREP_SYNC_WAIT(thd, WSREP_SYNC_WAIT_BEFORE_READ);
else
- WSREP_SYNC_WAIT(thd, WSREP_SYNC_WAIT_BEFORE_SHOW)
-#endif /* WITH_WSREP */
+ {
+ WSREP_SYNC_WAIT(thd, WSREP_SYNC_WAIT_BEFORE_SHOW);
+ if (lex->sql_command == SQLCOM_SHOW_PROFILE)
+ thd->profiling.discard_current_query();
+ }
thd->status_var.last_query_cost= 0.0;
@@ -4080,7 +4075,6 @@ end_with_restore_list:
if (check_one_table_access(thd, INDEX_ACL, all_tables))
goto error; /* purecov: inspected */
WSREP_TO_ISOLATION_BEGIN(first_table->db, first_table->table_name, NULL)
- thd->query_plan_flags|= QPLAN_ADMIN;
bzero((char*) &create_info, sizeof(create_info));
create_info.db_type= 0;
@@ -4243,49 +4237,6 @@ end_with_restore_list:
DBUG_PRINT("debug", ("lex->only_view: %d, table: %s.%s",
lex->only_view,
first_table->db, first_table->table_name));
- if (lex->only_view)
- {
- if (check_table_access(thd, SELECT_ACL, first_table, FALSE, 1, FALSE))
- {
- DBUG_PRINT("debug", ("check_table_access failed"));
- my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0),
- "SHOW", thd->security_ctx->priv_user,
- thd->security_ctx->host_or_ip, first_table->alias);
- goto error;
- }
- DBUG_PRINT("debug", ("check_table_access succeeded"));
-
- /* Ignore temporary tables if this is "SHOW CREATE VIEW" */
- first_table->open_type= OT_BASE_ONLY;
-
- }
- else
- {
- /*
- Temporary tables should be opened for SHOW CREATE TABLE, but not
- for SHOW CREATE VIEW.
- */
- if (thd->open_temporary_tables(all_tables))
- goto error;
-
- /*
- The fact that check_some_access() returned FALSE does not mean that
- access is granted. We need to check if first_table->grant.privilege
- contains any table-specific privilege.
- */
- DBUG_PRINT("debug", ("first_table->grant.privilege: %lx",
- first_table->grant.privilege));
- if (check_some_access(thd, SHOW_CREATE_TABLE_ACLS, first_table) ||
- (first_table->grant.privilege & SHOW_CREATE_TABLE_ACLS) == 0)
- {
- my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0),
- "SHOW", thd->security_ctx->priv_user,
- thd->security_ctx->host_or_ip, first_table->alias);
- goto error;
- }
- }
-
- /* Access is granted. Execute the command. */
res= mysqld_show_create(thd, first_table);
break;
#endif
@@ -4637,7 +4588,7 @@ end_with_restore_list:
case SQLCOM_DELETE:
{
WSREP_SYNC_WAIT(thd, WSREP_SYNC_WAIT_BEFORE_UPDATE_DELETE);
- select_result *sel_result=lex->result;
+ select_result *sel_result= NULL;
DBUG_ASSERT(first_table == all_tables && first_table != 0);
if (WSREP_CLIENT(thd) &&
wsrep_sync_wait(thd, WSREP_SYNC_WAIT_BEFORE_UPDATE_DELETE))
@@ -4668,16 +4619,15 @@ end_with_restore_list:
}
else
{
- if (!(sel_result= lex->result) &&
- !(sel_result= new (thd->mem_root) select_send(thd)))
- return 1;
+ if (!lex->result && !(sel_result= new (thd->mem_root) select_send(thd)))
+ goto error;
}
}
res = mysql_delete(thd, all_tables,
select_lex->where, &select_lex->order_list,
unit->select_limit_cnt, select_lex->options,
- sel_result);
+ lex->result ? lex->result : sel_result);
if (replaced_protocol)
{
@@ -6262,7 +6212,6 @@ end_with_restore_list:
case SQLCOM_REPAIR:
case SQLCOM_TRUNCATE:
case SQLCOM_ALTER_TABLE:
- thd->query_plan_flags|= QPLAN_ADMIN;
DBUG_ASSERT(first_table == all_tables && first_table != 0);
/* fall through */
case SQLCOM_SIGNAL:
@@ -6506,8 +6455,8 @@ static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables)
Protocol *save_protocol= NULL;
if (lex->analyze_stmt)
{
- if (result && result->is_result_interceptor())
- ((select_result_interceptor*)result)->disable_my_ok_calls();
+ if (result && result->result_interceptor())
+ result->result_interceptor()->disable_my_ok_calls();
else
{
DBUG_ASSERT(thd->protocol);
@@ -7062,7 +7011,7 @@ static bool check_show_access(THD *thd, TABLE_LIST *table)
Check_grant will grant access if there is any column privileges on
all of the tables thanks to the fourth parameter (bool show_table).
*/
- if (check_grant(thd, SELECT_ACL, dst_table, TRUE, UINT_MAX, FALSE))
+ if (check_grant(thd, SELECT_ACL, dst_table, TRUE, 1, FALSE))
return TRUE; /* Access denied */
close_thread_tables(thd);
@@ -9599,7 +9548,7 @@ bool create_table_precheck(THD *thd, TABLE_LIST *tables,
goto err;
/* If it is a merge table, check privileges for merge children. */
- if (lex->create_info.merge_list.first)
+ if (lex->create_info.merge_list)
{
/*
The user must have (SELECT_ACL | UPDATE_ACL | DELETE_ACL) on the
@@ -9637,8 +9586,7 @@ bool create_table_precheck(THD *thd, TABLE_LIST *tables,
*/
if (check_table_access(thd, SELECT_ACL | UPDATE_ACL | DELETE_ACL,
- lex->create_info.merge_list.first,
- FALSE, UINT_MAX, FALSE))
+ lex->create_info.merge_list, FALSE, UINT_MAX, FALSE))
goto err;
}
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 272d6615028..f99dc237cd0 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -1957,9 +1957,20 @@ static int mysql_test_show_grants(Prepared_statement *stmt)
DBUG_ENTER("mysql_test_show_grants");
THD *thd= stmt->thd;
List<Item> fields;
+ char buff[1024];
+ const char *username= NULL, *hostname= NULL, *rolename= NULL;
- mysql_show_grants_get_fields(thd, &fields, "Grants for");
-
+ if (get_show_user(thd, thd->lex->grant_user, &username, &hostname, &rolename))
+ DBUG_RETURN(1);
+
+ if (username)
+ strxmov(buff,"Grants for ",username,"@",hostname, NullS);
+ else if (rolename)
+ strxmov(buff,"Grants for ",rolename, NullS);
+ else
+ DBUG_RETURN(1);
+
+ mysql_show_grants_get_fields(thd, &fields, buff);
DBUG_RETURN(send_stmt_metadata(thd, stmt, &fields));
}
#endif /*NO_EMBEDDED_ACCESS_CHECKS*/
@@ -1983,7 +1994,7 @@ static int mysql_test_show_slave_status(Prepared_statement *stmt)
THD *thd= stmt->thd;
List<Item> fields;
- show_master_info_get_fields(thd, &fields, 0, 0);
+ show_master_info_get_fields(thd, &fields, thd->lex->verbose, 0);
DBUG_RETURN(send_stmt_metadata(thd, stmt, &fields));
}
@@ -2499,6 +2510,7 @@ static bool check_prepared_statement(Prepared_statement *stmt)
case SQLCOM_CREATE_INDEX:
case SQLCOM_DROP_INDEX:
case SQLCOM_ROLLBACK:
+ case SQLCOM_ROLLBACK_TO_SAVEPOINT:
case SQLCOM_TRUNCATE:
case SQLCOM_DROP_VIEW:
case SQLCOM_REPAIR:
@@ -2527,6 +2539,7 @@ static bool check_prepared_statement(Prepared_statement *stmt)
case SQLCOM_GRANT:
case SQLCOM_GRANT_ROLE:
case SQLCOM_REVOKE:
+ case SQLCOM_REVOKE_ALL:
case SQLCOM_REVOKE_ROLE:
case SQLCOM_KILL:
case SQLCOM_COMPOUND:
@@ -2550,8 +2563,26 @@ static bool check_prepared_statement(Prepared_statement *stmt)
break;
}
if (res == 0)
- DBUG_RETURN(stmt->is_sql_prepare() ?
- FALSE : (send_prep_stmt(stmt, 0) || thd->protocol->flush()));
+ {
+ if (!stmt->is_sql_prepare())
+ {
+ if (lex->describe || lex->analyze_stmt)
+ {
+ select_send result(thd);
+ List<Item> field_list;
+ res= thd->prepare_explain_fields(&result, &field_list,
+ lex->describe, lex->analyze_stmt) ||
+ send_prep_stmt(stmt, result.field_count(field_list)) ||
+ result.send_result_set_metadata(field_list,
+ Protocol::SEND_EOF);
+ }
+ else
+ res= send_prep_stmt(stmt, 0);
+ if (!res)
+ thd->protocol->flush();
+ }
+ DBUG_RETURN(FALSE);
+ }
error:
DBUG_RETURN(TRUE);
}
diff --git a/sql/sql_priv.h b/sql/sql_priv.h
index 55148167b32..81dea4e41b0 100644
--- a/sql/sql_priv.h
+++ b/sql/sql_priv.h
@@ -175,12 +175,6 @@
*/
#define OPTION_MASTER_SQL_ERROR (1ULL << 35)
-/*
- Dont report errors for individual rows,
- But just report error on commit (or read ofcourse)
- Note! Reserved for use in MySQL Cluster
-*/
-#define OPTION_ALLOW_BATCH (1ULL << 36) // THD, intern (slave)
#define OPTION_SKIP_REPLICATION (1ULL << 37) // THD, user
#define OPTION_RPL_SKIP_PARALLEL (1ULL << 38)
#define OPTION_FOUND_COMMENT (1ULL << 39) // SELECT, intern, parser
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 91a6445c870..69aa8a97a87 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -3929,7 +3929,7 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list,
DBUG_RETURN(1);
/* The following should be optimized to only clear critical things */
- bzero(stat, sizeof(JOIN_TAB)* table_count);
+ bzero((void*)stat, sizeof(JOIN_TAB)* table_count);
/* Initialize POSITION objects */
for (i=0 ; i <= table_count ; i++)
(void) new ((char*) (join->positions + i)) POSITION;
@@ -9028,7 +9028,7 @@ bool JOIN::get_best_combination()
1. Put into main join order a JOIN_TAB that represents a lookup or scan
in the temptable.
*/
- bzero(j, sizeof(JOIN_TAB));
+ bzero((void*)j, sizeof(JOIN_TAB));
j->join= this;
j->table= NULL; //temporary way to tell SJM tables from others.
j->ref.key = -1;
diff --git a/sql/sql_select.h b/sql/sql_select.h
index a134d601c76..09e8f5a3e10 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -203,7 +203,6 @@ class AGGR_OP;
class Filesort;
typedef struct st_join_table {
- st_join_table() {}
TABLE *table;
TABLE_LIST *tab_list;
KEYUSE *keyuse; /**< pointer to first used key */
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index e13952cbb6c..ce0e3bc6265 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -1206,13 +1206,56 @@ mysqld_show_create_get_fields(THD *thd, TABLE_LIST *table_list,
List<Item> *field_list, String *buffer)
{
bool error= TRUE;
+ LEX *lex= thd->lex;
MEM_ROOT *mem_root= thd->mem_root;
DBUG_ENTER("mysqld_show_create_get_fields");
DBUG_PRINT("enter",("db: %s table: %s",table_list->db,
table_list->table_name));
+ if (lex->only_view)
+ {
+ if (check_table_access(thd, SELECT_ACL, table_list, FALSE, 1, FALSE))
+ {
+ DBUG_PRINT("debug", ("check_table_access failed"));
+ my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0),
+ "SHOW", thd->security_ctx->priv_user,
+ thd->security_ctx->host_or_ip, table_list->alias);
+ goto exit;
+ }
+ DBUG_PRINT("debug", ("check_table_access succeeded"));
+
+ /* Ignore temporary tables if this is "SHOW CREATE VIEW" */
+ table_list->open_type= OT_BASE_ONLY;
+ }
+ else
+ {
+ /*
+ Temporary tables should be opened for SHOW CREATE TABLE, but not
+ for SHOW CREATE VIEW.
+ */
+ if (thd->open_temporary_tables(table_list))
+ goto exit;
+
+ /*
+ The fact that check_some_access() returned FALSE does not mean that
+ access is granted. We need to check if table_list->grant.privilege
+ contains any table-specific privilege.
+ */
+ DBUG_PRINT("debug", ("table_list->grant.privilege: %lx",
+ table_list->grant.privilege));
+ if (check_some_access(thd, SHOW_CREATE_TABLE_ACLS, table_list) ||
+ (table_list->grant.privilege & SHOW_CREATE_TABLE_ACLS) == 0)
+ {
+ my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0),
+ "SHOW", thd->security_ctx->priv_user,
+ thd->security_ctx->host_or_ip, table_list->alias);
+ goto exit;
+ }
+ }
+ /* Access is granted. Execute the command. */
+
/* We want to preserve the tree for views. */
- thd->lex->context_analysis_only|= CONTEXT_ANALYSIS_ONLY_VIEW;
+ lex->context_analysis_only|= CONTEXT_ANALYSIS_ONLY_VIEW;
{
/*
@@ -1227,14 +1270,14 @@ mysqld_show_create_get_fields(THD *thd, TABLE_LIST *table_list,
bool open_error=
open_tables(thd, &table_list, &counter,
MYSQL_OPEN_FORCE_SHARED_HIGH_PRIO_MDL) ||
- mysql_handle_derived(thd->lex, DT_INIT | DT_PREPARE);
+ mysql_handle_derived(lex, DT_INIT | DT_PREPARE);
thd->pop_internal_handler();
if (open_error && (thd->killed || thd->is_error()))
goto exit;
}
/* TODO: add environment variables show when it become possible */
- if (thd->lex->only_view && !table_list->view)
+ if (lex->only_view && !table_list->view)
{
my_error(ER_WRONG_OBJECT, MYF(0),
table_list->db, table_list->table_name, "VIEW");
@@ -6338,7 +6381,7 @@ static int get_schema_views_record(THD *thd, TABLE_LIST *tables,
{
TABLE_LIST table_list;
uint view_access;
- memset(&table_list, 0, sizeof(table_list));
+ table_list.reset();
table_list.db= tables->db;
table_list.table_name= tables->table_name;
table_list.grant.privilege= thd->col_access;
diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc
index 4f1ee2b4c1a..a39e0845a19 100644
--- a/sql/sql_trigger.cc
+++ b/sql/sql_trigger.cc
@@ -1794,7 +1794,7 @@ bool Table_triggers_list::drop_all_triggers(THD *thd, char *db, char *name)
bool result= 0;
DBUG_ENTER("drop_all_triggers");
- bzero(&table, sizeof(table));
+ table.reset();
init_sql_alloc(&table.mem_root, 8192, 0, MYF(0));
if (Table_triggers_list::check_n_load(thd, db, name, &table, 1))
@@ -2044,7 +2044,7 @@ bool Table_triggers_list::change_table_name(THD *thd, const char *db,
Trigger *err_trigger;
DBUG_ENTER("change_table_name");
- bzero(&table, sizeof(table));
+ table.reset();
init_sql_alloc(&table.mem_root, 8192, 0, MYF(0));
/*
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index abee979ff1c..94b8c662a06 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -843,15 +843,6 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
allocation in setup_ref_array().
*/
fake_select_lex->n_child_sum_items+= global_parameters()->n_sum_items;
-
- saved_error= fake_select_lex->join->
- prepare(fake_select_lex->table_list.first,
- 0, 0,
- global_parameters()->order_list.elements, // og_num
- global_parameters()->order_list.first, // order
- false, NULL, NULL, NULL,
- fake_select_lex, this);
- fake_select_lex->table_list.empty();
}
}
else
@@ -862,6 +853,24 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
*/
table->reset_item_list(&item_list);
}
+ if (fake_select_lex != NULL &&
+ (thd->stmt_arena->is_stmt_prepare() ||
+ (thd->lex->context_analysis_only & CONTEXT_ANALYSIS_ONLY_VIEW)))
+ {
+ if (!fake_select_lex->join &&
+ !(fake_select_lex->join=
+ new JOIN(thd, item_list, thd->variables.option_bits, result)))
+ {
+ fake_select_lex->table_list.empty();
+ DBUG_RETURN(TRUE);
+ }
+ saved_error= fake_select_lex->join->
+ prepare(fake_select_lex->table_list.first, 0, 0,
+ global_parameters()->order_list.elements, // og_num
+ global_parameters()->order_list.first, // order
+ false, NULL, NULL, NULL, fake_select_lex, this);
+ fake_select_lex->table_list.empty();
+ }
}
thd_arg->lex->current_select= lex_select_save;
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index 91b811fbb93..0cff47437c8 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -215,7 +215,8 @@ fill_defined_view_parts (THD *thd, TABLE_LIST *view)
LEX *lex= thd->lex;
TABLE_LIST decoy;
- memcpy (&decoy, view, sizeof (TABLE_LIST));
+ decoy= *view;
+ decoy.mdl_request.key.mdl_key_init(&view->mdl_request.key);
if (tdc_open_view(thd, &decoy, OPEN_VIEW_NO_PARSE))
return TRUE;
@@ -331,12 +332,11 @@ bool create_view_precheck(THD *thd, TABLE_LIST *tables, TABLE_LIST *view,
{
if (!tbl->table_in_first_from_clause)
{
- if (check_access(thd, SELECT_ACL, tbl->db,
- &tbl->grant.privilege,
- &tbl->grant.m_internal,
- 0, 0) ||
- check_grant(thd, SELECT_ACL, tbl, FALSE, 1, FALSE))
+ if (check_single_table_access(thd, SELECT_ACL, tbl, FALSE))
+ {
+ tbl->hide_view_error(thd);
goto err;
+ }
}
}
}
@@ -900,15 +900,8 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
View definition query is stored in the client character set.
*/
- char view_query_buff[4096];
- String view_query(view_query_buff,
- sizeof (view_query_buff),
- thd->charset());
-
- char is_query_buff[4096];
- String is_query(is_query_buff,
- sizeof (is_query_buff),
- system_charset_info);
+ StringBuffer<4096> view_query(thd->charset());
+ StringBuffer<4096> is_query(system_charset_info);
char md5[MD5_BUFF_LENGTH];
bool can_be_merged;
@@ -2155,7 +2148,7 @@ mysql_rename_view(THD *thd,
view definition parsing or use temporary 'view_def'
object for it.
*/
- bzero(&view_def, sizeof(view_def));
+ view_def.reset();
view_def.timestamp.str= view_def.timestamp_buffer;
view_def.view_suid= TRUE;
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 133aad53fb1..5b8c3c6c7ec 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -5825,7 +5825,7 @@ create_table_option:
from the global list.
*/
LEX *lex=Lex;
- lex->create_info.merge_list= lex->select_lex.table_list;
+ lex->create_info.merge_list= lex->select_lex.table_list.first;
lex->select_lex.table_list= lex->save_list;
/*
When excluding union list from the global list we assume that
@@ -5834,7 +5834,7 @@ create_table_option:
*/
TABLE_LIST *last_non_sel_table= lex->create_last_non_select_table;
DBUG_ASSERT(last_non_sel_table->next_global ==
- lex->create_info.merge_list.first);
+ lex->create_info.merge_list);
last_non_sel_table->next_global= 0;
Lex->query_tables_last= &last_non_sel_table->next_global;
@@ -13573,6 +13573,7 @@ load:
LOAD data_or_xml
{
LEX *lex= thd->lex;
+ mysql_init_select(lex);
if (lex->sphead)
{
diff --git a/sql/table.h b/sql/table.h
index c3c138c1278..c3ce5b8af51 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -762,6 +762,8 @@ struct TABLE_SHARE
/** Instrumentation for this table share. */
PSI_table_share *m_psi;
+ inline void reset() { bzero((void*)this, sizeof(*this)); }
+
/*
Set share's table cache key and update its db and table name appropriately.
@@ -1309,6 +1311,7 @@ public:
bool histograms_are_read;
MDL_ticket *mdl_ticket;
+ inline void reset() { bzero((void*)this, sizeof(*this)); }
void init(THD *thd, TABLE_LIST *tl);
bool fill_item_list(List<Item> *item_list) const;
void reset_item_list(List<Item> *item_list) const;
@@ -1751,6 +1754,7 @@ struct TABLE_LIST
Prepare TABLE_LIST that consists of one table instance to use in
open_and_lock_tables
*/
+ inline void reset() { bzero((void*)this, sizeof(*this)); }
inline void init_one_table(const char *db_name_arg,
size_t db_length_arg,
const char *table_name_arg,
@@ -1766,9 +1770,9 @@ struct TABLE_LIST
else
mdl_type= MDL_SHARED_READ;
- bzero((char*) this, sizeof(*this));
DBUG_ASSERT(!db_name_arg || strlen(db_name_arg) == db_length_arg);
DBUG_ASSERT(!table_name_arg || strlen(table_name_arg) == table_name_length_arg);
+ reset();
db= (char*) db_name_arg;
db_length= db_length_arg;
table_name= (char*) table_name_arg;
@@ -2272,8 +2276,7 @@ struct TABLE_LIST
@sa check_and_update_table_version()
*/
- inline
- bool is_table_ref_id_equal(TABLE_SHARE *s) const
+ inline bool is_table_ref_id_equal(TABLE_SHARE *s) const
{
return (m_table_ref_type == s->get_table_ref_type() &&
m_table_ref_version == s->get_table_ref_version());
@@ -2285,12 +2288,10 @@ struct TABLE_LIST
@sa check_and_update_table_version()
*/
- inline
- void set_table_ref_id(TABLE_SHARE *s)
+ inline void set_table_ref_id(TABLE_SHARE *s)
{ set_table_ref_id(s->get_table_ref_type(), s->get_table_ref_version()); }
- inline
- void set_table_ref_id(enum_table_ref_type table_ref_type_arg,
+ inline void set_table_ref_id(enum_table_ref_type table_ref_type_arg,
ulong table_ref_version_arg)
{
m_table_ref_type= table_ref_type_arg;
diff --git a/sql/tztime.cc b/sql/tztime.cc
index 82160231b03..1167ea18e7e 100644
--- a/sql/tztime.cc
+++ b/sql/tztime.cc
@@ -1537,16 +1537,11 @@ my_offset_tzs_get_key(Time_zone_offset *entry,
static void
tz_init_table_list(TABLE_LIST *tz_tabs)
{
- bzero(tz_tabs, sizeof(TABLE_LIST) * MY_TZ_TABLES_COUNT);
-
for (int i= 0; i < MY_TZ_TABLES_COUNT; i++)
{
- tz_tabs[i].alias= tz_tabs[i].table_name= tz_tables_names[i].str;
- tz_tabs[i].table_name_length= tz_tables_names[i].length;
- tz_tabs[i].db= tz_tables_db_name.str;
- tz_tabs[i].db_length= tz_tables_db_name.length;
- tz_tabs[i].lock_type= TL_READ;
-
+ tz_tabs[i].init_one_table(tz_tables_db_name.str, tz_tables_db_name.length,
+ tz_tables_names[i].str, tz_tables_names[i].length,
+ NULL, TL_READ);
if (i != MY_TZ_TABLES_COUNT - 1)
tz_tabs[i].next_global= tz_tabs[i].next_local= &tz_tabs[i+1];
if (i != 0)