Skip to content

Commit 23047d3

Browse files
committed
Merge 10.4 into 10.5
2 parents f86d97c + faf6d0e commit 23047d3

File tree

89 files changed

+1906
-873
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1906
-873
lines changed

client/mysql.cc

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ extern "C" {
9292
#include <conio.h>
9393
#else
9494
#include <readline.h>
95+
#if !defined(USE_LIBEDIT_INTERFACE)
96+
#include <history.h>
97+
#endif
9598
#define HAVE_READLINE
9699
#define USE_POPEN
97100
#endif
@@ -1043,22 +1046,6 @@ static const char *embedded_server_groups[]=
10431046
{ "server", "embedded", "mysql_SERVER", "mariadb_SERVER", 0 };
10441047

10451048
#ifdef HAVE_READLINE
1046-
/*
1047-
HIST_ENTRY is defined for libedit, but not for the real readline
1048-
Need to redefine it for real readline to find it
1049-
*/
1050-
#if !defined(HAVE_HIST_ENTRY)
1051-
typedef struct _hist_entry {
1052-
const char *line;
1053-
const char *data;
1054-
} HIST_ENTRY;
1055-
#endif
1056-
1057-
extern "C" int add_history(const char *command); /* From readline directory */
1058-
extern "C" int read_history(const char *command);
1059-
extern "C" int write_history(const char *command);
1060-
extern "C" HIST_ENTRY *history_get(int num);
1061-
extern "C" int history_length;
10621049
static int not_in_history(const char *line);
10631050
static void initialize_readline ();
10641051
static void fix_history(String *final_command);

client/mysqltest.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,9 +587,10 @@ ATTRIBUTE_NORETURN
587587
static void cleanup_and_exit(int exit_code);
588588

589589
ATTRIBUTE_NORETURN
590-
void really_die(const char *msg);
590+
static void really_die(const char *msg);
591591
void report_or_die(const char *fmt, ...);
592-
ATTRIBUTE_NORETURN void die(const char *fmt, ...);
592+
ATTRIBUTE_NORETURN
593+
static void die(const char *fmt, ...);
593594
static void make_error_message(char *buf, size_t len, const char *fmt, va_list args);
594595
ATTRIBUTE_NORETURN ATTRIBUTE_FORMAT(printf, 1, 2)
595596
void abort_not_supported_test(const char *fmt, ...);
@@ -1540,7 +1541,7 @@ static void make_error_message(char *buf, size_t len, const char *fmt, va_list a
15401541
s+= my_snprintf(s, end -s, "\n");
15411542
}
15421543

1543-
void die(const char *fmt, ...)
1544+
static void die(const char *fmt, ...)
15441545
{
15451546
char buff[DIE_BUFF_SIZE];
15461547
va_list args;
@@ -1549,7 +1550,7 @@ void die(const char *fmt, ...)
15491550
really_die(buff);
15501551
}
15511552

1552-
void really_die(const char *msg)
1553+
static void really_die(const char *msg)
15531554
{
15541555
static int dying= 0;
15551556
fflush(stdout);

include/my_atomic.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define MY_ATOMIC_INCLUDED
33

44
/* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
5+
Copyright (c) 2018, 2020, MariaDB
56
67
This program is free software; you can redistribute it and/or modify
78
it under the terms of the GNU General Public License as published by
@@ -169,4 +170,48 @@
169170
my_atomic_casptr((P), (E), (D))
170171
#endif
171172

173+
#ifdef __cplusplus
174+
#include <atomic>
175+
/**
176+
A wrapper for std::atomic, defaulting to std::memory_order_relaxed.
177+
178+
When it comes to atomic loads or stores at std::memory_order_relaxed
179+
on IA-32 or AMD64, this wrapper is only introducing some constraints
180+
to the C++ compiler, to prevent some optimizations of loads or
181+
stores.
182+
183+
On POWER and ARM, atomic loads and stores involve different instructions
184+
from normal loads and stores and will thus incur some overhead.
185+
186+
Because atomic read-modify-write operations will always incur
187+
overhead, we intentionally do not define
188+
operator++(), operator--(), operator+=(), operator-=(), or similar,
189+
to make the overhead stand out in the users of this code.
190+
*/
191+
template <typename Type> class Atomic_relaxed
192+
{
193+
std::atomic<Type> m;
194+
public:
195+
Atomic_relaxed(const Atomic_relaxed<Type> &rhs)
196+
{ m.store(rhs, std::memory_order_relaxed); }
197+
Atomic_relaxed(Type val) : m(val) {}
198+
Atomic_relaxed() {}
199+
200+
operator Type() const { return m.load(std::memory_order_relaxed); }
201+
Type operator=(const Type val)
202+
{ m.store(val, std::memory_order_relaxed); return val; }
203+
Type operator=(const Atomic_relaxed<Type> &rhs) { return *this= Type{rhs}; }
204+
Type fetch_add(const Type i, std::memory_order o= std::memory_order_relaxed)
205+
{ return m.fetch_add(i, o); }
206+
Type fetch_sub(const Type i, std::memory_order o= std::memory_order_relaxed)
207+
{ return m.fetch_sub(i, o); }
208+
bool compare_exchange_strong(Type& i1, const Type i2,
209+
std::memory_order o1= std::memory_order_relaxed,
210+
std::memory_order o2= std::memory_order_relaxed)
211+
{ return m.compare_exchange_strong(i1, i2, o1, o2); }
212+
Type exchange(const Type i, std::memory_order o= std::memory_order_relaxed)
213+
{ return m.exchange(i, o); }
214+
};
215+
#endif /* __cplusplus */
216+
172217
#endif /* MY_ATOMIC_INCLUDED */

include/my_valgrind.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#if defined(HAVE_VALGRIND_MEMCHECK_H) && defined(HAVE_valgrind)
3434
# include <valgrind/memcheck.h>
35+
# define HAVE_valgrind_or_MSAN
3536
# define MEM_UNDEFINED(a,len) VALGRIND_MAKE_MEM_UNDEFINED(a,len)
3637
# define MEM_MAKE_DEFINED(a,len) VALGRIND_MAKE_MEM_DEFINED(a,len)
3738
# define MEM_NOACCESS(a,len) VALGRIND_MAKE_MEM_NOACCESS(a,len)
@@ -50,6 +51,7 @@
5051
# define REDZONE_SIZE 8
5152
#elif __has_feature(memory_sanitizer)
5253
# include <sanitizer/msan_interface.h>
54+
# define HAVE_valgrind_or_MSAN
5355
# define MEM_UNDEFINED(a,len) __msan_allocated_memory(a,len)
5456
# define MEM_MAKE_DEFINED(a,len) __msan_unpoison(a,len)
5557
# define MEM_NOACCESS(a,len) ((void) 0)
@@ -65,16 +67,19 @@
6567
# define REDZONE_SIZE 0
6668
#endif /* HAVE_VALGRIND_MEMCHECK_H */
6769

68-
#if defined(TRASH_FREED_MEMORY)
69-
/* NOTE: Do not invoke TRASH_FILL directly! Use TRASH_ALLOC or TRASH_FREE.
70-
71-
The MEM_UNDEFINED() call before memset() is for canceling the effect
72-
of any previous MEM_NOACCESS(). We must invoke MEM_UNDEFINED() after
73-
writing the dummy pattern, unless MEM_NOACCESS() is going to be invoked.
74-
On AddressSanitizer, the MEM_UNDEFINED() in TRASH_ALLOC() has no effect. */
70+
#ifdef TRASH_FREED_MEMORY
71+
/*
72+
TRASH_FILL() has to call MEM_UNDEFINED() to cancel any effect of TRASH_FREE().
73+
This can happen in the case one does
74+
TRASH_ALLOC(A,B) ; TRASH_FREE(A,B) ; TRASH_ALLOC(A,B)
75+
to reuse the same memory in an internal memory allocator like MEM_ROOT.
76+
For my_malloc() and safemalloc() the extra MEM_UNDEFINED is bit of an
77+
overkill.
78+
TRASH_FILL() is an internal function and should not be used externally.
79+
*/
7580
#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)
7681
#else
77-
#define TRASH_FILL(A,B,C) while (0)
82+
#define TRASH_FILL(A,B,C) do { MEM_UNDEFINED((A), (B)); } while (0)
7883
#endif
7984
/** Note that some memory became allocated or uninitialized. */
8085
#define TRASH_ALLOC(A,B) do { TRASH_FILL(A,B,0xA5); MEM_UNDEFINED(A,B); } while(0)

include/span.h

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,33 @@ this program; if not, write to the Free Software Foundation, Inc.,
2424
namespace st_
2525
{
2626

27+
namespace detail
28+
{
29+
30+
template <class T> struct remove_cv
31+
{
32+
typedef T type;
33+
};
34+
template <class T> struct remove_cv<const T>
35+
{
36+
typedef T type;
37+
};
38+
template <class T> struct remove_cv<volatile T>
39+
{
40+
typedef T type;
41+
};
42+
template <class T> struct remove_cv<const volatile T>
43+
{
44+
typedef T type;
45+
};
46+
47+
} // namespace detail
48+
2749
template <class ElementType> class span
2850
{
2951
public:
3052
typedef ElementType element_type;
31-
typedef ElementType value_type;
53+
typedef typename detail::remove_cv<ElementType>::type value_type;
3254
typedef size_t size_type;
3355
typedef ptrdiff_t difference_type;
3456
typedef element_type *pointer;
@@ -38,7 +60,6 @@ template <class ElementType> class span
3860
typedef pointer iterator;
3961
typedef const_pointer const_iterator;
4062
typedef std::reverse_iterator<iterator> reverse_iterator;
41-
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
4263

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

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

6586
span &operator=(const span &other)
6687
{
67-
data_= other.data_;
68-
size_= other.size_;
88+
data_= other.data();
89+
size_= other.size();
6990
return *this;
7091
}
7192

7293
template <size_t Count> span<element_type> first() const
7394
{
7495
assert(!empty());
75-
return span(data_, 1);
96+
return span(data(), 1);
7697
}
7798
template <size_t Count> span<element_type> last() const
7899
{
79100
assert(!empty());
80-
return span(data_ + size() - 1, 1);
101+
return span(data() + size() - 1, 1);
81102
}
82103

83104
span<element_type> first(size_type count) const
84105
{
85106
assert(!empty());
86-
return span(data_, 1);
107+
return span(data(), 1);
87108
}
88109
span<element_type> last(size_type count) const
89110
{
90111
assert(!empty());
91-
return span(data_ + size() - 1, 1);
112+
return span(data() + size() - 1, 1);
92113
}
93114
span<element_type> subspan(size_type offset, size_type count) const
94115
{
95116
assert(!empty());
96117
assert(size() >= offset + count);
97-
return span(data_ + offset, count);
118+
return span(data() + offset, count);
98119
}
99120

100121
size_type size() const { return size_; }
101-
size_type size_bytes() const { return size_ * sizeof(ElementType); }
102-
bool empty() const __attribute__((warn_unused_result)) { return size_ == 0; }
122+
size_type size_bytes() const { return size() * sizeof(ElementType); }
123+
bool empty() const __attribute__((warn_unused_result))
124+
{
125+
return size() == 0;
126+
}
103127

104128
reference operator[](size_type idx) const
105129
{
106130
assert(size() > idx);
107-
return data_[idx];
131+
return data()[idx];
108132
}
109133
reference front() const
110134
{
111135
assert(!empty());
112-
return data_[0];
136+
return data()[0];
113137
}
114138
reference back() const
115139
{
116140
assert(!empty());
117-
return data_[size() - 1];
118-
}
119-
pointer data() const
120-
{
121-
assert(!empty());
122-
return data_;
141+
return data()[size() - 1];
123142
}
143+
pointer data() const { return data_; }
124144

125145
iterator begin() const { return data_; }
126146
iterator end() const { return data_ + size_; }
127147
reverse_iterator rbegin() const
128148
{
129-
return std::reverse_iterator<iterator>(std::advance(end(), -1));
149+
return std::reverse_iterator<iterator>(end());
130150
}
131151
reverse_iterator rend() const
132152
{
133-
return std::reverse_iterator<iterator>(std::advance(begin(), -1));
153+
return std::reverse_iterator<iterator>(begin());
134154
}
135155

136156
private:

libmariadb

mysql-test/main/custom_aggregate_functions.result

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,41 @@ NULL 8
11541154
drop function agg_sum;
11551155
drop table t1;
11561156
#
1157+
# User defined aggregate functions not working correctly when the schema is changed
1158+
#
1159+
CREATE SCHEMA IF NOT EXISTS common_schema;
1160+
CREATE SCHEMA IF NOT EXISTS another_schema;
1161+
DROP FUNCTION IF EXISTS common_schema.add_ints |
1162+
Warnings:
1163+
Note 1305 FUNCTION common_schema.add_ints does not exist
1164+
CREATE FUNCTION common_schema.add_ints(int_1 INT, int_2 INT) RETURNS INT NO SQL
1165+
BEGIN
1166+
RETURN int_1 + int_2;
1167+
END |
1168+
DROP FUNCTION IF EXISTS common_schema.sum_ints |
1169+
Warnings:
1170+
Note 1305 FUNCTION common_schema.sum_ints does not exist
1171+
CREATE AGGREGATE FUNCTION common_schema.sum_ints(int_val INT) RETURNS INT
1172+
BEGIN
1173+
DECLARE result INT DEFAULT 0;
1174+
DECLARE CONTINUE HANDLER FOR NOT FOUND RETURN result;
1175+
LOOP FETCH GROUP NEXT ROW;
1176+
SET result = common_schema.add_ints(result, int_val);
1177+
END LOOP;
1178+
END |
1179+
use common_schema;
1180+
SELECT common_schema.sum_ints(seq) FROM (SELECT 1 seq UNION ALL SELECT 2) t;
1181+
common_schema.sum_ints(seq)
1182+
3
1183+
USE another_schema;
1184+
SELECT common_schema.sum_ints(seq) FROM (SELECT 1 seq UNION ALL SELECT 2) t;
1185+
common_schema.sum_ints(seq)
1186+
3
1187+
drop database common_schema;
1188+
drop database another_schema;
1189+
USE test;
1190+
# End of 10.3 tests
1191+
#
11571192
# MDEV-18813 PROCEDURE and anonymous blocks silently ignore FETCH GROUP NEXT ROW
11581193
#
11591194
CREATE PROCEDURE p1()
@@ -1186,3 +1221,4 @@ STARTS CURRENT_TIMESTAMP + INTERVAL 1 MONTH
11861221
ENDS CURRENT_TIMESTAMP + INTERVAL 1 MONTH + INTERVAL 1 WEEK
11871222
DO FETCH GROUP NEXT ROW;
11881223
ERROR HY000: Aggregate specific instruction (FETCH GROUP NEXT ROW) used in a wrong context
1224+
# End of 10.4 tests

mysql-test/main/custom_aggregate_functions.test

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,42 @@ select i, sum(i) from t1 group by i with rollup;
966966
drop function agg_sum;
967967
drop table t1;
968968

969+
--echo #
970+
--echo # User defined aggregate functions not working correctly when the schema is changed
971+
--echo #
972+
973+
CREATE SCHEMA IF NOT EXISTS common_schema;
974+
CREATE SCHEMA IF NOT EXISTS another_schema;
975+
DELIMITER |;
976+
DROP FUNCTION IF EXISTS common_schema.add_ints |
977+
CREATE FUNCTION common_schema.add_ints(int_1 INT, int_2 INT) RETURNS INT NO SQL
978+
BEGIN
979+
RETURN int_1 + int_2;
980+
END |
981+
DROP FUNCTION IF EXISTS common_schema.sum_ints |
982+
CREATE AGGREGATE FUNCTION common_schema.sum_ints(int_val INT) RETURNS INT
983+
BEGIN
984+
DECLARE result INT DEFAULT 0;
985+
DECLARE CONTINUE HANDLER FOR NOT FOUND RETURN result;
986+
LOOP FETCH GROUP NEXT ROW;
987+
SET result = common_schema.add_ints(result, int_val);
988+
END LOOP;
989+
END |
990+
991+
DELIMITER ;|
992+
993+
use common_schema;
994+
SELECT common_schema.sum_ints(seq) FROM (SELECT 1 seq UNION ALL SELECT 2) t;
995+
996+
USE another_schema;
997+
SELECT common_schema.sum_ints(seq) FROM (SELECT 1 seq UNION ALL SELECT 2) t;
998+
999+
drop database common_schema;
1000+
drop database another_schema;
1001+
1002+
USE test;
1003+
1004+
--echo # End of 10.3 tests
9691005

9701006
--echo #
9711007
--echo # MDEV-18813 PROCEDURE and anonymous blocks silently ignore FETCH GROUP NEXT ROW
@@ -1016,3 +1052,5 @@ CREATE EVENT ev1
10161052
STARTS CURRENT_TIMESTAMP + INTERVAL 1 MONTH
10171053
ENDS CURRENT_TIMESTAMP + INTERVAL 1 MONTH + INTERVAL 1 WEEK
10181054
DO FETCH GROUP NEXT ROW;
1055+
1056+
--echo # End of 10.4 tests

0 commit comments

Comments
 (0)