duanbairan4235 2010-09-22 15:11
浏览 63
已采纳

MySQL:有一个索引和一个小文件或没有索引和没有filesort更好吗?

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!

  • 写回答

2条回答 默认 最新

  • douyuan4825 2010-09-23 00:55
    关注

    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:

    mysql> select id from table where id > 10000 and id < 20000 order by rand() limit 0,10;
    +-------+
    | id    |
    +-------+
    | 18560 | 
    | 18408 | 
    | 14058 | 
    | 19090 | 
    | 11100 | 
    | 18945 | 
    | 12656 | 
    | 16549 | 
    | 19321 | 
    | 12003 | 
    +-------+
    10 rows in set (0.04 sec)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程