Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old November 22nd, 2005, 08:47 AM
CSN
Guest
 
Posts: n/a
Default subqueries vs. separate queries

Is there much difference between using subqueries and
separating out them into separate queries?

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend




  #2  
Old November 22nd, 2005, 08:47 AM
Guy Fraser
Guest
 
Posts: n/a
Default Re: subqueries vs. separate queries

CSN wrote:
[color=blue]
>Is there much difference between using subqueries and
>separating out them into separate queries?
>
>[/color]
That would depend on what results your expecting, and how you intend on using the results.

For example if you want all the data in a single statement, you can't break it up, but the request will likely use more resources to complete.
If your application can cut and paste the data from multiple transactions, then simple queries may need less resources to complete, but remember that your application will require resources to cut and paste the results as well.

I have written a number of PHP functions that uses an array the results of a query to generate formatted html tables, graphs and statistical information. It is easiest to use a single complex query with subqueries, but it is possible to 'fake' a complex query by 'stacking' multiple results into an array.

Hope that helps.






---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

  #3  
Old November 22nd, 2005, 08:47 AM
Christopher Browne
Guest
 
Posts: n/a
Default Re: subqueries vs. separate queries

cool_screen_name90001@yahoo.com (CSN) writes:[color=blue]
> Is there much difference between using subqueries and separating out
> them into separate queries?[/color]

Yes. No. Maybe.

What kind of difference are you thinking about?

If you join queries together, you wind up with fewer queries, and your
outside code that manipulates the results will likely have less work
to do. There are certainly notions of "efficiency" and "simplicity"
that can out of that.

By the same token, those fewer queries are sure to be a bit more
complex, may be more difficult to write and understand, and may poke
at "edges" of the query optimizer such that they _may_, if you are
very unlucky, run unexpectedly slowly.

It is quite possible for the simplifications of your application to
outweigh the _possible_ costs...
--
output = ("cbbrowne" "@" "ntlug.org")
http://cbbrowne.com/info/linux.html
Would-be National Mottos:
USA: "We don't care where you come from. We can't find our *own*
country on a map..."
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,414 network members.