Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

Avoid Functions on Indexed Columns

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.

Rewards · v2.1

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.