Use three principles index

In selecting an index and writing queries to use these indexes, the following three principles always need to remember:

  1. Single-line access is very slow.
    Especially in the mechanical hard disk storage (SSD random I / O much faster, but it still holds). If the server reads a data block from the store to obtain one line only, then we wasted a lot of work. Preferably the read block can contain multiple rows as required. You can create an index reference position to improve efficiency.

  2. Data accessed sequentially range is very fast.
    Reason 1: sequential I / O does not require multiple disk seeks, the ratio of random I / O much faster (especially for mechanical hard drive).
    Reason 2: If the server data can be read sequentially as needed, then no additional sorting operation, and there is no need to do GROUP BY query and sorting the rows by group of polymerization is calculated.

  3. Index covers the query is very fast.
    If an index contains all the columns needed for the query, then the storage engine does not need to come back to the table to find the line. This avoids a lot of one-way access.

Overall: write the query should be possible to select the appropriate index to avoid a single line to find, use the native sequence data as possible in order to avoid additional sorting operation, and use the index as much as possible to cover the query .

Published 15 original articles · won praise 0 · Views 303

Guess you like

Origin blog.csdn.net/sinat_15051577/article/details/103925542