Skip to content

Commit df9133f

Browse files
committed
Move SQL-callable code related to multixacts into its own file
A patch is under discussion to add more SQL capabilities related to multixacts, and this move avoids bloating the file more than necessary. This affects pg_get_multixact_members(). A side effect of this move is the requirement to add mxstatus_to_string() to multixact.h. Extracted from a larger patch by the same author, tweaked by me. Author: Naga Appani <nagnrik@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Reviewed-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> Discussion: https://postgr.es/m/CA+QeY+AAsYK6WvBW4qYzHz4bahHycDAY_q5ECmHkEV_eB9ckzg@mail.gmail.com
1 parent 4a40380 commit df9133f

File tree

5 files changed

+91
-65
lines changed

5 files changed

+91
-65
lines changed

src/backend/access/transam/multixact.c

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,6 @@ static int mXactCacheGetById(MultiXactId multi, MultiXactMember **members);
398398
static void mXactCachePut(MultiXactId multi, int nmembers,
399399
MultiXactMember *members);
400400

401-
static char *mxstatus_to_string(MultiXactStatus status);
402-
403401
/* management of SLRU infrastructure */
404402
static bool MultiXactOffsetPagePrecedes(int64 page1, int64 page2);
405403
static bool MultiXactMemberPagePrecedes(int64 page1, int64 page2);
@@ -1747,7 +1745,7 @@ mXactCachePut(MultiXactId multi, int nmembers, MultiXactMember *members)
17471745
}
17481746
}
17491747

1750-
static char *
1748+
char *
17511749
mxstatus_to_string(MultiXactStatus status)
17521750
{
17531751
switch (status)
@@ -3414,68 +3412,6 @@ multixact_redo(XLogReaderState *record)
34143412
elog(PANIC, "multixact_redo: unknown op code %u", info);
34153413
}
34163414

3417-
Datum
3418-
pg_get_multixact_members(PG_FUNCTION_ARGS)
3419-
{
3420-
typedef struct
3421-
{
3422-
MultiXactMember *members;
3423-
int nmembers;
3424-
int iter;
3425-
} mxact;
3426-
MultiXactId mxid = PG_GETARG_TRANSACTIONID(0);
3427-
mxact *multi;
3428-
FuncCallContext *funccxt;
3429-
3430-
if (mxid < FirstMultiXactId)
3431-
ereport(ERROR,
3432-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3433-
errmsg("invalid MultiXactId: %u", mxid)));
3434-
3435-
if (SRF_IS_FIRSTCALL())
3436-
{
3437-
MemoryContext oldcxt;
3438-
TupleDesc tupdesc;
3439-
3440-
funccxt = SRF_FIRSTCALL_INIT();
3441-
oldcxt = MemoryContextSwitchTo(funccxt->multi_call_memory_ctx);
3442-
3443-
multi = palloc(sizeof(mxact));
3444-
/* no need to allow for old values here */
3445-
multi->nmembers = GetMultiXactIdMembers(mxid, &multi->members, false,
3446-
false);
3447-
multi->iter = 0;
3448-
3449-
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
3450-
elog(ERROR, "return type must be a row type");
3451-
funccxt->tuple_desc = tupdesc;
3452-
funccxt->attinmeta = TupleDescGetAttInMetadata(tupdesc);
3453-
funccxt->user_fctx = multi;
3454-
3455-
MemoryContextSwitchTo(oldcxt);
3456-
}
3457-
3458-
funccxt = SRF_PERCALL_SETUP();
3459-
multi = (mxact *) funccxt->user_fctx;
3460-
3461-
while (multi->iter < multi->nmembers)
3462-
{
3463-
HeapTuple tuple;
3464-
char *values[2];
3465-
3466-
values[0] = psprintf("%u", multi->members[multi->iter].xid);
3467-
values[1] = mxstatus_to_string(multi->members[multi->iter].status);
3468-
3469-
tuple = BuildTupleFromCStrings(funccxt->attinmeta, values);
3470-
3471-
multi->iter++;
3472-
pfree(values[0]);
3473-
SRF_RETURN_NEXT(funccxt, HeapTupleGetDatum(tuple));
3474-
}
3475-
3476-
SRF_RETURN_DONE(funccxt);
3477-
}
3478-
34793415
/*
34803416
* Entrypoint for sync.c to sync offsets files.
34813417
*/

src/backend/utils/adt/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ OBJS = \
6868
misc.o \
6969
multirangetypes.o \
7070
multirangetypes_selfuncs.o \
71+
multixactfuncs.o \
7172
name.o \
7273
network.o \
7374
network_gist.o \

src/backend/utils/adt/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ backend_sources += files(
5555
'misc.c',
5656
'multirangetypes.c',
5757
'multirangetypes_selfuncs.c',
58+
'multixactfuncs.c',
5859
'name.c',
5960
'network.c',
6061
'network_gist.c',
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* multixactfuncs.c
4+
* Functions for accessing multixact-related data.
5+
*
6+
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7+
* Portions Copyright (c) 1994, Regents of the University of California
8+
*
9+
* IDENTIFICATION
10+
* src/backend/utils/adt/multixactfuncs.c
11+
*
12+
*-------------------------------------------------------------------------
13+
*/
14+
15+
#include "postgres.h"
16+
17+
#include "access/multixact.h"
18+
#include "funcapi.h"
19+
#include "utils/builtins.h"
20+
21+
/*
22+
* pg_get_multixact_members
23+
*
24+
* Returns information about the MultiXactMembers of the specified
25+
* MultiXactId.
26+
*/
27+
Datum
28+
pg_get_multixact_members(PG_FUNCTION_ARGS)
29+
{
30+
typedef struct
31+
{
32+
MultiXactMember *members;
33+
int nmembers;
34+
int iter;
35+
} mxact;
36+
MultiXactId mxid = PG_GETARG_TRANSACTIONID(0);
37+
mxact *multi;
38+
FuncCallContext *funccxt;
39+
40+
if (mxid < FirstMultiXactId)
41+
ereport(ERROR,
42+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
43+
errmsg("invalid MultiXactId: %u", mxid)));
44+
45+
if (SRF_IS_FIRSTCALL())
46+
{
47+
MemoryContext oldcxt;
48+
TupleDesc tupdesc;
49+
50+
funccxt = SRF_FIRSTCALL_INIT();
51+
oldcxt = MemoryContextSwitchTo(funccxt->multi_call_memory_ctx);
52+
53+
multi = palloc(sizeof(mxact));
54+
/* no need to allow for old values here */
55+
multi->nmembers = GetMultiXactIdMembers(mxid, &multi->members, false,
56+
false);
57+
multi->iter = 0;
58+
59+
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
60+
elog(ERROR, "return type must be a row type");
61+
funccxt->tuple_desc = tupdesc;
62+
funccxt->attinmeta = TupleDescGetAttInMetadata(tupdesc);
63+
funccxt->user_fctx = multi;
64+
65+
MemoryContextSwitchTo(oldcxt);
66+
}
67+
68+
funccxt = SRF_PERCALL_SETUP();
69+
multi = (mxact *) funccxt->user_fctx;
70+
71+
while (multi->iter < multi->nmembers)
72+
{
73+
HeapTuple tuple;
74+
char *values[2];
75+
76+
values[0] = psprintf("%u", multi->members[multi->iter].xid);
77+
values[1] = mxstatus_to_string(multi->members[multi->iter].status);
78+
79+
tuple = BuildTupleFromCStrings(funccxt->attinmeta, values);
80+
81+
multi->iter++;
82+
pfree(values[0]);
83+
SRF_RETURN_NEXT(funccxt, HeapTupleGetDatum(tuple));
84+
}
85+
86+
SRF_RETURN_DONE(funccxt);
87+
}

src/include/access/multixact.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,6 @@ extern void multixact_desc(StringInfo buf, XLogReaderState *record);
158158
extern const char *multixact_identify(uint8 info);
159159
extern char *mxid_to_string(MultiXactId multi, int nmembers,
160160
MultiXactMember *members);
161+
extern char *mxstatus_to_string(MultiXactStatus status);
161162

162163
#endif /* MULTIXACT_H */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy