Avoid Functions on Indexed Columns
Medium
Query Optimization
The query SELECT * FROM Orders WHERE YEAR(order_date) = 2026 cannot use an index on order_date. Rewrite it so that the index can be used.
Table schema
Orders(id INT PRIMARY KEY, order_date DATE, amount INT) with INDEX(order_date)Sample data
Orders dated 2025-12-31, 2026-01-01 and 2026-12-31 (the last two should be returned)
Discussion
No discussions yet.
Shalyam Support
Hi! Ask us anything — we'll reply on WhatsApp or Telegram within 24 hours.