Matthew Wilson | 27 Apr 23:24

How to do a single big join rather than lots of little joins?

I've got a table of employees and a table of departments and a related
table that joins the two.

So when I do

    for dept in employee.departments:

the SQLObject machinery runs a separate query for each department row.
Sometimes, this is fine, but sometimes, I want to do a query where I
grab every department all at once.

I have been manually adding classmethods when I need the "all-at-once"
join to happen, so then I do:

    for dept in employee.get_all_departments_at_once():

Is there a better way to do what I'm doing?

I find that running lots and lots of single queries is really slow, so
in a lot of cases, I prefer to just grab everything.

Matt

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
Oleg Broytmann | 28 Apr 02:14
X-Face

Re: How to do a single big join rather than lots of little joins?

On Sun, Apr 27, 2008 at 09:28:19PM +0000, Matthew Wilson wrote:
> I've got a table of employees and a table of departments and a related
> table that joins the two.
> 
> So when I do
> 
>     for dept in employee.departments:
> 
> the SQLObject machinery runs a separate query for each department row.

   What is ".departments"? MultiplJoin? Use SQLMultipleJoin - it runs one
query for one access. It also handles ordering better (can use any SQL
expression). It returns SelectResults instead of a list, but every "for"
loop will happily iterate over it.

Oleg.
--

-- 
     Oleg Broytmann            http://phd.pp.ru/            phd <at> phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

Gmane