aboutsummaryrefslogtreecommitdiff
path: root/src/backend/tsearch/wparser.c
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2022-12-21 10:11:22 +0900
committerMichael Paquier <michael@paquier.xyz>2022-12-21 10:11:22 +0900
commit22e3b558052aa209cba2a8fec192d76b5faef19e (patch)
treeb4626ba839fad837c50e039ce56e6819a5e0f9f6 /src/backend/tsearch/wparser.c
parentf03bd5717eaf31569ca797a2f7d65608f88ac2a2 (diff)
downloadpostgresql-22e3b558052aa209cba2a8fec192d76b5faef19e.tar.gz
postgresql-22e3b558052aa209cba2a8fec192d76b5faef19e.zip
Switch some system functions to use get_call_result_type()
This shaves some code by replacing the combinations of CreateTemplateTupleDesc()/TupleDescInitEntry() hardcoding a mapping of the attributes listed in pg_proc.dat by get_call_result_type() to build the TupleDesc needed for the rows generated. get_call_result_type() is more expensive than the former style, but this removes some duplication with the lists of OUT parameters (pg_proc.dat and the attributes hardcoded in these code paths). This is applied to functions that are not considered as critical (aka that could be called repeatedly for monitoring purposes). Author: Bharath Rupireddy Reviewed-by: Robert Haas, Álvaro Herrera, Tom Lane, Michael Paquier Discussion: https://postgr.es/m/CALj2ACV23HW5HP5hFjd89FNS-z5X8r2jNXdMXcpN2BgTtKd87w@mail.gmail.com
Diffstat (limited to 'src/backend/tsearch/wparser.c')
-rw-r--r--src/backend/tsearch/wparser.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/src/backend/tsearch/wparser.c b/src/backend/tsearch/wparser.c
index 14bb60534f2..3ef043ac0e8 100644
--- a/src/backend/tsearch/wparser.c
+++ b/src/backend/tsearch/wparser.c
@@ -46,7 +46,8 @@ typedef struct HeadlineJsonState
static text *headline_json_value(void *_state, char *elem_value, int elem_len);
static void
-tt_setup_firstcall(FuncCallContext *funcctx, Oid prsid)
+tt_setup_firstcall(FuncCallContext *funcctx, FunctionCallInfo fcinfo,
+ Oid prsid)
{
TupleDesc tupdesc;
MemoryContext oldcontext;
@@ -66,15 +67,11 @@ tt_setup_firstcall(FuncCallContext *funcctx, Oid prsid)
(Datum) 0));
funcctx->user_fctx = (void *) st;
- tupdesc = CreateTemplateTupleDesc(3);
- TupleDescInitEntry(tupdesc, (AttrNumber) 1, "tokid",
- INT4OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 2, "alias",
- TEXTOID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 3, "description",
- TEXTOID, -1, 0);
-
+ if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
+ elog(ERROR, "return type must be a row type");
+ funcctx->tuple_desc = tupdesc;
funcctx->attinmeta = TupleDescGetAttInMetadata(tupdesc);
+
MemoryContextSwitchTo(oldcontext);
}
@@ -116,7 +113,7 @@ ts_token_type_byid(PG_FUNCTION_ARGS)
if (SRF_IS_FIRSTCALL())
{
funcctx = SRF_FIRSTCALL_INIT();
- tt_setup_firstcall(funcctx, PG_GETARG_OID(0));
+ tt_setup_firstcall(funcctx, fcinfo, PG_GETARG_OID(0));
}
funcctx = SRF_PERCALL_SETUP();
@@ -139,7 +136,7 @@ ts_token_type_byname(PG_FUNCTION_ARGS)
funcctx = SRF_FIRSTCALL_INIT();
prsId = get_ts_parser_oid(textToQualifiedNameList(prsname), false);
- tt_setup_firstcall(funcctx, prsId);
+ tt_setup_firstcall(funcctx, fcinfo, prsId);
}
funcctx = SRF_PERCALL_SETUP();
@@ -164,7 +161,8 @@ typedef struct
static void
-prs_setup_firstcall(FuncCallContext *funcctx, Oid prsid, text *txt)
+prs_setup_firstcall(FuncCallContext *funcctx, FunctionCallInfo fcinfo,
+ Oid prsid, text *txt)
{
TupleDesc tupdesc;
MemoryContext oldcontext;
@@ -209,12 +207,9 @@ prs_setup_firstcall(FuncCallContext *funcctx, Oid prsid, text *txt)
st->cur = 0;
funcctx->user_fctx = (void *) st;
- tupdesc = CreateTemplateTupleDesc(2);
- TupleDescInitEntry(tupdesc, (AttrNumber) 1, "tokid",
- INT4OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 2, "token",
- TEXTOID, -1, 0);
-
+ if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
+ elog(ERROR, "return type must be a row type");
+ funcctx->tuple_desc = tupdesc;
funcctx->attinmeta = TupleDescGetAttInMetadata(tupdesc);
MemoryContextSwitchTo(oldcontext);
}
@@ -256,7 +251,7 @@ ts_parse_byid(PG_FUNCTION_ARGS)
text *txt = PG_GETARG_TEXT_PP(1);
funcctx = SRF_FIRSTCALL_INIT();
- prs_setup_firstcall(funcctx, PG_GETARG_OID(0), txt);
+ prs_setup_firstcall(funcctx, fcinfo, PG_GETARG_OID(0), txt);
PG_FREE_IF_COPY(txt, 1);
}
@@ -281,7 +276,7 @@ ts_parse_byname(PG_FUNCTION_ARGS)
funcctx = SRF_FIRSTCALL_INIT();
prsId = get_ts_parser_oid(textToQualifiedNameList(prsname), false);
- prs_setup_firstcall(funcctx, prsId, txt);
+ prs_setup_firstcall(funcctx, fcinfo, prsId, txt);
}
funcctx = SRF_PERCALL_SETUP();