1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-08 11:42:09 +03:00

Remove custom Constraint node read/write implementations

This is part of an effort to reduce the number of special cases in the
automatically generated node support functions.

Allegedly, only certain fields of the Constraint node are valid based
on contype.  But this has historically not been kept up to date in the
read/write functions.  The Constraint node is only used for debugging
DDL statements, so there are no strong requirements for its output,
and there is no enforcement for its correctness.  (There was no read
support before a6bc3301925.)  Commits e7a552f303 and abf46ad9c7 are
examples of where omissions were fixed.

This patch just removes the custom read/write implementations for the
Constraint node type.  Now we just output all the fields, which is a
bit more than before, but at least we don't have to maintain these
functions anymore.  Also, we lose the string representation of the
contype field, but for this marginal use case that seems tolerable.
This patch also changes the documentation of the Constraint struct to
put less emphasis on grouping fields by constraint type but rather
document for each field how it's used.

Reviewed-by: Paul Jungwirth <pj@illuminatedcomputing.com>
Discussion: https://www.postgresql.org/message-id/flat/4b27fc50-8cd6-46f5-ab20-88dbaadca645@eisentraut.org
This commit is contained in:
Peter Eisentraut
2024-02-22 07:07:12 +01:00
parent 801792e528
commit fbc93b8b5f
3 changed files with 13 additions and 298 deletions

View File

@ -343,151 +343,6 @@ _readA_Const(void)
READ_DONE();
}
/*
* _readConstraint
*/
static Constraint *
_readConstraint(void)
{
READ_LOCALS(Constraint);
READ_STRING_FIELD(conname);
READ_BOOL_FIELD(deferrable);
READ_BOOL_FIELD(initdeferred);
READ_LOCATION_FIELD(location);
token = pg_strtok(&length); /* skip :contype */
token = pg_strtok(&length); /* get field value */
if (length == 4 && strncmp(token, "NULL", 4) == 0)
local_node->contype = CONSTR_NULL;
else if (length == 8 && strncmp(token, "NOT_NULL", 8) == 0)
local_node->contype = CONSTR_NOTNULL;
else if (length == 7 && strncmp(token, "DEFAULT", 7) == 0)
local_node->contype = CONSTR_DEFAULT;
else if (length == 8 && strncmp(token, "IDENTITY", 8) == 0)
local_node->contype = CONSTR_IDENTITY;
else if (length == 9 && strncmp(token, "GENERATED", 9) == 0)
local_node->contype = CONSTR_GENERATED;
else if (length == 5 && strncmp(token, "CHECK", 5) == 0)
local_node->contype = CONSTR_CHECK;
else if (length == 11 && strncmp(token, "PRIMARY_KEY", 11) == 0)
local_node->contype = CONSTR_PRIMARY;
else if (length == 6 && strncmp(token, "UNIQUE", 6) == 0)
local_node->contype = CONSTR_UNIQUE;
else if (length == 9 && strncmp(token, "EXCLUSION", 9) == 0)
local_node->contype = CONSTR_EXCLUSION;
else if (length == 11 && strncmp(token, "FOREIGN_KEY", 11) == 0)
local_node->contype = CONSTR_FOREIGN;
else if (length == 15 && strncmp(token, "ATTR_DEFERRABLE", 15) == 0)
local_node->contype = CONSTR_ATTR_DEFERRABLE;
else if (length == 19 && strncmp(token, "ATTR_NOT_DEFERRABLE", 19) == 0)
local_node->contype = CONSTR_ATTR_NOT_DEFERRABLE;
else if (length == 13 && strncmp(token, "ATTR_DEFERRED", 13) == 0)
local_node->contype = CONSTR_ATTR_DEFERRED;
else if (length == 14 && strncmp(token, "ATTR_IMMEDIATE", 14) == 0)
local_node->contype = CONSTR_ATTR_IMMEDIATE;
switch (local_node->contype)
{
case CONSTR_NULL:
/* no extra fields */
break;
case CONSTR_NOTNULL:
READ_NODE_FIELD(keys);
READ_INT_FIELD(inhcount);
READ_BOOL_FIELD(is_no_inherit);
READ_BOOL_FIELD(skip_validation);
READ_BOOL_FIELD(initially_valid);
break;
case CONSTR_DEFAULT:
READ_NODE_FIELD(raw_expr);
READ_STRING_FIELD(cooked_expr);
break;
case CONSTR_IDENTITY:
READ_NODE_FIELD(options);
READ_CHAR_FIELD(generated_when);
break;
case CONSTR_GENERATED:
READ_NODE_FIELD(raw_expr);
READ_STRING_FIELD(cooked_expr);
READ_CHAR_FIELD(generated_when);
break;
case CONSTR_CHECK:
READ_BOOL_FIELD(is_no_inherit);
READ_NODE_FIELD(raw_expr);
READ_STRING_FIELD(cooked_expr);
READ_BOOL_FIELD(skip_validation);
READ_BOOL_FIELD(initially_valid);
break;
case CONSTR_PRIMARY:
READ_NODE_FIELD(keys);
READ_BOOL_FIELD(without_overlaps);
READ_NODE_FIELD(including);
READ_NODE_FIELD(options);
READ_STRING_FIELD(indexname);
READ_STRING_FIELD(indexspace);
READ_BOOL_FIELD(reset_default_tblspc);
/* access_method and where_clause not currently used */
break;
case CONSTR_UNIQUE:
READ_BOOL_FIELD(nulls_not_distinct);
READ_NODE_FIELD(keys);
READ_BOOL_FIELD(without_overlaps);
READ_NODE_FIELD(including);
READ_NODE_FIELD(options);
READ_STRING_FIELD(indexname);
READ_STRING_FIELD(indexspace);
READ_BOOL_FIELD(reset_default_tblspc);
/* access_method and where_clause not currently used */
break;
case CONSTR_EXCLUSION:
READ_NODE_FIELD(exclusions);
READ_NODE_FIELD(including);
READ_NODE_FIELD(options);
READ_STRING_FIELD(indexname);
READ_STRING_FIELD(indexspace);
READ_BOOL_FIELD(reset_default_tblspc);
READ_STRING_FIELD(access_method);
READ_NODE_FIELD(where_clause);
break;
case CONSTR_FOREIGN:
READ_NODE_FIELD(pktable);
READ_NODE_FIELD(fk_attrs);
READ_NODE_FIELD(pk_attrs);
READ_CHAR_FIELD(fk_matchtype);
READ_CHAR_FIELD(fk_upd_action);
READ_CHAR_FIELD(fk_del_action);
READ_NODE_FIELD(fk_del_set_cols);
READ_NODE_FIELD(old_conpfeqop);
READ_OID_FIELD(old_pktable_oid);
READ_BOOL_FIELD(skip_validation);
READ_BOOL_FIELD(initially_valid);
break;
case CONSTR_ATTR_DEFERRABLE:
case CONSTR_ATTR_NOT_DEFERRABLE:
case CONSTR_ATTR_DEFERRED:
case CONSTR_ATTR_IMMEDIATE:
/* no extra fields */
break;
default:
elog(ERROR, "unrecognized ConstrType: %d", (int) local_node->contype);
break;
}
READ_DONE();
}
static RangeTblEntry *
_readRangeTblEntry(void)
{