Skip to content

Commit

Permalink
Merge 10.4 into 10.5
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-m committed May 18, 2020
2 parents f86d97c + faf6d0e commit 23047d3
Show file tree
Hide file tree
Showing 89 changed files with 1,906 additions and 873 deletions.
19 changes: 3 additions & 16 deletions client/mysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ extern "C" {
#include <conio.h>
#else
#include <readline.h>
#if !defined(USE_LIBEDIT_INTERFACE)
#include <history.h>
#endif
#define HAVE_READLINE
#define USE_POPEN
#endif
Expand Down Expand Up @@ -1043,22 +1046,6 @@ static const char *embedded_server_groups[]=
{ "server", "embedded", "mysql_SERVER", "mariadb_SERVER", 0 };

#ifdef HAVE_READLINE
/*
HIST_ENTRY is defined for libedit, but not for the real readline
Need to redefine it for real readline to find it
*/
#if !defined(HAVE_HIST_ENTRY)
typedef struct _hist_entry {
const char *line;
const char *data;
} HIST_ENTRY;
#endif

extern "C" int add_history(const char *command); /* From readline directory */
extern "C" int read_history(const char *command);
extern "C" int write_history(const char *command);
extern "C" HIST_ENTRY *history_get(int num);
extern "C" int history_length;
static int not_in_history(const char *line);
static void initialize_readline ();
static void fix_history(String *final_command);
Expand Down
9 changes: 5 additions & 4 deletions client/mysqltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -587,9 +587,10 @@ ATTRIBUTE_NORETURN
static void cleanup_and_exit(int exit_code);

ATTRIBUTE_NORETURN
void really_die(const char *msg);
static void really_die(const char *msg);
void report_or_die(const char *fmt, ...);
ATTRIBUTE_NORETURN void die(const char *fmt, ...);
ATTRIBUTE_NORETURN
static void die(const char *fmt, ...);
static void make_error_message(char *buf, size_t len, const char *fmt, va_list args);
ATTRIBUTE_NORETURN ATTRIBUTE_FORMAT(printf, 1, 2)
void abort_not_supported_test(const char *fmt, ...);
Expand Down Expand Up @@ -1540,7 +1541,7 @@ static void make_error_message(char *buf, size_t len, const char *fmt, va_list a
s+= my_snprintf(s, end -s, "\n");
}

void die(const char *fmt, ...)
static void die(const char *fmt, ...)
{
char buff[DIE_BUFF_SIZE];
va_list args;
Expand All @@ -1549,7 +1550,7 @@ void die(const char *fmt, ...)
really_die(buff);
}

void really_die(const char *msg)
static void really_die(const char *msg)
{
static int dying= 0;
fflush(stdout);
Expand Down
45 changes: 45 additions & 0 deletions include/my_atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define MY_ATOMIC_INCLUDED

/* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2018, 2020, 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
Expand Down Expand Up @@ -169,4 +170,48 @@
my_atomic_casptr((P), (E), (D))
#endif

#ifdef __cplusplus
#include <atomic>
/**
A wrapper for std::atomic, defaulting to std::memory_order_relaxed.
When it comes to atomic loads or stores at std::memory_order_relaxed
on IA-32 or AMD64, this wrapper is only introducing some constraints
to the C++ compiler, to prevent some optimizations of loads or
stores.
On POWER and ARM, atomic loads and stores involve different instructions
from normal loads and stores and will thus incur some overhead.
Because atomic read-modify-write operations will always incur
overhead, we intentionally do not define
operator++(), operator--(), operator+=(), operator-=(), or similar,
to make the overhead stand out in the users of this code.
*/
template <typename Type> class Atomic_relaxed
{
std::atomic<Type> m;
public:
Atomic_relaxed(const Atomic_relaxed<Type> &rhs)
{ m.store(rhs, std::memory_order_relaxed); }
Atomic_relaxed(Type val) : m(val) {}
Atomic_relaxed() {}

operator Type() const { return m.load(std::memory_order_relaxed); }
Type operator=(const Type val)
{ m.store(val, std::memory_order_relaxed); return val; }
Type operator=(const Atomic_relaxed<Type> &rhs) { return *this= Type{rhs}; }
Type fetch_add(const Type i, std::memory_order o= std::memory_order_relaxed)
{ return m.fetch_add(i, o); }
Type fetch_sub(const Type i, std::memory_order o= std::memory_order_relaxed)
{ return m.fetch_sub(i, o); }
bool compare_exchange_strong(Type& i1, const Type i2,
std::memory_order o1= std::memory_order_relaxed,
std::memory_order o2= std::memory_order_relaxed)
{ return m.compare_exchange_strong(i1, i2, o1, o2); }
Type exchange(const Type i, std::memory_order o= std::memory_order_relaxed)
{ return m.exchange(i, o); }
};
#endif /* __cplusplus */

#endif /* MY_ATOMIC_INCLUDED */
21 changes: 13 additions & 8 deletions include/my_valgrind.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#if defined(HAVE_VALGRIND_MEMCHECK_H) && defined(HAVE_valgrind)
# include <valgrind/memcheck.h>
# define HAVE_valgrind_or_MSAN
# define MEM_UNDEFINED(a,len) VALGRIND_MAKE_MEM_UNDEFINED(a,len)
# define MEM_MAKE_DEFINED(a,len) VALGRIND_MAKE_MEM_DEFINED(a,len)
# define MEM_NOACCESS(a,len) VALGRIND_MAKE_MEM_NOACCESS(a,len)
Expand All @@ -50,6 +51,7 @@
# define REDZONE_SIZE 8
#elif __has_feature(memory_sanitizer)
# include <sanitizer/msan_interface.h>
# define HAVE_valgrind_or_MSAN
# define MEM_UNDEFINED(a,len) __msan_allocated_memory(a,len)
# define MEM_MAKE_DEFINED(a,len) __msan_unpoison(a,len)
# define MEM_NOACCESS(a,len) ((void) 0)
Expand All @@ -65,16 +67,19 @@
# define REDZONE_SIZE 0
#endif /* HAVE_VALGRIND_MEMCHECK_H */

#if defined(TRASH_FREED_MEMORY)
/* NOTE: Do not invoke TRASH_FILL directly! Use TRASH_ALLOC or TRASH_FREE.
The MEM_UNDEFINED() call before memset() is for canceling the effect
of any previous MEM_NOACCESS(). We must invoke MEM_UNDEFINED() after
writing the dummy pattern, unless MEM_NOACCESS() is going to be invoked.
On AddressSanitizer, the MEM_UNDEFINED() in TRASH_ALLOC() has no effect. */
#ifdef TRASH_FREED_MEMORY
/*
TRASH_FILL() has to call MEM_UNDEFINED() to cancel any effect of TRASH_FREE().
This can happen in the case one does
TRASH_ALLOC(A,B) ; TRASH_FREE(A,B) ; TRASH_ALLOC(A,B)
to reuse the same memory in an internal memory allocator like MEM_ROOT.
For my_malloc() and safemalloc() the extra MEM_UNDEFINED is bit of an
overkill.
TRASH_FILL() is an internal function and should not be used externally.
*/
#define TRASH_FILL(A,B,C) do { const size_t trash_tmp= (B); MEM_UNDEFINED(A, trash_tmp); memset(A, C, trash_tmp); } while (0)
#else
#define TRASH_FILL(A,B,C) while (0)
#define TRASH_FILL(A,B,C) do { MEM_UNDEFINED((A), (B)); } while (0)
#endif
/** Note that some memory became allocated or uninitialized. */
#define TRASH_ALLOC(A,B) do { TRASH_FILL(A,B,0xA5); MEM_UNDEFINED(A,B); } while(0)
Expand Down
62 changes: 41 additions & 21 deletions include/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,33 @@ this program; if not, write to the Free Software Foundation, Inc.,
namespace st_
{

namespace detail
{

template <class T> struct remove_cv
{
typedef T type;
};
template <class T> struct remove_cv<const T>
{
typedef T type;
};
template <class T> struct remove_cv<volatile T>
{
typedef T type;
};
template <class T> struct remove_cv<const volatile T>
{
typedef T type;
};

} // namespace detail

template <class ElementType> class span
{
public:
typedef ElementType element_type;
typedef ElementType value_type;
typedef typename detail::remove_cv<ElementType>::type value_type;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef element_type *pointer;
Expand All @@ -38,7 +60,6 @@ template <class ElementType> class span
typedef pointer iterator;
typedef const_pointer const_iterator;
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;

span() : data_(NULL), size_(0) {}

Expand All @@ -64,73 +85,72 @@ template <class ElementType> class span

span &operator=(const span &other)
{
data_= other.data_;
size_= other.size_;
data_= other.data();
size_= other.size();
return *this;
}

template <size_t Count> span<element_type> first() const
{
assert(!empty());
return span(data_, 1);
return span(data(), 1);
}
template <size_t Count> span<element_type> last() const
{
assert(!empty());
return span(data_ + size() - 1, 1);
return span(data() + size() - 1, 1);
}

span<element_type> first(size_type count) const
{
assert(!empty());
return span(data_, 1);
return span(data(), 1);
}
span<element_type> last(size_type count) const
{
assert(!empty());
return span(data_ + size() - 1, 1);
return span(data() + size() - 1, 1);
}
span<element_type> subspan(size_type offset, size_type count) const
{
assert(!empty());
assert(size() >= offset + count);
return span(data_ + offset, count);
return span(data() + offset, count);
}

size_type size() const { return size_; }
size_type size_bytes() const { return size_ * sizeof(ElementType); }
bool empty() const __attribute__((warn_unused_result)) { return size_ == 0; }
size_type size_bytes() const { return size() * sizeof(ElementType); }
bool empty() const __attribute__((warn_unused_result))
{
return size() == 0;
}

reference operator[](size_type idx) const
{
assert(size() > idx);
return data_[idx];
return data()[idx];
}
reference front() const
{
assert(!empty());
return data_[0];
return data()[0];
}
reference back() const
{
assert(!empty());
return data_[size() - 1];
}
pointer data() const
{
assert(!empty());
return data_;
return data()[size() - 1];
}
pointer data() const { return data_; }

iterator begin() const { return data_; }
iterator end() const { return data_ + size_; }
reverse_iterator rbegin() const
{
return std::reverse_iterator<iterator>(std::advance(end(), -1));
return std::reverse_iterator<iterator>(end());
}
reverse_iterator rend() const
{
return std::reverse_iterator<iterator>(std::advance(begin(), -1));
return std::reverse_iterator<iterator>(begin());
}

private:
Expand Down
2 changes: 1 addition & 1 deletion libmariadb
36 changes: 36 additions & 0 deletions mysql-test/main/custom_aggregate_functions.result
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,41 @@ NULL 8
drop function agg_sum;
drop table t1;
#
# User defined aggregate functions not working correctly when the schema is changed
#
CREATE SCHEMA IF NOT EXISTS common_schema;
CREATE SCHEMA IF NOT EXISTS another_schema;
DROP FUNCTION IF EXISTS common_schema.add_ints |
Warnings:
Note 1305 FUNCTION common_schema.add_ints does not exist
CREATE FUNCTION common_schema.add_ints(int_1 INT, int_2 INT) RETURNS INT NO SQL
BEGIN
RETURN int_1 + int_2;
END |
DROP FUNCTION IF EXISTS common_schema.sum_ints |
Warnings:
Note 1305 FUNCTION common_schema.sum_ints does not exist
CREATE AGGREGATE FUNCTION common_schema.sum_ints(int_val INT) RETURNS INT
BEGIN
DECLARE result INT DEFAULT 0;
DECLARE CONTINUE HANDLER FOR NOT FOUND RETURN result;
LOOP FETCH GROUP NEXT ROW;
SET result = common_schema.add_ints(result, int_val);
END LOOP;
END |
use common_schema;
SELECT common_schema.sum_ints(seq) FROM (SELECT 1 seq UNION ALL SELECT 2) t;
common_schema.sum_ints(seq)
3
USE another_schema;
SELECT common_schema.sum_ints(seq) FROM (SELECT 1 seq UNION ALL SELECT 2) t;
common_schema.sum_ints(seq)
3
drop database common_schema;
drop database another_schema;
USE test;
# End of 10.3 tests
#
# MDEV-18813 PROCEDURE and anonymous blocks silently ignore FETCH GROUP NEXT ROW
#
CREATE PROCEDURE p1()
Expand Down Expand Up @@ -1186,3 +1221,4 @@ STARTS CURRENT_TIMESTAMP + INTERVAL 1 MONTH
ENDS CURRENT_TIMESTAMP + INTERVAL 1 MONTH + INTERVAL 1 WEEK
DO FETCH GROUP NEXT ROW;
ERROR HY000: Aggregate specific instruction (FETCH GROUP NEXT ROW) used in a wrong context
# End of 10.4 tests
38 changes: 38 additions & 0 deletions mysql-test/main/custom_aggregate_functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,42 @@ select i, sum(i) from t1 group by i with rollup;
drop function agg_sum;
drop table t1;

--echo #
--echo # User defined aggregate functions not working correctly when the schema is changed
--echo #

CREATE SCHEMA IF NOT EXISTS common_schema;
CREATE SCHEMA IF NOT EXISTS another_schema;
DELIMITER |;
DROP FUNCTION IF EXISTS common_schema.add_ints |
CREATE FUNCTION common_schema.add_ints(int_1 INT, int_2 INT) RETURNS INT NO SQL
BEGIN
RETURN int_1 + int_2;
END |
DROP FUNCTION IF EXISTS common_schema.sum_ints |
CREATE AGGREGATE FUNCTION common_schema.sum_ints(int_val INT) RETURNS INT
BEGIN
DECLARE result INT DEFAULT 0;
DECLARE CONTINUE HANDLER FOR NOT FOUND RETURN result;
LOOP FETCH GROUP NEXT ROW;
SET result = common_schema.add_ints(result, int_val);
END LOOP;
END |

DELIMITER ;|

use common_schema;
SELECT common_schema.sum_ints(seq) FROM (SELECT 1 seq UNION ALL SELECT 2) t;

USE another_schema;
SELECT common_schema.sum_ints(seq) FROM (SELECT 1 seq UNION ALL SELECT 2) t;

drop database common_schema;
drop database another_schema;

USE test;

--echo # End of 10.3 tests

--echo #
--echo # MDEV-18813 PROCEDURE and anonymous blocks silently ignore FETCH GROUP NEXT ROW
Expand Down Expand Up @@ -1016,3 +1052,5 @@ CREATE EVENT ev1
STARTS CURRENT_TIMESTAMP + INTERVAL 1 MONTH
ENDS CURRENT_TIMESTAMP + INTERVAL 1 MONTH + INTERVAL 1 WEEK
DO FETCH GROUP NEXT ROW;

--echo # End of 10.4 tests
Loading

0 comments on commit 23047d3

Please sign in to comment.