On Tue, 2025-02-11 at 10:39 -0800, James Hunter wrote: > * The Path would store "nbytes" (= the optimizer's estimate of how > much working memory a given Path will use), to allow for future > optimizer logic to consider memory usage when choosing the best Path. > > * The Plan would store a copy of "nbytes," along with "work_mem," and > the executor would enforce work_mem. A "(work_mem on)" option to the > "EXPLAIN" command would display both "nbytes" and "work_mem", per > Plan > node.
Storing work_mem in each Plan node, and using that to enforce the memory limit (rather than using the GUC directly), seems uncontroversial to me. I'd suggest a standalone patch. Storing the optimizer's estimate of the memory wanted also sounds like a good idea. Let's pick a better name than "nbytes" though; maybe "requested_mem" or something? This change would make it a lot easier for an extension to adjust the per-node-work_mem, and also seems like good infrastructure for anything we build into the planner later. I suggest a standalone patch for this, as well. Can you write a useful extension with just the above two core patches? Regards, Jeff Davis