Thread: Why does exprCollation reject List node?
Hi all, During writing pgsql_fdw codes, I noticed that exprCollation rejects non-Expr nodes with error "unrecognized node type: %d". Is this intentional behavior, or can it return InvalidOid for unrecognized nodes like exprInputCollation? Background information: I use exprCollation with expression_walker in pgsql_fdw to know whether an expression in baserestrictinfo->clause list uses any collation, to determine the clause can be pushed down safely. I want to allow pushing ScalarArrayOpExpr down, but its argument is represented as List, so a query contains ScalarArrayOpExpr ends with error when the traversing expression tree reaches arguments of ScalarArrayOpExpr. I've spent only few hours for research though, but the interface of exprCollation seems little odd. It accepts Node*, but its switch statement assumes that given object should be something derived from Expr, and it rejects other objects with elog(ERROR). Anyone know the reason? Regards, -- Shigeru Hanada
Shigeru HANADA <shigeru.hanada@gmail.com> writes: > During writing pgsql_fdw codes, I noticed that exprCollation rejects > non-Expr nodes with error "unrecognized node type: %d". Is this > intentional behavior, or can it return InvalidOid for unrecognized nodes > like exprInputCollation? Doesn't seem to me that asking for the collation of a list is very sensible, so I don't see a problem with that. > Background information: I use exprCollation with expression_walker in > pgsql_fdw to know whether an expression in baserestrictinfo->clause list > uses any collation, to determine the clause can be pushed down safely. Returning InvalidOid in such a case would be the *wrong answer*, because it would presumably lead the code to conclude that nothing within the list has a collation, which ain't necessarily so. regards, tom lane
On Fri, Mar 16, 2012 at 10:17 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote: > Shigeru HANADA <shigeru.hanada@gmail.com> writes: >> During writing pgsql_fdw codes, I noticed that exprCollation rejects >> non-Expr nodes with error "unrecognized node type: %d". Is this >> intentional behavior, or can it return InvalidOid for unrecognized nodes >> like exprInputCollation? > > Doesn't seem to me that asking for the collation of a list is very > sensible, so I don't see a problem with that. Oh, I've used the function wrongly. It returns the collation of the result of the expression, so passing a list doesn't make any sense. The comment of expression_tree_walker clearly says that it can handle List as well, so handling List in foreign_expr_walker by calilng itself recursively for each element in the list seems necessary. Regards, -- Shigeru Hanada