vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Latest Posts/Threads - optimal query? (https://vborg.vbsupport.ru/showthread.php?t=220812)

stryka 08-13-2009 05:22 PM

Latest Posts/Threads - optimal query?
 
I have 3million posts in my DB... Any suggestions on how i should do the query for "latest threads"

I currently have the following

SELECT a.title, a.lastpost, a.firstpostid, a.replycount, a.postuserid, a.forumid, a.postusername, b.title as forumname FROM vb_thread as a LEFT JOIN vb_forum as b ON a.forumid = b.forumid WHERE a.forumid != '24' ORDER BY a.threadid DESC LIMIT 7

I was actually thinking of creating a cron job that runs the above (Hourly), inserts into a temp talbe and i just pull from the sing table when i do the real query call

Deceptor 08-13-2009 06:33 PM

Your idea for the cron job is probably a better solution. It will suffer from lag but you could avoid that by creating several hooks to update the "cache" when threads/posts are created/moderated/moved/deleted (soft/hard)/merged/etc..

Andreas 08-14-2009 03:22 AM

1) Why to you join the forum table?
You don't really need that as you can get the forum title from forum cache.
In theory the join is correct, but what is theoretetically correct is not necessarily the best thing to do performance wise ;)

2) If you want the most up-to-date data with minimal db load, i'd add a hook on threaddata_postsave to invalidate the cache when the thread status (visible, forumid) changes.
When you display the results, check if the cache is there if not: build it.


All times are GMT. The time now is 01:22 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.00907 seconds
  • Memory Usage 1,706KB
  • 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
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete