Hi all,
New to the forum, glad to find it.
I work with WordPress and we’re having a debate on the WordPress developers mailing list about which is better: 1 query with joins or multiple queries? This is a statement that was made on the list:
[B]Quote:[/B] |
[I]Complex queries are the death of WP sites. Consider that
in most of the webhosting in this world, database servers are shared
amongst many websites. So you want to rely on the database as little
as possible.
Two simpler queries are often preferable to one query which adds load Note, I’m not commenting on the specific code, just making a general |
That goes against everything I’d learned in the past, but maybe he is right?
Here’s some psuedo-code mixing MySQL and PHP showing the different choices we were discussing:
1.) $slug = 'actor’SELECT p.post_title FROM wp_posts pINNER JOIN wp_term_relationships tr ON p.ID=tr.object_id INNER JOIN wp_term_taxonomy tt ON tr.term_taxonomy_id=tt.term_taxonomy_idINNER JOIN wp_terms t ON tt.term_id=t.term_idWHERE t.slug=$slug2.) $slug = ‘actor’$result = SELECT tr.object_id FROM wp_term_relationships tr INNER JOIN wp_term_taxonomy tt ON tr.term_taxonomy_id=tt.term_taxonomy_idINNER JOIN wp_terms t ON tt.term_id=t.term_idWHERE t.slug=$slugforeach($result as $row) $ids[] = $row->object_idSELECT post_title FROM wp_posts WHERE ID IN (ids)
Thanks in advance for your help in understanding this.