Mysql – Left outer join ruins query in MySQL


I have two tables. One of them is big, long with more than 500 columns (most of those are tinyint) and 360000 rows. It contains info about photos. Second one is small with just three int columns (surrogate primary key and two foreign keys) and one decimal. It has just 45000 rows and contains info about what people are on those photos. It's so small it doesn't even have indexes. What I have trouble with is selecting photos within clause that have no people marked on them.
Query with clause within just first big table takes acceptable few seconds. Then I make something like that

SELECT photos.* FROM photos 
 photos_people ON photos.photo_id = photos_people.photo_id 
WHERE photos_people.photo_people_id is NULL AND ... LIMIT 150;

Now it suddenly takes literally minutes. What am I doing wrong? Is there a way to speed up query?

Best Answer

Add an index on the column photo_id on both the tables- photos and photo_people.