Answering your very question:
I'm curious if putting an index on the date field will help speed up both queries?
If the condition on installdate
and serviceday
is selective (that is few rows satisfy it), then yes, it will help.
Date fields usually tend to be selective.
or will the fact that i use FUNDINGSTATUS
in the first where clause will make that query not utilize the index?
Yes, the index will still be used.
The engine will use the index to select only the records with installdate = $date
and the will additionally filter on the value of fundingstatus
.
For best results, create the following indexes:
ACCOUNTS (installdate, fundingstatus)
service (serviceday)
If DEAD
is a frequent value for fundingstatus
, it may be better to rewrite this query like this:
SELECT INSTALLER, INSTALLTIME, RESULT, JOBNUMBER, HONAME, ADDRESS, CITY, STATE, ZIP, NOTES, SMNOTES, '' as priority, PAFS, upsell, TERM, MMRUPGRADE, WARRANTY, EFT
FROM ACCOUNTS
WHERE INSTALLDATE = '$date' AND FUNDINGSTATUS < 'DEAD'
UNION ALL
SELECT INSTALLER, INSTALLTIME, RESULT, JOBNUMBER, HONAME, ADDRESS, CITY, STATE, ZIP, NOTES, SMNOTES, '' as priority, PAFS, upsell, TERM, MMRUPGRADE, WARRANTY, EFT
FROM ACCOUNTS
WHERE INSTALLDATE = '$date' AND FUNDINGSTATUS > 'DEAD'
UNION
SELECT technician, servicetime, result, ID, Customername, address, city, state, zip, notes, board, priority, '', '', '', '', '', ''
FROM service
WHERE serviceday = '$date'
ORDER BY
INSTALLER, priority
so that the range access on both fields (installdate, fundingstatus)
can be used.