Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用 PyMySQL 执行一个非常简单的查询:
SELECT `id` FROM `records` ORDER BY `id` DESC
records其中有超过 150 万行。id是主键。
records
id
这是 PyMySQL 的限制吗?如果我一次查询这么多行,还有什么我应该使用的吗?
您可以将查询分解为几个较小的查询:
from math import ceil batch_size = 1000 for start_at in range(int(ceil(total_rows / 1000 * 1.0))): sql = 'SELECT `id` from `RECORDS` ORDER BY `id` DESC LIMIT %i, %i' sql = sql % (start_at * batch_size, batch_size) # fetch rows