求助rownum的分页(第三层性能很低)

[复制链接]
查看11 | 回复9 | 2007-4-25 04:02:08 | 显示全部楼层 |阅读模式
select t_id,r from (select A.t_id,rownum r from (selectt_id from bnews where t_state=1 and t_cate=67and t_p_id='0' order by t_order desc ) A where rownum1

内两层的查询很快的
select A.t_id,rownum r from (selectt_id from bnews where t_state=1 and t_cate=67and t_p_id='0' order by t_order desc ) A where rownum1
执行计划
Object owner |Object name | Cost Cardinality | Bytes |IO cost
SELECT STATEMENT, GOAL = CHOOSE
16
8
360
16
VIEW
JHGXS
16
8
360

SORT ORDER BY
16
8
256
16
COUNT STOPKEY

VIEW
JHGXS
11
8
256

SORT ORDER BY STOPKEY
11
8
824
11
TABLE ACCESS BY INDEX ROWID
JHGXS
bnews
6
8
824
6
INDEX RANGE SCAN
JHGXS
bnews_CATE
31875
2
7.89s
按道理数据在内两层都取出来了.应该很快呀.
[ 本帖最后由 xiaotest 于 2010-8-28 11:12 编辑 ]
回复

使用道具 举报

千问 | 2007-4-25 04:02:08 | 显示全部楼层
select t_id,r from (select A.t_id,rownum r from
(selectt_id from bnews where t_state=1 and t_cate=67
and t_p_id='0' order by t_order desc ) A
where rownum1

你搞这么多排序干嘛啊??去掉试试
回复

使用道具 举报

千问 | 2007-4-25 04:02:08 | 显示全部楼层
去了order by rownum asc 还是一样的问题
回复

使用道具 举报

千问 | 2007-4-25 04:02:08 | 显示全部楼层
为什么要套上第三层?
第二层就应该拿出来所有id
然后就该根据每个id去做事情了吧
回复

使用道具 举报

千问 | 2007-4-25 04:02:08 | 显示全部楼层
这是分页的sql,第三层还有个约束条件的.
回复

使用道具 举报

千问 | 2007-4-25 04:02:08 | 显示全部楼层
这张表目前总共也就40多万条数据.以前执行这个分页sql是挺快的.我昨天执行了这个sql语句(把其中一个字段的null赋值):update bnewsset t_user='0' where t_user is null后关于这张表的分页查询就出现这个问题了.
[ 本帖最后由 xiaotest 于 2010-8-28 14:35 编辑 ]
回复

使用道具 举报

千问 | 2007-4-25 04:02:08 | 显示全部楼层
必须要三层吗?
select t_id,r from (selectt_idrownum r from bnews where t_state=1 and t_cate=67and t_p_id='0' and rownum1
回复

使用道具 举报

千问 | 2007-4-25 04:02:08 | 显示全部楼层
上三层是对的,谓词推进stop key效率比两层的要好,你的第3层还有条件??用autotrace对比对比吧,把执行计划格式化下,代码选择 宋体
回复

使用道具 举报

千问 | 2007-4-25 04:02:08 | 显示全部楼层
第3层没有其他条件了?
我也是因为昨天执行了这个sql语句(把其中一个字段的null赋值):update bnewsset t_user='0' where t_user is null
后分页查询就很慢了.你帮我分析分析是什么原因
[ 本帖最后由 xiaotest 于 2010-8-28 16:36 编辑 ]
回复

使用道具 举报

千问 | 2007-4-25 04:02:08 | 显示全部楼层
估计是执行计划改变了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行