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 1h74d8-0004zJ-MO for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Mar 2019 20:49:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h74d7-0007Nm-9K for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Mar 2019 20:49:37 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h74d7-0007KC-1f for pgsql-hackers@lists.postgresql.org; Thu, 21 Mar 2019 20:49:37 +0000 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h74d3-0000rR-PN for pgsql-hackers@postgresql.org; Thu, 21 Mar 2019 20:49:36 +0000 Received: by mail-qt1-x841.google.com with SMTP id t28so190659qte.6 for ; Thu, 21 Mar 2019 13:49:33 -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=gmu3ZlYEAbUPqkH2PvIr+0rlxigLEUGAfm0jSPwTKU4=; b=HpG9YGkAvuEb2UmMuZiVlSdB2I1QaZDy40NYUaFStg+AZ92L3CUYdUOaQtRLallyVa jyquN5Uo0Uzzu2bH9uVaBrVjkuORntWKwJqTaeI5Cdqc5EeVkw+PyHsikNANrYI6kAHq ytPXkt/5L9NLQyoyuPENyxZwkpmr9PatwR4BROUp2nFrqXZYmfU8RPRRGKXEYnoZGdlA q+fzYKCRoiNU1x1rd8aEUMNDUX/QnkJxcfx42lGWuE3vb4tmHd3h3Esq7w7Rm7CfawX+ 8MQycfp0XLz61vsQ4ZZVnE/lpmfLWDNa0QV5Xa29rpFY1gpO+lXf6HjRmf91FtDzifVb 4nQQ== 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=gmu3ZlYEAbUPqkH2PvIr+0rlxigLEUGAfm0jSPwTKU4=; b=Uq8MYG2IaOz79yPhlLXKxYhc5Gk9CXRFyWwhSeTxMAJV7byDQAzsKiPCC1czd35PPT 4wJfVQV/rf4LhklM7MIPab9qJGrsOUA9EVwVZw3iOfxL6mt3MM/tvqcv6l64FaDQrBeN fDaYSd7jzVkJNrrEjZtNAEygfjvzJe9cJx4jWH6C+2eWU6ijofd9hByF/K0EW654f6PS alr3Y1QBDD2KiwB90OTamC1bNRdkr8W+7KSG5lE/5IwG+Dw3XPtUjpVwr2hXpQSGnQiE 5DhKMvbHKOu9o5fH9IDizUyGEswcJLz0wXkNxFA8jHLUIt479rmQNTX9gkuetDV4UVIo 5TCA== X-Gm-Message-State: APjAAAVdXXGhwDUxP2Ti5W/qCv8BGEEVi/syycjdXF1G00fIowazdigH zyW37Ee63u9bikMT2qPrkNnoMg== X-Google-Smtp-Source: APXvYqygK7AcRfrWccphFw7rif9hUyecf6pxJF6drH6o4RV++3PbCQNodqM3wxwmmb6tJs1RMpgXFA== X-Received: by 2002:a0c:a485:: with SMTP id x5mr4913167qvx.206.1553201371936; Thu, 21 Mar 2019 13:49:31 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([190.121.29.3]) by smtp.gmail.com with ESMTPSA id u15sm4810341qth.54.2019.03.21.13.49.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Mar 2019 13:49:31 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id C9FB4120694; Thu, 21 Mar 2019 17:49:28 -0300 (-03) Date: Thu, 21 Mar 2019 17:49:28 -0300 From: Alvaro Herrera To: Jesper Pedersen Cc: Amit Langote , Pg Hackers Subject: Re: partitioned tables referenced by FKs Message-ID: <20190321204928.GA17535@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="0F1p//8PRICkK4MW" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190321201704.GA8280@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 --0F1p//8PRICkK4MW Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2019-Mar-21, Alvaro Herrera wrote: > 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 :-( Oh, actually, it's not a problem in PG11 ... or at least, it's not THIS problem in pg11. The bug was introduced by 1d92a0c9f7dd which ended the DEPENDENCY_INTERNAL_AUTO saga, so the bug is only in master, and that explains why I hadn't seen the problem before with my posted patch series. I think the attached is a better solution, which I'll go push shortly. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --0F1p//8PRICkK4MW Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="shadow.patch" diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index c339a2bb779..cb2c0010171 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1247,7 +1247,7 @@ index_constraint_create(Relation heapRelation, { Oid namespaceId = RelationGetNamespace(heapRelation); ObjectAddress myself, - referenced; + idxaddr; Oid conOid; bool deferrable; bool initdeferred; @@ -1341,15 +1341,9 @@ index_constraint_create(Relation heapRelation, * Note that the constraint has a dependency on the table, so we don't * need (or want) any direct dependency from the index to the table. */ - myself.classId = RelationRelationId; - myself.objectId = indexRelationId; - myself.objectSubId = 0; - - referenced.classId = ConstraintRelationId; - referenced.objectId = conOid; - referenced.objectSubId = 0; - - recordDependencyOn(&myself, &referenced, DEPENDENCY_INTERNAL); + ObjectAddressSet(myself, ConstraintRelationId, conOid); + ObjectAddressSet(idxaddr, RelationRelationId, indexRelationId); + recordDependencyOn(&idxaddr, &myself, DEPENDENCY_INTERNAL); /* * Also, if this is a constraint on a partition, give it partition-type @@ -1357,7 +1351,8 @@ index_constraint_create(Relation heapRelation, */ if (OidIsValid(parentConstraintId)) { - ObjectAddressSet(myself, ConstraintRelationId, conOid); + ObjectAddress referenced; + ObjectAddressSet(referenced, ConstraintRelationId, parentConstraintId); recordDependencyOn(&myself, &referenced, DEPENDENCY_PARTITION_PRI); ObjectAddressSet(referenced, RelationRelationId, @@ -1444,7 +1439,7 @@ index_constraint_create(Relation heapRelation, table_close(pg_index, RowExclusiveLock); } - return referenced; + return myself; } /* --0F1p//8PRICkK4MW--