Msg 530: The statement terminated. The maximum recursion 100 has been exhausted before statement completion. / MySQL 3636 Recursive query aborted after 1001 iterations
A recursive CTE exceeded the database’s recursion limit — often an infinite loop in hierarchical data.
The maximum recursion 100 has been exhaustedRecursive query aborted after Meaning
Cycles in parent/child data (a node that is its own ancestor) or missing termination conditions make recursion endless.
Common causes
- Cycle in hierarchical data
- Missing stop condition in the recursive part
- Legitimately deep hierarchies over the default limit
⚡ Quick fix
- Detect cycles (track visited ids/path)
- Add a depth limit column
- Raise the limit (OPTION (MAXRECURSION n), cte_max_recursion_depth) only for legitimate depth
Detailed fix by platform
SQL
WITH RECURSIVE t AS (SELECT id, parent_id, 1 depth FROM nodes WHERE id = 1 UNION ALL SELECT n.id, n.parent_id, t.depth + 1 FROM nodes n JOIN t ON n.parent_id = t.id WHERE t.depth < 50) SELECT * FROM t;
How to diagnose
- Data — Any cycles?
- Depth — Expected maximum?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- 1136 MySQL ERROR 1136 (21S01): Column count doesn't match value count at row 1
- aggregate in WHERE ERROR: aggregate functions are not allowed in WHERE (use HAVING) / MySQL 1111 Invalid use of group function
- GROUP BY Column must appear in the GROUP BY clause / isn't in GROUP BY (MySQL 1055 only_full_group_by)
Most viewed in SQL
Other ways to find it
Where this error sits
Origin: Data. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 12 Oct 2026