* ReadBufferExtended -- returns a buffer containing the requested * block of the requested relation. If the blknum * requested is P_NEW, extend the relation file and * allocate a new block. (Caller is responsible for * ensuring that only one backend tries to extend a * relation at the same time!) * * Returns: the buffer number for the buffer containing * the block read. The return
| 825 | * See buffer/README for details. |
| 826 | */ |
| 827 | Buffer |
| 828 | ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, |
| 829 | ReadBufferMode mode, BufferAccessStrategy strategy) |
| 830 | { |
| 831 | bool hit; |
| 832 | Buffer buf; |
| 833 | |
| 834 | /* Open it at the smgr level if not already done */ |
| 835 | RelationOpenSmgr(reln); |
| 836 | |
| 837 | /* |
| 838 | * Reject attempts to read non-local temporary relations; we would be |
| 839 | * likely to get wrong data since we have no visibility into the owning |
| 840 | * session's local buffers. |
| 841 | */ |
| 842 | if (RelationUsesLocalBuffers(reln) && RELATION_IS_OTHER_TEMP(reln)) |
| 843 | ereport(ERROR, |
| 844 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 845 | errmsg("cannot access temporary tables of other sessions"))); |
| 846 | |
| 847 | /* |
| 848 | * Read the buffer, and update pgstat counters to reflect a cache hit or |
| 849 | * miss. |
| 850 | */ |
| 851 | pgstat_count_buffer_read(reln); |
| 852 | buf = ReadBuffer_common(reln->rd_smgr, reln->rd_rel->relpersistence, |
| 853 | forkNum, blockNum, mode, strategy, &hit); |
| 854 | if (hit) |
| 855 | pgstat_count_buffer_hit(reln); |
| 856 | return buf; |
| 857 | } |
| 858 | |
| 859 | |
| 860 | /* |
no test coverage detected