30.patch

text/x-patch

Filename: 30.patch
Type: text/x-patch
Part: 4
Message: Re: ECPG FETCH readahead, was: Re: ECPG fixes

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: unified
File+
src/interfaces/ecpg/ecpglib/cursor.c 7 0
src/interfaces/ecpg/ecpglib/extern.h 1 0
commit 29425979f229ae99fe32b8540d65919e517b1c33
Author: Böszörményi Zoltán <zb@cybertec.at>
Date:   Wed Dec 4 14:27:29 2013 +0100

    ECPG: During FETCH ALL, temporarily use FETCHALL_MULTIPLIER times
    the current readahead window size. FETCHALL_MULTIPLIER == 1000.
    No change in regression tests.

diff --git a/src/interfaces/ecpg/ecpglib/cursor.c b/src/interfaces/ecpg/ecpglib/cursor.c
index 1c24133..2d024b8 100644
--- a/src/interfaces/ecpg/ecpglib/cursor.c
+++ b/src/interfaces/ecpg/ecpglib/cursor.c
@@ -1518,6 +1518,7 @@ ecpg_cursor_fetch(struct statement *stmt, struct cursor_descriptor *cur,
 	long		ntuples;
 	int		step;
 	int64		prev_pos, next_pos, start_idx, var_index;
+	int64		old_readahead;
 
 	switch (direction)
 	{
@@ -1689,6 +1690,10 @@ abs_rel:
 			goto abs_rel;
 		}
 
+		old_readahead = cur->readahead;
+		if (fetchall)
+			cur->readahead *= FETCHALL_MULTIPLIER;
+
 		/*
 		 * The direction is backward if FETCH BACKWARD ALL
 		 * or the amount to fetch is negative.
@@ -1772,6 +1777,8 @@ abs_rel:
 
 		sqlca->sqlerrd[2] = (var_index <= LONG_MAX ? var_index : 0);
 
+		cur->readahead = old_readahead;
+
 		if (var_index == 0)
 		{
 			ecpg_raise(stmt->lineno, ECPG_NOT_FOUND, ECPG_SQLSTATE_NO_DATA, NULL);
diff --git a/src/interfaces/ecpg/ecpglib/extern.h b/src/interfaces/ecpg/ecpglib/extern.h
index 612412f..de0f3b8 100644
--- a/src/interfaces/ecpg/ecpglib/extern.h
+++ b/src/interfaces/ecpg/ecpglib/extern.h
@@ -32,6 +32,7 @@ enum ARRAY_TYPE
 #define LOOP_FORWARD	(1)
 #define LOOP_BACKWARD	(-1)
 #define MAX_CACHE_MISS	(3)
+#define FETCHALL_MULTIPLIER	(1000)
 
 /* A generic varchar type. */
 struct ECPGgeneric_varchar