Danical
08-18-2010, 12:13 PM
So, I've been told with the newest version of Oracle SQL that it's up to 6 times more performant to rewrite subqueries as outer joins. Since I deal with millions of records per term, it would be insanely helpful to get at this performance break. So, for example:
select studentDetail.term_code_key "termCode",
studentDetail.pidm_key "studentId",
studentDetail.crn_key "sectionId",
studentDetail.subj_code || studentDetail.crse_number "sectionName"
from BANINST1.AS_ACADEMIC_HISTORY_DETAIL studentDetail
where studentDetail.pidm_key in ( select studentDetail2.pidm_key
from BANINST1.AS_ACADEMIC_HISTORY_DETAIL studentDetail2
where (studentDetail2.subj_code || studentDetail2.crse_number) in ( select distinct (sectionAttribute.scrattr_subj_code || sectionAttribute.scrattr_crse_numb)
from scrattr sectionAttribute
where sectionAttribute.SCRATTR_ATTR_CODE IN ('B','P') )
and studentDetail2.term_code_key between :selectCohortStartTerm.termCode and :selectCohortEndTerm.termCode
)
and studentDetail.term_code_key between to_number(:selectCohortStartTerm.termCode, 999999) and (to_number(:selectCohortEndTerm.termCode, 999999) + :selectCohortLength.durationYears)
order by 1, 2, 3
How do I make the 2 nested subqueries into joins in the FROM clause?
Note: anything trailing a ':' is a variable parameter set on the form before execution.
select studentDetail.term_code_key "termCode",
studentDetail.pidm_key "studentId",
studentDetail.crn_key "sectionId",
studentDetail.subj_code || studentDetail.crse_number "sectionName"
from BANINST1.AS_ACADEMIC_HISTORY_DETAIL studentDetail
where studentDetail.pidm_key in ( select studentDetail2.pidm_key
from BANINST1.AS_ACADEMIC_HISTORY_DETAIL studentDetail2
where (studentDetail2.subj_code || studentDetail2.crse_number) in ( select distinct (sectionAttribute.scrattr_subj_code || sectionAttribute.scrattr_crse_numb)
from scrattr sectionAttribute
where sectionAttribute.SCRATTR_ATTR_CODE IN ('B','P') )
and studentDetail2.term_code_key between :selectCohortStartTerm.termCode and :selectCohortEndTerm.termCode
)
and studentDetail.term_code_key between to_number(:selectCohortStartTerm.termCode, 999999) and (to_number(:selectCohortEndTerm.termCode, 999999) + :selectCohortLength.durationYears)
order by 1, 2, 3
How do I make the 2 nested subqueries into joins in the FROM clause?
Note: anything trailing a ':' is a variable parameter set on the form before execution.