Post
Topic
Board Pools (Altcoins)
Re: [ANN] profit switching auto-exchanging pool - middlecoin.com
by
turner3d
on 20/01/2014, 18:25:29 UTC
I hope the query on the "suggestion" is not what's in place; it's terribly inefficient. For starters, "FROM shares,users" is doing a left join which takes exponentially more resources than the appropriate inner join.

Suggested in http://pastebin.com/TQ206qQj:
Code:
SELECT users.username,COUNT(shares.*) FROM shares,users WHERE time<=FROM_UNIXTIME(1389867642) AND our_result='Y' AND users.userid=shares.userid GROUP BY shares.userid;

Much more efficient query:
Code:
SELECT u.username, COUNT(s.id)
FROM shares s
INNER JOIN users u ON u.userid=s.userid
WHERE s.time<=FROM_UNIXTIME(1389867642) AND s.our_result='Y'
GROUP BY s.userid

Note that this assumes that the shares table has an "id" column referenced in the COUNT operator. Doing a COUNT(*) also burns up unnecessary resources; it should be COUNT({unique column})