I have a table of users with around 1 million records "contacts".
And we keep a log of the emails we sent in another table "log\_sent" which is also around 1M records.

We need to find which users havn't received our newsletter yet.
So i am using the following query to get the next user we need to send to:

```
SELECT contact.* 
FROM contacts AS contact
LEFT JOIN log_sent AS sent ON sent.contact_id = contact.id
WHERE sent.id IS NULL 
LIMIT 0 , 1

```

This is what the EXPLAIN query returns:

```
id | select_type | table   | type | possible_keys | key        | key_len | ref                        | rows    | Extra
  1 | SIMPLE      | contact | ALL  | NULL          | NULL       | NULL    | NULL                       | 1031628 | 
1 | SIMPLE      | sent    | ref  | contact_id    | contact_id | 4       | admin_marketing.contact.id | 1       | Using where; Not exists

```

The log\_sent table has `contact_id` indexed.
The contacts table has `id` as the **primary index**.

This query take about **`1.8`** seconds to execute.
And the log\_sent table is growing so this will be problematic. How can I optimize this query.

For what i understand it seems that the query is search all 1 million records in the contacts table. But there is really no index i can use to limit the number of users used.
Or maybe i'm missing something ?