开发者

Oracle: Difference in execution plans between databases

开发者 https://www.devze.com 2022-12-28 04:32 出处:网络
I am comparing queries my development and production database. They are both Oracle 9i, but almost every single query has a completely different execution plan depending on the database.

I am comparing queries my development and production database.

They are both Oracle 9i, but almost every single query has a completely different execution plan depending on the database.

All tables/indexes are the same, but the dev database has about 1/10th the rows for each table.

On production, the query execution plan it picks for most queries is different from development, and the cost is somtimes 1000x higher. Queries on production also seem to be not using the correct indexes for queries in some cases (full table access).

I have ran dbms_utility.analyze schema on both databases recently as well in the hopes the CBO would figure something out.

Is there some other underlying oracle configuration that could be causing this?

I am a developer mostly so this kind of DBA analysis is开发者_Go百科 fairly confusing at first..


1) The first thing I would check is if the database parameters are equivalent across Prod and Dev. If one of the parameters that affects the decisions of the Cost Based Optimizer is different then all bets are off. You can see the parameter in v$parameter view;

2) Having up to date object statistics is great but keep in mind the large difference you pointed out - Dev has 10% of the rows of Prod. This rowcount is factored into how the CBO decides the best way to execute a query. Given the large difference in row counts I would not expect plans to be the same.

Depending on the circumstance the optimizer may choose to Full Table Scan a table with 20,000 rows (Dev)where it may decide an index is lower cost on the table that has 200,000 rows (Prod). (Numbers just for demonstration, the CBO uses costing algorighms for determining what to FTS and what to Index scan, not absolute values).

3) System statistics also factor into the explain plans. This is a set of statistics that represent CPU and disk i/o characteristics. If your hardware on both systems is different then I would expect your System Statistics to be different and this can affect the plans. Some good discussion from Jonathan Lewis here You can view system stats via the sys.aux_stats$ view.

Now I'm not sure why different plans are a bad thing for you... if stats are up to date and parameters set correctly you should be getting decent performance from either system no matter what the difference in size...

but it is possible to export statistics from your Prod system and load them into your Dev system. This make your Prod statistics available to your Dev database.

Check the Oracle documentation for the DBMS_STATS package, specifically the EXPORT_SCHEMA_STATS, EXPORT_SYSTEM_STATS, IMPORT_SCHEMA_STATS, IMPORT_SYSTEM_STATS procedures. Keep in mind you may need to disable the 10pm nightly statistics jobs on 10g/11g... or you can investigate Locking statistics after import so they are not updated by nightly jobs.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号