BEGIN
                                                                                                                                                                                                                                                                       QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Unique  (cost=21466.85..21477.75 rows=15 width=132) (actual rows=23 loops=1)
   Buffers: shared hit=21084
   ->  Incremental Sort  (cost=21466.85..21477.71 rows=15 width=132) (actual rows=159 loops=1)
         Sort Key: (COALESCE(la.canonical_node_id, upper(btrim(s.node_id)))), (COALESCE(s.uptime_secs, '0'::bigint)) DESC, s."time" DESC
         Presorted Key: (COALESCE(la.canonical_node_id, upper(btrim(s.node_id))))
         Full-sort Groups: 5  Sort Method: quicksort  Average Memory: 33kB  Peak Memory: 33kB
         Buffers: shared hit=21084
         ->  Merge Left Join  (cost=21466.11..21477.04 rows=15 width=132) (actual rows=159 loops=1)
               Merge Cond: (COALESCE(la.canonical_node_id, upper(btrim(s.node_id))) = (meshcore_canonical_node_id(raw_counts.rx_node_id)))
               Buffers: shared hit=21078
               ->  Merge Left Join  (cost=13150.29..13151.14 rows=15 width=214) (actual rows=159 loops=1)
                     Merge Cond: ((COALESCE(la.canonical_node_id, upper(btrim(s.node_id)))) = n.node_id)
                     Filter: ((n.name IS NULL) OR (n.name !~~ '%🚫%'::text))
                     Buffers: shared hit=9383
                     ->  Sort  (cost=28.38..28.42 rows=15 width=182) (actual rows=159 loops=1)
                           Sort Key: (COALESCE(la.canonical_node_id, upper(btrim(s.node_id))))
                           Sort Method: quicksort  Memory: 57kB
                           Buffers: shared hit=388
                           ->  Nested Loop Left Join  (cost=0.56..28.09 rows=15 width=182) (actual rows=159 loops=1)
                                 Buffers: shared hit=388
                                 ->  Custom Scan (ChunkAppend) on node_status_samples s  (cost=0.29..5.01 rows=15 width=117) (actual rows=159 loops=1)
                                       Chunks excluded during startup: 0
                                       Buffers: shared hit=70
                                       ->  Index Scan using _hyper_2_316_chunk_node_status_samples_time_idx on _hyper_2_316_chunk s_1  (cost=0.29..5.01 rows=15 width=117) (actual rows=159 loops=1)
                                             Index Cond: ("time" > (now() - '00:15:00'::interval))
                                             Filter: (network = ANY ('{ukmesh,northeast,teesside}'::text[]))
                                             Buffers: shared hit=70
                                 ->  Index Scan using node_identity_aliases_pkey on node_identity_aliases la  (cost=0.27..1.54 rows=1 width=130) (actual rows=0 loops=159)
                                       Index Cond: (source_node_id = upper(btrim(s.node_id)))
                                       Buffers: shared hit=318
                     ->  Sort  (cost=13121.91..13122.07 rows=64 width=64) (actual rows=8458 loops=1)
                           Sort Key: n.node_id
                           Sort Method: quicksort  Memory: 1270kB
                           Buffers: shared hit=8995
                           ->  Subquery Scan on n  (cost=13118.07..13119.99 rows=64 width=64) (actual rows=8365 loops=1)
                                 Buffers: shared hit=8995
                                 ->  CTE Scan on v  (cost=13118.07..13119.35 rows=64 width=381) (actual rows=8365 loops=1)
                                       Buffers: shared hit=8995
                                       CTE v
                                         ->  Merge Join  (cost=11854.79..13118.07 rows=64 width=381) (actual rows=8365 loops=1)
                                               Merge Cond: (r.canonical_node_id = mapped.canonical_node_id)
                                               Buffers: shared hit=8995
                                               CTE mapped
                                                 ->  Hash Left Join  (cost=30.16..9225.37 rows=12887 width=312) (actual rows=8461 loops=1)
                                                       Hash Cond: (upper(btrim(n_1.node_id)) = la_1.source_node_id)
                                                       Buffers: shared hit=8992
                                                       ->  Seq Scan on nodes n_1  (cost=0.00..9092.87 rows=12887 width=280) (actual rows=8461 loops=1)
                                                             Buffers: shared hit=8964
                                                       ->  Hash  (cost=28.96..28.96 rows=96 width=130) (actual rows=96 loops=1)
                                                             Buckets: 1024  Batches: 1  Memory Usage: 24kB
                                                             Buffers: shared hit=28
                                                             ->  Seq Scan on node_identity_aliases la_1  (cost=0.00..28.96 rows=96 width=130) (actual rows=96 loops=1)
                                                                   Buffers: shared hit=28
                                               ->  Subquery Scan on r  (cost=1491.90..2361.78 rows=64 width=292) (actual rows=8365 loops=1)
                                                     Filter: (r.representative_rank = 1)
                                                     Buffers: shared hit=8995
                                                     ->  WindowAgg  (cost=1491.90..2200.69 rows=12887 width=393) (actual rows=8365 loops=1)
                                                           Run Condition: (row_number() OVER (?) <= 1)
                                                           Buffers: shared hit=8995
                                                           ->  Sort  (cost=1491.90..1524.12 rows=12887 width=332) (actual rows=8461 loops=1)
                                                                 Sort Key: m.canonical_node_id, (CASE WHEN ((m.role = 2) AND (m.lat >= '-90'::double precision) AND (m.lat <= '90'::double precision) AND (m.lon >= '-180'::double precision) AND (m.lon <= '180'::double precision) AND ((abs(m.lat) >= '1e-09'::double precision) OR (abs(m.lon) >= '1e-09'::double precision))) THEN 0 WHEN (m.role = 2) THEN 1 WHEN (COALESCE(m.advert_count, 0) > 0) THEN 2 ELSE 3 END), (COALESCE(m.advert_count, 0)) DESC, m.last_seen DESC NULLS LAST, m.node_id
                                                                 Sort Method: quicksort  Memory: 2925kB
                                                                 Buffers: shared hit=8995
                                                                 ->  CTE Scan on mapped m  (cost=0.00..612.13 rows=12887 width=332) (actual rows=8461 loops=1)
                                                                       Buffers: shared hit=8992
                                               ->  GroupAggregate  (cost=1137.51..1527.62 rows=200 width=129) (actual rows=8365 loops=1)
                                                     Group Key: mapped.canonical_node_id
                                                     ->  Sort  (cost=1137.51..1169.73 rows=12887 width=117) (actual rows=8461 loops=1)
                                                           Sort Key: mapped.canonical_node_id, mapped.node_id
                                                           Sort Method: quicksort  Memory: 1988kB
                                                           ->  CTE Scan on mapped  (cost=0.00..257.74 rows=12887 width=117) (actual rows=8461 loops=1)
               ->  GroupAggregate  (cost=8315.82..8325.08 rows=34 width=40) (actual rows=26 loops=1)
                     Group Key: (meshcore_canonical_node_id(raw_counts.rx_node_id))
                     Buffers: shared hit=11695
                     ->  Sort  (cost=8315.82..8315.90 rows=34 width=40) (actual rows=26 loops=1)
                           Sort Key: (meshcore_canonical_node_id(raw_counts.rx_node_id))
                           Sort Method: quicksort  Memory: 27kB
                           Buffers: shared hit=11695
                           ->  Subquery Scan on raw_counts  (cost=8306.11..8314.95 rows=34 width=40) (actual rows=26 loops=1)
                                 Buffers: shared hit=11695
                                 ->  Finalize HashAggregate  (cost=8306.11..8306.45 rows=34 width=73) (actual rows=26 loops=1)
                                       Group Key: packets.rx_node_id
                                       Batches: 1  Memory Usage: 24kB
                                       Buffers: shared hit=11622
                                       ->  Custom Scan (ChunkAppend) on packets  (cost=0.42..8305.77 rows=68 width=73) (actual rows=51 loops=1)
                                             Chunks excluded during startup: 0
                                             Buffers: shared hit=11622
                                             ->  Partial HashAggregate  (cost=4936.64..4936.98 rows=34 width=73) (actual rows=26 loops=1)
                                                   Group Key: _hyper_1_312_chunk.rx_node_id
                                                   Batches: 1  Memory Usage: 24kB
                                                   Buffers: shared hit=8496
                                                   ->  Index Only Scan using _hyper_1_312_chunk_idx_packets_observer_region on _hyper_1_312_chunk  (cost=0.42..4611.13 rows=65102 width=65) (actual rows=67900 loops=1)
                                                         Index Cond: ((network = ANY ('{ukmesh,northeast,teesside}'::text[])) AND ("time" > (now() - '24:00:00'::interval)) AND (rx_node_id IS NOT NULL))
                                                         Heap Fetches: 11874
                                                         Buffers: shared hit=8496
                                             ->  Partial HashAggregate  (cost=3368.45..3368.79 rows=34 width=73) (actual rows=25 loops=1)
                                                   Group Key: _hyper_1_314_chunk.rx_node_id
                                                   Batches: 1  Memory Usage: 24kB
                                                   Buffers: shared hit=3126
                                                   ->  Index Only Scan using _hyper_1_314_chunk_idx_packets_observer_region on _hyper_1_314_chunk  (cost=0.42..3059.06 rows=61877 width=65) (actual rows=61865 loops=1)
                                                         Index Cond: ((network = ANY ('{ukmesh,northeast,teesside}'::text[])) AND ("time" > (now() - '24:00:00'::interval)) AND (rx_node_id IS NOT NULL))
                                                         Heap Fetches: 2438
                                                         Buffers: shared hit=3126
 Settings: max_parallel_workers_per_gather = '0', work_mem = '10076kB', effective_io_concurrency = '256', random_page_cost = '1.1', effective_cache_size = '1475MB', jit = 'off'
 Planning:
   Buffers: shared hit=2322 read=20
 Planning Time: 59.431 ms
 Execution Time: 207.755 ms
(108 rows)

ROLLBACK
