Forum Moderators: open
SELECT docid, (SUM(totalscore)) AS totalscore FROM wordlist WHERE stemmed='word1' OR stemmed='word2' GROUP BY docid ORDER BY totalscore DESC
Here is the explain:
table: wordlist
type: range
possible keys: stemmed
key: stemmed
key len: 10
ref: NULL
rows: 20099
extra: using WHERE; using temporary; using filesort
Can anyone help me with why this query is so slow? and if so, how could I speed it up? Thanks!
Have you tried it with only one WHERE?
Have you tried it without the SUM()?
Your index looks fine for the query.
Sometimes Scalar functions with Group By take longer to execute because it has to find the row first, then store the results.
Try it in various combinations to see which works the fastest to get a benchmark.