vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Queries' Relative Cost (https://vborg.vbsupport.ru/showthread.php?t=55855)

karmanis 08-03-2003 01:10 PM

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. :ogre:


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:

otero 08-04-2003 04:41 PM

?

filburt1 08-04-2003 04:52 PM

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. :)

Dean C 08-04-2003 05:40 PM

Or put the data into an array and loop through that?

Brad 08-05-2003 12:30 AM

Yes, use fetch_array() anytime you are required to use query info in a loop. :)

Erwin 08-05-2003 12:46 AM

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.

karmanis 08-05-2003 12:31 PM

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 ?? :confused:


many thanks


All times are GMT. The time now is 08:02 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.01117 seconds
  • Memory Usage 1,718KB
  • 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)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)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