Skip to content

Commit

Permalink
Merge 10.11 into 11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-m committed Nov 24, 2023
2 parents edb98da + a48c1b8 commit 5b6134b
Show file tree
Hide file tree
Showing 165 changed files with 2,019 additions and 450 deletions.
2 changes: 2 additions & 0 deletions client/mysql_upgrade.c
Expand Up @@ -1166,6 +1166,8 @@ static int install_used_plugin_data_types(void)
DYNAMIC_STRING ds_result;
const char *query = "SELECT table_comment FROM information_schema.tables"
" WHERE table_comment LIKE 'Unknown data type: %'";
if (opt_systables_only)
return 0;
if (init_dynamic_string(&ds_result, "", 512, 512))
die("Out of memory");
run_query(query, &ds_result, TRUE);
Expand Down
4 changes: 0 additions & 4 deletions debian/autobake-deb.sh
Expand Up @@ -142,10 +142,6 @@ in
# there is intentionally no customizations whatsoever.
;;
# Ubuntu
"bionic")
remove_rocksdb_tools
[ "$architecture" != amd64 ] && disable_pmem
;&
"focal")
replace_uring_with_aio
disable_libfmt
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/include/delete_anonymous_users.inc
@@ -1,7 +1,7 @@
# Remove anonymous users added by add_anonymous_users.inc
disable_warnings;
disable_query_log;
DELETE FROM mysql.user where host='localhost' and user='';
DELETE FROM mysql.global_priv where host='localhost' and user='';
FLUSH PRIVILEGES;
enable_query_log;
enable_warnings;
274 changes: 274 additions & 0 deletions mysql-test/main/cte_nonrecursive.result
Expand Up @@ -2337,4 +2337,278 @@ set sql_mode="oracle";
with data as (select 1 as id)
select id into @myid from data;
set sql_mode= @save_sql_mode;
#
# MDEV-31995 Bogus error executing PS for query using CTE with renaming of columns
#
create table t1 (a int, b int);
insert into t1 values (1,1),(1,2),(1,3),(2,1),(2,2);
create table t2 (a int, b int);
insert into t2 values (3,1),(3,2),(3,3),(4,1),(4,2);
with cte (c1,c2) as
(select a as col1, sum(b) as col2 from t1 group by col1)
select * from cte;
c1 c2
1 6
2 3
prepare st from "with cte (c1,c2) as
(select a as col1, sum(b) as col2 from t1 group by col1)
select * from cte";
execute st;
c1 c2
1 6
2 3
execute st;
c1 c2
1 6
2 3
drop prepare st;
create procedure sp() with cte (c1,c2) as
(select a as col1, sum(b) as col2 from t1 group by col1)
select * from cte;
call sp();
c1 c2
1 6
2 3
call sp();
c1 c2
1 6
2 3
drop procedure sp;
with cte (c1,c2) as
(select a as col1, sum(b) as col2 from t1 order by col1)
select * from cte;
c1 c2
1 9
prepare st from "with cte (c1,c2) as
(select a as col1, sum(b) as col2 from t1 order by col1)
select * from cte";
execute st;
c1 c2
1 9
execute st;
c1 c2
1 9
drop prepare st;
create procedure sp() with cte (c1,c2) as
(select a as col1, sum(b) as col2 from t1 order by col1)
select * from cte;
call sp();
c1 c2
1 9
call sp();
c1 c2
1 9
drop procedure sp;
with cte (c1,c2) as
(select a as col1, sum(b) as col2 from t1 where a > 1 group by col1
union select a as col3, sum(b) as col4 from t2 where b > 2 group by col3),
cte2 (c3, c4) as
(select a as col5, sum(b) as col6 from t1 where a <= 1 group by col5
union select a as col7, sum(b) as col8 from t2 where b <= 2 group by col7)
select * from cte where c1=1 union select * from cte2 where c3=3;
c1 c2
3 3
prepare st from "with cte (c1,c2) as
(select a as col1, sum(b) as col2 from t1 where a > 1 group by col1
union select a as col3, sum(b) as col4 from t2 where b > 2 group by col3),
cte2 (c3, c4) as
(select a as col5, sum(b) as col6 from t1 where a <= 1 group by col5
union select a as col7, sum(b) as col8 from t2 where b <= 2 group by col7)
select * from cte where c1=1 union select * from cte2 where c3=3";
execute st;
c1 c2
3 3
execute st;
c1 c2
3 3
drop prepare st;
create procedure sp() with cte (c1,c2) as
(select a as col1, sum(b) as col2 from t1 where a > 1 group by col1
union select a as col3, sum(b) as col4 from t2 where b > 2 group by col3),
cte2 (c3, c4) as
(select a as col5, sum(b) as col6 from t1 where a <= 1 group by col5
union select a as col7, sum(b) as col8 from t2 where b <= 2 group by col7)
select * from cte where c1=1 union select * from cte2 where c3=3;
call sp();
c1 c2
3 3
call sp();
c1 c2
3 3
drop procedure sp;
with cte (c1,c2) as (select * from t1)
select cte.c1+1 as col1 , cte.c2 as col2 from cte where cte.c1 > 1
union
select cte.c1 as col3, cte.c2+1 as col4 from cte where cte.c1 < 0;
col1 col2
3 1
3 2
prepare st from "with cte (c1,c2) as (select * from t1)
select cte.c1+1 as col1 , cte.c2 as col2 from cte where cte.c1 > 1
union
select cte.c1 as col3, cte.c2+1 as col4 from cte where cte.c1 < 0";
execute st;
col1 col2
3 1
3 2
execute st;
col1 col2
3 1
3 2
save this to the end to test errors >drop prepare st;
create procedure sp() with cte (c1,c2) as (select * from t1)
select cte.c1+1 as col1 , cte.c2 as col2 from cte where cte.c1 > 1
union
select cte.c1 as col3, cte.c2+1 as col4 from cte where cte.c1 < 0;
call sp();
col1 col2
3 1
3 2
call sp();
col1 col2
3 1
3 2
drop procedure sp;
insert into t1 select * from t2;
with cte (c1, c2)
as (select a, sum(b) from t1 where b > 1 group by a having sum(b) < 5)
select * from cte where c1 < 4 and c2 > 1;
c1 c2
2 2
# Check pushdown conditions in JSON output
explain format=json with cte (c1, c2)
as (select a, sum(b) from t1 where b > 1 group by a having sum(b) < 5)
select * from cte where c1 < 4 and c2 > 1;
EXPLAIN
{
"query_block": {
"select_id": 1,
"cost": "REPLACED",
"nested_loop": [
{
"table": {
"table_name": "<derived2>",
"access_type": "ALL",
"loops": 1,
"rows": 10,
"cost": "REPLACED",
"filtered": 100,
"attached_condition": "cte.c1 < 4 and cte.c2 > 1",
"materialized": {
"query_block": {
"select_id": 2,
"cost": "REPLACED",
"having_condition": "sum(t1.b) < 5 and c2 > 1",
"filesort": {
"sort_key": "t1.a",
"temporary_table": {
"nested_loop": [
{
"table": {
"table_name": "t1",
"access_type": "ALL",
"loops": 1,
"rows": 10,
"cost": "REPLACED",
"filtered": 100,
"attached_condition": "t1.b > 1 and t1.a < 4"
}
}
]
}
}
}
}
}
}
]
}
}
alter table t1 add column c int;
execute st;
ERROR HY000: WITH column list and SELECT field list have different column counts
drop prepare st;
drop table t1,t2;
Test out recursive CTEs
create table distances (src char(1), dest char(1), distance int);
create table city_population (city char(1), population int);
INSERT INTO `distances` VALUES ('A','A',0),('B','A',593),('C','A',800),
('D','A',221),('E','A',707),('F','A',869),('G','A',225),('H','A',519),
('A','B',919),('B','B',0),('C','B',440),('D','B',79),('E','B',79),
('F','B',154),('G','B',537),('H','B',220),('A','C',491),('B','C',794),
('C','C',0),('D','C',100),('E','C',350),('F','C',748),('G','C',712),
('H','C',315),('A','D',440),('B','D',256),('C','D',958),('D','D',0),
('E','D',255),('F','D',161),('G','D',63),('H','D',831),('A','E',968),
('B','E',345),('C','E',823),('D','E',81),('E','E',0),('F','E',436),
('G','E',373),('H','E',558),('A','F',670),('B','F',677),('C','F',375),
('D','F',843),('E','F',90),('F','F',0),('G','F',328),('H','F',881),
('A','G',422),('B','G',467),('C','G',67),('D','G',936),('E','G',480),
('F','G',592),('G','G',0),('H','G',819),('A','H',537),('B','H',229),
('C','H',534),('D','H',984),('E','H',319),('F','H',643),('G','H',257),
('H','H',0);
insert into city_population values ('A', 5000), ('B', 6000), ('C', 100000),
('D', 80000), ('E', 7000), ('F', 1000), ('G', 100), ('H', -80000);
#find the biggest city within 300 kellikams of 'E'
with recursive travel (src, path, dest, distance, population) as (
select city, cast('' as varchar(10)), city,
0, population
from city_population where city='E'
union all
select src.src, concat(src.path, dst.dest), dst.dest,
src.distance + dst.distance, dstc.population
from travel src
join distances dst on src.dest != dst.dest
join city_population dstc on dst.dest = dstc.city
where dst.src = src.dest and src.distance + dst.distance < 300
and length(path) < 10
)
select * from travel where dest != 'E' order by population desc, distance
limit 1;
src path dest distance population
E FD D 251 80000
prepare st from "with recursive travel (src, path, dest, distance, population) as (
select city, cast('' as varchar(10)), city,
0, population
from city_population where city='E'
union all
select src.src, concat(src.path, dst.dest), dst.dest,
src.distance + dst.distance, dstc.population
from travel src
join distances dst on src.dest != dst.dest
join city_population dstc on dst.dest = dstc.city
where dst.src = src.dest and src.distance + dst.distance < 300
and length(path) < 10
)
select * from travel where dest != 'E' order by population desc, distance
limit 1";
execute st;
src path dest distance population
E FD D 251 80000
execute st;
src path dest distance population
E FD D 251 80000
drop prepare st;
create procedure sp() with recursive travel (src, path, dest, distance, population) as (
select city, cast('' as varchar(10)), city,
0, population
from city_population where city='E'
union all
select src.src, concat(src.path, dst.dest), dst.dest,
src.distance + dst.distance, dstc.population
from travel src
join distances dst on src.dest != dst.dest
join city_population dstc on dst.dest = dstc.city
where dst.src = src.dest and src.distance + dst.distance < 300
and length(path) < 10
)
select * from travel where dest != 'E' order by population desc, distance
limit 1;
call sp();
src path dest distance population
E FD D 251 80000
call sp();
src path dest distance population
E FD D 251 80000
drop procedure sp;
drop table distances, city_population;
# End of 10.4 tests

0 comments on commit 5b6134b

Please sign in to comment.