Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Tommy.

Asked: August 08, 2022 - 3:46 pm UTC

Last updated: August 10, 2022 - 1:34 am UTC

Version: 10g

Viewed 1000+ times

You Asked

We have a query against a view in production which used to run efficiently. However, recent explain plan showed some full table scan in one table which proper index and join with other table in the view.
We indexed the table but it does not seem to fix the issue.
We later locked the stats for that table, and explain plan was showing correct index scan.
Note that the table have new rows inserting every day.

I think locking table stats is not a permanent solution and I think rebuilding index should have updated the stats. So I am confused why it is like that.

and Connor said...

The current (ie 11g onwards) solution for this is "SQL Plan Management" which you unfortunately wont have in 10g.

But for 10g, you can use outlines to lock a plan into place, eg

create outline my_outline for category my_category
on select [your query]

alter session/system set query_rewrite_enabled=true;
alter session/system set use_stored_outlines=my_category;


Alternatively you could look at SQL Profiles which add a little more stats information to a query to assist the optimizer with making the correct decision

https://docs.oracle.com/database/121/TGSQL/tgsql_profiles.htm#TGSQL596




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

More to Explore

Performance

Get all the information about database performance in the Database Performance guide.