Original query:

 Aggregate  (cost=270755.60..270755.61 rows=1 width=8) (actual time=8180.691..8180.692 rows=1 loops=1)
   CTE allowed_channels
     ->  Nested Loop Anti Join  (cost=151.38..5444.29 rows=637 width=16) (actual time=1.255..7.503 rows=1014 loops=1)
           Join Filter: ("channel_device_restrictions"."channel" = "c"."id")
           Rows Removed by Join Filter: 5080
           ->  Nested Loop  (cost=151.38..5382.93 rows=640 width=16) (actual time=1.181..6.525 rows=1019 loops=1)
                 ->  HashAggregate  (cost=151.10..158.61 rows=751 width=16) (actual time=1.144..1.338 rows=1138 loops=1)
                       Group Key: "channel_subscription_packs"."channel"
                       ->  Seq Scan on "channel_subscription_packs"  (cost=0.00..148.26 rows=1138 width=16) (actual time=0.013..0.866 rows=1138 loops=1)
                             Filter: ("subscription_pack" = ANY ('{c1e7a931-a68b-4e0f-9f09-e575c4ff9ea8}'::"uuid"[]))
                             Rows Removed by Filter: 6796
                 ->  Index Only Scan using "channels_pkey" on "channels" "c"  (cost=0.28..6.95 rows=1 width=16) (actual time=0.004..0.004 rows=1 loops=1138)
                       Index Cond: ("id" = "channel_subscription_packs"."channel")
                       Filter: (((NOT (alternatives: SubPlan 5 or hashed SubPlan 6)) OR (alternatives: SubPlan 7 or hashed SubPlan 8)) AND ((NOT (alternatives: SubPlan 1 or hashed SubPlan 2)) OR (alternatives: SubPlan 3 or hashed SubPlan 4)))
                       Rows Removed by Filter: 0
                       Heap Fetches: 1138
                       SubPlan 5
                         ->  Index Only Scan using "channel_allowed_dmas_pkey" on "channel_allowed_dmas"  (cost=0.28..15.29 rows=22 width=0) (actual time=0.001..0.001 rows=0 loops=1138)
                               Index Cond: ("channel" = "c"."id")
                               Heap Fetches: 127
                       SubPlan 6
                         ->  Seq Scan on "channel_allowed_dmas" "channel_allowed_dmas_1"  (cost=0.00..46.13 rows=2813 width=16) (never executed)
                       SubPlan 7
                         ->  Index Only Scan using "channel_allowed_dmas_pkey" on "channel_allowed_dmas" "channel_allowed_dmas_2"  (cost=0.28..2.30 rows=1 width=0) (actual time=0.001..0.001 rows=0 loops=127)
                               Index Cond: (("channel" = "c"."id") AND ("dma" = 770))
                               Heap Fetches: 12
                       SubPlan 8
                         ->  Seq Scan on "channel_allowed_dmas" "channel_allowed_dmas_3"  (cost=0.00..53.16 rows=12 width=16) (never executed)
                               Filter: ("dma" = 770)
                       SubPlan 1
                         ->  Index Only Scan using "channel_allowed_timezones_pkey" on "channel_allowed_timezones"  (cost=0.15..5.24 rows=5 width=0) (actual time=0.001..0.001 rows=0 loops=1023)
                               Index Cond: ("channel" = "c"."id")
                               Heap Fetches: 8
                       SubPlan 2
                         ->  Seq Scan on "channel_allowed_timezones" "channel_allowed_timezones_1"  (cost=0.00..20.70 rows=1070 width=16) (never executed)
                       SubPlan 3
                         ->  Index Only Scan using "channel_allowed_timezones_pkey" on "channel_allowed_timezones" "channel_allowed_timezones_2"  (cost=0.15..2.17 rows=1 width=0) (actual time=0.003..0.003 rows=0 loops=8)
                               Index Cond: (("channel" = "c"."id") AND ("timezone" = '-0700'::"text"))
                               Heap Fetches: 4
                       SubPlan 4
                         ->  Index Only Scan using "channel_allowed_timezones_pkey" on "channel_allowed_timezones" "channel_allowed_timezones_3"  (cost=0.15..14.23 rows=5 width=16) (never executed)
                               Index Cond: ("timezone" = '-0700'::"text")
                               Heap Fetches: 0
           ->  Materialize  (cost=0.00..13.38 rows=5 width=16) (actual time=0.000..0.000 rows=5 loops=1019)
                 ->  Seq Scan on "channel_device_restrictions"  (cost=0.00..13.35 rows=5 width=16) (actual time=0.019..0.069 rows=5 loops=1)
                       Filter: ("device" = 'browser'::"text")
                       Rows Removed by Filter: 663
   CTE tiles
     ->  Hash Join  (cost=126688.55..248227.31 rows=758867 width=472) (actual time=3128.439..6579.396 rows=1400704 loops=1)
           Hash Cond: ("a"."program" = "p"."id")
           ->  Hash Join  (cost=74859.61..186817.67 rows=758867 width=484) (actual time=2687.503..5401.966 rows=1400704 loops=1)
                 Hash Cond: ("a"."id" = "l"."asset")
                 ->  Seq Scan on "assets" "a"  (cost=0.00..97370.01 rows=1866501 width=248) (actual time=0.008..344.290 rows=1866501 loops=1)
                 ->  Hash  (cost=65373.77..65373.77 rows=758867 width=252) (actual time=2686.342..2686.342 rows=1402291 loops=1)
                       Buckets: 1048576 (originally 1048576)  Batches: 2 (originally 1)  Memory Usage: 256001kB
                       ->  Nested Loop  (cost=14.76..65373.77 rows=758867 width=252) (actual time=8.232..1820.708 rows=1402291 loops=1)
                             ->  HashAggregate  (cost=14.33..16.33 rows=200 width=16) (actual time=8.209..8.808 rows=1014 loops=1)
                                   Group Key: "allowed_channels"."id"
                                   ->  CTE Scan on "allowed_channels"  (cost=0.00..12.74 rows=637 width=16) (actual time=1.257..7.783 rows=1014 loops=1)
                             ->  Index Scan using "linear_channel_idx" on "linear" "l"  (cost=0.43..312.22 rows=1457 width=252) (actual time=0.010..1.275 rows=1383 loops=1014)
                                   Index Cond: ("channel" = "allowed_channels"."id")
           ->  Hash  (cost=38072.86..38072.86 rows=1100486 width=20) (actual time=437.865..437.865 rows=1100486 loops=1)
                 Buckets: 2097152  Batches: 1  Memory Usage: 72269kB
                 ->  Seq Scan on "programs" "p"  (cost=0.00..38072.86 rows=1100486 width=20) (actual time=0.017..200.643 rows=1100486 loops=1)
   ->  CTE Scan on "tiles"  (cost=0.00..17074.51 rows=3794 width=0) (actual time=3143.903..8180.606 rows=51 loops=1)
         Filter: ("name" = 'The Hunt for Red October'::"text")
         Rows Removed by Filter: 1400653