1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-24 10:47:04 +03:00

Add a way to create read stream object by using SMgrRelation.

Currently read stream object can be created only by using Relation.

Nazir Bilal Yavuz

Discussion: https://postgr.es/m/CAN55FZ0JKL6vk1xQp6rfOXiNFV1u1H0tJDPPGHWoiO3ea2Wc=A@mail.gmail.com
This commit is contained in:
Noah Misch 2024-07-20 04:22:12 -07:00
parent af07a827b9
commit a858be17c3
2 changed files with 72 additions and 14 deletions

View File

@ -406,10 +406,12 @@ read_stream_look_ahead(ReadStream *stream, bool suppress_advice)
* write extra data for each block into the space provided to it. It will
* also receive callback_private_data for its own purposes.
*/
ReadStream *
read_stream_begin_relation(int flags,
static ReadStream *
read_stream_begin_impl(int flags,
BufferAccessStrategy strategy,
Relation rel,
SMgrRelation smgr,
char persistence,
ForkNumber forknum,
ReadStreamBlockNumberCB callback,
void *callback_private_data,
@ -422,9 +424,6 @@ read_stream_begin_relation(int flags,
int strategy_pin_limit;
uint32 max_pinned_buffers;
Oid tablespace_id;
SMgrRelation smgr;
smgr = RelationGetSmgr(rel);
/*
* Decide how many I/Os we will allow to run at the same time. That
@ -434,7 +433,7 @@ read_stream_begin_relation(int flags,
*/
tablespace_id = smgr->smgr_rlocator.locator.spcOid;
if (!OidIsValid(MyDatabaseId) ||
IsCatalogRelation(rel) ||
(rel && IsCatalogRelation(rel)) ||
IsCatalogRelationOid(smgr->smgr_rlocator.locator.relNumber))
{
/*
@ -550,8 +549,8 @@ read_stream_begin_relation(int flags,
for (int i = 0; i < max_ios; ++i)
{
stream->ios[i].op.rel = rel;
stream->ios[i].op.smgr = RelationGetSmgr(rel);
stream->ios[i].op.persistence = rel->rd_rel->relpersistence;
stream->ios[i].op.smgr = smgr;
stream->ios[i].op.persistence = persistence;
stream->ios[i].op.forknum = forknum;
stream->ios[i].op.strategy = strategy;
}
@ -559,6 +558,55 @@ read_stream_begin_relation(int flags,
return stream;
}
/*
* Create a new read stream for reading a relation.
* See read_stream_begin_impl() for the detailed explanation.
*/
ReadStream *
read_stream_begin_relation(int flags,
BufferAccessStrategy strategy,
Relation rel,
ForkNumber forknum,
ReadStreamBlockNumberCB callback,
void *callback_private_data,
size_t per_buffer_data_size)
{
return read_stream_begin_impl(flags,
strategy,
rel,
RelationGetSmgr(rel),
rel->rd_rel->relpersistence,
forknum,
callback,
callback_private_data,
per_buffer_data_size);
}
/*
* Create a new read stream for reading a SMgr relation.
* See read_stream_begin_impl() for the detailed explanation.
*/
ReadStream *
read_stream_begin_smgr_relation(int flags,
BufferAccessStrategy strategy,
SMgrRelation smgr,
char smgr_persistence,
ForkNumber forknum,
ReadStreamBlockNumberCB callback,
void *callback_private_data,
size_t per_buffer_data_size)
{
return read_stream_begin_impl(flags,
strategy,
NULL,
smgr,
smgr_persistence,
forknum,
callback,
callback_private_data,
per_buffer_data_size);
}
/*
* Pull one pinned buffer out of a stream. Each call returns successive
* blocks in the order specified by the callback. If per_buffer_data_size was

View File

@ -15,6 +15,7 @@
#define READ_STREAM_H
#include "storage/bufmgr.h"
#include "storage/smgr.h"
/* Default tuning, reasonable for many users. */
#define READ_STREAM_DEFAULT 0x00
@ -57,6 +58,15 @@ extern ReadStream *read_stream_begin_relation(int flags,
void *callback_private_data,
size_t per_buffer_data_size);
extern Buffer read_stream_next_buffer(ReadStream *stream, void **per_buffer_data);
extern ReadStream *read_stream_begin_smgr_relation(int flags,
BufferAccessStrategy strategy,
SMgrRelation smgr,
char smgr_persistence,
ForkNumber forknum,
ReadStreamBlockNumberCB callback,
void *callback_private_data,
size_t per_buffer_data_size);
extern Buffer read_stream_next_buffer(ReadStream *stream, void **per_buffer_private);
extern void read_stream_reset(ReadStream *stream);
extern void read_stream_end(ReadStream *stream);