What happens when a SQL Query runs?

Source: Internet
Author: User

Posted by PADMA Chitturi in Uncategorized. Leave a Comment

Hi Folks,

It had been such a long time that I had written on SQL Server. Let's go for a trip on SQL architecture and few things which really might interest us.

Every one of us write queries and expect SQL to return results within no time. Had any of us questioned yourself, what's the mechanism inside SQL is serving the requests of users and making us hap PY!!

Well, let's see the architecture of SQL and what it behaves when we submit a query.

SQL Server Architecture and Life Cycle of a Query:

The above picture clearly depicts this SQL engine is split into the main engines:relational engine and Storage engine.

The relational engine is a query processor as its functionality is query optimization and execution. Confused with the words optimization and execution? Don ' t worry, would discuss on that.

Storage engine, haven name itself indicates that it's for managing SQL Server memory.

Buffer Pool: This is the major component as it holds the SQL Server memory. The buffer pool contains plan cache and data cache. Plan Cache is the one which is the storage area for execution plans and data cache holds the data.

What happens when we submit SELECT query?

SNI (SQL Server Network interface): When we submit a query, we is actually interacting with the SQL engine, which means that some connection have been ES tablished between client (user) and server to has communication. SNI is a protocol layer which establishes connection between client and server. The connection is responsible for sending requests and receiving data.

Command Parser: This component in relational engine checks the syntax of the query and returns any errors that would reach the client Via protocol layer. If The syntax is correct, query plan would be generated and would be checked against the plan cache. If The plan already exists in plan cache, it'll be reused. However, if it's not found, query tree would is generated (each node in the tree represents operation to be preformed) and This is passed as input to query optimizer.

Optimizer: It's the major component in SQL. It finds out multiple ways-to-execute a query and finds out of the best plan (with low cost and that would take less time to Execute). Finding out the efficient plan brings out the capability of optimizer.

Query Executor: The name itself is self-explanatory. IT executes the query plan i.e executes each step on the plan, interacts with storage engine to retrieve/modify data.

In order to access data, query executor interacts with storage engine via OLE DB to access methods.

Access Methods: It contains several methods to retrieve the data. This actually sends the request to Buffer manager.

Buffer Manager: It manages the buffer pool. If Some records need to be fetched, buffer Manager checks data cache and the data pages is already cached, they would be Fetched and passed back to access methods. If The data pages is not cached, they would is read from the disk, put it in data cache and then the results would be pas Sed to access methods.

Transaction Manager: This has the major Components-lock manager and Log Manager. The Lock Manager provides concurrency to the data and maintains isolation levels.  The Log Manager writes the changes to the transaction Log. As and when we hear about log and lock manager we would is landing up with many questions. let's take a break here and has a deep dive if I write about transaction logs and isolation levels.

What happens when a SQL Query runs?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.