简体   繁体   中英

sql query return time is random

I have a weird problem with displaying the results from a database on a website. My database is 2.3million rows long and has a fulltext index. I am using this as a query:

SELECT * 
FROM $tbl_name 
WHERE MATCH(DESCRIPTION) 
AGAINST ('$search') 
LIMIT $start, $limit.

The results are displayed using a php pagination which is why I use limit. Running the query on the actual database server through phpadmin consistently returns with times under 100ms. Althogh the query time is under 100ms it can still take u to 2 minutes because when I run the query it gets stuck at "loading". When the webpage runs the query I get anywhere from 300ms load time to 2 minutes. Based on that I used Chrome's built in developer console and see that the receiving time of my php script is the problem. Copying the table to a new table and creating a new fulltext index solves the problem for all of 2 minutes, then it just goes back to being insanely slow. I am using hostgator btw which im guessing is the problem. If anyone has any idea on why it is so random I would greatly appreciate it as 2 minutes to run a search is not acceptable ^.^, thanks a ton!

If this is a shared Webserver it could be that other people's sites are bogging down the server. Maybe you need to get a dedicated server instead?

You could also try running the query against the database over and over a few times to see if performance degrades there after the first 2 minutes like you notice through php.

Also, generally 2millions rows is a lot for MySQL, moreover for FULLTEXT w/ MySQL. You might want to consider a proper search engine at that point like Solr instead.

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