iis服务器助手广告广告
返回顶部
首页 > 资讯 > 数据库 >索引系列九--索引特性之有序优化distinct
  • 935
分享到

索引系列九--索引特性之有序优化distinct

2024-04-02 19:04:59 935人浏览 独家记忆
摘要

--DISTINCT测试前的准备drop table t purge;create table t as select * from dba_objects;update t set o

--DISTINCT测试前的准备

drop table t purge;

create table t as select * from dba_objects;

update t set object_id=rownum;

alter table T modify OBJECT_ID not null;

update t set object_id=2;

update t set object_id=3 where rownum<=25000;

commit;





set linesize 1000

set autotrace traceonly


select  distinct object_id from t ;

执行计划

-----------------------------------------------------------------------------------

| Id  | Operation          | Name | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |

-----------------------------------------------------------------------------------

|   0 | SELECT STATEMENT   |      | 88780 |  1127K|       |   717   (1)| 00:00:09 |

|   1 |  HASH UNIQUE       |      | 88780 |  1127K|  1752K|   717   (1)| 00:00:09 |

|   2 |   TABLE ACCESS FULL| T    | 88780 |  1127K|       |   292   (1)| 00:00:04 |

-----------------------------------------------------------------------------------

统计信息

----------------------------------------------------------

          0  recursive calls

          0  db block gets

       1047  consistent gets

          0  physical reads

          0  redo size

        462  bytes sent via sql*Net to client

        416  bytes received via SQL*Net from client

          2  SQL*Net roundtrips to/from client

          0  sorts (memory)

          0  sorts (disk)

          2  rows processed




--为T表的object_id列建索引

create index idx_t_object_id on t(object_id);

set linesize 1000

set autotrace traceonly


select   distinct object_id from t ;

执行计划

--------------------------------------------------------------------------------------

| Id  | Operation          | Name            | Rows  | Bytes | Cost (%CPU)| Time     |

--------------------------------------------------------------------------------------

|   0 | SELECT STATEMENT   |                 | 88780 |  1127K|   582   (1)| 00:00:07 |

|   1 |  SORT UNIQUE NOSORT|                 | 88780 |  1127K|   582   (1)| 00:00:07 |

|   2 |   INDEX FULL SCAN  | IDX_T_OBJECT_ID | 88780 |  1127K|   158   (1)| 00:00:02 |

--------------------------------------------------------------------------------------

统计信息

----------------------------------------------------------

          0  recursive calls

          0  db block gets

        145  consistent gets

          0  physical reads

          0  redo size

        462  bytes sent via SQL*Net to client

        416  bytes received via SQL*Net from client

          2  SQL*Net roundtrips to/from client

          0  sorts (memory)

          0  sorts (disk)

          2  rows processed

 

 


您可能感兴趣的文档:

--结束END--

本文标题: 索引系列九--索引特性之有序优化distinct

本文链接: https://www.lsjlt.com/news/41500.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作