I was trying to count the userpoints per category. The query works if I use a single level of category match. But if I try to get the points on subcategories too, the query gets too slow as it runs on uservotes table having thousands of rows. Is there a better way to do this? The current query is as follows with part of it coming from points update function in the core.
$catfilter = " and (userid_src.categoryid = b.categoryid or userid_src.categoryid in (
select categoryid from ^categories where parentid = b.categoryid)
or userid_src.categoryid in (
select categoryid from ^categories where parentid in (select categoryid from ^categories where parentid = b.categoryid)))";
$query1 = "insert into ^catpoints (categoryid, userid, points) (select b.categoryid,#, ".
$calculations['aselecteds']['multiple']."*(select ".$calculations['aselecteds']['formula'].$catfilter.")+".
$calculations['avoteds']['multiple']."*(select ".$calculations['avoteds']['formula'].$catfilter.")
as points
from ^categories b) on duplicate key update ^catpoints.points=points";