Let say I have 2 tables, TblA et TblB. TblA has millions of records each month while TblB has detailled informations for products.
Which query will be faster :
select
t1.*, t2.name
from
TblA as t1
left join
TblB as T2 on t1.idProduct = t2.idProduct
where
t1.month = 6
Or this one :
select
t1.*, t2.name
from
(select * from tblA where month = 6) as t1
left join
TblB as t2 on t1.idProduct = t2.idProduct
My guess is the second one will be faster because I pre-select only the month I want before doing the left join.
Are database system pre-build to handle the where clause before doing the left join?
Thanks!
run them both and look at the query plans
it will even give you a split on estimated time