On 01/06/2016 12:03 PM, David Rowley wrote:
I am not familiar with PostgreSQL optimizer, but I now looking inside its code and trying to find a way to fix this problem.
But if there is somebody is familar with optimizer and already knows solution, please let me know so that I do no spend time on this.
Actually I expect that most of the logic is already present in optimizer: there are several places where it is considered where and how to evaluate tlist.
For example, there are functions use_physical_tlist/disuse_physical_tlist which triggers whether the relation targetlist or only those Vars actually needed by the query. Not sure that that them are related to this particular case...
So most likely it will be enough to insert just one function call is the proper place, but it is necessary to find the function and the place;)