Post
Topic
Board Pools (Altcoins)
Re: [ANN] profit switching auto-exchanging pool - middlecoin.com
by
Test User
on 20/01/2014, 19:48:03 UTC
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})
You're right about the count(*), but other than the queries are identical.

Every DB I've ever used will elide the cross join in the first query into an inner join, when an appropriate equality exists in the where clause.

What is desperately needed here is indexing. shares.time should have an index, to avoid a table scan.