MartinThoma / write-math

On-line recognition of mathematical formulae
MIT License
46 stars 5 forks source link

Eliminate JOINs in gallery for speedup #43

Open MartinThoma opened 9 years ago

MartinThoma commented 9 years ago

Currently, the gallery page is too slow, because of queries like

SELECT `wm_raw_draw_data`.`id`, `data` as `image`, `creation_date`,
       COUNT(`wm_partial_answer`.`recording_id`) as `answers`,
       COUNT(`wm_worker_answers`.`raw_data_id`) as `answers2`
FROM `wm_raw_draw_data`
LEFT OUTER JOIN `wm_partial_answer`
     ON (`recording_id` = `wm_raw_draw_data`.`id`)
LEFT OUTER JOIN `wm_worker_answers`
     ON (`wm_worker_answers`.`raw_data_id` = `wm_raw_draw_data`.`id`)
WHERE
    `accepted_formula_id` IS NULL AND `is_image`=0 AND
    `classifiable`=1 AND `stroke_segmentable`=1 AND
    `nr_of_symbols` = 1
GROUP BY `wm_raw_draw_data`.`id`
HAVING `answers` > 0 OR `answers2` > 0
ORDER BY `probability` DESC ";

This could probably be much faster if the counters answers (user answers) and answers2 (automated answers) were just simple rows of that table.