Skip to Main Content
  • Questions
  • change running code's execution plan

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Anubha.

Asked: October 12, 2016 - 11:42 am UTC

Last updated: October 13, 2016 - 9:29 am UTC

Version: oracle11gR2

Viewed 1000+ times

You Asked

Hi Tom,

Suppose a package is executing in prod environment, currently proc A is running and after that Proc B will be executed in next 45 mins.
I have just spotted some problems in proc B execution plan(which was generated earlier). I cant change the code in 45 mins, as it is in production env. I cant touch related tables and index also.(no. of records are same as previous execution).
But I don't want oracle to pick the previous plan.
What can I do to change the execution plan.

Is there any way I can make the related stats stale?

Thanks in advance :)
--Anubha

and Connor said...

You could try purging the statement from the shared pool

https://blogs.oracle.com/mandalika/entry/oracle_rdbms_flushing_a_single


Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Incase of multiple child cursors

Rajeshwaran, Jeyabal, October 13, 2016 - 7:48 am UTC

Incase of sqlid having multiple child cursors, any option available there to flush a particular "child cursor" ?

demo@ORA11G> create table t as
  2  select a.*, decode(rownum,1,1,99) id
  3  from all_objects a;

Table created.

demo@ORA11G> create index t_idx on t(id);

Index created.

demo@ORA11G> begin
  2     dbms_stats.gather_table_stats(user,'T',
  3             estimate_percent=>100,
  4             method_opt=>'for all indexed columns size 2',
  5             cascade=>true);
  6  end;
  7  /

PL/SQL procedure successfully completed.

demo@ORA11G> variable x number
demo@ORA11G> exec :x := 1;

PL/SQL procedure successfully completed.

demo@ORA11G> select max(object_id) from t where id=:x;

MAX(OBJECT_ID)
--------------
            20

1 row selected.

demo@ORA11G> select * from table(dbms_xplan.display_cursor);

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
SQL_ID  3ggtvprg4js0q, child number 0
-------------------------------------
select max(object_id) from t where id=:x

Plan hash value: 1789076273

--------------------------------------------------------------------------------------
| Id  | Operation                    | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT             |       |       |       |     2 (100)|          |
|   1 |  SORT AGGREGATE              |       |     1 |    16 |            |          |
|   2 |   TABLE ACCESS BY INDEX ROWID| T     |     1 |    16 |     2   (0)| 00:00:01 |
|*  3 |    INDEX RANGE SCAN          | T_IDX |     1 |       |     1   (0)| 00:00:01 |
--------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   3 - access("ID"=:X)


20 rows selected.

demo@ORA11G> exec :x := 99;

PL/SQL procedure successfully completed.

demo@ORA11G> select max(object_id) from t where id=:x;

MAX(OBJECT_ID)
--------------
        107246

1 row selected.

demo@ORA11G> select * from table(dbms_xplan.display_cursor);

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
SQL_ID  3ggtvprg4js0q, child number 0
-------------------------------------
select max(object_id) from t where id=:x

Plan hash value: 1789076273

--------------------------------------------------------------------------------------
| Id  | Operation                    | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT             |       |       |       |     2 (100)|          |
|   1 |  SORT AGGREGATE              |       |     1 |    16 |            |          |
|   2 |   TABLE ACCESS BY INDEX ROWID| T     |     1 |    16 |     2   (0)| 00:00:01 |
|*  3 |    INDEX RANGE SCAN          | T_IDX |     1 |       |     1   (0)| 00:00:01 |
--------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   3 - access("ID"=:X)


20 rows selected.

demo@ORA11G> select max(object_id) from t where id=:x;

MAX(OBJECT_ID)
--------------
        107246

1 row selected.

demo@ORA11G> select * from table(dbms_xplan.display_cursor);

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
SQL_ID  3ggtvprg4js0q, child number 1
-------------------------------------
select max(object_id) from t where id=:x

Plan hash value: 2966233522

---------------------------------------------------------------------------
| Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |      |       |       |   667 (100)|          |
|   1 |  SORT AGGREGATE    |      |     1 |    16 |            |          |
|*  2 |   TABLE ACCESS FULL| T    | 84858 |  1325K|   667   (4)| 00:00:01 |
---------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - filter("ID"=:X)


19 rows selected.

demo@ORA11G> select address,hash_value from v$sqlarea where sql_id='3ggtvprg4js0q';

ADDRESS          HASH_VALUE
---------------- ----------
000007FF0A7BCE50 3729317910

1 row selected.

demo@ORA11G> exec sys.dbms_shared_pool.purge(name=>'000007FF0A7BCE50,3729317910',flag=>'c');

PL/SQL procedure successfully completed.

demo@ORA11G> select address,hash_value from v$sqlarea where sql_id='3ggtvprg4js0q';

no rows selected

demo@ORA11G>

Connor McDonald
October 13, 2016 - 9:29 am UTC

I dont think so

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library