[SQL Basics] Indexes
An index is used to speed up searching in the database.
By default, when you create this table, your data will be stored on disk and sorted by the "Id" primary key column. This default sort is called the "Clustered Index".
- Affects the physical order of data so there can only one clustered index.
With a clustered index the rows are stored physically on the disk in the same order as the index. There can therefore be only one clustered index.
But if you search by other non-primary key columns most of the time on this table, then you might want to consider changing the clustered index to this column instead.
There a few things to keep in mind when changing the default clustered index in a table:
- Lookups from non-clustered indexes must look up the query pointer in the clustered index to get the pointer to the actual data records instead of going directly to the data on disk (usually this performance hit is negligble).
- Inserts will be slower because the insert must be added in the exact right place in the clustered index. (NOTE: This does not re-order the data pages. It just inserts the record in the correct order in the page that it corresponds to. Data pages are stored as doubly-linked lists so each page is pointed to by the previous and next. Therefore, it is not important to reorder the pages, just their pointers and that is only in the case where the newly inserted row causes a new data page to be created.)
Non-clustered indexes are not copies of the table but a sorting of the columns you specify that "point" back to the data pages in the clustered index. With a non clustered index there is a second list that has pointers to the physical rows. You can have many non clustered indexes, although each new index will increase the time it takes to write new records.
It is generally faster to read from a clustered index if you want to get back all the columns. You do not have to go first to the index and then to the table.
Writing to a table with a clustered index can be slower, if there is a need to rearrange the data.
小总:Clustered index意思是在选取某个column A,以它排序来存储table里的所有records,所以当你以A为选择条件来做query的时候,因为physically records locate in the same order as the index,通过clustered index可以很快找到符合条件的records。
Non-clustered index意思是比如还是column A,index会存储A的值以及a pointer to the in the table where that value is actually stored.而clusterd index会在leaf node里存储整条record。所以clustered index会更快。
[SQL Basics] Indexes的更多相关文章
- Some SQL basics
1, Index An index is a set of data pointers stored on disk associated with a single table. The main ...
- Azure SQL Database (19) Stretch Database 概览
<Windows Azure Platform 系列文章目录> Azure SQL Database (19) Stretch Database 概览 Azure SQL Da ...
- SQL Server 堆表行存储大小(Record Size)
一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 堆表行记录存储格式(Heap) 案例分析(Case) 参考文献(References) 二.背 ...
- 【译】SQL Server索引进阶第八篇:唯一索引
原文:[译]SQL Server索引进阶第八篇:唯一索引 索引设计是数据库设计中比较重要的一个环节,对数据库的性能其中至关重要的作用,但是索引的设计却又不是那么容易的事情,性能也不是那么轻易就 ...
- SQL Server索引进阶:第十级,索引内部结构
原文地址: Stairway to SQL Server Indexes: Level 10,Index Internal Structure 本文是SQL Server索引进阶系列(Stairway ...
- SQL Server索引进阶:第九级,读懂执行计划
原文地址: Stairway to SQL Server Indexes: Level 9,Reading Query Plans 本文是SQL Server索引进阶系列(Stairway to SQ ...
- SQL Server索引进阶:第八级,唯一索引
原文地址: Stairway to SQL Server Indexes: Level 8,Unique Indexes 本文是SQL Server索引进阶系列(Stairway to SQL Ser ...
- SQL Server索引进阶:第七级,过滤的索引
原文地址: Stairway to SQL Server Indexes: Level 7,Filtered Indexes 本文是SQL Server索引进阶系列(Stairway to SQL S ...
- SQL Server索引进阶:第六级,标签
原文地址: Stairway to SQL Server Indexes: Level 6,Bookmarks 本文是SQL Server索引进阶系列(Stairway to SQL Server I ...
随机推荐
- js中cookie的使用
js中并没有封装好的存储cookie,取得cookie和删除cookie的函数,所以必须得自己手动处理,并且cookie中也只能存储字符串,不能存储数组等复杂的数据类型. // 添加cookie fu ...
- python 学习笔记十三 JQuery(进阶篇)
jQuery 是一个 JavaScript 库. jQuery 极大地简化了 JavaScript 编程. 安装jQuery 有两个版本的 jQuery 可供下载: Production versio ...
- MySQL安装(转)
本文介绍MySQL的安装 可以单独阅读,也可以作为PHP环境搭建的一部分 PHP完整配置信息请参考 http://www.cnblogs.com/azhe-style/articles/php_env ...
- javascript 去掉空格之后的字符 正则表达式
从后端数据库读取时间时,经常会把整个日期年月日包括时分秒都取到,如2015-1-28 14:56:00,但是一般的我们只需要前面的年月日就行了.一个简单的方法,直接用split(" &quo ...
- linux复习
linux的特点 - 免费的/开源 - 支持多线程/多用户 - 安全性好 - 对内存和文件管理优越 关机命令 ...
- 基于Jquery、JqueryUI插件编写
刚开始编写jquery插件的时候,只是从网上找个模板看着写,并不理解.刚刚仔细把官网的API看了下,突然觉得豁然开朗了.马上放假了想着应该整理整理不然忘了又. How to create a Jque ...
- iOS开发 贝塞尔曲线UIBezierPath
最近项目中需要用到用贝塞尔曲线去绘制路径 ,然后往路径里面填充图片,找到这篇文章挺好,记录下来 自己学习! 转至 http://blog.csdn.net/guo_hongjun1611/articl ...
- Security » Authorization » 简单授权
Simple Authorization¶ 简单授权 82 of 86 people found this helpful Authorization in MVC is controlled thr ...
- 防止SVN冲突,Elipse资源同步介绍
灰色向右箭头: 本地修改了 灰色向右箭头且中间有白色减号: 本地删除了,服务器未删除 灰色向右且中间有个加号的箭头:本地比SVN上多出的文件 蓝色向左箭头:svn上修改过 蓝色向左且中间有个加号的箭头 ...
- Java Web基础:JSP基础概念
JSP介绍 JSP全称是Java Server Pages,它和Servlet都是Sun公司定义的用于开发动态Web资源的技术,它解决了Servlet输出流排版复杂和难以维护的问题.JSP完美融合了H ...