Skip to content

Commit

Permalink
Optimize recent-submissions and recent-failed-submissions queries to …
Browse files Browse the repository at this point in the history
…avoid a full table scan
  • Loading branch information
cdhowie committed May 27, 2011
1 parent 15c9956 commit 3805dcf
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions htdocs/admin/index.php
Expand Up @@ -40,17 +40,21 @@ public function indexDefaultView()
sw.result AS result,
sw.time AS time
FROM
pool p,
worker w,
submitted_work sw
FROM (
SELECT pool_id, worker_id, result, time
WHERE sw.worker_id = w.id
AND sw.pool_id = p.id
FROM submitted_work
ORDER BY sw.id DESC
ORDER BY id DESC
LIMIT 10
LIMIT 10
) sw
INNER JOIN pool p
ON p.id = sw.pool_id
INNER JOIN worker w
ON w.id = sw.worker_id
');

$viewdata['recent-failed-submissions'] = db_query($pdo, '
Expand All @@ -60,18 +64,23 @@ public function indexDefaultView()
sw.result AS result,
sw.time AS time
FROM
pool p,
worker w,
submitted_work sw
FROM (
SELECT pool_id, worker_id, result, time
FROM submitted_work
WHERE result = 0
ORDER BY id DESC
WHERE sw.worker_id = w.id
AND sw.pool_id = p.id
AND sw.result = 0
LIMIT 10
) sw
ORDER BY sw.id DESC
INNER JOIN pool p
ON p.id = sw.pool_id
LIMIT 10
INNER JOIN worker w
ON w.id = sw.worker_id
');

$viewdata['worker-status'] = db_query($pdo, '
Expand Down

0 comments on commit 3805dcf

Please sign in to comment.