PHPWiki has a 5 second slow query each time you save a page edit. The query caught often in the "mysql-slow.log" is:
INSERT INTO wikiscore
SELECT w1.topage, COUNT(*)
FROM wikilinks AS w1, wikilinks AS w2
WHERE w2.topage=w1.frompage
GROUP BY w1.topage;
The current indexes are as follows:
table "wikilinks" has a primary index on "frompage" and "topage"
table "wikiscore" has a primary index on "pagename" and "score"
How could I reformulate the SELECT query to return the same results faster? How could I change the indexes so this query would be faster? My thought is it might be OVER-indexed?
I've timed the result of the SELECT part of the query only and it takes 1-2 seconds alone. The INSERT must take up the rest of that time.
There is a lag when saving pages that I would like to eliminate. I do not have the option of upgrading to another wiki engine (or version of PHPwiki) due to the amount of modifications that have been done.
Any ideas?
edit---
The results of "EXPLAIN" on the SELECT part of the query were:
SIMPLE
w2
index
PRIMARY
204
31871
Using index; Using temporary; Using filesort
SIMPLE
w1
ref
PRIMARY
PRIMARY
102
phpwiki.w2.topage
14
Using index