Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Homepage updater fixes #1605

Closed
wants to merge 6 commits into from
Closed

Homepage updater fixes #1605

wants to merge 6 commits into from

Conversation

zbynekwinkler
Copy link
Contributor

I have removed one of the homepage_* tables, split the update query by statements and integrated sentry (ref. #1598, #1601, #1549).

EDIT: I have removed also the other two homepage_* tables. Instead giving and receiving on participants are used. These fields are updated with triggers on tips table. Triggers on update of participants are still missing.

EDIT: Do not run it yet on a production size db. The calculation of giving and receiving for everyone takes forever. Need to look into it more.

The explain for the original query to get new participants:

                                                 QUERY PLAN
------------------------------------------------------------------------------------------------------------
 Limit  (cost=13791.88..13791.91 rows=12 width=19)
   ->  Sort  (cost=13791.88..13843.58 rows=20683 width=19)
         Sort Key: p.claimed_time
         ->  Unique  (cost=13007.48..13110.89 rows=20683 width=19)
               ->  Sort  (cost=13007.48..13059.18 rows=20683 width=19)
                     Sort Key: p.username
                     ->  Hash Join  (cost=1716.85..11524.90 rows=20683 width=19)
                           Hash Cond: (e.participant = p.username)
                           ->  Seq Scan on elsewhere e  (cost=0.00..8570.72 rows=48972 width=11)
                           ->  Hash  (cost=1336.11..1336.11 rows=20699 width=19)
                                 ->  Seq Scan on participants p  (cost=0.00..1336.11 rows=20699 width=19)
                                       Filter: ((claimed_time IS NOT NULL) AND (is_suspicious IS NOT TRUE))

The explain for the updated query with the added index:

                                                     QUERY PLAN
--------------------------------------------------------------------------------------------------------------------
 Limit  (cost=0.00..27.86 rows=12 width=19)
   ->  Nested Loop Semi Join  (cost=0.00..39941.83 rows=17203 width=19)
         ->  Index Scan using participants_claimed_time on participants p  (cost=0.00..3981.65 rows=20699 width=19)
               Index Cond: (claimed_time IS NOT NULL)
         ->  Index Scan using elsewhere_participant on elsewhere e  (cost=0.00..1.87 rows=1 width=11)
               Index Cond: (participant = p.username)

The new query is roughly 80x faster (under 10ms).
Each query by itself is less likely to hit statement_timeout.
Adding .strip() to the queries enables searching through logs
with 'grep postgres duration' to see which queries are over 50ms.
First line of the query can be used for its identification.
In preparation to use trigger to cache the values for easy and fast
lookup. It will eventually allow us to remove the homepage updater
thread.
The new queries with the added indexes execute instantaneously.
Need to add triggers when the participants are updated.
@chadwhitacre
Copy link
Contributor

Reticketed as #1610.

@chadwhitacre chadwhitacre deleted the homepage branch October 21, 2013 21:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants