pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: Dependencies for partitioned indexes are still a mess
Date: Wed, 12 Aug 2020 18:48:28 -0400
Message-ID: <20200812224828.GA3888@alvherre.pgsql> (raw)
In-Reply-To: <3170626.1594842723@sss.pgh.pa.us>

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

Attachments:

add-recursive-deps.patch (text/x-diff, 1.7K) download 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; } }

view thread (9+ messages)  latest in thread

Message-ID: <20200812224828.GA3888@alvherre.pgsql>
Permalink:  ../20200812224828.GA3888@alvherre.pgsql/
Also on:    postgresql.org/message-id/20200812224828.GA3888@alvherre.pgsql

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: alvherre@2ndquadrant.com, tgl@sss.pgh.pa.us, pgsql-hackers@lists.postgresql.org
  Subject: Re: Dependencies for partitioned indexes are still a mess
  In-Reply-To: <20200812224828.GA3888@alvherre.pgsql>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox