{"id":30988,"date":"2023-07-11T10:58:03","date_gmt":"2023-07-11T00:58:03","guid":{"rendered":"https:\/\/database.guide\/?p=30988"},"modified":"2023-07-12T11:46:29","modified_gmt":"2023-07-12T01:46:29","slug":"understanding-the-sys-ps_thread_stack-function-in-mysql","status":"publish","type":"post","link":"https:\/\/database.guide\/understanding-the-sys-ps_thread_stack-function-in-mysql\/","title":{"rendered":"Introduction to the sys.ps_thread_stack()\u00a0Function in MySQL"},"content":{"rendered":"\n<p>In MySQL, the <code>sys.ps_thread_stack()<\/code>&nbsp;function returns a JSON formatted stack of all statements, stages, and events within the Performance Schema for a given thread ID.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">Syntax<\/h2>\n\n\n\n<p>The syntax goes like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sys.ps_thread_stack(in_thread_id,in_verbose)<\/code><\/pre>\n\n\n\n<p>Where <em><code>in_thread_id<\/code><\/em> is the thread ID to check, and <em><code>in_verbose<\/code><\/em> is a <code>BOOLEAN<\/code> (i.e. either <code>TRUE<\/code> or <code>FALSE<\/code>) that indicates whether or not to include&nbsp;<code>file:lineno<\/code>&nbsp;information in the events.<\/p>\n\n\n\n<p>The first argument should match the <code>THREAD_ID<\/code> column from one of the rows in the <code>performance_schema.threads<\/code> table.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example<\/h2>\n\n\n\n<p>Here&#8217;s an example to demonstrate:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT sys.ps_thread_stack(138, FALSE);<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{\n    \"rankdir\": \"LR\",\n    \"nodesep\": \"0.10\",\n    \"stack_created\": \"2023-06-15 10:03:11\",\n    \"mysql_version\": \"8.0.29\",\n    \"mysql_user\": \"root@localhost\",\n    \"events\": []\n}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Passing the Wrong Number of Arguments<\/h2>\n\n\n\n<p>Passing the wrong number of arguments results in an error:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT sys.ps_thread_stack( 138 );<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ERROR 1318 (42000): Incorrect number of arguments for FUNCTION sys.ps_thread_stack; expected 2, got 1<\/pre>\n\n\n\n<p>The same applies when we don&#8217;t pass any arguments:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT sys.ps_thread_stack( );<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ERROR 1318 (42000): Incorrect number of arguments for FUNCTION sys.ps_thread_stack; expected 2, got 0<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In MySQL, the sys.ps_thread_stack()&nbsp;function returns a JSON formatted stack of all statements, stages, and events within the Performance Schema for a given thread ID.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[93,74,20],"class_list":["post-30988","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-functions","tag-system-functions","tag-what-is"],"_links":{"self":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/30988","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/comments?post=30988"}],"version-history":[{"count":5,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/30988\/revisions"}],"predecessor-version":[{"id":31365,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/30988\/revisions\/31365"}],"wp:attachment":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/media?parent=30988"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/categories?post=30988"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/tags?post=30988"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}