@@ -449,14 +449,22 @@ crossmatch_begin(CustomScanState *node, EState *estate, int eflags)
449
449
450
450
scan_state -> values = palloc (sizeof (Datum ) * nlist );
451
451
scan_state -> nulls = palloc (sizeof (bool ) * nlist );
452
+
453
+ /* Store blank tuple in case scan tlist is empty */
454
+ if (scan_state -> scan_tlist == NIL )
455
+ {
456
+ TupleDesc tupdesc = node -> ss .ss_ScanTupleSlot -> tts_tupleDescriptor ;
457
+ scan_state -> stored_tuple = heap_form_tuple (tupdesc , NULL , NULL );
458
+ }
459
+ else
460
+ scan_state -> stored_tuple = NULL ;
452
461
}
453
462
454
463
static TupleTableSlot *
455
464
crossmatch_exec (CustomScanState * node )
456
465
{
457
466
CrossmatchScanState * scan_state = (CrossmatchScanState * ) node ;
458
467
TupleTableSlot * slot = node -> ss .ss_ScanTupleSlot ;
459
- TupleDesc tupdesc = node -> ss .ss_ScanTupleSlot -> tts_tupleDescriptor ;
460
468
HeapTuple htup = scan_state -> stored_tuple ;
461
469
462
470
for (;;)
@@ -479,19 +487,29 @@ crossmatch_exec(CustomScanState *node)
479
487
return ExecClearTuple (node -> ss .ps .ps_ResultTupleSlot );
480
488
}
481
489
482
- htup1 .t_self = p_tids [0 ];
483
- heap_fetch (scan_state -> outer , SnapshotSelf , & htup1 , & buf1 , false, NULL );
484
- values [0 ] = heap_getattr (& htup1 , 1 , scan_state -> outer -> rd_att , & nulls [0 ]);
490
+ /* We don't have to fetch tuples if scan tlist is empty */
491
+ if (scan_state -> scan_tlist != NIL )
492
+ {
493
+ TupleDesc tupdesc = node -> ss .ss_ScanTupleSlot -> tts_tupleDescriptor ;
494
+
495
+ htup1 .t_self = p_tids [0 ];
496
+ heap_fetch (scan_state -> outer , SnapshotSelf ,
497
+ & htup1 , & buf1 , false, NULL );
498
+ values [0 ] = heap_getattr (& htup1 , 1 , scan_state -> outer -> rd_att ,
499
+ & nulls [0 ]);
485
500
486
- htup2 .t_self = p_tids [1 ];
487
- heap_fetch (scan_state -> inner , SnapshotSelf , & htup2 , & buf2 , false, NULL );
488
- values [1 ] = heap_getattr (& htup2 , 1 , scan_state -> inner -> rd_att , & nulls [1 ]);
501
+ htup2 .t_self = p_tids [1 ];
502
+ heap_fetch (scan_state -> inner , SnapshotSelf ,
503
+ & htup2 , & buf2 , false, NULL );
504
+ values [1 ] = heap_getattr (& htup2 , 1 , scan_state -> inner -> rd_att ,
505
+ & nulls [1 ]);
489
506
490
- ReleaseBuffer (buf1 );
491
- ReleaseBuffer (buf2 );
507
+ ReleaseBuffer (buf1 );
508
+ ReleaseBuffer (buf2 );
492
509
493
- htup = heap_form_tuple (tupdesc , values , nulls );
494
- scan_state -> stored_tuple = htup ;
510
+ htup = heap_form_tuple (tupdesc , values , nulls );
511
+ scan_state -> stored_tuple = htup ;
512
+ }
495
513
}
496
514
497
515
if (node -> ss .ps .ps_ProjInfo )
@@ -515,7 +533,8 @@ crossmatch_exec(CustomScanState *node)
515
533
node -> ss .ps .ps_TupFromTlist = false;
516
534
}
517
535
else
518
- return ExecStoreTuple (htup , node -> ss .ps .ps_ResultTupleSlot , InvalidBuffer , false);
536
+ return ExecStoreTuple (htup , node -> ss .ps .ps_ResultTupleSlot ,
537
+ InvalidBuffer , false);
519
538
}
520
539
}
521
540
0 commit comments