Обсуждение: psql: Make tab completion work for ANALYZE VERBOSE ...
Quick patch to fix the fact that the EXPLAIN ANALYZE VERBOSE is clobbering tab-completion for ANALYZE VERBOSE. -- Greg Sabino Mullane greg@endpoint.com End Point Corporation PGP Key: 0x14964AC8 Index: tab-complete.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/bin/psql/tab-complete.c,v retrieving revision 1.180 diff -c -r1.180 tab-complete.c *** 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[] =
Вложения
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
> 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@endpoint.com End Point Corporation PGP Key: 0x14964AC8
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