Commit b95d4398 authored by unknown's avatar unknown

Added new optino --sql-mode to mysqld.


Docs/manual.texi:
  New option, --sql-mode=option[,option[,option]]
sql/ha_myisam.cc:
  Fixed a segmentation fault -bug with myisam-recover which
  occurred if option specified was not a legal one.
sql/mysql_priv.h:
  New option --sql-mode
sql/mysqld.cc:
  New option --sql-mode
sql/sql_class.cc:
  New option --sql-mode
sql/sql_class.h:
  New option --sql-mode
sql/sql_lex.cc:
  option --sql-mode, ansi_quotes and ignore_space
sql/sql_parse.cc:
  option --sql-mode, ignore_space
sql/sql_select.cc:
  option --sql-mode, mode only_full_group_by
sql/sql_yacc.yy:
  option --sql-mode, modes pipes_as_concat and real_as_float
BitKeeper/etc/logging_ok:
  Logging to logging@openlogging.org accepted
parent b5545979
heikki@donna.mysql.fi jani@hynda.mysql.fi
jani@janikt.pp.saunalahti.fi
miguel@light.local
monty@hundin.mysql.fi
monty@tik.mysql.fi
monty@work.mysql.com
mwagner@evoq.mwagner.org
paul@central.snake.net
paul@teton.kitebird.com
sasha@mysql.sashanet.com
serg@serg.mysql.com
tim@threads.polyesthetic.msg
tim@white.box
jcole@tetra.spaceapes.com
davida@isil.mysql.com
tonu@x153.internalnet
...@@ -14595,6 +14595,13 @@ Disable using thread priorities for faster response time. ...@@ -14595,6 +14595,13 @@ Disable using thread priorities for faster response time.
Socket file to use for local connections instead of default Socket file to use for local connections instead of default
@code{/tmp/mysql.sock}. @code{/tmp/mysql.sock}.
@item --sql-mode=option[,option[,option...]]
Option can be one of: REAL_AS_FLOAT, PIPES_AS_CONCAT, ANSI_QUOTES,
IGNORE_SPACE, SERIALIZE, ONLY_FULL_GROUP_BY.
By specifying all of the above options is same as using --ansi.
With this option one can turn on only needed SQL modes. @xref{ANSI mode}.
@item transaction-isolation= @{ READ-UNCOMMITTED | READ-COMMITTED | REPEATABLE-READ | SERIALIZABLE @} @item transaction-isolation= @{ READ-UNCOMMITTED | READ-COMMITTED | REPEATABLE-READ | SERIALIZABLE @}
Sets the default transaction isolation level. @xref{SET TRANSACTION}. Sets the default transaction isolation level. @xref{SET TRANSACTION}.
...@@ -45720,6 +45727,8 @@ not yet 100% confident in this code. ...@@ -45720,6 +45727,8 @@ not yet 100% confident in this code.
@node News-3.23.41, News-3.23.40, News-3.23.x, News-3.23.x @node News-3.23.41, News-3.23.40, News-3.23.x, News-3.23.x
@appendixsubsec Changes in release 3.23.41 @appendixsubsec Changes in release 3.23.41
@itemize @bullet @itemize @bullet
@item Added option @code{--sql-mode=option[,option[,option]]}. Please see
@code{mysqld --help} for legal modes.
@item @item
Fixed optimizing bug in @code{ORDER BY} where some @code{ORDER BY} parts Fixed optimizing bug in @code{ORDER BY} where some @code{ORDER BY} parts
where wrongly removed. where wrongly removed.
...@@ -35,7 +35,7 @@ ulong myisam_recover_options= HA_RECOVER_NONE; ...@@ -35,7 +35,7 @@ ulong myisam_recover_options= HA_RECOVER_NONE;
/* bits in myisam_recover_options */ /* bits in myisam_recover_options */
const char *myisam_recover_names[] = const char *myisam_recover_names[] =
{ "DEFAULT", "BACKUP", "FORCE", "QUICK"}; { "DEFAULT", "BACKUP", "FORCE", "QUICK", NullS};
TYPELIB myisam_recover_typelib= {array_elements(myisam_recover_names),"", TYPELIB myisam_recover_typelib= {array_elements(myisam_recover_names),"",
myisam_recover_names}; myisam_recover_names};
......
...@@ -156,8 +156,7 @@ void kill_one_thread(THD *thd, ulong id); ...@@ -156,8 +156,7 @@ void kill_one_thread(THD *thd, ulong id);
#define OPTION_LOW_PRIORITY_UPDATES 8192 #define OPTION_LOW_PRIORITY_UPDATES 8192
#define OPTION_WARNINGS 16384 #define OPTION_WARNINGS 16384
#define OPTION_AUTO_IS_NULL 32768 #define OPTION_AUTO_IS_NULL 32768
#define OPTION_ANSI_MODE 65536L #define OPTION_SAFE_UPDATES 65536L*2
#define OPTION_SAFE_UPDATES OPTION_ANSI_MODE*2
#define OPTION_BUFFER_RESULT OPTION_SAFE_UPDATES*2 #define OPTION_BUFFER_RESULT OPTION_SAFE_UPDATES*2
#define OPTION_BIN_LOG OPTION_BUFFER_RESULT*2 #define OPTION_BIN_LOG OPTION_BUFFER_RESULT*2
#define OPTION_NOT_AUTO_COMMIT OPTION_BIN_LOG*2 #define OPTION_NOT_AUTO_COMMIT OPTION_BIN_LOG*2
...@@ -173,6 +172,14 @@ void kill_one_thread(THD *thd, ulong id); ...@@ -173,6 +172,14 @@ void kill_one_thread(THD *thd, ulong id);
#define QUERY_NO_INDEX_USED OPTION_STATUS_NO_TRANS_UPDATE*2 #define QUERY_NO_INDEX_USED OPTION_STATUS_NO_TRANS_UPDATE*2
#define QUERY_NO_GOOD_INDEX_USED QUERY_NO_INDEX_USED*2 #define QUERY_NO_GOOD_INDEX_USED QUERY_NO_INDEX_USED*2
/* Bits for different SQL modes modes (including ANSI mode) */
#define MODE_REAL_AS_FLOAT 1
#define MODE_PIPES_AS_CONCAT 2
#define MODE_ANSI_QUOTES 4
#define MODE_IGNORE_SPACE 8
#define MODE_SERIALIZABLE 16
#define MODE_ONLY_FULL_GROUP_BY 32
#define RAID_BLOCK_SIZE 1024 #define RAID_BLOCK_SIZE 1024
/* BINLOG_DUMP options */ /* BINLOG_DUMP options */
...@@ -530,7 +537,7 @@ extern ulong keybuff_size,sortbuff_size,max_item_sort_length,table_cache_size, ...@@ -530,7 +537,7 @@ extern ulong keybuff_size,sortbuff_size,max_item_sort_length,table_cache_size,
what_to_log,flush_time, what_to_log,flush_time,
max_tmp_tables,max_heap_table_size,query_buff_size, max_tmp_tables,max_heap_table_size,query_buff_size,
lower_case_table_names,thread_stack,thread_stack_min, lower_case_table_names,thread_stack,thread_stack_min,
binlog_cache_size, max_binlog_cache_size; binlog_cache_size, max_binlog_cache_size, opt_sql_mode;
extern ulong specialflag, current_pid; extern ulong specialflag, current_pid;
extern bool low_priority_updates, using_update_log; extern bool low_priority_updates, using_update_log;
extern bool opt_sql_bin_update, opt_safe_show_db, opt_warnings; extern bool opt_sql_bin_update, opt_safe_show_db, opt_warnings;
......
...@@ -211,7 +211,7 @@ static char mysql_home[FN_REFLEN],pidfile_name[FN_REFLEN]; ...@@ -211,7 +211,7 @@ static char mysql_home[FN_REFLEN],pidfile_name[FN_REFLEN];
static pthread_t select_thread; static pthread_t select_thread;
static bool opt_log,opt_update_log,opt_bin_log,opt_slow_log,opt_noacl, static bool opt_log,opt_update_log,opt_bin_log,opt_slow_log,opt_noacl,
opt_disable_networking=0, opt_bootstrap=0,opt_skip_show_db=0, opt_disable_networking=0, opt_bootstrap=0,opt_skip_show_db=0,
opt_ansi_mode=0,opt_myisam_log=0, opt_myisam_log=0,
opt_large_files=sizeof(my_off_t) > 4; opt_large_files=sizeof(my_off_t) > 4;
bool opt_sql_bin_update = 0, opt_log_slave_updates = 0, opt_safe_show_db=0; bool opt_sql_bin_update = 0, opt_log_slave_updates = 0, opt_safe_show_db=0;
FILE *bootstrap_file=0; FILE *bootstrap_file=0;
...@@ -307,6 +307,7 @@ char server_version[SERVER_VERSION_LENGTH]=MYSQL_SERVER_VERSION; ...@@ -307,6 +307,7 @@ char server_version[SERVER_VERSION_LENGTH]=MYSQL_SERVER_VERSION;
const char *first_keyword="first"; const char *first_keyword="first";
const char **errmesg; /* Error messages */ const char **errmesg; /* Error messages */
const char *myisam_recover_options_str="OFF"; const char *myisam_recover_options_str="OFF";
const char *sql_mode_str="OFF";
const char *default_tx_isolation_name; const char *default_tx_isolation_name;
enum_tx_isolation default_tx_isolation=ISO_READ_COMMITTED; enum_tx_isolation default_tx_isolation=ISO_READ_COMMITTED;
...@@ -320,6 +321,12 @@ double log_10[32]; /* 10 potences */ ...@@ -320,6 +321,12 @@ double log_10[32]; /* 10 potences */
I_List<THD> threads,thread_cache; I_List<THD> threads,thread_cache;
time_t start_time; time_t start_time;
ulong opt_sql_mode = 0L;
const char *sql_mode_names[] =
{ "REAL_AS_FLOAT", "PIPES_AS_CONCAT", "ANSI_QUOTES", "IGNORE_SPACE",
"SERIALIZE","ONLY_FULL_GROUP_BY", NullS };
TYPELIB sql_mode_typelib= {array_elements(sql_mode_names),"",
sql_mode_names};
MY_BITMAP temp_pool; MY_BITMAP temp_pool;
bool use_temp_pool=0; bool use_temp_pool=0;
...@@ -2471,7 +2478,8 @@ enum options { ...@@ -2471,7 +2478,8 @@ enum options {
OPT_GEMINI_FLUSH_LOG, OPT_GEMINI_RECOVER, OPT_GEMINI_FLUSH_LOG, OPT_GEMINI_RECOVER,
OPT_GEMINI_UNBUFFERED_IO, OPT_SKIP_SAFEMALLOC, OPT_GEMINI_UNBUFFERED_IO, OPT_SKIP_SAFEMALLOC,
OPT_SKIP_STACK_TRACE, OPT_SKIP_SYMLINKS, OPT_SKIP_STACK_TRACE, OPT_SKIP_SYMLINKS,
OPT_MAX_BINLOG_DUMP_EVENTS, OPT_SPORADIC_BINLOG_DUMP_FAIL OPT_MAX_BINLOG_DUMP_EVENTS, OPT_SPORADIC_BINLOG_DUMP_FAIL,
OPT_SQL_MODE
}; };
static struct option long_options[] = { static struct option long_options[] = {
...@@ -2604,6 +2612,7 @@ static struct option long_options[] = { ...@@ -2604,6 +2612,7 @@ static struct option long_options[] = {
{"skip-symlink", no_argument, 0, (int) OPT_SKIP_SYMLINKS}, {"skip-symlink", no_argument, 0, (int) OPT_SKIP_SYMLINKS},
{"skip-thread-priority", no_argument, 0, (int) OPT_SKIP_PRIOR}, {"skip-thread-priority", no_argument, 0, (int) OPT_SKIP_PRIOR},
{"sql-bin-update-same", no_argument, 0, (int) OPT_SQL_BIN_UPDATE_SAME}, {"sql-bin-update-same", no_argument, 0, (int) OPT_SQL_BIN_UPDATE_SAME},
{"sql-mode", required_argument, 0, (int) OPT_SQL_MODE},
#include "sslopt-longopts.h" #include "sslopt-longopts.h"
#ifdef __WIN__ #ifdef __WIN__
{"standalone", no_argument, 0, (int) OPT_STANDALONE}, {"standalone", no_argument, 0, (int) OPT_STANDALONE},
...@@ -2764,7 +2773,6 @@ CHANGEABLE_VAR changeable_vars[] = { ...@@ -2764,7 +2773,6 @@ CHANGEABLE_VAR changeable_vars[] = {
struct show_var_st init_vars[]= { struct show_var_st init_vars[]= {
{"ansi_mode", (char*) &opt_ansi_mode, SHOW_BOOL},
{"back_log", (char*) &back_log, SHOW_LONG}, {"back_log", (char*) &back_log, SHOW_LONG},
{"basedir", mysql_home, SHOW_CHAR}, {"basedir", mysql_home, SHOW_CHAR},
#ifdef HAVE_BERKELEY_DB #ifdef HAVE_BERKELEY_DB
...@@ -2866,6 +2874,7 @@ struct show_var_st init_vars[]= { ...@@ -2866,6 +2874,7 @@ struct show_var_st init_vars[]= {
{"slow_launch_time", (char*) &slow_launch_time, SHOW_LONG}, {"slow_launch_time", (char*) &slow_launch_time, SHOW_LONG},
{"socket", (char*) &mysql_unix_port, SHOW_CHAR_PTR}, {"socket", (char*) &mysql_unix_port, SHOW_CHAR_PTR},
{"sort_buffer", (char*) &sortbuff_size, SHOW_LONG}, {"sort_buffer", (char*) &sortbuff_size, SHOW_LONG},
{"sql_mode", (char*) &sql_mode_str, SHOW_CHAR_PTR},
{"table_cache", (char*) &table_cache_size, SHOW_LONG}, {"table_cache", (char*) &table_cache_size, SHOW_LONG},
{"table_type", (char*) &default_table_type_name, SHOW_CHAR_PTR}, {"table_type", (char*) &default_table_type_name, SHOW_CHAR_PTR},
{"thread_cache_size", (char*) &thread_cache_size, SHOW_LONG}, {"thread_cache_size", (char*) &thread_cache_size, SHOW_LONG},
...@@ -3049,6 +3058,9 @@ static void usage(void) ...@@ -3049,6 +3058,9 @@ static void usage(void)
Don't give threads different priorities.\n\ Don't give threads different priorities.\n\
--socket=... Socket file to use for connection\n\ --socket=... Socket file to use for connection\n\
-t, --tmpdir=path Path for temporary files\n\ -t, --tmpdir=path Path for temporary files\n\
--sql-mode=option[,option[,option...]] where option can be one of:\n\
REAL_AS_FLOAT, PIPES_AS_CONCAT, ANSI_QUOTES,\n\
IGNORE_SPACE, SERIALIZE, ONLY_FULL_GROUP_BY.\n\
--transaction-isolation\n\ --transaction-isolation\n\
Default transaction isolation level\n\ Default transaction isolation level\n\
--temp-pool Use a pool of temporary files\n\ --temp-pool Use a pool of temporary files\n\
...@@ -3202,8 +3214,9 @@ static void get_options(int argc,char **argv) ...@@ -3202,8 +3214,9 @@ static void get_options(int argc,char **argv)
opt_warnings=1; opt_warnings=1;
break; break;
case 'a': case 'a':
opt_ansi_mode=1; opt_sql_mode = (MODE_REAL_AS_FLOAT | MODE_PIPES_AS_CONCAT |
thd_startup_options|=OPTION_ANSI_MODE; MODE_ANSI_QUOTES | MODE_IGNORE_SPACE | MODE_SERIALIZABLE
| MODE_ONLY_FULL_GROUP_BY);
default_tx_isolation= ISO_SERIALIZABLE; default_tx_isolation= ISO_SERIALIZABLE;
break; break;
case 'b': case 'b':
...@@ -3726,6 +3739,19 @@ static void get_options(int argc,char **argv) ...@@ -3726,6 +3739,19 @@ static void get_options(int argc,char **argv)
ha_open_options|=HA_OPEN_ABORT_IF_CRASHED; ha_open_options|=HA_OPEN_ABORT_IF_CRASHED;
break; break;
} }
case OPT_SQL_MODE:
{
sql_mode_str = optarg;
if ((opt_sql_mode =
find_bit_type(optarg, &sql_mode_typelib)) == ~(ulong) 0)
{
fprintf(stderr, "Unknown option to sql-mode: %s\n", optarg);
exit(1);
}
if (opt_sql_mode & MODE_SERIALIZABLE)
default_tx_isolation= ISO_SERIALIZABLE;
break;
}
case OPT_MASTER_HOST: case OPT_MASTER_HOST:
master_host=optarg; master_host=optarg;
break; break;
......
...@@ -120,6 +120,7 @@ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0), ...@@ -120,6 +120,7 @@ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0),
server_status=SERVER_STATUS_AUTOCOMMIT; server_status=SERVER_STATUS_AUTOCOMMIT;
update_lock_default= low_priority_updates ? TL_WRITE_LOW_PRIORITY : TL_WRITE; update_lock_default= low_priority_updates ? TL_WRITE_LOW_PRIORITY : TL_WRITE;
options=thd_startup_options; options=thd_startup_options;
sql_mode=(uint) opt_sql_mode;
inactive_timeout=net_wait_timeout; inactive_timeout=net_wait_timeout;
open_options=ha_open_options; open_options=ha_open_options;
tx_isolation=session_tx_isolation=default_tx_isolation; tx_isolation=session_tx_isolation=default_tx_isolation;
......
...@@ -232,7 +232,7 @@ public: ...@@ -232,7 +232,7 @@ public:
char *query,*thread_stack; char *query,*thread_stack;
char *host,*user,*priv_user,*db,*ip; char *host,*user,*priv_user,*db,*ip;
const char *proc_info; const char *proc_info;
uint client_capabilities,max_packet_length; uint client_capabilities,sql_mode,max_packet_length;
uint master_access,db_access; uint master_access,db_access;
TABLE *open_tables,*temporary_tables; TABLE *open_tables,*temporary_tables;
MYSQL_LOCK *lock,*locked_tables; MYSQL_LOCK *lock,*locked_tables;
......
...@@ -121,7 +121,7 @@ void lex_init(void) ...@@ -121,7 +121,7 @@ void lex_init(void)
state_map[(uchar)'*']= (uchar) STATE_END_LONG_COMMENT; state_map[(uchar)'*']= (uchar) STATE_END_LONG_COMMENT;
state_map[(uchar)'@']= (uchar) STATE_USER_END; state_map[(uchar)'@']= (uchar) STATE_USER_END;
state_map[(uchar) '`']= (uchar) STATE_USER_VARIABLE_DELIMITER; state_map[(uchar) '`']= (uchar) STATE_USER_VARIABLE_DELIMITER;
if (thd_startup_options & OPTION_ANSI_MODE) if (opt_sql_mode & MODE_ANSI_QUOTES)
{ {
state_map[(uchar) '"'] = STATE_USER_VARIABLE_DELIMITER; state_map[(uchar) '"'] = STATE_USER_VARIABLE_DELIMITER;
} }
...@@ -149,7 +149,7 @@ LEX *lex_start(THD *thd, uchar *buf,uint length) ...@@ -149,7 +149,7 @@ LEX *lex_start(THD *thd, uchar *buf,uint length)
lex->ftfunc_list.empty(); lex->ftfunc_list.empty();
lex->convert_set=(lex->thd=thd)->convert_set; lex->convert_set=(lex->thd=thd)->convert_set;
lex->yacc_yyss=lex->yacc_yyvs=0; lex->yacc_yyss=lex->yacc_yyvs=0;
lex->ignore_space=test(thd->client_capabilities & CLIENT_IGNORE_SPACE); lex->ignore_space=test(thd->sql_mode & MODE_IGNORE_SPACE);
return lex; return lex;
} }
......
...@@ -412,6 +412,8 @@ check_connections(THD *thd) ...@@ -412,6 +412,8 @@ check_connections(THD *thd)
return(ER_OUT_OF_RESOURCES); return(ER_OUT_OF_RESOURCES);
thd->client_capabilities=uint2korr(net->read_pos); thd->client_capabilities=uint2korr(net->read_pos);
if (thd->client_capabilities & CLIENT_IGNORE_SPACE)
thd->sql_mode|= MODE_IGNORE_SPACE;
#ifdef HAVE_OPENSSL #ifdef HAVE_OPENSSL
DBUG_PRINT("info", DBUG_PRINT("info",
("pkt_len:%d, client capabilities: %d", ("pkt_len:%d, client capabilities: %d",
...@@ -538,8 +540,6 @@ pthread_handler_decl(handle_one_connection,arg) ...@@ -538,8 +540,6 @@ pthread_handler_decl(handle_one_connection,arg)
thd->options |= OPTION_BIG_SELECTS; thd->options |= OPTION_BIG_SELECTS;
if (thd->client_capabilities & CLIENT_COMPRESS) if (thd->client_capabilities & CLIENT_COMPRESS)
net->compress=1; // Use compression net->compress=1; // Use compression
if (thd->options & OPTION_ANSI_MODE)
thd->client_capabilities|=CLIENT_IGNORE_SPACE;
thd->proc_info=0; // Remove 'login' thd->proc_info=0; // Remove 'login'
thd->command=COM_SLEEP; thd->command=COM_SLEEP;
......
...@@ -5937,7 +5937,7 @@ setup_group(THD *thd,TABLE_LIST *tables,List<Item> &fields, ...@@ -5937,7 +5937,7 @@ setup_group(THD *thd,TABLE_LIST *tables,List<Item> &fields,
if (!order) if (!order)
return 0; /* Everything is ok */ return 0; /* Everything is ok */
if (thd->options & OPTION_ANSI_MODE) if (thd->sql_mode & MODE_ONLY_FULL_GROUP_BY)
{ {
Item *item; Item *item;
List_iterator<Item> li(fields); List_iterator<Item> li(fields);
...@@ -5959,7 +5959,7 @@ setup_group(THD *thd,TABLE_LIST *tables,List<Item> &fields, ...@@ -5959,7 +5959,7 @@ setup_group(THD *thd,TABLE_LIST *tables,List<Item> &fields,
return 1; return 1;
} }
} }
if (thd->options & OPTION_ANSI_MODE) if (thd->sql_mode & MODE_ONLY_FULL_GROUP_BY)
{ {
/* Don't allow one to use fields that is not used in GROUP BY */ /* Don't allow one to use fields that is not used in GROUP BY */
Item *item; Item *item;
......
...@@ -34,7 +34,7 @@ int yylex(void *yylval); ...@@ -34,7 +34,7 @@ int yylex(void *yylval);
inline Item *or_or_concat(Item* A, Item* B) inline Item *or_or_concat(Item* A, Item* B)
{ {
return (current_thd->options & OPTION_ANSI_MODE ? return (current_thd->sql_mode & MODE_PIPES_AS_CONCAT ?
(Item*) new Item_func_concat(A,B) : (Item*) new Item_cond_or(A,B)); (Item*) new Item_func_concat(A,B) : (Item*) new Item_cond_or(A,B));
} }
...@@ -915,7 +915,7 @@ int_type: ...@@ -915,7 +915,7 @@ int_type:
| BIGINT { $$=FIELD_TYPE_LONGLONG; } | BIGINT { $$=FIELD_TYPE_LONGLONG; }
real_type: real_type:
REAL { $$= current_thd->options & OPTION_ANSI_MODE ? REAL { $$= current_thd->sql_mode & MODE_REAL_AS_FLOAT ?
FIELD_TYPE_FLOAT : FIELD_TYPE_DOUBLE; } FIELD_TYPE_FLOAT : FIELD_TYPE_DOUBLE; }
| DOUBLE_SYM { $$=FIELD_TYPE_DOUBLE; } | DOUBLE_SYM { $$=FIELD_TYPE_DOUBLE; }
| DOUBLE_SYM PRECISION { $$=FIELD_TYPE_DOUBLE; } | DOUBLE_SYM PRECISION { $$=FIELD_TYPE_DOUBLE; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment