1460
MySQLERRORNotableServerHIGH confidence

Thread stack overrun — insufficient stack space

Production Risk

High — the query/routine will fail; server may need reconfiguration.

What this means

ER_STACK_OVERRUN_NEED_MORE (1460, SQLSTATE HY000) is raised when a MySQL thread exhausts its allocated stack space, typically caused by deeply nested stored procedure calls or complex recursive logic.

Why it happens
  1. 1Deeply nested stored procedure calls exceeding thread_stack size
  2. 2Recursive stored procedures with insufficient stack allocation
  3. 3thread_stack set too small for complex stored routines
How to reproduce
trigger — this will error
trigger — this will error
-- A deeply recursive stored procedure:
CALL recursive_proc(10000);  -- Too deep

expected output

ERROR 1460 (HY000): Thread stack overrun: 8192 bytes used of a 131072 byte stack, and 16384 bytes needed. Use 'mysqld --thread_stack=#' to specify a bigger stack.

Fix 1

Increase thread_stack in configuration

Increase thread_stack in configuration
-- In my.cnf:
-- thread_stack = 512K

-- Or check current value:
SHOW VARIABLES LIKE 'thread_stack';

Why this works

A larger thread_stack allows deeper call chains in stored procedures.

Fix 2

Reduce recursion depth

Reduce recursion depth
SET max_sp_recursion_depth = 10;  -- Limit recursion
-- Rewrite recursive logic as iterative using loops

Why this works

Limiting recursion depth prevents stack overruns from excessively deep call chains.

Sources
Official documentation ↗

MySQL 8.0 — 1460 ER_STACK_OVERRUN_NEED_MORE

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MySQL errors