- Affected version
- 2.1.x
I'm not sure if this should be considered bug or improvement request , I run a forum where
has more than 24M records , my slow query log is full with
This query takes about 16 seconds on a powerful server
after applying some optimizations it now takes only 0.2 seconds
suggested optimizations include
1 - creating optimal indexes
2- Avoiding Optimizer Hints
causes performance degradation.
3- Avoiding type casting
while preparing query , method
converted
to string , this prevents MySQL using index if column is indexed
Code:
xf_reaction_content
SQL:
SELECT content.reaction_id, COUNT(*)
FROM xf_reaction_content AS content
FORCE INDEX (content_user_id_reaction_date)
INNER JOIN xf_reaction AS reaction ON
(content.reaction_id = reaction.reaction_id)
WHERE content.content_user_id = '125'
AND reaction.active = 1
AND content.is_counted = 1
GROUP BY content.reaction_id
ORDER BY reaction.display_order;
This query takes about 16 seconds on a powerful server
after applying some optimizations it now takes only 0.2 seconds
suggested optimizations include
1 - creating optimal indexes
Code:
ALTER TABLE `xf_reaction` ADD INDEX `xf_reaction_idx_active_reaction_id` (`active`,`reaction_id`);
ALTER TABLE `xf_reaction_content` ADD INDEX `xf_reaction_content_idx_content_id_is_counted_reaction_id` (`content_user_id`,`is_counted`,`reaction_id`);
2- Avoiding Optimizer Hints
SQL:
FORCE INDEX (content_user_id_reaction_date)
3- Avoiding type casting
while preparing query , method
Code:
fetchPairs()
Code:
$userId