EntLib.com 专业电子商务平台

基于Microsoft .Net Framework / ASP.Net / C# / AJAX 平台构建的标准电子商务系统
随笔 - 99, 评论 - 74, 引用 - 0

Microsoft SQL Server 2008 All-in-One Desk Reference For Dummies 读书笔记之七

Microsoft SQL Server 2008 All-in-One Desk Reference For Dummies 读书笔记之七
 
SQL Server 2008是一个重大的产品版本,它推出了许多新的特性和关键的改进,使得它成为至今为止的最强大和最全面的 SQL Server 版本。《Microsoft SQL Server 2008 All-in-One Desk Reference For Dummies》包括了9本书,分别介绍了SQL Server 2008的一些特性和技术,内容图文并茂、非常直观、浅显易懂。本系列读书笔记分9篇,分别介绍每本书的一些值得关注的内容。
 
 
Book VII – Performance Tips and Tricks 性能调试及技巧
本节简单介绍了一些性能监控工具,如Windows 任务管理器、性能监视器、数据库引擎优化顾问(Database Engine Tuning Advisor)、以及SQL Server Profiler等等。这些都是DBA 优化和管理数据库的基本工具。
 
另外,介绍了如何使用索引(Index)来强化查询性能,分析了查询执行计划(Query Execution Plan)。其中,本节列举一些数据表的设计规范,如:
1. 总是定义主键值(Always define a primary key);
2. 避免前置通配符(Avoid leading wildcards);
3. 避免高度重复的索引值(Avoid highly duplicate indexes);
4. 不要忘记对临时表建立索引(Don’t forget to index temporary tables);
5. 在join列上建立索引(Place indexes on join columns);
 
下面分别演示了在查询过滤条件中使用和不使用前置通配符时,查询执行计划的不同表现。
在下面的查询脚本中,不使用前置通配符,发现建立在LoginID字段上的索引发生作用,查询时不要扫描整个聚集索引。
Select * from HumanResources.Employee
where LoginID like 'adventure-works\rob0%'
 
 

在下面的查询脚本中,由于使用前置通配符,发现建立在LoginID字段上的索引没有作用了,查询时需要扫描整个聚集索引。
 
Select * from HumanResources.Employee
where LoginID like '%adventure-works\rob0%'
 
 
下面是查询执行计划中部分输出的介绍:
物理运算(Physical Operation): Table Scan — To satisfy the query, SQL Server had to read (that is, scan) all the rows to return its results. Table scans can be extremely costly, especially when encountered on tables containing copious data.
估计开销 - Estimated Costs (I/O, CPU, 运算符Operator,子树 Subtree) — These indicators provide guidance on SQL Server’s internal estimates of its expected workload to return your results. Note: These numbers don’t mean much in isolation; they’re interesting only when compared against other query plans.
估计行数(Estimated Number of Rows): Because we asked to see all the rows, SQL Server accurately reports that it estimates a return result set size of rows.
 
欢迎访问http://blog.entlib.com/ 开源ASP.NET博客平台,了解更多的读书笔记。
 

 

 打印 | 发表评论 | posted on 2009年3月21日 0:59 | 目录 [ SQL Server & Service Broker ]

评 论

欢迎发表评论。

发表评论

标题  
姓名  
Email
主页
评论内容   
Please add 1 and 2 and type the answer here: