小编Jul*_*don的帖子

可扩展查询前 x 天内的事件运行计数

我已经在stackoverflow上发布了这个问题,但我想我可能会在这里得到更好的答案。
我有一个表存储用户发生的数百万个事件:

                                       Table "public.events"
   Column   |           Type           |                         Modifiers                         
------------+--------------------------+-----------------------------------------------------------
 event_id   | integer                  | not null default nextval('events_event_id_seq'::regclass)
 user_id    | bigint                   | 
 event_type | integer                  | 
 ts         | timestamp with time zone | 
Run Code Online (Sandbox Code Playgroud)

event_type 有 5 个不同的值、数百万用户以及每个用户每个 event_type 的不同事件数,通常范围为 1 到 50。

数据样本:

+-----------+----------+-------------+----------------------------+
| event_id  | user_id  | event_type  |         timestamp          |
+-----------+----------+-------------+----------------------------+
|        1  |       1  |          1  | January, 01 2015 00:00:00  |
|        2  |       1  |          1  | January, 10 2015 00:00:00  | …
Run Code Online (Sandbox Code Playgroud)

postgresql performance scalability window-functions postgresql-performance

5
推荐指数
1
解决办法
3210
查看次数