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

Query compilation essentials

The Query Processor is the component inside the SQL Server Database Engine that is responsible for compiling a query. In this section, we will focus on the highlighted sections of the following diagram, which handle query compilation:

The first stage of query processing is generally known as query compilation and includes a series of tasks that will eventually lead to the creation of a query plan. When an incoming T-SQL statement is parsed to perform syntax validations and ensure that it is correct T-SQL, a query hash value representing that statement as it was written is generated. If that query hash is already mapped to a cached query plan, it can just attempt to reuse that plan. However, if a query plan for the incoming query is not already found in the cache, query compilation proceeds with the following tasks:

  1. Perform binding, which is the process of verifying that the referenced tables and columns exist in the database schema.
  2. References to a view are replaced with the definition of that view. (This is called expanding the view.)
  3. Load metadata for the referenced tables and columns:
    1. The definition of tables, indexes, views, constraints, and so on that apply to the query
    2. Data distribution statistics on the applicable schema objects
  4. Verify whether data conversions are required for the query:
When the query-compilation process is complete, a structure that can be used by the Query Optimizer is produced, known as the algebrizer tree or query tree.

If the T-SQL statement is a Data Definition Language (DDL) statement, there's no possible optimization, and so a plan is produced and executed immediately. However, if the T-SQL statement is a Data Manipulation Language (DML) statement, SQL Server will move to an exploratory process known as query optimization.

主站蜘蛛池模板: 香河县| 安岳县| 滦南县| 香河县| 西和县| 正安县| 泸溪县| 正阳县| 沧州市| 白河县| 卢氏县| 丰台区| 旬邑县| 景德镇市| 兰西县| 甘谷县| 垫江县| 彭泽县| 曲水县| 东乌珠穆沁旗| 黄山市| 威宁| 灵璧县| 江川县| 贵南县| 吉林省| 梧州市| 独山县| 靖江市| 深圳市| 县级市| 庄河市| 凌海市| 凉山| 武强县| 繁峙县| 莫力| 万源市| 涪陵区| 兰溪市| 乾安县|