楼主: eygle

[精华] 一次分析的全过程,和大家交流!

[复制链接]
论坛徽章:
117
ITPUB元老
日期:2005-02-28 12:57:002012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20版主7段
日期:2012-05-15 15:24:11ITPUB 11周年纪念徽章
日期:2012-09-28 17:34:42ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:32紫蛋头
日期:2013-03-04 17:00:07优秀写手
日期:2013-12-18 09:29:09
21#
 楼主| 发表于 2003-1-23 12:23 | 只看该作者
Oracle9iR2是最后一个支持RBO的版本,Oracle10i将不再支持RBO,所以一切使用RBO的可以考虑作适当的转换了。

参考
Rule Based Optimizer is to be Desupported in Oracle10i
http://www.itpub.net/showthread.php?threadid=88905

SQL优化的方法是多种多样的,Oracle的COST就是在计算这些因素,当全表扫描优于索引扫描的时候Oracle自然会选择全表扫描。可是在CBO的优化上,Oralce是不值得完全信赖的,所以我们需要人为的介入。

在《Oracle 8优化技术》一书中,有如下说法:
• 非常喜欢O r a c l e,在于其具有灵活的可调节性。
• 非常厌恶O r a c l e,也在于其有灵活的可调节性。

实际上,只要能够达到可以接受的范围,那么我们的工作就是有效的。

没有最优,只有更优

使用道具 举报

回复
论坛徽章:
60
2007年度最佳版主
日期:2008-04-03 16:46:15现任管理团队成员
日期:2011-05-07 01:45:08双黄蛋
日期:2011-06-15 17:03:34ITPUB十周年纪念徽章
日期:2011-11-01 16:19:412012新春纪念徽章
日期:2012-01-04 11:49:542012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
22#
发表于 2003-1-23 12:43 | 只看该作者
看你分析了半天,还不知道你的几个表的基本情况呢,

你的几个表各有多少数据阿?


优化分析怎么不考虑这个呢,呵呵,离开实际情况的分析怕是站不住脚

使用道具 举报

回复
论坛徽章:
21
ITPUB元老
日期:2005-02-28 12:57:002012新春纪念徽章
日期:2012-02-13 15:11:182012新春纪念徽章
日期:2012-02-13 15:11:182012新春纪念徽章
日期:2012-02-13 15:11:182012新春纪念徽章
日期:2012-02-13 15:11:18马上有车
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:142012新春纪念徽章
日期:2012-02-13 15:11:18
23#
发表于 2003-1-23 12:48 | 只看该作者
这个问题的Eygle的分析处理步骤和大家的进展,大家可以在china oracle user group SQL TUning那边找到。
看看问题的分析和尝试的步骤,还是蛮有意思的。

使用道具 举报

回复
招聘 : Hadoop大数据库开发
论坛徽章:
39
生肖徽章2007版:猴
日期:2008-01-02 17:35:532010年世界杯参赛球队:阿根廷
日期:2010-07-02 16:05:252010年世界杯参赛球队:加纳
日期:2010-04-26 12:31:372010新春纪念徽章
日期:2010-03-01 11:06:23祖国60周年纪念徽章
日期:2009-10-09 08:28:00ITPUB8周年纪念徽章
日期:2009-09-27 10:21:22生肖徽章2007版:猴
日期:2009-03-10 21:29:55生肖徽章2007版:猴
日期:2009-03-10 21:23:27IT宝贝
日期:2009-02-18 13:00:30生肖徽章2007版:猴
日期:2008-12-25 14:22:01
24#
发表于 2003-1-23 13:31 | 只看该作者

使用道具 举报

回复
论坛徽章:
117
ITPUB元老
日期:2005-02-28 12:57:002012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20版主7段
日期:2012-05-15 15:24:11ITPUB 11周年纪念徽章
日期:2012-09-28 17:34:42ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:32紫蛋头
日期:2013-03-04 17:00:07优秀写手
日期:2013-12-18 09:29:09
25#
 楼主| 发表于 2003-1-23 13:54 | 只看该作者
最初由 Fenng 发布
[B]看你分析了半天,还不知道你的几个表的基本情况呢,

你的几个表各有多少数据阿?


优化分析怎么不考虑这个呢,呵呵,离开实际情况的分析怕是站不住脚 [/B]


所作的优化是我们的生产数据库,这个问题是在开发中实际遇到的。

所以并非脱离实际,实际上,如果脱离实际要生成这样的结果也是不容易的

其实即使不知道表的基本情况和数据量,从执行计划中也是可以看出前后的变化及结果的!

SQL> select 'sp_item' table_name,count(*) num_rows from sp_item
  2  union
  3  select 'sp_trans' table_name,count(*) num_rows from sp_trans
  4  union
  5  select 'sp_trans_sub' table_name,count(*) num_rows from sp_trans_sub
  6  /

TABLE_NAME     NUM_ROWS
------------ ----------
sp_item           29821
sp_trans          34627
sp_trans_sub     136916

SQL> select table_name,num_rows
from user_tables where table_name in ('SP_ITEM','SP_TRANS','SP_TRANS_SUB');

TABLE_NAME                       NUM_ROWS
------------------------------ ----------
SP_ITEM                             29763
SP_TRANS                            34321
SP_TRANS_SUB                       136371

SQL>

使用道具 举报

回复
论坛徽章:
4
ITPUB元老
日期:2005-02-28 12:57:00授权会员
日期:2005-10-30 17:05:33管理团队2006纪念徽章
日期:2006-04-16 22:44:45会员2006贡献徽章
日期:2006-04-17 13:46:34
26#
发表于 2003-1-23 15:59 | 只看该作者
不错,eygle说的这番话非常有道理。oracle给我提供了非常灵活的选择方式。虽然rbo推出舞台,但是我们也不能完全信任cbo,具体情况还是要具体分析。


QUOTE]最初由 eygle 发布
[B]Oracle9iR2是最后一个支持RBO的版本,Oracle10i将不再支持RBO,所以一切使用RBO的可以考虑作适当的转换了。

参考
Rule Based Optimizer is to be Desupported in Oracle10i
http://www.itpub.net/showthread.php?threadid=88905

SQL优化的方法是多种多样的,Oracle的COST就是在计算这些因素,当全表扫描优于索引扫描的时候Oracle自然会选择全表扫描。可是在CBO的优化上,Oralce是不值得完全信赖的,所以我们需要人为的介入。

在《Oracle 8优化技术》一书中,有如下说法:
• 非常喜欢O r a c l e,在于其具有灵活的可调节性。
• 非常厌恶O r a c l e,也在于其有灵活的可调节性。

实际上,只要能够达到可以接受的范围,那么我们的工作就是有效的。

没有最优,只有更优 [/B][/QUOTE]

使用道具 举报

回复
论坛徽章:
33
授权会员
日期:2005-10-30 17:05:33ITPUB十周年纪念徽章
日期:2011-11-01 16:19:412012新春纪念徽章
日期:2012-01-04 11:49:542012新春纪念徽章
日期:2012-02-13 15:11:522012新春纪念徽章
日期:2012-02-13 15:11:522012新春纪念徽章
日期:2012-02-13 15:11:522012新春纪念徽章
日期:2012-02-13 15:11:522012新春纪念徽章
日期:2012-02-13 15:11:522013年新春福章
日期:2013-02-25 14:51:24马上有车
日期:2014-02-19 11:55:14
27#
发表于 2003-1-24 09:26 | 只看该作者
这个china oracle user group在哪里?
cp师兄
最初由 chao_ping 发布
[B]这个问题的Eygle的分析处理步骤和大家的进展,大家可以在china oracle user group SQL TUning那边找到。
看看问题的分析和尝试的步骤,还是蛮有意思的。 [/B]

使用道具 举报

回复
论坛徽章:
33
授权会员
日期:2005-10-30 17:05:33ITPUB十周年纪念徽章
日期:2011-11-01 16:19:412012新春纪念徽章
日期:2012-01-04 11:49:542012新春纪念徽章
日期:2012-02-13 15:11:522012新春纪念徽章
日期:2012-02-13 15:11:522012新春纪念徽章
日期:2012-02-13 15:11:522012新春纪念徽章
日期:2012-02-13 15:11:522012新春纪念徽章
日期:2012-02-13 15:11:522013年新春福章
日期:2013-02-25 14:51:24马上有车
日期:2014-02-19 11:55:14
28#
发表于 2003-1-24 09:28 | 只看该作者
最初由 huang0905 发布
[B]eygle:
     请详细介绍如何得出的 execution plan and statistics 结果,是否是从表 plan_table 中? [/B]

http://www.xiaomai.org/read.php?id=217

使用道具 举报

回复
论坛徽章:
1
授权会员
日期:2005-10-30 17:05:33
29#
发表于 2003-2-8 11:43 | 只看该作者
When the Optimizer Uses Full Table Scans

The optimizer uses a full table scan in any of the following cases:

1.Lack of Access Paths: If the query is unable to use any existing indexes, then it uses a full table scan.
2.Large Amount of Data: If the optimizer thinks that the query will access most of the
blocks in the table, then it uses a full table scan, even though indexes might be
available.
3.Small Table: If a table contains less than DB_FILE_MULTIBLOCK_READ_COUNT
blocks under the high water mark, which can be read in a single I/O call, then a full
table scan might be cheaper than an index range scan, regardless of the fraction of
tables being accessed or indexes present.
4.Old Statistics :If the table has not been analyzed since it was created, and if it has less than DB_FILE_MULTIBLOCK_READ_COUNT blocks under the highwater mark,
then the optimizer thinks that the table is small and uses a full table scan. Look at
the LAST_ANALYZED and BLOCKS columns in the ALL_TABLES table to see what
the statistics reflect.

使用道具 举报

回复
论坛徽章:
1
授权会员
日期:2005-10-30 17:05:33
30#
发表于 2003-2-8 11:46 | 只看该作者
Why a Full Table Scan Is Faster for Accessing Large Amounts of Data ?

Full table scans are cheaper than index range scans when accessing a large fraction
of the blocks in a table. This is because full table scans can use larger I/O calls, and
making fewer large I/O calls is cheaper than making many smaller calls.

The elapsed time for an I/O call consists of two components:
1. Call setup time (head seek time, rotational latency)
2. Data transfer time (typically 10 MB a second or better)

In a typical I/O operation, setup costs consume most of the time. Data transfer time
for an 8-K buffer is less than 1 msec (out of the total time of 10 msec). This means
that you can transfer 128 KB in about 20 msec with a single 128 KB call, as opposed
to needing 160 msec with sixteen 8-KB calls.

Example Full Table Scan Compared to Index Range Scan
Consider a case in which 20% of the blocks in a 10,000-block table are accessed. The
following are true:
DB_FILE_MULTIBLOCK_READ_COUNT = 16
DB_BLOCK_SIZE = 8 K
Number of 8 K I/O calls required for index access = 2,000 (table) + index
Number of 128 K I/O calls required for full table scan = 10,000/16 = 625

Assume that each 8 K I/O takes 10 msec, and about 20 seconds are spent doing
single block I/O for the table blocks. This does not include the additional time to
perform the index block I/O. Assuming that each 128 K I/O takes 20 msec, about
12.5 seconds are spent waiting for the data blocks, with no wait required for any
index blocks.

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表