简体   繁体   中英

Simple MySQL select taking too much time

I am having following simple query, but its taking too much time (.5 seconds/half of a second), I am unable to find the reason. I want to improve the performance of Search.

Title

VARCHAR (50), Collation = latin1_general_ci, NULL allowed, MySQL Engine: MyISAM

Number of record in Product table: 163129

CatID

Foreign Key (int) From Category table

I already have tried this Optimize statement


OPTIMIZE table Product

Here is the simple query.


SELECT COUNT(*)
FROM 
Product
WHERE 
CatID=123 
AND Title = 'abc xyz'

Please help. Thanks in advance.

Taking more time meaning the table is not properly indexed and probably doing full table scan.

For this particular query a covering index would be useful

alter table Product add index cat_title_idx(CatID,Title);

Make sure to take a backup of the table before applying the index.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM