|
| 1 | + /** |
| 2 | + * @file mysql-reg_test_4707_threshold_resultset_size-t.cpp |
| 3 | + * @brief The test specifically examines the impact of different mysql-threshold_resultset_size threshold values on query response times |
| 4 | + * and addresses an identified issue caused by variable overflow, which results in slow performance. |
| 5 | + */ |
| 6 | + |
| 7 | +#include <string> |
| 8 | +#include <sstream> |
| 9 | +#include <chrono> |
| 10 | +#include "mysql.h" |
| 11 | +#include "command_line.h" |
| 12 | +#include "tap.h" |
| 13 | +#include "utils.h" |
| 14 | + |
| 15 | +CommandLine cl; |
| 16 | + |
| 17 | +int main(int argc, char** argv) { |
| 18 | + |
| 19 | + plan(6); // Total number of tests planned |
| 20 | + |
| 21 | + if (cl.getEnv()) |
| 22 | + return exit_status(); |
| 23 | + |
| 24 | + // Initialize Admin connection |
| 25 | + MYSQL* proxysql_admin = mysql_init(NULL); |
| 26 | + if (!proxysql_admin) { |
| 27 | + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); |
| 28 | + return -1; |
| 29 | + } |
| 30 | + |
| 31 | + // Connnect to ProxySQL Admin |
| 32 | + if (!mysql_real_connect(proxysql_admin, cl.admin_host, cl.admin_username, cl.admin_password, NULL, cl.admin_port, NULL, 0)) { |
| 33 | + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_admin)); |
| 34 | + return -1; |
| 35 | + } |
| 36 | + |
| 37 | + // Initialize Backend connection |
| 38 | + MYSQL* proxysql_backend = mysql_init(NULL); |
| 39 | + if (!proxysql_backend) { |
| 40 | + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_backend)); |
| 41 | + return -1; |
| 42 | + } |
| 43 | + |
| 44 | + // Connnect to ProxySQL Backend |
| 45 | + if (!mysql_real_connect(proxysql_backend, cl.host, cl.username, cl.password, NULL, cl.port, NULL, 0)) { |
| 46 | + fprintf(stderr, "File %s, line %d, Error: %s\n", __FILE__, __LINE__, mysql_error(proxysql_backend)); |
| 47 | + return -1; |
| 48 | + } |
| 49 | + MYSQL_QUERY(proxysql_admin, "DELETE FROM mysql_query_rules"); |
| 50 | + MYSQL_QUERY(proxysql_admin, "LOAD MYSQL QUERY RULES TO RUNTIME"); |
| 51 | + MYSQL_QUERY(proxysql_admin, "SET mysql-poll_timeout=2000"); |
| 52 | + MYSQL_QUERY(proxysql_admin, "SET mysql-threshold_resultset_size=8000"); |
| 53 | + MYSQL_QUERY(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME"); |
| 54 | + |
| 55 | + int rc; |
| 56 | + |
| 57 | + auto start = std::chrono::high_resolution_clock::now(); |
| 58 | + rc = mysql_query(proxysql_backend, "SELECT 1"); |
| 59 | + auto end = std::chrono::high_resolution_clock::now(); |
| 60 | + |
| 61 | + if (rc == 0) { |
| 62 | + MYSQL_RES* res = mysql_store_result(proxysql_backend); |
| 63 | + ok(res != nullptr, "Query executed successfully. %s", mysql_error(proxysql_backend)); |
| 64 | + mysql_free_result(res); |
| 65 | + } |
| 66 | + else { |
| 67 | + ok(false, "Error executing query. %s", mysql_error(proxysql_admin)); |
| 68 | + } |
| 69 | + |
| 70 | + std::chrono::duration<double, std::milli> duration = end - start; |
| 71 | + ok(duration.count() < 10.00, "Execution time should be less than 10 ms. Actual: %f ms", duration.count()); |
| 72 | + |
| 73 | + MYSQL_QUERY(proxysql_admin, "SET mysql-threshold_resultset_size=536870912"); |
| 74 | + MYSQL_QUERY(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME"); |
| 75 | + |
| 76 | + start = std::chrono::high_resolution_clock::now(); |
| 77 | + rc = mysql_query(proxysql_backend, "SELECT 1"); |
| 78 | + end = std::chrono::high_resolution_clock::now(); |
| 79 | + |
| 80 | + if (rc == 0) { |
| 81 | + MYSQL_RES* res = mysql_store_result(proxysql_backend); |
| 82 | + ok(res != nullptr, "Query executed successfully. %s", mysql_error(proxysql_backend)); |
| 83 | + mysql_free_result(res); |
| 84 | + } |
| 85 | + else { |
| 86 | + ok(false, "Error executing query. %s", mysql_error(proxysql_admin)); |
| 87 | + } |
| 88 | + duration = end - start; |
| 89 | + ok(duration.count() < 10.00, "Execution time should be less than 10 ms. Actual: %f ms", duration.count()); |
| 90 | + |
| 91 | + MYSQL_QUERY(proxysql_admin, "SET mysql-threshold_resultset_size=1073741824"); |
| 92 | + MYSQL_QUERY(proxysql_admin, "LOAD MYSQL VARIABLES TO RUNTIME"); |
| 93 | + |
| 94 | + start = std::chrono::high_resolution_clock::now(); |
| 95 | + rc = mysql_query(proxysql_backend, "SELECT 1"); |
| 96 | + end = std::chrono::high_resolution_clock::now(); |
| 97 | + |
| 98 | + if (rc == 0) { |
| 99 | + MYSQL_RES* res = mysql_store_result(proxysql_backend); |
| 100 | + ok(res != nullptr, "Query executed successfully. %s", mysql_error(proxysql_backend)); |
| 101 | + mysql_free_result(res); |
| 102 | + } |
| 103 | + else { |
| 104 | + ok(false, "Error executing query. %s", mysql_error(proxysql_admin)); |
| 105 | + } |
| 106 | + duration = end - start; |
| 107 | + ok(duration.count() < 10.00, "Execution time should be less than 10 ms. Actual: %f ms", duration.count()); |
| 108 | + |
| 109 | + mysql_close(proxysql_backend); |
| 110 | + mysql_close(proxysql_admin); |
| 111 | + |
| 112 | + return exit_status(); |
| 113 | +} |
0 commit comments