Database Star

If your SQL query feels painfully slow, here’s one thing you can look at:

Check the columns in your WHERE clause.

If they aren’t indexed, or you’re applying functions to them, the database can’t use the index effectively.

For example:

WHERE YEAR(order_date) = 2025

This forces a scan of the entire table, because if you have an index on order_date, the index can’t be used.

Instead, compare directly to a date range:

WHERE order_date >= '2025-01-01'
AND order_date < '2026-01-01'

You’ll get the same result, but the index should be used, so it would be much faster.

Have you run into this before?

2 months ago | [YT] | 150



@chaitanyakrishna-z4j

This method optimized my sql, Thanks

2 months ago (edited) | 0

@holger_p

Might depend on the specific SQL implementation. Your explanation is conclusive, but if Database designers know this, they should make an update, to use the index in this case also.

2 months ago (edited) | 0

@help3106

Wait,,, whatt

2 months ago | 2

@yapnog603

who DOES NOT do this??? jesus

2 months ago | 3