- 最后登录
- 2014-11-25
- 在线时间
- 19 小时
- 威望
- 0
- 金钱
- 54
- 注册时间
- 2014-8-16
- 阅读权限
- 10
- 帖子
- 22
- 精华
- 0
- 积分
- 0
- UID
- 1996
|
1#
发表于 2014-8-25 16:16:22
|
查看: 4981 |
回复: 11
本帖最后由 bayannur 于 2014-8-26 17:20 编辑
数据库版本10.2.5,linux主机,64G内存
以下两个执行计划,第一个为普通用户(有dba权限),第二个为sys用户。同样一条sql,为什么会产生两个执行计划?
第一个执行计划对一个历史表采取了全表扫,用时很长,估算几个小时以上。
第二个执行计划对该表走了索引范围扫描,用于不到1秒。
事实证明第二个执行计划是正确的,为什么普通用户不走索引呢?我该怎么优化一下,大家给支支招。
对应的10046已上传
sql如下:
select b.* from cpt_hforderinfo_his a, cpt_orderinfo_his b, dual where 1 = 1 and a.cpt_serialid = b.cpt_serialid and b.partner_orderid in (select * from table(mvadmin.myconvert('AB011408072139208118,AB011408072139208156,AB011407472139208118',',')));cpt_orderinfo_his 为分区表,按时间每月分区,大约1亿条数据
-------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
-------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1559K| 2193M| 751K (5)| 02:30:16 | | |
| 1 | NESTED LOOPS | | 1559K| 2193M| 751K (5)| 02:30:16 | | |
|* 2 | HASH JOIN RIGHT SEMI | | 4828K| 6695M| 751K (5)| 02:30:14 | | |
| 3 | COLLECTION ITERATOR PICKLER FETCH| MYCONVERT | | | | | | |
| 4 | PARTITION RANGE ALL | | 482M| 652G| 745K (5)| 02:29:06 | 1 | 99 |
| 5 | TABLE ACCESS FULL | CPT_ORDERINFO_HIS | 482M| 652G| 745K (5)| 02:29:06 | 1 | 99 |
|* 6 | INDEX RANGE SCAN | INDEX_HFORDERHIS_CPT_SERIALID | 1 | 21 | 1 (0)| 00:00:01 | | |
-------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
---------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1559K| 2268M| 231K (1)| 00:46:20 | | |
| 1 | NESTED LOOPS | | 1559K| 2268M| 231K (1)| 00:46:20 | | |
| 2 | NESTED LOOPS | | 4828K| 6925M| 231K (1)| 00:46:19 | | |
| 3 | VIEW | VW_NSO_1 | 8168 | 414K| 24 (0)| 00:00:01 | | |
| 4 | HASH UNIQUE | | 1 | 16336 | | | | |
| 5 | COLLECTION ITERATOR PICKLER FETCH| MYCONVERT | | | | | | |
| 6 | PARTITION RANGE ALL | | 4828K| 6685M| 231K (1)| 00:46:19 | 1 | 99 |
| 7 | TABLE ACCESS BY LOCAL INDEX ROWID | CPT_ORDERINFO_HIS | 4828K| 6685M| 231K (1)| 00:46:19 | 1 | 99 |
|* 8 | INDEX RANGE SCAN | INDEX_ORDERINFOHIS_PARTNER_OD | 1931K| | 65 (11)| 00:00:01 | 1 | 99 |
|* 9 | INDEX RANGE SCAN | INDEX_HFORDERHIS_CPT_SERIALID | 1 | 21 | 1 (0)| 00:00:01 | | |
--------------------------------------------------------------------------------------------------------------------------------------- |
|