Hi Eric,
The CBO determines the best plan by calculating an estimated COST for various execution plans and uses the plan with the lowest cost. To give CBO the most information (and the best chance of choosing a good execution plan) you should ANALYZE all tables to be queried. CBO works well for ad-hoc queries. For hard coded, repeated SQL statements, these should be tuned to obtain a repeatable optimal plan.
Any hint, except RULE, causes CBO to be used. It is very important to note that a HINT cannot be 'turned off' by any parameter settings.
As the optimzer evaulates the cost of each plan it compares it with the best cost plan seen so far. It keeps doing that until it gets to the best from the range of plans it considers. If the best plan selected is not the "ideal" plan based on the users knowledge of the data, the user can force a different plan by using "Hints".
In summary to make effective use of the CBO you should:
- Analyze all tables regularly.
- Set the required OPTIMIZER_GOAL (FIRST_ROWS or ALL_ROWS).
- Use hints to help direct the CBO where required.
- Use hints in PL/SQL to ensure the expected optimizer is used.
- Be careful with the use of bind variables.
Indira A
Never give up, Keep Trying