explain.depesz.com

PostgreSQL's explain analyze made readable

Result: Ihq69 : staging target geo

Settings

Optimization(s) for this plan:

# exclusive inclusive rows x rows loops node
1. 0.402 4.452 ↓ 11.5 23 1

Sort (cost=592.12..592.13 rows=2 width=5,138) (actual time=4.432..4.452 rows=23 loops=1)

  • Sort Key: selected_offers.previous_offer_id, apps.vip DESC, selected_offers.number, offer_steps.order_index
  • Sort Method: quicksort Memory: 36kB
2. 0.070 4.050 ↓ 11.5 23 1

Nested Loop Left Join (cost=575.97..592.11 rows=2 width=5,138) (actual time=3.606..4.050 rows=23 loops=1)

3. 0.050 3.925 ↓ 11.0 11 1

Nested Loop Left Join (cost=575.69..583.75 rows=1 width=5,131) (actual time=3.594..3.925 rows=11 loops=1)

4. 3.820 3.820 ↓ 11.0 11 1

CTE Scan on selected_offers (cost=575.42..575.44 rows=1 width=5,195) (actual time=3.583..3.820 rows=11 loops=1)

5.          

CTE selected_offers

6. 0.045 3.742 ↓ 11.0 11 1

Nested Loop Left Join (cost=350.23..575.42 rows=1 width=928) (actual time=3.572..3.742 rows=11 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. 1.159 3.653 ↓ 5.5 11 1

Index Scan using index_offers_on_iphone_offerwal_options_partial on offers (cost=341.19..477.05 rows=2 width=928) (actual time=3.527..3.653 rows=11 loops=1)

  • Index Cond: (min_user_installs <= 0)
  • Filter: ((target_gender IS NULL) AND ((started_at <= '2020-06-29 08:43:35.178062'::timestamp without time zone) OR (started_at IS NULL)) 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))))
  • Rows Removed by Filter: 4
8.          

SubPlan (for Index Scan)

9. 0.007 0.012 ↓ 0.0 0 1

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

  • Recheck Cond: (user_id = 198,336)
10. 0.005 0.005 ↓ 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.005..0.005 rows=0 loops=1)

  • Index Cond: (user_id = 198,336)
11. 0.002 0.023 ↓ 0.0 0 1

Bitmap Heap Scan on completed_offers (cost=9.03..97.39 rows=23 width=4) (actual time=0.022..0.023 rows=0 loops=1)

  • Recheck Cond: ((device_id = 878) OR (user_id = 198,336))
  • Filter: ((rewarded AND (device_id = 878)) OR ((user_id = 198,336) AND (device_id IS NULL)))
12. 0.003 0.021 ↓ 0.0 0 1

BitmapOr (cost=9.03..9.03 rows=23 width=0) (actual time=0.020..0.021 rows=0 loops=1)

13. 0.010 0.010 ↓ 0.0 0 1

Bitmap Index Scan on index_completed_offers_on_device_id (cost=0.00..4.47 rows=6 width=0) (actual time=0.010..0.010 rows=0 loops=1)

  • Index Cond: (device_id = 878)
14. 0.008 0.008 ↓ 0.0 0 1

Bitmap Index Scan on index_completed_offers_on_user_id (cost=0.00..4.55 rows=17 width=0) (actual time=0.007..0.008 rows=0 loops=1)

  • Index Cond: (user_id = 198,336)
15. 0.001 0.014 ↓ 0.0 0 1

Bitmap Heap Scan on completed_offers completed_offers_1 (cost=9.03..97.39 rows=23 width=4) (actual time=0.014..0.014 rows=0 loops=1)

  • Recheck Cond: ((device_id = 878) OR (user_id = 198,336))
  • Filter: ((rewarded AND (device_id = 878)) OR ((user_id = 198,336) AND (device_id IS NULL)))
16. 0.004 0.013 ↓ 0.0 0 1

BitmapOr (cost=9.03..9.03 rows=23 width=0) (actual time=0.012..0.013 rows=0 loops=1)

17. 0.005 0.005 ↓ 0.0 0 1

Bitmap Index Scan on index_completed_offers_on_device_id (cost=0.00..4.47 rows=6 width=0) (actual time=0.004..0.005 rows=0 loops=1)

  • Index Cond: (device_id = 878)
18. 0.004 0.004 ↓ 0.0 0 1

Bitmap Index Scan on index_completed_offers_on_user_id (cost=0.00..4.55 rows=17 width=0) (actual time=0.003..0.004 rows=0 loops=1)

  • Index Cond: (user_id = 198,336)
19. 0.014 0.020 ↓ 0.0 0 10

Materialize (cost=0.28..10.70 rows=2 width=4) (actual time=0.002..0.002 rows=0 loops=10)

20. 0.006 0.006 ↓ 0.0 0 1

Index Only Scan using index_installed_apps_on_device_id_and_app_id on installed_apps (cost=0.28..10.69 rows=2 width=4) (actual time=0.005..0.006 rows=0 loops=1)

  • Index Cond: (device_id = 878)
  • Heap Fetches: 0
21. 1.602 2.425 ↓ 130.3 782 1

Hash Left Join (cost=10.29..123.98 rows=6 width=4) (actual time=0.042..2.425 rows=782 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)))
22. 0.813 0.813 ↓ 1.0 782 1

Seq Scan on apps apps_1 (cost=0.00..109.78 rows=778 width=5) (actual time=0.007..0.813 rows=782 loops=1)

23. 0.002 0.010 ↓ 0.0 0 1

Hash (cost=10.26..10.26 rows=2 width=4) (actual time=0.009..0.010 rows=0 loops=1)

  • Buckets: 1,024 Batches: 1 Memory Usage: 8kB
24. 0.002 0.008 ↓ 0.0 0 1

Bitmap Heap Scan on installed_apps installed_apps_1 (cost=4.29..10.26 rows=2 width=4) (actual time=0.007..0.008 rows=0 loops=1)

  • Recheck Cond: (user_id = 198,336)
25. 0.006 0.006 ↓ 0.0 0 1

Bitmap Index Scan on index_installed_apps_on_user_id_and_app_id (cost=0.00..4.29 rows=2 width=0) (actual time=0.005..0.006 rows=0 loops=1)

  • Index Cond: (user_id = 198,336)
26. 0.000 0.000 ↓ 0.0 0

Index Only Scan using index_installed_apps_on_user_id_and_app_id on installed_apps installed_apps_2 (cost=0.28..10.60 rows=2 width=4) (never executed)

  • Index Cond: (user_id = 198,336)
  • Heap Fetches: 0
27. 0.024 0.044 ↓ 0.0 0 11

Materialize (cost=9.03..97.50 rows=23 width=8) (actual time=0.004..0.004 rows=0 loops=11)

28. 0.006 0.020 ↓ 0.0 0 1

Bitmap Heap Scan on completed_offers completed_offers_2 (cost=9.03..97.39 rows=23 width=8) (actual time=0.019..0.020 rows=0 loops=1)

  • Recheck Cond: ((device_id = 878) OR (user_id = 198,336))
  • Filter: ((device_id = 878) OR ((user_id = 198,336) AND (device_id IS NULL)))
29. 0.003 0.014 ↓ 0.0 0 1

BitmapOr (cost=9.03..9.03 rows=23 width=0) (actual time=0.013..0.014 rows=0 loops=1)

30. 0.006 0.006 ↓ 0.0 0 1

Bitmap Index Scan on index_completed_offers_on_device_id (cost=0.00..4.47 rows=6 width=0) (actual time=0.006..0.006 rows=0 loops=1)

  • Index Cond: (device_id = 878)
31. 0.005 0.005 ↓ 0.0 0 1

Bitmap Index Scan on index_completed_offers_on_user_id (cost=0.00..4.55 rows=17 width=0) (actual time=0.004..0.005 rows=0 loops=1)

  • Index Cond: (user_id = 198,336)
32. 0.055 0.055 ↑ 1.0 1 11

Index Scan using apps_pkey on apps (cost=0.28..8.29 rows=1 width=5) (actual time=0.005..0.005 rows=1 loops=11)

  • Index Cond: (id = selected_offers.app_id)
33. 0.055 0.055 ↑ 1.0 2 11

Index Scan using index_offer_steps_on_offer_id on offer_steps (cost=0.28..8.34 rows=2 width=11) (actual time=0.004..0.005 rows=2 loops=11)

  • Index Cond: (offer_id = selected_offers.id)
Planning time : 3.508 ms
Execution time : 5.132 ms