Search code examples
oraclequery-optimization

Is optimizer_use_sql_plan_baselines and resource_manager_cpu_allocation oracle system parameter have impact on sql query performance


Is optimizer_use_sql_plan_baselines and resource_manager_cpu_allocation oracle system parameter have impact on sql query performance.

We have two envt suppose A and B. On A Envt query is running fine but in Envt. B its tacking time. I have compared system parameter and found difference in values in optimizer_use_sql_plan_baselines and resource_manager_cpu_allocation .


Solution

  • SQL plan baselines and the resource manager certainly could have a huge impact on performance, and you should use the below two queries or confirm or deny that those parameters are related to your problem.

    GV$SQL stores which SQL plan baseline is associated with each SQL statement. Compare the SQL_PLAN_BASELINE column in the below query, and if they are equal then your problem is not related to baselines:

    select sql_plan_baseline, round(elapsed_time/1000000) elapsed_seconds, gv$sql.*
    from gv$sql
    order by elapsed_time desc;
    

    The Active Session History (ASH) views can tell you if the resource manager is an issue. If your queries are being throttled then you will see an event named "resmgr:cpu quantum" in the below query. (But pay attention to the counts - don't troubleshoot a wait event if it only happens a small number of times.)

    select nvl(event, 'CPU') event, count(*)
    from gv$active_session_history
    group by event
    order by count(*) desc;
    

    Resource manager can have other potentially negative affects. If you're in a data warehouse, and using parallel queries, it's possible that resource manager has downgraded the queries on one system. If you're using parallel queries, try comparing the SQL monitoring reports from both systems:

    select dbms_sqltune.report_sql_monitor(sql_id => '&YOUR_SQL_ID') from dual;
    

    However, I have a feeling that you're using the wrong approach for your problem. There are generally two approaches to Oracle database performance - database tuning and query tuning. If you're only interested in a single query, then you should probably focus on things like the execution plan and the wait events for the operations of that specific query.