我在mysql dB表上使用下面的2个查询,这个表大约有1,000万行。第一次计数是相当快的。第二个相当慢(可能要慢10倍)。
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 resultslocation列具有类似- Spain>Canary Islands>Lanzarote>Some Resort的值
'location‘列上的索引集-表为MyISAM
有没有人知道如何加速第二个查询。我知道它们的工作原理有点不同。
发布于 2020-12-13 23:09:25
小贴士:为了避免使用像SELECT count(*) as count这样的东西,它会占用你服务器上的大量资源。建议:每次向数据库中插入内容时,将值存储到数据库列中
from $table将它们存储在另一个数据库表中,并将其称为"Sums“,所有内容都插入到$table中,将"Sums”表的值更新为更高的数字。
https://stackoverflow.com/questions/60682528
复制相似问题