开发者

Indexing four columns?

I have a table that I use to retrieve drive times, according to longitude and latitude of the origin and destination. Although I am using Google's API to find new commute times, I store the results of previous queries locally so that if I need to query the same drive again, I won't have to use Google. (Google's web service is throttled.) Anyw开发者_JAVA百科ay, the table includes five columns:

    LatStart (smallmoney)
    LongStart (smallmoney)
    LatEnd (smallmoney)
    LongEnd (smallmoney)
    DriveTime (Int.  In seconds)

(Smallmoney, it turns out, works very well for longitude and latitude, as long as you only need four digits after the decimal, which is precise enough for this.)

My question is: For optimal performance in SELECT queries, should I index all four longitude / Latitude columns?

And a second question: We can assume that it won't delete very often, but in the long run as the table grows, it will still insert rows about 25% as often as it selects rows. Therefore, will an index on all four columns be detrimental to insert queries?


If you're searching on all 4, then probably you'll want to index them.

Another factor that you should consider is the padding you put on your index. Higher padding reduces the amount of re-paging that has to be done on your index (it's not actually called re-paging, but the word is escaping me at the moment), which is a benefit for writing, and a cost for reads. Lower padding is better for reads.

I'd index all 4, and then play around with the padding a bit to find the best setting.


An index on the long/lat columns will help select (read) performance at the expense of insert/update/delete (write) performance.

Measure the performance yourself before and after adding the index to determine if it is appropriate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜