The index data type is simple and appropriate, takes up little space, and avoids NULL values (NOT NULL) as much as possible, the better the performance.
Numeric types only need to be compared once, and strings will be compared verbatim; do not exceed 6 indexes, which will lead to performance degradation.
Fields with a lot of repeated data are not suitable for indexing, such as gender; random strings are not suitable for building clustered indexes (data movement)
Union index uses leftmost match
Index failure: avoid using or (use union all instead), in or not in (use exists instead), is null variable, matching query, or operator in the where clause, or perform expression and function operations on fields, %abc%otherwise !=it <>will Causes the engine to give up using the index and perform a full table scan
cache:
Cache invalidation: SQL case sensitivity, query_cache_sizesize exceeded, insufficient memory, cache timeout, data modification
-- 不会使用同一缓存
select name from users where id = 1;
SELECT name FROM users WHERE id = 1;