LIVE FROM THE MINNESOTA SEARCH SPRINT

The old queries:

SELECT SUM(i.score * t.count) AS score FROM search_index i INNER JOIN search_total t 
  ON i.word = t.word 
  INNER JOIN node n ON n.nid = i.sid 
  INNER JOIN users u ON n.uid = u.uid 
  WHERE n.status = 1 
    AND (i.word = 'drupal' OR i.word = 'rocks') 
    AND i.type = 'node' GROUP BY i.type, i.sid 
  HAVING COUNT(*) >= 2 ORDER BY score DESC LIMIT 0, 1;            


SELECT i.type, i.sid, 
  10 * (3.38941376736 * SUM(i.score * t.count)) +
  5 * POW(2, (GREATEST(MAX(n.created), MAX(n.changed), MAX(c.last_comment_timestamp)) - 1038678891) * 6.43e-8) + 
  1 * (2.0 - 2.0 / (1.0 + MAX(c.comment_count) * 0.00271002710027)) AS score 
FROM search_index i 
INNER JOIN search_total t ON i.word = t.word 
INNER JOIN node n ON n.nid = i.sid 
INNER JOIN users u ON n.uid = u.uid
LEFT JOIN node_comment_statistics c ON c.nid = i.sid 
WHERE n.status = 1 
  AND (i.word = 'drupal' OR i.word = 'rocks') 
  AND i.type = 'node' 
GROUP BY i.type, i.sid HAVING COUNT(*) >= 2 
ORDER BY score DESC LIMIT 0, 10 

In both cases, the clause INNER JOIN users u ON n.uid = u.uid is superfluous. Taking it out produces identical results and executes faster.

Comments

david lesieur’s picture

I have also taken this join out in the Faceted Search module, with no known adverse effects.

douggreen’s picture

Status: Needs review » Reviewed & tested by the community

I reviewed and agree that this is superfluous. None of the joins use user columns. I checked all of the {node}, {search_index} clauses, the clauses from the node-ranks such as {node_comment_statistics} and {node_count}, and the clauses from the advanced search form such as {term_node}. It passes all existing tests plus the new tests in #145242.

Great catch Robert! Marking as RTBC!

douggreen’s picture

I've also reviewed 5.x and 6.x and think that this can be backported, given that a few more eyes look at it and do some testing.

Anonymous’s picture

I gave the patch a go on my 5.3 version site. Looks good to me.

dries’s picture

Version: 7.x-dev » 6.x-dev

I've committed this to CVS HEAD. Thanks Robert. If Gabor wants to backport it to D6, he's welcome to do so.

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Needs work

Does not apply against Drupal 6, needs a reroll.

catch’s picture

Status: Needs work » Patch (to be ported)

Changing status.

david lesieur’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new930 bytes

Re-rolled for D6.

robertdouglass’s picture

Status: Needs review » Patch (to be ported)
StatusFileSize
new923 bytes
robertdouglass’s picture

ha. David and I were working on it simultaneously.

david lesieur’s picture

Status: Patch (to be ported) » Needs review

I'll re-join the Search Sprint chat room... :)

Both patches are identical.

douggreen’s picture

Status: Needs review » Reviewed & tested by the community

I confirmed that the patch applies to the DRUPAL-6 tag and I tested search on the 100k node database and the patch returns the expected results.

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, committed to D6.

robertdouglass’s picture

Version: 6.x-dev » 5.x-dev
Status: Fixed » Patch (to be ported)

Given that performance for search on D5 is still a hot topic this should get ported further.

tr’s picture

Status: Patch (to be ported) » Closed (won't fix)

Not going to be backported now that 5.x is officially unsupported.