Welcome 微信登录

首页 / 数据库 / MySQL / Oracle count(*)是否走索引

count(*)在平常工作中,使用到的频率很高,是否会走索引,对性能影响不小!但是不是所有的count(*)都能走索引!小记下create table t3(sid number not null primary key,sno number,sname varchar2(10))tablespace test;declaremaxrecords constant int:=100000;i int :=1;beginfor i in 1..maxrecords loopinsert into t3 values(i,i,"ocpyang");end loop;dbms_output.put_line(" 成功录入数据! ");commit;end;/declaremaxrecords constant int:=200000;i int :=100001;beginfor i in 100001..maxrecords loopinsert into t3(sid,sname) values(i,"ocpyang");end loop;dbms_output.put_line(" 成功录入数据! ");commit;end;/create index index_sno on t3(sno);exec dbms_stats.gather_table_stats("SYS","T3",cascade=>TRUE);***********1.count***********SQL> set autotrace traceonly explain stat;SQL> select count(*) from t3;执行计划----------------------------------------------------------Plan hash value: 463314188-------------------------------------------------------------------| Id | Operation | Name | Rows | Cost (%CPU)| Time |-------------------------------------------------------------------| 0 | SELECT STATEMENT | | 1 | 2 (0)| 00:00:01 || 1 | SORT AGGREGATE | | 1 | | || 2 | TABLE ACCESS FULL| T3 | 82 | 2 (0)| 00:00:01 |-------------------------------------------------------------------Note------ SQL plan baseline "SQL_PLAN_27gnhfjz9qahj14fae16c" used for this statement统计信息----------------------------------------------------------55 recursive calls38 db block gets521 consistent gets19 physical reads14676 redo size527 bytes sent via SQL*Net to client520 bytes received via SQL*Net from client2 SQL*Net roundtrips to/from client0 sorts (memory)0 sorts (disk)1 rows processed--通过全表扫描实现的.SQL> select count(*) from t1 where sid is not null;执行计划----------------------------------------------------------Plan hash value: 1551730033--------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |--------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 1 | 13 | 68 (0)| 00:00:01 || 1 | SORT AGGREGATE | | 1 | 13 | | || 2 | INDEX FAST FULL SCAN| SYS_C0023596 | 85899 | 1090K| 68 (0)| 00:00:01 |--------------------------------------------------------------------------------------Note------ dynamic sampling used for this statement (level=2)- SQL plan baseline "SQL_PLAN_4xztry6akgpqqf2d247c8" used for this statement统计信息----------------------------------------------------------4 recursive calls0 db block gets310 consistent gets0 physical reads0 redo size527 bytes sent via SQL*Net to client520 bytes received via SQL*Net from client2 SQL*Net roundtrips to/from client0 sorts (memory)0 sorts (disk)1 rows processed--通过索引实现的.更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12Oracle DBLink使用Oracle number显示科学计数的解决方法相关资讯      Oracle索引 
  • Oracle跳跃式索引扫描测试  (08月09日)
  • Oracle组合索引与回表  (08/07/2015 18:11:53)
  • Oracle 索引基本原理  (04/12/2015 18:03:58)
  • 关于Oracle位图索引内部浅论  (09/17/2015 19:23:59)
  • Oracle 索引的可见与隐藏(visible  (07/18/2015 09:41:42)
  • Oracle索引合并coalesce操作  (04/01/2015 20:21:34)
本文评论 查看全部评论 (0)
表情: 姓名: 字数