Skip to content

Commit a858be1

Browse files
committed
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
1 parent af07a82 commit a858be1

File tree

2 files changed

+72
-14
lines changed

2 files changed

+72
-14
lines changed

src/backend/storage/aio/read_stream.c

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -406,14 +406,16 @@ read_stream_look_ahead(ReadStream *stream, bool suppress_advice)
406406
* write extra data for each block into the space provided to it. It will
407407
* also receive callback_private_data for its own purposes.
408408
*/
409-
ReadStream *
410-
read_stream_begin_relation(int flags,
411-
BufferAccessStrategy strategy,
412-
Relation rel,
413-
ForkNumber forknum,
414-
ReadStreamBlockNumberCB callback,
415-
void *callback_private_data,
416-
size_t per_buffer_data_size)
409+
static ReadStream *
410+
read_stream_begin_impl(int flags,
411+
BufferAccessStrategy strategy,
412+
Relation rel,
413+
SMgrRelation smgr,
414+
char persistence,
415+
ForkNumber forknum,
416+
ReadStreamBlockNumberCB callback,
417+
void *callback_private_data,
418+
size_t per_buffer_data_size)
417419
{
418420
ReadStream *stream;
419421
size_t size;
@@ -422,9 +424,6 @@ read_stream_begin_relation(int flags,
422424
int strategy_pin_limit;
423425
uint32 max_pinned_buffers;
424426
Oid tablespace_id;
425-
SMgrRelation smgr;
426-
427-
smgr = RelationGetSmgr(rel);
428427

429428
/*
430429
* 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,
434433
*/
435434
tablespace_id = smgr->smgr_rlocator.locator.spcOid;
436435
if (!OidIsValid(MyDatabaseId) ||
437-
IsCatalogRelation(rel) ||
436+
(rel && IsCatalogRelation(rel)) ||
438437
IsCatalogRelationOid(smgr->smgr_rlocator.locator.relNumber))
439438
{
440439
/*
@@ -550,15 +549,64 @@ read_stream_begin_relation(int flags,
550549
for (int i = 0; i < max_ios; ++i)
551550
{
552551
stream->ios[i].op.rel = rel;
553-
stream->ios[i].op.smgr = RelationGetSmgr(rel);
554-
stream->ios[i].op.persistence = rel->rd_rel->relpersistence;
552+
stream->ios[i].op.smgr = smgr;
553+
stream->ios[i].op.persistence = persistence;
555554
stream->ios[i].op.forknum = forknum;
556555
stream->ios[i].op.strategy = strategy;
557556
}
558557

559558
return stream;
560559
}
561560

561+
/*
562+
* Create a new read stream for reading a relation.
563+
* See read_stream_begin_impl() for the detailed explanation.
564+
*/
565+
ReadStream *
566+
read_stream_begin_relation(int flags,
567+
BufferAccessStrategy strategy,
568+
Relation rel,
569+
ForkNumber forknum,
570+
ReadStreamBlockNumberCB callback,
571+
void *callback_private_data,
572+
size_t per_buffer_data_size)
573+
{
574+
return read_stream_begin_impl(flags,
575+
strategy,
576+
rel,
577+
RelationGetSmgr(rel),
578+
rel->rd_rel->relpersistence,
579+
forknum,
580+
callback,
581+
callback_private_data,
582+
per_buffer_data_size);
583+
}
584+
585+
/*
586+
* Create a new read stream for reading a SMgr relation.
587+
* See read_stream_begin_impl() for the detailed explanation.
588+
*/
589+
ReadStream *
590+
read_stream_begin_smgr_relation(int flags,
591+
BufferAccessStrategy strategy,
592+
SMgrRelation smgr,
593+
char smgr_persistence,
594+
ForkNumber forknum,
595+
ReadStreamBlockNumberCB callback,
596+
void *callback_private_data,
597+
size_t per_buffer_data_size)
598+
{
599+
return read_stream_begin_impl(flags,
600+
strategy,
601+
NULL,
602+
smgr,
603+
smgr_persistence,
604+
forknum,
605+
callback,
606+
callback_private_data,
607+
per_buffer_data_size);
608+
}
609+
562610
/*
563611
* Pull one pinned buffer out of a stream. Each call returns successive
564612
* blocks in the order specified by the callback. If per_buffer_data_size was

src/include/storage/read_stream.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define READ_STREAM_H
1616

1717
#include "storage/bufmgr.h"
18+
#include "storage/smgr.h"
1819

1920
/* Default tuning, reasonable for many users. */
2021
#define READ_STREAM_DEFAULT 0x00
@@ -57,6 +58,15 @@ extern ReadStream *read_stream_begin_relation(int flags,
5758
void *callback_private_data,
5859
size_t per_buffer_data_size);
5960
extern Buffer read_stream_next_buffer(ReadStream *stream, void **per_buffer_data);
61+
extern ReadStream *read_stream_begin_smgr_relation(int flags,
62+
BufferAccessStrategy strategy,
63+
SMgrRelation smgr,
64+
char smgr_persistence,
65+
ForkNumber forknum,
66+
ReadStreamBlockNumberCB callback,
67+
void *callback_private_data,
68+
size_t per_buffer_data_size);
69+
extern Buffer read_stream_next_buffer(ReadStream *stream, void **per_buffer_private);
6070
extern void read_stream_reset(ReadStream *stream);
6171
extern void read_stream_end(ReadStream *stream);
6272

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy