Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-04-2007, 02:15 PM
mfyvie mfyvie is offline
 
Join Date: Mar 2007
Location: Zurich, Switzerland
Posts: 336
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default mysql performance problem: inefficent query?

Hi guys,

I recently modified and ported someone else's mod to 3.6.x over on this post:

https://vborg.vbsupport.ru/showpost....17#post1199617

The original mod was to ensure to that all users get a unique avatar, and that they can't select the same avatar from the gallery. I changed the original query so that it provided the functionality I wanted (used avatars would simply disappear from the list).

In the last few months I've noticed periods where the board gets slow and I get reports via email of mysql exceeding the allowed number of connections.

I started logging the data and discovered that the same query was always present whenever there was a problem. This query seems to stay in the state "copying to tmp table" for some time. All other queries (like from other users going about their business on the forum) seem to be in a locked state until this original query clears.

When the system isn't busy, this query obviously clears in a reasonable period of time, and nobody notices. However, when the system is busy this query can take over a minute, and as the additional queries stack up, the number of connections soon runs out.

Unfortunately I don't know very much about mysql, I just kind of hacked this query together through trial and error, but this is what it looks like:

Code:
SELECT avatar.*, imagecategory.title AS category, user.avatarid AS useravatarid
FROM avatar AS avatar LEFT JOIN imagecategory AS imagecategory USING(imagecategoryid) LEFT JOIN user AS user ON (user.avatarid=avatar.avatarid)
WHERE minimumposts <= 2675
AND avatar.imagecategoryid=16
AND avatar.avatarid <> 0
AND ISNULL(user.avatarid)
ORDER BY avatar.displayorder
LIMIT 0,100
This was the exact query that I got from the "show full processlist" in mysql. It executed when I went into the control panel to select an avatar from the gallery.

Remember this query is not the vbulletin default!

So I have two questions:

1. Why do all other mysql queries get assigned a locked state before this one finishes?
2. Is there something about my query which is causing a massive load on the server? Surely it should complete in less than 1-2 minutes? Is there a more efficient way to write this query?

Thanks in advance for any assistance.

Just an update to this issue. I managed to solve the problem myself by adding an index to users.avatarid. I updated the original thread (referenced at the top of this thread) with the issue and the solution.
Reply With Quote
  #2  
Old 05-07-2007, 05:51 AM
Eikinskjaldi's Avatar
Eikinskjaldi Eikinskjaldi is offline
 
Join Date: Feb 2006
Location: Hell, never looked better
Posts: 572
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by mfyvie View Post
Unfortunately I don't know very much about mysql, I just kind of hacked this query together through trial and error, but this is what it looks like:

Code:
SELECT avatar.*, imagecategory.title AS category, user.avatarid AS useravatarid
FROM avatar AS avatar LEFT JOIN imagecategory AS imagecategory USING(imagecategoryid) LEFT JOIN user AS user ON (user.avatarid=avatar.avatarid)
WHERE minimumposts <= 2675
AND avatar.imagecategoryid=16
AND avatar.avatarid <> 0
AND ISNULL(user.avatarid)
ORDER BY avatar.displayorder
LIMIT 0,100
This was the exact query that I got from the "show full processlist" in mysql. It executed when I went into the control panel to select an avatar from the gallery.

Remember this query is not the vbulletin default!

So I have two questions:

1. Why do all other mysql queries get assigned a locked state before this one finishes?
2. Is there something about my query which is causing a massive load on the server? Surely it should complete in less than 1-2 minutes? Is there a more efficient way to write this query?

Thanks in advance for any assistance.

Just an update to this issue. I managed to solve the problem myself by adding an index to users.avatarid. I updated the original thread (referenced at the top of this thread) with the issue and the solution.
1) Whether or not a query locks the system depends on which indices it is using, which version of mysql you are running, and how long the query takes to run.

2) When writing a new query, always get an explain first. You can do this from the command line or phpmyadmin or similar, just put the word "explain" in front of the select. It will spit out a table showing you how much work is involved in the query. Details of the output can be found here
http://dev.mysql.com/doc/refman/5.0/en/explain.html

If adding an index didn't help with the speed, and you have system access to your db, you can also play around with the tmp table parameters.
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 07:44 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04577 seconds
  • Memory Usage 2,176KB
  • Queries Executed 13 (?)
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
  • (2)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (2)post_thanks_box
  • (2)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit_info
  • (2)postbit
  • (2)postbit_onlinestatus
  • (2)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_postinfo_query
  • fetch_postinfo
  • 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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete