Bug #24624 MySQL client ignores its own completion table
Submitted: 27 Nov 2006 16:09 Modified: 25 Feb 2008 19:47
Reporter: Tom Evans Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:ALL OS:Any (ALL)
Assigned to: Chad MILLER CPU Architecture:Any
Tags: client
Triage: D3 (Medium)

[27 Nov 2006 16:09] Tom Evans
Description:
In client/mysql.cc, in the function build_completion_hash(), some code was added (in 2000) to step through the global COMMANDS and add their names to the completion hash. In 2001, some more code was added to do some 'cleanup' of the completion hash and add all database, table and table column names to the hash.

This code was added AFTER the code to put SQL commands into the completion hash.

Net result => no SQL commands in the auto completion hash.

Furthermore, the list of SQL commands is woefully short. The supplied patch adds in all current MySQL keywords.

How to repeat:
Open mysql command line.
Type 'sel' or 'SEL'.
Press tab.

Suggested fix:
Apply affixed patch.
[27 Nov 2006 16:11] Tom Evans
Patch to add most keywords, and not trash the keywords completion

Attachment: mysql_5.0-completion-fix.diff (text/x-patch), 22.08 KiB.

[27 Nov 2006 19:49] Miguel Solorzano
Thank you for the bug report and suggestion patch.
[28 Nov 2006 11:14] Tom Evans
Gave it the wrong category - categories on the bug reporting page appear to be a limited subset of the ones here (no 'Command-line clients' category on reporting page)
[12 Dec 2006 16:47] Chad MILLER
Elliot and I both looked at this patch, and the reordering should go into both enterprise and community trees.

Instead of inserting the keywords, that list should be generated at compile time by scraping the grammar.  This should be ~5 lines of Perl or Python.
[28 Dec 2006 19:10] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/17436

ChangeSet@1.2360, 2006-12-28 14:08:57-05:00, cmiller@calliope.local.cmiller +3 -0
  Bug#24624: MySQL client ignores its own completion table
  
  The built-in tiny list of known tokens is inserted just before we clear
  the data.  In addition, the list of commands is embarassingly small.
  
  This reorders the statements so that the hash is cleared /before/ 
  inserting these tokens.
  
  At compile-time, gets a list of tokens that /this version/ of the server 
  knows about.  This has the disadvantage that if the client is used against
  an earlier version of the server, the completion hash of functions and 
  tokens might not represent the ones available at /that server/.  Hopefully,
  our grammar doesn't change enough to make this a problem.
  
  A future enhancement could implement SHOW GRAMMAR to get all the possible
  tokens that the destination server implements.
[29 Dec 2006 15:24] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/17463

ChangeSet@1.2360, 2006-12-28 13:54:47-05:00, cmiller@calliope.local.cmiller +3 -0
  Bug#24624: MySQL client ignores its own completion table
  
  The built-in tiny list of known tokens is inserted just before we clear
  the data.  In addition, the list of commands is embarassingly small.
  
  This reorders the statements so that the hash is cleared /before/ 
  inserting these tokens.
  
  At compile-time, gets a list of tokens that /this version/ of the server 
  knows about.  This has the disadvantage that if the client is used against
  an earlier version of the server, the completion hash of functions and 
  tokens might not represent the ones available at /that server/.  Hopefully,
  our grammar doesn't change enough to make this a problem.
  
  A future enhancement could implement SHOW GRAMMAR to get all the possible
  tokens that the destination server implements.
[26 Mar 2007 15:02] Tom Evans
Sigh, another community release, another chance ignored to fix a 7 year old bug.

Any chance of this EVER getting reviewed?
[11 Apr 2007 23:12] Magnus BlÄudd
- I'm not really sure if I like the idea of using perl for generating the file. Why not just build a simple .c file that #includes lex.h and prints out what we want? It hardly need to take any arguments, just build and run.
- Regardless of methode used to create the generated file it should be in "BUILT_SOURCES", no need to keep a generated file in bk. But it would maybe be easier if the client just included lex.h?
- There are a number of funky comments about access, powerbuilder and the like in the generated file. ;)

- +  /* hash client commands */
  +  while (cmd->name) 
  should probably say /* hash client builtin commands */
[7 Jun 2007 10:27] Tom Evans
Patch to enable autocompletion

Attachment: patch-client::lots (application/octet-stream, text), 16.30 KiB.

[7 Jun 2007 10:28] Tom Evans
Update patch for mysql 5.0.41

Patch is a drop in fix for freebsd, place in /usr/ports/databases/mysql50-server/files and rebuild mysql50-client
[10 Jan 2008 17:36] Tom Evans
Hello

Can I ask what is holding this up? I fully understand if you wish for a different solution and this is too low a priority to assign developer time to, however if that is the case, can I at least have a pointer as to how you would like this fixed.

This is a very old bug, it would be good to have it squashed.

Regards
[30 Jan 2008 21:08] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/41462

ChangeSet@1.2571, 2008-01-30 16:07:52-05:00, cmiller@zippy.cornsilk.net +1 -0
  Bug#24624: MySQL client ignores its own completion table
  
  Nothing was in the command-line dictionary, because of the wrong 
  order of instructions when populating it.
  
  This is a smaller, less optimistic patch that both fixes a bug and
  refreshes the list of keywords that the command-line library (e.g., 
  readline) can use to expand typed commands.  Now, read from the 
  command list /after/ we free the list, not before.
  
  The best way is to read the keywords from the lexer code, but that
  doesn't work everywhere yet.  Grr.
[30 Jan 2008 21:52] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/41463

ChangeSet@1.2571, 2008-01-30 16:51:39-05:00, cmiller@zippy.cornsilk.net +1 -0
  Bug#24624: MySQL client ignores its own completion table
  
  Nothing was in the command-line dictionary, because of the wrong 
  order of instructions when populating it.
  
  This is a smaller, less optimistic patch that both fixes a bug and
  refreshes the list of keywords that the command-line library (e.g., 
  readline) can use to expand typed commands.  Now, read from the 
  command list /after/ we free the list, not before.
  
  The best way is to read the keywords from the lexer code, but that
  doesn't work everywhere yet.  Grr.
[30 Jan 2008 23:57] Chad MILLER
Queued to -build trees, 5.0, 5.1, 6.0.
[25 Feb 2008 15:58] Bugs System
Pushed into 5.1.24-rc
[25 Feb 2008 16:04] Bugs System
Pushed into 6.0.5-alpha
[25 Feb 2008 16:04] Bugs System
Pushed into 5.0.58
[25 Feb 2008 19:47] Paul Dubois
Noted in 5.0.58, 5.1.24, 6.0.5 changelogs.

mysql did not use its completion table. Also, the table contained few
entries.
[30 Mar 2008 0:13] Jon Stephens
Also documented for 5.1.23-ndb-6.3.11.