Rechercher dans le manuel MySQL

26.12.17.5 The threads Table

The threads 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:

  1. mysql> SELECT * FROM performance_schema.threads\G
  2. *************************** 1. row ***************************
  3.           THREAD_ID: 1
  4.                NAME: thread/sql/main
  5.                TYPE: BACKGROUND
  6.      PROCESSLIST_ID: NULL
  7.    PROCESSLIST_USER: NULL
  8.    PROCESSLIST_HOST: NULL
  9.      PROCESSLIST_DB: NULL
  10. PROCESSLIST_COMMAND: NULL
  11.    PROCESSLIST_TIME: 80284
  12.   PROCESSLIST_STATE: NULL
  13.    PROCESSLIST_INFO: NULL
  14.    PARENT_THREAD_ID: NULL
  15.                ROLE: NULL
  16.        INSTRUMENTED: YES
  17.             HISTORY: YES
  18.     CONNECTION_TYPE: NULL
  19.        THREAD_OS_ID: 489803
  20.      RESOURCE_GROUP: SYS_default
  21. ...
  22. *************************** 4. row ***************************
  23.           THREAD_ID: 51
  24.                NAME: thread/sql/one_connection
  25.                TYPE: FOREGROUND
  26.      PROCESSLIST_ID: 34
  27.    PROCESSLIST_USER: isabella
  28.    PROCESSLIST_HOST: localhost
  29.      PROCESSLIST_DB: performance_schema
  30. PROCESSLIST_COMMAND: Query
  31.    PROCESSLIST_TIME: 0
  32.   PROCESSLIST_STATE: Sending data
  33.    PROCESSLIST_INFO: SELECT * FROM performance_schema.threads
  34.    PARENT_THREAD_ID: 1
  35.                ROLE: NULL
  36.        INSTRUMENTED: YES
  37.             HISTORY: YES
  38.     CONNECTION_TYPE: SSL/TLS
  39.        THREAD_OS_ID: 755399
  40.      RESOURCE_GROUP: USR_default
  41. ...

When the Performance Schema initializes, it populates the threads table based on the threads in existence then. Thereafter, a new row is added each time the server creates a thread.

The INSTRUMENTED and HISTORY column values for new threads are determined by the contents of the setup_actors table. For information about how to use the setup_actors table to control these columns, see Section 26.4.6, “Pre-Filtering by Thread”.

Removal of rows from the threads 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 the threads table that has a different PROCESSLIST_ID value. The initial INSTRUMENTED and HISTORY values for the new thread may be different from those of the original thread: The setup_actors table may have changed in the meantime, and if the INSTRUMENTED or HISTORY value for the original thread was changed after the row was initialized, the change does not carry over to the new thread.

The threads table columns with names having a prefix of PROCESSLIST_ provide information similar to that available from the INFORMATION_SCHEMA.PROCESSLIST table or the SHOW PROCESSLIST statement. Thus, all three sources provide thread-monitoring information. Use of threads differs from use of the other two sources in these ways:

  • Access to threads does not require a mutex and has minimal impact on server performance. INFORMATION_SCHEMA.PROCESSLIST and SHOW PROCESSLIST have negative performance consequences because they require a mutex.

  • threads provides additional information for each thread, such as whether it is a foreground or background thread, and the location within the server associated with the thread.

  • threads provides information about background threads, so it can be used to monitor activity the other thread information sources cannot.

  • You can enable or disable thread monitoring (that is, whether events executed by the thread are instrumented) and historical event logging. To control the initial INSTRUMENTED and HISTORY values for new foreground threads, use the setup_actors table. To control these aspects of existing threads, set the INSTRUMENTED and HISTORY columns of threads table rows. (For more information about the conditions under which thread monitoring and historical event logging occur, see the descriptions of the INSTRUMENTED and HISTORY columns.)

For these reasons, DBAs who perform server monitoring using INFORMATION_SCHEMA.PROCESSLIST or SHOW PROCESSLIST may wish to monitor using the threads table instead.

Note

For INFORMATION_SCHEMA.PROCESSLIST and SHOW PROCESSLIST, information about threads for other users is shown only if the current user has the PROCESS privilege. That is not true of the threads table; all rows are shown to any user who has the SELECT privilege for the table. Users who should not be able to see threads for other users should not be given that privilege.

The threads table has these columns:

  • THREAD_ID

    A unique thread identifier.

  • NAME

    The name associated with the thread instrumentation code in the server. For example, thread/sql/one_connection corresponds to the thread function in the code responsible for handling a user connection, and thread/sql/main stands for the main() function of the server.

  • TYPE

    The thread type, either FOREGROUND or BACKGROUND. User connection threads are foreground threads. Threads associated with internal server activity are background threads. Examples are internal InnoDB threads, binlog dump threads sending information to slaves, and slave I/O and SQL threads.

  • PROCESSLIST_ID

    For threads that are displayed in the INFORMATION_SCHEMA.PROCESSLIST table, this is the same value displayed in the ID column of that table. It is also the value displayed in the Id column of SHOW PROCESSLIST output, and the value that CONNECTION_ID() would return within that thread.

    For background threads (threads not associated with a user connection), PROCESSLIST_ID is NULL, so the values are not unique.

  • PROCESSLIST_USER

    The user associated with a foreground thread, NULL for a background thread.

  • PROCESSLIST_HOST

    The host name of the client associated with a foreground thread, NULL for a background thread.

    Unlike the HOST column of the INFORMATION_SCHEMA PROCESSLIST table or the Host column of SHOW PROCESSLIST output, the PROCESSLIST_HOST column 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 the socket_instances table:

    1. mysql> SELECT NAME, ENABLED, TIMED
    2.        FROM performance_schema.setup_instruments
    3.        WHERE NAME LIKE 'wait/io/socket%';
    4. +----------------------------------------+---------+-------+
    5. | NAME                                   | ENABLED | TIMED |
    6. +----------------------------------------+---------+-------+
    7. | wait/io/socket/sql/server_tcpip_socket | NO      | NO    |
    8. | wait/io/socket/sql/server_unix_socket  | NO      | NO    |
    9. | wait/io/socket/sql/client_connection   | NO      | NO    |
    10. +----------------------------------------+---------+-------+
    11. 3 rows in set (0.01 sec)
    12.  
    13. mysql> UPDATE performance_schema.setup_instruments
    14.        SET ENABLED='YES'
    15.        WHERE NAME LIKE 'wait/io/socket%';
    16. Query OK, 3 rows affected (0.00 sec)
    17. Rows matched: 3  Changed: 3  Warnings: 0
    18.  
    19. mysql> SELECT * FROM performance_schema.socket_instances\G
    20. *************************** 1. row ***************************
    21.            EVENT_NAME: wait/io/socket/sql/client_connection
    22. OBJECT_INSTANCE_BEGIN: 140612577298432
    23.             THREAD_ID: 31
    24.             SOCKET_ID: 53
    25.                    IP: ::ffff:127.0.0.1
    26.                  PORT: 55642
    27.                 STATE: ACTIVE
    28. ...
  • PROCESSLIST_DB

    The default database for the thread, or NULL if there is none.

  • PROCESSLIST_COMMAND

    For foreground threads, the type of command the thread is executing on behalf of the client, or Sleep if the session is idle. For descriptions of thread commands, see Section 8.14, “Examining Thread Information”. The value of this column corresponds to the COM_xxx commands of the client/server protocol and Com_xxx status variables. See Section 5.1.10, “Server Status Variables”

    Background threads do not execute commands on behalf of clients, so this column may be NULL.

  • PROCESSLIST_TIME

    The time in seconds that the thread has been in its current state.

  • PROCESSLIST_STATE

    An action, event, or state that indicates what the thread is doing. For descriptions of PROCESSLIST_STATE values, see Section 8.14, “Examining Thread Information”. If the value if NULL, 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_INFO

    The statement the thread is executing, or NULL if it is not executing any statement. The statement might be the one sent to the server, or an innermost statement if the statement executes other statements. For example, if a CALL statement executes a stored procedure that is executing a SELECT statement, the PROCESSLIST_INFO value shows the SELECT statement.

  • PARENT_THREAD_ID

    If this thread is a subthread (spawned by another thread), this is the THREAD_ID value of the spawning thread.

  • ROLE

    Unused.

  • INSTRUMENTED

    Whether events executed by the thread are instrumented. The value is YES or NO.

    • For foreground threads, the initial INSTRUMENTED value is determined by whether the user account associated with the thread matches any row in the setup_actors table. Matching is based on the values of the PROCESSLIST_USER and PROCESSLIST_HOST columns.

      If the thread spawns a subthread, matching occurs again for the threads table row created for the subthread.

    • For background threads, INSTRUMENTED is YES by default. setup_actors is not consulted because there is no associated user for background threads.

    • For any thread, its INSTRUMENTED value 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_instrumentation consumer in the setup_consumers table must be YES.

    • The threads.INSTRUMENTED column must be YES.

    • Monitoring occurs only for those thread events produced from instruments that have the ENABLED column set to YES in the setup_instruments table.

  • HISTORY

    Whether to log historical events for the thread. The value is YES or NO.

    • For foreground threads, the initial HISTORY value is determined by whether the user account associated with the thread matches any row in the setup_actors table. Matching is based on the values of the PROCESSLIST_USER and PROCESSLIST_HOST columns.

      If the thread spawns a subthread, matching occurs again for the threads table row created for the subthread.

    • For background threads, HISTORY is YES by default. setup_actors is not consulted because there is no associated user for background threads.

    • For any thread, its HISTORY value 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_consumers table must be enabled. For example, wait event logging in the events_waits_history and events_waits_history_long tables requires the corresponding events_waits_history and events_waits_history_long consumers to be YES.

    • The threads.HISTORY column must be YES.

    • Logging occurs only for those thread events produced from instruments that have the ENABLED column set to YES in the setup_instruments table.

  • CONNECTION_TYPE

    The protocol used to establish the connection, or NULL for background threads. Permitted values are TCP/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), and Shared Memory (Windows shared memory connection).

  • THREAD_OS_ID

    The 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_ID contains the operating system thread ID.

    • When a MySQL thread is not associated with the same operating system thread for its lifetime, THREAD_OS_ID contains NULL. This is typical for user sessions when the thread pool plugin is used (see Section 5.6.3, “MySQL Enterprise Thread Pool”).

    For Windows, THREAD_OS_ID corresponds to the thread ID visible in Process Explorer (https://technet.microsoft.com/en-us/sysinternals/bb896653.aspx).

    For Linux, THREAD_OS_ID corresponds to the value of the gettid() function. This value is exposed, for example, using the perf or ps -L commands, or in the proc file system (/proc/[pid]/task/[tid]). For more information, see the perf-stat(1), ps(1), and proc(5) man pages.

  • RESOURCE_GROUP

    The resource group label. This value is NULL if resource groups are not supported on the current platform or server configuration (see Resource Group Restrictions).

The threads 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 the threads table.


Zoek in de MySQL-handleiding

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 26/06/2006 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/mysql-rf-threads-table.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.

Referenties

  1. Bekijk - html-document Taal van het document:en Manuel MySQL : https://dev.mysql.com/

Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.

Inhoudsopgave Haut