1955
MariaDBERRORNotableStored RoutinesHIGH confidence
Recursive limit exceeded for stored procedure
Production Risk
Medium — procedure fails mid-execution; partial changes may remain.
What this means
A stored procedure exceeded the maximum recursion depth set by max_sp_recursion_depth. By default this value is 0 (no recursion allowed).
Why it happens
- 1Recursive CALL in a stored procedure with max_sp_recursion_depth set too low.
- 2Infinite recursion bug in the stored procedure logic.
How to reproduce
trigger — this will error
trigger — this will error
SET max_sp_recursion_depth = 5; CALL recursive_proc(10); -- exceeds depth of 5
expected output
ERROR 1955 (HY000): Recursive limit 5 (as set by the max_sp_recursion_depth variable) was exceeded for routine recursive_proc.
Fix 1
Increase max_sp_recursion_depth if recursion is intentional
Increase max_sp_recursion_depth if recursion is intentional
SET max_sp_recursion_depth = 20; CALL recursive_proc(10);
Why this works
Raise the depth limit to accommodate the required recursion depth.
Fix 2
Rewrite the procedure iteratively to avoid recursion
Rewrite the procedure iteratively to avoid recursion
-- Use a WHILE loop instead of recursive CALL
Why this works
Iterative approaches avoid the recursion limit entirely.
What not to do
✕
Sources
Official documentation ↗
MySQL 8.0 — 1955 ER_SP_RECURSION_LIMIT
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev