[PATCH] psql: Fix REPACK index completion after a column list
[PATCH] psql: Fix REPACK index completion after a column list
Hi hackers,
After a column list, psql's index completion for `REPACK` offers indexes
from unrelated tables. For example:
After a column list, psql's index completion for `REPACK` offers indexes
from unrelated tables. For example:
```
REPACK (ANALYZE) tab1 (c1) USING INDEX <Tab>
```
The completion code uses `prev3_wd` as the table name, but that word is
the column list in this form. The table-specific query returns nothing,
and completion falls back to listing all indexes.
The attached fix uses `prev4_wd` when a column list is present. It also
completes `USING INDEX` after the column list.
The regression tests are in a separate patch extending the existing
`src/bin/psql/t/010_tab_completion.pl`.
Thanks,
Sho
The completion code uses `prev3_wd` as the table name, but that word is
the column list in this form. The table-specific query returns nothing,
and completion falls back to listing all indexes.
The attached fix uses `prev4_wd` when a column list is present. It also
completes `USING INDEX` after the column list.
The regression tests are in a separate patch extending the existing
`src/bin/psql/t/010_tab_completion.pl`.
Thanks,
Sho
=======================================
Sho Ito (Sean)
E-mail: i.sho.0628@gmail.com
GitHub: https://github.com/sean0628/
=======================================
Re: [PATCH] psql: Fix REPACK index completion after a column list
От:
Chao Li <li.evan.chao@gmail.com>
Дата:
> On Nov 9, 2026, at 06:12, Sho Ito wrote: > > Hi hackers, > > After a column list, psql's index completion for `REPACK` offers indexes > from unrelated tables. For example: > > ``` > REPACK (ANALYZE) tab1 (c1) USING INDEX > ``` > > The completion code uses `prev3_wd` as the table name, but that word is > the column list in this form. The table-specific query returns nothing, > and completion falls back to listing all indexes. > > The attached fix uses `prev4_wd` when a column list is present. It also > completes `USING INDEX` after the column list. > > The regression tests are in a separate patch extending the existing > `src/bin/psql/t/010_tab_completion.pl`. > > Thanks, > Sho > > -- > ======================================= > Sho Ito (Sean) > > E-mail: i.sho.0628@gmail.com > LinkedIn: https://www.linkedin.com/in/sho-ito-0628/ > GitHub: https://github.com/sean0628/ > ======================================= > Hi Sho, Thanks for the patches. Both this patch and your other patch, "Complete INDEX after REPACK USING", look good to me. Since these two patches are closely related, I would suggest combining them into a single patch. I applied this patch first, but when I tried to apply the other one, I encountered a conflict. Combining them would make it easier for reviewers and committers to review and apply the changes. One other minor nit is that the test patch should normally be named v1-0002 rather than v1-0001. If you put both commits on the same branch and run "git format-patch", it will generate two patch files with 0001 and 0002 prefixes, respectively. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/
Re: [PATCH] psql: Fix REPACK index completion after a column list
Hi Chao,
Thank you for reviewing.
Since these two patches are closely related, I would suggest combining them into a single patch. I applied this patch first, but when I tried to apply the other one, I encountered a conflict. Combining them would make it easier for reviewers and committers to review and apply the changes.
I've combined both fixes in the attached v2 code
patch (0001), with the regression tests in a separate patch (0002).
The code combines the two v1 fixes.
patch (0001), with the regression tests in a separate patch (0002).
The code combines the two v1 fixes.
[1] https://commitfest.postgresql.org/patch/7610/
Thanks,
Sho
=======================================
Sho Ito (Sean)
E-mail: i.sho.0628@gmail.com
GitHub: https://github.com/sean0628/
=======================================
Re: [PATCH] psql: Fix REPACK index completion after a column list
От:
Chao Li <li.evan.chao@gmail.com>
Дата:
> On Nov 10, 2026, at 11:38, Sho Ito wrote:
>
> Hi Chao,
>
> Thank you for reviewing.
>
> Since these two patches are closely related, I would suggest combining them into a single patch. I applied this patch first, but when I tried to apply the other one, I encountered a conflict. Combining them would make it easier for reviewers and committers to review and apply the changes.
>
> I've combined both fixes in the attached v2 code
> patch (0001), with the regression tests in a separate patch (0002).
> The code combines the two v1 fixes.
>
> I will withdraw Commitfest entry #7610 [1].
>
> [1] https://commitfest.postgresql.org/patch/7610/
> Thanks,
> Sho
>
> --
> =======================================
> Sho Ito (Sean)
>
> E-mail: i.sho.0628@gmail.com
> LinkedIn: https://www.linkedin.com/in/sho-ito-0628/
> GitHub: https://github.com/sean0628/
> =======================================
>
Thanks for updating the patch. When testing v2, I found a problem:
```
evantest=# repack t (a)USING INDEX ;
ERROR: ANALYZE option must be specified when a column list is provided
```
After I typed in “(a)”, a tab typing auto filled in “USING INDEX”, but you can see the error. A column list is only allowed with ANALYZE specified. So,
```
Matches("REPACK", MatchAny, "(*)")
```
is questionable. It matches to above example.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
Re: [PATCH] psql: Fix REPACK index completion after a column list
Hi Chao,
I found a problem:
```
evantest=# repack t (a)USING INDEX ;
ERROR: ANALYZE option must be specified when a column list is provided
```
After I typed in “(a)”, a tab typing auto filled in “USING INDEX”, but you can see the error. A column list is only allowed with ANALYZE specified. So,
```
Matches("REPACK", MatchAny, "(*)")
```
is questionable. It matches to above example.
Thanks for catching this. In v3, I've removed the new `USING INDEX`
completion directly after a column list, preserving the existing
behaviour there. I've also removed completion after `REPACK t (a) USING`
and `REPACK t (a) USING INDEX`, since a column list requires `ANALYZE`
to be enabled in the command's option list.
completion directly after a column list, preserving the existing
behaviour there. I've also removed completion after `REPACK t (a) USING`
and `REPACK t (a) USING INDEX`, since a column list requires `ANALYZE`
to be enabled in the command's option list.
Checking whether that option list enables `ANALYZE` adds
enough complexity that I'd prefer to handle it in a separate patch.
V3 retains the fixes for completing `INDEX` after an explicitly typed
`USING` and looking up the correct table's indexes, including column-list
forms with an option list.
Thanks,
Sho
=======================================
Sho Ito (Sean)
E-mail: i.sho.0628@gmail.com
GitHub: https://github.com/sean0628/
=======================================
Re: [PATCH] psql: Fix REPACK index completion after a column list
От:
Ishjaap Singh <ishjaap.singh07@gmail.com>
Дата:
On Wed, 11 Nov 2026 at 10:40, Sho Ito wrote:
> V3 retains the fixes for completing `INDEX` after an explicitly typed
> `USING` and looking up the correct table's indexes, including
> column-list forms with an option list.
Hi Sho,
I tested v3 (both patches) on master (8d87367b39e) with a GNU readline
build, and ran the psql TAP tests on REL_19_STABLE (1db7119ac65) too.
Before the patch, REPACK USING gives "REPACK USING USING INDEX",
REPACK tab1 USING completes nothing, and
REPACK (ANALYZE) tab1 (c1) USING INDEX offers indexes from
unrelated tables. With v3 the first two complete INDEX, and the last
one completes to tab1's index. That also works with a schema-qualified
table and with a quoted mixed-case one. The server accepts the
resulting column-list statements for the plain and the quoted table.
Removing the catch-all TailMatches(MatchAny, "USING", "INDEX") rule
looks safe to me. ALTER TABLE's PRIMARY KEY/UNIQUE and REPLICA IDENTITY
forms have their own completion rules, and
ALTER TABLE ONLY ... ADD PRIMARY KEY USING INDEX lists the
same indexes before and after v3.
The psql TAP tests pass on both branches. Without the
tab-complete.in.c change, the TAP run fails at the first new REPACK
check. pgindent is clean; pgperltidy wants two lines in the new tests
rewrapped.
I agree with leaving the ANALYZE check for a later patch. With v3,
REPACK (VERBOSE) tab1 (c1) USING offers INDEX, which the server
rejects; that's the case the check would cover. A related case:
REPACK (CONCURRENTLY) USING and REPACK (ANALYZE) USING now
complete INDEX, and the server rejects both without a table name.
Those already gave invalid SQL before v3 ("USING USING INDEX"), so I
don't think either case blocks this patch.
A heads-up: this conflicts with my patch for the same block [1], which
stops offering USING INDEX right after REPACK (CONCURRENTLY) and
REPACK (ANALYZE), where a table name is required. The conflicts are in
adjacent completion rules and the test insertion point. I'm happy to
rebase whichever one lands second.
Looks good to me.
[1] https://commitfest.postgresql.org/patch/7574/
Thanks,
Ishjaap Singh
Re: [PATCH] psql: Fix REPACK index completion after a column list
Hi Ishjaap,
Thanks for the detailed review and testing on both branches.
> pgperltidy wants two lines in the new tests rewrapped.
I've applied the two `pgperltidy` formatting changes in the attached v4;
the code patch is unchanged. All four psql TAP suites pass on master
with assertions enabled.
> The conflicts are in adjacent completion rules and the test insertion point. I'm happy to
> rebase whichever one lands second.
the code patch is unchanged. All four psql TAP suites pass on master
with assertions enabled.
> The conflicts are in adjacent completion rules and the test insertion point. I'm happy to
> rebase whichever one lands second.
Thanks for offering to rebase #7574 if needed. I'm also happy to rebase
this series if #7574 lands first.
Thanks,
Sho
=======================================
Sho Ito (Sean)
E-mail: i.sho.0628@gmail.com
GitHub: https://github.com/sean0628/
=======================================
Re: [PATCH] psql: Fix REPACK index completion after a column list
От:
Álvaro Herrera <alvherre@kurilemu.de>
Дата:
Hi,
Hmm, so the commit message says
Leave completion directly after a column list unchanged. Adding USING
INDEX there requires accounting for the ANALYZE option and is deferred
to a separate change.
but that's not correct, isn't it? It's offering a column list itself
that's problematic (i.e., it requires the analyze option to be present),
not the USING INDEX clause. I don't see why we wouldn't offer to add
USING INDEX.
On the other hand, I think we could offer the opening "(" after the
table name, when an option list is present (I would do this regardless
of the ANALYZE begin present or not. If they add a column list with
options other than analyze, they get the error, but that's not too big a
problem. At worst, they discover that it's possible to list columns in
certain cases; for their next try they can either add the analyze or
drop the column list, at their preference. In fact, I wonder if we
should offer to add a column list even if there's no option list even
if it's not valid without it.)
Is really REPACK the first command where the syntax causes this kind of
problem? Hmm, I'm now wondering if we should make this error a WARNING
instead:
/*
* Make sure ANALYZE is specified if a column list is present.
*/
if ((params->options & CLUOPT_ANALYZE) == 0 && stmt->relation->va_cols != NIL)
ereport(ERROR,
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("ANALYZE option must be specified when a column list is provided"));
That would make the syntax less problematic: you're always "welcome" to
add a column list, only it will be ignored in some cases.
--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
Tom: There seems to be something broken here.
Teodor: I'm in sackcloth and ashes... Fixed.
http://postgr.es/m/482D1632.8010507@sigaev.ru
Re: [PATCH] psql: Fix REPACK index completion after a column list
Hi Álvaro,
Sorry for the late reply. Thank you for the review.
There is a similar restriction in `VACUUM`: `ExecVacuum()` rejects a
column list without `ANALYZE`, using the same error message [1]. I'd keep
any change from an error to a warning separate from this completion
fix and consider the behaviour of both commands together.
[1] https://github.com/postgres/postgres/blob/c074737f687f604b64f6ee830fccbbe854719823/src/backend/commands/vacuum.c#L341-L354
Thanks,
Sorry for the late reply. Thank you for the review.
Hmm, so the commit message says
Leave completion directly after a column list unchanged. Adding USING
INDEX there requires accounting for the ANALYZE option and is deferred
to a separate change.
but that's not correct, isn't it? It's offering a column list itself
that's problematic (i.e., it requires the analyze option to be present),
not the USING INDEX clause. I don't see why we wouldn't offer to add
USING INDEX.
You're right; the commit message conflated the column-list requirement
with the subsequent `USING INDEX` clause. V5 corrects that explanation,
completes `USING INDEX` after a column list, and offers `(` after a table
name when an option list is present, without checking `ANALYZE`.
with the subsequent `USING INDEX` clause. V5 corrects that explanation,
completes `USING INDEX` after a column list, and offers `(` after a table
name when an option list is present, without checking `ANALYZE`.
Is really REPACK the first command where the syntax causes this kind of
problem? Hmm, I'm now wondering if we should make this error a WARNING
instead:
column list without `ANALYZE`, using the same error message [1]. I'd keep
any change from an error to a warning separate from this completion
fix and consider the behaviour of both commands together.
[1] https://github.com/postgres/postgres/blob/c074737f687f604b64f6ee830fccbbe854719823/src/backend/commands/vacuum.c#L341-L354
Thanks,
Sho
=======================================
Sho Ito (Sean)
E-mail: i.sho.0628@gmail.com
GitHub: https://github.com/sean0628/
=======================================