When do I need to build an index, and when do I not need it?

When should I index?

  1. The primary key and foreign key of the table must have indexes

  2. There must be an index if the data volume exceeds 300

  3. For tables that are frequently connected to other tables, establish an index on the connection field

  4. Fields that often appear in where clauses, especially large table fields, must be indexed

  5. The index should be built on small fields. For large text fields or even long fields, do not build indexes


When is indexing unnecessary?

  1. Create a combined index, but the query predicate does not use the first column of the combined index, and the index is also invalid at this time

  2. Build an index on the table column that contains null values, and the index will not be used when using select count (*) from table

  3. Using the function on the index column will not use the index unless a new function index is created

  4. The indexed column will not use the index when performing implicit type conversion

  5. When the amount of query data accounts for a large proportion of the entire table, full scan table uses multiple block read queries to be faster

Guess you like

Origin www.cnblogs.com/dretrtg/p/12676113.html