Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
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 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 at 13:17

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.