Skip to content

Commit 684ffac

Browse files
committed
Remove unnecessary code in dependency_is_compatible_expression().
Scanning the expression for compatible Vars isn't really necessary, because the subsequent match against StatisticExtInfo entries will eliminate expressions containing other Vars just fine. Moreover, this code hadn't stopped to think about what to do with PlaceHolderVars or Aggrefs in the clause; and at least for the PHV case, that demonstrably leads to failures. Rather than work out whether it's reasonable to ignore those, let's just remove the whole stanza. Per report from Richard Guo. Back-patch to v14 where this code was added. Discussion: https://postgr.es/m/CAMbWs48Mmvm-acGevXuwpB=g5JMqVSL6i9z5UaJyLGJqa-XPAA@mail.gmail.com
1 parent bdc8d80 commit 684ffac

File tree

1 file changed

+3
-25
lines changed

1 file changed

+3
-25
lines changed

src/backend/statistics/dependencies.c

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,13 +1163,12 @@ clauselist_apply_dependencies(PlannerInfo *root, List *clauses,
11631163
* Determines if the expression is compatible with functional dependencies
11641164
*
11651165
* Similar to dependency_is_compatible_clause, but doesn't enforce that the
1166-
* expression is a simple Var. OTOH we check that there's at least one
1167-
* statistics object matching the expression.
1166+
* expression is a simple Var. On success, return the matching statistics
1167+
* expression into *expr.
11681168
*/
11691169
static bool
11701170
dependency_is_compatible_expression(Node *clause, Index relid, List *statlist, Node **expr)
11711171
{
1172-
List *vars;
11731172
ListCell *lc,
11741173
*lc2;
11751174
Node *clause_expr;
@@ -1316,29 +1315,8 @@ dependency_is_compatible_expression(Node *clause, Index relid, List *statlist, N
13161315
if (IsA(clause_expr, RelabelType))
13171316
clause_expr = (Node *) ((RelabelType *) clause_expr)->arg;
13181317

1319-
vars = pull_var_clause(clause_expr, 0);
1320-
1321-
foreach(lc, vars)
1322-
{
1323-
Var *var = (Var *) lfirst(lc);
1324-
1325-
/* Ensure Var is from the correct relation */
1326-
if (var->varno != relid)
1327-
return false;
1328-
1329-
/* We also better ensure the Var is from the current level */
1330-
if (var->varlevelsup != 0)
1331-
return false;
1332-
1333-
/* Also ignore system attributes (we don't allow stats on those) */
1334-
if (!AttrNumberIsForUserDefinedAttr(var->varattno))
1335-
return false;
1336-
}
1337-
13381318
/*
1339-
* Check if we actually have a matching statistics for the expression.
1340-
*
1341-
* XXX Maybe this is an overkill. We'll eliminate the expressions later.
1319+
* Search for a matching statistics expression.
13421320
*/
13431321
foreach(lc, statlist)
13441322
{

0 commit comments

Comments
 (0)