On Wed, 28 Apr 2021 at 21:38, Bharath Rupireddy <bharath.rupireddyforpostg...@gmail.com> wrote: > > On Wed, Apr 28, 2021 at 1:54 PM David Rowley <dgrowle...@gmail.com> wrote: > > I plan to push this in the next 24 hours or so. > > I happen to see explain_resultcache in resultcache.sql, seems like two > of the tests still have numbers for cache hits and misses - Hits: 980 > Misses: 20, won't these make tests unstable? Will these numbers be > same across machines? Or is it that no buildfarm had caught these? The > comment below says that, the hits and misses are not same across > machines: > -- Ensure we get some evictions. We're unable to validate the hits and misses > -- here as the number of entries that fit in the cache at once will vary > -- between different machines.
The only reason it would be unstable is if there are cache evictions. Evictions will only happen if the cache fills up and we need to make way for new entries. A 32-bit machine, for example, will use slightly less memory for caching items, so the number of evictions is going to be a bit less on those machine. Having an unstable number of evictions will cause the hits and misses to be unstable too. Otherwise, the number of misses is predictable, it'll be the number of distinct sets of parameters that we lookup in the cache. Any repeats will be a hit. So hits plus misses should just add up to the number of times that a normal parameterized nested loop would execute the inner side, and that's predictable too. It would only change if you change the query or the data in the table. > Should we remove the hide_hitmiss parameter in explain_resultcache and > always print N for non-zero and Zero for 0 hits and misses? This > clearly shows that we have 0 or non-zero hits or misses. I added that because if there are no evictions then the hits and misses should be perfectly stable, providing the test is small enough not to exceed work_mem and fill the cache. If someone was to run the tests with a small work_mem, then there would be no shortage of other tests that would fail due to plan changes. These tests were designed to be small enough so there's no danger of getting close to work_mem and filling the cache. However, I did add 1 test that sets work_mem down to 64kB to ensure the eviction code does get some exercise. You'll notice that I pass "true" to explain_resultcache() to hide the hits and misses there. We can't test the exact number of hits/misses/evictions there, but we can at least tell apart the zero and non-zero by how I coded explain_resultcache() to replace with Zero or N depending on if the number was zero or above zero. David