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
records150万を超える行があります。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