diff options
author | unknown <timour@mysql.com> | 2005-11-11 12:10:19 +0200 |
---|---|---|
committer | unknown <timour@mysql.com> | 2005-11-11 12:10:19 +0200 |
commit | b10c7d60bd46135760c59291415c49db6e8d8f71 (patch) | |
tree | a995862fd0f2b1724515d8a6ea8932c6df25abc8 | |
parent | 534275921e9f20bd071a3514b28ff795be04a4e5 (diff) | |
parent | 26cce41b72270a335de889badf8e26951d7f9b8c (diff) | |
download | mariadb-git-b10c7d60bd46135760c59291415c49db6e8d8f71.tar.gz |
Merge mysql.com:/home/timka/mysql/src/5.0-virgin
into mysql.com:/home/timka/mysql/src/5.0-bug-14662
-rw-r--r-- | mysql-test/r/select.result | 42 | ||||
-rw-r--r-- | mysql-test/t/select.test | 20 | ||||
-rw-r--r-- | sql/item.cc | 31 |
3 files changed, 82 insertions, 11 deletions
diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 318cf8e7b65..8a126b7ddfb 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -3241,3 +3241,45 @@ f1 f2 Warnings: Warning 1292 Incorrect date value: '2005-09-3a' for column 'f2' at row 1 drop table t1; +create table t1 (f1 int, f2 int); +insert into t1 values (1, 30), (2, 20), (3, 10); +create algorithm=merge view v1 as select f1, f2 from t1; +create algorithm=merge view v2 (f2, f1) as select f1, f2 from t1; +create algorithm=merge view v3 as select t1.f1 as f2, t1.f2 as f1 from t1; +select t1.f1 as x1, f1 from t1 order by t1.f1; +x1 f1 +1 1 +2 2 +3 3 +select v1.f1 as x1, f1 from v1 order by v1.f1; +x1 f1 +1 1 +2 2 +3 3 +select v2.f1 as x1, f1 from v2 order by v2.f1; +x1 f1 +10 10 +20 20 +30 30 +select v3.f1 as x1, f1 from v3 order by v3.f1; +x1 f1 +10 10 +20 20 +30 30 +select f1, f2, v1.f1 as x1 from v1 order by v1.f1; +f1 f2 x1 +1 30 1 +2 20 2 +3 10 3 +select f1, f2, v2.f1 as x1 from v2 order by v2.f1; +f1 f2 x1 +10 3 10 +20 2 20 +30 1 30 +select f1, f2, v3.f1 as x1 from v3 order by v3.f1; +f1 f2 x1 +10 3 10 +20 2 20 +30 1 30 +drop table t1; +drop view v1, v2, v3; diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index e7e6d899a66..33a3ff578f8 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -2729,3 +2729,23 @@ select * from t1 where f2 >= '2005-09-3a'; select * from t1 where f2 <= '2005-09-31'; select * from t1 where f2 <= '2005-09-3a'; drop table t1; + +# +# Bug ##14662 ORDER BY on column of a view, with an alias of the same +# column causes ambiguous +# + +create table t1 (f1 int, f2 int); +insert into t1 values (1, 30), (2, 20), (3, 10); +create algorithm=merge view v1 as select f1, f2 from t1; +create algorithm=merge view v2 (f2, f1) as select f1, f2 from t1; +create algorithm=merge view v3 as select t1.f1 as f2, t1.f2 as f1 from t1; +select t1.f1 as x1, f1 from t1 order by t1.f1; +select v1.f1 as x1, f1 from v1 order by v1.f1; +select v2.f1 as x1, f1 from v2 order by v2.f1; +select v3.f1 as x1, f1 from v3 order by v3.f1; +select f1, f2, v1.f1 as x1 from v1 order by v1.f1; +select f1, f2, v2.f1 as x1 from v2 order by v2.f1; +select f1, f2, v3.f1 as x1 from v3 order by v3.f1; +drop table t1; +drop view v1, v2, v3; diff --git a/sql/item.cc b/sql/item.cc index 1850b7d05c3..1767f9d97c1 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -4938,8 +4938,7 @@ bool Item_direct_view_ref::fix_fields(THD *thd, Item **reference) } /* - Compare view field's name with item's name before call to referenced - item's eq() + Compare two view column references for equality. SYNOPSIS Item_direct_view_ref::eq() @@ -4947,12 +4946,13 @@ bool Item_direct_view_ref::fix_fields(THD *thd, Item **reference) binary_cmp make binary comparison DESCRIPTION - Consider queries: - create view v1 as select t1.f1 as f2, t1.f2 as f1 from t1; - select * from v1 order by f1; - In order to choose right field for sorting we need to compare - given item's name (f1) to view field's name prior to calling - referenced item's eq(). + A view column reference is considered equal to another column + reference if the second one is a view column and if both column + references point to the same field. For views 'same field' means + the same Item_field object in the view translation table, where + the view translation table contains all result columns of the + view. This definition ensures that view columns are resolved + in the same manner as table columns. RETURN TRUE Referenced item is equal to given item @@ -4962,9 +4962,18 @@ bool Item_direct_view_ref::fix_fields(THD *thd, Item **reference) bool Item_direct_view_ref::eq(const Item *item, bool binary_cmp) const { - Item *it= ((Item *) item)->real_item(); - return (!it->name || !my_strcasecmp(system_charset_info, it->name, - field_name)) && ref && (*ref)->real_item()->eq(it, binary_cmp); + if (item->type() == REF_ITEM) + { + Item_ref *item_ref= (Item_ref*) item; + if (item_ref->ref_type() == VIEW_REF) + { + Item *item_ref_ref= *(item_ref->ref); + DBUG_ASSERT((*ref)->type() == FIELD_ITEM && + (item_ref_ref->type() == FIELD_ITEM)); + return (*ref == item_ref_ref); + } + } + return FALSE; } void Item_null_helper::print(String *str) |