Re: pg_dump does not dump domain not-null constraint's comments - Mailing list pgsql-hackers

From Noah Misch
Subject Re: pg_dump does not dump domain not-null constraint's comments
Date
Msg-id 20250913020233.fa.nmisch@google.com
Whole thread Raw
In response to Re: pg_dump does not dump domain not-null constraint's comments  (jian he <jian.universality@gmail.com>)
List pgsql-hackers
On Tue, Jul 15, 2025 at 03:40:38PM +0200, Álvaro Herrera wrote:
> On 2025-Jul-15, jian he wrote:
> > we should let:
> > dumpConstraint handles dumping separate "NOT VALID" domain constraints along
> > with their comments.
> > dumpDomain: handles dumping "inlined" valid (not separate) domain constraints
> > together with their comments.

This became commit 0858f0f.

> @@ -18487,8 +18493,25 @@ dumpConstraint(Archive *fout, const ConstraintInfo *coninfo)
>                                            .description = "CHECK CONSTRAINT",
>                                            .section = SECTION_POST_DATA,
>                                            .createStmt = q->data,
>                                            .dropStmt = delq->data));
> +
> +            if (coninfo->dobj.dump & DUMP_COMPONENT_COMMENT)
> +            {
> +                char       *qtypname;
> +
> +                PQExpBuffer conprefix = createPQExpBuffer();
> +                qtypname = pg_strdup(fmtId(tyinfo->dobj.name));
> +
> +                appendPQExpBuffer(conprefix, "CONSTRAINT %s ON DOMAIN",
> +                                  fmtId(coninfo->dobj.name));
> +
> +                dumpComment(fout, conprefix->data, qtypname,
> +                            tyinfo->dobj.namespace->dobj.name,
> +                            tyinfo->rolname,
> +                            coninfo->dobj.catId, 0, tyinfo->dobj.dumpId);

The last argument gives the dump object on which the comment has a dependency.
Since this is the case of a separately-dumped constraint, the comment needs to
depend on that constraint (coninfo), not on the domain (tyinfo):

-                            coninfo->dobj.catId, 0, tyinfo->dobj.dumpId);
+                            coninfo->dobj.catId, 0, coninfo->dobj.dumpId);

I didn't encounter a failure from this, but sufficient restore parallelism
might reach a failure.  A failure would look like a "does not exist" error in
the COMMENT command, due to the constraint not yet existing.
dumpTableConstraintComment() is an older case that optimally handles the last
dumpComment() arg.

In the absence of objections, I'll make it so.



pgsql-hackers by date:

Previous
From: Bharath Rupireddy
Date:
Subject: Re: Proposal: Conflict log history table for Logical Replication
Next
From: Sergey Shinderuk
Date:
Subject: Re: Error with DEFAULT VALUE in temp table