I'm analyzing some code I just inherited at work and I have a question:
This is a snippet of what I inherited:
Select sum(a.claim) as total
from claims c
inner join claim_entries ce
on c.id = ce.claim_id
and ce.deleted = 0
and ce.dos >='2012-03-01'
where c.deleted = 0
and c.document_type = 0
I rewrote the code so the ON clauses are in the WHERE clause:
Select sum(a.claim) as total
from claims c
inner join claim_entries ce
on c.id = ce.claim_id
where c.deleted = 0
and c.document_type = 0
and ce.deleted = 0
and ce.dos >='2012-03-01'
The original code ran in 36 seconds, while my rewrite ran in 9 seconds. Is there a difference to putting filters in the JOIN clause for an INNER JOIN as opposed to in the WHERE? I've only done that when using LEFT JOINS and never saw it done for an INNER JOIN. I'm also not sure why the original would take 4x longer than the rewrite, unless the data is cached after I ran the original.