Tuning a Query

Hi,
I came upon this query from HELL...
a 48 table join query :-(
SELECT jd.system_file_number
      ,jd.system_file_number_parent original_sf
      ,rfo.program_id program_id
      ,opo.current_conf_exp_date confirmation_expires_date
      ,rh.report_guid p_guid_id
      ,rh.annex_footnote annex_footnote
      ,rh.wage_confidential_yn
      ,rh.report_type_id
      ,h.hrc_number||' - '||h.office_name_en hrcc_office_name
      ,p_hrcc.area_code  hrcc_fax_area_code
      ,p_hrcc.phone_number hrcc_fax_number
      ,p2_hrcc.area_code hrcc_area_code
      ,p2_hrcc.phone_number hrcc_phone
      ,fo.name_to_print officer_name_to_print
      ,fo.phone_area_code officer_phone_area_code
      ,fo.phone_number officer_phone_number
      ,fo.phone_ext_number officer_phone_ext
      ,fo.fax_area_code officer_fax_area_code
      ,fo.fax_number officer_fax_number
      ,org.organization_id employer_id
      ,org.organization_name organization_name
      ,biz_phone.phone_number biz_phone_number
      ,biz_phone.area_code biz_area_code
      ,biz_phone.foreign_number biz_foreign_phone
      ,c.date_created contact_dt_created
      ,decode(rfo.program_id, 1,org.lcp_first_name || ' ' || org.lcp_last_name, c.name) contact_name
      ,c.job_title contact_job_title
      ,nvl((decode(rfo.program_id, 1,'Y', crfo1.primary_contact_yn)),'N') primary_contact_yn
      ,decode(rfo.program_id, 1,p_contact2.area_code,p_contact.area_code) contact_area_code
      ,decode(rfo.program_id, 1,p_contact2.phone_number, p_contact.phone_number) contact_phone
      ,decode(rfo.program_id, 1,p_contact2.ext_number, p_contact.ext_number) contact_ext
      ,decode(rfo.program_id, 1,p_contact_other2.area_code,p_contact_other.area_code) other_contact_area_code
      ,decode(rfo.program_id, 1,p_contact_other2.phone_number, p_contact_other.phone_number) other_contact_phone
      ,decode(rfo.program_id, 1,p_contact_other2.ext_number, p_contact_other.ext_number) other_contact_ext
      ,p_contact.foreign_number contact_foreign_phone
      ,p_contact_faxnum.area_code contact_fax_area
      ,p_contact_faxnum.phone_number contact_fax_number
      ,tp.third_party_id
      ,tp.third_party_name tp_org_name
      ,c_third.name tp_contact_name
      ,c_third.job_title tp_job_title
      ,c_third.date_created tp_contact_dt_created
      ,p_third.area_code tp_contact_area_code
      ,p_third.phone_number tp_contact_phone
      ,p_third.ext_number tp_contact_ext
      ,p_third.foreign_number tp_foreign_phone
      ,p_contact_fax.area_code rep_fax_area_code
      ,p_contact_fax.phone_number rep_fax_number
      ,p_contact_fax.foreign_number rep_fax_foreign_number
      ,fw.first_name foreign_worker_first_name
      ,fw.last_name foreign_worker_last_name
      ,fw.foreign_worker_id
      ,cn.noc_code noc_code
      ,nvl(rh.noc_title_print, jd.noc_title) noc_title_print
      ,(jd.number_of_positions - fnGlobal_GetCancelledPositions(jd.system_file_number)) number_of_positions
      ,decode(jd.educ_level_id,null,celc_rph.educ_level_name_en, celc.educ_level_name_en) educ_level_name
      ,nvl(ltrim(clro.language_desc_en || ' ' || jd.oral_lang_other_text), 'N/A') oral_language_desc
      ,nvl(ltrim(clrw.language_desc_en || ' ' || jd.written_lang_other_text), 'N/A') written_language_desc
      ,jd.licensing_body_name licensing_body_name
      ,jd.duration_of_employment duration_of_employment
      ,cduc.duration_unit_name_en duration_unit_name
      ,decode (jd.wage,null,'',0,'',trim(to_char(jd.wage,'999999999.00')) || ' / ') wage
      ,decode (jd.wage_unit_id,8,jd.wage_unit_other,cwuc.wage_unit_name_en) wage_unit
      ,decode(b.disability_insurance_yn,'Y','Disability insurance',null) benefits_disability_insurance
      ,decode(b.medical_insurance_yn,'Y','Medical insurance',null) benefits_medical_insurance
      ,decode(b.dental_insurance_yn,'Y','Dental insurance',null) benefits_dental_insurance
      ,decode(b.pension_yn,'Y','Pension',null) benefits_pension
      ,jd.wage_unit_other wage_unit_other
      ,decode(b.number_paid_holidays,null,null,0,null,trim(to_char(number_paid_holidays, '999.99'))||' day(s) paid holidays') benefits_number_paid_holidays
      ,decode(b.VACATION_PAY_PERCENT,null,null,0,null,trim(to_char(b.VACATION_PAY_PERCENT,'999.99')) ||'% vacation pay ') benefits_vacation_pay_percent
      ,decode(b.sick_leave,null,null,0,null,trim(to_char(b.sick_leave,'999.99'))||' day(s) paid sick leave') benefits_sick_leave
      ,b.other_benefit_text benefits_other_benefits_text
      ,decode(nvl(jd.hours_per_week,0),0,null,trim(to_char(jd.hours_per_week,'999.99'))||' hour(s) per week') hours_per_week
      ,decode(nvl(jd.hours_per_day,0),0,null,trim(to_char(jd.hours_per_day, '999.99'))||' hour(s) per day') hours_per_day
      ,decode(nvl(jd.hours_per_month,0),0,null,trim(to_char(jd.hours_per_month, '999.99'))||' hour(s) per month') hours_per_month
      ,to_char(jd.work_start_date,'YYYY-MM-DD') work_start_date
      ,decode(rfo.headliner_dancer_yn,'Y','Headliner',null) headliner_yn
      ,el.location_line_1 employment_location_line_1
      ,el.city employment_location_city
      ,cpcel.province_code_en employment_location_prvnc_cd
      ,decode(jd.days_off_per_week,null,'0 day(s)',trim(to_char(jd.days_off_per_week,'999.99'))|| ' day(s)') lcp_days_off_per_week
      ,decode(jd.room_and_board_amount, null, 'N/A', '$' || trim(to_char(jd.room_and_board_amount,'9999.99'))|| ' / '|| cwua.wage_unit_name_en) lcp_room_and_board
      ,decode(ljd.meal_deduction_amount, null,' ', '($'|| trim(to_char(ljd.meal_deduction_amount,'9999.99'))|| ' / '|| cwum.wage_unit_name_en || ')') lcp_meal_deduction
      ,decode(ljd.meal_deductions_yn,'Y', 'Yes', 'No') lcp_meal_deduction_yn
      ,decode(jd.contract_received_yn,'Y','Yes','No') contract_received_yn
      ,decode(b.accommodation_yn,'Y', 'Yes', 'No') lcp_private_accommodation_yn
      ,trim(to_char(jd.overtime_pay,'9999.99')) overtime_pay
      ,trim(to_char(jd.hours_to_overtime,'999.99')) hours_to_overtime
      ,to_char(jd.work_start_date,'YYYY-MM-DD') expected_start_date
      ,decode(agr.housing_proof_p_c_yn, 'Y','Yes','No') housing_proof_p_c_yn
      ,decode(agr.housing_proof_to_come_yn,'Y','Yes','No') housing_proof_to_come_yn
      ,to_char(agr.housing_proof_expected_date,'YYYY-MM-DD') housing_proof_expected_date
      ,decode(agr.off_site_contract_included_yn,'Y','Yes','No') off_site_contract_yn
      ,wage_currency.currency_type_code currency
      ,bd.legal_name org_legal_name
      ,bd.operating_name org_biz_name
      ,bd_tp.legal_name tp_legal_name
      ,bd_tp.operating_name tp_biz_name
      ,decode(b.accommodation_yn,'Y','Yes','No') accommodation_yn
      ,trim(to_char(b.rent_paid,'9999.99')) rent_paid
      ,cwac.wage_unit_name_en rent_period
--      ,b.accommodation_assistance
      ,b.accommodation_type
      ,org.address_id org_address_id
      ,a_biz.address_id biz_address_id
      ,a_biz.address_line_1 biz_address_line_1
      ,a_biz.address_line_2 biz_address_line_2
      ,a_biz.city biz_city
      ,a_biz.postal_code biz_postal_code
      ,NVL (biz_prov.province_code_en,NVL (biz_state.state_code_en, a_biz.other_country_text)) biz_prov
      ,tp.address_id tp_address_id
      ,a_tp_biz.address_id tp_biz_address_id
      ,a_tp_biz.address_line_1 tp_biz_address_line_1
      ,a_tp_biz.address_line_2 tp_biz_address_line_2
      ,a_tp_biz.city tp_biz_city
      ,a_tp_biz.postal_code tp_biz_postal_code
      ,NVL (tp_biz_prov.province_code_en,NVL (tp_biz_state.state_code_en, a_tp_biz.other_country_text)) tp_biz_prov
      ,rh.show_officer_phone_yn
FROM job_definitions jd
JOIN requests_for_opinion rfo ON rfo.request_for_opinion_id = jd.request_for_opinion_id
JOIN report_definitions rh ON rh.system_file_number = jd.system_file_number
JOIN report_history rph ON rph.system_file_number = rh.system_file_number 
AND  rph.report_guid = rh.report_guid
JOIN opinion_processes opo ON opo.system_file_number = jd.system_file_number
AND  opo.generates_process_id IS NULL
JOIN fw_officers fo ON fo.fw_officer_id = opo.dec_recommended_by_id
JOIN hrcc h ON h.hrcc_id = rh.hrcc_id
LEFT OUTER JOIN phones p_hrcc ON p_hrcc.hrcc_id = h.hrcc_id
AND  p_hrcc.phone_type_id = 4
LEFT OUTER JOIN phones p2_hrcc ON p2_hrcc.hrcc_id = h.hrcc_id
AND  p2_hrcc.phone_type_id = 2
JOIN organizations org ON org.organization_id = rfo.organization_id
LEFT OUTER JOIN phones p_contact2 ON p_contact2.organization_id  = org.organization_id
AND  p_contact2.phone_type_id = 1
LEFT OUTER JOIN phones p_contact_other2 ON p_contact_other2.organization_id = org.organization_id
AND  p_contact_other2.phone_type_id  = 3
LEFT OUTER JOIN contact_rfo crfo1 ON crfo1.request_for_opinion_id = rfo.request_for_opinion_id
AND  crfo1.user_deleted is null
AND  crfo1.third_party_id is null          
LEFT OUTER JOIN contacts c ON c.contact_id = crfo1.contact_id
LEFT OUTER JOIN phones p_contact ON p_contact.contact_id = c.contact_id
AND  p_contact.phone_type_id = 2
LEFT OUTER JOIN phones p_contact_faxnum ON p_contact_faxnum.contact_id = c.contact_id
AND  p_contact_faxnum.phone_type_id = 4
LEFT OUTER JOIN phones p_contact_other ON p_contact_other.contact_id  = c.contact_id
AND  p_contact_other.phone_type_id  = 3
LEFT OUTER JOIN contacts c_third
ON c_third.contact_id = fnglobal_get3rdpartycon4rfo(rfo.request_for_opinion_id)
LEFT OUTER JOIN contact_rfo crfo2 ON crfo2.request_for_opinion_id = rfo.request_for_opinion_id
and  crfo2.contact_id = c_third.contact_id
and  crfo2.user_deleted is null
and  crfo2.third_party_id is not null
LEFT OUTER JOIN phones p_third ON p_third.contact_id =  c_third.contact_id
AND  p_third.phone_type_id = 2
LEFT OUTER JOIN phones p_contact_fax ON p_contact_fax.contact_id = c_third.contact_id
AND  p_contact_fax.phone_type_id = 4
LEFT OUTER JOIN third_party tp ON tp.third_party_id = crfo2.third_party_id
LEFT OUTER JOIN foreign_workers fw ON fw.system_file_number = jd.system_file_number
JOIN cd_noc cn ON cn.noc_id = jd.noc_id
LEFT OUTER JOIN cd_education_level_codes celc ON celc.educ_level_id = jd.educ_level_id
LEFT OUTER JOIN cd_education_level_codes celc_rph ON celc_rph.educ_level_id = rph.educ_level_id
LEFT OUTER JOIN cd_language_requirements clro ON clro.language_requirement_id = jd.oral_language_id
LEFT OUTER JOIN cd_language_requirements clrw ON  clrw.language_requirement_id = jd.written_language_id
LEFT OUTER JOIN cd_duration_unit_codes cduc ON cduc.duration_unit_id = jd.duration_unit_id
LEFT OUTER JOIN cd_wage_unit_codes cwuc ON cwuc.wage_unit_id = jd.wage_unit_id
LEFT OUTER JOIN lcp_job_details ljd ON ljd.system_file_number = jd.system_file_number
LEFT OUTER JOIN cd_wage_unit_codes cwua ON cwua.wage_unit_id = jd.room_and_board_unit_id                     
LEFT OUTER JOIN cd_wage_unit_codes cwum ON cwum.wage_unit_id = ljd.meal_deduction_unit_id                   
LEFT OUTER JOIN cd_currency_types wage_currency ON wage_currency.currency_type_id = jd.wage_currency_type_id
LEFT OUTER JOIN benefits b ON b.system_file_number = jd.system_file_number
LEFT OUTER JOIN cd_wage_unit_codes cwac ON cwac.wage_unit_id = b.rent_period                                
LEFT OUTER JOIN agric_job_details agr ON agr.system_file_number = jd.system_file_number
LEFT OUTER JOIN employment_locations el ON el.system_file_number = jd.system_file_number
LEFT OUTER JOIN cd_province_codes cpcel ON cpcel.province_id = el.province_id
LEFT OUTER JOIN business_details bd ON bd.organization_id = org.organization_id
LEFT OUTER JOIN business_details bd_tp ON bd_tp.third_party_id = tp.third_party_id
LEFT OUTER JOIN phones biz_phone on biz_phone.organization_id = org.organization_id
AND biz_phone.phone_type_id = 2
LEFT OUTER JOIN addresses a_biz on a_biz.address_id = bd.business_address_id
LEFT OUTER JOIN cd_province_codes biz_prov ON biz_prov.province_id = a_biz.province_id
LEFT OUTER JOIN cd_state_codes biz_state ON biz_state.state_id = a_biz.state_id
LEFT OUTER JOIN addresses a_tp_biz on a_tp_biz.address_id = bd_tp.business_address_id
LEFT OUTER JOIN cd_province_codes tp_biz_prov ON tp_biz_prov.province_id = a_tp_biz.province_id
LEFT OUTER JOIN cd_state_codes tp_biz_state ON tp_biz_state.state_id = a_tp_biz.state_idI don't know where to begin... What do you suggest? How about a view, then I would just select the data from that view. OR, a DENORMALIZED table that would be used only for reporting (the query is used in a REPORT).
Any suggestions are welcomed !
Thanks in advance,
Marc

You can use two distinct aproaches.
The most technical is run the query with event 10046 and 10053 enabled,
And search where Oracle is making a statistic mistake.
If there is no mistake, then could be a lack of index. post the result of both traces and we can help you.
If you don´t know how to deal with traces,
enable the autotrace SET AUTOTRACE ON, SET TIMING ON, run the query and post the result.
As you have many tables involved, my guess is a wrong driving table due to difference among statistics and real data distribution.
Good luck
Helio Dias
http://heliodias.wordpress.com

Similar Messages

  • Please can you help me in Tuning this query..?

    Hi ,
    Please can you help me in re-structuring this query? .Details are given below.
    I have 2 tables as shown below and data is like this.
    Position
    COD IND
    AAA N
    BBB N
    CCC N
    DDD Y
    Distance
    orig dest
    AAA BBB
    BBB CCC
    AAA CCC
    I need to create the records like this
    start end
    DDD AAA
    DDD BBB
    DDD CCC
    The query which i am using now for this is
    select p.code AS start,
    P1.CODE AS end
    from position p, position p1
    where
    P.CODE != P1.CODE
    AND (P.ind = 'Y' or P1.IND = 'Y')
    AND not exists
    (select 1
    from distance d
    where (d.orig = p.code or d.dest = p.code)
    and (d.orig = p1.code or d.dest = p1.code))
    table is having above a crore record. so its taking a lot of time.
    Please someone please help in tuning this query?
    Thanks and regards,
    Shabir

    Looks like you want this
    select a.strt, b.ends from
    (select p.code strt from position p where p.ind='Y') a,
    (select p.code ends from position p where p.ind='N') b
    where not exists (select 1 from distance d where d.orig=a.strt or d.dest=a.strt);
    DDD     AAA
    DDD     BBB
    DDD     CCCYour query result is:
    AAA     DDD
    BBB     DDD
    CCC     DDD
    DDD     AAA
    DDD     BBB
    DDD     CCCYou should be more descriptive about what kind of result you want, so that people can get more interested in helping you.

  • Tuning this query

    Hi,
    Can anybody please help me in tuning this query?
    update tablec c set c.col1 = (select b.col1 from tableb b where c.col2 = b.col2 ) where
    c.col2 in (select distinct a.col1 from tablec a, tableb b where a.col2 = b.col2 and a.col1 != b.col1 )
    When i use "alter session force parallel DML" before running this query it takes only seconds, but when i use parallel hint or run it without hint, its running for hours.
    Thanks for your Help

    Hi itssan,
    You could try EXISTS.
    I think this is the same:
    update tablec c
       set c.col1 =
              (select b.col1
                 from tableb b
                where b.col2 = c.col2)
    where exists (select null
                     from tablec a, tableb b
                    where a.col2 = b.col2
                      and a.col1 != b.col1
                      and a.col1 = c.col2);Regards
    Peter

  • Tuning SQL query

    Please help me in tuning this query. This view has around 2 million of records
    SELECT * FROM employee_v
    WHERE status_id IN (SELECT MAX(v2.status_id)status_id
    FROM employee_v v2
    WHERE UPPER(v2.name) LIKE UPPER(:v_name)||'%'
    GROUP BY v2.emp_id, v2.project_id)
    ORDER BY status_type_id;
    Here:
    employees may work on one or more projects
    employee working on a given project may have one or more status_ids associated.
    for example:
    emp_id     project_id     status_id
    10     100     1
    10     100     2
    20     100     2
    20     200     3
    30     100     4
    30     200     5
    30     200     6
    40     200     6
    If you have any other suggestions , please let me know too. For example, I was thinking that the subquery should use actual tables instead of the view because view is based on 10 tables and the subquery can instead use two tables . Does it make sense?
    Thanks a lot for the help!
    Edited by: user5406804 on Apr 20, 2010 5:42 AM

    If you have any other suggestions , please let me know too. Wild shot in the dark, but maybe using EXISTS instead of IN speeds up your query:
    untested for obvious reasons
    select *
    from  employee_v v
    where  upper(v.name) like upper(:v_name)||'%'
    where not exists ( select null
                       from   employee_v v2
                       and    v2.status_id > v.status_id                  
                       and    v2.emp_id = v.emp_id -- assuming you have some emp_id PK column
                                                   -- if necessary, you need to change the name of this column ofcourse
    order by status_type_id;Do compare the resultsets, not sure this will give you the same/desired result, but it might give you an idea.
    For example, I was thinking that the subquery should use actual tables instead of the view because > view is based on 10 tables and the subquery can instead
    use two tables . Does it make sense?Sounds like worth a try to me, yes. Less data to plough through = faster response.
    As well as using a function based index on UPPER(name) might be worth a try.

  • Parameters to be considered for tuning the QUERY Performance.

    Hi Guys
    I wanted to identify the Query which is taking more resources through the Dynamic performance views and not through OEM.I wanter to tune the Query.
    Please suggest me on this. Also i wanted to know what are all the parameters to be considered for tuning a query like Query execution time, I/O Hits, Library cache hits, etc and from which performance view these paramaters can be taken. I also wanted to know how to find the size of library cache and how much queries can be holded in a library cache and what will be the retention of queries in library cache and how to retrive the queries from Library cache.
    Thanks a lot
    Edited by: user448837 on Sep 23, 2008 9:24 PM

    Hmm there is a parameter called makemyquery=super_fast, check that ;-).
    Ok jokes apart, your question is like asking a doctor that when a person is sick than how to troubleshoot his sickeness? So does a doctor start giving medicine immediately? No right? He has to check some symptoms of the patient. The same is applicable to the query also. There is no view as such which would tell you the performance of the query ie it is good or bad. Tell me if a query is taking up 5 minutes and I come and tell you this, what would you say its good or bad or the query took this much CPU time what would you say, its too much or too less? I am sure your answers would be "it depends". That's the key point.
    The supermost point in the performance check is two things, one the plan of the query. What kind of plan optimizer took for the query and whether it was really good or not? There are millions os ways to do som ething but the idea is to do it in the best way. That's what the idea of reading explain plan. I would suggest get your self familiar with explain plan's various paths and their pros and cons. Also about the query's charectristics, you can check V$sql, v$sqlarea , V$sql_text views.
    Your other question that you want to check the size of the library cache , its contents and the retention, I would say that its all internally managed. You never size library cache but shared pool only. Similary the best bet for a dba/developer is to check the queries are mostly shareable and there wont be any duplicate sqls. So the cursor_sharing parameter can be used for this. The control is not given to us to manage the rentention or the flushing of the queries from the cache.
    HTH
    Aman....

  • Can someone please suggest me in tuning this query?

    Can someone please suggest me in tuning this query?
    select pemail.email_oid,
    pemail.parent_oid,
    md.message_data_oid,
    ea.email_account_oid,
    ef.email_folder_oid,
    md.channel,
    ea.email_account_name,
    md.from_address,
    md.to_address,
    eref.ref_id ticket_number,
    ( select count(email_oid) from esg.email where email_oid = pemail.email_oid and email.attachment_flag = 'Y' ) attachment_flag_a,
    ( select count(email_oid) from esg.email cemail
    where cemail.parent_oid = pemail.email_oid and
    ( cemail.email_type is null or cemail.email_type != 'S') and
    cemail.vec_status not in ('G', 'D', 'P') and
    cemail.vec_status in ('N', 'O') and
    cemail.attachment_flag = 'Y' ) attachment_flag_b,
    md.received_date,
    pemail.vec_status,
    pemail.email_type,
    md.subject,
    md.content,
    pemail.tracking_id,
    pemail.assignee_oid,
    ( select count(email_oid) from email cemail
    where cemail.parent_oid = pemail.email_oid and
    (cemail.email_type is null or cemail.email_type != 'S' ) and
    cemail.vec_status not in ('G','D', 'P') and
    cemail.vec_status in ('N', 'O' ) ) child_email_cnt,
    ( select count(0) from email
    where vec_status = 'N' and
    email_type = 'O' and
    email_oid = pemail.email_oid and
    vec_status in ('N', 'O' )) parent_newemail_cnt,
    ( select count(0) from email
    where vec_status = 'N' and
    email_type = 'O' and
    parent_oid = pemail.email_oid and
    vec_status in ('N', 'O' )) child_newemail_cnt
    From esg.email pemail,
    esg.message_data md,
    esg.email_account ea,
    esg.email_folder ef,
    (select email_oid, ref_id from email_ref
    where email_ref_oid in (select min(email_ref_oid) from email_ref where ref_tid = -9000 and ref_sid = 'ESG' and confirmed_flag = 'Y' group by email_oid )) eref
    where
    md.message_data_oid = pemail.message_data_oid and
    pemail.email_folder_oid = ef.email_folder_oid(+) and
    ef.email_account_oid = ea.email_account_oid(+) and
    pemail.vec_status not in ('G','D','P') and
    pemail.vec_status in ('N', 'O') and
    pemail.email_oid = eref.email_oid(+) and
    lower(md.channel) in ('[email protected]', '[email protected]') and
    pemail.email_oid in
    ( select parent.email_oid from message_data md,
    email parent
    where md.message_data_oid = parent.message_data_oid and
    parent.parent_oid is null and
    pemail.email_type = 'O' and
    lower(md.to_address) in
    ( select lower(contact_info) from esg.user_profile up,
    esg.person p,
    esg.person_contact pc
    where up.user_oid = 802239 and
    up.person_oid = p.person_oid and
    p.person_oid = pc.person_oid and
    pc.contact_type_oid = 6 )
    union all
    select child.parent_oid from message_data md,
    email child
    where md.message_data_oid = child.message_data_oid and
    parent_oid is not null and
    child.vec_status not in ('G','D','P') and
    child.vec_status in ('N', 'O') and
    child.email_type = 'O' and
    lower(md.to_address) in
    ( select lower(contact_info) from esg.user_profile up,
    esg.person p,
    esg.person_contact pc
    where up.user_oid = 802239 and
    up.person_oid = p.person_oid and
    p.person_oid = pc.person_oid and
    pc.contact_type_oid = 6 )
    ORDER BY RECEIVED_DATE DESC;
    1st run
    Elapsed: 00:00:03.39
    2nd run
    Elapsed: 00:00:01.80
    SQL> Select TABLE_NAME,LAST_ANALYZED, num_rows from user_tables where table_name in ('EMAIL','MESSAGE_DATA', 'EMAIL_ACCOUNT','EMAIL_FOLDER','EMAIL_REF','USER_PROFILE','PERSON','PERSON_CONTACT');
    TABLE_NAME LAST_ANAL NUM_ROWS
    USER_PROFILE 11-JUN-11 385808
    PERSON_CONTACT 11-JUN-11 698624
    PERSON 11-JUN-11 405364
    MESSAGE_DATA 11-JUN-11 1069
    EMAIL_REF 11-JUN-11 559
    EMAIL_FOLDER 11-JUN-11 563
    EMAIL_ACCOUNT 11-JUN-11 563
    EMAIL 11-JUN-11 101652
    8 rows selected.
    row count from all tables
    email - 102063
    message_data - 1069
    email_account - 563
    email_folder - 563
    email_ref - 559
    user_profile - 386055
    person - 404057
    person_contact - 698696
    Thanks,
    Suman M.

    ======================================
    Execution Plan
    Plan hash value: 110416976
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 1 | 1361 | 17 |
    | 1 | SORT AGGREGATE | | 1 | 8 | |
    |* 2 | TABLE ACCESS BY INDEX ROWID | EMAIL | 1 | 8 | 1 |
    |* 3 | INDEX UNIQUE SCAN | PK_EMAIL | 1 | | 1 |
    | 4 | SORT AGGREGATE | | 1 | 8 | |
    |* 5 | TABLE ACCESS BY INDEX ROWID | EMAIL | 1 | 8 | 1 |
    |* 6 | INDEX RANGE SCAN | FK_EMAIL_PARENT | 3 | | 1 |
    | 7 | SORT AGGREGATE | | 1 | 6 | |
    |* 8 | TABLE ACCESS BY INDEX ROWID | EMAIL | 1 | 6 | 1 |
    |* 9 | INDEX RANGE SCAN | FK_EMAIL_PARENT | 3 | | 1 |
    | 10 | SORT AGGREGATE | | 1 | 10 | |
    |* 11 | TABLE ACCESS BY INDEX ROWID | EMAIL | 1 | 10 | 1 |
    |* 12 | INDEX UNIQUE SCAN | PK_EMAIL | 1 | | 1 |
    | 13 | SORT AGGREGATE | | 1 | 6 | |
    |* 14 | TABLE ACCESS BY INDEX ROWID | EMAIL | 1 | 6 | 1 |
    |* 15 | INDEX RANGE SCAN | FK_EMAIL_PARENT | 3 | | 1 |
    | 16 | SORT ORDER BY | | 1 | 1361 | 17 |
    |* 17 | FILTER | | | | |
    | 18 | NESTED LOOPS OUTER | | 1 | 1361 | 5 |
    | 19 | NESTED LOOPS OUTER | | 1 | 1336 | 4 |
    | 20 | NESTED LOOPS | | 1 | 1328 | 3 |
    | 21 | NESTED LOOPS OUTER | | 1 | 53 | 2 |
    | 22 | INLIST ITERATOR | | | | |
    | 23 | TABLE ACCESS BY INDEX ROWID | EMAIL | 1 | 35 | 1 |
    |* 24 | INDEX RANGE SCAN | IE_EMAIL | 55 | | 1 |
    | 25 | VIEW PUSHED PREDICATE | | 1 | 18 | 1 |
    | 26 | NESTED LOOPS | | 1 | 36 | 4 |
    | 27 | VIEW | VW_NSO_1 | 11 | 143 | 3 |
    | 28 | SORT GROUP BY | | 11 | 231 | 3 |
    |* 29 | TABLE ACCESS BY INDEX ROWID| EMAIL_REF | 11 | 231 | 3 |
    |* 30 | INDEX FULL SCAN | AK1_EMAIL_REF | 21 | | 3 |
    |* 31 | TABLE ACCESS BY INDEX ROWID | EMAIL_REF | 1 | 23 | 1 |
    |* 32 | INDEX UNIQUE SCAN | PK_EMAIL_REF | 1 | | 1 |
    |* 33 | TABLE ACCESS BY INDEX ROWID | MESSAGE_DATA | 1 | 1275 | 1 |
    |* 34 | INDEX UNIQUE SCAN | PK_MESSAGE_DATA | 1 | | 1 |
    | 35 | TABLE ACCESS BY INDEX ROWID | EMAIL_FOLDER | 1 | 8 | 1 |
    |* 36 | INDEX UNIQUE SCAN | PK_EMAIL_FOLDER | 1 | | 1 |
    | 37 | TABLE ACCESS BY INDEX ROWID | EMAIL_ACCOUNT | 1 | 25 | 1 |
    |* 38 | INDEX UNIQUE SCAN | PK_EMAIL_ACCOUNT | 1 | | 1 |
    | 39 | UNION-ALL | | | | |
    | 40 | NESTED LOOPS SEMI | | 1 | 116 | 5 |
    | 41 | NESTED LOOPS | | 1 | 50 | 2 |
    |* 42 | TABLE ACCESS BY INDEX ROWID | EMAIL | 1 | 14 | 1 |
    |* 43 | INDEX UNIQUE SCAN | PK_EMAIL | 1 | | 1 |
    | 44 | TABLE ACCESS BY INDEX ROWID | MESSAGE_DATA | 1069 | 38484 | 1 |
    |* 45 | INDEX UNIQUE SCAN | PK_MESSAGE_DATA | 1 | | 1 |
    |* 46 | VIEW | VW_NSO_3 | 1 | 66 | 3 |
    |* 47 | FILTER | | | | |
    | 48 | NESTED LOOPS | | 1 | 45 | 3 |
    | 49 | NESTED LOOPS | | 1 | 15 | 2 |
    | 50 | TABLE ACCESS BY INDEX ROWID | USER_PROFILE | 1 | 10 | 1 |
    |* 51 | INDEX UNIQUE SCAN | PK_USER | 1 | | 1 |
    |* 52 | INDEX UNIQUE SCAN | PK_PERSON | 405K| 1979K| 1 |
    |* 53 | TABLE ACCESS BY INDEX ROWID | PERSON_CONTACT | 1 | 30 | 1 |
    |* 54 | INDEX RANGE SCAN | FK_PERSON_CONTACT_PERSON | 2 | | 1 |
    | 55 | NESTED LOOPS | | 1 | 114 | 5 |
    | 56 | MERGE JOIN CARTESIAN | | 1 | 78 | 4 |
    |* 57 | TABLE ACCESS BY INDEX ROWID | EMAIL | 1 | 12 | 1 |
    |* 58 | INDEX RANGE SCAN | FK_EMAIL_PARENT | 1 | | 1 |
    | 59 | BUFFER SORT | | 1 | 66 | 3 |
    | 60 | VIEW | VW_NSO_2 | 1 | 66 | 3 |
    | 61 | SORT UNIQUE | | 1 | 45 | |
    | 62 | NESTED LOOPS | | 1 | 45 | 3 |
    | 63 | NESTED LOOPS | | 1 | 15 | 2 |
    | 64 | TABLE ACCESS BY INDEX ROWID| USER_PROFILE | 1 | 10 | 1 |
    |* 65 | INDEX UNIQUE SCAN | PK_USER | 1 | | 1 |
    |* 66 | INDEX UNIQUE SCAN | PK_PERSON | 405K| 1979K| 1 |
    |* 67 | TABLE ACCESS BY INDEX ROWID | PERSON_CONTACT | 1 | 30 | 1 |
    |* 68 | INDEX RANGE SCAN | FK_PERSON_CONTACT_PERSON | 2 | | 1 |
    |* 69 | TABLE ACCESS BY INDEX ROWID | MESSAGE_DATA | 1 | 36 | 1 |
    |* 70 | INDEX UNIQUE SCAN | PK_MESSAGE_DATA | 1 | | 1 |
    Predicate Information (identified by operation id):
    2 - filter("EMAIL"."ATTACHMENT_FLAG"='Y')
    3 - access("EMAIL_OID"=:B1)
    5 - filter("CEMAIL"."EMAIL_TYPE"<>'S' AND "CEMAIL"."VEC_STATUS"<>'G' AND
    "CEMAIL"."VEC_STATUS"<>'D' AND "CEMAIL"."VEC_STATUS"<>'P' AND ("CEMAIL"."VEC_STATUS"='N'
    OR "CEMAIL"."VEC_STATUS"='O') AND "CEMAIL"."ATTACHMENT_FLAG"='Y')
    6 - access("CEMAIL"."PARENT_OID"=:B1)
    8 - filter("CEMAIL"."EMAIL_TYPE"<>'S' AND "CEMAIL"."VEC_STATUS"<>'G' AND
    "CEMAIL"."VEC_STATUS"<>'D' AND "CEMAIL"."VEC_STATUS"<>'P' AND ("CEMAIL"."VEC_STATUS"='N'
    OR "CEMAIL"."VEC_STATUS"='O'))
    9 - access("CEMAIL"."PARENT_OID"=:B1)
    11 - filter("VEC_STATUS"='N' AND "EMAIL_TYPE"='O')
    12 - access("EMAIL_OID"=:B1)
    14 - filter("VEC_STATUS"='N' AND "EMAIL_TYPE"='O')
    15 - access("PARENT_OID"=:B1)
    17 - filter( EXISTS ( (SELECT "PARENT"."EMAIL_OID" FROM "EMAIL" "PARENT","MESSAGE_DATA"
    "MD", (SELECT LOWER("CONTACT_INFO") "$nso_col_1" FROM "ESG"."PERSON_CONTACT"
    "PC","ESG"."PERSON" "P","ESG"."USER_PROFILE" "UP" WHERE :B1='O' AND
    "UP"."USER_OID"=802239 AND "UP"."PERSON_OID"="P"."PERSON_OID" AND
    "P"."PERSON_OID"="PC"."PERSON_OID" AND "PC"."CONTACT_TYPE_OID"=6)
    "VW_NSO_3" WHERE
    "$nso_col_1"=LOWER("MD"."TO_ADDRESS") AND "MD"."MESSAGE_DATA_OID"="PARENT"."MESSAGE_DATA_O
    ID" AND "PARENT"."EMAIL_OID"=:B2 AND "PARENT"."PARENT_OID" IS NULL
    ) UNION ALL (SELECT
    "CHILD"."PARENT_OID" FROM "EMAIL" "CHILD","MESSAGE_DATA" "MD", (SELECT DISTINCT
    LOWER("CONTACT_INFO") "$nso_col_1" FROM "ESG"."PERSON_CONTACT" "PC","ESG"."PERSON"
    "P","ESG"."USER_PROFILE" "UP" WHERE "UP"."USER_OID"=802239 AND
    "UP"."PERSON_OID"="P"."PERSON_OID" AND "P"."PERSON_OID"="PC"."PERSON_OID" AND
    "PC"."CONTACT_TYPE_OID"=6) "VW_NSO_2" WHERE "MD"."MESSAGE_DATA_OID
    "="CHILD"."MESSAGE_DATA_
    OID" AND "$nso_col_1"=LOWER("MD"."TO_ADDRESS") AND "CHILD"."PARENT
    _OID"=:B3 AND
    "CHILD"."VEC_STATUS"<>'G' AND "CHILD"."VEC_STATUS"<>'D' AND "CHILD
    "."VEC_STATUS"<>'P' AND
    ("CHILD"."VEC_STATUS"='N' OR "CHILD"."VEC_STATUS"='O') AND "CHILD"
    ."EMAIL_TYPE"='O' AND
    "PARENT_OID" IS NOT NULL)))
    24 - access("PEMAIL"."VEC_STATUS"='N' OR "PEMAIL"."VEC_STATUS"='O')
    filter("PEMAIL"."VEC_STATUS"<>'G' AND "PEMAIL"."VEC_STATUS"<>'D' AND
    "PEMAIL"."VEC_STATUS"<>'P')
    29 - filter("CONFIRMED_FLAG"='Y')
    30 - access("REF_SID"='ESG' AND "REF_TID"=(-9000))
    filter("REF_TID"=(-9000) AND "REF_SID"='ESG')
    31 - filter("EMAIL_OID"="PEMAIL"."EMAIL_OID")
    32 - access("EMAIL_REF_OID"="$nso_col_1")
    33 - filter(LOWER("MD"."CHANNEL")='[email protected]' OR
    LOWER("MD"."CHANNEL")='[email protected]')
    34 - access("MD"."MESSAGE_DATA_OID"="PEMAIL"."MESSAGE_DATA_OID")
    36 - access("PEMAIL"."EMAIL_FOLDER_OID"="EF"."EMAIL_FOLDER_OID"(+))
    38 - access("EF"."EMAIL_ACCOUNT_OID"="EA"."EMAIL_ACCOUNT_OID"(+))
    42 - filter("PARENT"."PARENT_OID" IS NULL)
    43 - access("PARENT"."EMAIL_OID"=:B1)
    45 - access("MD"."MESSAGE_DATA_OID"="PARENT"."MESSAGE_DATA_OID")
    46 - filter("$nso_col_1"=LOWER("MD"."TO_ADDRESS"))
    47 - filter(:B1='O')
    51 - access("UP"."USER_OID"=802239)
    52 - access("UP"."PERSON_OID"="P"."PERSON_OID")
    53 - filter("PC"."CONTACT_TYPE_OID"=6)
    54 - access("P"."PERSON_OID"="PC"."PERSON_OID")
    57 - filter("CHILD"."VEC_STATUS"<>'G' AND "CHILD"."VEC_STATUS"<>'D' AND
    "CHILD"."VEC_STATUS"<>'P' AND ("CHILD"."VEC_STATUS"='N' OR "CHILD"
    ."VEC_STATUS"='O') AND
    "CHILD"."EMAIL_TYPE"='O')
    58 - access("CHILD"."PARENT_OID"=:B1)
    filter("PARENT_OID" IS NOT NULL)
    65 - access("UP"."USER_OID"=802239)
    66 - access("UP"."PERSON_OID"="P"."PERSON_OID")
    67 - filter("PC"."CONTACT_TYPE_OID"=6)
    68 - access("P"."PERSON_OID"="PC"."PERSON_OID")
    69 - filter("$nso_col_1"=LOWER("MD"."TO_ADDRESS"))
    70 - access("MD"."MESSAGE_DATA_OID"="CHILD"."MESSAGE_DATA_OID")
    Note
    - cpu costing is off (consider enabling it)
    Statistics
    3103 recursive calls
    0 db block gets
    599654 consistent gets
    2915 physical reads
    0 redo size
    1955 bytes sent via SQL*Net to client
    3895 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    331 sorts (memory)
    0 sorts (disk)
    0 rows processed
    =====================================

  • Help needed in tuning a query

    Hi,
    I need some help in performing tuning of a big query. Explain plan is as under:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    Edited by: AbdulHadi on Sep 16, 2011 3:56 PM
    Edited by: AHadi on Sep 19, 2011 10:02 AM

    3     SORT GROUP BY          47916     25M     491G     15M (3)     17:30:31               
    4     VIEW          870M     445G          15M (2)     17:24:08               
    5     HASH GROUP BY          870M     427G     885G     15M (2)     17:24:08               
    In above steps its using very high temporary tablespace usage. please try to tune your query.
    - dynamic sampling used for this statement
    The statistics appears to be stale.

  • Help in tuning the Query

    Pls see this attached query. This is hitting a table which has around 110 mil recs. And this takes around 60 min to execute. IS there any way to tune it better? I am assuming that because this uses the ' With tmp as' clauses, it might be using the Indexes.
    Can anyone suggest some tuning tips?
    Satish
    WITH all_edbc_pending_edg
         AS (SELECT
                    a.day_sk,
                    a.case_num,
                    a.edg_num,
                    a.edg_trace_id,
                    a.application_dt, 
                    a.current_elig_ind,
                    a.payment_begin_dt payment_beg_dt
             FROM   fct_eligibility_2 a,
                    dim_edg_activity_type b
             WHERE  a.current_elig_ind IN ('P','S','A')
    and mod(case_num,2)=0
                    AND b.eff_end_dt IS NULL
                    AND b.activity_type_cd IN ('IN','RE','IR','PR','OG')
                    AND a.activity_type_sk=b.activity_type_sk
    , Pick_Latest_Prior_Med as
    SELECT  t3.case_num,
            t3.edg_num,
            t3.current_elig_ind,
            t3.application_dt,
            t3.day_sk,
            t3.payment_beg_dt,
            t3.edg_trace_id
    FROM   (SELECT t2.*,
                   Row_number()
                     OVER(PARTITION BY t2.case_num,t2.edg_num, t2.application_dt ORDER BY t2.day_sk DESC, t2.payment_beg_dt DESC, t2.edg_trace_id DESC) AS rn
            FROM   all_edbc_pending_edg t2) t3
    WHERE  t3.rn = 1
    Select
           case_num,
           edg_num,
           application_dt,
           payment_beg_dt,
           edg_trace_id,
           current_elig_ind
    FROM
            SELECT  t1.case_num,
                   t1.edg_num, 
                   t1.application_dt, 
                   t1.payment_beg_dt,
                   t1.edg_trace_id,
                   t1.current_elig_ind
            FROM   (SELECT  t.*,
                           Row_number()
                             OVER(PARTITION BY t.case_num,t.edg_num ORDER BY t.day_sk DESC, t.payment_beg_dt DESC, t.edg_trace_id DESC) AS rn
                    FROM   Pick_Latest_Prior_Med  t) t1
            WHERE  t1.rn = 1
            ) p
    WHERE
           current_elig_ind IN ('P','S')

    Check this link and post what is required as mentioned in the link.
    SQL and PL/SQL FAQ
    >
    I am assuming that because this uses the ' With tmp as' clauses, it might be using the Indexes.
    >
    You don't need to assume. You can find out what's exactly happening if you follow the steps described in the above mentioned link.
    Regards
    Raj

  • Performance tuning in Query

    Dear All,
    My client wants to do the performance tuning in a query where it has the Global structure of 300 CKF & 300 RKF.
    They dont want to touch the MP, all they want to do some performance tuning through the front end without touching the Multiprovider.
    The CKF is little bit tricky where in Each CKF has 28 RKF and In each RKF atleast 2 variables are used an with hierarchy restrictions. The query is taking 30 - 40 min to execute. Kindly guide me how to handle this.
    Regards,
    Suman Thangadurai.

    HI,
    Improving query performance u2013
    -     Generate index.
    -     Build query on multiprovider and better use Constant Selection Function to bring infoset functionality to Multiprovider.
    -     Make your query more dynamic using variables.
    -     Do partitioning on IC when you have restriction on 0CALMONTH.
    -     Use more free charecterstics.
    -     Use include than exclude at Bex level.
    -     Utilize Cache mode and Read mode functions.
    Regards,
    rvc

  • Tuning OBIEE query with DB index, but it's getting slower

    Hello guys
    I just have a quick question about tuning the performance of sql query using bitmap indexes..
    Currently, there are 2 tables, date and fact. Fact table has about 1 billion row and date dim has about 1 million. These 2 tables are joined by 2 columns:
    Date.Dateid = Fact.snapshot.dates and Date.companyid = fact.companynumber
    I have query that needs to be run as the following:
    Select dates.dayofweek, dates,dates, fact.opened_amount from dates, facts
    where Date.Dateid = Fact.snapshot.dates and Date.companyid = fact.companynumber and dates.dayofweek = 'monday'.
    Currently this query is running forever. I think it is joining that takes a lot of time. I have created bitmap index on dayofweek column because it's low on distinctive rows. But it didn't seem to speed up with the performance, but rather made it worse. The explain plan before and after creating that index was the same as:
    Select statement optimizer
    nested loops
    partition list all
    index full scan RD_T.PK_FACTS_SNPSH
    TABLE ACCESS BY INDEX ROWID DATES_DIM
    INDEX UNIQUE SCAN DATES_DIM_DATE
    It seems the bitmap index I created for DATES_DIM wasn't used... Also, I am thinking what other indexes I should create for fact table..
    I'd like to know what other indexes will be helpful for me and on which table & columns?.. I am thinking of creating another one for companynumber since it also have low distinctive records.
    Currently I can't purge data or create smaller table, I have to what with what I have..
    So please let me know your thoughts in terms of performance tunings for such situation..
    Thanks

    Jack,
    Thank you for your response. It helped me to clean up the query. All the changes did not give a much better explain plan - at least not to my inexperienced eyes - but the total execution time for the query is now reduced to under two minutes. The query as it is now:
    select /*+ ordered all_rows */ x.rowid1
    from table(sdo_join('CYCLORAMA','GEOMETRIE','CYCLORAMA','GEOMETRIE','distance=3 mask=ANYINTERACT')) x
    , cyclorama s, cyclorama t
    where not x.rowid1 = x.rowid2
    and s.rowid = x.rowid1 and x.rowid2 = t.rowid
    and s.datasetid != t.datasetid
    and s.opnamedatum < t.opnamedatum;Because the docs state that mask=FILTER is the default, I added an explicit mask=ANYINTERACT to the sdo_join parameters when I removed the sdo_distance from the query. Still, the query returns 205035 records with the sdo_distance, and 205125 without. But this may be the result of the extra 0.001 from sdo_dim. I did not investigate as the 3 meter is not crucial.
    I believe I already had a mechanism in place to reduce the number of self-joins with "not x.rowid1 = x.rowid2" and "s.opnamedatum < t.opnamedatum". I can not guarantee that for all records s.opnamedatum < t.opnamedatum equals x.rowid1 < x.rowid2.
    Based on the [url http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14255/sdo_operat.htm#BGEDJIBF]docs, I finally added an 'ordered' hint and reshuffled the tables in the from clause.
    I'm happy with performance now, and creating a new table with the records to keep should not be a problem. Still I'm curious about the following:
    <li>Is it worth optimizing the SDO_DIM_ARRAY for the original table, e.g. narrowing the range of coordinate values?
    <li>How can sdo_join best be used for an anti-join, to select the records to keep?
    Thank you,
    J-----.

  • Performance tuning sql query

    Hi,
    Can anyone assist me in tuning the below query
    Thanks in Advance
    A.Gopal
    SELECT nvl(sum(p.GRP_ACTUALQUANTITY),0)                
    FROM GOODSRECEIPTS r, GOODSRECEIPTPOSITIONS p
    ,reportparameters plt,reportparameters spl,reportparameters mat
    WHERE r.GRH_NO = p.GRP_GRH_NO
    AND TRUNC(r.GRH_ARRIVAL) BETWEEN NVL(TO_DATE('01-jan-09'), TRUNC(r.GRH_ARRIVAL)) AND NVL(TO_DATE('31-jan-09'), TRUNC(r.GRH_ARRIVAL))
    AND (p.GRP_PLT_ID = 'VDN' OR 1 =0)
    AND (r.GRH_SPL_ID = '15035122' OR 1 =0)
    AND (p.GRP_MAT_ID = '1001360' OR 1 =0)
    AND ('01.01.2009' = 'TOTAL' or trunc(r.GRH_ARRIVAL,'mm') = to_date('01.01.2009','dd.mm.yyyy'))
                             and plt.rep_field = 'PLT_ID' AND plt.rep_id = 'AN_EXC_RAT' AND plt.rep_user = 'ANANTGOP'      
                        and spl.rep_field = 'SPL_ID' AND spl.rep_id = 'AN_EXC_RAT' AND spl.rep_user ='ANANTGOP'
                        and mat.rep_field = 'MAT_ID' AND mat.rep_id = 'AN_EXC_RAT' AND mat.rep_user = 'ANANTGOP'
                        and r.GRH_SPL_ID = decode(spl.rep_value,'All',r.GRH_SPL_ID,spl.rep_value)
                        and p.GRp_plt_ID = decode(plt.rep_value,'All',p.GRp_plt_ID,plt.rep_value)
                   and p.GRp_mat_ID = decode(mat.rep_value,'All',p.GRp_mat_ID,mat.rep_value)
    AND NOT EXISTS (SELECT 1 FROM GOODSRECEIPTUSAGESTATUS u
    WHERE p.GRP_GRH_NO = u.GRU_GRP_GRH_NO
    AND p.GRP_NO =u.GRU_GRP_NO
    AND u.GRU_UST_ID = 'CANCEL')

    This query is used in my Oracle report. The original query is like beow
         SELECT nvl(sum(p.GRP_ACTUALQUANTITY),0)                
    FROM GOODSRECEIPTS r, GOODSRECEIPTPOSITIONS p
    ,reportparameters plt,reportparameters spl,reportparameters mat
    WHERE r.GRH_NO = p.GRP_GRH_NO
    AND TRUNC(r.GRH_ARRIVAL) >= NVL(:l_date_from, TRUNC(r.GRH_ARRIVAL)) AND
              TRUNC(r.GRH_ARRIVAL) <=NVL(:l_date_to, TRUNC(r.GRH_ARRIVAL))
    AND (p.GRP_PLT_ID = :p_plt_id OR :ip_plt_group =0)
    AND (r.GRH_SPL_ID = :p_spl_id OR :ip_spl_group =0)
    AND (p.GRP_MAT_ID = :p_mat_id OR :ip_mat_group =0)
    AND (:l_flag = 'TOTAL' or trunc(r.GRH_ARRIVAL,'mm') = to_date(:p_month_abc_sp,'dd.mm.yyyy'))
                             and plt.rep_field = 'PLT_ID' AND plt.rep_id = :ip_rep_id AND plt.rep_user = :ip_rep_user      
                        and spl.rep_field = 'SPL_ID' AND spl.rep_id = :ip_rep_id AND spl.rep_user = :ip_rep_user
                        and mat.rep_field = 'MAT_ID' AND mat.rep_id = :ip_rep_id AND mat.rep_user = :ip_rep_user     
                        and r.GRH_SPL_ID = decode(spl.rep_value,'All',r.GRH_SPL_ID,spl.rep_value)
                        and p.GRp_plt_ID = decode(plt.rep_value,'All',p.GRp_plt_ID,plt.rep_value)
                   and p.GRp_mat_ID = decode(mat.rep_value,'All',p.GRp_mat_ID,mat.rep_value)
    AND NOT EXISTS (SELECT 1      
                                            FROM GOODSRECEIPTUSAGESTATUS u
                                            WHERE p.GRP_GRH_NO = u.GRU_GRP_GRH_NO
                        AND p.GRP_NO =u.GRU_GRP_NO
                                                                AND u.GRU_UST_ID = 'CANCEL');
    :ip_rep_id = 'AN_EXC_RAT'
    :ip_rep_user = 'ANANTGOP
    Value of :l_flag = '01.01.2009'
    (:p_month_abc_sp = '01.01.2009'
    Thanks
    A.Gopal

  • Query tuning for query using connect by prior

    I have written following query to fetch the data. The query is written in this format because there are multiple rows, which make one recrd and we need to bring that record into one row.
    For one CAT(commented here), this query takes around 4 minutes and fetches 6900 records but when it runs for 3 CAT, it takes 17 mins.
    I want to tune this as this has to run for 350 CAT values.
    It is doing FTS on the main table. I tried to use different hints like PARALLEL, APPEND (in insert) but nothing worked.
    The cost of the query is 51.
    Any help/suggestions will be appreciated.
    SELECT DISTINCT MIN(SEQ) SEQ,
    PT, APP, IT, LR, QT,CD, M_A_FLAG,
    STRAGG(REM) REM, -- aggregates the data from different columns to one which is parent
    CAT
    FROM (WITH R AS (SELECT CAT, SEQ, PT, M_A_FLAG, IT, LR,QT,CD, REM, APP
    FROM table1
    WHERE REC = '36' AND M_A_FLAG = '1'
    --AND CAT = '11113')
    SELECT CAT, SEQ,
    CONNECT_BY_ROOT PT AS PT,
    CONNECT_BY_ROOT APP AS APPL,
    M_A_FLAG,
    CONNECT_BY_ROOT IT AS IT,
    CONNECT_BY_ROOT LR AS LR,
    CONNECT_BY_ROOT QT AS QT,
    CONNECT_BY_ROOT CD AS CD,
    REM
    FROM R A
    START WITH PT IS NOT NULL
    CONNECT BY PRIOR SEQ + 1 = SEQ
    AND PRIOR CAT = CAT
    AND PT IS NULL)
    GROUP BY PT, APP, IT,LR, QT, CD, M_A_FLAG, CAT
    ORDER BY SEQ;
    Thanks.
    Edited by: user2544469 on Feb 11, 2011 1:12 AM

    The following threads detail the approach and information required.
    Please gather relevant info and post back.
    How to post a SQL tuning request - HOW TO: Post a SQL statement tuning request - template posting
    When your query takes too long - When your query takes too long ...

  • Tuning the query : Very Urgent

    Hi
    We have query wich needs tuning.when we are putting REGULAR EXPRESSION query is running fine but whne we put like LIKE stmt it is taking time.Here is the query below.Please help on tuning.
    SELECT a.order_number, b.last_update_date,TO_CHAR( b.split_percent,'FM99999.009') SPLIT_PERCENTAGE,
    rs.NAME " SALES_PERSON_NAME ", rs.salesrep_number, b.effective_date,
    b.creation_date "CREATION_DATE", rt.NAME "TERRITORY_NAME",
    rt.segment1 "ERP_CODE", a.booked_date "DATE_BOOKED",
    TO_CHAR(ROUND((( (SELECT SUM (ordered_quantity * unit_selling_price)
    FROM apps.oe_order_lines_all ol
    WHERE ol.header_id = a.header_id)
    * b.split_percent
    / 100
    ) , 2),'FM99999999999999999999.009') order_total ,
    (SELECT user_name
    FROM fnd_user
    WHERE user_id = b.last_updated_by) requested_by,
    b.obsolete_date
    FROM oe_order_headers_all a,
    apps.csm_header_sales_cr_hist b,
    jtf_rs_salesreps rs,
    ra_territories rt
    WHERE 1 = 1
    AND a.header_id = b.source_header_id
    AND b.territory_id = rt.territory_id
    AND b.salesrep_id = rs.salesrep_id
    AND b.source_type = 'O'
    AND a.order_number IN (
    SELECT a.order_number
    FROM oe_order_headers_all a,
    apps.csm_header_sales_cr_hist b,
    jtf_rs_salesreps rs,
    ra_territories rt
    WHERE 1 = 1
    AND a.header_id = b.source_header_id
    AND b.territory_id = rt.territory_id
    AND b.salesrep_id = rs.salesrep_id
    AND b.source_type = 'O'
    -- AND b.obsolete_date IS NULL --ommented by andondap as per TD#9648 Changes
    AND  REGEXP_LIKE ( rs.name , '(svc)|(Muti.*Y)|(Multi.*Y)|(._MY)')  Commented by andondap as per TD#9648 Changes
    AND b.last_update_date BETWEEN TO_DATE ('2012/11/25', 'YYYY/MM/DD') AND TO_DATE ('2013/03/23', 'YYYY/MM/DD')+ 0.9999
    AND REGEXP_LIKE ( rs.name,'(.MY)|(Muti.*Y))|(Multi.*Y)|(._MY) |(mlti)')
    AND rs.name LIKE '%SVC%MULTI%' OR rs.name NOT LIKE '%DUMMY%' OR rs.name LIKE 'Svc%Multi%' OR rs.name LIKE 'Svc%MY%'
    OR rs.name LIKE 'Service%Multi%' OR rs.name LIKE '%MY_SHARE_TM' OR rs.name LIKE '%MY_SHARE_T')
    ORDER BY a.order_number, b.creation_date
    Thanks
    Hibin

    Hmmm, let's see...
    1. OP provided formatted code using {noformat}{noformat} tags.... - FAILED
    2. OP provided database version in full... - FAILED
    3. OP provided table structures and index information... - FAILED
    4. OP provided cardinality and selectivity information... - FAILED
    5. OP provided explain plans... - FAILED
    6. OP provided execution traces... - FAILED
    7. OP is a new member and can be excused for above failures... - FAILED
    8. OP has asked previous questions and followed forum etiquette by marking them as answered... - FAILED
    9. OP has respected volunteers and other questioners by not marking his question as Urgent... - FAILED
    10. OP has read the forum FAQ ({message:id=9360002}) for posting his question...  - FAILED
    11. OP has read the forum FAQ ({message:id=9360003}) for posting a tuning question... - FAILED
    It's a good job you're not a computer program, you wouldn't have even compiled.
    so, points to note:
    This is a forum of volunteers.  There's no such thing as an Urgent question here, and it's considered rude to suggest your question is urgent, as that indicates you want immediate attention from the people who are giving up their own time to help, and who have their own jobs to do.  It's also rude for the other people who are asking questions, as everyone would like an answer to their problem as soon as possible, so what makes you any more special?  An urgent issue is one where a live system is down potentially putting people's lives at risk or causing a company to lose money, or somehow damage their services.  Such issues should be logged with Oracle Support, not on the free OTN forums.
    Next, when you post your question, ensure you provide all the information that is needed for people to be able to help you.  Read the FAQ posts which point to useful threads indicating what information is required, especially for tuning requests.
    Finally, when your questions have been answered, it is common courtesy to mark them as answered (and award points if appropriate), otherwise it indicates that you have no respect for the people who are helping you.
    If you follow all the advice above, you will end up creating a good question that people will be willing to help you with.   If you don't follow the advice above, such as in this question you've posted, you will find that few experts will bother to help (or if they post it will not likely be helpful advise you receive).  The choice is yours.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Please help!!! Tuning the query

    Hi,
    I am using Oracle BDBXML 2.4.16. In the following, policyContainer.dbxml has around 1000 documents and productsContainer.dbxml around 10 documents. The following query is taking around 6 - 8 seconds to fetch the data of around 300 records. I have created node-element-equality-string indexes on PolicyEvent, PolicyStatus, Archived, IsLatest, ProductID and CompanyID.
    I am novice on Query tuning. Can someone please help me to tune the following query. I have posted the query plan as well.
    Thanks in Advance!!
    Balakrishna.
    Query:
    query ' for $policy in collection("policyContainer.dbxml")/Policy[PolicyState/PolicyEvent=("APPLICATION","QUOTE","BINDER","POLICY","ENDORSEMENT QUOTE")]
    [PolicyHeader/ProductID = (for $product in collection("productsContainer.dbxml")/Product/ProductsHeader[CompanyID=(1)] return $product/ProductID)]
    [PolicyState/PolicyStatus !=("RATE","DECLINED ENDORSEMENT QUOTE","DECLINED NON-PRE ENDORSEMENT QUOTE","DECLINED EXTENSION QUOTE")]
    [PolicyState/Archived !="true"]
    [(PolicyState/IsLatest !="false"
    and (PolicyState/PolicyStatus != ("ENDORSEMENT QUOTE","NON-PRE ENDORSEMENT QUOTE","EXTENSION QUOTE")))
    or (PolicyState/IsLatest !="true"
    and (PolicyState/PolicyStatus =("ENDORSEMENT QUOTE","NON-PRE ENDORSEMENT QUOTE","EXTENSION QUOTE")))]
    let $state := $policy/PolicyState 
    let $header := $policy/PolicyHeader
    let $datatable := $policy/DataTable/DataTableInfo
    return
    <policyDetail>
    {$policy/SubmissionNumber},
    {$policy/DocumentNumber},
    {$policy/QuoteVersionNumber},
    {$state/*,$header/*,$datatable/*}
    </policyDetail>'
    Query plan:
    <XQuery>
      <Return>
        <LetTuple uri="" name="datatable">
          <LetTuple uri="" name="header">
            <LetTuple uri="" name="state">
              <ForTuple uri="" name="policy">
                <ContextTuple/>
                <QueryPlanToAST>
                  <BufferQP id="2">
                    <NegativeNodePredicateFilterQP uri="" name="#tmp67">
                      <NegativeNodePredicateFilterQP uri="" name="#tmp73">
                        <NodePredicateFilterQP uri="" name="#tmp404">
                          <ParentOfChildJoinQP>
                            <StepQP axis="parent-of-child" name="PolicyState" nodeType="element">
                              <UnionQP>
                                <ValueQP container="policyContainer.dbxml" index="node-element-equality-string" operation="eq" child="PolicyEvent" value="ENDORSEMENT QUOTE"/>
                                <ValueQP container="policyContainer.dbxml" index="node-element-equality-string" operation="eq" child="PolicyEvent" value="APPLICATION"/>
                                <ValueQP container="policyContainer.dbxml" index="node-element-equality-string" operation="eq" child="PolicyEvent" value="POLICY"/>
                                <ValueQP container="policyContainer.dbxml" index="node-element-equality-string" operation="eq" child="PolicyEvent" value="BINDER"/>
                                <ValueQP container="policyContainer.dbxml" index="node-element-equality-string" operation="eq" child="PolicyEvent" value="QUOTE"/>
                              </UnionQP>
                            </StepQP>
                            <StepQP axis="child" name="Policy" nodeType="element">
                              <SequentialScanQP container="policyContainer.dbxml" nodeType="document"/>
                            </StepQP>
                          </ParentOfChildJoinQP>
                          <ValueFilterQP comparison="eq" general="true">
                            <StepQP axis="child" name="ProductID" nodeType="element">
                              <StepQP axis="child" name="PolicyHeader" nodeType="element">
                                <VariableQP name="#tmp404"/>
                              </StepQP>
                            </StepQP>
                            <Atomize>
                              <Return>
                                <ForTuple uri="" name="product">
                                  <ContextTuple/>
                                  <QueryPlanToAST>
                                    <ParentOfChildJoinQP>
                                      <ValueFilterQP comparison="eq" general="true">
                                        <PresenceQP container="productsContainer.dbxml" index="node-element-equality-string" operation="prefix" child="CompanyID"/>
                                        <Sequence>
                                          <NumericTypeConstructor value="1.0E0" typeuri="http://www.w3.org/2001/XMLSchema" typename="integer"/>
                                        </Sequence>
                                      </ValueFilterQP>
                                      <StepQP axis="child" name="ProductsHeader" nodeType="element">
                                        <StepQP axis="child" name="Product" nodeType="element">
                                          <SequentialScanQP container="productsContainer.dbxml" nodeType="document"/>
                                        </StepQP>
                                      </StepQP>
                                    </ParentOfChildJoinQP>
                                  </QueryPlanToAST>
                                </ForTuple>
                                <QueryPlanToAST>
                                  <StepQP axis="child" name="ProductID" nodeType="element">
                                    <VariableQP name="product"/>
                                  </StepQP>
                                </QueryPlanToAST>
                              </Return>
                            </Atomize>
                          </ValueFilterQP>
                        </NodePredicateFilterQP>
                        <ValueFilterQP comparison="ne" general="true">
                          <ValueFilterQP comparison="ne" general="true">
                            <ValueFilterQP comparison="ne" general="true">
                              <ValueFilterQP comparison="ne" general="true">
                                <StepQP axis="child" name="PolicyStatus" nodeType="element">
                                  <StepQP axis="child" name="PolicyState" nodeType="element">
                                    <VariableQP name="#tmp73"/>
                                  </StepQP>
                                </StepQP>
                                <Sequence>
                                  <AnyAtomicTypeConstructor value="RATE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                                  <AnyAtomicTypeConstructor value="DECLINED ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                                  <AnyAtomicTypeConstructor value="DECLINED NON-PRE ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                                  <AnyAtomicTypeConstructor value="DECLINED EXTENSION QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                                </Sequence>
                              </ValueFilterQP>
                              <Sequence>
                                <AnyAtomicTypeConstructor value="RATE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                                <AnyAtomicTypeConstructor value="DECLINED ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                                <AnyAtomicTypeConstructor value="DECLINED NON-PRE ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                                <AnyAtomicTypeConstructor value="DECLINED EXTENSION QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                              </Sequence>
                            </ValueFilterQP>
                            <Sequence>
                              <AnyAtomicTypeConstructor value="RATE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                              <AnyAtomicTypeConstructor value="DECLINED ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                              <AnyAtomicTypeConstructor value="DECLINED NON-PRE ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                              <AnyAtomicTypeConstructor value="DECLINED EXTENSION QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                            </Sequence>
                          </ValueFilterQP>
                          <Sequence>
                            <AnyAtomicTypeConstructor value="RATE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                            <AnyAtomicTypeConstructor value="DECLINED ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                            <AnyAtomicTypeConstructor value="DECLINED NON-PRE ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                            <AnyAtomicTypeConstructor value="DECLINED EXTENSION QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                          </Sequence>
                        </ValueFilterQP>
                      </NegativeNodePredicateFilterQP>
                      <ChildJoinQP>
                        <StepQP axis="child" name="PolicyState" nodeType="element">
                          <VariableQP name="#tmp67"/>
                        </StepQP>
                        <ValueQP container="policyContainer.dbxml" index="node-element-equality-string" operation="eq" child="Archived" value="true"/>
                      </ChildJoinQP>
                    </NegativeNodePredicateFilterQP>
                    <UnionQP>
                      <NegativeNodePredicateFilterQP uri="" name="#tmp18">
                        <NegativeNodePredicateFilterQP uri="" name="#tmp46">
                          <BufferReferenceQP id="2"/>
                          <ChildJoinQP>
                            <StepQP axis="child" name="PolicyState" nodeType="element">
                              <VariableQP name="#tmp46"/>
                            </StepQP>
                            <ValueQP container="policyContainer.dbxml" index="node-element-equality-string" operation="eq" child="IsLatest" value="false"/>
                          </ChildJoinQP>
                        </NegativeNodePredicateFilterQP>
                        <ValueFilterQP comparison="ne" general="true">
                          <ValueFilterQP comparison="ne" general="true">
                            <ValueFilterQP comparison="ne" general="true">
                              <StepQP axis="child" name="PolicyStatus" nodeType="element">
                                <StepQP axis="child" name="PolicyState" nodeType="element">
                                  <VariableQP name="#tmp18"/>
                                </StepQP>
                              </StepQP>
                              <Sequence>
                                <AnyAtomicTypeConstructor value="ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                                <AnyAtomicTypeConstructor value="NON-PRE ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                                <AnyAtomicTypeConstructor value="EXTENSION QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                              </Sequence>
                            </ValueFilterQP>
                            <Sequence>
                              <AnyAtomicTypeConstructor value="ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                              <AnyAtomicTypeConstructor value="NON-PRE ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                              <AnyAtomicTypeConstructor value="EXTENSION QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                            </Sequence>
                          </ValueFilterQP>
                          <Sequence>
                            <AnyAtomicTypeConstructor value="ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                            <AnyAtomicTypeConstructor value="NON-PRE ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                            <AnyAtomicTypeConstructor value="EXTENSION QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                          </Sequence>
                        </ValueFilterQP>
                      </NegativeNodePredicateFilterQP>
                      <NegativeNodePredicateFilterQP uri="" name="#tmp56">
                        <ParentOfChildJoinQP>
                          <StepQP axis="parent-of-child" name="PolicyState" nodeType="element">
                            <UnionQP>
                              <ValueQP container="policyContainer.dbxml" index="node-element-equality-string" operation="eq" child="PolicyStatus" value="NON-PRE ENDORSEMENT QUOTE"/>
                              <ValueQP container="policyContainer.dbxml" index="node-element-equality-string" operation="eq" child="PolicyStatus" value="EXTENSION QUOTE"/>
                              <ValueQP container="policyContainer.dbxml" index="node-element-equality-string" operation="eq" child="PolicyStatus" value="ENDORSEMENT QUOTE"/>
                            </UnionQP>
                          </StepQP>
                          <BufferReferenceQP id="2"/>
                        </ParentOfChildJoinQP>
                        <ChildJoinQP>
                          <StepQP axis="child" name="PolicyState" nodeType="element">
                            <VariableQP name="#tmp56"/>
                          </StepQP>
                          <ValueQP container="policyContainer.dbxml" index="node-element-equality-string" operation="eq" child="IsLatest" value="true"/>
                        </ChildJoinQP>
                      </NegativeNodePredicateFilterQP>
                    </UnionQP>
                  </BufferQP>
                </QueryPlanToAST>
              </ForTuple>
              <QueryPlanToAST>
                <StepQP axis="child" name="PolicyState" nodeType="element">
                  <VariableQP name="policy"/>
                </StepQP>
              </QueryPlanToAST>
            </LetTuple>
            <QueryPlanToAST>
              <StepQP axis="child" name="PolicyHeader" nodeType="element">
                <VariableQP name="policy"/>
              </StepQP>
            </QueryPlanToAST>
          </LetTuple>
          <QueryPlanToAST>
            <StepQP axis="child" name="DataTableInfo" nodeType="element">
              <StepQP axis="child" name="DataTable" nodeType="element">
                <VariableQP name="policy"/>
              </StepQP>
            </StepQP>
          </QueryPlanToAST>
        </LetTuple>
        <DOMConstructor type="element">
          <Name>
            <Sequence>
              <ATQNameConstructor uri="" prefix="" localname="policyDetail" typeuri="http://www.w3.org/2001/XMLSchema" typename="QName"/>
            </Sequence>
          </Name>
          <Children>
            <ContentSequence>
              <QueryPlanToAST>
                <StepQP axis="child" name="SubmissionNumber" nodeType="element">
                  <VariableQP name="policy"/>
                </StepQP>
              </QueryPlanToAST>
            </ContentSequence>
            <ContentSequence>
              <Sequence>
                <AnyAtomicTypeConstructor value="," typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
              </Sequence>
            </ContentSequence>
            <ContentSequence>
              <QueryPlanToAST>
                <StepQP axis="child" name="DocumentNumber" nodeType="element">
                  <VariableQP name="policy"/>
                </StepQP>
              </QueryPlanToAST>
            </ContentSequence>
            <ContentSequence>
              <Sequence>
                <AnyAtomicTypeConstructor value="," typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
              </Sequence>
            </ContentSequence>
            <ContentSequence>
              <QueryPlanToAST>
                <StepQP axis="child" name="QuoteVersionNumber" nodeType="element">
                  <VariableQP name="policy"/>
                </StepQP>
              </QueryPlanToAST>
            </ContentSequence>
            <ContentSequence>
              <Sequence>
                <AnyAtomicTypeConstructor value="," typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
              </Sequence>
            </ContentSequence>
            <ContentSequence>
              <Parenthesized>
                <QueryPlanToAST>
                  <ChildJoinQP>
                    <VariableQP name="state"/>
                    <SequentialScanQP container="policyContainer.dbxml" nodeType="element"/>
                  </ChildJoinQP>
                </QueryPlanToAST>
                <QueryPlanToAST>
                  <StepQP axis="child" uri="*" name="*" nodeType="element">
                    <VariableQP name="header"/>
                  </StepQP>
                </QueryPlanToAST>
                <QueryPlanToAST>
                  <ChildJoinQP>
                    <VariableQP name="datatable"/>
                    <SequentialScanQP container="policyContainer.dbxml" nodeType="element"/>
                  </ChildJoinQP>
                </QueryPlanToAST>
              </Parenthesized>
            </ContentSequence>
          </Children>
        </DOMConstructor>
      </Return>
    </XQuery>

    The good news is that your indexes are being used (anywhere in the query plan where you see index="node-element-equality-string"), the bad news is that the entire policyContainer is being scanned several times (<SequentialScanQP container="policyContainer.dbxml" nodeType="element"/>). Your best bet is to upgrade to dbxml-2.5.16, since that has several improvements to the optimizer that should optimize away those scans. Failing that, use the shell command (dbxml) to add and remove indexes and see how that changes the query plan and speed. The following line is what is causing the scans:
    {$state/*,$header/*,$datatable/*}So add indexes that will help to locate those nodes, or change that line so that the query is faster.
    Lauren Foutz

  • Performance tuning of query

    SELECT * FROM
    FROM contracts a
    WHERE a.start_date > TO_DATE ('12/01/2009', 'mm/dd/yyyy')
    AND a.contracts_type IN ('C1','C2','C3','C4','C5','C6','C7','C8','C9','C10')
    explain plan gives the below details
    Cost: 1,351,083 Bytes: 49,313,352 Cardinality: 2,241,516
    how to tune the query

    Please read these.
    How to post a tuning request:
    HOW TO: Post a SQL statement tuning request - template posting
    When your query takes too long:
    When your query takes too long ...

  • Peformance tuning of query using bitmap indexes

    Hello guys
    I just have a quick question about tuning the performance of sql query using bitmap indexes..
    Currently, there are 2 tables, date and fact. Fact table has about 1 billion row and date dim has about 1 million. These 2 tables are joined by 2 columns:
    Date.Dateid = Fact.snapshot.dates and Date.companyid = fact.companynumber
    I have query that needs to be run as the following:
    Select dates.dayofweek, dates,dates, fact.opened_amount from dates, facts
    where Date.Dateid = Fact.snapshot.dates and Date.companyid = fact.companynumber and dates.dayofweek = 'monday'.
    Currently this query is running forever. I think it is joining that takes a lot of time. I have created bitmap index on dayofweek column because it's low on distinctive rows. But it didn't seem to speed up with the performance..
    I'd like to know what other indexes will be helpful for me.. I am thinking of creating another one for companynumber since it also have low distinctive records.
    Currently the query is being generated by frontend tools like OBIEE so I can't change the sql nor can't I purge data or create smaller table, I have to what with what I have..
    So please let me know your thoughts in terms of performance tunings.
    Thanks

    The explain plan is:
    Row cost Bytes
    Select statement optimizer 1 1
    nested loops 1 1 299
    partition list all 1 0 266
    index full scan RD_T.PK_FACTS_SNPSH 1 0 266
    TABLE ACCESS BY INDEX ROWID DATES_DIM 1 1 33
    INDEX UNIQUE SCAN DATES_DIM_DATE 1 1
    There is no changes nor wait states, but query is taking 18 mins to return results. When it does, it returns 1 billion rows, which is the same number of rows of the fact table....(strange?)That's not a bitmap plan. Plans using bitmaps should have steps indicating bitmap conversions; this plan is listing ordinary btree index access. The rows and bytes on the plan for the volume of data you suggested have to be incorrect. (1 row instead of 1B?????)
    What version of the data base are you using?
    What is your partition key?
    Are the partioned table indexes global or local? Is the partition key part of the join columns, and is it indexed?
    Analyze the tables and all indexes (use dbms_stats) and see if the statistics get better. If that doesn't work try the dynamic sampling hint (there is some overhead for this) to get statistics at runtime.
    I have seen stats like the ones you listed appear in 10g myself.
    Edited by: riedelme on Oct 30, 2009 10:37 AM

Maybe you are looking for

  • Multipage pdf in photoshop cs5

    Hi out there! I've upgraded from PS CS2 to CS5 - now I'm missing the option to compile multipaged pdf out from PS. I know for sure that bridge will compile psd's to one single pdf but bridge seems not to embed fonts used in a psd. And yes, I know tha

  • Windows not closing in safari

    whenever I use safari and try to close a window, the red x button does not work. What can I do? Please HELP ME!!!!! ibook g4   Mac OS X (10.4.5)  

  • "Scale to fit paper size" ......doesn't

    It's often convenient to scale a web page down to fit the entire page on letter size. This is doable with the Scale field in the print dialog box. On the other hand, I can't get Paper Handling>"Scale to fit paper size" to work in Safari. It works in

  • Is photoshop CS6 multi user??

    I bought and installed Photoshop CS6 onto my computer at work. My boss wants to know if it is multi user so we can install it onto our server.. is there any way to tell?

  • Red eye - Blue eye?

    The red-eye feature makes my eyes dark, almost black. Problem is, here where I live we all have blue eyes, and editing to dark black eyes looks strange when you infact have light blue eyes. Can this be changed? All tips are appreciated! Macbook   Mac