-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
site: player: Show first as well as last competition under teams
It's a bit confusing to show only the most-recent competition for a player, especially if they have been rostered for multiple competitions. Show the last-recent competition as well, to give a better overview of how long they have been on the team. Finding the maximal/minimal row is such a pain to do in SQL. Switch from the previous method of using window functions to using a CTE and multiple selects. While window functions work fine for grabbing either the minimum or maximum, they are really terrible for grabbing both (especially when there are NULL rows to ignore. To ensure we don't do a sequential scan on matches, denormalize the first/last scheduled date into competition. Signed-off-by: Sean Anderson <[email protected]>
- Loading branch information
Showing
5 changed files
with
122 additions
and
35 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
BEGIN; | ||
ALTER TABLE competition | ||
ADD scheduled_from BIGINT, | ||
ADD scheduled_to BIGINT, | ||
ADD CHECK (equal(scheduled_from ISNULL, scheduled_to ISNULL)); | ||
CREATE TEMP TABLE new AS SELECT | ||
league, | ||
compid, | ||
min(scheduled) AS scheduled_from, | ||
max(scheduled) AS scheduled_to | ||
FROM match | ||
GROUP BY league, compid; | ||
UPDATE competition AS comp | ||
SET | ||
scheduled_from = new.scheduled_from, | ||
scheduled_to = new.scheduled_to | ||
FROM new | ||
WHERE comp.league = new.league AND comp.compid = new.compid; | ||
COMMIT; |
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
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
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