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

Reply
 
Thread Tools Display Modes
  #1  
Old 01-20-2010, 12:07 PM
cedivad cedivad is offline
 
Join Date: Oct 2008
Location: Italy
Posts: 20
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Any idea to optimize THIS query?

I'm working hard on the load time of the pages of my script (script is my own, the only thing shared with vbulletin is the database). Expecially, i have big problems with this query:

[SQL]select threadid from thread where forumid=1082 order by dateline desc limit 0, 25;[/SQL]

The query takes about 0.5 sec. The forum (forumid=1082) has about 120'000 topics. The full database has about 5 milion threads.

Executing the query without the "order" takes 0.00 seconds, but i need to order it!

Do someone have some ideas on how to fix this?
Reply With Quote
  #2  
Old 01-20-2010, 01:43 PM
luki luki is offline
 
Join Date: Aug 2008
Location: Poland
Posts: 21
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try adding index to this field.

Code:
ALTER TABLE `thread` ADD INDEX (`dateline`);
Reply With Quote
  #3  
Old 01-20-2010, 05:02 PM
mokujin's Avatar
mokujin mokujin is offline
 
Join Date: Oct 2005
Location: Czech
Posts: 345
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

try this:
SELECT threadid, forumid, dateline
FROM thread
WHERE forumid = 1082
ORDER BY dateline DESC
LIMIT 0 , 25
Reply With Quote
  #4  
Old 01-20-2010, 05:10 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Eek.

If you're only pulling 25 threads from 120,000, then you should restrict by dateline as well.

Code:
WHERE dateline >= " . TIMENOW - (86400 * 7) . "
This would only pull threads created in the past week, which should be fine if the forum has any activity. This way you utilize the index and not kill the server.
Reply With Quote
  #5  
Old 01-20-2010, 06:53 PM
cedivad cedivad is offline
 
Join Date: Oct 2008
Location: Italy
Posts: 20
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for the replies.
vBulletin by default have the index for "dateline" already setted. I noticed that the query takes 0.5 second only the second time i try it, the first the result is
Code:
25 rows in set (5.60 sec)
Witch is really bad.

I can't cut the topics older than a week, since that i should order it by dateline ASC, that was only an example.

This is the example where the query is executed: http://it.narkive.com/c/1082 (loading 250 topics instead of 25 don't take any longer!). As stated above, the first time takes a long time (let's say 5 sec) while the second the query is cached so it's faster, (let's say 0.5 sec).

Thank you
Reply With Quote
  #6  
Old 01-20-2010, 06:58 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Have that all run as a cron... surely you wouldn't need all that as live data.
Reply With Quote
  #7  
Old 01-20-2010, 06:59 PM
cedivad cedivad is offline
 
Join Date: Oct 2008
Location: Italy
Posts: 20
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by cedivad View Post
vBulletin by default have the index for "dateline" already setted.
Ok, maybe i was wrong

Code:
mysql> ALTER TABLE `thread` ADD INDEX (`dateline`);
Query OK, 5236687 rows affected (4 min 41.92 sec)
Records: 5236687  Duplicates: 0  Warnings: 0
It now takes 0.5 sec else if it's not cached (i suppose). A great improvement

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

Quote:
Originally Posted by SirAdrian View Post
Have that all run as a cron... surely you wouldn't need all that as live data.
In fact i tought to do a static file cache... something like 16000 files of 0.4 mega each with the cache of every page of every category except the last one, that must be loaded "live". I think it's the best way
Reply With Quote
  #8  
Old 01-20-2010, 07:11 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You could do it way smaller than that. If you are ordering in ascending order, all you'd need is to have all the ids associated for every page. The rest can be live. That shouldn't take up much space at all.
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 10:20 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.04129 seconds
  • Memory Usage 2,231KB
  • 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
  • (4)bbcode_code
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete