[Commits] dee4b76f607: MDEV-18605: Loss of column aliases by using view and group
revision-id: dee4b76f607ca4ce6bec6338f1a29f742dd64601 (mariadb-10.3.12-66-gdee4b76f607) parent(s): 09bd2138522787a4e0b015695c462903f4a9e728 author: Oleksandr Byelkin committer: Oleksandr Byelkin timestamp: 2019-02-25 15:57:08 +0100 message: MDEV-18605: Loss of column aliases by using view and group Preserv column name with copy fields even if it is function and Co. --- mysql-test/main/view.result | 22 ++++++++++++++++++++++ mysql-test/main/view.test | 23 +++++++++++++++++++++++ sql/sql_select.cc | 2 ++ 3 files changed, 47 insertions(+) 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 @@ -6414,6 +6414,29 @@ drop table t1; --error ER_PARSE_ERROR 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
participants (1)
-
Oleksandr Byelkin