Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 89CAC1337B47 for ; Mon, 25 Apr 2011 11:57:16 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 35324-03 for ; Mon, 25 Apr 2011 14:57:09 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-bw0-f46.google.com (mail-bw0-f46.google.com [209.85.214.46]) by mail.postgresql.org (Postfix) with ESMTP id 355EF1337A67 for ; Mon, 25 Apr 2011 11:57:06 -0300 (ADT) Received: by bwz15 with SMTP id 15so1676805bwz.19 for ; Mon, 25 Apr 2011 07:57:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=K9gmrkYKJ+UxSFlCGm7Sdadd3NhBLXByY3EtaQy/fsM=; b=n2eXGmmX+TpGFMyJipwWVUcJmSVMScPjvtw6S+n24y1aC/njI38SKM0Cki1fv9y6yr v3+04/ECJcik6gYY3UDBqf4tSMWXTbtGxgV+TqMDKhUnfSYr4JKXoTWMt/MAvFeAO9gc 9ry18kCsFaDgH8XFUsSj3XQ4We6rx1SjjXqUg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=FFPilNqvTjs0p7Gr9tK41yJAG8AYorhI57P8k4ErEzVD/ZXzkUOs1xNCEMC02jJz5c /Pv/piQ+xKPalnHm3WCHHpPGOKguKR+dk5kI/A7OXoVcEIjNIuuk4nQ1CtORLz75g1KV cjRGiRut4tU9APX66b2k4OzqmHl1WUTE2SoZM= MIME-Version: 1.0 Received: by 10.204.20.132 with SMTP id f4mr1795175bkb.169.1303743425349; Mon, 25 Apr 2011 07:57:05 -0700 (PDT) Received: by 10.204.68.19 with HTTP; Mon, 25 Apr 2011 07:57:05 -0700 (PDT) In-Reply-To: <22050.1303341205@sss.pgh.pa.us> References: <201104201251.p3KCpox7062445@wwwmaster.postgresql.org> <22050.1303341205@sss.pgh.pa.us> Date: Mon, 25 Apr 2011 10:57:05 -0400 Message-ID: Subject: Re: BUG #5988: CTINE duplicates constraints From: Robert Haas To: Tom Lane Cc: Marko Tiikkaja , pgsql-bugs@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.898 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RFC_ABUSE_POST=0.001 X-Spam-Level: X-Archive-Number: 201104/186 X-Sequence-Number: 30105 On Wed, Apr 20, 2011 at 7:13 PM, Tom Lane wrote: > "Marko Tiikkaja" writes: >> CREATE TABLE IF NOT EXISTS duplicates some constraints if the new table >> isn't created: > > What this means is that the feature was implemented in the wrong place, > ie the short-circuit is after rather than before parse_utilcmds.c splits > up the CREATE TABLE command into multiple primitive actions. > > I have stated previously my opinion that this is a misconceived feature, > and it's now apparent that the implementation is as poorly thought > through as the definition. =A0My recommendation is to revert that patch > altogether. > > (BTW, before anyone suggests that s/continue/break/ would fix it, > I suggest experimenting with a table containing a serial column.) IIRC, quite a few people voiced support for this feature, so I think that ripping it out because you don't personally like it is not a good solution. That is exactly the sort of thing that gives us a reputation for parochialism. In fact, I believe that the person in response to whose complaint I wrote this patch had exactly that complaint. Having said that, it's not altogether obvious to me what a good fix for this problem would look like. The reason why the check isn't done before transformCreateStmt() is because we don't decide on the creation namespace until we get down to DefineRelation(). We could duplicate that logic prior to calling transformCreateStmt(). That would rely on getting the same answer both times, but apparently we're relying on that anyway in the case of a table with a serial column; else we'd be at risk of putting the sequence and table in different schemas. To avoid information leakage, we'd also need to duplicate the permissions-checking logic that immediately follows, which is a little ugly... but maybe not too ugly, if we encapsulate the whole thing in a function that gets called from multiple places, rather than duplicating the code. In fact, it looks like we already have a bit of information leakage here: rhaas=3D> create table secret.foo (a serial); NOTICE: CREATE TABLE will create implicit sequence "foo_a_seq2" for serial column "foo.a" ERROR: permission denied for schema secret We can infer the existence of foo_a_seq and foo_a_seq1. It seems like a better solution here would be to derive the creation namespace before we break up the statement into subcommands, and pass the OID around after that. Then we wouldn't be doing it multiple times and hoping to get the same answer, and the permissions checking would be happening at the beginning of the process instead of at some point in the middle, which is really the root cause of the above information leak. --=20 Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company