这么一句话,到底慢在那里啊?

[复制链接]
查看11 | 回复9 | 2011-5-7 01:45:08 | 显示全部楼层 |阅读模式
select t.某某字段,t.某某字段,t.某某字段,t.某某字段
from 某某表的名字 t where
t.sendunit like '4304211%' and t.operatestatus='40'
and substr(t.changetype,1,1)'3' and substr(t.changetype,1,1)'4'
应为业务需要,因此t.sendunit like '4304211%' ,这里需要用like,没有办法,业务需要
我认为是t.sendunit是没有建立缩影的原因导致查询任何一条记录,起码10秒以上,而数据库管理员给我的答复是:过多使用oracle的substr函数导致,不知道到底是什么原因啊?
回复

使用道具 举报

千问 | 2011-5-7 01:45:08 | 显示全部楼层
对t.sendunit和t.changetype建函数索引也许有帮助
回复

使用道具 举报

千问 | 2011-5-7 01:45:08 | 显示全部楼层
我也是这么认为在T.SENDUNIT上加INDEX比较好.我原来的一个查询就是在关键条件上加了索引变快了很多.SUBSTR不会占用太多的时间的.
回复

使用道具 举报

千问 | 2011-5-7 01:45:08 | 显示全部楼层
For this select ,I suggest to build a index based on
(operatestatus,sendunit).
回复

使用道具 举报

千问 | 2011-5-7 01:45:08 | 显示全部楼层
如果没记错的话。
使用substr的话索引会失效的。
回复

使用道具 举报

千问 | 2011-5-7 01:45:08 | 显示全部楼层
看看你SQL的执行计划
回复

使用道具 举报

千问 | 2011-5-7 01:45:08 | 显示全部楼层
t.sendunit like '4304211%' and t.operatestatus='40'
位置互换
回复

使用道具 举报

千问 | 2011-5-7 01:45:08 | 显示全部楼层
select t.某某字段,t.某某字段,t.某某字段,t.某某字段
from 某某表的名字 t where
t.sendunit between '4304211' and '4304212' and t.operatestatus='40'
and substr(t.changetype,1,1)'3' and substr(t.changetype,1,1)'4'
回复

使用道具 举报

千问 | 2011-5-7 01:45:08 | 显示全部楼层
select语句优化有一个原则,就是Where条件从上到下,应该由复杂到简单。因为系统编译执行的时候是从最后一个条件开始运行。因此,最后一个条件应该是最简单的,依次反推回来!另外like也要少用。试试这个:
select t.某某字段,t.某某字段,t.某某字段,t.某某字段
from 某某表的名字
where
substr(t.sendunit,1,7) = '4304211'
and substr(t.changetype,1,1)'3'
and substr(t.changetype,1,1)'4'
and t.operatestatus='40'
回复

使用道具 举报

千问 | 2011-5-7 01:45:08 | 显示全部楼层
那是不是可以这样些呢:
select t.某某字段,t.某某字段,t.某某字段,t.某某字段
from 某某表的名字
where
substr(t.sendunit,1,7) = '4304211'and
substr(t.changetype,1,1) not in ('3','4') and
t.operatestatus='40'
呵呵,初学者,多请教
回复

使用道具 举报

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

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行