Small optimization of alert queries (#16282)
Emmanuel Vasilakis committed
Oct 27, 2023 at 15:35 UTC
59a983abb47026584f146d1b475f38d2c8195347
2 files changed
+4
-2
database/sqlite/sqlite_aclk_alert.c
+2
-2
@@ -71,9 +71,9 @@ fail:
71
//decide if some events should be sent or not
72
#define SQL_SELECT_ALERT_BY_ID \
73
"SELECT hld.new_status, hl.config_hash_id, hld.unique_id FROM health_log hl, aclk_alert_%s aa, health_log_detail hld " \
74
- "WHERE hl.host_id = @host_id AND hld.unique_id = aa.filtered_alert_unique_id " \
74
+ "WHERE hl.host_id = @host_id AND +hld.unique_id = aa.filtered_alert_unique_id " \
75
"AND hld.alarm_id = @alarm_id AND hl.health_log_id = hld.health_log_id " \
76
- "ORDER BY hld.alarm_event_id DESC LIMIT 1;"
76
+ "ORDER BY hld.rowid DESC LIMIT 1;"
77
78
static bool should_send_to_cloud(RRDHOST *host, ALARM_ENTRY *ae)
79
{
database/sqlite/sqlite_functions.c
+2
@@ -60,6 +60,8 @@ const char *database_config[] = {
60
"CREATE INDEX IF NOT EXISTS health_log_d_ind_3 ON health_log_detail (transition_id);",
61
"CREATE INDEX IF NOT EXISTS health_log_d_ind_5 ON health_log_detail (health_log_id, unique_id DESC);",
62
"CREATE INDEX IF NOT EXISTS health_log_d_ind_6 on health_log_detail (health_log_id, when_key)",
63
+ "CREATE INDEX IF NOT EXISTS health_log_d_ind_7 on health_log_detail (alarm_id);",
64
+ "CREATE INDEX IF NOT EXISTS health_log_d_ind_8 on health_log_detail (new_status, updated_by_id);",
65
66
NULL
67
};