explain.depesz.com

PostgreSQL's explain analyze made readable

Result: R22M

Settings
# exclusive inclusive rows x rows loops node
1. 0.007 15,933.101 ↓ 2.0 20 1

Subquery Scan on relation_list (cost=1,399,363.63..1,399,363.76 rows=10 width=4) (actual time=15,933.077..15,933.101 rows=20 loops=1)

2. 0.016 15,933.094 ↓ 2.0 20 1

Limit (cost=1,399,363.63..1,399,363.66 rows=10 width=1,299) (actual time=15,933.076..15,933.094 rows=20 loops=1)

3. 133.043 15,933.078 ↓ 2.0 20 1

Sort (cost=1,399,363.63..1,399,363.66 rows=10 width=1,299) (actual time=15,933.075..15,933.078 rows=20 loops=1)

  • Sort Key: relation_grouped.id DESC
  • Sort Method: top-N heapsort Memory: 26kB
4. 147.401 15,800.035 ↓ 34,115.7 341,157 1

Subquery Scan on relation_grouped (cost=1,399,358.27..1,399,363.47 rows=10 width=1,299) (actual time=12,428.786..15,800.035 rows=341,157 loops=1)

5. 0.000 15,652.634 ↓ 34,115.7 341,157 1

Group (cost=1,399,358.27..1,399,363.37 rows=10 width=769) (actual time=12,428.784..15,652.634 rows=341,157 loops=1)

  • Group Key: r.id, tz.time_zone, crp.color
6.          

Initplan (for Group)

7. 248.557 10,218.755 ↓ 10.8 341,157 1

HashAggregate (cost=1,398,901.43..1,399,216.45 rows=31,502 width=4) (actual time=10,114.506..10,218.755 rows=341,157 loops=1)

  • Group Key: edl.entity_id
8.          

CTE user_data_filter

9. 43.323 50.140 ↓ 1.0 155,719 1

Bitmap Heap Scan on user_data_access (cost=3,406.92..42,415.01 rows=148,967 width=48) (actual time=6.975..50.140 rows=155,719 loops=1)

  • Recheck Cond: (user_id = 1199)
  • Filter: (NOT deleted)
  • Heap Blocks: exact=1509
10. 6.817 6.817 ↓ 1.0 155,719 1

Bitmap Index Scan on idx_user_data_access_user_id (cost=0.00..3,369.68 rows=148,967 width=0) (actual time=6.817..6.817 rows=155,719 loops=1)

  • Index Cond: (user_id = 1199)
11. 83.340 9,970.198 ↓ 11.0 346,244 1

Append (cost=345,129.52..1,356,407.67 rows=31,502 width=4) (actual time=1,021.511..9,970.198 rows=346,244 loops=1)

12. 305.215 1,618.926 ↓ 12.2 346,244 1

Merge Join (cost=345,129.52..353,362.68 rows=28,316 width=4) (actual time=1,021.510..1,618.926 rows=346,244 loops=1)

  • Merge Cond: ((edl.ancestor_id = da.entity_id) AND (edl.ancestor_type_id = da.entity_type_id))
13. 611.219 1,016.887 ↓ 1.0 1,023,780 1

Sort (cost=336,122.69..338,586.48 rows=985,516 width=12) (actual time=794.122..1,016.887 rows=1,023,780 loops=1)

  • Sort Key: edl.ancestor_id, edl.ancestor_type_id
  • Sort Method: external merge Disk: 22056kB
14. 405.668 405.668 ↓ 1.0 1,023,780 1

Index Scan using idx_entity_data_link_entity_type_id on entity_data_link edl (cost=0.56..221,166.51 rows=985,516 width=12) (actual time=0.020..405.668 rows=1,023,780 loops=1)

  • Index Cond: (entity_type_id = 1)
  • Filter: (NOT deleted)
15. 171.014 296.824 ↓ 5.0 375,931 1

Sort (cost=9,006.82..9,193.03 rows=74,484 width=8) (actual time=227.327..296.824 rows=375,931 loops=1)

  • Sort Key: da.entity_id, da.entity_type_id
  • Sort Method: external sort Disk: 3360kB
16. 125.810 125.810 ↓ 2.1 155,719 1

CTE Scan on user_data_filter da (cost=0.00..2,979.34 rows=74,484 width=8) (actual time=6.979..125.810 rows=155,719 loops=1)

  • Filter: self_access
17. 0.001 8,267.932 ↓ 0.0 0 1

Nested Loop (cost=858,607.35..1,002,572.46 rows=3,186 width=4) (actual time=8,267.932..8,267.932 rows=0 loops=1)

  • Join Filter: (edc.ancestor_type_id = ANY (da_1.access_type_ids))
18. 0.007 8,267.931 ↓ 0.0 0 1

Merge Join (cost=858,606.79..884,298.63 rows=92,239 width=40) (actual time=8,267.931..8,267.931 rows=0 loops=1)

  • Merge Cond: ((edl_1.ancestor_id = da_1.entity_id) AND (edl_1.ancestor_type_id = da_1.entity_type_id))
19. 1,320.414 8,250.194 ↑ 3,210,355.0 1 1

Sort (cost=849,599.96..857,625.85 rows=3,210,355 width=16) (actual time=8,250.193..8,250.194 rows=1 loops=1)

  • Sort Key: edl_1.ancestor_id, edl_1.ancestor_type_id
  • Sort Method: external merge Disk: 84368kB
20. 6,929.780 6,929.780 ↓ 1.0 3,312,396 1

Seq Scan on entity_data_link edl_1 (cost=0.00..447,786.06 rows=3,210,355 width=16) (actual time=0.826..6,929.780 rows=3,312,396 loops=1)

  • Filter: (parent AND (NOT deleted))
  • Rows Removed by Filter: 14519610
21. 0.018 17.730 ↓ 0.0 0 1

Sort (cost=9,006.82..9,193.03 rows=74,484 width=40) (actual time=17.730..17.730 rows=0 loops=1)

  • Sort Key: da_1.entity_id, da_1.entity_type_id
  • Sort Method: quicksort Memory: 25kB
22. 17.712 17.712 ↓ 0.0 0 1

CTE Scan on user_data_filter da_1 (cost=0.00..2,979.34 rows=74,484 width=40) (actual time=17.712..17.712 rows=0 loops=1)

  • Filter: (NOT self_access)
  • Rows Removed by Filter: 155719
23. 0.000 0.000 ↓ 0.0 0

Index Scan using idx_entity_data_link_entity_type_id_ancestor_type_id_ancestor_i on entity_data_link edc (cost=0.56..1.21 rows=3 width=12) (never executed)

  • Index Cond: ((entity_type_id = 1) AND (ancestor_type_id = edl_1.entity_type_id) AND (ancestor_id = edl_1.entity_id))
  • Filter: (NOT deleted)
24. 254.351 12,508.968 ↓ 34,115.7 341,157 1

Sort (cost=141.81..141.84 rows=10 width=60) (actual time=12,428.671..12,508.968 rows=341,157 loops=1)

  • Sort Key: r.id, tz.time_zone, crp.color
  • Sort Method: external merge Disk: 24776kB
25. 372.413 12,254.617 ↓ 34,115.7 341,157 1

Nested Loop Left Join (cost=2.78..141.64 rows=10 width=60) (actual time=10,360.524..12,254.617 rows=341,157 loops=1)

26. 169.646 11,199.890 ↓ 34,115.7 341,157 1

Hash Left Join (cost=2.35..56.99 rows=10 width=60) (actual time=10,360.507..11,199.890 rows=341,157 loops=1)

  • Hash Cond: (r.time_zone_id = tz.id)
27. 11,030.215 11,030.215 ↓ 34,115.7 341,157 1

Index Scan using pk_relation on relation r (cost=0.42..55.05 rows=10 width=48) (actual time=10,360.462..11,030.215 rows=341,157 loops=1)

  • Index Cond: (id = ANY ($3))
  • Filter: ((NOT deleted) AND (client_id = 1007))
28. 0.013 0.029 ↑ 1.0 41 1

Hash (cost=1.41..1.41 rows=41 width=20) (actual time=0.028..0.029 rows=41 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 11kB
29. 0.016 0.016 ↑ 1.0 41 1

Seq Scan on time_zone tz (cost=0.00..1.41 rows=41 width=20) (actual time=0.008..0.016 rows=41 loops=1)

30. 682.314 682.314 ↑ 1.0 1 341,157

Index Scan using idx_composite_rating_performance_supid_cltid_chart_id on composite_rating_performance crp (cost=0.43..8.46 rows=1 width=12) (actual time=0.002..0.002 rows=1 loops=341,157)

  • Index Cond: ((supplier_id = r.id) AND (client_id = r.client_id) AND (client_id = 1007) AND (chart_id = 2))
Planning time : 2.249 ms
Execution time : 15,957.731 ms