content_image/704530.jpg content_image/704531.jpg
PS_CURRENT_THREAD_ID()  was added in MySQL 8.0.16. It may be used as a shortcut for invoking the sys  schema ps_thread_id()  function with an argument of NULL  or CONNECTION_ID() . 

• PS_THREAD_ID( connection_id ) 

Given a connection ID, returns a BIGINT UNSIGNED  value representing the Performance Schema thread ID assigned to the connection ID, or NULL  if no thread ID exists for the connection ID. The latter can occur for threads that are not instrumented. 

The connection ID argument is a value of the type given in the PROCESSLIST_ID  column of the Performance Schema threads  table or the Id  column of SHOW PROCESSLIST  output. 

The thread ID return value is a value of the type given in the THREAD_ID  column of Performance Schema tables. 

Performance Schema configuration affects PS_THREAD_ID()  operation as follows. (These remarks also apply to PS_CURRENT_THREAD_ID() .) 

•Disabling the thread_instrumentation  consumer disables statistics from being collected and aggregated at the thread level, but has no effect on PS_THREAD_ID() . 

•If performance_schema_max_thread_instances  is not 0, the Performance Schema allocates memory for thread statistics and assigns an internal ID to each thread for which instance memory is available. If there are threads for which instance memory is not available, PS_THREAD_ID()  returns NULL ; in this case, Performance_schema_thread_instances_lost  is nonzero. 

•If performance_schema_max_thread_instances  is 0, the Performance Schema allocates no thread memory and PS_THREAD_ID()  returns NULL . 

•If the Performance Schema itself is disabled, PS_THREAD_ID()  produces an error. 

mysql> SELECT PS_THREAD_ID(6); 

<img src='content_image/704530.jpg'>

PS_THREAD_ID()  was added in MySQL 8.0.16. It may be used instead of the sys  schema ps_thread_id()  function, keeping in mind this difference: 

•With an argument of NULL , sys.ps_thread_id()  returns the thread ID for the current connection, whereas PS_THREAD_ID()  returns NULL . To obtain the current connection thread ID, use PS_CURRENT_THREAD_ID()  instead. 

## 12.23 Internal Functions 

<img src='content_image/704531.jpg'>

