what are different optimizer modes

 OPTIMIZER_MODE:

If you have a large table with millions of rows and you want to retrieve all the rows, you should set the OPTIMIZER_MODE parameter to "ALL_ROWS". For example:


SELECT * FROM large_table

WHERE condition = value

ORDER BY column_name;


If you want to retrieve a small number of rows quickly, you should set the OPTIMIZER_MODE parameter to "FIRST_ROWS". For example:


SELECT /*+ FIRST_ROWS */ column1, column2

FROM small_table

WHERE condition = value

ORDER BY column_name;


If you want to retrieve a specific number of rows quickly, you should set the OPTIMIZER_MODE parameter to "FIRST_ROWS_N". For example:


SELECT /*+ FIRST_ROWS(n) */ column1, column2

FROM small_table

WHERE condition = value

ORDER BY column_name;


OPTIMIZER_INDEX_COST_ADJ:

If you want to encourage the optimizer to use an index, you can set the OPTIMIZER_INDEX_COST_ADJ parameter to a higher value. For example:


ALTER SESSION SET OPTIMIZER_INDEX_COST_ADJ = 100;


If you want to discourage the optimizer from using an index, you can set the OPTIMIZER_INDEX_COST_ADJ parameter to a lower value. For example:


ALTER SESSION SET OPTIMIZER_INDEX_COST_ADJ = 10;


OPTIMIZER_INDEX_CACHING:

If you want the optimizer to cache more index data in memory, you can set the OPTIMIZER_INDEX_CACHING parameter to a higher value. For example:


ALTER SESSION SET OPTIMIZER_INDEX_CACHING = 90;


If you want the optimizer to cache less index data in memory, you can set the OPTIMIZER_INDEX_CACHING parameter to a lower value. For example:


ALTER SESSION SET OPTIMIZER_INDEX_CACHING = 50;


OPTIMIZER_DYNAMIC_SAMPLING:

If you want the optimizer to sample more data to estimate selectivity, you can set the OPTIMIZER_DYNAMIC_SAMPLING parameter to a higher value. For example:


ALTER SESSION SET OPTIMIZER_DYNAMIC_SAMPLING = 4;


If you want the optimizer to sample less data to estimate selectivity, you can set the OPTIMIZER_DYNAMIC_SAMPLING parameter to a lower value. For example:


ALTER SESSION SET OPTIMIZER_DYNAMIC_SAMPLING = 1;


eg:


If you want to encourage the optimizer to use an index, you can set the OPTIMIZER_INDEX_COST_ADJ parameter to a higher value. For example:


ALTER SESSION SET OPTIMIZER_INDEX_COST_ADJ = 100;


If you want to discourage the optimizer from using an index, you can set the OPTIMIZER_INDEX_COST_ADJ parameter to a lower value. For example:


ALTER SESSION SET OPTIMIZER_INDEX_COST_ADJ = 10;

Sure, I'd be happy to explain this parameter further and give an example.


The OPTIMIZER_INDEX_COST_ADJ parameter is used to control how much the optimizer values the use of an index. The optimizer calculates the cost of different execution plans and chooses the one with the lowest cost. If an index is used in the execution plan, the optimizer will assign a cost to that index usage.


By setting the OPTIMIZER_INDEX_COST_ADJ parameter to a higher value, you are telling the optimizer to place more importance on the use of an index when calculating the cost of different execution plans. This means that the optimizer will be more likely to choose a plan that uses an index, even if it is not the lowest-cost option.


On the other hand, if you set the OPTIMIZER_INDEX_COST_ADJ parameter to a lower value, you are telling the optimizer to place less importance on the use of an index when calculating the cost of different execution plans. This means that the optimizer will be less likely to choose a plan that uses an index, even if it is the lowest-cost option.


For example, let's say you have a table with a large number of rows, and you want to run a query that selects a small subset of those rows based on a specific column. You know that there is an index on that column and you want the optimizer to use it. You can set the OPTIMIZER_INDEX_COST_ADJ parameter to a higher value to encourage the optimizer to choose a plan that uses the index, like this:


ALTER SESSION SET OPTIMIZER_INDEX_COST_ADJ = 100;


On the other hand, if you know that the index is not selective enough, or there is some other reason why using the index would result in a slower query, you can set the OPTIMIZER_INDEX_COST_ADJ parameter to a lower value to discourage the optimizer from using it, like this:


ALTER SESSION SET OPTIMIZER_INDEX_COST_ADJ = 10;


Comments

Popular posts from this blog

Understanding Terraform

How to make CRS and ASM not to restart after server reboot

How to repair ASM disk header