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

Commit28b0478

Browse files
committed
Handle restriction clause lists more uniformly in postgres_fdw.
Clauses in the lists retained by postgres_fdw during planning weresometimes bare boolean clauses, sometimes RestrictInfos, and sometimesa mixture of the two in the same list. The comment about that situationdidn't come close to telling the full truth, either. Aside from beingconfusing, this had a couple of bad practical consequences:* waste of planning cycles due to inability to cache per-clause selectivityand cost estimates;* sometimes, RestrictInfos would sneak into the fdw_private list of afinished Plan node, causing failures if, for example, we tried to shipthe Plan tree to a parallel worker.(It may well be that it's a bug in the parallel-query logic that wewould ever try to ship such a plan to a parallel worker, but in anycase this deserves to be cleaned up.)To fix, rearrange so that clause lists in PgFdwRelationInfo are alwayslists of RestrictInfos, and then strip the RestrictInfos at the lastminute when making a Plan node. In passing do a bit of refactoring andcomment cleanup in postgresGetForeignPlan and foreign_join_ok.Although the messiness here dates back at least to 9.6, there's no evidencethat it causes anything worse than wasted planning cycles in 9.6, so noback-patch for now.Per fuzz testing by Andreas Seltenreich.Tom Lane and Ashutosh BapatDiscussion:https://postgr.es/m/87tw5x4vcu.fsf@credativ.de
1 parentff7bce1 commit28b0478

File tree

3 files changed

+168
-135
lines changed

3 files changed

+168
-135
lines changed

‎contrib/postgres_fdw/deparse.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ classifyConditions(PlannerInfo *root,
210210

211211
foreach(lc,input_conds)
212212
{
213-
RestrictInfo*ri= (RestrictInfo*)lfirst(lc);
213+
RestrictInfo*ri=lfirst_node(RestrictInfo,lc);
214214

215215
if (is_foreign_expr(root,baserel,ri->clause))
216216
*remote_conds=lappend(*remote_conds,ri);
@@ -869,6 +869,7 @@ build_tlist_to_deparse(RelOptInfo *foreignrel)
869869
{
870870
List*tlist=NIL;
871871
PgFdwRelationInfo*fpinfo= (PgFdwRelationInfo*)foreignrel->fdw_private;
872+
ListCell*lc;
872873

873874
/*
874875
* For an upper relation, we have already built the target list while
@@ -884,9 +885,14 @@ build_tlist_to_deparse(RelOptInfo *foreignrel)
884885
tlist=add_to_flat_tlist(tlist,
885886
pull_var_clause((Node*)foreignrel->reltarget->exprs,
886887
PVC_RECURSE_PLACEHOLDERS));
887-
tlist=add_to_flat_tlist(tlist,
888-
pull_var_clause((Node*)fpinfo->local_conds,
889-
PVC_RECURSE_PLACEHOLDERS));
888+
foreach(lc,fpinfo->local_conds)
889+
{
890+
RestrictInfo*rinfo=lfirst_node(RestrictInfo,lc);
891+
892+
tlist=add_to_flat_tlist(tlist,
893+
pull_var_clause((Node*)rinfo->clause,
894+
PVC_RECURSE_PLACEHOLDERS));
895+
}
890896

891897
returntlist;
892898
}
@@ -1049,6 +1055,7 @@ deparseSelectSql(List *tlist, bool is_subquery, List **retrieved_attrs,
10491055
* "buf".
10501056
*
10511057
* quals is the list of clauses to be included in the WHERE clause.
1058+
* (These may or may not include RestrictInfo decoration.)
10521059
*/
10531060
staticvoid
10541061
deparseFromExpr(List*quals,deparse_expr_cxt*context)
@@ -1262,6 +1269,9 @@ deparseLockingClause(deparse_expr_cxt *context)
12621269
*
12631270
* The conditions in the list are assumed to be ANDed. This function is used to
12641271
* deparse WHERE clauses, JOIN .. ON clauses and HAVING clauses.
1272+
*
1273+
* Depending on the caller, the list elements might be either RestrictInfos
1274+
* or bare clauses.
12651275
*/
12661276
staticvoid
12671277
appendConditions(List*exprs,deparse_expr_cxt*context)
@@ -1278,16 +1288,9 @@ appendConditions(List *exprs, deparse_expr_cxt *context)
12781288
{
12791289
Expr*expr= (Expr*)lfirst(lc);
12801290

1281-
/*
1282-
* Extract clause from RestrictInfo, if required. See comments in
1283-
* declaration of PgFdwRelationInfo for details.
1284-
*/
1291+
/* Extract clause from RestrictInfo, if required */
12851292
if (IsA(expr,RestrictInfo))
1286-
{
1287-
RestrictInfo*ri= (RestrictInfo*)expr;
1288-
1289-
expr=ri->clause;
1290-
}
1293+
expr= ((RestrictInfo*)expr)->clause;
12911294

12921295
/* Connect expressions with "AND" and parenthesize each condition. */
12931296
if (!is_first)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp