Skip to content

MDEV-34817: Performance schema is not cleared of removed package routines#4941

Open
kjarir wants to merge 1 commit intoMariaDB:10.11from
kjarir:MDEV-34817-fix-test-order
Open

MDEV-34817: Performance schema is not cleared of removed package routines#4941
kjarir wants to merge 1 commit intoMariaDB:10.11from
kjarir:MDEV-34817-fix-test-order

Conversation

@kjarir
Copy link
Copy Markdown
Contributor

@kjarir kjarir commented Apr 14, 2026

Problem

When DROP DATABASE or DROP PACKAGE BODY is executed, sp_drop_db_routines() was not calling MYSQL_DROP_SP for Oracle-style package body sub-routines. This caused stale ghost rows to remain in events_statements_summary_by_program, making the MTR test perfschema.lowercase_fs_off fail non-deterministically when run after compat/oracle.sp-package.

Fix

  1. In sp_drop_routine_internal: iterate sub-routines and call MYSQL_DROP_SP before removing the package from cache.
  2. In sp_drop_db_routines: use the thread's package body cache to identify and clear sub-routines when a package body is dropped during DROP DATABASE.

Testing

  • Added regression test: perfschema.mdev34817
  • Verified with: ./mtr --no-reorder compat/oracle.sp-package perfschema.lowercase_fs_off --repeat=5
  • Full perfschema suite passes

References

Closes MDEV-34817
Closes MDEV-35282

@kjarir kjarir force-pushed the MDEV-34817-fix-test-order branch from f8f310c to 4b18863 Compare April 14, 2026 17:59
@kjarir kjarir changed the title MDEV-34817: Fix Performance Schema not clearing package sub-routine stats on DROP DATABASE/DROP PACKAGE BODY MDEV-34817: perfschema.lowercase_fs_off fails on buildbot Apr 14, 2026
@grooverdan grooverdan self-assigned this Apr 15, 2026
@kjarir kjarir force-pushed the MDEV-34817-fix-test-order branch 3 times, most recently from a85b8f2 to 840d71d Compare April 15, 2026 14:50
@grooverdan grooverdan changed the title MDEV-34817: perfschema.lowercase_fs_off fails on buildbot MDEV-34817: Performance schema is not cleared of removed package routines Apr 15, 2026
Copy link
Copy Markdown
Member

@grooverdan grooverdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As 10.11 is affected too, sorry it wasn't obvious on the bug, back port this to there. Note a few variable constructs are different, but the compiler will find them.

There's a test case for DROP DATABASE, but as your implementation highlights, DROP PACKAGE/ DROP PACKAGE BODY are also affected. Just testing one of these is sufficient as both end up in sp_drop_routine_internal.

Lastly, the improved commit message header is better than the previous MDEV title. But I think the title I rename this PR is clearer again so please use that. There should be a body in the commit message describing the problem and correction.

Comment thread mysql-test/suite/compat/oracle/t/perfschema.test
Comment thread mysql-test/suite/compat/oracle/t/perfschema.test Outdated
Comment thread sql/sp.cc
Comment thread sql/sp.cc Outdated
@grooverdan grooverdan added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Apr 15, 2026
@kjarir
Copy link
Copy Markdown
Contributor Author

kjarir commented Apr 16, 2026

Thanks for the detailed review @grooverdan. Working through all the points now, will push an updated version shortly with the static helper, improved test formatting, DROP PACKAGE test case, and updated commit message.

@kjarir kjarir force-pushed the MDEV-34817-fix-test-order branch 2 times, most recently from 140e66f to a2fa6a1 Compare April 16, 2026 04:01
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 16, 2026

CLA assistant check
All committers have signed the CLA.

@kjarir kjarir force-pushed the MDEV-34817-fix-test-order branch 2 times, most recently from 4678182 to d43140a Compare April 16, 2026 06:36
@grooverdan grooverdan changed the base branch from 11.8 to 10.11 April 16, 2026 06:41
@grooverdan grooverdan self-requested a review April 16, 2026 07:13
Copy link
Copy Markdown
Member

@grooverdan grooverdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its currently failing on embedded tests.

--- /home/buildbot/amd64-debian-11-debug-ps-embedded/build/mysql-test/suite/compat/oracle/r/perfschema.result	2026-04-16 06:40:34.000000000 +0000
+++ /home/buildbot/amd64-debian-11-debug-ps-embedded/build/mysql-test/suite/compat/oracle/r/perfschema.reject	2026-04-16 06:45:26.326364209 +0000
@@ -40,7 +40,6 @@
 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;

I suspect that a --source include/not_embedded.inc might be needed as many of mysql-test/suite/compat/oracle/t around stored procedures already do. I'm going to leave this as a call to the second reviewer so no need to address this immediately.

Comment thread sql/sp.cc Outdated
Comment on lines 1091 to 1105
@@ -1104,6 +1104,35 @@ sp_returns_type(THD *thd, String &result, const sp_head *sp)
used to indicate about errors.
*/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is description of function Sp_handler::sp_drop_routine_internal, please move this to its correct place, right above the function body.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks! I'll move the description block to its correct place right above the Sp_handler::sp_drop_routine_internal function body.

Comment thread sql/sp.cc Outdated
@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,
Copy link
Copy Markdown
Contributor

@raghunandanbhat raghunandanbhat Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sp_cache is thread-local. what should happen in this scenario?

  • in connection-1, I create a db & pkg and call - call db.pkg.p1()
  • in connection-2, I drop the db. sp_psi_drop_package_routines finds nothing in the sp_cache.
  • switch to connection-1 and query perfschema, the row is still there.
connect (con1, localhost, root,,);
connect (con2, localhost, root,,);

connection con1;

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();

connection con2;
--echo # Testing DROP DATABASE
DROP DATABASE mdev34817_db;

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

out-

 CALL mdev34817_db.pkg1.p1();
+connection con2;
 # Testing DROP DATABASE
 DROP DATABASE mdev34817_db;
+connection con1;
 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
+PROCEDURE	mdev34817_db	pkg1.p1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right since sp_cache is thread-local, if the dropping connection never loaded the package, the cache will be empty and PSI cleanup will be silently skipped. The fix needs to read the sub-routine names directly from mysql.proc instead of relying on the cache, similar to how sp_drop_db_routines already iterates the table. I'll rework the approach accordingly.

@@ -0,0 +1,66 @@
--echo #
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend adding these two-

--source include/not_embedded.inc
--source include/have_perfschema.inc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I'll add both include/not_embedded.inc and include/have_perfschema.inc at the top of the test.

@kjarir kjarir force-pushed the MDEV-34817-fix-test-order branch from d43140a to 2979f0f Compare April 17, 2026 13:56
@kjarir kjarir force-pushed the MDEV-34817-fix-test-order branch from 2979f0f to f408493 Compare April 17, 2026 13:59
@kjarir kjarir requested a review from raghunandanbhat April 17, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements.

Development

Successfully merging this pull request may close these issues.

4 participants