Skip to content

Commit a460dab

Browse files
authored
Merge pull request #138 from andrewm4894/sql-optimize
Optimize SQL queries
2 parents 6cec2a0 + a8b0928 commit a460dab

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

metrics/defaults/sql/alerts.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ where
2020
and
2121
metric_type = 'metric'
2222
and
23-
date(metric_timestamp) >= date('now', '-{{ alert_metric_timestamp_max_days_ago }} day')
23+
metric_timestamp >= date('now', '-{{ alert_metric_timestamp_max_days_ago }} day')
2424
{% if alert_exclude_metrics is defined %}
2525
and
2626
-- Exclude the specified metrics
@@ -43,7 +43,7 @@ where
4343
and
4444
metric_type = 'score'
4545
and
46-
date(metric_timestamp) >= date('now', '-{{ alert_metric_timestamp_max_days_ago }} day')
46+
metric_timestamp >= date('now', '-{{ alert_metric_timestamp_max_days_ago }} day')
4747
group by metric_timestamp, metric_batch, metric_name
4848
),
4949

@@ -61,7 +61,7 @@ where
6161
and
6262
metric_type = 'alert'
6363
and
64-
date(metric_timestamp) >= date('now', '-{{ alert_metric_timestamp_max_days_ago }} day')
64+
metric_timestamp >= date('now', '-{{ alert_metric_timestamp_max_days_ago }} day')
6565
group by metric_timestamp, metric_batch, metric_name
6666
),
6767

metrics/defaults/sql/change.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ where
2121
metric_type = 'metric'
2222
and
2323
-- Filter to the last {{ change_metric_timestamp_max_days_ago }} days
24-
date(metric_timestamp) >= date('now', '-{{ change_metric_timestamp_max_days_ago }} day')
24+
metric_timestamp >= date('now', '-{{ change_metric_timestamp_max_days_ago }} day')
2525
{% if change_include_metrics is defined %}
2626
and
2727
-- Include only the specified metrics
@@ -51,7 +51,7 @@ where
5151
metric_type = 'change'
5252
and
5353
-- Filter to the last {{ change_metric_timestamp_max_days_ago }} days
54-
date(metric_timestamp) >= date('now', '-{{ change_metric_timestamp_max_days_ago }} day')
54+
metric_timestamp >= date('now', '-{{ change_metric_timestamp_max_days_ago }} day')
5555
{% if change_include_metrics is defined %}
5656
and
5757
-- Include only the specified metrics

metrics/defaults/sql/dashboard.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ metric_value_data AS (
1313
FROM {{ table_key }}
1414
WHERE metric_batch = '{{ metric_batch }}'
1515
AND metric_type = 'metric'
16-
AND DATE(metric_timestamp) >= DATE('now', '-{{ alert_metric_timestamp_max_days_ago }} day')
16+
AND metric_timestamp >= DATE('now', '-{{ alert_metric_timestamp_max_days_ago }} day')
1717
GROUP BY metric_timestamp, metric_batch, metric_name
1818
),
1919

@@ -26,7 +26,7 @@ metric_score_data AS (
2626
FROM {{ table_key }}
2727
WHERE metric_batch = '{{ metric_batch }}'
2828
AND metric_type = 'score'
29-
AND DATE(metric_timestamp) >= DATE('now', '-{{ alert_metric_timestamp_max_days_ago }} day')
29+
AND metric_timestamp >= DATE('now', '-{{ alert_metric_timestamp_max_days_ago }} day')
3030
GROUP BY metric_timestamp, metric_batch, metric_name
3131
),
3232

@@ -39,7 +39,7 @@ metric_alert_data AS (
3939
FROM {{ table_key }}
4040
WHERE metric_batch = '{{ metric_batch }}'
4141
AND metric_type = 'alert'
42-
AND DATE(metric_timestamp) >= DATE('now', '-{{ alert_metric_timestamp_max_days_ago }} day')
42+
AND metric_timestamp >= DATE('now', '-{{ alert_metric_timestamp_max_days_ago }} day')
4343
GROUP BY metric_timestamp, metric_batch, metric_name
4444
),
4545

@@ -52,7 +52,7 @@ metric_change_data AS (
5252
FROM {{ table_key }}
5353
WHERE metric_batch = '{{ metric_batch }}'
5454
AND metric_type = 'change'
55-
AND DATE(metric_timestamp) >= DATE('now', '-{{ change_metric_timestamp_max_days_ago }} day')
55+
AND metric_timestamp >= DATE('now', '-{{ change_metric_timestamp_max_days_ago }} day')
5656
GROUP BY metric_timestamp, metric_batch, metric_name
5757
),
5858

metrics/defaults/sql/llmalert.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ where
1818
and
1919
metric_type = 'metric'
2020
and
21-
date(metric_timestamp) >= date('now', '-{{ llmalert_metric_timestamp_max_days_ago }} day')
21+
metric_timestamp >= date('now', '-{{ llmalert_metric_timestamp_max_days_ago }} day')
2222
group by metric_timestamp, metric_batch, metric_name
2323
),
2424

@@ -36,7 +36,7 @@ where
3636
and
3737
metric_type = 'score'
3838
and
39-
date(metric_timestamp) >= date('now', '-{{ llmalert_metric_timestamp_max_days_ago }} day')
39+
metric_timestamp >= date('now', '-{{ llmalert_metric_timestamp_max_days_ago }} day')
4040
group by metric_timestamp, metric_batch, metric_name
4141
),
4242

@@ -54,7 +54,7 @@ where
5454
and
5555
metric_type = 'alert'
5656
and
57-
date(metric_timestamp) >= date('now', '-{{ llmalert_metric_timestamp_max_days_ago }} day')
57+
metric_timestamp >= date('now', '-{{ llmalert_metric_timestamp_max_days_ago }} day')
5858
group by metric_timestamp, metric_batch, metric_name
5959
),
6060

metrics/defaults/sql/plot.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ metric_value_data AS (
1313
FROM {{ table_key }}
1414
WHERE metric_batch = '{{ metric_batch }}'
1515
AND metric_type = 'metric'
16-
AND DATE(metric_timestamp) >= DATE('now', '-{{ alert_metric_timestamp_max_days_ago }} day')
16+
AND metric_timestamp >= DATE('now', '-{{ alert_metric_timestamp_max_days_ago }} day')
1717
GROUP BY metric_timestamp, metric_batch, metric_name
1818
),
1919

@@ -26,7 +26,7 @@ metric_score_data AS (
2626
FROM {{ table_key }}
2727
WHERE metric_batch = '{{ metric_batch }}'
2828
AND metric_type = 'score'
29-
AND DATE(metric_timestamp) >= DATE('now', '-{{ alert_metric_timestamp_max_days_ago }} day')
29+
AND metric_timestamp >= DATE('now', '-{{ alert_metric_timestamp_max_days_ago }} day')
3030
GROUP BY metric_timestamp, metric_batch, metric_name
3131
),
3232

@@ -39,7 +39,7 @@ metric_alert_data AS (
3939
FROM {{ table_key }}
4040
WHERE metric_batch = '{{ metric_batch }}'
4141
AND metric_type = 'alert'
42-
AND DATE(metric_timestamp) >= DATE('now', '-{{ alert_metric_timestamp_max_days_ago }} day')
42+
AND metric_timestamp >= DATE('now', '-{{ alert_metric_timestamp_max_days_ago }} day')
4343
GROUP BY metric_timestamp, metric_batch, metric_name
4444
),
4545

@@ -52,7 +52,7 @@ metric_change_data AS (
5252
FROM {{ table_key }}
5353
WHERE metric_batch = '{{ metric_batch }}'
5454
AND metric_type = 'change'
55-
AND DATE(metric_timestamp) >= DATE('now', '-{{ change_metric_timestamp_max_days_ago }} day')
55+
AND metric_timestamp >= DATE('now', '-{{ change_metric_timestamp_max_days_ago }} day')
5656
GROUP BY metric_timestamp, metric_batch, metric_name
5757
),
5858

metrics/defaults/sql/summary.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ SELECT
88
FROM {{ table_key }}
99
WHERE
1010
-- Limit to the last {{ summary_metric_timestamp_max_days_ago }} days
11-
DATE(metric_timestamp) >= DATE('now', '-{{ summary_metric_timestamp_max_days_ago }} day')
11+
metric_timestamp >= DATE('now', '-{{ summary_metric_timestamp_max_days_ago }} day')
1212
GROUP BY metric_batch, metric_name
1313
ORDER BY n_alert DESC
1414
;

0 commit comments

Comments
 (0)