On Oct 16, 2026 05:36, David Rowley <[email protected]> wrote >> overstate Memoize hit rates. > > If that's true for Memoize, please provide a test case that shows a > Memoize node being used on a DEFAULT_NUM_DISTINCT estimate.
Thanks for pointing this out. You are right. I do not have a test case showing a Memoize node being used on a DEFAULT_NUM_DISTINCT estimate. In fact, for Memoize I am trying to address the opposite problem: when a join contains a UNION ALL subquery, the planner detects DEFAULT_NUM_DISTINCT and avoids using Memoize. This patch tries to widen that boundary. I still use the hi estimate (the sum of all member estimates, when available) to avoid overstating the hit rate. Below are the cases I have tested where Memoize is used more effectively. I have not yet found a counterexample in which Memoize caused a worse plan. Thanks.
postgresql-flattened-union-all-memoize-reproducer.sql
Description: Binary data
