A simple example shows Oracle's "selfless" robustness

Source: Internet
Author: User

A simple example shows Oracle's "selfless" robustness

Oracle's strength lies in its ability to always help you choose the right execution plan, even if you give it wrong instructions.

Lab:

1. Create a test table:

Collect statistics:

Create a B-Tree Index: <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20141031/2014103109132018.png" alt = "\">

2. Execute select id from tbl_plan; to view its execution plan:

Because a B-tree index is created, the id value can be obtained from the index without full table scan. However, full table scan is used here.

Even if HINT is used, full table scan is still used:


The reason is that this is a B-tree index and does not store NULL values, although this table does not have NULL values. If you directly query records from a B-tree index that may contain NULL values, the NULL value is not stored in the index, and some records are missing, the query results will be wrong, therefore, Oracle does not choose to use index scanning, but instead performs full table scanning..

3. Set the id field to non-empty:

This is equivalent to a unique index.

Then execute select id from tbl_plan ;:

Oracle chooses fast and full index scanning. Because id is an index field, it is the fastest way to obtain the value directly from the index.

If the HINT method is used:

Oracle allows the use of HINT.

Summary:

From the simple example above, Oracle will always help you select the correct execution plan. Even if you give the wrong information to Oracle, Oracle's "selfless" spirit deserves our learning, if our application system is robust enough, it would be better.

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.