Notes on java database indexes

Index Disadvantages

1. Although the index greatly improves the query speed, it will reduce the speed of updating the table, such as insert, update and delete on the table. Because when the table is updated, not only the data but also the index file must be saved.
2. Create an index file that will occupy disk space. In general, this problem is not serious, but if you create multiple composite indexes on a large table, the index file will grow quickly.
Indexes are only one factor to improve efficiency. If you have tables with large amounts of data, you need to spend time researching the establishment of the best indexes or optimizing query statements.

Indexing Considerations

When using an index, there are some tips and precautions as follows:
1. The index will not contain a column with a null value.
As long as the column contains a null value, it will not be included in the index. In a composite index, as long as one column contains a null value, Then this column is invalid for this composite index. So we don't let the default value of the field be null when designing the database.
2. Use a short index to index
the string column, and if possible should specify a prefix length. For example, if you have a column of char(255), if within the first 10 or 20 characters, most values ​​are unique, then don't index the entire column. Short indexes can not only improve query speed but also save disk space and I/O operations.
3. Index column sorting
query uses only one index, so if the index has been used in the where clause, the column in the order by will not use the index. Therefore, do not use the sorting operation if the default sorting of the database can meet the requirements; try not to include sorting of multiple columns, and create composite indexes for these columns if necessary.
4. The like statement operation
is generally not recommended to use the like operation. If it must be used, how to use it is also a problem. like "%aaa%" will not use the index while like "aaa%" will use the index.
5. Do not perform operations on columns,
which will cause the index to fail and perform a full table scan, such as

SELECT * FROM table_name WHERE YEAR(column_name)<2017;

6. Do not use not in and <> operations

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325814819&siteId=291194637