Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add index of account and reblog to statuses #5785

Merged

Conversation

abcang
Copy link
Contributor

@abcang abcang commented Nov 22, 2017

The following queries are slow, Pawoo may take up to 3 seconds. In addition, this query is called frequently.

SELECT "statuses"."reblog_of_id" FROM "statuses" WHERE "statuses"."reblog_of_id" IN (99046179400728714, 99046176127578155, 99046170926784058, 99046170374900651, 99046153389623869, 99046160265702183, 99046097285901719, 99046080186626998, 99046074205722840, 99045984037260435, 99045983731556084, 99045338921659833, 99045983560245332, 99045335466626882, 99045983350250471, 99045331208338469, 99045908667215211, 99045879652396515, 99045878005639113, 99045861377305786, 99045856694868158, 99045788942898025, 99045781487599457, 99045778259286296) AND "statuses"."account_id" = 1 ORDER BY "statuses"."id" DESC

In this PR, indexes of account_id and reblog_of_id are created. The following explain is the result of my small individual instance execution. index_statuses_on_account_id_and_reblog_of_id is used and the speed is improving. It is considered to be more effective in large instances.

Before

Sort  (cost=122.28..122.29 rows=1 width=16) (actual time=0.150..0.150 rows=0 loops=1)
  Sort Key: id DESC
  Sort Method: quicksort  Memory: 25kB
  ->  Bitmap Heap Scan on statuses  (cost=118.23..122.27 rows=1 width=16) (actual time=0.134..0.134 rows=0 loops=1)
        Recheck Cond: ((account_id = 1) AND (reblog_of_id = ANY ('{99046179400728714,99046176127578155,99046170926784058,99046170374900651,99046153389623869,99046160265702183,99046097285901719,99046080186626998,99046074205722840,99045984037260435,99045983731556084,99045338921659833,99045983560245332,99045335466626882,99045983350250471,99045331208338469,99045908667215211,99045879652396515,99045878005639113,99045861377305786,99045856694868158,99045788942898025,99045781487599457,99045778259286296}'::bigint[])))
        ->  BitmapAnd  (cost=118.23..118.23 rows=1 width=0) (actual time=0.131..0.131 rows=0 loops=1)
              ->  Bitmap Index Scan on index_statuses_on_account_id_id  (cost=0.00..14.60 rows=291 width=0) (actual time=0.080..0.080 rows=290 loops=1)
                    Index Cond: (account_id = 1)
              ->  Bitmap Index Scan on index_statuses_on_reblog_of_id  (cost=0.00..103.38 rows=54 width=0) (actual time=0.039..0.039 rows=9 loops=1)
                    Index Cond: (reblog_of_id = ANY ('{99046179400728714,99046176127578155,99046170926784058,99046170374900651,99046153389623869,99046160265702183,99046097285901719,99046080186626998,99046074205722840,99045984037260435,99045983731556084,99045338921659833,99045983560245332,99045335466626882,99045983350250471,99045331208338469,99045908667215211,99045879652396515,99045878005639113,99045861377305786,99045856694868158,99045788942898025,99045781487599457,99045778259286296}'::bigint[]))
Planning time: 0.301 ms
Execution time: 0.207 ms

After

Sort  (cost=106.28..106.28 rows=1 width=16) (actual time=0.052..0.052 rows=0 loops=1)
  Sort Key: id DESC
  Sort Method: quicksort  Memory: 25kB
  ->  Index Scan using index_statuses_on_account_id_and_reblog_of_id on statuses  (cost=0.42..106.27 rows=1 width=16) (actual time=0.047..0.047 rows=0 loops=1)
        Index Cond: ((account_id = 1) AND (reblog_of_id = ANY ('{99046179400728714,99046176127578155,99046170926784058,99046170374900651,99046153389623869,99046160265702183,99046097285901719,99046080186626998,99046074205722840,99045984037260435,99045983731556084,99045338921659833,99045983560245332,99045335466626882,99045983350250471,99045331208338469,99045908667215211,99045879652396515,99045878005639113,99045861377305786,99045856694868158,99045788942898025,99045781487599457,99045778259286296}'::bigint[])))
Planning time: 0.131 ms
Execution time: 0.076 ms

@ykzts ykzts added the performance Runtime performance label Nov 22, 2017
@abcang abcang force-pushed the add_index_account_and_reblog_of_id_to_statuses branch from 9bd5307 to 486fed8 Compare November 24, 2017 02:31
@Gargron Gargron merged commit a78f66c into mastodon:master Nov 24, 2017
@abcang abcang deleted the add_index_account_and_reblog_of_id_to_statuses branch November 24, 2017 13:42
cobodo pushed a commit to cobodo/mastodon that referenced this pull request Dec 6, 2017
abcang added a commit to pixiv/mastodon that referenced this pull request Dec 18, 2017
abcang added a commit to pixiv/mastodon that referenced this pull request Dec 18, 2017
…og_of_id_to_statuses

Add index of account and reblog to statuses (mastodon#5785)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Runtime performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants