How to optimize the slow SQL Execution caused by converting B-tree indexes into BITMAP indexes (BITMAP CONVERSION)

Source: Internet
Author: User

At Oracle 9i or above, Oracle sometimes chooses to convert the B-Tree index to BITMAP for SQL Execution, resulting in an extremely bad execution plan.

The conversion is determined by the hidden parameter _ B _tree_bitmap_plans. If this parameter is set to true, it is converted. Otherwise, no conversion is performed. In 8i, the default value of this parameter is false,

Therefore, only when a bitmap index exists will the B-tree index be converted to bitmap; and In 9i, if this parameter is set to true by default, any index may be performed.

Bitmap conversion.

 

There are two solutions:

1. Disable converting B-tree indexes to Bitmap indexes by adjusting the _ B _tree_bitmap_plans Parameter

 

Alter system set "_ B _tree_bitmap_plans" = false;

Select Name, Value From v $ parameter Where Name = '_ B _tree_bitmap_plans'

 

In bitmap conversion from/to rowids is the execution plan after bitmap conversion:

In the customer's database system, once this SQL statement executes bitmap conversion, the execution time will be extended to about 50 seconds, and a single process will occupy 100% of the CPU resources, and switch is disabled, the CPU resource usage is normal and can be completed in 40 milliseconds.

SQL> alter session set "_ B _tree_bitmap_plans" = false;
Session altered.
Elapsed: 00:00:00. 01
SQL> @ SQL
COUNT (DISTINCTTAB2.WFID)
------------------------
708
Elapsed: 00:00:00. 41
SQL> alter session set "_ B _tree_bitmap_plans" = true;
Session altered.
Elapsed: 00:00:00. 00
SQL> @ SQL
COUNT (DISTINCTTAB2.WFID)
------------------------
708

Elapsed: 00:00:52. 80

Finally, set the global implicit parameter _ B _tree_bitmap_plans to disable bitmap conversion.

2. Execute the package begin dbms_stats.gather_table_stats ('user', 'table name'); END; Re-calculate the table information 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.