1996-08-28 03:59:28 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* builtins.h
|
1996-08-28 03:59:28 +02:00
|
|
|
* Declarations for operations on built-in types.
|
|
|
|
*
|
|
|
|
*
|
2022-01-08 01:04:57 +01:00
|
|
|
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/include/utils/builtins.h
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef BUILTINS_H
|
|
|
|
#define BUILTINS_H
|
|
|
|
|
2000-08-24 05:29:15 +02:00
|
|
|
#include "fmgr.h"
|
2016-12-28 18:00:00 +01:00
|
|
|
#include "nodes/nodes.h"
|
2017-01-17 18:00:00 +01:00
|
|
|
#include "utils/fmgrprotos.h"
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2020-02-01 22:57:14 +01:00
|
|
|
/* Sign + the most decimal digits an 8-byte number could have */
|
|
|
|
#define MAXINT8LEN 20
|
2016-08-14 00:31:14 +02:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/* bool.c */
|
2009-03-09 15:34:35 +01:00
|
|
|
extern bool parse_bool(const char *value, bool *result);
|
|
|
|
extern bool parse_bool_with_len(const char *value, size_t len, bool *result);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2006-04-06 00:11:58 +02:00
|
|
|
/* domains.c */
|
Provide database object names as separate fields in error messages.
This patch addresses the problem that applications currently have to
extract object names from possibly-localized textual error messages,
if they want to know for example which index caused a UNIQUE_VIOLATION
failure. It adds new error message fields to the wire protocol, which
can carry the name of a table, table column, data type, or constraint
associated with the error. (Since the protocol spec has always instructed
clients to ignore unrecognized field types, this should not create any
compatibility problem.)
Support for providing these new fields has been added to just a limited set
of error reports (mainly, those in the "integrity constraint violation"
SQLSTATE class), but we will doubtless add them to more calls in future.
Pavel Stehule, reviewed and extensively revised by Peter Geoghegan, with
additional hacking by Tom Lane.
2013-01-29 23:06:26 +01:00
|
|
|
extern void domain_check(Datum value, bool isnull, Oid domainType,
|
|
|
|
void **extra, MemoryContext mcxt);
|
|
|
|
extern int errdatatype(Oid datatypeOid);
|
|
|
|
extern int errdomainconstraint(Oid datatypeOid, const char *conname);
|
2006-04-06 00:11:58 +02:00
|
|
|
|
2021-08-19 02:20:13 +02:00
|
|
|
/* encode.c */
|
|
|
|
extern uint64 hex_encode(const char *src, size_t len, char *dst);
|
|
|
|
extern uint64 hex_decode(const char *src, size_t len, char *dst);
|
2022-12-15 01:42:05 +01:00
|
|
|
extern uint64 hex_decode_safe(const char *src, size_t len, char *dst,
|
|
|
|
Node *escontext);
|
2021-08-19 02:20:13 +02:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/* int.c */
|
2012-06-25 00:51:46 +02:00
|
|
|
extern int2vector *buildint2vector(const int16 *int2s, int n);
|
2000-10-24 22:16:48 +02:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
/* name.c */
|
2020-08-10 18:51:31 +02:00
|
|
|
extern void namestrcpy(Name name, const char *str);
|
2000-01-22 15:20:56 +01:00
|
|
|
extern int namestrcmp(Name name, const char *str);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* numutils.c */
|
2018-07-22 23:58:01 +02:00
|
|
|
extern int16 pg_strtoint16(const char *s);
|
Convert a few datatype input functions to use "soft" error reporting.
This patch converts the input functions for bool, int2, int4, int8,
float4, float8, numeric, and contrib/cube to the new soft-error style.
array_in and record_in are also converted. There's lots more to do,
but this is enough to provide proof-of-concept that the soft-error
API is usable, as well as reference examples for how to convert
input functions.
This patch is mostly by me, but it owes very substantial debt to
earlier work by Nikita Glukhov, Andrew Dunstan, and Amul Sul.
Thanks to Andres Freund for review.
Discussion: https://postgr.es/m/3bbbb0df-7382-bf87-9737-340ba096e034@postgrespro.ru
2022-12-09 16:14:53 +01:00
|
|
|
extern int16 pg_strtoint16_safe(const char *s, Node *escontext);
|
2018-07-22 23:58:01 +02:00
|
|
|
extern int32 pg_strtoint32(const char *s);
|
Convert a few datatype input functions to use "soft" error reporting.
This patch converts the input functions for bool, int2, int4, int8,
float4, float8, numeric, and contrib/cube to the new soft-error style.
array_in and record_in are also converted. There's lots more to do,
but this is enough to provide proof-of-concept that the soft-error
API is usable, as well as reference examples for how to convert
input functions.
This patch is mostly by me, but it owes very substantial debt to
earlier work by Nikita Glukhov, Andrew Dunstan, and Amul Sul.
Thanks to Andres Freund for review.
Discussion: https://postgr.es/m/3bbbb0df-7382-bf87-9737-340ba096e034@postgrespro.ru
2022-12-09 16:14:53 +01:00
|
|
|
extern int32 pg_strtoint32_safe(const char *s, Node *escontext);
|
2022-02-14 21:29:45 +01:00
|
|
|
extern int64 pg_strtoint64(const char *s);
|
Convert a few datatype input functions to use "soft" error reporting.
This patch converts the input functions for bool, int2, int4, int8,
float4, float8, numeric, and contrib/cube to the new soft-error style.
array_in and record_in are also converted. There's lots more to do,
but this is enough to provide proof-of-concept that the soft-error
API is usable, as well as reference examples for how to convert
input functions.
This patch is mostly by me, but it owes very substantial debt to
earlier work by Nikita Glukhov, Andrew Dunstan, and Amul Sul.
Thanks to Andres Freund for review.
Discussion: https://postgr.es/m/3bbbb0df-7382-bf87-9737-340ba096e034@postgrespro.ru
2022-12-09 16:14:53 +01:00
|
|
|
extern int64 pg_strtoint64_safe(const char *s, Node *escontext);
|
2020-06-13 02:32:00 +02:00
|
|
|
extern int pg_itoa(int16 i, char *a);
|
2022-09-20 22:09:30 +02:00
|
|
|
extern int pg_ultoa_n(uint32 value, char *a);
|
|
|
|
extern int pg_ulltoa_n(uint64 value, char *a);
|
|
|
|
extern int pg_ltoa(int32 value, char *a);
|
|
|
|
extern int pg_lltoa(int64 value, char *a);
|
2020-02-01 22:57:14 +01:00
|
|
|
extern char *pg_ultostr_zeropad(char *str, uint32 value, int32 minwidth);
|
|
|
|
extern char *pg_ultostr(char *str, uint32 value);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* oid.c */
|
2005-03-29 02:17:27 +02:00
|
|
|
extern oidvector *buildoidvector(const Oid *oids, int n);
|
2010-06-13 19:43:13 +02:00
|
|
|
extern Oid oidparse(Node *node);
|
2017-03-01 17:55:28 +01:00
|
|
|
extern int oid_cmp(const void *p1, const void *p2);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/* regexp.c */
|
2012-07-10 20:54:37 +02:00
|
|
|
extern char *regexp_fixed_prefix(text *text_re, bool case_insensitive,
|
|
|
|
Oid collation, bool *exact);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
1999-10-04 01:55:40 +02:00
|
|
|
/* ruleutils.c */
|
2022-04-08 14:16:38 +02:00
|
|
|
extern PGDLLIMPORT bool quote_all_identifiers;
|
2002-04-25 04:56:56 +02:00
|
|
|
extern const char *quote_identifier(const char *ident);
|
2009-07-16 08:33:46 +02:00
|
|
|
extern char *quote_qualified_identifier(const char *qualifier,
|
2002-04-25 04:56:56 +02:00
|
|
|
const char *ident);
|
2018-03-19 23:49:53 +01:00
|
|
|
extern void generate_operator_clause(fmStringInfo buf,
|
|
|
|
const char *leftop, Oid leftoptype,
|
|
|
|
Oid opoid,
|
|
|
|
const char *rightop, Oid rightoptype);
|
2011-02-08 22:04:18 +01:00
|
|
|
|
1996-11-10 04:06:38 +01:00
|
|
|
/* varchar.c */
|
2016-02-03 20:17:35 +01:00
|
|
|
extern int bpchartruelen(char *s, int len);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2017-01-21 02:29:53 +01:00
|
|
|
/* popular functions from varlena.c */
|
2008-03-25 23:42:46 +01:00
|
|
|
extern text *cstring_to_text(const char *s);
|
|
|
|
extern text *cstring_to_text_with_len(const char *s, int len);
|
|
|
|
extern char *text_to_cstring(const text *t);
|
|
|
|
extern void text_to_cstring_buffer(const text *src, char *dst, size_t dst_len);
|
|
|
|
|
|
|
|
#define CStringGetTextDatum(s) PointerGetDatum(cstring_to_text(s))
|
|
|
|
#define TextDatumGetCString(d) text_to_cstring((text *) DatumGetPointer(d))
|
|
|
|
|
2003-05-13 01:08:52 +02:00
|
|
|
/* xid.c */
|
Allow read only connections during recovery, known as Hot Standby.
Enabled by recovery_connections = on (default) and forcing archive recovery using a recovery.conf. Recovery processing now emulates the original transactions as they are replayed, providing full locking and MVCC behaviour for read only queries. Recovery must enter consistent state before connections are allowed, so there is a delay, typically short, before connections succeed. Replay of recovering transactions can conflict and in some cases deadlock with queries during recovery; these result in query cancellation after max_standby_delay seconds have expired. Infrastructure changes have minor effects on normal running, though introduce four new types of WAL record.
New test mode "make standbycheck" allows regression tests of static command behaviour on a standby server while in recovery. Typical and extreme dynamic behaviours have been checked via code inspection and manual testing. Few port specific behaviours have been utilised, though primary testing has been on Linux only so far.
This commit is the basic patch. Additional changes will follow in this release to enhance some aspects of behaviour, notably improved handling of conflicts, deadlock detection and query cancellation. Changes to VACUUM FULL are also required.
Simon Riggs, with significant and lengthy review by Heikki Linnakangas, including streamlined redesign of snapshot creation and two-phase commit.
Important contributions from Florian Pflug, Mark Kirkwood, Merlin Moncure, Greg Stark, Gianni Ciolli, Gabriele Bartolini, Hannu Krosing, Robert Haas, Tatsuo Ishii, Hiroyuki Yamada plus support and feedback from many other community members.
2009-12-19 02:32:45 +01:00
|
|
|
extern int xidComparator(const void *arg1, const void *arg2);
|
Fix ordering of XIDs in ProcArrayApplyRecoveryInfo
Commit 8431e296ea reworked ProcArrayApplyRecoveryInfo to sort XIDs
before adding them to KnownAssignedXids. But the XIDs are sorted using
xidComparator, which compares the XIDs simply as uint32 values, not
logically. KnownAssignedXidsAdd() however expects XIDs in logical order,
and calls TransactionIdFollowsOrEquals() to enforce that. If there are
XIDs for which the two orderings disagree, an error is raised and the
recovery fails/restarts.
Hitting this issue is fairly easy - you just need two transactions, one
started before the 4B limit (e.g. XID 4294967290), the other sometime
after it (e.g. XID 1000). Logically (4294967290 <= 1000) but when
compared using xidComparator we try to add them in the opposite order.
Which makes KnownAssignedXidsAdd() fail with an error like this:
ERROR: out-of-order XID insertion in KnownAssignedXids
This only happens during replica startup, while processing RUNNING_XACTS
records to build the snapshot. Once we reach STANDBY_SNAPSHOT_READY, we
skip these records. So this does not affect already running replicas,
but if you restart (or create) a replica while there are transactions
with XIDs for which the two orderings disagree, you may hit this.
Long-running transactions and frequent replica restarts increase the
likelihood of hitting this issue. Once the replica gets into this state,
it can't be started (even if the old transactions are terminated).
Fixed by sorting the XIDs logically - this is fine because we're dealing
with normal XIDs (because it's XIDs assigned to backends) and from the
same wraparound epoch (otherwise the backends could not be running at
the same time on the primary node). So there are no problems with the
triangle inequality, which is why xidComparator compares raw values.
Investigation and root cause analysis by Abhijit Menon-Sen. Patch by me.
This issue is present in all releases since 9.4, however releases up to
9.6 are EOL already so backpatch to 10 only.
Reviewed-by: Abhijit Menon-Sen
Reviewed-by: Alvaro Herrera
Backpatch-through: 10
Discussion: https://postgr.es/m/36b8a501-5d73-277c-4972-f58a4dce088a%40enterprisedb.com
2022-01-27 17:53:53 +01:00
|
|
|
extern int xidLogicalComparator(const void *arg1, const void *arg2);
|
1997-03-09 21:41:02 +01:00
|
|
|
|
2010-11-24 23:04:19 +01:00
|
|
|
/* inet_cidr_ntop.c */
|
2019-08-19 01:27:23 +02:00
|
|
|
extern char *pg_inet_cidr_ntop(int af, const void *src, int bits,
|
|
|
|
char *dst, size_t size);
|
1998-10-03 07:41:01 +02:00
|
|
|
|
|
|
|
/* inet_net_pton.c */
|
2019-08-19 01:27:23 +02:00
|
|
|
extern int pg_inet_net_pton(int af, const char *src,
|
|
|
|
void *dst, size_t size);
|
1998-10-03 07:41:01 +02:00
|
|
|
|
1998-10-22 22:40:50 +02:00
|
|
|
/* network.c */
|
Fix assorted issues in convert_to_scalar().
If convert_to_scalar is passed a pair of datatypes it can't cope with,
its former behavior was just to elog(ERROR). While this is OK so far as
the core code is concerned, there's extension code that would like to use
scalarltsel/scalargtsel/etc as selectivity estimators for operators that
work on non-core datatypes, and this behavior is a show-stopper for that
use-case. If we simply allow convert_to_scalar to return FALSE instead of
outright failing, then the main logic of scalarltsel/scalargtsel will work
fine for any operator that behaves like a scalar inequality comparison.
The lack of conversion capability will mean that we can't estimate to
better than histogram-bin-width precision, since the code will effectively
assume that the comparison constant falls at the middle of its bin. But
that's still a lot better than nothing. (Someday we should provide a way
for extension code to supply a custom version of convert_to_scalar, but
today is not that day.)
While poking at this issue, we noted that the existing code for handling
type bytea in convert_to_scalar is several bricks shy of a load.
It assumes without checking that if the comparison value is type bytea,
the bounds values are too; in the worst case this could lead to a crash.
It also fails to detoast the input values, so that the comparison result is
complete garbage if any input is toasted out-of-line, compressed, or even
just short-header. I'm not sure how often such cases actually occur ---
the bounds values, at least, are probably safe since they are elements of
an array and hence can't be toasted. But that doesn't make this code OK.
Back-patch to all supported branches, partly because author requested that,
but mostly because of the bytea bugs. The change in API for the exposed
routine convert_network_to_scalar() is theoretically a back-patch hazard,
but it seems pretty unlikely that any third-party code is calling that
function directly.
Tomas Vondra, with some adjustments by me
Discussion: https://postgr.es/m/b68441b6-d18f-13ab-b43b-9a72188a4e02@2ndquadrant.com
2018-03-04 02:31:35 +01:00
|
|
|
extern double convert_network_to_scalar(Datum value, Oid typid, bool *failure);
|
2001-06-17 04:05:20 +02:00
|
|
|
extern Datum network_scan_first(Datum in);
|
|
|
|
extern Datum network_scan_last(Datum in);
|
2007-05-18 01:31:49 +02:00
|
|
|
extern void clean_ipv6_addr(int addr_family, char *addr);
|
1998-10-03 07:41:01 +02:00
|
|
|
|
1998-12-30 20:56:35 +01:00
|
|
|
/* numeric.c */
|
2001-10-14 01:32:34 +02:00
|
|
|
extern Datum numeric_float8_no_overflow(PG_FUNCTION_ARGS);
|
2000-06-13 09:35:40 +02:00
|
|
|
|
2000-07-09 23:30:21 +02:00
|
|
|
/* format_type.c */
|
2018-02-17 23:02:15 +01:00
|
|
|
|
|
|
|
/* Control flags for format_type_extended */
|
|
|
|
#define FORMAT_TYPE_TYPEMOD_GIVEN 0x01 /* typemod defined by caller */
|
|
|
|
#define FORMAT_TYPE_ALLOW_INVALID 0x02 /* allow invalid types */
|
|
|
|
#define FORMAT_TYPE_FORCE_QUALIFY 0x04 /* force qualification of type */
|
2020-07-06 05:12:11 +02:00
|
|
|
#define FORMAT_TYPE_INVALID_AS_NULL 0x08 /* NULL if undefined */
|
2018-02-17 23:02:15 +01:00
|
|
|
extern char *format_type_extended(Oid type_oid, int32 typemod, bits16 flags);
|
|
|
|
|
2001-08-09 20:28:18 +02:00
|
|
|
extern char *format_type_be(Oid type_oid);
|
2013-03-20 22:19:19 +01:00
|
|
|
extern char *format_type_be_qualified(Oid type_oid);
|
2001-10-08 21:55:07 +02:00
|
|
|
extern char *format_type_with_typemod(Oid type_oid, int32 typemod);
|
2018-02-17 23:02:15 +01:00
|
|
|
|
2000-08-25 20:05:54 +02:00
|
|
|
extern int32 type_maximum_size(Oid type_oid, int32 typemod);
|
2000-07-07 21:24:43 +02:00
|
|
|
|
2000-09-05 22:25:14 +02:00
|
|
|
/* quote.c */
|
2011-02-22 22:33:44 +01:00
|
|
|
extern char *quote_literal_cstr(const char *rawstr);
|
2007-10-14 01:06:28 +02:00
|
|
|
|
1996-08-28 03:59:28 +02:00
|
|
|
#endif /* BUILTINS_H */
|