Loading mysql-test/r/view.result +18 −0 Original line number Diff line number Diff line Loading @@ -3117,4 +3117,22 @@ Warnings: Note 1003 select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2` from `test`.`t1` order by `test`.`t1`.`f1`,`test`.`t1`.`f2` drop view v1; drop table t1; CREATE TABLE t1 ( id int(11) NOT NULL PRIMARY KEY, country varchar(32), code int(11) default NULL ); INSERT INTO t1 VALUES (1,'ITALY',100),(2,'ITALY',200),(3,'FRANCE',100), (4,'ITALY',100); CREATE VIEW v1 AS SELECT * FROM t1; SELECT code, COUNT(DISTINCT country) FROM t1 GROUP BY code ORDER BY MAX(id); code COUNT(DISTINCT country) 200 1 100 2 SELECT code, COUNT(DISTINCT country) FROM v1 GROUP BY code ORDER BY MAX(id); code COUNT(DISTINCT country) 200 1 100 2 DROP VIEW v1; DROP TABLE t1; End of 5.0 tests. mysql-test/t/view.test +20 −0 Original line number Diff line number Diff line Loading @@ -3038,4 +3038,24 @@ explain extended select * from v1 order by f1; drop view v1; drop table t1; # # Bug#26209: queries with GROUP BY and ORDER BY using views # CREATE TABLE t1 ( id int(11) NOT NULL PRIMARY KEY, country varchar(32), code int(11) default NULL ); INSERT INTO t1 VALUES (1,'ITALY',100),(2,'ITALY',200),(3,'FRANCE',100), (4,'ITALY',100); CREATE VIEW v1 AS SELECT * FROM t1; SELECT code, COUNT(DISTINCT country) FROM t1 GROUP BY code ORDER BY MAX(id); SELECT code, COUNT(DISTINCT country) FROM v1 GROUP BY code ORDER BY MAX(id); DROP VIEW v1; DROP TABLE t1; --echo End of 5.0 tests. sql/sql_select.cc +8 −8 Original line number Diff line number Diff line Loading @@ -12744,15 +12744,15 @@ SORT_FIELD *make_unireg_sortorder(ORDER *order, uint *length, for (;order;order=order->next,pos++) { Item *item= order->item[0]->real_item(); pos->field= 0; pos->item= 0; if (order->item[0]->type() == Item::FIELD_ITEM) pos->field= ((Item_field*) (*order->item))->field; else if (order->item[0]->type() == Item::SUM_FUNC_ITEM && !order->item[0]->const_item()) pos->field= ((Item_sum*) order->item[0])->get_tmp_table_field(); else if (order->item[0]->type() == Item::COPY_STR_ITEM) if (item->type() == Item::FIELD_ITEM) pos->field= ((Item_field*) item)->field; else if (item->type() == Item::SUM_FUNC_ITEM && !item->const_item()) pos->field= ((Item_sum*) item)->get_tmp_table_field(); else if (item->type() == Item::COPY_STR_ITEM) { // Blob patch pos->item= ((Item_copy_string*) (*order->item))->item; pos->item= ((Item_copy_string*) item)->item; } else pos->item= *order->item; Loading Loading
mysql-test/r/view.result +18 −0 Original line number Diff line number Diff line Loading @@ -3117,4 +3117,22 @@ Warnings: Note 1003 select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2` from `test`.`t1` order by `test`.`t1`.`f1`,`test`.`t1`.`f2` drop view v1; drop table t1; CREATE TABLE t1 ( id int(11) NOT NULL PRIMARY KEY, country varchar(32), code int(11) default NULL ); INSERT INTO t1 VALUES (1,'ITALY',100),(2,'ITALY',200),(3,'FRANCE',100), (4,'ITALY',100); CREATE VIEW v1 AS SELECT * FROM t1; SELECT code, COUNT(DISTINCT country) FROM t1 GROUP BY code ORDER BY MAX(id); code COUNT(DISTINCT country) 200 1 100 2 SELECT code, COUNT(DISTINCT country) FROM v1 GROUP BY code ORDER BY MAX(id); code COUNT(DISTINCT country) 200 1 100 2 DROP VIEW v1; DROP TABLE t1; End of 5.0 tests.
mysql-test/t/view.test +20 −0 Original line number Diff line number Diff line Loading @@ -3038,4 +3038,24 @@ explain extended select * from v1 order by f1; drop view v1; drop table t1; # # Bug#26209: queries with GROUP BY and ORDER BY using views # CREATE TABLE t1 ( id int(11) NOT NULL PRIMARY KEY, country varchar(32), code int(11) default NULL ); INSERT INTO t1 VALUES (1,'ITALY',100),(2,'ITALY',200),(3,'FRANCE',100), (4,'ITALY',100); CREATE VIEW v1 AS SELECT * FROM t1; SELECT code, COUNT(DISTINCT country) FROM t1 GROUP BY code ORDER BY MAX(id); SELECT code, COUNT(DISTINCT country) FROM v1 GROUP BY code ORDER BY MAX(id); DROP VIEW v1; DROP TABLE t1; --echo End of 5.0 tests.
sql/sql_select.cc +8 −8 Original line number Diff line number Diff line Loading @@ -12744,15 +12744,15 @@ SORT_FIELD *make_unireg_sortorder(ORDER *order, uint *length, for (;order;order=order->next,pos++) { Item *item= order->item[0]->real_item(); pos->field= 0; pos->item= 0; if (order->item[0]->type() == Item::FIELD_ITEM) pos->field= ((Item_field*) (*order->item))->field; else if (order->item[0]->type() == Item::SUM_FUNC_ITEM && !order->item[0]->const_item()) pos->field= ((Item_sum*) order->item[0])->get_tmp_table_field(); else if (order->item[0]->type() == Item::COPY_STR_ITEM) if (item->type() == Item::FIELD_ITEM) pos->field= ((Item_field*) item)->field; else if (item->type() == Item::SUM_FUNC_ITEM && !item->const_item()) pos->field= ((Item_sum*) item)->get_tmp_table_field(); else if (item->type() == Item::COPY_STR_ITEM) { // Blob patch pos->item= ((Item_copy_string*) (*order->item))->item; pos->item= ((Item_copy_string*) item)->item; } else pos->item= *order->item; Loading