I am doing a very simple update on a table, which also triggers a really simple trigger, and it gives me the error
#1436 - Thread stack overrun: 6136 bytes used of a 131072 byte stack, and 128000 bytes needed.
The query I execute:
UPDATE field_values SET value = 'asaf' WHERE field_values.id =1
The value field is a text field. So in theory it could become quiet big. Which is not the case in this situation.
The trigger that’s getting executed is:
DELIMITER $$
CREATE TRIGGER field_value_update_trigger BEFORE UPDATE ON community_fields_values
FOR EACH ROW BEGIN
INSERT INTO user_field_log (user_id, field_id, value) VALUES (NEW.user_id, NEW.field_id, NEW.value);
END;
$$
DELIMITER ;
Why is this error showing? It’s not like there is any heavy query involved. Also note that the database is almost empty, just 2 rows in community_fields_values and no rows in the user_field_log
MySQL version: 5.1.44
1436 – Thread stack overrun: 6136 bytes used of a 131072 byte stack, and 128000 bytes needed.
The error 1436 corresponds to ER_STACK_OVERRUN_NEED_MORE in the mysql 5.1 code :
The code printing the error seen is in sql/sql_parse.cc,
function check_stack_overrun() :
From the values seen, margin is 128000, and my_thread_stack_size is 131072.
The only call to check_stack_overrun() that tries to reserve 128000 bytes is from:
The value of STACK_MIN_SIZE is 16000:
So far, everything works as expected for the server:
sp_head::execute.
The amount of stack needed by the MySQL trigger execution does not depends on the trigger complexity itself, or the content / structure of the tables involved.
What the real question is, I guess, why is the thread_stack only at 128K (131072).
The server variable named ‘thread_stack’ is implemented in C as ‘my_thread_stack_size’ in sql/mysqld.cc :
1024L*128L is the minimum value for this parameter.
The default value is DEFAULT_THREAD_STACK, which is defined in include/my_pthread.h:
So, by default, the stack size should be 192K (32bits) or 256K (64bits architectures).
First, check how the mysqld binary was compiled, to see what is the default value:
On my system, I got 256K on a 64 bits platform.
If there are different values, maybe someone build the server with different compiling options, such as -DDEFAULT_THREAD_STACK (or just modified the source) … I would question where the binary is coming from in that case.
Second, check my.cnf for default values provided in the configuration file itself.
A line setting a value to thread_stack explicitly (and with a low value) would definitively cause the error seen.
Last, check the server log file for an error such as this (see sql/mysqld.cc) :
The server code calls:
and complains in the log if the pthread library used less.
Long story short, the error is seen because the thread_stack is too small compared to the default values shipped with the server.
This can happen:
options
reading the code, I never have seen it myself).
I hope this answer the question.
Regards,
— Marc Alff
Update (2014-03-11), to make the "how to fix" more obvious.
What is going on, in all likelihood, is that the default value for thread_stack file was changed in the my.cnf file.
How to fix it is trivial then, find where thread_stack is set in the my.cnf file, and either remove the setting (trusting the server code to provide a decent default value, so this does not happen again next time) or increase the stack size.
Update (2021-04-28), check where the thread_stack comes from:
Use table
performance_schema.variables_infoto find out where a given variable comes from.Here the default is the factory value (compiled in the mysqld binary).
Another example:
Here the thread_stack is set in the my.cnf file reported.
Refman:
https://dev.mysql.com/doc/refman/8.0/en/performance-schema-variables-info-table.html