Created
September 28, 2022 17:13
-
-
Save all4miller/5ce2480a892386294df67fb9be3b1694 to your computer and use it in GitHub Desktop.
This file contains 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
drop table if exists datatz; | |
create table if not exists datatz ( | |
timestmp timestamp, | |
user_id integer, | |
stat double precision | |
); | |
insert into datatz | |
select timestmp, | |
user_id, | |
random() * 100 as stat | |
from generate_series(now() - INTERVAL '2 years', now(), INTERVAL '5 minutes') as timestmp, | |
generate_series(1,100) user_id; | |
create index idx_datatz_timestmp on datatz ( | |
timestmp | |
); | |
vacuum analyze datatz; | |
explain (analyze, buffers) | |
select count(*) | |
from datatz | |
where timestmp >= current_date - interval '7 days'; | |
explain (analyze, buffers) | |
select count(*) | |
from datatz | |
where timestmp >= current_date - interval '30 days'; | |
explain (analyze, buffers) | |
select count(*) | |
from datatz | |
where timestmp between '1 JAN 2021' and '31 DEC 2021' | |
select pg_size_pretty (pg_relation_size('datatz')); | |
select pg_size_pretty (pg_total_relation_size ('datatz')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment