1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* oid.c
|
2000-12-22 22:36:09 +01:00
|
|
|
* Functions for the built-in type Oid ... also oidvector.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2023-01-02 21:00:37 +01:00
|
|
|
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/backend/utils/adt/oid.c
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2000-11-21 05:27:39 +01:00
|
|
|
#include "postgres.h"
|
1996-11-06 11:32:10 +01:00
|
|
|
|
2000-01-10 16:41:34 +01:00
|
|
|
#include <ctype.h>
|
2000-12-22 22:36:09 +01:00
|
|
|
#include <limits.h>
|
2000-11-21 05:27:39 +01:00
|
|
|
|
2005-03-29 02:17:27 +02:00
|
|
|
#include "catalog/pg_type.h"
|
2003-05-09 17:44:42 +02:00
|
|
|
#include "libpq/pqformat.h"
|
Convert a few more datatype input functions to report errors softly.
Convert assorted internal-ish datatypes, namely aclitemin,
int2vectorin, oidin, oidvectorin, pg_lsn_in, pg_snapshot_in,
and tidin to the new style.
(Some others you might expect to find in this group, such as
cidin and xidin, need no changes because they never throw
errors at all. That seems a little cheesy ... but it is not in
the charter of this patch series to add new error conditions.)
Amul Sul, minor mods by me
Discussion: https://postgr.es/m/CAAJ_b97KeDWUdpTKGOaFYPv0OicjOu6EW+QYWj-Ywrgj_aEy1g@mail.gmail.com
2022-12-14 23:50:24 +01:00
|
|
|
#include "nodes/miscnodes.h"
|
2016-11-29 18:00:00 +01:00
|
|
|
#include "nodes/value.h"
|
2005-03-29 02:17:27 +02:00
|
|
|
#include "utils/array.h"
|
1999-07-16 05:14:30 +02:00
|
|
|
#include "utils/builtins.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2003-05-09 17:44:42 +02:00
|
|
|
|
2005-03-29 02:17:27 +02:00
|
|
|
#define OidVectorSize(n) (offsetof(oidvector, values) + (n) * sizeof(Oid))
|
|
|
|
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* USER I/O ROUTINES *
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2000-12-22 22:36:09 +01:00
|
|
|
Datum
|
|
|
|
oidin(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
char *s = PG_GETARG_CSTRING(0);
|
|
|
|
Oid result;
|
|
|
|
|
Detect bad input for types xid, xid8, and cid.
Historically these input functions just called strtoul or strtoull
and returned the result, with no error detection whatever. Upgrade
them to reject garbage input and out-of-range values, similarly to
our other numeric input routines.
To share the code for this with type oid, adjust the existing
"oidin_subr" to be agnostic about the SQL name of the type it is
handling, and move it to numutils.c; then clone it for 64-bit types.
Because the xid types previously accepted hex and octal input by
reason of calling strtoul[l] with third argument zero, I made the
common subroutine do that too, with the consequence that type oid
now also accepts hex and octal input. In view of 6fcda9aba, that
seems like a good thing.
While at it, simplify the existing over-complicated handling of
syntax errors from strtoul: we only need one ereturn not three.
Discussion: https://postgr.es/m/3526121.1672000729@sss.pgh.pa.us
2022-12-27 17:40:01 +01:00
|
|
|
result = uint32in_subr(s, NULL, "oid", fcinfo->context);
|
2000-12-22 22:36:09 +01:00
|
|
|
PG_RETURN_OID(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
oidout(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
Oid o = PG_GETARG_OID(0);
|
|
|
|
char *result = (char *) palloc(12);
|
|
|
|
|
|
|
|
snprintf(result, 12, "%u", o);
|
|
|
|
PG_RETURN_CSTRING(result);
|
|
|
|
}
|
|
|
|
|
2003-05-09 17:44:42 +02:00
|
|
|
/*
|
|
|
|
* oidrecv - converts external binary format to oid
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
oidrecv(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
|
|
|
|
|
|
|
|
PG_RETURN_OID((Oid) pq_getmsgint(buf, sizeof(Oid)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* oidsend - converts oid to binary format
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
oidsend(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
Oid arg1 = PG_GETARG_OID(0);
|
|
|
|
StringInfoData buf;
|
|
|
|
|
|
|
|
pq_begintypsend(&buf);
|
2017-10-12 06:00:46 +02:00
|
|
|
pq_sendint32(&buf, arg1);
|
2003-05-09 17:44:42 +02:00
|
|
|
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
|
|
|
|
}
|
|
|
|
|
2005-03-29 02:17:27 +02:00
|
|
|
/*
|
|
|
|
* construct oidvector given a raw array of Oids
|
|
|
|
*
|
|
|
|
* If oids is NULL then caller must fill values[] afterward
|
|
|
|
*/
|
|
|
|
oidvector *
|
|
|
|
buildoidvector(const Oid *oids, int n)
|
|
|
|
{
|
|
|
|
oidvector *result;
|
|
|
|
|
|
|
|
result = (oidvector *) palloc0(OidVectorSize(n));
|
|
|
|
|
|
|
|
if (n > 0 && oids)
|
|
|
|
memcpy(result->values, oids, n * sizeof(Oid));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach standard array header. For historical reasons, we set the index
|
|
|
|
* lower bound to 0 not 1.
|
|
|
|
*/
|
2007-02-28 00:48:10 +01:00
|
|
|
SET_VARSIZE(result, OidVectorSize(n));
|
2005-03-29 02:17:27 +02:00
|
|
|
result->ndim = 1;
|
2005-11-17 23:14:56 +01:00
|
|
|
result->dataoffset = 0; /* never any nulls */
|
2005-03-29 02:17:27 +02:00
|
|
|
result->elemtype = OIDOID;
|
|
|
|
result->dim1 = n;
|
|
|
|
result->lbound1 = 0;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2000-12-22 22:36:09 +01:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*
|
2000-01-10 17:13:23 +01:00
|
|
|
* oidvectorin - converts "num num ..." to internal form
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
oidvectorin(PG_FUNCTION_ARGS)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2000-06-05 09:29:25 +02:00
|
|
|
char *oidString = PG_GETARG_CSTRING(0);
|
Convert a few more datatype input functions to report errors softly.
Convert assorted internal-ish datatypes, namely aclitemin,
int2vectorin, oidin, oidvectorin, pg_lsn_in, pg_snapshot_in,
and tidin to the new style.
(Some others you might expect to find in this group, such as
cidin and xidin, need no changes because they never throw
errors at all. That seems a little cheesy ... but it is not in
the charter of this patch series to add new error conditions.)
Amul Sul, minor mods by me
Discussion: https://postgr.es/m/CAAJ_b97KeDWUdpTKGOaFYPv0OicjOu6EW+QYWj-Ywrgj_aEy1g@mail.gmail.com
2022-12-14 23:50:24 +01:00
|
|
|
Node *escontext = fcinfo->context;
|
2005-03-29 02:17:27 +02:00
|
|
|
oidvector *result;
|
2023-01-15 23:32:09 +01:00
|
|
|
int nalloc;
|
2005-03-29 02:17:27 +02:00
|
|
|
int n;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2023-01-15 23:32:09 +01:00
|
|
|
nalloc = 32; /* arbitrary initial size guess */
|
|
|
|
result = (oidvector *) palloc0(OidVectorSize(nalloc));
|
2005-03-29 02:17:27 +02:00
|
|
|
|
2023-01-15 23:32:09 +01:00
|
|
|
for (n = 0;; n++)
|
1997-03-12 22:13:19 +01:00
|
|
|
{
|
2000-12-03 21:45:40 +01:00
|
|
|
while (*oidString && isspace((unsigned char) *oidString))
|
2000-01-10 16:41:34 +01:00
|
|
|
oidString++;
|
2000-12-22 22:36:09 +01:00
|
|
|
if (*oidString == '\0')
|
|
|
|
break;
|
2023-01-15 23:32:09 +01:00
|
|
|
|
|
|
|
if (n >= nalloc)
|
|
|
|
{
|
|
|
|
nalloc *= 2;
|
|
|
|
result = (oidvector *) repalloc(result, OidVectorSize(nalloc));
|
|
|
|
}
|
|
|
|
|
Detect bad input for types xid, xid8, and cid.
Historically these input functions just called strtoul or strtoull
and returned the result, with no error detection whatever. Upgrade
them to reject garbage input and out-of-range values, similarly to
our other numeric input routines.
To share the code for this with type oid, adjust the existing
"oidin_subr" to be agnostic about the SQL name of the type it is
handling, and move it to numutils.c; then clone it for 64-bit types.
Because the xid types previously accepted hex and octal input by
reason of calling strtoul[l] with third argument zero, I made the
common subroutine do that too, with the consequence that type oid
now also accepts hex and octal input. In view of 6fcda9aba, that
seems like a good thing.
While at it, simplify the existing over-complicated handling of
syntax errors from strtoul: we only need one ereturn not three.
Discussion: https://postgr.es/m/3526121.1672000729@sss.pgh.pa.us
2022-12-27 17:40:01 +01:00
|
|
|
result->values[n] = uint32in_subr(oidString, &oidString,
|
|
|
|
"oid", escontext);
|
Convert a few more datatype input functions to report errors softly.
Convert assorted internal-ish datatypes, namely aclitemin,
int2vectorin, oidin, oidvectorin, pg_lsn_in, pg_snapshot_in,
and tidin to the new style.
(Some others you might expect to find in this group, such as
cidin and xidin, need no changes because they never throw
errors at all. That seems a little cheesy ... but it is not in
the charter of this patch series to add new error conditions.)
Amul Sul, minor mods by me
Discussion: https://postgr.es/m/CAAJ_b97KeDWUdpTKGOaFYPv0OicjOu6EW+QYWj-Ywrgj_aEy1g@mail.gmail.com
2022-12-14 23:50:24 +01:00
|
|
|
if (SOFT_ERROR_OCCURRED(escontext))
|
|
|
|
PG_RETURN_NULL();
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
2005-03-29 02:17:27 +02:00
|
|
|
|
2007-02-28 00:48:10 +01:00
|
|
|
SET_VARSIZE(result, OidVectorSize(n));
|
2005-03-29 02:17:27 +02:00
|
|
|
result->ndim = 1;
|
2005-11-17 23:14:56 +01:00
|
|
|
result->dataoffset = 0; /* never any nulls */
|
2005-03-29 02:17:27 +02:00
|
|
|
result->elemtype = OIDOID;
|
|
|
|
result->dim1 = n;
|
|
|
|
result->lbound1 = 0;
|
2000-01-10 05:36:37 +01:00
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
PG_RETURN_POINTER(result);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-01-10 17:13:23 +01:00
|
|
|
* oidvectorout - converts internal form to "num num ..."
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
oidvectorout(PG_FUNCTION_ARGS)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2005-03-29 02:17:27 +02:00
|
|
|
oidvector *oidArray = (oidvector *) PG_GETARG_POINTER(0);
|
2000-01-10 16:41:34 +01:00
|
|
|
int num,
|
2005-03-29 02:17:27 +02:00
|
|
|
nnums = oidArray->dim1;
|
1998-02-11 20:14:04 +01:00
|
|
|
char *rp;
|
1996-07-09 08:22:35 +02:00
|
|
|
char *result;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/* assumes sign, 10 digits, ' ' */
|
2005-03-29 02:17:27 +02:00
|
|
|
rp = result = (char *) palloc(nnums * 12 + 1);
|
|
|
|
for (num = 0; num < nnums; num++)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2000-01-10 16:41:34 +01:00
|
|
|
if (num != 0)
|
|
|
|
*rp++ = ' ';
|
2005-03-29 02:17:27 +02:00
|
|
|
sprintf(rp, "%u", oidArray->values[num]);
|
1996-07-09 08:22:35 +02:00
|
|
|
while (*++rp != '\0')
|
|
|
|
;
|
|
|
|
}
|
2000-01-10 16:41:34 +01:00
|
|
|
*rp = '\0';
|
2000-06-05 09:29:25 +02:00
|
|
|
PG_RETURN_CSTRING(result);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2003-05-09 17:44:42 +02:00
|
|
|
/*
|
|
|
|
* oidvectorrecv - converts external binary format to oidvector
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
oidvectorrecv(PG_FUNCTION_ARGS)
|
|
|
|
{
|
Change function call information to be variable length.
Before this change FunctionCallInfoData, the struct arguments etc for
V1 function calls are stored in, always had space for
FUNC_MAX_ARGS/100 arguments, storing datums and their nullness in two
arrays. For nearly every function call 100 arguments is far more than
needed, therefore wasting memory. Arg and argnull being two separate
arrays also guarantees that to access a single argument, two
cachelines have to be touched.
Change the layout so there's a single variable-length array with pairs
of value / isnull. That drastically reduces memory consumption for
most function calls (on x86-64 a two argument function now uses
64bytes, previously 936 bytes), and makes it very likely that argument
value and its nullness are on the same cacheline.
Arguments are stored in a new NullableDatum struct, which, due to
padding, needs more memory per argument than before. But as usually
far fewer arguments are stored, and individual arguments are cheaper
to access, that's still a clear win. It's likely that there's other
places where conversion to NullableDatum arrays would make sense,
e.g. TupleTableSlots, but that's for another commit.
Because the function call information is now variable-length
allocations have to take the number of arguments into account. For
heap allocations that can be done with SizeForFunctionCallInfoData(),
for on-stack allocations there's a new LOCAL_FCINFO(name, nargs) macro
that helps to allocate an appropriately sized and aligned variable.
Some places with stack allocation function call information don't know
the number of arguments at compile time, and currently variably sized
stack allocations aren't allowed in postgres. Therefore allow for
FUNC_MAX_ARGS space in these cases. They're not that common, so for
now that seems acceptable.
Because of the need to allocate FunctionCallInfo of the appropriate
size, older extensions may need to update their code. To avoid subtle
breakages, the FunctionCallInfoData struct has been renamed to
FunctionCallInfoBaseData. Most code only references FunctionCallInfo,
so that shouldn't cause much collateral damage.
This change is also a prerequisite for more efficient expression JIT
compilation (by allocating the function call information on the stack,
allowing LLVM to optimize it away); previously the size of the call
information caused problems inside LLVM's optimizer.
Author: Andres Freund
Reviewed-By: Tom Lane
Discussion: https://postgr.es/m/20180605172952.x34m5uz6ju6enaem@alap3.anarazel.de
2019-01-26 23:17:52 +01:00
|
|
|
LOCAL_FCINFO(locfcinfo, 3);
|
2003-05-09 17:44:42 +02:00
|
|
|
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
|
2005-03-29 02:17:27 +02:00
|
|
|
oidvector *result;
|
|
|
|
|
2006-03-02 22:13:04 +01:00
|
|
|
/*
|
|
|
|
* Normally one would call array_recv() using DirectFunctionCall3, but
|
|
|
|
* that does not work since array_recv wants to cache some data using
|
|
|
|
* fcinfo->flinfo->fn_extra. So we need to pass it our own flinfo
|
|
|
|
* parameter.
|
|
|
|
*/
|
Change function call information to be variable length.
Before this change FunctionCallInfoData, the struct arguments etc for
V1 function calls are stored in, always had space for
FUNC_MAX_ARGS/100 arguments, storing datums and their nullness in two
arrays. For nearly every function call 100 arguments is far more than
needed, therefore wasting memory. Arg and argnull being two separate
arrays also guarantees that to access a single argument, two
cachelines have to be touched.
Change the layout so there's a single variable-length array with pairs
of value / isnull. That drastically reduces memory consumption for
most function calls (on x86-64 a two argument function now uses
64bytes, previously 936 bytes), and makes it very likely that argument
value and its nullness are on the same cacheline.
Arguments are stored in a new NullableDatum struct, which, due to
padding, needs more memory per argument than before. But as usually
far fewer arguments are stored, and individual arguments are cheaper
to access, that's still a clear win. It's likely that there's other
places where conversion to NullableDatum arrays would make sense,
e.g. TupleTableSlots, but that's for another commit.
Because the function call information is now variable-length
allocations have to take the number of arguments into account. For
heap allocations that can be done with SizeForFunctionCallInfoData(),
for on-stack allocations there's a new LOCAL_FCINFO(name, nargs) macro
that helps to allocate an appropriately sized and aligned variable.
Some places with stack allocation function call information don't know
the number of arguments at compile time, and currently variably sized
stack allocations aren't allowed in postgres. Therefore allow for
FUNC_MAX_ARGS space in these cases. They're not that common, so for
now that seems acceptable.
Because of the need to allocate FunctionCallInfo of the appropriate
size, older extensions may need to update their code. To avoid subtle
breakages, the FunctionCallInfoData struct has been renamed to
FunctionCallInfoBaseData. Most code only references FunctionCallInfo,
so that shouldn't cause much collateral damage.
This change is also a prerequisite for more efficient expression JIT
compilation (by allocating the function call information on the stack,
allowing LLVM to optimize it away); previously the size of the call
information caused problems inside LLVM's optimizer.
Author: Andres Freund
Reviewed-By: Tom Lane
Discussion: https://postgr.es/m/20180605172952.x34m5uz6ju6enaem@alap3.anarazel.de
2019-01-26 23:17:52 +01:00
|
|
|
InitFunctionCallInfoData(*locfcinfo, fcinfo->flinfo, 3,
|
2011-04-13 01:19:24 +02:00
|
|
|
InvalidOid, NULL, NULL);
|
2006-03-02 22:13:04 +01:00
|
|
|
|
Change function call information to be variable length.
Before this change FunctionCallInfoData, the struct arguments etc for
V1 function calls are stored in, always had space for
FUNC_MAX_ARGS/100 arguments, storing datums and their nullness in two
arrays. For nearly every function call 100 arguments is far more than
needed, therefore wasting memory. Arg and argnull being two separate
arrays also guarantees that to access a single argument, two
cachelines have to be touched.
Change the layout so there's a single variable-length array with pairs
of value / isnull. That drastically reduces memory consumption for
most function calls (on x86-64 a two argument function now uses
64bytes, previously 936 bytes), and makes it very likely that argument
value and its nullness are on the same cacheline.
Arguments are stored in a new NullableDatum struct, which, due to
padding, needs more memory per argument than before. But as usually
far fewer arguments are stored, and individual arguments are cheaper
to access, that's still a clear win. It's likely that there's other
places where conversion to NullableDatum arrays would make sense,
e.g. TupleTableSlots, but that's for another commit.
Because the function call information is now variable-length
allocations have to take the number of arguments into account. For
heap allocations that can be done with SizeForFunctionCallInfoData(),
for on-stack allocations there's a new LOCAL_FCINFO(name, nargs) macro
that helps to allocate an appropriately sized and aligned variable.
Some places with stack allocation function call information don't know
the number of arguments at compile time, and currently variably sized
stack allocations aren't allowed in postgres. Therefore allow for
FUNC_MAX_ARGS space in these cases. They're not that common, so for
now that seems acceptable.
Because of the need to allocate FunctionCallInfo of the appropriate
size, older extensions may need to update their code. To avoid subtle
breakages, the FunctionCallInfoData struct has been renamed to
FunctionCallInfoBaseData. Most code only references FunctionCallInfo,
so that shouldn't cause much collateral damage.
This change is also a prerequisite for more efficient expression JIT
compilation (by allocating the function call information on the stack,
allowing LLVM to optimize it away); previously the size of the call
information caused problems inside LLVM's optimizer.
Author: Andres Freund
Reviewed-By: Tom Lane
Discussion: https://postgr.es/m/20180605172952.x34m5uz6ju6enaem@alap3.anarazel.de
2019-01-26 23:17:52 +01:00
|
|
|
locfcinfo->args[0].value = PointerGetDatum(buf);
|
|
|
|
locfcinfo->args[0].isnull = false;
|
|
|
|
locfcinfo->args[1].value = ObjectIdGetDatum(OIDOID);
|
|
|
|
locfcinfo->args[1].isnull = false;
|
|
|
|
locfcinfo->args[2].value = Int32GetDatum(-1);
|
|
|
|
locfcinfo->args[2].isnull = false;
|
2006-03-02 22:13:04 +01:00
|
|
|
|
Change function call information to be variable length.
Before this change FunctionCallInfoData, the struct arguments etc for
V1 function calls are stored in, always had space for
FUNC_MAX_ARGS/100 arguments, storing datums and their nullness in two
arrays. For nearly every function call 100 arguments is far more than
needed, therefore wasting memory. Arg and argnull being two separate
arrays also guarantees that to access a single argument, two
cachelines have to be touched.
Change the layout so there's a single variable-length array with pairs
of value / isnull. That drastically reduces memory consumption for
most function calls (on x86-64 a two argument function now uses
64bytes, previously 936 bytes), and makes it very likely that argument
value and its nullness are on the same cacheline.
Arguments are stored in a new NullableDatum struct, which, due to
padding, needs more memory per argument than before. But as usually
far fewer arguments are stored, and individual arguments are cheaper
to access, that's still a clear win. It's likely that there's other
places where conversion to NullableDatum arrays would make sense,
e.g. TupleTableSlots, but that's for another commit.
Because the function call information is now variable-length
allocations have to take the number of arguments into account. For
heap allocations that can be done with SizeForFunctionCallInfoData(),
for on-stack allocations there's a new LOCAL_FCINFO(name, nargs) macro
that helps to allocate an appropriately sized and aligned variable.
Some places with stack allocation function call information don't know
the number of arguments at compile time, and currently variably sized
stack allocations aren't allowed in postgres. Therefore allow for
FUNC_MAX_ARGS space in these cases. They're not that common, so for
now that seems acceptable.
Because of the need to allocate FunctionCallInfo of the appropriate
size, older extensions may need to update their code. To avoid subtle
breakages, the FunctionCallInfoData struct has been renamed to
FunctionCallInfoBaseData. Most code only references FunctionCallInfo,
so that shouldn't cause much collateral damage.
This change is also a prerequisite for more efficient expression JIT
compilation (by allocating the function call information on the stack,
allowing LLVM to optimize it away); previously the size of the call
information caused problems inside LLVM's optimizer.
Author: Andres Freund
Reviewed-By: Tom Lane
Discussion: https://postgr.es/m/20180605172952.x34m5uz6ju6enaem@alap3.anarazel.de
2019-01-26 23:17:52 +01:00
|
|
|
result = (oidvector *) DatumGetPointer(array_recv(locfcinfo));
|
2006-03-02 22:13:04 +01:00
|
|
|
|
Change function call information to be variable length.
Before this change FunctionCallInfoData, the struct arguments etc for
V1 function calls are stored in, always had space for
FUNC_MAX_ARGS/100 arguments, storing datums and their nullness in two
arrays. For nearly every function call 100 arguments is far more than
needed, therefore wasting memory. Arg and argnull being two separate
arrays also guarantees that to access a single argument, two
cachelines have to be touched.
Change the layout so there's a single variable-length array with pairs
of value / isnull. That drastically reduces memory consumption for
most function calls (on x86-64 a two argument function now uses
64bytes, previously 936 bytes), and makes it very likely that argument
value and its nullness are on the same cacheline.
Arguments are stored in a new NullableDatum struct, which, due to
padding, needs more memory per argument than before. But as usually
far fewer arguments are stored, and individual arguments are cheaper
to access, that's still a clear win. It's likely that there's other
places where conversion to NullableDatum arrays would make sense,
e.g. TupleTableSlots, but that's for another commit.
Because the function call information is now variable-length
allocations have to take the number of arguments into account. For
heap allocations that can be done with SizeForFunctionCallInfoData(),
for on-stack allocations there's a new LOCAL_FCINFO(name, nargs) macro
that helps to allocate an appropriately sized and aligned variable.
Some places with stack allocation function call information don't know
the number of arguments at compile time, and currently variably sized
stack allocations aren't allowed in postgres. Therefore allow for
FUNC_MAX_ARGS space in these cases. They're not that common, so for
now that seems acceptable.
Because of the need to allocate FunctionCallInfo of the appropriate
size, older extensions may need to update their code. To avoid subtle
breakages, the FunctionCallInfoData struct has been renamed to
FunctionCallInfoBaseData. Most code only references FunctionCallInfo,
so that shouldn't cause much collateral damage.
This change is also a prerequisite for more efficient expression JIT
compilation (by allocating the function call information on the stack,
allowing LLVM to optimize it away); previously the size of the call
information caused problems inside LLVM's optimizer.
Author: Andres Freund
Reviewed-By: Tom Lane
Discussion: https://postgr.es/m/20180605172952.x34m5uz6ju6enaem@alap3.anarazel.de
2019-01-26 23:17:52 +01:00
|
|
|
Assert(!locfcinfo->isnull);
|
2006-03-02 22:13:04 +01:00
|
|
|
|
2009-09-04 13:20:23 +02:00
|
|
|
/* sanity checks: oidvector must be 1-D, 0-based, no nulls */
|
2005-11-17 23:14:56 +01:00
|
|
|
if (ARR_NDIM(result) != 1 ||
|
|
|
|
ARR_HASNULL(result) ||
|
2009-09-04 13:20:23 +02:00
|
|
|
ARR_ELEMTYPE(result) != OIDOID ||
|
|
|
|
ARR_LBOUND(result)[0] != 0)
|
2005-03-29 02:17:27 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
|
|
|
|
errmsg("invalid oidvector data")));
|
2009-09-04 13:20:23 +02:00
|
|
|
|
2003-05-09 17:44:42 +02:00
|
|
|
PG_RETURN_POINTER(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* oidvectorsend - converts oidvector to binary format
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
oidvectorsend(PG_FUNCTION_ARGS)
|
|
|
|
{
|
2005-03-29 02:17:27 +02:00
|
|
|
return array_send(fcinfo);
|
2003-05-09 17:44:42 +02:00
|
|
|
}
|
|
|
|
|
2010-06-13 19:43:13 +02:00
|
|
|
/*
|
2019-07-22 03:01:50 +02:00
|
|
|
* oidparse - get OID from ICONST/FCONST node
|
2010-06-13 19:43:13 +02:00
|
|
|
*/
|
|
|
|
Oid
|
|
|
|
oidparse(Node *node)
|
|
|
|
{
|
|
|
|
switch (nodeTag(node))
|
|
|
|
{
|
|
|
|
case T_Integer:
|
|
|
|
return intVal(node);
|
|
|
|
case T_Float:
|
2010-07-06 21:19:02 +02:00
|
|
|
|
2010-06-13 19:43:13 +02:00
|
|
|
/*
|
|
|
|
* Values too large for int4 will be represented as Float
|
|
|
|
* constants by the lexer. Accept these if they are valid OID
|
|
|
|
* strings.
|
|
|
|
*/
|
Detect bad input for types xid, xid8, and cid.
Historically these input functions just called strtoul or strtoull
and returned the result, with no error detection whatever. Upgrade
them to reject garbage input and out-of-range values, similarly to
our other numeric input routines.
To share the code for this with type oid, adjust the existing
"oidin_subr" to be agnostic about the SQL name of the type it is
handling, and move it to numutils.c; then clone it for 64-bit types.
Because the xid types previously accepted hex and octal input by
reason of calling strtoul[l] with third argument zero, I made the
common subroutine do that too, with the consequence that type oid
now also accepts hex and octal input. In view of 6fcda9aba, that
seems like a good thing.
While at it, simplify the existing over-complicated handling of
syntax errors from strtoul: we only need one ereturn not three.
Discussion: https://postgr.es/m/3526121.1672000729@sss.pgh.pa.us
2022-12-27 17:40:01 +01:00
|
|
|
return uint32in_subr(castNode(Float, node)->fval, NULL,
|
|
|
|
"oid", NULL);
|
2010-06-13 19:43:13 +02:00
|
|
|
default:
|
|
|
|
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));
|
|
|
|
}
|
|
|
|
return InvalidOid; /* keep compiler quiet */
|
|
|
|
}
|
|
|
|
|
2017-03-01 17:55:28 +01:00
|
|
|
/* qsort comparison function for Oids */
|
|
|
|
int
|
|
|
|
oid_cmp(const void *p1, const void *p2)
|
|
|
|
{
|
|
|
|
Oid v1 = *((const Oid *) p1);
|
|
|
|
Oid v2 = *((const Oid *) p2);
|
|
|
|
|
|
|
|
if (v1 < v2)
|
|
|
|
return -1;
|
|
|
|
if (v1 > v2)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-05-09 17:44:42 +02:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* PUBLIC ROUTINES *
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
oideq(PG_FUNCTION_ARGS)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2000-06-05 09:29:25 +02:00
|
|
|
Oid arg1 = PG_GETARG_OID(0);
|
|
|
|
Oid arg2 = PG_GETARG_OID(1);
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(arg1 == arg2);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
oidne(PG_FUNCTION_ARGS)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2000-06-05 09:29:25 +02:00
|
|
|
Oid arg1 = PG_GETARG_OID(0);
|
|
|
|
Oid arg2 = PG_GETARG_OID(1);
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(arg1 != arg2);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2000-11-21 04:23:21 +01:00
|
|
|
Datum
|
|
|
|
oidlt(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
Oid arg1 = PG_GETARG_OID(0);
|
|
|
|
Oid arg2 = PG_GETARG_OID(1);
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(arg1 < arg2);
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
oidle(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
Oid arg1 = PG_GETARG_OID(0);
|
|
|
|
Oid arg2 = PG_GETARG_OID(1);
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(arg1 <= arg2);
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
oidge(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
Oid arg1 = PG_GETARG_OID(0);
|
|
|
|
Oid arg2 = PG_GETARG_OID(1);
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(arg1 >= arg2);
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
oidgt(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
Oid arg1 = PG_GETARG_OID(0);
|
|
|
|
Oid arg2 = PG_GETARG_OID(1);
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(arg1 > arg2);
|
|
|
|
}
|
|
|
|
|
2001-08-15 00:21:59 +02:00
|
|
|
Datum
|
|
|
|
oidlarger(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
Oid arg1 = PG_GETARG_OID(0);
|
|
|
|
Oid arg2 = PG_GETARG_OID(1);
|
|
|
|
|
|
|
|
PG_RETURN_OID((arg1 > arg2) ? arg1 : arg2);
|
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
oidsmaller(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
Oid arg1 = PG_GETARG_OID(0);
|
|
|
|
Oid arg2 = PG_GETARG_OID(1);
|
|
|
|
|
|
|
|
PG_RETURN_OID((arg1 < arg2) ? arg1 : arg2);
|
|
|
|
}
|
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
oidvectoreq(PG_FUNCTION_ARGS)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2005-03-29 02:17:27 +02:00
|
|
|
int32 cmp = DatumGetInt32(btoidvectorcmp(fcinfo));
|
2000-06-05 09:29:25 +02:00
|
|
|
|
2005-03-29 02:17:27 +02:00
|
|
|
PG_RETURN_BOOL(cmp == 0);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
oidvectorne(PG_FUNCTION_ARGS)
|
1998-10-29 19:07:09 +01:00
|
|
|
{
|
2005-03-29 02:17:27 +02:00
|
|
|
int32 cmp = DatumGetInt32(btoidvectorcmp(fcinfo));
|
2000-06-05 09:29:25 +02:00
|
|
|
|
2005-03-29 02:17:27 +02:00
|
|
|
PG_RETURN_BOOL(cmp != 0);
|
1998-10-29 19:07:09 +01:00
|
|
|
}
|
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
oidvectorlt(PG_FUNCTION_ARGS)
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
2005-03-29 02:17:27 +02:00
|
|
|
int32 cmp = DatumGetInt32(btoidvectorcmp(fcinfo));
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(cmp < 0);
|
1998-08-19 04:04:17 +02:00
|
|
|
}
|
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
oidvectorle(PG_FUNCTION_ARGS)
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
2005-03-29 02:17:27 +02:00
|
|
|
int32 cmp = DatumGetInt32(btoidvectorcmp(fcinfo));
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(cmp <= 0);
|
1998-08-19 04:04:17 +02:00
|
|
|
}
|
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
oidvectorge(PG_FUNCTION_ARGS)
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
2005-03-29 02:17:27 +02:00
|
|
|
int32 cmp = DatumGetInt32(btoidvectorcmp(fcinfo));
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(cmp >= 0);
|
1998-08-19 04:04:17 +02:00
|
|
|
}
|
|
|
|
|
2000-06-05 09:29:25 +02:00
|
|
|
Datum
|
|
|
|
oidvectorgt(PG_FUNCTION_ARGS)
|
1998-08-19 04:04:17 +02:00
|
|
|
{
|
2005-03-29 02:17:27 +02:00
|
|
|
int32 cmp = DatumGetInt32(btoidvectorcmp(fcinfo));
|
|
|
|
|
|
|
|
PG_RETURN_BOOL(cmp > 0);
|
1998-08-19 04:04:17 +02:00
|
|
|
}
|