Skip to content

Instantly share code, notes, and snippets.

@ijunaid8989
Created January 8, 2026 14:44
Show Gist options
  • Select an option

  • Save ijunaid8989/7fae23a4d4f01eef5b1ab0a995baa028 to your computer and use it in GitHub Desktop.

Select an option

Save ijunaid8989/7fae23a4d4f01eef5b1ab0a995baa028 to your computer and use it in GitHub Desktop.
Limit (cost=75619.09..75619.14 rows=1 width=84) (actual time=101099.589..101099.594 rows=1 loops=1)
Output: ((m.inserted_at)::date), c.updated_by_id, c.organization_id, (count(c.id)), ((sum((COALESCE(sum(m.segments) FILTER (WHERE ((m.type)::text = 'sms'::text)), '0'::bigint))))::integer), ((sum((COALESCE(sum(m.segments) FILTER (WHERE ((m.type)::text = 'mms'::text)), '0'::bigint))))::integer), (sum(a.sent_messages)), (sum(a.failed_deliveries)), (sum(a.unsubscribes)), (sum(a.responses)), (sum(a.link_clicks))
Buffers: shared hit=3268301
-> GroupAggregate (cost=75619.09..75619.19 rows=2 width=84) (actual time=101099.587..101099.592 rows=1 loops=1)
Output: ((m.inserted_at)::date), c.updated_by_id, c.organization_id, count(c.id), (sum((COALESCE(sum(m.segments) FILTER (WHERE ((m.type)::text = 'sms'::text)), '0'::bigint))))::integer, (sum((COALESCE(sum(m.segments) FILTER (WHERE ((m.type)::text = 'mms'::text)), '0'::bigint))))::integer, sum(a.sent_messages), sum(a.failed_deliveries), sum(a.unsubscribes), sum(a.responses), sum(a.link_clicks)
Group Key: c.updated_by_id, ((m.inserted_at)::date), c.organization_id
Buffers: shared hit=3268301
-> Sort (cost=75619.09..75619.10 rows=2 width=80) (actual time=101099.566..101099.571 rows=4 loops=1)
Output: ((m.inserted_at)::date), c.updated_by_id, c.organization_id, c.id, (COALESCE(sum(m.segments) FILTER (WHERE ((m.type)::text = 'sms'::text)), '0'::bigint)), (COALESCE(sum(m.segments) FILTER (WHERE ((m.type)::text = 'mms'::text)), '0'::bigint)), a.sent_messages, a.failed_deliveries, a.unsubscribes, a.responses, a.link_clicks
Sort Key: c.updated_by_id, ((m.inserted_at)::date), c.organization_id
Sort Method: quicksort Memory: 25kB
Buffers: shared hit=3268301
-> Nested Loop Left Join (cost=75602.52..75619.08 rows=2 width=80) (actual time=101099.490..101099.528 rows=4 loops=1)
Output: ((m.inserted_at)::date), c.updated_by_id, c.organization_id, c.id, (COALESCE(sum(m.segments) FILTER (WHERE ((m.type)::text = 'sms'::text)), '0'::bigint)), (COALESCE(sum(m.segments) FILTER (WHERE ((m.type)::text = 'mms'::text)), '0'::bigint)), a.sent_messages, a.failed_deliveries, a.unsubscribes, a.responses, a.link_clicks
Buffers: shared hit=3268292
-> GroupAggregate (cost=75602.10..75602.16 rows=2 width=60) (actual time=101099.442..101099.456 rows=4 loops=1)
Output: c.id, c.organization_id, c.updated_by_id, ((m.inserted_at)::date), COALESCE(sum(m.segments) FILTER (WHERE ((m.type)::text = 'sms'::text)), '0'::bigint), COALESCE(sum(m.segments) FILTER (WHERE ((m.type)::text = 'mms'::text)), '0'::bigint)
Group Key: c.id, ((m.inserted_at)::date)
Buffers: shared hit=3268276
-> Sort (cost=75602.10..75602.10 rows=2 width=52) (actual time=101099.428..101099.434 rows=36 loops=1)
Output: c.id, ((m.inserted_at)::date), c.organization_id, c.updated_by_id, m.segments, m.type
Sort Key: c.id, ((m.inserted_at)::date)
Sort Method: quicksort Memory: 28kB
Buffers: shared hit=3268276
-> Nested Loop (cost=3925.28..75602.09 rows=2 width=52) (actual time=100583.965..101099.394 rows=36 loops=1)
Output: c.id, (m.inserted_at)::date, c.organization_id, c.updated_by_id, m.segments, m.type
Buffers: shared hit=3268276
-> Bitmap Heap Scan on public.campaigns c (cost=161.24..240.75 rows=20 width=40) (actual time=1.826..22.368 rows=1549 loops=1)
Output: c.id, c.organization_id, c.updated_by_id
Recheck Cond: ((c.updated_by_id = 74960) AND (c.organization_id = 'd2c1ebe6-6cad-4f31-b081-7b87bf2a4563'::uuid))
Heap Blocks: exact=1545
Buffers: shared hit=1574
-> BitmapAnd (cost=161.24..161.24 rows=20 width=0) (actual time=1.577..1.579 rows=0 loops=1)
Buffers: shared hit=29
-> Bitmap Index Scan on campaigns_updated_by_id_index (cost=0.00..26.65 rows=1897 width=0) (actual time=0.276..0.277 rows=1573 loops=1)
Index Cond: (c.updated_by_id = 74960)
Buffers: shared hit=8
-> Bitmap Index Scan on campaigns_organization_id_index (cost=0.00..134.33 rows=8787 width=0) (actual time=1.248..1.248 rows=9012 loops=1)
Index Cond: (c.organization_id = 'd2c1ebe6-6cad-4f31-b081-7b87bf2a4563'::uuid)
Buffers: shared hit=21
-> Bitmap Heap Scan on public.messages m (cost=3764.04..3768.06 rows=1 width=32) (actual time=65.247..65.247 rows=0 loops=1549)
Output: m.inserted_at, m.segments, m.type, m.campaign_id
Recheck Cond: ((m.campaign_id = c.id) AND (m.inserted_at >= '2026-01-07 00:00:00'::timestamp without time zone) AND (m.inserted_at <= '2026-01-07 23:59:59.999999'::timestamp without time zone) AND (m.inserted_at IS NOT NULL))
Rows Removed by Index Recheck: 0
Heap Blocks: exact=166
Buffers: shared hit=3266702
-> BitmapAnd (cost=3764.04..3764.04 rows=1 width=0) (actual time=65.241..65.241 rows=0 loops=1549)
Buffers: shared hit=3266536
-> Bitmap Index Scan on messages_campaign_id_index (cost=0.00..35.79 rows=2029 width=0) (actual time=0.030..0.030 rows=74 loops=1549)
Index Cond: (m.campaign_id = c.id)
Buffers: shared hit=6196
-> Bitmap Index Scan on messages_inserted_at_index (cost=0.00..3701.90 rows=104426 width=0) (actual time=65.788..65.788 rows=1120312 loops=1535)
Index Cond: ((m.inserted_at >= '2026-01-07 00:00:00'::timestamp without time zone) AND (m.inserted_at <= '2026-01-07 23:59:59.999999'::timestamp without time zone) AND (m.inserted_at IS NOT NULL))
Buffers: shared hit=3260340
-> Index Scan using analytics_campaign_id_index on public.analytics a (cost=0.42..8.44 rows=1 width=36) (actual time=0.016..0.016 rows=1 loops=4)
Output: a.sent_messages, a.failed_deliveries, a.unsubscribes, a.responses, a.link_clicks, a.campaign_id
Index Cond: (a.campaign_id = c.id)
Buffers: shared hit=16
Query Identifier: -8403608326026600989
Planning:
Buffers: shared hit=1235
Planning Time: 5.067 ms
Execution Time: 101100.646 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment