second On Thu, 6 Apr 2023 at 14:14, Melanie Plageman <melanieplage...@gmail.com> wrote: > > Attached is v14 which adds back in tests for the BUFFER_USAGE_LIMIT > option.
I've spent quite a bit of time looking at this since you sent it. I've also made quite a few changes, mostly cosmetic ones, but there are a few things below which are more fundamental. 1. I don't really think we need to support VACUUM (BUFFER_USAGE_LIMIT -1); It's just the same as VACUUM; Removing that makes the documentation more simple. 2. I don't think we really need to allow vacuum_buffer_usage_limit = -1. I think we can just set this to 256 and leave it. If we allow -1 then we need to document what -1 means. The more I think about it, the more strange it seems to allow -1. I can't quite imagine work_mem = -1 means 4MB. Why 4MB? Changing this means we don't really need to do anything special in: + if (VacuumBufferUsageLimit > -1) + bstrategy = GetAccessStrategyWithSize(BAS_VACUUM, VacuumBufferUsageLimit); + else + bstrategy = GetAccessStrategy(BAS_VACUUM); That simply becomes: bstrategy = GetAccessStrategyWithSize(BAS_VACUUM, VacuumBufferUsageLimit); The code inside GetAccessStrategyWithSize() handles returning NULL when the GUC is zero. The equivalent in ExecVacuum() becomes: if (ring_size > -1) bstrategy = GetAccessStrategyWithSize(BAS_VACUUM, ring_size); else bstrategy = GetAccessStrategyWithSize(BAS_VACUUM, VacuumBufferUsageLimit); instead of: if (ring_size > -1) bstrategy = GetAccessStrategyWithSize(BAS_VACUUM, ring_size); else if (VacuumBufferUsageLimit > -1) bstrategy = GetAccessStrategyWithSize(BAS_VACUUM, VacuumBufferUsageLimit); else bstrategy = GetAccessStrategy(BAS_VACUUM); 3. There was a bug in GetAccessStrategyBufferCount() (I renamed it to that from StrategyGetBufferCount()) that didn't handle NULL input. The problem was that if you set vacuum_buffer_usage_limit = 0 then did a parallel vacuum that GetAccessStrategyWithSize() would return NULL due to the 0 buffer input, but GetAccessStrategyBufferCount() couldn't handle NULL. I've adjusted GetAccessStrategyBufferCount() just to return 0 on NULL input. Most of the rest is cosmetic. GetAccessStrategyWithSize() ended up looking quite different. I didn't see the sense in converting the shared_buffer size into kilobytes to compare when we could just convert ring_size_kb to buffers slightly sooner and then just do: /* Cap to 1/8th of shared_buffers */ ring_buffers = Min(NBuffers / 8, ring_buffers); I renamed nbuffers to ring_buffers as it was a little too confusing to have nbuffers (for ring size) and NBuffers (for shared_buffers). A few other changes like getting rid of the regression test and code check for VACUUM (ONLY_DATABASE_STATS, BUFFER_USAGE_LIMIT 0); There is already an if check and ERROR that looks for ONLY_DATABASE_STATS with any other option slightly later in the function. I also got rid of the documentation that mentioned that wasn't supported as there's already a mention in the ONLY_DATABASE_STATS which says it's not supported with anything else. No other option seemed to care enough to mention it, so I don't think BUFFER_USAGE_LIMIT is an exception. I've attached v15. I've only glanced at the vacuumdb patch so far. I'm not expecting it to be too controversial. I'm fairly happy with v15 now but would welcome anyone who wants to have a look in the next 8 hours or so, else I plan to push it. David
v15_buffer_usage_limit.patch
Description: Binary data