Keine Cache-Version

Caching deaktiviert Standardeinstellung für diese Seite:aktiviert (code DEF204)
Wenn die Anzeige zu langsam ist, können Sie den Benutzermodus deaktivieren, um die zwischengespeicherte Version anzuzeigen.

Rechercher dans le manuel MySQL

8.2.4 Optimizing Performance Schema Queries

Applications that monitor databases may make frequent use of Performance Schema tables. To write queries for these tables most efficiently, take advantage of their indexes. For example, include a WHERE clause that restricts retrieved rows based on comparison to specific values in an indexed column.

Most Performance Schema tables have indexes. Tables that do not are those that normally contain few rows or are unlikely to be queried frequently. Performance Schema indexes give the optimizer access to execution plans other than full table scans. These indexes also improve performance for related objects, such as sys schema views that use those tables.

To see whether a given Performance Schema table has indexes and what they are, use SHOW INDEX or SHOW CREATE TABLE:

  1. mysql> SHOW INDEX FROM performance_schema.accounts\G
  2. *************************** 1. row ***************************
  3.         Table: accounts
  4.    Non_unique: 0
  5.      Key_name: ACCOUNT
  6.  Seq_in_index: 1
  7.   Column_name: USER
  8.   Cardinality: NULL
  9.      Sub_part: NULL
  10.        Packed: NULL
  11.          Null: YES
  12.    Index_type: HASH
  13.       Comment:
  14. Index_comment:
  15.       Visible: YES
  16. *************************** 2. row ***************************
  17.         Table: accounts
  18.    Non_unique: 0
  19.      Key_name: ACCOUNT
  20.  Seq_in_index: 2
  21.   Column_name: HOST
  22.   Cardinality: NULL
  23.      Sub_part: NULL
  24.        Packed: NULL
  25.          Null: YES
  26.    Index_type: HASH
  27.       Comment:
  28. Index_comment:
  29.       Visible: YES
  30.  
  31. mysql> SHOW CREATE TABLE performance_schema.rwlock_instances\G
  32. *************************** 1. row ***************************
  33.        Table: rwlock_instances
  34. Create Table: CREATE TABLE `rwlock_instances` (
  35.   `NAME` varchar(128) NOT NULL,
  36.   `OBJECT_INSTANCE_BEGIN` bigint(20) unsigned NOT NULL,
  37.   `WRITE_LOCKED_BY_THREAD_ID` bigint(20) unsigned DEFAULT NULL,
  38.   `READ_LOCKED_BY_COUNT` int(10) unsigned NOT NULL,
  39.   PRIMARY KEY (`OBJECT_INSTANCE_BEGIN`),
  40.   KEY `NAME` (`NAME`),
  41.   KEY `WRITE_LOCKED_BY_THREAD_ID` (`WRITE_LOCKED_BY_THREAD_ID`)
  42. ) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci

To see the execution plan for a Performance Schema query and whether it uses any indexes, use EXPLAIN:

  1. mysql> EXPLAIN SELECT * FROM performance_schema.accounts
  2.        WHERE (USER,HOST) = ('root','localhost')\G
  3. *************************** 1. row ***************************
  4.            id: 1
  5.   select_type: SIMPLE
  6.         table: accounts
  7.    partitions: NULL
  8.          type: const
  9. possible_keys: ACCOUNT
  10.           key: ACCOUNT
  11.       key_len: 278
  12.           ref: const,const
  13.          rows: 1
  14.      filtered: 100.00
  15.         Extra: NULL

The EXPLAIN output indicates that the optimizer uses the accounts table ACCOUNT index that comprises the USER and HOST columns.

Performance Schema indexes are virtual: They are a construct of the Performance Schema storage engine and use no memory or disk storage. The Performance Schema reports index information to the optimizer so that it can construct efficient execution plans. The Performance Schema in turn uses optimizer information about what to look for (for example, a particular key value), so that it can perform efficient lookups without building actual index structures. This implementation provides two important benefits:

  • It entirely avoids the maintenance cost normally incurred for tables that undergo frequent updates.

  • It reduces at an early stage of query execution the amount of data retrieved. For conditions on the indexed columns, the Performance Schema efficiently returns only table rows that satisfy the query conditions. Without an index, the Performance Schema would return all rows in the table, requiring that the optimizer later evaluate the conditions against each row to produce the final result.

Performance Schema indexes are predefined and cannot be dropped, added, or altered.

Performance Schema indexes are similar to hash indexes. For example:

  • They are used only for equality comparisons that use the = or <=> operators.

  • They are unordered. If a query result must have specific row ordering characteristics, include an ORDER BY clause.

For additional information about hash indexes, see Section 8.3.9, “Comparison of B-Tree and Hash Indexes”.


Suchen Sie im MySQL-Handbuch

Deutsche Übersetzung

Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.

Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.

Vielen Dank im Voraus.

Dokument erstellt 26/06/2006, zuletzt geändert 26/10/2018
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/mysql-rf-performance-schema-optimization.html

Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.

Referenzen

  1. Zeigen Sie - html-Dokument Sprache des Dokuments:en Manuel MySQL : https://dev.mysql.com/

Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.

Inhaltsverzeichnis Haut