Nice catch, Lars-Erik!
One comment, see inline ...
On Nov 22, 2008, at 1:32 PM, Lars-Erik.Bjork@stripped wrote:
> #At file:///home/lb200670/devel/mysql/trampoline/ based on
> revid:john.embretsen@stripped
>
> 2916 lars-erik.bjork@stripped 2008-11-22
> This is a patch for bug#40614 Falcon datetime indexes can not
> handle 0000-00-00
>
>
> After we have found a hit in the index, registered in the
> bitmap, we
> check the actual value of the record to see if it really
> matches (the
> index may be dirty). Further down the stack, in
> Value::compare, we
> compare the stored value (0) to the key value (f. ex
> 20061212000000). The stored value is represented as a small int,
> whereas the key value is an int64. The comparison is done by
> subtracting the key value from the stored value, and
> returning this as
> an integer. However, because the special 0 (not NULL) value
> is much
> smaller than the key value, the result will be outside the
> range of an
> int. Therefore, when the int only uses the last 4 bytes of
> the result,
> the sign-bit of the integer will vary depending on the year
> part of
> the datetime value. This fools Value::compare into returning
> that the
> 0 datetime-value is greater than a much greater datetime-
> value for
> some values of year. The solution is to check if the result is
> greater, equal or smaller than 0, looking at the result as an
> int64
> and then returning 1, 0 or -1, instead of returning the
> result of the
> subtraction as an int
[cut]
>
> === added file 'mysql-test/suite/falcon/r/falcon_bug_40614.result'
> --- a/mysql-test/suite/falcon/r/falcon_bug_40614.result 1970-01-01
> 00:00:00 +0000
> +++ b/mysql-test/suite/falcon/r/falcon_bug_40614.result 2008-11-22
> 12:31:45 +0000
> @@ -0,0 +1,561 @@
> +*** Bug #40614 ***
> +SET @@storage_engine = 'Falcon';
> +DROP TABLE IF EXISTS t1;
> +CREATE TABLE t1 (datetime_key datetime, key(datetime_key));
> +insert into t1 values ('0000-00-00');
> +select * from t1 where datetime_key < '1970-01-01';
[cut]
> +select * from t1 where datetime_key < '2154-01-01';
> +datetime_key
> +0000-00-00 00:00:00
> +DROP TABLE t1;
>
For the non-enlightened, it would be good to know why you chose a
range from 1975 - 2154. I think a simple comment at the beginning of
the test would be enough; maybe also a pointer to the MySQL
documentation.
[cut]
>
> --
> MySQL Code Commits Mailing List
> For list archives: http://lists.mysql.com/commits
> To unsubscribe: http://lists.mysql.com/commits?
> unsub=hakan@stripped
>