Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf10a025

Browse files
committed
Implement List support for TransactionId
Use it for RelationSyncEntry->streamed_txns, which is currently using aninteger list.The API support is not complete, not because it is hard to write butbecause it's unclear that it's worth the code space, there being solittle use of XID lists.Discussion:https://postgr.es/m/202205130830.g5ntonhztspb@alvherre.pgsqlReviewed-by: Amit Kapila <amit.kapila16@gmail.com>
1 parent55f4802 commitf10a025

File tree

5 files changed

+70
-12
lines changed

5 files changed

+70
-12
lines changed

‎src/backend/nodes/list.c

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#defineIsPointerList(l)((l) == NIL || IsA((l), List))
5555
#defineIsIntegerList(l)((l) == NIL || IsA((l), IntList))
5656
#defineIsOidList(l)((l) == NIL || IsA((l), OidList))
57+
#defineIsXidList(l)((l) == NIL || IsA((l), XidList))
5758

5859
#ifdefUSE_ASSERT_CHECKING
5960
/*
@@ -71,7 +72,8 @@ check_list_invariants(const List *list)
7172

7273
Assert(list->type==T_List||
7374
list->type==T_IntList||
74-
list->type==T_OidList);
75+
list->type==T_OidList||
76+
list->type==T_XidList);
7577
}
7678
#else
7779
#definecheck_list_invariants(l) ((void) 0)
@@ -383,6 +385,24 @@ lappend_oid(List *list, Oid datum)
383385
returnlist;
384386
}
385387

388+
/*
389+
* Append a TransactionId to the specified list. See lappend()
390+
*/
391+
List*
392+
lappend_xid(List*list,TransactionIddatum)
393+
{
394+
Assert(IsXidList(list));
395+
396+
if (list==NIL)
397+
list=new_list(T_XidList,1);
398+
else
399+
new_tail_cell(list);
400+
401+
llast_xid(list)=datum;
402+
check_list_invariants(list);
403+
returnlist;
404+
}
405+
386406
/*
387407
* Make room for a new cell at position 'pos' (measured from 0).
388408
* 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)
714734
return false;
715735
}
716736

737+
/*
738+
* Return true iff the TransactionId 'datum' is a member of the list.
739+
*/
740+
bool
741+
list_member_xid(constList*list,TransactionIddatum)
742+
{
743+
constListCell*cell;
744+
745+
Assert(IsXidList(list));
746+
check_list_invariants(list);
747+
748+
foreach(cell,list)
749+
{
750+
if (lfirst_oid(cell)==datum)
751+
return true;
752+
}
753+
754+
return false;
755+
}
756+
717757
/*
718758
* Delete the n'th cell (counting from 0) in list.
719759
*

‎src/backend/nodes/outfuncs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ _outList(StringInfo str, const List *node)
221221
appendStringInfoChar(str,'i');
222222
elseif (IsA(node,OidList))
223223
appendStringInfoChar(str,'o');
224+
elseif (IsA(node,XidList))
225+
appendStringInfoChar(str,'x');
224226

225227
foreach(lc,node)
226228
{
@@ -239,6 +241,8 @@ _outList(StringInfo str, const List *node)
239241
appendStringInfo(str," %d",lfirst_int(lc));
240242
elseif (IsA(node,OidList))
241243
appendStringInfo(str," %u",lfirst_oid(lc));
244+
elseif (IsA(node,XidList))
245+
appendStringInfo(str," %u",lfirst_xid(lc));
242246
else
243247
elog(ERROR,"unrecognized list node type: %d",
244248
(int)node->type);

‎src/backend/replication/pgoutput/pgoutput.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,15 +1923,7 @@ init_rel_sync_cache(MemoryContext cachectx)
19231923
staticbool
19241924
get_schema_sent_in_streamed_txn(RelationSyncEntry*entry,TransactionIdxid)
19251925
{
1926-
ListCell*lc;
1927-
1928-
foreach(lc,entry->streamed_txns)
1929-
{
1930-
if (xid== (uint32)lfirst_int(lc))
1931-
return true;
1932-
}
1933-
1934-
return false;
1926+
returnlist_member_xid(entry->streamed_txns,xid);
19351927
}
19361928

19371929
/*
@@ -1945,7 +1937,7 @@ set_schema_sent_in_streamed_txn(RelationSyncEntry *entry, TransactionId xid)
19451937

19461938
oldctx=MemoryContextSwitchTo(CacheMemoryContext);
19471939

1948-
entry->streamed_txns=lappend_int(entry->streamed_txns,xid);
1940+
entry->streamed_txns=lappend_xid(entry->streamed_txns,xid);
19491941

19501942
MemoryContextSwitchTo(oldctx);
19511943
}
@@ -2248,7 +2240,7 @@ cleanup_rel_sync_cache(TransactionId xid, bool is_commit)
22482240
*/
22492241
foreach(lc,entry->streamed_txns)
22502242
{
2251-
if (xid==(uint32)lfirst_int(lc))
2243+
if (xid==lfirst_xid(lc))
22522244
{
22532245
if (is_commit)
22542246
entry->schema_sent= true;

‎src/include/nodes/nodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ typedef enum NodeTag
317317
T_List,
318318
T_IntList,
319319
T_OidList,
320+
T_XidList,
320321

321322
/*
322323
* TAGS FOR EXTENSIBLE NODES (extensible.h)

‎src/include/nodes/pg_list.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ typedef union ListCell
4545
void*ptr_value;
4646
intint_value;
4747
Oidoid_value;
48+
TransactionIdxid_value;
4849
}ListCell;
4950

5051
typedefstructList
@@ -169,6 +170,7 @@ list_length(const List *l)
169170
#definelfirst(lc)((lc)->ptr_value)
170171
#definelfirst_int(lc)((lc)->int_value)
171172
#definelfirst_oid(lc)((lc)->oid_value)
173+
#definelfirst_xid(lc)((lc)->xid_value)
172174
#definelfirst_node(type,lc)castNode(type, lfirst(lc))
173175

174176
#definelinitial(l)lfirst(list_nth_cell(l, 0))
@@ -194,6 +196,7 @@ list_length(const List *l)
194196
#definellast(l)lfirst(list_last_cell(l))
195197
#definellast_int(l)lfirst_int(list_last_cell(l))
196198
#definellast_oid(l)lfirst_oid(list_last_cell(l))
199+
#definellast_xid(l)lfirst_xid(list_last_cell(l))
197200
#definellast_node(type,l)castNode(type, llast(l))
198201

199202
/*
@@ -202,6 +205,7 @@ list_length(const List *l)
202205
#definelist_make_ptr_cell(v)((ListCell) {.ptr_value = (v)})
203206
#definelist_make_int_cell(v)((ListCell) {.int_value = (v)})
204207
#definelist_make_oid_cell(v)((ListCell) {.oid_value = (v)})
208+
#definelist_make_xid_cell(v)((ListCell) {.xid_value = (v)})
205209

206210
#definelist_make1(x1) \
207211
list_make1_impl(T_List, list_make_ptr_cell(x1))
@@ -248,6 +252,21 @@ list_length(const List *l)
248252
list_make_oid_cell(x3), list_make_oid_cell(x4), \
249253
list_make_oid_cell(x5))
250254

255+
#definelist_make1_xid(x1) \
256+
list_make1_impl(T_XidList, list_make_xid_cell(x1))
257+
#definelist_make2_xid(x1,x2) \
258+
list_make2_impl(T_XidList, list_make_xid_cell(x1), list_make_xid_cell(x2))
259+
#definelist_make3_xid(x1,x2,x3) \
260+
list_make3_impl(T_XidList, list_make_xid_cell(x1), list_make_xid_cell(x2), \
261+
list_make_xid_cell(x3))
262+
#definelist_make4_xid(x1,x2,x3,x4) \
263+
list_make4_impl(T_XidList, list_make_xid_cell(x1), list_make_xid_cell(x2), \
264+
list_make_xid_cell(x3), list_make_xid_cell(x4))
265+
#definelist_make5_xid(x1,x2,x3,x4,x5) \
266+
list_make5_impl(T_XidList, list_make_xid_cell(x1), list_make_xid_cell(x2), \
267+
list_make_xid_cell(x3), list_make_xid_cell(x4), \
268+
list_make_xid_cell(x5))
269+
251270
/*
252271
* Locate the n'th cell (counting from 0) of the list.
253272
* It is an assertion failure if there is no such cell.
@@ -539,6 +558,7 @@ extern List *list_make5_impl(NodeTag t, ListCell datum1, ListCell datum2,
539558
externpg_nodiscardList*lappend(List*list,void*datum);
540559
externpg_nodiscardList*lappend_int(List*list,intdatum);
541560
externpg_nodiscardList*lappend_oid(List*list,Oiddatum);
561+
externpg_nodiscardList*lappend_xid(List*list,TransactionIddatum);
542562

543563
externpg_nodiscardList*list_insert_nth(List*list,intpos,void*datum);
544564
externpg_nodiscardList*list_insert_nth_int(List*list,intpos,intdatum);
@@ -557,6 +577,7 @@ extern bool list_member(const List *list, const void *datum);
557577
externboollist_member_ptr(constList*list,constvoid*datum);
558578
externboollist_member_int(constList*list,intdatum);
559579
externboollist_member_oid(constList*list,Oiddatum);
580+
externboollist_member_xid(constList*list,TransactionIddatum);
560581

561582
externpg_nodiscardList*list_delete(List*list,void*datum);
562583
externpg_nodiscardList*list_delete_ptr(List*list,void*datum);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp