From: Evgeny Potemkin Date: March 15 2010 5:43pm Subject: Re: bzr commit into mysql-5.1-bugteam branch (martin.hansson:3384) Bug#50918 List-Archive: http://lists.mysql.com/commits/103293 Message-Id: <4B9E71A8.2030403@sun.com> MIME-Version: 1.0 Content-Type: text/plain; CHARSET=US-ASCII; format=flowed Content-Transfer-Encoding: 7BIT Hi Martin, Ok to push with minor comments (see below). Regards, Evgen. On 03/10/10 19:38, Martin Hansson wrote: > #At file:///data0/martin/bzr/bug50918/5.1bt-commit/ based on revid:davi.arnaut@stripped > > 3384 Martin Hansson 2010-03-10 > Bug#50918: Date columns treated differently in Views than in > Base Tables > > The type inferrence of a view column caused the result to be > interpreted as the wrong type: DATE colums were interpreted > as TIME and TIME as DATETIME. This happened because view > columns are represented by Item_ref objects as opposed to > Item_field's. Item_ref had no method for retrieving a TIME > value and thus was forced to depend on the default > implementation for any expression, which caused the > expression to be evaluated as a string and then parsed into > a TIME/DATETIME value. > > Fixed by letting Item_ref classes forward the request for a > TIME value to the referred Item - which is a field in this > case - this reads the TIME value directly without > conversion. > > modified: > mysql-test/r/type_date.result > mysql-test/t/type_date.test > sql/item.h > === modified file 'mysql-test/r/type_date.result' > --- a/mysql-test/r/type_date.result 2009-01-13 14:04:28 +0000 > +++ b/mysql-test/r/type_date.result 2010-03-10 16:38:48 +0000 > @@ -275,4 +275,25 @@ select * from t1 where a between '0000-0 > a > 0000-00-01 > drop table t1; > +# > +# Bug#50918: Date columns treated differently in Views than in Base > +# Tables > +# > +CREATE TABLE t1 ( the_date DATE, the_time TIME ); > +INSERT INTO t1 VALUES ( '2010-01-01', '01:01:01' ); > +SELECT * FROM t1 t11 JOIN t1 t12 ON addtime( t11.the_date, t11.the_time ) = > +addtime( t12.the_date, t12.the_time ); > +the_date the_time the_date the_time > +2010-01-01 01:01:01 2010-01-01 01:01:01 > +CREATE VIEW v1 AS SELECT * FROM t1; > +SELECT * FROM t1 JOIN v1 ON addtime( t1.the_date, t1.the_time ) = > +addtime( v1.the_date, v1.the_time ); > +the_date the_time the_date the_time > +2010-01-01 01:01:01 2010-01-01 01:01:01 > +SELECT * FROM t1 JOIN v1 ON addtime( t1.the_date, t1.the_time ) = > +addtime( cast(v1.the_date AS DATETIME), v1.the_time ); > +the_date the_time the_date the_time > +2010-01-01 01:01:01 2010-01-01 01:01:01 > +DROP TABLE t1; > +DROP VIEW v1; > End of 5.1 tests > > === modified file 'mysql-test/t/type_date.test' > --- a/mysql-test/t/type_date.test 2009-01-13 14:04:28 +0000 > +++ b/mysql-test/t/type_date.test 2010-03-10 16:38:48 +0000 > @@ -246,4 +246,24 @@ insert into t1 values ('0000-01-01'), (' > select * from t1 where a between '0000-00-01' and '0000-00-02'; > drop table t1; > > +--echo # > +--echo # Bug#50918: Date columns treated differently in Views than in Base > +--echo # Tables > +--echo # > +CREATE TABLE t1 ( the_date DATE, the_time TIME ); > +INSERT INTO t1 VALUES ( '2010-01-01', '01:01:01' ); > + > +SELECT * FROM t1 t11 JOIN t1 t12 ON addtime( t11.the_date, t11.the_time ) = > + addtime( t12.the_date, t12.the_time ); > + > +CREATE VIEW v1 AS SELECT * FROM t1; > +SELECT * FROM t1 JOIN v1 ON addtime( t1.the_date, t1.the_time ) = > + addtime( v1.the_date, v1.the_time ); > + > +SELECT * FROM t1 JOIN v1 ON addtime( t1.the_date, t1.the_time ) = > + addtime( cast(v1.the_date AS DATETIME), v1.the_time ); > + > +DROP TABLE t1; > +DROP VIEW v1; > + > --echo End of 5.1 tests > > === modified file 'sql/item.h' > --- a/sql/item.h 2010-02-06 19:54:30 +0000 > +++ b/sql/item.h 2010-03-10 16:38:48 +0000 > @@ -2317,6 +2317,12 @@ public: > if (ref&& result_type() == ROW_RESULT) > (*ref)->bring_value(); > } > + bool get_time(MYSQL_TIME *ltime) > + { > + if (*ref != NULL) > + return (*ref)->get_time(ltime); > + return Item::get_time(ltime); It's better to add DBUG_ASSERT(fixed) and the just return (*ref)->get_time(...) Because if *ref == NULL then Item::get_time will fail this assert anyway. > + } > > }; > > > > > >