Bug #25430 variable not found in SELECT @@global.ft_max_word_len;
Submitted: 5 Jan 2007 11:25 Modified: 15 Mar 2010 23:27
Reporter: Péter Szabó Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: DML Severity:S3 (Non-critical)
Version:5.1.15-BK, 5.1.11-beta, 5.1.23 OS:Linux (Linux)
Assigned to: CPU Architecture:Any
Tags: Contribution

[5 Jan 2007 11:25] Péter Szabó
Description:
SHOW GLOBAL VARIABLES LIKE 'ft_max_word_len' shows it, but
SELECT @@global.ft_max_word_len doesn't show it.

How to repeat:
$ mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 5.1.11-beta

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> SHOW GLOBAL VARIABLES LIKE 'ft_max_word_len';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| ft_max_word_len | 64    | 
+-----------------+-------+
1 row in set (0.00 sec)

mysql> SELECT @@global.ft_max_word_len;
ERROR 1193 (HY000): Unknown system variable 'ft_max_word_len'
[5 Jan 2007 11:56] Valeriy Kravchuk
Thank you for a bug report. Verified just as described with latest 5.1.15-BK on Linux:

openxs@suse:~/dbs/5.1> bin/mysql -uroot test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.15-beta Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> SELECT @@global.ft_max_word_len;
ERROR 1193 (HY000): Unknown system variable 'ft_max_word_len'
mysql> show global variables like 'ft_max%';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| ft_max_word_len | 84    |
+-----------------+-------+
1 row in set (0.01 sec)
[31 Oct 2007 12:08] terry tao
The 5.1.23-bk on linux has the issue too.Because the ft_max_word_len is not managed by class sys_var,it is not accessible as @@ft_max_word_len in SELECT or SET.Most of these variables are readonly after server start,so they can be managed by the class sys_var_readonly.

===== set_var.cc 1.254 vs edited =====
--- 1.254/sql/set_var.cc        
+++ edited/set_var.cc   
@@ -654,7 +654,6 @@
 static sys_var_log_output sys_var_log_output_state(&vars, "log_output", &log_output_options,
                                            &log_output_typelib, 0);

-
 /*
   Additional variables (not derived from sys_var class, not accessible as
   @@varname in SELECT or SET). Sorted in alphabetical order to facilitate
@@ -664,50 +663,73 @@

 #define FIXED_VARS_SIZE (sizeof(fixed_vars) / sizeof(SHOW_VAR))
 static SHOW_VAR fixed_vars[]= {
-  {"back_log",                (char*) &back_log,                    SHOW_LONG},
-  {"character_sets_dir",      mysql_charsets_dir,                   SHOW_CHAR},
-  {"ft_max_word_len",         (char*) &ft_max_word_len,             SHOW_LONG},
-  {"ft_min_word_len",         (char*) &ft_min_word_len,             SHOW_LONG},
-  {"ft_query_expansion_limit",(char*) &ft_query_expansion_limit,    SHOW_LONG},
-  {"ft_stopword_file",        (char*) &ft_stopword_file,            SHOW_CHAR_PTR},
-  {"init_file",               (char*) &opt_init_file,               SHOW_CHAR_PTR},
-  {"language",                language,                             SHOW_CHAR},
-  {"large_files_support",     (char*) &opt_large_files,             SHOW_BOOL},
-  {"large_page_size",         (char*) &opt_large_page_size,         SHOW_INT},
-  {"large_pages",             (char*) &opt_large_pages,             SHOW_MY_BOOL},
+};
+
+/*
+  Move variables from fixed_vars to sys_var_readonly.
+*/
+
+#define DECLARE_SYSVAR_READONLY(chain,name,val,var_type,show_type)\
+static uchar *get_##name(THD *thd) \
+{ \
+  return (uchar*)val; \
+}\
+static sys_var_readonly  sys_##name(chain, #name,var_type,show_type,get_##name);
+
+
+DECLARE_SYSVAR_READONLY(&vars,back_log,&back_log,OPT_GLOBAL,SHOW_LONG);
+DECLARE_SYSVAR_READONLY(&vars,ft_max_word_len,&ft_max_word_len,OPT_GLOBAL,SHOW_LONG);
+DECLARE_SYSVAR_READONLY(&vars,ft_min_word_len,&ft_min_word_len,OPT_GLOBAL,SHOW_LONG);
+DECLARE_SYSVAR_READONLY(&vars,ft_query_expansion_limit,&ft_query_expansion_limit,OPT_GLOBAL,SHOW_LONG);
+DECLARE_SYSVAR_READONLY(&vars,ft_stopword_file,&ft_stopword_file,OPT_GLOBAL,SHOW_CHAR_PTR);
+DECLARE_SYSVAR_READONLY(&vars,init_file,&opt_init_file,OPT_GLOBAL,SHOW_CHAR_PTR);
+DECLARE_SYSVAR_READONLY(&vars,language,language,OPT_GLOBAL,SHOW_CHAR);
+DECLARE_SYSVAR_READONLY(&vars,large_files_support,&opt_large_files,OPT_GLOBAL,SHOW_BOOL);
+DECLARE_SYSVAR_READONLY(&vars,large_page_size,&opt_large_page_size,OPT_GLOBAL,SHOW_INT);
+DECLARE_SYSVAR_READONLY(&vars,large_pages,&opt_large_pages,OPT_GLOBAL,SHOW_MY_BOOL);
+
 #ifdef HAVE_MLOCKALL
-  {"locked_in_memory",       (char*) &locked_in_memory,            SHOW_MY_BOOL},
+DECLARE_SYSVAR_READONLY(&vars,locked_in_memory,&locked_in_memory,OPT_GLOBAL,SHOW_MY_BOOL);
 #endif
-  {"log",                     (char*) &opt_log,                     SHOW_MY_BOOL},
-  {"log_bin",                 (char*) &opt_bin_log,                 SHOW_BOOL},
-  {"log_error",               (char*) log_error_file,               SHOW_CHAR},
-  {"log_slow_queries",        (char*) &opt_slow_log,                SHOW_MY_BOOL},
-  {"lower_case_file_system",  (char*) &lower_case_file_system,      SHOW_MY_BOOL},
-  {"lower_case_table_names",  (char*) &lower_case_table_names,      SHOW_INT},
-  {"myisam_recover_options",  (char*) &myisam_recover_options_str,  SHOW_CHAR_PTR},
+
+DECLARE_SYSVAR_READONLY(&vars,log,&opt_log,OPT_GLOBAL,SHOW_MY_BOOL);
+DECLARE_SYSVAR_READONLY(&vars,log_bin,&opt_bin_log,OPT_GLOBAL,SHOW_BOOL);
+DECLARE_SYSVAR_READONLY(&vars,log_error,log_error_file,OPT_GLOBAL,SHOW_CHAR);
+DECLARE_SYSVAR_READONLY(&vars,log_slow_queries,&opt_slow_log,OPT_GLOBAL,SHOW_MY_BOOL);
+DECLARE_SYSVAR_READONLY(&vars,lower_case_file_system,&lower_case_file_system,OPT_GLOBAL,SHOW_MY_BOOL);
+DECLARE_SYSVAR_READONLY(&vars,lower_case_table_names,&lower_case_table_names,OPT_GLOBAL,SHOW_INT);
+DECLARE_SYSVAR_READONLY(&vars,myisam_recover_options,&myisam_recover_options_str,OPT_GLOBAL,SHOW_CHAR_PTR);
+
 #ifdef __NT__
-  {"named_pipe",             (char*) &opt_enable_named_pipe,       SHOW_MY_BOOL},
+DECLARE_SYSVAR_READONLY(&vars,named_pipe,&opt_enable_named_pipe,OPT_GLOBAL,SHOW_MY_BOOL);
 #endif
-  {"open_files_limit",       (char*) &open_files_limit,            SHOW_LONG},
-  {"pid_file",                (char*) pidfile_name,                 SHOW_CHAR},
-  {"plugin_dir",              (char*) opt_plugin_dir,               SHOW_CHAR},
-  {"port",                    (char*) &mysqld_port,                 SHOW_INT},
-  {"protocol_version",        (char*) &protocol_version,            SHOW_INT},
+
+DECLARE_SYSVAR_READONLY(&vars,open_files_limit,&open_files_limit,OPT_GLOBAL,SHOW_LONG);
+DECLARE_SYSVAR_READONLY(&vars,pid_file,pidfile_name,OPT_GLOBAL,SHOW_CHAR);
+DECLARE_SYSVAR_READONLY(&vars,plugin_dir,opt_plugin_dir,OPT_GLOBAL,SHOW_CHAR);
+DECLARE_SYSVAR_READONLY(&vars,port,&mysqld_port,OPT_GLOBAL,SHOW_INT);
+DECLARE_SYSVAR_READONLY(&vars,protocol_version,&protocol_version,OPT_GLOBAL,SHOW_INT);
+
 #ifdef HAVE_SMEM
-  {"shared_memory",           (char*) &opt_enable_shared_memory,    SHOW_MY_BOOL},
-  {"shared_memory_base_name", (char*) &shared_memory_base_name,     SHOW_CHAR_PTR},
+DECLARE_SYSVAR_READONLY(&vars,shared_memory,&opt_enable_shared_memory,OPT_GLOBAL,SHOW_MY_BOOL);
+DECLARE_SYSVAR_READONLY(&vars,shared_memory_base_name,&shared_memory_base_name,OPT_GLOBAL,SHOW_CHAR_PTR);
 #endif
-  {"skip_external_locking",   (char*) &my_disable_locking,          SHOW_MY_BOOL},
-  {"skip_networking",         (char*) &opt_disable_networking,      SHOW_BOOL},
-  {"skip_show_database",      (char*) &opt_skip_show_db,            SHOW_BOOL},
+
+DECLARE_SYSVAR_READONLY(&vars,skip_external_locking,&my_disable_locking,OPT_GLOBAL,SHOW_MY_BOOL);
+DECLARE_SYSVAR_READONLY(&vars,skip_networking,&opt_disable_networking,OPT_GLOBAL,SHOW_BOOL);
+DECLARE_SYSVAR_READONLY(&vars,skip_show_database,&opt_skip_show_db,OPT_GLOBAL,SHOW_BOOL);
+
 #ifdef HAVE_SYS_UN_H
-  {"socket",                  (char*) &mysqld_unix_port,            SHOW_CHAR_PTR},
+DECLARE_SYSVAR_READONLY(&vars,socket,&mysqld_unix_port,OPT_GLOBAL,SHOW_CHAR_PTR);
 #endif
+
 #ifdef HAVE_THR_SETCONCURRENCY
-  {"thread_concurrency",      (char*) &concurrency,                 SHOW_LONG},
+DECLARE_SYSVAR_READONLY(&vars,thread_concurrency,&concurrency,OPT_GLOBAL,SHOW_LONG);
 #endif
-  {"thread_stack",            (char*) &thread_stack,                SHOW_LONG},
-};
+
+DECLARE_SYSVAR_READONLY(&vars,thread_stack,&thread_stack,OPT_GLOBAL,SHOW_LONG);
+
+

 bool sys_var::check(THD *thd, set_var *var)
@@ -1506,6 +1528,14 @@
     value= *(ha_rows*) value_ptr(thd, var_type, base);
     pthread_mutex_unlock(&LOCK_global_system_variables);
     return new Item_int((longlong) value);
+  }
+  case SHOW_BOOL:
+  {
+    int32 value;
+    pthread_mutex_lock(&LOCK_global_system_variables);
+    value= *(bool*) value_ptr(thd, var_type, base);
+    pthread_mutex_unlock(&LOCK_global_system_variables);
+    return new Item_int(value,1);
   }
   case SHOW_MY_BOOL:
   {
[5 Feb 2008 23:45] Sveta Smirnova
There is similar bug #34314. One should be duplicate of each other.
[8 May 2009 18:14] Masood Mortazavi
Péter Szabó -

Given you're interested in contribution to MySQL, please note that MySQL is using a new contributor agreement (i.e. the "Sun Contributor Agreement"). 

Under the Sun Contributor Agreement (SCA), the contributor retains copyrights while also granting those same rights to Sun as the project sponsor. It supersedes the previously used MySQL Contributor License Agreement (CLA).

You can get a copy of the SCA document here:
http://www.sun.com/software/opensource/sca.pdf 

When you sign and submit your copy of the SCA document as described here: 
  http://forge.mysql.com/wiki/Sun_Contributor_Agreement , 
your signatory status will be reflected, along with your interest in contributing to MySQL, here: 
   https://sca.dev.java.net/CA_signatories.htm 

Being on the SCA signatories list will facilitate review and interaction regarding your code contributions to MySQL (as well as to any other Sun-managed Open-Source project).
[3 Oct 2009 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[6 Mar 2010 10:57] Bugs System
Pushed into 5.5.3-m3 (revid:alik@sun.com-20100306103849-hha31z2enhh7jwt3) (version source revid:vvaintroub@fedora12-20091225154921-x25a5pyw1pxiwobv) (merge vers: 5.5.99) (pib:16)
[15 Mar 2010 23:27] Paul DuBois
Noted in 5.5.3 changelog.

Some system variables displayed by SHOW VARIABLES could not be
selected using SELECT @@{GLOBAL,SESSION}.var_name.
[17 Mar 2010 17:03] Ståle Deraas
This bugreport was closed as part of WL#4738 "streamline/simplify@@variable creation process". The contributed patch was not used.