1

I have a view with a flag (relationship, only show flagged nodes). I have modified it a few times and now I see in the query output that views has the join added twice:

INNER JOIN {flag_content} flag_content_node ON node.nid = flag_content_node.content_id AND flag_content_node.fid = '9'
LEFT JOIN {flag_content} flag_content ON node.nid = flag_content.content_id AND flag_content.fid = '9'

Is there a performance hit for the extra LEFT JOIN?

  • I am going to assume that the INNER JOIN is added to do the "only show flagged nodes" part of the query, and that the LEFT JOIN is there to satisfy the flag relationship itself. Why they aren't merged together I dunno, but if you can or want to modify the query, I THINK LEFT JOIN {flag_content} flag_content ON node.nid = flag_content.content_id AND flag_content.content_id IS NOT NULL AND flag_content.fid = '9' will do it and take out the more expensive INNER JOIN in the process. – Jimajamma Apr 11 '13 at 0:08
  • "Is there a performance hit for the extra LEFT JOIN?" The way to answer this is not by a question but by measurement. If there's only a few rows in the flag_content table, almost certainly not. If there are millions, maybe. If that's your case and this query gets runs a lot you may want to optimize it, but you shouldn't do so until you are sure it's going to make a difference. – Alfred Armstrong Apr 11 '13 at 13:17
0

Astonish Design did a good write up on this topic: Writing Efficient Queries in Drupal.

You should measure your specific queries though, it always depends on the amount of data you are working with, proper indices, mysql configuration and so on. Joining too many tables will almost always increase your query execution time, keep that in mind.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.