If you are just checking for existence of a field, consider using SELECT COUNT(*) FROM emails where email='[email protected]' instead. This will only require reading a single field, and so will cost less and be marginally faster on large tables.
And as Pentium10 suggested, consider using multiple lookups in a single query. You could do this like:
SELECT SUM((IF(email = '[email protected]', 1, 0)) as m1,
SUM((IF(email = '[email protected]', 1, 0)) as m2,
SUM((IF(email = '[email protected]', 1, 0)) as m3,
...
FROM emails
You're going to be limited to something like 64k of these in a single query, but it should be very fast to compute since it only requires scan of a single column in one pass.
Alternately,if you wanted the e-mails as one per row, you could do something a little bit fancier like
SELECT email FROM emails WHERE email IN
('[email protected]', '[email protected]', '[email protected]'...)
GROUP BY email
As a further optimization, you could do it as a LEFT JOIN:
SELECT t1.email as email, IF(t2.email is not null, true, false) as found
FROM [interesting_emails] t1
LEFT OUTER JOIN [emails] t2 ON t1.email = t2.email
If the interesting_emails had the list of emails you wanted to check, like
[email protected]
[email protected]
[email protected]
If the emails table contained only mail1@ and maiil2@, then you'd get back as results:
email found
______________ _____
[email protected] true
[email protected] false
[email protected] true
The advantage of doing it this way is that it will scale up to the billions of e-mails if needed (when the number gets large you might consider using a JOIN EACH instead of a JOIN).