Bug #52374 Statement Completion Fails on Windows
Submitted: 25 Mar 2010 17:41 Modified: 25 Mar 2010 20:19
Reporter: Paul B. Davis Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.1.45, all OS:Windows (x86 OR amd64)
Assigned to: CPU Architecture:Any
Tags: Auto Completion, autocomplete, Statement Completion, tab completion

[25 Mar 2010 17:41] Paul B. Davis
Description:
Tab key statement completion is completely nonfunctional on Windows.

This has been tested on Windows 7 amd64 and Windows Server 2003 x86.

The following console session dump outlines the problem.  At the end of the session dump, after typing SELECT * FROM te<tab>, the final <tab> keystroke should result in a statement autocompletion action that prints the rest of the table name "test2."  The completed statement would appear as:

SELECT * FROM test2

Instead, the client merely prints a tab character to the console and the cursor jumps a few character positions.  No auto completion ever happens, and the client never posts any messages about rehashing the database information.

Additionally, there is no observable delay in connecting to mysql servers, even geographically distant servers with complicated schema.  (The help printout of the -A switch implies that this delay might be observable).

The console session dump:

D:\source>mysql -h bpdsql -u root -p --auto-rehash
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 5.1.45-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> \#
mysql> use test
Database changed
mysql> \#
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| innodbt        |
| t              |
| test2          |
+----------------+
3 rows in set (0.00 sec)

mysql> SELECT * FROM te<tab>

Abbreviated --help printout from my instance of mysql.exe:

D:\source>mysql -h bpdsql -u root -p --auto-rehash --help
mysql  Ver 14.14 Distrib 5.1.45, for Win64 (unknown)
Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.

...

Default options are read from the following files in the given order:
C:\Windows\my.ini C:\Windows\my.cnf C:\my.ini C:\my.cnf C:\Program Files\MySQL\MySQL Server 5.1\my.ini C:\Program Files\MySQL\MySQL Server 5.1\my.cnf
The following groups are read: mysql client
The following options may be given as the first argument:
--print-defaults        Print the program argument list and exit.
--no-defaults           Don't read default options from any option file.
--defaults-file=#       Only read default options from the given file #.
--defaults-extra-file=# Read this file after the global files are read.

Variables (--variable-name=value)
and boolean options {FALSE|TRUE}  Value (after reading options)
--------------------------------- -----------------------------
auto-rehash                       TRUE
character-sets-dir                (No default value)
column-type-info                  FALSE
comments                          FALSE
compress                          FALSE
debug-check                       FALSE
debug-info                        FALSE
database                          (No default value)
default-character-set             latin1
delimiter                         ;
vertical                          FALSE
force                             FALSE
named-commands                    FALSE
ignore-spaces                     FALSE
local-infile                      FALSE
no-beep                           FALSE
host                              bpdsql
html                              FALSE
xml                               FALSE
line-numbers                      TRUE
unbuffered                        FALSE
column-names                      TRUE
sigint-ignore                     FALSE
port                              0
prompt                            mysql>
quick                             FALSE
raw                               FALSE
reconnect                         TRUE
shared-memory-base-name           (No default value)
socket                            (No default value)
ssl                               FALSE
ssl-ca                            (No default value)
ssl-capath                        (No default value)
ssl-cert                          (No default value)
ssl-cipher                        (No default value)
ssl-key                           (No default value)
ssl-verify-server-cert            FALSE
table                             FALSE
user                              root
safe-updates                      FALSE
i-am-a-dummy                      FALSE
connect_timeout                   0
max_allowed_packet                16777216
net_buffer_length                 16384
select_limit                      1000
max_join_size                     1000000
secure-auth                       FALSE
show-warnings                     FALSE

How to repeat:
To Repro:

Download the 5.1.45 version of mySQL, and install it on your Windows workstation.

Open a command prompt by type "cmd" at the "Run" dialog in Windows.

Use "mysql.exe" to open a connection to a mysql server.
Ex: mysql -h YourServer -u YourUser -p --auto-rehash

Type your password when prompted.

Once connected, type the "use" command to switch to an example database.
Ex: use test;

Type "\#" and press enter to ensure that database rehashing occurs.
(Note that no informational printout follows execution of this statement)

Test statement completion by typing a simple SQL query with an incomplete table name.
Ex: SELECT * FROM te

Type a TAB keystroke after "te," and observe that tab completion does not occur as explained in the MySQL Documentation.

Suggested fix:
Fix tab completion on Windows, and ensure that it is part of your release testing cycle going forward.

This is basic functionality that brings a major usability impact to the table for Windows users.
[25 Mar 2010 20:19] Sveta Smirnova
Thank you for the report.

Verified as described.

Probably this should be documented at http://dev.mysql.com/doc/refman/5.1/en/mysql-command-options.html#option_mysql_auto-rehash
[25 Apr 2013 23:08] MySQL Verification Team
Duplicate of this one: http://bugs.mysql.com/bug.php?id=68718 .
[9 Aug 2013 6:46] Steven NOT_FOUND
Actually, tab completion in 5.6.12 on Linux is also broken. Compiling shows:

02-make.out:[  5%] Building C object cmd-line-utils/libedit/CMakeFiles/edit.dir/readline.c.o
02-make.out:[ 84%] Building CXX object client/CMakeFiles/mysql.dir/readline.cc.o
02-make.out:[100%] Building CXX object libmysqld/examples/CMakeFiles/mysql_embedded.dir/__/__/client/readline.cc.o

Which would seem to indicate that the requisite readline support is available.
Command line editing in vi-mode is working, which seems to indicate that readline is functinal.

Using "mysql --auto-rehash", adding "auto-rehash" to the [mysql] section of my.cnf in all of the locations it is used from, or using "rehash" at the prompt or using \# at the prompt all fail to complete.

I realize that the mysql client is something of a step-child, but some of us do really have to use the command line. Having to cut+paste longer table names is a pain.
[2 Apr 2014 9:20] MySQL Verification Team
also http://bugs.mysql.com/bug.php?id=71338