diff options
author | Oleksandr Byelkin <sanja@mariadb.com> | 2019-02-25 15:57:08 +0100 |
---|---|---|
committer | Oleksandr Byelkin <sanja@mariadb.com> | 2019-02-25 15:57:08 +0100 |
commit | dee4b76f607ca4ce6bec6338f1a29f742dd64601 (patch) | |
tree | 09f474950b3315625091b34a5adbdb07c5ef60a8 | |
parent | 09bd2138522787a4e0b015695c462903f4a9e728 (diff) | |
download | mariadb-git-bb-10.3-MDEV-18605.tar.gz |
MDEV-18605: Loss of column aliases by using view and groupbb-10.3-MDEV-18605
Preserv column name with copy fields even if it is function and Co.
-rw-r--r-- | mysql-test/main/view.result | 22 | ||||
-rw-r--r-- | mysql-test/main/view.test | 23 | ||||
-rw-r--r-- | sql/sql_select.cc | 2 |
3 files changed, 47 insertions, 0 deletions
diff --git a/mysql-test/main/view.result b/mysql-test/main/view.result index d97517d5ce7..2629eb46200 100644 --- a/mysql-test/main/view.result +++ b/mysql-test/main/view.result @@ -6705,5 +6705,27 @@ drop table t1; ALTER VIEW IF NOT EXISTS v1 AS SELECT 1; ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'IF NOT EXISTS v1 AS SELECT 1' at line 1 # +# MDEV-18605: Loss of column aliases by using view and group +# +CREATE TABLE t1 (id int, foo int); +CREATE VIEW v1 AS SELECT id, IFNULL(foo,'') AS foo FROM t1; +INSERT INTO t1 (id, foo) VALUES (1,1),(2,2); +SELECT v.id, v.foo AS bar FROM v1 v +WHERE id = 2; +id bar +2 2 +SELECT v.id, v.foo AS bar FROM v1 v +GROUP BY v.id; +id bar +1 1 +2 2 +SELECT v.id, v.foo AS bar FROM v1 v +WHERE id = 2 +GROUP BY v.id; +id bar +2 2 +Drop View v1; +Drop table t1; +# # End of 10.3 tests # diff --git a/mysql-test/main/view.test b/mysql-test/main/view.test index 82ef38f0eb6..643f050cee5 100644 --- a/mysql-test/main/view.test +++ b/mysql-test/main/view.test @@ -6415,5 +6415,28 @@ drop table t1; ALTER VIEW IF NOT EXISTS v1 AS SELECT 1; --echo # +--echo # MDEV-18605: Loss of column aliases by using view and group +--echo # + +CREATE TABLE t1 (id int, foo int); +CREATE VIEW v1 AS SELECT id, IFNULL(foo,'') AS foo FROM t1; + +INSERT INTO t1 (id, foo) VALUES (1,1),(2,2); + +SELECT v.id, v.foo AS bar FROM v1 v + WHERE id = 2; + +SELECT v.id, v.foo AS bar FROM v1 v + GROUP BY v.id; + +SELECT v.id, v.foo AS bar FROM v1 v + WHERE id = 2 + GROUP BY v.id; + +#Cleanup +Drop View v1; +Drop table t1; + +--echo # --echo # End of 10.3 tests --echo # diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 439853c2f66..0bc27f18d47 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -23914,7 +23914,9 @@ setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param, real_pos->type() == Item::COND_ITEM) && !real_pos->with_sum_func) { // Save for send fields + LEX_CSTRING real_name= pos->name; pos= real_pos; + pos->name= real_name; /* TODO: In most cases this result will be sent to the user. This should be changed to use copy_int or copy_real depending |