diff options
author | evgen@moonbone.local <> | 2005-07-12 23:24:35 +0400 |
---|---|---|
committer | evgen@moonbone.local <> | 2005-07-12 23:24:35 +0400 |
commit | bb1f81607cdacf87cb3b87d6da04b5b01a8e5b50 (patch) | |
tree | 6b6c4daa9cac4f3d04e44c27cda81755e8aa6fee | |
parent | e06e06ffeb8dbcd2737720be9f78c5fe75b9c0f5 (diff) | |
parent | de016ca78a732e65f55e040f12b5461ca2c1d27d (diff) | |
download | mariadb-git-bb1f81607cdacf87cb3b87d6da04b5b01a8e5b50.tar.gz |
Merge
-rw-r--r-- | mysql-test/r/view.result | 9 | ||||
-rw-r--r-- | mysql-test/t/view.test | 9 | ||||
-rw-r--r-- | sql/item.cc | 29 | ||||
-rw-r--r-- | sql/item.h | 1 |
4 files changed, 48 insertions, 0 deletions
diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 3fd85cc883b..f9843d40f07 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -1948,6 +1948,15 @@ s1 s2 DROP PROCEDURE p1; DROP VIEW v1; DROP TABLE t1; +create table t1 (f1 int, f2 int); +create view v1 as select f1 as f3, f2 as f1 from t1; +insert into t1 values (1,3),(2,1),(3,2); +select * from v1 order by f1; +f3 f1 +2 1 +3 2 +1 3 +drop table t1; CREATE TABLE t1 (f1 char) ENGINE = innodb; INSERT INTO t1 VALUES ('A'); CREATE VIEW v1 AS SELECT * FROM t1; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 2ccac059724..6b10edc7abd 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -1790,6 +1790,15 @@ DROP VIEW v1; DROP TABLE t1; # +# Test for bug #11709 View was ordered by wrong column +# +create table t1 (f1 int, f2 int); +create view v1 as select f1 as f3, f2 as f1 from t1; +insert into t1 values (1,3),(2,1),(3,2); +select * from v1 order by f1; +drop table t1; + +# # Test for bug #11771: wrong query_id in SELECT * FROM <view> # diff --git a/sql/item.cc b/sql/item.cc index 4679b62643e..c8d988c0ae9 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -4499,6 +4499,35 @@ bool Item_direct_view_ref::fix_fields(THD *thd, Item **reference) return Item_direct_ref::fix_fields(thd, reference); } +/* + Compare view field's name with item's name before call to referenced + item's eq() + + SYNOPSIS + Item_direct_view_ref::eq() + item item to compare with + 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(). + + RETURN + TRUE Referenced item is equal to given item + FALSE otherwise +*/ + + +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); +} void Item_null_helper::print(String *str) { diff --git a/sql/item.h b/sql/item.h index 12acb8dd28d..8a694a467ae 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1524,6 +1524,7 @@ public: :Item_direct_ref(thd, item) {} bool fix_fields(THD *, Item **); + bool eq(const Item *item, bool binary_cmp) const; }; |