News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

SMF 1.1 query speedup tip

Started by Nibbler, November 17, 2005, 02:09:30 PM

Previous topic - Next topic

Nibbler

Hi,

While working to reduce mysql usage I noticed that this query was starting to appear in the slow query log (set at 2 seconds):


  SELECT COUNT(ID_MSG)
  FROM smf_messages
  WHERE posterTime < N
  AND ID_TOPIC = N


So I extended this key:

KEY posterTime (posterTime)

to this:

KEY posterTime_topic (posterTime,ID_TOPIC)

And changed the query to a SELECT COUNT(*) so that the new key will be used.

This gave this performance increase on a sample query from:


mysql> SELECT COUNT(ID_MSG)
    ->                                 FROM smf_messages
    ->                                 WHERE posterTime < 1132250283
    ->                                         AND ID_TOPIC = 15;
+---------------+
| COUNT(ID_MSG) |
+---------------+
|         79379 |
+---------------+
1 row in set (1.51 sec)


to


mysql> SELECT COUNT(*)
    ->                                 FROM smf_messages
    ->                                 WHERE posterTime < 1132250283
    ->                                         AND ID_TOPIC = 15;
+----------+
| COUNT(*) |
+----------+
|    79379 |
+----------+
1 row in set (0.06 sec)


I hope this is useful to someone.

For reference, the forum is http://www.bettandget.org/forum/ [nofollow] running on MySQL 4.0.25
I wanna be sedated.

Grudge

Thanks for the tip, we'll look into it. If you have any more suggestions then by our guests :)
I'm only a half geek really...

Joshua Dickerson

In MySQL 5 it should be able to use the key for ID_TOPIC ;)
Come work with me at Promenade Group



Need help? See the wiki. Want to help SMF? See the wiki!

Did you know you can help develop SMF? See us on Github.

How have you bettered the world today?

Compuart

Thanks for posting this suggestion. The query you mentioned and more of these type of queries will be addressed in RC2.
Hendrik Jan Visser
Former Lead Developer & Co-founder www.simplemachines.org
Personal Signature:
Realitynet.nl -> ExpeditieRobinson.net / PekingExpress.org / WieIsDeMol.Com

Advertisement: