I think that SELECT needs a LIMIT 1 on it; from memory this will pull all matching records even though we only care if there is just a single one.