27,579
社区成员
发帖
与我相关
我的任务
分享
调用过程时候,比如日期变量
过程中,用另外变量替换了一下。
set @rq11=substring(@rq1,1,4)||'/'||substring(@rq1,5,2)||'/'||substring(@rq1,7,2)||' 00:00:00:000'
set @rq22=substring(@rq2,1,4)||'/'||substring(@rq2,5,2)||'/'||substring(@rq2,7,2)||' 23:59:59:999'
这一替换,导致最后查询时候。rq列始终不走索引,走表扫描。
rq>=@rq11 and rq<=@rq22
必须强制指定rq索引才可以。统计值已经更新到最新
测试了下,不用新变量替换,就可以正常走rq索引。
哪位有研究的。?
insert #tmp
select a.djlx,a.dh,a.lx,a.kh,a.je
from ZQ_IV_XSFQ_ZQ_H a ,CM_ZQ_SET_HDDQ_H b
where a.djlx='ZQJH' and a.dh=b.dh and a.str >= @str1 and a.str <= @str2
and b.oprid>=@oprid1 and b.oprid<=@oprid2
and b.adtrs>=@rq11 and b.adtrs<=@rq22
[/quote]
要不更新一下表的统计信息,sybase中应该也有吧[/quote]
统计 信息,都更新到最新了
表数据也不大,前表32w,后表79W[/quote]
sybase能强制用索引不insert #tmp
select a.djlx,a.dh,a.lx,a.kh,a.je
from ZQ_IV_XSFQ_ZQ_H a ,CM_ZQ_SET_HDDQ_H b
where a.djlx='ZQJH' and a.dh=b.dh and a.str >= @str1 and a.str <= @str2
and b.oprid>=@oprid1 and b.oprid<=@oprid2
and b.adtrs>=@rq11 and b.adtrs<=@rq22
[/quote]
要不更新一下表的统计信息,sybase中应该也有吧[/quote]
统计 信息,都更新到最新了
表数据也不大,前表32w,后表79Winsert #tmp
select a.djlx,a.dh,a.lx,a.kh,a.je
from ZQ_IV_XSFQ_ZQ_H a ,CM_ZQ_SET_HDDQ_H b
where a.djlx='ZQJH' and a.dh=b.dh and a.str >= @str1 and a.str <= @str2
and b.oprid>=@oprid1 and b.oprid<=@oprid2
and b.adtrs>=@rq11 and b.adtrs<=@rq22
[/quote]
要不更新一下表的统计信息,sybase中应该也有吧insert #tmp
select a.djlx,a.dh,a.lx,a.kh,a.je
from ZQ_IV_XSFQ_ZQ_H a ,CM_ZQ_SET_HDDQ_H b
where a.djlx='ZQJH' and a.dh=b.dh and a.str >= @str1 and a.str <= @str2
and b.oprid>=@oprid1 and b.oprid<=@oprid2
and b.adtrs>=@rq11 and b.adtrs<=@rq22
是sybase ase
单个语句,变量值带进去,执行计划没有问题,1秒出结果。
一旦过程里,就走表扫描,要8分钟出结果
调用语句
execute dbo.szy_test;1 @empid = '12090227', @oprid1 = '', @oprid2 = '99999999', @rq1= '20140104', @rq2 = '20140104', @str1 = '8270', @str2 = '8270'
部分语句:
set @rq11=substring(@rq1,1,4)||'/'||substring(@rq1,5,2)||'/'||substring(@rq1,7,2)||' 00:00:00:000'
set @rq22=substring(@rq2,1,4)||'/'||substring(@rq2,5,2)||'/'||substring(@rq2,7,2)||' 23:59:59:999'
insert #tmp
select a.djlx,a.dh,a.lx,a.kh,a.je
from ZQ_IV_XSFQ_ZQ a ,CM_ZQ_SET_HDDQ_H b
where a.djlx='ZQJH' and a.dh=b.dh and a.str >= @str1 and a.str <= @str2
and b.adtrs>=@rq11 and b.adtrs<=@rq22
and b.oprid>=@oprid1 and b.oprid<=@oprid2
执行计划:
STEP 1
The type of query is INSERT.
The update mode is direct.
FROM TABLE
CM_ZQ_SET_HDDQ_H
b
Nested iteration.
Table Scan.
Forward scan.
Positioning at start of table.
Using I/O Size 16 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.
FROM TABLE
ZQ_IV_XSFQ_ZQ
a
Nested iteration.
Using Clustered Index.
Index : PK_ZQ_IV_XSFQ_ZQ
Forward scan.
Positioning by key.
Keys are:
djlx ASC
dh ASC
str ASC
Using I/O Size 4 Kbytes for index leaf pages.
With LRU Buffer Replacement Strategy for index leaf pages.
Using I/O Size 4 Kbytes for data pages.
With LRU Buffer Replacement Strategy for data pages.
TO TABLE
#tmp
Using I/O Size 4 Kbytes for data pages.