Commit 754c3f51 authored by unknown's avatar unknown

Bug#30787: Stored function ignores user defined alias.

Simple subselects are pulled into upper selects. This operation substitutes the
pulled subselect for the first item from the select list of the subselect.
If an alias is defined for a subselect it is inherited by the replacement item.
As this is done after fix_fields phase this alias isn't showed if the
replacement item is a stored function. This happens because the Item_func_sp::make_field
function makes send field from its result_field and ignores the defined alias.

Now when an alias is defined the Item_func_sp::make_field function sets it for
the returned field.


mysql-test/t/sp.test:
  Added a test case for the bug#30787: Stored function ignores user defined alias.
mysql-test/r/sp.result:
  Added a test case for the bug#30787: Stored function ignores user defined alias.
sql/item_func.cc:
  Bug#30787: Stored function ignores user defined alias.
  Now when an alias is defined the Item_func_sp::make_field function sets it for
  the returned field.
parent e30a0dda
...@@ -6578,6 +6578,23 @@ DROP PROCEDURE db28318_a.t1; ...@@ -6578,6 +6578,23 @@ DROP PROCEDURE db28318_a.t1;
DROP PROCEDURE db28318_b.t2; DROP PROCEDURE db28318_b.t2;
DROP DATABASE db28318_a; DROP DATABASE db28318_a;
DROP DATABASE db28318_b; DROP DATABASE db28318_b;
#
# Bug#30787: Stored function ignores user defined alias.
#
use test;
drop function if exists func30787;
create table t1(f1 int);
insert into t1 values(1),(2);
create function func30787(p1 int) returns int
begin
return p1;
end |
select (select func30787(f1)) as ttt from t1;
ttt
1
2
drop function func30787;
drop table t1;
# ------------------------------------------------------------------ # ------------------------------------------------------------------
# -- End of 5.0 tests # -- End of 5.0 tests
# ------------------------------------------------------------------ # ------------------------------------------------------------------
...@@ -7699,6 +7699,25 @@ DROP PROCEDURE db28318_b.t2; ...@@ -7699,6 +7699,25 @@ DROP PROCEDURE db28318_b.t2;
DROP DATABASE db28318_a; DROP DATABASE db28318_a;
DROP DATABASE db28318_b; DROP DATABASE db28318_b;
--echo #
--echo # Bug#30787: Stored function ignores user defined alias.
--echo #
use test;
--disable_warnings
drop function if exists func30787;
--enable_warnings
create table t1(f1 int);
insert into t1 values(1),(2);
delimiter |;
create function func30787(p1 int) returns int
begin
return p1;
end |
delimiter ;|
select (select func30787(f1)) as ttt from t1;
drop function func30787;
drop table t1;
--echo # ------------------------------------------------------------------ --echo # ------------------------------------------------------------------
--echo # -- End of 5.0 tests --echo # -- End of 5.0 tests
......
...@@ -5515,6 +5515,8 @@ Item_func_sp::make_field(Send_field *tmp_field) ...@@ -5515,6 +5515,8 @@ Item_func_sp::make_field(Send_field *tmp_field)
DBUG_ENTER("Item_func_sp::make_field"); DBUG_ENTER("Item_func_sp::make_field");
DBUG_ASSERT(sp_result_field); DBUG_ASSERT(sp_result_field);
sp_result_field->make_field(tmp_field); sp_result_field->make_field(tmp_field);
if (name)
tmp_field->col_name= name;
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
......
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