17,090
社区成员
发帖
与我相关
我的任务
分享
OPER@tl> select * from test;
AAA BBB CCC
-------------------- -------------------- ----------
张 一 1
一 张 2
张 张 3
多少 张 4
少 发 5
OPER@tl> create index ind_test1 on test(aaa);
索引已创建。
OPER@tl> create index ind_test2 on test(bbb);
索引已创建。
OPER@tl> set autot traceonly
OPER@tl> select * from test
2 where rowid in(select rn from (
3 (select /*+ index(test ind_test1) */
4 aaa,rowid rn
5 from test
6 where aaa like '%张%'
7 union
8 select /*+ index(test ind_test2) */
9 bbb,rowid rn
10 from test
11 where bbb like '%张%')))
12 /
执行计划
----------------------------------------------------------
Plan hash value: 4114598729
-----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 20 | 6 (50)| 00:00:01 |
| 1 | NESTED LOOPS | | 1 | 20 | 6 (50)| 00:00:01 |
| 2 | VIEW | VW_NSO_1 | 2 | 24 | 4 (50)| 00:00:01 |
| 3 | HASH UNIQUE | | 1 | 24 | | |
| 4 | VIEW | | 2 | 24 | 4 (50)| 00:00:01 |
| 5 | SORT UNIQUE | | 2 | 16 | 4 (75)| 00:00:01 |
| 6 | UNION-ALL | | | | | |
|* 7 | INDEX FULL SCAN | IND_TEST1 | 1 | 8 | 1 (0)| 00:00:01 |
|* 8 | INDEX FULL SCAN | IND_TEST2 | 1 | 8 | 1 (0)| 00:00:01 |
| 9 | TABLE ACCESS BY USER ROWID| TEST | 1 | 8 | 1 (0)| 00:00:01 |
-----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
7 - filter("AAA" LIKE '%张%')
8 - filter("BBB" LIKE '%张%')
统计信息
----------------------------------------------------------
0 recursive calls
0 db block gets
6 consistent gets
0 physical reads
0 redo size
602 bytes sent via SQL*Net to client
400 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
4 rows processed
OPER@tl> select * from test
2 where rowid in(select rn from (
3 (select /*+ index_ffs(test ind_test1) */
4 aaa,rowid rn
5 from test
6 where aaa like '%张%'
7 union
8 select /*+ index_ffs(test ind_test1) */
9 bbb,rowid rn
10 from test
11 where bbb like '%张%')))
12 /
执行计划
----------------------------------------------------------
Plan hash value: 2460625359
-----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 20 | 7 (43)| 00:00:01 |
| 1 | NESTED LOOPS | | 1 | 20 | 7 (43)| 00:00:01 |
| 2 | VIEW | VW_NSO_1 | 2 | 24 | 5 (40)| 00:00:01 |
| 3 | HASH UNIQUE | | 1 | 24 | | |
| 4 | VIEW | | 2 | 24 | 5 (40)| 00:00:01 |
| 5 | SORT UNIQUE | | 2 | 16 | 5 (60)| 00:00:01 |
| 6 | UNION-ALL | | | | | |
|* 7 | INDEX FAST FULL SCAN | IND_TEST1 | 1 | 8 | 2 (0)| 00:00:01 |
|* 8 | INDEX FULL SCAN | IND_TEST2 | 1 | 8 | 1 (0)| 00:00:01 |
| 9 | TABLE ACCESS BY USER ROWID| TEST | 1 | 8 | 1 (0)| 00:00:01 |
-----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
7 - filter("AAA" LIKE '%张%')
8 - filter("BBB" LIKE '%张%')
统计信息
----------------------------------------------------------
1 recursive calls
0 db block gets
8 consistent gets
0 physical reads
0 redo size
602 bytes sent via SQL*Net to client
400 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
4 rows processed
OPER@tl> select * from test where aaa like '%张%' or bbb like '%张%';
执行计划
----------------------------------------------------------
Plan hash value: 1357081020
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 8 | 3 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| TEST | 1 | 8 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("AAA" LIKE '%张%' OR "BBB" LIKE '%张%')
统计信息
----------------------------------------------------------
0 recursive calls
0 db block gets
8 consistent gets
0 physical reads
0 redo size
602 bytes sent via SQL*Net to client
400 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
4 rows processed