Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 27th, 2012, 01:37 PM
SFDonovan's Avatar
SFDonovan SFDonovan is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Location: Texas
Posts: 351 SFDonovan User rank is Lance Corporal (50 - 100 Reputation Level)SFDonovan User rank is Lance Corporal (50 - 100 Reputation Level)SFDonovan User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 3 Days 15 h 18 m 27 sec
Reputation Power: 6
Facebook
Scalar select (single row subquery)

I'm trying to speed this up. 88 seconds is far too long. I need to identify if a student belongs to an ACAD_PLAN that has an ACAD_SUB_PLAN with ACAD_SUBPLAN_TYPE = 'AOP'. AOP is Accelerated Online Program. Trying to modify it into a subquery. emplid exist in PS_ACAD_PLAN and PS_ACAD_SUBPLAN.

PS_ACAD_SUBPLN_TBL is just a setup table that contains the attributes of the ACAD_SUBPLAN. Each one if effective dated where I get the MAX(EFFDT)

So an inner query and an outer query, but which is which?

Code:
sql Code:
Original - sql Code
  1. SELECT
  2. A.EMPLID
  3. , C.INSTITUTION
  4. , A.ACAD_CAREER
  5. , A.EFFDT
  6. , A.EFFSEQ
  7. , A.ACAD_PLAN
  8. , B.ACAD_SUB_PLAN
  9. , C.ACAD_SUBPLAN_TYPE
  10. FROM PS_ACAD_PLAN A, PS_ACAD_SUBPLAN B , PS_ACAD_SUBPLN_TBL C
  11. WHERE A.EMPLID = B.EMPLID
  12. AND A.ACAD_CAREER = B.ACAD_CAREER
  13. AND A.STDNT_CAR_NBR = B.STDNT_CAR_NBR
  14. AND A.ACAD_PLAN = C.ACAD_PLAN
  15. AND B.ACAD_SUB_PLAN = C.ACAD_SUB_PLAN
  16. AND A.ACAD_CAREER = 'GRAD'
  17. AND C.ACAD_SUBPLAN_TYPE = 'AOP'
  18. AND C.EFF_STATUS = 'A'
  19. AND A.EFFDT = (
  20.  SELECT MAX(AA.EFFDT)
  21.   FROM PS_ACAD_PLAN AA
  22.  WHERE A.EMPLID = AA.EMPLID
  23.    AND A.ACAD_CAREER = AA.ACAD_CAREER
  24.    AND A.STDNT_CAR_NBR = AA.STDNT_CAR_NBR)
  25. AND A.EFFSEQ = (
  26.  SELECT MAX(AAA.EFFSEQ)
  27.   FROM PS_ACAD_PLAN AAA
  28.  WHERE A.EMPLID = AAA.EMPLID
  29.    AND A.ACAD_CAREER = AAA.ACAD_CAREER
  30.    AND A.STDNT_CAR_NBR = AAA.STDNT_CAR_NBR
  31.    AND A.EFFDT = AAA.EFFDT)
  32.    AND A.plan_sequence = (
  33.  SELECT MIN(AB.plan_sequence)
  34.   FROM ps_acad_plan AB
  35.  WHERE A.emplid = AB.emplid
  36.    AND A.acad_career = AB.acad_career
  37.    AND A.stdnt_car_nbr = AB.stdnt_car_nbr
  38.    AND A.effseq = AB.effseq
  39.    AND A.effdt = AB.effdt)
  40.    AND B.EFFDT = (
  41.  SELECT MAX(BB.EFFDT)
  42.   FROM PS_ACAD_SUBPLAN BB
  43.  WHERE B.EMPLID = BB.EMPLID
  44.  AND B.ACAD_CAREER = BB.ACAD_CAREER
  45.  AND B.STDNT_CAR_NBR = BB.STDNT_CAR_NBR
  46.  AND B.ACAD_PLAN = BB.ACAD_PLAN
  47.    AND B.ACAD_SUB_PLAN = BB.ACAD_SUB_PLAN)
  48.    AND B.EFFSEQ = (
  49.  SELECT MAX(BC.EFFSEQ)
  50.   FROM PS_ACAD_SUBPLAN BC
  51.  WHERE B.EMPLID = BC.EMPLID
  52.    AND B.ACAD_CAREER = BC.ACAD_CAREER
  53.    AND B.STDNT_CAR_NBR = BC.STDNT_CAR_NBR
  54.    AND B.ACAD_PLAN = BC.ACAD_PLAN
  55.    AND B.ACAD_SUB_PLAN = BC.ACAD_SUB_PLAN)
  56.    AND C.EFFDT = (
  57.  SELECT MAX(CC.EFFDT)
  58.   FROM PS_ACAD_SUBPLN_TBL CC
  59.  WHERE C.ACAD_PLAN = CC.ACAD_PLAN
  60.    AND C.ACAD_SUB_PLAN = CC.ACAD_SUB_PLAN
  61.    AND C.INSTITUTION = CC.INSTITUTION);

Last edited by SFDonovan : August 27th, 2012 at 02:06 PM.

Reply With Quote
  #2  
Old August 27th, 2012, 02:28 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
I can not say that I fully understand what you are trying to do (others might, of course)
so I will restrict my questions/suggestions to the generic ones with which I always begin.

Have you examined the EXPLAIN PLAN to see where the time is taken?
Do all the appropriate columns have indexes?
Do the indexed columns have current statistics?

Clive
Comments on this post
debasisdas agrees!

Reply With Quote
  #3  
Old August 30th, 2012, 01:58 PM
LKBrwn_DBA's Avatar
LKBrwn_DBA LKBrwn_DBA is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Sep 2006
Posts: 759 LKBrwn_DBA User rank is Major (30000 - 40000 Reputation Level)LKBrwn_DBA User rank is Major (30000 - 40000 Reputation Level)LKBrwn_DBA User rank is Major (30000 - 40000 Reputation Level)LKBrwn_DBA User rank is Major (30000 - 40000 Reputation Level)LKBrwn_DBA User rank is Major (30000 - 40000 Reputation Level)LKBrwn_DBA User rank is Major (30000 - 40000 Reputation Level)LKBrwn_DBA User rank is Major (30000 - 40000 Reputation Level)LKBrwn_DBA User rank is Major (30000 - 40000 Reputation Level)LKBrwn_DBA User rank is Major (30000 - 40000 Reputation Level)LKBrwn_DBA User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 5 h 9 m 31 sec
Reputation Power: 349
Cool

Quote:
Originally Posted by SFDonovan
I'm trying to speed this up....Etc...


Also, if you provide some sample data with expected results, perhaps someone could try and re-write the query using analytical functions.
__________________

Reply With Quote
  #4  
Old August 30th, 2012, 02:31 PM
SFDonovan's Avatar
SFDonovan SFDonovan is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Location: Texas
Posts: 351 SFDonovan User rank is Lance Corporal (50 - 100 Reputation Level)SFDonovan User rank is Lance Corporal (50 - 100 Reputation Level)SFDonovan User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 3 Days 15 h 18 m 27 sec
Reputation Power: 6
Facebook
Quote:
Originally Posted by clivew
I can not say that I fully understand what you are trying to do (others might, of course)
so I will restrict my questions/suggestions to the generic ones with which I always begin.

Have you examined the EXPLAIN PLAN to see where the time is taken?
Do all the appropriate columns have indexes?
Do the indexed columns have current statistics?

Clive


What I'm trying to do is find if a current logged in user belongs to an academic plan, and also has a academic sub plan with a subplan type of 'AOP'. What we want to do is limit the search parameters they can use to register for courses... meaning we only want those classes with a subplan type = 'AOP' to show up. I instead made another sub query like so that made the query faster....(instead of joining on all three tables)

My first nested loop now looks like this.

sql Code:
Original - sql Code
  1. AND B.ACAD_PLAN = (
  2. SELECT C.ACAD_PLAN
  3. FROM PS_ACAD_SUBPLN_TBL C
  4. WHERE B.ACAD_SUB_PLAN = C.ACAD_SUB_PLAN
  5. AND C.ACAD_SUBPLAN_TYPE = 'AOP'
  6. AND C.EFF_STATUS = 'A'
  7. AND C.INSTITUTION = 'NT752')


Yes all the appropriate columns have indexes.
I have done an EXPLAIN PLAN FOR. (I could never read these worth a damn.. )



Quote:
------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 157 | 29 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 157 | | |
| 2 | NESTED LOOPS | | 1 | 157 | 25 (0)| 00:00:01 |
| 3 | NESTED LOOPS | | 1 | 144 | 21 (0)| 00:00:01 |
| 4 | NESTED LOOPS | | 1 | 131 | 17 (0)| 00:00:01 |
| 5 | NESTED LOOPS | | 1 | 122 | 13 (0)| 00:00:01 |
| 6 | NESTED LOOPS | | 1 | 109 | 9 (0)| 00:00:01 |
| 7 | NESTED LOOPS | | 1 | 64 | 7 (0)| 00:00:01 |
| 8 | VIEW | VW_SQ_2 | 1 | 33 | 4 (0)| 00:00:01 |
| 9 | HASH GROUP BY | | 1 | 25 | 4 (0)| 00:00:01 |
| 10 | TABLE ACCESS BY INDEX ROWID | PS_ACAD_PLAN | 1 | 25 | 4 (0)| 00:00:01 |
|* 11 | INDEX RANGE SCAN | PS_ACAD_PLAN | 1 | | 3 (0)| 00:00:01 |
| 12 | TABLE ACCESS BY INDEX ROWID | PS_ACAD_PLAN | 1 | 31 | 3 (0)| 00:00:01 |
|* 13 | INDEX RANGE SCAN | PS_ACAD_PLAN | 1 | | 2 (0)| 00:00:01 |
|* 14 | INDEX RANGE SCAN | PS_ACAD_SUBPLAN | 1 | 45 | 2 (0)| 00:00:01 |
| 15 | NESTED LOOPS | | 1 | 65 | 4 (0)| 00:00:01 |
| 16 | VIEW | VW_SQ_1 | 1 | 27 | 3 (0)| 00:00:01 |
| 17 | SORT GROUP BY | | 1 | 32 | 3 (0)| 00:00:01 |
| 18 | TABLE ACCESS BY INDEX ROWID| PS_ACAD_SUBPLN_TBL | 1 | 32 | 3 (0)| 00:00:01 |
|* 19 | INDEX RANGE SCAN | PS_ACAD_SUBPLN_TBL | 1 | | 2 (0)| 00:00:01 |
|* 20 | TABLE ACCESS BY INDEX ROWID | PS_ACAD_SUBPLN_TBL | 1 | 38 | 1 (0)| 00:00:01 |
|* 21 | INDEX UNIQUE SCAN | PS_ACAD_SUBPLN_TBL | 1 | | 0 (0)| 00:00:01 |
|* 22 | VIEW PUSHED PREDICATE | VW_SQ_3 | 1 | 13 | 4 (0)| 00:00:01 |
|* 23 | FILTER | | | | | |
| 24 | SORT AGGREGATE | | 1 | 28 | | |
|* 25 | FILTER | | | | | |
|* 26 | INDEX RANGE SCAN | PS_ACAD_PLAN | 1 | | 3 (0)| 00:00:01 |
|* 27 | VIEW PUSHED PREDICATE | VW_SQ_5 | 1 | 9 | 4 (0)| 00:00:01 |
|* 28 | FILTER | | | | | |
| 29 | SORT AGGREGATE | | 1 | 42 | | |
|* 30 | FILTER | | | | | |
|* 31 | INDEX RANGE SCAN | PS_ACAD_SUBPLAN | 1 | | 3 (0)| 00:00:01 |
|* 32 | VIEW PUSHED PREDICATE | VW_SQ_6 | 1 | 13 | 4 (0)| 00:00:01 |
|* 33 | FILTER | | | | | |
| 34 | SORT AGGREGATE | | 1 | 37 | | |
|* 35 | FILTER | | | | | |
|* 36 | INDEX RANGE SCAN | PS_ACAD_SUBPLAN | 1 | | 3 (0)| 00:00:01 |
|* 37 | VIEW PUSHED PREDICATE | VW_SQ_4 | 1 | 13 | 4 (0)| 00:00:01 |
|* 38 | FILTER | | | | | |
| 39 | SORT AGGREGATE | | 1 | 31 | | |
|* 40 | FILTER | | | | | |
| 41 | TABLE ACCESS BY INDEX ROWID | PS_ACAD_PLAN | 1 | 31 | 4 (0)| 00:00:01 |
|* 42 | INDEX RANGE SCAN | PS_ACAD_PLAN | 1 | | 3 (0)| 00:00:01 |
------------------------------------------------------------------------------------------------------------

Reply With Quote
  #5  
Old September 17th, 2012, 12:46 AM
ilesterg ilesterg is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 3 ilesterg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 35 sec
Reputation Power: 0
hey there, peoplesoft fella.let me digest your problem.

Reply With Quote
  #6  
Old September 17th, 2012, 01:22 AM
ilesterg ilesterg is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 3 ilesterg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 35 sec
Reputation Power: 0
Quote:
Originally Posted by SFDonovan
I need to identify if a student belongs to an ACAD_PLAN that has an ACAD_SUB_PLAN with ACAD_SUBPLAN_TYPE = 'AOP'. AOP is Accelerated Online Program. Trying to modify it into a subquery. emplid exist in PS_ACAD_PLAN and PS_ACAD_SUBPLAN.

PS_ACAD_SUBPLN_TBL is just a setup table that contains the attributes of the ACAD_SUBPLAN. Each one if effective dated where I get the MAX(EFFDT)


Hi. your requirement seems to be simple, and I cant find any problem with your query except that i don't understand why you have to match the following:
C.INSTITUTION = CC.INSTITUTION

I just want to clarify some design points based on what i understand from your query:
1. an employee could have more than 1 acad plan/career, and you only want one row (latest GRAD)
2. an employee could have more than 1 sub acad plans for each acad plan/career, and you want the latest sub acad plan for the acad plan GRAD of type AOP.
3. for each acad/sub acad plan combination, there is a corresponding INSTITUTION in acad_subpln_tbl, and you want the latest active (A) institution for the acad/subacad combination.

With that, I think this topic should be more of a query optimization issue. Are these all the indices?

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Scalar select (single row subquery)

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap