Summary:
Tuple to string utility functions (YbHeapTupleToString(), YbHeapTupleToStringWithIsOmitted(), YbTupleTableSlotToStringWithIsOmitted()) have multiple issues:
- Code duplication across YbHeapTupleToString() and YbHeapTupleToStringWithIsOmitted()
- YbTupleTableSlotToStringWithIsOmitted() calls YbHeapTupleToStringWithIsOmitted(), but it should be the other way around.
- Even the implementation is incorrect. YbTupleTableSlotToStringWithIsOmitted() incorrectly asserts that `shouldFree` should be false. This is not the case for virtual and minimal tuple table slots.
- `ExecFetchSlotHeapTuple()` expects the slot to be non-empty. YbTupleTableSlotToStringWithIsOmitted() doesn't make any such check before calling it.
Rework these functions.
Jira: DB-15633
Test Plan:
Manual tested the functions using the follwing patch:
```
diff --git a/src/postgres/src/backend/access/yb_access/yb_scan.c b/src/postgres/src/backend/access/yb_access/yb_scan.c
index b69b5830a6..698918b95d 100644
--- a/src/postgres/src/backend/access/yb_access/yb_scan.c
+++ b/src/postgres/src/backend/access/yb_access/yb_scan.c
@@ -4297,6 +4297,15 @@ ybFetchNext(YbcPgStatement handle, TupleTableSlot *slot, Oid relid)
TABLETUPLE_YBCTID(slot) = PointerGetDatum(syscols.ybctid);
slot->tts_tableOid = relid;
}
+ elog(INFO, "slot to string: %s", YbSlotToString(slot));
+ if (!TTS_EMPTY(slot))
+ {
+ bool free;
+ HeapTuple tuple = ExecFetchSlotHeapTuple(slot, false, &free);
+ elog(INFO, "heap tuple to string: %s", YbHeapTupleToString(tuple, slot->tts_tupleDescriptor));
+ if (free)
+ pfree(tuple);
+ }
}
/***************************************************************************
```
followed by:
```
select * from pg_class limit 1;
```
Reviewers: telgersma, fizaa, stiwary
Reviewed By: stiwary
Subscribers: yql
Differential Revision: https://phorge.dev.yugabyte.com/D42322