Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d50d172

Browse files
author
Etsuro Fujita
committed
postgres_fdw: Perform the (FINAL, NULL) upperrel operations remotely.
The upper-planner pathification allows FDWs to arrange to push down different types of upper-stage operations to the remote side. This commit teaches postgres_fdw to do it for the (FINAL, NULL) upperrel, which is responsible for doing LockRows, LIMIT, and/or ModifyTable. This provides the ability for postgres_fdw to handle SELECT commands so that it 1) skips the LockRows step (if any) (note that this is safe since it performs early locking) and 2) pushes down the LIMIT and/or OFFSET restrictions (if any) to the remote side. This doesn't handle the INSERT/UPDATE/DELETE cases. Author: Etsuro Fujita Reviewed-By: Antonin Houska and Jeff Janes Discussion: https://postgr.es/m/87pnz1aby9.fsf@news-spur.riddles.org.uk
1 parent aef65db commit d50d172

File tree

7 files changed

+656
-390
lines changed

7 files changed

+656
-390
lines changed

contrib/postgres_fdw/deparse.c

+35-2
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ static void deparseSelectSql(List *tlist, bool is_subquery, List **retrieved_att
169169
static void deparseLockingClause(deparse_expr_cxt *context);
170170
static void appendOrderByClause(List *pathkeys, bool has_final_sort,
171171
deparse_expr_cxt *context);
172+
static void appendLimitClause(deparse_expr_cxt *context);
172173
static void appendConditions(List *exprs, deparse_expr_cxt *context);
173174
static void deparseFromExprForRel(StringInfo buf, PlannerInfo *root,
174175
RelOptInfo *foreignrel, bool use_alias,
@@ -930,7 +931,7 @@ build_tlist_to_deparse(RelOptInfo *foreignrel)
930931
void
931932
deparseSelectStmtForRel(StringInfo buf, PlannerInfo *root, RelOptInfo *rel,
932933
List *tlist, List *remote_conds, List *pathkeys,
933-
bool has_final_sort, bool is_subquery,
934+
bool has_final_sort, bool has_limit, bool is_subquery,
934935
List **retrieved_attrs, List **params_list)
935936
{
936937
deparse_expr_cxt context;
@@ -988,6 +989,10 @@ deparseSelectStmtForRel(StringInfo buf, PlannerInfo *root, RelOptInfo *rel,
988989
if (pathkeys)
989990
appendOrderByClause(pathkeys, has_final_sort, &context);
990991

992+
/* Add LIMIT clause if necessary */
993+
if (has_limit)
994+
appendLimitClause(&context);
995+
991996
/* Add any necessary FOR UPDATE/SHARE. */
992997
deparseLockingClause(&context);
993998
}
@@ -1591,7 +1596,8 @@ deparseRangeTblRef(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel,
15911596
/* Deparse the subquery representing the relation. */
15921597
appendStringInfoChar(buf, '(');
15931598
deparseSelectStmtForRel(buf, root, foreignrel, NIL,
1594-
fpinfo->remote_conds, NIL, false, true,
1599+
fpinfo->remote_conds, NIL,
1600+
false, false, true,
15951601
&retrieved_attrs, params_list);
15961602
appendStringInfoChar(buf, ')');
15971603

@@ -3160,6 +3166,33 @@ appendOrderByClause(List *pathkeys, bool has_final_sort,
31603166
reset_transmission_modes(nestlevel);
31613167
}
31623168

3169+
/*
3170+
* Deparse LIMIT/OFFSET clause.
3171+
*/
3172+
static void
3173+
appendLimitClause(deparse_expr_cxt *context)
3174+
{
3175+
PlannerInfo *root = context->root;
3176+
StringInfo buf = context->buf;
3177+
int nestlevel;
3178+
3179+
/* Make sure any constants in the exprs are printed portably */
3180+
nestlevel = set_transmission_modes();
3181+
3182+
if (root->parse->limitCount)
3183+
{
3184+
appendStringInfoString(buf, " LIMIT ");
3185+
deparseExpr((Expr *) root->parse->limitCount, context);
3186+
}
3187+
if (root->parse->limitOffset)
3188+
{
3189+
appendStringInfoString(buf, " OFFSET ");
3190+
deparseExpr((Expr *) root->parse->limitOffset, context);
3191+
}
3192+
3193+
reset_transmission_modes(nestlevel);
3194+
}
3195+
31633196
/*
31643197
* appendFunctionName
31653198
* Deparses function name from given function oid.

contrib/postgres_fdw/expected/postgres_fdw.out

+251-369
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)