re:dashでよく使われているクエリーを調べる
re:dashのFork機能はすごく好きなんだけど、便利すぎて気軽にForkされる結果、使ってるのか使ってないのかわからないクエリーが増えてしまいがち。
この記事をみたら統計情報っぽいのが取れるようなので、ちょっといじって以下のようにした。
使用しているバージョンは 0.10.1+b1836
。
SELECT object_id AS query_id, SUM(CASE WHEN action = 'view' THEN 1 ELSE 0 END) AS view, SUM(CASE WHEN action = 'execute' THEN 1 ELSE 0 END) AS execute FROM events WHERE object_type = 'query' AND object_id != '' AND created_at BETWEEN to_date('2016-11-01', 'YYYY-MM-DD') AND to_date('2016-11-17', 'YYYY-MM-DD') GROUP BY object_id ORDER BY execute DESC;
結果はこんな感じ。
object_id | view | execute -----------+------+--------- 78 | 125 | 99 68 | 123 | 106 87 | 68 | 66 79 | 68 | 55 85 | 68 | 42 103 | 63 | 50 107 | 59 | 43 8 | 58 | 13 89 | 53 | 7 125 | 52 | 28 109 | 48 | 21 104 | 44 | 11 112 | 39 | 21 100 | 39 | 19 115 | 31 | 2 122 | 25 | 9
この結果をみて、使用頻度の低いクエリーは積極的にアーカイブすることができそう。
おまけ
events
テーブルはこんな感じ。
テーブル "public.events" 列 | 型 | 修飾語 -----------------------+--------------------------+----------------------------------------------------- id | integer | not null default nextval('events_id_seq'::regclass) org_id | integer | not null user_id | integer | action | character varying(255) | not null object_type | character varying(255) | not null object_id | character varying(255) | additional_properties | text | created_at | timestamp with time zone | not null インデックス: "events_pkey" PRIMARY KEY, btree (id) "events_org_id" btree (org_id) "events_user_id" btree (user_id) 外部キー制約: "events_org_id_fkey" FOREIGN KEY (org_id) REFERENCES organizations(id) "events_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id)
action
, object_type
にはこんな値が入っていた。
action
add_data_source add_member api_get archive autorefresh cancel_execute change_data_source_permission create delete edit edit_description edit_name execute execute_query fork login pivot remove_data_source remove_member search update update_data_source view view_source
object_type
dashboard data_source datasource group group_data_sources page query redash user visualization widget