WL#8754: Deprecate COM_XXX commands which are redundant.

Affects: Server-5.7   —   Status: Complete

As we are moving in the direction of having more and more functionality
available with SQL instead of COM_XXXX commands we reached the point to
deprecate COM_FIELD_LIST. The fate of COM_FIELD_LIST should follow the one of
COM_CREATE_DB and COM_DROP_DB, which were already removed in the past.
The functionality of COM_FIELD_LIST is limited to what can be achieved with SQL
against INFORMATION_SCHEMA. Also, internally, COM_FIELD_LIST is counted as
SQLCOM_SHOW_FIELDS, in other words - emulates it.
- COM_FIELD_LIST's results can be achieved in different ways
- there is an SQL way to do it
- deprecation and removal will remove one code path more to be supported

The command is used at least by libmysql, but is exported in other APIs. In
libmysql it is used by mysql_list_fields(). This function also might be
deprecated or in case we want to save it, then it should be emulated with SQL
(either SHOW FIELDS or SQL againt I_S)

PHP exports mysql_field_list() in its old MySQL extension. The function is
deprecated in PHP since 5.4.0 (now 5.4 is at EOL phase and PHP 7 is coming). The
whole extension is gone in PHP 7.

Connector/C++ although based on libmysql (Connector/C) doesn't use
mysql_list_fields() and thus the command.

Connector/ODBC as based on libmysql uses mysql_list_fields() in the cases when
queries against INFORMATION_SCHEMA are disabled. C/ODBC can be changed to issue
SHOW FIELDS as SQL and not use the API call.

Connector/J is not based on libmysql. It only defines a FIELD_LIST (not
COM_FIELD_LIST) as a constant but doesn't use it.

Following COM_XXX commands can be deprecated as there are alternative sql 
statements associated with them.
COM_FIELD_LIST (show columns sql statement)
COM_REFRESH (flush sql statement)
COM_PROCESS_INFO(show processlist sql statement)
COM_PROCESS_KILL (kill connection/query sql statement)

User Documentation
==================

http://dev.mysql.com/doc/relnotes/mysql/5.7/en/news-5-7-11.html

http://dev.mysql.com/doc/refman/5.7/en/mysql-kill.html
http://dev.mysql.com/doc/refman/5.7/en/mysql-list-fields.html
http://dev.mysql.com/doc/refman/5.7/en/mysql-list-processes.html
http://dev.mysql.com/doc/refman/5.7/en/mysql-refresh.html

http://dev.mysql.com/doc/internals/en/com-process-kill.html
http://dev.mysql.com/doc/internals/en/com-field-list.html
http://dev.mysql.com/doc/internals/en/com-process-info.html
http://dev.mysql.com/doc/internals/en/com-refresh.html
FR1: Server reports a deprecated warning message for the following COM commands:
     COM_FIELD_LIST, COM_REFRESH, COM_PROCESS_INFO, COM_PROCESS_KILL
FR2: mysql_list_fields() when invoked issue a deprecated warning as 
    "COM_FIELD_LIST is deprecated and will be removed in a future version.
     Instead please use mysql_query() with SHOW COLUMNS FROM statement"
FR3: mysql_refresh() when invoked issue a deprecated warning as 
    "COM_REFRESH is deprecated and will be removed in a future version.
     Instead please use mysql_query() with FLUSH statement."
FR4: mysql_list_processes() when invoked issue a deprecated warning as 
    "COM_PROCESS_INFO is deprecated and will be removed in a future version.
     Instead please use mysql_query() with SHOW PROCESSLIST statement."
FR5: mysql_kill() when invoked issue a deprecated warning as 
    "COM_PROCESS_KILL is deprecated and will be removed in a future version.
     Instead please use mysql_query() with KILL statement."

COM commands are hard to extend as they need protocol change, with SQL
statements there is no such restriction. There are few COM commands for
which we have an equivalent SQL statements. Below is the list:

COM_FIELD_LIST   - SHOW COLUMNS FROM statement
COM_REFRESH      - FLUSH statement
COM_PROCESS_INFO - SHOW PROCESSLIST statement
COM_PROCESS_KILL - KILL CONNECTION/QUERY statement

With this WL the above COM command will be deprecated and removed in future 
release. These COM commands are called in following APIs.
mysql_list_fields()
mysql_refresh()
mysql_list_processes()
mysql_kill()
Thus any client application which invokes any of the above APIs will receive a
deprecated warning from server.

Below is a simple client application code which expects a warning from server:

  rc= mysql_query(mysql, "create table t1(c1 int primary key, c2 char(10))");
  myquery(rc);
  result= mysql_list_fields(mysql, "t1", NULL);
  mytest(result);
  rc= my_process_result_set(result);
  DIE_UNLESS(rc == 0);
  mysql_free_result(result);
  rc= mysql_query(mysql, "SHOW WARNINGS");
  myquery(rc);
  result= mysql_store_result(mysql);
  mytest(result);
  rc= my_process_result_set(result);
  DIE_UNLESS(rc == 1);
  mysql_free_result(result);
  myquery(mysql_query(mysql, "drop table t1"));

Below code changes are done to deprecate following list of COM commands:
COM_FIELD_LIST
COM_REFRESH
COM_PROCESS_INFO
COM_PROCESS_KILL

--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -1379,6 +1379,8 @@ bool dispatch_command(THD *thd, COM_DATA *com_data,
     TABLE_LIST table_list;
     LEX_STRING table_name;
     LEX_STRING db;
+    push_deprecated_warn(thd, "mysql_list_fields()",
+                         "SHOW COLUMNS FROM statement");
     /*
       SHOW statements should not add the used tables to the list of tables
       used in a transaction.
@@ -1473,7 +1475,6 @@ bool dispatch_command(THD *thd, COM_DATA *com_data,
       trans_rollback_implicit(thd);
       thd->mdl_context.release_transactional_locks();
     }
-
     thd->cleanup_after_query();
     break;
   }
@@ -1548,6 +1549,7 @@ bool dispatch_command(THD *thd, COM_DATA *com_data,
       break;
     close_thread_tables(thd);
     thd->mdl_context.release_transactional_locks();
+    push_deprecated_warn(thd, "mysql_refresh()", "FLUSH statement");
     my_ok(thd);
     break;
   }
@@ -1629,6 +1631,8 @@ bool dispatch_command(THD *thd, COM_DATA *com_data,
       thd,
       thd->security_context()->check_access(PROCESS_ACL) ?
       NullS : thd->security_context()->priv_user().str, 0);
+    push_deprecated_warn(thd, "mysql_list_processes()",
+                         "SHOW PROCESSLIST statement");
     break;
   case COM_PROCESS_KILL:
   {
@@ -1640,6 +1644,8 @@ bool dispatch_command(THD *thd, COM_DATA *com_data,
       sql_kill(thd, com_data->com_kill.id, false);
     }
     break;
+    push_deprecated_warn(thd, "mysql_kill()",
+                         "KILL CONNECTION/QUERY statement");
   }