社区
Oracle 高级技术
帖子详情
select count(*) from table 性能
cjy218
2008-05-21 03:17:49
select count(*) from table 性能..有比这语句一样的....
...全文
1218
17
打赏
收藏
select count(*) from table 性能
select count(*) from table 性能..有比这语句一样的....
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
17 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
zxg1127_1
2009-06-11
打赏
举报
回复
学习 了
8193102
2008-07-05
打赏
举报
回复
所以总要自己试试,不同版本的ORACLE都会有不同的惊喜.
wffffc
2008-06-04
打赏
举报
回复
SQL> select count(*) from emp;
COUNT(*)
----------
14
执行计划
----------------------------------------------------------
Plan hash value: 2937609675
-------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 1 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | INDEX FULL SCAN| PK_EMP | 14 | 1 (0)| 00:00:01 |
-------------------------------------------------------------------
统计信息
----------------------------------------------------------
301 recursive calls
0 db block gets
56 consistent gets 第一次执行没有将数据进行缓存,看不出问题
8 physical reads
0 redo size
419 bytes sent via SQL*Net to client
416 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
6 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> select count(*) from emp;
COUNT(*)
----------
14
执行计划
----------------------------------------------------------
Plan hash value: 2937609675
-------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 1 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 |
INDEX FULL SCAN| PK_EMP
| 14 | 1 (0)| 00:00:01 |
-------------------------------------------------------------------
统计信息
----------------------------------------------------------
0 recursive calls
0 db block gets
1 consistent gets
0 physical reads
0 redo size
419 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)
1 rows processed
SQL> select count(empno) from emp;
COUNT(EMPNO)
------------
14
执行计划
----------------------------------------------------------
Plan hash value: 2937609675
-------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 1 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 |
INDEX FULL SCAN| PK_EMP
| 14 | 1 (0)| 00:00:01 |
-------------------------------------------------------------------
统计信息
----------------------------------------------------------
1 recursive calls
0 db block gets
1 consistent gets
0 physical reads
0 redo size
423 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)
1 rows processed
SQL> select count(ename) from emp;
COUNT(ENAME)
------------
14
执行计划
----------------------------------------------------------
Plan hash value: 2083865914
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 6 | 3 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 6 | | |
| 2 |
TABLE ACCESS FULL| EMP
| 14 | 84 | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------
统计信息
----------------------------------------------------------
24 recursive calls
0 db block gets
10 consistent gets
8 physical reads
0 redo size
423 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)
1 rows processed
SQL> select count(ename) from emp;
COUNT(ENAME)
------------
14
执行计划
----------------------------------------------------------
Plan hash value: 2083865914
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 6 | 3 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 6 | | |
| 2 | TABLE ACCESS FULL| EMP | 14 | 84 | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------
统计信息
----------------------------------------------------------
0 recursive calls
0 db block gets
7 consistent gets
0 physical reads
0 redo size
423 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)
1 rows processed
这样看来count(*) 和count(索引列)差不多,count(非索引列)效果比较差了
colinTongzw
2008-06-04
打赏
举报
回复
count(*)不比count(字段)慢
某些资料上说:用*会统计所有列,显然要比一个世界的列名效率低。这种说法其实是没有根据的。我们来看:
select count(*) from Tgongwen
用时:1500毫秒
select count(gid) from Tgongwen
用时:1483毫秒
select count(fariqi) from Tgongwen
用时:3140毫秒
select count(title) from Tgongwen
用时:52050毫秒
从以上可以看出,如果用count(*)和用count(主键)的速度是相当的,而count(*)却比其他任何除主键以外的字段汇总速度要快,而且字段越长,汇总的速度就越慢。我想,如果用count(*), SQL SERVER可能会自动查找最小字段来汇总的。当然,如果您直接写count(主键)将会来的更直接些。
8193102
2008-06-04
打赏
举报
回复
不相信的兄弟,完全可以找多个试试
8193102
2008-06-04
打赏
举报
回复
select count(*) 似乎快一些,因为实际上它用的是rowid, 大部分情况是这样
lilingbill
2008-06-04
打赏
举报
回复
主要看你的表建立主键或者索引与否。如果建立 了的,那么count(*)和count(1)差不多的执行效率。优化器都将从索引中去获取全部总记录数。而不是从硬盘上。
wll123a123
2008-06-04
打赏
举报
回复
呵呵,这个问题有趣
hebo2005
2008-06-02
打赏
举报
回复
[Quote=引用 7 楼 lightning8 的回复:]
select count(0) from table 比 select count(*) from table 速度快
[/Quote]
只能是据说
还有种说法,这两种的速度是一样的
另外还有种写法
count(索引字段)
据说是最快的
tchx
2008-06-02
打赏
举报
回复
我测试过1千多万的,COUNT(*)比COUNT(1)之类速度要快一点。
clarkchiang
2008-06-02
打赏
举报
回复
select count(0) from table 比 select count(*) from table 速度快
ruihuahan
2008-05-27
打赏
举报
回复
force 一个短行的索引吧,可以减少 IO。
cjy218
2008-05-22
打赏
举报
回复
一个700百万记录的表
现在要统计表的记录数 怎么用最优方法获得记录总数
xudaqing2008
2008-05-22
打赏
举报
回复
[Quote=引用 4 楼 cjy218 的回复:]
一个700百万记录的表
现在要统计表的记录数 怎么用最优方法获得记录总数
[/Quote]
select count(0) from table是最优的,你可以试一试
xudaqing2008
2008-05-21
打赏
举报
回复
select count(0) from table
robin_ares
2008-05-21
打赏
举报
回复
说中文吧
Jane_64
2008-05-21
打赏
举报
回复
什么意思?不明白
【SQL Server】sql中去除重复的数据
select
distinct * from
table
总的思路就是先找出表中重复数据中的一条数据,插入临时表中,删除所有的重复数据,然后再将临时表中的数据插入表中。所以重点是如何找出重复数据中的一条数据,有三种情况 ...
select
* from
table
where id in(...
mysql中
select
* from(
select
* from
table
)name 派生表别名
在编写mysql程序时遇见以下写法:
SELECT
clarify_issue.statistics_time FROM( ...不知道为什么
select
* from()后面为什么有
table
name,通过查询可知,当通过查询得到新的
table
时,必须有一个别名,即每个派生...
hive可以执行
select
* from
table
;“ 却无法执行"
select
count
(*) from
table
;"
而执行"
select
count
(*) from
table
;"需要启动mapreduce任务。解决方法看执行过程的错误信息,我得到的信息是当前用户对于hdfs文件系统的/user文件夹没有写权限,只要开放权限,就可以解决问题。
SELECT
* FROM
table
LIMIT
使用查询语句的时候,经常要返回前几条或者中间某几行数据,这个时候怎么办呢?不用担心,已 经为我们提供了这样一个功能。 LIMIT 子句可以被用于强制
SELECT
语句返回指定的记录数。...
SELECT
* FROM
table
LIMIT [...
mysql篇-
select
* from
table
for update使用行锁还是表锁?
select
* from
table
for update使用行锁还是表锁,主要看是否使用到索引或主键,如果没有使用到索引或主键,则使用了表锁,如果使用到索引或主键,则是行锁 行锁 id是主键,usrId是索引
select
* from
table
for ...
Oracle 高级技术
3,494
社区成员
18,710
社区内容
发帖
与我相关
我的任务
Oracle 高级技术
Oracle 高级技术相关讨论专区
复制链接
扫一扫
分享
社区描述
Oracle 高级技术相关讨论专区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章