]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dict-sql: Use LIMIT in SQL queries with dict_iterate_set_limit()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sun, 16 Oct 2016 19:58:07 +0000 (22:58 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 19 Oct 2016 12:39:37 +0000 (15:39 +0300)
src/lib-dict/dict-sql.c

index f0538d59c7c947a5729c9096084c7fa48ebe1acc..d7fe4053e1c0412fdfa8fb4fb0499aba0eb5bc0c 100644 (file)
@@ -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;
 }