# Recursive CTE hangs - Mandelbrot set calculation

XMLWordPrintable

#### Details

• Type: Bug
• Status: In Progress
• Priority: Major
• Resolution: Unresolved
• Affects Version/s: 10.2, 10.3, 10.4.12, 10.4, 10.5
• Fix Version/s:
• Component/s:
• Labels:

#### Description

I was inspired by this tutorial for SQLite to try the same thing for MariaDB - skip ahead to the "Outlandish Recursive Query Examples" section:
https://infoshri.com/latest-news/the-mandelbrot-set-in-sql/

So I re-wrote the query slightly, just changing the min function to be least so it will run in MariaDB:

 `WITH RECURSIVE` ` xaxis(x) AS (VALUES(-2.0) UNION ALL SELECT x+0.05 FROM xaxis WHERE x<1.2),` ` yaxis(y) AS (VALUES(-1.0) UNION ALL SELECT y+0.1 FROM yaxis WHERE y<1.0),` ` m(iter, cx, cy, x, y) AS (` ` SELECT 0, x, y, 0.0, 0.0 FROM xaxis, yaxis` ` UNION ALL` ` SELECT iter+1, cx, cy, x*x-y*y + cx, 2.0*x*y + cy FROM m ` ` WHERE (x*x + y*y) < 4.0 AND iter<28` ` ),` ` m2(iter, cx, cy) AS (` ` SELECT max(iter), cx, cy FROM m GROUP BY cx, cy` ` ),` ` a(t) AS (` ` SELECT group_concat( substr(' .+*#', 1+least(iter/7,4), 1), '') ` ` FROM m2 GROUP BY cy` ` )` ```SELECT group_concat(rtrim(t),x'0a') FROM a; ```

The query seems to run forever without completing.

I've also tested the query with the most recent MySQL version - 8.0.19, just changing the VALUES to VALUES ROW and setting @@cte_max_recursion_depth to a big number in the query above. The query doesn't seem to complete there either.

#### Attachments

1. mandelbrot_m2_sqlite.txt
30 kB

#### People

Assignee:
Igor Babaev
Reporter:
Karl Levik
Votes:
0 Vote for this issue
Watchers:
3 Start watching this issue

#### Dates

Created:
Updated: