From 9d1bba7dc28a219d9de47e14bad5888e9a495877 Mon Sep 17 00:00:00 2001 From: Tomas Vondra Date: Wed, 4 Mar 2020 22:25:54 +0100 Subject: [PATCH 02/11] Simplify parsing of ScalarArrayOpExpr We know ScalarArrayOpExpr is always of the form Var op Const in this exact order, so we don't need to check if var is on the left. --- src/backend/statistics/dependencies.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/backend/statistics/dependencies.c b/src/backend/statistics/dependencies.c index 36941b8535..a75b9d73db 100644 --- a/src/backend/statistics/dependencies.c +++ b/src/backend/statistics/dependencies.c @@ -803,21 +803,22 @@ dependency_is_compatible_clause(Node *clause, Index relid, AttrNumber *attnum) } else if (IsA(rinfo->clause, ScalarArrayOpExpr)) { - /* If it's an opclause, check for Var IN Const. */ + /* If it's an scalar array operator, check for Var IN Const. */ ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) rinfo->clause; /* Only expressions with two arguments are candidates. */ if (list_length(expr->args) != 2) return false; - /* Make sure non-selected argument is a pseudoconstant. */ - if (is_pseudo_constant_clause(lsecond(expr->args))) - var = linitial(expr->args); - else if (is_pseudo_constant_clause(linitial(expr->args))) - var = lsecond(expr->args); - else + /* + * We know it's always (Var IN Const), so we assume the var is the + * first argument, and pseudoconstant is the second one. + */ + if (!is_pseudo_constant_clause(lsecond(expr->args))) return false; + var = linitial(expr->args); + /* * If it's not an "=" operator, just ignore the clause, as it's not * compatible with functional dependencies. The operator is identified -- 2.21.1