I don't have my new system set up yet and I'm not familiar with git(hub), but here's my code suggestion for most_solve_hours.php, maybe someone else wants to integrate it into the repository (if not, I'll do it, but I don't know when). Or maybe it can just serve as an example for how to precompute and use stuff later. I tested this code when I wrote it recently, and it did speed up the very slow original query a lot.
Do this once after every update/import of the database:
Code:
DROP TABLE HelperMostSolveHours;
CREATE TABLE HelperMostSolveHours
SELECT personId, personCountryId, continentId, year,
(sum( if(value1>0,value1,0) ) +
sum( if(value2>0,value2,0) ) +
sum( if(value3>0,value3,0) ) +
sum( if(value4>0,value4,0) ) +
sum( if(value5>0,value5,0) ))/100/60/60 hours,
personName
FROM Results
JOIN Events ON Events.id = eventId
JOIN Competitions ON Results.competitionId = Competitions.id
JOIN Countries ON Results.countryId = Countries.id
WHERE format = 'time'
GROUP BY personId, Results.countryId, year;
Use this (well, with the dynamic conditions instead of hardcoded year<=2008 etc, of course) in the viewer script:
Code:
SELECT sum(hours) hours, personId, personName, personCountryId
FROM HelperMostSolveHours
WHERE continentId = '_Europe'
AND year <= 2008
GROUP BY personId
ORDER BY hours DESC
LIMIT 100;
Some timings on my PC:
Original query: 15-17 seconds
Original query simply without the "LIMIT 100": 1.0-1.7 seconds
(Very interesting, somehow telling it to produce less made it a lot slower... apparently the overhead of trying to do less work actually made it a lot *more* work.)
Precomputation: 3 seconds
Query using the precomputed table: 0.1-0.2 seconds
Bookmarks