@@ -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
}
@@ -221,8 +257,9 @@ canonicalOpExpr(OpExpr *opExpr, Relids base_relids)
221
257
l = unnestClause (list_nth (opExpr -> args , 0 ));
222
258
r = unnestClause (list_nth (opExpr -> args , 1 ));
223
259
224
- elog (DEBUG5 , "l arg: %s" , nodeToString (l ));
225
- elog (DEBUG5 , "r arg: %s" , nodeToString (r ));
260
+ /* Temporarily disable nodeToString calls to avoid RestrictInfo issues */
261
+ elog (DEBUG5 , "l arg: [nodeToString disabled for debugging]" );
262
+ elog (DEBUG5 , "r arg: [nodeToString disabled for debugging]" );
226
263
227
264
swapOperandsAsNeeded (& l , & r , & operatorid , base_relids );
228
265
@@ -341,23 +378,35 @@ colnameFromVar(Var *var, PlannerInfo *root, FdwPlanState *planstate)
341
378
*/
342
379
bool isAttrInRestrictInfo (Index relid , AttrNumber attno , RestrictInfo * restrictinfo )
343
380
{
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
381
+ List * vars ;
352
382
ListCell * lc ;
383
+ List * actual_clauses ;
384
+ ListCell * clause_lc ;
385
+
386
+ elog (DEBUG1 , "DEBUG: isAttrInRestrictInfo using extract_actual_clauses (clause nodeTag=%d)" , nodeTag ((Node * )restrictinfo -> clause ));
387
+
388
+ /* Use extract_actual_clauses to properly handle RestrictInfo */
389
+ actual_clauses = extract_actual_clauses (list_make1 (restrictinfo ), false);
353
390
354
- foreach (lc , vars )
391
+ foreach (clause_lc , actual_clauses )
355
392
{
356
- Var * var = (Var * )lfirst (lc );
393
+ Node * clause = (Node * )lfirst (clause_lc );
357
394
358
- if (var -> varno == relid && var -> varattno == attno )
395
+ vars = pull_var_clause (clause ,
396
+ #if PG_VERSION_NUM >= 90600
397
+ PVC_RECURSE_AGGREGATES | PVC_RECURSE_PLACEHOLDERS );
398
+ #else
399
+ PVC_RECURSE_AGGREGATES , PVC_RECURSE_PLACEHOLDERS );
400
+ #endif
401
+
402
+ foreach (lc , vars )
359
403
{
360
- return true;
404
+ Var * var = (Var * )lfirst (lc );
405
+
406
+ if (var -> varno == relid && var -> varattno == attno )
407
+ {
408
+ return true;
409
+ }
361
410
}
362
411
}
363
412
return false;
0 commit comments