@@ -5688,7 +5688,7 @@ examine_simple_variable(PlannerInfo *root, Var *var,
5688
5688
* of learning something even with it.
5689
5689
*/
5690
5690
if (subquery -> setOperations ||
5691
- subquery -> groupClause ||
5691
+ // subquery->groupClause ||
5692
5692
subquery -> groupingSets )
5693
5693
return ;
5694
5694
@@ -5703,6 +5703,42 @@ examine_simple_variable(PlannerInfo *root, Var *var,
5703
5703
rte -> eref -> aliasname , var -> varattno );
5704
5704
var = (Var * ) ste -> expr ;
5705
5705
5706
+ if (subquery -> groupClause )
5707
+ {
5708
+ List * groupVars = NIL ;
5709
+ List * targetVars = NIL ;
5710
+ ListCell * lc ;
5711
+
5712
+ /* Collect unique expressions from GROUP BY */
5713
+ foreach (lc , subquery -> groupClause )
5714
+ {
5715
+ SortGroupClause * sgc = (SortGroupClause * ) lfirst (lc );
5716
+ TargetEntry * tle = get_sortgroupref_tle (sgc -> tleSortGroupRef , subquery -> targetList );
5717
+
5718
+ if (tle && tle -> expr )
5719
+ groupVars = list_append_unique (groupVars , tle -> expr );
5720
+ }
5721
+
5722
+ /* Collect unique expressions from the target list */
5723
+ foreach (lc , subquery -> targetList )
5724
+ {
5725
+ TargetEntry * targetTle = (TargetEntry * ) lfirst (lc );
5726
+ if (targetTle && targetTle -> expr )
5727
+ targetVars = list_append_unique (targetVars , targetTle -> expr );
5728
+ }
5729
+
5730
+ if (equal (groupVars , targetVars ))
5731
+ {
5732
+ vardata -> isunique = true;
5733
+ }
5734
+
5735
+ list_free (groupVars );
5736
+ list_free (targetVars );
5737
+ }
5738
+
5739
+
5740
+
5741
+
5706
5742
/*
5707
5743
* If subquery uses DISTINCT, we can't make use of any stats for the
5708
5744
* variable ... but, if it's the only DISTINCT column, we are entitled
0 commit comments