summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbell@sanja.is.com.ua <>2004-08-31 11:58:45 +0300
committerbell@sanja.is.com.ua <>2004-08-31 11:58:45 +0300
commit771c2998edf3a954c037a1fa262e0bd29ed8034e (patch)
tree093226f954ab64443f59cb0f9061b853763aa75a
parent392c306969d8d07b9d3f5d0f1a77d531752f7371 (diff)
downloadmariadb-git-771c2998edf3a954c037a1fa262e0bd29ed8034e.tar.gz
ORDER clause printing fixed (BUG#5156)
-rw-r--r--mysql-test/r/subselect.result4
-rw-r--r--mysql-test/r/view.result9
-rw-r--r--mysql-test/t/view.test10
-rw-r--r--sql/sql_lex.cc9
-rw-r--r--sql/sql_parse.cc1
-rw-r--r--sql/sql_select.cc4
-rw-r--r--sql/table.h3
7 files changed, 36 insertions, 4 deletions
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result
index 80dd5c4077a..cdde932f851 100644
--- a/mysql-test/r/subselect.result
+++ b/mysql-test/r/subselect.result
@@ -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
NULL UNION RESULT <union1,3> ALL NULL NULL NULL NULL NULL
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 a from t3 where a<t2.a*4 order by 1 desc limit 1) a
3 1
@@ -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
2 SUBQUERY t3 ALL NULL NULL NULL NULL 3 Using where; Using filesort
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);
a
2
diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result
index 14df4f1846d..8ed85e611a6 100644
--- a/mysql-test/r/view.result
+++ b/mysql-test/r/view.result
@@ -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`
drop view v2;
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;
diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test
index d4209cc3cb8..3bb995f8022 100644
--- a/mysql-test/t/view.test
+++ b/mysql-test/t/view.test
@@ -1135,3 +1135,13 @@ show create view v2;
show create view v2;
drop view v2;
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;
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 31c175fee88..dc69a41b090 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -1470,7 +1470,14 @@ void st_select_lex::print_order(String *str, ORDER *order)
{
for (; order; order= order->next)
{
- (*order->item)->print(str);
+ if (order->counter_used)
+ {
+ char buffer[20];
+ my_snprintf(buffer, 20, "%u", order->counter);
+ str->append(buffer);
+ }
+ else
+ (*order->item)->print(str);
if (!order->asc)
str->append(" desc", 5);
if (order->next)
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 3abb2b957bc..54156459f86 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -4935,6 +4935,7 @@ bool add_to_list(THD *thd, SQL_LIST &list,Item *item,bool asc)
order->asc = asc;
order->free_me=0;
order->used=0;
+ order->counter_used= 0;
list.link_in_list((byte*) order,(byte**) &order->next);
DBUG_RETURN(0);
}
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 1768f332fd3..3ecda7284c8 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -10066,8 +10066,10 @@ find_order_in_list(THD *thd, Item **ref_pointer_array,
thd->where);
return 1;
}
- order->item= ref_pointer_array + count-1;
+ order->item= ref_pointer_array + count - 1;
order->in_field_list= 1;
+ order->counter= count;
+ order->counter_used= 1;
return 0;
}
uint counter;
diff --git a/sql/table.h b/sql/table.h
index dd41ab79b7b..68c7febb5b6 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -29,9 +29,12 @@ typedef struct st_order {
Item **item; /* Point at item in select fields */
Item *item_ptr; /* Storage for initial item */
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 free_me; /* true if item isn't shared */
bool in_field_list; /* true if in select field list */
+ bool counter_used; /* parapeter was counter of columns */
Field *field; /* If tmp-table group */
char *buff; /* If tmp-table group */
table_map used,depend_map;