Skip to content

Commit a34e6c3

Browse files
committed
remove additional and useless loop for each relation file when do ptrack_get_pagemapset query reported by #12
1 parent 6f1a27b commit a34e6c3

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

ptrack.c

+12-7
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,14 @@ ptrack_filelist_getnext(PtScanCtx * ctx)
368368
return ptrack_filelist_getnext(ctx);
369369
}
370370

371+
if (fst.st_size == 0)
372+
{
373+
elog(WARNING, "ptrack: skip empty file %s", fullpath);
374+
375+
/* But try the next one */
376+
return ptrack_filelist_getnext(ctx);
377+
}
378+
371379
if (pfl->segno > 0)
372380
{
373381
ctx->relsize = pfl->segno * RELSEG_SIZE + fst.st_size / BLCKSZ;
@@ -494,7 +502,7 @@ ptrack_get_pagemapset(PG_FUNCTION_ARGS)
494502
XLogRecPtr update_lsn2;
495503

496504
/* Stop traversal if there are no more segments */
497-
if (ctx->bid.blocknum > ctx->relsize)
505+
if (ctx->bid.blocknum + 1 > ctx->relsize)
498506
{
499507
/* We completed a segment and there is a bitmap to return */
500508
if (pagemap.bitmap != NULL)
@@ -526,12 +534,9 @@ ptrack_get_pagemapset(PG_FUNCTION_ARGS)
526534
if (htup)
527535
SRF_RETURN_NEXT(funcctx, HeapTupleGetDatum(htup));
528536
}
529-
else
530-
{
531-
/* We have just processed unchanged file, let's pick next */
532-
if (ptrack_filelist_getnext(ctx) < 0)
533-
SRF_RETURN_DONE(funcctx);
534-
}
537+
538+
if (ptrack_filelist_getnext(ctx) < 0)
539+
SRF_RETURN_DONE(funcctx);
535540
}
536541

537542
hash = BID_HASH_FUNC(ctx->bid);

0 commit comments

Comments
 (0)