我一直致力于从我的数据库 (11g) 中的表中获取分页结果。虽然我有一个有效的查询(即结果是正确的),但它的性能不如我希望的那样好,我正在努力提高它的效率(估计仅在该查询上每秒调用 60 次)。
所以首先,我阅读了在 Oracle 中计算页数的有效方法是什么?,并且文章也指出了这一点,但不幸的是,它根本没有讨论所提出的查询的执行计划(我会在星期一看到它们)。
这是我提出的查询(表分区part_code是日期范围):
select <all-columns> from (
select rownum as rnum, <all-columns> from (
select /*+index (my_table index)*/ <all-columns> from my_table
where part_code in (?, ?, ?)
and date between ? and ?
and type in (?, ?, ?)
and func_col1 = ?
/*potentially: and func_col2 = ? and func_col3 = ? ... */
order by date, type, id
)
) where rnum between M and N; /* N-M ~= …Run Code Online (Sandbox Code Playgroud)