FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » General » Database discussions » Query taking 2 minutes (Board grinds to halt for that period of time)
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Query taking 2 minutes [message #163685 is a reply to message #163684] Wed, 24 November 2010 11:23 Go to previous messageGo to previous message
Ernesto is currently offline  Ernesto   Sweden
Messages: 413
Registered: August 2005
Karma:
Senior Member
I stripped off the ORDER BY clause in the SQL and added a group by t.id. I also changed the default sort order to DESC instead of ASC

The final echoed SQL for the "Unread posts" option now looks like this, when echoed:
SELECT 
m.id, m.thread_id, m.poster_id, m.post_stamp, m.msg_opt, m.apr,
t.id AS topic_id, t.thread_opt, t.root_msg_id, t.last_post_date, t.last_post_id, t.forum_id, t.views, t.replies, t.tdescr, 
f.message_threshold, f.name, 
u.id AS user_id, u.alias AS login, 
r.last_view, 
mm.id AS md, m2.subject AS thr_subject, 
COALESCE(g2.group_cache_opt, g1.group_cache_opt) AS group_cache_opt 
FROM fud26_msg m 
INNER JOIN fud26_thread t ON m.thread_id=t.id 
INNER JOIN fud26_msg m2 ON m2.id=t.root_msg_id 
INNER JOIN fud26_forum f ON t.forum_id=f.id 
INNER JOIN fud26_cat c ON f.cat_id=c.id 
INNER JOIN fud26_group_cache g1 ON g1.user_id=2147483647 AND g1.resource_id=f.id 
LEFT JOIN fud26_group_cache g2 ON g2.user_id=2002 AND g2.resource_id=f.id 
LEFT JOIN fud26_read r ON r.thread_id=t.id AND r.user_id=2002 
LEFT JOIN fud26_users u ON m.poster_id=u.id 
LEFT JOIN fud26_mod mm ON mm.forum_id=f.id AND mm.user_id=2002 
WHERE m.apr=1 
AND m.post_stamp > 0
AND (mm.id IS NOT NULL OR (COALESCE(g2.group_cache_opt, g1.group_cache_opt) & 2) > 0) 
GROUP BY t.id DESC LIMIT 0,40


This is however, not a suitable change if you wanna keep the functionality of showing all messages.

Basically what I changed was that I removed all ORDER BY, grouped it by thread_id (t.id) and stripped away unecessary columns from the message table that are not needed when displaying only topics.

I am not done yet, but obviously the ordering is the criminal here, especially when it tries to order hundreds of thousands of rows and entries.

I will try to post my alterations when done, still tweaking things for speed.


[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Cannot connect to database
Next Topic: Has anyone tried to use this w/SQL Server 2000
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 05:37:45 GMT 2024

Total time taken to generate the page: 0.03925 seconds