Trending is very slow

I’m wondering what makes the Trending function to be so slow. Is it the amount of federated servers? Or maybe some of them are too slow? Something else? When I compared my server, https://glan.no to a big server like https://makertube.net/, earlier, the response time wasn’t that big, as far as I remember. Now it is. My server use about 10s compared to about 2s for Makertube. I’m using the Hot as the default trending algorithm.

Is there anything I can tweak to make it go faster?

Enable slow logs on your postgresql server to copy the SQL request that is slow. Then connect to your database using psql, prepend your sql request with explain analyze and paste the output :pray:

                                                                                                                                                                                                                                                                                                                    QUERY PLAN                                                                                                                                                                                                                                                                                                                    
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Incremental Sort  (cost=100826.46..101579.02 rows=630 width=1812) (actual time=11760.699..11763.158 rows=344 loops=1)
   Sort Key: (((((((log((GREATEST(1, (video_1.likes - 1)))::double precision) * '150'::double precision) + (log((GREATEST(1, (video_1.dislikes - 1)))::double precision) * '-150'::double precision)) + (log(((video_1.views + 1))::double precision) * '16'::double precision)) + (log((GREATEST(1, video_1.comments))::double precision) * '100'::double precision)) + ((SubPlan 1))::double precision) + ((power((CASE WHEN ("userVideoHistory_1".id IS NULL) THEN 0 ELSE 1 END)::numeric, 2.0) * '-100'::numeric))::double precision)) DESC, video.views DESC
   Presorted Key: (((((((log((GREATEST(1, (video_1.likes - 1)))::double precision) * '150'::double precision) + (log((GREATEST(1, (video_1.dislikes - 1)))::double precision) * '-150'::double precision)) + (log(((video_1.views + 1))::double precision) * '16'::double precision)) + (log((GREATEST(1, video_1.comments))::double precision) * '100'::double precision)) + ((SubPlan 1))::double precision) + ((power((CASE WHEN ("userVideoHistory_1".id IS NULL) THEN 0 ELSE 1 END)::numeric, 2.0) * '-100'::numeric))::double precision))
   Full-sort Groups: 9  Sort Method: quicksort  Average Memory: 96kB  Peak Memory: 102kB
   ->  Nested Loop Left Join  (cost=100795.45..101555.98 rows=630 width=1812) (actual time=11760.284..11762.481 rows=344 loops=1)
         ->  Nested Loop Left Join  (cost=100795.02..101333.86 rows=309 width=1763) (actual time=11760.243..11761.688 rows=172 loops=1)
               ->  Nested Loop Left Join  (cost=100794.73..101221.13 rows=179 width=1607) (actual time=11760.215..11761.416 rows=70 loops=1)
                     Join Filter: (video.id = "userVideoHistory"."videoId")
                     Rows Removed by Join Filter: 210
                     ->  Nested Loop Left Join  (cost=100794.73..101211.93 rows=179 width=1599) (actual time=11760.175..11761.328 rows=70 loops=1)
                           ->  Nested Loop  (cost=100794.46..101158.39 rows=179 width=1578) (actual time=11760.158..11761.213 rows=70 loops=1)
                                 Join Filter: ("VideoChannel"."accountId" = "VideoChannel->Account".id)
                                 ->  Nested Loop Left Join  (cost=100794.17..101116.34 rows=107 width=1562) (actual time=11760.099..11761.013 rows=70 loops=1)
                                       ->  Nested Loop Left Join  (cost=100793.88..101077.29 rows=62 width=1406) (actual time=11760.064..11760.792 rows=25 loops=1)
                                             ->  Nested Loop  (cost=100793.60..101058.75 rows=62 width=1385) (actual time=11760.040..11760.704 rows=25 loops=1)
                                                   ->  Nested Loop  (cost=100793.31..101050.08 rows=25 width=1310) (actual time=11760.013..11760.589 rows=25 loops=1)
                                                         ->  Nested Loop  (cost=100793.03..101011.35 rows=25 width=1235) (actual time=11759.982..11760.461 rows=25 loops=1)
                                                               ->  Nested Loop  (cost=100792.74..101003.63 rows=25 width=1016) (actual time=11759.938..11760.299 rows=25 loops=1)
                                                                     ->  Limit  (cost=100792.32..100792.38 rows=25 width=20) (actual time=11759.805..11759.853 rows=25 loops=1)
                                                                           ->  Sort  (cost=100792.32..101655.22 rows=345159 width=20) (actual time=11690.301..11690.347 rows=25 loops=1)
                                                                                 Sort Key: (((((((log((GREATEST(1, (video_1.likes - 1)))::double precision) * '150'::double precision) + (log((GREATEST(1, (video_1.dislikes - 1)))::double precision) * '-150'::double precision)) + (log(((video_1.views + 1))::double precision) * '16'::double precision)) + (log((GREATEST(1, video_1.comments))::double precision) * '100'::double precision)) + ((SubPlan 1))::double precision) + ((power((CASE WHEN ("userVideoHistory_1".id IS NULL) THEN 0 ELSE 1 END)::numeric, 2.0) * '-100'::numeric))::double precision)) DESC, video_1.views DESC
                                                                                 Sort Method: top-N heapsort  Memory: 28kB
                                                                                 ->  Hash Join  (cost=10476.58..91052.18 rows=345159 width=20) (actual time=67.247..11673.726 rows=94511 loops=1)
                                                                                       Hash Cond: ("videoChannel".id = "channelActor"."videoChannelId")
                                                                                       Join Filter: (EXISTS(SubPlan 3) OR (video_1.remote IS FALSE))
                                                                                       Rows Removed by Join Filter: 234345
                                                                                       ->  Hash Join  (cost=6340.97..55898.65 rows=279386 width=45) (actual time=48.060..496.707 rows=328856 loops=1)
                                                                                             Hash Cond: (video_1."channelId" = "videoChannel".id)
                                                                                             ->  Hash Left Join  (cost=2.20..45931.19 rows=166969 width=37) (actual time=0.767..351.751 rows=328857 loops=1)
                                                                                                   Hash Cond: (video_1.id = "userVideoHistory_1"."videoId")
                                                                                                   ->  Seq Scan on video video_1  (cost=1.02..45491.72 rows=166969 width=33) (actual time=0.735..286.361 rows=328857 loops=1)
                                                                                                         Filter: (("isLive" IS FALSE) AND (NOT (ANY (id = (hashed SubPlan 2).col1))) AND ((state = 1) OR ((state = 2) AND ("waitTranscoding" IS FALSE))) AND ((privacy = 1) OR (privacy = 4)))
                                                                                                         Rows Removed by Filter: 7402
                                                                                                         SubPlan 2
                                                                                                           ->  Seq Scan on "videoBlacklist"  (cost=0.00..1.02 rows=2 width=4) (actual time=0.266..0.267 rows=2 loops=1)
                                                                                                   ->  Hash  (cost=1.14..1.14 rows=3 width=8) (actual time=0.017..0.018 rows=3 loops=1)
                                                                                                         Buckets: 1024  Batches: 1  Memory Usage: 9kB
                                                                                                         ->  Seq Scan on "userVideoHistory" "userVideoHistory_1"  (cost=0.00..1.14 rows=3 width=8) (actual time=0.012..0.013 rows=3 loops=1)
                                                                                                               Filter: ("userId" = 2)
                                                                                                               Rows Removed by Filter: 8
                                                                                             ->  Hash  (cost=6098.14..6098.14 rows=19251 width=8) (actual time=47.220..47.245 rows=11540 loops=1)
                                                                                                   Buckets: 32768  Batches: 1  Memory Usage: 707kB
                                                                                                   ->  Nested Loop Anti Join  (cost=1806.86..6098.14 rows=19251 width=8) (actual time=14.475..44.583 rows=11540 loops=1)
                                                                                                         Join Filter: ("serverBlocklist"."targetServerId" = "accountActor"."serverId")
                                                                                                         Rows Removed by Join Filter: 11540
                                                                                                         ->  Hash Join  (cost=1806.86..5808.21 rows=19261 width=12) (actual time=14.431..41.651 rows=11541 loops=1)
                                                                                                               Hash Cond: ("accountActor"."accountId" = account.id)
                                                                                                               ->  Seq Scan on actor "accountActor"  (cost=0.00..3780.27 rows=28427 width=12) (actual time=0.007..6.751 rows=28456 loops=1)
                                                                                                               ->  Hash  (cost=1663.16..1663.16 rows=11496 width=12) (actual time=14.364..14.384 rows=11541 loops=1)
                                                                                                                     Buckets: 16384  Batches: 1  Memory Usage: 624kB
                                                                                                                     ->  Hash Anti Join  (cost=884.73..1663.16 rows=11496 width=12) (actual time=4.788..12.743 rows=11541 loops=1)
                                                                                                                           Hash Cond: (account.id = "accountBlocklist"."targetAccountId")
                                                                                                                           ->  Hash Join  (cost=869.74..1503.00 rows=11505 width=12) (actual time=4.693..11.523 rows=11541 loops=1)
                                                                                                                                 Hash Cond: ("videoChannel"."accountId" = account.id)
                                                                                                                                 ->  Seq Scan on "videoChannel"  (cost=0.00..603.05 rows=11505 width=8) (actual time=0.008..3.110 rows=11541 loops=1)
                                                                                                                                 ->  Hash  (cost=657.66..657.66 rows=16966 width=4) (actual time=4.634..4.635 rows=16915 loops=1)
                                                                                                                                       Buckets: 32768  Batches: 1  Memory Usage: 851kB
                                                                                                                                       ->  Seq Scan on account  (cost=0.00..657.66 rows=16966 width=4) (actual time=0.008..2.876 rows=16915 loops=1)
                                                                                                                           ->  Hash  (cost=14.82..14.82 rows=14 width=4) (actual time=0.079..0.094 rows=0 loops=1)
                                                                                                                                 Buckets: 1024  Batches: 1  Memory Usage: 8kB
                                                                                                                                 ->  Bitmap Heap Scan on "accountBlocklist"  (cost=4.26..14.82 rows=14 width=4) (actual time=0.079..0.080 rows=0 loops=1)
                                                                                                                                       Recheck Cond: ("accountId" = ANY ('{1,3}'::integer[]))
                                                                                                                                       ->  Bitmap Index Scan on account_blocklist_account_id_target_account_id  (cost=0.00..4.26 rows=14 width=0) (actual time=0.036..0.036 rows=0 loops=1)
                                                                                                                                             Index Cond: ("accountId" = ANY ('{1,3}'::integer[]))
                                                                                                         ->  Materialize  (cost=0.00..1.02 rows=1 width=4) (actual time=0.000..0.000 rows=1 loops=11541)
                                                                                                               ->  Seq Scan on "serverBlocklist"  (cost=0.00..1.01 rows=1 width=4) (actual time=0.027..0.028 rows=1 loops=1)
                                                                                                                     Filter: ("accountId" = ANY ('{1,3}'::integer[]))
                                                                                       ->  Hash  (cost=3780.27..3780.27 rows=28427 width=8) (actual time=18.859..18.860 rows=11541 loops=1)
                                                                                             Buckets: 32768  Batches: 1  Memory Usage: 707kB
                                                                                             ->  Seq Scan on actor "channelActor"  (cost=0.00..3780.27 rows=28427 width=8) (actual time=0.040..15.629 rows=28456 loops=1)
                                                                                       SubPlan 1
                                                                                         ->  Result  (cost=0.00..0.02 rows=1 width=32) (actual time=0.000..0.000 rows=1 loops=94511)
                                                                                       SubPlan 3
                                                                                         ->  Limit  (cost=9.28..16.61 rows=1 width=4) (actual time=0.033..0.033 rows=0 loops=328856)
                                                                                               ->  Append  (cost=9.28..31.28 rows=3 width=4) (actual time=0.033..0.033 rows=0 loops=328856)
                                                                                                     ->  Hash Join  (cost=9.28..16.62 rows=1 width=4) (actual time=0.020..0.020 rows=0 loops=328856)
                                                                                                           Hash Cond: ("actorFollowShare"."targetActorId" = "videoShare"."actorId")
                                                                                                           ->  Seq Scan on "actorFollow" "actorFollowShare"  (cost=0.00..6.85 rows=96 width=4) (actual time=0.001..0.011 rows=80 loops=326995)
                                                                                                                 Filter: (("actorId" = 1) AND (state = 'accepted'::"enum_actorFollow_state"))
                                                                                                                 Rows Removed by Filter: 100
                                                                                                           ->  Hash  (cost=9.25..9.25 rows=2 width=4) (actual time=0.003..0.003 rows=2 loops=328856)
                                                                                                                 Buckets: 1024  Batches: 1  Memory Usage: 9kB
                                                                                                                 ->  Index Scan using video_share_video_id on "videoShare"  (cost=0.42..9.25 rows=2 width=4) (actual time=0.003..0.003 rows=2 loops=328856)
                                                                                                                       Index Cond: ("videoId" = video_1.id)
                                                                                                     ->  Seq Scan on "actorFollow"  (cost=0.00..7.33 rows=1 width=4) (actual time=0.008..0.008 rows=0 loops=235479)
                                                                                                           Filter: (("targetActorId" = "accountActor".id) AND ("actorId" = 1) AND (state = 'accepted'::"enum_actorFollow_state"))
                                                                                                           Rows Removed by Filter: 190
                                                                                                     ->  Seq Scan on "actorFollow" "actorFollow_1"  (cost=0.00..7.33 rows=1 width=4) (actual time=0.008..0.008 rows=0 loops=234355)
                                                                                                           Filter: (("targetActorId" = "channelActor".id) AND ("actorId" = 1) AND (state = 'accepted'::"enum_actorFollow_state"))
                                                                                                           Rows Removed by Filter: 190
                                                                     ->  Index Scan using video_pkey on video  (cost=0.42..8.44 rows=1 width=1008) (actual time=0.014..0.014 rows=1 loops=25)
                                                                           Index Cond: (id = video_1.id)
                                                               ->  Index Scan using "videoChannel_pkey" on "videoChannel" "VideoChannel"  (cost=0.29..0.31 rows=1 width=219) (actual time=0.006..0.006 rows=1 loops=25)
                                                                     Index Cond: (id = video."channelId")
                                                         ->  Index Scan using actor_account_id on actor "VideoChannel->Account->Actor"  (cost=0.29..1.55 rows=1 width=75) (actual time=0.004..0.004 rows=1 loops=25)
                                                               Index Cond: ("accountId" = "VideoChannel"."accountId")
                                                   ->  Index Scan using actor_video_channel_id on actor "VideoChannel->Actor"  (cost=0.29..0.35 rows=1 width=75) (actual time=0.003..0.003 rows=1 loops=25)
                                                         Index Cond: ("videoChannelId" = video."channelId")
                                             ->  Index Scan using server_pkey on server "VideoChannel->Actor->Server"  (cost=0.28..0.30 rows=1 width=21) (actual time=0.002..0.002 rows=1 loops=25)
                                                   Index Cond: (id = "VideoChannel->Actor"."serverId")
                                       ->  Index Scan using actor_image_actor_id_type_width on "actorImage" "VideoChannel->Actor->Avatars"  (cost=0.29..0.60 rows=3 width=160) (actual time=0.005..0.007 rows=3 loops=25)
                                             Index Cond: (("actorId" = "VideoChannel->Actor".id) AND (type = 1))
                                 ->  Index Scan using account_pkey on account "VideoChannel->Account"  (cost=0.29..0.38 rows=1 width=16) (actual time=0.002..0.002 rows=1 loops=70)
                                       Index Cond: (id = "VideoChannel->Account->Actor"."accountId")
                           ->  Index Scan using server_pkey on server "VideoChannel->Account->Actor->Server"  (cost=0.28..0.30 rows=1 width=21) (actual time=0.001..0.001 rows=1 loops=70)
                                 Index Cond: (id = "VideoChannel->Account->Actor"."serverId")
                     ->  Materialize  (cost=0.00..1.15 rows=3 width=12) (actual time=0.000..0.001 rows=3 loops=70)
                           ->  Seq Scan on "userVideoHistory"  (cost=0.00..1.14 rows=3 width=12) (actual time=0.023..0.024 rows=3 loops=1)
                                 Filter: ("userId" = 2)
                                 Rows Removed by Filter: 8
               ->  Index Scan using actor_image_actor_id_type_width on "actorImage" "VideoChannel->Account->Actor->Avatars"  (cost=0.29..0.60 rows=3 width=160) (actual time=0.002..0.003 rows=2 loops=70)
                     Index Cond: (("actorId" = "VideoChannel->Account->Actor".id) AND (type = 1))
         ->  Index Scan using thumbnail_video_id on thumbnail "Thumbnails"  (cost=0.42..0.70 rows=2 width=53) (actual time=0.003..0.004 rows=2 loops=172)
               Index Cond: ("videoId" = video.id)
 Planning Time: 18.355 ms
 JIT:
   Functions: 169
   Options: Inlining false, Optimization false, Expressions true, Deforming true
   Timing: Generation 11.136 ms (Deform 3.016 ms), Inlining 0.000 ms, Optimization 7.473 ms, Emission 62.654 ms, Total 81.263 ms
 Execution Time: 11774.986 ms
(120 rader)


Thank you, can you test:

explain analyze SELECT
  "video".*,
  "VideoChannel"."id" AS "VideoChannel.id",
  "VideoChannel"."name" AS "VideoChannel.name",
  "VideoChannel"."description" AS "VideoChannel.description",
  "VideoChannel"."accountId" AS "VideoChannel.accountId",
  "VideoChannel->Actor"."id" AS "VideoChannel.Actor.id",
  "VideoChannel->Actor"."preferredUsername" AS "VideoChannel.Actor.preferredUsername",
  "VideoChannel->Actor"."url" AS "VideoChannel.Actor.url",
  "VideoChannel->Actor"."serverId" AS "VideoChannel.Actor.serverId",
  "VideoChannel->Actor"."accountId" AS "VideoChannel.Actor.accountId",
  "VideoChannel->Actor"."videoChannelId" AS "VideoChannel.Actor.videoChannelId",
  "VideoChannel->Actor->Avatars"."id" AS "VideoChannel.Actor.Avatars.id",
  "VideoChannel->Actor->Avatars"."width" AS "VideoChannel.Actor.Avatars.width",
  "VideoChannel->Actor->Avatars"."filename" AS "VideoChannel.Actor.Avatars.filename",
  "VideoChannel->Actor->Avatars"."type" AS "VideoChannel.Actor.Avatars.type",
  "VideoChannel->Actor->Avatars"."fileUrl" AS "VideoChannel.Actor.Avatars.fileUrl",
  "VideoChannel->Actor->Avatars"."cached" AS "VideoChannel.Actor.Avatars.cached",
  "VideoChannel->Actor->Avatars"."createdAt" AS "VideoChannel.Actor.Avatars.createdAt",
  "VideoChannel->Actor->Avatars"."updatedAt" AS "VideoChannel.Actor.Avatars.updatedAt",
  "VideoChannel->Actor->Server"."id" AS "VideoChannel.Actor.Server.id",
  "VideoChannel->Actor->Server"."host" AS "VideoChannel.Actor.Server.host",
  "VideoChannel->Account"."id" AS "VideoChannel.Account.id",
  "VideoChannel->Account"."name" AS "VideoChannel.Account.name",
  "VideoChannel->Account->Actor"."id" AS "VideoChannel.Account.Actor.id",
  "VideoChannel->Account->Actor"."preferredUsername" AS "VideoChannel.Account.Actor.preferredUsername",
  "VideoChannel->Account->Actor"."url" AS "VideoChannel.Account.Actor.url",
  "VideoChannel->Account->Actor"."serverId" AS "VideoChannel.Account.Actor.serverId",
  "VideoChannel->Account->Actor"."accountId" AS "VideoChannel.Account.Actor.accountId",
  "VideoChannel->Account->Actor"."videoChannelId" AS "VideoChannel.Account.Actor.videoChannelId",
  "VideoChannel->Account->Actor->Avatars"."id" AS "VideoChannel.Account.Actor.Avatars.id",
  "VideoChannel->Account->Actor->Avatars"."width" AS "VideoChannel.Account.Actor.Avatars.width",
  "VideoChannel->Account->Actor->Avatars"."filename" AS "VideoChannel.Account.Actor.Avatars.filename",
  "VideoChannel->Account->Actor->Avatars"."type" AS "VideoChannel.Account.Actor.Avatars.type",
  "VideoChannel->Account->Actor->Avatars"."fileUrl" AS "VideoChannel.Account.Actor.Avatars.fileUrl",
  "VideoChannel->Account->Actor->Avatars"."cached" AS "VideoChannel.Account.Actor.Avatars.cached",
  "VideoChannel->Account->Actor->Avatars"."createdAt" AS "VideoChannel.Account.Actor.Avatars.createdAt",
  "VideoChannel->Account->Actor->Avatars"."updatedAt" AS "VideoChannel.Account.Actor.Avatars.updatedAt",
  "VideoChannel->Account->Actor->Server"."id" AS "VideoChannel.Account.Actor.Server.id",
  "VideoChannel->Account->Actor->Server"."host" AS "VideoChannel.Account.Actor.Server.host",
  "Thumbnails"."id" AS "Thumbnails.id",
  "Thumbnails"."filename" AS "Thumbnails.filename",
  "Thumbnails"."height" AS "Thumbnails.height",
  "Thumbnails"."width" AS "Thumbnails.width",
  "Thumbnails"."fileUrl" AS "Thumbnails.fileUrl"
FROM
  (
    WITH "videoCandidates" AS (
      SELECT
        "videoShare"."videoId"
      FROM
        "videoShare"
      WHERE
        "videoShare"."actorId" IN (
          SELECT
            "targetActorId"
          FROM
            "actorFollow"
          WHERE
            "actorFollow"."actorId" = 1
            AND "actorFollow"."state" = 'accepted'
        )
      UNION
      SELECT
        "video"."id"
      FROM
        "video"
        INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId"
        INNER JOIN "actor" "channelActor" ON "videoChannel"."id" = "channelActor"."videoChannelId"
      WHERE
        "channelActor"."id" IN (
          SELECT
            "targetActorId"
          FROM
            "actorFollow"
          WHERE
            "actorFollow"."actorId" = 1
            AND "actorFollow"."state" = 'accepted'
        )
      UNION
      SELECT
        "video"."id"
      FROM
        "video"
        INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId"
        INNER JOIN "account" ON "account"."id" = "videoChannel"."accountId"
        INNER JOIN "actor" "accountActor" ON "account"."id" = "accountActor"."accountId"
      WHERE
        "accountActor"."id" IN (
          SELECT
            "targetActorId"
          FROM
            "actorFollow"
          WHERE
            "actorFollow"."actorId" = 1
            AND "actorFollow"."state" = 'accepted'
        )
      UNION
      SELECT
        "video"."id"
      FROM
        "video"
      WHERE
        "remote" IS FALSE
    )
    SELECT
      "video"."id",
      LOG(GREATEST(1, "video"."likes" - 1)) * 150 + LOG(GREATEST(1, "video"."dislikes" - 1)) * -150 + LOG("video"."views" + 1) * 16 + LOG(GREATEST(1, "video"."comments")) * 100 + (
        SELECT
          (
            EXTRACT(
              epoch
              FROM
                "video"."publishedAt"
            ) - 1446156582
          ) / 47000
      ) AS "score",
      0 as similarity
    FROM
      "video"
      INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId"
      INNER JOIN "account" ON "account"."id" = "videoChannel"."accountId"
      INNER JOIN "actor" "accountActor" ON "account"."id" = "accountActor"."accountId"
      INNER JOIN "videoCandidates" ON "video"."id" = "videoCandidates"."videoId"
    WHERE
      "video"."id" NOT IN (
        SELECT
          "videoBlacklist"."videoId"
        FROM
          "videoBlacklist"
      )
      AND NOT EXISTS (
        SELECT
          1
        FROM
          "accountBlocklist"
        WHERE
          "accountBlocklist"."accountId" IN ('1')
          AND "accountBlocklist"."targetAccountId" = "account"."id"
      )
      AND NOT EXISTS (
        SELECT
          1
        FROM
          "serverBlocklist"
        WHERE
          "serverBlocklist"."accountId" IN ('1')
          AND "serverBlocklist"."targetServerId" = "accountActor"."serverId"
      )
      AND (
        "video"."state" = 1
        OR (
          "video"."state" = 2
          AND "video"."waitTranscoding" IS false
        )
      )
      AND "video"."privacy" = 1
      AND "video"."isLive" IS FALSE
    ORDER BY
      "score" DESC,
      "video"."views" DESC
    LIMIT
      25 OFFSET 0
  ) AS "tmp"
  INNER JOIN "video" ON "tmp"."id" = "video"."id"
  INNER JOIN "videoChannel" AS "VideoChannel" ON "video"."channelId" = "VideoChannel"."id"
  INNER JOIN "actor" AS "VideoChannel->Actor" ON "VideoChannel"."id" = "VideoChannel->Actor"."videoChannelId"
  LEFT OUTER JOIN "server" AS "VideoChannel->Actor->Server" ON "VideoChannel->Actor"."serverId" = "VideoChannel->Actor->Server"."id"
  LEFT OUTER JOIN "actorImage" AS "VideoChannel->Actor->Avatars" ON "VideoChannel->Actor"."id" = "VideoChannel->Actor->Avatars"."actorId"
  AND "VideoChannel->Actor->Avatars"."type" = 1
  INNER JOIN "account" AS "VideoChannel->Account" ON "VideoChannel"."accountId" = "VideoChannel->Account"."id"
  INNER JOIN "actor" AS "VideoChannel->Account->Actor" ON "VideoChannel->Account"."id" = "VideoChannel->Account->Actor"."accountId"
  LEFT OUTER JOIN "server" AS "VideoChannel->Account->Actor->Server" ON "VideoChannel->Account->Actor"."serverId" = "VideoChannel->Account->Actor->Server"."id"
  LEFT OUTER JOIN "actorImage" AS "VideoChannel->Account->Actor->Avatars" ON "VideoChannel->Account->Actor"."id" = "VideoChannel->Account->Actor->Avatars"."actorId"
  AND "VideoChannel->Account->Actor->Avatars"."type" = 1
  LEFT OUTER JOIN "thumbnail" AS "Thumbnails" ON "video"."id" = "Thumbnails"."videoId"
ORDER BY
  "score" DESC,
  "video"."views" DESC

I get the following error from that:
ERROR: column VideoChannel->Actor->Avatars.cached does not exist
LINE 18: « VideoChannel->Actor->Avatars ».« cached » AS "VideoChannel.A…
^

Sorry, try:

explain analyze SELECT
  "video".*,
  "VideoChannel"."id" AS "VideoChannel.id",
  "VideoChannel"."name" AS "VideoChannel.name",
  "VideoChannel"."description" AS "VideoChannel.description",
  "VideoChannel"."accountId" AS "VideoChannel.accountId",
  "VideoChannel->Actor"."id" AS "VideoChannel.Actor.id",
  "VideoChannel->Actor"."preferredUsername" AS "VideoChannel.Actor.preferredUsername",
  "VideoChannel->Actor"."url" AS "VideoChannel.Actor.url",
  "VideoChannel->Actor"."serverId" AS "VideoChannel.Actor.serverId",
  "VideoChannel->Actor"."accountId" AS "VideoChannel.Actor.accountId",
  "VideoChannel->Actor"."videoChannelId" AS "VideoChannel.Actor.videoChannelId",
  "VideoChannel->Actor->Avatars"."id" AS "VideoChannel.Actor.Avatars.id",
  "VideoChannel->Actor->Avatars"."width" AS "VideoChannel.Actor.Avatars.width",
  "VideoChannel->Actor->Avatars"."filename" AS "VideoChannel.Actor.Avatars.filename",
  "VideoChannel->Actor->Avatars"."type" AS "VideoChannel.Actor.Avatars.type",
  "VideoChannel->Actor->Avatars"."fileUrl" AS "VideoChannel.Actor.Avatars.fileUrl",
  "VideoChannel->Actor->Avatars"."createdAt" AS "VideoChannel.Actor.Avatars.createdAt",
  "VideoChannel->Actor->Avatars"."updatedAt" AS "VideoChannel.Actor.Avatars.updatedAt",
  "VideoChannel->Actor->Server"."id" AS "VideoChannel.Actor.Server.id",
  "VideoChannel->Actor->Server"."host" AS "VideoChannel.Actor.Server.host",
  "VideoChannel->Account"."id" AS "VideoChannel.Account.id",
  "VideoChannel->Account"."name" AS "VideoChannel.Account.name",
  "VideoChannel->Account->Actor"."id" AS "VideoChannel.Account.Actor.id",
  "VideoChannel->Account->Actor"."preferredUsername" AS "VideoChannel.Account.Actor.preferredUsername",
  "VideoChannel->Account->Actor"."url" AS "VideoChannel.Account.Actor.url",
  "VideoChannel->Account->Actor"."serverId" AS "VideoChannel.Account.Actor.serverId",
  "VideoChannel->Account->Actor"."accountId" AS "VideoChannel.Account.Actor.accountId",
  "VideoChannel->Account->Actor"."videoChannelId" AS "VideoChannel.Account.Actor.videoChannelId",
  "VideoChannel->Account->Actor->Avatars"."id" AS "VideoChannel.Account.Actor.Avatars.id",
  "VideoChannel->Account->Actor->Avatars"."width" AS "VideoChannel.Account.Actor.Avatars.width",
  "VideoChannel->Account->Actor->Avatars"."filename" AS "VideoChannel.Account.Actor.Avatars.filename",
  "VideoChannel->Account->Actor->Avatars"."type" AS "VideoChannel.Account.Actor.Avatars.type",
  "VideoChannel->Account->Actor->Avatars"."fileUrl" AS "VideoChannel.Account.Actor.Avatars.fileUrl",
  "VideoChannel->Account->Actor->Avatars"."createdAt" AS "VideoChannel.Account.Actor.Avatars.createdAt",
  "VideoChannel->Account->Actor->Avatars"."updatedAt" AS "VideoChannel.Account.Actor.Avatars.updatedAt",
  "VideoChannel->Account->Actor->Server"."id" AS "VideoChannel.Account.Actor.Server.id",
  "VideoChannel->Account->Actor->Server"."host" AS "VideoChannel.Account.Actor.Server.host",
  "Thumbnails"."id" AS "Thumbnails.id",
  "Thumbnails"."filename" AS "Thumbnails.filename",
  "Thumbnails"."height" AS "Thumbnails.height",
  "Thumbnails"."width" AS "Thumbnails.width",
  "Thumbnails"."fileUrl" AS "Thumbnails.fileUrl"
FROM
  (
    WITH "videoCandidates" AS (
      SELECT
        "videoShare"."videoId"
      FROM
        "videoShare"
      WHERE
        "videoShare"."actorId" IN (
          SELECT
            "targetActorId"
          FROM
            "actorFollow"
          WHERE
            "actorFollow"."actorId" = 1
            AND "actorFollow"."state" = 'accepted'
        )
      UNION
      SELECT
        "video"."id"
      FROM
        "video"
        INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId"
        INNER JOIN "actor" "channelActor" ON "videoChannel"."id" = "channelActor"."videoChannelId"
      WHERE
        "channelActor"."id" IN (
          SELECT
            "targetActorId"
          FROM
            "actorFollow"
          WHERE
            "actorFollow"."actorId" = 1
            AND "actorFollow"."state" = 'accepted'
        )
      UNION
      SELECT
        "video"."id"
      FROM
        "video"
        INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId"
        INNER JOIN "account" ON "account"."id" = "videoChannel"."accountId"
        INNER JOIN "actor" "accountActor" ON "account"."id" = "accountActor"."accountId"
      WHERE
        "accountActor"."id" IN (
          SELECT
            "targetActorId"
          FROM
            "actorFollow"
          WHERE
            "actorFollow"."actorId" = 1
            AND "actorFollow"."state" = 'accepted'
        )
      UNION
      SELECT
        "video"."id"
      FROM
        "video"
      WHERE
        "remote" IS FALSE
    )
    SELECT
      "video"."id",
      LOG(GREATEST(1, "video"."likes" - 1)) * 150 + LOG(GREATEST(1, "video"."dislikes" - 1)) * -150 + LOG("video"."views" + 1) * 16 + LOG(GREATEST(1, "video"."comments")) * 100 + (
        SELECT
          (
            EXTRACT(
              epoch
              FROM
                "video"."publishedAt"
            ) - 1446156582
          ) / 47000
      ) AS "score",
      0 as similarity
    FROM
      "video"
      INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId"
      INNER JOIN "account" ON "account"."id" = "videoChannel"."accountId"
      INNER JOIN "actor" "accountActor" ON "account"."id" = "accountActor"."accountId"
      INNER JOIN "videoCandidates" ON "video"."id" = "videoCandidates"."videoId"
    WHERE
      "video"."id" NOT IN (
        SELECT
          "videoBlacklist"."videoId"
        FROM
          "videoBlacklist"
      )
      AND NOT EXISTS (
        SELECT
          1
        FROM
          "accountBlocklist"
        WHERE
          "accountBlocklist"."accountId" IN ('1')
          AND "accountBlocklist"."targetAccountId" = "account"."id"
      )
      AND NOT EXISTS (
        SELECT
          1
        FROM
          "serverBlocklist"
        WHERE
          "serverBlocklist"."accountId" IN ('1')
          AND "serverBlocklist"."targetServerId" = "accountActor"."serverId"
      )
      AND (
        "video"."state" = 1
        OR (
          "video"."state" = 2
          AND "video"."waitTranscoding" IS false
        )
      )
      AND "video"."privacy" = 1
      AND "video"."isLive" IS FALSE
    ORDER BY
      "score" DESC,
      "video"."views" DESC
    LIMIT
      25 OFFSET 0
  ) AS "tmp"
  INNER JOIN "video" ON "tmp"."id" = "video"."id"
  INNER JOIN "videoChannel" AS "VideoChannel" ON "video"."channelId" = "VideoChannel"."id"
  INNER JOIN "actor" AS "VideoChannel->Actor" ON "VideoChannel"."id" = "VideoChannel->Actor"."videoChannelId"
  LEFT OUTER JOIN "server" AS "VideoChannel->Actor->Server" ON "VideoChannel->Actor"."serverId" = "VideoChannel->Actor->Server"."id"
  LEFT OUTER JOIN "actorImage" AS "VideoChannel->Actor->Avatars" ON "VideoChannel->Actor"."id" = "VideoChannel->Actor->Avatars"."actorId"
  AND "VideoChannel->Actor->Avatars"."type" = 1
  INNER JOIN "account" AS "VideoChannel->Account" ON "VideoChannel"."accountId" = "VideoChannel->Account"."id"
  INNER JOIN "actor" AS "VideoChannel->Account->Actor" ON "VideoChannel->Account"."id" = "VideoChannel->Account->Actor"."accountId"
  LEFT OUTER JOIN "server" AS "VideoChannel->Account->Actor->Server" ON "VideoChannel->Account->Actor"."serverId" = "VideoChannel->Account->Actor->Server"."id"
  LEFT OUTER JOIN "actorImage" AS "VideoChannel->Account->Actor->Avatars" ON "VideoChannel->Account->Actor"."id" = "VideoChannel->Account->Actor->Avatars"."actorId"
  AND "VideoChannel->Account->Actor->Avatars"."type" = 1
  LEFT OUTER JOIN "thumbnail" AS "Thumbnails" ON "video"."id" = "Thumbnails"."videoId"
ORDER BY
  "score" DESC,
  "video"."views" DESC
                                                                                                                                                                                                                                                QUERY PLAN                                                                                                                                                                                                                                                 
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Incremental Sort  (cost=115684.69..116431.10 rows=644 width=1920) (actual time=813.617..816.074 rows=344 loops=1)
   Sort Key: ((((((log((GREATEST(1, (video_1.likes - 1)))::double precision) * '150'::double precision) + (log((GREATEST(1, (video_1.dislikes - 1)))::double precision) * '-150'::double precision)) + (log(((video_1.views + 1))::double precision) * '16'::double precision)) + (log((GREATEST(1, video_1.comments))::double precision) * '100'::double precision)) + ((SubPlan 1))::double precision)) DESC, video.views DESC
   Presorted Key: ((((((log((GREATEST(1, (video_1.likes - 1)))::double precision) * '150'::double precision) + (log((GREATEST(1, (video_1.dislikes - 1)))::double precision) * '-150'::double precision)) + (log(((video_1.views + 1))::double precision) * '16'::double precision)) + (log((GREATEST(1, video_1.comments))::double precision) * '100'::double precision)) + ((SubPlan 1))::double precision))
   Full-sort Groups: 9  Sort Method: quicksort  Average Memory: 112kB  Peak Memory: 121kB
   ->  Nested Loop Left Join  (cost=115653.95..116407.46 rows=644 width=1920) (actual time=813.236..815.410 rows=344 loops=1)
         ->  Nested Loop Left Join  (cost=115653.52..116183.28 rows=310 width=1779) (actual time=813.190..814.645 rows=172 loops=1)
               ->  Nested Loop Left Join  (cost=115653.23..116070.47 rows=179 width=1624) (actual time=813.171..814.404 rows=70 loops=1)
                     ->  Nested Loop  (cost=115652.95..116016.94 rows=179 width=1603) (actual time=813.142..814.277 rows=70 loops=1)
                           Join Filter: ("VideoChannel"."accountId" = "VideoChannel->Account".id)
                           ->  Nested Loop Left Join  (cost=115652.67..115974.88 rows=107 width=1587) (actual time=813.115..814.107 rows=70 loops=1)
                                 ->  Nested Loop Left Join  (cost=115652.38..115935.81 rows=62 width=1432) (actual time=813.060..813.892 rows=25 loops=1)
                                       ->  Nested Loop  (cost=115652.10..115917.27 rows=62 width=1411) (actual time=813.036..813.818 rows=25 loops=1)
                                             ->  Nested Loop  (cost=115651.81..115908.58 rows=25 width=1336) (actual time=813.013..813.725 rows=25 loops=1)
                                                   ->  Nested Loop  (cost=115651.52..115869.85 rows=25 width=1261) (actual time=812.987..813.624 rows=25 loops=1)
                                                         ->  Nested Loop  (cost=115651.24..115862.13 rows=25 width=1042) (actual time=812.961..813.515 rows=25 loops=1)
                                                               ->  Limit  (cost=115650.82..115650.88 rows=25 width=20) (actual time=812.853..813.194 rows=25 loops=1)
                                                                     ->  Sort  (cost=115650.82..115689.72 rows=15560 width=20) (actual time=747.197..747.535 rows=25 loops=1)
                                                                           Sort Key: ((((((log((GREATEST(1, (video_1.likes - 1)))::double precision) * '150'::double precision) + (log((GREATEST(1, (video_1.dislikes - 1)))::double precision) * '-150'::double precision)) + (log(((video_1.views + 1))::double precision) * '16'::double precision)) + (log((GREATEST(1, video_1.comments))::double precision) * '100'::double precision)) + ((SubPlan 1))::double precision)) DESC, video_1.views DESC
                                                                           Sort Method: top-N heapsort  Memory: 27kB
                                                                           ->  Hash Anti Join  (cost=68472.91..115211.72 rows=15560 width=20) (actual time=234.348..733.240 rows=94578 loops=1)
                                                                                 Hash Cond: (account.id = "accountBlocklist"."targetAccountId")
                                                                                 ->  Hash Join  (cost=68458.47..113833.82 rows=15566 width=32) (actual time=234.176..632.697 rows=94578 loops=1)
                                                                                       Hash Cond: ("videoChannel"."accountId" = account.id)
                                                                                       ->  Nested Loop Anti Join  (cost=67588.74..112939.69 rows=9290 width=36) (actual time=228.363..604.977 rows=94578 loops=1)
                                                                                             Join Filter: ("serverBlocklist"."targetServerId" = "accountActor"."serverId")
                                                                                             Rows Removed by Join Filter: 94578
                                                                                             ->  Hash Join  (cost=67588.74..112799.25 rows=9295 width=40) (actual time=228.300..579.004 rows=94578 loops=1)
                                                                                                   Hash Cond: ("videoChannel"."accountId" = "accountActor"."accountId")
                                                                                                   ->  Hash Join  (cost=63453.13..108639.24 rows=9295 width=32) (actual time=199.874..528.673 rows=94578 loops=1)
                                                                                                         Hash Cond: (video_1."channelId" = "videoChannel".id)
                                                                                                         ->  Hash Join  (cost=62706.27..107867.97 rows=9295 width=32) (actual time=195.196..501.307 rows=94578 loops=1)
                                                                                                               Hash Cond: (video_1.id = "videoShare"."videoId")
                                                                                                               ->  Seq Scan on video video_1  (cost=1.02..44731.72 rows=164190 width=32) (actual time=0.712..173.460 rows=328961 loops=1)
                                                                                                                     Filter: (("isLive" IS FALSE) AND (NOT (ANY (id = (hashed SubPlan 2).col1))) AND (privacy = 1) AND ((state = 1) OR ((state = 2) AND ("waitTranscoding" IS FALSE))))
                                                                                                                     Rows Removed by Filter: 7377
                                                                                                                     SubPlan 2
                                                                                                                       ->  Seq Scan on "videoBlacklist"  (cost=0.00..1.02 rows=2 width=4) (actual time=0.288..0.289 rows=3 loops=1)
                                                                                                               ->  Hash  (cost=62467.24..62467.24 rows=19040 width=4) (actual time=194.216..194.533 rows=95048 loops=1)
                                                                                                                     Buckets: 131072 (originally 32768)  Batches: 1 (originally 1)  Memory Usage: 4366kB
                                                                                                                     ->  HashAggregate  (cost=62276.84..62467.24 rows=19040 width=4) (actual time=161.086..182.122 rows=95048 loops=1)
                                                                                                                           Group Key: "videoShare"."videoId"
                                                                                                                           Batches: 1  Memory Usage: 6929kB
                                                                                                                           ->  Append  (cost=1008.18..62229.24 rows=19040 width=4) (actual time=0.782..131.617 rows=96252 loops=1)
                                                                                                                                 ->  Gather  (cost=1008.18..18495.03 rows=14221 width=4) (actual time=0.780..54.654 rows=93873 loops=1)
                                                                                                                                       Workers Planned: 2
                                                                                                                                       Workers Launched: 2
                                                                                                                                       ->  Hash Join  (cost=8.18..16072.93 rows=5925 width=4) (actual time=5.889..50.551 rows=31291 loops=3)
                                                                                                                                             Hash Cond: ("videoShare"."actorId" = "actorFollow"."targetActorId")
                                                                                                                                             ->  Parallel Seq Scan on "videoShare"  (cost=0.00..15341.33 rows=275333 width=8) (actual time=0.031..26.394 rows=217076 loops=3)
                                                                                                                                             ->  Hash  (cost=6.96..6.96 rows=98 width=4) (actual time=5.700..5.702 rows=88 loops=3)
                                                                                                                                                   Buckets: 1024  Batches: 1  Memory Usage: 12kB
                                                                                                                                                   ->  Seq Scan on "actorFollow"  (cost=0.00..6.96 rows=98 width=4) (actual time=5.623..5.675 rows=88 loops=3)
                                                                                                                                                         Filter: (("actorId" = 1) AND (state = 'accepted'::"enum_actorFollow_state"))
                                                                                                                                                         Rows Removed by Filter: 110
                                                                                                                                 ->  Nested Loop  (cost=1.00..1485.71 rows=2865 width=4) (actual time=0.194..3.032 rows=1175 loops=1)
                                                                                                                                       Join Filter: ("videoChannel_1".id = video_2."channelId")
                                                                                                                                       ->  Nested Loop  (cost=0.58..717.50 rows=98 width=8) (actual time=0.161..0.640 rows=18 loops=1)
                                                                                                                                             ->  Nested Loop  (cost=0.30..683.44 rows=98 width=4) (actual time=0.118..0.526 rows=88 loops=1)
                                                                                                                                                   ->  Seq Scan on "actorFollow" "actorFollow_1"  (cost=0.00..6.96 rows=98 width=4) (actual time=0.060..0.087 rows=88 loops=1)
                                                                                                                                                         Filter: (("actorId" = 1) AND (state = 'accepted'::"enum_actorFollow_state"))
                                                                                                                                                         Rows Removed by Filter: 110
                                                                                                                                                   ->  Memoize  (cost=0.30..7.25 rows=1 width=8) (actual time=0.005..0.005 rows=1 loops=88)
                                                                                                                                                         Cache Key: "actorFollow_1"."targetActorId"
                                                                                                                                                         Cache Mode: logical
                                                                                                                                                         Hits: 0  Misses: 88  Evictions: 0  Overflows: 0  Memory Usage: 10kB
                                                                                                                                                         ->  Index Scan using actor_pkey on actor "channelActor"  (cost=0.29..7.24 rows=1 width=8) (actual time=0.004..0.004 rows=1 loops=88)
                                                                                                                                                               Index Cond: (id = "actorFollow_1"."targetActorId")
                                                                                                                                             ->  Index Only Scan using "videoChannel_pkey" on "videoChannel" "videoChannel_1"  (cost=0.29..0.35 rows=1 width=4) (actual time=0.001..0.001 rows=0 loops=88)
                                                                                                                                                   Index Cond: (id = "channelActor"."videoChannelId")
                                                                                                                                                   Heap Fetches: 16
                                                                                                                                       ->  Index Scan using video_channel_id on video video_2  (cost=0.42..7.01 rows=66 width=8) (actual time=0.008..0.108 rows=65 loops=18)
                                                                                                                                             Index Cond: ("channelId" = "channelActor"."videoChannelId")
                                                                                                                                 ->  Nested Loop  (cost=1.29..1746.81 rows=1943 width=4) (actual time=0.212..2.954 rows=1192 loops=1)
                                                                                                                                       Join Filter: ("videoChannel_2"."accountId" = account_1.id)
                                                                                                                                       ->  Nested Loop  (cost=1.00..1348.01 rows=1159 width=12) (actual time=0.194..2.004 rows=1192 loops=1)
                                                                                                                                             ->  Nested Loop  (cost=0.58..721.21 rows=40 width=12) (actual time=0.179..0.540 rows=25 loops=1)
                                                                                                                                                   ->  Nested Loop  (cost=0.30..683.44 rows=98 width=4) (actual time=0.061..0.364 rows=88 loops=1)
                                                                                                                                                         ->  Seq Scan on "actorFollow" "actorFollow_2"  (cost=0.00..6.96 rows=98 width=4) (actual time=0.035..0.055 rows=88 loops=1)
                                                                                                                                                               Filter: (("actorId" = 1) AND (state = 'accepted'::"enum_actorFollow_state"))
                                                                                                                                                               Rows Removed by Filter: 110
                                                                                                                                                         ->  Memoize  (cost=0.30..7.25 rows=1 width=8) (actual time=0.003..0.003 rows=1 loops=88)
                                                                                                                                                               Cache Key: "actorFollow_2"."targetActorId"
                                                                                                                                                               Cache Mode: logical
                                                                                                                                                               Hits: 0  Misses: 88  Evictions: 0  Overflows: 0  Memory Usage: 10kB
                                                                                                                                                               ->  Index Scan using actor_pkey on actor "accountActor_1"  (cost=0.29..7.24 rows=1 width=8) (actual time=0.003..0.003 rows=1 loops=88)
                                                                                                                                                                     Index Cond: (id = "actorFollow_2"."targetActorId")
                                                                                                                                                   ->  Index Scan using video_channel_account_id on "videoChannel" "videoChannel_2"  (cost=0.29..0.38 rows=1 width=8) (actual time=0.002..0.002 rows=0 loops=88)
                                                                                                                                                         Index Cond: ("accountId" = "accountActor_1"."accountId")
                                                                                                                                             ->  Index Scan using video_channel_id on video video_3  (cost=0.42..15.01 rows=66 width=8) (actual time=0.004..0.054 rows=48 loops=25)
                                                                                                                                                   Index Cond: ("channelId" = "videoChannel_2".id)
                                                                                                                                       ->  Index Only Scan using account_pkey on account account_1  (cost=0.29..0.33 rows=1 width=4) (actual time=0.001..0.001 rows=1 loops=1192)
                                                                                                                                             Index Cond: (id = "accountActor_1"."accountId")
                                                                                                                                             Heap Fetches: 489
                                                                                                                                 ->  Gather  (cost=1000.00..40406.50 rows=11 width=4) (actual time=2.822..64.085 rows=12 loops=1)
                                                                                                                                       Workers Planned: 2
                                                                                                                                       Workers Launched: 2
                                                                                                                                       ->  Parallel Seq Scan on video video_4  (cost=0.00..39405.40 rows=5 width=4) (actual time=8.220..46.665 rows=4 loops=3)
                                                                                                                                             Filter: (remote IS FALSE)
                                                                                                                                             Rows Removed by Filter: 112109
                                                                                                         ->  Hash  (cost=603.05..603.05 rows=11505 width=8) (actual time=4.633..4.634 rows=11550 loops=1)
                                                                                                               Buckets: 16384  Batches: 1  Memory Usage: 580kB
                                                                                                               ->  Seq Scan on "videoChannel"  (cost=0.00..603.05 rows=11505 width=8) (actual time=0.070..3.484 rows=11550 loops=1)
                                                                                                   ->  Hash  (cost=3780.27..3780.27 rows=28427 width=8) (actual time=28.309..28.310 rows=16932 loops=1)
                                                                                                         Buckets: 32768  Batches: 1  Memory Usage: 918kB
                                                                                                         ->  Seq Scan on actor "accountActor"  (cost=0.00..3780.27 rows=28427 width=8) (actual time=0.041..24.723 rows=28482 loops=1)
                                                                                             ->  Materialize  (cost=0.00..1.02 rows=1 width=4) (actual time=0.000..0.000 rows=1 loops=94578)
                                                                                                   ->  Seq Scan on "serverBlocklist"  (cost=0.00..1.01 rows=1 width=4) (actual time=0.045..0.047 rows=1 loops=1)
                                                                                                         Filter: ("accountId" = 1)
                                                                                       ->  Hash  (cost=657.66..657.66 rows=16966 width=4) (actual time=5.785..5.786 rows=16932 loops=1)
                                                                                             Buckets: 32768  Batches: 1  Memory Usage: 852kB
                                                                                             ->  Seq Scan on account  (cost=0.00..657.66 rows=16966 width=4) (actual time=0.053..4.398 rows=16932 loops=1)
                                                                                 ->  Hash  (cost=14.35..14.35 rows=7 width=4) (actual time=0.020..0.022 rows=0 loops=1)
                                                                                       Buckets: 1024  Batches: 1  Memory Usage: 8kB
                                                                                       ->  Bitmap Heap Scan on "accountBlocklist"  (cost=4.21..14.35 rows=7 width=4) (actual time=0.019..0.021 rows=0 loops=1)
                                                                                             Recheck Cond: ("accountId" = 1)
                                                                                             ->  Bitmap Index Scan on account_blocklist_account_id_target_account_id  (cost=0.00..4.21 rows=7 width=0) (actual time=0.015..0.015 rows=0 loops=1)
                                                                                                   Index Cond: ("accountId" = 1)
                                                                                 SubPlan 1
                                                                                   ->  Result  (cost=0.00..0.02 rows=1 width=32) (actual time=0.000..0.000 rows=1 loops=94578)
                                                               ->  Index Scan using video_pkey on video  (cost=0.42..8.44 rows=1 width=1034) (actual time=0.009..0.009 rows=1 loops=25)
                                                                     Index Cond: (id = video_1.id)
                                                         ->  Index Scan using "videoChannel_pkey" on "videoChannel" "VideoChannel"  (cost=0.29..0.31 rows=1 width=219) (actual time=0.003..0.003 rows=1 loops=25)
                                                               Index Cond: (id = video."channelId")
                                                   ->  Index Scan using actor_account_id on actor "VideoChannel->Account->Actor"  (cost=0.29..1.55 rows=1 width=75) (actual time=0.003..0.003 rows=1 loops=25)
                                                         Index Cond: ("accountId" = "VideoChannel"."accountId")
                                             ->  Index Scan using actor_video_channel_id on actor "VideoChannel->Actor"  (cost=0.29..0.35 rows=1 width=75) (actual time=0.002..0.002 rows=1 loops=25)
                                                   Index Cond: ("videoChannelId" = video."channelId")
                                       ->  Index Scan using server_pkey on server "VideoChannel->Actor->Server"  (cost=0.28..0.30 rows=1 width=21) (actual time=0.002..0.002 rows=1 loops=25)
                                             Index Cond: (id = "VideoChannel->Actor"."serverId")
                                 ->  Index Scan using actor_image_actor_id_type_width on "actorImage" "VideoChannel->Actor->Avatars"  (cost=0.29..0.60 rows=3 width=159) (actual time=0.005..0.007 rows=3 loops=25)
                                       Index Cond: (("actorId" = "VideoChannel->Actor".id) AND (type = 1))
                           ->  Index Scan using account_pkey on account "VideoChannel->Account"  (cost=0.29..0.38 rows=1 width=16) (actual time=0.002..0.002 rows=1 loops=70)
                                 Index Cond: (id = "VideoChannel->Account->Actor"."accountId")
                     ->  Index Scan using server_pkey on server "VideoChannel->Account->Actor->Server"  (cost=0.28..0.30 rows=1 width=21) (actual time=0.001..0.001 rows=1 loops=70)
                           Index Cond: (id = "VideoChannel->Account->Actor"."serverId")
               ->  Index Scan using actor_image_actor_id_type_width on "actorImage" "VideoChannel->Account->Actor->Avatars"  (cost=0.29..0.60 rows=3 width=159) (actual time=0.002..0.002 rows=2 loops=70)
                     Index Cond: (("actorId" = "VideoChannel->Account->Actor".id) AND (type = 1))
         ->  Index Scan using thumbnail_video_id on thumbnail "Thumbnails"  (cost=0.42..0.70 rows=2 width=145) (actual time=0.003..0.004 rows=2 loops=172)
               Index Cond: ("videoId" = video.id)
 Planning Time: 15.807 ms
 JIT:
   Functions: 230
   Options: Inlining false, Optimization false, Expressions true, Deforming true
   Timing: Generation 11.562 ms (Deform 6.135 ms), Inlining 0.000 ms, Optimization 9.100 ms, Emission 83.809 ms, Total 104.470 ms
 Execution Time: 849.518 ms
(145 rows)


Seems better, thank you. Implemented in Optimize videos list SQL query · Chocobozzz/PeerTube@576b8f8 · GitHub