Database Reference
In-Depth Information
Parser
When a query is submitted, SQL Server passes it to the algebrizer within the relational engine . (This relational engine
is one of the two main parts of SQL Server data retrieval and manipulation, with the other being the storage engine ,
which is responsible for data access, modifications, and caching.) The relational engine takes care of parsing, name
and type resolution, and optimization. It also executes a query as per the query execution plan and requests data from
the storage engine.
The first part of the algebrizer process is the parser. The parser checks an incoming query, validating it for the
correct syntax. The query is terminated if a syntax error is detected. If multiple queries are submitted together as a
batch as follows (note the error in syntax), then the parser checks the complete batch together for syntax and cancels
the complete batch when it detects a syntax error. (Note that more than one syntax error may appear in a batch, but
the parser goes no further than the first one.)
CREATE TABLE dbo.Test1 (c1 INT);
INSERT INTO dbo.Test1
VALUES (1);
CEILEKT * FROM dbo.t1; --Error: I meant, SELECT * FROM t1
On validating a query for correct syntax, the parser generates an internal data structure called a parse tree for the
algebrizer. The parser and algebrizer taken together are called query compilation .
Binding
The parse tree generated by the parser is passed to the next part of the algebrizer for processing. The algebrizer now
resolves all the names of the different objects, meaning the tables, the columns, and so on, that are being referenced
in the T-SQL in a process called binding . It also identifies all the various data types being processed. It even checks for
the location of aggregates (such as GROUP BY and MAX ). The output of all these verifications and resolutions is a binary
set of data called a query processor tree .
To see this part of the algebrizer in action, if the following batch query is submitted, then the first three
statements before the error statement are executed, and the errant statement and the one after it are cancelled.
IF (SELECT OBJECT_ID('dbo.Test1')
) IS NOT NULL
DROP TABLE dbo.Test1;
GO
CREATE TABLE dbo.Test1 (c1 INT) ;
INSERT INTO dbo.Test1
VALUES (1);
SELECT 'Before Error',
c1
FROM dbo.Test1 AS t;
SELECT 'error',
c1
FROM dbo.no_Test1;
--Error: Table doesn't exist
SELECT 'after error' c1
FROM dbo.Test1 AS t;
 
Search WWH ::




Custom Search