楼主: IOOOOOOOOOO

看到DBA发了这么一个脚本,不知道是什么意思!

[复制链接]
论坛徽章:
2
授权会员
日期:2008-11-09 14:44:28数据库板块每日发贴之星
日期:2009-02-23 01:01:02
11#
发表于 2008-11-27 15:41 | 只看该作者
不错

使用道具 举报

回复
招聘 : Java研发
论坛徽章:
71
马上加薪
日期:2014-02-19 11:55:14蜘蛛蛋
日期:2012-12-26 18:16:01茶鸡蛋
日期:2012-11-16 08:12:48ITPUB 11周年纪念徽章
日期:2012-10-09 18:05:07奥运会纪念徽章:网球
日期:2012-08-23 14:58:08奥运会纪念徽章:沙滩排球
日期:2012-07-19 17:28:14版主2段
日期:2012-07-07 02:21:02咸鸭蛋
日期:2012-03-23 18:17:482012新春纪念徽章
日期:2012-02-13 15:13:512012新春纪念徽章
日期:2012-02-13 15:13:51
12#
发表于 2008-11-27 16:02 | 只看该作者
原帖由 Yong Huang 于 2008-11-27 11:21 发表


oradbHome was saying that when status is null, the index still has (null, '1'), so it's still an entry in the index. If the index were on (status) only, when status is null, the index wouldn't even have an entry for this row so a full table scan is the only option.

It's a clever trick to improve performance in special cases. "其实在设计中尽量避免字段为null, 不能用null 代表业务意义" means you should not have or should only have very few cases where you'll have a where-clase like "where status is null"; instead, you should design the model such that a special value, say, 'NULL', is put in the column whenever you would otherwise put null (i.e. nothing) in the column and your where-clause becomes "where status='NULL'". That's a good suggestion. But sometimes it's just not easy to predict during the design time.

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
13#
发表于 2008-11-28 05:52 | 只看该作者
原帖由 anlinew 于 2008-11-27 02:02 发表

所以:软件系统的优化应该是全生命周期的


Agree. For now, the DBA's remedy works. Alternatively, if status doesn't have many distinct values and the table doesn't have frequent small DMLs, a bitmap index on (status) will do, too. (Infrequent bulk DMLs are fine with bitmap indexes.) One other idea is to talk to the application team to see if it's too much trouble to change the code to handle a new value, say, "NULL", instead of an empty null. If it's OK, just update the column to change all null's to "NULL". Then a NOT NULL constraint can be added, which may even further boost performance of this or other SQLs because CBO has more information about this column in considering the best plan.

Yong Huang

使用道具 举报

回复
论坛徽章:
12
会员2006贡献徽章
日期:2006-04-17 13:46:34生肖徽章2007版:兔
日期:2009-03-10 21:27:28ERP板块每日发贴之星
日期:2007-10-24 01:04:58ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:44设计板块每日发贴之星
日期:2007-10-18 01:06:03ITPUB元老
日期:2007-10-11 14:47:20开发板块每日发贴之星
日期:2007-10-10 01:05:30行业板块每日发贴之星
日期:2007-10-01 01:05:12行业板块每日发贴之星
日期:2007-09-30 01:05:35会员2007贡献徽章
日期:2007-09-26 18:42:10
14#
发表于 2008-11-28 15:13 | 只看该作者
YH说的很有创见

使用道具 举报

回复
论坛徽章:
8
2009新春纪念徽章
日期:2009-01-04 14:52:28祖国60周年纪念徽章
日期:2009-10-09 08:28:002010新春纪念徽章
日期:2010-03-01 11:07:24ITPUB9周年纪念徽章
日期:2010-10-08 09:32:25ITPUB十周年纪念徽章
日期:2011-11-01 16:23:262013年新春福章
日期:2013-02-25 14:51:24沸羊羊
日期:2015-03-04 14:51:522015年新春福章
日期:2015-03-06 11:57:31
15#
发表于 2008-11-28 15:25 | 只看该作者
学习了,就是为了增加利用索引的机会啊。

使用道具 举报

回复
论坛徽章:
38
2010新春纪念徽章
日期:2010-01-04 08:33:082012新春纪念徽章
日期:2012-02-13 15:12:252012新春纪念徽章
日期:2012-02-13 15:12:252012新春纪念徽章
日期:2012-02-13 15:12:252012新春纪念徽章
日期:2012-02-13 15:12:252012新春纪念徽章
日期:2012-02-13 15:12:25版主2段
日期:2012-05-15 15:24:11优秀写手
日期:2013-12-18 09:29:08马上有车
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14
16#
发表于 2008-11-29 19:24 | 只看该作者
的确是一个很不错的方法,值得学习。

使用道具 举报

回复
论坛徽章:
2
ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:44CTO参与奖
日期:2009-01-15 11:42:46
17#
发表于 2008-12-7 10:49 | 只看该作者
学习了,谢谢

使用道具 举报

回复
论坛徽章:
2
ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:44CTO参与奖
日期:2009-01-15 11:42:46
18#
发表于 2008-12-7 11:48 | 只看该作者
create index idx_prodd on prodd (status,'1');
刚刚试了下,这会在每个叶节点上都增加一个为‘1’的值,所以记录数很大的时候应该会增加不少索引所占的空间,使用时要衡量利弊。
dump的内容。
row#0[8020] flag: ------, lock: 0, len=16
col 0; len 4; (4):  74 65 73 74   \\该列原值
col 1; len 1; (1):  31    \\31=0011 0001=49  chr(49)=1
col 2; len 6; (6):  01 00 01 ae 00 03  \\ rowid 无object_id
row#1[8006] flag: ------, lock: 0, len=14
col 0; len 2; (2):  74 6a
col 1; len 1; (1):  31
col 2; len 6; (6):  01 00 01 ae 00 02
row#2[7991] flag: ------, lock: 0, len=15
col 0; len 3; (3):  74 6d 6a
col 1; len 1; (1):  31
col 2; len 6; (6):  01 00 01 ae 00 00
row#3[7979] flag: ------, lock: 0, len=12
col 0; NULL
col 1; len 1; (1):  31
col 2; len 6; (6):  01 00 01 ae 00 01
row#4[7967] flag: ------, lock: 0, len=12
col 0; NULL
col 1; len 1; (1):  31
col 2; len 6; (6):  01 00 01 ae 00 04
----- end of leaf block dump -----


其实这也就是人为的将包含null的列的单列索引转换为了该列与一个常数‘1’所组成的复合索引。

[ 本帖最后由 beybey911 于 2008-12-7 11:54 编辑 ]

使用道具 举报

回复
论坛徽章:
10000
绿钻
日期:2016-02-22 15:43:08绿钻
日期:2016-03-01 18:19:01绿钻
日期:2016-02-22 15:43:08绿钻
日期:2016-03-01 18:19:01绿钻
日期:2015-12-16 18:42:35绿钻
日期:2015-12-11 00:18:01绿钻
日期:2015-09-10 13:05:08绿钻
日期:2015-12-11 00:18:01绿钻
日期:2015-09-10 13:05:08绿钻
日期:2015-09-10 13:05:08
19#
发表于 2008-12-7 16:59 | 只看该作者
学习了,顶

使用道具 举报

回复
论坛徽章:
3742
生肖徽章2007版:羊
日期:2013-02-08 10:53:41生肖徽章2007版:羊
日期:2013-02-08 10:53:41生肖徽章2007版:羊
日期:2013-02-08 10:53:41生肖徽章2007版:羊
日期:2013-02-08 10:53:41生肖徽章2007版:羊
日期:2013-02-08 10:53:41生肖徽章2007版:羊
日期:2013-02-08 10:53:41生肖徽章2007版:羊
日期:2013-02-08 10:53:41生肖徽章2007版:羊
日期:2013-02-08 10:53:41生肖徽章2007版:羊
日期:2013-02-08 10:53:41生肖徽章2007版:羊
日期:2013-02-08 10:53:41
20#
发表于 2008-12-8 14:24 | 只看该作者
有创意的想法 学习了

使用道具 举报

回复

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

本版积分规则 发表回复

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