Re: Some bugs in psql_complete of psql

From: Kyotaro HORIGUCHI <horiguchi(dot)kyotaro(at)lab(dot)ntt(dot)co(dot)jp>
To: masao(dot)fujii(at)gmail(dot)com
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Some bugs in psql_complete of psql
Date: 2015-12-22 09:44:02
Message-ID: 20151222.184402.42713785.horiguchi.kyotaro@lab.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello, I returned to this since Thomas' psql-completion patch has
been committed.

This patch has been recreated on it.

"IN TABLESPACE xxx OWNED BY" has been alredy fixed so I removed it.
The attched files are the following,

1. 0001-Fix-tab-complete-of-CREATE-INDEX.patch

Fixes completion for CREATE INDEX in ordinary way.

2. 0001-Fix-completion-for-CREATE-INDEX-type-2.patch

An alternative for 1. Introduces multilevel matching. This
effectively can avoid false matching, simplify each expression
and reduce the number of matching operations.

3. 0002-Fix-tab-completion-for-DROP-INDEX.patch

Fix of DROP INDEX completion in the type-2 way.

=====
At Tue, 08 Dec 2015 17:56:19 +0900 (Tokyo Standard Time), Kyotaro HORIGUCHI <horiguchi(dot)kyotaro(at)lab(dot)ntt(dot)co(dot)jp> wrote in <20151208(dot)175619(dot)245979824(dot)horiguchi(dot)kyotaro(at)lab(dot)ntt(dot)co(dot)jp>
> > I tested whether the following patterns work as expected or not.
> >
> > CREATE UNIQUE INDEX CONCURRENTLY name ON
> > CREATE UNIQUE INDEX CONCURRENTLY ON
> > CREATE UNIQUE INDEX name ON
> > CREATE UNIQUE INDEX ON
> > CREATE INDEX CONCURRENTLY name ON
> > CREATE INDEX CONCURRENTLY ON
> > CREATE INDEX name ON
> > CREATE INDEX ON
> >
> > Then I found the following problems.
> >
> > "CREATE UNIQUE INDEX CONCURRENTLY <tab>" didn't suggest "ON".
> > "CREATE UNIQUE INDEX ON <tab>" suggested nothing.
> > "CREATE INDEX ON <tab>" suggested nothing.

All of the cases above are completed correctly. As a new feature,
this patch allows "IF NOT EXISTS". As the result, the following
part of the syntax of CREATE INDEX is completed correctly.

CREATE [UNIQUE] INDEX [CONCURRENTLY] [[IF NOT EXISTS] iname] ON tname

> > "CREATE INDEX CONCURRENTLY <tab>" didn't suggest "ON".

Now it suggests "ON", "IF NOT EXISTS" and existing index names.

> > BTW, I found that tab-completion for DROP INDEX has the following problems.
> >
> > "DROP INDEX <tab>" didn't suggest "CONCURRENTLY".
> > "DROP INDEX CONCURRENTLY name <tab>" suggested nothing.

They are completed by the "things" completion. The first patch
gives a wrong suggestion for DROP INDEX CONCURRENTLY with "IF NOT
EXISTS". This can be avoided adding HeadMatches to every matching
for "CREATE INDEX..." syntexes but it is too bothersome.

Instaed, in the second alternative patch, I enclosed the whole
"CREATE INDEX" stuff by an if(HeadMatches2("CREATE",
"UNIQUE|INDEX")) block to avoid the false match and simplify each
matching expression. As a side effect, the total number of the
executions of matching expressions can be reduced. (This wouldn't
be just a bug fix, but rarther a kind of refactoring.)

The third patch fixes the behavior for DROP INDEX in this way.

Thoughs? Suggestions?

regards,

--
Kyotaro Horiguchi
NTT Open Source Software Center

Attachment Content-Type Size
0001-Fix-tab-complete-of-CREATE-INDEX.patch text/x-patch 4.4 KB
0001-Fix-completion-for-CREATE-INDEX-type-2.patch text/x-patch 5.5 KB
0002-Fix-tab-completion-for-DROP-INDEX.patch text/x-patch 1.9 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2015-12-22 09:45:30 Re: custom function for converting human readable sizes to bytes
Previous Message Peter Geoghegan 2015-12-22 09:36:52 Re: A Typo in regress/sql/privileges.sql