Merge branch 'db_indexes' into dev
This commit is contained in:
commit
c2b236f5a0
4 changed files with 56 additions and 0 deletions
1
server/.gitignore
vendored
1
server/.gitignore
vendored
|
@ -2,3 +2,4 @@
|
|||
.env
|
||||
.idea
|
||||
env_setup.sh
|
||||
query_testing/*.json
|
||||
|
|
16
server/migrations/2020-01-11-012452_add_indexes/down.sql
vendored
Normal file
16
server/migrations/2020-01-11-012452_add_indexes/down.sql
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
drop index idx_post_creator;
|
||||
drop index idx_post_community;
|
||||
|
||||
drop index idx_post_like_post;
|
||||
drop index idx_post_like_user;
|
||||
|
||||
drop index idx_comment_creator;
|
||||
drop index idx_comment_parent;
|
||||
drop index idx_comment_post;
|
||||
|
||||
drop index idx_comment_like_comment;
|
||||
drop index idx_comment_like_user;
|
||||
drop index idx_comment_like_post;
|
||||
|
||||
drop index idx_community_creator;
|
||||
drop index idx_community_category;
|
17
server/migrations/2020-01-11-012452_add_indexes/up.sql
vendored
Normal file
17
server/migrations/2020-01-11-012452_add_indexes/up.sql
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
-- Go through all the tables joins, optimize every view, CTE, etc.
|
||||
create index idx_post_creator on post (creator_id);
|
||||
create index idx_post_community on post (community_id);
|
||||
|
||||
create index idx_post_like_post on post_like (post_id);
|
||||
create index idx_post_like_user on post_like (user_id);
|
||||
|
||||
create index idx_comment_creator on comment (creator_id);
|
||||
create index idx_comment_parent on comment (parent_id);
|
||||
create index idx_comment_post on comment (post_id);
|
||||
|
||||
create index idx_comment_like_comment on comment_like (comment_id);
|
||||
create index idx_comment_like_user on comment_like (user_id);
|
||||
create index idx_comment_like_post on comment_like (post_id);
|
||||
|
||||
create index idx_community_creator on community (creator_id);
|
||||
create index idx_community_category on community (category_id);
|
22
server/query_testing/generate_explain_reports.sh
vendored
Executable file
22
server/query_testing/generate_explain_reports.sh
vendored
Executable file
|
@ -0,0 +1,22 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Do the views first
|
||||
|
||||
echo "explain (analyze, format json) select * from user_view" > explain.sql
|
||||
psql -qAt -U lemmy -f explain.sql > user_view.json
|
||||
|
||||
echo "explain (analyze, format json) select * from post_view where user_id is null order by hot_rank desc" > explain.sql
|
||||
psql -qAt -U lemmy -f explain.sql > post_view.json
|
||||
|
||||
echo "explain (analyze, format json) select * from comment_view where user_id is null" > explain.sql
|
||||
psql -qAt -U lemmy -f explain.sql > comment_view.json
|
||||
|
||||
echo "explain (analyze, format json) select * from community_view where user_id is null order by hot_rank desc" > explain.sql
|
||||
psql -qAt -U lemmy -f explain.sql > community_view.json
|
||||
|
||||
echo "explain (analyze, format json) select * from site_view limit 1" > explain.sql
|
||||
psql -qAt -U lemmy -f explain.sql > site_view.json
|
||||
|
||||
grep "Execution Time" *.json
|
||||
|
||||
rm explain.sql
|
Loading…
Reference in a new issue