What happens when a SQL Query runs?
Posted by Padma Chitturi in Uncategorized. Leave a Comment
Hi Folks,
It has been such a long time that I have 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 that is serving the requests of users and making us happy !!
Well, let’s see the architecture of SQL and how it behaves when we submit a query.
SQL Server Architecture and Life Cycle of a Query:

The above picture clearly depicts that SQL Engine is split into two main engines: Relational Engine and Storage Engine.
The Relational engine is query processor as its functionality is query optimization and execution. Confused with the words optimization and execution ? Don’t worry, will discuss on that.
Storage engine– the name itself indicates that it is 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 are actually interacting with the SQL engine, which means that some connection has been established between client (user) and server to have 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 will be generated and will be checked against the plan cache. If the plan already exists in plan cache, it will be reused. However, if it’s not found, query tree would be generated (each node in the tree represents operation to be preformed) and this will be passed as input to query optimizer.
Optimizer: It is the major component in SQL. It finds out multiple ways to execute a query and finds out 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 in the plan, interacts with storage engine to retrieve/modify data.
In order to access data, query executor interacts with storage engine via OLEDB 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 are already cached, they would be fetched and passed back to access methods. If the data pages are not cached, they would be read from the disk, put it on data cache and then the results would be passed to access methods.
Transaction Manager: This has two 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 be landing up with many questions. Let’s take a break here and have deep dive when I write about transaction logs and isolation levels.
What happens when a SQL Query runs?的更多相关文章
- jstl中的sql:query标签获取的结果如何格式化输出
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- .net连接DB2的异常SQL0666 - SQL query exceeds specified time limit or storage limit.错误处理
SQL0666 - SQL query exceeds specified time limit or storage limit. 原因:查询超时 解决办法: set the DbCommand.C ...
- NHibernate系列文章二十六:NHibernate查询之SQL Query查询(附程序下载)
摘要 NHibernate在很早的版本就提供了SQL Query(原生SQL查询),对于很复杂的查询,如果使用其他的查询方式实现比较困难的时候,一般使用SQL Query.使用SQL Query是基于 ...
- Freebie - Utility Form: Generate Excel Report From SQL Query In Oracle Forms 6i And 11g
Sharing a form to generate Excel file report from SQL query in Oracle Forms. This form can be used i ...
- jasper ireport create a report with parameters without sql query
I'm new in jasper ireport , and I want to know if it is possible to create a report only with static ...
- 使用JSTL的sql:query标签制作分页查询遇到NoSuchFieldError: deferredExpression
参考:http://hi.baidu.com/desyle/item/4fe650265792d7182a0f1c33 症状: 如题所述,代码如下 <sql:query var="re ...
- REP-20147 Cannot implement column link for this detail SQL query. Converting to group link.
注:本文为原创,作为学习交流使用,转载请标明作者及出处,作者保留追究法律责任的权力. Lumen Su lzsu1989#gmail.com (#=@) www.cnblogs.com/lzsu198 ...
- EntityFramework 学习 一 Execute Native SQL Query
SQL query for entity types: using (var ctx = new SchoolDBEntities()) { var studentList = ctx.Student ...
- Entity Framework Tutorial Basics(39):Raw SQL Query
Execute Native SQL Query You can execute native raw SQL query against the database using DBContext. ...
随机推荐
- git - 使用原理
对git操作最大的功臣就是.git目录下的HEAD HEAD是什么 HEAD其实是一个类似于指针的东西,只不过这个指针的含义是指向当前的分支,当你再[ git checkout 分支 ] 的时候这个分 ...
- 解决Mac开机变慢 command +option + P + R
Mac开机变慢怎么办? command +option + P + R 重点是 开机 后 一直按 该4个键不放 听到3声音响 屏幕出现灰暗灰暗几次 开机速度 5s 重置PRAM和NVRAM的方法都是 ...
- [New learn]GCD的基本使用
https://github.com/xufeng79x/GCDDemo 1.简介 介绍GCD的使用,介绍多种队列与同步异步多种情况下的组合运行情况. 2.基本使用步骤 如果使用GCD则一般也就两个步 ...
- 去掉a标签的虚线框,避免出现奇怪的选中区域
a{blr:expression(this.onFocus=this.blur())}/*去掉a标签的虚线框,避免出现奇怪的选中区域*/
- LeetCode239. Sliding Window Maximum
Given an array nums, there is a sliding window of size k which is moving from the very left of the a ...
- LeetCode解题报告—— Group Anagrams & Pow(x, n) & Spiral Matrix
1. Group Anagrams Given an array of strings, group anagrams together. For example, given: ["eat ...
- 如何修改wordpress的.po和.mo配置文件
如果我们在定制个性化WP模版时,若要修改默认语言包中文字描述,则可以通过修改zh_CN.mo和zh_CN.po来实现,但mo文件是不能直接修改编辑,因此就只能修改po文件了,po文件不能通过我们常用的 ...
- sql中where和having的区别
“Where” 是一个约束声明,使用Where来约束来自数据库的数据,Where是在结果返回之前起作用的,且Where中不能使用聚合函数. “Having”是一个过滤声明,是在查询返回结果集以后对查询 ...
- vue分页tbale小荔枝
首先,动态加载数据 <table class="table table-bordered table-condensed no_margin_bottom jyjg_tab" ...
- 深入了解HTTP协议
1.HTTP协议简介 超文本传输协议(HTTP,HyperText Transfer Protocol)是互联网上应用最为广泛的一种网络协议.所有的WWW文件都必须遵守这个标准. 1.1背景 设计HT ...