Prediceate(谓词):一个查询中的WHERE限制条件。 在查看执行计划的信息中,经常会看到两个谓词filter和access
,它们的区别是什么,理解了这个两个词对我们解读Oracle的执行计划信息会有所帮助。 简单地说,执行计划如果显示是access,就表示这个谓词条件的值将会影响数据的访问路径(表还是索引),而filter表示谓词条件的值并不会影响数据访问路径,只起到过滤的作用。 二、举例说明:
----创建一张表echo---- 1 SQL> create table echo as select * from dba_objects; 2 3 Table created. 4 5 SQL> set autotrace trace exp; 6 SQL> set linesize 150; 7 SQL> select * from echo where object_id=1000; 8 9 Execution Plan 10 ---------------------------------------------------------- 11 Plan hash value: 642657756 12 13 -------------------------------------------------------------------------- 14 | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | 15 -------------------------------------------------------------------------- 16 | 0 | SELECT STATEMENT | | 12 | 2484 | 289 (1)| 00:00:04 | 17 |* 1 | TABLE ACCESS FULL| ECHO | 12 | 2484 | 289 (1)| 00:00:04 | 18 -------------------------------------------------------------------------- 19 20 Predicate Information (identified by operation id): 21 --------------------------------------------------- 22 23 1 - filter("OBJECT_ID"=1000) ----因为表echo没有创建索引,执行计划没有选择数据访问路径的余地,谓词条件在这里只是起到数据过滤的作用,所以使用了filter。 24 25 Note 26 ----- 27 - dynamic sampling used for this statement (level=2) 28 ----创建索引的情况---- 29 SQL> create index echo_ind on echo(object_id); 30 31 Index created. 32 33 SQL> select * from echo where object_id=1000; 34 35 Execution Plan 36 ---------------------------------------------------------- 37 Plan hash value: 1345159126 38 39 ---------------------------------------------------------------------------------------- 40 | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | 41 ---------------------------------------------------------------------------------------- 42 | 0 | SELECT STATEMENT | | 1 | 207 | 2 (0)| 00:00:01 | 43 | 1 | TABLE ACCESS BY INDEX ROWID| ECHO | 1 | 207 | 2 (0)| 00:00:01 | 44 |* 2 | INDEX RANGE SCAN | ECHO_IND | 1 | | 1 (0)| 00:00:01 | 45 ---------------------------------------------------------------------------------------- 46 47 Predicate Information (identified by operation id): 48 --------------------------------------------------- 49 50 2 - access("OBJECT_ID"=1000) ----谓词条件影响到数据访问的路径,选择了索引,所以用access。 51 52 Note 53 ----- 54 - dynamic sampling used for this statement (level=2)
时间: 2024-12-28 20:42:50