General optimization MySQL First look at the data to find whether the index, no index to index, index time to avoid the index failure.
Look at the following two statements
MySQL [release_test_oa]> EXPLAIN SELECT * from Workflow_logs WHERE ID-100 < 300000;+----+-------------+----------- ----+------+---------------+------+---------+------+------+-------------+| ID | Select_type | Table | type | possible_keys | key | key_len | ref | rows | Extra |+----+-------------+---------------+------+---------------+------+---------+------+------+---------- ---+| 1 | Simple | Workflow_logs | All | NULL | NULL | NULL | NULL | 3998 | Using where |+----+-------------+---------------+------+---------------+------+---------+------+------+--------- ----+
MySQL [release_test_oa]> EXPLAIN SELECT * from Workflow_logs WHERE ID < 300000-100, +----+-------------+----------- ----+-------+---------------+---------+---------+------+------+-------------+| ID | Select_type | Table | type | possible_keys | key | key_len | ref | rows | Extra |+----+-------------+---------------+-------+---------------+---------+---------+------+------+------ -------+| 1 | Simple | Workflow_logs | Range | PRIMARY | PRIMARY | 8 | NULL | 1999 | Using where |+----+-------------+---------------+-------+---------------+---------+---------+------+------+----- --------+
The above sentence does not use the index on the ID field, and the following is used, so avoid expression evaluation on the column.
MySQL Indexing and optimization learning