vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Forum and Server Management (https://vborg.vbsupport.ru/forumdisplay.php?f=232)
-   -   Unoptimized query (https://vborg.vbsupport.ru/showthread.php?t=223931)

cobaku 09-25-2009 11:42 AM

Unoptimized query
 
is below query normal it sometimes takes 27 seconds on some big forum sections which kills performance like crazy

from what i understand it only counts number of threads in certain forums
yes there are alot of threads on my forum but is there anything i can do to optimize this query, there is 1 more but i can live with the other.

Somehow i feel like noone can help me.


PHP Code:

SELECT COUNT(*) AS threadsSUM(IF(thread.lastpost 1253852688 AND open <> 1010)) AS newthread

FROM thread 
AS thread


WHERE forumid 
1220
    
AND sticky 0
    
     
AND visible IN (0,1,2)

id    select_type    table    type    possible_keys    key    key_len    ref    rows    Extra
1    SIMPLE    thread    range    forumid    forumid    6         119685    Using where

Time Before
0.24812 seconds
Time After
3.76783 seconds
Time Taken
3.51971 seconds

Memory Before
3,558.711 KB
Memory After
3,558.566 KB
Memory Used
: -0.145 KB 


Dean C 09-25-2009 01:06 PM

How many threads are we talking? Also where did you pull that query from?

sockwater 09-25-2009 01:26 PM

Quote:

Originally Posted by Dean C (Post 1890423)
How many threads are we talking? Also where did you pull that query from?

forumdisplay.php line 720 in 3.8.4.

Dean C 09-25-2009 02:23 PM

I don't have a copy of vB's database handy to check, so check this index doesn't already exist. Try creating an index on the thread table with these fields in this order:

INDEX(forumid, sticky, visible)

Saying that, that query shouldn't be be particularly show. Can you also paste the full profiling output.

kmike 09-25-2009 02:40 PM

The query is already using that index, according to EXPLAIN in the first post:
Code:

id    select_type    table    type    possible_keys    key    key_len    ref    rows    Extra
1    SIMPLE    thread    range    forumid    forumid    6        119685    Using where

It's just that the number of matching rows is too big.
I'm afraid nothing could be done from the vBulletin side of things. Maybe some MySQL server tweaking will help to speed up that query.

Dean C 09-25-2009 05:35 PM

Quote:

Originally Posted by kmike (Post 1890464)
The query is already using that index, according to EXPLAIN in the first post:
Code:

id    select_type    table    type    possible_keys    key    key_len    ref    rows    Extra
1    SIMPLE    thread    range    forumid    forumid    6        119685    Using where

It's just that the number of matching rows is too big.
I'm afraid nothing could be done from the vBulletin side of things. Maybe some MySQL server tweaking will help to speed up that query.

Yep I did say check the index doesn't already exist ;)

Code:

KEY forumid (forumid, visible, sticky, lastpost),

Adrian Schneider 09-25-2009 05:46 PM

1 Attachment(s)
All code optimizations aside, you could edit this forum so it only shows threads from the past 6 months or year instead. This should significantly reduce the # of threads and still utilize the index.

kmike 09-25-2009 06:18 PM

Oh yes.
Hopefully the default sort order for that forum is by the last post time, otherwise the index wouldn't work.

cobaku 09-25-2009 07:53 PM

thanks so much for the replies , i think i understand the solution from the replies
i am on it right now

that forumid had 120.000 threads

--------------- Added [DATE]1253994808[/DATE] at [TIME]1253994808[/TIME] ---------------

i could only do siradrian's solution and it works.

Do you think this mod will help me with only single query
https://vborg.vbsupport.ru/showthread.php?t=210897
it looks a little hard.

Adrian Schneider 09-28-2009 09:11 AM

Afraid not. That mod is just to help automate common administrative queries. The easiest solution to implement is changing the option I mentioned above.

If you do not want to do that (and honestly I don't see why not...) then here is my thought.... Why on earth would you want to browse through 120,000 threads? The data does not get lost; you can still search and find it. I don't see people going past about 5-10 pages. Maybe 20 if they are bored. People use searching.

If your forum is that busy, where you cannot restrict posts by the past 6-12m because users will want to browse further, then I would suggest that you create some subforums and shift the content there instead. This way you can index by forumid and get way faster results without losing any user experience.

Anyway, if you insist on returning huge datasets back to the user, then here are more ideas:

Upgrade your hardware - This is generally expensive and will only solve the problem temporarily.

Implement caching - If you use 3rd party caching, I suppose it's of medium difficulty to set up. If you use MySQL's query cache, it would be pretty simple. In this example, all you'd need to do is some normalization on the linux timestamp it uses in the field list. If you round it to the nearest thousand or even hundred, it would be utilized. The way it's set up now, it can't be used. What this would do is have the query results re-used (instant repeat queries) until the data changes and invalidates it.

Again, especially if you use MySQL query caching, this is a band-aid solution.

Implement Sphinx -This is quite difficult / expensive to set up, but it's probably the most beneficial in terms of performance and growth support. Sphinx is a search daemon which is often used to replace keyword searching, but it can also perform full data scans VERY quickly. You can have it scan through hundreds of millions of rows in the time it would take MySQL to scan tens of thousands. For a board your size, it would be bringing the data back in under a tenth of a second easily.


All times are GMT. The time now is 11:34 PM.

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.01282 seconds
  • Memory Usage 1,747KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (1)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete