sybase 查询优化(真是无语啊,请帮忙)
时间:2010-09-16
来源:互联网
有一张表A
(
id int
type int
)
该表中有10万条记录.
id是主键
type上建立有非聚集索引
另一张表B
(
type int
)
表B中有一部分表A中包含的type值.
要执行如下查询:
select A.id from A,B where A.type = B.type
现在我查询一次要5秒左右.但我希望它能在1秒内搞定(同样的语句不用任何调整oracle就是1秒左右,对SYBASE真是无语啊).
有没有什么办法来优化这个查询
PS:实际上的SQL语句是这样拼的(从一个视图和表里联合查询,我曾经把视图改成表,也是一样慢,FT,)
String hql1 = "select r.type, r." + regstateName + ", count(distinct r.regino) " +
"from com.bpcc.egov.gs12315.po.ViewRegdealinfo as r , com.bpcc.egov.gs12315.po.Infotransfer as i " +
"where i.sendate > ? and i.sendate < ? and r.currentdept = i.recdept and r.currentdept = ? " +
" and r.currentdept <> r.regdep " + state_sql +
" group by r.type, r." + regstateName + " order by r.type, r." + regstateName;
这个语句应该并不复杂,但sybase 就是需要7-8秒,而oracle只需1秒左右。。。。恨不得淹了sybase,,,
(
id int
type int
)
该表中有10万条记录.
id是主键
type上建立有非聚集索引
另一张表B
(
type int
)
表B中有一部分表A中包含的type值.
要执行如下查询:
select A.id from A,B where A.type = B.type
现在我查询一次要5秒左右.但我希望它能在1秒内搞定(同样的语句不用任何调整oracle就是1秒左右,对SYBASE真是无语啊).
有没有什么办法来优化这个查询
PS:实际上的SQL语句是这样拼的(从一个视图和表里联合查询,我曾经把视图改成表,也是一样慢,FT,)
String hql1 = "select r.type, r." + regstateName + ", count(distinct r.regino) " +
"from com.bpcc.egov.gs12315.po.ViewRegdealinfo as r , com.bpcc.egov.gs12315.po.Infotransfer as i " +
"where i.sendate > ? and i.sendate < ? and r.currentdept = i.recdept and r.currentdept = ? " +
" and r.currentdept <> r.regdep " + state_sql +
" group by r.type, r." + regstateName + " order by r.type, r." + regstateName;
这个语句应该并不复杂,但sybase 就是需要7-8秒,而oracle只需1秒左右。。。。恨不得淹了sybase,,,
作者: lqm11 发布时间: 2010-09-16
请把查询计划打出来看看,
set showplan on
set statistics io,time on
再执行你的SQL语句,看看有什么输出。
set showplan on
set statistics io,time on
再执行你的SQL语句,看看有什么输出。
作者: jarjar 发布时间: 2010-09-19
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28