From: Timo Sirainen Date: Sun, 16 Oct 2016 19:58:07 +0000 (+0300) Subject: dict-sql: Use LIMIT in SQL queries with dict_iterate_set_limit() X-Git-Tag: 2.2.26~116 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=df6bf0202815c053fd1d9ed16e792445dcd182bb;p=thirdparty%2Fdovecot%2Fcore.git dict-sql: Use LIMIT in SQL queries with dict_iterate_set_limit() --- diff --git a/src/lib-dict/dict-sql.c b/src/lib-dict/dict-sql.c index f0538d59c7..d7fe4053e1 100644 --- a/src/lib-dict/dict-sql.c +++ b/src/lib-dict/dict-sql.c @@ -616,6 +616,12 @@ sql_dict_iterate_build_next_query(struct sql_dict_iterate_context *ctx, } else if ((ctx->flags & DICT_ITERATE_FLAG_SORT_BY_VALUE) != 0) str_printfa(query, " ORDER BY %s", map->value_field); + if (ctx->ctx.max_rows > 0) { + i_assert(ctx->ctx.row_count < ctx->ctx.max_rows); + str_printfa(query, " LIMIT %llu", + (unsigned long long)(ctx->ctx.max_rows - ctx->ctx.row_count)); + } + ctx->map = map; return 1; }