From cbdd54e415c53e9fa7df8bd3b17b09612b8c0c5d Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 16 Aug 2005 16:31:16 -0700 Subject: [PATCH 1/5] Fix SLEEP() to be interruptable. (Bug #12582) include/my_global.h: Add set_timespec_nsec() for setting higher-resolution time. sql/item_func.cc: Use pthread_cond_timedwait() for SLEEP() so that it can be killed using the normal thread/query-killing code. --- include/my_global.h | 7 +++++++ sql/item_func.cc | 30 ++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/include/my_global.h b/include/my_global.h index 95763f64e55..2627ea8e821 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -939,6 +939,13 @@ typedef char bool; /* Ordinary boolean values 0 1 */ #endif /* HAVE_TIMESPEC_TS_SEC */ #endif /* set_timespec */ +#define set_timespec_nsec(ABSTIME,NSEC) \ +{\ + ulonglong now= my_getsystime(); \ + (ABSTIME).tv_sec= (now / ULL(10000000)) + (NSEC / ULL(1000000000)); \ + (ABSTIME).tv_nsec= (now % ULL(10000000)) * 100 + (NSEC % ULL(1000000000)); \ +} + /* Define-funktions for reading and storing in machine independent format (low byte first) diff --git a/sql/item_func.cc b/sql/item_func.cc index 61467595424..460d442de89 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -3266,10 +3266,36 @@ void Item_func_benchmark::print(String *str) longlong Item_func_sleep::val_int() { + THD *thd= current_thd; + struct timespec abstime; + pthread_cond_t cond; + int error= 0; + DBUG_ASSERT(fixed == 1); + double time= args[0]->val_real(); - my_sleep((ulong)time*1000000L); - return 0; + set_timespec_nsec(abstime, (ulonglong)(time * ULL(1000000000))); + + pthread_cond_init(&cond, NULL); + pthread_mutex_lock(&LOCK_user_locks); + + thd->mysys_var->current_mutex= &LOCK_user_locks; + thd->mysys_var->current_cond= &cond; + + while (!thd->killed && + (error= pthread_cond_timedwait(&cond, &LOCK_user_locks, + &abstime) != ETIMEDOUT) && + error != EINVAL) ; + + pthread_mutex_lock(&thd->mysys_var->mutex); + thd->mysys_var->current_mutex= 0; + thd->mysys_var->current_cond= 0; + pthread_mutex_unlock(&thd->mysys_var->mutex); + + pthread_mutex_unlock(&LOCK_user_locks); + pthread_cond_destroy(&cond); + + return (error == ETIMEDOUT) ? 0 : 1; } From 12bed9ff4f7fb3303accace6ca0561e467867794 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 17 Aug 2005 18:08:30 -0700 Subject: [PATCH 2/5] Fix up definition of new set_timespec_nsec() macro. (Related to bug #12582) include/my_global.h: Add distinct set_timespec_nsec() macro for when HAVE_TIMESPEC_TS_SEC is defined. --- include/my_global.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/include/my_global.h b/include/my_global.h index 2627ea8e821..2546dde754d 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -927,7 +927,17 @@ typedef char bool; /* Ordinary boolean values 0 1 */ #ifndef set_timespec #ifdef HAVE_TIMESPEC_TS_SEC -#define set_timespec(ABSTIME,SEC) { (ABSTIME).ts_sec=time(0) + (time_t) (SEC); (ABSTIME).ts_nsec=0; } +#define set_timespec(ABSTIME,SEC) \ +{ \ + (ABSTIME).ts_sec=time(0) + (time_t) (SEC); \ + (ABSTIME).ts_nsec=0; \ +} +#define set_timespec_nsec(ABSTIME,NSEC) \ +{\ + ulonglong now= my_getsystime(); \ + (ABSTIME).ts_sec= (now / ULL(10000000)) + (NSEC / ULL(1000000000)); \ + (ABSTIME).ts_nsec= (now % ULL(10000000)) * 100 + (NSEC % ULL(1000000000)); \ +} #else #define set_timespec(ABSTIME,SEC) \ {\ @@ -936,15 +946,14 @@ typedef char bool; /* Ordinary boolean values 0 1 */ (ABSTIME).tv_sec=tv.tv_sec+(time_t) (SEC);\ (ABSTIME).tv_nsec=tv.tv_usec*1000;\ } -#endif /* HAVE_TIMESPEC_TS_SEC */ -#endif /* set_timespec */ - #define set_timespec_nsec(ABSTIME,NSEC) \ {\ ulonglong now= my_getsystime(); \ (ABSTIME).tv_sec= (now / ULL(10000000)) + (NSEC / ULL(1000000000)); \ (ABSTIME).tv_nsec= (now % ULL(10000000)) * 100 + (NSEC % ULL(1000000000)); \ } +#endif /* HAVE_TIMESPEC_TS_SEC */ +#endif /* set_timespec */ /* Define-funktions for reading and storing in machine independent format From c471e84bc0111f1fb09632b9f7e5a6f9f81c1491 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 17 Aug 2005 18:42:07 -0700 Subject: [PATCH 3/5] Fix bad merge of sql/item_strfunc.cc by aivanov sql/item_strfunc.cc: Fix bad merge --- sql/item_strfunc.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 1e1cc123e60..094a0c56319 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -2176,9 +2176,6 @@ void Item_func_lpad::fix_length_and_dec() { ulonglong length= ((ulonglong) args[1]->val_int() * collation.collation->mbmaxlen); - /*a comment before (merged) */ - length= max((ulonglong)args[0]->max_length, length); - /*a comment after */ if (length >= MAX_BLOB_WIDTH) { length= MAX_BLOB_WIDTH; From 6dfb784791aecfb85315239b370b8ef157a08cb2 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 17 Aug 2005 19:56:14 -0700 Subject: [PATCH 4/5] Revert patch for Bug #12595, it causes the sql_mode test to fail. mysql-test/r/select.result: Update results mysql-test/t/select.test: Remove regression test sql/item_cmpfunc.cc: Revert patch for checking length of ESCAPE, it is not correct. --- mysql-test/r/select.result | 11 ----------- mysql-test/t/select.test | 11 ----------- sql/item_cmpfunc.cc | 6 ------ 3 files changed, 28 deletions(-) diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 1b35df534a0..b20949d4a62 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -2756,14 +2756,3 @@ DROP TABLE t1,t2; select x'10' + 0, X'10' + 0, b'10' + 0, B'10' + 0; x'10' + 0 X'10' + 0 b'10' + 0 B'10' + 0 16 16 2 2 -CREATE TABLE BUG_12595(a varchar(100)); -INSERT INTO BUG_12595 VALUES ('hakan%'), ('hakank'), ("ha%an"); -SELECT * FROM BUG_12595 WHERE a LIKE 'hakan*%' ESCAPE '*'; -a -hakan% -SELECT * FROM BUG_12595 WHERE a LIKE 'hakan**%' ESCAPE '**'; -ERROR HY000: Incorrect arguments to ESCAPE -SELECT * FROM BUG_12595 WHERE a LIKE 'ha%%an' ESCAPE '%'; -a -ha%an -DROP TABLE BUG_12595; diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index 390c4372f16..8e74167852b 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -2348,14 +2348,3 @@ DROP TABLE t1,t2; # select x'10' + 0, X'10' + 0, b'10' + 0, B'10' + 0; - -# -# BUG #12595 -# -CREATE TABLE BUG_12595(a varchar(100)); -INSERT INTO BUG_12595 VALUES ('hakan%'), ('hakank'), ("ha%an"); -SELECT * FROM BUG_12595 WHERE a LIKE 'hakan*%' ESCAPE '*'; --- error 1210 -SELECT * FROM BUG_12595 WHERE a LIKE 'hakan**%' ESCAPE '**'; -SELECT * FROM BUG_12595 WHERE a LIKE 'ha%%an' ESCAPE '%'; -DROP TABLE BUG_12595; diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index c305196615a..b513fb26bdb 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -2792,12 +2792,6 @@ bool Item_func_like::fix_fields(THD *thd, Item **ref) { /* If we are on execution stage */ String *escape_str= escape_item->val_str(&tmp_value1); - /* ESCAPE must be 1 char in length.*/ - if (escape_str && escape_str->numchars() != 1) - { - my_error(ER_WRONG_ARGUMENTS,MYF(0),"ESCAPE"); - return TRUE; - } escape= escape_str ? *(escape_str->ptr()) : '\\'; /* From fc44a776494edfc9ce5f6deb2bc997f003627fae Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 17 Aug 2005 19:57:07 -0700 Subject: [PATCH 5/5] Fix minor typo in handling of error conditions and return of SLEEP(). sql/item_func.cc: Remove unnecessary initialization, fix parens placement --- sql/item_func.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/item_func.cc b/sql/item_func.cc index 460d442de89..d3b53db2d54 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -3269,7 +3269,7 @@ longlong Item_func_sleep::val_int() THD *thd= current_thd; struct timespec abstime; pthread_cond_t cond; - int error= 0; + int error; DBUG_ASSERT(fixed == 1); @@ -3284,7 +3284,7 @@ longlong Item_func_sleep::val_int() while (!thd->killed && (error= pthread_cond_timedwait(&cond, &LOCK_user_locks, - &abstime) != ETIMEDOUT) && + &abstime)) != ETIMEDOUT && error != EINVAL) ; pthread_mutex_lock(&thd->mysys_var->mutex);