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

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

主站蜘蛛池模板: 黔江区| 西畴县| 铁岭市| 应用必备| 太康县| 巩留县| 凤台县| 安陆市| 临夏县| 闸北区| 吉林市| 荆州市| 南川市| 台东县| 万安县| 沅陵县| 凤庆县| 武山县| 朝阳区| 尚义县| 呼和浩特市| 潮安县| 资源县| 济宁市| 牙克石市| 台山市| 调兵山市| 南漳县| 宁武县| 青铜峡市| 宜川县| 濮阳市| 青阳县| 英吉沙县| 西华县| 横山县| 临澧县| 比如县| 泰和县| 旺苍县| 宿松县|