Re: psql: Make tab completion work for ANALYZE VERBOSE ...

Lists: pgsql-hackers
From: Greg Sabino Mullane <greg(at)endpoint(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: psql: Make tab completion work for ANALYZE VERBOSE ...
Date: 2009-03-27 01:31:57
Message-ID: 49CC2C8D.3070607@endpoint.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Quick patch to fix the fact that the EXPLAIN ANALYZE VERBOSE is clobbering
tab-completion for ANALYZE VERBOSE.

--
Greg Sabino Mullane greg(at)endpoint(dot)com
End Point Corporation
PGP Key: 0x14964AC8

Attachment Content-Type Size
psql.tab-complete-analyze-verbose.patch text/x-diff 1017 bytes

From: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
To: Greg Sabino Mullane <greg(at)endpoint(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: psql: Make tab completion work for ANALYZE VERBOSE ...
Date: 2009-03-27 07:55:44
Message-ID: 49CC8680.3090904@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greg Sabino Mullane wrote:
> Quick patch to fix the fact that the EXPLAIN ANALYZE VERBOSE is clobbering
> tab-completion for ANALYZE VERBOSE.

Thanks.

> *** tab-complete.c 24 Feb 2009 10:06:34 -0000 1.180
> --- tab-complete.c 27 Mar 2009 01:29:06 -0000
> ***************
> *** 1627,1633 ****
> else if (pg_strcasecmp(prev_wd, "VERBOSE") == 0 &&
> pg_strcasecmp(prev3_wd, "VACUUM") != 0 &&
> pg_strcasecmp(prev4_wd, "VACUUM") != 0 &&
> ! (pg_strcasecmp(prev2_wd, "ANALYZE") == 0 ||
> pg_strcasecmp(prev2_wd, "EXPLAIN") == 0))
> {
> static const char *const list_EXPLAIN[] =
> --- 1627,1634 ----
> else if (pg_strcasecmp(prev_wd, "VERBOSE") == 0 &&
> pg_strcasecmp(prev3_wd, "VACUUM") != 0 &&
> pg_strcasecmp(prev4_wd, "VACUUM") != 0 &&
> ! ((pg_strcasecmp(prev2_wd, "ANALYZE") == 0 &&
> ! pg_strcasecmp(prev3_wd, "EXPLAIN") == 0) ||
> pg_strcasecmp(prev2_wd, "EXPLAIN") == 0))
> {
> static const char *const list_EXPLAIN[] =

I find that that particular rule is formatted differently than the
others. It took me a while to figure out how it works. All the others
check the keywords from left to right, but this checks that the previous
word is VERBOSE and works to the left from there, kind of. I also don't
understand why the explicit check for VACUUM is there. It only makes a
difference if you write something like "VACUUM EXPLAIN VERBOSE", which
isn't valid. I guess it was needed before this fix to not match "VACUUM
ANALYZE", but isn't anymore.

I'd suggest to write it like this:

> else if ((pg_strcasecmp(prev2_wd, "EXPLAIN") == 0 &&
> pg_strcasecmp(prev_wd, "VERBOSE") == 0) ||
> (pg_strcasecmp(prev3_wd, "EXPLAIN") == 0 &&
> pg_strcasecmp(prev2_wd, "ANALYZE") == 0 &&
> pg_strcasecmp(prev_wd, "VERBOSE") == 0))

While we're at it, any idea what the logic behind this rule is:

> else if ((pg_strcasecmp(prev_wd, "ANALYZE") == 0 &&
> pg_strcasecmp(prev2_wd, "VERBOSE") == 0) ||
> (pg_strcasecmp(prev_wd, "VERBOSE") == 0 &&
> pg_strcasecmp(prev2_wd, "ANALYZE") == 0))
> COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);

? The first part of that I understand, "ANALYZE VERBOSE", but "VERBOSE
ANALYZE" isn't valid SQL.

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com


From: Greg Sabino Mullane <greg(at)endpoint(dot)com>
To: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: psql: Make tab completion work for ANALYZE VERBOSE ...
Date: 2009-03-27 13:37:00
Message-ID: 49CCD67C.2000301@endpoint.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

> I find that that particular rule is formatted differently than the
> others. It took me a while to figure out how it works.

Yeah, me too, but I was trying to keep my change inline with the local logic, so
to speak. +1 to making it more consistent.

> While we're at it, any idea what the logic behind this rule is:
>
>> else if ((pg_strcasecmp(prev_wd, "ANALYZE") == 0 &&
>> pg_strcasecmp(prev2_wd, "VERBOSE") == 0) ||
>> (pg_strcasecmp(prev_wd, "VERBOSE") == 0 &&
>> pg_strcasecmp(prev2_wd, "ANALYZE") == 0))
>> COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
>
> ? The first part of that I understand, "ANALYZE VERBOSE", but "VERBOSE
> ANALYZE" isn't valid SQL.

I suspect this is to catch "VACUUM VERBOSE ANALYZE" (where VACUUM would be the
implicit prev3_wd)

--
Greg Sabino Mullane greg(at)endpoint(dot)com
End Point Corporation
PGP Key: 0x14964AC8


From: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
To: Greg Sabino Mullane <greg(at)endpoint(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: psql: Make tab completion work for ANALYZE VERBOSE ...
Date: 2009-03-27 15:00:09
Message-ID: 49CCE9F9.50605@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greg Sabino Mullane wrote:
>> I find that that particular rule is formatted differently than the
>> others. It took me a while to figure out how it works.
>
> Yeah, me too, but I was trying to keep my change inline with the local logic, so
> to speak. +1 to making it more consistent.

Ok, committed with the more consistent formatting.

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com