summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <monty@donna.mysql.com>2000-08-15 20:09:37 +0300
committerunknown <monty@donna.mysql.com>2000-08-15 20:09:37 +0300
commit8b3993bc017512c3bf20315b12d1a8b7a6870381 (patch)
tree5f72e7444fbc3c8d944a66b54b26550a04e4f0be /sql
parent99110483b2271095dd8b2cb655e3a054f6f7c5a5 (diff)
downloadmariadb-git-8b3993bc017512c3bf20315b12d1a8b7a6870381.tar.gz
Fixed for Ia64 + delayed key creation + a lot of small bug fixes
Docs/Makefile.am: Removed typo Docs/internals.texi: Added documentation about filesort Docs/manual.texi: Lots of changes, including information about the password in the mysql.user table config.h.in: ***MISSING WEAVE*** heap/hp_rnext.c: Fix of reading of read-next include/config-win.h: Fix for Ia64 include/global.h: Fix for Ia64 include/my_base.h: Fix for Ia64 include/myisam.h: New repair options isam/_dynrec.c: Typo fixes isam/_search.c: Fix for Ia64 merge/rrnd.c: Fix of ORDER BY for MERGE tables myisam/ft_eval.c: Fix for Ia64 myisam/ft_parser.c: Fix for Ia64 myisam/ft_static.c: Portability fixes myisam/mi_check.c: Fix for Ia64 + delay key creation myisam/mi_locking.c: Portability fixes myisam/myisamdef.h: Fixes for automatic table repair myisam/myisampack.c: Version number increment myisammrg/myrg_rrnd.c: Fix of ORDER BY for mymerge tables mysql.proj: Updated mysys/charset.c: Fix for Ia64 mysys/mf_casecnv.c: Fix for Ia64 mysys/mf_pack.c: Fix for Ia64 mysys/mf_path.c: Fix for Ia64 mysys/mf_wfile.c: Fix for Ia64 mysys/my_alloc.c: Fix for Ia64 mysys/my_lib.c: Fix for Ia64 mysys/my_lread.c: Fix for Ia64 mysys/my_lwrite.c: Fix for Ia64 mysys/my_winthread.c: Fix for Ia64 mysys/string.c: Fix for Ia64 mysys/thr_alarm.c: Fix for Ia64 mysys/thr_rwlock.c: Fix of scheduler bug for systems without rw_locks regex/regcomp.c: Fix for Ia64 regex/regex.h: Fix for Ia64 regex/regex2.h: Fix for Ia64 scripts/mysqlhotcopy.sh: Explicit version number (because of bitkeeper) sql-bench/bench-init.pl.sh: New help message sql-bench/server-cfg.sh: Updates for postgreSQL 7.0 sql/ChangeLog: Changelog sql/field.cc: Fix of datetime function handling sql/filesort.cc: More comments sql/gen_lex_hash.cc: More options sql/ha_berkeley.cc: Fix for part key reading sql/ha_berkeley.h: Indentation sql/ha_myisam.cc: Fix for delayed key creation sql/ha_myisam.h: Fix for delayed key creation sql/handler.h: Fix for delayed key creation sql/item_func.cc: Fix of crash when using constant expression with UDF functions in WHERE sql/item_timefunc.cc: Fix of datetime function handling sql/mini_client.cc: Portability fix sql/mysql_priv.h: Optimization of select initialization sql/mysqld.cc: Portability fixes, thread cache and min argument for connect_timeout sql/sql_load.cc: Delayed key handling sql/sql_parse.cc: Portability fixes and select initialization optimization sql/sql_select.cc: Small optimization + more comments sql/sql_table.cc: Fix default value adding to blob with alter table + delayed index creation sql/sql_yacc.yy: Optimized select initialization sql/structs.h: Fix for part key read strings/ctype-sjis.c: Fix for Ia64 strings/ctype-tis620.c: Fix for Ia64 strings/t_ctype.h: bk fix support-files/mysql.spec.sh: Added comment vio/viotest-ssl.cc: bk fix vio/viotest-sslconnect.cc: bk fix vio/viotest.cc: bk fix BitKeeper/etc/logging_ok: Logging to logging@openlogging.org accepted
Diffstat (limited to 'sql')
-rw-r--r--sql/ChangeLog6
-rw-r--r--sql/field.cc3
-rw-r--r--sql/filesort.cc4
-rw-r--r--sql/gen_lex_hash.cc19
-rw-r--r--sql/ha_berkeley.cc40
-rw-r--r--sql/ha_berkeley.h2
-rw-r--r--sql/ha_myisam.cc69
-rw-r--r--sql/ha_myisam.h3
-rw-r--r--sql/handler.h2
-rw-r--r--sql/item_func.cc16
-rw-r--r--sql/item_timefunc.cc2
-rw-r--r--sql/mini_client.cc4
-rw-r--r--sql/mysql_priv.h1
-rw-r--r--sql/mysqld.cc11
-rw-r--r--sql/sql_load.cc5
-rw-r--r--sql/sql_parse.cc57
-rw-r--r--sql/sql_select.cc81
-rw-r--r--sql/sql_table.cc10
-rw-r--r--sql/sql_yacc.yy33
-rw-r--r--sql/structs.h3
20 files changed, 245 insertions, 126 deletions
diff --git a/sql/ChangeLog b/sql/ChangeLog
index 81ce83aa243..65a5bca0bf9 100644
--- a/sql/ChangeLog
+++ b/sql/ChangeLog
@@ -1,3 +1,9 @@
+2000-08-08 Michael Widenius <monty@mysql.com>
+
+* Changed ALTER TABLE and LOAD DATA INFILE to create non unique, small keys
+ after all rows are inserted.
+* Fixed use of UDF function with const arguments in WHERE clause.
+
2000-07-11 Michael Widenius <monty@mysql.com>
* Extended safe_mysqld; Patch by Christian Hammers
diff --git a/sql/field.cc b/sql/field.cc
index c903ea456a5..9018021cb93 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -2418,6 +2418,7 @@ bool Field_timestamp::get_date(TIME *ltime,
ltime->second= start->tm_sec;
ltime->second_part= 0;
ltime->neg= 0;
+ ltime->time_type=TIMESTAMP_FULL;
}
return 0;
}
@@ -3005,6 +3006,7 @@ bool Field_newdate::get_date(TIME *ltime,bool fuzzydate)
ltime->day= tmp & 31;
ltime->month= (tmp >> 5) & 15;
ltime->year= (tmp >> 9);
+ ltime->time_type=TIMESTAMP_DATE;
return (!fuzzydate && (!ltime->month || !ltime->day) && ltime->year) ? 1 : 0;
}
@@ -3181,6 +3183,7 @@ bool Field_datetime::get_date(TIME *ltime,bool fuzzydate)
part1=(long) (tmp/LL(1000000));
part2=(long) (tmp - (ulonglong) part1*LL(1000000));
+ ltime->time_type= TIMESTAMP_FULL;
ltime->neg=0;
ltime->second_part=0;
ltime->second= part2%100;
diff --git a/sql/filesort.cc b/sql/filesort.cc
index 44b7a7ab42e..ae07bec3323 100644
--- a/sql/filesort.cc
+++ b/sql/filesort.cc
@@ -192,7 +192,7 @@ ha_rows filesort(TABLE **table, SORT_FIELD *sortorder, uint s_length,
memavl=MIN_SORT_MEMORY;
}
param.keys--;
- maxbuffer+=10; /* Some extra range */
+ maxbuffer+=10; /* Some extra range */
if (memavl < MIN_SORT_MEMORY)
{
@@ -209,7 +209,7 @@ ha_rows filesort(TABLE **table, SORT_FIELD *sortorder, uint s_length,
&tempfile, selected_records_file)) ==
HA_POS_ERROR)
goto err;
- if (maxbuffer == 0)
+ if (maxbuffer == 0) // The whole set is in memory
{
if (save_index(&param,sort_keys,(uint) records))
goto err;
diff --git a/sql/gen_lex_hash.cc b/sql/gen_lex_hash.cc
index 3e1f6f15a6b..d3504b36d44 100644
--- a/sql/gen_lex_hash.cc
+++ b/sql/gen_lex_hash.cc
@@ -27,6 +27,7 @@
#include "lex.h"
bool opt_search=0,opt_verbose=0;
+ulong opt_count=100000;
#define max_allowed_array 8000 // Don't generate bigger arrays than this
#define max_symbol 32767 // Use this for 'not found'
@@ -316,6 +317,7 @@ void print_arrays()
static struct option long_options[] =
{
+ {"count", required_argument, 0, 'c'},
{"search", no_argument, 0, 'S'},
{"verbose", no_argument, 0, 'v'},
{"version", no_argument, 0, 'V'},
@@ -328,7 +330,7 @@ static struct option long_options[] =
static void usage(int version)
{
- printf("%s Ver 3.0 Distrib %s, for %s (%s)\n",
+ printf("%s Ver 3.1 Distrib %s, for %s (%s)\n",
my_progname, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
if (version)
return;
@@ -337,6 +339,7 @@ static void usage(int version)
puts("This program generates a perfect hashing function for the sql_lex.cc");
printf("Usage: %s [OPTIONS]\n", my_progname);
printf("\n\
+-c, --count=# Try count times to find a optimal hash table\n\
-r, --rnd1=# Set 1 part of rnd value for hash generator\n\
-R, --rnd2=# Set 2 part of rnd value for hash generator\n\
-t, --type=# Set type of char table to generate\n\
@@ -353,10 +356,13 @@ static int get_options(int argc, char **argv)
{
int c,option_index=0;
- while ((c=getopt_long(argc,argv,"?SvVr:R:t:",
+ while ((c=getopt_long(argc,argv,"?SvVc:r:R:t:",
long_options, &option_index)) != EOF)
{
switch(c) {
+ case 'c':
+ opt_count=atol(optarg);
+ break;
case 'r':
best_t1=atol(optarg);
break;
@@ -466,8 +472,7 @@ int main(int argc,char **argv)
int error;
MY_INIT(argv[0]);
- start_value=1277803L; best_t1=331678L; best_t2=4097229L; best_type=1;
- /* mode=5791 add=6 func_type: 0 */
+ start_value=6059524L; best_t1=2194873L; best_t2=4441039L; best_type=4; /* mode=4159 add=8 func_type: 0 */
if (get_options(argc,(char **) argv))
exit(1);
@@ -488,7 +493,7 @@ int main(int argc,char **argv)
start_value, best_t1,best_t2,best_type,best_mod,best_add,
best_functype);
- for (uint i=1 ; i <= 100000 ; i++)
+ for (uint i=1 ; i <= opt_count ; i++)
{
if (i % 10 == 0)
{
@@ -532,7 +537,9 @@ printf("/* This code is generated by gen_lex_hash.cc that seeks for a perfect\nh
print_arrays();
- printf("/* t1= %lu t2=%lu type= %d */\n\n",best_t1,best_t2,best_type);
+ printf("/* start_value=%ldL; best_t1=%ldL; best_t2=%ldL; best_type=%d; */ /* mode=%d add=%d type: %d */\n\n",
+ start_value, best_t1, best_t2,best_type,
+ best_mod, best_add, best_functype);
printf("inline SYMBOL *get_hash_symbol(const char *s,unsigned int length,bool function)\n\
{\n\
diff --git a/sql/ha_berkeley.cc b/sql/ha_berkeley.cc
index f9cafd44839..5d76af832ae 100644
--- a/sql/ha_berkeley.cc
+++ b/sql/ha_berkeley.cc
@@ -228,7 +228,7 @@ berkeley_cmp_packed_key(const DBT *new_key, const DBT *saved_key)
key_length-=length;
saved_key_ptr+=key_part->field->packed_col_length(saved_key_ptr);
}
- return 0;
+ return key->handler.bdb_return_if_eq;
}
@@ -250,7 +250,7 @@ berkeley_cmp_fix_length_key(const DBT *new_key, const DBT *saved_key)
key_length-= key_part->length;
saved_key_ptr+=key_part->length;
}
- return 0;
+ return key->handler.bdb_return_if_eq;
}
@@ -964,6 +964,8 @@ int ha_berkeley::read_row(int error, char *buf, uint keynr, DBT *row,
}
+/* This is only used to read whole keys */
+
int ha_berkeley::index_read_idx(byte * buf, uint keynr, const byte * key,
uint key_len, enum ha_rkey_function find_flag)
{
@@ -982,14 +984,38 @@ int ha_berkeley::index_read(byte * buf, const byte * key,
uint key_len, enum ha_rkey_function find_flag)
{
DBT row;
+ int error;
DBUG_ENTER("index_read");
statistic_increment(ha_read_key_count,&LOCK_status);
bzero((char*) &row,sizeof(row));
- DBUG_RETURN(read_row(cursor->c_get(cursor,
- pack_key(&last_key, active_index,
- key_buff, key, key_len),
- &row, DB_SET),
- buf, active_index, &row, 0));
+ if (key_len == table->key_info[active_index].key_length)
+ {
+ error=read_row(cursor->c_get(cursor, pack_key(&last_key,
+ active_index,
+ key_buff,
+ key, key_len),
+ &row, DB_SET),
+ buf, active_index, &row, 0);
+ }
+ else
+ {
+ /* read of partial key */
+ pack_key(&last_key, active_index, key_buff, key, key_len);
+ /* Store for compare */
+ memcpy(key_buff2, key_buff, last_key.size);
+ ((KEY*) last_key.app_private)->handler.bdb_return_if_eq= -1;
+ error=read_row(cursor->c_get(cursor, &last_key, &row, DB_SET_RANGE),
+ buf, active_index, &row, 0);
+ ((KEY*) last_key.app_private)->handler.bdb_return_if_eq=0;
+ if (!error && find_flag == HA_READ_KEY_EXACT)
+ {
+ /* Check that we didn't find a key that wasn't equal to the current
+ one */
+ if (!error && ::key_cmp(table, key_buff2, active_index, key_len))
+ error=HA_ERR_KEY_NOT_FOUND;
+ }
+ }
+ DBUG_RETURN(error);
}
diff --git a/sql/ha_berkeley.h b/sql/ha_berkeley.h
index 95851363686..9a8872b5df0 100644
--- a/sql/ha_berkeley.h
+++ b/sql/ha_berkeley.h
@@ -121,7 +121,7 @@ class ha_berkeley: public handler
enum ha_rkey_function end_search_flag);
int create(const char *name, register TABLE *form,
- HA_CREATE_INFO *create_info);
+ HA_CREATE_INFO *create_info);
int delete_table(const char *name);
THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
enum thr_lock_type lock_type);
diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc
index 513a5affcb2..187cf703ce8 100644
--- a/sql/ha_myisam.cc
+++ b/sql/ha_myisam.cc
@@ -30,11 +30,12 @@
#include "../myisam/myisamdef.h"
#endif
-ulong myisam_sort_buffer_size;
#if !defined(HAVE_PREAD)
pthread_mutex_t THR_LOCK_keycache;
#endif
+ulong myisam_sort_buffer_size;
+
/*****************************************************************************
** MyISAM tables
*****************************************************************************/
@@ -57,7 +58,12 @@ static void mi_check_print_msg(MI_CHECK *param, const char* msg_type,
sql_print_error(msgbuf);
return;
}
-
+ if (param->testflag & (T_CREATE_MISSING_KEYS | T_SAFE_REPAIR |
+ T_AUTO_REPAIR))
+ {
+ my_message(ER_NOT_KEYFILE,msgbuf,MYF(MY_WME));
+ return;
+ }
net_store_data(packet, param->table_name);
net_store_data(packet, param->op_name);
net_store_data(packet, msg_type);
@@ -328,29 +334,37 @@ int ha_myisam::analyze(THD *thd)
}
-int ha_myisam::repair(THD* thd, HA_CHECK_OPT* check_opt)
+int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt)
{
if (!file) return HA_CHECK_INTERNAL_ERROR;
int error ;
MI_CHECK param;
- MYISAM_SHARE* share = file->s;
- char fixed_name[FN_REFLEN];
-
+
myisamchk_init(&param);
param.thd = thd;
param.op_name = (char*) "repair";
- param.table_name = table->table_name;
- param.testflag = check_opt->flags | T_SILENT|T_FORCE_CREATE|T_REP_BY_SORT;
- param.sort_buffer_length= check_opt->sort_buffer_size;
+ param.testflag = (check_opt->flags | T_SILENT|T_FORCE_CREATE|T_REP_BY_SORT|
+ T_STATISTICS);
if (check_opt->quick)
param.opt_rep_quick++;
+ param.sort_buffer_length= check_opt->sort_buffer_size;
+ return repair(thd,param);
+}
+
+
+int ha_myisam::repair(THD *thd, MI_CHECK &param)
+{
+ int error;
+ char fixed_name[FN_REFLEN];
+ MYISAM_SHARE* share = file->s;
+
+ param.table_name = table->table_name;
param.tmpfile_createflag = O_RDWR | O_TRUNC;
param.using_global_keycache = 1;
VOID(fn_format(fixed_name,file->filename,"",MI_NAME_IEXT,
4+ (param.opt_follow_links ? 16 : 0)));
-
- if (share->state.key_map)
+ if (mi_test_if_sort_rep(file,file->state->records))
error = mi_repair_by_sort(&param, file, fixed_name, param.opt_rep_quick);
else
error= mi_repair(&param, file, fixed_name, param.opt_rep_quick);
@@ -397,6 +411,38 @@ int ha_myisam::repair(THD* thd, HA_CHECK_OPT* check_opt)
}
+/* Deactive all not unique index that can be recreated fast */
+
+void ha_myisam::deactivate_non_unique_index(ha_rows rows)
+{
+ if (!(specialflag & SPECIAL_SAFE_MODE))
+ mi_dectivate_non_unique_index(file,rows);
+}
+
+
+bool ha_myisam::activate_all_index(THD *thd)
+{
+ int error=0;
+ char fixed_name[FN_REFLEN];
+ MI_CHECK param;
+ MYISAM_SHARE* share = file->s;
+ DBUG_ENTER("activate_all_index");
+ if (share->state.key_map != ((ulonglong) 1L << share->base.keys)-1)
+ {
+ const char *save_proc_info=thd->proc_info;
+ thd->proc_info="creating index";
+ myisamchk_init(&param);
+ param.op_name = (char*) "recreating_index";
+ param.testflag = (T_SILENT | T_REP_BY_SORT |
+ T_STATISTICS | T_CREATE_MISSING_KEYS | T_TRUST_HEADER);
+ param.myf_rw&= ~MY_WAIT_IF_FULL;
+ param.sort_buffer_length= myisam_sort_buffer_size;
+ param.opt_rep_quick++;
+ error=repair(thd,param) != HA_CHECK_OK;
+ thd->proc_info=save_proc_info;
+ }
+ DBUG_RETURN(error);
+}
int ha_myisam::update_row(const byte * old_data, byte * new_data)
{
@@ -870,4 +916,3 @@ int ha_myisam::ft_read(byte * buf)
table->status=error ? STATUS_NOT_FOUND: 0;
return error;
}
-
diff --git a/sql/ha_myisam.h b/sql/ha_myisam.h
index a25711d720b..8e391f6e3c2 100644
--- a/sql/ha_myisam.h
+++ b/sql/ha_myisam.h
@@ -30,6 +30,7 @@ class ha_myisam: public handler
{
MI_INFO *file;
uint int_option_flag;
+ int repair(THD *thd, MI_CHECK &param);
public:
ha_myisam(TABLE *table): handler(table), file(0),
@@ -76,6 +77,8 @@ class ha_myisam: public handler
int reset(void);
int external_lock(THD *thd, int lock_type);
int delete_all_rows(void);
+ void deactivate_non_unique_index(ha_rows rows);
+ bool activate_all_index(THD *thd);
ha_rows records_in_range(int inx,
const byte *start_key,uint start_key_len,
enum ha_rkey_function start_search_flag,
diff --git a/sql/handler.h b/sql/handler.h
index a86b390e78b..208ae989218 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -261,6 +261,8 @@ public:
virtual int optimize(THD* thd);
virtual int analyze(THD* thd);
virtual int dump(THD* thd, int fd = -1) { return ER_DUMP_NOT_IMPLEMENTED; }
+ virtual void deactivate_non_unique_index(ha_rows rows) {}
+ virtual bool activate_all_index(THD *thd) {return 0;}
// not implemented by default
virtual int net_read_dump(NET* net)
{ return ER_DUMP_NOT_IMPLEMENTED; }
diff --git a/sql/item_func.cc b/sql/item_func.cc
index e59221eb0f5..90201597873 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -1040,9 +1040,13 @@ udf_handler::fix_fields(THD *thd,TABLE_LIST *tables,Item_result_field *func,
char buff[sizeof(double)]; // Max argument in function
DBUG_ENTER("Item_udf_func::fix_fields");
- if (thd && check_stack_overrun(thd,buff))
- return 0; // Fatal error flag is set!
-
+ if (thd)
+ {
+ if (check_stack_overrun(thd,buff))
+ return 0; // Fatal error flag is set!
+ }
+ else
+ thd=current_thd; // In WHERE / const clause
udf_func *tmp_udf=find_udf(u_d->name,strlen(u_d->name),1);
if (!tmp_udf)
@@ -1140,9 +1144,7 @@ udf_handler::fix_fields(THD *thd,TABLE_LIST *tables,Item_result_field *func,
break;
}
}
-
- if(thd)
- thd->net.last_error[0]=0;
+ thd->net.last_error[0]=0;
my_bool (*init)(UDF_INIT *, UDF_ARGS *, char *)=
(my_bool (*)(UDF_INIT *, UDF_ARGS *, char *))
u_d->func_init;
@@ -1588,6 +1590,8 @@ static user_var_entry *get_variable(HASH *hash, LEX_STRING &name,
bool Item_func_set_user_var::fix_fields(THD *thd,TABLE_LIST *tables)
{
+ if (!thd)
+ thd=current_thd;
if (Item_func::fix_fields(thd,tables) ||
!(entry= get_variable(&thd->user_vars, name, 1)))
return 1;
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index 90a6cc2910c..fcb68d07f61 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -431,6 +431,7 @@ void Item_func_curdate::fix_length_and_dec()
ltime.second= 0;
ltime.second_part=0;
ltime.neg=0;
+ ltime.time_type=TIMESTAMP_DATE;
}
bool Item_func_curdate::get_date(TIME *res,
@@ -487,6 +488,7 @@ void Item_func_now::fix_length_and_dec()
ltime.second= start->tm_sec;
ltime.second_part=0;
ltime.neg=0;
+ ltime.time_type=TIMESTAMP_FULL;
}
bool Item_func_now::get_date(TIME *res,
diff --git a/sql/mini_client.cc b/sql/mini_client.cc
index 49433bdf96a..c0e6b3c3cbe 100644
--- a/sql/mini_client.cc
+++ b/sql/mini_client.cc
@@ -231,7 +231,7 @@ static int mc_sock_connect(File s, const struct sockaddr *name, uint namelen, ui
return connect(s, (struct sockaddr*) name, namelen);
#else
int flags, res, s_err;
- size_socket s_err_size = sizeof(uint);
+ socklen_t s_err_size = sizeof(uint);
fd_set sfds;
struct timeval tv;
@@ -500,7 +500,7 @@ mc_mysql_connect(MYSQL *mysql,const char *host, const char *user,
UNIXaddr.sun_family = AF_UNIX;
strmov(UNIXaddr.sun_path, unix_socket);
if (mc_sock_connect(sock,(struct sockaddr *) &UNIXaddr, sizeof(UNIXaddr),
- mysql->options.connect_timeout) <0)
+ mysql->options.connect_timeout) <0)
{
DBUG_PRINT("error",("Got error %d on connect to local server",ERRNO));
net->last_errno=CR_CONNECTION_ERROR;
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index 0963b4dd03a..788502ca2a3 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -219,6 +219,7 @@ int quick_rm_table(enum db_type base,const char *db,
const char *table_name);
bool mysql_change_db(THD *thd,const char *name);
void mysql_parse(THD *thd,char *inBuf,uint length);
+void mysql_init_select(LEX *lex);
pthread_handler_decl(handle_one_connection,arg);
int handle_bootstrap(THD *thd,FILE *file);
sig_handler end_thread_signal(int sig);
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 179c7ecd9dc..ed3a5d38188 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -656,7 +656,7 @@ static void set_user(const char *user)
unireg_abort(1);
}
#ifdef HAVE_INITGROUPS
- initgroups(user,ent->pw_gid);
+ initgroups((char*) user,ent->pw_gid);
#endif
if (setgid(ent->pw_gid) == -1)
{
@@ -876,8 +876,8 @@ void end_thread(THD *thd, bool put_in_cache)
thread_count--;
delete thd;
- if (cached_thread_count < thread_cache_size && ! abort_loop &&
- !kill_cached_threads)
+ if (put_in_cache && cached_thread_count < thread_cache_size &&
+ ! abort_loop && !kill_cached_threads)
{
/* Don't kill the thread, just put it in cache for reuse */
DBUG_PRINT("info", ("Adding thread to cache"))
@@ -891,8 +891,9 @@ void end_thread(THD *thd, bool put_in_cache)
{
wake_thread--;
thd=thread_cache.get();
- threads.append(thd);
+ thd->real_id=pthread_self();
(void) thd->store_globals();
+ threads.append(thd);
pthread_mutex_unlock(&LOCK_thread_count);
DBUG_VOID_RETURN;
}
@@ -2229,7 +2230,7 @@ CHANGEABLE_VAR changeable_vars[] = {
{ "bdb_cache_size", (long*) &berkeley_cache_size, KEY_CACHE_SIZE,
20*1024, (long) ~0, 0, IO_SIZE},
#endif
- { "connect_timeout", (long*) &connect_timeout,CONNECT_TIMEOUT,1,65535,0,1},
+ { "connect_timeout", (long*) &connect_timeout,CONNECT_TIMEOUT,2,65535,0,1},
{ "delayed_insert_timeout",(long*) &delayed_insert_timeout,
DELAYED_WAIT_TIMEOUT,1,~0L,0,1},
{ "delayed_insert_limit",(long*) &delayed_insert_limit,
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index 6f7db9c5a48..8f6af5a811b 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -217,13 +217,16 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
table->time_stamp=0;
table->next_number_field=table->found_next_number_field;
VOID(table->file->extra(HA_EXTRA_WRITE_CACHE));
+ table->file->deactivate_non_unique_index((ha_rows) 0);
table->copy_blobs=1;
if (!field_term->length() && !enclosed->length())
error=read_fixed_length(thd,info,table,fields,read_info);
else
error=read_sep_field(thd,info,table,fields,read_info,*enclosed);
- if (table->file->extra(HA_EXTRA_NO_CACHE))
+ if (table->file->extra(HA_EXTRA_NO_CACHE) ||
+ table->file->activate_all_index((ha_rows) 0))
error=1; /* purecov: inspected */
+
table->time_stamp=save_time_stamp;
table->next_number_field=0;
if (thd->lock)
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 0c7b0b8187f..3d903acbfbf 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -34,6 +34,9 @@ extern I_List<i_string> binlog_do_db, binlog_ignore_db;
extern int yyparse(void);
extern "C" pthread_mutex_t THR_LOCK_keycache;
+#ifdef SOLARIS
+extern "C" int gethostname(char *name, int namelen);
+#endif
static bool check_table_access(THD *thd,uint want_access,TABLE_LIST *tables);
static bool check_lock_tables(THD *thd,TABLE_LIST *tables);
@@ -1571,22 +1574,23 @@ mysql_execute_command(void)
/* Check that the user isn't trying to change a password for another
user if he doesn't have UPDATE privilege to the MySQL database */
- List_iterator <LEX_USER> user_list(lex->users_list);
- LEX_USER *user;
- if(thd->user)
+ if (thd->user) // If not replication
+ {
+ LEX_USER *user;
+ List_iterator <LEX_USER> user_list(lex->users_list);
while ((user=user_list++))
+ {
+ if (user->password.str &&
+ (strcmp(thd->user,user->user.str) ||
+ user->host.str &&
+ my_strcasecmp(user->host.str, thd->host ? thd->host : thd->ip)))
{
- if (user->password.str &&
- (strcmp(thd->user,user->user.str) ||
- user->host.str && my_strcasecmp(user->host.str,
- thd->host ? thd->host : thd->ip)))
- {
- if (check_access(thd, UPDATE_ACL, "mysql",0,1))
- goto error;
- break; // We are allowed to do changes
- }
+ if (check_access(thd, UPDATE_ACL, "mysql",0,1))
+ goto error;
+ break; // We are allowed to do changes
}
-
+ }
+ }
if (tables)
{
if (grant_option && check_grant(thd,
@@ -1614,11 +1618,11 @@ mysql_execute_command(void)
res = mysql_grant(thd, lex->db, lex->users_list, lex->grant,
lex->sql_command == SQLCOM_REVOKE);
if(!res)
- {
- mysql_update_log.write(thd->query,thd->query_length);
- Query_log_event qinfo(thd, thd->query);
- mysql_bin_log.write(&qinfo);
- }
+ {
+ mysql_update_log.write(thd->query,thd->query_length);
+ Query_log_event qinfo(thd, thd->query);
+ mysql_bin_log.write(&qinfo);
+ }
}
break;
}
@@ -1853,12 +1857,27 @@ mysql_init_query(THD *thd)
thd->lex.table_list.first=0;
thd->lex.table_list.next= (byte**) &thd->lex.table_list.first;
- thd->lex.proc_list.first=0; // Needed by sql_select
thd->fatal_error=0; // Safety
thd->last_insert_id_used=thd->query_start_used=thd->insert_id_used=0;
DBUG_VOID_RETURN;
}
+void
+mysql_init_select(LEX *lex)
+{
+ lex->where=lex->having=0;
+ lex->select_limit=current_thd->default_select_limit;
+ lex->offset_limit=0L;
+ lex->options=0;
+ lex->exchange = 0;
+ lex->proc_list.first=0;
+ lex->order_list.elements=lex->group_list.elements=0;
+ lex->order_list.first=0;
+ lex->order_list.next= (byte**) &lex->order_list.first;
+ lex->group_list.first=0;
+ lex->group_list.next= (byte**) &lex->group_list.first;
+}
+
void
mysql_parse(THD *thd,char *inBuf,uint length)
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 030b6f6fb5c..749bbb5b1f5 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -1939,35 +1939,37 @@ get_best_combination(JOIN *join)
}
else
{
- for (i=0 ; i < keyparts ; keyuse++,i++)
- {
- while (keyuse->keypart != i ||
- ((~used_tables) & keyuse->used_tables))
- keyuse++; /* Skipp other parts */
-
- uint maybe_null= test(keyinfo->key_part[i].null_bit);
- j->ref.items[i]=keyuse->val; // Save for cond removal
- if (!keyuse->used_tables &&
- !(join->select_options & SELECT_DESCRIBE))
- { // Compare against constant
- store_key_item *tmp=new store_key_item(keyinfo->key_part[i].field,
- (char*)key_buff + maybe_null,
- maybe_null ?
- (char*) key_buff : 0,
- keyinfo->key_part[i].length,
- keyuse->val);
- if (current_thd->fatal_error)
- {
- return TRUE;
+ THD *thd=current_thd;
+ for (i=0 ; i < keyparts ; keyuse++,i++)
+ {
+ while (keyuse->keypart != i ||
+ ((~used_tables) & keyuse->used_tables))
+ keyuse++; /* Skipp other parts */
+
+ uint maybe_null= test(keyinfo->key_part[i].null_bit);
+ j->ref.items[i]=keyuse->val; // Save for cond removal
+ if (!keyuse->used_tables &&
+ !(join->select_options & SELECT_DESCRIBE))
+ { // Compare against constant
+ store_key_item *tmp=new store_key_item(keyinfo->key_part[i].field,
+ (char*)key_buff +
+ maybe_null,
+ maybe_null ?
+ (char*) key_buff : 0,
+ keyinfo->key_part[i].length,
+ keyuse->val);
+ if (thd->fatal_error)
+ {
+ return TRUE;
+ }
+ tmp->copy();
}
- tmp->copy();
+ else
+ *ref_key++= get_store_key(keyuse,join->const_table_map,
+ &keyinfo->key_part[i],
+ (char*) key_buff,maybe_null);
+ key_buff+=keyinfo->key_part[i].store_length;
}
- else
- *ref_key++= get_store_key(keyuse,join->const_table_map,
- &keyinfo->key_part[i],
- (char*) key_buff,maybe_null);
- key_buff+=keyinfo->key_part[i].store_length;
- }
} /* not ftkey */
*ref_key=0; // end_marker
if (j->type == JT_FT) /* no-op */;
@@ -2319,8 +2321,11 @@ join_free(JOIN *join)
if (join->table)
{
- /* only sorted table is cached */
- if (join->tables > join->const_tables)
+ /*
+ Only a sorted table may be cached. This sorted table is always the
+ first non const table in join->table
+ */
+ if (join->tables > join->const_tables) // Test for not-const tables
free_io_cache(join->table[join->const_tables]);
for (tab=join->join_tab,end=tab+join->tables ; tab != end ; tab++)
{
@@ -2858,23 +2863,24 @@ remove_eq_conds(COND *cond,Item::cond_result *cond_value)
Item_func_isnull *func=(Item_func_isnull*) cond;
Item **args= func->arguments();
+ THD *thd=current_thd;
if (args[0]->type() == Item::FIELD_ITEM)
{
Field *field=((Item_field*) args[0])->field;
if (field->flags & AUTO_INCREMENT_FLAG && !field->table->maybe_null &&
- (current_thd->options & OPTION_AUTO_IS_NULL) &&
- current_thd->insert_id())
+ (thd->options & OPTION_AUTO_IS_NULL) &&
+ thd->insert_id())
{
COND *new_cond;
if ((new_cond= new Item_func_eq(args[0],
new Item_int("last_insert_id()",
- current_thd->insert_id(),
+ thd->insert_id(),
21))))
{
cond=new_cond;
- cond->fix_fields(current_thd,0);
+ cond->fix_fields(thd,0);
}
- current_thd->insert_id(0); // Clear for next request
+ thd->insert_id(0); // Clear for next request
}
/* fix to replace 'NULL' dates with '0' (shreeve@uci.edu) */
else if (((field->type() == FIELD_TYPE_DATE) ||
@@ -2885,7 +2891,7 @@ remove_eq_conds(COND *cond,Item::cond_result *cond_value)
if ((new_cond= new Item_func_eq(args[0],new Item_int("0", 0, 2))))
{
cond=new_cond;
- cond->fix_fields(current_thd,0);
+ cond->fix_fields(thd,0);
}
}
}
@@ -6229,6 +6235,11 @@ static bool add_ref_to_table_cond(THD *thd, JOIN_TAB *join_tab)
}
if (thd->fatal_error)
DBUG_RETURN(TRUE);
+
+ /*
+ Here we pass 0 as the first argument to fix_fields that don't need
+ to do any stack checking (This is already done in the initial fix_fields).
+ */
cond->fix_fields((THD *) 0,(TABLE_LIST *) 0);
if (join_tab->select)
{
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 6e39a1a962b..57ba100ef96 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -709,6 +709,7 @@ bool close_cached_table(THD *thd,TABLE *table)
DBUG_RETURN(result);
}
+
int mysql_repair_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt)
{
TABLE_LIST *table;
@@ -1144,6 +1145,11 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
}
if (alter)
{
+ if (def->sql_type == FIELD_TYPE_BLOB)
+ {
+ my_error(ER_BLOB_CANT_HAVE_DEFAULT,MYF(0),def->change);
+ DBUG_RETURN(-1);
+ }
def->def=alter->def; // Use new default
alter_it.remove();
}
@@ -1504,6 +1510,8 @@ copy_data_between_tables(TABLE *from,TABLE *to,List<create_field> &create,
to->file->external_lock(thd,F_WRLCK);
to->file->extra(HA_EXTRA_WRITE_CACHE);
+ from->file->info(HA_STATUS_VARIABLE);
+ to->file->deactivate_non_unique_index(from->file->records);
List_iterator<create_field> it(create);
create_field *def;
@@ -1554,6 +1562,8 @@ copy_data_between_tables(TABLE *from,TABLE *to,List<create_field> &create,
to->file->print_error(tmp_error,MYF(0));
error=1;
}
+ if (to->file->activate_all_index(thd))
+ error=1;
if (ha_commit(thd) || to->file->external_lock(thd,F_UNLCK))
error=1;
*copied= found_count;
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 21f7ec1c48a..006d829005f 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -680,17 +680,7 @@ create3:
/* empty*/ {}
| opt_duplicate SELECT_SYM
{
- LEX *lex=Lex;
- lex->where=lex->having=0;
- lex->select_limit=current_thd->default_select_limit;
- lex->offset_limit=0L;
- lex->options=0;
- lex->exchange = 0;
- lex->order_list.elements=lex->group_list.elements=0;
- lex->order_list.first=0;
- lex->order_list.next= (byte**) &lex->order_list.first;
- lex->group_list.first=0;
- lex->group_list.next= (byte**) &lex->group_list.first;
+ mysql_init_select(Lex);
}
select_options select_item_list opt_select_from {}
@@ -1149,17 +1139,8 @@ select:
SELECT_SYM
{
LEX *lex=Lex;
- lex->where=lex->having=0;
- lex->select_limit=current_thd->default_select_limit;
- lex->offset_limit=0L;
- lex->options=0;
lex->sql_command= SQLCOM_SELECT;
- lex->exchange = 0;
- lex->order_list.elements=lex->group_list.elements=0;
- lex->order_list.first=0;
- lex->order_list.next= (byte**) &lex->order_list.first;
- lex->group_list.first=0;
- lex->group_list.next= (byte**) &lex->group_list.first;
+ mysql_init_select(lex);
}
select_options select_item_list select_into
@@ -1973,17 +1954,9 @@ insert_values:
| SELECT_SYM
{
LEX *lex=Lex;
- lex->where=lex->having=0;
- lex->select_limit=current_thd->default_select_limit;
- lex->offset_limit=0L;
- lex->options=0;
- lex->order_list.elements=lex->group_list.elements=0;
- lex->order_list.first=0;
- lex->order_list.next= (byte**) &lex->order_list.first;
- lex->group_list.first=0;
- lex->group_list.next= (byte**) &lex->group_list.first;
lex->sql_command = (lex->sql_command == SQLCOM_INSERT ?
SQLCOM_INSERT_SELECT : SQLCOM_REPLACE_SELECT);
+ mysql_init_select(lex);
}
select_options select_item_list select_from {}
diff --git a/sql/structs.h b/sql/structs.h
index b32f957da25..edd1a2a68c4 100644
--- a/sql/structs.h
+++ b/sql/structs.h
@@ -70,6 +70,9 @@ typedef struct st_key {
KEY_PART_INFO *key_part;
char *name; /* Name of key */
ulong *rec_per_key; /* Key part distribution */
+ union {
+ uint bdb_return_if_eq;
+ } handler;
} KEY;