Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
461 views
in Technique[技术] by (71.8m points)

How effective is a MySQL index on an INT field storing unix epoch?

A lot of the information on designing strong indices recommends not using them on fields with extremely little data repetition. However, since time-based conditions are a big part of our application people have recommended using an index on the timestamp field to improve query speed.

Is it worth the resource cost to add an index for an INT field storing the unix epoch? The timestamps are essentially never the same, aside from when multiple records are stored at the same second.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If your queries are primarily "about" timestamp (that is, where clauses involving that field significantly limit the portion of the data to be scanned), or you're ordering large-ish result sets by timestamp, then I'd say that an index on that field would be extremely useful.

There's nothing magical about indexes. Just as yourself if a list of timestamps and "row numbers" (a thought-abstraction not intended to correlate with anything real), sorted by the timestamp, would be useful in answering questions more quickly and by looking at less of the data.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...