数据库分页的方法与性能考虑

12 阅读1分钟

一、低性能方案

mysql/postgre: limit, offset

dynamodb:      startkey, lastkey (ExclusiveStartKey, LastEvaluatedKey)

elasticsearch: from, size

二、性能优化方案

mysql/postgre: 有自增id、updateAt索引的,使用 id>mmm limit n,或updateAt > 'y-m-d' limit n

三、高性能方案

比较精确的查询与过滤

四、遍历全部数据

mysql/postgre/dynamodb/es: 使用cursor, next token