Here's v7; known problems have been addressed except the one above.Jesper's GetCachedPlan() slowness has not been addressed either.

As I said before, I'm thinking of getting rid of the whole business ofchecking partitions on the referenced side of an FK at DROP time, andinstead jut forbid the DROP completely if any FKs reference an ancestorof that partition. We can allow DETACH for the case, which can dealwith scanning the table referenced tuples and remove the appropriatedependencies.