LIMIT OFFSET,LENGTH是否需要ORDER BY才能进行分页?

编程入门 行业动态 更新时间:2024-10-27 02:21:36
本文介绍了LIMIT OFFSET,LENGTH是否需要ORDER BY才能进行分页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个MyISAM表,整个表有28,900个.我正在按1500的块进行处理,这是这样的查询:

I have a MyISAM table with 28,900 entires. I'm processing it in chunks of 1500, which a query like this:

SELECT * FROM table WHERE id>0 LIMIT $iStart,1500

然后我循环遍历此操作,并每次将$ iStart递增1500.

Then I loop over this and increment $iStart by 1500 each time.

问题是查询在某些情况下返回相同的行.例如,LIMIT 0,1500查询返回的行数与LIMIT 28500,1500查询相同.

The problem is that the queries are returning the same rows in some cases. For example the LIMIT 0,1500 query returns some of the same rows as the LIMIT 28500,1500 query does.

如果我不对行进行排序,难道我不希望使用LIMIT进行分页吗?

If I don't ORDER the rows, can I not expect to use LIMIT for pagination?

(发生这些查询时,该表是静态的,没有其他查询在进行,这会改变其行).

推荐答案

几乎与其他所有SQL引擎一样,除非指定ORDER BY子句,否则MySQL MyISAM表根本无法保证行的返回顺序. .通常,它们返回的顺序将是它们从文件系统中读取的顺序,根据更新,删除甚至是缓存的选择的状态,查询的顺序可能会因查询而异.

Like pretty much every other SQL engine out there, MySQL MyISAM tables make no guarantees at all about the order in which rows are returned unless you specify an ORDER BY clause. Typically the order they are returned in will be the order they were read off the filesystem in, which can change from query to query depending on updates, deletes, and even the state of cached selects.

如果要避免同一行返回不止一次,则必须按某种顺序排序,主键是最明显的候选者.

If you want to avoid having the same row returned more than once then you must order by something, the primary key being the most obvious candidate.

更多推荐

LIMIT OFFSET,LENGTH是否需要ORDER BY才能进行分页?

本文发布于:2023-10-22 22:37:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1518938.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分页   OFFSET   LIMIT   ORDER   LENGTH

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!