Re: Error position support for ComputeIndexAttrs - Mailing list pgsql-hackers

From jian he
Subject Re: Error position support for ComputeIndexAttrs
Date
Msg-id CACJufxHv13cw9g-mM+skF4JrhAA4dULFvQctwvDpuOL4mwKoRA@mail.gmail.com
Whole thread Raw
In response to Re: Error position support for ComputeIndexAttrs  (Kirill Reshke <reshkekirill@gmail.com>)
Responses Re: Error position support for ComputeIndexAttrs
List pgsql-hackers
On Wed, Dec 31, 2025 at 10:37 PM Kirill Reshke <reshkekirill@gmail.com> wrote:
>
> 4)  DefineIndex inside ATAddIndex. It is triggered for patterns like
> "alter table t add constraint c unique (ii);" - current patch set
> missing support for them. I tried to pass pstate here, but no success,
> because exprLocation returns -1 in ComputeIndexAttrs. Please see my
> attempt attached. I guess this can be completed to get location
> support, but I do not have any time today.

hi.

This will not work for ``ALTER TABLE t ADD CONSTRAINT c UNIQUE (ii);``.
In this case, gram.y produces a single Constraint node, and Constraint node
contain only one location field. However, a unique location is required for each
IndexElem node.
Simply assigning the same location value to all IndexElem nodes does not seem
worth the effort required to add support for this.

see transformIndexConstraint:
``
foreach(lc, constraint->keys)
{
            /* OK, add it to the index definition */
            iparam = makeNode(IndexElem);
             ........
            iparam->location = -1;
            index->indexParams = lappend(index->indexParams, iparam);
}
``

also
``ALTER TABLE t ADD CONSTRAINT c UNIQUE (ii);``
the Constraint.location is the location of the word "CONSTRAINT",
which is far from the IndexElem location we want to report.


--
jian
https://www.enterprisedb.com



pgsql-hackers by date:

Previous
From: Chao Li
Date:
Subject: intarray: fix an edge case int32 overflow bug
Next
From: Chao Li
Date:
Subject: Re: DOC: fixes multiple errors in alter table doc