summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/subselect.result8
-rw-r--r--mysql-test/t/subselect.test8
-rw-r--r--sql/item.h6
-rw-r--r--sql/item_func.cc2
4 files changed, 21 insertions, 3 deletions
diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result
index 03bb588fec9..c3d774c2d6e 100644
--- a/mysql-test/r/subselect.result
+++ b/mysql-test/r/subselect.result
@@ -1624,3 +1624,11 @@ select 2 in (select * from t1);
1
SET SQL_SELECT_LIMIT=default;
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;
diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test
index 1a33890360d..6d5b463cfce 100644
--- a/mysql-test/t/subselect.test
+++ b/mysql-test/t/subselect.test
@@ -1066,3 +1066,11 @@ select 2 in (select * from t1);
SET SQL_SELECT_LIMIT=default;
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;
diff --git a/sql/item.h b/sql/item.h
index 727132916f0..31641d42455 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -428,8 +428,10 @@ class Item_uint :public Item_int
{
public:
Item_uint(const char *str_arg, uint length) :
- Item_int(str_arg, (longlong) strtoull(str_arg,(char**) 0,10), length) {}
- Item_uint(uint32 i) :Item_int((longlong) i, 10) {}
+ Item_int(str_arg, (longlong) strtoull(str_arg,(char**) 0,10), length)
+ { fixed= 0; }
+ Item_uint(uint32 i) :Item_int((longlong) i, 10)
+ { fixed= 0; }
double val() { return ulonglong2double((ulonglong)value); }
String *val_str(String*);
Item *new_item() { return new Item_uint(name,max_length); }
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 0327204dbfd..d5e94c7bd35 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -205,7 +205,7 @@ Item_func::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
{
Item *item;
/* 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))
return 1; /* purecov: inspected */
item= *arg;