EXPLAIN ANALYZE SELECT
  project_id,
  date_trunc('day', created_at) as interval_start,
  count(DISTINCT ip_address) as unique_visitors
FROM analytics_visits
WHERE user_id='2c182b8f-ad65-4543-8ac9-2c47bb20172d' AND created_at >= '2024-10-01' AND status <> 404 
GROUP BY post_id, project_id, interval_start;

                                                                                    QUERY PLAN                              
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 GroupAggregate  (cost=97609.43..106340.14 rows=62826 width=48) (actual time=2070.275..2345.613 rows=1767 loops=1)
   Group Key: post_id, project_id, (date_trunc('day'::text, created_at))
   ->  Gather Merge  (cost=97609.43..104926.56 rows=62826 width=105) (actual time=2070.160..2219.845 rows=60055 loops=1)
         Workers Planned: 2
         Workers Launched: 2
         ->  Sort  (cost=96609.41..96674.85 rows=26178 width=105) (actual time=1838.860..1845.864 rows=20018 loops=3)
               Sort Key: post_id, project_id, (date_trunc('day'::text, created_at))
               Sort Method: quicksort  Memory: 3539kB
               Worker 0:  Sort Method: quicksort  Memory: 3455kB
               Worker 1:  Sort Method: quicksort  Memory: 3208kB
               ->  Parallel Seq Scan on analytics_visits  (cost=0.00..94688.46 rows=26178 width=105) (actual time=345.497..1762.156 rows=20018 loops=3)
                     Filter: ((created_at >= '2024-10-01 00:00:00'::timestamp without time zone) AND (status <> 404) AND (user_id = '2c182b8f-ad65-4543-8ac9-2c47bb20172d'::uuid))
                     Rows Removed by Filter: 785366
 Planning Time: 0.540 ms
 JIT:
   Functions: 15
   Options: Inlining false, Optimization false, Expressions true, Deforming true
   Timing: Generation 20.496 ms, Inlining 0.000 ms, Optimization 14.859 ms, Emission 419.851 ms, Total 455.205 ms
 Execution Time: 3002.404 ms
(19 rows)
