Skip to content

Commit 39e2c95

Browse files
committed
Merge 10.3 into 10.4
2 parents fcc9f8b + 08d8bce commit 39e2c95

File tree

5 files changed

+305
-10
lines changed

5 files changed

+305
-10
lines changed

mysql-test/main/table_value_constr.result

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2887,6 +2887,181 @@ drop table t1,t2,t3;
28872887
select sum((values(1)));
28882888
sum((values(1)))
28892889
1
2890+
#
2891+
# MDEV-22786: Nested table values constructors
2892+
#
2893+
values ((values (2)));
2894+
(values (2))
2895+
2
2896+
values ((values (2)), (5), (select 4));
2897+
(values (2)) 5 (select 4)
2898+
2 5 4
2899+
values ((7), (values (2)), (5), (select 4));
2900+
7 (values (2)) 5 (select 4)
2901+
7 2 5 4
2902+
values ((values (2))) union values ((values (3)));
2903+
(values (2))
2904+
2
2905+
3
2906+
values ((values (2))), ((values (3)));
2907+
(values (2))
2908+
2
2909+
3
2910+
values ((values (2))), ((select 4)), ((values (3)));
2911+
(values (2))
2912+
2
2913+
4
2914+
3
2915+
values ((values (4)), (values (5))), ((values (1)), (values (7)));
2916+
(values (4)) (values (5))
2917+
4 5
2918+
1 7
2919+
values ((values (4)), (select 5)), ((select 1), (values (7)));
2920+
(values (4)) (select 5)
2921+
4 5
2922+
1 7
2923+
values ((select 2)) union values ((values (3)));
2924+
(select 2)
2925+
2
2926+
3
2927+
values ((values (2))) union values((select 3));
2928+
(values (2))
2929+
2
2930+
3
2931+
values ((values (2))) union all values ((values (2)));
2932+
(values (2))
2933+
2
2934+
2
2935+
values ((values (4)), (values (5))), ((values (1)), (values (7)))
2936+
union
2937+
values ((values (4)), (select 5)), ((select 2), (values (8)));
2938+
(values (4)) (values (5))
2939+
4 5
2940+
1 7
2941+
2 8
2942+
values ((values (4)), (values (5))), ((values (1)), (values (7)))
2943+
union all
2944+
values ((values (4)), (select 5)), ((select 2), (values (8)));
2945+
(values (4)) (values (5))
2946+
4 5
2947+
1 7
2948+
4 5
2949+
2 8
2950+
values ((values (1) union values (1)));
2951+
(values (1) union values (1))
2952+
1
2953+
values ((values (1) union values (1) union values (1)));
2954+
(values (1) union values (1) union values (1))
2955+
1
2956+
values ((values ((values (4)))));
2957+
(values ((values (4))))
2958+
4
2959+
values ((values ((select 5))));
2960+
(values ((select 5)))
2961+
5
2962+
values ((select (values (4))), (values ((values(5)))));
2963+
(select (values (4))) (values ((values(5))))
2964+
4 5
2965+
values ((select (values (4))), (values ((select 5))));
2966+
(select (values (4))) (values ((select 5)))
2967+
4 5
2968+
values ((select (values (4))), (values ((values(5)))))
2969+
union
2970+
values ((select (values (4))), (values ((select 7))));
2971+
(select (values (4))) (values ((values(5))))
2972+
4 5
2973+
4 7
2974+
values ((values (2))), ((values ((values (4)))));
2975+
(values (2))
2976+
2
2977+
4
2978+
values ((values (2))), ((values ((select 4))));
2979+
(values (2))
2980+
2
2981+
4
2982+
values ((values (2))), ((values ((values (4)))))
2983+
union
2984+
values ((values (8))), ((values ((select 4))));
2985+
(values (2))
2986+
2
2987+
4
2988+
8
2989+
values ((values (2))), ((values ((values (4)))))
2990+
union all
2991+
values ((values (8))), ((values ((select 4))));
2992+
(values (2))
2993+
2
2994+
4
2995+
8
2996+
4
2997+
select * from (values ((values (2)))) dt;
2998+
(values (2))
2999+
2
3000+
select * from (values ((values (2)), (5), (select 4))) dt;
3001+
(values (2)) 5 (select 4)
3002+
2 5 4
3003+
select * from (values ((values (2))) union values ((values (3)))) dt;
3004+
(values (2))
3005+
2
3006+
3
3007+
select * from (values ((values (2))), ((values (3)))) dt;
3008+
(values (2))
3009+
2
3010+
3
3011+
select * from (values ((values (2))), ((values (3)))) dt;
3012+
(values (2))
3013+
2
3014+
3
3015+
select * from (values ((values (2))), ((select 4)), ((values (3)))) dt;
3016+
(values (2))
3017+
2
3018+
4
3019+
3
3020+
create table t1 (a int);
3021+
insert into t1 values (3), (7), (1);
3022+
values ((values ((select a from t1 where a=7))));
3023+
(values ((select a from t1 where a=7)))
3024+
7
3025+
values ((values ((select (values(2)) from t1 where a=8))));
3026+
(values ((select (values(2)) from t1 where a=8)))
3027+
NULL
3028+
values ((values ((select a from t1 where a=7))))
3029+
union
3030+
values ((values ((select (values(2)) from t1 where a=8))));
3031+
(values ((select a from t1 where a=7)))
3032+
7
3033+
NULL
3034+
values ((values ((select a from t1 where a in ((values (7)))))));
3035+
(values ((select a from t1 where a in ((values (7))))))
3036+
7
3037+
values ((values ((select a from t1 where a in ((values (7), (8)))))));
3038+
(values ((select a from t1 where a in ((values (7), (8))))))
3039+
7
3040+
values ((values
3041+
((select a from t1 where a in (values (7) union values (8))))));
3042+
(values
3043+
((select a from t1 where a in (values (7) union values (8)))))
3044+
7
3045+
values ((values ((select (values(2)) from t1 where a=8))));
3046+
(values ((select (values(2)) from t1 where a=8)))
3047+
NULL
3048+
values ((select (values(2)) from t1 where a<7));
3049+
ERROR 21000: Subquery returns more than 1 row
3050+
select * from (values ((values ((select a from t1 where a=7))))) dt;
3051+
(values ((select a from t1 where a=7)))
3052+
7
3053+
select * from (values ((values ((select (values(2)) from t1 where a=8))))) dt;
3054+
(values ((select (values(2)) from t1 where a=8)))
3055+
NULL
3056+
insert into t1(a) values ((values (2))), ((values (3)));
3057+
select * from t1;
3058+
a
3059+
3
3060+
7
3061+
1
3062+
2
3063+
3
3064+
drop table t1;
28903065
End of 10.3 tests
28913066
#
28923067
# MDEV-22610 Crash in INSERT INTO t1 (VALUES (DEFAULT) UNION VALUES (DEFAULT))

mysql-test/main/table_value_constr.test

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,112 @@ drop table t1,t2,t3;
15221522

15231523
select sum((values(1)));
15241524

1525+
--echo #
1526+
--echo # MDEV-22786: Nested table values constructors
1527+
--echo #
1528+
1529+
values ((values (2)));
1530+
1531+
values ((values (2)), (5), (select 4));
1532+
1533+
values ((7), (values (2)), (5), (select 4));
1534+
1535+
values ((values (2))) union values ((values (3)));
1536+
1537+
values ((values (2))), ((values (3)));
1538+
1539+
values ((values (2))), ((select 4)), ((values (3)));
1540+
1541+
values ((values (4)), (values (5))), ((values (1)), (values (7)));
1542+
1543+
values ((values (4)), (select 5)), ((select 1), (values (7)));
1544+
1545+
values ((select 2)) union values ((values (3)));
1546+
1547+
values ((values (2))) union values((select 3));
1548+
1549+
values ((values (2))) union all values ((values (2)));
1550+
1551+
values ((values (4)), (values (5))), ((values (1)), (values (7)))
1552+
union
1553+
values ((values (4)), (select 5)), ((select 2), (values (8)));
1554+
1555+
values ((values (4)), (values (5))), ((values (1)), (values (7)))
1556+
union all
1557+
values ((values (4)), (select 5)), ((select 2), (values (8)));
1558+
1559+
values ((values (1) union values (1)));
1560+
1561+
values ((values (1) union values (1) union values (1)));
1562+
1563+
values ((values ((values (4)))));
1564+
1565+
values ((values ((select 5))));
1566+
1567+
values ((select (values (4))), (values ((values(5)))));
1568+
1569+
values ((select (values (4))), (values ((select 5))));
1570+
1571+
values ((select (values (4))), (values ((values(5)))))
1572+
union
1573+
values ((select (values (4))), (values ((select 7))));
1574+
1575+
values ((values (2))), ((values ((values (4)))));
1576+
1577+
values ((values (2))), ((values ((select 4))));
1578+
1579+
values ((values (2))), ((values ((values (4)))))
1580+
union
1581+
values ((values (8))), ((values ((select 4))));
1582+
1583+
values ((values (2))), ((values ((values (4)))))
1584+
union all
1585+
values ((values (8))), ((values ((select 4))));
1586+
1587+
select * from (values ((values (2)))) dt;
1588+
1589+
select * from (values ((values (2)), (5), (select 4))) dt;
1590+
1591+
select * from (values ((values (2))) union values ((values (3)))) dt;
1592+
1593+
select * from (values ((values (2))), ((values (3)))) dt;
1594+
1595+
select * from (values ((values (2))), ((values (3)))) dt;
1596+
1597+
select * from (values ((values (2))), ((select 4)), ((values (3)))) dt;
1598+
1599+
create table t1 (a int);
1600+
insert into t1 values (3), (7), (1);
1601+
1602+
values ((values ((select a from t1 where a=7))));
1603+
1604+
values ((values ((select (values(2)) from t1 where a=8))));
1605+
1606+
values ((values ((select a from t1 where a=7))))
1607+
union
1608+
values ((values ((select (values(2)) from t1 where a=8))));
1609+
1610+
values ((values ((select a from t1 where a in ((values (7)))))));
1611+
1612+
values ((values ((select a from t1 where a in ((values (7), (8)))))));
1613+
1614+
values ((values
1615+
((select a from t1 where a in (values (7) union values (8))))));
1616+
1617+
values ((values ((select (values(2)) from t1 where a=8))));
1618+
1619+
--error ER_SUBQUERY_NO_1_ROW
1620+
values ((select (values(2)) from t1 where a<7));
1621+
1622+
select * from (values ((values ((select a from t1 where a=7))))) dt;
1623+
1624+
select * from (values ((values ((select (values(2)) from t1 where a=8))))) dt;
1625+
1626+
insert into t1(a) values ((values (2))), ((values (3)));
1627+
select * from t1;
1628+
1629+
drop table t1;
1630+
15251631
--echo End of 10.3 tests
15261632

15271633
--echo #

sql/sql_lex.cc

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,6 +2487,8 @@ void st_select_lex::init_select()
24872487
with_dep= 0;
24882488
join= 0;
24892489
lock_type= TL_READ_DEFAULT;
2490+
save_many_values.empty();
2491+
save_insert_list= 0;
24902492
tvc= 0;
24912493
in_funcs.empty();
24922494
curr_tvc_name= 0;
@@ -8897,7 +8899,6 @@ bool LEX::last_field_generated_always_as_row_end()
88978899
VERS_SYS_END_FLAG);
88988900
}
88998901

8900-
89018902
void st_select_lex_unit::reset_distinct()
89028903
{
89038904
union_distinct= NULL;
@@ -8913,6 +8914,20 @@ void st_select_lex_unit::reset_distinct()
89138914
}
89148915

89158916

8917+
void LEX::save_values_list_state()
8918+
{
8919+
current_select->save_many_values= many_values;
8920+
current_select->save_insert_list= insert_list;
8921+
}
8922+
8923+
8924+
void LEX::restore_values_list_state()
8925+
{
8926+
many_values= current_select->save_many_values;
8927+
insert_list= current_select->save_insert_list;
8928+
}
8929+
8930+
89168931
void st_select_lex_unit::fix_distinct()
89178932
{
89188933
if (union_distinct && this != union_distinct->master_unit())
@@ -9409,6 +9424,7 @@ bool LEX::parsed_insert_select(SELECT_LEX *first_select)
94099424
bool LEX::parsed_TVC_start()
94109425
{
94119426
SELECT_LEX *sel;
9427+
save_values_list_state();
94129428
many_values.empty();
94139429
insert_list= 0;
94149430
if (!(sel= alloc_select(TRUE)) ||
@@ -9422,14 +9438,13 @@ bool LEX::parsed_TVC_start()
94229438

94239439
SELECT_LEX *LEX::parsed_TVC_end()
94249440
{
9425-
94269441
SELECT_LEX *res= pop_select(); // above TVC select
94279442
if (!(res->tvc=
94289443
new (thd->mem_root) table_value_constr(many_values,
94299444
res,
94309445
res->options)))
94319446
return NULL;
9432-
many_values.empty();
9447+
restore_values_list_state();
94339448
return res;
94349449
}
94359450

sql/sql_lex.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,8 @@ class st_select_lex: public st_select_lex_node
12871287
/* it is for correct printing SELECT options */
12881288
thr_lock_type lock_type;
12891289

1290+
List<List_item> save_many_values;
1291+
List<Item> *save_insert_list;
12901292
table_value_constr *tvc;
12911293
bool in_tvc;
12921294

@@ -4409,13 +4411,6 @@ struct LEX: public Query_tables_list
44094411
return false;
44104412
}
44114413

4412-
void tvc_start()
4413-
{
4414-
field_list.empty();
4415-
many_values.empty();
4416-
insert_list= 0;
4417-
}
4418-
44194414
SELECT_LEX_UNIT *alloc_unit();
44204415
SELECT_LEX *alloc_select(bool is_select);
44214416
SELECT_LEX_UNIT *create_unit(SELECT_LEX*);
@@ -4470,6 +4465,8 @@ struct LEX: public Query_tables_list
44704465
bool distinct);
44714466
SELECT_LEX *parsed_subselect(SELECT_LEX_UNIT *unit);
44724467
bool parsed_insert_select(SELECT_LEX *firs_select);
4468+
void save_values_list_state();
4469+
void restore_values_list_state();
44734470
bool parsed_TVC_start();
44744471
SELECT_LEX *parsed_TVC_end();
44754472
TABLE_LIST *parsed_derived_table(SELECT_LEX_UNIT *unit,

sql/sql_tvc.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,8 @@ st_select_lex *wrap_tvc(THD *thd, st_select_lex *tvc_sl,
672672
wrapper_sl->nest_level= tvc_sl->nest_level;
673673
wrapper_sl->parsing_place= tvc_sl->parsing_place;
674674
wrapper_sl->set_linkage(tvc_sl->get_linkage());
675+
wrapper_sl->exclude_from_table_unique_test=
676+
tvc_sl->exclude_from_table_unique_test;
675677

676678
lex->current_select= wrapper_sl;
677679
item= new (thd->mem_root) Item_field(thd, &wrapper_sl->context,

0 commit comments

Comments
 (0)