]> granicus.if.org Git - postgresql/commitdiff
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 e28a8dc533e66e3bb1aef6d02e76fc757f682a59..614fd293ed1b4b5ddba4c233c3817a579f5f3408 100644 (file)
@@ -617,6 +617,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.