开发者

mysql offset true behaviour

I'm creating a pagination with a where clause. I need to know the true behaviour of the offset.

  1. Is the offset calculated based on all the rows that match the where clause? Or
  2. The offset is calculated like an id and all rows are considered. Eg. If you s开发者_开发问答pecify an offset of 5, rows will be returned starting from the 6th row in the table even of the first 4 rows don't match the where clause?

Edit: I want to be sure since the second behaviour would be totally incorrect and cause problems. Thanks for your answers. I can't comment as my browser fails at javascript and ajax horribly.


Yes the offset is calculated based on all rows that matches the where clause. Just try it.


Are you talking about using the LIMIT clause? LIMIT puts a cap on the number of successful matches, not the total matches. The offset portion of limit is calculated from the matches rather than all eligible rows. MySQL will not necessarily scan rows in a given order and may not scan some rows at all, so it wouldn't short change you rows if a failed match had a lower index.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜