2002-11-25 19:12:12 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* outfuncs.c
|
2002-11-25 19:12:12 +01:00
|
|
|
* Output functions for Postgres tree nodes.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
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-07-09 08:22:35 +02:00
|
|
|
*
|
2002-11-25 19:12:12 +01:00
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/backend/nodes/outfuncs.c
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2002-11-25 19:12:12 +01:00
|
|
|
*-------------------------------------------------------------------------
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1999-07-17 22:18:55 +02:00
|
|
|
#include "postgres.h"
|
2000-01-14 01:53:21 +01:00
|
|
|
|
2000-10-31 11:22:13 +01:00
|
|
|
#include <ctype.h>
|
|
|
|
|
Make serialization of Nodes' scalar-array fields more robust.
When the ability to print variable-length-array fields was first
added to outfuncs.c, there was no corresponding read capability,
as it was used only for debug dumps of planner-internal Nodes.
Not a lot of thought seems to have been put into the output format:
it's just the space-separated array elements and nothing else.
Later such fields appeared in Plan nodes, and still later we grew
read support so that Plans could be transferred to parallel workers,
but the original text format wasn't rethought. It seems inadequate
to me because (a) no cross-check is possible that we got the right
number of array entries, (b) we can't tell the difference between
a NULL pointer and a zero-length array, and (c) except for
WRITE_INDEX_ARRAY, we'd crash if a non-zero length is specified
when the pointer is NULL, a situation that can arise in some fields
that we currently conveniently avoid printing.
Since we're currently in a campaign to make the Node infrastructure
generally more it-just-works-without-thinking-about-it, now seems
like a good time to improve this.
Let's adopt a format similar to that used for Lists, that is "<>"
for a NULL pointer or "(item item item)" otherwise. Also retool
the code to not have so many copies of the identical logic.
I bumped catversion out of an abundance of caution, although I think
that we don't use any such array fields in Nodes that can get into
the catalogs.
Discussion: https://postgr.es/m/1528424.1658272135@sss.pgh.pa.us
2022-07-20 19:04:33 +02:00
|
|
|
#include "access/attnum.h"
|
2012-03-05 22:15:59 +01:00
|
|
|
#include "lib/stringinfo.h"
|
2018-12-10 17:12:43 +01:00
|
|
|
#include "miscadmin.h"
|
Automatically generate node support functions
Add a script to automatically generate the node support functions
(copy, equal, out, and read, as well as the node tags enum) from the
struct definitions.
For each of the four node support files, it creates two include files,
e.g., copyfuncs.funcs.c and copyfuncs.switch.c, to include in the main
file. All the scaffolding of the main file stays in place.
I have tried to mostly make the coverage of the output match what is
currently there. For example, one could now do out/read coverage of
utility statement nodes, but I have manually excluded those for now.
The reason is mainly that it's easier to diff the before and after,
and adding a bunch of stuff like this might require a separate
analysis and review.
Subtyping (TidScan -> Scan) is supported.
For the hard cases, you can just write a manual function and exclude
generating one. For the not so hard cases, there is a way of
annotating struct fields to get special behaviors. For example,
pg_node_attr(equal_ignore) has the field ignored in equal functions.
(In this patch, I have only ifdef'ed out the code to could be removed,
mainly so that it won't constantly have merge conflicts. It will be
deleted in a separate patch. All the code comments that are worth
keeping from those sections have already been moved to the header
files where the structs are defined.)
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/c1097590-a6a4-486a-64b1-e1f9cc0533ce%40enterprisedb.com
2022-07-09 08:52:19 +02:00
|
|
|
#include "nodes/bitmapset.h"
|
|
|
|
#include "nodes/nodes.h"
|
|
|
|
#include "nodes/pg_list.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "utils/datum.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2017-06-22 04:57:23 +02:00
|
|
|
static void outChar(StringInfo str, char c);
|
|
|
|
|
1998-05-10 01:46:35 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/*
|
|
|
|
* Macros to simplify output of different kinds of fields. Use these
|
|
|
|
* wherever possible to reduce the chance for silly typos. Note that these
|
|
|
|
* hard-wire conventions about the names of the local variables in an Out
|
|
|
|
* routine.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Write the label for the node type */
|
|
|
|
#define WRITE_NODE_TYPE(nodelabel) \
|
2003-04-24 23:16:45 +02:00
|
|
|
appendStringInfoString(str, nodelabel)
|
2002-11-25 19:12:12 +01:00
|
|
|
|
|
|
|
/* Write an integer field (anything written as ":fldname %d") */
|
|
|
|
#define WRITE_INT_FIELD(fldname) \
|
|
|
|
appendStringInfo(str, " :" CppAsString(fldname) " %d", node->fldname)
|
|
|
|
|
|
|
|
/* Write an unsigned integer field (anything written as ":fldname %u") */
|
|
|
|
#define WRITE_UINT_FIELD(fldname) \
|
|
|
|
appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)
|
|
|
|
|
2017-10-12 01:52:46 +02:00
|
|
|
/* Write an unsigned integer field (anything written with UINT64_FORMAT) */
|
|
|
|
#define WRITE_UINT64_FIELD(fldname) \
|
|
|
|
appendStringInfo(str, " :" CppAsString(fldname) " " UINT64_FORMAT, \
|
|
|
|
node->fldname)
|
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/* Write an OID field (don't hard-wire assumption that OID is same as uint) */
|
|
|
|
#define WRITE_OID_FIELD(fldname) \
|
|
|
|
appendStringInfo(str, " :" CppAsString(fldname) " %u", node->fldname)
|
|
|
|
|
|
|
|
/* Write a long-integer field */
|
|
|
|
#define WRITE_LONG_FIELD(fldname) \
|
|
|
|
appendStringInfo(str, " :" CppAsString(fldname) " %ld", node->fldname)
|
|
|
|
|
|
|
|
/* Write a char field (ie, one ascii character) */
|
|
|
|
#define WRITE_CHAR_FIELD(fldname) \
|
2017-06-22 04:57:23 +02:00
|
|
|
(appendStringInfo(str, " :" CppAsString(fldname) " "), \
|
|
|
|
outChar(str, node->fldname))
|
2002-11-25 19:12:12 +01:00
|
|
|
|
|
|
|
/* Write an enumerated-type field as an integer code */
|
|
|
|
#define WRITE_ENUM_FIELD(fldname, enumtype) \
|
|
|
|
appendStringInfo(str, " :" CppAsString(fldname) " %d", \
|
|
|
|
(int) node->fldname)
|
|
|
|
|
|
|
|
/* Write a float field --- caller must give format to define precision */
|
|
|
|
#define WRITE_FLOAT_FIELD(fldname,format) \
|
|
|
|
appendStringInfo(str, " :" CppAsString(fldname) " " format, node->fldname)
|
|
|
|
|
|
|
|
/* Write a boolean field */
|
|
|
|
#define WRITE_BOOL_FIELD(fldname) \
|
|
|
|
appendStringInfo(str, " :" CppAsString(fldname) " %s", \
|
|
|
|
booltostr(node->fldname))
|
|
|
|
|
|
|
|
/* Write a character-string (possibly NULL) field */
|
|
|
|
#define WRITE_STRING_FIELD(fldname) \
|
2017-08-16 05:34:39 +02:00
|
|
|
(appendStringInfoString(str, " :" CppAsString(fldname) " "), \
|
2016-09-16 15:36:19 +02:00
|
|
|
outToken(str, node->fldname))
|
2002-11-25 19:12:12 +01:00
|
|
|
|
2008-08-29 01:09:48 +02:00
|
|
|
/* Write a parse location field (actually same as INT case) */
|
|
|
|
#define WRITE_LOCATION_FIELD(fldname) \
|
|
|
|
appendStringInfo(str, " :" CppAsString(fldname) " %d", node->fldname)
|
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/* Write a Node field */
|
|
|
|
#define WRITE_NODE_FIELD(fldname) \
|
2017-08-16 05:34:39 +02:00
|
|
|
(appendStringInfoString(str, " :" CppAsString(fldname) " "), \
|
2016-04-08 23:26:36 +02:00
|
|
|
outNode(str, node->fldname))
|
2002-11-25 19:12:12 +01:00
|
|
|
|
2003-02-08 21:20:55 +01:00
|
|
|
/* Write a bitmapset field */
|
|
|
|
#define WRITE_BITMAPSET_FIELD(fldname) \
|
2017-08-16 05:34:39 +02:00
|
|
|
(appendStringInfoString(str, " :" CppAsString(fldname) " "), \
|
2016-09-16 15:36:19 +02:00
|
|
|
outBitmapset(str, node->fldname))
|
2003-02-08 21:20:55 +01:00
|
|
|
|
2022-07-20 19:54:25 +02:00
|
|
|
/* Write a variable-length array (not a List) of Node pointers */
|
|
|
|
#define WRITE_NODE_ARRAY(fldname, len) \
|
|
|
|
(appendStringInfoString(str, " :" CppAsString(fldname) " "), \
|
|
|
|
writeNodeArray(str, (const Node * const *) node->fldname, len))
|
|
|
|
|
Make serialization of Nodes' scalar-array fields more robust.
When the ability to print variable-length-array fields was first
added to outfuncs.c, there was no corresponding read capability,
as it was used only for debug dumps of planner-internal Nodes.
Not a lot of thought seems to have been put into the output format:
it's just the space-separated array elements and nothing else.
Later such fields appeared in Plan nodes, and still later we grew
read support so that Plans could be transferred to parallel workers,
but the original text format wasn't rethought. It seems inadequate
to me because (a) no cross-check is possible that we got the right
number of array entries, (b) we can't tell the difference between
a NULL pointer and a zero-length array, and (c) except for
WRITE_INDEX_ARRAY, we'd crash if a non-zero length is specified
when the pointer is NULL, a situation that can arise in some fields
that we currently conveniently avoid printing.
Since we're currently in a campaign to make the Node infrastructure
generally more it-just-works-without-thinking-about-it, now seems
like a good time to improve this.
Let's adopt a format similar to that used for Lists, that is "<>"
for a NULL pointer or "(item item item)" otherwise. Also retool
the code to not have so many copies of the identical logic.
I bumped catversion out of an abundance of caution, although I think
that we don't use any such array fields in Nodes that can get into
the catalogs.
Discussion: https://postgr.es/m/1528424.1658272135@sss.pgh.pa.us
2022-07-20 19:04:33 +02:00
|
|
|
/* Write a variable-length array of AttrNumber */
|
2018-12-22 06:53:37 +01:00
|
|
|
#define WRITE_ATTRNUMBER_ARRAY(fldname, len) \
|
Make serialization of Nodes' scalar-array fields more robust.
When the ability to print variable-length-array fields was first
added to outfuncs.c, there was no corresponding read capability,
as it was used only for debug dumps of planner-internal Nodes.
Not a lot of thought seems to have been put into the output format:
it's just the space-separated array elements and nothing else.
Later such fields appeared in Plan nodes, and still later we grew
read support so that Plans could be transferred to parallel workers,
but the original text format wasn't rethought. It seems inadequate
to me because (a) no cross-check is possible that we got the right
number of array entries, (b) we can't tell the difference between
a NULL pointer and a zero-length array, and (c) except for
WRITE_INDEX_ARRAY, we'd crash if a non-zero length is specified
when the pointer is NULL, a situation that can arise in some fields
that we currently conveniently avoid printing.
Since we're currently in a campaign to make the Node infrastructure
generally more it-just-works-without-thinking-about-it, now seems
like a good time to improve this.
Let's adopt a format similar to that used for Lists, that is "<>"
for a NULL pointer or "(item item item)" otherwise. Also retool
the code to not have so many copies of the identical logic.
I bumped catversion out of an abundance of caution, although I think
that we don't use any such array fields in Nodes that can get into
the catalogs.
Discussion: https://postgr.es/m/1528424.1658272135@sss.pgh.pa.us
2022-07-20 19:04:33 +02:00
|
|
|
(appendStringInfoString(str, " :" CppAsString(fldname) " "), \
|
|
|
|
writeAttrNumberCols(str, node->fldname, len))
|
2018-12-22 06:53:37 +01:00
|
|
|
|
Make serialization of Nodes' scalar-array fields more robust.
When the ability to print variable-length-array fields was first
added to outfuncs.c, there was no corresponding read capability,
as it was used only for debug dumps of planner-internal Nodes.
Not a lot of thought seems to have been put into the output format:
it's just the space-separated array elements and nothing else.
Later such fields appeared in Plan nodes, and still later we grew
read support so that Plans could be transferred to parallel workers,
but the original text format wasn't rethought. It seems inadequate
to me because (a) no cross-check is possible that we got the right
number of array entries, (b) we can't tell the difference between
a NULL pointer and a zero-length array, and (c) except for
WRITE_INDEX_ARRAY, we'd crash if a non-zero length is specified
when the pointer is NULL, a situation that can arise in some fields
that we currently conveniently avoid printing.
Since we're currently in a campaign to make the Node infrastructure
generally more it-just-works-without-thinking-about-it, now seems
like a good time to improve this.
Let's adopt a format similar to that used for Lists, that is "<>"
for a NULL pointer or "(item item item)" otherwise. Also retool
the code to not have so many copies of the identical logic.
I bumped catversion out of an abundance of caution, although I think
that we don't use any such array fields in Nodes that can get into
the catalogs.
Discussion: https://postgr.es/m/1528424.1658272135@sss.pgh.pa.us
2022-07-20 19:04:33 +02:00
|
|
|
/* Write a variable-length array of Oid */
|
2018-12-22 06:53:37 +01:00
|
|
|
#define WRITE_OID_ARRAY(fldname, len) \
|
Make serialization of Nodes' scalar-array fields more robust.
When the ability to print variable-length-array fields was first
added to outfuncs.c, there was no corresponding read capability,
as it was used only for debug dumps of planner-internal Nodes.
Not a lot of thought seems to have been put into the output format:
it's just the space-separated array elements and nothing else.
Later such fields appeared in Plan nodes, and still later we grew
read support so that Plans could be transferred to parallel workers,
but the original text format wasn't rethought. It seems inadequate
to me because (a) no cross-check is possible that we got the right
number of array entries, (b) we can't tell the difference between
a NULL pointer and a zero-length array, and (c) except for
WRITE_INDEX_ARRAY, we'd crash if a non-zero length is specified
when the pointer is NULL, a situation that can arise in some fields
that we currently conveniently avoid printing.
Since we're currently in a campaign to make the Node infrastructure
generally more it-just-works-without-thinking-about-it, now seems
like a good time to improve this.
Let's adopt a format similar to that used for Lists, that is "<>"
for a NULL pointer or "(item item item)" otherwise. Also retool
the code to not have so many copies of the identical logic.
I bumped catversion out of an abundance of caution, although I think
that we don't use any such array fields in Nodes that can get into
the catalogs.
Discussion: https://postgr.es/m/1528424.1658272135@sss.pgh.pa.us
2022-07-20 19:04:33 +02:00
|
|
|
(appendStringInfoString(str, " :" CppAsString(fldname) " "), \
|
|
|
|
writeOidCols(str, node->fldname, len))
|
2018-12-22 06:53:37 +01:00
|
|
|
|
Make serialization of Nodes' scalar-array fields more robust.
When the ability to print variable-length-array fields was first
added to outfuncs.c, there was no corresponding read capability,
as it was used only for debug dumps of planner-internal Nodes.
Not a lot of thought seems to have been put into the output format:
it's just the space-separated array elements and nothing else.
Later such fields appeared in Plan nodes, and still later we grew
read support so that Plans could be transferred to parallel workers,
but the original text format wasn't rethought. It seems inadequate
to me because (a) no cross-check is possible that we got the right
number of array entries, (b) we can't tell the difference between
a NULL pointer and a zero-length array, and (c) except for
WRITE_INDEX_ARRAY, we'd crash if a non-zero length is specified
when the pointer is NULL, a situation that can arise in some fields
that we currently conveniently avoid printing.
Since we're currently in a campaign to make the Node infrastructure
generally more it-just-works-without-thinking-about-it, now seems
like a good time to improve this.
Let's adopt a format similar to that used for Lists, that is "<>"
for a NULL pointer or "(item item item)" otherwise. Also retool
the code to not have so many copies of the identical logic.
I bumped catversion out of an abundance of caution, although I think
that we don't use any such array fields in Nodes that can get into
the catalogs.
Discussion: https://postgr.es/m/1528424.1658272135@sss.pgh.pa.us
2022-07-20 19:04:33 +02:00
|
|
|
/* Write a variable-length array of Index */
|
2021-09-14 09:34:50 +02:00
|
|
|
#define WRITE_INDEX_ARRAY(fldname, len) \
|
Make serialization of Nodes' scalar-array fields more robust.
When the ability to print variable-length-array fields was first
added to outfuncs.c, there was no corresponding read capability,
as it was used only for debug dumps of planner-internal Nodes.
Not a lot of thought seems to have been put into the output format:
it's just the space-separated array elements and nothing else.
Later such fields appeared in Plan nodes, and still later we grew
read support so that Plans could be transferred to parallel workers,
but the original text format wasn't rethought. It seems inadequate
to me because (a) no cross-check is possible that we got the right
number of array entries, (b) we can't tell the difference between
a NULL pointer and a zero-length array, and (c) except for
WRITE_INDEX_ARRAY, we'd crash if a non-zero length is specified
when the pointer is NULL, a situation that can arise in some fields
that we currently conveniently avoid printing.
Since we're currently in a campaign to make the Node infrastructure
generally more it-just-works-without-thinking-about-it, now seems
like a good time to improve this.
Let's adopt a format similar to that used for Lists, that is "<>"
for a NULL pointer or "(item item item)" otherwise. Also retool
the code to not have so many copies of the identical logic.
I bumped catversion out of an abundance of caution, although I think
that we don't use any such array fields in Nodes that can get into
the catalogs.
Discussion: https://postgr.es/m/1528424.1658272135@sss.pgh.pa.us
2022-07-20 19:04:33 +02:00
|
|
|
(appendStringInfoString(str, " :" CppAsString(fldname) " "), \
|
|
|
|
writeIndexCols(str, node->fldname, len))
|
2021-09-14 09:34:50 +02:00
|
|
|
|
Make serialization of Nodes' scalar-array fields more robust.
When the ability to print variable-length-array fields was first
added to outfuncs.c, there was no corresponding read capability,
as it was used only for debug dumps of planner-internal Nodes.
Not a lot of thought seems to have been put into the output format:
it's just the space-separated array elements and nothing else.
Later such fields appeared in Plan nodes, and still later we grew
read support so that Plans could be transferred to parallel workers,
but the original text format wasn't rethought. It seems inadequate
to me because (a) no cross-check is possible that we got the right
number of array entries, (b) we can't tell the difference between
a NULL pointer and a zero-length array, and (c) except for
WRITE_INDEX_ARRAY, we'd crash if a non-zero length is specified
when the pointer is NULL, a situation that can arise in some fields
that we currently conveniently avoid printing.
Since we're currently in a campaign to make the Node infrastructure
generally more it-just-works-without-thinking-about-it, now seems
like a good time to improve this.
Let's adopt a format similar to that used for Lists, that is "<>"
for a NULL pointer or "(item item item)" otherwise. Also retool
the code to not have so many copies of the identical logic.
I bumped catversion out of an abundance of caution, although I think
that we don't use any such array fields in Nodes that can get into
the catalogs.
Discussion: https://postgr.es/m/1528424.1658272135@sss.pgh.pa.us
2022-07-20 19:04:33 +02:00
|
|
|
/* Write a variable-length array of int */
|
2018-12-22 06:53:37 +01:00
|
|
|
#define WRITE_INT_ARRAY(fldname, len) \
|
Make serialization of Nodes' scalar-array fields more robust.
When the ability to print variable-length-array fields was first
added to outfuncs.c, there was no corresponding read capability,
as it was used only for debug dumps of planner-internal Nodes.
Not a lot of thought seems to have been put into the output format:
it's just the space-separated array elements and nothing else.
Later such fields appeared in Plan nodes, and still later we grew
read support so that Plans could be transferred to parallel workers,
but the original text format wasn't rethought. It seems inadequate
to me because (a) no cross-check is possible that we got the right
number of array entries, (b) we can't tell the difference between
a NULL pointer and a zero-length array, and (c) except for
WRITE_INDEX_ARRAY, we'd crash if a non-zero length is specified
when the pointer is NULL, a situation that can arise in some fields
that we currently conveniently avoid printing.
Since we're currently in a campaign to make the Node infrastructure
generally more it-just-works-without-thinking-about-it, now seems
like a good time to improve this.
Let's adopt a format similar to that used for Lists, that is "<>"
for a NULL pointer or "(item item item)" otherwise. Also retool
the code to not have so many copies of the identical logic.
I bumped catversion out of an abundance of caution, although I think
that we don't use any such array fields in Nodes that can get into
the catalogs.
Discussion: https://postgr.es/m/1528424.1658272135@sss.pgh.pa.us
2022-07-20 19:04:33 +02:00
|
|
|
(appendStringInfoString(str, " :" CppAsString(fldname) " "), \
|
|
|
|
writeIntCols(str, node->fldname, len))
|
2018-12-22 06:53:37 +01:00
|
|
|
|
Make serialization of Nodes' scalar-array fields more robust.
When the ability to print variable-length-array fields was first
added to outfuncs.c, there was no corresponding read capability,
as it was used only for debug dumps of planner-internal Nodes.
Not a lot of thought seems to have been put into the output format:
it's just the space-separated array elements and nothing else.
Later such fields appeared in Plan nodes, and still later we grew
read support so that Plans could be transferred to parallel workers,
but the original text format wasn't rethought. It seems inadequate
to me because (a) no cross-check is possible that we got the right
number of array entries, (b) we can't tell the difference between
a NULL pointer and a zero-length array, and (c) except for
WRITE_INDEX_ARRAY, we'd crash if a non-zero length is specified
when the pointer is NULL, a situation that can arise in some fields
that we currently conveniently avoid printing.
Since we're currently in a campaign to make the Node infrastructure
generally more it-just-works-without-thinking-about-it, now seems
like a good time to improve this.
Let's adopt a format similar to that used for Lists, that is "<>"
for a NULL pointer or "(item item item)" otherwise. Also retool
the code to not have so many copies of the identical logic.
I bumped catversion out of an abundance of caution, although I think
that we don't use any such array fields in Nodes that can get into
the catalogs.
Discussion: https://postgr.es/m/1528424.1658272135@sss.pgh.pa.us
2022-07-20 19:04:33 +02:00
|
|
|
/* Write a variable-length array of bool */
|
2018-12-22 06:53:37 +01:00
|
|
|
#define WRITE_BOOL_ARRAY(fldname, len) \
|
Make serialization of Nodes' scalar-array fields more robust.
When the ability to print variable-length-array fields was first
added to outfuncs.c, there was no corresponding read capability,
as it was used only for debug dumps of planner-internal Nodes.
Not a lot of thought seems to have been put into the output format:
it's just the space-separated array elements and nothing else.
Later such fields appeared in Plan nodes, and still later we grew
read support so that Plans could be transferred to parallel workers,
but the original text format wasn't rethought. It seems inadequate
to me because (a) no cross-check is possible that we got the right
number of array entries, (b) we can't tell the difference between
a NULL pointer and a zero-length array, and (c) except for
WRITE_INDEX_ARRAY, we'd crash if a non-zero length is specified
when the pointer is NULL, a situation that can arise in some fields
that we currently conveniently avoid printing.
Since we're currently in a campaign to make the Node infrastructure
generally more it-just-works-without-thinking-about-it, now seems
like a good time to improve this.
Let's adopt a format similar to that used for Lists, that is "<>"
for a NULL pointer or "(item item item)" otherwise. Also retool
the code to not have so many copies of the identical logic.
I bumped catversion out of an abundance of caution, although I think
that we don't use any such array fields in Nodes that can get into
the catalogs.
Discussion: https://postgr.es/m/1528424.1658272135@sss.pgh.pa.us
2022-07-20 19:04:33 +02:00
|
|
|
(appendStringInfoString(str, " :" CppAsString(fldname) " "), \
|
|
|
|
writeBoolCols(str, node->fldname, len))
|
2002-11-25 19:12:12 +01:00
|
|
|
|
2001-01-08 01:31:43 +01:00
|
|
|
#define booltostr(x) ((x) ? "true" : "false")
|
|
|
|
|
2002-12-12 16:49:42 +01:00
|
|
|
|
2000-01-14 01:53:21 +01:00
|
|
|
/*
|
2016-09-16 15:36:19 +02:00
|
|
|
* outToken
|
2000-01-14 01:53:21 +01:00
|
|
|
* Convert an ordinary string (eg, an identifier) into a form that
|
|
|
|
* will be decoded back to a plain token by read.c's functions.
|
|
|
|
*
|
|
|
|
* If a null or empty string is given, it is encoded as "<>".
|
|
|
|
*/
|
2016-09-16 15:36:19 +02:00
|
|
|
void
|
|
|
|
outToken(StringInfo str, const char *s)
|
2000-01-14 01:53:21 +01:00
|
|
|
{
|
|
|
|
if (s == NULL || *s == '\0')
|
|
|
|
{
|
2013-10-31 15:55:59 +01:00
|
|
|
appendStringInfoString(str, "<>");
|
2000-01-14 01:53:21 +01:00
|
|
|
return;
|
|
|
|
}
|
2000-04-12 19:17:23 +02:00
|
|
|
|
2000-01-14 01:53:21 +01:00
|
|
|
/*
|
|
|
|
* Look for characters or patterns that are treated specially by read.c
|
2001-01-07 02:08:48 +01:00
|
|
|
* (either in pg_strtok() or in nodeRead()), and therefore need a
|
|
|
|
* protective backslash.
|
2000-01-14 01:53:21 +01:00
|
|
|
*/
|
|
|
|
/* These characters only need to be quoted at the start of the string */
|
|
|
|
if (*s == '<' ||
|
2015-12-23 04:43:46 +01:00
|
|
|
*s == '"' ||
|
2000-12-03 21:45:40 +01:00
|
|
|
isdigit((unsigned char) *s) ||
|
2001-01-08 01:31:43 +01:00
|
|
|
((*s == '+' || *s == '-') &&
|
|
|
|
(isdigit((unsigned char) s[1]) || s[1] == '.')))
|
2000-01-14 01:53:21 +01:00
|
|
|
appendStringInfoChar(str, '\\');
|
|
|
|
while (*s)
|
|
|
|
{
|
|
|
|
/* These chars must be backslashed anywhere in the string */
|
|
|
|
if (*s == ' ' || *s == '\n' || *s == '\t' ||
|
|
|
|
*s == '(' || *s == ')' || *s == '{' || *s == '}' ||
|
|
|
|
*s == '\\')
|
|
|
|
appendStringInfoChar(str, '\\');
|
|
|
|
appendStringInfoChar(str, *s++);
|
|
|
|
}
|
|
|
|
}
|
1999-08-31 03:28:37 +02:00
|
|
|
|
2017-06-22 04:57:23 +02:00
|
|
|
/*
|
|
|
|
* Convert one char. Goes through outToken() so that special characters are
|
|
|
|
* escaped.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
outChar(StringInfo str, char c)
|
|
|
|
{
|
|
|
|
char in[2];
|
|
|
|
|
|
|
|
in[0] = c;
|
|
|
|
in[1] = '\0';
|
|
|
|
|
|
|
|
outToken(str, in);
|
|
|
|
}
|
|
|
|
|
Make serialization of Nodes' scalar-array fields more robust.
When the ability to print variable-length-array fields was first
added to outfuncs.c, there was no corresponding read capability,
as it was used only for debug dumps of planner-internal Nodes.
Not a lot of thought seems to have been put into the output format:
it's just the space-separated array elements and nothing else.
Later such fields appeared in Plan nodes, and still later we grew
read support so that Plans could be transferred to parallel workers,
but the original text format wasn't rethought. It seems inadequate
to me because (a) no cross-check is possible that we got the right
number of array entries, (b) we can't tell the difference between
a NULL pointer and a zero-length array, and (c) except for
WRITE_INDEX_ARRAY, we'd crash if a non-zero length is specified
when the pointer is NULL, a situation that can arise in some fields
that we currently conveniently avoid printing.
Since we're currently in a campaign to make the Node infrastructure
generally more it-just-works-without-thinking-about-it, now seems
like a good time to improve this.
Let's adopt a format similar to that used for Lists, that is "<>"
for a NULL pointer or "(item item item)" otherwise. Also retool
the code to not have so many copies of the identical logic.
I bumped catversion out of an abundance of caution, although I think
that we don't use any such array fields in Nodes that can get into
the catalogs.
Discussion: https://postgr.es/m/1528424.1658272135@sss.pgh.pa.us
2022-07-20 19:04:33 +02:00
|
|
|
/*
|
|
|
|
* common implementation for scalar-array-writing functions
|
|
|
|
*
|
|
|
|
* The data format is either "<>" for a NULL pointer or "(item item item)".
|
|
|
|
* fmtstr must include a leading space, and the rest of it must produce
|
|
|
|
* something that will be seen as a single simple token by pg_strtok().
|
|
|
|
* convfunc can be empty, or the name of a conversion macro or function.
|
|
|
|
*/
|
|
|
|
#define WRITE_SCALAR_ARRAY(fnname, datatype, fmtstr, convfunc) \
|
|
|
|
static void \
|
|
|
|
fnname(StringInfo str, const datatype *arr, int len) \
|
|
|
|
{ \
|
|
|
|
if (arr != NULL) \
|
|
|
|
{ \
|
|
|
|
appendStringInfoChar(str, '('); \
|
|
|
|
for (int i = 0; i < len; i++) \
|
|
|
|
appendStringInfo(str, fmtstr, convfunc(arr[i])); \
|
|
|
|
appendStringInfoChar(str, ')'); \
|
|
|
|
} \
|
|
|
|
else \
|
|
|
|
appendStringInfoString(str, "<>"); \
|
|
|
|
}
|
|
|
|
|
|
|
|
WRITE_SCALAR_ARRAY(writeAttrNumberCols, AttrNumber, " %d",)
|
|
|
|
WRITE_SCALAR_ARRAY(writeOidCols, Oid, " %u",)
|
|
|
|
WRITE_SCALAR_ARRAY(writeIndexCols, Index, " %u",)
|
|
|
|
WRITE_SCALAR_ARRAY(writeIntCols, int, " %d",)
|
|
|
|
WRITE_SCALAR_ARRAY(writeBoolCols, bool, " %s", booltostr)
|
|
|
|
|
2022-07-20 19:54:25 +02:00
|
|
|
/*
|
|
|
|
* Print an array (not a List) of Node pointers.
|
|
|
|
*
|
|
|
|
* The decoration is identical to that of scalar arrays, but we can't
|
|
|
|
* quite use appendStringInfo() in the loop.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
writeNodeArray(StringInfo str, const Node *const *arr, int len)
|
|
|
|
{
|
|
|
|
if (arr != NULL)
|
|
|
|
{
|
|
|
|
appendStringInfoChar(str, '(');
|
|
|
|
for (int i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
appendStringInfoChar(str, ' ');
|
|
|
|
outNode(str, arr[i]);
|
|
|
|
}
|
|
|
|
appendStringInfoChar(str, ')');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
appendStringInfoString(str, "<>");
|
|
|
|
}
|
|
|
|
|
Make serialization of Nodes' scalar-array fields more robust.
When the ability to print variable-length-array fields was first
added to outfuncs.c, there was no corresponding read capability,
as it was used only for debug dumps of planner-internal Nodes.
Not a lot of thought seems to have been put into the output format:
it's just the space-separated array elements and nothing else.
Later such fields appeared in Plan nodes, and still later we grew
read support so that Plans could be transferred to parallel workers,
but the original text format wasn't rethought. It seems inadequate
to me because (a) no cross-check is possible that we got the right
number of array entries, (b) we can't tell the difference between
a NULL pointer and a zero-length array, and (c) except for
WRITE_INDEX_ARRAY, we'd crash if a non-zero length is specified
when the pointer is NULL, a situation that can arise in some fields
that we currently conveniently avoid printing.
Since we're currently in a campaign to make the Node infrastructure
generally more it-just-works-without-thinking-about-it, now seems
like a good time to improve this.
Let's adopt a format similar to that used for Lists, that is "<>"
for a NULL pointer or "(item item item)" otherwise. Also retool
the code to not have so many copies of the identical logic.
I bumped catversion out of an abundance of caution, although I think
that we don't use any such array fields in Nodes that can get into
the catalogs.
Discussion: https://postgr.es/m/1528424.1658272135@sss.pgh.pa.us
2022-07-20 19:04:33 +02:00
|
|
|
/*
|
|
|
|
* Print a List.
|
|
|
|
*/
|
1996-11-10 04:06:38 +01:00
|
|
|
static void
|
2011-12-07 20:46:56 +01:00
|
|
|
_outList(StringInfo str, const List *node)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2011-12-07 20:46:56 +01:00
|
|
|
const ListCell *lc;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2000-01-14 01:53:21 +01:00
|
|
|
appendStringInfoChar(str, '(');
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2004-05-26 06:41:50 +02:00
|
|
|
if (IsA(node, IntList))
|
|
|
|
appendStringInfoChar(str, 'i');
|
|
|
|
else if (IsA(node, OidList))
|
|
|
|
appendStringInfoChar(str, 'o');
|
2022-07-04 14:52:12 +02:00
|
|
|
else if (IsA(node, XidList))
|
|
|
|
appendStringInfoChar(str, 'x');
|
2004-05-26 06:41:50 +02:00
|
|
|
|
|
|
|
foreach(lc, node)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* For the sake of backward compatibility, we emit a slightly
|
|
|
|
* different whitespace format for lists of nodes vs. other types of
|
|
|
|
* lists. XXX: is this necessary?
|
|
|
|
*/
|
|
|
|
if (IsA(node, List))
|
|
|
|
{
|
2016-04-08 23:26:36 +02:00
|
|
|
outNode(str, lfirst(lc));
|
Represent Lists as expansible arrays, not chains of cons-cells.
Originally, Postgres Lists were a more or less exact reimplementation of
Lisp lists, which consist of chains of separately-allocated cons cells,
each having a value and a next-cell link. We'd hacked that once before
(commit d0b4399d8) to add a separate List header, but the data was still
in cons cells. That makes some operations -- notably list_nth() -- O(N),
and it's bulky because of the next-cell pointers and per-cell palloc
overhead, and it's very cache-unfriendly if the cons cells end up
scattered around rather than being adjacent.
In this rewrite, we still have List headers, but the data is in a
resizable array of values, with no next-cell links. Now we need at
most two palloc's per List, and often only one, since we can allocate
some values in the same palloc call as the List header. (Of course,
extending an existing List may require repalloc's to enlarge the array.
But this involves just O(log N) allocations not O(N).)
Of course this is not without downsides. The key difficulty is that
addition or deletion of a list entry may now cause other entries to
move, which it did not before.
For example, that breaks foreach() and sister macros, which historically
used a pointer to the current cons-cell as loop state. We can repair
those macros transparently by making their actual loop state be an
integer list index; the exposed "ListCell *" pointer is no longer state
carried across loop iterations, but is just a derived value. (In
practice, modern compilers can optimize things back to having just one
loop state value, at least for simple cases with inline loop bodies.)
In principle, this is a semantics change for cases where the loop body
inserts or deletes list entries ahead of the current loop index; but
I found no such cases in the Postgres code.
The change is not at all transparent for code that doesn't use foreach()
but chases lists "by hand" using lnext(). The largest share of such
code in the backend is in loops that were maintaining "prev" and "next"
variables in addition to the current-cell pointer, in order to delete
list cells efficiently using list_delete_cell(). However, we no longer
need a previous-cell pointer to delete a list cell efficiently. Keeping
a next-cell pointer doesn't work, as explained above, but we can improve
matters by changing such code to use a regular foreach() loop and then
using the new macro foreach_delete_current() to delete the current cell.
(This macro knows how to update the associated foreach loop's state so
that no cells will be missed in the traversal.)
There remains a nontrivial risk of code assuming that a ListCell *
pointer will remain good over an operation that could now move the list
contents. To help catch such errors, list.c can be compiled with a new
define symbol DEBUG_LIST_MEMORY_USAGE that forcibly moves list contents
whenever that could possibly happen. This makes list operations
significantly more expensive so it's not normally turned on (though it
is on by default if USE_VALGRIND is on).
There are two notable API differences from the previous code:
* lnext() now requires the List's header pointer in addition to the
current cell's address.
* list_delete_cell() no longer requires a previous-cell argument.
These changes are somewhat unfortunate, but on the other hand code using
either function needs inspection to see if it is assuming anything
it shouldn't, so it's not all bad.
Programmers should be aware of these significant performance changes:
* list_nth() and related functions are now O(1); so there's no
major access-speed difference between a list and an array.
* Inserting or deleting a list element now takes time proportional to
the distance to the end of the list, due to moving the array elements.
(However, it typically *doesn't* require palloc or pfree, so except in
long lists it's probably still faster than before.) Notably, lcons()
used to be about the same cost as lappend(), but that's no longer true
if the list is long. Code that uses lcons() and list_delete_first()
to maintain a stack might usefully be rewritten to push and pop at the
end of the list rather than the beginning.
* There are now list_insert_nth...() and list_delete_nth...() functions
that add or remove a list cell identified by index. These have the
data-movement penalty explained above, but there's no search penalty.
* list_concat() and variants now copy the second list's data into
storage belonging to the first list, so there is no longer any
sharing of cells between the input lists. The second argument is
now declared "const List *" to reflect that it isn't changed.
This patch just does the minimum needed to get the new implementation
in place and fix bugs exposed by the regression tests. As suggested
by the foregoing, there's a fair amount of followup work remaining to
do.
Also, the ENABLE_LIST_COMPAT macros are finally removed in this
commit. Code using those should have been gone a dozen years ago.
Patch by me; thanks to David Rowley, Jesper Pedersen, and others
for review.
Discussion: https://postgr.es/m/11587.1550975080@sss.pgh.pa.us
2019-07-15 19:41:58 +02:00
|
|
|
if (lnext(node, lc))
|
2004-05-26 06:41:50 +02:00
|
|
|
appendStringInfoChar(str, ' ');
|
|
|
|
}
|
|
|
|
else if (IsA(node, IntList))
|
|
|
|
appendStringInfo(str, " %d", lfirst_int(lc));
|
|
|
|
else if (IsA(node, OidList))
|
|
|
|
appendStringInfo(str, " %u", lfirst_oid(lc));
|
2022-07-04 14:52:12 +02:00
|
|
|
else if (IsA(node, XidList))
|
|
|
|
appendStringInfo(str, " %u", lfirst_xid(lc));
|
2004-05-26 06:41:50 +02:00
|
|
|
else
|
|
|
|
elog(ERROR, "unrecognized list node type: %d",
|
|
|
|
(int) node->type);
|
|
|
|
}
|
2001-01-08 01:31:43 +01:00
|
|
|
|
|
|
|
appendStringInfoChar(str, ')');
|
|
|
|
}
|
|
|
|
|
2003-02-08 21:20:55 +01:00
|
|
|
/*
|
2016-09-16 15:36:19 +02:00
|
|
|
* outBitmapset -
|
2003-02-08 21:20:55 +01:00
|
|
|
* converts a bitmap set of integers
|
|
|
|
*
|
2004-05-08 23:21:18 +02:00
|
|
|
* Note: the output format is "(b int int ...)", similar to an integer List.
|
2003-02-08 21:20:55 +01:00
|
|
|
*/
|
2016-09-16 15:36:19 +02:00
|
|
|
void
|
|
|
|
outBitmapset(StringInfo str, const Bitmapset *bms)
|
2003-02-08 21:20:55 +01:00
|
|
|
{
|
|
|
|
int x;
|
|
|
|
|
|
|
|
appendStringInfoChar(str, '(');
|
2004-05-08 23:21:18 +02:00
|
|
|
appendStringInfoChar(str, 'b');
|
2014-11-28 19:37:25 +01:00
|
|
|
x = -1;
|
|
|
|
while ((x = bms_next_member(bms, x)) >= 0)
|
2003-02-08 21:20:55 +01:00
|
|
|
appendStringInfo(str, " %d", x);
|
|
|
|
appendStringInfoChar(str, ')');
|
|
|
|
}
|
|
|
|
|
2002-12-12 16:49:42 +01:00
|
|
|
/*
|
|
|
|
* Print the value of a Datum given its type.
|
|
|
|
*/
|
2016-04-08 23:26:36 +02:00
|
|
|
void
|
|
|
|
outDatum(StringInfo str, Datum value, int typlen, bool typbyval)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2002-12-12 16:49:42 +01:00
|
|
|
Size length,
|
|
|
|
i;
|
|
|
|
char *s;
|
2002-11-25 19:12:12 +01:00
|
|
|
|
2002-12-12 16:49:42 +01:00
|
|
|
length = datumGetSize(value, typbyval, typlen);
|
1999-01-21 17:08:55 +01:00
|
|
|
|
2002-12-12 16:49:42 +01:00
|
|
|
if (typbyval)
|
1997-12-05 00:20:32 +01:00
|
|
|
{
|
2002-12-12 16:49:42 +01:00
|
|
|
s = (char *) (&value);
|
|
|
|
appendStringInfo(str, "%u [ ", (unsigned int) length);
|
|
|
|
for (i = 0; i < (Size) sizeof(Datum); i++)
|
|
|
|
appendStringInfo(str, "%d ", (int) (s[i]));
|
2013-10-31 15:55:59 +01:00
|
|
|
appendStringInfoChar(str, ']');
|
2002-12-12 16:49:42 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s = (char *) DatumGetPointer(value);
|
|
|
|
if (!PointerIsValid(s))
|
2013-10-31 15:55:59 +01:00
|
|
|
appendStringInfoString(str, "0 [ ]");
|
2002-12-12 16:49:42 +01:00
|
|
|
else
|
1997-12-05 00:20:32 +01:00
|
|
|
{
|
2002-12-12 16:49:42 +01:00
|
|
|
appendStringInfo(str, "%u [ ", (unsigned int) length);
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
appendStringInfo(str, "%d ", (int) (s[i]));
|
2013-10-31 15:55:59 +01:00
|
|
|
appendStringInfoChar(str, ']');
|
1997-12-05 00:20:32 +01:00
|
|
|
}
|
|
|
|
}
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2000-10-05 21:11:39 +02:00
|
|
|
|
Automatically generate node support functions
Add a script to automatically generate the node support functions
(copy, equal, out, and read, as well as the node tags enum) from the
struct definitions.
For each of the four node support files, it creates two include files,
e.g., copyfuncs.funcs.c and copyfuncs.switch.c, to include in the main
file. All the scaffolding of the main file stays in place.
I have tried to mostly make the coverage of the output match what is
currently there. For example, one could now do out/read coverage of
utility statement nodes, but I have manually excluded those for now.
The reason is mainly that it's easier to diff the before and after,
and adding a bunch of stuff like this might require a separate
analysis and review.
Subtyping (TidScan -> Scan) is supported.
For the hard cases, you can just write a manual function and exclude
generating one. For the not so hard cases, there is a way of
annotating struct fields to get special behaviors. For example,
pg_node_attr(equal_ignore) has the field ignored in equal functions.
(In this patch, I have only ifdef'ed out the code to could be removed,
mainly so that it won't constantly have merge conflicts. It will be
deleted in a separate patch. All the code comments that are worth
keeping from those sections have already been moved to the header
files where the structs are defined.)
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/c1097590-a6a4-486a-64b1-e1f9cc0533ce%40enterprisedb.com
2022-07-09 08:52:19 +02:00
|
|
|
#include "outfuncs.funcs.c"
|
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
/*
|
2022-07-09 15:06:01 +02:00
|
|
|
* Support functions for nodes with custom_read_write attribute or
|
|
|
|
* special_read_write attribute
|
2002-11-25 19:12:12 +01:00
|
|
|
*/
|
|
|
|
|
2007-02-20 18:32:18 +01:00
|
|
|
static void
|
2022-07-09 15:06:01 +02:00
|
|
|
_outConst(StringInfo str, const Const *node)
|
2007-02-20 18:32:18 +01:00
|
|
|
{
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_NODE_TYPE("CONST");
|
2007-02-20 18:32:18 +01:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_OID_FIELD(consttype);
|
|
|
|
WRITE_INT_FIELD(consttypmod);
|
|
|
|
WRITE_OID_FIELD(constcollid);
|
|
|
|
WRITE_INT_FIELD(constlen);
|
|
|
|
WRITE_BOOL_FIELD(constbyval);
|
|
|
|
WRITE_BOOL_FIELD(constisnull);
|
|
|
|
WRITE_LOCATION_FIELD(location);
|
2007-02-20 18:32:18 +01:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
appendStringInfoString(str, " :constvalue ");
|
|
|
|
if (node->constisnull)
|
|
|
|
appendStringInfoString(str, "<>");
|
|
|
|
else
|
|
|
|
outDatum(str, node->constvalue, node->constlen, node->constbyval);
|
2002-11-25 19:12:12 +01:00
|
|
|
}
|
1998-12-15 03:24:15 +01:00
|
|
|
|
2002-11-25 19:12:12 +01:00
|
|
|
static void
|
2022-07-09 15:06:01 +02:00
|
|
|
_outBoolExpr(StringInfo str, const BoolExpr *node)
|
2002-11-25 19:12:12 +01:00
|
|
|
{
|
2022-07-09 15:06:01 +02:00
|
|
|
char *opstr = NULL;
|
1998-12-15 03:24:15 +01:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_NODE_TYPE("BOOLEXPR");
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
/* do-it-yourself enum representation */
|
|
|
|
switch (node->boolop)
|
|
|
|
{
|
|
|
|
case AND_EXPR:
|
|
|
|
opstr = "and";
|
|
|
|
break;
|
|
|
|
case OR_EXPR:
|
|
|
|
opstr = "or";
|
|
|
|
break;
|
|
|
|
case NOT_EXPR:
|
|
|
|
opstr = "not";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
appendStringInfoString(str, " :boolop ");
|
|
|
|
outToken(str, opstr);
|
2002-11-25 19:12:12 +01:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_NODE_FIELD(args);
|
|
|
|
WRITE_LOCATION_FIELD(location);
|
2002-11-25 19:12:12 +01:00
|
|
|
}
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
static void
|
2022-07-09 15:06:01 +02:00
|
|
|
_outForeignKeyOptInfo(StringInfo str, const ForeignKeyOptInfo *node)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2022-07-09 15:06:01 +02:00
|
|
|
int i;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_NODE_TYPE("FOREIGNKEYOPTINFO");
|
Move targetlist SRF handling from expression evaluation to new executor node.
Evaluation of set returning functions (SRFs_ in the targetlist (like SELECT
generate_series(1,5)) so far was done in the expression evaluation (i.e.
ExecEvalExpr()) and projection (i.e. ExecProject/ExecTargetList) code.
This meant that most executor nodes performing projection, and most
expression evaluation functions, had to deal with the possibility that an
evaluated expression could return a set of return values.
That's bad because it leads to repeated code in a lot of places. It also,
and that's my (Andres's) motivation, made it a lot harder to implement a
more efficient way of doing expression evaluation.
To fix this, introduce a new executor node (ProjectSet) that can evaluate
targetlists containing one or more SRFs. To avoid the complexity of the old
way of handling nested expressions returning sets (e.g. having to pass up
ExprDoneCond, and dealing with arguments to functions returning sets etc.),
those SRFs can only be at the top level of the node's targetlist. The
planner makes sure (via split_pathtarget_at_srfs()) that SRF evaluation is
only necessary in ProjectSet nodes and that SRFs are only present at the
top level of the node's targetlist. If there are nested SRFs the planner
creates multiple stacked ProjectSet nodes. The ProjectSet nodes always get
input from an underlying node.
We also discussed and prototyped evaluating targetlist SRFs using ROWS
FROM(), but that turned out to be more complicated than we'd hoped.
While moving SRF evaluation to ProjectSet would allow to retain the old
"least common multiple" behavior when multiple SRFs are present in one
targetlist (i.e. continue returning rows until all SRFs are at the end of
their input at the same time), we decided to instead only return rows till
all SRFs are exhausted, returning NULL for already exhausted ones. We
deemed the previous behavior to be too confusing, unexpected and actually
not particularly useful.
As a side effect, the previously prohibited case of multiple set returning
arguments to a function, is now allowed. Not because it's particularly
desirable, but because it ends up working and there seems to be no argument
for adding code to prohibit it.
Currently the behavior for COALESCE and CASE containing SRFs has changed,
returning multiple rows from the expression, even when the SRF containing
"arm" of the expression is not evaluated. That's because the SRFs are
evaluated in a separate ProjectSet node. As that's quite confusing, we're
likely to instead prohibit SRFs in those places. But that's still being
discussed, and the code would reside in places not touched here, so that's
a task for later.
There's a lot of, now superfluous, code dealing with set return expressions
around. But as the changes to get rid of those are verbose largely boring,
it seems better for readability to keep the cleanup as a separate commit.
Author: Tom Lane and Andres Freund
Discussion: https://postgr.es/m/20160822214023.aaxz5l4igypowyri@alap3.anarazel.de
2017-01-18 21:46:50 +01:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_UINT_FIELD(con_relid);
|
|
|
|
WRITE_UINT_FIELD(ref_relid);
|
|
|
|
WRITE_INT_FIELD(nkeys);
|
|
|
|
WRITE_ATTRNUMBER_ARRAY(conkey, node->nkeys);
|
|
|
|
WRITE_ATTRNUMBER_ARRAY(confkey, node->nkeys);
|
|
|
|
WRITE_OID_ARRAY(conpfeqop, node->nkeys);
|
|
|
|
WRITE_INT_FIELD(nmatched_ec);
|
|
|
|
WRITE_INT_FIELD(nconst_ec);
|
|
|
|
WRITE_INT_FIELD(nmatched_rcols);
|
|
|
|
WRITE_INT_FIELD(nmatched_ri);
|
|
|
|
/* for compactness, just print the number of matches per column: */
|
|
|
|
appendStringInfoString(str, " :eclass");
|
|
|
|
for (i = 0; i < node->nkeys; i++)
|
|
|
|
appendStringInfo(str, " %d", (node->eclass[i] != NULL));
|
|
|
|
appendStringInfoString(str, " :rinfos");
|
|
|
|
for (i = 0; i < node->nkeys; i++)
|
|
|
|
appendStringInfo(str, " %d", list_length(node->rinfos[i]));
|
Move targetlist SRF handling from expression evaluation to new executor node.
Evaluation of set returning functions (SRFs_ in the targetlist (like SELECT
generate_series(1,5)) so far was done in the expression evaluation (i.e.
ExecEvalExpr()) and projection (i.e. ExecProject/ExecTargetList) code.
This meant that most executor nodes performing projection, and most
expression evaluation functions, had to deal with the possibility that an
evaluated expression could return a set of return values.
That's bad because it leads to repeated code in a lot of places. It also,
and that's my (Andres's) motivation, made it a lot harder to implement a
more efficient way of doing expression evaluation.
To fix this, introduce a new executor node (ProjectSet) that can evaluate
targetlists containing one or more SRFs. To avoid the complexity of the old
way of handling nested expressions returning sets (e.g. having to pass up
ExprDoneCond, and dealing with arguments to functions returning sets etc.),
those SRFs can only be at the top level of the node's targetlist. The
planner makes sure (via split_pathtarget_at_srfs()) that SRF evaluation is
only necessary in ProjectSet nodes and that SRFs are only present at the
top level of the node's targetlist. If there are nested SRFs the planner
creates multiple stacked ProjectSet nodes. The ProjectSet nodes always get
input from an underlying node.
We also discussed and prototyped evaluating targetlist SRFs using ROWS
FROM(), but that turned out to be more complicated than we'd hoped.
While moving SRF evaluation to ProjectSet would allow to retain the old
"least common multiple" behavior when multiple SRFs are present in one
targetlist (i.e. continue returning rows until all SRFs are at the end of
their input at the same time), we decided to instead only return rows till
all SRFs are exhausted, returning NULL for already exhausted ones. We
deemed the previous behavior to be too confusing, unexpected and actually
not particularly useful.
As a side effect, the previously prohibited case of multiple set returning
arguments to a function, is now allowed. Not because it's particularly
desirable, but because it ends up working and there seems to be no argument
for adding code to prohibit it.
Currently the behavior for COALESCE and CASE containing SRFs has changed,
returning multiple rows from the expression, even when the SRF containing
"arm" of the expression is not evaluated. That's because the SRFs are
evaluated in a separate ProjectSet node. As that's quite confusing, we're
likely to instead prohibit SRFs in those places. But that's still being
discussed, and the code would reside in places not touched here, so that's
a task for later.
There's a lot of, now superfluous, code dealing with set return expressions
around. But as the changes to get rid of those are verbose largely boring,
it seems better for readability to keep the cleanup as a separate commit.
Author: Tom Lane and Andres Freund
Discussion: https://postgr.es/m/20160822214023.aaxz5l4igypowyri@alap3.anarazel.de
2017-01-18 21:46:50 +01:00
|
|
|
}
|
|
|
|
|
2009-10-10 03:43:50 +02:00
|
|
|
static void
|
2022-07-09 15:06:01 +02:00
|
|
|
_outEquivalenceClass(StringInfo str, const EquivalenceClass *node)
|
2009-10-10 03:43:50 +02:00
|
|
|
{
|
2022-07-09 15:06:01 +02:00
|
|
|
/*
|
|
|
|
* To simplify reading, we just chase up to the topmost merged EC and
|
|
|
|
* print that, without bothering to show the merge-ees separately.
|
|
|
|
*/
|
|
|
|
while (node->ec_merged)
|
|
|
|
node = node->ec_merged;
|
2009-10-10 03:43:50 +02:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_NODE_TYPE("EQUIVALENCECLASS");
|
2009-10-10 03:43:50 +02:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_NODE_FIELD(ec_opfamilies);
|
|
|
|
WRITE_OID_FIELD(ec_collation);
|
|
|
|
WRITE_NODE_FIELD(ec_members);
|
|
|
|
WRITE_NODE_FIELD(ec_sources);
|
|
|
|
WRITE_NODE_FIELD(ec_derives);
|
|
|
|
WRITE_BITMAPSET_FIELD(ec_relids);
|
|
|
|
WRITE_BOOL_FIELD(ec_has_const);
|
|
|
|
WRITE_BOOL_FIELD(ec_has_volatile);
|
|
|
|
WRITE_BOOL_FIELD(ec_below_outer_join);
|
|
|
|
WRITE_BOOL_FIELD(ec_broken);
|
|
|
|
WRITE_UINT_FIELD(ec_sortref);
|
|
|
|
WRITE_UINT_FIELD(ec_min_security);
|
|
|
|
WRITE_UINT_FIELD(ec_max_security);
|
2009-10-10 03:43:50 +02:00
|
|
|
}
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
static void
|
2022-07-09 15:06:01 +02:00
|
|
|
_outExtensibleNode(StringInfo str, const ExtensibleNode *node)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2022-07-09 15:06:01 +02:00
|
|
|
const ExtensibleNodeMethods *methods;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
methods = GetExtensibleNodeMethods(node->extnodename, false);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_NODE_TYPE("EXTENSIBLENODE");
|
2010-10-14 22:56:39 +02:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_STRING_FIELD(extnodename);
|
2010-10-14 22:56:39 +02:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
/* serialize the private fields */
|
|
|
|
methods->nodeOut(str, node);
|
2010-10-14 22:56:39 +02:00
|
|
|
}
|
|
|
|
|
2005-04-20 00:35:18 +02:00
|
|
|
static void
|
2022-07-09 15:06:01 +02:00
|
|
|
_outRangeTblEntry(StringInfo str, const RangeTblEntry *node)
|
2005-04-20 00:35:18 +02:00
|
|
|
{
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_NODE_TYPE("RANGETBLENTRY");
|
|
|
|
|
|
|
|
/* put alias + eref first to make dump more legible */
|
|
|
|
WRITE_NODE_FIELD(alias);
|
|
|
|
WRITE_NODE_FIELD(eref);
|
|
|
|
WRITE_ENUM_FIELD(rtekind, RTEKind);
|
2005-04-20 00:35:18 +02:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
switch (node->rtekind)
|
|
|
|
{
|
|
|
|
case RTE_RELATION:
|
|
|
|
WRITE_OID_FIELD(relid);
|
|
|
|
WRITE_CHAR_FIELD(relkind);
|
|
|
|
WRITE_INT_FIELD(rellockmode);
|
|
|
|
WRITE_NODE_FIELD(tablesample);
|
|
|
|
break;
|
|
|
|
case RTE_SUBQUERY:
|
|
|
|
WRITE_NODE_FIELD(subquery);
|
|
|
|
WRITE_BOOL_FIELD(security_barrier);
|
|
|
|
break;
|
|
|
|
case RTE_JOIN:
|
|
|
|
WRITE_ENUM_FIELD(jointype, JoinType);
|
|
|
|
WRITE_INT_FIELD(joinmergedcols);
|
|
|
|
WRITE_NODE_FIELD(joinaliasvars);
|
|
|
|
WRITE_NODE_FIELD(joinleftcols);
|
|
|
|
WRITE_NODE_FIELD(joinrightcols);
|
|
|
|
WRITE_NODE_FIELD(join_using_alias);
|
|
|
|
break;
|
|
|
|
case RTE_FUNCTION:
|
|
|
|
WRITE_NODE_FIELD(functions);
|
|
|
|
WRITE_BOOL_FIELD(funcordinality);
|
|
|
|
break;
|
|
|
|
case RTE_TABLEFUNC:
|
|
|
|
WRITE_NODE_FIELD(tablefunc);
|
|
|
|
break;
|
|
|
|
case RTE_VALUES:
|
|
|
|
WRITE_NODE_FIELD(values_lists);
|
|
|
|
WRITE_NODE_FIELD(coltypes);
|
|
|
|
WRITE_NODE_FIELD(coltypmods);
|
|
|
|
WRITE_NODE_FIELD(colcollations);
|
|
|
|
break;
|
|
|
|
case RTE_CTE:
|
|
|
|
WRITE_STRING_FIELD(ctename);
|
|
|
|
WRITE_UINT_FIELD(ctelevelsup);
|
|
|
|
WRITE_BOOL_FIELD(self_reference);
|
|
|
|
WRITE_NODE_FIELD(coltypes);
|
|
|
|
WRITE_NODE_FIELD(coltypmods);
|
|
|
|
WRITE_NODE_FIELD(colcollations);
|
|
|
|
break;
|
|
|
|
case RTE_NAMEDTUPLESTORE:
|
|
|
|
WRITE_STRING_FIELD(enrname);
|
|
|
|
WRITE_FLOAT_FIELD(enrtuples, "%.0f");
|
|
|
|
WRITE_OID_FIELD(relid);
|
|
|
|
WRITE_NODE_FIELD(coltypes);
|
|
|
|
WRITE_NODE_FIELD(coltypmods);
|
|
|
|
WRITE_NODE_FIELD(colcollations);
|
|
|
|
break;
|
|
|
|
case RTE_RESULT:
|
|
|
|
/* no extra fields */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
elog(ERROR, "unrecognized RTE kind: %d", (int) node->rtekind);
|
|
|
|
break;
|
|
|
|
}
|
2005-04-20 00:35:18 +02:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_BOOL_FIELD(lateral);
|
|
|
|
WRITE_BOOL_FIELD(inh);
|
|
|
|
WRITE_BOOL_FIELD(inFromCl);
|
|
|
|
WRITE_UINT_FIELD(requiredPerms);
|
|
|
|
WRITE_OID_FIELD(checkAsUser);
|
|
|
|
WRITE_BITMAPSET_FIELD(selectedCols);
|
|
|
|
WRITE_BITMAPSET_FIELD(insertedCols);
|
|
|
|
WRITE_BITMAPSET_FIELD(updatedCols);
|
|
|
|
WRITE_BITMAPSET_FIELD(extraUpdatedCols);
|
|
|
|
WRITE_NODE_FIELD(securityQuals);
|
2005-04-20 00:35:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-07-09 15:06:01 +02:00
|
|
|
_outA_Expr(StringInfo str, const A_Expr *node)
|
2005-04-20 00:35:18 +02:00
|
|
|
{
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_NODE_TYPE("A_EXPR");
|
2005-04-20 00:35:18 +02:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
switch (node->kind)
|
|
|
|
{
|
|
|
|
case AEXPR_OP:
|
|
|
|
WRITE_NODE_FIELD(name);
|
|
|
|
break;
|
|
|
|
case AEXPR_OP_ANY:
|
2022-08-15 12:43:52 +02:00
|
|
|
appendStringInfoString(str, " ANY");
|
2022-09-25 00:18:33 +02:00
|
|
|
WRITE_NODE_FIELD(name);
|
2022-07-09 15:06:01 +02:00
|
|
|
break;
|
|
|
|
case AEXPR_OP_ALL:
|
2022-08-15 12:43:52 +02:00
|
|
|
appendStringInfoString(str, " ALL");
|
2022-09-25 00:18:33 +02:00
|
|
|
WRITE_NODE_FIELD(name);
|
2022-07-09 15:06:01 +02:00
|
|
|
break;
|
|
|
|
case AEXPR_DISTINCT:
|
2022-08-15 12:43:52 +02:00
|
|
|
appendStringInfoString(str, " DISTINCT");
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_NODE_FIELD(name);
|
|
|
|
break;
|
|
|
|
case AEXPR_NOT_DISTINCT:
|
2022-08-15 12:43:52 +02:00
|
|
|
appendStringInfoString(str, " NOT_DISTINCT");
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_NODE_FIELD(name);
|
|
|
|
break;
|
|
|
|
case AEXPR_NULLIF:
|
2022-08-15 12:43:52 +02:00
|
|
|
appendStringInfoString(str, " NULLIF");
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_NODE_FIELD(name);
|
|
|
|
break;
|
|
|
|
case AEXPR_IN:
|
2022-08-15 12:43:52 +02:00
|
|
|
appendStringInfoString(str, " IN");
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_NODE_FIELD(name);
|
|
|
|
break;
|
|
|
|
case AEXPR_LIKE:
|
2022-08-15 12:43:52 +02:00
|
|
|
appendStringInfoString(str, " LIKE");
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_NODE_FIELD(name);
|
|
|
|
break;
|
|
|
|
case AEXPR_ILIKE:
|
2022-08-15 12:43:52 +02:00
|
|
|
appendStringInfoString(str, " ILIKE");
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_NODE_FIELD(name);
|
|
|
|
break;
|
|
|
|
case AEXPR_SIMILAR:
|
2022-08-15 12:43:52 +02:00
|
|
|
appendStringInfoString(str, " SIMILAR");
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_NODE_FIELD(name);
|
|
|
|
break;
|
|
|
|
case AEXPR_BETWEEN:
|
2022-08-15 12:43:52 +02:00
|
|
|
appendStringInfoString(str, " BETWEEN");
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_NODE_FIELD(name);
|
|
|
|
break;
|
|
|
|
case AEXPR_NOT_BETWEEN:
|
2022-08-15 12:43:52 +02:00
|
|
|
appendStringInfoString(str, " NOT_BETWEEN");
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_NODE_FIELD(name);
|
|
|
|
break;
|
|
|
|
case AEXPR_BETWEEN_SYM:
|
2022-08-15 12:43:52 +02:00
|
|
|
appendStringInfoString(str, " BETWEEN_SYM");
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_NODE_FIELD(name);
|
|
|
|
break;
|
|
|
|
case AEXPR_NOT_BETWEEN_SYM:
|
2022-08-15 12:43:52 +02:00
|
|
|
appendStringInfoString(str, " NOT_BETWEEN_SYM");
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_NODE_FIELD(name);
|
|
|
|
break;
|
|
|
|
default:
|
2022-09-25 00:18:33 +02:00
|
|
|
elog(ERROR, "unrecognized A_Expr_Kind: %d", (int) node->kind);
|
2022-07-09 15:06:01 +02:00
|
|
|
break;
|
|
|
|
}
|
2002-11-25 19:12:12 +01:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_NODE_FIELD(lexpr);
|
|
|
|
WRITE_NODE_FIELD(rexpr);
|
|
|
|
WRITE_LOCATION_FIELD(location);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-07-09 15:06:01 +02:00
|
|
|
_outInteger(StringInfo str, const Integer *node)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2022-07-09 15:06:01 +02:00
|
|
|
appendStringInfo(str, "%d", node->ival);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
Redesign tablesample method API, and do extensive code review.
The original implementation of TABLESAMPLE modeled the tablesample method
API on index access methods, which wasn't a good choice because, without
specialized DDL commands, there's no way to build an extension that can
implement a TSM. (Raw inserts into system catalogs are not an acceptable
thing to do, because we can't undo them during DROP EXTENSION, nor will
pg_upgrade behave sanely.) Instead adopt an API more like procedural
language handlers or foreign data wrappers, wherein the only SQL-level
support object needed is a single handler function identified by having
a special return type. This lets us get rid of the supporting catalog
altogether, so that no custom DDL support is needed for the feature.
Adjust the API so that it can support non-constant tablesample arguments
(the original coding assumed we could evaluate the argument expressions at
ExecInitSampleScan time, which is undesirable even if it weren't outright
unsafe), and discourage sampling methods from looking at invisible tuples.
Make sure that the BERNOULLI and SYSTEM methods are genuinely repeatable
within and across queries, as required by the SQL standard, and deal more
honestly with methods that can't support that requirement.
Make a full code-review pass over the tablesample additions, and fix
assorted bugs, omissions, infelicities, and cosmetic issues (such as
failure to put the added code stanzas in a consistent ordering).
Improve EXPLAIN's output of tablesample plans, too.
Back-patch to 9.5 so that we don't have to support the original API
in production.
2015-07-25 20:39:00 +02:00
|
|
|
static void
|
2022-07-09 15:06:01 +02:00
|
|
|
_outFloat(StringInfo str, const Float *node)
|
Redesign tablesample method API, and do extensive code review.
The original implementation of TABLESAMPLE modeled the tablesample method
API on index access methods, which wasn't a good choice because, without
specialized DDL commands, there's no way to build an extension that can
implement a TSM. (Raw inserts into system catalogs are not an acceptable
thing to do, because we can't undo them during DROP EXTENSION, nor will
pg_upgrade behave sanely.) Instead adopt an API more like procedural
language handlers or foreign data wrappers, wherein the only SQL-level
support object needed is a single handler function identified by having
a special return type. This lets us get rid of the supporting catalog
altogether, so that no custom DDL support is needed for the feature.
Adjust the API so that it can support non-constant tablesample arguments
(the original coding assumed we could evaluate the argument expressions at
ExecInitSampleScan time, which is undesirable even if it weren't outright
unsafe), and discourage sampling methods from looking at invisible tuples.
Make sure that the BERNOULLI and SYSTEM methods are genuinely repeatable
within and across queries, as required by the SQL standard, and deal more
honestly with methods that can't support that requirement.
Make a full code-review pass over the tablesample additions, and fix
assorted bugs, omissions, infelicities, and cosmetic issues (such as
failure to put the added code stanzas in a consistent ordering).
Improve EXPLAIN's output of tablesample plans, too.
Back-patch to 9.5 so that we don't have to support the original API
in production.
2015-07-25 20:39:00 +02:00
|
|
|
{
|
2022-07-09 15:06:01 +02:00
|
|
|
/*
|
|
|
|
* We assume the value is a valid numeric literal and so does not need
|
|
|
|
* quoting.
|
|
|
|
*/
|
|
|
|
appendStringInfoString(str, node->fval);
|
Redesign tablesample method API, and do extensive code review.
The original implementation of TABLESAMPLE modeled the tablesample method
API on index access methods, which wasn't a good choice because, without
specialized DDL commands, there's no way to build an extension that can
implement a TSM. (Raw inserts into system catalogs are not an acceptable
thing to do, because we can't undo them during DROP EXTENSION, nor will
pg_upgrade behave sanely.) Instead adopt an API more like procedural
language handlers or foreign data wrappers, wherein the only SQL-level
support object needed is a single handler function identified by having
a special return type. This lets us get rid of the supporting catalog
altogether, so that no custom DDL support is needed for the feature.
Adjust the API so that it can support non-constant tablesample arguments
(the original coding assumed we could evaluate the argument expressions at
ExecInitSampleScan time, which is undesirable even if it weren't outright
unsafe), and discourage sampling methods from looking at invisible tuples.
Make sure that the BERNOULLI and SYSTEM methods are genuinely repeatable
within and across queries, as required by the SQL standard, and deal more
honestly with methods that can't support that requirement.
Make a full code-review pass over the tablesample additions, and fix
assorted bugs, omissions, infelicities, and cosmetic issues (such as
failure to put the added code stanzas in a consistent ordering).
Improve EXPLAIN's output of tablesample plans, too.
Back-patch to 9.5 so that we don't have to support the original API
in production.
2015-07-25 20:39:00 +02:00
|
|
|
}
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
static void
|
2022-07-09 15:06:01 +02:00
|
|
|
_outBoolean(StringInfo str, const Boolean *node)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2022-07-09 15:06:01 +02:00
|
|
|
appendStringInfoString(str, node->boolval ? "true" : "false");
|
2011-10-11 20:20:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-07-09 15:06:01 +02:00
|
|
|
_outString(StringInfo str, const String *node)
|
2011-10-11 20:20:06 +02:00
|
|
|
{
|
2022-07-09 15:06:01 +02:00
|
|
|
/*
|
|
|
|
* We use outToken to provide escaping of the string's content, but we
|
|
|
|
* don't want it to do anything with an empty string.
|
|
|
|
*/
|
|
|
|
appendStringInfoChar(str, '"');
|
|
|
|
if (node->sval[0] != '\0')
|
|
|
|
outToken(str, node->sval);
|
|
|
|
appendStringInfoChar(str, '"');
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2005-04-20 00:35:18 +02:00
|
|
|
static void
|
2022-07-09 15:06:01 +02:00
|
|
|
_outBitString(StringInfo str, const BitString *node)
|
2005-04-20 00:35:18 +02:00
|
|
|
{
|
2022-07-09 15:06:01 +02:00
|
|
|
/* internal representation already has leading 'b' */
|
|
|
|
appendStringInfoString(str, node->bsval);
|
2005-04-20 00:35:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-07-09 15:06:01 +02:00
|
|
|
_outA_Const(StringInfo str, const A_Const *node)
|
2005-04-20 00:35:18 +02:00
|
|
|
{
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_NODE_TYPE("A_CONST");
|
2005-04-20 00:35:18 +02:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
if (node->isnull)
|
2022-08-11 10:35:39 +02:00
|
|
|
appendStringInfoString(str, " NULL");
|
2022-07-09 15:06:01 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
appendStringInfoString(str, " :val ");
|
|
|
|
outNode(str, &node->val);
|
|
|
|
}
|
|
|
|
WRITE_LOCATION_FIELD(location);
|
2005-04-20 00:35:18 +02:00
|
|
|
}
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
static void
|
2022-07-09 15:06:01 +02:00
|
|
|
_outConstraint(StringInfo str, const Constraint *node)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_NODE_TYPE("CONSTRAINT");
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_STRING_FIELD(conname);
|
|
|
|
WRITE_BOOL_FIELD(deferrable);
|
|
|
|
WRITE_BOOL_FIELD(initdeferred);
|
|
|
|
WRITE_LOCATION_FIELD(location);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
appendStringInfoString(str, " :contype ");
|
|
|
|
switch (node->contype)
|
|
|
|
{
|
|
|
|
case CONSTR_NULL:
|
|
|
|
appendStringInfoString(str, "NULL");
|
|
|
|
break;
|
2021-02-27 10:59:36 +01:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
case CONSTR_NOTNULL:
|
|
|
|
appendStringInfoString(str, "NOT_NULL");
|
|
|
|
break;
|
2021-02-27 10:59:36 +01:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
case CONSTR_DEFAULT:
|
|
|
|
appendStringInfoString(str, "DEFAULT");
|
|
|
|
WRITE_NODE_FIELD(raw_expr);
|
|
|
|
WRITE_STRING_FIELD(cooked_expr);
|
|
|
|
break;
|
2021-02-27 10:59:36 +01:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
case CONSTR_IDENTITY:
|
|
|
|
appendStringInfoString(str, "IDENTITY");
|
2022-08-12 08:17:30 +02:00
|
|
|
WRITE_NODE_FIELD(options);
|
2022-07-09 15:06:01 +02:00
|
|
|
WRITE_CHAR_FIELD(generated_when);
|
|
|
|
break;
|
1998-12-15 03:24:15 +01:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
case CONSTR_GENERATED:
|
|
|
|
appendStringInfoString(str, "GENERATED");
|
|
|
|
WRITE_NODE_FIELD(raw_expr);
|
|
|
|
WRITE_STRING_FIELD(cooked_expr);
|
|
|
|
WRITE_CHAR_FIELD(generated_when);
|
|
|
|
break;
|
1998-12-15 03:24:15 +01:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
case CONSTR_CHECK:
|
|
|
|
appendStringInfoString(str, "CHECK");
|
|
|
|
WRITE_BOOL_FIELD(is_no_inherit);
|
|
|
|
WRITE_NODE_FIELD(raw_expr);
|
|
|
|
WRITE_STRING_FIELD(cooked_expr);
|
2022-08-13 10:32:38 +02:00
|
|
|
WRITE_BOOL_FIELD(skip_validation);
|
|
|
|
WRITE_BOOL_FIELD(initially_valid);
|
2022-07-09 15:06:01 +02:00
|
|
|
break;
|
1998-02-13 04:27:47 +01:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
case CONSTR_PRIMARY:
|
|
|
|
appendStringInfoString(str, "PRIMARY_KEY");
|
|
|
|
WRITE_NODE_FIELD(keys);
|
|
|
|
WRITE_NODE_FIELD(including);
|
|
|
|
WRITE_NODE_FIELD(options);
|
|
|
|
WRITE_STRING_FIELD(indexname);
|
|
|
|
WRITE_STRING_FIELD(indexspace);
|
|
|
|
WRITE_BOOL_FIELD(reset_default_tblspc);
|
|
|
|
/* access_method and where_clause not currently used */
|
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
case CONSTR_UNIQUE:
|
|
|
|
appendStringInfoString(str, "UNIQUE");
|
|
|
|
WRITE_BOOL_FIELD(nulls_not_distinct);
|
|
|
|
WRITE_NODE_FIELD(keys);
|
|
|
|
WRITE_NODE_FIELD(including);
|
|
|
|
WRITE_NODE_FIELD(options);
|
|
|
|
WRITE_STRING_FIELD(indexname);
|
|
|
|
WRITE_STRING_FIELD(indexspace);
|
|
|
|
WRITE_BOOL_FIELD(reset_default_tblspc);
|
|
|
|
/* access_method and where_clause not currently used */
|
|
|
|
break;
|
2007-02-19 03:23:12 +01:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
case CONSTR_EXCLUSION:
|
|
|
|
appendStringInfoString(str, "EXCLUSION");
|
|
|
|
WRITE_NODE_FIELD(exclusions);
|
|
|
|
WRITE_NODE_FIELD(including);
|
|
|
|
WRITE_NODE_FIELD(options);
|
|
|
|
WRITE_STRING_FIELD(indexname);
|
|
|
|
WRITE_STRING_FIELD(indexspace);
|
|
|
|
WRITE_BOOL_FIELD(reset_default_tblspc);
|
|
|
|
WRITE_STRING_FIELD(access_method);
|
|
|
|
WRITE_NODE_FIELD(where_clause);
|
|
|
|
break;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
case CONSTR_FOREIGN:
|
|
|
|
appendStringInfoString(str, "FOREIGN_KEY");
|
|
|
|
WRITE_NODE_FIELD(pktable);
|
|
|
|
WRITE_NODE_FIELD(fk_attrs);
|
|
|
|
WRITE_NODE_FIELD(pk_attrs);
|
|
|
|
WRITE_CHAR_FIELD(fk_matchtype);
|
|
|
|
WRITE_CHAR_FIELD(fk_upd_action);
|
|
|
|
WRITE_CHAR_FIELD(fk_del_action);
|
|
|
|
WRITE_NODE_FIELD(fk_del_set_cols);
|
|
|
|
WRITE_NODE_FIELD(old_conpfeqop);
|
|
|
|
WRITE_OID_FIELD(old_pktable_oid);
|
|
|
|
WRITE_BOOL_FIELD(skip_validation);
|
|
|
|
WRITE_BOOL_FIELD(initially_valid);
|
|
|
|
break;
|
2017-03-08 16:39:37 +01:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
case CONSTR_ATTR_DEFERRABLE:
|
|
|
|
appendStringInfoString(str, "ATTR_DEFERRABLE");
|
|
|
|
break;
|
2017-03-08 16:39:37 +01:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
case CONSTR_ATTR_NOT_DEFERRABLE:
|
|
|
|
appendStringInfoString(str, "ATTR_NOT_DEFERRABLE");
|
|
|
|
break;
|
2017-03-08 16:39:37 +01:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
case CONSTR_ATTR_DEFERRED:
|
|
|
|
appendStringInfoString(str, "ATTR_DEFERRED");
|
|
|
|
break;
|
2006-08-02 03:59:48 +02:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
case CONSTR_ATTR_IMMEDIATE:
|
|
|
|
appendStringInfoString(str, "ATTR_IMMEDIATE");
|
|
|
|
break;
|
2007-02-19 03:23:12 +01:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
default:
|
2022-09-25 00:18:33 +02:00
|
|
|
elog(ERROR, "unrecognized ConstrType: %d", (int) node->contype);
|
2022-07-09 15:06:01 +02:00
|
|
|
break;
|
|
|
|
}
|
2006-08-02 03:59:48 +02:00
|
|
|
}
|
|
|
|
|
2008-10-04 23:56:55 +02:00
|
|
|
|
2022-07-09 15:06:01 +02:00
|
|
|
/*
|
|
|
|
* outNode -
|
|
|
|
* converts a Node into ascii string and append it to 'str'
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
outNode(StringInfo str, const void *obj)
|
2017-04-01 06:17:18 +02:00
|
|
|
{
|
2022-07-09 15:06:01 +02:00
|
|
|
/* Guard against stack overflow due to overly complex expressions */
|
|
|
|
check_stack_depth();
|
2018-12-10 17:12:43 +01:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
if (obj == NULL)
|
2013-10-31 15:55:59 +01:00
|
|
|
appendStringInfoString(str, "<>");
|
2022-07-13 10:34:54 +02:00
|
|
|
else if (IsA(obj, List) || IsA(obj, IntList) || IsA(obj, OidList) ||
|
|
|
|
IsA(obj, XidList))
|
2004-05-26 06:41:50 +02:00
|
|
|
_outList(str, obj);
|
Remove Value node struct
The Value node struct is a weird construct. It is its own node type,
but most of the time, it actually has a node type of Integer, Float,
String, or BitString. As a consequence, the struct name and the node
type don't match most of the time, and so it has to be treated
specially a lot. There doesn't seem to be any value in the special
construct. There is very little code that wants to accept all Value
variants but nothing else (and even if it did, this doesn't provide
any convenient way to check it), and most code wants either just one
particular node type (usually String), or it accepts a broader set of
node types besides just Value.
This change removes the Value struct and node type and replaces them
by separate Integer, Float, String, and BitString node types that are
proper node types and structs of their own and behave mostly like
normal node types.
Also, this removes the T_Null node tag, which was previously also a
possible variant of Value but wasn't actually used outside of the
Value contained in A_Const. Replace that by an isnull field in
A_Const.
Reviewed-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/5ba6bc5b-3f95-04f2-2419-f8ddb4c046fb@enterprisedb.com
2021-09-09 07:58:12 +02:00
|
|
|
/* nodeRead does not want to see { } around these! */
|
|
|
|
else if (IsA(obj, Integer))
|
|
|
|
_outInteger(str, (Integer *) obj);
|
|
|
|
else if (IsA(obj, Float))
|
|
|
|
_outFloat(str, (Float *) obj);
|
2022-01-14 10:46:49 +01:00
|
|
|
else if (IsA(obj, Boolean))
|
|
|
|
_outBoolean(str, (Boolean *) obj);
|
Remove Value node struct
The Value node struct is a weird construct. It is its own node type,
but most of the time, it actually has a node type of Integer, Float,
String, or BitString. As a consequence, the struct name and the node
type don't match most of the time, and so it has to be treated
specially a lot. There doesn't seem to be any value in the special
construct. There is very little code that wants to accept all Value
variants but nothing else (and even if it did, this doesn't provide
any convenient way to check it), and most code wants either just one
particular node type (usually String), or it accepts a broader set of
node types besides just Value.
This change removes the Value struct and node type and replaces them
by separate Integer, Float, String, and BitString node types that are
proper node types and structs of their own and behave mostly like
normal node types.
Also, this removes the T_Null node tag, which was previously also a
possible variant of Value but wasn't actually used outside of the
Value contained in A_Const. Replace that by an isnull field in
A_Const.
Reviewed-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/5ba6bc5b-3f95-04f2-2419-f8ddb4c046fb@enterprisedb.com
2021-09-09 07:58:12 +02:00
|
|
|
else if (IsA(obj, String))
|
|
|
|
_outString(str, (String *) obj);
|
|
|
|
else if (IsA(obj, BitString))
|
|
|
|
_outBitString(str, (BitString *) obj);
|
1996-07-09 08:22:35 +02:00
|
|
|
else
|
|
|
|
{
|
2000-01-14 01:53:21 +01:00
|
|
|
appendStringInfoChar(str, '{');
|
1996-07-09 08:22:35 +02:00
|
|
|
switch (nodeTag(obj))
|
|
|
|
{
|
Automatically generate node support functions
Add a script to automatically generate the node support functions
(copy, equal, out, and read, as well as the node tags enum) from the
struct definitions.
For each of the four node support files, it creates two include files,
e.g., copyfuncs.funcs.c and copyfuncs.switch.c, to include in the main
file. All the scaffolding of the main file stays in place.
I have tried to mostly make the coverage of the output match what is
currently there. For example, one could now do out/read coverage of
utility statement nodes, but I have manually excluded those for now.
The reason is mainly that it's easier to diff the before and after,
and adding a bunch of stuff like this might require a separate
analysis and review.
Subtyping (TidScan -> Scan) is supported.
For the hard cases, you can just write a manual function and exclude
generating one. For the not so hard cases, there is a way of
annotating struct fields to get special behaviors. For example,
pg_node_attr(equal_ignore) has the field ignored in equal functions.
(In this patch, I have only ifdef'ed out the code to could be removed,
mainly so that it won't constantly have merge conflicts. It will be
deleted in a separate patch. All the code comments that are worth
keeping from those sections have already been moved to the header
files where the structs are defined.)
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/c1097590-a6a4-486a-64b1-e1f9cc0533ce%40enterprisedb.com
2022-07-09 08:52:19 +02:00
|
|
|
#include "outfuncs.switch.c"
|
1999-02-23 09:01:47 +01:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
default:
|
2003-08-04 02:43:34 +02:00
|
|
|
|
2003-07-23 01:30:39 +02:00
|
|
|
/*
|
|
|
|
* This should be an ERROR, but it's too useful to be able to
|
2016-04-08 23:26:36 +02:00
|
|
|
* dump structures that outNode only understands part of.
|
2003-07-23 01:30:39 +02:00
|
|
|
*/
|
|
|
|
elog(WARNING, "could not dump unrecognized node type: %d",
|
|
|
|
(int) nodeTag(obj));
|
1996-07-09 08:22:35 +02:00
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
2000-01-14 01:53:21 +01:00
|
|
|
appendStringInfoChar(str, '}');
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* nodeToString -
|
1999-04-25 05:19:27 +02:00
|
|
|
* returns the ascii representation of the Node as a palloc'd string
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
char *
|
2011-12-07 20:46:56 +01:00
|
|
|
nodeToString(const void *obj)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1999-04-25 05:19:27 +02:00
|
|
|
StringInfoData str;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-04-25 05:19:27 +02:00
|
|
|
/* see stringinfo.h for an explanation of this maneuver */
|
|
|
|
initStringInfo(&str);
|
2016-04-08 23:26:36 +02:00
|
|
|
outNode(&str, obj);
|
1999-04-25 05:19:27 +02:00
|
|
|
return str.data;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
2016-09-16 15:36:19 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* bmsToString -
|
|
|
|
* returns the ascii representation of the Bitmapset as a palloc'd string
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
bmsToString(const Bitmapset *bms)
|
|
|
|
{
|
|
|
|
StringInfoData str;
|
|
|
|
|
|
|
|
/* see stringinfo.h for an explanation of this maneuver */
|
|
|
|
initStringInfo(&str);
|
|
|
|
outBitmapset(&str, bms);
|
|
|
|
return str.data;
|
|
|
|
}
|