oracle查询效率
表,都创建索引了,但是查询速度依然很慢,高手请指教。
- SQL code
select sx201008.stmc stmc,(nvl(sx201008.i_kaizhangsl,0)+nvl(sx201009.i_kaizhangsl,0)+nvl(sx201010.i_kaizhangsl,0)+nvl(sx201011.i_kaizhangsl,0)) i_kaizhangsl,'预警分析' title,'2010-11-29' rq,'徐州首创' sx ,'6798023' jhsl,'80' red,'100' yellow from (select '徐州首创' stmc,0+sum(i_zongyongl) i_kaizhangsl from IBCS_XZ.ZW_YINGYEZ201008 a inner join IBCS_XZ.ZW_YINGYEZ_ZB201008 b on a.i_feeid=b.i_feeid where a.i_jlzt=0 and i_y*100+i_m=201008 and b.i_jlzt=0 and i_feiyongdlbh=580 and i_xiaozhang<>20) sx201008 left join (select '徐州首创' stmc,450776+sum(i_zongyongl) i_kaizhangsl from IBCS_XZ.ZW_YINGYEZ201009 a inner join IBCS_XZ.ZW_YINGYEZ_ZB201009 b on a.i_feeid=b.i_feeid where a.i_jlzt=0 and i_y*100+i_m=201009 and b.i_jlzt=0 and i_feiyongdlbh=580 and i_xiaozhang<>20) sx201009 on sx201009.stmc=sx201008.stmc left join (select '徐州首创' stmc,-17120+sum(i_zongyongl) i_kaizhangsl from IBCS_XZ.ZW_YINGYEZ201010 a inner join IBCS_XZ.ZW_YINGYEZ_ZB201010 b on a.i_feeid=b.i_feeid where a.i_jlzt=0 and i_y*100+i_m=201010 and b.i_jlzt=0 and i_feiyongdlbh=580 and i_xiaozhang<>20) sx201010 on sx201010.stmc=sx201008.stmc left join (select '徐州首创' stmc,sum(i_zongyongl)-16506 i_kaizhangsl from IBCS_XZ.zw_yingyez a inner join IBCS_XZ.zw_yingyez_zb b on a.i_feeid=b.i_feeid where a.i_jlzt=0 and i_y*100+i_m=201011 and b.i_jlzt=0 and i_feiyongdlbh=580 and i_xiaozhang<>20) sx201011 on sx201011.stmc=sx201008.stmc union all select sx201003.stmc stmc,(nvl(sx201003.i_kaizhangsl,0)+nvl(sx201004.i_kaizhangsl,0)+nvl(sx201005.i_kaizhangsl,0)+nvl(sx201006.i_kaizhangsl,0)+nvl(sx201007.i_kaizhangsl,0)+nvl(sx201008.i_kaizhangsl,0)+nvl(sx201009.i_kaizhangsl,0)+nvl(sx201010.i_kaizhangsl,0)+nvl(sx201011.i_kaizhangsl,0)) i_kaizhangsl,'预警分析' title,'2010-11-29' rq,'铜陵首创' sx ,'43677613' jhsl,'80' red,'100' yellow from (select '铜陵首创' stmc,0+sum(i_zongyongl) i_kaizhangsl from IBCS_TL.ZW_YINGYEZ201003 a inner join IBCS_TL.ZW_YINGYEZ_ZB201003 b on a.i_feeid=b.i_feeid where a.i_jlzt=0 and i_y*100+i_m=201003 and b.i_jlzt=0 and i_feiyongdlbh=580 and i_xiaozhang<>20) sx201003 left join (select '铜陵首创' stmc,75278+sum(i_zongyongl) i_kaizhangsl from IBCS_TL.ZW_YINGYEZ201004 a inner join IBCS_TL.ZW_YINGYEZ_ZB201004 b on a.i_feeid=b.i_feeid where a.i_jlzt=0 and i_y*100+i_m=201004 and b.i_jlzt=0 and i_feiyongdlbh=580 and i_xiaozhang<>20) sx201004 on sx201004.stmc=sx201003.stmc left join (select '铜陵首创' stmc,142742+sum(i_zongyongl) i_kaizhangsl from IBCS_TL.ZW_YINGYEZ201005 a inner join IBCS_TL.ZW_YINGYEZ_ZB201005 b on a.i_feeid=b.i_feeid where a.i_jlzt=0 and i_y*100+i_m=201005 and b.i_jlzt=0 and i_feiyongdlbh=580 and i_xiaozhang<>20) sx201005 on sx201005.stmc=sx201003.stmc left join (select '铜陵首创' stmc,55950+sum(i_zongyongl) i_kaizhangsl from IBCS_TL.ZW_YINGYEZ201006 a inner join IBCS_TL.ZW_YINGYEZ_ZB201006 b on a.i_feeid=b.i_feeid where a.i_jlzt=0 and i_y*100+i_m=201006 and b.i_jlzt=0 and i_feiyongdlbh=580 and i_xiaozhang<>20) sx201006 on sx201006.stmc=sx201003.stmc left join (select '铜陵首创' stmc,-156033+sum(i_zongyongl) i_kaizhangsl from IBCS_TL.ZW_YINGYEZ201007 a inner join IBCS_TL.ZW_YINGYEZ_ZB201007 b on a.i_feeid=b.i_feeid where a.i_jlzt=0 and i_y*100+i_m=201007 and b.i_jlzt=0 and i_feiyongdlbh=580 and i_xiaozhang<>20) sx201007 on sx201007.stmc=sx201003.stmc left join (select '铜陵首创' stmc,82416+sum(i_zongyongl) i_kaizhangsl from IBCS_TL.ZW_YINGYEZ201008 a inner join IBCS_TL.ZW_YINGYEZ_ZB201008 b on a.i_feeid=b.i_feeid where a.i_jlzt=0 and i_y*100+i_m=201008 and b.i_jlzt=0 and i_feiyongdlbh=580 and i_xiaozhang<>20) sx201008 on sx201008.stmc=sx201003.stmc left join (select '铜陵首创' stmc,25169+sum(i_zongyongl) i_kaizhangsl from IBCS_TL.ZW_YINGYEZ201009 a inner join IBCS_TL.ZW_YINGYEZ_ZB201009 b on a.i_feeid=b.i_feeid where a.i_jlzt=0 and i_y*100+i_m=201009 and b.i_jlzt=0 and i_feiyongdlbh=580 and i_xiaozhang<>20) sx201009 on sx201009.stmc=sx201003.stmc left join (select '铜陵首创' stmc,-36730+sum(i_zongyongl) i_kaizhangsl from IBCS_TL.ZW_YINGYEZ201010 a inner join IBCS_TL.ZW_YINGYEZ_ZB201010 b on a.i_feeid=b.i_feeid where a.i_jlzt=0 and i_y*100+i_m=201010 and b.i_jlzt=0 and i_feiyongdlbh=580 and i_xiaozhang<>20) sx201010 on sx201010.stmc=sx201003.stmc left join (select '铜陵首创' stmc,44304+sum(i_zongyongl) i_kaizhangsl from IBCS_TL.zw_yingyez a inner join IBCS_TL.zw_yingyez_zb b on a.i_feeid=b.i_feeid where a.i_jlzt=0 and i_y*100+i_m=201011 and b.i_jlzt=0 and i_feiyongdlbh=580 and i_xiaozhang<>20) sx201011 on sx201011.stmc=sx201003.stmc
上面这种SQL,在sql server执行时间2S,在oracle执行要9S。
高手请指教..
[解决办法]
看到这样的SQL我就晕
如果数据大,9s也不慢啊!
我出一个报表都要要4-5分钟,你可想而知了。。。
[解决办法]
[解决办法]
没什么好怀疑Oracle的,既然选择了,就勇敢的去接受和信任吧
2000万数据量,才9s已经相当不错了!
你要相信Oracle的CBO优化模式。
[解决办法]
sql真晕 这么强悍的sql。好多年没写过了
[解决办法]
9S相当可以啦,你就满足吧
[解决办法]
[解决办法]
oracle除了建索引能加快速度外,还有调整查询条件的位置。
SQL语句执行是从右向左的,能过滤掉大批量数据的条件放在外层,也能加快查询速度
[解决办法]
奶奶的,客户这么叼啊! 那你可要有心理准备! 9秒说实话 可以啦。
[解决办法]
初来乍到 就是看看
[解决办法]
可以先创建一个联合视图,再进行查询,这样可能速度会快点。
[解决办法]
新手路过,过来看看!!!
[解决办法]
楼主可以考虑用hint自己调整sql的连接顺序或连接方式,
如:用no_query_transformation取消oracle对sql的优化,
用ordered把连接顺序调整为from后面从左向右,
如果是oltp系统,可以考虑用use_nl或use_hash等,
如果是数据仓库,可以考虑用use_merge
等等。
[解决办法]
强人啊
[解决办法]
[解决办法]
[解决办法]
[解决办法]
[解决办法]
2000W的数据9S数据正常了…
[解决办法]
[解决办法]
[解决办法]
如果你要对内联视图或子查询加hint的话,那最外层select最好加一个/*+ NO_QUERY_TRANSFORMATION*/,否则很可能所加的hint被ORACLE优化掉。
[解决办法]
那就组合一下试试:
- SQL code
select /*+ NO_QUERY_TRANSFORMATION ordered index(a,b)*/ sum(i_zongyongl) i_kaizhangsl from IBCS_TL.ZW_YINGYEZ_ZB201005 b, IBCS_TL.ZW_YINGYEZ201005 a where b.i_feiyongdlbh = 580 and b.i_jlzt = 0 and b.i_feeid = a.i_feeid and a.i_jlzt = 0 and a.i_xiaozhang <>2 0 and a.i_y = 2010 and a.i_m = 5;
[解决办法]
[解决办法]
对于复合索引,只有当查询条件有所有该索引引用的字段或有第一个字段的时候才有可能走索引,
你试试给i_feiyongdlbh这一个字段单独建个索引,再重试一下以前试过的那些SQL。
[解决办法]
把表结构帖出来给我。
[解决办法]
你直接把创建语句(包括表和所有的索引和主建的创建语句)帖出来。
只有字段有啥用啊?
[解决办法]
- SQL code
--试一下下面这个SQL:select /*+ ordered index(b)*/ sum(i_zongyongl) i_kaizhangsl from IBCS_TL.ZW_YINGYEZ_ZB201005 b, IBCS_TL.ZW_YINGYEZ201005 a where b.i_feiyongdlbh = 580 and b.i_jlzt = 0 and b.i_feeid = a.i_feeid and a.i_jlzt = 0 and a.i_xiaozhang <> 20 and a.i_y = 2010 and a.i_m = 5
[解决办法]
收集一下统计信息看?
[解决办法]
[解决办法]
[解决办法]
[解决办法]
[解决办法]
[解决办法]
老兄!
问题还没解决那?
你在深圳不?要是在的话,或许我可以周末去你们公司看一下——事先声明,我就算到了现场也不一定能搞定。
[解决办法]
调一下顺序,9S已经不错了
[解决办法]
[解决办法]
在sql server和oracle数据的存储分布,系统参数配置,等没有对比,所以运行时间也没有可比性.
只有在相同的存储条件下,才有比较的意义
[解决办法]
这么长的sql看着都累
要是我的话就用个中间表
另外你建立索引不一定用到索引,因为在索引列上面用到函数、不等于之类的会使索引失效