Alvaro Herrera <alvhe...@2ndquadrant.com> writes: > You do? Unless I misunderstood, your options are:
> 1. (the patch you attached) create a temporary memory context that is > used for everything, then at the end copy the good stuff to CacheMemCxt > (or a sub-context thereof). This still needs to copy. > 2. create a temp memory context, do everything there, do retail freeing > of everything we don't want, reparenting the context to CacheMemCxt. > Hope we didn't forget to pfree anything. > How is any of those superior to what I propose? I doubt that what you're suggesting is terribly workable. It's not just RelationBuildPartitionDesc that's at issue. Part of what will be the long-lived data structure is made by partition_bounds_create, and that invokes quite a boatload of code that both makes the final data structure and leaks a lot of intermediate junk. Having to be very careful about permanent vs temporary data throughout all of that seems like a recipe for bugs. The existing code in RelationBuildPartitionDesc is already pretty good about avoiding copying of data other than the output of partition_bounds_create. In fact, I think it's already close to what you're suggesting other than that point. So I think --- particularly given that we need something we can back-patch into v11 --- that we shouldn't try to do anything much more complicated than what Robert is suggesting. regards, tom lane