The first thing I did was to set up a local copy of Phpfox 5.3.0 RC1 (not yet released) with content (users, blogs, friends,...), then enabled the slow_query_log and set the long_query_time to 2, because this is a local server with no traffic I assumed a safe bet that no query would take longer than 2 seconds. Then I enabled log-queries-not-using-indexes to capture those in the slow query log. Then using the script I was able to find queries that could be optimized (theoretically at least).
There were indeed some queries using union and joins that could be optimized (large sites will likely see a performance increase in 5.3.0 RC1).
I do have to point out a couple of things:
First, some queries are being logged but they are meant to scan the full table, for example when getting all the user groups we want all the records in that table, using indexes would not improve performance because we want everything in that table, intentionally this table is typically very small, it defaults to 5 records and in normal circumstances shouldn't grow beyond 10 rows.
Second, In some cases, MySQL seemed to not want to use a specific index, for example with this query:
SELECT COUNT(*) FROM phpfox_user AS u JOIN phpfox_user_field AS ufield ON (ufield.user_id = u.user_id) WHERE u.status_id = 0 AND u.view_id = 0If you run that query with explain you will see that MySQL had many indexes to use but chose none, and in my test it did run a full table scan. So to help in this situation we implemented the function forceIndex(
$iCnt = $this->database() ->from($this->_sTable, 'u') ->forceIndex('status_id') ->join(Phpfox::getT('user_field'), 'ufield', 'ufield.user_id = u.user_id') ->where($this->_aConditions) ->execute('getSlaveField');There surely are queries still to fix, if you find them please let us know, we will continue looking for them but must also attend to other bug reports.
No comments:
Post a Comment