File tree Expand file tree Collapse file tree
1770589396319_optimize_friends_queries
1770589601000_perf_get_player_matches_optimization Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- CREATE OR REPLACE FUNCTION public .get_player_matches(player public .players ) RETURNS SETOF public .matches
2- LANGUAGE plpgsql STABLE
3- AS $$
4- DECLARE
5- BEGIN
6- RETURN QUERY
7- SELECT DISTINCT m.*
8- FROM match_lineup_players mlp
9- INNER JOIN matches m ON (m .lineup_1_id = mlp .match_lineup_id OR m .lineup_2_id = mlp .match_lineup_id )
10- WHERE mlp .steam_id = player .steam_id ;
11- END;
1+ CREATE OR REPLACE FUNCTION public .get_player_matches(player public .players )
2+ RETURNS SETOF public .matches
3+ LANGUAGE SQL STABLE
4+ AS $$
5+ SELECT DISTINCT m.*
6+ FROM match_lineup_players mlp
7+ JOIN matches m ON m .lineup_1_id = mlp .match_lineup_id
8+ WHERE mlp .steam_id = player .steam_id
9+
10+ UNION
11+
12+ SELECT DISTINCT m.*
13+ FROM match_lineup_players mlp
14+ JOIN matches m ON m .lineup_2_id = mlp .match_lineup_id
15+ WHERE mlp .steam_id = player .steam_id ;
1216$$;
1317
1418CREATE OR REPLACE FUNCTION public .get_total_player_matches(player players)
Original file line number Diff line number Diff line change 1- CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_friends_other_player_steam_id
1+ CREATE INDEX IF NOT EXISTS idx_friends_other_player_steam_id
22 ON friends(other_player_steam_id, player_steam_id);
Original file line number Diff line number Diff line change 1+ CREATE INDEX IF NOT EXISTS idx_matches_created_at
2+ ON matches(created_at DESC );
You can’t perform that action at this time.
0 commit comments