count(*)的速度问题
来源:百度知道 编辑:UC知道 时间:2024/06/06 10:51:37
select * from temp_tb_vipinfo t,tb_bussrecord b where t.zch=b.zch and b.rec_type=0 and b.rec_context like '%%'
select count(*) from temp_tb_vipinfo t,tb_bussrecord b where t.zch=b.zch and b.rec_type=0 and b.rec_context like '%%'
注:用的是Oracle数据库。有人说count里面不用*,写索引列或者1,结果是无效的。
1楼的,我没说要全查出来,我只是需要获得记录的总数,况且目前的情况是全查出来很快,查总数量很慢,明白?
用不着把它全部查询出来吧.?显示几十条数据就不错了啊.。
写个分页的存储过程啊.这个有利于查询的速度得到提高.。
你select * 速度比较快,是因为你当前显示的只有十几二十行,你要是把你查出来的结果都遍历一遍的话,速度和select count(*)的速度基本没太大差别
两个语句都要是遍历你所要查的那部分数据
可以给你个sql,先保证你的用户有dba权限才能查到所用时间
select/*+rule*/ username,sid,opname,
round(sofar*100 / totalwork,0) || '%' as progress,
time_remaining,sql_text
from v$session_longops , v$sql
where time_remaining <> 0
and sql_address = address
and sql_hash_value = hash_value;
你可以把select *的数据拖到底部,看看用时多少?可以用上边的sql监控一下
不知道你用的什么工具,toad的话plsql的话,有个按钮可以直接拽到底
select count(*) from temp_tb_vipinfo t,tb_bussrecord b where t.zch=b.zch and b.rec_type=0 and b.rec_context like '%%'
或select count(1) from temp_tb_vipinfo t,tb_bussrecord b where t.zch=b.zch and b.rec_type=0 and b.rec_context like '%%'
select count(t.zch) from temp_tb_vipinfo t,tb_bussrecord b where t.zch=b.zch an