diff options
author | Ramil Kalimullin <ramil@mysql.com> | 2008-07-14 15:57:56 +0500 |
---|---|---|
committer | Ramil Kalimullin <ramil@mysql.com> | 2008-07-14 15:57:56 +0500 |
commit | a3619d2e865eb5705a8acfc10db91ae700bb7043 (patch) | |
tree | c7c25d6d79b46690e65e90e8929566d938e167cc /sql | |
parent | d59b37130513b7d8b20f98f9bfe49546cc1e8757 (diff) | |
parent | e000e4a2a298f92c246ae10e7178ab03645a434a (diff) | |
download | mariadb-git-a3619d2e865eb5705a8acfc10db91ae700bb7043.tar.gz |
auto-merge
Diffstat (limited to 'sql')
-rw-r--r-- | sql/item_cmpfunc.cc | 6 | ||||
-rw-r--r-- | sql/item_strfunc.cc | 65 |
2 files changed, 56 insertions, 15 deletions
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index f267ad39984..2db77eb7c56 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -3758,6 +3758,9 @@ longlong Item_func_in::val_int() return (longlong) (!null_value && tmp != negated); } + if ((null_value= args[0]->null_value)) + return 0; + have_null= 0; for (uint i= 1 ; i < arg_count ; i++) { Item_result cmp_type= item_cmp_type(left_result_type, args[i]->result_type()); @@ -3766,9 +3769,6 @@ longlong Item_func_in::val_int() if (!(value_added_map & (1 << (uint)cmp_type))) { in_item->store_value(args[0]); - if ((null_value=args[0]->null_value)) - return 0; - have_null= 0; value_added_map|= 1 << (uint)cmp_type; } if (!in_item->cmp(args[i]) && !args[i]->null_value) diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 56aa44b453e..4e01728f71c 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -3370,7 +3370,8 @@ static char clock_seq_and_node_str[]="-0000-000000000000"; number of 100-nanosecond intervals between 1582-10-15 00:00:00.00 and 1970-01-01 00:00:00.00. */ -#define UUID_TIME_OFFSET ((ulonglong) 141427 * 24 * 60 * 60 * 1000 * 10 ) +#define UUID_TIME_OFFSET ((ulonglong) 141427 * 24 * 60 * 60 * \ + 1000 * 1000 * 10) #define UUID_VERSION 0x1000 #define UUID_VARIANT 0x8000 @@ -3429,24 +3430,64 @@ String *Item_func_uuid::val_str(String *str) set_clock_seq_str(); } - ulonglong tv=my_getsystime() + UUID_TIME_OFFSET + nanoseq; - if (unlikely(tv < uuid_time)) - set_clock_seq_str(); - else if (unlikely(tv == uuid_time)) + ulonglong tv= my_getsystime() + UUID_TIME_OFFSET + nanoseq; + + if (likely(tv > uuid_time)) { - /* special protection from low-res system clocks */ - nanoseq++; - tv++; + /* + Current time is ahead of last timestamp, as it should be. + If we "borrowed time", give it back, just as long as we + stay ahead of the previous timestamp. + */ + if (nanoseq) + { + DBUG_ASSERT((tv > uuid_time) && (nanoseq > 0)); + /* + -1 so we won't make tv= uuid_time for nanoseq >= (tv - uuid_time) + */ + ulong delta= min(nanoseq, (ulong) (tv - uuid_time -1)); + tv-= delta; + nanoseq-= delta; + } } else { - if (nanoseq) + if (unlikely(tv == uuid_time)) { - tv-=nanoseq; - nanoseq=0; + /* + For low-res system clocks. If several requests for UUIDs + end up on the same tick, we add a nano-second to make them + different. + ( current_timestamp + nanoseq * calls_in_this_period ) + may end up > next_timestamp; this is OK. Nonetheless, we'll + try to unwind nanoseq when we get a chance to. + If nanoseq overflows, we'll start over with a new numberspace + (so the if() below is needed so we can avoid the ++tv and thus + match the follow-up if() if nanoseq overflows!). + */ + if (likely(++nanoseq)) + ++tv; + } + + if (unlikely(tv <= uuid_time)) + { + /* + If the admin changes the system clock (or due to Daylight + Saving Time), the system clock may be turned *back* so we + go through a period once more for which we already gave out + UUIDs. To avoid duplicate UUIDs despite potentially identical + times, we make a new random component. + We also come here if the nanoseq "borrowing" overflows. + In either case, we throw away any nanoseq borrowing since it's + irrelevant in the new numberspace. + */ + set_clock_seq_str(); + tv= my_getsystime() + UUID_TIME_OFFSET; + nanoseq= 0; + DBUG_PRINT("uuid",("making new numberspace")); } - DBUG_ASSERT(tv > uuid_time); } + uuid_time=tv; pthread_mutex_unlock(&LOCK_uuid_generator); |