changeset 20885:3f713b46d3b3

dict-sql: Use LIMIT in SQL queries with dict_iterate_set_limit()
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Sun, 16 Oct 2016 22:58:07 +0300
parents c9e829c8a36f
children b88d0049df32
files src/lib-dict/dict-sql.c
diffstat 1 files changed, 6 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-dict/dict-sql.c	Sun Oct 16 22:40:18 2016 +0300
+++ b/src/lib-dict/dict-sql.c	Sun Oct 16 22:58:07 2016 +0300
@@ -616,6 +616,12 @@
 	} 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;
 }