explain.depesz.com

PostgreSQL's explain analyze made readable

Result: GR9n : before target geo

Settings

Optimization(s) for this plan:

# exclusive inclusive rows x rows loops node
1. 0.528 3.337 ↓ 100.3 301 1

Sort (cost=1,456.77..1,456.77 rows=3 width=5,163) (actual time=3.320..3.337 rows=301 loops=1)

  • Sort Key: selected_offers.previous_offer_id, apps.vip DESC, selected_offers.number, offer_steps.order_index
  • Sort Method: quicksort Memory: 330kB
2. 0.279 2.809 ↓ 100.3 301 1

Nested Loop Left Join (cost=1,441.55..1,456.74 rows=3 width=5,163) (actual time=0.362..2.809 rows=301 loops=1)

3. 0.192 2.229 ↓ 301.0 301 1

Nested Loop Left Join (cost=1,437.37..1,445.43 rows=1 width=5,131) (actual time=0.359..2.229 rows=301 loops=1)

4. 1.736 1.736 ↓ 301.0 301 1

CTE Scan on selected_offers (cost=1,437.23..1,437.25 rows=1 width=5,195) (actual time=0.354..1.736 rows=301 loops=1)

5.          

CTE selected_offers

6. 0.177 1.165 ↓ 301.0 301 1

Nested Loop Left Join (cost=82.35..1,437.23 rows=1 width=2,488) (actual time=0.347..1.165 rows=301 loops=1)

  • Join Filter: (completed_offers_2.offer_id = offers.id)
  • Filter: (((offers.reward_after)::text = 'prepared_review_creation'::text) OR (((offers.reward_after)::text <> 'prepared_review_creation'::text) AND (completed_offers_2.id IS NULL)))
7. 0.790 0.988 ↓ 7.9 301 1

Index Scan using offers_pkey on offers (cost=82.35..1,424.36 rows=38 width=2,488) (actual time=0.342..0.988 rows=301 loops=1)

  • Filter: ((NOT hidden) AND (NOT archived) AND iphone AND (target_gender IS NULL) AND ((started_at <= '2020-06-29 07:02:14.601493'::timestamp without time zone) OR (started_at IS NULL)) AND (rem_day_installs > 0) AND (min_user_installs <= 0) AND ((max_user_installs > 0) OR (max_user_installs IS NULL)) AND ((review_type = 0) OR (review_type IS NULL)) AND (NOT (hashed SubPlan 1)) AND ((reward_after)::text <> 'prepared_review_publication'::text) AND ((reward_after)::text <> 'prepared_review_creation'::text) AND ((hashed SubPlan 5) OR (previous_offer_id IS NULL)) AND ((NOT (hashed SubPlan 6)) OR (second_chance_offer_id IS NULL)) AND ((country)::text = 'ru'::text) AND ((((reward_after)::text = ANY ('{click,app_postback,retention}'::text[])) AND (SubPlan 2) AND (hashed SubPlan 3)) OR (((reward_after)::text = ANY ('{review,prepared_review_publication,prepared_review_creation,callibration_review,partner_webhook}'::text[])) AND ((NOT for_user_installed_app) OR (for_user_installed_app AND (hashed SubPlan 4)))) OR (((reward_after)::text = ANY ('{click,prepared_review_publication,retention}'::text[])) AND (previous_offer_id IS NOT NULL))))
8.          

SubPlan (for Index Scan)

9. 0.002 0.003 ↓ 0.0 0 1

Bitmap Heap Scan on callibration_reviews (cost=4.17..11.28 rows=3 width=4) (actual time=0.003..0.003 rows=0 loops=1)

  • Recheck Cond: (user_id = 1)
10. 0.001 0.001 ↓ 0.0 0 1

Bitmap Index Scan on index_callibration_reviews_on_user_id (cost=0.00..4.17 rows=3 width=0) (actual time=0.001..0.001 rows=0 loops=1)

  • Index Cond: (user_id = 1)
11. 0.002 0.002 ↓ 0.0 0 1

Seq Scan on completed_offers (cost=0.00..12.10 rows=1 width=4) (actual time=0.002..0.002 rows=0 loops=1)

  • Filter: ((rewarded AND (device_id = 1)) OR ((user_id = 1) AND (device_id IS NULL)))
12. 0.001 0.001 ↓ 0.0 0 1

Seq Scan on completed_offers completed_offers_1 (cost=0.00..12.10 rows=1 width=4) (actual time=0.001..0.001 rows=0 loops=1)

  • Filter: ((rewarded AND (device_id = 1)) OR ((user_id = 1) AND (device_id IS NULL)))
13. 0.000 0.000 ↓ 0.0 0 301

Materialize (cost=4.18..12.66 rows=4 width=4) (actual time=0.000..0.000 rows=0 loops=301)

14. 0.000 0.001 ↓ 0.0 0 1

Bitmap Heap Scan on installed_apps (cost=4.18..12.64 rows=4 width=4) (actual time=0.001..0.001 rows=0 loops=1)

  • Recheck Cond: (device_id = 1)
15. 0.001 0.001 ↓ 0.0 0 1

Bitmap Index Scan on index_installed_apps_on_device_id_and_app_id (cost=0.00..4.18 rows=4 width=0) (actual time=0.001..0.001 rows=0 loops=1)

  • Index Cond: (device_id = 1)
16. 0.144 0.192 ↓ 150.5 301 1

Hash Left Join (cost=12.69..29.87 rows=2 width=4) (actual time=0.020..0.192 rows=301 loops=1)

  • Hash Cond: (apps_1.id = installed_apps_1.app_id)
  • Filter: ((NOT apps_1.only_one_install) OR (apps_1.only_one_install AND (installed_apps_1.app_id IS NULL)))
17. 0.047 0.047 ↑ 1.0 301 1

Seq Scan on apps apps_1 (cost=0.00..16.01 rows=301 width=5) (actual time=0.004..0.047 rows=301 loops=1)

18. 0.000 0.001 ↓ 0.0 0 1

Hash (cost=12.64..12.64 rows=4 width=4) (actual time=0.001..0.001 rows=0 loops=1)

  • Buckets: 1,024 Batches: 1 Memory Usage: 8kB
19. 0.000 0.001 ↓ 0.0 0 1

Bitmap Heap Scan on installed_apps installed_apps_1 (cost=4.18..12.64 rows=4 width=4) (actual time=0.001..0.001 rows=0 loops=1)

  • Recheck Cond: (user_id = 1)
20. 0.001 0.001 ↓ 0.0 0 1

Bitmap Index Scan on index_installed_apps_on_user_id_and_app_id (cost=0.00..4.18 rows=4 width=0) (actual time=0.001..0.001 rows=0 loops=1)

  • Index Cond: (user_id = 1)
21. 0.000 0.000 ↓ 0.0 0

Bitmap Heap Scan on installed_apps installed_apps_2 (cost=4.18..12.64 rows=4 width=4) (never executed)

  • Recheck Cond: (user_id = 1)
22. 0.000 0.000 ↓ 0.0 0

Bitmap Index Scan on index_installed_apps_on_user_id_and_app_id (cost=0.00..4.18 rows=4 width=0) (never executed)

  • Index Cond: (user_id = 1)
23. 0.000 0.000 ↓ 0.0 0 301

Materialize (cost=0.00..12.11 rows=1 width=8) (actual time=0.000..0.000 rows=0 loops=301)

24. 0.002 0.002 ↓ 0.0 0 1

Seq Scan on completed_offers completed_offers_2 (cost=0.00..12.10 rows=1 width=8) (actual time=0.002..0.002 rows=0 loops=1)

  • Filter: ((device_id = 1) OR ((user_id = 1) AND (device_id IS NULL)))
25. 0.301 0.301 ↑ 1.0 1 301

Index Scan using apps_pkey on apps (cost=0.15..8.17 rows=1 width=5) (actual time=0.001..0.001 rows=1 loops=301)

  • Index Cond: (id = selected_offers.app_id)
26. 0.301 0.301 ↓ 0.0 0 301

Bitmap Heap Scan on offer_steps (cost=4.17..11.28 rows=3 width=36) (actual time=0.001..0.001 rows=0 loops=301)

  • Recheck Cond: (offer_id = selected_offers.id)
27. 0.000 0.000 ↓ 0.0 0 301

Bitmap Index Scan on index_offer_steps_on_offer_id (cost=0.00..4.17 rows=3 width=0) (actual time=0.000..0.000 rows=0 loops=301)

  • Index Cond: (offer_id = selected_offers.id)
Planning time : 1.769 ms
Execution time : 3.738 ms