diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 28162334546..193adac7533 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -1176,3 +1176,10 @@ test.`f``1` () 5 drop view v1; drop function `f``1`; +create function x () returns int return 5; +create view v1 as select x (); +select * from v1; +x () +5 +drop view v1; +drop function x; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 4f5a6f3ddc4..cc659a59f6d 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -1116,3 +1116,12 @@ show create view v1; select * from v1; drop view v1; drop function `f``1`; + +# +# tested problem when function name length close to ALIGN_SIZE +# +create function x () returns int return 5; +create view v1 as select x (); +select * from v1; +drop view v1; +drop function x; diff --git a/sql/item_func.cc b/sql/item_func.cc index f5a9d9ef9bc..b5af98b6caf 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -3271,12 +3271,14 @@ const char * Item_func_sp::func_name() const { THD * thd= current_thd; + /* Calculate length to avoud reallocation of string for sure */ uint len= ((m_name->m_db.length + m_name->m_name.length)*2 + //characters*quoting 2 + // ` and ` 1 + // . - 1); // end of string - String qname(alloc_root(&thd->mem_root, len), len, + 1 + // end of string + ALIGN_SIZE(1)); // to avoid String reallocation + String qname((char *)alloc_root(&thd->mem_root, len), len, system_charset_info); qname.length(0); append_identifier(thd, &qname, m_name->m_db.str, m_name->m_db.length);