Reputation: 4289
I have the following query
select e_name
from my_table
where year_week between yearweek('2021-11-10') and yearweek('2021-11-18');
will the yearweek('2021-11-10')
function be executed only once, before the execution, or will it be calculated for each row?
is it better to calculate it before?
select e_name
from my_table
where year_week between 202145 and 202146;
note: the yearweek
func gets a static variable - and does not depened on the db rows
Upvotes: 1
Views: 278
Reputation: 562270
https://dev.mysql.com/doc/refman/8.0/en/where-optimization.html says:
Constant expressions used by indexes are evaluated only once.
Upvotes: 2