LIMITandOFFSETallow you to retrieve just a portion of the rows that are generated by the rest of the query:
SELECTselect_listFROMtable_expression[LIMIT {number| ALL }] [OFFSETnumber]
If a limit count is given,no more than that many rows will be returned (but possibly less,if the query itself yields less rows).LIMIT ALLis the same as omitting theLIMITclause.
OFFSETsays to skip that many rows before beginning to return rows.OFFSET 0is the same as omitting theOFFSETclause. If bothOFFSETandLIMITappear,thenOFFSETrows are skipped before starting to count theLIMITrows that are returned.
When usingLIMIT,it is important to use anorDER BYclause that constrains the result rows into a unique order. Otherwise you will get an unpredictable subset of the query's rows. You may be asking for the tenth through twentieth rows,but tenth through twentieth in what ordering? The ordering is unkNown,unless you specifiedORDER BY.
The query optimizer takesLIMITinto account when generating a query plan,so you are very likely to get different plans (yielding different row orders) depending on what you give forLIMITandOFFSET. Thus,using differentLIMIT/OFFSETvalues to select different subsets of a query resultwill give inconsistent resultsunless you enforce a predictable result ordering withORDER BY. This is not a bug; it is an inherent consequence of the fact that sql does not promise to deliver the results of a query in any particular order unlessORDER BYis used to constrain the order.
The rows skipped by anOFFSETclause still have to be co@R_502_6466@ted inside the server; therefore a largeOFFSETcan be inefficient.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。