Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 88fa2ce

Browse files
author
Commitfest Bot
committed
[CF 52/5269] v3 - Improve statistics estimation considering GROUP-BY as a 'uniqueiser'
This commit was automatically generated by a robot at cfbot.cputube.org. It is based on patches submitted to the PostgreSQL mailing lists and registered in the PostgreSQL Commitfest application. This branch will be overwritten each time a new patch version is posted to the email thread, and also periodically to check for bitrot caused by changes on the master branch. Commitfest entry: https://commitfest.postgresql.org/52/5269 Patch(es): https://www.postgresql.org/message-id/b6ad2bb9-94c8-417b-b795-28c1fa9f4793@postgrespro.ru Author(s):
2 parents c623e85 + 2217b3f commit 88fa2ce

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

src/backend/utils/adt/selfuncs.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5688,7 +5688,7 @@ examine_simple_variable(PlannerInfo *root, Var *var,
56885688
* of learning something even with it.
56895689
*/
56905690
if (subquery->setOperations ||
5691-
subquery->groupClause ||
5691+
// subquery->groupClause ||
56925692
subquery->groupingSets)
56935693
return;
56945694

@@ -5703,6 +5703,42 @@ examine_simple_variable(PlannerInfo *root, Var *var,
57035703
rte->eref->aliasname, var->varattno);
57045704
var = (Var *) ste->expr;
57055705

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+
57065742
/*
57075743
* If subquery uses DISTINCT, we can't make use of any stats for the
57085744
* variable ... but, if it's the only DISTINCT column, we are entitled

0 commit comments

Comments
 (0)