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

Reply
 
Thread Tools Display Modes
  #1  
Old 08-03-2003, 01:10 PM
karmanis karmanis is offline
 
Join Date: Jun 2003
Posts: 20
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Queries' Relative Cost

Which one do you think that woud add the LESS load to your server...


choice 1)
1 simple query selecting the latest 5 posts from 20 specified forums, among 100.000 posts.... repeated 10 times in a loop. gre:


choice 2)
1 query selecting the 5 latest posts from each of 200 forums (total =1000 selected posts), among 100.000 posts... applied just once
+
1 query selecting all the posts (should be 5 in total ) from 20 specified forums, among 1000 posts... repeated 10 times in a loop



It will also be of some interest, if you specify how many times heavier (approximately) would be the "other choice".

many thanks !
:bunny:
Reply With Quote
  #2  
Old 08-04-2003, 04:41 PM
otero otero is offline
 
Join Date: Jun 2003
Location: miami
Posts: 15
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

?
Reply With Quote
  #3  
Old 08-04-2003, 04:52 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You should never need to query in a loop. Instead, I suggest that you instead think of a different way of writing the queries such that it isn't necessary to loop.
Reply With Quote
  #4  
Old 08-04-2003, 05:40 PM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Or put the data into an array and loop through that?
Reply With Quote
  #5  
Old 08-05-2003, 12:30 AM
Brad Brad is offline
 
Join Date: Nov 2001
Posts: 4,765
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes, use fetch_array() anytime you are required to use query info in a loop.
Reply With Quote
  #6  
Old 08-05-2003, 12:46 AM
Erwin's Avatar
Erwin Erwin is offline
 
Join Date: Jan 2002
Posts: 7,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Do 1 query to select the things you want with DESC LIMIT 5, then use WHILE and ENDWHILE to process what you collected in a meaningful manner and parsing the results into the template.
Reply With Quote
  #7  
Old 08-05-2003, 12:31 PM
karmanis karmanis is offline
 
Join Date: Jun 2003
Posts: 20
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So, you all suggest me to go with one query gathering all the info I want, and some while statements to further process specific parts of the info.

But let me ask you something here. How, for example, would I gather the latest 5 thread titles from each one of 20 forums, using just one query ?

Supposing that the following query can be used to select the last 5 threads from a single forum....

Code:
$DB_site->query("SELECT threadid,title FROM thread 
WHERE forumid = $forumid 
ORDER BY lastpost DESC limit 5")
..how could we achieve to additionally:

1) have it selecting the last 5 threads from the first forum of $myforums[mylist], after that from the second one, the third... until all forums have been used. At the end I would have selected 5*20=1000 threads, the latest 5 from each of my 20 forums in the list.

2) have it selecting not only from the parsed forum in the list, but also from all its subforums (not stated in the list).


Are these possible with a single query, or I would end up using 20, one query for each forum ??


many thanks
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 02:00 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.05776 seconds
  • Memory Usage 2,218KB
  • 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
  • (1)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)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