From: Pavan Deolasee Date: Fri, 20 Jan 2017 09:45:43 +0000 (+0530) Subject: A very naive way to deal with the fact that RemoteQuery (which EXECUTE DIRECT X-Git-Tag: XL_10_R1BETA1~331 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=8854567268857dff727361fa14eb786e4862ebf4;p=postgres-xl.git 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 --- 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.