‎2006 Oct 27 2:18 PM
Hi friends,
I am facing problem in breaking up a select statement which contains join between 10 tables.
can you people suggest me different options for removing join in a select statements.
‎2006 Oct 27 2:21 PM
‎2006 Oct 27 2:22 PM
‎2006 Oct 27 2:43 PM
Let me take a example for this problem
Lets say there are 8 table
tab1
tab2 and so on..
now my select statement has a join condition as
select (fields) from
tab1
innerjoin tab2 on tab1field1 = tab2field1
innerjoin tab3 on tab3~field3 = tab1-field3
innerjoin tab4 on tab4field4 = tab2field4
innerjoin tab5 on tab5field1 = tab1field1 and
tab5~field5 = tab1-field5
innerjoin tab6 on tab6~field5 = tab5-field5
innerjoin tab7 on tab7~field1 = tab1-field1 and
tab7field3 = tab3field3 and
tab7field5 = tab5field5 and
innerjoin tab8 on tab8field8 = tab7field8
This creaets a huge table from which fields are fetched.
Its a bit difficult to use For all entries in this case.
Can creating views be of any help in this case.
‎2006 Oct 27 2:48 PM
What exactly is the problem? IE, why are you doing this? Is there a performance issue here?
Rob
‎2006 Oct 27 2:53 PM
Because of these joins this statement is taking a long time to execute. That is why i want it to be done in some other way.
‎2006 Oct 27 2:59 PM
It's possible to split up the select, but difficult to say exactly how without seeing the exact code. Could you please post it?
In general, a large join shouldn't cause a performance problem by itself, but if it's not well constructed (IE not using indexes) that can cause a problem.
Rob
‎2006 Oct 27 3:04 PM
Hi Rob
here is the actual select statement.
have a look at it and see what can be done with this.
I tried out to break it in two parts, but was unsucessful.
SELECT AFKO~AUFNR "Order Number
AFKO~GSTRP "Order Basic start date
AFKO~GSTRS "Order Scheduled start
AFIH~PRIOK "Maint order Priority
AFIH~ILART "Maint activity type
AFIH~WARPL "Maint plan
AFIH~ABNUM "Package num
AFIH~WAPOS "Maint item
ILOA~TPLNR "Functional location
ILOA~ABCKZ "ABC indicator for technical object
AUFK~KTEXT "Order Short text
AUFK~AUART "Order type
AUFK~OBJNR "object num of order
AFVC~OBJNR "Object num of operation
AFVC~ANLZU "Task list oper's sys condition
CRHD~ARBPL "Work center
AFVV~ARBEI "Plan hours for the activity
AFVV~ISMNW "Actual hours
MPOS~WSTRA "Strategy
AFKO~PLNNR
AFKO~PLNAL
MHIS~ZAEHL "Maint package
FROM ( AFKO "afko: Order header
INNER JOIN AUFK "aufk: Order master data.
ON AUFKAUFNR = AFKOAUFNR
INNER JOIN AFIH "afih: Maint order header
ON AFIHAUFNR = AUFKAUFNR
INNER JOIN ILOA "iloa: PM Obj Loc & Acct Assgmt
ON ILOAILOAN = AFIHILOAN
INNER JOIN caufv "
ON caufvAUFNR = AFKOAUFNR
INNER JOIN AFVC "afvc: Operation within an order
ON AFVCAUFPL = CAUFVAUFPL
INNER JOIN AFVV "afvv: qty/dates in operation
ON AFVVAUFPL = AFKOAUFPL
INNER JOIN CRHD "crhd: Work Center Header
ON CRHDOBJID = AFVCARBID
INNER JOIN PLAS
ON PLASPLNTY = AFVCPLNTY
AND PLASPLNNR = AFVCPLNNR
AND PLASPLNAL = AFVCPLNAL
AND PLASZAEHL = AFVCZAEHL
INNER JOIN PLWP
ON PLWPPLNTY = AFVCPLNTY
AND PLWPPLNNR = PLASPLNNR
AND PLWPPLNAL = PLASPLNAL
INNER JOIN MHIS "mhis: Maint plan history
ON MHISZAEHL = PLWPPAKET
LEFT OUTER JOIN MPOS "mpos: Maint item
ON MPOSWAPOS = AFIHWAPOS
)
INTO TABLE I_CO_MH3
WHERE AFKO~GSTRS IN S_DATES "Order scheduled start date
AND AFKO~GSTRS IN R_ONE_YEAR "Restriction by year
AND ILOA~TPLNR IN S_TPLNR "func location input
AND CRHD~OBJTY = 'A' "Object types of CIM resource
‎2006 Oct 27 3:18 PM
It looks to me that your problem has more to do with the use of indexes rather than the join. Although there is an index on TPLNR in ILOA and OBJTY in CRHD, I don't think they will be restrictive enough to help much.
Rob
‎2006 Oct 27 3:27 PM
Hi Rob thanks for the advice.
Can you please elaborate a bit more on this, and how how can we make this work properly.
Thnaks in advance.
‎2006 Oct 27 3:30 PM
YOu've used CAUFV in the join, it's is a view for tables AFKO and AUFK. Take it out from join and use
ON AFVCAUFPL = AFKOAUFPL in the next join condition with AFVC.
Regards
Sridhar
‎2006 Oct 27 3:31 PM
Well, I'm not sure I can. I was just trying to get you to find the source of the problem rather than just assuming the join was the sole source. I think you need to examine your logic to determine why you are selecting these fields from these tables using your selection criteria.
Rob