我有一个包含大约 100,000 条记录的 MySQL 表。当我尝试使用主键(无符号整数)从该表中选择大约 20 行时,执行大约需要一秒钟。有没有办法优化这个?
表:电影
Column Type Null Default
film_id int(11) No
film_name varchar(45) No
film_overview text No
film_tagline varchar(150)Yes NULL
release_date date Yes NULL
api_id int(11) No
category_id int(11) No 0
电影索引
Keyname Type Unique Packed Column Cardinality Collation Null Comment
PRIMARY BTREE Yes No film_id 110236 A No
api_id BTREE No No api_id 110236 A No
film_id BTREE No No film_id 110236 A No
category_id BTREE No No category_id 4 A No
解释
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY films ALL NULL NULL NULL NULL 115029 Using where
2 DEPENDENT SUBQUERY popular_films ALL NULL NULL NULL NULL 18 Using where
询问
SELECT film_name FROM `films`
WHERE film_id in (SELECT film_id FROM popular_films);