Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 0E157B5DBF2 for ; Fri, 5 Aug 2011 21:01:36 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 64498-02 for ; Sat, 6 Aug 2011 00:01:30 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mailout-de.gmx.net (mailout-de.gmx.net [213.165.64.22]) by mail.postgresql.org (Postfix) with SMTP id B5E39B5D803 for ; Fri, 5 Aug 2011 21:01:29 -0300 (ADT) Received: (qmail invoked by alias); 06 Aug 2011 00:01:28 -0000 Received: from a88-115-218-165.elisa-laajakaista.fi (EHLO [10.0.0.102]) [88.115.218.165] by mail.gmx.net (mp062) with SMTP; 06 Aug 2011 02:01:28 +0200 X-Authenticated: #495269 X-Provags-ID: V01U2FsdGVkX1/273dCF1r2B/PXyRWVyUeevLQM6Z3lUVdNBtj644 OTU3NG7Pmm7+bm Subject: Re: cataloguing NOT NULL constraints From: Peter Eisentraut To: Alvaro Herrera Cc: Dean Rasheed , Robert Haas , Pg Hackers In-Reply-To: <1312488608-sup-8244@alvh.no-ip.org> References: <20110707213401.GA27098@alvh.no-ip.org> <1311291819-sup-6206@alvh.no-ip.org> <1311367030-sup-9426@alvh.no-ip.org> <1311985058-sup-952@alvh.no-ip.org> <1312342392-sup-7189@alvh.no-ip.org> <1312480674.24208.8.camel@vanquo.pezone.net> <1312488608-sup-8244@alvh.no-ip.org> Content-Type: text/plain; charset="UTF-8" Date: Sat, 06 Aug 2011 03:01:25 +0300 Message-ID: <1312588885.24208.40.camel@vanquo.pezone.net> Mime-Version: 1.0 X-Mailer: Evolution 2.32.3 Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.83 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RP_MATCHES_RCVD=-0.931 X-Spam-Level: X-Archive-Number: 201108/282 X-Sequence-Number: 193037 On tor, 2011-08-04 at 16:15 -0400, Alvaro Herrera wrote: > > Have you considered just cataloging NOT NULL constraints as CHECK > > constraints and teaching the reverse parser to convert "x CHECK (x IS > > NOT NULL)" to "x NOT NULL". > > Hmm, no, I admit I haven't. The current approach was suggested very > early in the history of this patch. Well, the early patch thought this was a small problem. Now we know it's a big problem, so it might be better to solve it terms of another big problem that is already solved. :-) > > It seems to me that we're adding a whole > > lot of hoopla here that is essentially identical to the existing CHECK > > constraint support (it must be, per SQL standard), for no additional > > functionality. > > Yeah, perhaps you're right. The main reason they were considered > separately is that we wanted to have them to be optimized via > pg_attribute.attnotnull, but my patch does away with the need for that > because it is maintained separately anyway. Hmm, OK, but in any case you could have kept attnotnull and treated it as a kind of optimization that indicates whether you can derive not-nullability from existing CHECK constraints (which you can easily do in enough cases). > Before embarking on rewriting this patch from scratch, I would like to > know what's your opinion (or the SQL standard's) on the fact that this > patch separated the PRIMARY KEY from NOT NULL constraints, so that they > don't act exactly alike (to wit, the not-nullness of a PK does not > inherit while the one from a NOT NULL constraint does). The SQL standard deals with inheritance in terms of composite types, which don't have constraints, so that doesn't give any guidance. That said, I think the substitutability property of object-oriented systems, namely that you can use a child object in place of a parent object, requires in principle that we inherit all constraints (by default, at least). We don't inherit primary keys because of implementation issues with indexes, but at some point in the future we should fix that. So to some degree, inheriting the not-null property of primary keys while not inheriting the rest of it is a bit wrong, but it would appear to be a step in the right direction, and changing established behavior seems a bit gratuitous to me.