diff options
| -rw-r--r-- | src/pl/plpgsql/src/pl_exec.c | 14 |
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. |
