select a.exec_sqn, a.dept_code
from ipmonmex a, lis_test_reg b
where a.exec_sqn = b.exec_sqn
and b.barcode = '1002052716' 执行速度的2分钟左右,实在是太慢了,但是也是用到了索引,a.exec_sqn是唯一索引,b.exec_sqn是普通索引。 执行计划如下 SELECT STATEMENT, GOAL = CHOOSE 耗费=1267 基数=77072 字节=4084816
MERGE JOIN 耗费=1267 基数=77072 字节=4084816
TABLE ACCESS BY GLOBAL INDEX ROWID 对象所有者=TLHIS 对象名称=IPMONMEX 耗费=826 基数=7707246 字节=107901444
INDEX FULL SCAN 对象所有者=TLHIS 对象名称=PK_IPMONMEX 耗费=26 基数=7707246
SORT JOIN 耗费=441 基数=63901 字节=2492139
INDEX RANGE SCAN 对象所有者=TLHIS 对象名称=LIS 耗费=2 基数=63901 字节=2492139
from ipmonmex a, lis_test_reg b
where a.exec_sqn = b.exec_sqn
and b.barcode = '1002052716' 执行速度的2分钟左右,实在是太慢了,但是也是用到了索引,a.exec_sqn是唯一索引,b.exec_sqn是普通索引。 执行计划如下 SELECT STATEMENT, GOAL = CHOOSE 耗费=1267 基数=77072 字节=4084816
MERGE JOIN 耗费=1267 基数=77072 字节=4084816
TABLE ACCESS BY GLOBAL INDEX ROWID 对象所有者=TLHIS 对象名称=IPMONMEX 耗费=826 基数=7707246 字节=107901444
INDEX FULL SCAN 对象所有者=TLHIS 对象名称=PK_IPMONMEX 耗费=26 基数=7707246
SORT JOIN 耗费=441 基数=63901 字节=2492139
INDEX RANGE SCAN 对象所有者=TLHIS 对象名称=LIS 耗费=2 基数=63901 字节=2492139
from ipmonmex a, lis_test_reg b
where a.exec_sqn = b.exec_sqn
and b.barcode = '1002052716' 就这么一句要两分钟?那分别对ipmonmex , lis_test_reg 表的exec_sqn 列建立索引.如果还不行,对lis_test_reg 的 barcode 列再连接索引.
http://blog.csdn.net/tianlesoftware/archive/2009/10/15/4672023.aspx
------------------------------------------------------------------------------
Blog: http://blog.csdn.net/tianlesoftware
网上资源: http://tianlesoftware.download.csdn.net
相关视频:http://blog.csdn.net/tianlesoftware/archive/2009/11/27/4886500.aspx
Q Q 群:62697716
lis_test_reg表 2564284行ipmonmex , lis_test_reg 表的exec_sqn 已经建立了索引,索引类型分别是 唯一索引 和 普通索引lis_test_reg表的 barcode 也有索引,索引的类型是 普通索引//1
select b.exec_sqn
from lis_test_reg b
where b.barcode = '1002052716'
速度非常快 用不到0.1秒//2
select a.exec_sqn, a.inpatient_no
from ipmonmex a
where a.exec_sqn in ('2009120117227165','2009120117227167') //手工具体赋的值
速度非常快 用不到0.1秒//3
select a.exec_sqn,a.nurse_cell_code
from ipmonmex a
where a.exec_sqn in
(select b.exec_sqn from lis_test_reg b where b.barcode = '1002052716')如果是这样的话,速度就是非常慢了,用两分钟左右。
//4
select a.exec_sqn, a.dept_code
from ipmonmex a, lis_test_reg b
where a.exec_sqn = b.exec_sqn
and b.barcode = '1002052716' 如果是这样的话,速度就是非常慢了,用两分钟左右。比较了一下子执行计划,3,4的sql
ipmonmex表用到的是exec_sqn列的索引,扫描方法是INDEX FULL SCAN
而执行 2的sql
ipmonmex表用到的是exec_sqn列的索引,扫描方法是INDEX RANGE SCAN有没有什么办法可以强制索引的扫描方法。
楼主把SQL 改一下试试. select a.exec_sqn from ipmonmex a where a.exec_sqn in (select b.exec_sqn from lis_test_reg b and b.barcode = '1002052716');之前的SQL 效率太低了..
------------------------------------------------------------------------------
Blog: http://blog.csdn.net/tianlesoftware
网上资源: http://tianlesoftware.download.csdn.net
相关视频:http://blog.csdn.net/tianlesoftware/archive/2009/11/27/4886500.aspx
Q Q 群:62697716
where exists (select 'X' from
lis_test_reg b where b.exec_sqn=a.exec_sqn and b.barcode = '1002052716');
select /*+ no_merge(b) leading(b) */ a.exec_sqn, a.dept_code
from ipmonmex a, (select exec_sqn from lis_test_reg where b.barcode = '1002052716') b
where a.exec_sqn = b.exec_sqn;
from ipmonmex a, (select exec_sqn from lis_test_reg where barcode = '1002052716') b
where a.exec_sqn = b.exec_sqn;
试一下这样效率行不行。。
速度还是不行,ipmonmex表变成了全表扫描。
from ipmonmex a, (select exec_sqn,barcode from lis_test_reg where barcode='1002052716')b
where a.exec_sqn = b.exec_sqn