Commit c9a87dba authored by unknown's avatar unknown

Portability fixes found during 5.0 test compilation

Fixed bug in ORDER BY on a small column (Bug #2147)
Fixed error from pthread_mutex_destroy() when one had wrong errmsg file



client/mysqltest.c:
  Added handling of error on query send
  (Needed for init_connection.test)
mysql-test/mysql-test-run.sh:
  Added tracing of mysqldump and mysqlbinlog
mysql-test/r/init_connect.result:
  Updated tests
mysql-test/r/order_by.result:
  Added test for bug filesort bug
mysql-test/t/init_connect-master.opt:
  Added proper quoting (for Solaris and OSF)
mysql-test/t/init_connect.test:
  Portability fix
mysql-test/t/order_by.test:
  Added test for bug #2147 (bug in filesort)
sql/filesort.cc:
  Fixed bug in filesort (Bug #2147)
sql/item.h:
  Clear 'fixed' on cleanup (For prepared statements)
sql/item_func.cc:
  Protect mutex destroy.
  (Fixed error from pthread_mutex_destroy() when one had wrong errmsg file)
sql/log_event.cc:
  Portability fix
sql/sql_class.h:
  Fixed compiler warning
sql/sql_prepare.cc:
  Portability fix. (Some compilers doesn't support jump over variables declared in for())
parent 6e558d61
...@@ -2154,7 +2154,7 @@ int run_query(MYSQL* mysql, struct st_query* q, int flags) ...@@ -2154,7 +2154,7 @@ int run_query(MYSQL* mysql, struct st_query* q, int flags)
DYNAMIC_STRING ds_tmp; DYNAMIC_STRING ds_tmp;
DYNAMIC_STRING eval_query; DYNAMIC_STRING eval_query;
char* query; char* query;
int query_len; int query_len, got_error_on_send= 0;
DBUG_ENTER("run_query"); DBUG_ENTER("run_query");
if (q->type != Q_EVAL) if (q->type != Q_EVAL)
...@@ -2179,9 +2179,13 @@ int run_query(MYSQL* mysql, struct st_query* q, int flags) ...@@ -2179,9 +2179,13 @@ int run_query(MYSQL* mysql, struct st_query* q, int flags)
else else
ds= &ds_res; ds= &ds_res;
if ((flags & QUERY_SEND) && mysql_send_query(mysql, query, query_len)) if (flags & QUERY_SEND)
die("At line %u: unable to send query '%s'(mysql_errno=%d,errno=%d)", {
start_lineno, query, mysql_errno(mysql), errno); got_error_on_send= mysql_send_query(mysql, query, query_len);
if (got_error_on_send && !q->expected_errno[0])
die("At line %u: unable to send query '%s' (mysql_errno=%d , errno=%d)",
start_lineno, query, mysql_errno(mysql), errno);
}
do do
{ {
...@@ -2194,9 +2198,10 @@ int run_query(MYSQL* mysql, struct st_query* q, int flags) ...@@ -2194,9 +2198,10 @@ int run_query(MYSQL* mysql, struct st_query* q, int flags)
if (!(flags & QUERY_REAP)) if (!(flags & QUERY_REAP))
DBUG_RETURN(0); DBUG_RETURN(0);
if ((!counter && (*mysql->methods->read_query_result)(mysql)) || if (got_error_on_send ||
(!(last_result= res= mysql_store_result(mysql)) && (!counter && (*mysql->methods->read_query_result)(mysql)) ||
mysql_field_count(mysql))) (!(last_result= res= mysql_store_result(mysql)) &&
mysql_field_count(mysql)))
{ {
if (q->require_file) if (q->require_file)
{ {
......
...@@ -198,6 +198,8 @@ USER_TEST= ...@@ -198,6 +198,8 @@ USER_TEST=
EXTRA_MASTER_OPT="" EXTRA_MASTER_OPT=""
EXTRA_MYSQL_TEST_OPT="" EXTRA_MYSQL_TEST_OPT=""
EXTRA_MYSQLDUMP_OPT=""
EXTRA_MYSQLBINLOG_OPT=""
USE_RUNNING_SERVER="" USE_RUNNING_SERVER=""
DO_GCOV="" DO_GCOV=""
DO_GDB="" DO_GDB=""
...@@ -373,6 +375,10 @@ while test $# -gt 0; do ...@@ -373,6 +375,10 @@ while test $# -gt 0; do
--debug=d:t:i:A,$MYSQL_TEST_DIR/var/log/slave.trace" --debug=d:t:i:A,$MYSQL_TEST_DIR/var/log/slave.trace"
EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT \ EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT \
--debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysqltest.trace" --debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysqltest.trace"
EXTRA_MYSQLDUMP_OPT="$EXTRA_MYSQLDUMP_OPT \
--debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysqldump.trace"
EXTRA_MYSQLBINLOG_OPT="$EXTRA_MYSQLBINLOG_OPT \
--debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysqlbinlog.trace"
;; ;;
--fast) --fast)
FAST_START=1 FAST_START=1
...@@ -490,8 +496,8 @@ else ...@@ -490,8 +496,8 @@ else
fi fi
fi fi
MYSQL_DUMP="$MYSQL_DUMP --no-defaults -uroot --socket=$MASTER_MYSOCK" MYSQL_DUMP="$MYSQL_DUMP --no-defaults -uroot --socket=$MASTER_MYSOCK $EXTRA_MYSQLDUMP_OPT"
MYSQL_BINLOG="$MYSQL_BINLOG --no-defaults --local-load=$MYSQL_TMP_DIR" MYSQL_BINLOG="$MYSQL_BINLOG --no-defaults --local-load=$MYSQL_TMP_DIR $EXTRA_MYSQLBINLOG_OPT"
export MYSQL_DUMP export MYSQL_DUMP
export MYSQL_BINLOG export MYSQL_BINLOG
......
...@@ -20,5 +20,5 @@ hex(a) ...@@ -20,5 +20,5 @@ hex(a)
616263 616263
set GLOBAL init_connect="adsfsdfsdfs"; set GLOBAL init_connect="adsfsdfsdfs";
select @a; select @a;
ERROR HY000: Lost connection to MySQL server during query Got one of the listed errors
drop table t1; drop table t1;
...@@ -584,3 +584,9 @@ CREATE TABLE t1 (a INT, b INT); ...@@ -584,3 +584,9 @@ CREATE TABLE t1 (a INT, b INT);
SET @id=0; SET @id=0;
UPDATE t1 SET a=0 ORDER BY (a=@id), b; UPDATE t1 SET a=0 ORDER BY (a=@id), b;
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1 ( id smallint(6) unsigned NOT NULL default '0', menu tinyint(4) NOT NULL default '0', KEY id (id), KEY menu (menu)) ENGINE=MyISAM;
INSERT INTO t1 VALUES (11384, 2),(11392, 2);
SELECT id FROM t1 WHERE id <11984 AND menu =2 ORDER BY id DESC LIMIT 1 ;
id
11392
drop table t1;
--set-variable=init_connect="set @a='a\0c'" --set-variable=init_connect="set @a='a\\0c'"
...@@ -28,7 +28,7 @@ connection con0; ...@@ -28,7 +28,7 @@ connection con0;
set GLOBAL init_connect="adsfsdfsdfs"; set GLOBAL init_connect="adsfsdfsdfs";
connect (con5,localhost,user_1,,); connect (con5,localhost,user_1,,);
connection con5; connection con5;
--error 2013 --error 2013,2006
select @a; select @a;
connection con0; connection con0;
drop table t1; drop table t1;
...@@ -373,3 +373,11 @@ SET @id=0; ...@@ -373,3 +373,11 @@ SET @id=0;
UPDATE t1 SET a=0 ORDER BY (a=@id), b; UPDATE t1 SET a=0 ORDER BY (a=@id), b;
DROP TABLE t1; DROP TABLE t1;
#
# Bug when doing an order by on a 1 byte string (Bug #2147)
#
CREATE TABLE t1 ( id smallint(6) unsigned NOT NULL default '0', menu tinyint(4) NOT NULL default '0', KEY id (id), KEY menu (menu)) ENGINE=MyISAM;
INSERT INTO t1 VALUES (11384, 2),(11392, 2);
SELECT id FROM t1 WHERE id <11984 AND menu =2 ORDER BY id DESC LIMIT 1 ;
drop table t1;
...@@ -151,8 +151,6 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length, ...@@ -151,8 +151,6 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length,
records=table->file->estimate_number_of_rows(); records=table->file->estimate_number_of_rows();
selected_records_file= 0; selected_records_file= 0;
} }
if (param.rec_length == param.ref_length && records > param.max_rows)
records=param.max_rows; /* purecov: inspected */
if (multi_byte_charset && if (multi_byte_charset &&
!(param.tmp_buffer=my_malloc(param.sort_length,MYF(MY_WME)))) !(param.tmp_buffer=my_malloc(param.sort_length,MYF(MY_WME))))
...@@ -182,7 +180,7 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length, ...@@ -182,7 +180,7 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length,
DISK_BUFFER_SIZE, MYF(MY_WME))) DISK_BUFFER_SIZE, MYF(MY_WME)))
goto err; goto err;
param.keys--; param.keys--; /* TODO: check why we do this */
param.sort_form= table; param.sort_form= table;
param.end=(param.local_sortorder=sortorder)+s_length; param.end=(param.local_sortorder=sortorder)+s_length;
if ((records=find_all_keys(&param,select,sort_keys, &buffpek_pointers, if ((records=find_all_keys(&param,select,sort_keys, &buffpek_pointers,
...@@ -408,16 +406,6 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select, ...@@ -408,16 +406,6 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select,
if (write_keys(param,sort_keys,idx,buffpek_pointers,tempfile)) if (write_keys(param,sort_keys,idx,buffpek_pointers,tempfile))
DBUG_RETURN(HA_POS_ERROR); DBUG_RETURN(HA_POS_ERROR);
idx=0; idx=0;
if (param->ref_length == param->rec_length &&
my_b_tell(tempfile)/param->rec_length >= param->max_rows)
{
/*
We are writing the result index file and have found all
rows that we need. Abort the sort and return the result.
*/
error=HA_ERR_END_OF_FILE;
break; /* Found enough records */
}
indexpos++; indexpos++;
} }
make_sortkey(param,sort_keys[idx++],ref_pos); make_sortkey(param,sort_keys[idx++],ref_pos);
......
...@@ -128,7 +128,7 @@ class Item { ...@@ -128,7 +128,7 @@ class Item {
virtual ~Item() { name=0; cleanup(); } /*lint -e1509 */ virtual ~Item() { name=0; cleanup(); } /*lint -e1509 */
void set_name(const char *str,uint length, CHARSET_INFO *cs); void set_name(const char *str,uint length, CHARSET_INFO *cs);
void init_make_field(Send_field *tmp_field,enum enum_field_types type); void init_make_field(Send_field *tmp_field,enum enum_field_types type);
virtual void cleanup() {} virtual void cleanup() { fixed=0; }
virtual void make_field(Send_field *field); virtual void make_field(Send_field *field);
virtual bool fix_fields(THD *, struct st_table_list *, Item **); virtual bool fix_fields(THD *, struct st_table_list *, Item **);
virtual int save_in_field(Field *field, bool no_conversions); virtual int save_in_field(Field *field, bool no_conversions);
......
...@@ -1772,17 +1772,25 @@ char *ull_get_key(const ULL *ull,uint *length, ...@@ -1772,17 +1772,25 @@ char *ull_get_key(const ULL *ull,uint *length,
return (char*) ull->key; return (char*) ull->key;
} }
static bool item_user_lock_inited= 0;
void item_user_lock_init(void) void item_user_lock_init(void)
{ {
pthread_mutex_init(&LOCK_user_locks,MY_MUTEX_INIT_SLOW); pthread_mutex_init(&LOCK_user_locks,MY_MUTEX_INIT_SLOW);
hash_init(&hash_user_locks,system_charset_info, hash_init(&hash_user_locks,system_charset_info,
16,0,0,(hash_get_key) ull_get_key,NULL,0); 16,0,0,(hash_get_key) ull_get_key,NULL,0);
item_user_lock_inited= 1;
} }
void item_user_lock_free(void) void item_user_lock_free(void)
{ {
hash_free(&hash_user_locks); if (item_user_lock_inited)
pthread_mutex_destroy(&LOCK_user_locks); {
item_user_lock_inited= 0;
hash_free(&hash_user_locks);
pthread_mutex_destroy(&LOCK_user_locks);
}
} }
void item_user_lock_release(ULL *ull) void item_user_lock_release(ULL *ull)
...@@ -2442,7 +2450,7 @@ Item_func_get_user_var::val_str(String *str) ...@@ -2442,7 +2450,7 @@ Item_func_get_user_var::val_str(String *str)
{ {
DBUG_ENTER("Item_func_get_user_var::val_str"); DBUG_ENTER("Item_func_get_user_var::val_str");
if (!var_entry) if (!var_entry)
return (String*) 0; // No such variable DBUG_RETURN((String*) 0); // No such variable
DBUG_RETURN(var_entry->val_str(&null_value, str, decimals)); DBUG_RETURN(var_entry->val_str(&null_value, str, decimals));
} }
......
...@@ -2344,13 +2344,13 @@ int User_var_log_event::exec_event(struct st_relay_log_info* rli) ...@@ -2344,13 +2344,13 @@ int User_var_log_event::exec_event(struct st_relay_log_info* rli)
float8get(real_val, val); float8get(real_val, val);
it= new Item_real(real_val); it= new Item_real(real_val);
val= (char*) &real_val; // Pointer to value in native format val= (char*) &real_val; // Pointer to value in native format
val_len= sizeof(real_val); val_len= 8;
break; break;
case INT_RESULT: case INT_RESULT:
int_val= (longlong) uint8korr(val); int_val= (longlong) uint8korr(val);
it= new Item_int(int_val); it= new Item_int(int_val);
val= (char*) &int_val; // Pointer to value in native format val= (char*) &int_val; // Pointer to value in native format
val_len= sizeof(int_val); val_len= 8;
break; break;
case STRING_RESULT: case STRING_RESULT:
it= new Item_string(val, val_len, charset); it= new Item_string(val, val_len, charset);
......
...@@ -801,8 +801,11 @@ class THD :public ilink, ...@@ -801,8 +801,11 @@ class THD :public ilink,
inline void end_time() { time(&start_time); } inline void end_time() { time(&start_time); }
inline void set_time(time_t t) { time_after_lock=start_time=user_time=t; } inline void set_time(time_t t) { time_after_lock=start_time=user_time=t; }
inline void lock_time() { time(&time_after_lock); } inline void lock_time() { time(&time_after_lock); }
inline void insert_id(ulonglong id) inline void insert_id(ulonglong id_arg)
{ last_insert_id=id; insert_id_used=1; } {
last_insert_id= id_arg;
insert_id_used=1;
}
inline ulonglong insert_id(void) inline ulonglong insert_id(void)
{ {
if (!last_insert_id_used) if (!last_insert_id_used)
......
...@@ -887,7 +887,7 @@ bool mysql_stmt_prepare(THD *thd, char *packet, uint packet_length) ...@@ -887,7 +887,7 @@ bool mysql_stmt_prepare(THD *thd, char *packet, uint packet_length)
{ {
LEX *lex; LEX *lex;
Prepared_statement *stmt= new Prepared_statement(thd); Prepared_statement *stmt= new Prepared_statement(thd);
SELECT_LEX *sl;
DBUG_ENTER("mysql_stmt_prepare"); DBUG_ENTER("mysql_stmt_prepare");
if (stmt == 0) if (stmt == 0)
...@@ -918,7 +918,7 @@ bool mysql_stmt_prepare(THD *thd, char *packet, uint packet_length) ...@@ -918,7 +918,7 @@ bool mysql_stmt_prepare(THD *thd, char *packet, uint packet_length)
my_pthread_setprio(pthread_self(),WAIT_PRIOR); my_pthread_setprio(pthread_self(),WAIT_PRIOR);
// save WHERE clause pointers to avoid damaging they by optimisation // save WHERE clause pointers to avoid damaging they by optimisation
for (SELECT_LEX *sl= thd->lex->all_selects_list; for (sl= thd->lex->all_selects_list;
sl; sl;
sl= sl->next_select_in_list()) sl= sl->next_select_in_list())
{ {
......
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