The Big Sleep

This is a discussion on The Big Sleep within the MySQL Database forums, part of the Database Forums category; Just curious, is this expected behaviour?: mysql> SELECT GREATEST(SLEEP(3),SLEEP(4)); +-----------------------------+ | GREATEST(SLEEP(3),SLEEP(4)) | +-----------------------------+ | 0 | +-----------------------------+ ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-20-2007
strawberry
 
Posts: n/a
Default The Big Sleep

Just curious, is this expected behaviour?:

mysql> SELECT GREATEST(SLEEP(3),SLEEP(4));
+-----------------------------+
| GREATEST(SLEEP(3),SLEEP(4)) |
+-----------------------------+
| 0 |
+-----------------------------+
1 row in set (8.71 sec)

Reply With Quote
  #2 (permalink)  
Old 10-20-2007
Paul Lautman
 
Posts: n/a
Default Re: The Big Sleep

strawberry wrote:
> Just curious, is this expected behaviour?:
>
> mysql> SELECT GREATEST(SLEEP(3),SLEEP(4));
> +-----------------------------+
>> GREATEST(SLEEP(3),SLEEP(4)) |

> +-----------------------------+
>> 0 |

> +-----------------------------+
> 1 row in set (8.71 sec)


I guess it depends on what can "interrupt" SLEEP?

I would expect
SELECT GREATEST(LOUD_SNORE(),SLEEP(4));
to return 1


Reply With Quote
  #3 (permalink)  
Old 10-20-2007
J.O. Aho
 
Posts: n/a
Default Re: The Big Sleep

Paul Lautman wrote:
> strawberry wrote:
>> Just curious, is this expected behaviour?:
>>
>> mysql> SELECT GREATEST(SLEEP(3),SLEEP(4));
>> +-----------------------------+
>>> GREATEST(SLEEP(3),SLEEP(4)) |

>> +-----------------------------+
>>> 0 |

>> +-----------------------------+
>> 1 row in set (8.71 sec)

>
> I guess it depends on what can "interrupt" SLEEP?
>
> I would expect
> SELECT GREATEST(LOUD_SNORE(),SLEEP(4));
> to return 1
>
>

From the online manual
http://dev.mysql.com/doc/refman/5.0/...function_sleep

SLEEP(duration)

Sleeps (pauses) for the number of seconds given by the duration argument, then
returns 0. If SLEEP() is interrupted, it returns 1. The duration may have a
fractional part given in microseconds. This function was added in MySQL 5.0.12.

So, the results seems to be right.

--

//Aho
Reply With Quote
  #4 (permalink)  
Old 10-20-2007
J.O. Aho
 
Posts: n/a
Default Re: The Big Sleep

strawberry wrote:
> Just curious, is this expected behaviour?:
>
> mysql> SELECT GREATEST(SLEEP(3),SLEEP(4));
> +-----------------------------+
> | GREATEST(SLEEP(3),SLEEP(4)) |
> +-----------------------------+
> | 0 |
> +-----------------------------+
> 1 row in set (8.71 sec)
>

Greatest can't guess the value that a function returns, it has to wait and see
what happens, so it first waits 3 seconds for the first sleep to finish, and
then 4 seconds for the second sleep to finish, none of the sleep functions
will be interrupted (without outer interference) and therefore you get 0.

I think you would see the pattern if you change the sleep values on a mysql
server that runs on a low load machine.

--

//Aho
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:59 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0