mirror of https://github.com/postgres/postgres
Add helper functions that output arrays in a standard format, and use the functions inside heapdesc routines. This allows tools like pg_walinspect to show a detailed description of the page offset number arrays for records like PRUNE and VACUUM (unless there was an FPI). Also document the conventions that desc routines should follow. Only the heapdesc routines follow the conventions for now, so they're just guidelines for the time being. Based on a suggestion from Andres Freund. Author: Melanie Plageman <melanieplageman@gmail.com> Reviewed-By: Peter Geoghegan <pg@bowt.ie> Discussion: https://postgr.es/m/flat/20230109215842.fktuhesvayno6o4g%40awork3.anarazel.depull/137/head
parent
76c111a7f1
commit
7d8219a444
@ -0,0 +1,84 @@ |
||||
/*-------------------------------------------------------------------------
|
||||
* |
||||
* rmgrdesc_utils.c |
||||
* Support functions for rmgrdesc routines |
||||
* |
||||
* Copyright (c) 2023, PostgreSQL Global Development Group |
||||
* |
||||
* |
||||
* IDENTIFICATION |
||||
* src/backend/access/rmgrdesc/rmgrdesc_utils.c |
||||
* |
||||
*------------------------------------------------------------------------- |
||||
*/ |
||||
#include "postgres.h" |
||||
|
||||
#include "access/rmgrdesc_utils.h" |
||||
#include "storage/off.h" |
||||
|
||||
/*
|
||||
* Guidelines for formatting desc functions: |
||||
* |
||||
* member1_name: member1_value, member2_name: member2_value |
||||
* |
||||
* If the value is a list, please use: |
||||
* |
||||
* member3_name: [ member3_list_value1, member3_list_value2 ] |
||||
* |
||||
* The first item appended to the string should not be prepended by any spaces |
||||
* or comma, however all subsequent appends to the string are responsible for |
||||
* prepending themselves with a comma followed by a space. |
||||
* |
||||
* Arrays should have a space between the opening square bracket and first |
||||
* element and between the last element and closing brace. |
||||
* |
||||
* Flags should be in ALL CAPS. |
||||
* |
||||
* For lists/arrays of items, the number of those items should be listed at |
||||
* the beginning with all of the other numbers. |
||||
* |
||||
* List punctuation should still be included even if there are 0 items. |
||||
* |
||||
* Composite objects in a list should be surrounded with { }. |
||||
*/ |
||||
void |
||||
array_desc(StringInfo buf, void *array, size_t elem_size, int count, |
||||
void (*elem_desc) (StringInfo buf, void *elem, void *data), |
||||
void *data) |
||||
{ |
||||
if (count == 0) |
||||
{ |
||||
appendStringInfoString(buf, " []"); |
||||
return; |
||||
} |
||||
appendStringInfo(buf, " ["); |
||||
for (int i = 0; i < count; i++) |
||||
{ |
||||
if (i > 0) |
||||
appendStringInfoString(buf, ","); |
||||
appendStringInfoString(buf, " "); |
||||
|
||||
elem_desc(buf, (char *) array + elem_size * i, data); |
||||
} |
||||
appendStringInfoString(buf, " ]"); |
||||
} |
||||
|
||||
void |
||||
offset_elem_desc(StringInfo buf, void *offset, void *data) |
||||
{ |
||||
appendStringInfo(buf, "%u", *(OffsetNumber *) offset); |
||||
} |
||||
|
||||
void |
||||
redirect_elem_desc(StringInfo buf, void *offset, void *data) |
||||
{ |
||||
OffsetNumber *new_offset = (OffsetNumber *) offset; |
||||
|
||||
appendStringInfo(buf, "%u->%u", new_offset[0], new_offset[1]); |
||||
} |
||||
|
||||
void |
||||
relid_desc(StringInfo buf, void *relid, void *data) |
||||
{ |
||||
appendStringInfo(buf, "%u", *(Oid *) relid); |
||||
} |
@ -0,0 +1,22 @@ |
||||
/*-------------------------------------------------------------------------
|
||||
* |
||||
* rmgrdesc_utils.h |
||||
* Support functions for rmgrdesc routines |
||||
* |
||||
* Copyright (c) 2023, PostgreSQL Global Development Group |
||||
* |
||||
* src/include/access/rmgrdesc_utils.h |
||||
* |
||||
*------------------------------------------------------------------------- |
||||
*/ |
||||
#ifndef RMGRDESC_UTILS_H_ |
||||
#define RMGRDESC_UTILS_H_ |
||||
|
||||
extern void array_desc(StringInfo buf, void *array, size_t elem_size, int count, |
||||
void (*elem_desc) (StringInfo buf, void *elem, void *data), |
||||
void *data); |
||||
extern void offset_elem_desc(StringInfo buf, void *offset, void *data); |
||||
extern void redirect_elem_desc(StringInfo buf, void *offset, void *data); |
||||
extern void relid_desc(StringInfo buf, void *relid, void *data); |
||||
|
||||
#endif /* RMGRDESC_UTILS_H */ |
Loading…
Reference in new issue