diff --git a/include/query_processor.h b/include/query_processor.h index f5e42b3bf..5d7bef076 100644 --- a/include/query_processor.h +++ b/include/query_processor.h @@ -335,6 +335,7 @@ class Query_Processor { SQLite3_result * fast_routing_resultset; void load_fast_routing(SQLite3_result *resultset); SQLite3_result * get_current_query_rules_fast_routing(); + int get_current_query_rules_fast_routing_count(); int testing___find_HG_in_mysql_query_rules_fast_routing(char *username, char *schemaname, int flagIN); int testing___find_HG_in_mysql_query_rules_fast_routing_dual(char *username, char *schemaname, int flagIN); diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index f76b6a384..e846182e6 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -3621,6 +3621,20 @@ void admin_session_handler(MySQL_Session *sess, void *_pa, PtrSize_t *pkt) { } } } + + // if the client simply executes: + // SELECT COUNT(*) FROM runtime_mysql_query_rules_fast_routing + // we just return the count + if (strcmp("SELECT COUNT(*) FROM runtime_mysql_query_rules_fast_routing", query_no_space)==0) { + int cnt = GloQPro->get_current_query_rules_fast_routing_count(); + l_free(query_length,query); + char buf[256]; + sprintf(buf,"SELECT %d AS 'COUNT(*)'", cnt); + query=l_strdup(buf); + query_length=strlen(query)+1; + goto __run_query; + } + if (!strncasecmp("TRUNCATE ", query_no_space, strlen("TRUNCATE "))) { if (sess->session_type == PROXYSQL_SESSION_ADMIN) { // no stats if (strstr(query_no_space,"stats_mysql_query_digest")) { diff --git a/lib/Query_Processor.cpp b/lib/Query_Processor.cpp index 2cc1d9fa6..499894503 100644 --- a/lib/Query_Processor.cpp +++ b/lib/Query_Processor.cpp @@ -840,6 +840,14 @@ SQLite3_result * Query_Processor::get_current_query_rules() { return result; } +int Query_Processor::get_current_query_rules_fast_routing_count() { + int result = 0; + pthread_rwlock_rdlock(&rwlock); + result = fast_routing_resultset->rows_count; + pthread_rwlock_unlock(&rwlock); + return result; +} + SQLite3_result * Query_Processor::get_current_query_rules_fast_routing() { proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 4, "Dumping current query rules fast_routing, using Global version %d\n", version); SQLite3_result *result=new SQLite3_result(5);