Re: [PATCHES] [badalex@gmail.com: Re: [BUGS] Problem identifying constraints which should not be inherited] - Mailing list pgsql-hackers

From Alex Hunsaker
Subject Re: [PATCHES] [badalex@gmail.com: Re: [BUGS] Problem identifying constraints which should not be inherited]
Date
Msg-id 34d269d40805062341g6cd610beweb28afd63caae7b8@mail.gmail.com
Whole thread Raw
In response to Re: [PATCHES] [badalex@gmail.com: Re: [BUGS] Problem identifying constraints which should not be inherited]  (NikhilS <nikkhils@gmail.com>)
List pgsql-hackers
On Wed, May 7, 2008 at 12:20 AM, Alex Hunsaker <badalex@gmail.com> wrote:
>  Find attached a diff from v4-v5, and a full patch.
>
>   src/backend/commands/tablecmds.c   |  242 +++++++++++++++++++++++-------------
>
>  src/backend/utils/cache/syscache.c |   12 --
>
>  src/include/catalog/indexing.h     |    2 -
>   src/include/utils/syscache.h       |    1 -
>   4 files changed, 153 insertions(+), 104 deletions(-)
>
>  Currently this loops through all the constraints for a relation (old
>  behavior of MergeAttributesIntoExisting)... Do you think its worth
>  adding a non-unique index to speed this up?  If so I can whip up a
>  patch real quick if you think its worth it... else
>

*sigh* Here is a fiix for a possible bogus "failed to find constraint"
error when we are trying to drop a constraint that is not a check
constraint
(interesting no regression tests failed... caught it while reviewing
the patch I just posted)

*** a/src/backend/commands/tablecmds.c
--- /bsrc/backend/commands/tablecmds.c
*************** ATExecDropConstraint(Relation rel, const
*** 5080,5094 ****

                                con = (Form_pg_constraint) GETSTRUCT(tuple);

-                               if (con->contype != CONSTRAINT_CHECK)
-                                       continue;
-
                                if (strcmp(NameStr(con->conname),
                                                   constrName) != 0)
                                        continue;
                                else
                                        found = true;

                                if (con->coninhcount <= 0)
                                        elog(ERROR, "relation %u has
non-inherited constraint \"%s\"",
                                                childrelid, constrName);
--- 5080,5095 ----

                                con = (Form_pg_constraint) GETSTRUCT(tuple);

                                if (strcmp(NameStr(con->conname),
                                                   constrName) != 0)
                                        continue;
                                else
                                        found = true;

+                               /* Right now only CHECK constraints
can be inherited */
+                               if (con->contype != CONSTRAINT_CHECK)
+                                       continue;
+
                                if (con->coninhcount <= 0)
                                        elog(ERROR, "relation %u has
non-inherited constraint \"%s\"",
                                                childrelid, constrName);

pgsql-hackers by date:

Previous
From: Dimitri Fontaine
Date:
Subject: Re: alter + preserving dependencies
Next
From: KaiGai Kohei
Date:
Subject: Re: [0/4] Proposal of SE-PostgreSQL patches