[wp-hackers] Time for a wp_post_relationships table?

Otto otto at ottodestruct.com
Wed Aug 4 19:32:16 UTC 2010


On Wed, Aug 4, 2010 at 2:08 PM, Mike Schinkel
<mikeschinkel at newclarity.net> wrote:
> When I see that type of code like above, it saddens me.  That potentially runs two queries (assuming no cache hit) when it could run easily one. WordPress is starting to add more MySQL queries per page load and query drain performance; better not to propagate them it possible. And if the number of "connected records" is large, it could generate a huge query being sent to MySQL not the least of which if it has to loop through all the records once to build the array of connected ids and a second time loop through all the post records yet again, this time to collect up the posts. Things like that add up.
>
> A more performant way to do that would be to use a posts_join and posts_where hook to add a "related_to" and/or "related_from" arguments that appends the correct join and where clauses reducing to a single query what should be a single query.  Better yet would be to add wp_post_relationships to WordPress core and add those parameters into query() itself.

Ugh. No, man. 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
to the database server. Why? Because the DB server is generally your
major bottleneck. Loading any sort of work onto it with JOINs and the
like causes you nothing but trouble in the long run.

Note, I'm not commenting on the specific code, just making a general
observation. If I can do two or three queries with no joins, it's
usually a heck of a lot faster than one complicated query with two or
three joins. Less queries is not always better.

-Otto


More information about the wp-hackers mailing list