summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <evgen@moonbone.local>2005-10-12 03:32:14 +0400
committerunknown <evgen@moonbone.local>2005-10-12 03:32:14 +0400
commit0654c0146cbeee5ce9d3a0df8e5ae7f8c2987b4a (patch)
treea09394ef99d7c7d90d08beb454232ef5e10cce48
parenteb6ad8a75487cbe5df48413c2e5e4b7cfc3a2237 (diff)
parent76235f4f9f5c4e4d36eb1cc4e32f387cd41f1654 (diff)
downloadmariadb-git-0654c0146cbeee5ce9d3a0df8e5ae7f8c2987b4a.tar.gz
Manual merge, fix for bug #7672
mysql-test/r/select.result: Manual merge mysql-test/t/select.test: Manual merge sql/item.cc: Manual merge sql/sql_lex.cc: Manual merge sql/sql_lex.h: Manual merge sql/sql_select.cc: Manual merge
-rw-r--r--mysql-test/r/select.result10
-rw-r--r--mysql-test/t/select.test9
-rw-r--r--sql/item.cc10
-rw-r--r--sql/sql_lex.cc1
-rw-r--r--sql/sql_lex.h1
5 files changed, 31 insertions, 0 deletions
diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result
index 993fe7d22f1..c2545ff1080 100644
--- a/mysql-test/r/select.result
+++ b/mysql-test/r/select.result
@@ -2617,3 +2617,13 @@ select found_rows();
found_rows()
1
DROP TABLE t1;
+CREATE TABLE t1 (a INT, b INT);
+(SELECT a, b AS c FROM t1) ORDER BY c+1;
+a c
+(SELECT a, b AS c FROM t1) ORDER BY b+1;
+a c
+SELECT a, b AS c FROM t1 ORDER BY c+1;
+a c
+SELECT a, b AS c FROM t1 ORDER BY b+1;
+a c
+drop table t1;
diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test
index b51ea89c7dd..a3a0faac1aa 100644
--- a/mysql-test/t/select.test
+++ b/mysql-test/t/select.test
@@ -2053,6 +2053,7 @@ AND FK_firma_id = 2;
drop table t1;
#
+#
# Test for Bug#8009, SELECT failed on bigint unsigned when using HEX
#
@@ -2165,3 +2166,11 @@ select found_rows();
DROP TABLE t1;
# End of 4.1 tests
+# Bug 7672 Unknown column error in order clause
+#
+CREATE TABLE t1 (a INT, b INT);
+(SELECT a, b AS c FROM t1) ORDER BY c+1;
+(SELECT a, b AS c FROM t1) ORDER BY b+1;
+SELECT a, b AS c FROM t1 ORDER BY c+1;
+SELECT a, b AS c FROM t1 ORDER BY b+1;
+drop table t1;
diff --git a/sql/item.cc b/sql/item.cc
index 010189c321c..3c3a6d273fe 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -1760,6 +1760,16 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
if ((tmp= find_field_in_tables(thd, this, tables, &where, 0)) ==
not_found_field)
{
+ if (thd->lex.select_lex.is_item_list_lookup)
+ {
+ Item** res= find_item_in_list(this, thd->lex.select_lex.item_list);
+ if (res && *res && (*res)->type() == Item::FIELD_ITEM)
+ {
+ set_field((*((Item_field**)res))->field);
+ return 0;
+ }
+ }
+
/*
We can't find table field in table list of current select,
consequently we have to find it in outer subselect(s).
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 8636b6542fc..47de2ff36c7 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -160,6 +160,7 @@ void lex_start(THD *thd, uchar *buf,uint length)
lex->duplicates= DUP_ERROR;
lex->ignore= 0;
lex->proc_list.first= 0;
+ lex->select_lex.is_item_list_lookup= 0;
}
void lex_end(LEX *lex)
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 8d919f12563..47908ba8685 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -426,6 +426,7 @@ public:
List<Item> item_list; /* list of fields & expressions */
List<String> interval_list, use_index, *use_index_ptr,
ignore_index, *ignore_index_ptr;
+ bool is_item_list_lookup;
/*
Usualy it is pointer to ftfunc_list_alloc, but in union used to create fake
select_lex for calling mysql_select under results of union