Problem Summary
From Redmine:
Root Cause Analysis
The slowness was caused by the get_categories_for_contexts function in qbank_managecategories\helper. This function used a Correlated Subquery inside the main SELECT statement to calculate the questioncount for each category.
This means for every single category row returned, a complex subquery was executed again. If there were 1,000 categories, the subquery would run 1,000 times, leading to extremely poor performance.
The original problematic SQL looked something like this:
SELECT c.*,
(SELECT COUNT(1) ... WHERE ... c.id = qbe.questioncategoryid ...) AS questioncount
FROM {question_categories} c
WHERE ...