Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ryandotsmith/wcld
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Smith (ace hacker) committed Mar 26, 2012
2 parents 469e1b7 + fba1ee1 commit b9779b5
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions readme.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ quickly group our app's average response time grouped by hour:
$ heroku pg:psql $ heroku pg:psql
``` ```


### Avg

```sql ```sql
SELECT SELECT
date_trunc('hour', time) AS time_group, date_trunc('hour', time) AS time_group,
Expand All @@ -51,6 +53,38 @@ WHERE
2012-02-14 03:00:00+00 | 00:00:00.073081 2012-02-14 03:00:00+00 | 00:00:00.073081
``` ```


### Percentile

```sql
SELECT
perctile,
avg(elapsed_time::interval)
FROM (
SELECT
data -> 'elapsed_time' as elapsed_time,
ntile(100) over (order by (data -> 'elapsed_time')) as perctile
FROM
log_data
WHERE
data -> 'action' = 'find_prev_rec'
and
time > now() - '9 minutes'::interval
and
expired = false
) x
WHERE
perctile = 95
GROUP BY perctile
;
```

```
perctile | avg
----------+-----------------
95 | 00:00:00.008944
(1 row)
```

### Indicies ### Indicies


One possible indexing strategy: One possible indexing strategy:
Expand Down

0 comments on commit b9779b5

Please sign in to comment.