From 9f74a2281f6f10b5160051c8291713b9f5ed5205 Mon Sep 17 00:00:00 2001 From: Tatsuo Ishii Date: Fri, 14 Aug 2020 10:45:54 +0900 Subject: [PATCH] Add statistics for INSERT/UPDATE/DELETE etc. SQL commands. We already allow to collect stats for SELECT, but it would be useful to collect stats for other types of SQL commands. APIs to fetch stats data is also added. No UI is added yet. Currently, any SQL commands (besides SELECT/INSERT/UPDATE/DELETE) other than: case(T_CheckPointStmt): case(T_DeallocateStmt): case(T_DiscardStmt): case(T_ExecuteStmt): case(T_ExplainStmt): case(T_ListenStmt): case(T_LoadStmt): case(T_LockStmt): case(T_NotifyStmt): case(T_PrepareStmt): case(T_TransactionStmt): case(T_UnlistenStmt): case(T_VacuumStmt): case(T_VariableSetStmt): case(T_VariableShowStmt): are counted as DDL commands. Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2020-July/003754.html --- src/include/utils/statistics.h | 5 +++ src/utils/statistics.c | 72 ++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/src/include/utils/statistics.h b/src/include/utils/statistics.h index 4f0a33f42..d235cc37d 100644 --- a/src/include/utils/statistics.h +++ b/src/include/utils/statistics.h @@ -26,5 +26,10 @@ void stat_set_stat_area(void *address); void stat_init_stat_area(void); void stat_count_up(int backend_node_id, Node *parsetree); uint64 stat_get_select_count(int backend_node_id); +uint64 stat_get_insert_count(int backend_node_id); +uint64 stat_get_update_count(int backend_node_id); +uint64 stat_get_delete_count(int backend_node_id); +uint64 stat_get_ddl_count(int backend_node_id); +uint64 stat_get_other_count(int backend_node_id); #endif /* statistics_h */ diff --git a/src/utils/statistics.c b/src/utils/statistics.c index db3ac0ba6..373ba5e2c 100644 --- a/src/utils/statistics.c +++ b/src/utils/statistics.c @@ -92,6 +92,48 @@ stat_count_up(int backend_node_id, Node *parse_tree) { per_node_stat[backend_node_id].select_cnt++; } + + else if (IsA(parse_tree, InsertStmt)) + { + per_node_stat[backend_node_id].insert_cnt++; + } + + else if (IsA(parse_tree, UpdateStmt)) + { + per_node_stat[backend_node_id].update_cnt++; + } + + else if (IsA(parse_tree, DeleteStmt)) + { + per_node_stat[backend_node_id].delete_cnt++; + } + + else + { + switch(nodeTag(parse_tree)) + { + case(T_CheckPointStmt): + case(T_DeallocateStmt): + case(T_DiscardStmt): + case(T_ExecuteStmt): + case(T_ExplainStmt): + case(T_ListenStmt): + case(T_LoadStmt): + case(T_LockStmt): + case(T_NotifyStmt): + case(T_PrepareStmt): + case(T_TransactionStmt): + case(T_UnlistenStmt): + case(T_VacuumStmt): + case(T_VariableSetStmt): + case(T_VariableShowStmt): + per_node_stat[backend_node_id].other_cnt++; + break; + + default: + per_node_stat[backend_node_id].ddl_cnt++; + } + } } /* @@ -102,3 +144,33 @@ stat_get_select_count(int backend_node_id) { return per_node_stat[backend_node_id].select_cnt; } + +uint64 +stat_get_insert_count(int backend_node_id) +{ + return per_node_stat[backend_node_id].insert_cnt; +} + +uint64 +stat_get_update_count(int backend_node_id) +{ + return per_node_stat[backend_node_id].update_cnt; +} + +uint64 +stat_get_delete_count(int backend_node_id) +{ + return per_node_stat[backend_node_id].delete_cnt; +} + +uint64 +stat_get_ddl_count(int backend_node_id) +{ + return per_node_stat[backend_node_id].ddl_cnt; +} + +uint64 +stat_get_other_count(int backend_node_id) +{ + return per_node_stat[backend_node_id].other_cnt; +} -- 2.39.5