Re: Checking join outer relation uniqueness to prevent unnecessary memoization - Mailing list pgsql-hackers

From David Rowley
Subject Re: Checking join outer relation uniqueness to prevent unnecessary memoization
Date
Msg-id CAApHDvpEziKD4uXOm4ySe7UKZiy4dSeH0Eo+K_O-M-dyYmGUUw@mail.gmail.com
Whole thread Raw
In response to Checking join outer relation uniqueness to prevent unnecessary memoization  (Jacob Jackson <jej.jackson.08@gmail.com>)
Responses Re: Checking join outer relation uniqueness to prevent unnecessary memoization
List pgsql-hackers
On Fri, 2 Jan 2026 at 04:30, Jacob Jackson <jej.jackson.08@gmail.com> wrote:
> The current memoization cost calculation method often results in memoize nodes being added even when they are useless
dueto the outer side of the join being guaranteed unique due to constraints, increasing overhead unnecessarily. To try
toprevent this, I am exploring methods to check whether the outer side of the join is guaranteed unique before adding
memoizenodes. The simplest method I have found thus far is to use innerrel_is_unique, passing in the outer relation
wherethe inner relation normally would be. This appears to work (although it is logically different from the other uses
ofinnerrel_is_unique), and adds negligible overhead for simple joins because it can often reuse cached values from
otherpotential join orders. 

Do you have an example case of this happening? Ideally, the code that
should disfavour Memoize for this case is estimate_num_groups() as
called in cost_memoize_rescan() by returning that there's 1 group per
input row. I guess that's not happening for this case? Why?

David



pgsql-hackers by date:

Previous
From: Tatsuo Ishii
Date:
Subject: Re: Row pattern recognition
Next
From: Andreas Karlsson
Date:
Subject: Re: Use Postgres as meson wrap subproject