Aggregation and non-clustered index

 Aggregation and non-clustered index

Brief summary:

  • Index to the primary key clustered index is created
  • Non-clustered index to a non-primary key index is created

the difference:

  • Data clustered index the leaf node is stored in the table
  • Non-clustered index is stored in the leaf node and the primary key index column
  • When using the non-clustered index query the data, get the primary key data found on the leaves go looking for. (To get the primary key and then look for a process called back to the table)

Non-clustered indexes also called secondary indexes, do not tangle so many terms, it is equivalent on the line ~

When non-clustered index created is not necessarily a single row, you can create multiple index columns.

  • At this point it is related to the column which will take the index, which column do not take the issue of the index (leftmost matching principle -> behind say)
  • Create multiple single (non-clustered) index when the index tree will generate more (so much to create indexes take up disk space

Create multi-column index is also related to a special index -> index covering

  • In front of us know, if not a clustered index, the leaf node storage is the primary key column value +
  • And ultimately to "return to form", that is, to find once again by the primary key. This will be slower
  • A covering index is to be queried and indexed columns are corresponding, not back to the operating table!

For example:

  • Now I created the index (username,age), when the query data: select username , age from user where username = 'Java3y' and age = 20.
  • Clearly we know that we are taking the index top of the query, and to check out the columns in the leaf nodes exist! So, would not return to the table -
  • Therefore, the index can be used to cover as much as possible to use it ~

Storage Features

  1. Clustered index. Table data in order to store the index, that is consistent with the physical order of the index table entries recorded. For clustered index, i.e. leaf nodes storing real data lines, no additional separate data page. Most can only create a clustered index on a table, because the physical order there is only one real data.
  2. Non-clustered index. Regardless of the sequence table data storing index order. For non-clustered index, the leaf node includes an index field values ​​and the logical pointer to the data page data line, which amount is consistent with the number of lines of data table rows.
    To summarize: the clustered index is a sparse index, an index page of data pages stored on a page pointer, rather than the row pointer. For non-clustered index, the index is intensive, on an index page of data pages for each of its data storage a row index record.

 

innodb Repeatable Read isolation level to solve the country's non-repeatable read problem, use MVCC version resolved.

innode use next-key locks gap phantom read lock solution is read in the current situation .

Dirty reads and non-repeatable read transaction is a read, write another transaction caused.

The two transactions together when writing cause read and write conflict, resulting in the loss Update: update of a transaction covered by the updated results of other transactions. The solution are:

  • Use Serializable isolation level, the transaction is executed in serial!
  • Optimistic locking
  • Pessimistic locking

 

If we use the index is the row lock lock, if the index is not used table locks, but the data we have used in the operation of the lock down.

Note that:

1. row lock must have an index to achieve, otherwise it will automatically lock the entire table, then it is not the line lock.

2. Two transactions can not lock the same index

Guess you like

Origin www.cnblogs.com/heqiyoujing/p/11221980.html