Skip to content

Commit 3681034

Browse files
committed
Merge branch '10.3' into 10.4
2 parents d1eeb4b + 3e2afcb commit 3681034

File tree

8 files changed

+247
-47
lines changed

8 files changed

+247
-47
lines changed

debian/libmariadb3.install

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ usr/lib/mysql/plugin/client_ed25519.so
33
usr/lib/mysql/plugin/dialog.so
44
usr/lib/mysql/plugin/mysql_clear_password.so
55
usr/lib/mysql/plugin/sha256_password.so
6+
usr/lib/mysql/plugin/caching_sha2_password.so

mysql-test/main/table_value_constr.result

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
748748
3 MATERIALIZED <derived2> ALL NULL NULL NULL NULL 2 100.00
749749
2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
750750
Warnings:
751-
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1)) `tvc_0`) where 1
751+
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1)) `tvc_0`) where 1
752752
explain extended select * from t1
753753
where a in (select * from (values (1)) as tvc_0);
754754
id select_type table type possible_keys key key_len ref rows filtered Extra
@@ -983,7 +983,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
983983
3 MATERIALIZED <derived2> ALL NULL NULL NULL NULL 2 100.00
984984
2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
985985
Warnings:
986-
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1),(2)) `tvc_0`) where 1
986+
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1),(2)) `tvc_0`) where 1
987987
explain extended select * from t1
988988
where a = any (select * from (values (1),(2)) as tvc_0);
989989
id select_type table type possible_keys key key_len ref rows filtered Extra
@@ -2776,6 +2776,112 @@ id select_type table type possible_keys key key_len ref rows Extra
27762776
2 SUBQUERY t1 ALL NULL NULL NULL NULL 3 Using where
27772777
drop table t1;
27782778
#
2779+
# MDEV-24910: TVC containing subquery used as a subselect
2780+
#
2781+
create table t1 (a int) engine=myisam;
2782+
insert into t1 values (3), (7), (1);
2783+
create table t2 (b int) engine=myisam;
2784+
insert into t2 values (1), (2);
2785+
select (values ((select 2))) from t2;
2786+
(values ((select 2)))
2787+
2
2788+
2
2789+
explain select (values ((select 2))) from t2;
2790+
id select_type table type possible_keys key key_len ref rows Extra
2791+
1 PRIMARY t2 ALL NULL NULL NULL NULL 2
2792+
4 SUBQUERY <derived2> ALL NULL NULL NULL NULL 2
2793+
2 DERIVED NULL NULL NULL NULL NULL NULL NULL No tables used
2794+
Warnings:
2795+
Note 1249 Select 3 was reduced during optimization
2796+
prepare stmt from "select (values ((select 2))) from t2";
2797+
execute stmt;
2798+
(values ((select 2)))
2799+
2
2800+
2
2801+
execute stmt;
2802+
(values ((select 2)))
2803+
2
2804+
2
2805+
deallocate prepare stmt;
2806+
select (values ((select * from t1 where a > 10))) from t2;
2807+
(values ((select * from t1 where a > 10)))
2808+
NULL
2809+
NULL
2810+
explain select (values ((select * from t1 where a > 10))) from t2;
2811+
id select_type table type possible_keys key key_len ref rows Extra
2812+
1 PRIMARY t2 ALL NULL NULL NULL NULL 2
2813+
4 SUBQUERY <derived2> ALL NULL NULL NULL NULL 2
2814+
2 DERIVED NULL NULL NULL NULL NULL NULL NULL No tables used
2815+
3 SUBQUERY t1 ALL NULL NULL NULL NULL 3 Using where
2816+
prepare stmt from "select (values ((select * from t1 where a > 10))) from t2";
2817+
execute stmt;
2818+
(values ((select * from t1 where a > 10)))
2819+
NULL
2820+
NULL
2821+
execute stmt;
2822+
(values ((select * from t1 where a > 10)))
2823+
NULL
2824+
NULL
2825+
deallocate prepare stmt;
2826+
create table t3 (a int);
2827+
insert into t3 values
2828+
(3), (7), (7), (1), (3), (9), (7), (9), (8), (7), (8);
2829+
create view v1 as select count(a) as c from t3 group by a;
2830+
select
2831+
(values ((select * from t3 where a in (select * from v1))));
2832+
(values ((select * from t3 where a in (select * from v1))))
2833+
1
2834+
explain select
2835+
(values ((select * from t3 where a in (select * from v1))));
2836+
id select_type table type possible_keys key key_len ref rows Extra
2837+
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used
2838+
6 SUBQUERY <derived2> ALL NULL NULL NULL NULL 2
2839+
2 DERIVED NULL NULL NULL NULL NULL NULL NULL No tables used
2840+
3 SUBQUERY t3 ALL NULL NULL NULL NULL 11
2841+
3 SUBQUERY <subquery4> eq_ref distinct_key distinct_key 8 func 1 Using where
2842+
4 MATERIALIZED <derived5> ALL NULL NULL NULL NULL 11
2843+
5 DERIVED t3 ALL NULL NULL NULL NULL 11 Using temporary; Using filesort
2844+
prepare stmt from "select
2845+
(values ((select * from t3 where a in (select * from v1))))";
2846+
execute stmt;
2847+
(values ((select * from t3 where a in (select * from v1))))
2848+
1
2849+
execute stmt;
2850+
(values ((select * from t3 where a in (select * from v1))))
2851+
1
2852+
deallocate prepare stmt;
2853+
select
2854+
(values ((select * from t3
2855+
where a > 10 and a in (select * from v1))));
2856+
(values ((select * from t3
2857+
where a > 10 and a in (select * from v1))))
2858+
NULL
2859+
explain select
2860+
(values ((select * from t3
2861+
where a > 10 and a in (select * from v1))));
2862+
id select_type table type possible_keys key key_len ref rows Extra
2863+
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used
2864+
6 SUBQUERY <derived2> ALL NULL NULL NULL NULL 2
2865+
2 DERIVED NULL NULL NULL NULL NULL NULL NULL No tables used
2866+
3 SUBQUERY t3 ALL NULL NULL NULL NULL 11 Using where
2867+
3 SUBQUERY <subquery4> eq_ref distinct_key distinct_key 8 func 1 Using where
2868+
4 MATERIALIZED <derived5> ALL NULL NULL NULL NULL 11
2869+
5 DERIVED t3 ALL NULL NULL NULL NULL 11 Using temporary; Using filesort
2870+
prepare stmt from "select
2871+
(values ((select * from t3
2872+
where a > 10 and a in (select * from v1))))";
2873+
execute stmt;
2874+
(values ((select * from t3
2875+
where a > 10 and a in (select * from v1))))
2876+
NULL
2877+
execute stmt;
2878+
(values ((select * from t3
2879+
where a > 10 and a in (select * from v1))))
2880+
NULL
2881+
deallocate prepare stmt;
2882+
drop view v1;
2883+
drop table t1,t2,t3;
2884+
#
27792885
# End of 10.3 tests
27802886
#
27812887
#

mysql-test/main/table_value_constr.test

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,63 @@ eval explain $q3;
14591459

14601460
drop table t1;
14611461

1462+
--echo #
1463+
--echo # MDEV-24910: TVC containing subquery used as a subselect
1464+
--echo #
1465+
1466+
create table t1 (a int) engine=myisam;
1467+
insert into t1 values (3), (7), (1);
1468+
create table t2 (b int) engine=myisam;
1469+
insert into t2 values (1), (2);
1470+
1471+
let $q1=
1472+
select (values ((select 2))) from t2;
1473+
eval $q1;
1474+
eval explain $q1;
1475+
eval prepare stmt from "$q1";
1476+
execute stmt;
1477+
execute stmt;
1478+
deallocate prepare stmt;
1479+
1480+
let $q2=
1481+
select (values ((select * from t1 where a > 10))) from t2;
1482+
eval $q2;
1483+
eval explain $q2;
1484+
eval prepare stmt from "$q2";
1485+
execute stmt;
1486+
execute stmt;
1487+
deallocate prepare stmt;
1488+
1489+
create table t3 (a int);
1490+
insert into t3 values
1491+
(3), (7), (7), (1), (3), (9), (7), (9), (8), (7), (8);
1492+
1493+
create view v1 as select count(a) as c from t3 group by a;
1494+
1495+
let $q3=
1496+
select
1497+
(values ((select * from t3 where a in (select * from v1))));
1498+
eval $q3;
1499+
eval explain $q3;
1500+
eval prepare stmt from "$q3";
1501+
execute stmt;
1502+
execute stmt;
1503+
deallocate prepare stmt;
1504+
1505+
let $q4=
1506+
select
1507+
(values ((select * from t3
1508+
where a > 10 and a in (select * from v1))));
1509+
eval $q4;
1510+
eval explain $q4;
1511+
eval prepare stmt from "$q4";
1512+
execute stmt;
1513+
execute stmt;
1514+
deallocate prepare stmt;
1515+
1516+
drop view v1;
1517+
drop table t1,t2,t3;
1518+
14621519
--echo #
14631520
--echo # End of 10.3 tests
14641521
--echo #

mysql-test/suite/compat/oracle/r/table_value_constr.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
746746
3 MATERIALIZED <derived2> ALL NULL NULL NULL NULL 2 100.00
747747
2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
748748
Warnings:
749-
Note 1003 select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" semi join ((values (1)) "tvc_0") where 1
749+
Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" semi join ((values (1)) "tvc_0") where 1
750750
explain extended select * from t1
751751
where a in (select * from (values (1)) as tvc_0);
752752
id select_type table type possible_keys key key_len ref rows filtered Extra
@@ -981,7 +981,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
981981
3 MATERIALIZED <derived2> ALL NULL NULL NULL NULL 2 100.00
982982
2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used
983983
Warnings:
984-
Note 1003 select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" semi join ((values (1),(2)) "tvc_0") where 1
984+
Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" semi join ((values (1),(2)) "tvc_0") where 1
985985
explain extended select * from t1
986986
where a = any (select * from (values (1),(2)) as tvc_0);
987987
id select_type table type possible_keys key key_len ref rows filtered Extra

mysys/lf_hash.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232

3333
/* An element of the list */
3434
typedef struct {
35-
intptr volatile link; /* a pointer to the next element in a list and a flag */
36-
uint32 hashnr; /* reversed hash number, for sorting */
35+
intptr link; /* a pointer to the next element in a list and a flag */
3736
const uchar *key;
3837
size_t keylen;
38+
uint32 hashnr; /* reversed hash number, for sorting */
3939
/*
4040
data is stored here, directly after the keylen.
4141
thus the pointer to data is (void*)(slist_element_ptr+1)
@@ -49,7 +49,7 @@ const int LF_HASH_OVERHEAD= sizeof(LF_SLIST);
4949
in a list) from l_find to l_insert/l_delete
5050
*/
5151
typedef struct {
52-
intptr volatile *prev;
52+
intptr *prev;
5353
LF_SLIST *curr, *next;
5454
} CURSOR;
5555

@@ -86,8 +86,8 @@ typedef struct {
8686
0 - ok
8787
1 - error (callbck returned 1)
8888
*/
89-
static int l_find(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr,
90-
const uchar *key, size_t keylen, CURSOR *cursor, LF_PINS *pins,
89+
static int l_find(LF_SLIST **head, CHARSET_INFO *cs, uint32 hashnr,
90+
const uchar *key, uint keylen, CURSOR *cursor, LF_PINS *pins,
9191
my_hash_walk_action callback)
9292
{
9393
uint32 cur_hashnr;
@@ -169,7 +169,7 @@ static int l_find(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr,
169169
it uses pins[0..2], on return all pins are removed.
170170
if there're nodes with the same key value, a new node is added before them.
171171
*/
172-
static LF_SLIST *l_insert(LF_SLIST * volatile *head, CHARSET_INFO *cs,
172+
static LF_SLIST *l_insert(LF_SLIST **head, CHARSET_INFO *cs,
173173
LF_SLIST *node, LF_PINS *pins, uint flags)
174174
{
175175
CURSOR cursor;
@@ -221,7 +221,7 @@ static LF_SLIST *l_insert(LF_SLIST * volatile *head, CHARSET_INFO *cs,
221221
NOTE
222222
it uses pins[0..2], on return all pins are removed.
223223
*/
224-
static int l_delete(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr,
224+
static int l_delete(LF_SLIST **head, CHARSET_INFO *cs, uint32 hashnr,
225225
const uchar *key, uint keylen, LF_PINS *pins)
226226
{
227227
CURSOR cursor;
@@ -279,7 +279,7 @@ static int l_delete(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr,
279279
it uses pins[0..2], on return the pin[2] keeps the node found
280280
all other pins are removed.
281281
*/
282-
static LF_SLIST *l_search(LF_SLIST * volatile *head, CHARSET_INFO *cs,
282+
static LF_SLIST *l_search(LF_SLIST **head, CHARSET_INFO *cs,
283283
uint32 hashnr, const uchar *key, uint keylen,
284284
LF_PINS *pins)
285285
{
@@ -320,7 +320,7 @@ static inline my_hash_value_type calc_hash(CHARSET_INFO *cs,
320320

321321
#define MAX_LOAD 1.0 /* average number of elements in a bucket */
322322

323-
static int initialize_bucket(LF_HASH *, LF_SLIST * volatile*, uint, LF_PINS *);
323+
static int initialize_bucket(LF_HASH *, LF_SLIST **, uint, LF_PINS *);
324324

325325
static void default_initializer(LF_HASH *hash, void *dst, const void *src)
326326
{
@@ -399,7 +399,7 @@ void lf_hash_destroy(LF_HASH *hash)
399399
int lf_hash_insert(LF_HASH *hash, LF_PINS *pins, const void *data)
400400
{
401401
int csize, bucket, hashnr;
402-
LF_SLIST *node, * volatile *el;
402+
LF_SLIST *node, **el;
403403

404404
node= (LF_SLIST *)lf_alloc_new(pins);
405405
if (unlikely(!node))
@@ -438,7 +438,7 @@ int lf_hash_insert(LF_HASH *hash, LF_PINS *pins, const void *data)
438438
*/
439439
int lf_hash_delete(LF_HASH *hash, LF_PINS *pins, const void *key, uint keylen)
440440
{
441-
LF_SLIST * volatile *el;
441+
LF_SLIST **el;
442442
uint bucket, hashnr;
443443

444444
hashnr= hash->hash_function(hash->charset, (uchar *)key, keylen) & INT_MAX32;
@@ -474,7 +474,7 @@ void *lf_hash_search_using_hash_value(LF_HASH *hash, LF_PINS *pins,
474474
my_hash_value_type hashnr,
475475
const void *key, uint keylen)
476476
{
477-
LF_SLIST * volatile *el, *found;
477+
LF_SLIST **el, *found;
478478
uint bucket;
479479

480480
/* hide OOM errors - if we cannot initialize a bucket, try the previous one */
@@ -508,7 +508,7 @@ int lf_hash_iterate(LF_HASH *hash, LF_PINS *pins,
508508
CURSOR cursor;
509509
uint bucket= 0;
510510
int res;
511-
LF_SLIST * volatile *el;
511+
LF_SLIST **el;
512512

513513
el= lf_dynarray_lvalue(&hash->array, bucket);
514514
if (unlikely(!el))
@@ -540,13 +540,13 @@ static const uchar *dummy_key= (uchar*)"";
540540
0 - ok
541541
-1 - out of memory
542542
*/
543-
static int initialize_bucket(LF_HASH *hash, LF_SLIST * volatile *node,
543+
static int initialize_bucket(LF_HASH *hash, LF_SLIST **node,
544544
uint bucket, LF_PINS *pins)
545545
{
546546
uint parent= my_clear_highest_bit(bucket);
547547
LF_SLIST *dummy= (LF_SLIST *)my_malloc(sizeof(LF_SLIST), MYF(MY_WME));
548548
LF_SLIST **tmp= 0, *cur;
549-
LF_SLIST * volatile *el= lf_dynarray_lvalue(&hash->array, parent);
549+
LF_SLIST **el= lf_dynarray_lvalue(&hash->array, parent);
550550
if (unlikely(!el || !dummy))
551551
return -1;
552552
if (*el == NULL && bucket &&

sql/sql_lex.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2530,6 +2530,8 @@ void st_select_lex_node::add_slave(st_select_lex_node *slave_arg)
25302530
{
25312531
slave= slave_arg;
25322532
slave_arg->master= this;
2533+
slave->prev= &master->slave;
2534+
slave->next= 0;
25332535
}
25342536
}
25352537

@@ -2551,6 +2553,27 @@ void st_select_lex_node::link_chain_down(st_select_lex_node *first)
25512553
slave= first;
25522554
}
25532555

2556+
/*
2557+
@brief
2558+
Substitute this node in select tree for a newly creates node
2559+
2560+
@param subst the node to substitute for
2561+
2562+
@details
2563+
The function substitute this node in the select tree for a newly
2564+
created node subst. This node is just removed from the tree but all
2565+
its link fields and the attached sub-tree remain untouched.
2566+
*/
2567+
2568+
void st_select_lex_node::substitute_in_tree(st_select_lex_node *subst)
2569+
{
2570+
if ((subst->next= next))
2571+
next->prev= &subst->next;
2572+
subst->prev= prev;
2573+
(*prev)= subst;
2574+
subst->master= master;
2575+
}
2576+
25542577
/*
25552578
include on level down (but do not link)
25562579

sql/sql_lex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ class st_select_lex_node {
764764
link_next= NULL;
765765
link_prev= NULL;
766766
}
767-
767+
void substitute_in_tree(st_select_lex_node *subst);
768768

769769
void set_slave(st_select_lex_node *slave_arg) { slave= slave_arg; }
770770
void move_node(st_select_lex_node *where_to_move)

0 commit comments

Comments
 (0)