I've got a query in MySQL:
SELECT FIELD1, FIELD2, FIELD3
FROM TABLE1
WHERE
(FIELD3 >= INT1 AND FIELD3 <= INT2)
AND FIELD2 IN (INTEGER_LIST)
Any ideas how to make this query faster? Both FIELD2 and FIELD3 are indexed. Even, when check on FIELD2 is removed, nothing happens related to performance.
Execution plan information:
id: 1
select_type: SIMPLE
table: TABLE1
type: ref
possible_keys: FIELD2, FIELD3
key: FIELD2
ref: const
rows: 310000
Extra: using where
Yes. An index on table1(field2, field3, field1)
should speed this query:
create index table1_field2_field3_field1 on table1(field2, field3, field1)
Did you try setting up a compound index on (FIELD3, FIELD2) ? (see leftmost prefix issues in MySQL)
Setting an index really depends on the type of query you are expecting :
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.