高手看一下这句SQL是否可以再优化 急

hkzhou 2003-08-27 11:21:49
select khdm,
(case when
max(isnull(yy_xshkxx.xsxtrq,''))>=max(isnull(yy_xshkxx.hkrq,'*'))
then max(isnull(yy_xshkxx.xsxtrq,''))
else max(isnull(yy_xshkxx.hkrq,'*'))
end)
from yy_xshkxx (index pk_yy_xshkxx)
where isnull(yy_xshkxx.cdbz,'')=''
group by khdm
表yy_xshkxx有270万条数据,pk_yy_xshkxx是群集索引包含xsxtrq,hkrq,khdm
执行它我花了6分钟。请教一下可否再优化一下。把时间降下来。
showplan 显示为
The type of query is SELECT (into Worktable1).
GROUP BY
Evaluate Grouped MAXIMUM AGGREGATE.
Evaluate Grouped MAXIMUM AGGREGATE.


FROM TABLE
yy_xshkxx
Nested iteration.
Using Clustered Index.
Index : pk_yy_xshkxx
Ascending scan.
Positioning at start of table.
Using I/O Size 2 Kbytes.
With MRU Buffer Replacement Strategy.
TO TABLE
Worktable1.


...全文
18 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
tchatcha 2003-09-02
  • 打赏
  • 举报
回复
这样的语句不慢才怪呢
zyhlhx 2003-09-02
  • 打赏
  • 举报
回复
备份服务器只是一个程序,与 ASE 数据库服务是独立的,只要启动就可以
可以参考 数据库管理员指南

hkzhou 2003-09-02
  • 打赏
  • 举报
回复
我已经彻底放弃了。拿它没法
----------------------------------------------------------
对了,那位知道备份服务器怎么配置吗?令人汗颜,我们公司竟然没有设置备份服务器!!!!!!
或者有这方面的文章。。
谁帮我解决了这个问题。我再开贴给200分。不好意思我可用分现在也不富裕了!
hkzhou 2003-09-01
  • 打赏
  • 举报
回复
可惜没有覆盖索引得
zyhlhx 2003-08-29
  • 打赏
  • 举报
回复
最根本的办法还是考虑修改
select * from yy_xshkxx where isnull(yy_xshkxx.cdbz,'')=''
的查询速度

考虑修改应用设计吧
hkzhou 2003-08-29
  • 打赏
  • 举报
回复
请问如何更改
hkzhou 2003-08-28
  • 打赏
  • 举报
回复
cdbz不是群集索引字段
hkzhou 2003-08-28
  • 打赏
  • 举报
回复
select * from yy_xshkxx (index pk_yy_xshkxx)
where isnull(yy_xshkxx.cdbz,'')=''

肯定很慢 因为cdbz不为空的行很少 这样要检索出至少200万行出来
hkzhou 2003-08-28
  • 打赏
  • 举报
回复
xsxtrq,hkrq 在数据库中有空值,而改IO,老板肯定会不允许
brook_huang 2003-08-28
  • 打赏
  • 举报
回复
你看一下规则,是不是可以把max(isnull(yy_xshkxx.xsxtrq,''))和max(isnull(yy_xshkxx.hkrq,'*'))的isnull函数去掉。

zyhlhx 2003-08-28
  • 打赏
  • 举报
回复
先看看 select * from yy_xshkxx (index pk_yy_xshkxx)
where isnull(yy_xshkxx.cdbz,'')=''

需要多少时间 !!如果时间长,可以把isnull(yy_xshkxx.cdbz,'')=''
改成 where yy_xshkxx.cdbz is null or yy_xshkxx.cdbz = ''
另外 cdbz是不是索引字段? 如果在复合索引中,是不是第一个字段?

zyhlhx 2003-08-28
  • 打赏
  • 举报
回复
可以建立一个 16 K cache ,然后指定 用 16k i/o看看
zyhlhx 2003-08-28
  • 打赏
  • 举报
回复
不能怪服务器,你的查询采用的是 With MRU Buffer Replacement Strategy
数据一会就会被替换掉,又要做物理读呀
hkzhou 2003-08-28
  • 打赏
  • 举报
回复
晕 服务器太不稳定了 这次执行又花了很少时间
(SQL Server cpu time: 0 ms.
Table: yy_xshkxx scan count 1, logical reads: (regular=245291 apf=0 total=245291), physical reads: (regular=8 apf=25280 total=25288), apf IOs used=25280
Table: Worktable1 scan count 1, logical reads: (regular=2937075 apf=0 total=2937075), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Total writes for this command: 0

Execution Time 293.
SQL Server cpu time: 29300 ms. SQL Server elapsed time: 55596 ms.)
zyhlhx 2003-08-28
  • 打赏
  • 举报
回复
这种情况一般是表扫描

where isnull(yy_xshkxx.cdbz,'')=''

hkzhou 2003-08-27
  • 打赏
  • 举报
回复
我优化过,它开始是10分钟 降了4分钟。但是感觉时间还是太久。实在水平有限,我看不出还哪里可以优化。还请高手不吝指教 谢谢

2,596

社区成员

发帖
与我相关
我的任务
社区描述
Sybase相关技术讨论区
社区管理员
  • Sybase社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧