Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
046d442d
Commit
046d442d
authored
Mar 27, 2017
by
Vladislav Vaintroub
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '10.2' of
https://github.com/mariadb/server
into 10.2
parents
d3f82e3a
ad7da60d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
169 additions
and
3 deletions
+169
-3
mysql-test/r/cte_recursive.result
mysql-test/r/cte_recursive.result
+80
-0
mysql-test/t/cte_recursive.test
mysql-test/t/cte_recursive.test
+81
-0
sql/sql_cte.cc
sql/sql_cte.cc
+2
-0
sql/sql_derived.cc
sql/sql_derived.cc
+6
-3
No files found.
mysql-test/r/cte_recursive.result
View file @
046d442d
...
...
@@ -2408,3 +2408,83 @@ ANALYZE
}
}
}
#
# mdev-12360: recursive reference in left operand of LEFT JOIN
#
create table folks(id int, name char(32), dob date, father int, mother int);
insert into folks values
(100, 'Me', '2000-01-01', 20, 30),
(20, 'Dad', '1970-02-02', 10, 9),
(30, 'Mom', '1975-03-03', 8, 7),
(10, 'Grandpa Bill', '1940-04-05', null, null),
(9, 'Grandma Ann', '1941-10-15', null, null),
(25, 'Uncle Jim', '1968-11-18', 8, 7),
(98, 'Sister Amy', '2001-06-20', 20, 30),
(7, 'Grandma Sally', '1943-08-23', null, 6),
(8, 'Grandpa Ben', '1940-10-21', null, null),
(6, 'Grandgrandma Martha', '1923-05-17', null, null),
(67, 'Cousin Eddie', '1992-02-28', 25, 27),
(27, 'Auntie Melinda', '1971-03-29', null, null);
with recursive
ancestor_ids (id)
as
(
select father from folks where name = 'Me'
union
select mother from folks where name = 'Me'
union
select father from ancestor_ids as a left join folks on folks.id = a.id
union
select mother from ancestor_ids as a left join folks on folks.id = a.id
),
ancestors
as
(
select p.* from folks as p, ancestor_ids as a
where p.id = a.id
)
select * from ancestors;
id name dob father mother
20 Dad 1970-02-02 10 9
30 Mom 1975-03-03 8 7
10 Grandpa Bill 1940-04-05 NULL NULL
9 Grandma Ann 1941-10-15 NULL NULL
7 Grandma Sally 1943-08-23 NULL 6
8 Grandpa Ben 1940-10-21 NULL NULL
6 Grandgrandma Martha 1923-05-17 NULL NULL
drop table folks;
#
# mdev-12368: crash with mutually recursive CTE
# that arenot Standard compliant
#
create table value_nodes (v char(4));
create table module_nodes(m char(4));
create table module_arguments(m char(4), v char(4));
create table module_results(m char(4), v char(4));
with recursive
reached_values as
(
select v from value_nodes where v in ('v3','v7','v9')
union
select module_results.v from module_results, applied_modules
where module_results.m = applied_modules.m
),
applied_modules as
(
select module_nodes.m
from
module_nodes
left join
(
module_arguments
left join
reached_values
on module_arguments.v = reached_values.v
)
on reached_values.v is null and
module_nodes.m = module_arguments.m
where module_arguments.m is null
)
select * from reached_values;
ERROR HY000: Restrictions imposed on recursive definitions are violated for table 'applied_modules'
drop table value_nodes, module_nodes, module_arguments, module_results;
mysql-test/t/cte_recursive.test
View file @
046d442d
...
...
@@ -1517,3 +1517,84 @@ with recursive src(counter) as
union
select
counter
+
1
from
src
where
counter
<
10
)
select
*
from
src
;
--
echo
#
--
echo
# mdev-12360: recursive reference in left operand of LEFT JOIN
--
echo
#
create
table
folks
(
id
int
,
name
char
(
32
),
dob
date
,
father
int
,
mother
int
);
insert
into
folks
values
(
100
,
'Me'
,
'2000-01-01'
,
20
,
30
),
(
20
,
'Dad'
,
'1970-02-02'
,
10
,
9
),
(
30
,
'Mom'
,
'1975-03-03'
,
8
,
7
),
(
10
,
'Grandpa Bill'
,
'1940-04-05'
,
null
,
null
),
(
9
,
'Grandma Ann'
,
'1941-10-15'
,
null
,
null
),
(
25
,
'Uncle Jim'
,
'1968-11-18'
,
8
,
7
),
(
98
,
'Sister Amy'
,
'2001-06-20'
,
20
,
30
),
(
7
,
'Grandma Sally'
,
'1943-08-23'
,
null
,
6
),
(
8
,
'Grandpa Ben'
,
'1940-10-21'
,
null
,
null
),
(
6
,
'Grandgrandma Martha'
,
'1923-05-17'
,
null
,
null
),
(
67
,
'Cousin Eddie'
,
'1992-02-28'
,
25
,
27
),
(
27
,
'Auntie Melinda'
,
'1971-03-29'
,
null
,
null
);
with
recursive
ancestor_ids
(
id
)
as
(
select
father
from
folks
where
name
=
'Me'
union
select
mother
from
folks
where
name
=
'Me'
union
select
father
from
ancestor_ids
as
a
left
join
folks
on
folks
.
id
=
a
.
id
union
select
mother
from
ancestor_ids
as
a
left
join
folks
on
folks
.
id
=
a
.
id
),
ancestors
as
(
select
p
.*
from
folks
as
p
,
ancestor_ids
as
a
where
p
.
id
=
a
.
id
)
select
*
from
ancestors
;
drop
table
folks
;
--
echo
#
--
echo
# mdev-12368: crash with mutually recursive CTE
--
echo
# that arenot Standard compliant
--
echo
#
create
table
value_nodes
(
v
char
(
4
));
create
table
module_nodes
(
m
char
(
4
));
create
table
module_arguments
(
m
char
(
4
),
v
char
(
4
));
create
table
module_results
(
m
char
(
4
),
v
char
(
4
));
--
ERROR
ER_NOT_STANDARD_COMPLIANT_RECURSIVE
with
recursive
reached_values
as
(
select
v
from
value_nodes
where
v
in
(
'v3'
,
'v7'
,
'v9'
)
union
select
module_results
.
v
from
module_results
,
applied_modules
where
module_results
.
m
=
applied_modules
.
m
),
applied_modules
as
(
select
module_nodes
.
m
from
module_nodes
left
join
(
module_arguments
left
join
reached_values
on
module_arguments
.
v
=
reached_values
.
v
)
on
reached_values
.
v
is
null
and
module_nodes
.
m
=
module_arguments
.
m
where
module_arguments
.
m
is
null
)
select
*
from
reached_values
;
drop
table
value_nodes
,
module_nodes
,
module_arguments
,
module_results
;
\ No newline at end of file
sql/sql_cte.cc
View file @
046d442d
...
...
@@ -1168,6 +1168,8 @@ bool With_element::check_unrestricted_recursive(st_select_lex *sel,
ti
.
rewind
();
while
((
tbl
=
ti
++
))
{
if
(
!
tbl
->
is_with_table_recursive_reference
())
continue
;
for
(
TABLE_LIST
*
tab
=
tbl
;
tab
;
tab
=
tab
->
embedding
)
{
if
(
tab
->
outer_join
&
(
JOIN_TYPE_LEFT
|
JOIN_TYPE_RIGHT
))
...
...
sql/sql_derived.cc
View file @
046d442d
...
...
@@ -789,9 +789,12 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived)
*/
if
(
res
)
{
if
(
derived
->
table
&&
!
derived
->
is_with_table_recursive_reference
())
free_tmp_table
(
thd
,
derived
->
table
);
delete
derived
->
derived_result
;
if
(
!
derived
->
is_with_table_recursive_reference
())
{
if
(
derived
->
table
)
free_tmp_table
(
thd
,
derived
->
table
);
delete
derived
->
derived_result
;
}
}
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment