Commit 82da9855 authored by Oleksandr Byelkin's avatar Oleksandr Byelkin

MDEV-18605: Loss of column aliases by using view and group

Preserv column name with copy fields even if it is function and Co.
parent 50b3632f
......@@ -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
#
......@@ -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 #
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment