oracle
rownum: pseudo-column rownum can be used for paging query, rownum only supports <,<=,!=, so paging query needs to use subquery
example:
select * from (select t.*, ROWNUM RN from table t ) a where a.RN between 5 and 10
rownid: Each row of data in the table has a unique address flag
When querying data, when indexing according to the conditions, the rowid of the query data will be returned, and then the data of the data where the rowid is located will be returned to the table to query.
Therefore, when the selected fields are all in the index item, there is no need to go back to the table to query.
Of course, building too many indexes on a table is not the root of the query.
Therefore, when a large amount of data is queried, if the rowid of the specific paging data can be obtained, it is believed that the query efficiency will be much higher.
Example 1:
select row_.*, rownum rownum_
from (select t.*, ROWNUM rn
from table t
where create_time >= to_date('2016-10-19 00:00:00', 'yyyy-mm-dd hh24:mi:ss')
order by id) row_
where row_.rn between 4000 and 5000
Example 2:
select b.*
from (select rn
from (select row_.*, rownum rownum_
from (select rowid rn
from table t
where create_time >=
to_date('2016-10-19 00:00:00',
'yyyy-mm-dd hh24:mi:ss')
order by id) row_
where rownum <= 5000)
where rownum_ > 4000) a,
table b
where rn = b.rowid order by id
通过查看执行计划,两条sql查询无论从扫描数据的行数,消耗内存,耗时等因素例2则高很多
参考:
http://blog.csdn.net/lang_man_xing/article/details/7353789
http://blog.csdn.net/chenxizhiyi/article/details/6331849