官术网_书友最值得收藏!

  • Learn T-SQL Querying
  • Pedro Lopes Pam Lahoud
  • 235字
  • 2021-06-24 14:38:16

The Trivial Plan stage

As mentioned in the Query optimization essentials section of Chapter 2Understanding Query Processing, SQL Server does cost-based optimization. But this has an expensive startup cost and so SQL Server will try to avoid this cost for simple queries that may only have one possible query execution plan.

The Trivial Plan stage generates plans for which there are no alternatives, and which require a cost-based decision. The following examples can be executed in the AdventureWorks sample database.

The following is a SELECT … INTO or INSERT INTO statement over a single table with no conditions:

SELECT NationalIDNumber, JobTitle, MaritalStatus
INTO HumanResources.Employee2
FROM HumanResources.Employee;

The preceding query produces the following execution plan:

The following is an INSERT INTO statement over a single table with a simple condition covered by an index:

INSERT INTO HumanResources.Employee2
SELECT NationalIDNumber, JobTitle, MaritalStatus
FROM HumanResources.Employee
WHERE BusinessEntityID < 10;

The preceding query  produces the following execution plan:

The following is aINSERT statement with a VALUES clause:

INSERT INTO HumanResources.Employee2
VALUES (87656896, 'CIO', 'M');

The preceding query  produces the following execution plan:

The information on the optimization level is stored in the execution plan under the Optimization Level property, with a value of TRIVIAL, as shown in the following screenshot:

The Trivial Plan stage typically finds very inexpensive query plans that are not affected by cardinality estimations.

主站蜘蛛池模板: 宝清县| 娱乐| 保定市| 安塞县| 吴桥县| 洛阳市| 洪雅县| 永福县| 舟山市| 合水县| 六枝特区| 昭平县| 汪清县| 宁安市| 沙田区| 安多县| 德保县| 星子县| 榆中县| 湘阴县| 嘉荫县| 城口县| 绍兴县| 合江县| 武山县| 双峰县| 陇西县| 多伦县| 溆浦县| 鄂州市| 崇文区| 吉首市| 石渠县| 正蓝旗| 远安县| 贵州省| 屏东县| 上杭县| 大邑县| 永福县| 大关县|