Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k5zXz-0002KR-S3 for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Aug 2020 22:48:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k5zXx-00013L-Tf for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Aug 2020 22:48:37 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k5zXx-00013E-Ms for pgsql-hackers@lists.postgresql.org; Wed, 12 Aug 2020 22:48:37 +0000 Received: from mail-qk1-x744.google.com ([2607:f8b0:4864:20::744]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1k5zXt-0006LE-HQ for pgsql-hackers@lists.postgresql.org; Wed, 12 Aug 2020 22:48:35 +0000 Received: by mail-qk1-x744.google.com with SMTP id 2so3603027qkf.10 for ; Wed, 12 Aug 2020 15:48: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=ukySxnQj3C5kRBHN6gsedu3BV8NkG2TVxAxmLcHyrro=; b=1fFZN2tXEbSsDPQ6NHM1iD03BgXgAL4MS+g/CLNermbMg6+i1spW0R0J9dhoKHeoiU sNSwlFScWW+QhUX/XRl7E064GKry2Eh7ZfKwigUhpMXTQlb+PMYCguePoSspyNkCgEhZ H4g8QIPxrfy/nIcoqzGsutNYHpyXGA3MKUcA6dMdFduLu1X6I3z5rBzAvSQh9DvQz9dh 6pPjhAgZh1YQ3QvVnNEpjL+rT1yuGac7OJcwCujW59s31cxLJwqrPN77G9TFUyArKr69 wPCBVj/TveNHZD5wBb7WHxgdXTfjrNOrHDhkiLjxlW/MRglm+1PuV+cZ3q/d4eNGY2ue C18g== 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=ukySxnQj3C5kRBHN6gsedu3BV8NkG2TVxAxmLcHyrro=; b=BG+qAVi4RPjK3yiR6Jt1cnzcBbie+cysSUE9VcyVbaDfCnFWaSYSLV3jgmJv1mfWZx YedOsFLLQkb4IiJs/9hV7koWWgEoqu2aXP+a9mMZw+J6Zoq3teceo2wYXP00fmf/T1OQ uBNIVjzsf7szrr3QB6Y4sU7Lsm8O8abzGyZXPUbtu83WrttKSzk9giyRtH6bgDUQMYC7 T2OTtx0+qov1Ef9DqZkzcFNBJaPJ9YOe92tIxHqbuwDTsYJ9eO07hyFmurr5QJPd5LJF atB1hemoBAdP9KYDFEUdKPnrlmVVo3TOlYQ6gEIdzUv8K/sgfiJz8hN5BHyZrXu2rr5D Z0+Q== X-Gm-Message-State: AOAM532V2NcGCGXH7K/+EMsBHyVnun3x4MoKODilYpI6tAC9mpgYLop9 0fQJ3dF9pYb0KD0RPCRddco2+/xwN8xL8RPo4r8BpQvSOoQbTnojaPSA/c7Iv56gUvVTCPesJl5 lLNakHo5pCrlIqVyzqHqp4MvgrrybRZSihOhvS806vvE9XgQs+LcpnzEozsweLXMqetoerwMF0p naCtqktGjdb8cvyLZn X-Google-Smtp-Source: ABdhPJzKyJa6VMJ+xswt+rIzo80uUQeX9Q2tFeQHhY1G1dmvbzKQGP0Of3f3wi3xbSUKG9KnmUmrjg== X-Received: by 2002:a37:e04:: with SMTP id 4mr2082993qko.269.1597272511434; Wed, 12 Aug 2020 15:48:31 -0700 (PDT) Received: from perhan.alvh.no-ip.org ([190.95.19.47]) by smtp.gmail.com with ESMTPSA id q126sm3440749qkb.75.2020.08.12.15.48.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Aug 2020 15:48:30 -0700 (PDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id D419D2A0D10; Wed, 12 Aug 2020 18:48:28 -0400 (-04) Date: Wed, 12 Aug 2020 18:48:28 -0400 From: Alvaro Herrera To: Tom Lane Cc: pgsql-hackers@lists.postgresql.org Subject: Re: Dependencies for partitioned indexes are still a mess Message-ID: <20200812224828.GA3888@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="AqsLC8rIMeq19msA" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3170626.1594842723@sss.pgh.pa.us> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --AqsLC8rIMeq19msA Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2020-Jul-15, Tom Lane wrote: > Issue #2: parallel restore does not work > > 1. dropdb r2; createdb r2 > 2. pg_restore -j8 -d r2 regression.dump > > This is fairly timing-dependent, but some attempts fail with messages > like > > pg_restore: while PROCESSING TOC: > pg_restore: from TOC entry 6684; 2606 29166 FK CONSTRAINT fk fk_a_fkey postgres > pg_restore: error: could not execute query: ERROR: there is no unique constraint matching given keys for referenced table "pk" > Command was: ALTER TABLE fkpart3.fk > ADD CONSTRAINT fk_a_fkey FOREIGN KEY (a) REFERENCES fkpart3.pk(a); Hmm, we do make the FK constraint depend on the ATTACH for the direct children; what I think we're lacking is dependencies on descendants twice-removed (?) or higher. This mock patch seems to fix this problem by adding dependencies recursively on all children of the index; I no longer see this problem with it. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --AqsLC8rIMeq19msA Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="add-recursive-deps.patch" diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 42391b0b2c..c78bbd7d00 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -7412,6 +7412,24 @@ getExtendedStatistics(Archive *fout) destroyPQExpBuffer(query); } +/* recursive bit of getConstraints */ +static void +addConstrChildIdxDeps(DumpableObject *dobj, IndxInfo *refidx) +{ + SimplePtrListCell *cell; + + for (cell = refidx->partattaches.head; cell; cell = cell->next) + { + DumpableObject *childobj = (DumpableObject *) cell->ptr; + IndexAttachInfo *attach = (IndexAttachInfo *) childobj; + + addObjectDependency(dobj, childobj->dumpId); + + if (attach->partitionIdx->partattaches.head != NULL) + addConstrChildIdxDeps(dobj, attach->partitionIdx); + } +} + /* * getConstraints * @@ -7517,25 +7535,20 @@ getConstraints(Archive *fout, TableInfo tblinfo[], int numTables) reftable = findTableByOid(constrinfo[j].confrelid); if (reftable && reftable->relkind == RELKIND_PARTITIONED_TABLE) { - IndxInfo *refidx; Oid indexOid = atooid(PQgetvalue(res, j, i_conindid)); if (indexOid != InvalidOid) { for (int k = 0; k < reftable->numIndexes; k++) { - SimplePtrListCell *cell; + IndxInfo *refidx; /* not our index? */ if (reftable->indexes[k].dobj.catId.oid != indexOid) continue; refidx = &reftable->indexes[k]; - for (cell = refidx->partattaches.head; cell; - cell = cell->next) - addObjectDependency(&constrinfo[j].dobj, - ((DumpableObject *) - cell->ptr)->dumpId); + addConstrChildIdxDeps(&constrinfo[j].dobj, refidx); break; } } --AqsLC8rIMeq19msA--