Is there any way that I can see what is stored in those indexes?
I understand the query mentioned below lists down all the schema indexes and their details:
SELECT DISTINCT
TABLE_NAME,
INDEX_NAME
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = 'your_schema';
(taken from Mark Byers’s response to How to see indexes for a database or table in MySQL?)
2
Answers
I’ll answer for MySQL only, because PostgreSQL’s information_schema does not have a table called
statistics
.SELECT <column> FROM <table>
shows the values that are indexed. In other words, the leaf nodes of the index are exactly the values in the columns the index was created for.If you want to see the index data structure itself, MySQL provides no access to this. It depends on the table’s storage engine.
There are some tools developed by an InnoDB expert Jeremy Cole that can inspect the internal structure of index pages. See https://blog.jcole.us/innodb/ for his blogs on this subject and https://github.com/jeremycole/innodb_ruby for his tools.
You can use the query you mentioned to retrieve a list of indexes and their details for a specific schema. You can also use the following query to get more detailed information about a specific index:
This query should return the following information about the specified index:
Non_unique: Whether the index is unique or not
Key_name: The name of the index
Seq_in_index: The sequence number of the column within the index
Column_name: The name of the column that is indexed
Collation: The collation of the indexed column
Cardinality: The number of unique values in the indexed column
Sub_part: The length of indexed prefix for the column
Packed: Information about the packed state of the index
Null: Whether the indexed column can contain NULL values
Index_type: The type of the index
Comment: Additional information about the index
You can also use the following query to get the indexes for all tables in a specific schema:
This should give you the table name, index name and column name that the index is on.
You can also use the following query to get the indexes for all tables in a specific schema and see the column in the index
This should give you the table name, index name and columns that the index is on.
In any case, you should replace "your_schema" with the name of the schema you want to get the information for and "your_table_name" with the name of the table you want to get information for.