与B树索引相关的执行计划
发表于:2025-11-09 作者:千家信息网编辑
千家信息网最后更新 2025年11月09日,索引唯一扫描,索引范围扫描,索引全扫描,索引快速全扫描和索引跳跃式扫描。索引唯一扫描:SQL> create table employee(gender varchar2(1),employee_id
千家信息网最后更新 2025年11月09日与B树索引相关的执行计划
索引唯一扫描,索引范围扫描,索引全扫描,索引快速全扫描和索引跳跃式扫描。
索引唯一扫描:
SQL> create table employee(gender varchar2(1),employee_id number);Table created.SQL> insert into employee values('F',99);1 row created.SQL> insert into employee values('F',100);1 row created.SQL> insert into employee values('M',101);1 row created. SQL> insert into employee values('M',102);1 row created.SQL> insert into employee values('M',103);1 row created.SQL> insert into employee values('M',104);1 row created.SQL> insert into employee values('M',105);1 row created.SQL> insert into employee values('F',106);1 row created.SQL> commit;Commit complete.SQL> create unique index idx_unqi_emp on employee(employee_id);Index created.SQL> select * from employee where employee_id=100;G EMPLOYEE_ID- -----------F 100SQL> set lines 200 pagesize 1000SQL> select plan_table_output from table(dbms_xplan.display_cursor(null,null,'ALL'));PLAN_TABLE_OUTPUT---------------------------------------------------------------------------------SQL_IDbum8qv24s6tqp, child number 0-------------------------------------select * from employee where employee_id=100Plan hash value: 1037614268--------------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |--------------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | | | 1 (100)| || 1 | TABLE ACCESS BY INDEX ROWID| EMPLOYEE | 1 |15 | 1 (0)| 00:00:01 ||* 2 | INDEX UNIQUE SCAN | IDX_UNQI_EMP | 1 | | 0 (0)| |---------------------------------------------------------------------------------31 rows selected.索引范围扫描:
SQL> drop index idx_unqi_emp;Index dropped.SQL> create index idx_unqi_emp on employee(employee_id);Index created.SQL> select * from employee where employee_id=100;G EMPLOYEE_ID- -----------F 100SQL> select plan_table_output from table(dbms_xplan.display_cursor(null,null,'ALL'));PLAN_TABLE_OUTPUT-----------------------------------------------------------------------------------------------------------------------------------------SQL_IDbum8qv24s6tqp, child number 0select * from employee where employee_id=100Plan hash value: 407794244--------------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |--------------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | | | 2 (100)| || 1 | TABLE ACCESS BY INDEX ROWID| EMPLOYEE | 1 |15 | 2 (0)| 00:00:01 ||* 2 | INDEX RANGE SCAN | IDX_UNQI_EMP | 1 | | 1 (0)| 00:00:01 |--------------------------------------------------------------------------------------------
索引快速全扫描:
SQL> begin 2 for i in 1..5000 loop 3 insert into employee values('F',i); 4 end loop; 5 commit; 6 end; 7 /PL/SQL procedure successfully completed.SQL> begin 2 for i in 5001..10000 loop 3 insert into employee values('M',i); 4 end loop; 5 commit; 6 end; 7 /PL/SQL procedure successfully completed.
SQL> select gender,count(*) from employee group by gender;G COUNT(*)- ----------M5000F5000
BEGIN DBMS_STATS.GATHER_TABLE_STATS(ownname => 'SCOTT', tabname => 'EMPLOYEE', estimate_percent => 100, method_opt => 'for all columns size repeat', no_invalidate => FALSE, degree => 8, granularity => 'ALL', cascade => TRUE); END;
PL/SQL procedure successfully completed.SQL> set autot traceSQL> select employee_id from employee;10000 rows selected.Execution Plan----------------------------------------------------------Plan hash value: 2119105728------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 10000 | 40000 | 7 (0)| 00:00:01 || 1 | TABLE ACCESS FULL| EMPLOYEE | 10000 | 40000 | 7 (0)| 00:00:01 |------------------------------------------------------------------------------
提示走索引,无效,因为employee_id有null值:
SQL> create index idx_emp_1 on employee(employee_id);Index created.SQL> select /*+ index(employee idx_emp_1) */ employee_id from employee;10000 rows selected.Execution Plan----------------------------------------------------------Plan hash value: 2119105728------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 10000 | 40000 | 7 (0)| 00:00:01 || 1 | TABLE ACCESS FULL| EMPLOYEE | 10000 | 40000 | 7 (0)| 00:00:01 |------------------------------------------------------------------------------
建立组合索引,或许把employee_id限制为非空:
SQL> select /*+ index(employee idx_emp_1) */ employee_id from employee;10000 rows selected.Execution Plan----------------------------------------------------------Plan hash value: 438557521------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 10000 | 40000 | 25 (0)| 00:00:01 || 1 | INDEX FULL SCAN | IDX_EMP_1 | 10000 | 40000 | 25 (0)| 00:00:01 |------------------------------------------------------------------------------
索引跳跃扫描:SQL> create index idx_emp_1 on employee(gender,employee_id);Index created.SQL> select * from employee where employee_id=109;Execution Plan----------------------------------------------------------Plan hash value: 2039022311------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 1 | 6 | 3 (0)| 00:00:01 ||* 1 | INDEX SKIP SCAN | IDX_EMP_1 | 1 | 6 | 3 (0)| 00:00:01 |------------------------------------------------------------------------------Predicate Information (identified by operation id):--------------------------------------------------- 1 - access("EMPLOYEE_ID"=109) filter("EMPLOYEE_ID"=109)Statistics---------------------------------------------------------- 1 recursive calls 0 db block gets 6 consistent gets 3 physical reads 0 redo size 600 bytes sent via SQL*Net to client 524 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processed
索引
范围
提示
组合
限制
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
eda51k 软件开发区
服务器sas硬盘盒
数据库如何区分陈旧数据与新数据
冬奥会网络安全保障工作方案
织梦数据库设置密码
广西企业党建软件开发专业制作
网络安全与远程控制
网络安全的标准由谁制定
北京凤天优网络技术有限公司
软件开发使用合同范本
网络安全侦查故事
软件开发科研攻关
学习网络技术学什么
土地质量调查数据库建设
软件开发商授权投标
ibm数据库管理员好不好
大数据专业开设什么数据库
服务器管理员可以干点什么
网络安全设备介绍
正向代理服务器作用
如何判断数据库表是否有数据
香港服务器可以使用微信支付没
数据库中的主键怎么解释
安卓服务器开发语言
计算机网络安全知识大赛
新加坡服务器备案吗
南威网络安全
计算机技术和科学软件开发
王者一个号在两个服务器怎么看
数据库增删改查指令