Created
March 26, 2018 13:41
-
-
Save ltebean/12d43c32dc71d4ba239e9e55629a4727 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INSERT INTO users(app_user_id) SELECT user_id FROM generate_series(1,1000000) user_id; | |
INSERT INTO events(user_id, event_name, event_time, event_properties) | |
SELECT trunc(random() * 900000 + 1), trunc(random() * 10 + 1)::text | |
,NOW() - '1 hour'::INTERVAL * (random() * 1000 + 1), '{"age": 80}' | |
FROM generate_series(1,10000000) id; | |
SELECT count(*) FROM events | |
explain SELECT count(user_id) FROM users | |
WHERE TRUE AND user_id IN | |
( | |
SELECT user_id FROM events | |
WHERE event_name = '5' AND event_time > NOW() - '1000 day'::INTERVAL | |
AND (event_properties->>'age')::INT > 10 | |
GROUP BY user_id | |
HAVING count(*) > 0 | |
) | |
AND user_id IN | |
( | |
SELECT user_id FROM events | |
WHERE event_name = '3' AND event_time > NOW() - '1000 day'::INTERVAL | |
GROUP BY user_id | |
HAVING count(*) > 2 | |
) | |
AND user_id IN | |
( | |
SELECT user_id FROM events | |
WHERE event_name = '1' AND event_time > NOW() - '1000 day'::INTERVAL | |
GROUP BY user_id | |
HAVING count(*) > 2 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment