@@ -41,6 +41,7 @@ List *clausesInvolvingAttr(Index relid, AttrNumber attnum,
41
41
42
42
Expr * fdw_get_em_expr (EquivalenceClass * ec , RelOptInfo * rel );
43
43
44
+
44
45
/*
45
46
* The list of needed columns (represented by their respective vars)
46
47
* is pulled from:
@@ -59,30 +60,61 @@ extractColumns(List *reltargetlist, List *restrictinfolist)
59
60
List * targetcolumns ;
60
61
Node * node = (Node * )lfirst (lc );
61
62
62
- targetcolumns = pull_var_clause (node ,
63
+ elog (DEBUG1 , "DEBUG: Processing node in target list (nodeTag=%d)" , nodeTag (node ));
64
+
65
+ /* Check if this is a RestrictInfo node and handle it properly */
66
+ if (IsA (node , RestrictInfo ))
67
+ {
68
+ List * actual_clauses = extract_actual_clauses (list_make1 (node ), false);
69
+ ListCell * clause_lc ;
70
+
71
+ foreach (clause_lc , actual_clauses )
72
+ {
73
+ Node * clause = (Node * )lfirst (clause_lc );
74
+ List * clause_vars = pull_var_clause (clause ,
63
75
#if PG_VERSION_NUM >= 90600
64
- PVC_RECURSE_AGGREGATES |
65
- PVC_RECURSE_PLACEHOLDERS );
76
+ PVC_RECURSE_AGGREGATES | PVC_RECURSE_PLACEHOLDERS );
66
77
#else
67
- PVC_RECURSE_AGGREGATES ,
68
- PVC_RECURSE_PLACEHOLDERS );
78
+ PVC_RECURSE_AGGREGATES , PVC_RECURSE_PLACEHOLDERS );
69
79
#endif
70
- columns = list_union (columns , targetcolumns );
80
+ columns = list_union (columns , clause_vars );
81
+ }
82
+ }
83
+ else
84
+ {
85
+ /* For non-RestrictInfo nodes, call pull_var_clause directly */
86
+ targetcolumns = pull_var_clause (node ,
87
+ #if PG_VERSION_NUM >= 90600
88
+ PVC_RECURSE_AGGREGATES | PVC_RECURSE_PLACEHOLDERS );
89
+ #else
90
+ PVC_RECURSE_AGGREGATES , PVC_RECURSE_PLACEHOLDERS );
91
+ #endif
92
+ columns = list_union (columns , targetcolumns );
93
+ }
71
94
i ++ ;
72
95
}
73
- foreach (lc , restrictinfolist )
96
+ /* Use extract_actual_clauses to properly handle RestrictInfo nodes */
97
+ if (restrictinfolist != NIL )
74
98
{
75
- List * targetcolumns ;
76
- RestrictInfo * node = (RestrictInfo * )lfirst (lc );
77
- targetcolumns = pull_var_clause ((Node * )node -> clause ,
99
+ List * actual_clauses = extract_actual_clauses (restrictinfolist , false);
100
+ ListCell * clause_lc ;
101
+
102
+ elog (DEBUG1 , "DEBUG: Processing %d actual clauses from restrictinfo list" , list_length (actual_clauses ));
103
+
104
+ foreach (clause_lc , actual_clauses )
105
+ {
106
+ List * targetcolumns ;
107
+ Node * clause = (Node * )lfirst (clause_lc );
108
+
109
+ elog (DEBUG1 , "DEBUG: Processing actual clause (nodeTag=%d)" , nodeTag (clause ));
110
+ targetcolumns = pull_var_clause (clause ,
78
111
#if PG_VERSION_NUM >= 90600
79
- PVC_RECURSE_AGGREGATES |
80
- PVC_RECURSE_PLACEHOLDERS );
112
+ PVC_RECURSE_AGGREGATES | PVC_RECURSE_PLACEHOLDERS );
81
113
#else
82
- PVC_RECURSE_AGGREGATES ,
83
- PVC_RECURSE_PLACEHOLDERS );
114
+ PVC_RECURSE_AGGREGATES , PVC_RECURSE_PLACEHOLDERS );
84
115
#endif
85
- columns = list_union (columns , targetcolumns );
116
+ columns = list_union (columns , targetcolumns );
117
+ }
86
118
}
87
119
return columns ;
88
120
}
@@ -151,6 +183,10 @@ unnestClause(Node *node)
151
183
return (Node * )((RelabelType * )node )-> arg ;
152
184
case T_ArrayCoerceExpr :
153
185
return (Node * )((ArrayCoerceExpr * )node )-> arg ;
186
+ #if PG_VERSION_NUM >= 160000
187
+ case T_RestrictInfo :
188
+ return (Node * )((RestrictInfo * )node )-> clause ;
189
+ #endif
154
190
default :
155
191
return node ;
156
192
}
@@ -341,23 +377,35 @@ colnameFromVar(Var *var, PlannerInfo *root, FdwPlanState *planstate)
341
377
*/
342
378
bool isAttrInRestrictInfo (Index relid , AttrNumber attno , RestrictInfo * restrictinfo )
343
379
{
344
- List * vars = pull_var_clause ((Node * )restrictinfo -> clause ,
345
- #if PG_VERSION_NUM >= 90600
346
- PVC_RECURSE_AGGREGATES |
347
- PVC_RECURSE_PLACEHOLDERS );
348
- #else
349
- PVC_RECURSE_AGGREGATES ,
350
- PVC_RECURSE_PLACEHOLDERS );
351
- #endif
380
+ List * vars ;
352
381
ListCell * lc ;
382
+ List * actual_clauses ;
383
+ ListCell * clause_lc ;
384
+
385
+ elog (DEBUG1 , "DEBUG: isAttrInRestrictInfo using extract_actual_clauses (clause nodeTag=%d)" , nodeTag ((Node * )restrictinfo -> clause ));
386
+
387
+ /* Use extract_actual_clauses to properly handle RestrictInfo */
388
+ actual_clauses = extract_actual_clauses (list_make1 (restrictinfo ), false);
353
389
354
- foreach (lc , vars )
390
+ foreach (clause_lc , actual_clauses )
355
391
{
356
- Var * var = (Var * )lfirst (lc );
392
+ Node * clause = (Node * )lfirst (clause_lc );
357
393
358
- if (var -> varno == relid && var -> varattno == attno )
394
+ vars = pull_var_clause (clause ,
395
+ #if PG_VERSION_NUM >= 90600
396
+ PVC_RECURSE_AGGREGATES | PVC_RECURSE_PLACEHOLDERS );
397
+ #else
398
+ PVC_RECURSE_AGGREGATES , PVC_RECURSE_PLACEHOLDERS );
399
+ #endif
400
+
401
+ foreach (lc , vars )
359
402
{
360
- return true;
403
+ Var * var = (Var * )lfirst (lc );
404
+
405
+ if (var -> varno == relid && var -> varattno == attno )
406
+ {
407
+ return true;
408
+ }
361
409
}
362
410
}
363
411
return false;
0 commit comments