Allow rel_is_distinct_for() to look through RelabelType below OpExpr.

This lets it do the right thing for, eg, varchar columns.
Back-patch to 9.5 where this logic appeared.

David Rowley, per report from Kim Rose Carlsen

Discussion: https://postgr.es/m/VI1PR05MB17091F9A9876528055D6A827C76D0@VI1PR05MB1709.eurprd05.prod.outlook.com
This commit is contained in:
Tom Lane 2017-09-17 15:28:51 -04:00
parent 27c6619e9c
commit 6f44fe7f12
1 changed files with 8 additions and 0 deletions

View File

@ -703,6 +703,14 @@ rel_is_distinct_for(PlannerInfo *root, RelOptInfo *rel, List *clause_list)
else
var = (Var *) get_leftop(rinfo->clause);
/*
* We may ignore any RelabelType node above the operand. (There
* won't be more than one, since eval_const_expressions() has been
* applied already.)
*/
if (var && IsA(var, RelabelType))
var = (Var *) ((RelabelType *) var)->arg;
/*
* If inner side isn't a Var referencing a subquery output column,
* this clause doesn't help us.