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

  • 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.

主站蜘蛛池模板: 邵东县| 新安县| 玛多县| 竹北市| 澄城县| 应城市| 鄂托克前旗| 阿巴嘎旗| 犍为县| 浑源县| 庆云县| 南木林县| 闽侯县| 射洪县| 成安县| 祁门县| 汕尾市| 特克斯县| 搜索| 唐河县| 瑞丽市| 闽侯县| 新田县| 礼泉县| 桑日县| 康定县| 英德市| 邵阳县| 临高县| 四子王旗| 安泽县| 杭锦后旗| 巴彦淖尔市| 开原市| 山东| 陆丰市| 台州市| 隆德县| 荣昌县| 岱山县| 千阳县|