Re: Functional dependencies and GROUP BY

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Peter Eisentraut <peter_e@gmx.net>
Cc: Alex Hunsaker <badalex@gmail.com>, pgsql-hackers@postgresql.org
Date: 2010-08-07T02:51:32Z
Lists: pgsql-hackers
Peter Eisentraut <peter_e@gmx.net> writes:
> Next version.  Changed dependencies to pg_constraint, removed handling
> of unique constraints for now, and made some enhancements so that views
> track dependencies on constraints even in subqueries.  Should be close
> to final now. :-)

I've committed this with some revisions, notably:

The view.c changes were fundamentally wrong.  The right place to
extract dependencies from a parsetree is in dependency.c, specifically
find_expr_references_walker.  The way you were doing it meant that
dependencies on constraints would only be noticed for views, not for
other cases such as stored plans.

I rewrote the catalog search to look only at pg_constraint, not using
pg_index at all.  I think this will be easier to extend to the case of
looking for UNIQUE + NOT NULL, whenever we get around to doing that.
I also moved the search into catalog/pg_constraint.c, because it didn't
seem to belong in parse_agg (as hinted by the large number of #include
additions you had to make to put it there).

I put in a bit of caching logic to prevent repeating the search for
multiple Vars of the same relation.  Tests or no tests, I can't believe
that's going to be cheap enough that we want to repeat it over and
over...

			regards, tom lane