12
返回列表 发新帖
楼主: nilone

[原创] 优化SQL到底看什么指标?

[复制链接]
论坛徽章:
2
2010新春纪念徽章
日期:2010-03-01 11:08:37ITPUB十周年纪念徽章
日期:2011-11-01 16:25:22
11#
 楼主| 发表于 2010-1-21 18:19 | 只看该作者
我倒觉得数据仓库中大部分都应该用hash join,OLTP则应该避免。

使用道具 举报

回复
论坛徽章:
8
ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:442009日食纪念
日期:2009-07-22 09:30:002010新春纪念徽章
日期:2010-01-04 08:33:082010新春纪念徽章
日期:2010-03-01 11:19:072011新春纪念徽章
日期:2011-01-04 10:37:10ITPUB十周年纪念徽章
日期:2011-11-01 16:21:15ITPUB 11周年纪念徽章
日期:2012-10-09 18:06:202013年新春福章
日期:2013-02-25 14:51:24
12#
发表于 2010-1-21 20:18 | 只看该作者
我倒觉得数据仓库中大部分都应该用hash join,OLTP则应该避免。

----

这个要按需而定。

DW最常见的查询
dimension table 和 FACT table
再加上一些和时间 区域 产品相关的filter

FACT table一个就 有几百个GB, 甚至TB

等着把它full scan一遍 再hash join , 花儿都谢了

使用道具 举报

回复
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
13#
发表于 2010-1-22 00:23 | 只看该作者
原帖由 nilone 于 2010-1-21 00:40 发表
逻辑读是不是需要把查询结果全部读出来才能得到?
如果该查询过程要很久(一个小时),那逻辑读怎么得到?怎么执行优化过程?


If the SQL was run before, as you see in v$sql* views, logical reads (i.e. buffer_gets column) is already available. If it's a new SQL and it doesn't finish running within a reasonable time, as when you're tuning a data warehouse query, then of course you have to rely on other factors, such as calculated cost.

To others,

We're talking about "优化SQL到底看什么指标", not about what execution paths are usually good.

Yong Huang

使用道具 举报

回复
论坛徽章:
2
2010新春纪念徽章
日期:2010-03-01 11:08:37ITPUB十周年纪念徽章
日期:2011-11-01 16:25:22
14#
 楼主| 发表于 2010-1-22 08:46 | 只看该作者
YONGHUANG能否提供一个案例,老实说我对consistent read ,buffer gets还没有理解透。set autotrace使用不多。平时优化SQL也就看下执行路径是不是自己期望的,时间是不是快了些,其实谈不上不专业,最终还是要面对一个科学的步骤。

[ 本帖最后由 nilone 于 2010-1-22 08:50 编辑 ]

使用道具 举报

回复
论坛徽章:
2
2010新春纪念徽章
日期:2010-03-01 11:08:37ITPUB十周年纪念徽章
日期:2011-11-01 16:25:22
15#
 楼主| 发表于 2010-1-22 08:52 | 只看该作者
原帖由 wang5 于 2010-1-21 20:18 发表
我倒觉得数据仓库中大部分都应该用hash join,OLTP则应该避免。

----

这个要按需而定。

DW最常见的查询
dimension table 和 FACT table
再加上一些和时间 区域 产品相关的filter

FACT table一个就 有几百个GB, 甚至TB

等着把它full scan一遍 再hash join , 花儿都谢了



我一般考虑把FACT table 过滤字段上建立索引,作为关联的prob表,dimention table作为build表,不会要把FACT table 全表扫描一遍吧。
不知道我的做法是否妥当。

使用道具 举报

回复
论坛徽章:
2
2010新春纪念徽章
日期:2010-03-01 11:08:37ITPUB十周年纪念徽章
日期:2011-11-01 16:25:22
16#
 楼主| 发表于 2010-1-22 08:55 | 只看该作者
Yong Huang的意思是:的确是要等一个SQL执行完毕了才获取逻辑读数值吗?你所说的参考其他的计算代价,有没有既定的原则来看?
事实上,我平时面对的主要是DW的批量数据处理。


原帖由 Yong Huang 于 2010-1-22 00:23 发表


If the SQL was run before, as you see in v$sql* views, logical reads (i.e. buffer_gets column) is already available. If it's a new SQL and it doesn't finish running within a reasonable time, as when you're tuning a data warehouse query, then of course you have to rely on other factors, such as calculated cost.

To others,

We're talking about "优化SQL到底看什么指标", not about what execution paths are usually good.

Yong Huang

使用道具 举报

回复
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
17#
发表于 2010-1-23 06:00 | 只看该作者
> 的确是要等一个SQL执行完毕了才获取逻辑读数值吗?

Yes. But if the SQL runs a long time and you don't want to wait till it finishes, you can always check v$sql* views for the SQL's cumulative buffer_gets at that moment, or v$sesstat for the session's cumulative 'consistent gets' (find statistic# in v$statname or v$sysstat).

> 你所说的参考其他的计算代价,有没有既定的原则来看?

No. But you can always just read the explained plan and see from what step on the cost increases the most. Suppose the plan is like:

operation cost
...
op1          1000
op2          900
op3          10
op4          3

You know you need to focus on op2.

Yong Huang

使用道具 举报

回复
论坛徽章:
1
2011新春纪念徽章
日期:2011-02-18 11:42:49
18#
发表于 2010-3-5 15:10 | 只看该作者
如果表特别大的话,可以考虑使用分区,可大大减少逻辑读.

使用道具 举报

回复

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

本版积分规则 发表回复

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