Skip to content
Snippets Groups Projects
Commit 18f9decb authored by Tom Robinson's avatar Tom Robinson
Browse files

Add query_hash column and indexes, use for /api/dataset/duration endpoint

parent 69cd19e0
No related branches found
No related tags found
No related merge requests found
databaseChangeLog:
- changeSet:
id: 37
author: tlrobinson
changes:
- addColumn:
tableName: query_queryexecution
columns:
- column:
name: query_hash
type: int
constraints:
nullable: true
- addNotNullConstraint:
tableName: query_queryexecution
columnName: query_hash
columnDataType: int
defaultNullValue: 0
- createIndex:
tableName: query_queryexecution
indexName: idx_query_queryexecution_query_hash
columns:
column:
name: query_hash
- createIndex:
tableName: query_queryexecution
indexName: idx_query_queryexecution_started_at
columns:
column:
name: started_at
......@@ -34,6 +34,7 @@
{"include": {"file": "migrations/033_add_physical_schema_tables.yaml"}},
{"include": {"file": "migrations/034_add_pulse_channel_enabled_field.yaml"}},
{"include": {"file": "migrations/035_modify_setting_value_length.yaml"}},
{"include": {"file": "migrations/036_add_dashboard_filters_columns.yaml"}}
{"include": {"file": "migrations/036_add_dashboard_filters_columns.yaml"}},
{"include": {"file": "migrations/037_add_query_hash_and_indexes.yaml"}}
]
}
......@@ -40,7 +40,7 @@
;; add sensible constraints for results limits on our query
(let [query (assoc body :constraints dataset-query-api-constraints)
running-times (db/select-field :running_time QueryExecution
:json_query (json/generate-string query)
:query_hash (hash query)
{:order-by [[:started_at :desc]]
:limit 10})]
{:average (float (/ (reduce + running-times)
......
......@@ -570,9 +570,11 @@
[query {:keys [executed_by]}]
{:pre [(integer? executed_by)]}
(let [query-uuid (.toString (java.util.UUID/randomUUID))
query-hash (hash query)
query-execution {:uuid query-uuid
:executor_id executed_by
:json_query query
:query_hash query-hash
:query_id nil
:version 0
:status :starting
......@@ -588,7 +590,7 @@
:start_time_millis (System/currentTimeMillis)}
query (assoc query :info {:executed-by executed_by
:uuid query-uuid
:query-hash (hash query)
:query-hash query-hash
:query-type (if (mbql-query? query) "MBQL" "native")})]
(try
(let [result (process-query query)]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment