Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions mysql-test/suite/compat/oracle/r/perfschema.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#
# MDEV-34817 Performance schema does not clear package routines
#
SET sql_mode=ORACLE;
CREATE DATABASE mdev34817_db;
CREATE PACKAGE mdev34817_db.pkg1 AS
PROCEDURE p1();
END;
$$
CREATE PACKAGE BODY mdev34817_db.pkg1 AS
PROCEDURE p1() AS
BEGIN
NULL;
END;
END;
$$
CALL mdev34817_db.pkg1.p1();
# Testing DROP DATABASE
DROP DATABASE mdev34817_db;
SELECT object_type, object_schema, object_name
FROM performance_schema.events_statements_summary_by_program
WHERE LOWER(object_schema)='mdev34817_db';
object_type object_schema object_name
# Testing DROP PACKAGE BODY
CREATE DATABASE mdev34817_db;
CREATE PACKAGE mdev34817_db.pkg1 AS
PROCEDURE p1();
END;
$$
CREATE PACKAGE BODY mdev34817_db.pkg1 AS
PROCEDURE p1() AS
BEGIN
NULL;
END;
END;
$$
CALL mdev34817_db.pkg1.p1();
DROP PACKAGE BODY mdev34817_db.pkg1;
SELECT object_type, object_schema, object_name
FROM performance_schema.events_statements_summary_by_program
WHERE LOWER(object_schema)='mdev34817_db';
object_type object_schema object_name
mdev34817_db pkg1
DROP DATABASE mdev34817_db;
#
# End of 10.11 tests
#
66 changes: 66 additions & 0 deletions mysql-test/suite/compat/oracle/t/perfschema.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
--echo #
--echo # MDEV-34817 Performance schema does not clear package routines
Comment thread
grooverdan marked this conversation as resolved.
--echo #

SET sql_mode=ORACLE;
CREATE DATABASE mdev34817_db;

DELIMITER $$;

CREATE PACKAGE mdev34817_db.pkg1 AS
PROCEDURE p1();
END;
$$

CREATE PACKAGE BODY mdev34817_db.pkg1 AS
PROCEDURE p1() AS
BEGIN
NULL;
END;
END;
$$

DELIMITER ;$$

CALL mdev34817_db.pkg1.p1();

--echo # Testing DROP DATABASE
DROP DATABASE mdev34817_db;

SELECT object_type, object_schema, object_name
FROM performance_schema.events_statements_summary_by_program
WHERE LOWER(object_schema)='mdev34817_db';

--echo # Testing DROP PACKAGE BODY
CREATE DATABASE mdev34817_db;

DELIMITER $$;

CREATE PACKAGE mdev34817_db.pkg1 AS
PROCEDURE p1();
END;
$$

CREATE PACKAGE BODY mdev34817_db.pkg1 AS
PROCEDURE p1() AS
BEGIN
NULL;
END;
END;
$$

DELIMITER ;$$

CALL mdev34817_db.pkg1.p1();

DROP PACKAGE BODY mdev34817_db.pkg1;

SELECT object_type, object_schema, object_name
FROM performance_schema.events_statements_summary_by_program
WHERE LOWER(object_schema)='mdev34817_db';

DROP DATABASE mdev34817_db;

--echo #
--echo # End of 10.11 tests
--echo #
44 changes: 43 additions & 1 deletion sql/sp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,35 @@ sp_returns_type(THD *thd, String &result, const sp_head *sp)
used to indicate about errors.
*/

#ifdef HAVE_PSI_SP_INTERFACE
/**
Drop statistics for all package sub-routines from performance schema.
@param spc The cache to look up the package body.
@param name The package body name.
*/
static void sp_psi_drop_package_routines(sp_cache **spc,
const Database_qualified_name *name)
{
sp_head *ph;
if ((ph= sp_cache_lookup(spc, name)))
{
sp_package *pkg= ph->get_package();
if (pkg)
{
List_iterator<LEX> it(pkg->m_routine_implementations);
for (LEX *lex; (lex= it++); )
{
sp_head *sub= lex->sphead;
MYSQL_DROP_SP(sub->m_handler->type(), name->m_db.str,
static_cast<uint>(name->m_db.length),
sub->m_name.str, static_cast<uint>(sub->m_name.length));
}
}
}
}
#endif


int
Sp_handler::sp_drop_routine_internal(THD *thd,
const Database_qualified_name *name,
Expand All @@ -1126,6 +1155,11 @@ Sp_handler::sp_drop_routine_internal(THD *thd,
sp_head *sp;
sp_cache **spc= get_cache(thd);
DBUG_ASSERT(spc);
#ifdef HAVE_PSI_SP_INTERFACE
if (type() == SP_TYPE_PACKAGE_BODY)
sp_psi_drop_package_routines(spc, name);
#endif

if ((sp= sp_cache_lookup(spc, name)))
sp_cache_remove(spc, &sp);
/* Drop statistics for this stored program from performance schema. */
Expand Down Expand Up @@ -1871,10 +1905,18 @@ sp_drop_db_routines(THD *thd, const char *db)
String buf;
// the following assumes MODE_PAD_CHAR_TO_FULL_LENGTH being *unset*
String *name= table->field[MYSQL_PROC_FIELD_NAME]->val_str(&buf);
name->strip_sp();

enum_sp_type sp_type= (enum_sp_type) table->field[MYSQL_PROC_MYSQL_TYPE]->ptr[0];
enum_sp_type sp_type= (enum_sp_type) table->field[MYSQL_PROC_MYSQL_TYPE]->val_int();
/* Drop statistics for this stored program from performance schema. */
MYSQL_DROP_SP(sp_type, db, static_cast<uint>(db_length), name->ptr(), name->length());
if (sp_type == SP_TYPE_PACKAGE_BODY)
{
LEX_CSTRING db_cstr= {db, db_length};
LEX_CSTRING name_cstr= {name->ptr(), name->length()};
sp_name spn(&db_cstr, &name_cstr, true);
sp_psi_drop_package_routines(&thd->sp_package_body_cache, &spn);
}
#endif
}
else
Expand Down