Skip to content

Instantly share code, notes, and snippets.

@dlebauer
Created November 2, 2022 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlebauer/c840ab669383f8d1a4d1d7436176a90e to your computer and use it in GitHub Desktop.
Save dlebauer/c840ab669383f8d1a4d1d7436176a90e to your computer and use it in GitHub Desktop.
figuring out why the dbfiles table gets so big
select extract(year from created_at) as year, container_type, count(*) as n from dbfiles where id between 1000000000 and 2000000000 group by container_type, year order by container_type, year;
select created_user_id, container_type, count(*) as n from dbfiles where id between 1000000000 and 2000000000 group by container_type, created_user_id order by n desc;
select * from dbfiles where created_user_id is not null;
select extract(year from created_at) as year, created_user_id, container_type, count(*) as n from dbfiles where id between 9000000000 and 10000000000 group by container_type, created_user_id, year order by year, container_type, created_user_id;
select null as year, created_user_id, container_type, count(*) as n from dbfiles where id between 9000000000 and 10000000000 group by container_type, created_user_id order by container_type, created_user_id;
select count(*) from dbfiles where container_type = 'Posterior';
select count(distinct container_id) from dbfiles where container_type = 'Posterior';
select count(*) as n, container_id from dbfiles where container_type = 'Posterior' group by container_id order by n desc;
select * from dbfiles where container_id = 1000000032;
select count(*) from dbfiles where container_type = 'Input'; --462,801
select count(distinct container_id) from dbfiles where container_type = 'Input'; --374,782
select count(distinct file_name) from dbfiles where container_type = 'Input';--400,000
select count(distinct file_path) from dbfiles where container_type = 'Input';--208,961
select count(*) as n, file_path from dbfiles where container_type = 'Posterior' group by file_path order by n desc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment