Impact of statistical information on the Execution Plan (2)

Source: Internet
Author: User
Impact of statistical information on the Execution Plan (ii) Impact of statistical information in the previous article on the Execution Plan (I) demonstrate the impact of statistical information on the connection mode, this article will show you the impact of statistical information on single-table data acquisition methods. Execute the following code on the last test DB to create a test table and insert the data CHECK2_T3 (IDINT, COL1CHAR (800 ), COL2

Impact of statistical information on the Execution Plan (ii) Impact of statistical information in the previous article on the Execution Plan (I) demonstrate the impact of statistical information on the connection mode, this article will show you the impact of statistical information on single-table data acquisition methods. Execute the following code on the last test DB to create a test table and insert the data CHECK2_T3 (id int, COL1 CHAR (800), COL2

Impact of statistical information on the Execution Plan (2)

The impact of statistical information on the execution plan in the previous article (I) demonstrates the impact of statistical information on the connection mode. This article will show you the impact of statistical information on the data acquisition mode in a single table.

Run the following code on the last test database to create a test table and insert data.

CHECK2_T3 (id int, COL1 CHAR (800), COL2 INT, COL3 CHAR (5000), CHECK2_T3 ),

Then execute the following code to create a non-clustered index ON col1. we know that the related statistical information is automatically created when the index is created. WITH (STATISTICS_NORECOMPUTE = ON) disables automatic update of the statistical information.

NCIX_COL1 ON CHECK2_T3 (COL1) WITH (STATISTICS_NORECOMPUTE = ON) SHOW_STATISTICS (CHECK2_T3, NCIX_COL1)

Then execute the following SQL statement to check that the execution plan is indexed.

(COL2) FROM CHECK2_T3

Insert 30 million C records into the table. Because automatic update of statistics is disabled, the statistics remain unchanged.

CHECK2_T3 ,),

At this time, the number of records in C becomes 30 W +, and then execute the following two SQL statements. ② the SQL statements use the table prompt, server space, to allow the query to go through a full table scan, ① The Execution Plan is the same as the previous one. In this case, the overhead of the RID operator is quite high. The following two comparisons show the performance advantages of table scan.

In the following two statements, the test speed on my local machine is twice faster than ①. On the virtual host, pay attention to clearing the cache after multiple executions.

① ②

① The execution plan did not perform table scanning because we did not update the statistical information. We updated the statistical information and executed it again. ① We found that the execution plan changed to a table scan.

The demo is completed here.

In summary, compared with the effect of statistical information on the connection mode, the effect on the single-Table query mode is not so significant, because the changes in the table size have an effect on the operators before and after the statistics information is updated. As shown above, although table scanning improves efficiency, it still cannot be accepted by us. Hong Kong space, we hope it will be faster and it is best to avoid querying the original table data page, then you can include the COL2 field in the COL1 index, so that you can directly scan the index on the COL1 field to complete this query, just as the execution plan green prompt line "missing Index ". After this column index is created, the sq efficiency is greatly improved. You can enable statistics io to observe that the logical reads are greatly reduced.

In addition, the missing indexes prompted by sqlserver can improve the query efficiency. However, you should also understand that every index creation will reduce the system write efficiency, these are not discussed in this article. I will share some optimization methods and precautions in future special series.

Posted on

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.