The current 6.x-2.x dev views build uses LEFT JOINs ... consider use of INNER JOINs as an alternative.

Originally posted here:
http://groups.drupal.org/node/10840

Comments

merlinofchaos’s picture

Status: Active » Fixed

Keep in mind that unless you're using a filter to get the information, a LEFT join is preferable. So in general, Views prefers the left join to an INNER.

In the case of some filters, it may be worthwhile to change the join to an INNER, but we have to be careful. An exclusion join won't work with an INNER (term_node.nid NOT IN (3, 4, 5)) so the logic has to be very aware of all the possible permutations.

For example, for the 'reduce duplicates' version of OR, we also need a LEFT join. That's because we do this crazy join that creates a single JOIN for each term (LEFT JOIN foo ON foo.nid = n.nid AND foo.tid = $term) and then adds a filter so that the join succeeds if any one of the variously joined foo.tables comes up with a hit. (Thus preventing duplicate records if *multiple* terms hit).

And looking at the code, the simple OR join without the reduce duplicates actually doesn't pull the $join object, so it's slightly more complicated to go and change that. Tho only 2 lines of code there since it's already set up to pull the join elsewhere and, heh, I had already made it an easy method here.

BTW if you want to go crazy, read the code for the many to one helper. =)

I made some changes and tried all the permutations I can think of and I think I have it working right.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.