commit 1734535948465e36d0a1c99380b3139654c7610b Author: Gurjeet Singh Date: Sun Jan 19 19:22:06 2025 -0800 Minimal changes to support pg_block_queries diff --git a/src/backend/nodes/gen_node_support.pl b/src/backend/nodes/gen_node_support.pl index 7c012c27f8..e10402cde8 100644 --- a/src/backend/nodes/gen_node_support.pl +++ b/src/backend/nodes/gen_node_support.pl @@ -148,7 +148,7 @@ my @abstract_types = qw(Node); # is not in a header file. We generate node tags for them, but # they otherwise don't participate in node support. my @extra_tags = qw( - IntList OidList XidList + IntList Int64List OidList XidList AllocSetContext GenerationContext SlabContext BumpContext TIDBitmap WindowObjectData diff --git a/src/backend/nodes/list.c b/src/backend/nodes/list.c index 1597b8e812..f1b4c61485 100644 --- a/src/backend/nodes/list.c +++ b/src/backend/nodes/list.c @@ -54,6 +54,7 @@ */ #define IsPointerList(l) ((l) == NIL || IsA((l), List)) #define IsIntegerList(l) ((l) == NIL || IsA((l), IntList)) +#define IsInt64List(l) ((l) == NIL || IsA((l), Int64List)) #define IsOidList(l) ((l) == NIL || IsA((l), OidList)) #define IsXidList(l) ((l) == NIL || IsA((l), XidList)) @@ -73,6 +74,7 @@ check_list_invariants(const List *list) Assert(list->type == T_List || list->type == T_IntList || + list->type == T_Int64List || list->type == T_OidList || list->type == T_XidList); } @@ -368,6 +370,24 @@ lappend_int(List *list, int datum) return list; } +/* + * Append an int64 to the specified list. See lappend() + */ +List * +lappend_int64(List *list, int64 datum) +{ + Assert(IsInt64List(list)); + + if (list == NIL) + list = new_list(T_Int64List, 1); + else + new_tail_cell(list); + + llast_int64(list) = datum; + check_list_invariants(list); + return list; +} + /* * Append an OID to the specified list. See lappend() */ @@ -715,6 +735,26 @@ list_member_int(const List *list, int datum) return false; } +/* + * Return true iff the int64 'datum' is a member of the list. + */ +bool +list_member_int64(const List *list, int64 datum) +{ + const ListCell *cell; + + Assert(IsInt64List(list)); + check_list_invariants(list); + + foreach(cell, list) + { + if (lfirst_int64(cell) == datum) + return true; + } + + return false; +} + /* * Return true iff the OID 'datum' is a member of the list. */ diff --git a/src/include/nodes/pg_list.h b/src/include/nodes/pg_list.h index a872fc501e..f034b93d32 100644 --- a/src/include/nodes/pg_list.h +++ b/src/include/nodes/pg_list.h @@ -46,6 +46,7 @@ typedef union ListCell { void *ptr_value; int int_value; + int64 int64_value; Oid oid_value; TransactionId xid_value; } ListCell; @@ -171,12 +172,14 @@ list_length(const List *l) */ #define lfirst(lc) ((lc)->ptr_value) #define lfirst_int(lc) ((lc)->int_value) +#define lfirst_int64(lc) ((lc)->int64_value) #define lfirst_oid(lc) ((lc)->oid_value) #define lfirst_xid(lc) ((lc)->xid_value) #define lfirst_node(type,lc) castNode(type, lfirst(lc)) #define linitial(l) lfirst(list_nth_cell(l, 0)) #define linitial_int(l) lfirst_int(list_nth_cell(l, 0)) +#define linitial_int64(l) lfirst_int64(list_nth_cell(l, 0)) #define linitial_oid(l) lfirst_oid(list_nth_cell(l, 0)) #define linitial_node(type,l) castNode(type, linitial(l)) @@ -197,6 +200,7 @@ list_length(const List *l) #define llast(l) lfirst(list_last_cell(l)) #define llast_int(l) lfirst_int(list_last_cell(l)) +#define llast_int64(l) lfirst_int64(list_last_cell(l)) #define llast_oid(l) lfirst_oid(list_last_cell(l)) #define llast_xid(l) lfirst_xid(list_last_cell(l)) #define llast_node(type,l) castNode(type, llast(l)) @@ -204,10 +208,11 @@ list_length(const List *l) /* * Convenience macros for building fixed-length lists */ -#define list_make_ptr_cell(v) ((ListCell) {.ptr_value = (v)}) -#define list_make_int_cell(v) ((ListCell) {.int_value = (v)}) -#define list_make_oid_cell(v) ((ListCell) {.oid_value = (v)}) -#define list_make_xid_cell(v) ((ListCell) {.xid_value = (v)}) +#define list_make_ptr_cell( v) ((ListCell) {.ptr_value = (v)}) +#define list_make_int_cell( v) ((ListCell) {.int_value = (v)}) +#define list_make_int64_cell(v) ((ListCell) {.int64_value = (v)}) +#define list_make_oid_cell( v) ((ListCell) {.oid_value = (v)}) +#define list_make_xid_cell( v) ((ListCell) {.xid_value = (v)}) #define list_make1(x1) \ list_make1_impl(T_List, list_make_ptr_cell(x1)) @@ -239,6 +244,9 @@ list_length(const List *l) list_make_int_cell(x3), list_make_int_cell(x4), \ list_make_int_cell(x5)) +#define list_make1_int64(x1) \ + list_make1_impl(T_Int64List, list_make_int64_cell(x1)) + #define list_make1_oid(x1) \ list_make1_impl(T_OidList, list_make_oid_cell(x1)) #define list_make2_oid(x1,x2) \ @@ -468,6 +476,7 @@ for_each_cell_setup(const List *lst, const ListCell *initcell) */ #define foreach_ptr(type, var, lst) foreach_internal(type, *, var, lst, lfirst) #define foreach_int(var, lst) foreach_internal(int, , var, lst, lfirst_int) +#define foreach_int64(var, lst) foreach_internal(int64, , var, lst, lfirst_int64) #define foreach_oid(var, lst) foreach_internal(Oid, , var, lst, lfirst_oid) #define foreach_xid(var, lst) foreach_internal(TransactionId, , var, lst, lfirst_xid) @@ -610,6 +619,7 @@ extern List *list_make5_impl(NodeTag t, ListCell datum1, ListCell datum2, extern pg_nodiscard List *lappend(List *list, void *datum); extern pg_nodiscard List *lappend_int(List *list, int datum); +extern pg_nodiscard List *lappend_int64(List *list, int64 datum); extern pg_nodiscard List *lappend_oid(List *list, Oid datum); extern pg_nodiscard List *lappend_xid(List *list, TransactionId datum); @@ -629,6 +639,7 @@ extern pg_nodiscard List *list_truncate(List *list, int new_size); extern bool list_member(const List *list, const void *datum); extern bool list_member_ptr(const List *list, const void *datum); extern bool list_member_int(const List *list, int datum); +extern bool list_member_int64(const List *list, int64 datum); extern bool list_member_oid(const List *list, Oid datum); extern bool list_member_xid(const List *list, TransactionId datum);