Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfbc93b8

Browse files
committed
Remove custom Constraint node read/write implementations
This is part of an effort to reduce the number of special cases in theautomatically generated node support functions.Allegedly, only certain fields of the Constraint node are valid basedon contype. But this has historically not been kept up to date in theread/write functions. The Constraint node is only used for debuggingDDL statements, so there are no strong requirements for its output,and there is no enforcement for its correctness. (There was no readsupport beforea6bc330.) Commitse7a552f andabf46ad areexamples of where omissions were fixed.This patch just removes the custom read/write implementations for theConstraint node type. Now we just output all the fields, which is abit more than before, but at least we don't have to maintain thesefunctions anymore. Also, we lose the string representation of thecontype field, but for this marginal use case that seems tolerable.This patch also changes the documentation of the Constraint struct toput less emphasis on grouping fields by constraint type but ratherdocument 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
1 parent801792e commitfbc93b8

File tree

3 files changed

+13
-298
lines changed

3 files changed

+13
-298
lines changed

‎src/backend/nodes/outfuncs.c

Lines changed: 0 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -704,134 +704,6 @@ _outA_Const(StringInfo str, const A_Const *node)
704704
WRITE_LOCATION_FIELD(location);
705705
}
706706

707-
staticvoid
708-
_outConstraint(StringInfostr,constConstraint*node)
709-
{
710-
WRITE_NODE_TYPE("CONSTRAINT");
711-
712-
WRITE_STRING_FIELD(conname);
713-
WRITE_BOOL_FIELD(deferrable);
714-
WRITE_BOOL_FIELD(initdeferred);
715-
WRITE_LOCATION_FIELD(location);
716-
717-
appendStringInfoString(str," :contype ");
718-
switch (node->contype)
719-
{
720-
caseCONSTR_NULL:
721-
appendStringInfoString(str,"NULL");
722-
break;
723-
724-
caseCONSTR_NOTNULL:
725-
appendStringInfoString(str,"NOT_NULL");
726-
WRITE_NODE_FIELD(keys);
727-
WRITE_INT_FIELD(inhcount);
728-
WRITE_BOOL_FIELD(is_no_inherit);
729-
WRITE_BOOL_FIELD(skip_validation);
730-
WRITE_BOOL_FIELD(initially_valid);
731-
break;
732-
733-
caseCONSTR_DEFAULT:
734-
appendStringInfoString(str,"DEFAULT");
735-
WRITE_NODE_FIELD(raw_expr);
736-
WRITE_STRING_FIELD(cooked_expr);
737-
break;
738-
739-
caseCONSTR_IDENTITY:
740-
appendStringInfoString(str,"IDENTITY");
741-
WRITE_NODE_FIELD(options);
742-
WRITE_CHAR_FIELD(generated_when);
743-
break;
744-
745-
caseCONSTR_GENERATED:
746-
appendStringInfoString(str,"GENERATED");
747-
WRITE_NODE_FIELD(raw_expr);
748-
WRITE_STRING_FIELD(cooked_expr);
749-
WRITE_CHAR_FIELD(generated_when);
750-
break;
751-
752-
caseCONSTR_CHECK:
753-
appendStringInfoString(str,"CHECK");
754-
WRITE_BOOL_FIELD(is_no_inherit);
755-
WRITE_NODE_FIELD(raw_expr);
756-
WRITE_STRING_FIELD(cooked_expr);
757-
WRITE_BOOL_FIELD(skip_validation);
758-
WRITE_BOOL_FIELD(initially_valid);
759-
break;
760-
761-
caseCONSTR_PRIMARY:
762-
appendStringInfoString(str,"PRIMARY_KEY");
763-
WRITE_NODE_FIELD(keys);
764-
WRITE_BOOL_FIELD(without_overlaps);
765-
WRITE_NODE_FIELD(including);
766-
WRITE_NODE_FIELD(options);
767-
WRITE_STRING_FIELD(indexname);
768-
WRITE_STRING_FIELD(indexspace);
769-
WRITE_BOOL_FIELD(reset_default_tblspc);
770-
/* access_method and where_clause not currently used */
771-
break;
772-
773-
caseCONSTR_UNIQUE:
774-
appendStringInfoString(str,"UNIQUE");
775-
WRITE_BOOL_FIELD(nulls_not_distinct);
776-
WRITE_NODE_FIELD(keys);
777-
WRITE_BOOL_FIELD(without_overlaps);
778-
WRITE_NODE_FIELD(including);
779-
WRITE_NODE_FIELD(options);
780-
WRITE_STRING_FIELD(indexname);
781-
WRITE_STRING_FIELD(indexspace);
782-
WRITE_BOOL_FIELD(reset_default_tblspc);
783-
/* access_method and where_clause not currently used */
784-
break;
785-
786-
caseCONSTR_EXCLUSION:
787-
appendStringInfoString(str,"EXCLUSION");
788-
WRITE_NODE_FIELD(exclusions);
789-
WRITE_NODE_FIELD(including);
790-
WRITE_NODE_FIELD(options);
791-
WRITE_STRING_FIELD(indexname);
792-
WRITE_STRING_FIELD(indexspace);
793-
WRITE_BOOL_FIELD(reset_default_tblspc);
794-
WRITE_STRING_FIELD(access_method);
795-
WRITE_NODE_FIELD(where_clause);
796-
break;
797-
798-
caseCONSTR_FOREIGN:
799-
appendStringInfoString(str,"FOREIGN_KEY");
800-
WRITE_NODE_FIELD(pktable);
801-
WRITE_NODE_FIELD(fk_attrs);
802-
WRITE_NODE_FIELD(pk_attrs);
803-
WRITE_CHAR_FIELD(fk_matchtype);
804-
WRITE_CHAR_FIELD(fk_upd_action);
805-
WRITE_CHAR_FIELD(fk_del_action);
806-
WRITE_NODE_FIELD(fk_del_set_cols);
807-
WRITE_NODE_FIELD(old_conpfeqop);
808-
WRITE_OID_FIELD(old_pktable_oid);
809-
WRITE_BOOL_FIELD(skip_validation);
810-
WRITE_BOOL_FIELD(initially_valid);
811-
break;
812-
813-
caseCONSTR_ATTR_DEFERRABLE:
814-
appendStringInfoString(str,"ATTR_DEFERRABLE");
815-
break;
816-
817-
caseCONSTR_ATTR_NOT_DEFERRABLE:
818-
appendStringInfoString(str,"ATTR_NOT_DEFERRABLE");
819-
break;
820-
821-
caseCONSTR_ATTR_DEFERRED:
822-
appendStringInfoString(str,"ATTR_DEFERRED");
823-
break;
824-
825-
caseCONSTR_ATTR_IMMEDIATE:
826-
appendStringInfoString(str,"ATTR_IMMEDIATE");
827-
break;
828-
829-
default:
830-
elog(ERROR,"unrecognized ConstrType: %d", (int)node->contype);
831-
break;
832-
}
833-
}
834-
835707

836708
/*
837709
* outNode -

‎src/backend/nodes/readfuncs.c

Lines changed: 0 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -343,151 +343,6 @@ _readA_Const(void)
343343
READ_DONE();
344344
}
345345

346-
/*
347-
* _readConstraint
348-
*/
349-
staticConstraint*
350-
_readConstraint(void)
351-
{
352-
READ_LOCALS(Constraint);
353-
354-
READ_STRING_FIELD(conname);
355-
READ_BOOL_FIELD(deferrable);
356-
READ_BOOL_FIELD(initdeferred);
357-
READ_LOCATION_FIELD(location);
358-
359-
token=pg_strtok(&length);/* skip :contype */
360-
token=pg_strtok(&length);/* get field value */
361-
if (length==4&&strncmp(token,"NULL",4)==0)
362-
local_node->contype=CONSTR_NULL;
363-
elseif (length==8&&strncmp(token,"NOT_NULL",8)==0)
364-
local_node->contype=CONSTR_NOTNULL;
365-
elseif (length==7&&strncmp(token,"DEFAULT",7)==0)
366-
local_node->contype=CONSTR_DEFAULT;
367-
elseif (length==8&&strncmp(token,"IDENTITY",8)==0)
368-
local_node->contype=CONSTR_IDENTITY;
369-
elseif (length==9&&strncmp(token,"GENERATED",9)==0)
370-
local_node->contype=CONSTR_GENERATED;
371-
elseif (length==5&&strncmp(token,"CHECK",5)==0)
372-
local_node->contype=CONSTR_CHECK;
373-
elseif (length==11&&strncmp(token,"PRIMARY_KEY",11)==0)
374-
local_node->contype=CONSTR_PRIMARY;
375-
elseif (length==6&&strncmp(token,"UNIQUE",6)==0)
376-
local_node->contype=CONSTR_UNIQUE;
377-
elseif (length==9&&strncmp(token,"EXCLUSION",9)==0)
378-
local_node->contype=CONSTR_EXCLUSION;
379-
elseif (length==11&&strncmp(token,"FOREIGN_KEY",11)==0)
380-
local_node->contype=CONSTR_FOREIGN;
381-
elseif (length==15&&strncmp(token,"ATTR_DEFERRABLE",15)==0)
382-
local_node->contype=CONSTR_ATTR_DEFERRABLE;
383-
elseif (length==19&&strncmp(token,"ATTR_NOT_DEFERRABLE",19)==0)
384-
local_node->contype=CONSTR_ATTR_NOT_DEFERRABLE;
385-
elseif (length==13&&strncmp(token,"ATTR_DEFERRED",13)==0)
386-
local_node->contype=CONSTR_ATTR_DEFERRED;
387-
elseif (length==14&&strncmp(token,"ATTR_IMMEDIATE",14)==0)
388-
local_node->contype=CONSTR_ATTR_IMMEDIATE;
389-
390-
switch (local_node->contype)
391-
{
392-
caseCONSTR_NULL:
393-
/* no extra fields */
394-
break;
395-
396-
caseCONSTR_NOTNULL:
397-
READ_NODE_FIELD(keys);
398-
READ_INT_FIELD(inhcount);
399-
READ_BOOL_FIELD(is_no_inherit);
400-
READ_BOOL_FIELD(skip_validation);
401-
READ_BOOL_FIELD(initially_valid);
402-
break;
403-
404-
caseCONSTR_DEFAULT:
405-
READ_NODE_FIELD(raw_expr);
406-
READ_STRING_FIELD(cooked_expr);
407-
break;
408-
409-
caseCONSTR_IDENTITY:
410-
READ_NODE_FIELD(options);
411-
READ_CHAR_FIELD(generated_when);
412-
break;
413-
414-
caseCONSTR_GENERATED:
415-
READ_NODE_FIELD(raw_expr);
416-
READ_STRING_FIELD(cooked_expr);
417-
READ_CHAR_FIELD(generated_when);
418-
break;
419-
420-
caseCONSTR_CHECK:
421-
READ_BOOL_FIELD(is_no_inherit);
422-
READ_NODE_FIELD(raw_expr);
423-
READ_STRING_FIELD(cooked_expr);
424-
READ_BOOL_FIELD(skip_validation);
425-
READ_BOOL_FIELD(initially_valid);
426-
break;
427-
428-
caseCONSTR_PRIMARY:
429-
READ_NODE_FIELD(keys);
430-
READ_BOOL_FIELD(without_overlaps);
431-
READ_NODE_FIELD(including);
432-
READ_NODE_FIELD(options);
433-
READ_STRING_FIELD(indexname);
434-
READ_STRING_FIELD(indexspace);
435-
READ_BOOL_FIELD(reset_default_tblspc);
436-
/* access_method and where_clause not currently used */
437-
break;
438-
439-
caseCONSTR_UNIQUE:
440-
READ_BOOL_FIELD(nulls_not_distinct);
441-
READ_NODE_FIELD(keys);
442-
READ_BOOL_FIELD(without_overlaps);
443-
READ_NODE_FIELD(including);
444-
READ_NODE_FIELD(options);
445-
READ_STRING_FIELD(indexname);
446-
READ_STRING_FIELD(indexspace);
447-
READ_BOOL_FIELD(reset_default_tblspc);
448-
/* access_method and where_clause not currently used */
449-
break;
450-
451-
caseCONSTR_EXCLUSION:
452-
READ_NODE_FIELD(exclusions);
453-
READ_NODE_FIELD(including);
454-
READ_NODE_FIELD(options);
455-
READ_STRING_FIELD(indexname);
456-
READ_STRING_FIELD(indexspace);
457-
READ_BOOL_FIELD(reset_default_tblspc);
458-
READ_STRING_FIELD(access_method);
459-
READ_NODE_FIELD(where_clause);
460-
break;
461-
462-
caseCONSTR_FOREIGN:
463-
READ_NODE_FIELD(pktable);
464-
READ_NODE_FIELD(fk_attrs);
465-
READ_NODE_FIELD(pk_attrs);
466-
READ_CHAR_FIELD(fk_matchtype);
467-
READ_CHAR_FIELD(fk_upd_action);
468-
READ_CHAR_FIELD(fk_del_action);
469-
READ_NODE_FIELD(fk_del_set_cols);
470-
READ_NODE_FIELD(old_conpfeqop);
471-
READ_OID_FIELD(old_pktable_oid);
472-
READ_BOOL_FIELD(skip_validation);
473-
READ_BOOL_FIELD(initially_valid);
474-
break;
475-
476-
caseCONSTR_ATTR_DEFERRABLE:
477-
caseCONSTR_ATTR_NOT_DEFERRABLE:
478-
caseCONSTR_ATTR_DEFERRED:
479-
caseCONSTR_ATTR_IMMEDIATE:
480-
/* no extra fields */
481-
break;
482-
483-
default:
484-
elog(ERROR,"unrecognized ConstrType: %d", (int)local_node->contype);
485-
break;
486-
}
487-
488-
READ_DONE();
489-
}
490-
491346
staticRangeTblEntry*
492347
_readRangeTblEntry(void)
493348
{

‎src/include/nodes/parsenodes.h

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,44 +2566,34 @@ typedef enum ConstrType/* types of constraints */
25662566

25672567
typedefstructConstraint
25682568
{
2569-
pg_node_attr(custom_read_write)
2570-
25712569
NodeTagtype;
25722570
ConstrTypecontype;/* see above */
2573-
2574-
/* Fields used for most/all constraint types: */
25752571
char*conname;/* Constraint name, or NULL if unnamed */
25762572
booldeferrable;/* DEFERRABLE? */
25772573
boolinitdeferred;/* INITIALLY DEFERRED? */
2578-
intlocation;/* token location, or -1 if unknown */
2579-
2580-
/* Fields used for constraints with expressions (CHECK and DEFAULT): */
2574+
boolskip_validation;/* skip validation of existing rows? */
2575+
boolinitially_valid;/* mark the new constraint as valid? */
25812576
boolis_no_inherit;/* is constraint non-inheritable? */
2582-
Node*raw_expr;/* expr, as untransformed parse tree */
2583-
char*cooked_expr;/* expr, as nodeToString representation */
2577+
Node*raw_expr;/* CHECK or DEFAULT expression, as
2578+
* untransformed parse tree */
2579+
char*cooked_expr;/* CHECK or DEFAULT expression, as
2580+
* nodeToString representation */
25842581
chargenerated_when;/* ALWAYS or BY DEFAULT */
2585-
2586-
/* Fields used for "raw" NOT NULL constraints: */
2587-
intinhcount;/* initial inheritance count to apply */
2588-
2589-
/* Fields used for unique constraints (UNIQUE and PRIMARY KEY): */
2582+
intinhcount;/* initial inheritance count to apply, for
2583+
* "raw" NOT NULL constraints */
25902584
boolnulls_not_distinct;/* null treatment for UNIQUE constraints */
25912585
List*keys;/* String nodes naming referenced key
2592-
* column(s);also usedfor NOT NULL */
2586+
* column(s); forUNIQUE/PK/NOT NULL */
25932587
boolwithout_overlaps;/* WITHOUT OVERLAPS specified */
25942588
List*including;/* String nodes naming referenced nonkey
2595-
* column(s) */
2596-
2597-
/* Fields used for EXCLUSION constraints: */
2598-
List*exclusions;/* list of (IndexElem, operator name) pairs */
2599-
2600-
/* Fields used for index constraints (UNIQUE, PRIMARY KEY, EXCLUSION): */
2589+
* column(s); for UNIQUE/PK */
2590+
List*exclusions;/* list of (IndexElem, operator name) pairs;
2591+
* for exclusion constraints */
26012592
List*options;/* options from WITH clause */
26022593
char*indexname;/* existing index to use; otherwise NULL */
26032594
char*indexspace;/* index tablespace; NULL for default */
26042595
boolreset_default_tblspc;/* reset default_tablespace prior to
26052596
* creating the index */
2606-
/* These could be, but currently are not, used for UNIQUE/PKEY: */
26072597
char*access_method;/* index access method; NULL for default */
26082598
Node*where_clause;/* partial index predicate */
26092599

@@ -2619,9 +2609,7 @@ typedef struct Constraint
26192609
Oidold_pktable_oid;/* pg_constraint.confrelid of my former
26202610
* self */
26212611

2622-
/* Fields used for constraints that allow a NOT VALID specification */
2623-
boolskip_validation;/* skip validation of existing rows? */
2624-
boolinitially_valid;/* mark the new constraint as valid? */
2612+
intlocation;/* token location, or -1 if unknown */
26252613
}Constraint;
26262614

26272615
/* ----------------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp