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
361 changes: 361 additions & 0 deletions mysql-test/main/mdev_39993.result

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions mysql-test/main/mdev_39993.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#
# MDEV-39993: mariadb-upgrade drops existing EXECUTE grants on sys stored
# routines during upgrade because sys schema scripts use DROP+CREATE
# instead of CREATE OR REPLACE
#
--source include/have_perfschema.inc

CREATE USER testuser@localhost;

GRANT EXECUTE ON FUNCTION sys.quote_identifier TO testuser@localhost;
GRANT EXECUTE ON PROCEDURE sys.table_exists TO testuser@localhost;

--echo # Grants BEFORE running upgrade
--sorted_result
SHOW GRANTS FOR testuser@localhost;

--echo # Run mariadb-upgrade (re-installs sys schema)
--exec $MYSQL_UPGRADE --force 2>&1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Logging the entire verbose output of mariadb-upgrade makes the test highly fragile and prone to failure. Any future changes to the mysql or sys schemas (such as adding, removing, or renaming tables/views), or running the test in environments with different storage engine configurations (e.g., with or without InnoDB enabled), will cause result mismatches and test failures.

It is highly recommended to wrap the $MYSQL_UPGRADE execution with --disable_result_log and --enable_result_log to suppress this output. The test's correctness is already verified by checking the grants and routine functionality before and after the upgrade.

--disable_result_log
--exec $MYSQL_UPGRADE --force 2>&1
--enable_result_log

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have to agree here. it's a good suggestion.


--echo # Grants AFTER running upgrade (must be preserved)
--sorted_result
SHOW GRANTS FOR testuser@localhost;

--echo # Verify routines still work after replacement
SELECT sys.quote_identifier('test') AS quoted;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is not a valid test IMHO: I'd test it with the actual user that is being created for the test.


--echo # Verify CREATE OR REPLACE works for fresh routine (simulate new install)
DROP FUNCTION IF EXISTS sys.quote_identifier;
--exec $MYSQL_UPGRADE --force 2>&1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Similarly, suppress the verbose output of the second mariadb-upgrade execution to prevent test fragility due to schema or environment differences.

--disable_result_log
--exec $MYSQL_UPGRADE --force 2>&1
--enable_result_log

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

here too.


--echo # Routine recreated successfully
SELECT sys.quote_identifier('test') AS quoted;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is also not what should be tested. Of course the procedure will be recreated. And this is probably tested someplace else already. I'd suggest dropping the whole test part: it doesn't contribute to more coverage IMHO.

Instead you should be testing all of the affected procedures and functions in SYS: there's quite a number of them and you're just testing the one.
I'd add grants to all of the procedures to the test user and verify if all of these survive the upgrade.


# Cleanup
--let $MYSQLD_DATADIR= `select @@datadir`
--remove_file $MYSQLD_DATADIR/mariadb_upgrade_info
DROP USER testuser@localhost;
7 changes: 2 additions & 5 deletions scripts/maria_add_gis_sp.sql.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@ SET sql_mode='';

@ADD_GIS_SP_SET_DELIMITER@

DROP PROCEDURE IF EXISTS AddGeometryColumn;
DROP PROCEDURE IF EXISTS DropGeometryColumn;

CREATE DEFINER=`mariadb.sys`@`localhost` PROCEDURE AddGeometryColumn(catalog varchar(64), t_schema varchar(64),
CREATE OR REPLACE DEFINER=`mariadb.sys`@`localhost` PROCEDURE AddGeometryColumn(catalog varchar(64), t_schema varchar(64),
t_name varchar(64), geometry_column varchar(64), t_srid int) SQL SECURITY INVOKER
begin
set @qwe= concat('ALTER TABLE ', t_schema, '.', t_name, ' ADD ', geometry_column,' GEOMETRY REF_SYSTEM_ID=', t_srid); PREPARE ls from @qwe; execute ls; deallocate prepare ls; end @ADD_GIS_SP_EOL@

CREATE DEFINER=`mariadb.sys`@`localhost` PROCEDURE DropGeometryColumn(catalog varchar(64), t_schema varchar(64),
CREATE OR REPLACE DEFINER=`mariadb.sys`@`localhost` PROCEDURE DropGeometryColumn(catalog varchar(64), t_schema varchar(64),
t_name varchar(64), geometry_column varchar(64)) SQL SECURITY INVOKER
begin
set @qwe= concat('ALTER TABLE ', t_schema, '.', t_name, ' DROP ', geometry_column); PREPARE ls from @qwe; execute ls; deallocate prepare ls; end @ADD_GIS_SP_EOL@
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DROP FUNCTION IF EXISTS extract_schema_from_file_name;

DELIMITER $$

CREATE DEFINER='mariadb.sys'@'localhost' FUNCTION extract_schema_from_file_name (
CREATE OR REPLACE DEFINER='mariadb.sys'@'localhost' FUNCTION extract_schema_from_file_name (
path VARCHAR(512)
)
RETURNS VARCHAR(64)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DROP FUNCTION IF EXISTS extract_table_from_file_name;

DELIMITER $$

CREATE DEFINER='mariadb.sys'@'localhost' FUNCTION extract_table_from_file_name (
CREATE OR REPLACE DEFINER='mariadb.sys'@'localhost' FUNCTION extract_table_from_file_name (
path VARCHAR(512)
)
RETURNS VARCHAR(64)
Expand Down
4 changes: 1 addition & 3 deletions scripts/sys_schema/functions/format_bytes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DROP FUNCTION IF EXISTS format_bytes;

DELIMITER $$

CREATE DEFINER='mariadb.sys'@'localhost' FUNCTION format_bytes (
CREATE OR REPLACE DEFINER='mariadb.sys'@'localhost' FUNCTION format_bytes (
-- We feed in and return TEXT here, as aggregates of
-- bytes can return numbers larger than BIGINT UNSIGNED
bytes TEXT
Expand Down
4 changes: 1 addition & 3 deletions scripts/sys_schema/functions/format_path.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DROP FUNCTION IF EXISTS format_path;

DELIMITER $$

CREATE DEFINER='mariadb.sys'@'localhost' FUNCTION format_path (
CREATE OR REPLACE DEFINER='mariadb.sys'@'localhost' FUNCTION format_path (
in_path VARCHAR(512)
)
RETURNS VARCHAR(512) CHARSET UTF8
Expand Down
4 changes: 1 addition & 3 deletions scripts/sys_schema/functions/format_path_57.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DROP FUNCTION IF EXISTS format_path;

DELIMITER $$

CREATE DEFINER='mariadb.sys'@'localhost' FUNCTION format_path (
CREATE OR REPLACE DEFINER='mariadb.sys'@'localhost' FUNCTION format_path (
in_path VARCHAR(512)
)
RETURNS VARCHAR(512) CHARSET UTF8
Expand Down
4 changes: 1 addition & 3 deletions scripts/sys_schema/functions/format_statement.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DROP FUNCTION IF EXISTS format_statement;

DELIMITER $$

CREATE DEFINER='mariadb.sys'@'localhost' FUNCTION format_statement (
CREATE OR REPLACE DEFINER='mariadb.sys'@'localhost' FUNCTION format_statement (
statement LONGTEXT
)
RETURNS LONGTEXT
Expand Down
4 changes: 1 addition & 3 deletions scripts/sys_schema/functions/format_time.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DROP FUNCTION IF EXISTS format_time;

DELIMITER $$

CREATE DEFINER='mariadb.sys'@'localhost' FUNCTION format_time (
CREATE OR REPLACE DEFINER='mariadb.sys'@'localhost' FUNCTION format_time (
-- We feed in and return TEXT here, as aggregates of
-- picoseconds can return numbers larger than BIGINT UNSIGNED
picoseconds TEXT
Expand Down
4 changes: 1 addition & 3 deletions scripts/sys_schema/functions/list_add.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DROP FUNCTION IF EXISTS list_add;

DELIMITER $$

CREATE DEFINER='mariadb.sys'@'localhost' FUNCTION list_add (
CREATE OR REPLACE DEFINER='mariadb.sys'@'localhost' FUNCTION list_add (
in_list TEXT,
in_add_value TEXT
)
Expand Down
4 changes: 1 addition & 3 deletions scripts/sys_schema/functions/list_drop.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DROP FUNCTION IF EXISTS list_drop;

DELIMITER $$

CREATE DEFINER='mariadb.sys'@'localhost' FUNCTION list_drop (
CREATE OR REPLACE DEFINER='mariadb.sys'@'localhost' FUNCTION list_drop (
in_list TEXT,
in_drop_value TEXT
)
Expand Down
4 changes: 1 addition & 3 deletions scripts/sys_schema/functions/ps_is_account_enabled.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DROP FUNCTION IF EXISTS ps_is_account_enabled;

DELIMITER $$

CREATE DEFINER='mariadb.sys'@'localhost' FUNCTION ps_is_account_enabled (
CREATE OR REPLACE DEFINER='mariadb.sys'@'localhost' FUNCTION ps_is_account_enabled (
in_host VARCHAR(60),
in_user VARCHAR(16)
)
Expand Down
4 changes: 1 addition & 3 deletions scripts/sys_schema/functions/ps_is_account_enabled_57.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DROP FUNCTION IF EXISTS ps_is_account_enabled;

DELIMITER $$

CREATE DEFINER='mariadb.sys'@'localhost' FUNCTION ps_is_account_enabled (
CREATE OR REPLACE DEFINER='mariadb.sys'@'localhost' FUNCTION ps_is_account_enabled (
in_host VARCHAR(60),
in_user VARCHAR(32)
)
Expand Down
4 changes: 1 addition & 3 deletions scripts/sys_schema/functions/ps_is_consumer_enabled.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DROP FUNCTION IF EXISTS ps_is_consumer_enabled;

DELIMITER $$

CREATE DEFINER='mariadb.sys'@'localhost' FUNCTION ps_is_consumer_enabled (
CREATE OR REPLACE DEFINER='mariadb.sys'@'localhost' FUNCTION ps_is_consumer_enabled (
in_consumer varchar(64)
)
RETURNS enum('YES', 'NO')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DROP FUNCTION IF EXISTS ps_is_instrument_default_enabled;

DELIMITER $$

CREATE DEFINER='mariadb.sys'@'localhost' FUNCTION ps_is_instrument_default_enabled (
CREATE OR REPLACE DEFINER='mariadb.sys'@'localhost' FUNCTION ps_is_instrument_default_enabled (
in_instrument VARCHAR(128)
)
RETURNS ENUM('YES', 'NO')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DROP FUNCTION IF EXISTS ps_is_instrument_default_timed;

DELIMITER $$

CREATE DEFINER='mariadb.sys'@'localhost' FUNCTION ps_is_instrument_default_timed (
CREATE OR REPLACE DEFINER='mariadb.sys'@'localhost' FUNCTION ps_is_instrument_default_timed (
in_instrument VARCHAR(128)
)
RETURNS ENUM('YES', 'NO')
Expand Down
4 changes: 1 addition & 3 deletions scripts/sys_schema/functions/ps_is_thread_instrumented.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DROP FUNCTION IF EXISTS ps_is_thread_instrumented;

DELIMITER $$

CREATE DEFINER='mariadb.sys'@'localhost' FUNCTION ps_is_thread_instrumented (
CREATE OR REPLACE DEFINER='mariadb.sys'@'localhost' FUNCTION ps_is_thread_instrumented (
in_connection_id BIGINT UNSIGNED
) RETURNS ENUM('YES', 'NO', 'UNKNOWN')
COMMENT '
Expand Down
4 changes: 1 addition & 3 deletions scripts/sys_schema/functions/ps_thread_account.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DROP FUNCTION IF EXISTS ps_thread_account;

DELIMITER $$

CREATE DEFINER='mariadb.sys'@'localhost' FUNCTION ps_thread_account (
CREATE OR REPLACE DEFINER='mariadb.sys'@'localhost' FUNCTION ps_thread_account (
in_thread_id BIGINT UNSIGNED
) RETURNS TEXT
COMMENT '
Expand Down
4 changes: 1 addition & 3 deletions scripts/sys_schema/functions/ps_thread_id.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DROP FUNCTION IF EXISTS ps_thread_id;

DELIMITER $$

CREATE DEFINER='mariadb.sys'@'localhost' FUNCTION ps_thread_id (
CREATE OR REPLACE DEFINER='mariadb.sys'@'localhost' FUNCTION ps_thread_id (
in_connection_id BIGINT UNSIGNED
) RETURNS BIGINT UNSIGNED
COMMENT '
Expand Down
4 changes: 1 addition & 3 deletions scripts/sys_schema/functions/ps_thread_stack.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DROP FUNCTION IF EXISTS ps_thread_stack;

DELIMITER $$

CREATE DEFINER='mariadb.sys'@'localhost' FUNCTION ps_thread_stack (
CREATE OR REPLACE DEFINER='mariadb.sys'@'localhost' FUNCTION ps_thread_stack (
thd_id BIGINT UNSIGNED,
debug BOOLEAN
)
Expand Down
4 changes: 1 addition & 3 deletions scripts/sys_schema/functions/ps_thread_trx_info.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DROP FUNCTION IF EXISTS ps_thread_trx_info;

DELIMITER $$

CREATE DEFINER='mariadb.sys'@'localhost' FUNCTION ps_thread_trx_info (
CREATE OR REPLACE DEFINER='mariadb.sys'@'localhost' FUNCTION ps_thread_trx_info (
in_thread_id BIGINT UNSIGNED
) RETURNS LONGTEXT
COMMENT '
Expand Down
4 changes: 1 addition & 3 deletions scripts/sys_schema/functions/quote_identifier.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DROP FUNCTION IF EXISTS quote_identifier;

DELIMITER $$

-- https://dev.mysql.com/doc/refman/5.7/en/identifiers.html
-- Maximum supported length for any of the current identifiers in 5.7.5+ is 256 characters.
-- Before that, user variables could have any length.
--
-- Based on Paul Dubois' suggestion in Bug #78823/Bug #22011361.
CREATE DEFINER='mariadb.sys'@'localhost' FUNCTION quote_identifier(in_identifier TEXT)
CREATE OR REPLACE DEFINER='mariadb.sys'@'localhost' FUNCTION quote_identifier(in_identifier TEXT)
RETURNS TEXT CHARSET UTF8
COMMENT '
Description
Expand Down
4 changes: 1 addition & 3 deletions scripts/sys_schema/functions/sys_get_config.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DROP FUNCTION IF EXISTS sys_get_config;

DELIMITER $$

CREATE DEFINER='mariadb.sys'@'localhost' FUNCTION sys_get_config (
CREATE OR REPLACE DEFINER='mariadb.sys'@'localhost' FUNCTION sys_get_config (
in_variable_name VARCHAR(128),
in_default_value VARCHAR(128)
)
Expand Down
4 changes: 1 addition & 3 deletions scripts/sys_schema/functions/version_major.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DROP FUNCTION IF EXISTS version_major;

DELIMITER $$

CREATE DEFINER='mariadb.sys'@'localhost' FUNCTION version_major ()
CREATE OR REPLACE DEFINER='mariadb.sys'@'localhost' FUNCTION version_major ()
RETURNS TINYINT UNSIGNED
COMMENT '
Description
Expand Down
4 changes: 1 addition & 3 deletions scripts/sys_schema/functions/version_minor.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DROP FUNCTION IF EXISTS version_minor;

DELIMITER $$

CREATE DEFINER='mariadb.sys'@'localhost' FUNCTION version_minor ()
CREATE OR REPLACE DEFINER='mariadb.sys'@'localhost' FUNCTION version_minor ()
RETURNS TINYINT UNSIGNED
COMMENT '
Description
Expand Down
4 changes: 1 addition & 3 deletions scripts/sys_schema/functions/version_patch.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DROP FUNCTION IF EXISTS version_patch;

DELIMITER $$

CREATE DEFINER='mariadb.sys'@'localhost' FUNCTION version_patch ()
CREATE OR REPLACE DEFINER='mariadb.sys'@'localhost' FUNCTION version_patch ()
RETURNS TINYINT UNSIGNED
COMMENT '
Description
Expand Down
4 changes: 1 addition & 3 deletions scripts/sys_schema/procedures/create_synonym_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DROP PROCEDURE IF EXISTS create_synonym_db;

DELIMITER $$

CREATE DEFINER='mariadb.sys'@'localhost' PROCEDURE create_synonym_db (
CREATE OR REPLACE DEFINER='mariadb.sys'@'localhost' PROCEDURE create_synonym_db (
IN in_db_name VARCHAR(64),
IN in_synonym VARCHAR(64)
)
Expand Down
4 changes: 1 addition & 3 deletions scripts/sys_schema/procedures/diagnostics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

DROP PROCEDURE IF EXISTS diagnostics;

DELIMITER $$

CREATE DEFINER='mariadb.sys'@'localhost' PROCEDURE diagnostics (
CREATE OR REPLACE DEFINER='mariadb.sys'@'localhost' PROCEDURE diagnostics (
IN in_max_runtime int unsigned, IN in_interval int unsigned,
IN in_auto_config enum ('current', 'medium', 'full')
)
Expand Down
Loading
Loading