Im trying to create a script that shows the most viewed documents, but it's creating many temporary tables on disk.... Here's the query, I don't see where the error is or where the query turns abusive.
select
notas.notid,
notas.ttl,
notas.brv,
notas.fch,
nots.notid,
nots.cnt,
nots.fch,
nots.sccn,
SUM(nots.hit) AS lasuma
FROM cadenano_cbc_noticias.notas
INNER JOIN cadenano_cbc_relacbc.nots
ON notas.notid = nots.notid
WHERE nots.cnt = 'notas'
AND nots.fch BETWEEN CURDATE() - INTERVAL 3 DAY AND CURDATE()
GROUP BY nots.notid
ORDER BY lasuma DESC
LIMIT 10
Can some one point me in the right direction?
You can speed up a query if you look at the part of the query that uses the data for calculations: where
clauses and order
clauses mostly.
If you don't have already then add indexes on nots.cnt
and nots.fch
.
It is also a good practice to run a explain
:
explain select notas.notid, ...
The output will tell you if keys are used and where not.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.