I have this query:

```
SELECT * 
FROM wp_dev_posts, wp_dev_postmeta, wp_dev_term_relationships 
WHERE ((post_type = 'projects') OR (post_type = 'post_cost_codes')) 
    AND (wp_dev_posts.ID = wp_dev_postmeta.post_id) 
    AND (wp_dev_posts.ID = wp_dev_term_relationships.object_id);
```

My question, is that when I have this in the where:

    wp_dev_posts.ID = wp_dev_term_relationships.object_id

What's the correct way to optimize this? Am I better to use joins? Do I set index's? Do I use foreign keys? On a large database this is actually take a few seconds to run.

SQL newbie here.

FYI, this is Wordpress, with 33k rows in posts, about 250k rows in postmeta.