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. ...
随机推荐
- 【模板】BZOJ 3781: 小B的询问 莫队算法
http://www.lydsy.com/JudgeOnline/problem.php?id=3781 N个数的序列,每次询问区间中每种数字出现次数的平方和,可以离线. 丢模板: #include ...
- hadoop中setOutputKeyClass和setOutputValueClass里类型
初学mapreduce programing,纠结一天的问题如下: job.setOutputKeyClass和job.setOutputValueClas在默认情况下是同时设置map阶段和reduc ...
- js-callee,call,apply概念
JS - caller,callee,call,apply 概念[转载] 在提到上述的概念之前,首先想说说javascript中函数的隐含参数:arguments Arguments : 该对象代表正 ...
- js刷新页面代码
第一种: location.reload() 第二种: location.replace(location.href) 第三种: history.go() 第四种: location=location ...
- opencv c++基本操作
常用操作 imread imread (char *filename, int flag=1); 第二个参数,int类型的flags,为载入标识,它指定一个加载图像的颜色类型.可以看到它自带缺省值1. ...
- 玩转RaspberryPi
step1:烧制树莓派内存卡 可以用[Linux系统烧制]http://www.williamsang.com/archives/1764.html 如果用windows烧制的话,就用Win32 Di ...
- python启停脚本的编写
先占个位置,打算记录一下启停python 的脚本start.sh,stop.sh的写法. 内容包括启动python脚本的方式,日志的重定向,获取进程id,以及杀掉进程. 参考文章: http://bl ...
- 微信小程序获取用户信息“授权失败”场景的处理
很多的时候我们在处理小程序功能的时候需要用户获取用户信息,但是呢为了信息安全,用户不授权导致授权失败场景:但是小程序第二次不在启动授权信息弹层,为了用户体验,可以用以下方式处理: function i ...
- APP线上问题收集信息整理
常话说“软件是不能保证百分百没有bug的”,因此当我们的APP上线之后,市场的使用人员会反馈一些我们测试人员可能在测试时遗漏的问题,包括也不防会有一些需求的反馈,这些问题均由售后人员反馈整理,以一种方 ...
- centos7 安装rlwrap
https://blog.csdn.net/zhjmozhi/article/details/78347216