Rechercher dans le manuel MySQL
8.3.12 Invisible Indexes
MySQL supports invisible indexes; that is, indexes that are not used by the optimizer. The feature applies to indexes other than primary keys (either explicit or implicit).
Indexes are visible by default. To control index visibility
explicitly for a new index, use a VISIBLE
or
INVISIBLE
keyword as part of the index
definition for CREATE TABLE
,
CREATE INDEX
, or
ALTER TABLE
:
To alter the visibility of an existing index, use a
VISIBLE
or INVISIBLE
keyword with the ALTER TABLE ... ALTER INDEX
operation:
Information about whether an index is visible or invisible is
available from the
INFORMATION_SCHEMA.STATISTICS
table
or SHOW INDEX
output. For
example:
- FROM INFORMATION_SCHEMA.STATISTICS
- +------------+------------+
- | INDEX_NAME | IS_VISIBLE |
- +------------+------------+
- | i_idx | YES |
- +------------+------------+
Invisible indexes make it possible to test the effect of removing an index on query performance, without making a destructive change that must be undone should the index turn out to be required. Dropping and re-adding an index can be expensive for a large table, whereas making it invisible and visible are fast, in-place operations.
If an index made invisible actually is needed or used by the optimizer, there are several ways to notice the effect of its absence on queries for the table:
Errors occur for queries that include index hints that refer to the invisible index.
Performance Schema data shows an increase in workload for affected queries.
Queries have different
EXPLAIN
execution plans.Queries appear in the slow query log that did not appear there previously.
The use_invisible_indexes
flag of the
optimizer_switch
system
variable controls whether the optimizer uses invisible indexes
for query execution plan construction. If the flag is
off
(the default), the optimizer ignores
invisible indexes (the same behavior as prior to the
introduction of this flag). If the flag is
on
, invisible indexes remain invisible but
the optimizer takes them into account for execution plan
construction.
Index visibility does not affect index maintenance. For example, an index continues to be updated per changes to table rows, and a unique index prevents insertion of duplicates into a column, regardless of whether the index is visible or invisible.
A table with no explicit primary key may still have an effective
implicit primary key if it has any UNIQUE
indexes on NOT NULL
columns. In this case,
the first such index places the same constraint on table rows as
an explicit primary key and that index cannot be made invisible.
Consider the following table definition:
The definition includes no explicit primary key, but the index
on NOT NULL
column j
places the same constraint on rows as a primary key and cannot
be made invisible:
Now suppose that an explicit primary key is added to the table:
The explicit primary key cannot be made invisible. In addition,
the unique index on j
no longer acts as an
implicit primary key and as a result can be made invisible:
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-invisible-indexes.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
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.