Skip to content

Commit

Permalink
MDEV-18605: Loss of column aliases by using view and group
Browse files Browse the repository at this point in the history
Preserv column name with copy fields even if it is function and Co.
  • Loading branch information
sanja-byelkin committed Feb 26, 2019
1 parent 50b3632 commit 82da985
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
22 changes: 22 additions & 0 deletions mysql-test/main/view.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
23 changes: 23 additions & 0 deletions mysql-test/main/view.test
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
2 changes: 2 additions & 0 deletions sql/sql_select.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 82da985

Please sign in to comment.