I am using the 2 queries below on a mysql dB table which has about 10 million rows. The first count one is quite fast. The second is quite slow (maybe 10 times slower).
SELECT count(*) as count
from $table
WHERE SUBSTRING_INDEX(location, '>', 3) LIKE '%$mylocation%'
... show count
SELECT name, location, hotel, rating
FROM $table
WHERE SUBSTRING_INDEX(location, '>', 3) LIKE '%$mylocation%'
...loop to show results
location column has values like - Spain>Canary Islands>Lanzarote>Some Resort
Index set on 'location' column - Table is MyISAM
Does anyone have any ideas on how I can speed up the second query. I understand they both work a bit differently.
Tip: To avoid using something like SELECT count(*) as count
Which takes a lot of resource from your server. Recommendation: Store the values into a Database column, everytime you insert something into your database
from $table
Store them in another database table and call it "Sums" , everything something is inserted into $table
, Update the value of "Sums" Table to a higher number.
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.