Commit 771c2998 authored by bell@sanja.is.com.ua's avatar bell@sanja.is.com.ua

ORDER clause printing fixed (BUG#5156)

parent 392c3069
...@@ -186,7 +186,7 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -186,7 +186,7 @@ id select_type table type possible_keys key key_len ref rows Extra
4 SUBQUERY t2 ALL NULL NULL NULL NULL 2 4 SUBQUERY t2 ALL NULL NULL NULL NULL 2
NULL UNION RESULT <union1,3> ALL NULL NULL NULL NULL NULL NULL UNION RESULT <union1,3> ALL NULL NULL NULL NULL NULL
Warnings: Warnings:
Note 1003 (select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`b` = (select `test`.`t3`.`a` AS `a` from `test`.`t3` order by `test`.`t3`.`a` desc limit 1))) union (select `test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t4` where (`test`.`t4`.`b` = (select (max(`test`.`t2`.`a`) * 4) AS `max(t2.a)*4` from `test`.`t2`)) order by `test`.`t4`.`a`) Note 1003 (select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`b` = (select `test`.`t3`.`a` AS `a` from `test`.`t3` order by 1 desc limit 1))) union (select `test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t4` where (`test`.`t4`.`b` = (select (max(`test`.`t2`.`a`) * 4) AS `max(t2.a)*4` from `test`.`t2`)) order by `test`.`t4`.`a`)
select (select a from t3 where a<t2.a*4 order by 1 desc limit 1), a from t2; select (select a from t3 where a<t2.a*4 order by 1 desc limit 1), a from t2;
(select a from t3 where a<t2.a*4 order by 1 desc limit 1) a (select a from t3 where a<t2.a*4 order by 1 desc limit 1) a
3 1 3 1
...@@ -202,7 +202,7 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -202,7 +202,7 @@ id select_type table type possible_keys key key_len ref rows Extra
3 DERIVED t2 ALL NULL NULL NULL NULL 2 Using where 3 DERIVED t2 ALL NULL NULL NULL NULL 2 Using where
2 SUBQUERY t3 ALL NULL NULL NULL NULL 3 Using where; Using filesort 2 SUBQUERY t3 ALL NULL NULL NULL NULL 3 Using where; Using filesort
Warnings: Warnings:
Note 1003 select (select `test`.`t3`.`a` AS `a` from `test`.`t3` where (`test`.`t3`.`a` < 8) order by `test`.`t3`.`a` desc limit 1) AS `(select t3.a from t3 where a<8 order by 1 desc limit 1)`,`tt`.`a` AS `a` from (select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`a` > 1)) `tt` Note 1003 select (select `test`.`t3`.`a` AS `a` from `test`.`t3` where (`test`.`t3`.`a` < 8) order by 1 desc limit 1) AS `(select t3.a from t3 where a<8 order by 1 desc limit 1)`,`tt`.`a` AS `a` from (select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`a` > 1)) `tt`
select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3) order by 1 desc limit 1); select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3) order by 1 desc limit 1);
a a
2 2
......
...@@ -1193,3 +1193,12 @@ Table Create Table ...@@ -1193,3 +1193,12 @@ Table Create Table
v2 CREATE VIEW `test`.`v2` AS select (`test`.`t2`.`col1` collate latin1_german1_ci) AS `col1 collate latin1_german1_ci` from `test`.`t2` v2 CREATE VIEW `test`.`v2` AS select (`test`.`t2`.`col1` collate latin1_german1_ci) AS `col1 collate latin1_german1_ci` from `test`.`t2`
drop view v2; drop view v2;
drop table t2; drop table t2;
create table t1 (a int);
insert into t1 values (1), (2);
create view v1 as select 5 from t1 order by 1;
select * from v1;
5
5
5
drop view v1;
drop table t1;
...@@ -1135,3 +1135,13 @@ show create view v2; ...@@ -1135,3 +1135,13 @@ show create view v2;
show create view v2; show create view v2;
drop view v2; drop view v2;
drop table t2; drop table t2;
#
# order by refers on integer field
#
create table t1 (a int);
insert into t1 values (1), (2);
create view v1 as select 5 from t1 order by 1;
select * from v1;
drop view v1;
drop table t1;
...@@ -1470,6 +1470,13 @@ void st_select_lex::print_order(String *str, ORDER *order) ...@@ -1470,6 +1470,13 @@ void st_select_lex::print_order(String *str, ORDER *order)
{ {
for (; order; order= order->next) for (; order; order= order->next)
{ {
if (order->counter_used)
{
char buffer[20];
my_snprintf(buffer, 20, "%u", order->counter);
str->append(buffer);
}
else
(*order->item)->print(str); (*order->item)->print(str);
if (!order->asc) if (!order->asc)
str->append(" desc", 5); str->append(" desc", 5);
......
...@@ -4935,6 +4935,7 @@ bool add_to_list(THD *thd, SQL_LIST &list,Item *item,bool asc) ...@@ -4935,6 +4935,7 @@ bool add_to_list(THD *thd, SQL_LIST &list,Item *item,bool asc)
order->asc = asc; order->asc = asc;
order->free_me=0; order->free_me=0;
order->used=0; order->used=0;
order->counter_used= 0;
list.link_in_list((byte*) order,(byte**) &order->next); list.link_in_list((byte*) order,(byte**) &order->next);
DBUG_RETURN(0); DBUG_RETURN(0);
} }
......
...@@ -10066,8 +10066,10 @@ find_order_in_list(THD *thd, Item **ref_pointer_array, ...@@ -10066,8 +10066,10 @@ find_order_in_list(THD *thd, Item **ref_pointer_array,
thd->where); thd->where);
return 1; return 1;
} }
order->item= ref_pointer_array + count-1; order->item= ref_pointer_array + count - 1;
order->in_field_list= 1; order->in_field_list= 1;
order->counter= count;
order->counter_used= 1;
return 0; return 0;
} }
uint counter; uint counter;
......
...@@ -29,9 +29,12 @@ typedef struct st_order { ...@@ -29,9 +29,12 @@ typedef struct st_order {
Item **item; /* Point at item in select fields */ Item **item; /* Point at item in select fields */
Item *item_ptr; /* Storage for initial item */ Item *item_ptr; /* Storage for initial item */
Item **item_copy; /* For SPs; the original item ptr */ Item **item_copy; /* For SPs; the original item ptr */
int counter; /* position in SELECT list, correct
only if counter_used is true*/
bool asc; /* true if ascending */ bool asc; /* true if ascending */
bool free_me; /* true if item isn't shared */ bool free_me; /* true if item isn't shared */
bool in_field_list; /* true if in select field list */ bool in_field_list; /* true if in select field list */
bool counter_used; /* parapeter was counter of columns */
Field *field; /* If tmp-table group */ Field *field; /* If tmp-table group */
char *buff; /* If tmp-table group */ char *buff; /* If tmp-table group */
table_map used,depend_map; table_map used,depend_map;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment