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
Comment #1
david lesieur commentedI have also taken this join out in the Faceted Search module, with no known adverse effects.
Comment #2
douggreen commentedI 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!
Comment #3
douggreen commentedI'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.
Comment #4
Anonymous (not verified) commentedI gave the patch a go on my 5.3 version site. Looks good to me.
Comment #5
dries commentedI've committed this to CVS HEAD. Thanks Robert. If Gabor wants to backport it to D6, he's welcome to do so.
Comment #6
gábor hojtsyDoes not apply against Drupal 6, needs a reroll.
Comment #7
catchChanging status.
Comment #8
david lesieur commentedRe-rolled for D6.
Comment #9
robertdouglass commentedComment #10
robertdouglass commentedha. David and I were working on it simultaneously.
Comment #11
david lesieur commentedI'll re-join the Search Sprint chat room... :)
Both patches are identical.
Comment #12
douggreen commentedI 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.
Comment #13
gábor hojtsyThanks, committed to D6.
Comment #14
robertdouglass commentedGiven that performance for search on D5 is still a hot topic this should get ported further.
Comment #15
tr commentedNot going to be backported now that 5.x is officially unsupported.