Database - Index interview FAQ

Q & A is based on known data structures.

  1. What indexes are?
  • Index value in the database is one or more columns in the table is sorted a configuration.
  1. Why use the data index?
  • Enhance the retrieval speed, accelerating the connection between the table and the table
  1. What types of indexes?
  • FULLTEXT full-text index can be created on the full-text index (MyISAM, Innodb5.6 +) CHAR, VARCHAR, TEXT columns
  • HASH hash index (MEMORY support)
  • BTREE B-tree index
  • B + TREE B + tree index
  • RTREE R-tree index
  1. What type index? What are the characteristics?
  • Ordinary Index: speed up queries
  • The only index: speed up queries + + unique column values ​​may be null
  • Primary key index: the acceleration column value uniquely query + + + null is not only a table
  • Composite index: a multi-column index value of the composition, a combination of dedicated to searching, combined efficiency is greater than the index
  • Full-text indexing: the content of the text word segmentation, search
  1. What data should add an index?
  • Where clause field frequently used index should be created
  • Grouping field or sort field should create an index
  • Connect field two tables should create an index
  • Storage space is more suitable for fixed keyword text field type of field selected as the index compared, char type is more suitable
  • Take up less storage space is more suitable for field selected as a keyword index compared with the string, integer field more suitable
  • Long article index data should consider using the index short, if the majority of the front of the field is different, then specify a prefix length.
  1. What data is not suitable as an index?
  • Frequently updated fields are not suitable for creating an index
  • It does not appear in the where clause field
  1. What is the data structure of the index mysql?
  • The general use of B + tree indexing
  1. Do you know other index type?
  • Hash index B-tree index
  1. Hash and time complexity index B + tree index is how much?
  • o (1) the sum o (logN)
  1. Why mysql hash index is faster but also with B + TREE indexed?
  • This and related business scenarios. Only a selected data, hash faster (o (1)). Database often choose the N if using a hash index that is o (n), this time due to the B + tree index order (o (logn)), and have linked list on the leaf node, its query efficiency than hash to faster a.
  • On the hard disk, the index itself generally large index store, not all at once stored in memory, the B + tree design may allow for batch loading data, while the lower height of the tree, to find the high efficiency.
  • We all know that the hard disk I / O speed is very slow compared to memory, and the index is used to speed up queries, the need to reduce I / O operations, memory, and disk units of pages to exchange data, in order to reduce I / O, when a new node index, apply directly a page space, memory allocation is page-aligned, to achieve a first node I / O.
Published 34 original articles · won praise 7 · views 8171

Guess you like

Origin blog.csdn.net/ilo114/article/details/88617617