The principle mysql index &


What index is: is a list of the values stored in the index field and the data corresponding to the physical address of a sort, using the index field query, do not scan the entire table match, straight to the diverted data corresponding to the physical address by the index table, and then find the corresponding data;

advantages: implemented by using the index number of B +, reduction of I / O operations, increasing search efficiency

disadvantages: the need for additional disk space, add, delete, change operations have additional

classification:
  1. Primary key index, i.e., the primary key
  2. Unique index field is set when the only constraint already exists, or alter table table_name add unique index_name ( "column");
  3. General index table in the index field as normal: alter table table_name add index index_name ( "column");
  4. Composite index:
    1. A combination of a plurality of fields as an index: alter table table_name add index index_name ( "columnA", "columnB", "columnC");
    2. Or the first few characters of a plurality of fields as an index: alter table table_name add index index_name ( "columnA (3)", "columnB (4)", "columnC (5)"); // 3 three fields before, 4,5 characters as an index
    3. Follow the "most left-prefix", sorted by frequency of use of search fields, high frequency discharge left; directly columnB, columnC no effect index
  5. Full-text index:
    1. 创建:alter table table_name add fulltext index index_name("column");
    2. 查询:select * from table match(index_name) against("xxx");

data structure:

        

    SELECT * FROM tab WHERE index_column = "Chinese"; index_column index data is that there is a green field, numbers, strings can be, data is data corresponding to the line.

    

Index field: Px in FIG.

Why a B + tree (personal understanding)

  • With respect to the binary: the binary tree each node has at most two child nodes, a single B-tree node class can accommodate many keywords, while there are many child nodes, reducing the height, determining / IO significantly reduced number of readings (not well understood, the index the data itself is also hard on)
  • With respect to the number of B-: B + only keep non-child node index number, the data does not exist, only instead of directly reading the index data, consume less IO; B + tree number of non-child node pointer and number of child nodes is equal key, a case where the same data amount, B + book a high number of shorter, reducing IO

B- tree:       

        





Guess you like

Origin www.cnblogs.com/dfdi33/p/11548133.html