@@ -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
0 commit comments