Skip to content

Commit dad7a8e

Browse files
committed
Merge 10.2 into 10.3
2 parents 7476e8c + 5139cfa commit dad7a8e

30 files changed

+1257
-120
lines changed

include/intrusive_list.h renamed to include/ilist.h

Lines changed: 77 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,28 @@
2121
#include <cstddef>
2222
#include <iterator>
2323

24-
namespace intrusive
25-
{
26-
2724
// Derive your class from this struct to insert to a linked list.
28-
template <class Tag= void> struct list_node
25+
template <class Tag= void> struct ilist_node
2926
{
30-
list_node(list_node *next= NULL, list_node *prev= NULL)
31-
: next(next), prev(prev)
27+
ilist_node()
28+
#ifndef DBUG_OFF
29+
:
30+
next(NULL), prev(NULL)
31+
#endif
3232
{
3333
}
3434

35-
list_node *next;
36-
list_node *prev;
35+
ilist_node(ilist_node *next, ilist_node *prev) : next(next), prev(prev) {}
36+
37+
ilist_node *next;
38+
ilist_node *prev;
3739
};
3840

3941
// Modelled after std::list<T>
40-
template <class T, class Tag= void> class list
42+
template <class T, class Tag= void> class ilist
4143
{
4244
public:
43-
typedef list_node<Tag> ListNode;
45+
typedef ilist_node<Tag> ListNode;
4446
class Iterator;
4547

4648
// All containers in C++ should define these types to implement generic
@@ -103,10 +105,10 @@ template <class T, class Tag= void> class list
103105
private:
104106
ListNode *node_;
105107

106-
friend class list;
108+
friend class ilist;
107109
};
108110

109-
list() : sentinel_(&sentinel_, &sentinel_), size_(0) {}
111+
ilist() : sentinel_(&sentinel_, &sentinel_) {}
110112

111113
reference front() { return *begin(); }
112114
reference back() { return *--end(); }
@@ -129,14 +131,18 @@ template <class T, class Tag= void> class list
129131
reverse_iterator rend() { return reverse_iterator(begin()); }
130132
const_reverse_iterator rend() const { return reverse_iterator(begin()); }
131133

132-
bool empty() const { return size_ == 0; }
133-
size_type size() const { return size_; }
134+
bool empty() const { return sentinel_.next == &sentinel_; }
135+
136+
// Not implemented because it's O(N)
137+
// size_type size() const
138+
// {
139+
// return static_cast<size_type>(std::distance(begin(), end()));
140+
// }
134141

135142
void clear()
136143
{
137144
sentinel_.next= &sentinel_;
138145
sentinel_.prev= &sentinel_;
139-
size_= 0;
140146
}
141147

142148
iterator insert(iterator pos, reference value)
@@ -150,7 +156,6 @@ template <class T, class Tag= void> class list
150156
static_cast<ListNode &>(value).prev= prev;
151157
static_cast<ListNode &>(value).next= curr;
152158

153-
++size_;
154159
return iterator(&value);
155160
}
156161

@@ -162,13 +167,12 @@ template <class T, class Tag= void> class list
162167
prev->next= next;
163168
next->prev= prev;
164169

165-
// This is not required for list functioning. But maybe it'll prevent bugs
166-
// and ease debugging.
170+
#ifndef DBUG_OFF
167171
ListNode *curr= pos.node_;
168172
curr->prev= NULL;
169173
curr->next= NULL;
174+
#endif
170175

171-
--size_;
172176
return next;
173177
}
174178

@@ -179,12 +183,63 @@ template <class T, class Tag= void> class list
179183
void pop_front() { erase(begin()); }
180184

181185
// STL version is O(n) but this is O(1) because an element can't be inserted
182-
// several times in the same intrusive list.
186+
// several times in the same ilist.
183187
void remove(reference value) { erase(iterator(&value)); }
184188

185189
private:
186190
ListNode sentinel_;
187-
size_type size_;
188191
};
189192

190-
} // namespace intrusive
193+
// Similar to ilist but also has O(1) size() method.
194+
template <class T, class Tag= void> class sized_ilist : public ilist<T, Tag>
195+
{
196+
typedef ilist<T, Tag> BASE;
197+
198+
public:
199+
// All containers in C++ should define these types to implement generic
200+
// container interface.
201+
typedef T value_type;
202+
typedef std::size_t size_type;
203+
typedef std::ptrdiff_t difference_type;
204+
typedef value_type &reference;
205+
typedef const value_type &const_reference;
206+
typedef T *pointer;
207+
typedef const T *const_pointer;
208+
typedef typename BASE::Iterator iterator;
209+
typedef const typename BASE::Iterator const_iterator;
210+
typedef std::reverse_iterator<iterator> reverse_iterator;
211+
typedef std::reverse_iterator<const iterator> const_reverse_iterator;
212+
213+
sized_ilist() : size_(0) {}
214+
215+
size_type size() const { return size_; }
216+
217+
void clear()
218+
{
219+
BASE::clear();
220+
size_= 0;
221+
}
222+
223+
iterator insert(iterator pos, reference value)
224+
{
225+
++size_;
226+
return BASE::insert(pos, value);
227+
}
228+
229+
iterator erase(iterator pos)
230+
{
231+
--size_;
232+
return BASE::erase(pos);
233+
}
234+
235+
void push_back(reference value) { insert(BASE::end(), value); }
236+
void pop_back() { erase(BASE::end()); }
237+
238+
void push_front(reference value) { insert(BASE::begin(), value); }
239+
void pop_front() { erase(BASE::begin()); }
240+
241+
void remove(reference value) { erase(iterator(&value)); }
242+
243+
private:
244+
size_type size_;
245+
};

mysql-test/main/partition_alter.result

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,55 @@ t1 CREATE TABLE `t1` (
122122
PARTITION `p02` ENGINE = MyISAM,
123123
PARTITION `p03` ENGINE = MyISAM)
124124
drop table t1;
125-
create or replace table t1 (x int) partition by hash (x) (partition p1, partition p2);
125+
#
126+
# MDEV-19751 Wrong partitioning by KEY() after key dropped
127+
#
128+
create or replace table t1 (pk int, x timestamp(6), primary key (pk, x)) engine innodb
129+
partition by key() partitions 2;
130+
insert into t1 (pk, x) values (1, '2000-01-01 00:00'), (2, '2000-01-01 00:01');
131+
# Inplace for DROP PRIMARY KEY when partitioned by default field list is denied
132+
alter table t1 drop primary key, drop column x, add primary key (pk), algorithm=inplace;
133+
ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY
134+
alter table t1 drop primary key, drop column x, add primary key (pk);
135+
select * from t1 partition (p0);
136+
pk
137+
1
138+
drop table t1;
139+
create or replace table t1 (pk int not null, x timestamp(6), unique u(pk, x)) engine innodb
140+
partition by key() partitions 2;
141+
insert into t1 (pk, x) values (1, '2000-01-01 00:00'), (2, '2000-01-01 00:01');
142+
# Same for NOT NULL UNIQUE KEY as this is actually primary key
143+
alter table t1 drop key u, drop column x, add unique (pk), algorithm=inplace;
144+
ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY
145+
alter table t1 drop key u, drop column x, add unique (pk);
146+
select * from t1 partition (p0);
147+
pk
148+
1
149+
drop table t1;
150+
create or replace table t1 (pk int, x timestamp(6), primary key (pk)) engine innodb
151+
partition by key(pk) partitions 2;
152+
insert into t1 (pk, x) values (1, '2000-01-01 00:00'), (2, '2000-01-01 00:01');
153+
# Inplace for DROP PRIMARY KEY when partitioned by explicit field list is allowed
154+
alter table t1 drop primary key, add primary key (pk, x), algorithm=inplace;
155+
select * from t1 partition (p0);
156+
pk x
157+
1 2000-01-01 00:00:00.000000
158+
drop table t1;
159+
create or replace table t1 (k int, x timestamp(6), unique key u (x, k)) engine innodb
160+
partition by key(k) partitions 2;
161+
insert into t1 (k, x) values (1, '2000-01-01 00:00'), (2, '2000-01-01 00:01');
162+
# Inplace for DROP KEY is allowed
163+
alter table t1 drop key u, algorithm=inplace;
164+
select * from t1 partition (p0);
165+
k x
166+
1 2000-01-01 00:00:00.000000
167+
drop table t1;
168+
# End of 10.2 tests
169+
#
170+
# MDEV-14817 Server crashes in prep_alter_part_table()
171+
# after table lock and multiple add partition
172+
#
173+
create table t1 (x int) partition by hash (x) (partition p1, partition p2);
126174
lock table t1 write;
127175
alter table t1 add partition (partition p1);
128176
ERROR HY000: Duplicate partition name p1
@@ -134,7 +182,7 @@ drop table t1;
134182
# ha_partition::update_row or `part_id == m_last_part' in
135183
# ha_partition::delete_row upon UPDATE/DELETE after dropping versioning
136184
#
137-
create or replace table t1 (pk int, f int, primary key(pk, f)) engine=innodb
185+
create table t1 (pk int, f int, primary key(pk, f)) engine=innodb
138186
partition by key() partitions 2;
139187
insert into t1 values (1,10),(2,11);
140188
# expected to hit same partition
@@ -152,3 +200,4 @@ pk
152200
2
153201
delete from t1;
154202
drop table t1;
203+
# End of 10.3 tests

mysql-test/main/partition_alter.test

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,52 @@ alter online table t1 delay_key_write=1;
113113
show create table t1;
114114
drop table t1;
115115

116-
#
117-
# MDEV-14817 Server crashes in prep_alter_part_table() after table lock and multiple add partition
118-
#
119-
create or replace table t1 (x int) partition by hash (x) (partition p1, partition p2);
116+
--echo #
117+
--echo # MDEV-19751 Wrong partitioning by KEY() after key dropped
118+
--echo #
119+
create or replace table t1 (pk int, x timestamp(6), primary key (pk, x)) engine innodb
120+
partition by key() partitions 2;
121+
insert into t1 (pk, x) values (1, '2000-01-01 00:00'), (2, '2000-01-01 00:01');
122+
--echo # Inplace for DROP PRIMARY KEY when partitioned by default field list is denied
123+
--error ER_ALTER_OPERATION_NOT_SUPPORTED
124+
alter table t1 drop primary key, drop column x, add primary key (pk), algorithm=inplace;
125+
alter table t1 drop primary key, drop column x, add primary key (pk);
126+
select * from t1 partition (p0);
127+
drop table t1;
128+
129+
create or replace table t1 (pk int not null, x timestamp(6), unique u(pk, x)) engine innodb
130+
partition by key() partitions 2;
131+
insert into t1 (pk, x) values (1, '2000-01-01 00:00'), (2, '2000-01-01 00:01');
132+
--echo # Same for NOT NULL UNIQUE KEY as this is actually primary key
133+
--error ER_ALTER_OPERATION_NOT_SUPPORTED
134+
alter table t1 drop key u, drop column x, add unique (pk), algorithm=inplace;
135+
alter table t1 drop key u, drop column x, add unique (pk);
136+
select * from t1 partition (p0);
137+
drop table t1;
138+
139+
create or replace table t1 (pk int, x timestamp(6), primary key (pk)) engine innodb
140+
partition by key(pk) partitions 2;
141+
insert into t1 (pk, x) values (1, '2000-01-01 00:00'), (2, '2000-01-01 00:01');
142+
--echo # Inplace for DROP PRIMARY KEY when partitioned by explicit field list is allowed
143+
alter table t1 drop primary key, add primary key (pk, x), algorithm=inplace;
144+
select * from t1 partition (p0);
145+
drop table t1;
146+
147+
create or replace table t1 (k int, x timestamp(6), unique key u (x, k)) engine innodb
148+
partition by key(k) partitions 2;
149+
insert into t1 (k, x) values (1, '2000-01-01 00:00'), (2, '2000-01-01 00:01');
150+
--echo # Inplace for DROP KEY is allowed
151+
alter table t1 drop key u, algorithm=inplace;
152+
select * from t1 partition (p0);
153+
drop table t1;
154+
155+
--echo # End of 10.2 tests
156+
157+
--echo #
158+
--echo # MDEV-14817 Server crashes in prep_alter_part_table()
159+
--echo # after table lock and multiple add partition
160+
--echo #
161+
create table t1 (x int) partition by hash (x) (partition p1, partition p2);
120162
lock table t1 write;
121163
--error ER_SAME_NAME_PARTITION
122164
alter table t1 add partition (partition p1);
@@ -129,7 +171,7 @@ drop table t1;
129171
--echo # ha_partition::update_row or `part_id == m_last_part' in
130172
--echo # ha_partition::delete_row upon UPDATE/DELETE after dropping versioning
131173
--echo #
132-
create or replace table t1 (pk int, f int, primary key(pk, f)) engine=innodb
174+
create table t1 (pk int, f int, primary key(pk, f)) engine=innodb
133175
partition by key() partitions 2;
134176

135177
insert into t1 values (1,10),(2,11);
@@ -142,3 +184,5 @@ select * from t1 partition(p0);
142184
select * from t1 partition(p1);
143185
delete from t1;
144186
drop table t1;
187+
188+
--echo # End of 10.3 tests

mysql-test/main/processlist_notembedded.result

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ connection default;
88
SET DEBUG_SYNC= 'now WAIT_FOR in_sync';
99
FOUND 1 /sleep/ in MDEV-20466.text
1010
SET DEBUG_SYNC= 'now SIGNAL go';
11+
connection con1;
12+
user
1113
disconnect con1;
14+
connection default;
1215
SET DEBUG_SYNC = 'RESET';
1316
End of 5.5 tests

mysql-test/main/processlist_notembedded.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ remove_file $MYSQLTEST_VARDIR/tmp/MDEV-20466.text;
3030

3131
SET DEBUG_SYNC= 'now SIGNAL go';
3232

33+
connection con1;
34+
reap;
3335
disconnect con1;
36+
connection default;
3437

3538
SET DEBUG_SYNC = 'RESET';
3639

mysql-test/main/selectivity.result

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,5 +1871,20 @@ id select_type table type possible_keys key key_len ref rows Extra
18711871
set optimizer_switch= @save_optimizer_switch;
18721872
set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
18731873
drop table t1,t2;
1874+
#
1875+
# MDEV-21495: Conditional jump or move depends on uninitialised value in sel_arg_range_seq_next
1876+
#
1877+
CREATE TABLE t1(a INT, b INT);
1878+
INSERT INTO t1 SELECT seq, seq from seq_1_to_100;
1879+
set optimizer_use_condition_selectivity=4;
1880+
ANALYZE TABLE t1 PERSISTENT FOR ALL;
1881+
Table Op Msg_type Msg_text
1882+
test.t1 analyze status Engine-independent statistics collected
1883+
test.t1 analyze status OK
1884+
SELECT * from t1 WHERE a = 5 and b = 5;
1885+
a b
1886+
5 5
1887+
set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
1888+
drop table t1;
18741889
# End of 10.1 tests
18751890
set @@global.histogram_size=@save_histogram_size;

mysql-test/main/selectivity.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,18 @@ set optimizer_switch= @save_optimizer_switch;
12721272
set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
12731273
drop table t1,t2;
12741274

1275+
--echo #
1276+
--echo # MDEV-21495: Conditional jump or move depends on uninitialised value in sel_arg_range_seq_next
1277+
--echo #
1278+
1279+
CREATE TABLE t1(a INT, b INT);
1280+
INSERT INTO t1 SELECT seq, seq from seq_1_to_100;
1281+
set optimizer_use_condition_selectivity=4;
1282+
ANALYZE TABLE t1 PERSISTENT FOR ALL;
1283+
SELECT * from t1 WHERE a = 5 and b = 5;
1284+
set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
1285+
drop table t1;
1286+
12751287
--echo # End of 10.1 tests
12761288

12771289
#

mysql-test/main/selectivity_innodb.result

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,6 +1881,21 @@ id select_type table type possible_keys key key_len ref rows Extra
18811881
set optimizer_switch= @save_optimizer_switch;
18821882
set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
18831883
drop table t1,t2;
1884+
#
1885+
# MDEV-21495: Conditional jump or move depends on uninitialised value in sel_arg_range_seq_next
1886+
#
1887+
CREATE TABLE t1(a INT, b INT);
1888+
INSERT INTO t1 SELECT seq, seq from seq_1_to_100;
1889+
set optimizer_use_condition_selectivity=4;
1890+
ANALYZE TABLE t1 PERSISTENT FOR ALL;
1891+
Table Op Msg_type Msg_text
1892+
test.t1 analyze status Engine-independent statistics collected
1893+
test.t1 analyze status OK
1894+
SELECT * from t1 WHERE a = 5 and b = 5;
1895+
a b
1896+
5 5
1897+
set optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity;
1898+
drop table t1;
18841899
# End of 10.1 tests
18851900
set @@global.histogram_size=@save_histogram_size;
18861901
set optimizer_switch=@save_optimizer_switch_for_selectivity_test;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--skip-stack-trace --skip-core-file
2+
--default-storage-engine=Aria

0 commit comments

Comments
 (0)