Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0276ae4

Browse files
committed
Improve a few things in pg_walinspect
This improves a few things in pg_walinspect: - Return NULL rather than empty strings in pg_get_wal_records_info() for the block references and the record description if there is no information provided by the fallback. This point has been raised by Peter Geoghegan. - Add a check on XLogRecHasAnyBlockRefs() for pg_get_wal_block_info(), to directly skip records that have no block references. This speeds up the function a bit, depending on the number of records that have no block references. Author: Bharath Rupireddy Reviewed-by: Kyotaro Horiguchi, Michael Paquier Discussion: https://postgr.es/m/CALj2ACWL9RG8sGJHinggRNBTxgRWJTSxCkB+cE6=t3Phh=Ey+A@mail.gmail.com
1 parent 850f4b4 commit 0276ae4

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

contrib/pg_walinspect/pg_walinspect.c

+27-15
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,6 @@ GetWALRecordInfo(XLogReaderState *record, Datum *values,
186186
RmgrData desc;
187187
uint32 fpi_len = 0;
188188
StringInfoData rec_desc;
189-
StringInfoData rec_blk_ref;
190-
uint32 main_data_len;
191189
int i = 0;
192190

193191
desc = GetRmgr(XLogRecGetRmid(record));
@@ -199,23 +197,33 @@ GetWALRecordInfo(XLogReaderState *record, Datum *values,
199197
initStringInfo(&rec_desc);
200198
desc.rm_desc(&rec_desc, record);
201199

202-
/* Block references. */
203-
initStringInfo(&rec_blk_ref);
204-
XLogRecGetBlockRefInfo(record, false, true, &rec_blk_ref, &fpi_len);
205-
206-
main_data_len = XLogRecGetDataLen(record);
207-
208200
values[i++] = LSNGetDatum(record->ReadRecPtr);
209201
values[i++] = LSNGetDatum(record->EndRecPtr);
210202
values[i++] = LSNGetDatum(XLogRecGetPrev(record));
211203
values[i++] = TransactionIdGetDatum(XLogRecGetXid(record));
212204
values[i++] = CStringGetTextDatum(desc.rm_name);
213205
values[i++] = CStringGetTextDatum(id);
214206
values[i++] = UInt32GetDatum(XLogRecGetTotalLen(record));
215-
values[i++] = UInt32GetDatum(main_data_len);
207+
values[i++] = UInt32GetDatum(XLogRecGetDataLen(record));
208+
216209
values[i++] = UInt32GetDatum(fpi_len);
217-
values[i++] = CStringGetTextDatum(rec_desc.data);
218-
values[i++] = CStringGetTextDatum(rec_blk_ref.data);
210+
211+
if (rec_desc.len > 0)
212+
values[i++] = CStringGetTextDatum(rec_desc.data);
213+
else
214+
nulls[i++] = true;
215+
216+
/* Block references. */
217+
if (XLogRecHasAnyBlockRefs(record))
218+
{
219+
StringInfoData rec_blk_ref;
220+
221+
initStringInfo(&rec_blk_ref);
222+
XLogRecGetBlockRefInfo(record, false, true, &rec_blk_ref, &fpi_len);
223+
values[i++] = CStringGetTextDatum(rec_blk_ref.data);
224+
}
225+
else
226+
nulls[i++] = true;
219227

220228
Assert(i == ncols);
221229
}
@@ -377,6 +385,11 @@ pg_get_wal_block_info(PG_FUNCTION_ARGS)
377385
while (ReadNextXLogRecord(xlogreader) &&
378386
xlogreader->EndRecPtr <= end_lsn)
379387
{
388+
CHECK_FOR_INTERRUPTS();
389+
390+
if (!XLogRecHasAnyBlockRefs(xlogreader))
391+
continue;
392+
380393
/* Use the tmp context so we can clean up after each tuple is done */
381394
old_cxt = MemoryContextSwitchTo(tmp_cxt);
382395

@@ -385,8 +398,6 @@ pg_get_wal_block_info(PG_FUNCTION_ARGS)
385398
/* clean up and switch back */
386399
MemoryContextSwitchTo(old_cxt);
387400
MemoryContextReset(tmp_cxt);
388-
389-
CHECK_FOR_INTERRUPTS();
390401
}
391402

392403
MemoryContextDelete(tmp_cxt);
@@ -483,8 +494,6 @@ GetWALRecordsInfo(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
483494
#define PG_GET_WAL_RECORDS_INFO_COLS 11
484495
XLogReaderState *xlogreader;
485496
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
486-
Datum values[PG_GET_WAL_RECORDS_INFO_COLS] = {0};
487-
bool nulls[PG_GET_WAL_RECORDS_INFO_COLS] = {0};
488497
MemoryContext old_cxt;
489498
MemoryContext tmp_cxt;
490499

@@ -501,6 +510,9 @@ GetWALRecordsInfo(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
501510
while (ReadNextXLogRecord(xlogreader) &&
502511
xlogreader->EndRecPtr <= end_lsn)
503512
{
513+
Datum values[PG_GET_WAL_RECORDS_INFO_COLS] = {0};
514+
bool nulls[PG_GET_WAL_RECORDS_INFO_COLS] = {0};
515+
504516
/* Use the tmp context so we can clean up after each tuple is done */
505517
old_cxt = MemoryContextSwitchTo(tmp_cxt);
506518

0 commit comments

Comments
 (0)