summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2021-08-18 18:22:35 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2021-08-18 18:22:35 +0300
commit4a2595727465648f2d4e794d1b2f182345f0bee8 (patch)
tree8d4734e6c5b2795455416191ca50d5a0fbd23cd9 /sql
parentda171182b7d79d21177d113d2bbaecbca21d8bbc (diff)
parentf84e28c119b495da77e197f7cd18af4048fc3126 (diff)
downloadmariadb-git-4a2595727465648f2d4e794d1b2f182345f0bee8.tar.gz
Merge 10.4 into 10.5
Diffstat (limited to 'sql')
-rw-r--r--sql/field.cc3
-rw-r--r--sql/field.h35
-rw-r--r--sql/filesort.cc9
-rw-r--r--sql/ha_partition.cc217
-rw-r--r--sql/ha_partition.h14
-rw-r--r--sql/item_jsonfunc.h2
-rw-r--r--sql/log.cc3
-rw-r--r--sql/log.h6
-rw-r--r--sql/sql_audit.h2
-rw-r--r--sql/sql_class.cc4
-rw-r--r--sql/sql_lex.cc5
-rw-r--r--sql/sql_prepare.cc5
-rw-r--r--sql/sql_repl.cc12
-rw-r--r--sql/sql_view.cc2
-rw-r--r--sql/table.cc4
-rw-r--r--sql/table.h2
16 files changed, 247 insertions, 78 deletions
diff --git a/sql/field.cc b/sql/field.cc
index 71ca27c5ad0..08bde5f58e1 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -1,6 +1,6 @@
/*
Copyright (c) 2000, 2017, Oracle and/or its affiliates.
- Copyright (c) 2008, 2020, MariaDB
+ Copyright (c) 2008, 2021, MariaDB
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
@@ -8612,6 +8612,7 @@ int Field_blob::store(const char *from,size_t length,CHARSET_INFO *cs)
rc= well_formed_copy_with_check((char*) value.ptr(), (uint) new_length,
cs, from, length,
length, true, &copy_len);
+ value.length(copy_len);
Field_blob::store_length(copy_len);
bmove(ptr+packlength,(uchar*) &tmp,sizeof(char*));
diff --git a/sql/field.h b/sql/field.h
index 9fe4db3b521..6ada7f94507 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -4554,7 +4554,13 @@ public:
uchar *new_ptr, uint32 length,
uchar *new_null_ptr, uint new_null_bit) override;
void sql_type(String &str) const override;
- inline bool copy()
+ /**
+ Copy blob buffer into internal storage "value" and update record pointer.
+
+ @retval true Memory allocation error
+ @retval false Success
+ */
+ bool copy()
{
uchar *tmp= get_ptr();
if (value.copy((char*) tmp, get_length(), charset()))
@@ -4566,6 +4572,33 @@ public:
memcpy(ptr+packlength, &tmp, sizeof(char*));
return 0;
}
+ void swap(String &inout, bool set_read_value)
+ {
+ if (set_read_value)
+ read_value.swap(inout);
+ else
+ value.swap(inout);
+ }
+ /**
+ Return pointer to blob cache or NULL if not cached.
+ */
+ String * cached(bool *set_read_value)
+ {
+ char *tmp= (char *) get_ptr();
+ if (!value.is_empty() && tmp == value.ptr())
+ {
+ *set_read_value= false;
+ return &value;
+ }
+
+ if (!read_value.is_empty() && tmp == read_value.ptr())
+ {
+ *set_read_value= true;
+ return &read_value;
+ }
+
+ return NULL;
+ }
/* store value for the duration of the current read record */
inline void swap_value_and_read_value()
{
diff --git a/sql/filesort.cc b/sql/filesort.cc
index 4eea588007e..766415f58fb 100644
--- a/sql/filesort.cc
+++ b/sql/filesort.cc
@@ -713,6 +713,15 @@ const char* dbug_print_table_row(TABLE *table)
}
+const char* dbug_print_row(TABLE *table, uchar *rec)
+{
+ table->move_fields(table->field, rec, table->record[0]);
+ const char* ret= dbug_print_table_row(table);
+ table->move_fields(table->field, table->record[0], rec);
+ return ret;
+}
+
+
/*
Print a text, SQL-like record representation into dbug trace.
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc
index 2c60a98de33..73e9f8ee84f 100644
--- a/sql/ha_partition.cc
+++ b/sql/ha_partition.cc
@@ -5417,59 +5417,69 @@ bool ha_partition::init_record_priority_queue()
/*
Initialize the ordered record buffer.
*/
- if (!m_ordered_rec_buffer)
- {
- size_t alloc_len;
- uint used_parts= bitmap_bits_set(&m_part_info->read_partitions);
-
- if (used_parts == 0) /* Do nothing since no records expected. */
- DBUG_RETURN(false);
+ size_t alloc_len;
+ uint used_parts= bitmap_bits_set(&m_part_info->read_partitions);
- /* Allocate record buffer for each used partition. */
- m_priority_queue_rec_len= m_rec_length + PARTITION_BYTES_IN_POS;
- if (!m_using_extended_keys)
- m_priority_queue_rec_len += get_open_file_sample()->ref_length;
- alloc_len= used_parts * m_priority_queue_rec_len;
- /* Allocate a key for temporary use when setting up the scan. */
- alloc_len+= table_share->max_key_length;
+ if (used_parts == 0) /* Do nothing since no records expected. */
+ DBUG_RETURN(false);
- if (!(m_ordered_rec_buffer= (uchar*)my_malloc(key_memory_partition_sort_buffer,
- alloc_len, MYF(MY_WME))))
- DBUG_RETURN(true);
+ /* Allocate record buffer for each used partition. */
+ m_priority_queue_rec_len= m_rec_length + ORDERED_REC_OFFSET;
+ if (!m_using_extended_keys)
+ m_priority_queue_rec_len+= get_open_file_sample()->ref_length;
+ alloc_len= used_parts * m_priority_queue_rec_len;
+ /* Allocate a key for temporary use when setting up the scan. */
+ alloc_len+= table_share->max_key_length;
+ Ordered_blob_storage **blob_storage;
+ Ordered_blob_storage *objs;
+ const size_t n_all= used_parts * table->s->blob_fields;
+
+ if (!my_multi_malloc(key_memory_partition_sort_buffer, MYF(MY_WME),
+ &m_ordered_rec_buffer, alloc_len,
+ &blob_storage, n_all * sizeof *blob_storage,
+ &objs, n_all * sizeof *objs, NULL))
+ DBUG_RETURN(true);
- /*
- We set-up one record per partition and each record has 2 bytes in
- front where the partition id is written. This is used by ordered
- index_read.
- We also set-up a reference to the first record for temporary use in
- setting up the scan.
- */
- char *ptr= (char*) m_ordered_rec_buffer;
- uint i;
- for (i= bitmap_get_first_set(&m_part_info->read_partitions);
- i < m_tot_parts;
- i= bitmap_get_next_set(&m_part_info->read_partitions, i))
+ /*
+ We set-up one record per partition and each record has 2 bytes in
+ front where the partition id is written. This is used by ordered
+ index_read.
+ We also set-up a reference to the first record for temporary use in
+ setting up the scan.
+ */
+ char *ptr= (char*) m_ordered_rec_buffer;
+ uint i;
+ for (i= bitmap_get_first_set(&m_part_info->read_partitions);
+ i < m_tot_parts;
+ i= bitmap_get_next_set(&m_part_info->read_partitions, i))
+ {
+ DBUG_PRINT("info", ("init rec-buf for part %u", i));
+ if (table->s->blob_fields)
{
- DBUG_PRINT("info", ("init rec-buf for part %u", i));
- int2store(ptr, i);
- ptr+= m_priority_queue_rec_len;
+ for (uint j= 0; j < table->s->blob_fields; ++j, ++objs)
+ blob_storage[j]= new (objs) Ordered_blob_storage;
+ *((Ordered_blob_storage ***) ptr)= blob_storage;
+ blob_storage+= table->s->blob_fields;
}
- m_start_key.key= (const uchar*)ptr;
+ int2store(ptr + sizeof(String **), i);
+ ptr+= m_priority_queue_rec_len;
+ }
+ m_start_key.key= (const uchar*)ptr;
- /* Initialize priority queue, initialized to reading forward. */
- int (*cmp_func)(void *, uchar *, uchar *);
- void *cmp_arg= (void*) this;
- if (!m_using_extended_keys && !(table_flags() & HA_SLOW_CMP_REF))
- cmp_func= cmp_key_rowid_part_id;
- else
- cmp_func= cmp_key_part_id;
- DBUG_PRINT("info", ("partition queue_init(1) used_parts: %u", used_parts));
- if (init_queue(&m_queue, used_parts, 0, 0, cmp_func, cmp_arg, 0, 0))
- {
- my_free(m_ordered_rec_buffer);
- m_ordered_rec_buffer= NULL;
- DBUG_RETURN(true);
- }
+ /* Initialize priority queue, initialized to reading forward. */
+ int (*cmp_func)(void *, uchar *, uchar *);
+ void *cmp_arg= (void*) this;
+ if (!m_using_extended_keys && !(table_flags() & HA_SLOW_CMP_REF))
+ cmp_func= cmp_key_rowid_part_id;
+ else
+ cmp_func= cmp_key_part_id;
+ DBUG_PRINT("info", ("partition queue_init(1) used_parts: %u", used_parts));
+ if (init_queue(&m_queue, used_parts, ORDERED_PART_NUM_OFFSET,
+ 0, cmp_func, cmp_arg, 0, 0))
+ {
+ my_free(m_ordered_rec_buffer);
+ m_ordered_rec_buffer= NULL;
+ DBUG_RETURN(true);
}
DBUG_RETURN(false);
}
@@ -5484,6 +5494,20 @@ void ha_partition::destroy_record_priority_queue()
DBUG_ENTER("ha_partition::destroy_record_priority_queue");
if (m_ordered_rec_buffer)
{
+ if (table->s->blob_fields)
+ {
+ char *ptr= (char *) m_ordered_rec_buffer;
+ for (uint i= bitmap_get_first_set(&m_part_info->read_partitions);
+ i < m_tot_parts;
+ i= bitmap_get_next_set(&m_part_info->read_partitions, i))
+ {
+ Ordered_blob_storage **blob_storage= *((Ordered_blob_storage ***) ptr);
+ for (uint b= 0; b < table->s->blob_fields; ++b)
+ blob_storage[b]->blob.free();
+ ptr+= m_priority_queue_rec_len;
+ }
+ }
+
delete_queue(&m_queue);
my_free(m_ordered_rec_buffer);
m_ordered_rec_buffer= NULL;
@@ -5711,12 +5735,10 @@ static int cmp_part_ids(uchar *ref1, uchar *ref2)
extern "C" int cmp_key_part_id(void *ptr, uchar *ref1, uchar *ref2)
{
ha_partition *file= (ha_partition*)ptr;
- int res;
- if ((res= key_rec_cmp(file->m_curr_key_info, ref1 + PARTITION_BYTES_IN_POS,
- ref2 + PARTITION_BYTES_IN_POS)))
- {
+ if (int res= key_rec_cmp(file->m_curr_key_info,
+ ref1 + PARTITION_BYTES_IN_POS,
+ ref2 + PARTITION_BYTES_IN_POS))
return res;
- }
return cmp_part_ids(ref1, ref2);
}
@@ -6964,6 +6986,48 @@ int ha_partition::pre_ft_end()
}
+void ha_partition::swap_blobs(uchar * rec_buf, Ordered_blob_storage ** storage, bool restore)
+{
+ uint *ptr, *end;
+ uint blob_n= 0;
+ table->move_fields(table->field, rec_buf, table->record[0]);
+ for (ptr= table->s->blob_field, end= ptr + table->s->blob_fields;
+ ptr != end; ++ptr, ++blob_n)
+ {
+ DBUG_ASSERT(*ptr < table->s->fields);
+ Field_blob *blob= (Field_blob*) table->field[*ptr];
+ DBUG_ASSERT(blob->flags & BLOB_FLAG);
+ DBUG_ASSERT(blob->field_index == *ptr);
+ if (!bitmap_is_set(table->read_set, *ptr) || blob->is_null())
+ continue;
+
+ Ordered_blob_storage &s= *storage[blob_n];
+
+ if (restore)
+ {
+ /*
+ We protect only blob cache (value or read_value). If the cache was
+ empty that doesn't mean the blob was empty. Blobs allocated by a
+ storage engine should work just fine.
+ */
+ if (!s.blob.is_empty())
+ blob->swap(s.blob, s.set_read_value);
+ }
+ else
+ {
+ bool set_read_value;
+ String *cached= blob->cached(&set_read_value);
+ if (cached)
+ {
+ cached->swap(s.blob);
+ s.set_read_value= set_read_value;
+ }
+ }
+ }
+ table->move_fields(table->field, table->record[0], rec_buf);
+}
+
+
/**
Initialize a full text search using the extended API.
@@ -7671,8 +7735,8 @@ int ha_partition::handle_ordered_index_scan(uchar *buf, bool reverse_order)
{
DBUG_PRINT("info", ("reading from part %u (scan_type: %u)",
i, m_index_scan_type));
- DBUG_ASSERT(i == uint2korr(part_rec_buf_ptr));
- uchar *rec_buf_ptr= part_rec_buf_ptr + PARTITION_BYTES_IN_POS;
+ DBUG_ASSERT(i == uint2korr(part_rec_buf_ptr + ORDERED_PART_NUM_OFFSET));
+ uchar *rec_buf_ptr= part_rec_buf_ptr + ORDERED_REC_OFFSET;
handler *file= m_file[i];
switch (m_index_scan_type) {
@@ -7752,6 +7816,12 @@ int ha_partition::handle_ordered_index_scan(uchar *buf, bool reverse_order)
Initialize queue without order first, simply insert
*/
queue_element(&m_queue, j++)= part_rec_buf_ptr;
+ if (table->s->blob_fields)
+ {
+ Ordered_blob_storage **storage=
+ *((Ordered_blob_storage ***) part_rec_buf_ptr);
+ swap_blobs(rec_buf_ptr, storage, false);
+ }
}
else if (error == HA_ERR_KEY_NOT_FOUND)
{
@@ -7794,7 +7864,7 @@ int ha_partition::handle_ordered_index_scan(uchar *buf, bool reverse_order)
DBUG_PRINT("info", ("partition !bitmap_is_set(&m_mrr_used_partitions, i)"));
continue;
}
- DBUG_ASSERT(i == uint2korr(part_rec_buf_ptr));
+ DBUG_ASSERT(i == uint2korr(part_rec_buf_ptr + ORDERED_PART_NUM_OFFSET));
if (smallest_range_seq == m_stock_range_seq[i])
{
m_stock_range_seq[i]= 0;
@@ -7841,12 +7911,17 @@ void ha_partition::return_top_record(uchar *buf)
{
uint part_id;
uchar *key_buffer= queue_top(&m_queue);
- uchar *rec_buffer= key_buffer + PARTITION_BYTES_IN_POS;
+ uchar *rec_buffer= key_buffer + ORDERED_REC_OFFSET;
DBUG_ENTER("ha_partition::return_top_record");
DBUG_PRINT("enter", ("partition this: %p", this));
- part_id= uint2korr(key_buffer);
+ part_id= uint2korr(key_buffer + ORDERED_PART_NUM_OFFSET);
memcpy(buf, rec_buffer, m_rec_length);
+ if (table->s->blob_fields)
+ {
+ Ordered_blob_storage **storage= *((Ordered_blob_storage ***) key_buffer);
+ swap_blobs(buf, storage, true);
+ }
m_last_part= part_id;
DBUG_PRINT("info", ("partition m_last_part: %u", m_last_part));
m_top_entry= part_id;
@@ -7898,7 +7973,7 @@ int ha_partition::handle_ordered_index_scan_key_not_found()
This partition is used and did return HA_ERR_KEY_NOT_FOUND
in index_read_map.
*/
- curr_rec_buf= part_buf + PARTITION_BYTES_IN_POS;
+ curr_rec_buf= part_buf + ORDERED_REC_OFFSET;
error= m_file[i]->ha_index_next(curr_rec_buf);
/* HA_ERR_KEY_NOT_FOUND is not allowed from index_next! */
DBUG_ASSERT(error != HA_ERR_KEY_NOT_FOUND);
@@ -7949,7 +8024,8 @@ int ha_partition::handle_ordered_next(uchar *buf, bool is_next_same)
DBUG_RETURN(HA_ERR_END_OF_FILE);
uint part_id= m_top_entry;
- uchar *rec_buf= queue_top(&m_queue) + PARTITION_BYTES_IN_POS;
+ uchar *part_rec_buf_ptr= queue_top(&m_queue);
+ uchar *rec_buf= part_rec_buf_ptr + ORDERED_REC_OFFSET;
handler *file;
if (m_key_not_found)
@@ -7991,7 +8067,16 @@ int ha_partition::handle_ordered_next(uchar *buf, bool is_next_same)
if (m_index_scan_type == partition_read_range)
{
error= file->read_range_next();
- memcpy(rec_buf, table->record[0], m_rec_length);
+ if (likely(!error))
+ {
+ memcpy(rec_buf, table->record[0], m_rec_length);
+ if (table->s->blob_fields)
+ {
+ Ordered_blob_storage **storage=
+ *((Ordered_blob_storage ***) part_rec_buf_ptr);
+ swap_blobs(rec_buf, storage, false);
+ }
+ }
}
else if (m_index_scan_type == partition_read_multi_range)
{
@@ -8028,6 +8113,11 @@ int ha_partition::handle_ordered_next(uchar *buf, bool is_next_same)
DBUG_PRINT("info", ("m_mrr_range_current->id: %u",
m_mrr_range_current->id));
memcpy(rec_buf, table->record[0], m_rec_length);
+ if (table->s->blob_fields)
+ {
+ Ordered_blob_storage **storage= *((Ordered_blob_storage ***) part_rec_buf_ptr);
+ swap_blobs(rec_buf, storage, false);
+ }
if (((PARTITION_KEY_MULTI_RANGE *) m_range_info[part_id])->id !=
m_mrr_range_current->id)
{
@@ -8078,9 +8168,8 @@ int ha_partition::handle_ordered_next(uchar *buf, bool is_next_same)
DBUG_PRINT("info",("partition !bitmap_is_set(&m_mrr_used_partitions, i)"));
continue;
}
- DBUG_PRINT("info",("partition uint2korr: %u",
- uint2korr(part_rec_buf_ptr)));
- DBUG_ASSERT(i == uint2korr(part_rec_buf_ptr));
+ DBUG_ASSERT(i == uint2korr(part_rec_buf_ptr +
+ ORDERED_PART_NUM_OFFSET));
DBUG_PRINT("info", ("partition m_stock_range_seq[%u]: %u",
i, m_stock_range_seq[i]));
if (smallest_range_seq == m_stock_range_seq[i])
@@ -8169,7 +8258,7 @@ int ha_partition::handle_ordered_prev(uchar *buf)
DBUG_RETURN(HA_ERR_END_OF_FILE);
uint part_id= m_top_entry;
- uchar *rec_buf= queue_top(&m_queue) + PARTITION_BYTES_IN_POS;
+ uchar *rec_buf= queue_top(&m_queue) + ORDERED_REC_OFFSET;
handler *file= m_file[part_id];
if (unlikely((error= file->ha_index_prev(rec_buf))))
diff --git a/sql/ha_partition.h b/sql/ha_partition.h
index b77e20f3e9c..c082274b1be 100644
--- a/sql/ha_partition.h
+++ b/sql/ha_partition.h
@@ -21,8 +21,19 @@
#include "sql_partition.h" /* part_id_range, partition_element */
#include "queues.h" /* QUEUE */
-#define PARTITION_BYTES_IN_POS 2
+struct Ordered_blob_storage
+{
+ String blob;
+ bool set_read_value;
+ Ordered_blob_storage() : set_read_value(false)
+ {}
+};
+
#define PAR_EXT ".par"
+#define PARTITION_BYTES_IN_POS 2
+#define ORDERED_PART_NUM_OFFSET sizeof(Ordered_blob_storage **)
+#define ORDERED_REC_OFFSET (ORDERED_PART_NUM_OFFSET + PARTITION_BYTES_IN_POS)
+
/** Struct used for partition_name_hash */
typedef struct st_part_name_def
@@ -933,6 +944,7 @@ private:
int handle_ordered_next(uchar * buf, bool next_same);
int handle_ordered_prev(uchar * buf);
void return_top_record(uchar * buf);
+ void swap_blobs(uchar* rec_buf, Ordered_blob_storage ** storage, bool restore);
public:
/*
-------------------------------------------------------------------------
diff --git a/sql/item_jsonfunc.h b/sql/item_jsonfunc.h
index 0026fce21b2..d5c385b81fe 100644
--- a/sql/item_jsonfunc.h
+++ b/sql/item_jsonfunc.h
@@ -444,7 +444,7 @@ public:
const char *func_name() const
{
return mode_insert ?
- (mode_replace ? "json_set" : "json_insert") : "json_update";
+ (mode_replace ? "json_set" : "json_insert") : "json_replace";
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_json_insert>(thd, this); }
diff --git a/sql/log.cc b/sql/log.cc
index d9a271c56bd..3cfe6bbfd37 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -3392,7 +3392,7 @@ MYSQL_BIN_LOG::MYSQL_BIN_LOG(uint *sync_period)
checksum_alg_reset(BINLOG_CHECKSUM_ALG_UNDEF),
relay_log_checksum_alg(BINLOG_CHECKSUM_ALG_UNDEF),
description_event_for_exec(0), description_event_for_queue(0),
- current_binlog_id(0)
+ current_binlog_id(0), reset_master_count(0)
{
/*
We don't want to initialize locks here as such initialization depends on
@@ -4485,6 +4485,7 @@ err:
}
mysql_cond_broadcast(&COND_xid_list);
reset_master_pending--;
+ reset_master_count++;
mysql_mutex_unlock(&LOCK_xid_list);
}
diff --git a/sql/log.h b/sql/log.h
index eaf7cde1c07..e7df904d49e 100644
--- a/sql/log.h
+++ b/sql/log.h
@@ -675,6 +675,11 @@ public:
my_off_t last_commit_pos_offset;
ulong current_binlog_id;
+ /*
+ Tracks the number of times that the master has been reset
+ */
+ Atomic_counter<uint64> reset_master_count;
+
MYSQL_BIN_LOG(uint *sync_period);
/*
note that there's no destructor ~MYSQL_BIN_LOG() !
@@ -888,6 +893,7 @@ public:
inline mysql_mutex_t* get_log_lock() { return &LOCK_log; }
inline mysql_cond_t* get_bin_log_cond() { return &COND_bin_log_updated; }
inline IO_CACHE* get_log_file() { return &log_file; }
+ inline uint64 get_reset_master_count() { return reset_master_count; }
inline void lock_index() { mysql_mutex_lock(&LOCK_index);}
inline void unlock_index() { mysql_mutex_unlock(&LOCK_index);}
diff --git a/sql/sql_audit.h b/sql/sql_audit.h
index 40276c86a78..64500067699 100644
--- a/sql/sql_audit.h
+++ b/sql/sql_audit.h
@@ -155,7 +155,7 @@ void mysql_audit_general(THD *thd, uint event_subtype,
DBUG_ENTER("mysql_audit_general");
if (mysql_audit_general_enabled())
{
- char user_buff[MAX_USER_HOST_SIZE];
+ char user_buff[MAX_USER_HOST_SIZE+1];
mysql_event_general event;
event.event_subclass= event_subtype;
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 37580568de5..df241afc838 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -5403,8 +5403,8 @@ extern "C" bool thd_is_strict_mode(const MYSQL_THD thd)
*/
void thd_get_query_start_data(THD *thd, char *buf)
{
- LEX_CSTRING field_name;
- Field_timestampf f((uchar *)buf, NULL, 0, Field::NONE, &field_name, NULL, 6);
+ Field_timestampf f((uchar *)buf, nullptr, 0, Field::NONE, &empty_clex_str,
+ nullptr, 6);
f.store_TIME(thd->query_start(), thd->query_start_sec_part());
}
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 5a39b380855..03dcd825de7 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -3536,7 +3536,7 @@ bool st_select_lex::setup_ref_array(THD *thd, uint order_group_num)
prepared statement
*/
Query_arena *arena= thd->stmt_arena;
- const uint n_elems= (n_sum_items +
+ const size_t n_elems= (n_sum_items +
n_child_sum_items +
item_list.elements +
select_n_reserved +
@@ -3544,7 +3544,8 @@ bool st_select_lex::setup_ref_array(THD *thd, uint order_group_num)
select_n_where_fields +
order_group_num +
hidden_bit_fields +
- fields_in_window_functions) * 5;
+ fields_in_window_functions) * (size_t) 5;
+ DBUG_ASSERT(n_elems % 5 == 0);
if (!ref_pointer_array.is_null())
{
/*
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index b1a5a3e7199..a6fb17eaa74 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -3445,6 +3445,11 @@ static void mysql_stmt_execute_common(THD *thd,
stmt_id == LAST_STMT_ID, read_types))
{
my_error(ER_MALFORMED_PACKET, MYF(0));
+ /*
+ Let's set the thd->query_string so the audit plugin
+ can report the executed query that failed.
+ */
+ thd->set_query_inner(stmt->query_string);
DBUG_VOID_RETURN;
}
diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc
index ff2faca5ecf..c49ea7d5908 100644
--- a/sql/sql_repl.cc
+++ b/sql/sql_repl.cc
@@ -4375,6 +4375,7 @@ bool show_binlogs(THD* thd)
Protocol *protocol= thd->protocol;
uint retry_count= 0;
size_t cur_dir_len;
+ uint64 expected_reset_masters;
DBUG_ENTER("show_binlogs");
if (!mysql_bin_log.is_open())
@@ -4399,6 +4400,7 @@ retry:
mysql_mutex_lock(mysql_bin_log.get_log_lock());
mysql_bin_log.lock_index();
mysql_bin_log.raw_get_current_log(&cur);
+ expected_reset_masters= mysql_bin_log.get_reset_master_count();
mysql_mutex_unlock(mysql_bin_log.get_log_lock());
/* The following call unlocks lock_index */
@@ -4419,6 +4421,16 @@ retry:
cur_link->name.str+= dir_len;
cur_link->name.length-= dir_len;
+ if (mysql_bin_log.get_reset_master_count() > expected_reset_masters)
+ {
+ /*
+ Reset master was called after we cached filenames.
+ Reinitialize the cache.
+ */
+ free_root(&mem_root, MYF(MY_MARK_BLOCKS_FREE));
+ goto retry;
+ }
+
if (!(strncmp(fname+dir_len, cur.log_file_name+cur_dir_len, length)))
cur_link->size= cur.pos; /* The active log, use the active position */
else
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index b7f64389f02..a95e52a72a0 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -845,7 +845,7 @@ int mariadb_fix_view(THD *thd, TABLE_LIST *view, bool wrong_checksum,
if ((view->md5.str= (char *)thd->alloc(32 + 1)) == NULL)
DBUG_RETURN(HA_ADMIN_FAILED);
}
- view->calc_md5(view->md5.str);
+ view->calc_md5(const_cast<char*>(view->md5.str));
view->md5.length= 32;
}
view->mariadb_version= MYSQL_VERSION_ID;
diff --git a/sql/table.cc b/sql/table.cc
index 2197fa9dd7b..91a94238514 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -5532,12 +5532,12 @@ void TABLE::reset_item_list(List<Item> *item_list, uint skip) const
buffer buffer for md5 writing
*/
-void TABLE_LIST::calc_md5(const char *buffer)
+void TABLE_LIST::calc_md5(char *buffer)
{
uchar digest[16];
compute_md5_hash(digest, select_stmt.str,
select_stmt.length);
- sprintf((char *) buffer,
+ sprintf(buffer,
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
digest[0], digest[1], digest[2], digest[3],
digest[4], digest[5], digest[6], digest[7],
diff --git a/sql/table.h b/sql/table.h
index d063a3f27be..31b25e7de61 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -2625,7 +2625,7 @@ struct TABLE_LIST
List<String> *partition_names;
#endif /* WITH_PARTITION_STORAGE_ENGINE */
- void calc_md5(const char *buffer);
+ void calc_md5(char *buffer);
int view_check_option(THD *thd, bool ignore_failure);
bool create_field_translation(THD *thd);
bool setup_underlying(THD *thd);