Go Back   vb.org Archive > Community Discussions > Forum and Server Management
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-07-2008, 04:19 PM
tscbh tscbh is offline
 
Join Date: Jun 2005
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Slow queries

I had this type of query which show on my slow-queries log. It always cost my server about 5~6 seconds.

Could you please tell me if this is normal. How do I optimize it?

I do not have any other queries as slow as that.

# Time: 080507 18:05:58
# User@Host: forum @ [192.168.0.1]
# Query_time: 5 Lock_time: 0 Rows_sent: 30 Rows_examined: 328846
use forum;
SELECT user.*,usertextfield.*,userfield.*, user.userid, options,
IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid
,IF((NOT(options & 1024) AND (user.usergroupid IN (-1,6) OR FIND_IN_SET('6', membergroupids))), 0, reputation) AS reputationscore,level
,avatar.avatarpath,NOT ISNULL(customavatar.userid) AS hascustomavatar,customavatar.dateline AS avatardateline, customavatar.width AS avwidth, customavatar.height AS avheight

, IF((options & 512 AND user.userid <> 0), 1, lastactivity) AS lastvisittime

FROM user AS user
LEFT JOIN usertextfield AS usertextfield ON(usertextfield.userid=user.userid)
LEFT JOIN userfield AS userfield ON(userfield.userid=user.userid)
LEFT JOIN reputationlevel AS reputationlevel ON(user.reputationlevelid=reputationlevel.reputati onlevelid)
LEFT JOIN avatar AS avatar ON(avatar.avatarid = user.avatarid) LEFT JOIN customavatar AS customavatar ON(customavatar.userid = user.userid)

WHERE 1=1
AND user.usergroupid IN (-1,6,7,2,5)
ORDER BY reputationscore asc , user.username
LIMIT 61680, 30;
Reply With Quote
  #2  
Old 05-07-2008, 04:21 PM
ssslippy ssslippy is offline
 
Join Date: Jan 2006
Posts: 877
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Do you have your avatars stored in the database?
Reply With Quote
  #3  
Old 05-07-2008, 08:07 PM
tscbh tscbh is offline
 
Join Date: Jun 2005
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yeah,

Thanks ssslippy. I move it to file storage now. I couldn't believe it's served from the database! I have more than 80,000 members. That's why my database server so slow.
Reply With Quote
  #4  
Old 05-08-2008, 09:51 PM
ssslippy ssslippy is offline
 
Join Date: Jan 2006
Posts: 877
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Dont forget to move your attachments there also and user album pictures should also be stored to files instead of the database.
Reply With Quote
  #5  
Old 05-08-2008, 09:59 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

And, don't forget that if they are stored in the filesystem, they do NOT get backed up when you backup your database. You must back those files/directories up separately now.
Reply With Quote
  #6  
Old 05-09-2008, 12:03 AM
tscbh tscbh is offline
 
Join Date: Jun 2005
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi guys,

Thanks for all the tips.

I already moved all attachments (I don't have user album pictures), but yesterday I still got slow queries on my sql server.

I used a separate server for sql. This server is using only 5% of the CPU on average.

I don't know why I got that sql queries. Do I have to index anything to make it faster. What I see is mysql server examine 328,846 rows. This is not good isn't it?

Any suggestion?
Reply With Quote
  #7  
Old 05-09-2008, 03:57 PM
ssslippy ssslippy is offline
 
Join Date: Jan 2006
Posts: 877
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can you tell us what page and what query is causing this? I dont see why anything should be looking at 300k rows.
Reply With Quote
  #8  
Old 05-09-2008, 05:44 PM
tscbh tscbh is offline
 
Join Date: Jun 2005
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I have no idea which page does it. My forum is pretty simple, very limited mod used.

I got about 20 of this queries in 1 days. This isn't much, but hackers can use this to attach my server.

After examining the slow queries log, I found that some queries examine as much as 420K rows.

Any idea?
Reply With Quote
  #9  
Old 05-09-2008, 07:50 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You need to go do a search through your pages to see where this query is being used. Do a global search for something like "ISNULL(customavatar.userid) AS hascustomavatar" since it looks like a pretty specific thing that doesn't get used often.

edit: Yep, only 22 instances. It looks very much like the query in memberlist.php on line 562. Start with that, see if it's the same query and if there are additions to the query from the standard (like from the hook above it - memberlist_fetch).
Reply With Quote
  #10  
Old 05-10-2008, 01:33 AM
ssslippy ssslippy is offline
 
Join Date: Jan 2006
Posts: 877
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Would you happen to have living avatars installed?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:48 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05474 seconds
  • Memory Usage 2,247KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete