Re: CHECK Constraint Deferrable - Mailing list pgsql-hackers

From Himanshu Upadhyaya
Subject Re: CHECK Constraint Deferrable
Date
Msg-id CAPF61jCSd85jkVMz_P7kirjyEVGcAJjPpfjgOYDNh2QgSBQMew@mail.gmail.com
Whole thread Raw
In response to Re: CHECK Constraint Deferrable  (Dilip Kumar <dilipbalaut@gmail.com>)
List pgsql-hackers


On Fri, Sep 8, 2023 at 1:23 PM Dilip Kumar <dilipbalaut@gmail.com> wrote:
2.
- if ((failed = ExecRelCheck(resultRelInfo, slot, estate)) != NULL)
+ if ((failed = ExecRelCheck(resultRelInfo, slot, estate,
checkConstraint, &recheckConstraints)) != NULL && !recheckConstraints)


Why recheckConstraints need to get as output from ExecRelCheck?  I
mean whether it will be rechecked or nor is already known by the
caller and
Yes it will be known to the caller but  ExecRelCheck will set this new parameter only if any one of the constraint is defined as Deferrable (in create table statement) and there is a potential constraint violation.
Whether the constraint failed or passed is known based on the return
value so why do you need to extra parameter here?

Because if normal CHECK constraint(non Deferrable) is violated, no need to proceed with the insertion and in that case recheckConstraints will hold "false" but if Deferrable check constraint is violated, we need to revalidate the constraint at commit time and recheckConstraints will hold "true". 

5.
+typedef enum checkConstraintRecheck
+{
+ CHECK_RECHECK_DISABLED, /* Recheck of CHECK constraint is disabled, so
+ * DEFERRED CHECK constraint will be
+ * considered as non-deferrable check
+ * constraint.  */
+ CHECK_RECHECK_ENABLED, /* Recheck of CHECK constraint is enabled, so
+ * CHECK constraint will be validated but
+ * error will not be reported for deferred
+ * CHECK constraint. */
+ CHECK_RECHECK_EXISTING /* Recheck of existing violated CHECK
+ * constraint, indicates that this is a
+ * deferred recheck of a row that was reported
+ * as a potential violation of CHECK
+ * CONSTRAINT */
+} checkConstraintRecheck;

I do not like the naming convention here, especially the words
RECHECK, DISABLE, and ENABLE. And also the name of the enum is a bit
off.  We can name it more like a unique constraint
YES, PARTIAL, EXISTING

I can think of alternative ENUM name as "EnforceDeferredCheck" and  member as “CHECK_DEFERRED_YES”, “CHECK_DEFRRED_NO” and “CHECK_DEFERRED_EXISTING”.

Thoughts?
--
Regards,
Himanshu Upadhyaya
EnterpriseDB: http://www.enterprisedb.com

pgsql-hackers by date:

Previous
From: Daniel Gustafsson
Date:
Subject: Re: Build the docs if there are changes in docs and don't run other tasks if the changes are only in docs
Next
From: "Hayato Kuroda (Fujitsu)"
Date:
Subject: RE: [PoC] pg_upgrade: allow to upgrade publisher node