如果where条件列查询目标SQL返回数据量比较少时,可以使用创建索引的方式来减少全表扫描的消耗。
例子:以ta表为例,在object_id上创建单键值B-Tree索引:
创建测试表:
create table ta as select * from dba_objects;
创建索引:
create index idx_object_id on ta( object_id) ;
查看执行计划:
select /*+ gather_plan_statistics */
*
from ta
where ta.object_id is null;
SQL> select * from table(dbms_xplan.display_cursor(null,0,'ALLSTATS LAST'));
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------------------------------
SQL_ID 88gbh334ujqz7, child number 0
-------------------------------------
select /*+ gather_plan_statistics */ * from ta where ta.object_id
is null
Plan hash value: 824468716
---------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads |
---------------------------
列值有NULL值创建索引
最新推荐文章于 2024-05-23 11:14:25 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)