【标题】(请简要描述下实现的内容)
合并pg pr:PrivateRefCount相关问题修复
【实现内容】:
1.合入PG PR:2d115e47c861878669ba0814b3d97a4e4c347e8b

* Fix various shortcomings of the new PrivateRefCount infrastructure.

As noted by Tom Lane the improvements in 4b4b680c3d6 had the problem
that in some situations we searched, entered and modified entries in
the private refcount hash while holding a spinlock. I had tried to
keep the logic entirely local to PinBuffer_Locked(), but that's not
really possible given it's called with a spinlock held...

Besides being disadvantageous from a performance point of view, this
also has problems with error handling safety. If we failed inserting
an entry into the hashtable due to an out of memory error, we'd error
out with a held spinlock. Not good.

Change the way private refcounts are manipulated: Before a buffer can
be tracked an entry has to be reserved using
ReservePrivateRefCountEntry(); then, if a entry is not found using
GetPrivateRefCountEntry(), it can be entered with
NewPrivateRefCountEntry().

Also take advantage of the fact that PinBuffer_Locked() currently is
never called for buffers that already have been pinned by the current
backend and don't search the private refcount entries for preexisting
local pins. That results in a small, but measurable, performance
improvement.

Additionally make ReleaseBuffer() always call UnpinBuffer() for shared
buffers. That avoids duplicating work in an eventual UnpinBuffer()
call that already has been done in ReleaseBuffer() and also saves some
code.

Per discussion with Tom Lane.

Discussion: 15028.1418772313@sss.pgh.pa.us

2.合入PG PR:d25fbf9f3ecffb5c80a9201a6310e74da24556a4

* Fix two off-by-one errors in bufmgr.c.

In 4b4b680c I passed a buffer index number (starting from 0) instead of
a proper Buffer id (which start from 1 for shared buffers) in two
places.

This wasn't noticed so far as one of those locations isn't compiled at
all (PrintPinnedBufs) and the other one (InvalidBuffer) requires a
unlikely, but possible, set of circumstances to trigger a symptom.

To reduce the likelihood of such incidents a bit also convert existing
open coded mappings from buffer descriptors to buffer ids with
BufferDescriptorGetBuffer().

Author: Qingqing Zhou
Reported-By: Qingqing Zhou
Discussion: CAJjS0u2ai9ooUisKtkV8cuVUtEkMTsbK8c7juNAjv8K11zeCQg@mail.gmail.com
Backpatch: 9.5 where the private ref count infrastructure was introduced

【根因分析】:

【实现方案】:

【关联需求或issue】:

【开发自验报告】:

  1. 请附上自验结果(内容或者截图)
  2. 是否可以添加fastcheck测试用例,如是,请补充fastcheck用例
  3. 是否涉及资料修改,如是,在docs仓库补充资料
  4. 是否考虑升级场景(系统表修改、日志持久化以及修改执行态数据格式)
  5. 是否考虑在线扩容等扩展场景
  6. 是否考虑异常场景/并发场景/前向兼容/性能场景
  7. 是否对其他模块产生影响

【其他说明】: