- 最后登录
- 2015-5-21
- 在线时间
- 100 小时
- 威望
- 0
- 金钱
- 345
- 注册时间
- 2012-12-19
- 阅读权限
- 10
- 帖子
- 99
- 精华
- 0
- 积分
- 0
- UID
- 824
|
1#
发表于 2013-1-10 09:31:05
|
查看: 3851 |
回复: 6
帖子有说
通常情况下, 用UNION替换WHERE子句中的OR将会起到较好的效果. 对索引列使用OR将造成全表扫描. 注意, 以上规则只针对多个索引列有效. 如果有column没有被索引, 查询效率可能会因为你没有选择OR而降低。
我就实验了下
explain plan for (select * from Ar_Cash_Receipts_All cr where cr.org_id=103 or cr.org_id=104)
1
2 -------------------------------------------------------------------------------
3 | Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
4 -------------------------------------------------------------------------------
5 | 0 | SELECT STATEMENT | | 98191 | 20M| 1594 (3)|
6 |* 1 | TABLE ACCESS FULL| AR_CASH_RECEIPTS_ALL | 98191 | 20M| 1594 (3)|
7 -------------------------------------------------------------------------------
8
9 Predicate Information (identified by operation id):
10 ---------------------------------------------------
11
12 1 - filter("CR"."ORG_ID"=103 OR "CR"."ORG_ID"=104)
13
14 Note
15 -----
16 - 'PLAN_TABLE' is old version
explain plan for (select * from Ar_Cash_Receipts_All cr where cr.org_id=103
union select * from Ar_Cash_Receipts_All cr where cr.org_id=104)
1
2 -----------------------------------------------------------------------------------------
3 | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)|
4 -----------------------------------------------------------------------------------------
5 | 0 | SELECT STATEMENT | | 98190 | 20M| | 7777 (51)|
6 | 1 | SORT UNIQUE | | 98190 | 20M| 80M| 7777 (51)|
7 | 2 | UNION-ALL | | | | | |
8 |* 3 | TABLE ACCESS FULL| AR_CASH_RECEIPTS_ALL | 49095 | 10M| | 1590 (2)|
9 |* 4 | TABLE ACCESS FULL| AR_CASH_RECEIPTS_ALL | 49095 | 10M| | 1590 (2)|
10 -----------------------------------------------------------------------------------------
11
12 Predicate Information (identified by operation id):
13 ---------------------------------------------------
14
15 3 - filter("CR"."ORG_ID"=103)
16 4 - filter("CR"."ORG_ID"=104)
17
18 Note
19 -----
20 - 'PLAN_TABLE' is old version
语句挺简单的,但是没看出来第二条比第一条强太多啊,有能帮忙解释下的么?感激不尽
注:只是实验所以是select * 的 |
|