fix issue on slow pg function