Commit f54827e5 authored by ram@gw.mysql.r18.ru's avatar ram@gw.mysql.r18.ru

Fix for the bug #3118: Subquery and order by

parent 0be2ef68
...@@ -1624,3 +1624,11 @@ select 2 in (select * from t1); ...@@ -1624,3 +1624,11 @@ select 2 in (select * from t1);
1 1
SET SQL_SELECT_LIMIT=default; SET SQL_SELECT_LIMIT=default;
drop table t1; drop table t1;
CREATE TABLE t1 (a int, b int, INDEX (a));
INSERT INTO t1 VALUES (1, 1), (1, 2), (1, 3);
SELECT * FROM t1 WHERE a = (SELECT MAX(a) FROM t1 WHERE a = 1) ORDER BY b;
a b
1 1
1 2
1 3
DROP TABLE t1;
...@@ -1066,3 +1066,11 @@ select 2 in (select * from t1); ...@@ -1066,3 +1066,11 @@ select 2 in (select * from t1);
SET SQL_SELECT_LIMIT=default; SET SQL_SELECT_LIMIT=default;
drop table t1; drop table t1;
#
# Bug #3118: subselect + order by
#
CREATE TABLE t1 (a int, b int, INDEX (a));
INSERT INTO t1 VALUES (1, 1), (1, 2), (1, 3);
SELECT * FROM t1 WHERE a = (SELECT MAX(a) FROM t1 WHERE a = 1) ORDER BY b;
DROP TABLE t1;
...@@ -428,8 +428,10 @@ class Item_uint :public Item_int ...@@ -428,8 +428,10 @@ class Item_uint :public Item_int
{ {
public: public:
Item_uint(const char *str_arg, uint length) : Item_uint(const char *str_arg, uint length) :
Item_int(str_arg, (longlong) strtoull(str_arg,(char**) 0,10), length) {} Item_int(str_arg, (longlong) strtoull(str_arg,(char**) 0,10), length)
Item_uint(uint32 i) :Item_int((longlong) i, 10) {} { fixed= 0; }
Item_uint(uint32 i) :Item_int((longlong) i, 10)
{ fixed= 0; }
double val() { return ulonglong2double((ulonglong)value); } double val() { return ulonglong2double((ulonglong)value); }
String *val_str(String*); String *val_str(String*);
Item *new_item() { return new Item_uint(name,max_length); } Item *new_item() { return new Item_uint(name,max_length); }
......
...@@ -205,7 +205,7 @@ Item_func::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) ...@@ -205,7 +205,7 @@ Item_func::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
{ {
Item *item; Item *item;
/* We can't yet set item to *arg as fix_fields may change *arg */ /* We can't yet set item to *arg as fix_fields may change *arg */
if ((*arg)->fix_fields(thd, tables, arg) || if ((!(*arg)->fixed && (*arg)->fix_fields(thd, tables, arg)) ||
(*arg)->check_cols(allowed_arg_cols)) (*arg)->check_cols(allowed_arg_cols))
return 1; /* purecov: inspected */ return 1; /* purecov: inspected */
item= *arg; item= *arg;
......
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