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
56d3a0e7
Commit
56d3a0e7
authored
Dec 07, 2018
by
Sergei Golubchik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-17967 Add a solution of the 8 queens problem to the regression test for CTE
parent
ac31ff62
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
0 deletions
+72
-0
mysql-test/main/cte_recursive.result
mysql-test/main/cte_recursive.result
+38
-0
mysql-test/main/cte_recursive.test
mysql-test/main/cte_recursive.test
+34
-0
No files found.
mysql-test/main/cte_recursive.result
View file @
56d3a0e7
...
@@ -1608,6 +1608,44 @@ id name dob father mother
...
@@ -1608,6 +1608,44 @@ id name dob father mother
8 Grandpa Ben 1940-10-21 NULL NULL
8 Grandpa Ben 1940-10-21 NULL NULL
6 Grandgrandma Martha 1923-05-17 NULL NULL
6 Grandgrandma Martha 1923-05-17 NULL NULL
drop table my_ancestors;
drop table my_ancestors;
WITH RECURSIVE
positions(i) AS (
VALUES(0)
UNION SELECT ALL
i+1 FROM positions WHERE i < 4*4-1
),
solutions(board, n_queens) AS (
SELECT REPEAT('-', 4*4), 0
FROM positions
UNION
SELECT
concat(substr(board, 1, i),'*',substr(board, i+2)),n_queens + 1 AS n_queens
FROM positions AS ps, solutions
WHERE n_queens < 4
AND substr(board,1,i) != '*'
AND NOT EXISTS (
SELECT 1 FROM positions WHERE
substr(board,i+1,1) = '*' AND
(
i % 4 = ps.i % 4 OR
i div 4 = ps.i div 4 OR
i div 4 + (i % 4) = ps.i div 4 + (ps.i % 4) OR
i div 4 - (i % 4) = ps.i div 4 - (ps.i % 4)
)
)
)
SELECT regexp_replace(board,concat('(',REPEAT('.', 4),')'),'\\1\n') n_queens FROM solutions WHERE n_queens = 4;
n_queens
-*--
---*
*---
--*-
--*-
*---
---*
-*--
#
#
#
MDEV-10883: execution of prepared statement from SELECT
#
MDEV-10883: execution of prepared statement from SELECT
#
with recursive CTE that renames columns
#
with recursive CTE that renames columns
...
...
mysql-test/main/cte_recursive.test
View file @
56d3a0e7
...
@@ -1200,6 +1200,40 @@ select * from my_ancestors;
...
@@ -1200,6 +1200,40 @@ select * from my_ancestors;
drop
table
my_ancestors
;
drop
table
my_ancestors
;
#
# MDEV-17967 Add a solution of the 8 queens problem to the regression test for CTE
#
# adapted to MariaDB from https://rosettacode.org/wiki/N-queens_problem#SQL
#
let
$N
=
4
;
# 8 takes too long for a test
eval
WITH
RECURSIVE
positions
(
i
)
AS
(
VALUES
(
0
)
UNION
SELECT
ALL
i
+
1
FROM
positions
WHERE
i
<
$N
*
$N
-
1
),
solutions
(
board
,
n_queens
)
AS
(
SELECT
REPEAT
(
'-'
,
$N
*
$N
),
0
FROM
positions
UNION
SELECT
concat
(
substr
(
board
,
1
,
i
),
'*'
,
substr
(
board
,
i
+
2
)),
n_queens
+
1
AS
n_queens
FROM
positions
AS
ps
,
solutions
WHERE
n_queens
<
$N
AND
substr
(
board
,
1
,
i
)
!=
'*'
AND
NOT
EXISTS
(
SELECT
1
FROM
positions
WHERE
substr
(
board
,
i
+
1
,
1
)
=
'*'
AND
(
i
%
$N
=
ps
.
i
%
$N
OR
i
div
$N
=
ps
.
i
div
$N
OR
i
div
$N
+
(
i
%
$N
)
=
ps
.
i
div
$N
+
(
ps
.
i
%
$N
)
OR
i
div
$N
-
(
i
%
$N
)
=
ps
.
i
div
$N
-
(
ps
.
i
%
$N
)
)
)
)
SELECT
regexp_replace
(
board
,
concat
(
'('
,
REPEAT
(
'.'
,
$N
),
')'
),
'\\\\1\\n'
)
n_queens
FROM
solutions
WHERE
n_queens
=
$N
;
--
echo
#
--
echo
#
--
echo
# MDEV-10883: execution of prepared statement from SELECT
--
echo
# MDEV-10883: execution of prepared statement from SELECT
--
echo
# with recursive CTE that renames columns
--
echo
# with recursive CTE that renames columns
...
...
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