diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index b31c52404a..bb4c10b193 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -3056,14 +3056,20 @@ limit_needed(Query *parse) * Since some other DBMSes do not allow references to ungrouped columns, it's * not unusual to find all columns listed in GROUP BY even though listing the * primary-key columns would be sufficient. Deleting such excess columns - * avoids redundant sorting work, so it's worth doing. When we do this, we - * must mark the plan as dependent on the pkey constraint (compare the - * parser's check_ungrouped_columns() and check_functional_grouping()). + * avoids redundant sorting work, so it's worth doing. * - * In principle, we could treat any NOT-NULL columns appearing in a UNIQUE - * index as the determining columns. But as with check_functional_grouping(), - * there's currently no way to represent dependency on a NOT NULL constraint, - * so we consider only the pkey for now. + * Currently we only make use of pkey constraints for this, however, we may + * wish to take this further in the future and also use unique constraints + * which have NOT NULL columns. In the past, there had been some + * misconception that we could not do this due to lack of a way to invalidate + * plans when NOT NULL constraints are dropped. Such plans will be + * invalidated through relcache invalidation during the ALTER TABLE and + * subsequent invalidation checks which are done when we're about to execute + * these plans during the call to AcquireExecutorLocks(). + * + * This should not be confused with check_functional_grouping(), where we must + * record dependencies to ensure objects such as VIEWs do not become invalid + * due to a constraint being dropped. */ static void remove_useless_groupby_columns(PlannerInfo *root) @@ -3172,10 +3178,6 @@ remove_useless_groupby_columns(PlannerInfo *root) /* Remember the attnos of the removable columns */ surplusvars[relid] = bms_difference(relattnos, pkattnos); - - /* Also, mark the resulting plan as dependent on this constraint */ - parse->constraintDeps = lappend_oid(parse->constraintDeps, - constraintOid); } }