Searching for users email contacts in db


I’m busying building a tool for my site where i get a users email contacts which i then want to match with email addresses of users in my database.

This is all fine, but my question is that if a user has hundreds of contacts, and im searching through thousands of users, isn’t this going to be a very intensive query?

SELECT userid FROM users WHERE email IN (" . implode(",",$contacts) . ")

Should i be doing this some other way or limit the number of users that i search for or is this not a problem? I have set the ‘email’ field as unique, but should i be doing some other kind of indexing?


no, the unique index is sufficient

do an EXPLAIN on the query to confirm :slight_smile:

by the way, i have more than one email address, and i don’t think i am very unique :smiley:


thanks very much!