diff --git a/mysql-test/suite/versioning/r/optimized.result b/mysql-test/suite/versioning/r/optimized.result index 046b3d0d4f2..6704e2c5aac 100644 --- a/mysql-test/suite/versioning/r/optimized.result +++ b/mysql-test/suite/versioning/r/optimized.result @@ -52,7 +52,6 @@ select * from t group by b having b=2 system_time as of timestamp now(6); a b Warnings: Warning 4109 Attempt to read unversioned field `b` in historical query -Warning 4109 Attempt to read unversioned field `b` in historical query select a from t where b=2 system_time as of timestamp now(6); a Warnings: @@ -71,7 +70,6 @@ select count(*), b from t group by b having b=NULL system_time as of timestamp n count(*) b Warnings: Warning 4109 Attempt to read unversioned field `b` in historical query -Warning 4109 Attempt to read unversioned field `b` in historical query select a, b from t; a b 1 2 @@ -85,7 +83,6 @@ select * from t for system_time as of timestamp now(6) group by b having b=2; a b Warnings: Warning 4109 Attempt to read unversioned field `b` in historical query -Warning 4109 Attempt to read unversioned field `b` in historical query select a from t for system_time as of timestamp now(6) where b=2; a Warnings: @@ -104,7 +101,6 @@ select count(*), b from t for system_time as of timestamp now(6) group by b havi count(*) b Warnings: Warning 4109 Attempt to read unversioned field `b` in historical query -Warning 4109 Attempt to read unversioned field `b` in historical query create or replace table t ( a int, b int not null without system versioning diff --git a/mysql-test/suite/versioning/r/select.result b/mysql-test/suite/versioning/r/select.result index f83eaff02a4..99dd8845f03 100644 --- a/mysql-test/suite/versioning/r/select.result +++ b/mysql-test/suite/versioning/r/select.result @@ -358,9 +358,18 @@ x y 3 1 select * from t1 for system_time all, t2 for system_time all system_time all; ERROR HY000: Unused clause: 'SYSTEM_TIME' +### Issue #365, bug 4 (related to #226, optimized fields) +create or replace table t1 (i int, b int) with system versioning; +insert into t1 values (0, 0), (0, 0); +select min(i) over (partition by b) as f +from (select i + 0 as i, b from t1) as tt +order by i; +f +0 +0 drop view v1; drop table t1, t2; -call innodb_verify_vtq(27); +call innodb_verify_vtq(28); No A B C D 1 1 1 1 1 2 1 1 1 1 @@ -389,6 +398,7 @@ No A B C D 25 1 1 1 1 26 1 1 1 1 27 1 1 1 1 +28 1 1 1 1 drop procedure verify_vtq; drop procedure innodb_verify_vtq; drop function default_engine; diff --git a/mysql-test/suite/versioning/t/select.test b/mysql-test/suite/versioning/t/select.test index 6ec45db6c08..6421524bc3b 100644 --- a/mysql-test/suite/versioning/t/select.test +++ b/mysql-test/suite/versioning/t/select.test @@ -181,9 +181,16 @@ select * from t1, t2 system_time all; --error ER_VERS_UNUSED_CLAUSE select * from t1 for system_time all, t2 for system_time all system_time all; +--echo ### Issue #365, bug 4 (related to #226, optimized fields) +create or replace table t1 (i int, b int) with system versioning; +insert into t1 values (0, 0), (0, 0); +select min(i) over (partition by b) as f +from (select i + 0 as i, b from t1) as tt +order by i; + drop view v1; drop table t1, t2; -call innodb_verify_vtq(27); +call innodb_verify_vtq(28); -- source suite/versioning/common_finish.inc diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 62bf4dad684..9153e75a365 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1371,13 +1371,13 @@ JOIN::prepare(TABLE_LIST *tables_init, for (ORDER *ord= order; ord; ord= ord->next) { ord->item_ptr= (*ord->item)->transform(thd, transformer, NULL); - ord->item= &ord->item_ptr; + *ord->item= ord->item_ptr; } for (ORDER *ord= group_list; ord; ord= ord->next) { ord->item_ptr= (*ord->item)->transform(thd, transformer, NULL); - ord->item= &ord->item_ptr; + *ord->item= ord->item_ptr; } if (having)