mirror of
https://github.com/postgres/postgres.git
synced 2025-06-07 11:02:12 +03:00
postgres_fdw: Remove redundancy in postgresAcquireSampleRowsFunc().
Previously, in the loop in postgresAcquireSampleRowsFunc() to iterate fetching rows from a given remote table, we redundantly 1) determined the fetch size by parsing the table's server/table-level options and then 2) constructed the fetch command; remove that redundancy. Author: Etsuro Fujita Reviewed-by: Julien Rouhaud Discussion: https://postgr.es/m/CAPmGK17_urk9qkLV65_iYMFw64z5qhdfhY=tMVV6Jg4KNYx8+w@mail.gmail.com
This commit is contained in:
parent
e72489e101
commit
2a1612104c
@ -4490,31 +4490,20 @@ postgresAcquireSampleRowsFunc(Relation relation, int elevel,
|
|||||||
/* In what follows, do not risk leaking any PGresults. */
|
/* In what follows, do not risk leaking any PGresults. */
|
||||||
PG_TRY();
|
PG_TRY();
|
||||||
{
|
{
|
||||||
|
char fetch_sql[64];
|
||||||
|
int fetch_size;
|
||||||
|
ListCell *lc;
|
||||||
|
|
||||||
res = pgfdw_exec_query(conn, sql.data);
|
res = pgfdw_exec_query(conn, sql.data);
|
||||||
if (PQresultStatus(res) != PGRES_COMMAND_OK)
|
if (PQresultStatus(res) != PGRES_COMMAND_OK)
|
||||||
pgfdw_report_error(ERROR, res, conn, false, sql.data);
|
pgfdw_report_error(ERROR, res, conn, false, sql.data);
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
res = NULL;
|
res = NULL;
|
||||||
|
|
||||||
/* Retrieve and process rows a batch at a time. */
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
char fetch_sql[64];
|
|
||||||
int fetch_size;
|
|
||||||
int numrows;
|
|
||||||
int i;
|
|
||||||
ListCell *lc;
|
|
||||||
|
|
||||||
/* Allow users to cancel long query */
|
|
||||||
CHECK_FOR_INTERRUPTS();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* XXX possible future improvement: if rowstoskip is large, we
|
* Determine the fetch size. The default is arbitrary, but shouldn't
|
||||||
* could issue a MOVE rather than physically fetching the rows,
|
* be enormous.
|
||||||
* then just adjust rowstoskip and samplerows appropriately.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* The fetch size is arbitrary, but shouldn't be enormous. */
|
|
||||||
fetch_size = 100;
|
fetch_size = 100;
|
||||||
foreach(lc, server->options)
|
foreach(lc, server->options)
|
||||||
{
|
{
|
||||||
@ -4537,10 +4526,26 @@ postgresAcquireSampleRowsFunc(Relation relation, int elevel,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fetch some rows */
|
/* Construct command to fetch rows from remote. */
|
||||||
snprintf(fetch_sql, sizeof(fetch_sql), "FETCH %d FROM c%u",
|
snprintf(fetch_sql, sizeof(fetch_sql), "FETCH %d FROM c%u",
|
||||||
fetch_size, cursor_number);
|
fetch_size, cursor_number);
|
||||||
|
|
||||||
|
/* Retrieve and process rows a batch at a time. */
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
int numrows;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* Allow users to cancel long query */
|
||||||
|
CHECK_FOR_INTERRUPTS();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* XXX possible future improvement: if rowstoskip is large, we
|
||||||
|
* could issue a MOVE rather than physically fetching the rows,
|
||||||
|
* then just adjust rowstoskip and samplerows appropriately.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Fetch some rows */
|
||||||
res = pgfdw_exec_query(conn, fetch_sql);
|
res = pgfdw_exec_query(conn, fetch_sql);
|
||||||
/* On error, report the original query, not the FETCH. */
|
/* On error, report the original query, not the FETCH. */
|
||||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user