Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2a16121

Browse files
author
Etsuro Fujita
committed
postgres_fdw: Remove redundancy in postgresAcquireSampleRowsFunc().
Previously, in the loop in postgresAcquireSampleRowsFunc() to iteratefetching rows from a given remote table, we redundantly 1) determined thefetch size by parsing the table's server/table-level options and then 2)constructed the fetch command; remove that redundancy.Author: Etsuro FujitaReviewed-by: Julien RouhaudDiscussion:https://postgr.es/m/CAPmGK17_urk9qkLV65_iYMFw64z5qhdfhY=tMVV6Jg4KNYx8+w@mail.gmail.com
1 parente72489e commit2a16121

File tree

1 file changed

+34
-29
lines changed

1 file changed

+34
-29
lines changed

‎contrib/postgres_fdw/postgres_fdw.c

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4490,20 +4490,51 @@ postgresAcquireSampleRowsFunc(Relation relation, int elevel,
44904490
/* In what follows, do not risk leaking any PGresults. */
44914491
PG_TRY();
44924492
{
4493+
charfetch_sql[64];
4494+
intfetch_size;
4495+
ListCell*lc;
4496+
44934497
res=pgfdw_exec_query(conn,sql.data);
44944498
if (PQresultStatus(res)!=PGRES_COMMAND_OK)
44954499
pgfdw_report_error(ERROR,res,conn, false,sql.data);
44964500
PQclear(res);
44974501
res=NULL;
44984502

4503+
/*
4504+
* Determine the fetch size. The default is arbitrary, but shouldn't
4505+
* be enormous.
4506+
*/
4507+
fetch_size=100;
4508+
foreach(lc,server->options)
4509+
{
4510+
DefElem*def= (DefElem*)lfirst(lc);
4511+
4512+
if (strcmp(def->defname,"fetch_size")==0)
4513+
{
4514+
fetch_size=strtol(defGetString(def),NULL,10);
4515+
break;
4516+
}
4517+
}
4518+
foreach(lc,table->options)
4519+
{
4520+
DefElem*def= (DefElem*)lfirst(lc);
4521+
4522+
if (strcmp(def->defname,"fetch_size")==0)
4523+
{
4524+
fetch_size=strtol(defGetString(def),NULL,10);
4525+
break;
4526+
}
4527+
}
4528+
4529+
/* Construct command to fetch rows from remote. */
4530+
snprintf(fetch_sql,sizeof(fetch_sql),"FETCH %d FROM c%u",
4531+
fetch_size,cursor_number);
4532+
44994533
/* Retrieve and process rows a batch at a time. */
45004534
for (;;)
45014535
{
4502-
charfetch_sql[64];
4503-
intfetch_size;
45044536
intnumrows;
45054537
inti;
4506-
ListCell*lc;
45074538

45084539
/* Allow users to cancel long query */
45094540
CHECK_FOR_INTERRUPTS();
@@ -4514,33 +4545,7 @@ postgresAcquireSampleRowsFunc(Relation relation, int elevel,
45144545
* then just adjust rowstoskip and samplerows appropriately.
45154546
*/
45164547

4517-
/* The fetch size is arbitrary, but shouldn't be enormous. */
4518-
fetch_size=100;
4519-
foreach(lc,server->options)
4520-
{
4521-
DefElem*def= (DefElem*)lfirst(lc);
4522-
4523-
if (strcmp(def->defname,"fetch_size")==0)
4524-
{
4525-
fetch_size=strtol(defGetString(def),NULL,10);
4526-
break;
4527-
}
4528-
}
4529-
foreach(lc,table->options)
4530-
{
4531-
DefElem*def= (DefElem*)lfirst(lc);
4532-
4533-
if (strcmp(def->defname,"fetch_size")==0)
4534-
{
4535-
fetch_size=strtol(defGetString(def),NULL,10);
4536-
break;
4537-
}
4538-
}
4539-
45404548
/* Fetch some rows */
4541-
snprintf(fetch_sql,sizeof(fetch_sql),"FETCH %d FROM c%u",
4542-
fetch_size,cursor_number);
4543-
45444549
res=pgfdw_exec_query(conn,fetch_sql);
45454550
/* On error, report the original query, not the FETCH. */
45464551
if (PQresultStatus(res)!=PGRES_TUPLES_OK)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp