`
darrenzhu
  • 浏览: 809902 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Sybase SQL性能诊断

阅读更多

Performance and Tuning Series: Query Processing and Abstract Plans
http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc00743.1570/html/queryprocessing/title.htm

Query plan/showplan output description
http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc20022_1251/html/monitoring/X85682.htm


1) set showplan on;
执行sql语句并且显示query plan

2) set showplan on;
   set noexec on;
不执行sql语句,只显示sql语句的query plan

3)对于存储过程,使用set fmtonly on

4) set showplan on;
   set noexec off;
   set statistics plancost on;
   会执行sql语句,打印出query plan,同时打印出query plan的图形表示。

有关set statistics plancost on详细信息,请参见《Adaptive Server 参考手册:命令》。此命令用于比较查询计划的估计开销和实际开销。它将其输出显示为表示查询计划树的半图形化的树。这是一种诊断查询性能问题的非常有用的工具。

Also "set statistics io on" is very useful

5. 其他相关set命令
set statistics {io, subquerycache, time, plancost, simulate} {on | off}
显示各种类型的统计信息
• io — 显示有关语句中引用的每个表的统计信息:
• 访问表的次数(扫描计数)
• 逻辑读取的数目(内存中访问的页)
• 物理读取次数(数据库设备访问)
statistics io 为每个命令显示写入的缓冲区数目。
如果 Adaptive Server 已配置为强制资源限制,则 statistics io 还显示
总的 I/O 开销。
• subquerycache — 为每个子查询显示子查询高速缓存中的高速缓存
命中次数、未命中次数和行数。
• time — 显示 Adaptive Server 分析和编译每个命令所用的时间。在
命令的每一个步骤, statistics time 显示 Adaptive Server 执行此命
令所需的时间。时间以毫秒或时钟周期为单位指定,其确切值与
计算机有关。
• plancost — 以树格式显示查询统计信息。
注释 启用 set statistics plancost 后,Adaptive Server 将 lio、pio
和 row 的名称分别缩写为 l、p 和 r。
• simulate — 指定优化程序应使用模拟统计信息来优化查询。
请参见《性能和调优指南》中的第 34 章“使用 set statistics 命令”。


Understanding the Information You Have Gathered
http://infocenter.sybase.com/archive/index.jsp?topic=/com.sybase.39996_1250/html/svrtsg/svrtsg170.htm
You have taken a number of steps to get information about your optimizer problem. Here is an explanation of each of these steps:


select @@version
select @@version displays the version of Adaptive Server you are running, including the SWR level and platform.


sp_help
sp_help provides more accurate information about a table than the script you used to create the table and its indexes. In the event that indexes have been added or changed or that columns have been added via alter table, sp_help will show the present state of the table(s).


set showplan on
The set showplan on command shows which query plan the optimizer has chosen for your query. Use set showplan on before running any query or procedure you will be analyzing.

In some cases you may need to issue the set noexec on command to save time when you are running a very long query. The order of these commands is important:

set showplan on
set noexec on
go
<query text...>
go
There are several important items of information to look for when reading showplan output:

Cache Utilization

Adaptive Server uses two major strategies, named LRU and MRU respectively, for its data cache. The type of strategy used in a given query depends on whether a cached page needs to be accessed more than once. showplan’s "Buffer Replacement Strategy" messages show the cache strategy used for data pages and index leaf pages. See “Caches and Object Bindings” in the Performance and Tuning Guide for more information about cache strategies.

If you want to investigate your caches, for example to learn whether a cache is under- or over-utilized, you can use sp_sysmon. See “Data Cache Management” in the Performance and Tuning Guide.

Index Utilization

Was an index used? Which one? Was a table scan done? To answer these questions, check the portion of showplan output following FROM TABLE for messages like "Table Scan" or "Using Clustered Index".

Join Information

When evaluating joins, look for

the order of tables in a join, also known as join order; knowing the order that the optimizer chose for joins is critical to your analysis. When your query joins two or more tables, showplan’s FROM TABLE messages show the order in which the optimizer will join the tables.

Whether it is a nested-loop join or a sort-merge join (applies to 12.0 and later).

Refer to “Using set showplan” in the Performance and Tuning Guide for more information on interpreting showplan results.


set statistics io on
Since any analysis of a performance problem will require knowledge of the number and types of I/Os performed for the query, the set statistics io on command is critical.

NoteIf your query is taking very long to complete, using statistics io and statistics time may not be feasible. If you analyze your long-running query using set noexec on, you cannot obtain I/O information since noexec on stops all the output of statistics io.

The set statistics io on command provides you with the following information:

Physical reads

This is the number of times Adaptive Server accesses the disk. The first time a query is run, the number of physical reads will generally be high. This happens because the required pages are not usually in cache. Subsequent runs of the query can access the pages in cache, and physical reads are minimized, if not avoided. If the number of physical reads remains high during subsequent executions of a query, you will need to take a close look at how the query executes.

In some instances, the size of the data cache may also be a problem. If it is too small, pages have to be read from disk more often. Likewise, configuration of named caches and use of large I/O buffer pools can have an impact on performance. See “Memory Use and Performance” in the Performance and Tuning Guide for details on configuring the data cache to improve performance.

Logical reads

Logical reads are a combination of physical reads and "cache hits" - reads from pages in cache. If your statistics show a number of logical reads and no physical reads, it means that all required pages are in cache, which is the ideal situation. To determine the cache hit ratio (the percentage of pages that were found in cache) for your query, use the formula:

                  Logical reads - (Physical reads * Pages per I/O)
Cache hit ratio = -----------------------------------------------
                                     Logical reads
Use set showplan on to see the I/O size used by the query. With 2K pages, a query using 4K I/O reads 2 pages with each I/O.

Scan count

This is the number of times the table was read (using either a table scan or an index) in order to find rows to satisfy the query or join. In nearly all simple single table queries, the scan count will be 1. When an OR clause is present there will be one scan count for each OR in the query. In the case of a join, the scan count can be crucial.

If the optimizer chose a bad join order, you are likely to see a very high number of scan counts on a large table, causing a very high number of logical reads. However, you should take the table size into account when interpreting scan counts. A high scan count on a small table is preferable to a moderate scan count on a large table. Although the scan count of the small table is high, the physical reads should be low. A 1000-scan count for a 1-page table is better than a 100-scan count of a 1000-page table.

The following example demonstrates how join order and scan count affect the number of reads (on 12.0 and later, the example represents a nested-loop join):

Table A has 1 page and 10 rows that qualify for the join. Table B has 1000 pages and 10 rows that qualify for the join.

If Table B is the outer table of the join Adaptive Server will only need to read through it once in order to find all qualifying rows. The single scan totals 1000 reads. Adaptive Server then reads Table A for each qualifying row found in B. The single page in A is scanned 10 times, equaling 10 reads, with a total of 1010 reads for the query. If A were the outer table Adaptive Server would have to read B once for each of the ten qualifying rows on A: 1000 pages multiplied by 10 scans equals 10,000 reads.

This example assumes that there is no useful index available.

Total writes for this command

This is the total number of writes Adaptive Server did for the query. This count includes inserts, updates and deletes on user tables, temporary tables and work tables. Even queries that do not include data manipulation statements may require writes to work tables or temporary tables, which are counted here.


set statistics time on
set statistics time on provides the following information:

Adaptive Server elapsed time

This is the total accumulated elapsed time that is recorded for the query or command. This can seem long if, for example, a query was blocked by a lock, network traffic or other resource contention. The time the query must wait for the blockage to clear is added to the elapsed time.

Adaptive Server CPU time

This is the amount of time for which the query had exclusive use of the CPU. It reflects the time taken to parse, compile, and execute the query. Functions add to the CPU time. For example, a convert statement will increase the CPU time slightly. Also, compute-intensive queries and queries that perform a large amount of I/O take more CPU time.

The output of set statistics time on may be useful, but it is not usually a significant factor in most optimizer analyses.


dbcc traceon (3604)
This trace flag sends the output of dbcc traceon (302) and dbcc traceon (310) to the screen.


dbcc traceon (302)
This trace flag returns the optimizer's cost estimates for each SARG and join clause in the query. Trace flag 302 is documented in greater detail in “Tuning with dbcc traceon” in the Performance and Tuning Guide.

Here is the information to watch for in dbcc traceon (302) output:

All SARGs and join clauses in the query should be shown in the optimizer's cost estimates. If not, determine why.

Check that row and page counts are accurate, since these counts are important for optimization.

If you think that the page and row counts are off, check the counts. Run optdiag statistics. To improve performance, counts and other statistics are changed in memory and flushed to systabstats periodically by the housekeeper task. You can also flush in-memory statistics to systabstats by running optdiag statistics or executing sp_flushstats table_name.


dbcc traceon (310)
dbcc traceon (310) gives the optimizer cost estimates for permutations of a join or joins. Examine the dbcc traceon (310) output to determine whether the query is “connected.” If so, it indicates that the join will not result in a cartesian product. The statement “query is connected” will appear after the optimizer has performed cost estimates on all possible indexes, as indicated in the output of dbcc traceon (302) .


IO statistics output explanation
below is one row of the output when set statistics io on for q query
Table: Worktable1 scan count 1, logical reads: (regular=6391 apf=0 total=6391), physical reads: (regular=7919 apf=0 total=7919), apf IOs used=0



http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc20022_1251/html/monitoring/monitoring99.htm
Statistics for reads
statistics io reports the number of logical and physical reads for each table and index included in a query, including worktables. I/O for indexes is included with the I/O for the table.


Table 4-1 shows the values that statistics io reports for logical and physical reads.

Table 4-1: statistics io output for reads
logical reads
regular
Number of times that a page needed by the query was found in cache; only pages not brought in by asynchronous prefetch (APF) are counted here.

apf
Number of times that a request brought in by an APF request was found in cache.

total
Sum of regular and apf logical reads.


physical reads
regular
Number of times a buffer was brought into cache by regular asynchronous I/O

apf
Number of times that a buffer w.as brought into cache by APF.

total
Sum of regular and apf physical reads.

apf IOs used
Number of buffers brought in by APF in which one or more pages were used during the query.
分享到:
评论

相关推荐

    第11讲:深入理解指针(1).pdf

    第11讲:深入理解指针(1)

    springboot整合 freemarker方法

    springboot整合 freemarker方法

    第14讲:深入理解指针(4).pdf

    第14讲:深入理解指针(4)

    同行者4.1.2语音助手

    《同行者4.1.2语音助手:车机版安装详解》 在现代科技日新月异的时代,智能车载设备已经成为了汽车生活的重要组成部分。"同行者4.1.2"便是这样一款专为车机设计的语音助手,旨在提供更为便捷、安全的驾驶体验。该版本针对掌讯全系列设备进行了兼容优化,让车主能够轻松实现语音控制,减少驾驶过程中的手动操作,提升行车安全性。 我们来了解下"同行者4.1.2"的核心功能。这款语音助手集成了智能语音识别技术,用户可以通过简单的语音指令完成导航、音乐播放、电话拨打等一系列操作,有效避免了因操作手机或车机带来的分心。此外,其强大的语义理解和自学习能力,使得它能逐步适应用户的口音和习惯,提供更个性化的服务。 在安装过程中,用户需要注意的是,"同行者4.1.2"包含了四个核心组件,分别是: 1. TXZCore.apk:这是同行者语音助手的基础框架,包含了语音识别和处理的核心算法,是整个应用运行的基础。 2. com.txznet.comm.base.BaseApplication.apk:这个文件可能包含了应用的公共模块和基础服务,为其他组件提供支持。 3. TXZsetting.apk:这

    市场拓展主管绩效考核表.xls

    市场拓展主管绩效考核表

    “线上购车3D全方位体验:汽车模型展示与个性化定制功能”,three.js案例- 线上购车3d展示(源码) 包含内容:1.汽车模型展示;2.汽车肤;3.轮毂部件更;4.开关车门动画;5.汽车尺寸测量

    “线上购车3D全方位体验:汽车模型展示与个性化定制功能”,three.js案例- 线上购车3d展示(源码) 包含内容:1.汽车模型展示;2.汽车肤;3.轮毂部件更;4.开关车门动画;5.汽车尺寸测量;6.自动驾驶;7.镜面倒影;8.hdr运用;9.移动端适配; 本为html+css+three.js源码 ,核心关键词:three.js案例; 线上购车3D展示; 汽车模型展示; 汽车换肤; 轮毂部件更换; 开关车门动画; 汽车尺寸测量; 自动驾驶; 镜面倒影; HDR运用; 移动端适配; HTML+CSS+three.js源码。,"Three.js源码:线上购车3D展示案例,含汽车模型、换肤、轮毂更换等九大功能"

    (数据权威)中国城市_县域统计面板数据二合一

    数据名称:2000-2022年各县市区主要社会经济发展指标面板数据 数据类型:dta格式 数据来源:中国县域统计

    120页-环卫车项目初步方案.pdf

    一、智慧环卫管理平台的建设背景与目标 智慧环卫管理平台的建设源于对环卫管理全面升级的需求。当前,城管局已拥有139辆配备车载GPS系统、摄像头和油耗传感器的环卫车辆,但环卫人员尚未配备智能移动终端,公厕也缺乏信息化系统和智能终端设备。为了提升环卫作业效率、实现精细化管理并节省开支,智慧环卫管理平台应运而生。该平台旨在通过信息化技术和软硬件设备,如车载智能终端和环卫手机App,实时了解环卫人员、车辆的工作状态、信息和历史记录,使环卫作业管理透明化、精细化。同时,平台还期望通过数据模型搭建和数据研读,实现更合理的环卫动态资源配置,为环卫工作的科学、健康、持续发展提供决策支持。 二、智慧环卫管理平台的建设内容与功能 智慧环卫管理平台的建设内容包括运行机制体制建设、业务流程设计、智慧公厕系统建设、网络建设、主机和储存平台需求、平台运维管理体系、硬件标准规范体系以及考核评价体系等多个方面。其中,智慧公厕系统建设尤为关键,它能实时监控公厕运行状态,保障公厕的清洁和正常运行。平台建设还充分利用了现有的电子政务网络资源,并考虑了有线和无线网络的需求。在功能上,平台通过普查、整合等手段全面收集环卫车辆、企业、人员、设施、设备等数据,建立智慧环卫基础数据库。利用智能传感、卫星定位等技术实现环卫作业的在线监管和远程监控,实现对道路、公共场所等的作业状况和卫生状况的全面监管。此外,平台还建立了环卫作业网格化管理责任机制,实现从作业过程到结果的全面监管,科学评价区域、部门、单位和人员的作业效果。 三、智慧环卫管理平台的效益与风险规避 智慧环卫管理平台的建设将带来显著的环境、经济和管理效益。环境方面,它将有力推进环境卫生监管服务工作,改善环境卫生状况,为人民群众创造更加清洁、卫生的工作和生活环境。经济方面,通过智慧化监管,大大降低了传统管理手段的成本,提高了监管的准确性和效率。管理方面,平台能够追踪溯源市民反映的问题,如公厕异味、渣土车辆抛洒等,并找到相应的责任单位进行处置,防止类似事件再次发生。同时,平台还拥有强大的预警机制功能,能够在很多环卫问题尚未出现前进行处置。然而,平台建设也面临一定的风险,如部门协调、配合问题,建设单位选择风险以及不可预测的自然灾害等。为了规避这些风险,需要加强领导、统一思想,选择优秀的系统集成商承接项目建设,并做好计算机和应用系统的培训工作。同时,也要注意标准制定工作和相关法律法规的制定工作,以保证系统建设完成后能够真正为环卫管理工作带来便利。

    36 -企业管理主管绩效考核表1.xlsx

    36 -企业管理主管绩效考核表1

    1.1 -1.4 工程代码

    1.1 -1.4 工程代码

    USDT合约,USDT智能合约

    USDT合约,USDT智能合约

    基于姿态估计三维人脸形状重建.pdf

    基于姿态估计三维人脸形状重建.pdf

    一般员工绩效考核表模板(通用版) (2).xls

    一般员工绩效考核表模板(通用版) (2)

    全国295个地级市2011-2022互联网宽带接入用户数互联网普及率(数据权威)

    全国各省295地级市互联网普及率、互联网用户数、每百人互联网宽带用户(2011-2022年) 数据年份:2011-2022年(2022存在部分缺失) 数据范围:全国各省295个地级市 数据来源:地方统计局

    (数据权威)碳排放、碳中和、碳交易、碳金融、碳计算、碳建模资料

    一、各省、分行业CO2排放、283个地级市碳排放及计算过程 2.分行业二氧化碳排放量 在这里插入图片描述 3、280多个地级市碳排放及计算过程 二、碳中和文献、最新政策、碳金融数据+数学建模 1.二氧化碳减排规划,碳金融数据收集及数学建模 2.碳中和政策和下载量最高的碳中和论文 三、碳排放+碳市场+碳交易+碳中和+碳排放核算Excel自动计算表 全行业碳排放核算Excel自动计算表 四、碳交易数据 五、主要能源碳排放计算参数

    第20讲:自定义类型:结构体.pdf

    第20讲:自定义类型:结构体

    视觉跟踪算法综述.pdf

    视觉跟踪算法综述.pdf

    MATLAB超效率SBM-DEA模型代码详解:简易操作指南及期望与非期望产出的超效率分析,附Malmquist指数与分解功能,MATLAB的超效率SBM-DEA模型代码(有安装教程和内容讲解之类的东西

    MATLAB超效率SBM-DEA模型代码详解:简易操作指南及期望与非期望产出的超效率分析,附Malmquist指数与分解功能,MATLAB的超效率SBM-DEA模型代码(有安装教程和内容讲解之类的东西),操作很简单 可以做期望产出和非期望产出的超效率和非超效率sbm模型和Malmquist指数和分解 ,MATLAB; SBM-DEA模型; 超效率SBM-DEA; 安装教程; 内容讲解; 期望产出; 非期望产出; 超效率与非超效率sbm模型; Malmquist指数; 分解。,"MATLAB超效SBM-DEA模型代码:非期望产出分析的便捷工具"

    人事行政主管绩效考核评分表.xls

    人事行政主管绩效考核评分表

    人力资源管理工具绩效考核excel模板.xlsx

    人力资源管理工具绩效考核excel模板

Global site tag (gtag.js) - Google Analytics