David542
David542

Reputation: 110123

Any advantage in indexing a DATE column?

In mysql, is there any benefit to adding an index to a DATE column? I will be using the column for comparisons such as:

SELECT * FROM birthdays WHERE date > today + 3 days;

Would indexing the date column improve performance here?

Upvotes: 2

Views: 3261

Answers (3)

Jean-François Savard
Jean-François Savard

Reputation: 21004

Yes, it will avoid some full scan by eliminating some rows in condition.

Check out this thread, it's well explained :

Is it a good idea to index datetime field in mysql?

Upvotes: 1

Iłya Bursov
Iłya Bursov

Reputation: 24146

Index will improve performance.

Without index mysql will have to scan all rows.

With index - it will create sorted "array", so it will be able to use binary search to find where today+3 starts and just scan all further rows of this array instead of full scan.

Upvotes: 0

Janick Bernet
Janick Bernet

Reputation: 21184

Yes, it can use it to do a range scan in the query you suggested.

Upvotes: 0

Related Questions