mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Implement List support for TransactionId
Use it for RelationSyncEntry->streamed_txns, which is currently using an integer list. The API support is not complete, not because it is hard to write but because it's unclear that it's worth the code space, there being so little use of XID lists. Discussion: https://postgr.es/m/202205130830.g5ntonhztspb@alvherre.pgsql Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
This commit is contained in:
@@ -54,6 +54,7 @@
|
||||
#define IsPointerList(l) ((l) == NIL || IsA((l), List))
|
||||
#define IsIntegerList(l) ((l) == NIL || IsA((l), IntList))
|
||||
#define IsOidList(l) ((l) == NIL || IsA((l), OidList))
|
||||
#define IsXidList(l) ((l) == NIL || IsA((l), XidList))
|
||||
|
||||
#ifdef USE_ASSERT_CHECKING
|
||||
/*
|
||||
@@ -71,7 +72,8 @@ check_list_invariants(const List *list)
|
||||
|
||||
Assert(list->type == T_List ||
|
||||
list->type == T_IntList ||
|
||||
list->type == T_OidList);
|
||||
list->type == T_OidList ||
|
||||
list->type == T_XidList);
|
||||
}
|
||||
#else
|
||||
#define check_list_invariants(l) ((void) 0)
|
||||
@@ -383,6 +385,24 @@ lappend_oid(List *list, Oid datum)
|
||||
return list;
|
||||
}
|
||||
|
||||
/*
|
||||
* Append a TransactionId to the specified list. See lappend()
|
||||
*/
|
||||
List *
|
||||
lappend_xid(List *list, TransactionId datum)
|
||||
{
|
||||
Assert(IsXidList(list));
|
||||
|
||||
if (list == NIL)
|
||||
list = new_list(T_XidList, 1);
|
||||
else
|
||||
new_tail_cell(list);
|
||||
|
||||
llast_xid(list) = datum;
|
||||
check_list_invariants(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
/*
|
||||
* Make room for a new cell at position 'pos' (measured from 0).
|
||||
* The data in the cell is left undefined, and must be filled in by the
|
||||
@@ -714,6 +734,26 @@ list_member_oid(const List *list, Oid datum)
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return true iff the TransactionId 'datum' is a member of the list.
|
||||
*/
|
||||
bool
|
||||
list_member_xid(const List *list, TransactionId datum)
|
||||
{
|
||||
const ListCell *cell;
|
||||
|
||||
Assert(IsXidList(list));
|
||||
check_list_invariants(list);
|
||||
|
||||
foreach(cell, list)
|
||||
{
|
||||
if (lfirst_oid(cell) == datum)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete the n'th cell (counting from 0) in list.
|
||||
*
|
||||
|
||||
@@ -221,6 +221,8 @@ _outList(StringInfo str, const List *node)
|
||||
appendStringInfoChar(str, 'i');
|
||||
else if (IsA(node, OidList))
|
||||
appendStringInfoChar(str, 'o');
|
||||
else if (IsA(node, XidList))
|
||||
appendStringInfoChar(str, 'x');
|
||||
|
||||
foreach(lc, node)
|
||||
{
|
||||
@@ -239,6 +241,8 @@ _outList(StringInfo str, const List *node)
|
||||
appendStringInfo(str, " %d", lfirst_int(lc));
|
||||
else if (IsA(node, OidList))
|
||||
appendStringInfo(str, " %u", lfirst_oid(lc));
|
||||
else if (IsA(node, XidList))
|
||||
appendStringInfo(str, " %u", lfirst_xid(lc));
|
||||
else
|
||||
elog(ERROR, "unrecognized list node type: %d",
|
||||
(int) node->type);
|
||||
|
||||
Reference in New Issue
Block a user