Joining 5 tables vs. using temp table
Posted in 1998
Topics: Performance & Tuning, SQL Development & Query Writing, Clustering, Grid & MACH11
Hi
I have a tree hierarchy like this
Reg
/ \\
Div1..n Div
/ \\
District1...n District
/ \\
Local
Mgr1...n Local Mgr
/ \\
usr1...
usrn usr1. usrn
I have one other big table "tasresult" where it has "date" and "userid"
and transaction type.
If Region Manager querys, it should give "divMgrID" and each type of
transaction and #of times.
Basically it adds up subtree of users tasks as if divMgr did it.
I can do same query by using cursor pointing to "divmgrID" and adding
all users into Temp table and
joinging temp table one time with "taskresult" instead of 4 more joins
. Then I drop temp table and
recreate for each divmgrID.
If I use joins, how do I give final results adding even tasks performed
by "LocalMgrs, DistMgrs, DivMgrs"
This is the SQL query for joins
select div.div_mgr_id, t.taskid,count(*)
from reg_mgr r, div_mgr div, dis_mgr dis,loc_mgr l, usr_list
usr,taskresult t
where r.reg_serial = "1"div.div_serial = dis.div_serial and
dis.dis_serial = l.dis_serial and
l.loc_serial = usr.loc_serial and
usr.user_id = t.userid and
group by 1,2
order by 1,2
What is the performance gain? Is it better always to use temp table.
Could you please mail me
Thank you
Sukumar Konduru
sukumar@gte.net