A simple demo example to look at Oracle's "selfless" robustness

Source: Internet
Author: User

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


Experiment:

1. Create a frequently :

Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvymlzyww=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70 /gravity/center ">


Collect statistics:


To create a B-Tree index:


2. Run the Select ID from Tbl_plan; View its run schedule :

Because the B-tree index is created, it is normal to be able 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.

assume that you query a record directly from a B-tree index that might include a null value. Null values are not stored in the index. Will leak some records, then the query results will be wrong, so Oracle does not choose to use the index scan, but the full table scan .


3. Set the ID field to non-null :

Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvymlzyww=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70 /gravity/center ">

This is the equivalent of a unique index.


Run the Select ID again from Tbl_plan;:

Oracle chooses an index high-speed full scan, which is the fastest way to get a value directly from the index because the ID is an indexed field.


The assumption is that the hint method is used:

This is an index full scan, not as high-speed full scan, but at least hint played a role. The reason is that getting a value from a non-empty index is a reliable way. Oracle therefore agrees to the use of hint .


Summary :

You can see it from the Simple demo sample above. Oracle will always help you choose the right plan for your operation, even if you give the wrong information to Oracle. Oracle's "Selfless" spirit is worth learning. Let's say that our application system is strong enough, that's better.

A simple demo example to look 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.