PDF (A4) - 41.3Mb
Man Pages (TGZ) - 262.8Kb
Man Pages (Zip) - 368.8Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb
Thethreads table contains a row for each server thread. Each row contains information about a thread and indicates whether monitoring and historical event logging are enabled for it:
mysql> SELECT * FROM performance_schema.threads\G*************************** 1. row *************************** THREAD_ID: 1 NAME: thread/sql/main TYPE: BACKGROUND PROCESSLIST_ID: NULL PROCESSLIST_USER: NULL PROCESSLIST_HOST: NULL PROCESSLIST_DB: mysql PROCESSLIST_COMMAND: NULL PROCESSLIST_TIME: 418094 PROCESSLIST_STATE: NULL PROCESSLIST_INFO: NULL PARENT_THREAD_ID: NULL ROLE: NULL INSTRUMENTED: YES HISTORY: YES CONNECTION_TYPE: NULL THREAD_OS_ID: 5856 RESOURCE_GROUP: SYS_default EXECUTION_ENGINE: PRIMARY CONTROLLED_MEMORY: 1456MAX_CONTROLLED_MEMORY: 67480 TOTAL_MEMORY: 1270430 MAX_TOTAL_MEMORY: 1307317 TELEMETRY_ACTIVE: NO... When the Performance Schema initializes, it populates thethreads table based on the threads in existence then. Thereafter, a new row is added each time the server creates a thread.
TheINSTRUMENTED andHISTORY column values for new threads are determined by the contents of thesetup_actors table. For information about how to use thesetup_actors table to control these columns, seeSection 29.4.6, “Pre-Filtering by Thread”.
Removal of rows from thethreads table occurs when threads end. For a thread associated with a client session, removal occurs when the session ends. If a client has auto-reconnect enabled and the session reconnects after a disconnect, the session becomes associated with a new row in thethreads table that has a differentPROCESSLIST_ID value. The initialINSTRUMENTED andHISTORY values for the new thread may be different from those of the original thread: Thesetup_actors table may have changed in the meantime, and if theINSTRUMENTED orHISTORY value for the original thread was changed after the row was initialized, the change does not carry over to the new thread.
You can enable or disable thread monitoring (that is, whether events executed by the thread are instrumented) and historical event logging. To control the initialINSTRUMENTED andHISTORY values for new foreground threads, use thesetup_actors table. To control these aspects of existing threads, set theINSTRUMENTED andHISTORY columns ofthreads table rows. (For more information about the conditions under which thread monitoring and historical event logging occur, see the descriptions of theINSTRUMENTED andHISTORY columns.)
For a comparison of thethreads table columns with names having a prefix ofPROCESSLIST_ to other process information sources, seeSources of Process Information.
For thread information sources other than thethreads table, information about threads for other users is shown only if the current user has thePROCESS privilege. That is not true of thethreads table; all rows are shown to any user who has theSELECT privilege for the table. Users who should not be able to see threads for other users by accessing thethreads table should not be given theSELECT privilege for it.
Thethreads table has these columns:
THREAD_IDA unique thread identifier.
NAMEThe name associated with the thread instrumentation code in the server. For example,
thread/sql/one_connectioncorresponds to the thread function in the code responsible for handling a user connection, andthread/sql/mainstands for themain()function of the server.TYPEThe thread type, either
FOREGROUNDorBACKGROUND. User connection threads are foreground threads. Threads associated with internal server activity are background threads. Examples are internalInnoDBthreads,“binlog dump” threads sending information to replicas, and replication I/O and SQL threads.PROCESSLIST_IDFor a foreground thread (associated with a user connection), this is the connection identifier. This is the same value displayed in the
IDcolumn of theINFORMATION_SCHEMAPROCESSLISTtable, displayed in theIdcolumn ofSHOW PROCESSLISToutput, and returned by theCONNECTION_ID()function within the thread.For a background thread (not associated with a user connection),
PROCESSLIST_IDisNULL, so the values are not unique.PROCESSLIST_USERThe user associated with a foreground thread,
NULLfor a background thread.PROCESSLIST_HOSTThe host name of the client associated with a foreground thread,
NULLfor a background thread.Unlike the
HOSTcolumn of theINFORMATION_SCHEMAPROCESSLISTtable or theHostcolumn ofSHOW PROCESSLISToutput, thePROCESSLIST_HOSTcolumn does not include the port number for TCP/IP connections. To obtain this information from the Performance Schema, enable the socket instrumentation (which is not enabled by default) and examine thesocket_instancestable:mysql> SELECT NAME, ENABLED, TIMED FROM performance_schema.setup_instruments WHERE NAME LIKE 'wait/io/socket%';+----------------------------------------+---------+-------+| NAME | ENABLED | TIMED |+----------------------------------------+---------+-------+| wait/io/socket/sql/server_tcpip_socket | NO | NO || wait/io/socket/sql/server_unix_socket | NO | NO || wait/io/socket/sql/client_connection | NO | NO |+----------------------------------------+---------+-------+3 rows in set (0.01 sec)mysql> UPDATE performance_schema.setup_instruments SET ENABLED='YES' WHERE NAME LIKE 'wait/io/socket%';Query OK, 3 rows affected (0.00 sec)Rows matched: 3 Changed: 3 Warnings: 0mysql> SELECT * FROM performance_schema.socket_instances\G*************************** 1. row *************************** EVENT_NAME: wait/io/socket/sql/client_connectionOBJECT_INSTANCE_BEGIN: 140612577298432 THREAD_ID: 31 SOCKET_ID: 53 IP: ::ffff:127.0.0.1 PORT: 55642 STATE: ACTIVE...PROCESSLIST_DBThe default database for the thread, or
NULLif none has been selected.PROCESSLIST_COMMANDFor foreground threads, the type of command the thread is executing on behalf of the client, or
Sleepif the session is idle. For descriptions of thread commands, seeSection 10.14, “Examining Server Thread (Process) Information”. The value of this column corresponds to theCOM_commands of the client/server protocol andxxxCom_status variables. SeeSection 7.1.10, “Server Status Variables”xxxBackground threads do not execute commands on behalf of clients, so this column may be
NULL.PROCESSLIST_TIMEThe time in seconds that the thread has been in its current state. For a replica SQL thread, the value is the number of seconds between the timestamp of the last replicated event and the real time of the replica host. SeeSection 19.2.3, “Replication Threads”.
PROCESSLIST_STATEAn action, event, or state that indicates what the thread is doing. For descriptions of
PROCESSLIST_STATEvalues, seeSection 10.14, “Examining Server Thread (Process) Information”. If the value ifNULL, the thread may correspond to an idle client session or the work it is doing is not instrumented with stages.Most states correspond to very quick operations. If a thread stays in a given state for many seconds, there might be a problem that bears investigation.
PROCESSLIST_INFOThe statement the thread is executing, or
NULLif it is executing no statement. The statement might be the one sent to the server, or an innermost statement if the statement executes other statements. For example, if aCALLstatement executes a stored procedure that is executing aSELECTstatement, thePROCESSLIST_INFOvalue shows theSELECTstatement.PARENT_THREAD_IDIf this thread is a subthread (spawned by another thread), this is the
THREAD_IDvalue of the spawning thread.ROLEUnused.
INSTRUMENTEDWhether events executed by the thread are instrumented. The value is
YESorNO.For foreground threads, the initial
INSTRUMENTEDvalue is determined by whether the user account associated with the thread matches any row in thesetup_actorstable. Matching is based on the values of thePROCESSLIST_USERandPROCESSLIST_HOSTcolumns.If the thread spawns a subthread, matching occurs again for the
threadstable row created for the subthread.For background threads,
INSTRUMENTEDisYESby default.setup_actorsis not consulted because there is no associated user for background threads.For any thread, its
INSTRUMENTEDvalue can be changed during the lifetime of the thread.
For monitoring of events executed by the thread to occur, these things must be true:
The
thread_instrumentationconsumer in thesetup_consumerstable must beYES.The
threads.INSTRUMENTEDcolumn must beYES.Monitoring occurs only for those thread events produced from instruments that have the
ENABLEDcolumn set toYESin thesetup_instrumentstable.
HISTORYWhether to log historical events for the thread. The value is
YESorNO.For foreground threads, the initial
HISTORYvalue is determined by whether the user account associated with the thread matches any row in thesetup_actorstable. Matching is based on the values of thePROCESSLIST_USERandPROCESSLIST_HOSTcolumns.If the thread spawns a subthread, matching occurs again for the
threadstable row created for the subthread.For background threads,
HISTORYisYESby default.setup_actorsis not consulted because there is no associated user for background threads.For any thread, its
HISTORYvalue can be changed during the lifetime of the thread.
For historical event logging for the thread to occur, these things must be true:
The appropriate history-related consumers in the
setup_consumerstable must be enabled. For example, wait event logging in theevents_waits_historyandevents_waits_history_longtables requires the correspondingevents_waits_historyandevents_waits_history_longconsumers to beYES.The
threads.HISTORYcolumn must beYES.Logging occurs only for those thread events produced from instruments that have the
ENABLEDcolumn set toYESin thesetup_instrumentstable.
CONNECTION_TYPEThe protocol used to establish the connection, or
NULLfor background threads. Permitted values areTCP/IP(TCP/IP connection established without encryption),SSL/TLS(TCP/IP connection established with encryption),Socket(Unix socket file connection),Named Pipe(Windows named pipe connection), andShared Memory(Windows shared memory connection).THREAD_OS_IDThe thread or task identifier as defined by the underlying operating system, if there is one:
When a MySQL thread is associated with the same operating system thread for its lifetime,
THREAD_OS_IDcontains the operating system thread ID.When a MySQL thread is not associated with the same operating system thread for its lifetime,
THREAD_OS_IDcontainsNULL. This is typical for user sessions when the thread pool plugin is used (seeSection 7.6.3, “MySQL Enterprise Thread Pool”).
For Windows,
THREAD_OS_IDcorresponds to the thread ID visible in Process Explorer (https://technet.microsoft.com/en-us/sysinternals/bb896653.aspx).For Linux,
THREAD_OS_IDcorresponds to the value of thegettid()function. This value is exposed, for example, using theperf orps -L commands, or in theprocfile system (/proc/). For more information, see the[pid]/task/[tid]perf-stat(1),ps(1), andproc(5)man pages.RESOURCE_GROUPThe resource group label. This value is
NULLif resource groups are not supported on the current platform or server configuration (seeResource Group Restrictions).EXECUTION_ENGINEThe query execution engine. The value is either
PRIMARYorSECONDARY. For use with MySQL HeatWave Service and MySQL HeatWave, where thePRIMARYengine isInnoDBand theSECONDARYengine is MySQL HeatWave (RAPID). For MySQL Community Edition Server, MySQL Enterprise Edition Server (on-premise), and MySQL HeatWave Service without MySQL HeatWave, the value is alwaysPRIMARY.CONTROLLED_MEMORYAmount of controlled memory used by the thread.
MAX_CONTROLLED_MEMORYMaximum value of
CONTROLLED_MEMORYseen during the thread execution.TOTAL_MEMORYThe current amount of memory, controlled or not, used by the thread.
MAX_TOTAL_MEMORYThe maximum value of
TOTAL_MEMORYseen during the thread execution.TELEMETRY_ACTIVEWhether the thread has an active telemetry seesion attached. The value is
YESorNO.
Thethreads table has these indexes:
Primary key on (
THREAD_ID)Index on (
NAME)Index on (
PROCESSLIST_ID)Index on (
PROCESSLIST_USER,PROCESSLIST_HOST)Index on (
PROCESSLIST_HOST)Index on (
THREAD_OS_ID)Index on (
RESOURCE_GROUP)
TRUNCATE TABLE is not permitted for thethreads table.
PDF (A4) - 41.3Mb
Man Pages (TGZ) - 262.8Kb
Man Pages (Zip) - 368.8Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb