Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h747l-0003P4-Bt for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Mar 2019 20:17:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h747k-0007Hm-2B for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Mar 2019 20:17:12 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h747j-0007He-Nj for pgsql-hackers@lists.postgresql.org; Thu, 21 Mar 2019 20:17:11 +0000 Received: from mail-qk1-x744.google.com ([2607:f8b0:4864:20::744]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h747g-0007C7-Vu for pgsql-hackers@postgresql.org; Thu, 21 Mar 2019 20:17:10 +0000 Received: by mail-qk1-x744.google.com with SMTP id z76so17129586qkb.12 for ; Thu, 21 Mar 2019 13:17:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=S9PfSD0YWlZmbLZXdn0oGQI9CshLJL6ZD4nwxLfyOac=; b=ZG/x+5YucKaWJnYZjCaLGvjdHGzzaqYPaQNaDLX3tEIVagXt9ROvOTQKT+Zkoz0/LM AoPRgmt9gJmt7M/2zy/XcB3XhhP70WYcSTKF6bZpvQeERgiVZEUj1YhFCoh8FNMa1BHn vlWmpcJMCssnV4bK7t1F7obh9MQE/vFgP+wplWR6t6q8Hqmd2Y7iauI5r+/ASJBH5RW5 dk4FLwWaUa/xUMwXb1jwuNXjO6JtJbKjbK8ZNg+mjqsX3cGB19JzPMZ/dwr9UxH2H2A2 O5pReeY2cPWfC24fA/f0YLjZ0itv9Y2Z2GiAKFTA7LvLTMtav4YPWJqMNn1JK4bcvyS7 L2Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=S9PfSD0YWlZmbLZXdn0oGQI9CshLJL6ZD4nwxLfyOac=; b=P1VZoVdWSCtjxc5jCsIRvi0WW9/G7RbEKz/NupJSFFwInXDJJGGnibhvfodAAj+6C5 CvpOl2/ASxSI+hrk39pMrdM3RvPIe/q8TKTG8TAkzFkL8Fh/8StDWJwhFQQmfPkeKaRT wPwLqvv4r+SKAuGwdddQf5mb2+DHmzvgNXHuElH0l+HeBdzYUc/KuifmcmKUQQkmh2Ak 8+LpNM5EGnnxxncM/wMLxqC2Ce8Uh38T3UQvHgJr5wuI1sDVBDJkQk0ekw9LeUVmUyCO TOEq2lvN1sgpAj9x2ptavFLYRYF/1K8MI94+eV/o+re3NhmzWR3wfYA8qKp7M5VMJEyt popg== X-Gm-Message-State: APjAAAVi5OcDwTBibeHED0mfrDFzUj3QQjwErHPaVMNdD59RatEEKJ2T naGG/zhKU7Ra7p3Vi6rpDGX76A== X-Google-Smtp-Source: APXvYqwgg9P6zW4akXkwySJYXGv+h1OExJ2lqSOUl3UJarbHOyPLClaqYMKq5OJUVzgxadboykFtug== X-Received: by 2002:a37:cfdd:: with SMTP id v90mr4299167qkl.305.1553199427862; Thu, 21 Mar 2019 13:17:07 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([190.121.29.3]) by smtp.gmail.com with ESMTPSA id n24sm4931927qtc.21.2019.03.21.13.17.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Mar 2019 13:17:06 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 82B34120694; Thu, 21 Mar 2019 17:17:04 -0300 (-03) Date: Thu, 21 Mar 2019 17:17:04 -0300 From: Alvaro Herrera To: Jesper Pedersen Cc: Amit Langote , Pg Hackers Subject: Re: partitioned tables referenced by FKs Message-ID: <20190321201704.GA8280@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190318204235.GA30360@alvherre.pgsql> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2019-Mar-18, Alvaro Herrera wrote: > > I'm getting a failure in the pg_upgrade test: > > > > -- > > +-- Name: pk5 pk5_pkey; Type: CONSTRAINT; Schema: regress_fk; Owner: > > jpedersen > > +-- > > + > > +ALTER TABLE ONLY regress_fk.pk5 > > + ADD CONSTRAINT pk5_pkey PRIMARY KEY (a); > > + > > + > > +-- > > > > when running check-world. > > So I tested this case just now (after fixing a couple of bugs) and see a > slightly different problem now: those excess lines are actually just > that pg_dump chose to print the constraints in different order, as there > are identical lines with "-" in the diff I get. The databases actually > *are* identical as far as I can tell. I haven't yet figured out how to > fix this; of course, the easiest solution is to just drop the regress_fk > schema at the end of the foreign_key.sql regression test, but I would > prefer a different solution. I figured this out. It's actually a bug in pg11, whereby we're setting a dependency wrongly. If you try to do pg_describe_object() the pg_depend entries for tables set up the way the regression test does it, it'll fail with a "cache lookup failed for constraint XYZ". In other words, pg_depend contains bogus data :-( Here's one possible fix: diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index c339a2bb779..8f62b454f75 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1357,6 +1357,8 @@ index_constraint_create(Relation heapRelation, */ if (OidIsValid(parentConstraintId)) { + ObjectAddress referenced; /* XXX shadow outer variable */ + ObjectAddressSet(myself, ConstraintRelationId, conOid); ObjectAddressSet(referenced, ConstraintRelationId, parentConstraintId); recordDependencyOn(&myself, &referenced, DEPENDENCY_PARTITION_PRI); I can tell the raised eyebrows from a mile away :-( The problem (and the reason shadowing the variable solves it) is that the outer 'referenced' is the function's return value. This block was clobbering the value previously set, which is what we really wanted to return. /me dons paper bag I'll go figure out what a better solution is. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services