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

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.

主站蜘蛛池模板: 浙江省| 安阳市| 宾川县| 绥化市| 大同市| 和硕县| 海安县| 远安县| 锡林郭勒盟| 湾仔区| 韶山市| 凤台县| 盐池县| 德化县| 青海省| 蒙阴县| 灵山县| 湘西| 盘山县| 枣庄市| 旺苍县| 加查县| 南木林县| 山西省| 凌源市| 怀集县| 海晏县| 涪陵区| 恭城| 化德县| 颍上县| 杭锦旗| 祁门县| 杭锦后旗| 福建省| 土默特右旗| 武宣县| 庆云县| 平顺县| 尚志市| 麻阳|