简体   繁体   中英

mysql table indexing on null timestamp

I have a mysql table with a timestamp field.
Most of the queries on this table will be where someIntegerIield=? and theTimestampField is null where someIntegerIield=? and theTimestampField is null .

Should I use the timestamp field as part of the index?
Or should I create and maintain another filed that will be set to 0 when the timestamp field is null and 1 otherwise ?

Other alternatives are also welcome.

Yes, you can use an index for "time between timestamp1 and timestamp2". Default index type in MySQL / InnoDB is BTREE, which works with comparisons too (<, >, between), as well as prefixes. And yes, MySQL does use IS NULL/ IS NOT NULL in index conditions. http://dev.mysql.com/doc/refman/5.5/en//is-null-optimization.html for some table types (including InnoDB).

If you are on an earlier version of MySQL, you can always try "EXPLAIN": it will tell you if it uses an index or not (and which) for your query

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM