From efefddbc85cd2fdd6c36a61fe39000af97ca1458 Mon Sep 17 00:00:00 2001 From: Yan Tingwang Date: Fri, 18 Jul 2025 20:18:14 +0800 Subject: [PATCH] test: add sqlness test for max execution time (#6517) * add sqlness test for max_execution_time Signed-off-by: codephage. * add Pre-line comments SQLNESS PROTOCOL MYSQL Signed-off-by: codephage. * fix(mysql): support max_execution_time variable Co-authored-by: evenyag Signed-off-by: codephage. * fix: test::test_check & sqlness test mysql Signed-off-by: codephage. * add sqlness test for max_execution_time Signed-off-by: codephage. * add Pre-line comments SQLNESS PROTOCOL MYSQL Signed-off-by: codephage. * fix(mysql): support max_execution_time variable Co-authored-by: evenyag Signed-off-by: codephage. * fix: test::test_check & sqlness test mysql Signed-off-by: codephage. * chore: Unify the sql style Signed-off-by: codephage. --------- Signed-off-by: codephage. Co-authored-by: evenyag --- src/servers/src/mysql/federated.rs | 12 +- tests/cases/standalone/common/mysql.result | 14 +- .../common/system/max_execution_time.result | 208 ++++++++++++++++++ .../common/system/max_execution_time.sql | 101 +++++++++ 4 files changed, 322 insertions(+), 13 deletions(-) create mode 100644 tests/cases/standalone/common/system/max_execution_time.result create mode 100644 tests/cases/standalone/common/system/max_execution_time.sql diff --git a/src/servers/src/mysql/federated.rs b/src/servers/src/mysql/federated.rs index 9769bd1f6f..fb5cd8a009 100644 --- a/src/servers/src/mysql/federated.rs +++ b/src/servers/src/mysql/federated.rs @@ -170,7 +170,7 @@ fn select_variable(query: &str, query_context: QueryContextRef) -> Option = var .split(" as ") .map(|x| { @@ -355,11 +355,11 @@ mod test { // complex variables let query = "/* mysql-connector-java-8.0.17 (Revision: 16a712ddb3f826a1933ab42b0039f7fb9eebc6ec) */SELECT @@session.auto_increment_increment AS auto_increment_increment, @@character_set_client AS character_set_client, @@character_set_connection AS character_set_connection, @@character_set_results AS character_set_results, @@character_set_server AS character_set_server, @@collation_server AS collation_server, @@collation_connection AS collation_connection, @@init_connect AS init_connect, @@interactive_timeout AS interactive_timeout, @@license AS license, @@lower_case_table_names AS lower_case_table_names, @@max_allowed_packet AS max_allowed_packet, @@net_write_timeout AS net_write_timeout, @@performance_schema AS performance_schema, @@sql_mode AS sql_mode, @@system_time_zone AS system_time_zone, @@time_zone AS time_zone, @@transaction_isolation AS transaction_isolation, @@wait_timeout AS wait_timeout;"; let expected = "\ -+--------------------------+----------------------+--------------------------+-----------------------+----------------------+------------------+----------------------+--------------+---------------------+---------+------------------------+--------------------+-------------------+--------------------+----------+------------------+---------------+-----------------------+---------------+ -| auto_increment_increment | character_set_client | character_set_connection | character_set_results | character_set_server | collation_server | collation_connection | init_connect | interactive_timeout | license | lower_case_table_names | max_allowed_packet | net_write_timeout | performance_schema | sql_mode | system_time_zone | time_zone | transaction_isolation | wait_timeout; | -+--------------------------+----------------------+--------------------------+-----------------------+----------------------+------------------+----------------------+--------------+---------------------+---------+------------------------+--------------------+-------------------+--------------------+----------+------------------+---------------+-----------------------+---------------+ -| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 31536000 | 0 | 0 | 134217728 | 31536000 | 0 | 0 | Asia/Shanghai | Asia/Shanghai | REPEATABLE-READ | 31536000 | -+--------------------------+----------------------+--------------------------+-----------------------+----------------------+------------------+----------------------+--------------+---------------------+---------+------------------------+--------------------+-------------------+--------------------+----------+------------------+---------------+-----------------------+---------------+"; ++--------------------------+----------------------+--------------------------+-----------------------+----------------------+------------------+----------------------+--------------+---------------------+---------+------------------------+--------------------+-------------------+--------------------+----------+------------------+---------------+-----------------------+--------------+ +| auto_increment_increment | character_set_client | character_set_connection | character_set_results | character_set_server | collation_server | collation_connection | init_connect | interactive_timeout | license | lower_case_table_names | max_allowed_packet | net_write_timeout | performance_schema | sql_mode | system_time_zone | time_zone | transaction_isolation | wait_timeout | ++--------------------------+----------------------+--------------------------+-----------------------+----------------------+------------------+----------------------+--------------+---------------------+---------+------------------------+--------------------+-------------------+--------------------+----------+------------------+---------------+-----------------------+--------------+ +| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 31536000 | 0 | 0 | 134217728 | 31536000 | 0 | 0 | Asia/Shanghai | Asia/Shanghai | REPEATABLE-READ | 31536000 | ++--------------------------+----------------------+--------------------------+-----------------------+----------------------+------------------+----------------------+--------------+---------------------+---------+------------------------+--------------------+-------------------+--------------------+----------+------------------+---------------+-----------------------+--------------+"; test(query, expected); let query = "show variables"; diff --git a/tests/cases/standalone/common/mysql.result b/tests/cases/standalone/common/mysql.result index 980990fa7a..5f120aec90 100644 --- a/tests/cases/standalone/common/mysql.result +++ b/tests/cases/standalone/common/mysql.result @@ -2,19 +2,19 @@ SELECt @@tx_isolation; +-----------------+ -| @@tx_isolation; | +| @@tx_isolation | +-----------------+ -| 0 | +| REPEATABLE-READ | +-----------------+ -- SQLNESS PROTOCOL MYSQL SELECT @@version_comment; -+--------------------+ -| @@version_comment; | -+--------------------+ -| 0 | -+--------------------+ ++-------------------+ +| @@version_comment | ++-------------------+ +| Greptime | ++-------------------+ -- SQLNESS PROTOCOL MYSQL SHOW DATABASES; diff --git a/tests/cases/standalone/common/system/max_execution_time.result b/tests/cases/standalone/common/system/max_execution_time.result new file mode 100644 index 0000000000..12aa180cb3 --- /dev/null +++ b/tests/cases/standalone/common/system/max_execution_time.result @@ -0,0 +1,208 @@ +-- Test default values +-- SQLNESS PROTOCOL MYSQL +SELECT @@max_execution_time; + ++----------------------+ +| @@max_execution_time | ++----------------------+ +| 0 | ++----------------------+ + +-- Test basic settings +-- Using global variable +-- SQLNESS PROTOCOL MYSQL +SET MAX_EXECUTION_TIME = 1000; + +affected_rows: 0 + +-- SQLNESS PROTOCOL MYSQL +SELECT @@max_execution_time; + ++----------------------+ +| @@max_execution_time | ++----------------------+ +| 1000 | ++----------------------+ + +-- Using session variable +-- SQLNESS PROTOCOL MYSQL +SET SESSION MAX_EXECUTION_TIME = 2000; + +affected_rows: 0 + +-- SQLNESS PROTOCOL MYSQL +SELECT @@session.max_execution_time; + ++------------------------------+ +| @@session.max_execution_time | ++------------------------------+ +| 2000 | ++------------------------------+ + +-- Test different formats +-- Using session variable +-- SQLNESS PROTOCOL MYSQL +SET @@SESSION.MAX_EXECUTION_TIME = 3000; + +affected_rows: 0 + +-- SQLNESS PROTOCOL MYSQL +SELECT @@session.max_execution_time; + ++------------------------------+ +| @@session.max_execution_time | ++------------------------------+ +| 3000 | ++------------------------------+ + +-- Using local variable +-- SQLNESS PROTOCOL MYSQL +SET LOCAL MAX_EXECUTION_TIME = 4000; + +affected_rows: 0 + +-- SQLNESS PROTOCOL MYSQL +SELECT @@max_execution_time; + ++----------------------+ +| @@max_execution_time | ++----------------------+ +| 4000 | ++----------------------+ + +-- Test case insensitivity +-- set +-- Lowercase +-- SQLNESS PROTOCOL MYSQL +set max_execution_time = 5000; + +affected_rows: 0 + +-- SQLNESS PROTOCOL MYSQL +SELECT @@max_execution_time; + ++----------------------+ +| @@max_execution_time | ++----------------------+ +| 5000 | ++----------------------+ + +-- Mixed case +-- SQLNESS PROTOCOL MYSQL +SET max_EXECUTION_time = 6000; + +affected_rows: 0 + +-- SQLNESS PROTOCOL MYSQL +SELECT @@max_execution_time; + ++----------------------+ +| @@max_execution_time | ++----------------------+ +| 6000 | ++----------------------+ + +-- Uppercase +-- SQLNESS PROTOCOL MYSQL +SET MAX_EXECUTION_TIME = 7000; + +affected_rows: 0 + +-- SQLNESS PROTOCOL MYSQL +SELECT @@max_execution_time; + ++----------------------+ +| @@max_execution_time | ++----------------------+ +| 7000 | ++----------------------+ + +-- select +-- Lowercase +-- SQLNESS PROTOCOL MYSQL +SET max_execution_time = 8000; + +affected_rows: 0 + +-- SQLNESS PROTOCOL MYSQL +SELECT @@max_execution_time; + ++----------------------+ +| @@max_execution_time | ++----------------------+ +| 8000 | ++----------------------+ + +-- Mixed case +-- SQLNESS PROTOCOL MYSQL +SET max_execution_time = 9000; + +affected_rows: 0 + +-- SQLNESS PROTOCOL MYSQL +SELECT @@max_Execution_time; + ++----------------------+ +| @@max_execution_time | ++----------------------+ +| 9000 | ++----------------------+ + +-- Uppercase +-- SQLNESS PROTOCOL MYSQL +SET max_execution_time = 10000; + +affected_rows: 0 + +-- SQLNESS PROTOCOL MYSQL +SELECT @@MAX_EXECUTION_TIME; + ++----------------------+ +| @@max_execution_time | ++----------------------+ +| 10000 | ++----------------------+ + +-- Test the boundary +-- Negative value (not allowed) +-- SQLNESS PROTOCOL MYSQL +SET max_execution_time = -1; + +Failed to execute query, err: MySqlError { ERROR 1235 (42000): (Unsupported): Not supported: Unsupported timeout expr -1 in set variable statement } + +-- Maximum value for u64 +-- SQLNESS PROTOCOL MYSQL +SET max_execution_time = 18446744073709551615; + +affected_rows: 0 + +-- SQLNESS PROTOCOL MYSQL +SELECT @@max_execution_time; + ++----------------------+ +| @@max_execution_time | ++----------------------+ +| 18446744073709551615 | ++----------------------+ + +-- Maximum value for u64 + 1 (out of range) +-- SQLNESS PROTOCOL MYSQL +SET max_execution_time = 18446744073709551616; + +Failed to execute query, err: MySqlError { ERROR 1235 (42000): (Unsupported): Not supported: Invalid timeout expr 18446744073709551616 in set variable statement } + +--minimum value for u64 +-- SQLNESS PROTOCOL MYSQL +SET max_execution_time = 0; + +affected_rows: 0 + +-- SQLNESS PROTOCOL MYSQL +SELECT @@max_execution_time; + ++----------------------+ +| @@max_execution_time | ++----------------------+ +| 0 | ++----------------------+ + diff --git a/tests/cases/standalone/common/system/max_execution_time.sql b/tests/cases/standalone/common/system/max_execution_time.sql new file mode 100644 index 0000000000..0770b50a5a --- /dev/null +++ b/tests/cases/standalone/common/system/max_execution_time.sql @@ -0,0 +1,101 @@ +-- Test default values +-- SQLNESS PROTOCOL MYSQL +SELECT @@max_execution_time; + +-- Test basic settings +-- Using global variable +-- SQLNESS PROTOCOL MYSQL +SET MAX_EXECUTION_TIME = 1000; + +-- SQLNESS PROTOCOL MYSQL +SELECT @@max_execution_time; + +-- Using session variable +-- SQLNESS PROTOCOL MYSQL +SET SESSION MAX_EXECUTION_TIME = 2000; + +-- SQLNESS PROTOCOL MYSQL +SELECT @@session.max_execution_time; + +-- Test different formats +-- Using session variable +-- SQLNESS PROTOCOL MYSQL +SET @@SESSION.MAX_EXECUTION_TIME = 3000; + +-- SQLNESS PROTOCOL MYSQL +SELECT @@session.max_execution_time; + +-- Using local variable +-- SQLNESS PROTOCOL MYSQL +SET LOCAL MAX_EXECUTION_TIME = 4000; + +-- SQLNESS PROTOCOL MYSQL +SELECT @@max_execution_time; + +-- Test case insensitivity +-- set +-- Lowercase +-- SQLNESS PROTOCOL MYSQL +set max_execution_time = 5000; + +-- SQLNESS PROTOCOL MYSQL +SELECT @@max_execution_time; + +-- Mixed case +-- SQLNESS PROTOCOL MYSQL +SET max_EXECUTION_time = 6000; + +-- SQLNESS PROTOCOL MYSQL +SELECT @@max_execution_time; + +-- Uppercase +-- SQLNESS PROTOCOL MYSQL +SET MAX_EXECUTION_TIME = 7000; + +-- SQLNESS PROTOCOL MYSQL +SELECT @@max_execution_time; + +-- select +-- Lowercase +-- SQLNESS PROTOCOL MYSQL +SET max_execution_time = 8000; + +-- SQLNESS PROTOCOL MYSQL +SELECT @@max_execution_time; + +-- Mixed case +-- SQLNESS PROTOCOL MYSQL +SET max_execution_time = 9000; + +-- SQLNESS PROTOCOL MYSQL +SELECT @@max_Execution_time; + +-- Uppercase +-- SQLNESS PROTOCOL MYSQL +SET max_execution_time = 10000; + +-- SQLNESS PROTOCOL MYSQL +SELECT @@MAX_EXECUTION_TIME; + +-- Test the boundary +-- Negative value (not allowed) +-- SQLNESS PROTOCOL MYSQL +SET max_execution_time = -1; + +-- Maximum value for u64 +-- SQLNESS PROTOCOL MYSQL +SET max_execution_time = 18446744073709551615; + +-- SQLNESS PROTOCOL MYSQL +SELECT @@max_execution_time; + +-- Maximum value for u64 + 1 (out of range) +-- SQLNESS PROTOCOL MYSQL +SET max_execution_time = 18446744073709551616; + +--minimum value for u64 +-- SQLNESS PROTOCOL MYSQL +SET max_execution_time = 0; + +-- SQLNESS PROTOCOL MYSQL +SELECT @@max_execution_time;