MySQL:有索引和小文件排序更好还是没有索引和文件排序更好?
我有一个大型数据库(180k+行并且增长很快)的位置数据,并将它们绘制在谷歌地图上。对于给定的视口,我只想提供 100 个适用点的样本。因此,数据库是按纬度/经度查询的,但如果我在这些行上放置索引,问题是 100 个点的样本将位于视图端口的底部或顶部(取决于索引的使用方式) 。如果不使用索引,这些点几乎随机地分散在视口中,这是更理想的。我可以通过第三个几乎随机的字段进行文件排序,对索引结果产生相同的效果。
所以,问题似乎是,哪个更好:对 180k+ 行进行无索引查询,或者对 4k 行和 4k 行等内容进行索引查询。进行文件排序?谢谢!
I have a large database (180k+ rows and growing fast) of location data and am plotting them on a google map. For a given view port, I just want to serve up a sample of 100 applicable points. The database is therefore queried by lat/lng, but if I put an index on these rows the problem is that the sample of 100 points will be either at the bottom or the top of the view port (depending on how the index is used). If no index is used, the points are pretty much randomly scattered across the view port, which is much more desirable. I can create the same effect on the indexed results by doing a filesort by a third, pretty much random field.
So, the issue seems to be, what is better: An unindexed query on 180k+ rows, or an indexed query which will look at something like 4k rows & do a filesort? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您会发现许多反对使用“ORDER BY RAND()”的论点,尽管在这种情况下如果您对字段建立索引并且发现分析结果可以接受,那么它可能会很有用:
You'll find many arguments against using "ORDER BY RAND()", although it may be useful in this situation if you do index the field and you find the profiling results to be acceptable:
分析带索引和不带索引的查询。我在 dbForge Studio for MySQL 中使用探查器。
Profiling your query with index and without it. I use profiler in dbForge Studio for MySQL.