php - MySQL: Is it better to have an index and a small filesort or no index and no filesort? -
i have large database (180k+ rows , growing fast) of location data , plotting them on google map. given view port, want serve sample of 100 applicable points. database therefore queried lat/lng, if put index on these rows problem sample of 100 points either @ bottom or top of view port (depending on how index used). if no index used, points pretty randomly scattered across view port, more desirable. can create same effect on indexed results doing filesort third, pretty random field.
so, issue seems be, better: unindexed query on 180k+ rows, or indexed query @ 4k rows & filesort? thanks!
you'll find many arguments against using "order rand()", although may useful in situation if do index field , find profiling results acceptable:
mysql> select id table id > 10000 , id < 20000 order rand() limit 0,10; +-------+ | id | +-------+ | 18560 | | 18408 | | 14058 | | 19090 | | 11100 | | 18945 | | 12656 | | 16549 | | 19321 | | 12003 | +-------+ 10 rows in set (0.04 sec)
Comments
Post a Comment