Skip to content

Commit 340feb0

Browse files
committed
Merge mariadb-10.3.27 into 10.3
2 parents bafbfb5 + dba846c commit 340feb0

File tree

6 files changed

+143
-15
lines changed

6 files changed

+143
-15
lines changed

mysql-test/main/range.result

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ SELECT * FROM t1 WHERE
12511251
5 <= a AND b = 3 OR
12521252
3 <= a;
12531253
id select_type table type possible_keys key key_len ref rows Extra
1254-
1 SIMPLE t1 range a a 5 NULL 3 Using where; Using index
1254+
1 SIMPLE t1 range a a 5 NULL 4 Using where; Using index
12551255
SELECT * FROM t1 WHERE
12561256
3 <= a AND a <= 5 OR
12571257
5 <= a AND b = 3 OR
@@ -3033,6 +3033,39 @@ a b
30333033
set eq_range_index_dive_limit=default;
30343034
drop table t1;
30353035
#
3036+
# MDEV-24117: Memory management problem in statistics state...
3037+
# (just the testcase)
3038+
#
3039+
create table t0(a int);
3040+
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
3041+
create table t1(a int);
3042+
insert into t1
3043+
select A.a + B.a* 10 + C.a * 100 + D.a * 1000
3044+
from t0 A, t0 B, t0 C, t0 D
3045+
where D.a<4;
3046+
create table t2 (
3047+
a int,
3048+
b int,
3049+
key(a)
3050+
);
3051+
insert into t2 values (1,1),(2,2),(3,3);
3052+
set @query=(select group_concat(a) from t1);
3053+
set @tmp_24117= @@max_session_mem_used;
3054+
#
3055+
# On debug build, the usage was
3056+
# - 2.8M without the bug
3057+
# - 1G with the bug.
3058+
set max_session_mem_used=64*1024*1024;
3059+
set @query=concat('explain select * from t2 where a=1 or a in (', @query, ')');
3060+
prepare s from @query;
3061+
# This should not fail with an error:
3062+
execute s;
3063+
id select_type table type possible_keys key key_len ref rows Extra
3064+
1 SIMPLE t2 ALL a NULL NULL NULL 3 Using where
3065+
set max_session_mem_used=@tmp_24117;
3066+
deallocate prepare s;
3067+
drop table t0,t1,t2;
3068+
#
30363069
# MDEV-23811: Both disjunct of WHERE condition contain range conditions
30373070
# for the same index such that the second range condition
30383071
# fully covers the first one. Additionally one of the disjuncts

mysql-test/main/range.test

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,6 +2067,52 @@ set eq_range_index_dive_limit=default;
20672067

20682068
drop table t1;
20692069

2070+
--echo #
2071+
--echo # MDEV-24117: Memory management problem in statistics state...
2072+
--echo # (just the testcase)
2073+
--echo #
2074+
2075+
create table t0(a int);
2076+
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
2077+
2078+
create table t1(a int);
2079+
2080+
# 4K rows
2081+
insert into t1
2082+
select A.a + B.a* 10 + C.a * 100 + D.a * 1000
2083+
from t0 A, t0 B, t0 C, t0 D
2084+
where D.a<4;
2085+
2086+
create table t2 (
2087+
a int,
2088+
b int,
2089+
key(a)
2090+
);
2091+
2092+
insert into t2 values (1,1),(2,2),(3,3);
2093+
2094+
set @query=(select group_concat(a) from t1);
2095+
2096+
set @tmp_24117= @@max_session_mem_used;
2097+
2098+
--echo #
2099+
--echo # On debug build, the usage was
2100+
--echo # - 2.8M without the bug
2101+
--echo # - 1G with the bug.
2102+
2103+
set max_session_mem_used=64*1024*1024;
2104+
2105+
set @query=concat('explain select * from t2 where a=1 or a in (', @query, ')');
2106+
2107+
prepare s from @query;
2108+
2109+
--echo # This should not fail with an error:
2110+
execute s;
2111+
set max_session_mem_used=@tmp_24117;
2112+
2113+
deallocate prepare s;
2114+
2115+
drop table t0,t1,t2;
20702116
--echo #
20712117
--echo # MDEV-23811: Both disjunct of WHERE condition contain range conditions
20722118
--echo # for the same index such that the second range condition

mysql-test/main/range_mrr_icp.result

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ SELECT * FROM t1 WHERE
12531253
5 <= a AND b = 3 OR
12541254
3 <= a;
12551255
id select_type table type possible_keys key key_len ref rows Extra
1256-
1 SIMPLE t1 range a a 5 NULL 3 Using where; Using index
1256+
1 SIMPLE t1 range a a 5 NULL 4 Using where; Using index
12571257
SELECT * FROM t1 WHERE
12581258
3 <= a AND a <= 5 OR
12591259
5 <= a AND b = 3 OR
@@ -3045,6 +3045,39 @@ a b
30453045
set eq_range_index_dive_limit=default;
30463046
drop table t1;
30473047
#
3048+
# MDEV-24117: Memory management problem in statistics state...
3049+
# (just the testcase)
3050+
#
3051+
create table t0(a int);
3052+
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
3053+
create table t1(a int);
3054+
insert into t1
3055+
select A.a + B.a* 10 + C.a * 100 + D.a * 1000
3056+
from t0 A, t0 B, t0 C, t0 D
3057+
where D.a<4;
3058+
create table t2 (
3059+
a int,
3060+
b int,
3061+
key(a)
3062+
);
3063+
insert into t2 values (1,1),(2,2),(3,3);
3064+
set @query=(select group_concat(a) from t1);
3065+
set @tmp_24117= @@max_session_mem_used;
3066+
#
3067+
# On debug build, the usage was
3068+
# - 2.8M without the bug
3069+
# - 1G with the bug.
3070+
set max_session_mem_used=64*1024*1024;
3071+
set @query=concat('explain select * from t2 where a=1 or a in (', @query, ')');
3072+
prepare s from @query;
3073+
# This should not fail with an error:
3074+
execute s;
3075+
id select_type table type possible_keys key key_len ref rows Extra
3076+
1 SIMPLE t2 ALL a NULL NULL NULL 3 Using where
3077+
set max_session_mem_used=@tmp_24117;
3078+
deallocate prepare s;
3079+
drop table t0,t1,t2;
3080+
#
30483081
# MDEV-23811: Both disjunct of WHERE condition contain range conditions
30493082
# for the same index such that the second range condition
30503083
# fully covers the first one. Additionally one of the disjuncts

sql/opt_range.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8910,15 +8910,9 @@ tree_or(RANGE_OPT_PARAM *param,SEL_TREE *tree1,SEL_TREE *tree2)
89108910
}
89118911
bool no_imerge_from_ranges= FALSE;
89128912

8913-
SEL_TREE *rt1= tree1;
8914-
SEL_TREE *rt2= tree2;
89158913
/* Build the range part of the tree for the formula (1) */
89168914
if (sel_trees_can_be_ored(param, tree1, tree2, &ored_keys))
89178915
{
8918-
if (no_merges1)
8919-
rt1= new SEL_TREE(tree1, TRUE, param);
8920-
if (no_merges2)
8921-
rt2= new SEL_TREE(tree2, TRUE, param);
89228916
bool must_be_ored= sel_trees_must_be_ored(param, tree1, tree2, ored_keys);
89238917
no_imerge_from_ranges= must_be_ored;
89248918

@@ -8976,6 +8970,12 @@ tree_or(RANGE_OPT_PARAM *param,SEL_TREE *tree1,SEL_TREE *tree2)
89768970
else if (!no_ranges1 && !no_ranges2 && !no_imerge_from_ranges)
89778971
{
89788972
/* Build the imerge part of the tree for the formula (1) */
8973+
SEL_TREE *rt1= tree1;
8974+
SEL_TREE *rt2= tree2;
8975+
if (no_merges1)
8976+
rt1= new SEL_TREE(tree1, TRUE, param);
8977+
if (no_merges2)
8978+
rt2= new SEL_TREE(tree2, TRUE, param);
89798979
if (!rt1 || !rt2 ||
89808980
result->merges.push_back(imerge_from_ranges) ||
89818981
imerge_from_ranges->or_sel_tree(param, rt1) ||
@@ -9641,7 +9641,7 @@ key_or(RANGE_OPT_PARAM *param, SEL_ARG *key1,SEL_ARG *key2)
96419641
if (!tmp->next_key_part)
96429642
{
96439643
SEL_ARG *key2_next= key2->next;
9644-
if (key2->use_count)
9644+
if (key2_shared)
96459645
{
96469646
SEL_ARG *key2_cpy= new SEL_ARG(*key2);
96479647
if (!key2_cpy)

sql/sql_prepare.cc

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3238,27 +3238,38 @@ void mysqld_stmt_execute(THD *thd, char *packet_arg, uint packet_length)
32383238
void mysqld_stmt_bulk_execute(THD *thd, char *packet_arg, uint packet_length)
32393239
{
32403240
uchar *packet= (uchar*)packet_arg; // GCC 4.0.1 workaround
3241+
DBUG_ENTER("mysqld_stmt_execute_bulk");
3242+
3243+
const uint packet_header_lenght= 4 + 2; //ID & 2 bytes of flags
3244+
3245+
if (packet_length < packet_header_lenght)
3246+
{
3247+
my_error(ER_MALFORMED_PACKET, MYF(0));
3248+
DBUG_VOID_RETURN;
3249+
}
3250+
32413251
ulong stmt_id= uint4korr(packet);
32423252
uint flags= (uint) uint2korr(packet + 4);
32433253
uchar *packet_end= packet + packet_length;
3244-
DBUG_ENTER("mysqld_stmt_execute_bulk");
32453254

32463255
if (!(thd->client_capabilities &
32473256
MARIADB_CLIENT_STMT_BULK_OPERATIONS))
32483257
{
32493258
DBUG_PRINT("error",
32503259
("An attempt to execute bulk operation without support"));
32513260
my_error(ER_UNSUPPORTED_PS, MYF(0));
3261+
DBUG_VOID_RETURN;
32523262
}
32533263
/* Check for implemented parameters */
32543264
if (flags & (~STMT_BULK_FLAG_CLIENT_SEND_TYPES))
32553265
{
32563266
DBUG_PRINT("error", ("unsupported bulk execute flags %x", flags));
32573267
my_error(ER_UNSUPPORTED_PS, MYF(0));
3268+
DBUG_VOID_RETURN;
32583269
}
32593270

32603271
/* stmt id and two bytes of flags */
3261-
packet+= 4 + 2;
3272+
packet+= packet_header_lenght;
32623273
mysql_stmt_execute_common(thd, stmt_id, packet, packet_end, 0, TRUE,
32633274
(flags & STMT_BULK_FLAG_CLIENT_SEND_TYPES));
32643275
DBUG_VOID_RETURN;
@@ -3335,9 +3346,11 @@ stmt_execute_packet_sanity_check(Prepared_statement *stmt,
33353346
{
33363347
/*
33373348
If there is no parameters, this should be normally already end
3338-
of the packet. If it's not - then error
3349+
of the packet, but it is not a problem if something left (popular
3350+
mistake in protocol implementation) because we will not read anymore
3351+
from the buffer.
33393352
*/
3340-
return (packet_end > packet);
3353+
return false;
33413354
}
33423355
return false;
33433356
}

tests/mysql_client_test.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20995,8 +20995,11 @@ static void test_mdev19838()
2099520995
" VALUES "
2099620996
"(0x1111111111111111)", -1);
2099720997

20998-
/* Expecting an error if parameters are sent */
20999-
DIE_UNLESS(rc != 0 || paramCount == 0);
20998+
/*
20999+
We allow junk at the end of the packet in case of
21000+
no parameters. So it will succeed.
21001+
*/
21002+
DIE_UNLESS(rc == 0);
2100021003
}
2100121004

2100221005
mysql_stmt_close(stmt);

0 commit comments

Comments
 (0)