commit e0480bdd3ed9a494dbe2124c73f58b9d629244df
Author: Böszörményi Zoltán <zboszor@pr.hu>
Date:   Wed Apr 16 10:36:03 2014 +0200

    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 da83c92..7e231d7 100644
--- a/src/interfaces/ecpg/ecpglib/cursor.c
+++ b/src/interfaces/ecpg/ecpglib/cursor.c
@@ -1510,20 +1510,21 @@ ecpg_cursor_next_pos(struct statement *stmt, struct cursor_descriptor *cur,
 static bool
 ecpg_cursor_fetch(struct statement *stmt, struct cursor_descriptor *cur,
 					enum ECPG_cursor_direction direction,
 					int64 amount, bool fetchall)
 {
 	struct sqlca_t *sqlca = ECPGget_sqlca();
 	bool		backward, next_atstart, next_atend, error, append;
 	long		ntuples;
 	int		step;
 	int64		prev_pos, next_pos, start_idx, var_index;
+	int64		old_readahead;
 
 	switch (direction)
 	{
 	case ECPGc_absolute:
 	case ECPGc_relative:
 abs_rel:
 
 		/*
 		 * If there were MAX_CACHE_MISS cache misses already, switch to
 		 * executing the FETCH ABSOLUTE/RELATIVE as is.
@@ -1681,20 +1682,24 @@ abs_rel:
 			direction = ECPGc_forward;
 		}
 
 	case ECPGc_forward:
 		if (!fetchall && amount == 0)
 		{
 			direction = ECPGc_relative;
 			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.
 		 */
 		backward = ((direction == ECPGc_backward) || (amount < 0));
 		step = (backward ? LOOP_BACKWARD : LOOP_FORWARD);
 
 		var_index = 0;
 		append = false;
 		while (fetchall || (!fetchall && amount))
@@ -1764,20 +1769,22 @@ abs_rel:
 			}
 
 			if (cur_amount > 1)
 				cur->cache_miss = 0;
 
 			append = true;
 		}
 
 		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);
 			return false;
 		}
 		break;
 
 	default:
 		/*
 		 * The ECPGc_*_in_var variants cannot occur here.
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
@@ -25,20 +25,21 @@ extern bool ecpg_internal_regression_mode;
 enum ARRAY_TYPE
 {
 	ECPG_ARRAY_ERROR, ECPG_ARRAY_NOT_SET, ECPG_ARRAY_ARRAY, ECPG_ARRAY_VECTOR, ECPG_ARRAY_NONE
 };
 
 #define ECPG_IS_ARRAY(X) ((X) == ECPG_ARRAY_ARRAY || (X) == ECPG_ARRAY_VECTOR)
 
 #define LOOP_FORWARD	(1)
 #define LOOP_BACKWARD	(-1)
 #define MAX_CACHE_MISS	(3)
+#define FETCHALL_MULTIPLIER	(1000)
 
 /* A generic varchar type. */
 struct ECPGgeneric_varchar
 {
 	int			len;
 	char		arr[1];
 };
 
 /*
  * type information cache
