diff --git a/mysql-test/main/path_embed_func.result b/mysql-test/main/path_embed_func.result index 20b28c5a389..fbe13ed731e 100644 --- a/mysql-test/main/path_embed_func.result +++ b/mysql-test/main/path_embed_func.result @@ -29,8 +29,8 @@ BEGIN RETURN func2(); END; $$ -SELECT func(); -func() +SELECT test.func(); +test.func() test2.func2 SET PATH 'test3'; SELECT test.func(); @@ -47,8 +47,8 @@ BEGIN RETURN CONCAT(func2(), '+', func2()); END; $$ -SELECT func(); -func() +SELECT test.func(); +test.func() test2.func2+test2.func2 SET PATH 'test3'; SELECT test.func(); @@ -65,8 +65,8 @@ BEGIN RETURN CONCAT(func2(), '+', func2(), '+', func4()); END; $$ -SELECT func(); -func() +SELECT test.func(); +test.func() test2.func2+test2.func2+test4.func4 SET PATH 'test3'; SELECT test.func(); diff --git a/mysql-test/main/path_embed_func.test b/mysql-test/main/path_embed_func.test index 52565319a27..c20eaf169c7 100644 --- a/mysql-test/main/path_embed_func.test +++ b/mysql-test/main/path_embed_func.test @@ -42,7 +42,7 @@ END; $$ DELIMITER ;$$ -SELECT func(); +SELECT test.func(); SET PATH 'test3'; SELECT test.func(); @@ -61,7 +61,7 @@ END; $$ DELIMITER ;$$ -SELECT func(); +SELECT test.func(); SET PATH 'test3'; SELECT test.func(); @@ -80,7 +80,7 @@ END; $$ DELIMITER ;$$ -SELECT func(); +SELECT test.func(); SET PATH 'test3'; SELECT test.func(); diff --git a/mysql-test/main/path_embed_proc.result b/mysql-test/main/path_embed_proc.result index 9ff201cdd2c..439b1ed38c5 100644 --- a/mysql-test/main/path_embed_proc.result +++ b/mysql-test/main/path_embed_proc.result @@ -29,6 +29,7 @@ BEGIN SELECT func2(); END; $$ +SET PATH 'CURRENT_SCHEMA'; CALL proc; func2() test2.func2 diff --git a/mysql-test/main/path_embed_proc.test b/mysql-test/main/path_embed_proc.test index c3d9c35f2c9..25b3d2c30e0 100644 --- a/mysql-test/main/path_embed_proc.test +++ b/mysql-test/main/path_embed_proc.test @@ -43,6 +43,7 @@ $$ DELIMITER ;$$ +SET PATH 'CURRENT_SCHEMA'; CALL proc; SET PATH 'test3'; CALL test.proc; diff --git a/mysql-test/main/path_embed_view.result b/mysql-test/main/path_embed_view.result index 2570dc9b3c8..7de2ef17498 100644 --- a/mysql-test/main/path_embed_view.result +++ b/mysql-test/main/path_embed_view.result @@ -147,7 +147,7 @@ DROP VIEW v2; # SET PATH 'test4'; CREATE VIEW v2 AS SELECT a, func(a) FROM t1; -ERROR 42000: FUNCTION test.func does not exist +ERROR 42000: FUNCTION func does not exist # # CREATE VIEW using a function that calls another function in the same schema # diff --git a/mysql-test/main/path_resolution.result b/mysql-test/main/path_resolution.result index 2b8ed28279a..1ba83911949 100644 --- a/mysql-test/main/path_resolution.result +++ b/mysql-test/main/path_resolution.result @@ -41,6 +41,10 @@ USE test2; SELECT func(); func() Invoke from Db: test, Rt: func +SET PATH 'sys'; +USE test; +SELECT func(); +ERROR 42000: FUNCTION func does not exist SET @@path = DEFAULT; # # type 1.5 @@ -92,7 +96,7 @@ func() Invoke from Db: test, Rt: func DROP FUNCTION test.func; SELECT func(); -ERROR 42000: FUNCTION test2.func does not exist +ERROR 42000: FUNCTION func does not exist SET @@path = DEFAULT; # # type 1.7 @@ -657,6 +661,10 @@ USE test2; CALL proc; trace: Invoke from Db: test, Rt: proc +SET PATH 'sys'; +USE test; +CALL proc; +ERROR 42000: PROCEDURE proc does not exist SET @@path = DEFAULT; # # type 3.5 @@ -708,7 +716,7 @@ trace: Invoke from Db: test, Rt: proc DROP PROCEDURE test.proc; CALL proc; -ERROR 42000: PROCEDURE test2.proc does not exist +ERROR 42000: PROCEDURE proc does not exist SET @@path = DEFAULT; # # type 3.7 @@ -1346,7 +1354,7 @@ func() Invoke from Db: test, Rt: func DROP FUNCTION test.func; SELECT func(); -ERROR 42000: FUNCTION test2.func does not exist +ERROR 42000: FUNCTION func does not exist SET @@path = DEFAULT; # # type 5.7 @@ -2105,7 +2113,7 @@ Invoke from Db: test, Rt: proc Invoke from Db: test, Rt: proc DROP PROCEDURE test.proc; CALL proc; -ERROR 42000: PROCEDURE test2.proc does not exist +ERROR 42000: PROCEDURE proc does not exist SET @@path = DEFAULT; # # type 7.7 @@ -2757,12 +2765,12 @@ CREATE DATABASE test2; USE test2; SET PATH 'test'; CREATE FUNCTION func2() RETURNS TEXT RETURN func(); -SELECT func2(); -func2() +SELECT test2.func2(); +test2.func2() Invoke from Db: test, Rt: func SET PATH 'test3'; -SELECT func2(); -func2() +SELECT test2.func2(); +test2.func2() Invoke from Db: test, Rt: func DROP FUNCTION test.func; DROP DATABASE test2; @@ -2791,7 +2799,7 @@ USE `"`; CREATE FUNCTION func() RETURNS TEXT RETURN 'Invoke from Db: \", Rt: func'; USE test; SELECT func(); -ERROR 42000: FUNCTION test.func does not exist +ERROR 42000: FUNCTION func does not exist SET PATH '`"`'; SELECT func(); func() diff --git a/mysql-test/main/path_resolution.test b/mysql-test/main/path_resolution.test index 2b8d27268e1..7e019f40241 100644 --- a/mysql-test/main/path_resolution.test +++ b/mysql-test/main/path_resolution.test @@ -90,6 +90,11 @@ SET PATH 'sys,test'; USE test2; SELECT func(); +SET PATH 'sys'; +USE test; +--error ER_SP_DOES_NOT_EXIST +SELECT func(); + # subtest finish, deinit SET @@path = DEFAULT; @@ -857,6 +862,11 @@ SET PATH 'sys,test'; USE test2; CALL proc; +SET PATH 'sys'; +USE test; +--error ER_SP_DOES_NOT_EXIST +CALL proc; + # subtest finish, deinit SET @@path = DEFAULT; @@ -3465,10 +3475,10 @@ CREATE DATABASE test2; USE test2; SET PATH 'test'; CREATE FUNCTION func2() RETURNS TEXT RETURN func(); -SELECT func2(); +SELECT test2.func2(); SET PATH 'test3'; -SELECT func2(); +SELECT test2.func2(); DROP FUNCTION test.func; DROP DATABASE test2; diff --git a/sql/item_create.cc b/sql/item_create.cc index fefb6f3ba9b..b3becabb9e0 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -2887,7 +2887,7 @@ Create_qfunc::create_func(THD *thd, const LEX_CSTRING *name, List *item_list) { Lex_ident_db_normalized db; - if (thd->lex->sphead || thd->db.str) + if (thd->lex->sphead) { db= thd->lex->copy_db_normalized(); if (!db.str) diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index e5d70dab569..60e96c4fe20 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -7936,7 +7936,7 @@ sp_name *LEX::make_sp_name(THD *thd, const Lex_ident_sys_st &name, bool with_db) Lex_ident_db_normalized db; if (Lex_ident_routine::check_name_with_error(name)) return NULL; - if (with_db || thd->lex->sphead || thd->db.str) + if (with_db || thd->lex->sphead) if (!(db= copy_db_normalized()).str) return NULL; return new (thd->mem_root) sp_name(db, name, false); diff --git a/sql/sql_path.cc b/sql/sql_path.cc index dce7b7c024b..982fbffaf98 100644 --- a/sql/sql_path.cc +++ b/sql/sql_path.cc @@ -130,17 +130,21 @@ bool Sql_path::resolve(THD *thd, sp_head *caller, sp_name *name, } } - // If PATH contains only CURRENT_SCHEMA (default), skip PATH resolution - // to avoid extra table operations that affect performance - if (!name->m_explicit_name && m_count == 1 && is_cur_schema(0)) - return false; - bool resolved= false; for (size_t i= 0; i < m_count; i++) { Lex_ident_db schema; if (is_cur_schema(i)) { + // If PATH contains only CURRENT_SCHEMA (default), skip PATH resolution + // to avoid extra table operations that affect performance + if (m_count== 1 && !name->m_explicit_name) + { + if (!name->m_db.str && thd->db.str) + name->m_db= thd->copy_db_normalized(); + return false; + } + schema= resolve_current_schema(thd, caller, i); if (!schema.str) continue; // CURRENT_SCHEMA resolution failed, skip this entry