summaryrefslogtreecommitdiff
path: root/src/pl
diff options
context:
space:
mode:
authorPavan Deolasee2017-01-20 09:45:43 +0000
committerPavan Deolasee2017-05-05 04:59:33 +0000
commit8854567268857dff727361fa14eb786e4862ebf4 (patch)
treebf99ffb7d544b8131ced1c122fc0058b514c4050 /src/pl
parent9ddddcb8d51fd640f59401ea9bc335d08bf5a23c (diff)
A very naive way to deal with the fact that RemoteQuery (which EXECUTE DIRECT
internally uses) cannot support cursor fetch. FOR EXECUTE query inside plpgsql uses cursor mechanism to fetch a few tuples at a time. But that fails badly when the query is a EXECUTE DIRECT statement because we internally use RemoteQuery to execute that. Instead just fetch 10000 tuples at a time and complain if RemoteQuery returns more than 10000 rows. May be that's enough for the scenario that we're trying to address where a global view can be created using EXECUTE DIRECT
Diffstat (limited to 'src/pl')
-rw-r--r--src/pl/plpgsql/src/pl_exec.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c
index 428743532b..31ae38e395 100644
--- a/src/pl/plpgsql/src/pl_exec.c
+++ b/src/pl/plpgsql/src/pl_exec.c
@@ -5169,6 +5169,7 @@ exec_for_query(PLpgSQL_execstate *estate, PLpgSQL_stmt_forq *stmt,
bool found = false;
int rc = PLPGSQL_RC_OK;
uint64 n;
+ long count;
/*
* Determine if we assign to a record or a row
@@ -5191,10 +5192,21 @@ exec_for_query(PLpgSQL_execstate *estate, PLpgSQL_stmt_forq *stmt,
* few more rows to avoid multiple trips through executor startup
* overhead.
*/
- SPI_cursor_fetch(portal, true, prefetch_ok ? 10 : 1);
+#define MAX_REMOTE_QUERY_FETCH 10000
+ if (IsA(linitial(portal->stmts), PlannedStmt) &&
+ IsA(((PlannedStmt *) linitial(portal->stmts))->planTree, RemoteQuery))
+ count = MAX_REMOTE_QUERY_FETCH;
+ else
+ count = prefetch_ok ? 10 : 1;
+
+ SPI_cursor_fetch(portal, true, count);
tuptab = SPI_tuptable;
n = SPI_processed;
+ if (n == MAX_REMOTE_QUERY_FETCH)
+ elog(ERROR, "Can fetch only %d tuples via RemoteQuery execution",
+ MAX_REMOTE_QUERY_FETCH);
+
/*
* If the query didn't return any rows, set the target to NULL and fall
* through with found = false.