In MySQL, the sys.ps_thread_stack() function returns a JSON formatted stack of all statements, stages, and events within the Performance Schema for a given thread ID.
Syntax
The syntax goes like this:
sys.ps_thread_stack(in_thread_id,in_verbose)
Where in_thread_id is the thread ID to check, and in_verbose is a BOOLEAN (i.e. either TRUE or FALSE) that indicates whether or not to include file:lineno information in the events.
The first argument should match the THREAD_ID column from one of the rows in the performance_schema.threads table.
Example
Here’s an example to demonstrate:
SELECT sys.ps_thread_stack(138, FALSE);
Result:
{
"rankdir": "LR",
"nodesep": "0.10",
"stack_created": "2023-06-15 10:03:11",
"mysql_version": "8.0.29",
"mysql_user": "root@localhost",
"events": []
}
Passing the Wrong Number of Arguments
Passing the wrong number of arguments results in an error:
SELECT sys.ps_thread_stack( 138 );
Result:
ERROR 1318 (42000): Incorrect number of arguments for FUNCTION sys.ps_thread_stack; expected 2, got 1
The same applies when we don’t pass any arguments:
SELECT sys.ps_thread_stack( );
Result:
ERROR 1318 (42000): Incorrect number of arguments for FUNCTION sys.ps_thread_stack; expected 2, got 0