大表下的 MySQL 性能
我有一个简历表 - 姓名、简历文本、邮政编码、名字、姓氏、经度、纬度、邮政编码... 500,000+行
我也查询它的方式:
按位置,例如:
1) SELECT * FROM resumes
WHERE ((latitude BETWEEN 44.3523845787 AND 45.6809474213)
AND (longitude BETWEEN -110.873064254 AND -108.993603746))
GROUP BY lastname,longitude
LIMIT 0, 50
by name
2) SELECT * from resumes
(MATCH(resume) AGAINST ('donald')) AS relevance
FROM resumes
WHERE (MATCH(resume) AGAINST ('donald'))
GROUP BY lastname,longitude
ORDER BY relevance DESC
LIMIT 0, 50
对该表的查询一开始非常慢,但之后相同的查询速度更快,我认为它正在缓存它......
我怎样才能加快这些查询的速度?谢谢
i have a table of resumes - names, resume text, zipcode, firstname, lastname, longitude, latitude, zip ... 500,000+ rows
i query it too ways:
by location, example:
1) SELECT * FROM resumes
WHERE ((latitude BETWEEN 44.3523845787 AND 45.6809474213)
AND (longitude BETWEEN -110.873064254 AND -108.993603746))
GROUP BY lastname,longitude
LIMIT 0, 50
by name
2) SELECT * from resumes
(MATCH(resume) AGAINST ('donald')) AS relevance
FROM resumes
WHERE (MATCH(resume) AGAINST ('donald'))
GROUP BY lastname,longitude
ORDER BY relevance DESC
LIMIT 0, 50
queries on this table are very slow at first, but same query afterwards is faster, i think it's caching it ...
how can i speed up these queries? thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个可以很少使用 btree 索引。最好的情况是,它会抓取所有适合纬度或经度的位置,并调查沿其他维度的潜在行。您想要的是它只调查适合较小盒子的行。
为此,您需要一个空间索引。
同样,这也需要一种不是 btree 的特殊索引 -- a
This one can make little use of btree indexes. At best, it would grab all locations that fit for the latitude, or the longitude, and investigate potential rows along the other dimension. What you want is for it to only investigate rows that fit in a smaller box.
For this, you need a spacial index.
Likewise, this also needs a special kind of index which is not btree -- a full text index to be specific.
MySQL 执行快捷方式评估,将限制最大行数的条件放在 where 子句中。
如果您布局表格时没有重复行,那么使用分组依据选择 * 是一种不同的“消除重复行”编写方式,您也不需要分组依据。这将大大加快你的查询速度。
MySQL does shortcut evaluation put the condition that limits the maximum number of rows first in your where clause.
Select * with a group by is a different way of writing "eliminate duplicate rows" if you lay out your tables so there are no duplicate rows to begin with you don't need the group by either. This will speed up your queries a lot.