简体   繁体   中英

Analog of “Index-only scans” from PostgreSQL in MySQL

When analyzing PostgreSQL query execution plans for some queries you can exploit Index-only scans :

Index-only scans are a major performance feature added to Postgres 9.2. They allow certain types of queries to be satisfied just by retrieving data from indexes, and not from tables.

Is there something similar you can use in MySQL?

It's funny that you want something like Postgres index-only scans in Mysql.
Because there are this feature in Mysql long before the Postgres 9.2. But in mysql this feature called covering index :

An index that includes all the columns retrieved by a query. Instead of using the index values as pointers to find the full table rows, the query returns values from the index structure, saving disk I/O. InnoDB can apply this optimization technique to more indexes than MyISAM can, because InnoDB secondary indexes also include the primary key columns. InnoDB cannot apply this technique for queries against tables modified by a transaction, until that transaction ends.

Any column index or composite index could act as a covering index, given the right query. Design your indexes and queries to take advantage of this optimization technique wherever possible.

Yes - if there is a covering index for the query, MySQL may read the index only, not table data.

http://dev.mysql.com/doc/refman/5.7/en/mysql-indexes.html

In some cases, a query can be optimized to retrieve values without consulting the data rows. (An index that provides all the necessary results for a query is called a covering index.) If a query uses from a table only columns that are included in some index, the selected values can be retrieved from the index tree for greater speed:

 SELECT key_part3 FROM tbl_name WHERE key_part1=1 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM