Allow rel_is_distinct_for() to look through RelabelType below OpExpr.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 17 Sep 2017 19:28:51 +0000 (15:28 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 17 Sep 2017 19:28:51 +0000 (15:28 -0400)
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

src/backend/optimizer/plan/analyzejoins.c

index 34317fe7782b58f04d4030494069a836dcd5f2d4..511603b5810185d448c8b80dfc2e786bbd765558 100644 (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.