Oracle execution plan-all_rows and first_rows (n) optimizer Modes

Source: Internet
Author: User
0. Create an environment
SQL> create usertest identified by test  2 default tablespace users  3 temporary tablespace temp  4 quota unlimited on users;User created.SQL> grant createsession, resource, alter session to test;Grant succeeded.SQL> conntest/test;Connected.SQL> create tableemp(id number, name varchar2(10));Table created.SQL> insert intoemp values(100, 'tom');1 row created.SQL> insert intoemp values(200, 'mike');1 row created.SQL> insert intoemp values(300, 'jack');1 row created.SQL> insert intoemp values(400, 'rose');1 row created.SQL> commit;Commit complete.
1. Low data volume 1.1 first_rows_10
SQL> setautotrace traceonly;SQL> executedbms_stats.gather_table_stats('TEST', 'emp', cascade=>true);PL/SQL proceduresuccessfully completed.SQL> altersession set optimizer_mode=first_rows_10;Session altered.

1.2 all_rows
SQL> alter sessionset optimizer_mode=all_rows;Session altered.

1.3 Analysis

By comparing the above simple examples, we can see that there is no index in the table. When the data volume is small and the value is unique, the two modes have the same performance.

2. Low data volume
SQL> create indexemp_idx on emp(name);Index created.SQL> setautotrace offSQL> insert intoemp select * from emp;4 rows created.SQL> insert intoemp select * from emp;8 rows created.SQL> /16 rows created.SQL> /32 rows created.SQL> /64 rows created.SQL> /128 rows created.SQL> /256 rows created.SQL> /512 rows created.SQL> /1024 rows created.SQL> /2048 rows created.SQL> /4096 rows created.SQL> /8192 rows created.SQL> /16384 rows created.SQL> /32768 rows created.SQL> commit;Commit complete.SQL> executedbms_stats.gather_table_stats('TEST', 'emp', cascade=>true);PL/SQL proceduresuccessfully completed.

2.1 first_rows_10

SQL> setautotrace traceonlySQL> altersession set optimizer_mode=first_rows_10;Session altered.

2.2 all_rows
SQL> setautotrace traceonlySQL> altersession set optimizer_mode=all_rows;Session altered.

2.3 Analysis

We can see that fisrt_rows has gone through the index, which is obviously not an ideal result. all_rows has gone through the full table scan, and we can see that the cost is significantly lower.

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.