Skip to content

Commit 1f75b45

Browse files
committed
Improve tab completion of REINDEX in psql
This allows the tab completion of REINDEX to handle an optional parenthesized list of options. This case is more complicated than VACUUM or ANALYZE because of CONCURRENTLY and the different object types to consider with the reindex. Author: Justin Pryzby Reviewed-by: Alexey Kondratov, Michael Paquier Discussion: https://postgr.es/m/20200403182712.GR14618@telsasoft.com
1 parent 1784f27 commit 1f75b45

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

src/bin/psql/tab-complete.c

+29-9
Original file line numberDiff line numberDiff line change
@@ -3430,28 +3430,48 @@ psql_completion(const char *text, int start, int end)
34303430
COMPLETE_WITH("DATA");
34313431

34323432
/* REINDEX */
3433-
else if (Matches("REINDEX"))
3433+
else if (Matches("REINDEX") ||
3434+
Matches("REINDEX", "(*)"))
34343435
COMPLETE_WITH("TABLE", "INDEX", "SYSTEM", "SCHEMA", "DATABASE");
3435-
else if (Matches("REINDEX", "TABLE"))
3436+
else if (Matches("REINDEX", "TABLE") ||
3437+
Matches("REINDEX", "(*)", "TABLE"))
34363438
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexables,
34373439
" UNION SELECT 'CONCURRENTLY'");
3438-
else if (Matches("REINDEX", "INDEX"))
3440+
else if (Matches("REINDEX", "INDEX") ||
3441+
Matches("REINDEX", "(*)", "INDEX"))
34393442
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes,
34403443
" UNION SELECT 'CONCURRENTLY'");
3441-
else if (Matches("REINDEX", "SCHEMA"))
3444+
else if (Matches("REINDEX", "SCHEMA") ||
3445+
Matches("REINDEX", "(*)", "SCHEMA"))
34423446
COMPLETE_WITH_QUERY(Query_for_list_of_schemas
34433447
" UNION SELECT 'CONCURRENTLY'");
3444-
else if (Matches("REINDEX", "SYSTEM|DATABASE"))
3448+
else if (Matches("REINDEX", "SYSTEM|DATABASE") ||
3449+
Matches("REINDEX", "(*)", "SYSTEM|DATABASE"))
34453450
COMPLETE_WITH_QUERY(Query_for_list_of_databases
34463451
" UNION SELECT 'CONCURRENTLY'");
3447-
else if (Matches("REINDEX", "TABLE", "CONCURRENTLY"))
3452+
else if (Matches("REINDEX", "TABLE", "CONCURRENTLY") ||
3453+
Matches("REINDEX", "(*)", "TABLE", "CONCURRENTLY"))
34483454
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexables, NULL);
3449-
else if (Matches("REINDEX", "INDEX", "CONCURRENTLY"))
3455+
else if (Matches("REINDEX", "INDEX", "CONCURRENTLY") ||
3456+
Matches("REINDEX", "(*)", "INDEX", "CONCURRENTLY"))
34503457
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes, NULL);
3451-
else if (Matches("REINDEX", "SCHEMA", "CONCURRENTLY"))
3458+
else if (Matches("REINDEX", "SCHEMA", "CONCURRENTLY") ||
3459+
Matches("REINDEX", "(*)", "SCHEMA", "CONCURRENTLY"))
34523460
COMPLETE_WITH_QUERY(Query_for_list_of_schemas);
3453-
else if (Matches("REINDEX", "SYSTEM|DATABASE", "CONCURRENTLY"))
3461+
else if (Matches("REINDEX", "SYSTEM|DATABASE", "CONCURRENTLY") ||
3462+
Matches("REINDEX", "(*)", "SYSTEM|DATABASE", "CONCURRENTLY"))
34543463
COMPLETE_WITH_QUERY(Query_for_list_of_databases);
3464+
else if (HeadMatches("REINDEX", "(*") &&
3465+
!HeadMatches("REINDEX", "(*)"))
3466+
{
3467+
/*
3468+
* This fires if we're in an unfinished parenthesized option list.
3469+
* get_previous_words treats a completed parenthesized option list as
3470+
* one word, so the above test is correct.
3471+
*/
3472+
if (ends_with(prev_wd, '(') || ends_with(prev_wd, ','))
3473+
COMPLETE_WITH("VERBOSE");
3474+
}
34553475

34563476
/* SECURITY LABEL */
34573477
else if (Matches("SECURITY"))

0 commit comments

Comments
 (0)