]> granicus.if.org Git - postgresql/blob - src/backend/optimizer/plan/setrefs.c
513480c4e20691d0964671c900f360e101bbd981
[postgresql] / src / backend / optimizer / plan / setrefs.c
1 /*-------------------------------------------------------------------------
2  *
3  * setrefs.c
4  *        Post-processing of a completed plan tree: fix references to subplan
5  *        vars, and compute regproc values for operators
6  *
7  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  *
11  * IDENTIFICATION
12  *        $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.90 2003/01/15 23:10:32 tgl Exp $
13  *
14  *-------------------------------------------------------------------------
15  */
16 #include "postgres.h"
17
18
19 #include "nodes/makefuncs.h"
20 #include "nodes/nodeFuncs.h"
21 #include "optimizer/clauses.h"
22 #include "optimizer/planmain.h"
23 #include "optimizer/tlist.h"
24 #include "optimizer/var.h"
25 #include "parser/parsetree.h"
26
27
28 typedef struct
29 {
30         List       *rtable;
31         List       *outer_tlist;
32         List       *inner_tlist;
33         Index           acceptable_rel;
34 } join_references_context;
35
36 typedef struct
37 {
38         Index           subvarno;
39         List       *subplan_targetlist;
40         bool            tlist_has_non_vars;
41 } replace_vars_with_subplan_refs_context;
42
43 static void fix_expr_references(Plan *plan, Node *node);
44 static bool fix_expr_references_walker(Node *node, void *context);
45 static void set_join_references(Join *join, List *rtable);
46 static void set_uppernode_references(Plan *plan, Index subvarno);
47 static List *join_references(List *clauses,
48                                                          List *rtable,
49                                                          List *outer_tlist,
50                                                          List *inner_tlist,
51                                                          Index acceptable_rel);
52 static Node *join_references_mutator(Node *node,
53                                                 join_references_context *context);
54 static Node *replace_vars_with_subplan_refs(Node *node,
55                                                            Index subvarno,
56                                                            List *subplan_targetlist,
57                                                            bool tlist_has_non_vars);
58 static Node *replace_vars_with_subplan_refs_mutator(Node *node,
59                                                 replace_vars_with_subplan_refs_context *context);
60 static bool fix_opfuncids_walker(Node *node, void *context);
61
62 /*****************************************************************************
63  *
64  *              SUBPLAN REFERENCES
65  *
66  *****************************************************************************/
67
68 /*
69  * set_plan_references
70  *        This is the final processing pass of the planner/optimizer.  The plan
71  *        tree is complete; we just have to adjust some representational details
72  *        for the convenience of the executor.  We update Vars in upper plan nodes
73  *        to refer to the outputs of their subplans, and we compute regproc OIDs
74  *        for operators (ie, we look up the function that implements each op).
75  *
76  *        set_plan_references recursively traverses the whole plan tree.
77  *
78  * Returns nothing of interest, but modifies internal fields of nodes.
79  */
80 void
81 set_plan_references(Plan *plan, List *rtable)
82 {
83         List       *pl;
84
85         if (plan == NULL)
86                 return;
87
88         /*
89          * Plan-type-specific fixes
90          */
91         switch (nodeTag(plan))
92         {
93                 case T_SeqScan:
94                         fix_expr_references(plan, (Node *) plan->targetlist);
95                         fix_expr_references(plan, (Node *) plan->qual);
96                         break;
97                 case T_IndexScan:
98                         fix_expr_references(plan, (Node *) plan->targetlist);
99                         fix_expr_references(plan, (Node *) plan->qual);
100                         fix_expr_references(plan,
101                                                                 (Node *) ((IndexScan *) plan)->indxqual);
102                         fix_expr_references(plan,
103                                                         (Node *) ((IndexScan *) plan)->indxqualorig);
104                         break;
105                 case T_TidScan:
106                         fix_expr_references(plan, (Node *) plan->targetlist);
107                         fix_expr_references(plan, (Node *) plan->qual);
108                         fix_expr_references(plan,
109                                                                 (Node *) ((TidScan *) plan)->tideval);
110                         break;
111                 case T_SubqueryScan:
112                         {
113                                 RangeTblEntry *rte;
114
115                                 /*
116                                  * We do not do set_uppernode_references() here, because a
117                                  * SubqueryScan will always have been created with correct
118                                  * references to its subplan's outputs to begin with.
119                                  */
120                                 fix_expr_references(plan, (Node *) plan->targetlist);
121                                 fix_expr_references(plan, (Node *) plan->qual);
122
123                                 /* Recurse into subplan too */
124                                 rte = rt_fetch(((SubqueryScan *) plan)->scan.scanrelid,
125                                                            rtable);
126                                 Assert(rte->rtekind == RTE_SUBQUERY);
127                                 set_plan_references(((SubqueryScan *) plan)->subplan,
128                                                                         rte->subquery->rtable);
129                         }
130                         break;
131                 case T_FunctionScan:
132                         {
133                                 RangeTblEntry *rte;
134
135                                 fix_expr_references(plan, (Node *) plan->targetlist);
136                                 fix_expr_references(plan, (Node *) plan->qual);
137                                 rte = rt_fetch(((FunctionScan *) plan)->scan.scanrelid,
138                                                            rtable);
139                                 Assert(rte->rtekind == RTE_FUNCTION);
140                                 fix_expr_references(plan, rte->funcexpr);
141                         }
142                         break;
143                 case T_NestLoop:
144                         set_join_references((Join *) plan, rtable);
145                         fix_expr_references(plan, (Node *) plan->targetlist);
146                         fix_expr_references(plan, (Node *) plan->qual);
147                         fix_expr_references(plan, (Node *) ((Join *) plan)->joinqual);
148                         break;
149                 case T_MergeJoin:
150                         set_join_references((Join *) plan, rtable);
151                         fix_expr_references(plan, (Node *) plan->targetlist);
152                         fix_expr_references(plan, (Node *) plan->qual);
153                         fix_expr_references(plan, (Node *) ((Join *) plan)->joinqual);
154                         fix_expr_references(plan,
155                                                         (Node *) ((MergeJoin *) plan)->mergeclauses);
156                         break;
157                 case T_HashJoin:
158                         set_join_references((Join *) plan, rtable);
159                         fix_expr_references(plan, (Node *) plan->targetlist);
160                         fix_expr_references(plan, (Node *) plan->qual);
161                         fix_expr_references(plan, (Node *) ((Join *) plan)->joinqual);
162                         fix_expr_references(plan,
163                                                           (Node *) ((HashJoin *) plan)->hashclauses);
164                         break;
165                 case T_Hash:
166                         /*
167                          * Hash does not evaluate its targetlist or quals, so don't
168                          * touch those (see comments below).  But we do need to fix its
169                          * hashkeys.  The hashkeys are a little bizarre because they
170                          * need to match the hashclauses of the parent HashJoin node,
171                          * so we use join_references to fix them.
172                          */
173                         ((Hash *) plan)->hashkeys =
174                                 join_references(((Hash *) plan)->hashkeys,
175                                                                 rtable,
176                                                                 NIL,
177                                                                 plan->lefttree->targetlist,
178                                                                 (Index) 0);
179                         break;
180                 case T_Material:
181                 case T_Sort:
182                 case T_Unique:
183                 case T_SetOp:
184                 case T_Limit:
185
186                         /*
187                          * These plan types don't actually bother to evaluate their
188                          * targetlists or quals (because they just return their
189                          * unmodified input tuples).  The optimizer is lazy about
190                          * creating really valid targetlists for them.  Best to just
191                          * leave the targetlist alone.  In particular, we do not want
192                          * to process subplans for them, since we will likely end
193                          * up reprocessing subplans that also appear in lower levels
194                          * of the plan tree!
195                          */
196                         break;
197                 case T_Agg:
198                 case T_Group:
199                         set_uppernode_references(plan, (Index) 0);
200                         fix_expr_references(plan, (Node *) plan->targetlist);
201                         fix_expr_references(plan, (Node *) plan->qual);
202                         break;
203                 case T_Result:
204
205                         /*
206                          * Result may or may not have a subplan; no need to fix up
207                          * subplan references if it hasn't got one...
208                          *
209                          * XXX why does Result use a different subvarno from Agg/Group?
210                          */
211                         if (plan->lefttree != NULL)
212                                 set_uppernode_references(plan, (Index) OUTER);
213                         fix_expr_references(plan, (Node *) plan->targetlist);
214                         fix_expr_references(plan, (Node *) plan->qual);
215                         fix_expr_references(plan, ((Result *) plan)->resconstantqual);
216                         break;
217                 case T_Append:
218
219                         /*
220                          * Append, like Sort et al, doesn't actually evaluate its
221                          * targetlist or quals, and we haven't bothered to give it its
222                          * own tlist copy.      So, don't fix targetlist/qual. But do
223                          * recurse into child plans.
224                          */
225                         foreach(pl, ((Append *) plan)->appendplans)
226                                 set_plan_references((Plan *) lfirst(pl), rtable);
227                         break;
228                 default:
229                         elog(ERROR, "set_plan_references: unknown plan type %d",
230                                  nodeTag(plan));
231                         break;
232         }
233
234         /*
235          * Now recurse into child plans and initplans, if any
236          *
237          * NOTE: it is essential that we recurse into child plans AFTER we set
238          * subplan references in this plan's tlist and quals.  If we did the
239          * reference-adjustments bottom-up, then we would fail to match this
240          * plan's var nodes against the already-modified nodes of the
241          * children.  Fortunately, that consideration doesn't apply to SubPlan
242          * nodes; else we'd need two passes over the expression trees.
243          */
244         set_plan_references(plan->lefttree, rtable);
245         set_plan_references(plan->righttree, rtable);
246
247         foreach(pl, plan->initPlan)
248         {
249                 SubPlan *sp = (SubPlan *) lfirst(pl);
250
251                 Assert(IsA(sp, SubPlan));
252                 set_plan_references(sp->plan, sp->rtable);
253         }
254 }
255
256 /*
257  * fix_expr_references
258  *        Do final cleanup on expressions (targetlists or quals).
259  *
260  * This consists of looking up operator opcode info for OpExpr nodes
261  * and recursively performing set_plan_references on subplans.
262  *
263  * The Plan argument is currently unused, but might be needed again someday.
264  */
265 static void
266 fix_expr_references(Plan *plan, Node *node)
267 {
268         /* This tree walk requires no special setup, so away we go... */
269         fix_expr_references_walker(node, NULL);
270 }
271
272 static bool
273 fix_expr_references_walker(Node *node, void *context)
274 {
275         if (node == NULL)
276                 return false;
277         if (IsA(node, OpExpr))
278                 set_opfuncid((OpExpr *) node);
279         else if (IsA(node, DistinctExpr))
280                 set_opfuncid((OpExpr *) node); /* rely on struct equivalence */
281         else if (IsA(node, SubPlan))
282         {
283                 SubPlan *sp = (SubPlan *) node;
284
285                 set_plan_references(sp->plan, sp->rtable);
286         }
287         return expression_tree_walker(node, fix_expr_references_walker, context);
288 }
289
290 /*
291  * set_join_references
292  *        Modifies the target list and quals of a join node to reference its
293  *        subplans, by setting the varnos to OUTER or INNER and setting attno
294  *        values to the result domain number of either the corresponding outer
295  *        or inner join tuple item.
296  *
297  * In the case of a nestloop with inner indexscan, we will also need to
298  * apply the same transformation to any outer vars appearing in the
299  * quals of the child indexscan.
300  *
301  *      'join' is a join plan node
302  *      'rtable' is the associated range table
303  */
304 static void
305 set_join_references(Join *join, List *rtable)
306 {
307         Plan       *outer_plan = join->plan.lefttree;
308         Plan       *inner_plan = join->plan.righttree;
309         List       *outer_tlist = outer_plan->targetlist;
310         List       *inner_tlist = inner_plan->targetlist;
311
312         /* All join plans have tlist, qual, and joinqual */
313         join->plan.targetlist = join_references(join->plan.targetlist,
314                                                                                         rtable,
315                                                                                         outer_tlist,
316                                                                                         inner_tlist,
317                                                                                         (Index) 0);
318         join->plan.qual = join_references(join->plan.qual,
319                                                                           rtable,
320                                                                           outer_tlist,
321                                                                           inner_tlist,
322                                                                           (Index) 0);
323         join->joinqual = join_references(join->joinqual,
324                                                                          rtable,
325                                                                          outer_tlist,
326                                                                          inner_tlist,
327                                                                          (Index) 0);
328
329         /* Now do join-type-specific stuff */
330         if (IsA(join, NestLoop))
331         {
332                 if (IsA(inner_plan, IndexScan))
333                 {
334                         /*
335                          * An index is being used to reduce the number of tuples scanned
336                          * in the inner relation.  If there are join clauses being used
337                          * with the index, we must update their outer-rel var nodes to
338                          * refer to the outer side of the join.
339                          */
340                         IndexScan  *innerscan = (IndexScan *) inner_plan;
341                         List       *indxqualorig = innerscan->indxqualorig;
342
343                         /* No work needed if indxqual refers only to its own rel... */
344                         if (NumRelids((Node *) indxqualorig) > 1)
345                         {
346                                 Index           innerrel = innerscan->scan.scanrelid;
347
348                                 /* only refs to outer vars get changed in the inner qual */
349                                 innerscan->indxqualorig = join_references(indxqualorig,
350                                                                                                                   rtable,
351                                                                                                                   outer_tlist,
352                                                                                                                   NIL,
353                                                                                                                   innerrel);
354                                 innerscan->indxqual = join_references(innerscan->indxqual,
355                                                                                                           rtable,
356                                                                                                           outer_tlist,
357                                                                                                           NIL,
358                                                                                                           innerrel);
359                                 /*
360                                  * We must fix the inner qpqual too, if it has join clauses
361                                  * (this could happen if the index is lossy: some indxquals
362                                  * may get rechecked as qpquals).
363                                  */
364                                 if (NumRelids((Node *) inner_plan->qual) > 1)
365                                         inner_plan->qual = join_references(inner_plan->qual,
366                                                                                                            rtable,
367                                                                                                            outer_tlist,
368                                                                                                            NIL,
369                                                                                                            innerrel);
370                         }
371                 }
372                 else if (IsA(inner_plan, TidScan))
373                 {
374                         TidScan    *innerscan = (TidScan *) inner_plan;
375                         Index           innerrel = innerscan->scan.scanrelid;
376
377                         innerscan->tideval = join_references(innerscan->tideval,
378                                                                                                  rtable,
379                                                                                                  outer_tlist,
380                                                                                                  NIL,
381                                                                                                  innerrel);
382                 }
383         }
384         else if (IsA(join, MergeJoin))
385         {
386                 MergeJoin  *mj = (MergeJoin *) join;
387
388                 mj->mergeclauses = join_references(mj->mergeclauses,
389                                                                                    rtable,
390                                                                                    outer_tlist,
391                                                                                    inner_tlist,
392                                                                                    (Index) 0);
393         }
394         else if (IsA(join, HashJoin))
395         {
396                 HashJoin   *hj = (HashJoin *) join;
397
398                 hj->hashclauses = join_references(hj->hashclauses,
399                                                                                   rtable,
400                                                                                   outer_tlist,
401                                                                                   inner_tlist,
402                                                                                   (Index) 0);
403         }
404 }
405
406 /*
407  * set_uppernode_references
408  *        Update the targetlist and quals of an upper-level plan node
409  *        to refer to the tuples returned by its lefttree subplan.
410  *
411  * This is used for single-input plan types like Agg, Group, Result.
412  *
413  * In most cases, we have to match up individual Vars in the tlist and
414  * qual expressions with elements of the subplan's tlist (which was
415  * generated by flatten_tlist() from these selfsame expressions, so it
416  * should have all the required variables).  There is an important exception,
417  * however: GROUP BY and ORDER BY expressions will have been pushed into the
418  * subplan tlist unflattened.  If these values are also needed in the output
419  * then we want to reference the subplan tlist element rather than recomputing
420  * the expression.
421  */
422 static void
423 set_uppernode_references(Plan *plan, Index subvarno)
424 {
425         Plan       *subplan = plan->lefttree;
426         List       *subplan_targetlist,
427                            *output_targetlist,
428                            *l;
429         bool            tlist_has_non_vars;
430
431         if (subplan != NULL)
432                 subplan_targetlist = subplan->targetlist;
433         else
434                 subplan_targetlist = NIL;
435
436         /*
437          * Detect whether subplan tlist has any non-Vars (typically it won't
438          * because it's been flattened).  This allows us to save comparisons
439          * in common cases.
440          */
441         tlist_has_non_vars = false;
442         foreach(l, subplan_targetlist)
443         {
444                 TargetEntry *tle = (TargetEntry *) lfirst(l);
445
446                 if (tle->expr && !IsA(tle->expr, Var))
447                 {
448                         tlist_has_non_vars = true;
449                         break;
450                 }
451         }
452
453         output_targetlist = NIL;
454         foreach(l, plan->targetlist)
455         {
456                 TargetEntry *tle = (TargetEntry *) lfirst(l);
457                 Node       *newexpr;
458
459                 newexpr = replace_vars_with_subplan_refs((Node *) tle->expr,
460                                                                                                  subvarno,
461                                                                                                  subplan_targetlist,
462                                                                                                  tlist_has_non_vars);
463                 output_targetlist = lappend(output_targetlist,
464                                                                   makeTargetEntry(tle->resdom,
465                                                                                                   (Expr *) newexpr));
466         }
467         plan->targetlist = output_targetlist;
468
469         plan->qual = (List *)
470                 replace_vars_with_subplan_refs((Node *) plan->qual,
471                                                                            subvarno,
472                                                                            subplan_targetlist,
473                                                                            tlist_has_non_vars);
474 }
475
476 /*
477  * join_references
478  *         Creates a new set of targetlist entries or join qual clauses by
479  *         changing the varno/varattno values of variables in the clauses
480  *         to reference target list values from the outer and inner join
481  *         relation target lists.
482  *
483  * This is used in two different scenarios: a normal join clause, where
484  * all the Vars in the clause *must* be replaced by OUTER or INNER references;
485  * and an indexscan being used on the inner side of a nestloop join.
486  * In the latter case we want to replace the outer-relation Vars by OUTER
487  * references, but not touch the Vars of the inner relation.
488  *
489  * For a normal join, acceptable_rel should be zero so that any failure to
490  * match a Var will be reported as an error.  For the indexscan case,
491  * pass inner_tlist = NIL and acceptable_rel = the ID of the inner relation.
492  *
493  * 'clauses' is the targetlist or list of join clauses
494  * 'rtable' is the current range table
495  * 'outer_tlist' is the target list of the outer join relation
496  * 'inner_tlist' is the target list of the inner join relation, or NIL
497  * 'acceptable_rel' is either zero or the rangetable index of a relation
498  *              whose Vars may appear in the clause without provoking an error.
499  *
500  * Returns the new expression tree.  The original clause structure is
501  * not modified.
502  */
503 static List *
504 join_references(List *clauses,
505                                 List *rtable,
506                                 List *outer_tlist,
507                                 List *inner_tlist,
508                                 Index acceptable_rel)
509 {
510         join_references_context context;
511
512         context.rtable = rtable;
513         context.outer_tlist = outer_tlist;
514         context.inner_tlist = inner_tlist;
515         context.acceptable_rel = acceptable_rel;
516         return (List *) join_references_mutator((Node *) clauses, &context);
517 }
518
519 static Node *
520 join_references_mutator(Node *node,
521                                                 join_references_context *context)
522 {
523         if (node == NULL)
524                 return NULL;
525         if (IsA(node, Var))
526         {
527                 Var                *var = (Var *) node;
528                 Resdom     *resdom;
529
530                 /* First look for the var in the input tlists */
531                 resdom = tlist_member((Node *) var, context->outer_tlist);
532                 if (resdom)
533                 {
534                         Var                *newvar = (Var *) copyObject(var);
535
536                         newvar->varno = OUTER;
537                         newvar->varattno = resdom->resno;
538                         return (Node *) newvar;
539                 }
540                 resdom = tlist_member((Node *) var, context->inner_tlist);
541                 if (resdom)
542                 {
543                         Var                *newvar = (Var *) copyObject(var);
544
545                         newvar->varno = INNER;
546                         newvar->varattno = resdom->resno;
547                         return (Node *) newvar;
548                 }
549
550                 /* Return the Var unmodified, if it's for acceptable_rel */
551                 if (var->varno == context->acceptable_rel)
552                         return (Node *) copyObject(var);
553
554                 /* No referent found for Var */
555                 elog(ERROR, "join_references: variable not in subplan target lists");
556         }
557         return expression_tree_mutator(node,
558                                                                    join_references_mutator,
559                                                                    (void *) context);
560 }
561
562 /*
563  * replace_vars_with_subplan_refs
564  *              This routine modifies an expression tree so that all Var nodes
565  *              reference target nodes of a subplan.  It is used to fix up
566  *              target and qual expressions of non-join upper-level plan nodes.
567  *
568  * An error is raised if no matching var can be found in the subplan tlist
569  * --- so this routine should only be applied to nodes whose subplans'
570  * targetlists were generated via flatten_tlist() or some such method.
571  *
572  * If tlist_has_non_vars is true, then we try to match whole subexpressions
573  * against elements of the subplan tlist, so that we can avoid recomputing
574  * expressions that were already computed by the subplan.  (This is relatively
575  * expensive, so we don't want to try it in the common case where the
576  * subplan tlist is just a flattened list of Vars.)
577  *
578  * 'node': the tree to be fixed (a target item or qual)
579  * 'subvarno': varno to be assigned to all Vars
580  * 'subplan_targetlist': target list for subplan
581  * 'tlist_has_non_vars': true if subplan_targetlist contains non-Var exprs
582  *
583  * The resulting tree is a copy of the original in which all Var nodes have
584  * varno = subvarno, varattno = resno of corresponding subplan target.
585  * The original tree is not modified.
586  */
587 static Node *
588 replace_vars_with_subplan_refs(Node *node,
589                                                            Index subvarno,
590                                                            List *subplan_targetlist,
591                                                            bool tlist_has_non_vars)
592 {
593         replace_vars_with_subplan_refs_context context;
594
595         context.subvarno = subvarno;
596         context.subplan_targetlist = subplan_targetlist;
597         context.tlist_has_non_vars = tlist_has_non_vars;
598         return replace_vars_with_subplan_refs_mutator(node, &context);
599 }
600
601 static Node *
602 replace_vars_with_subplan_refs_mutator(Node *node,
603                                                  replace_vars_with_subplan_refs_context *context)
604 {
605         if (node == NULL)
606                 return NULL;
607         if (IsA(node, Var))
608         {
609                 Var                *var = (Var *) node;
610                 Resdom     *resdom;
611                 Var                *newvar;
612
613                 resdom = tlist_member((Node *) var, context->subplan_targetlist);
614                 if (!resdom)
615                         elog(ERROR, "replace_vars_with_subplan_refs: variable not in subplan target list");
616                 newvar = (Var *) copyObject(var);
617                 newvar->varno = context->subvarno;
618                 newvar->varattno = resdom->resno;
619                 return (Node *) newvar;
620         }
621         /* Try matching more complex expressions too, if tlist has any */
622         if (context->tlist_has_non_vars)
623         {
624                 Resdom     *resdom;
625
626                 resdom = tlist_member(node, context->subplan_targetlist);
627                 if (resdom)
628                 {
629                         /* Found a matching subplan output expression */
630                         Var                *newvar;
631
632                         newvar = makeVar(context->subvarno,
633                                                          resdom->resno,
634                                                          resdom->restype,
635                                                          resdom->restypmod,
636                                                          0);
637                         newvar->varnoold = 0;           /* wasn't ever a plain Var */
638                         newvar->varoattno = 0;
639                         return (Node *) newvar;
640                 }
641         }
642         return expression_tree_mutator(node,
643                                                                    replace_vars_with_subplan_refs_mutator,
644                                                                    (void *) context);
645 }
646
647 /*****************************************************************************
648  *                                      OPERATOR REGPROC LOOKUP
649  *****************************************************************************/
650
651 /*
652  * fix_opfuncids
653  *        Calculate opfuncid field from opno for each OpExpr node in given tree.
654  *        The given tree can be anything expression_tree_walker handles.
655  *
656  * The argument is modified in-place.  (This is OK since we'd want the
657  * same change for any node, even if it gets visited more than once due to
658  * shared structure.)
659  */
660 void
661 fix_opfuncids(Node *node)
662 {
663         /* This tree walk requires no special setup, so away we go... */
664         fix_opfuncids_walker(node, NULL);
665 }
666
667 static bool
668 fix_opfuncids_walker(Node *node, void *context)
669 {
670         if (node == NULL)
671                 return false;
672         if (IsA(node, OpExpr))
673                 set_opfuncid((OpExpr *) node);
674         else if (IsA(node, DistinctExpr))
675                 set_opfuncid((OpExpr *) node); /* rely on struct equivalence */
676         return expression_tree_walker(node, fix_opfuncids_walker, context);
677 }