test: add sqlness test for max execution time (#6517)

* add sqlness test for max_execution_time

Signed-off-by: codephage. <tingwangyan2020@163.com>

* add Pre-line comments SQLNESS PROTOCOL MYSQL

Signed-off-by: codephage. <tingwangyan2020@163.com>

* fix(mysql): support max_execution_time variable

Co-authored-by: evenyag <realevenyag@gmail.com>
Signed-off-by: codephage. <tingwangyan2020@163.com>

* fix: test::test_check & sqlness test mysql

Signed-off-by: codephage. <tingwangyan2020@163.com>

* add sqlness test for max_execution_time

Signed-off-by: codephage. <tingwangyan2020@163.com>

* add Pre-line comments SQLNESS PROTOCOL MYSQL

Signed-off-by: codephage. <tingwangyan2020@163.com>

* fix(mysql): support max_execution_time variable

Co-authored-by: evenyag <realevenyag@gmail.com>
Signed-off-by: codephage. <tingwangyan2020@163.com>

* fix: test::test_check & sqlness test mysql

Signed-off-by: codephage. <tingwangyan2020@163.com>

* chore: Unify the sql style

Signed-off-by: codephage. <tingwangyan2020@163.com>

---------

Signed-off-by: codephage. <tingwangyan2020@163.com>
Co-authored-by: evenyag <realevenyag@gmail.com>
Signed-off-by: evenyag <realevenyag@gmail.com>
This commit is contained in:
Yan Tingwang
2025-07-18 20:18:14 +08:00
committed by Yingwen
parent b83e6e2b18
commit ff402fd6f6
4 changed files with 322 additions and 13 deletions

View File

@@ -170,7 +170,7 @@ fn select_variable(query: &str, query_context: QueryContextRef) -> Option<Output
// skip the first "select"
for var in vars.iter().skip(1) {
let var = var.trim_matches(|c| c == ' ' || c == ',');
let var = var.trim_matches(|c| c == ' ' || c == ',' || c == ';');
let var_as: Vec<&str> = 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";

View File

@@ -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;

View File

@@ -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 |
+----------------------+

View File

@@ -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;