A simple example looks at Oracle's "selfless" robustness

Source: Internet
Author: User

The power of Oracle is that he can always help you choose the right execution plan , even if you give it the wrong instructions.


Experiment:

1. Create a test table :


Collect statistics:


To create a B-Tree index:


2. Execute select ID from Tbl_plan; view its execution plan :

Because the B-tree index is created, it is normal to get the value of the ID from the index without a full table scan, but the full table scan is used here.


Even with hint, this still uses a full table scan:



This is because this is a B-tree index and does not store null values, although this table does not have null values. If a record is queried directly from a B-tree index that may contain a null value, the null value is not stored in the index, and some records are omitted, so the query results are wrong, so Oracle does not choose to use an index scan, but a full table scan .


3. Set the ID field to non-null :

This is the equivalent of a unique index.


Re-execute Select ID from Tbl_plan;:

Oracle chooses an index fast full scan, because ID is an indexed field and getting values directly from the index is the quickest way.


If you are using the Hint method:

this uses an index full scan, as well as a fast full scan of the index, but at least hint plays a role because obtaining a value from a non-empty index is a reliable way, so Oracle allows the use of hint .


Summary :

As you can see from the simple example above, Oracle will always help you choose the right execution plan, even if you give the wrong information to oracle,oracle this "selfless" spirit is worth learning, if our application is strong enough, it would be better.

A simple example looks at Oracle's "selfless" robustness

Related Article

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.