1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* readfuncs.c
|
1997-09-07 07:04:48 +02:00
|
|
|
* Reader functions for Postgres tree nodes.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2015-01-06 17:43:47 +01:00
|
|
|
* Portions Copyright (c) 1996-2015, 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/nodes/readfuncs.c
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* NOTES
|
2002-11-25 19:12:12 +01:00
|
|
|
* Path and Plan nodes do not have any readfuncs support, because we
|
2014-05-06 18:12:18 +02:00
|
|
|
* never have occasion to read them in. (There was once code here that
|
2002-12-13 20:46:01 +01:00
|
|
|
* claimed to read them, but it was broken as well as unused.) We
|
|
|
|
* never read executor state trees, either.
|
1997-09-07 07:04:48 +02:00
|
|
|
*
|
2008-08-29 01:09:48 +02:00
|
|
|
* Parse location fields are written out by outfuncs.c, but only for
|
|
|
|
* possible debugging use. When reading a location field, we discard
|
|
|
|
* the stored value and set the location field to -1 (ie, "unknown").
|
|
|
|
* This is because nodes coming from a stored rule should not be thought
|
|
|
|
* to have a known location in the current query's text.
|
|
|
|
*
|
1996-07-09 08:22:35 +02:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
|
2001-01-07 02:08:48 +01:00
|
|
|
#include <math.h>
|
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
#include "nodes/parsenodes.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "nodes/readfuncs.h"
|
2002-11-25 19:12:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Macros to simplify reading of different kinds of fields. Use these
|
2014-05-06 18:12:18 +02:00
|
|
|
* wherever possible to reduce the chance for silly typos. Note that these
|
2002-11-25 19:12:12 +01:00
|
|
|
* hard-wire conventions about the names of the local variables in a Read
|
|
|
|
* routine.
|
|
|
|
*/
|
|
|
|
|
2004-05-26 06:41:50 +02:00
|
|
|
/* Macros for declaring appropriate local variables */
|
2002-11-25 19:12:12 +01:00
|
|
|
|
|
|
|
/* A few guys need only local_node */
|
|
|
|
#define READ_LOCALS_NO_FIELDS(nodeTypeName) \
|
|
|
|
nodeTypeName *local_node = makeNode(nodeTypeName)
|
|
|
|
|
|
|
|
/* And a few guys need only the pg_strtok support fields */
|
2004-05-26 06:41:50 +02:00
|
|
|
#define READ_TEMP_LOCALS() \
|
|
|
|
char *token; \
|
2012-07-01 04:27:49 +02:00
|
|
|
int length
|
2002-11-25 19:12:12 +01:00
|
|
|
|
2004-05-26 06:41:50 +02:00
|
|
|
/* ... but most need both */
|
|
|
|
#define READ_LOCALS(nodeTypeName) \
|
|
|
|
READ_LOCALS_NO_FIELDS(nodeTypeName); \
|
|
|
|
READ_TEMP_LOCALS()
|
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/* Read an integer field (anything written as ":fldname %d") */
|
|
|
|
#define READ_INT_FIELD(fldname) \
|
|
|
|
token = pg_strtok(&length); /* skip :fldname */ \
|
|
|
|
token = pg_strtok(&length); /* get field value */ \
|
|
|
|
local_node->fldname = atoi(token)
|
|
|
|
|
|
|
|
/* Read an unsigned integer field (anything written as ":fldname %u") */
|
|
|
|
#define READ_UINT_FIELD(fldname) \
|
|
|
|
token = pg_strtok(&length); /* skip :fldname */ \
|
|
|
|
token = pg_strtok(&length); /* get field value */ \
|
|
|
|
local_node->fldname = atoui(token)
|
|
|
|
|
|
|
|
/* Read an OID field (don't hard-wire assumption that OID is same as uint) */
|
|
|
|
#define READ_OID_FIELD(fldname) \
|
|
|
|
token = pg_strtok(&length); /* skip :fldname */ \
|
|
|
|
token = pg_strtok(&length); /* get field value */ \
|
|
|
|
local_node->fldname = atooid(token)
|
|
|
|
|
|
|
|
/* Read a char field (ie, one ascii character) */
|
|
|
|
#define READ_CHAR_FIELD(fldname) \
|
|
|
|
token = pg_strtok(&length); /* skip :fldname */ \
|
|
|
|
token = pg_strtok(&length); /* get field value */ \
|
|
|
|
local_node->fldname = token[0]
|
|
|
|
|
|
|
|
/* Read an enumerated-type field that was written as an integer code */
|
|
|
|
#define READ_ENUM_FIELD(fldname, enumtype) \
|
|
|
|
token = pg_strtok(&length); /* skip :fldname */ \
|
|
|
|
token = pg_strtok(&length); /* get field value */ \
|
|
|
|
local_node->fldname = (enumtype) atoi(token)
|
|
|
|
|
|
|
|
/* Read a float field */
|
|
|
|
#define READ_FLOAT_FIELD(fldname) \
|
|
|
|
token = pg_strtok(&length); /* skip :fldname */ \
|
|
|
|
token = pg_strtok(&length); /* get field value */ \
|
|
|
|
local_node->fldname = atof(token)
|
|
|
|
|
|
|
|
/* Read a boolean field */
|
|
|
|
#define READ_BOOL_FIELD(fldname) \
|
|
|
|
token = pg_strtok(&length); /* skip :fldname */ \
|
|
|
|
token = pg_strtok(&length); /* get field value */ \
|
|
|
|
local_node->fldname = strtobool(token)
|
|
|
|
|
|
|
|
/* Read a character-string field */
|
|
|
|
#define READ_STRING_FIELD(fldname) \
|
|
|
|
token = pg_strtok(&length); /* skip :fldname */ \
|
|
|
|
token = pg_strtok(&length); /* get field value */ \
|
|
|
|
local_node->fldname = nullable_string(token, length)
|
|
|
|
|
2008-08-29 01:09:48 +02:00
|
|
|
/* Read a parse location field (and throw away the value, per notes above) */
|
|
|
|
#define READ_LOCATION_FIELD(fldname) \
|
|
|
|
token = pg_strtok(&length); /* skip :fldname */ \
|
|
|
|
token = pg_strtok(&length); /* get field value */ \
|
2014-01-16 10:55:08 +01:00
|
|
|
(void) token; /* in case not used elsewhere */ \
|
2009-06-11 16:49:15 +02:00
|
|
|
local_node->fldname = -1 /* set field to "unknown" */
|
2008-08-29 01:09:48 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/* Read a Node field */
|
|
|
|
#define READ_NODE_FIELD(fldname) \
|
|
|
|
token = pg_strtok(&length); /* skip :fldname */ \
|
2012-07-01 04:27:49 +02:00
|
|
|
(void) token; /* in case not used elsewhere */ \
|
2004-05-06 16:01:33 +02:00
|
|
|
local_node->fldname = nodeRead(NULL, 0)
|
2002-11-25 19:12:12 +01:00
|
|
|
|
2009-01-22 21:16:10 +01:00
|
|
|
/* Read a bitmapset field */
|
|
|
|
#define READ_BITMAPSET_FIELD(fldname) \
|
|
|
|
token = pg_strtok(&length); /* skip :fldname */ \
|
2014-01-16 10:55:08 +01:00
|
|
|
(void) token; /* in case not used elsewhere */ \
|
2009-01-22 21:16:10 +01:00
|
|
|
local_node->fldname = _readBitmapset()
|
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/* Routine exit */
|
|
|
|
#define READ_DONE() \
|
|
|
|
return local_node
|
2001-01-07 02:08:48 +01:00
|
|
|
|
|
|
|
|
2001-01-08 01:31:43 +01:00
|
|
|
/*
|
|
|
|
* NOTE: use atoi() to read values written with %d, or atoui() to read
|
|
|
|
* values written with %u in outfuncs.c. An exception is OID values,
|
2014-05-06 18:12:18 +02:00
|
|
|
* for which use atooid(). (As of 7.1, outfuncs.c writes OIDs as %u,
|
2001-01-08 01:31:43 +01:00
|
|
|
* but this will probably change in the future.)
|
|
|
|
*/
|
|
|
|
#define atoui(x) ((unsigned int) strtoul((x), NULL, 10))
|
|
|
|
|
|
|
|
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
|
|
|
|
|
|
|
|
#define strtobool(x) ((*(x) == 't') ? true : false)
|
|
|
|
|
|
|
|
#define nullable_string(token,length) \
|
2004-01-07 19:56:30 +01:00
|
|
|
((length) == 0 ? NULL : debackslash(token, length))
|
2001-01-08 01:31:43 +01:00
|
|
|
|
|
|
|
|
2001-01-07 02:08:48 +01:00
|
|
|
static Datum readDatum(bool typbyval);
|
|
|
|
|
2009-01-22 21:16:10 +01:00
|
|
|
/*
|
|
|
|
* _readBitmapset
|
|
|
|
*/
|
|
|
|
static Bitmapset *
|
|
|
|
_readBitmapset(void)
|
|
|
|
{
|
2009-06-11 16:49:15 +02:00
|
|
|
Bitmapset *result = NULL;
|
|
|
|
|
2009-01-22 21:16:10 +01:00
|
|
|
READ_TEMP_LOCALS();
|
|
|
|
|
|
|
|
token = pg_strtok(&length);
|
|
|
|
if (token == NULL)
|
|
|
|
elog(ERROR, "incomplete Bitmapset structure");
|
|
|
|
if (length != 1 || token[0] != '(')
|
|
|
|
elog(ERROR, "unrecognized token: \"%.*s\"", length, token);
|
|
|
|
|
|
|
|
token = pg_strtok(&length);
|
|
|
|
if (token == NULL)
|
|
|
|
elog(ERROR, "incomplete Bitmapset structure");
|
|
|
|
if (length != 1 || token[0] != 'b')
|
|
|
|
elog(ERROR, "unrecognized token: \"%.*s\"", length, token);
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
2009-06-11 16:49:15 +02:00
|
|
|
int val;
|
|
|
|
char *endptr;
|
2009-01-22 21:16:10 +01:00
|
|
|
|
|
|
|
token = pg_strtok(&length);
|
|
|
|
if (token == NULL)
|
|
|
|
elog(ERROR, "unterminated Bitmapset structure");
|
|
|
|
if (length == 1 && token[0] == ')')
|
|
|
|
break;
|
|
|
|
val = (int) strtol(token, &endptr, 10);
|
|
|
|
if (endptr != token + length)
|
|
|
|
elog(ERROR, "unrecognized integer: \"%.*s\"", length, token);
|
|
|
|
result = bms_add_member(result, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/*
|
|
|
|
* _readQuery
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
static Query *
|
2000-10-23 00:15:13 +02:00
|
|
|
_readQuery(void)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_LOCALS(Query);
|
|
|
|
|
|
|
|
READ_ENUM_FIELD(commandType, CmdType);
|
|
|
|
READ_ENUM_FIELD(querySource, QuerySource);
|
2012-06-10 21:20:04 +02:00
|
|
|
local_node->queryId = 0; /* not saved in output format */
|
2003-05-02 22:54:36 +02:00
|
|
|
READ_BOOL_FIELD(canSetTag);
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_NODE_FIELD(utilityStmt);
|
|
|
|
READ_INT_FIELD(resultRelation);
|
|
|
|
READ_BOOL_FIELD(hasAggs);
|
2008-12-28 19:54:01 +01:00
|
|
|
READ_BOOL_FIELD(hasWindowFuncs);
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_BOOL_FIELD(hasSubLinks);
|
2008-08-02 23:32:01 +02:00
|
|
|
READ_BOOL_FIELD(hasDistinctOn);
|
2008-10-04 23:56:55 +02:00
|
|
|
READ_BOOL_FIELD(hasRecursive);
|
2011-02-26 00:56:23 +01:00
|
|
|
READ_BOOL_FIELD(hasModifyingCTE);
|
2009-10-28 15:55:47 +01:00
|
|
|
READ_BOOL_FIELD(hasForUpdate);
|
Row-Level Security Policies (RLS)
Building on the updatable security-barrier views work, add the
ability to define policies on tables to limit the set of rows
which are returned from a query and which are allowed to be added
to a table. Expressions defined by the policy for filtering are
added to the security barrier quals of the query, while expressions
defined to check records being added to a table are added to the
with-check options of the query.
New top-level commands are CREATE/ALTER/DROP POLICY and are
controlled by the table owner. Row Security is able to be enabled
and disabled by the owner on a per-table basis using
ALTER TABLE .. ENABLE/DISABLE ROW SECURITY.
Per discussion, ROW SECURITY is disabled on tables by default and
must be enabled for policies on the table to be used. If no
policies exist on a table with ROW SECURITY enabled, a default-deny
policy is used and no records will be visible.
By default, row security is applied at all times except for the
table owner and the superuser. A new GUC, row_security, is added
which can be set to ON, OFF, or FORCE. When set to FORCE, row
security will be applied even for the table owner and superusers.
When set to OFF, row security will be disabled when allowed and an
error will be thrown if the user does not have rights to bypass row
security.
Per discussion, pg_dump sets row_security = OFF by default to ensure
that exports and backups will have all data in the table or will
error if there are insufficient privileges to bypass row security.
A new option has been added to pg_dump, --enable-row-security, to
ask pg_dump to export with row security enabled.
A new role capability, BYPASSRLS, which can only be set by the
superuser, is added to allow other users to be able to bypass row
security using row_security = OFF.
Many thanks to the various individuals who have helped with the
design, particularly Robert Haas for his feedback.
Authors include Craig Ringer, KaiGai Kohei, Adam Brightwell, Dean
Rasheed, with additional changes and rework by me.
Reviewers have included all of the above, Greg Smith,
Jeff McCormick, and Robert Haas.
2014-09-19 17:18:35 +02:00
|
|
|
READ_BOOL_FIELD(hasRowSecurity);
|
2008-10-04 23:56:55 +02:00
|
|
|
READ_NODE_FIELD(cteList);
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_NODE_FIELD(rtable);
|
|
|
|
READ_NODE_FIELD(jointree);
|
|
|
|
READ_NODE_FIELD(targetList);
|
2013-07-18 23:10:16 +02:00
|
|
|
READ_NODE_FIELD(withCheckOptions);
|
Add support for INSERT ... ON CONFLICT DO NOTHING/UPDATE.
The newly added ON CONFLICT clause allows to specify an alternative to
raising a unique or exclusion constraint violation error when inserting.
ON CONFLICT refers to constraints that can either be specified using a
inference clause (by specifying the columns of a unique constraint) or
by naming a unique or exclusion constraint. DO NOTHING avoids the
constraint violation, without touching the pre-existing row. DO UPDATE
SET ... [WHERE ...] updates the pre-existing tuple, and has access to
both the tuple proposed for insertion and the existing tuple; the
optional WHERE clause can be used to prevent an update from being
executed. The UPDATE SET and WHERE clauses have access to the tuple
proposed for insertion using the "magic" EXCLUDED alias, and to the
pre-existing tuple using the table name or its alias.
This feature is often referred to as upsert.
This is implemented using a new infrastructure called "speculative
insertion". It is an optimistic variant of regular insertion that first
does a pre-check for existing tuples and then attempts an insert. If a
violating tuple was inserted concurrently, the speculatively inserted
tuple is deleted and a new attempt is made. If the pre-check finds a
matching tuple the alternative DO NOTHING or DO UPDATE action is taken.
If the insertion succeeds without detecting a conflict, the tuple is
deemed inserted.
To handle the possible ambiguity between the excluded alias and a table
named excluded, and for convenience with long relation names, INSERT
INTO now can alias its target table.
Bumps catversion as stored rules change.
Author: Peter Geoghegan, with significant contributions from Heikki
Linnakangas and Andres Freund. Testing infrastructure by Jeff Janes.
Reviewed-By: Heikki Linnakangas, Andres Freund, Robert Haas, Simon Riggs,
Dean Rasheed, Stephen Frost and many others.
2015-05-08 05:31:36 +02:00
|
|
|
READ_NODE_FIELD(onConflict);
|
2006-08-12 04:52:06 +02:00
|
|
|
READ_NODE_FIELD(returningList);
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_NODE_FIELD(groupClause);
|
|
|
|
READ_NODE_FIELD(havingQual);
|
2008-12-28 19:54:01 +01:00
|
|
|
READ_NODE_FIELD(windowClause);
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_NODE_FIELD(distinctClause);
|
|
|
|
READ_NODE_FIELD(sortClause);
|
|
|
|
READ_NODE_FIELD(limitOffset);
|
|
|
|
READ_NODE_FIELD(limitCount);
|
2006-04-30 20:30:40 +02:00
|
|
|
READ_NODE_FIELD(rowMarks);
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_NODE_FIELD(setOperations);
|
2010-08-07 04:44:09 +02:00
|
|
|
READ_NODE_FIELD(constraintDeps);
|
2000-11-12 01:37:02 +01:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_DONE();
|
1998-01-06 19:53:02 +01:00
|
|
|
}
|
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/*
|
|
|
|
* _readNotifyStmt
|
2002-03-21 17:02:16 +01:00
|
|
|
*/
|
|
|
|
static NotifyStmt *
|
|
|
|
_readNotifyStmt(void)
|
|
|
|
{
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_LOCALS(NotifyStmt);
|
2002-03-21 17:02:16 +01:00
|
|
|
|
2008-09-01 22:42:46 +02:00
|
|
|
READ_STRING_FIELD(conditionname);
|
2010-02-16 23:34:57 +01:00
|
|
|
READ_STRING_FIELD(payload);
|
2002-03-21 17:02:16 +01:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_DONE();
|
2002-03-21 17:02:16 +01:00
|
|
|
}
|
|
|
|
|
2003-03-10 04:53:52 +01:00
|
|
|
/*
|
|
|
|
* _readDeclareCursorStmt
|
|
|
|
*/
|
|
|
|
static DeclareCursorStmt *
|
|
|
|
_readDeclareCursorStmt(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(DeclareCursorStmt);
|
|
|
|
|
|
|
|
READ_STRING_FIELD(portalname);
|
|
|
|
READ_INT_FIELD(options);
|
|
|
|
READ_NODE_FIELD(query);
|
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
2013-07-18 23:10:16 +02:00
|
|
|
/*
|
|
|
|
* _readWithCheckOption
|
|
|
|
*/
|
|
|
|
static WithCheckOption *
|
|
|
|
_readWithCheckOption(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(WithCheckOption);
|
|
|
|
|
2015-04-25 02:34:26 +02:00
|
|
|
READ_ENUM_FIELD(kind, WCOKind);
|
|
|
|
READ_STRING_FIELD(relname);
|
2013-07-18 23:10:16 +02:00
|
|
|
READ_NODE_FIELD(qual);
|
|
|
|
READ_BOOL_FIELD(cascaded);
|
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/*
|
2008-08-02 23:32:01 +02:00
|
|
|
* _readSortGroupClause
|
1998-01-06 19:53:02 +01:00
|
|
|
*/
|
2008-08-02 23:32:01 +02:00
|
|
|
static SortGroupClause *
|
|
|
|
_readSortGroupClause(void)
|
1998-01-06 19:53:02 +01:00
|
|
|
{
|
2008-08-02 23:32:01 +02:00
|
|
|
READ_LOCALS(SortGroupClause);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_UINT_FIELD(tleSortGroupRef);
|
2008-08-02 23:32:01 +02:00
|
|
|
READ_OID_FIELD(eqop);
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_OID_FIELD(sortop);
|
2007-01-09 03:14:16 +01:00
|
|
|
READ_BOOL_FIELD(nulls_first);
|
2010-10-31 02:55:20 +01:00
|
|
|
READ_BOOL_FIELD(hashable);
|
1999-05-12 17:02:39 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_DONE();
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2008-12-28 19:54:01 +01:00
|
|
|
/*
|
|
|
|
* _readWindowClause
|
|
|
|
*/
|
|
|
|
static WindowClause *
|
|
|
|
_readWindowClause(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(WindowClause);
|
|
|
|
|
|
|
|
READ_STRING_FIELD(name);
|
|
|
|
READ_STRING_FIELD(refname);
|
|
|
|
READ_NODE_FIELD(partitionClause);
|
|
|
|
READ_NODE_FIELD(orderClause);
|
2008-12-31 01:08:39 +01:00
|
|
|
READ_INT_FIELD(frameOptions);
|
2010-02-12 18:33:21 +01:00
|
|
|
READ_NODE_FIELD(startOffset);
|
|
|
|
READ_NODE_FIELD(endOffset);
|
2008-12-28 19:54:01 +01:00
|
|
|
READ_UINT_FIELD(winref);
|
|
|
|
READ_BOOL_FIELD(copiedOrder);
|
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
2006-04-30 20:30:40 +02:00
|
|
|
/*
|
|
|
|
* _readRowMarkClause
|
|
|
|
*/
|
|
|
|
static RowMarkClause *
|
|
|
|
_readRowMarkClause(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(RowMarkClause);
|
|
|
|
|
|
|
|
READ_UINT_FIELD(rti);
|
Improve concurrency of foreign key locking
This patch introduces two additional lock modes for tuples: "SELECT FOR
KEY SHARE" and "SELECT FOR NO KEY UPDATE". These don't block each
other, in contrast with already existing "SELECT FOR SHARE" and "SELECT
FOR UPDATE". UPDATE commands that do not modify the values stored in
the columns that are part of the key of the tuple now grab a SELECT FOR
NO KEY UPDATE lock on the tuple, allowing them to proceed concurrently
with tuple locks of the FOR KEY SHARE variety.
Foreign key triggers now use FOR KEY SHARE instead of FOR SHARE; this
means the concurrency improvement applies to them, which is the whole
point of this patch.
The added tuple lock semantics require some rejiggering of the multixact
module, so that the locking level that each transaction is holding can
be stored alongside its Xid. Also, multixacts now need to persist
across server restarts and crashes, because they can now represent not
only tuple locks, but also tuple updates. This means we need more
careful tracking of lifetime of pg_multixact SLRU files; since they now
persist longer, we require more infrastructure to figure out when they
can be removed. pg_upgrade also needs to be careful to copy
pg_multixact files over from the old server to the new, or at least part
of multixact.c state, depending on the versions of the old and new
servers.
Tuple time qualification rules (HeapTupleSatisfies routines) need to be
careful not to consider tuples with the "is multi" infomask bit set as
being only locked; they might need to look up MultiXact values (i.e.
possibly do pg_multixact I/O) to find out the Xid that updated a tuple,
whereas they previously were assured to only use information readily
available from the tuple header. This is considered acceptable, because
the extra I/O would involve cases that would previously cause some
commands to block waiting for concurrent transactions to finish.
Another important change is the fact that locking tuples that have
previously been updated causes the future versions to be marked as
locked, too; this is essential for correctness of foreign key checks.
This causes additional WAL-logging, also (there was previously a single
WAL record for a locked tuple; now there are as many as updated copies
of the tuple there exist.)
With all this in place, contention related to tuples being checked by
foreign key rules should be much reduced.
As a bonus, the old behavior that a subtransaction grabbing a stronger
tuple lock than the parent (sub)transaction held on a given tuple and
later aborting caused the weaker lock to be lost, has been fixed.
Many new spec files were added for isolation tester framework, to ensure
overall behavior is sane. There's probably room for several more tests.
There were several reviewers of this patch; in particular, Noah Misch
and Andres Freund spent considerable time in it. Original idea for the
patch came from Simon Riggs, after a problem report by Joel Jacobson.
Most code is from me, with contributions from Marti Raudsepp, Alexander
Shulgin, Noah Misch and Andres Freund.
This patch was discussed in several pgsql-hackers threads; the most
important start at the following message-ids:
AANLkTimo9XVcEzfiBR-ut3KVNDkjm2Vxh+t8kAmWjPuv@mail.gmail.com
1290721684-sup-3951@alvh.no-ip.org
1294953201-sup-2099@alvh.no-ip.org
1320343602-sup-2290@alvh.no-ip.org
1339690386-sup-8927@alvh.no-ip.org
4FE5FF020200002500048A3D@gw.wicourts.gov
4FEAB90A0200002500048B7D@gw.wicourts.gov
2013-01-23 16:04:59 +01:00
|
|
|
READ_ENUM_FIELD(strength, LockClauseStrength);
|
2014-10-07 22:23:34 +02:00
|
|
|
READ_ENUM_FIELD(waitPolicy, LockWaitPolicy);
|
2009-10-28 15:55:47 +01:00
|
|
|
READ_BOOL_FIELD(pushedDown);
|
2006-04-30 20:30:40 +02:00
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
2008-10-04 23:56:55 +02:00
|
|
|
/*
|
|
|
|
* _readCommonTableExpr
|
|
|
|
*/
|
|
|
|
static CommonTableExpr *
|
|
|
|
_readCommonTableExpr(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(CommonTableExpr);
|
|
|
|
|
|
|
|
READ_STRING_FIELD(ctename);
|
|
|
|
READ_NODE_FIELD(aliascolnames);
|
|
|
|
READ_NODE_FIELD(ctequery);
|
|
|
|
READ_LOCATION_FIELD(location);
|
|
|
|
READ_BOOL_FIELD(cterecursive);
|
|
|
|
READ_INT_FIELD(cterefcount);
|
|
|
|
READ_NODE_FIELD(ctecolnames);
|
|
|
|
READ_NODE_FIELD(ctecoltypes);
|
|
|
|
READ_NODE_FIELD(ctecoltypmods);
|
2011-02-08 22:04:18 +01:00
|
|
|
READ_NODE_FIELD(ctecolcollations);
|
2008-10-04 23:56:55 +02:00
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/*
|
|
|
|
* _readSetOperationStmt
|
2000-10-05 21:11:39 +02:00
|
|
|
*/
|
|
|
|
static SetOperationStmt *
|
2000-10-23 00:15:13 +02:00
|
|
|
_readSetOperationStmt(void)
|
2000-10-05 21:11:39 +02:00
|
|
|
{
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_LOCALS(SetOperationStmt);
|
2000-10-05 21:11:39 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_ENUM_FIELD(op, SetOperation);
|
|
|
|
READ_BOOL_FIELD(all);
|
|
|
|
READ_NODE_FIELD(larg);
|
|
|
|
READ_NODE_FIELD(rarg);
|
2004-05-26 06:41:50 +02:00
|
|
|
READ_NODE_FIELD(colTypes);
|
2006-08-10 04:36:29 +02:00
|
|
|
READ_NODE_FIELD(colTypmods);
|
2011-02-08 22:04:18 +01:00
|
|
|
READ_NODE_FIELD(colCollations);
|
2008-08-07 03:11:52 +02:00
|
|
|
READ_NODE_FIELD(groupClauses);
|
2000-10-05 21:11:39 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_DONE();
|
|
|
|
}
|
2000-10-05 21:11:39 +02:00
|
|
|
|
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/*
|
|
|
|
* Stuff from primnodes.h.
|
|
|
|
*/
|
2000-10-05 21:11:39 +02:00
|
|
|
|
2002-12-12 16:49:42 +01:00
|
|
|
static Alias *
|
|
|
|
_readAlias(void)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2002-12-12 16:49:42 +01:00
|
|
|
READ_LOCALS(Alias);
|
2000-02-15 21:49:31 +01:00
|
|
|
|
2002-12-12 16:49:42 +01:00
|
|
|
READ_STRING_FIELD(aliasname);
|
|
|
|
READ_NODE_FIELD(colnames);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-12-12 16:49:42 +01:00
|
|
|
READ_DONE();
|
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-12-12 16:49:42 +01:00
|
|
|
static RangeVar *
|
|
|
|
_readRangeVar(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(RangeVar);
|
|
|
|
|
|
|
|
local_node->catalogname = NULL; /* not currently saved in output
|
|
|
|
* format */
|
|
|
|
|
|
|
|
READ_STRING_FIELD(schemaname);
|
|
|
|
READ_STRING_FIELD(relname);
|
|
|
|
READ_ENUM_FIELD(inhOpt, InhOption);
|
2010-12-13 18:34:26 +01:00
|
|
|
READ_CHAR_FIELD(relpersistence);
|
2002-12-12 16:49:42 +01:00
|
|
|
READ_NODE_FIELD(alias);
|
2008-09-01 22:42:46 +02:00
|
|
|
READ_LOCATION_FIELD(location);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_DONE();
|
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2007-02-20 18:32:18 +01:00
|
|
|
static IntoClause *
|
|
|
|
_readIntoClause(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(IntoClause);
|
|
|
|
|
|
|
|
READ_NODE_FIELD(rel);
|
|
|
|
READ_NODE_FIELD(colNames);
|
|
|
|
READ_NODE_FIELD(options);
|
|
|
|
READ_ENUM_FIELD(onCommit, OnCommitAction);
|
|
|
|
READ_STRING_FIELD(tableSpaceName);
|
Clean up the mess around EXPLAIN and materialized views.
Revert the matview-related changes in explain.c's API, as per recent
complaint from Robert Haas. The reason for these appears to have been
principally some ill-considered choices around having intorel_startup do
what ought to be parse-time checking, plus a poor arrangement for passing
it the view parsetree it needs to store into pg_rewrite when creating a
materialized view. Do the latter by having parse analysis stick a copy
into the IntoClause, instead of doing it at runtime. (On the whole,
I seriously question the choice to represent CREATE MATERIALIZED VIEW as a
variant of SELECT INTO/CREATE TABLE AS, because that means injecting even
more complexity into what was already a horrid legacy kluge. However,
I didn't go so far as to rethink that choice ... yet.)
I also moved several error checks into matview parse analysis, and
made the check for external Params in a matview more accurate.
In passing, clean things up a bit more around interpretOidsOption(),
and fix things so that we can use that to force no-oids for views,
sequences, etc, thereby eliminating the need to cons up "oids = false"
options when creating them.
catversion bump due to change in IntoClause. (I wonder though if we
really need readfuncs/outfuncs support for IntoClause anymore.)
2013-04-13 01:25:20 +02:00
|
|
|
READ_NODE_FIELD(viewQuery);
|
2011-11-25 05:21:06 +01:00
|
|
|
READ_BOOL_FIELD(skipData);
|
2007-02-20 18:32:18 +01:00
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/*
|
|
|
|
* _readVar
|
|
|
|
*/
|
|
|
|
static Var *
|
|
|
|
_readVar(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(Var);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_UINT_FIELD(varno);
|
|
|
|
READ_INT_FIELD(varattno);
|
|
|
|
READ_OID_FIELD(vartype);
|
|
|
|
READ_INT_FIELD(vartypmod);
|
2011-02-08 22:04:18 +01:00
|
|
|
READ_OID_FIELD(varcollid);
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_UINT_FIELD(varlevelsup);
|
|
|
|
READ_UINT_FIELD(varnoold);
|
|
|
|
READ_INT_FIELD(varoattno);
|
2008-08-29 01:09:48 +02:00
|
|
|
READ_LOCATION_FIELD(location);
|
2000-11-12 01:37:02 +01:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_DONE();
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/*
|
|
|
|
* _readConst
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
2002-11-25 19:12:12 +01:00
|
|
|
static Const *
|
|
|
|
_readConst(void)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_LOCALS(Const);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_OID_FIELD(consttype);
|
2007-03-17 01:11:05 +01:00
|
|
|
READ_INT_FIELD(consttypmod);
|
2011-02-08 22:04:18 +01:00
|
|
|
READ_OID_FIELD(constcollid);
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_INT_FIELD(constlen);
|
|
|
|
READ_BOOL_FIELD(constbyval);
|
|
|
|
READ_BOOL_FIELD(constisnull);
|
2008-08-29 01:09:48 +02:00
|
|
|
READ_LOCATION_FIELD(location);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
token = pg_strtok(&length); /* skip :constvalue */
|
|
|
|
if (local_node->constisnull)
|
|
|
|
token = pg_strtok(&length); /* skip "<>" */
|
|
|
|
else
|
|
|
|
local_node->constvalue = readDatum(local_node->constbyval);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_DONE();
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/*
|
2002-12-12 16:49:42 +01:00
|
|
|
* _readParam
|
|
|
|
*/
|
|
|
|
static Param *
|
|
|
|
_readParam(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(Param);
|
|
|
|
|
2006-04-22 03:26:01 +02:00
|
|
|
READ_ENUM_FIELD(paramkind, ParamKind);
|
2002-12-12 16:49:42 +01:00
|
|
|
READ_INT_FIELD(paramid);
|
|
|
|
READ_OID_FIELD(paramtype);
|
2006-12-10 23:13:27 +01:00
|
|
|
READ_INT_FIELD(paramtypmod);
|
2011-03-20 01:29:08 +01:00
|
|
|
READ_OID_FIELD(paramcollid);
|
2008-08-29 01:09:48 +02:00
|
|
|
READ_LOCATION_FIELD(location);
|
2002-12-12 16:49:42 +01:00
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* _readAggref
|
|
|
|
*/
|
|
|
|
static Aggref *
|
|
|
|
_readAggref(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(Aggref);
|
|
|
|
|
|
|
|
READ_OID_FIELD(aggfnoid);
|
|
|
|
READ_OID_FIELD(aggtype);
|
2011-03-20 01:29:08 +01:00
|
|
|
READ_OID_FIELD(aggcollid);
|
|
|
|
READ_OID_FIELD(inputcollid);
|
Support ordered-set (WITHIN GROUP) aggregates.
This patch introduces generic support for ordered-set and hypothetical-set
aggregate functions, as well as implementations of the instances defined in
SQL:2008 (percentile_cont(), percentile_disc(), rank(), dense_rank(),
percent_rank(), cume_dist()). We also added mode() though it is not in the
spec, as well as versions of percentile_cont() and percentile_disc() that
can compute multiple percentile values in one pass over the data.
Unlike the original submission, this patch puts full control of the sorting
process in the hands of the aggregate's support functions. To allow the
support functions to find out how they're supposed to sort, a new API
function AggGetAggref() is added to nodeAgg.c. This allows retrieval of
the aggregate call's Aggref node, which may have other uses beyond the
immediate need. There is also support for ordered-set aggregates to
install cleanup callback functions, so that they can be sure that
infrastructure such as tuplesort objects gets cleaned up.
In passing, make some fixes in the recently-added support for variadic
aggregates, and make some editorial adjustments in the recent FILTER
additions for aggregates. Also, simplify use of IsBinaryCoercible() by
allowing it to succeed whenever the target type is ANY or ANYELEMENT.
It was inconsistent that it dealt with other polymorphic target types
but not these.
Atri Sharma and Andrew Gierth; reviewed by Pavel Stehule and Vik Fearing,
and rather heavily editorialized upon by Tom Lane
2013-12-23 22:11:35 +01:00
|
|
|
READ_NODE_FIELD(aggdirectargs);
|
2006-07-27 21:52:07 +02:00
|
|
|
READ_NODE_FIELD(args);
|
2009-12-15 18:57:48 +01:00
|
|
|
READ_NODE_FIELD(aggorder);
|
|
|
|
READ_NODE_FIELD(aggdistinct);
|
2013-07-17 02:15:36 +02:00
|
|
|
READ_NODE_FIELD(aggfilter);
|
2002-12-12 16:49:42 +01:00
|
|
|
READ_BOOL_FIELD(aggstar);
|
Allow aggregate functions to be VARIADIC.
There's no inherent reason why an aggregate function can't be variadic
(even VARIADIC ANY) if its transition function can handle the case.
Indeed, this patch to add the feature touches none of the planner or
executor, and little of the parser; the main missing stuff was DDL and
pg_dump support.
It is true that variadic aggregates can create the same sort of ambiguity
about parameters versus ORDER BY keys that was complained of when we
(briefly) had both one- and two-argument forms of string_agg(). However,
the policy formed in response to that discussion only said that we'd not
create any built-in aggregates with varying numbers of arguments, not that
we shouldn't allow users to do it. So the logical extension of that is
we can allow users to make variadic aggregates as long as we're wary about
shipping any such in core.
In passing, this patch allows aggregate function arguments to be named, to
the extent of remembering the names in pg_proc and dumping them in pg_dump.
You can't yet call an aggregate using named-parameter notation. That seems
like a likely future extension, but it'll take some work, and it's not what
this patch is really about. Likewise, there's still some work needed to
make window functions handle VARIADIC fully, but I left that for another
day.
initdb forced because of new aggvariadic field in Aggref parse nodes.
2013-09-03 23:08:38 +02:00
|
|
|
READ_BOOL_FIELD(aggvariadic);
|
Support ordered-set (WITHIN GROUP) aggregates.
This patch introduces generic support for ordered-set and hypothetical-set
aggregate functions, as well as implementations of the instances defined in
SQL:2008 (percentile_cont(), percentile_disc(), rank(), dense_rank(),
percent_rank(), cume_dist()). We also added mode() though it is not in the
spec, as well as versions of percentile_cont() and percentile_disc() that
can compute multiple percentile values in one pass over the data.
Unlike the original submission, this patch puts full control of the sorting
process in the hands of the aggregate's support functions. To allow the
support functions to find out how they're supposed to sort, a new API
function AggGetAggref() is added to nodeAgg.c. This allows retrieval of
the aggregate call's Aggref node, which may have other uses beyond the
immediate need. There is also support for ordered-set aggregates to
install cleanup callback functions, so that they can be sure that
infrastructure such as tuplesort objects gets cleaned up.
In passing, make some fixes in the recently-added support for variadic
aggregates, and make some editorial adjustments in the recent FILTER
additions for aggregates. Also, simplify use of IsBinaryCoercible() by
allowing it to succeed whenever the target type is ANY or ANYELEMENT.
It was inconsistent that it dealt with other polymorphic target types
but not these.
Atri Sharma and Andrew Gierth; reviewed by Pavel Stehule and Vik Fearing,
and rather heavily editorialized upon by Tom Lane
2013-12-23 22:11:35 +01:00
|
|
|
READ_CHAR_FIELD(aggkind);
|
2009-12-15 18:57:48 +01:00
|
|
|
READ_UINT_FIELD(agglevelsup);
|
2008-08-29 01:09:48 +02:00
|
|
|
READ_LOCATION_FIELD(location);
|
2002-12-12 16:49:42 +01:00
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
2008-12-28 19:54:01 +01:00
|
|
|
/*
|
|
|
|
* _readWindowFunc
|
|
|
|
*/
|
|
|
|
static WindowFunc *
|
|
|
|
_readWindowFunc(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(WindowFunc);
|
|
|
|
|
|
|
|
READ_OID_FIELD(winfnoid);
|
|
|
|
READ_OID_FIELD(wintype);
|
2011-03-20 01:29:08 +01:00
|
|
|
READ_OID_FIELD(wincollid);
|
|
|
|
READ_OID_FIELD(inputcollid);
|
2008-12-28 19:54:01 +01:00
|
|
|
READ_NODE_FIELD(args);
|
2013-07-17 02:15:36 +02:00
|
|
|
READ_NODE_FIELD(aggfilter);
|
2008-12-28 19:54:01 +01:00
|
|
|
READ_UINT_FIELD(winref);
|
|
|
|
READ_BOOL_FIELD(winstar);
|
|
|
|
READ_BOOL_FIELD(winagg);
|
|
|
|
READ_LOCATION_FIELD(location);
|
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
2002-12-12 16:49:42 +01:00
|
|
|
/*
|
|
|
|
* _readArrayRef
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
2002-12-12 16:49:42 +01:00
|
|
|
static ArrayRef *
|
|
|
|
_readArrayRef(void)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2002-12-12 16:49:42 +01:00
|
|
|
READ_LOCALS(ArrayRef);
|
|
|
|
|
2003-04-09 01:20:04 +02:00
|
|
|
READ_OID_FIELD(refarraytype);
|
|
|
|
READ_OID_FIELD(refelemtype);
|
2007-03-17 01:11:05 +01:00
|
|
|
READ_INT_FIELD(reftypmod);
|
2011-03-20 01:29:08 +01:00
|
|
|
READ_OID_FIELD(refcollid);
|
2002-12-12 16:49:42 +01:00
|
|
|
READ_NODE_FIELD(refupperindexpr);
|
|
|
|
READ_NODE_FIELD(reflowerindexpr);
|
|
|
|
READ_NODE_FIELD(refexpr);
|
|
|
|
READ_NODE_FIELD(refassgnexpr);
|
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* _readFuncExpr
|
|
|
|
*/
|
|
|
|
static FuncExpr *
|
|
|
|
_readFuncExpr(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(FuncExpr);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_OID_FIELD(funcid);
|
|
|
|
READ_OID_FIELD(funcresulttype);
|
|
|
|
READ_BOOL_FIELD(funcretset);
|
2013-01-22 02:25:26 +01:00
|
|
|
READ_BOOL_FIELD(funcvariadic);
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_ENUM_FIELD(funcformat, CoercionForm);
|
2011-03-20 01:29:08 +01:00
|
|
|
READ_OID_FIELD(funccollid);
|
|
|
|
READ_OID_FIELD(inputcollid);
|
2002-12-12 16:49:42 +01:00
|
|
|
READ_NODE_FIELD(args);
|
2008-08-29 01:09:48 +02:00
|
|
|
READ_LOCATION_FIELD(location);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_DONE();
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2009-10-08 04:39:25 +02:00
|
|
|
/*
|
|
|
|
* _readNamedArgExpr
|
|
|
|
*/
|
|
|
|
static NamedArgExpr *
|
|
|
|
_readNamedArgExpr(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(NamedArgExpr);
|
|
|
|
|
|
|
|
READ_NODE_FIELD(arg);
|
|
|
|
READ_STRING_FIELD(name);
|
|
|
|
READ_INT_FIELD(argnumber);
|
|
|
|
READ_LOCATION_FIELD(location);
|
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/*
|
2002-12-12 16:49:42 +01:00
|
|
|
* _readOpExpr
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
2002-12-12 16:49:42 +01:00
|
|
|
static OpExpr *
|
|
|
|
_readOpExpr(void)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2002-12-12 16:49:42 +01:00
|
|
|
READ_LOCALS(OpExpr);
|
2000-09-12 23:07:18 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_OID_FIELD(opno);
|
2002-12-12 16:49:42 +01:00
|
|
|
READ_OID_FIELD(opfuncid);
|
2003-08-04 02:43:34 +02:00
|
|
|
|
2002-12-12 16:49:42 +01:00
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* The opfuncid is stored in the textual format primarily for debugging
|
|
|
|
* and documentation reasons. We want to always read it as zero to force
|
2014-05-06 18:12:18 +02:00
|
|
|
* it to be re-looked-up in the pg_operator entry. This ensures that
|
2005-10-15 04:49:52 +02:00
|
|
|
* stored rules don't have hidden dependencies on operators' functions.
|
|
|
|
* (We don't currently support an ALTER OPERATOR command, but might
|
|
|
|
* someday.)
|
2002-12-12 16:49:42 +01:00
|
|
|
*/
|
|
|
|
local_node->opfuncid = InvalidOid;
|
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_OID_FIELD(opresulttype);
|
|
|
|
READ_BOOL_FIELD(opretset);
|
2011-03-20 01:29:08 +01:00
|
|
|
READ_OID_FIELD(opcollid);
|
|
|
|
READ_OID_FIELD(inputcollid);
|
2002-12-12 16:49:42 +01:00
|
|
|
READ_NODE_FIELD(args);
|
2008-08-29 01:09:48 +02:00
|
|
|
READ_LOCATION_FIELD(location);
|
2000-09-12 23:07:18 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_DONE();
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/*
|
2002-12-12 16:49:42 +01:00
|
|
|
* _readDistinctExpr
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
2002-12-12 16:49:42 +01:00
|
|
|
static DistinctExpr *
|
|
|
|
_readDistinctExpr(void)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2002-12-12 16:49:42 +01:00
|
|
|
READ_LOCALS(DistinctExpr);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-12-12 16:49:42 +01:00
|
|
|
READ_OID_FIELD(opno);
|
|
|
|
READ_OID_FIELD(opfuncid);
|
2003-08-04 02:43:34 +02:00
|
|
|
|
2002-12-12 16:49:42 +01:00
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* The opfuncid is stored in the textual format primarily for debugging
|
|
|
|
* and documentation reasons. We want to always read it as zero to force
|
2014-05-06 18:12:18 +02:00
|
|
|
* it to be re-looked-up in the pg_operator entry. This ensures that
|
2005-10-15 04:49:52 +02:00
|
|
|
* stored rules don't have hidden dependencies on operators' functions.
|
|
|
|
* (We don't currently support an ALTER OPERATOR command, but might
|
|
|
|
* someday.)
|
2002-12-12 16:49:42 +01:00
|
|
|
*/
|
|
|
|
local_node->opfuncid = InvalidOid;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2002-12-12 16:49:42 +01:00
|
|
|
READ_OID_FIELD(opresulttype);
|
|
|
|
READ_BOOL_FIELD(opretset);
|
2011-03-20 01:29:08 +01:00
|
|
|
READ_OID_FIELD(opcollid);
|
|
|
|
READ_OID_FIELD(inputcollid);
|
|
|
|
READ_NODE_FIELD(args);
|
|
|
|
READ_LOCATION_FIELD(location);
|
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* _readNullIfExpr
|
|
|
|
*/
|
|
|
|
static NullIfExpr *
|
|
|
|
_readNullIfExpr(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(NullIfExpr);
|
|
|
|
|
|
|
|
READ_OID_FIELD(opno);
|
|
|
|
READ_OID_FIELD(opfuncid);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The opfuncid is stored in the textual format primarily for debugging
|
|
|
|
* and documentation reasons. We want to always read it as zero to force
|
2014-05-06 18:12:18 +02:00
|
|
|
* it to be re-looked-up in the pg_operator entry. This ensures that
|
2011-03-20 01:29:08 +01:00
|
|
|
* stored rules don't have hidden dependencies on operators' functions.
|
|
|
|
* (We don't currently support an ALTER OPERATOR command, but might
|
|
|
|
* someday.)
|
|
|
|
*/
|
|
|
|
local_node->opfuncid = InvalidOid;
|
|
|
|
|
|
|
|
READ_OID_FIELD(opresulttype);
|
|
|
|
READ_BOOL_FIELD(opretset);
|
|
|
|
READ_OID_FIELD(opcollid);
|
|
|
|
READ_OID_FIELD(inputcollid);
|
2002-12-12 16:49:42 +01:00
|
|
|
READ_NODE_FIELD(args);
|
2008-08-29 01:09:48 +02:00
|
|
|
READ_LOCATION_FIELD(location);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_DONE();
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2003-06-29 02:33:44 +02:00
|
|
|
/*
|
|
|
|
* _readScalarArrayOpExpr
|
|
|
|
*/
|
|
|
|
static ScalarArrayOpExpr *
|
|
|
|
_readScalarArrayOpExpr(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(ScalarArrayOpExpr);
|
|
|
|
|
|
|
|
READ_OID_FIELD(opno);
|
|
|
|
READ_OID_FIELD(opfuncid);
|
2003-08-04 02:43:34 +02:00
|
|
|
|
2003-06-29 02:33:44 +02:00
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* The opfuncid is stored in the textual format primarily for debugging
|
|
|
|
* and documentation reasons. We want to always read it as zero to force
|
2014-05-06 18:12:18 +02:00
|
|
|
* it to be re-looked-up in the pg_operator entry. This ensures that
|
2005-10-15 04:49:52 +02:00
|
|
|
* stored rules don't have hidden dependencies on operators' functions.
|
|
|
|
* (We don't currently support an ALTER OPERATOR command, but might
|
|
|
|
* someday.)
|
2003-06-29 02:33:44 +02:00
|
|
|
*/
|
|
|
|
local_node->opfuncid = InvalidOid;
|
|
|
|
|
|
|
|
READ_BOOL_FIELD(useOr);
|
2011-03-20 01:29:08 +01:00
|
|
|
READ_OID_FIELD(inputcollid);
|
2003-06-29 02:33:44 +02:00
|
|
|
READ_NODE_FIELD(args);
|
2008-08-29 01:09:48 +02:00
|
|
|
READ_LOCATION_FIELD(location);
|
2003-06-29 02:33:44 +02:00
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
2002-12-12 16:49:42 +01:00
|
|
|
/*
|
|
|
|
* _readBoolExpr
|
|
|
|
*/
|
|
|
|
static BoolExpr *
|
|
|
|
_readBoolExpr(void)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2002-12-12 16:49:42 +01:00
|
|
|
READ_LOCALS(BoolExpr);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-12-12 16:49:42 +01:00
|
|
|
/* do-it-yourself enum representation */
|
|
|
|
token = pg_strtok(&length); /* skip :boolop */
|
|
|
|
token = pg_strtok(&length); /* get field value */
|
|
|
|
if (strncmp(token, "and", 3) == 0)
|
|
|
|
local_node->boolop = AND_EXPR;
|
|
|
|
else if (strncmp(token, "or", 2) == 0)
|
|
|
|
local_node->boolop = OR_EXPR;
|
|
|
|
else if (strncmp(token, "not", 3) == 0)
|
|
|
|
local_node->boolop = NOT_EXPR;
|
|
|
|
else
|
2003-07-23 01:30:39 +02:00
|
|
|
elog(ERROR, "unrecognized boolop \"%.*s\"", length, token);
|
2000-09-12 23:07:18 +02:00
|
|
|
|
2002-12-12 16:49:42 +01:00
|
|
|
READ_NODE_FIELD(args);
|
2008-08-29 01:09:48 +02:00
|
|
|
READ_LOCATION_FIELD(location);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_DONE();
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/*
|
|
|
|
* _readSubLink
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
2002-11-25 19:12:12 +01:00
|
|
|
static SubLink *
|
|
|
|
_readSubLink(void)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_LOCALS(SubLink);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_ENUM_FIELD(subLinkType, SubLinkType);
|
Implement UPDATE tab SET (col1,col2,...) = (SELECT ...), ...
This SQL-standard feature allows a sub-SELECT yielding multiple columns
(but only one row) to be used to compute the new values of several columns
to be updated. While the same results can be had with an independent
sub-SELECT per column, such a workaround can require a great deal of
duplicated computation.
The standard actually says that the source for a multi-column assignment
could be any row-valued expression. The implementation used here is
tightly tied to our existing sub-SELECT support and can't handle other
cases; the Bison grammar would have some issues with them too. However,
I don't feel too bad about this since other cases can be converted into
sub-SELECTs. For instance, "SET (a,b,c) = row_valued_function(x)" could
be written "SET (a,b,c) = (SELECT * FROM row_valued_function(x))".
2014-06-18 19:22:25 +02:00
|
|
|
READ_INT_FIELD(subLinkId);
|
2005-12-28 02:30:02 +01:00
|
|
|
READ_NODE_FIELD(testexpr);
|
2003-01-10 22:08:15 +01:00
|
|
|
READ_NODE_FIELD(operName);
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_NODE_FIELD(subselect);
|
2008-08-29 01:09:48 +02:00
|
|
|
READ_LOCATION_FIELD(location);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_DONE();
|
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-12-12 16:49:42 +01:00
|
|
|
/*
|
2002-12-14 01:17:59 +01:00
|
|
|
* _readSubPlan is not needed since it doesn't appear in stored rules.
|
2002-12-12 16:49:42 +01:00
|
|
|
*/
|
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/*
|
|
|
|
* _readFieldSelect
|
|
|
|
*/
|
|
|
|
static FieldSelect *
|
|
|
|
_readFieldSelect(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(FieldSelect);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_NODE_FIELD(arg);
|
|
|
|
READ_INT_FIELD(fieldnum);
|
|
|
|
READ_OID_FIELD(resulttype);
|
|
|
|
READ_INT_FIELD(resulttypmod);
|
2011-03-20 01:29:08 +01:00
|
|
|
READ_OID_FIELD(resultcollid);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_DONE();
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2004-06-09 21:08:20 +02:00
|
|
|
/*
|
|
|
|
* _readFieldStore
|
|
|
|
*/
|
|
|
|
static FieldStore *
|
|
|
|
_readFieldStore(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(FieldStore);
|
|
|
|
|
|
|
|
READ_NODE_FIELD(arg);
|
|
|
|
READ_NODE_FIELD(newvals);
|
|
|
|
READ_NODE_FIELD(fieldnums);
|
|
|
|
READ_OID_FIELD(resulttype);
|
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/*
|
|
|
|
* _readRelabelType
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
2002-11-25 19:12:12 +01:00
|
|
|
static RelabelType *
|
|
|
|
_readRelabelType(void)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_LOCALS(RelabelType);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_NODE_FIELD(arg);
|
|
|
|
READ_OID_FIELD(resulttype);
|
|
|
|
READ_INT_FIELD(resulttypmod);
|
2011-03-20 01:29:08 +01:00
|
|
|
READ_OID_FIELD(resultcollid);
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_ENUM_FIELD(relabelformat, CoercionForm);
|
2008-08-29 01:09:48 +02:00
|
|
|
READ_LOCATION_FIELD(location);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_DONE();
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2007-06-05 23:31:09 +02:00
|
|
|
/*
|
|
|
|
* _readCoerceViaIO
|
|
|
|
*/
|
|
|
|
static CoerceViaIO *
|
|
|
|
_readCoerceViaIO(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(CoerceViaIO);
|
|
|
|
|
|
|
|
READ_NODE_FIELD(arg);
|
|
|
|
READ_OID_FIELD(resulttype);
|
2011-03-20 01:29:08 +01:00
|
|
|
READ_OID_FIELD(resultcollid);
|
2007-06-05 23:31:09 +02:00
|
|
|
READ_ENUM_FIELD(coerceformat, CoercionForm);
|
2008-08-29 01:09:48 +02:00
|
|
|
READ_LOCATION_FIELD(location);
|
2007-06-05 23:31:09 +02:00
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
2007-03-28 01:21:12 +02:00
|
|
|
/*
|
|
|
|
* _readArrayCoerceExpr
|
|
|
|
*/
|
|
|
|
static ArrayCoerceExpr *
|
|
|
|
_readArrayCoerceExpr(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(ArrayCoerceExpr);
|
|
|
|
|
|
|
|
READ_NODE_FIELD(arg);
|
|
|
|
READ_OID_FIELD(elemfuncid);
|
|
|
|
READ_OID_FIELD(resulttype);
|
|
|
|
READ_INT_FIELD(resulttypmod);
|
2011-03-20 01:29:08 +01:00
|
|
|
READ_OID_FIELD(resultcollid);
|
2007-03-28 01:21:12 +02:00
|
|
|
READ_BOOL_FIELD(isExplicit);
|
|
|
|
READ_ENUM_FIELD(coerceformat, CoercionForm);
|
2008-08-29 01:09:48 +02:00
|
|
|
READ_LOCATION_FIELD(location);
|
2007-03-28 01:21:12 +02:00
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
2004-12-12 00:26:51 +01:00
|
|
|
/*
|
|
|
|
* _readConvertRowtypeExpr
|
|
|
|
*/
|
|
|
|
static ConvertRowtypeExpr *
|
|
|
|
_readConvertRowtypeExpr(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(ConvertRowtypeExpr);
|
|
|
|
|
|
|
|
READ_NODE_FIELD(arg);
|
|
|
|
READ_OID_FIELD(resulttype);
|
|
|
|
READ_ENUM_FIELD(convertformat, CoercionForm);
|
2008-08-29 01:09:48 +02:00
|
|
|
READ_LOCATION_FIELD(location);
|
2004-12-12 00:26:51 +01:00
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
2011-03-11 22:27:51 +01:00
|
|
|
/*
|
|
|
|
* _readCollateExpr
|
|
|
|
*/
|
|
|
|
static CollateExpr *
|
|
|
|
_readCollateExpr(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(CollateExpr);
|
|
|
|
|
|
|
|
READ_NODE_FIELD(arg);
|
|
|
|
READ_OID_FIELD(collOid);
|
|
|
|
READ_LOCATION_FIELD(location);
|
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/*
|
|
|
|
* _readCaseExpr
|
|
|
|
*/
|
|
|
|
static CaseExpr *
|
|
|
|
_readCaseExpr(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(CaseExpr);
|
1998-11-22 11:48:45 +01:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_OID_FIELD(casetype);
|
2011-03-20 01:29:08 +01:00
|
|
|
READ_OID_FIELD(casecollid);
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_NODE_FIELD(arg);
|
|
|
|
READ_NODE_FIELD(args);
|
|
|
|
READ_NODE_FIELD(defresult);
|
2008-08-29 01:09:48 +02:00
|
|
|
READ_LOCATION_FIELD(location);
|
1999-08-09 08:20:27 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_DONE();
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/*
|
|
|
|
* _readCaseWhen
|
1999-11-23 21:07:06 +01:00
|
|
|
*/
|
2002-11-25 19:12:12 +01:00
|
|
|
static CaseWhen *
|
|
|
|
_readCaseWhen(void)
|
1999-11-23 21:07:06 +01:00
|
|
|
{
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_LOCALS(CaseWhen);
|
1999-11-23 21:07:06 +01:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_NODE_FIELD(expr);
|
|
|
|
READ_NODE_FIELD(result);
|
2008-08-29 01:09:48 +02:00
|
|
|
READ_LOCATION_FIELD(location);
|
1999-11-23 21:07:06 +01:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_DONE();
|
1999-11-23 21:07:06 +01:00
|
|
|
}
|
|
|
|
|
2004-03-17 21:48:43 +01:00
|
|
|
/*
|
|
|
|
* _readCaseTestExpr
|
|
|
|
*/
|
|
|
|
static CaseTestExpr *
|
|
|
|
_readCaseTestExpr(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(CaseTestExpr);
|
|
|
|
|
|
|
|
READ_OID_FIELD(typeId);
|
|
|
|
READ_INT_FIELD(typeMod);
|
2011-02-08 22:04:18 +01:00
|
|
|
READ_OID_FIELD(collation);
|
2004-03-17 21:48:43 +01:00
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
2003-04-09 01:20:04 +02:00
|
|
|
/*
|
|
|
|
* _readArrayExpr
|
|
|
|
*/
|
|
|
|
static ArrayExpr *
|
|
|
|
_readArrayExpr(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(ArrayExpr);
|
|
|
|
|
|
|
|
READ_OID_FIELD(array_typeid);
|
2011-03-20 01:29:08 +01:00
|
|
|
READ_OID_FIELD(array_collid);
|
2003-04-09 01:20:04 +02:00
|
|
|
READ_OID_FIELD(element_typeid);
|
|
|
|
READ_NODE_FIELD(elements);
|
2003-08-18 01:43:27 +02:00
|
|
|
READ_BOOL_FIELD(multidims);
|
2008-08-29 01:09:48 +02:00
|
|
|
READ_LOCATION_FIELD(location);
|
2003-04-09 01:20:04 +02:00
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
2004-05-11 00:44:49 +02:00
|
|
|
/*
|
|
|
|
* _readRowExpr
|
|
|
|
*/
|
|
|
|
static RowExpr *
|
|
|
|
_readRowExpr(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(RowExpr);
|
|
|
|
|
|
|
|
READ_NODE_FIELD(args);
|
|
|
|
READ_OID_FIELD(row_typeid);
|
|
|
|
READ_ENUM_FIELD(row_format, CoercionForm);
|
2008-10-06 19:39:26 +02:00
|
|
|
READ_NODE_FIELD(colnames);
|
2008-08-29 01:09:48 +02:00
|
|
|
READ_LOCATION_FIELD(location);
|
2004-05-11 00:44:49 +02:00
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
2005-12-28 02:30:02 +01:00
|
|
|
/*
|
|
|
|
* _readRowCompareExpr
|
|
|
|
*/
|
|
|
|
static RowCompareExpr *
|
|
|
|
_readRowCompareExpr(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(RowCompareExpr);
|
|
|
|
|
|
|
|
READ_ENUM_FIELD(rctype, RowCompareType);
|
|
|
|
READ_NODE_FIELD(opnos);
|
2006-12-23 01:43:13 +01:00
|
|
|
READ_NODE_FIELD(opfamilies);
|
2011-03-20 01:29:08 +01:00
|
|
|
READ_NODE_FIELD(inputcollids);
|
2005-12-28 02:30:02 +01:00
|
|
|
READ_NODE_FIELD(largs);
|
|
|
|
READ_NODE_FIELD(rargs);
|
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
2003-02-16 03:30:39 +01:00
|
|
|
/*
|
|
|
|
* _readCoalesceExpr
|
|
|
|
*/
|
|
|
|
static CoalesceExpr *
|
|
|
|
_readCoalesceExpr(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(CoalesceExpr);
|
|
|
|
|
|
|
|
READ_OID_FIELD(coalescetype);
|
2011-03-20 01:29:08 +01:00
|
|
|
READ_OID_FIELD(coalescecollid);
|
2003-02-16 03:30:39 +01:00
|
|
|
READ_NODE_FIELD(args);
|
2008-08-29 01:09:48 +02:00
|
|
|
READ_LOCATION_FIELD(location);
|
2003-02-16 03:30:39 +01:00
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
2005-06-27 00:05:42 +02:00
|
|
|
/*
|
|
|
|
* _readMinMaxExpr
|
|
|
|
*/
|
|
|
|
static MinMaxExpr *
|
|
|
|
_readMinMaxExpr(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(MinMaxExpr);
|
|
|
|
|
|
|
|
READ_OID_FIELD(minmaxtype);
|
2011-03-20 01:29:08 +01:00
|
|
|
READ_OID_FIELD(minmaxcollid);
|
|
|
|
READ_OID_FIELD(inputcollid);
|
2005-06-27 00:05:42 +02:00
|
|
|
READ_ENUM_FIELD(op, MinMaxOp);
|
|
|
|
READ_NODE_FIELD(args);
|
2008-08-29 01:09:48 +02:00
|
|
|
READ_LOCATION_FIELD(location);
|
2005-06-27 00:05:42 +02:00
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
2006-12-24 01:29:20 +01:00
|
|
|
/*
|
|
|
|
* _readXmlExpr
|
|
|
|
*/
|
|
|
|
static XmlExpr *
|
|
|
|
_readXmlExpr(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(XmlExpr);
|
|
|
|
|
|
|
|
READ_ENUM_FIELD(op, XmlExprOp);
|
|
|
|
READ_STRING_FIELD(name);
|
|
|
|
READ_NODE_FIELD(named_args);
|
|
|
|
READ_NODE_FIELD(arg_names);
|
|
|
|
READ_NODE_FIELD(args);
|
2007-02-03 15:06:56 +01:00
|
|
|
READ_ENUM_FIELD(xmloption, XmlOptionType);
|
|
|
|
READ_OID_FIELD(type);
|
|
|
|
READ_INT_FIELD(typmod);
|
2008-08-29 01:09:48 +02:00
|
|
|
READ_LOCATION_FIELD(location);
|
2006-12-24 01:29:20 +01:00
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/*
|
|
|
|
* _readNullTest
|
2000-09-29 20:21:41 +02:00
|
|
|
*/
|
2002-11-25 19:12:12 +01:00
|
|
|
static NullTest *
|
|
|
|
_readNullTest(void)
|
2000-09-29 20:21:41 +02:00
|
|
|
{
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_LOCALS(NullTest);
|
2000-09-29 20:21:41 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_NODE_FIELD(arg);
|
|
|
|
READ_ENUM_FIELD(nulltesttype, NullTestType);
|
2010-01-02 00:03:10 +01:00
|
|
|
READ_BOOL_FIELD(argisrow);
|
2015-02-22 20:40:27 +01:00
|
|
|
READ_LOCATION_FIELD(location);
|
2000-09-29 20:21:41 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_DONE();
|
2000-09-29 20:21:41 +02:00
|
|
|
}
|
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/*
|
|
|
|
* _readBooleanTest
|
2002-05-12 22:10:05 +02:00
|
|
|
*/
|
2002-11-25 19:12:12 +01:00
|
|
|
static BooleanTest *
|
|
|
|
_readBooleanTest(void)
|
2002-05-12 22:10:05 +02:00
|
|
|
{
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_LOCALS(BooleanTest);
|
2002-05-12 22:10:05 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_NODE_FIELD(arg);
|
|
|
|
READ_ENUM_FIELD(booltesttype, BoolTestType);
|
2015-02-22 20:40:27 +01:00
|
|
|
READ_LOCATION_FIELD(location);
|
2002-05-12 22:10:05 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_DONE();
|
2002-05-12 22:10:05 +02:00
|
|
|
}
|
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/*
|
2003-02-03 22:15:45 +01:00
|
|
|
* _readCoerceToDomain
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
2003-02-03 22:15:45 +01:00
|
|
|
static CoerceToDomain *
|
|
|
|
_readCoerceToDomain(void)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2003-02-03 22:15:45 +01:00
|
|
|
READ_LOCALS(CoerceToDomain);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_NODE_FIELD(arg);
|
2003-02-03 22:15:45 +01:00
|
|
|
READ_OID_FIELD(resulttype);
|
|
|
|
READ_INT_FIELD(resulttypmod);
|
2011-03-20 01:29:08 +01:00
|
|
|
READ_OID_FIELD(resultcollid);
|
2003-02-03 22:15:45 +01:00
|
|
|
READ_ENUM_FIELD(coercionformat, CoercionForm);
|
2008-08-29 01:09:48 +02:00
|
|
|
READ_LOCATION_FIELD(location);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_DONE();
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/*
|
2003-02-03 22:15:45 +01:00
|
|
|
* _readCoerceToDomainValue
|
2002-11-25 19:12:12 +01:00
|
|
|
*/
|
2003-02-03 22:15:45 +01:00
|
|
|
static CoerceToDomainValue *
|
|
|
|
_readCoerceToDomainValue(void)
|
2002-11-25 19:12:12 +01:00
|
|
|
{
|
2003-02-03 22:15:45 +01:00
|
|
|
READ_LOCALS(CoerceToDomainValue);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_OID_FIELD(typeId);
|
|
|
|
READ_INT_FIELD(typeMod);
|
2011-03-20 01:29:08 +01:00
|
|
|
READ_OID_FIELD(collation);
|
2008-08-29 01:09:48 +02:00
|
|
|
READ_LOCATION_FIELD(location);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_DONE();
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2003-07-03 18:34:26 +02:00
|
|
|
/*
|
|
|
|
* _readSetToDefault
|
|
|
|
*/
|
|
|
|
static SetToDefault *
|
|
|
|
_readSetToDefault(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(SetToDefault);
|
|
|
|
|
|
|
|
READ_OID_FIELD(typeId);
|
|
|
|
READ_INT_FIELD(typeMod);
|
2011-03-20 01:29:08 +01:00
|
|
|
READ_OID_FIELD(collation);
|
2008-08-29 01:09:48 +02:00
|
|
|
READ_LOCATION_FIELD(location);
|
2003-07-03 18:34:26 +02:00
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
2007-06-11 03:16:30 +02:00
|
|
|
/*
|
|
|
|
* _readCurrentOfExpr
|
|
|
|
*/
|
|
|
|
static CurrentOfExpr *
|
|
|
|
_readCurrentOfExpr(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(CurrentOfExpr);
|
|
|
|
|
|
|
|
READ_UINT_FIELD(cvarno);
|
|
|
|
READ_STRING_FIELD(cursor_name);
|
2007-06-12 00:22:42 +02:00
|
|
|
READ_INT_FIELD(cursor_param);
|
2007-06-11 03:16:30 +02:00
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
Add support for INSERT ... ON CONFLICT DO NOTHING/UPDATE.
The newly added ON CONFLICT clause allows to specify an alternative to
raising a unique or exclusion constraint violation error when inserting.
ON CONFLICT refers to constraints that can either be specified using a
inference clause (by specifying the columns of a unique constraint) or
by naming a unique or exclusion constraint. DO NOTHING avoids the
constraint violation, without touching the pre-existing row. DO UPDATE
SET ... [WHERE ...] updates the pre-existing tuple, and has access to
both the tuple proposed for insertion and the existing tuple; the
optional WHERE clause can be used to prevent an update from being
executed. The UPDATE SET and WHERE clauses have access to the tuple
proposed for insertion using the "magic" EXCLUDED alias, and to the
pre-existing tuple using the table name or its alias.
This feature is often referred to as upsert.
This is implemented using a new infrastructure called "speculative
insertion". It is an optimistic variant of regular insertion that first
does a pre-check for existing tuples and then attempts an insert. If a
violating tuple was inserted concurrently, the speculatively inserted
tuple is deleted and a new attempt is made. If the pre-check finds a
matching tuple the alternative DO NOTHING or DO UPDATE action is taken.
If the insertion succeeds without detecting a conflict, the tuple is
deemed inserted.
To handle the possible ambiguity between the excluded alias and a table
named excluded, and for convenience with long relation names, INSERT
INTO now can alias its target table.
Bumps catversion as stored rules change.
Author: Peter Geoghegan, with significant contributions from Heikki
Linnakangas and Andres Freund. Testing infrastructure by Jeff Janes.
Reviewed-By: Heikki Linnakangas, Andres Freund, Robert Haas, Simon Riggs,
Dean Rasheed, Stephen Frost and many others.
2015-05-08 05:31:36 +02:00
|
|
|
/*
|
|
|
|
* _readInferenceElem
|
|
|
|
*/
|
|
|
|
static InferenceElem *
|
|
|
|
_readInferenceElem(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(InferenceElem);
|
|
|
|
|
|
|
|
READ_NODE_FIELD(expr);
|
|
|
|
READ_OID_FIELD(infercollid);
|
|
|
|
READ_OID_FIELD(inferopfamily);
|
|
|
|
READ_OID_FIELD(inferopcinputtype);
|
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*
|
2002-11-25 19:12:12 +01:00
|
|
|
* _readTargetEntry
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
2002-11-25 19:12:12 +01:00
|
|
|
static TargetEntry *
|
|
|
|
_readTargetEntry(void)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_LOCALS(TargetEntry);
|
|
|
|
|
|
|
|
READ_NODE_FIELD(expr);
|
2005-04-06 18:34:07 +02:00
|
|
|
READ_INT_FIELD(resno);
|
|
|
|
READ_STRING_FIELD(resname);
|
|
|
|
READ_UINT_FIELD(ressortgroupref);
|
|
|
|
READ_OID_FIELD(resorigtbl);
|
|
|
|
READ_INT_FIELD(resorigcol);
|
|
|
|
READ_BOOL_FIELD(resjunk);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_DONE();
|
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-12-12 16:49:42 +01:00
|
|
|
/*
|
|
|
|
* _readRangeTblRef
|
|
|
|
*/
|
|
|
|
static RangeTblRef *
|
|
|
|
_readRangeTblRef(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(RangeTblRef);
|
|
|
|
|
|
|
|
READ_INT_FIELD(rtindex);
|
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* _readJoinExpr
|
|
|
|
*/
|
|
|
|
static JoinExpr *
|
|
|
|
_readJoinExpr(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(JoinExpr);
|
|
|
|
|
|
|
|
READ_ENUM_FIELD(jointype, JoinType);
|
|
|
|
READ_BOOL_FIELD(isNatural);
|
|
|
|
READ_NODE_FIELD(larg);
|
|
|
|
READ_NODE_FIELD(rarg);
|
2009-07-16 08:33:46 +02:00
|
|
|
READ_NODE_FIELD(usingClause);
|
2002-12-12 16:49:42 +01:00
|
|
|
READ_NODE_FIELD(quals);
|
|
|
|
READ_NODE_FIELD(alias);
|
|
|
|
READ_INT_FIELD(rtindex);
|
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* _readFromExpr
|
|
|
|
*/
|
|
|
|
static FromExpr *
|
|
|
|
_readFromExpr(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(FromExpr);
|
|
|
|
|
|
|
|
READ_NODE_FIELD(fromlist);
|
|
|
|
READ_NODE_FIELD(quals);
|
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
Add support for INSERT ... ON CONFLICT DO NOTHING/UPDATE.
The newly added ON CONFLICT clause allows to specify an alternative to
raising a unique or exclusion constraint violation error when inserting.
ON CONFLICT refers to constraints that can either be specified using a
inference clause (by specifying the columns of a unique constraint) or
by naming a unique or exclusion constraint. DO NOTHING avoids the
constraint violation, without touching the pre-existing row. DO UPDATE
SET ... [WHERE ...] updates the pre-existing tuple, and has access to
both the tuple proposed for insertion and the existing tuple; the
optional WHERE clause can be used to prevent an update from being
executed. The UPDATE SET and WHERE clauses have access to the tuple
proposed for insertion using the "magic" EXCLUDED alias, and to the
pre-existing tuple using the table name or its alias.
This feature is often referred to as upsert.
This is implemented using a new infrastructure called "speculative
insertion". It is an optimistic variant of regular insertion that first
does a pre-check for existing tuples and then attempts an insert. If a
violating tuple was inserted concurrently, the speculatively inserted
tuple is deleted and a new attempt is made. If the pre-check finds a
matching tuple the alternative DO NOTHING or DO UPDATE action is taken.
If the insertion succeeds without detecting a conflict, the tuple is
deemed inserted.
To handle the possible ambiguity between the excluded alias and a table
named excluded, and for convenience with long relation names, INSERT
INTO now can alias its target table.
Bumps catversion as stored rules change.
Author: Peter Geoghegan, with significant contributions from Heikki
Linnakangas and Andres Freund. Testing infrastructure by Jeff Janes.
Reviewed-By: Heikki Linnakangas, Andres Freund, Robert Haas, Simon Riggs,
Dean Rasheed, Stephen Frost and many others.
2015-05-08 05:31:36 +02:00
|
|
|
/*
|
|
|
|
* _readOnConflictExpr
|
|
|
|
*/
|
|
|
|
static OnConflictExpr *
|
|
|
|
_readOnConflictExpr(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(OnConflictExpr);
|
|
|
|
|
|
|
|
READ_ENUM_FIELD(action, OnConflictAction);
|
|
|
|
READ_NODE_FIELD(arbiterElems);
|
|
|
|
READ_NODE_FIELD(arbiterWhere);
|
|
|
|
READ_NODE_FIELD(onConflictSet);
|
|
|
|
READ_NODE_FIELD(onConflictWhere);
|
|
|
|
READ_OID_FIELD(constraint);
|
|
|
|
READ_INT_FIELD(exclRelIndex);
|
|
|
|
READ_NODE_FIELD(exclRelTlist);
|
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
2002-12-12 16:49:42 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Stuff from parsenodes.h.
|
|
|
|
*/
|
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/*
|
|
|
|
* _readRangeTblEntry
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
static RangeTblEntry *
|
2000-10-23 00:15:13 +02:00
|
|
|
_readRangeTblEntry(void)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_LOCALS(RangeTblEntry);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/* put alias + eref first to make dump more legible */
|
|
|
|
READ_NODE_FIELD(alias);
|
|
|
|
READ_NODE_FIELD(eref);
|
|
|
|
READ_ENUM_FIELD(rtekind, RTEKind);
|
2002-03-22 03:56:37 +01:00
|
|
|
|
|
|
|
switch (local_node->rtekind)
|
|
|
|
{
|
|
|
|
case RTE_RELATION:
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_OID_FIELD(relid);
|
2011-02-23 01:23:23 +01:00
|
|
|
READ_CHAR_FIELD(relkind);
|
2002-03-22 03:56:37 +01:00
|
|
|
break;
|
|
|
|
case RTE_SUBQUERY:
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_NODE_FIELD(subquery);
|
2011-12-22 22:15:57 +01:00
|
|
|
READ_BOOL_FIELD(security_barrier);
|
2002-03-22 03:56:37 +01:00
|
|
|
break;
|
2008-10-04 23:56:55 +02:00
|
|
|
case RTE_JOIN:
|
|
|
|
READ_ENUM_FIELD(jointype, JoinType);
|
|
|
|
READ_NODE_FIELD(joinaliasvars);
|
|
|
|
break;
|
2002-05-12 22:10:05 +02:00
|
|
|
case RTE_FUNCTION:
|
Support multi-argument UNNEST(), and TABLE() syntax for multiple functions.
This patch adds the ability to write TABLE( function1(), function2(), ...)
as a single FROM-clause entry. The result is the concatenation of the
first row from each function, followed by the second row from each
function, etc; with NULLs inserted if any function produces fewer rows than
others. This is believed to be a much more useful behavior than what
Postgres currently does with multiple SRFs in a SELECT list.
This syntax also provides a reasonable way to combine use of column
definition lists with WITH ORDINALITY: put the column definition list
inside TABLE(), where it's clear that it doesn't control the ordinality
column as well.
Also implement SQL-compliant multiple-argument UNNEST(), by turning
UNNEST(a,b,c) into TABLE(unnest(a), unnest(b), unnest(c)).
The SQL standard specifies TABLE() with only a single function, not
multiple functions, and it seems to require an implicit UNNEST() which is
not what this patch does. There may be something wrong with that reading
of the spec, though, because if it's right then the spec's TABLE() is just
a pointless alternative spelling of UNNEST(). After further review of
that, we might choose to adopt a different syntax for what this patch does,
but in any case this functionality seems clearly worthwhile.
Andrew Gierth, reviewed by Zoltán Böszörményi and Heikki Linnakangas, and
significantly revised by me
2013-11-22 01:37:02 +01:00
|
|
|
READ_NODE_FIELD(functions);
|
2013-07-29 17:38:01 +02:00
|
|
|
READ_BOOL_FIELD(funcordinality);
|
2002-05-12 22:10:05 +02:00
|
|
|
break;
|
2006-08-02 03:59:48 +02:00
|
|
|
case RTE_VALUES:
|
|
|
|
READ_NODE_FIELD(values_lists);
|
2011-04-18 21:31:52 +02:00
|
|
|
READ_NODE_FIELD(values_collations);
|
2006-08-02 03:59:48 +02:00
|
|
|
break;
|
2008-10-04 23:56:55 +02:00
|
|
|
case RTE_CTE:
|
|
|
|
READ_STRING_FIELD(ctename);
|
|
|
|
READ_UINT_FIELD(ctelevelsup);
|
|
|
|
READ_BOOL_FIELD(self_reference);
|
|
|
|
READ_NODE_FIELD(ctecoltypes);
|
|
|
|
READ_NODE_FIELD(ctecoltypmods);
|
2011-02-08 22:04:18 +01:00
|
|
|
READ_NODE_FIELD(ctecolcollations);
|
2002-03-22 03:56:37 +01:00
|
|
|
break;
|
|
|
|
default:
|
2003-07-23 01:30:39 +02:00
|
|
|
elog(ERROR, "unrecognized RTE kind: %d",
|
|
|
|
(int) local_node->rtekind);
|
2002-03-22 03:56:37 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-08-08 01:02:54 +02:00
|
|
|
READ_BOOL_FIELD(lateral);
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_BOOL_FIELD(inh);
|
|
|
|
READ_BOOL_FIELD(inFromCl);
|
2004-01-15 00:01:55 +01:00
|
|
|
READ_UINT_FIELD(requiredPerms);
|
2005-06-28 07:09:14 +02:00
|
|
|
READ_OID_FIELD(checkAsUser);
|
2009-01-22 21:16:10 +01:00
|
|
|
READ_BITMAPSET_FIELD(selectedCols);
|
2015-05-08 00:20:46 +02:00
|
|
|
READ_BITMAPSET_FIELD(insertedCols);
|
|
|
|
READ_BITMAPSET_FIELD(updatedCols);
|
2014-04-13 03:04:58 +02:00
|
|
|
READ_NODE_FIELD(securityQuals);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_DONE();
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
Support multi-argument UNNEST(), and TABLE() syntax for multiple functions.
This patch adds the ability to write TABLE( function1(), function2(), ...)
as a single FROM-clause entry. The result is the concatenation of the
first row from each function, followed by the second row from each
function, etc; with NULLs inserted if any function produces fewer rows than
others. This is believed to be a much more useful behavior than what
Postgres currently does with multiple SRFs in a SELECT list.
This syntax also provides a reasonable way to combine use of column
definition lists with WITH ORDINALITY: put the column definition list
inside TABLE(), where it's clear that it doesn't control the ordinality
column as well.
Also implement SQL-compliant multiple-argument UNNEST(), by turning
UNNEST(a,b,c) into TABLE(unnest(a), unnest(b), unnest(c)).
The SQL standard specifies TABLE() with only a single function, not
multiple functions, and it seems to require an implicit UNNEST() which is
not what this patch does. There may be something wrong with that reading
of the spec, though, because if it's right then the spec's TABLE() is just
a pointless alternative spelling of UNNEST(). After further review of
that, we might choose to adopt a different syntax for what this patch does,
but in any case this functionality seems clearly worthwhile.
Andrew Gierth, reviewed by Zoltán Böszörményi and Heikki Linnakangas, and
significantly revised by me
2013-11-22 01:37:02 +01:00
|
|
|
/*
|
|
|
|
* _readRangeTblFunction
|
|
|
|
*/
|
|
|
|
static RangeTblFunction *
|
|
|
|
_readRangeTblFunction(void)
|
|
|
|
{
|
|
|
|
READ_LOCALS(RangeTblFunction);
|
|
|
|
|
|
|
|
READ_NODE_FIELD(funcexpr);
|
|
|
|
READ_INT_FIELD(funccolcount);
|
|
|
|
READ_NODE_FIELD(funccolnames);
|
|
|
|
READ_NODE_FIELD(funccoltypes);
|
|
|
|
READ_NODE_FIELD(funccoltypmods);
|
|
|
|
READ_NODE_FIELD(funccolcollations);
|
|
|
|
READ_BITMAPSET_FIELD(funcparams);
|
|
|
|
|
|
|
|
READ_DONE();
|
|
|
|
}
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/*
|
|
|
|
* parseNodeString
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2002-11-25 19:12:12 +01:00
|
|
|
* Given a character string representing a node tree, parseNodeString creates
|
|
|
|
* the internal node structure.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2001-01-07 02:08:48 +01:00
|
|
|
* The string to be read must already have been loaded into pg_strtok().
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1998-02-26 05:46:47 +01:00
|
|
|
Node *
|
2002-11-25 19:12:12 +01:00
|
|
|
parseNodeString(void)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2002-11-25 19:12:12 +01:00
|
|
|
void *return_value;
|
2003-08-04 02:43:34 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
READ_TEMP_LOCALS();
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2001-01-07 02:08:48 +01:00
|
|
|
token = pg_strtok(&length);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
#define MATCH(tokname, namelen) \
|
2010-12-22 04:11:40 +01:00
|
|
|
(length == namelen && memcmp(token, tokname, namelen) == 0)
|
2002-11-25 19:12:12 +01:00
|
|
|
|
2002-12-12 16:49:42 +01:00
|
|
|
if (MATCH("QUERY", 5))
|
1997-09-07 07:04:48 +02:00
|
|
|
return_value = _readQuery();
|
2013-07-18 23:10:16 +02:00
|
|
|
else if (MATCH("WITHCHECKOPTION", 15))
|
|
|
|
return_value = _readWithCheckOption();
|
2008-08-02 23:32:01 +02:00
|
|
|
else if (MATCH("SORTGROUPCLAUSE", 15))
|
|
|
|
return_value = _readSortGroupClause();
|
2008-12-28 19:54:01 +01:00
|
|
|
else if (MATCH("WINDOWCLAUSE", 12))
|
|
|
|
return_value = _readWindowClause();
|
2006-04-30 20:30:40 +02:00
|
|
|
else if (MATCH("ROWMARKCLAUSE", 13))
|
|
|
|
return_value = _readRowMarkClause();
|
2008-10-04 23:56:55 +02:00
|
|
|
else if (MATCH("COMMONTABLEEXPR", 15))
|
|
|
|
return_value = _readCommonTableExpr();
|
2002-11-25 19:12:12 +01:00
|
|
|
else if (MATCH("SETOPERATIONSTMT", 16))
|
2000-10-05 21:11:39 +02:00
|
|
|
return_value = _readSetOperationStmt();
|
2002-12-12 16:49:42 +01:00
|
|
|
else if (MATCH("ALIAS", 5))
|
|
|
|
return_value = _readAlias();
|
|
|
|
else if (MATCH("RANGEVAR", 8))
|
|
|
|
return_value = _readRangeVar();
|
2007-02-20 18:32:18 +01:00
|
|
|
else if (MATCH("INTOCLAUSE", 10))
|
|
|
|
return_value = _readIntoClause();
|
2002-12-12 16:49:42 +01:00
|
|
|
else if (MATCH("VAR", 3))
|
|
|
|
return_value = _readVar();
|
|
|
|
else if (MATCH("CONST", 5))
|
|
|
|
return_value = _readConst();
|
|
|
|
else if (MATCH("PARAM", 5))
|
|
|
|
return_value = _readParam();
|
|
|
|
else if (MATCH("AGGREF", 6))
|
|
|
|
return_value = _readAggref();
|
2008-12-28 19:54:01 +01:00
|
|
|
else if (MATCH("WINDOWFUNC", 10))
|
|
|
|
return_value = _readWindowFunc();
|
2002-12-12 16:49:42 +01:00
|
|
|
else if (MATCH("ARRAYREF", 8))
|
|
|
|
return_value = _readArrayRef();
|
|
|
|
else if (MATCH("FUNCEXPR", 8))
|
|
|
|
return_value = _readFuncExpr();
|
2009-10-08 04:39:25 +02:00
|
|
|
else if (MATCH("NAMEDARGEXPR", 12))
|
|
|
|
return_value = _readNamedArgExpr();
|
2002-12-12 16:49:42 +01:00
|
|
|
else if (MATCH("OPEXPR", 6))
|
|
|
|
return_value = _readOpExpr();
|
|
|
|
else if (MATCH("DISTINCTEXPR", 12))
|
|
|
|
return_value = _readDistinctExpr();
|
2011-03-20 01:29:08 +01:00
|
|
|
else if (MATCH("NULLIFEXPR", 10))
|
|
|
|
return_value = _readNullIfExpr();
|
2003-06-29 02:33:44 +02:00
|
|
|
else if (MATCH("SCALARARRAYOPEXPR", 17))
|
|
|
|
return_value = _readScalarArrayOpExpr();
|
2002-12-12 16:49:42 +01:00
|
|
|
else if (MATCH("BOOLEXPR", 8))
|
|
|
|
return_value = _readBoolExpr();
|
|
|
|
else if (MATCH("SUBLINK", 7))
|
|
|
|
return_value = _readSubLink();
|
|
|
|
else if (MATCH("FIELDSELECT", 11))
|
|
|
|
return_value = _readFieldSelect();
|
2004-06-09 21:08:20 +02:00
|
|
|
else if (MATCH("FIELDSTORE", 10))
|
|
|
|
return_value = _readFieldStore();
|
2002-12-12 16:49:42 +01:00
|
|
|
else if (MATCH("RELABELTYPE", 11))
|
|
|
|
return_value = _readRelabelType();
|
2007-06-05 23:31:09 +02:00
|
|
|
else if (MATCH("COERCEVIAIO", 11))
|
|
|
|
return_value = _readCoerceViaIO();
|
2007-03-28 01:21:12 +02:00
|
|
|
else if (MATCH("ARRAYCOERCEEXPR", 15))
|
|
|
|
return_value = _readArrayCoerceExpr();
|
2004-12-12 00:26:51 +01:00
|
|
|
else if (MATCH("CONVERTROWTYPEEXPR", 18))
|
|
|
|
return_value = _readConvertRowtypeExpr();
|
2011-03-11 22:27:51 +01:00
|
|
|
else if (MATCH("COLLATE", 7))
|
|
|
|
return_value = _readCollateExpr();
|
2002-11-25 19:12:12 +01:00
|
|
|
else if (MATCH("CASE", 4))
|
1998-12-14 01:02:17 +01:00
|
|
|
return_value = _readCaseExpr();
|
2002-11-25 19:12:12 +01:00
|
|
|
else if (MATCH("WHEN", 4))
|
1998-12-14 01:02:17 +01:00
|
|
|
return_value = _readCaseWhen();
|
2004-03-17 21:48:43 +01:00
|
|
|
else if (MATCH("CASETESTEXPR", 12))
|
|
|
|
return_value = _readCaseTestExpr();
|
2003-04-09 01:20:04 +02:00
|
|
|
else if (MATCH("ARRAY", 5))
|
|
|
|
return_value = _readArrayExpr();
|
2004-05-11 00:44:49 +02:00
|
|
|
else if (MATCH("ROW", 3))
|
|
|
|
return_value = _readRowExpr();
|
2005-12-28 02:30:02 +01:00
|
|
|
else if (MATCH("ROWCOMPARE", 10))
|
|
|
|
return_value = _readRowCompareExpr();
|
2003-02-16 03:30:39 +01:00
|
|
|
else if (MATCH("COALESCE", 8))
|
|
|
|
return_value = _readCoalesceExpr();
|
2005-06-27 00:05:42 +02:00
|
|
|
else if (MATCH("MINMAX", 6))
|
|
|
|
return_value = _readMinMaxExpr();
|
2006-12-24 01:29:20 +01:00
|
|
|
else if (MATCH("XMLEXPR", 7))
|
|
|
|
return_value = _readXmlExpr();
|
2002-11-25 19:12:12 +01:00
|
|
|
else if (MATCH("NULLTEST", 8))
|
2001-06-20 00:39:12 +02:00
|
|
|
return_value = _readNullTest();
|
2002-11-25 19:12:12 +01:00
|
|
|
else if (MATCH("BOOLEANTEST", 11))
|
2001-06-20 00:39:12 +02:00
|
|
|
return_value = _readBooleanTest();
|
2003-02-03 22:15:45 +01:00
|
|
|
else if (MATCH("COERCETODOMAIN", 14))
|
|
|
|
return_value = _readCoerceToDomain();
|
|
|
|
else if (MATCH("COERCETODOMAINVALUE", 19))
|
|
|
|
return_value = _readCoerceToDomainValue();
|
2003-07-03 18:34:26 +02:00
|
|
|
else if (MATCH("SETTODEFAULT", 12))
|
|
|
|
return_value = _readSetToDefault();
|
2007-06-11 03:16:30 +02:00
|
|
|
else if (MATCH("CURRENTOFEXPR", 13))
|
|
|
|
return_value = _readCurrentOfExpr();
|
Add support for INSERT ... ON CONFLICT DO NOTHING/UPDATE.
The newly added ON CONFLICT clause allows to specify an alternative to
raising a unique or exclusion constraint violation error when inserting.
ON CONFLICT refers to constraints that can either be specified using a
inference clause (by specifying the columns of a unique constraint) or
by naming a unique or exclusion constraint. DO NOTHING avoids the
constraint violation, without touching the pre-existing row. DO UPDATE
SET ... [WHERE ...] updates the pre-existing tuple, and has access to
both the tuple proposed for insertion and the existing tuple; the
optional WHERE clause can be used to prevent an update from being
executed. The UPDATE SET and WHERE clauses have access to the tuple
proposed for insertion using the "magic" EXCLUDED alias, and to the
pre-existing tuple using the table name or its alias.
This feature is often referred to as upsert.
This is implemented using a new infrastructure called "speculative
insertion". It is an optimistic variant of regular insertion that first
does a pre-check for existing tuples and then attempts an insert. If a
violating tuple was inserted concurrently, the speculatively inserted
tuple is deleted and a new attempt is made. If the pre-check finds a
matching tuple the alternative DO NOTHING or DO UPDATE action is taken.
If the insertion succeeds without detecting a conflict, the tuple is
deemed inserted.
To handle the possible ambiguity between the excluded alias and a table
named excluded, and for convenience with long relation names, INSERT
INTO now can alias its target table.
Bumps catversion as stored rules change.
Author: Peter Geoghegan, with significant contributions from Heikki
Linnakangas and Andres Freund. Testing infrastructure by Jeff Janes.
Reviewed-By: Heikki Linnakangas, Andres Freund, Robert Haas, Simon Riggs,
Dean Rasheed, Stephen Frost and many others.
2015-05-08 05:31:36 +02:00
|
|
|
else if (MATCH("INFERENCEELEM", 13))
|
|
|
|
return_value = _readInferenceElem();
|
2002-12-12 16:49:42 +01:00
|
|
|
else if (MATCH("TARGETENTRY", 11))
|
|
|
|
return_value = _readTargetEntry();
|
|
|
|
else if (MATCH("RANGETBLREF", 11))
|
|
|
|
return_value = _readRangeTblRef();
|
|
|
|
else if (MATCH("JOINEXPR", 8))
|
|
|
|
return_value = _readJoinExpr();
|
|
|
|
else if (MATCH("FROMEXPR", 8))
|
|
|
|
return_value = _readFromExpr();
|
Add support for INSERT ... ON CONFLICT DO NOTHING/UPDATE.
The newly added ON CONFLICT clause allows to specify an alternative to
raising a unique or exclusion constraint violation error when inserting.
ON CONFLICT refers to constraints that can either be specified using a
inference clause (by specifying the columns of a unique constraint) or
by naming a unique or exclusion constraint. DO NOTHING avoids the
constraint violation, without touching the pre-existing row. DO UPDATE
SET ... [WHERE ...] updates the pre-existing tuple, and has access to
both the tuple proposed for insertion and the existing tuple; the
optional WHERE clause can be used to prevent an update from being
executed. The UPDATE SET and WHERE clauses have access to the tuple
proposed for insertion using the "magic" EXCLUDED alias, and to the
pre-existing tuple using the table name or its alias.
This feature is often referred to as upsert.
This is implemented using a new infrastructure called "speculative
insertion". It is an optimistic variant of regular insertion that first
does a pre-check for existing tuples and then attempts an insert. If a
violating tuple was inserted concurrently, the speculatively inserted
tuple is deleted and a new attempt is made. If the pre-check finds a
matching tuple the alternative DO NOTHING or DO UPDATE action is taken.
If the insertion succeeds without detecting a conflict, the tuple is
deemed inserted.
To handle the possible ambiguity between the excluded alias and a table
named excluded, and for convenience with long relation names, INSERT
INTO now can alias its target table.
Bumps catversion as stored rules change.
Author: Peter Geoghegan, with significant contributions from Heikki
Linnakangas and Andres Freund. Testing infrastructure by Jeff Janes.
Reviewed-By: Heikki Linnakangas, Andres Freund, Robert Haas, Simon Riggs,
Dean Rasheed, Stephen Frost and many others.
2015-05-08 05:31:36 +02:00
|
|
|
else if (MATCH("ONCONFLICTEXPR", 14))
|
|
|
|
return_value = _readOnConflictExpr();
|
2002-12-12 16:49:42 +01:00
|
|
|
else if (MATCH("RTE", 3))
|
|
|
|
return_value = _readRangeTblEntry();
|
Support multi-argument UNNEST(), and TABLE() syntax for multiple functions.
This patch adds the ability to write TABLE( function1(), function2(), ...)
as a single FROM-clause entry. The result is the concatenation of the
first row from each function, followed by the second row from each
function, etc; with NULLs inserted if any function produces fewer rows than
others. This is believed to be a much more useful behavior than what
Postgres currently does with multiple SRFs in a SELECT list.
This syntax also provides a reasonable way to combine use of column
definition lists with WITH ORDINALITY: put the column definition list
inside TABLE(), where it's clear that it doesn't control the ordinality
column as well.
Also implement SQL-compliant multiple-argument UNNEST(), by turning
UNNEST(a,b,c) into TABLE(unnest(a), unnest(b), unnest(c)).
The SQL standard specifies TABLE() with only a single function, not
multiple functions, and it seems to require an implicit UNNEST() which is
not what this patch does. There may be something wrong with that reading
of the spec, though, because if it's right then the spec's TABLE() is just
a pointless alternative spelling of UNNEST(). After further review of
that, we might choose to adopt a different syntax for what this patch does,
but in any case this functionality seems clearly worthwhile.
Andrew Gierth, reviewed by Zoltán Böszörményi and Heikki Linnakangas, and
significantly revised by me
2013-11-22 01:37:02 +01:00
|
|
|
else if (MATCH("RANGETBLFUNCTION", 16))
|
|
|
|
return_value = _readRangeTblFunction();
|
2003-03-10 04:53:52 +01:00
|
|
|
else if (MATCH("NOTIFY", 6))
|
|
|
|
return_value = _readNotifyStmt();
|
|
|
|
else if (MATCH("DECLARECURSOR", 13))
|
|
|
|
return_value = _readDeclareCursorStmt();
|
1997-09-07 07:04:48 +02:00
|
|
|
else
|
2002-11-25 19:12:12 +01:00
|
|
|
{
|
|
|
|
elog(ERROR, "badly formatted node string \"%.32s\"...", token);
|
|
|
|
return_value = NULL; /* keep compiler quiet */
|
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return (Node *) return_value;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/*
|
|
|
|
* readDatum
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2001-01-07 02:08:48 +01:00
|
|
|
* Given a string representation of a constant, recreate the appropriate
|
|
|
|
* Datum. The string representation embeds length info, but not byValue,
|
|
|
|
* so we must be told that.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
static Datum
|
2001-01-07 02:08:48 +01:00
|
|
|
readDatum(bool typbyval)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2001-01-08 01:31:43 +01:00
|
|
|
Size length,
|
|
|
|
i;
|
1997-09-08 04:41:22 +02:00
|
|
|
int tokenLength;
|
|
|
|
char *token;
|
|
|
|
Datum res;
|
|
|
|
char *s;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* read the actual length of the value
|
|
|
|
*/
|
2001-01-07 02:08:48 +01:00
|
|
|
token = pg_strtok(&tokenLength);
|
2001-01-08 01:31:43 +01:00
|
|
|
length = atoui(token);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2001-07-03 18:52:48 +02:00
|
|
|
token = pg_strtok(&tokenLength); /* read the '[' */
|
|
|
|
if (token == NULL || token[0] != '[')
|
2014-01-23 23:18:23 +01:00
|
|
|
elog(ERROR, "expected \"[\" to start datum, but got \"%s\"; length = %zu",
|
|
|
|
token ? (const char *) token : "[NULL]", length);
|
2001-01-07 02:08:48 +01:00
|
|
|
|
|
|
|
if (typbyval)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
2001-01-08 01:31:43 +01:00
|
|
|
if (length > (Size) sizeof(Datum))
|
2014-01-23 23:18:23 +01:00
|
|
|
elog(ERROR, "byval datum but length = %zu", length);
|
2000-01-14 01:53:21 +01:00
|
|
|
res = (Datum) 0;
|
1997-09-07 07:04:48 +02:00
|
|
|
s = (char *) (&res);
|
2001-01-08 01:31:43 +01:00
|
|
|
for (i = 0; i < (Size) sizeof(Datum); i++)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
2001-01-07 02:08:48 +01:00
|
|
|
token = pg_strtok(&tokenLength);
|
1997-09-07 07:04:48 +02:00
|
|
|
s[i] = (char) atoi(token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (length <= 0)
|
2000-01-14 01:53:21 +01:00
|
|
|
res = (Datum) NULL;
|
|
|
|
else
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
|
|
|
s = (char *) palloc(length);
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
{
|
2001-01-07 02:08:48 +01:00
|
|
|
token = pg_strtok(&tokenLength);
|
1997-09-07 07:04:48 +02:00
|
|
|
s[i] = (char) atoi(token);
|
|
|
|
}
|
|
|
|
res = PointerGetDatum(s);
|
|
|
|
}
|
|
|
|
|
2001-07-03 18:52:48 +02:00
|
|
|
token = pg_strtok(&tokenLength); /* read the ']' */
|
2001-01-07 02:08:48 +01:00
|
|
|
if (token == NULL || token[0] != ']')
|
2014-01-23 23:18:23 +01:00
|
|
|
elog(ERROR, "expected \"]\" to end datum, but got \"%s\"; length = %zu",
|
|
|
|
token ? (const char *) token : "[NULL]", length);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return res;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|