explain.depesz.com

PostgreSQL's explain analyze made readable

Result: VX8r0

Settings
# exclusive inclusive rows x rows loops node
1. 0.000 0.771 ↓ 3.0 3 1

Result (cost=67.21..73.09 rows=1 width=515) (actual time=0.613..0.771 rows=3 loops=1)

  • One-Time Filter: ((current_setting('nimble.company_id'::text))::bytea = '\x4d670aba143e3287b9d4427a'::bytea)
2.          

Initplan (for Result)

3. 0.010 0.010 ↑ 1.0 1 1

Function Scan on can_view_all_contacts (cost=0.01..0.02 rows=1 width=1) (actual time=0.010..0.010 rows=1 loops=1)

4. 0.002 0.765 ↓ 3.0 3 1

Nested Loop Left Join (cost=67.21..73.09 rows=1 width=515) (actual time=0.609..0.765 rows=3 loops=1)

  • Join Filter: (contacts.id = contacts__timestamps.contact_id)
5. 0.006 0.718 ↓ 3.0 3 1

Nested Loop Left Join (cost=58.70..64.51 rows=1 width=374) (actual time=0.564..0.718 rows=3 loops=1)

  • Join Filter: (contacts.id = contacts_values.contact_id)
  • Rows Removed by Join Filter: 3
6. 0.008 0.202 ↓ 3.0 3 1

Nested Loop Left Join (cost=9.34..14.75 rows=1 width=233) (actual time=0.166..0.202 rows=3 loops=1)

  • Join Filter: (contacts.id = contacts__addresses.contact_id)
  • Rows Removed by Join Filter: 3
7. 0.065 0.065 ↓ 3.0 3 1

Index Scan using contacts_pkey on contacts (cost=0.43..5.78 rows=1 width=92) (actual time=0.046..0.065 rows=3 loops=1)

  • Index Cond: ((company_id = '\x4d670aba143e3287b9d4427a'::bytea) AND (id = ANY ('{""\\x56b1303eb2a6bd497256f7f2"",""\\x56b1303fb2a6bd497256f7ff"",""\\x56b1303fb2a6bd497256f808""}'::bytea[])))
  • Filter: ($0 OR (owner_id = (current_setting('nimble.user_id'::text))::bytea) OR (read_for_users && '{""\\x00""}'::bytea[]) OR (read_for_users && ARRAY[(current_setting('nimble.user_id'::text))::bytea]) OR (read_for_groups && (string_to_array(current_setting('nimble.group_ids'::text), ','::text))::bytea[]) OR (edit_for_users && ARRAY[(current_setting('nimble.user_id'::text))::bytea]) OR (edit_for_groups && (string_to_array(current_setting('nimble.group_ids'::text), ','::text))::bytea[]))
8. 0.021 0.129 ↓ 2.0 2 3

GroupAggregate (cost=8.91..8.95 rows=1 width=141) (actual time=0.042..0.043 rows=2 loops=3)

  • Group Key: contacts__addresses.contact_id
9. 0.027 0.108 ↓ 2.0 2 3

Sort (cost=8.91..8.91 rows=1 width=90) (actual time=0.036..0.036 rows=2 loops=3)

  • Sort Key: contacts__addresses.contact_id
  • Sort Method: quicksort Memory: 25kB
10. 0.059 0.081 ↓ 2.0 2 1

Index Scan using contacts__addresses_pkey on contacts__addresses (cost=0.55..8.90 rows=1 width=90) (actual time=0.066..0.081 rows=2 loops=1)

  • Index Cond: ((company_id = '\x4d670aba143e3287b9d4427a'::bytea) AND (contact_id = ANY ('{""\\x56b1303eb2a6bd497256f7f2"",""\\x56b1303fb2a6bd497256f7ff"",""\\x56b1303fb2a6bd497256f808""}'::bytea[])))
  • Filter: ((SubPlan 3) IS TRUE)
11.          

SubPlan (for Index Scan)

12. 0.017 0.022 ↑ 1.0 1 2

Index Scan using contacts_pkey on contacts contacts_1 (cost=0.45..2.81 rows=1 width=1) (actual time=0.011..0.011 rows=1 loops=2)

  • Index Cond: ((company_id = (current_setting('nimble.company_id'::text))::bytea) AND (id = contacts__addresses.contact_id))
  • Filter: ((company_id = company_id) AND ($2 OR (owner_id = (current_setting('nimble.user_id'::text))::bytea) OR (read_for_users && '{""\\x00""}'::bytea[]) OR (read_for_users && ARRAY[(current_setting('nimble.user_id'::text))::bytea]) OR (read_for_groups && (string_to_array(current_setting('nimble.group_ids'::text), ','::text))::bytea[]) OR (edit_for_users && ARRAY[(current_setting('nimble.user_id'::text))::bytea]) OR (edit_for_groups && (string_to_array(current_setting('nimble.group_ids'::text), ','::text))::bytea[])))
13.          

Initplan (for Index Scan)

14. 0.005 0.005 ↑ 1.0 1 1

Function Scan on can_view_all_contacts_1 (cost=0.01..0.02 rows=1 width=1) (actual time=0.004..0.005 rows=1 loops=1)

15. 0.123 0.510 ↑ 3.5 2 3

GroupAggregate (cost=49.36..49.61 rows=7 width=141) (actual time=0.139..0.170 rows=2 loops=3)

  • Group Key: contacts_values.contact_id
16. 0.035 0.387 ↓ 3.4 24 3

Sort (cost=49.36..49.38 rows=7 width=60) (actual time=0.127..0.129 rows=24 loops=3)

  • Sort Key: contacts_values.contact_id
  • Sort Method: quicksort Memory: 30kB
17. 0.107 0.352 ↓ 7.0 49 1

Index Scan using contacts_values_pkey on contacts_values (cost=0.56..49.26 rows=7 width=60) (actual time=0.050..0.352 rows=49 loops=1)

  • Index Cond: ((company_id = '\x4d670aba143e3287b9d4427a'::bytea) AND (contact_id = ANY ('{""\\x56b1303eb2a6bd497256f7f2"",""\\x56b1303fb2a6bd497256f7ff"",""\\x56b1303fb2a6bd497256f808""}'::bytea[])))
  • Filter: (alternatives: SubPlan 5 or hashed SubPlan 7)
18.          

SubPlan (for Index Scan)

19. 0.241 0.245 ↑ 1.0 1 49

Index Scan using contacts_pkey on contacts contacts_2 (cost=0.45..2.80 rows=1 width=0) (actual time=0.005..0.005 rows=1 loops=49)

  • Index Cond: ((company_id = (current_setting('nimble.company_id'::text))::bytea) AND (id = contacts_values.contact_id))
  • Filter: ((company_id = company_id) AND ($4 OR (owner_id = (current_setting('nimble.user_id'::text))::bytea) OR (read_for_users && '{""\\x00""}'::bytea[]) OR (read_for_users && ARRAY[(current_setting('nimble.user_id'::text))::bytea]) OR (read_for_groups && (string_to_array(current_setting('nimble.group_ids'::text), ','::text))::bytea[]) OR (edit_for_users && ARRAY[(current_setting('nimble.user_id'::text))::bytea]) OR (edit_for_groups && (string_to_array(current_setting('nimble.group_ids'::text), ','::text))::bytea[])) AND ((current_setting('nimble.view_all_contacts'::text))::boolean OR ((owner_id IS NOT NULL) AND (owner_id = (current_setting('nimble.user_id'::text))::bytea)) OR (read_for_users && '{""\\x00""}'::bytea[]) OR (read_for_users && ARRAY[(current_setting('nimble.user_id'::text))::bytea]) OR (read_for_groups && (string_to_array(current_setting('nimble.group_ids'::text), ','::text))::bytea[]) OR (edit_for_users && ARRAY[(current_setting('nimble.user_id'::text))::bytea]) OR (edit_for_groups && (string_to_array(current_setting('nimble.group_ids'::text), ','::text))::bytea[])))
20.          

Initplan (for Index Scan)

21. 0.004 0.004 ↑ 1.0 1 1

Function Scan on can_view_all_contacts_2 (cost=0.01..0.02 rows=1 width=1) (actual time=0.004..0.004 rows=1 loops=1)

22. 0.000 0.000 ↓ 0.0 0

Index Scan using contacts_pkey on contacts contacts_3 (cost=0.45..73,997.18 rows=144 width=13) (never executed)

  • Index Cond: (company_id = (current_setting('nimble.company_id'::text))::bytea)
  • Filter: ((company_id = company_id) AND ($6 OR (owner_id = (current_setting('nimble.user_id'::text))::bytea) OR (read_for_users && '{""\\x00""}'::bytea[]) OR (read_for_users && ARRAY[(current_setting('nimble.user_id'::text))::bytea]) OR (read_for_groups && (string_to_array(current_setting('nimble.group_ids'::text), ','::text))::bytea[]) OR (edit_for_users && ARRAY[(current_setting('nimble.user_id'::text))::bytea]) OR (edit_for_groups && (string_to_array(current_setting('nimble.group_ids'::text), ','::text))::bytea[])) AND ((current_setting('nimble.view_all_contacts'::text))::boolean OR ((owner_id IS NOT NULL) AND (owner_id = (current_setting('nimble.user_id'::text))::bytea)) OR (read_for_users && '{""\\x00""}'::bytea[]) OR (read_for_users && ARRAY[(current_setting('nimble.user_id'::text))::bytea]) OR (read_for_groups && (string_to_array(current_setting('nimble.group_ids'::text), ','::text))::bytea[]) OR (edit_for_users && ARRAY[(current_setting('nimble.user_id'::text))::bytea]) OR (edit_for_groups && (string_to_array(current_setting('nimble.group_ids'::text), ','::text))::bytea[])))
23.          

Initplan (for Index Scan)

24. 0.000 0.000 ↓ 0.0 0

Function Scan on can_view_all_contacts_3 (cost=0.01..0.02 rows=1 width=1) (never executed)

25. 0.000 0.045 ↓ 0.0 0 3

GroupAggregate (cost=8.49..8.52 rows=1 width=141) (actual time=0.015..0.015 rows=0 loops=3)

  • Group Key: contacts__timestamps.contact_id
26. 0.016 0.045 ↓ 0.0 0 3

Sort (cost=8.49..8.49 rows=1 width=45) (actual time=0.015..0.015 rows=0 loops=3)

  • Sort Key: contacts__timestamps.contact_id
  • Sort Method: quicksort Memory: 25kB
27. 0.029 0.029 ↓ 0.0 0 1

Index Scan using contacts__timestamps_pkey on contacts__timestamps (cost=0.41..8.48 rows=1 width=45) (actual time=0.029..0.029 rows=0 loops=1)

  • Index Cond: ((company_id = '\x4d670aba143e3287b9d4427a'::bytea) AND (contact_id = ANY ('{""\\x56b1303eb2a6bd497256f7f2"",""\\x56b1303fb2a6bd497256f7ff"",""\\x56b1303fb2a6bd497256f808""}'::bytea[])))
  • Filter: ((SubPlan 9) IS TRUE)
28.          

SubPlan (for Index Scan)

29. 0.000 0.000 ↓ 0.0 0

Index Scan using contacts_pkey on contacts contacts_4 (cost=0.45..2.81 rows=1 width=1) (never executed)

  • Index Cond: ((company_id = (current_setting('nimble.company_id'::text))::bytea) AND (id = contacts__timestamps.contact_id))
  • Filter: ((company_id = company_id) AND ($8 OR (owner_id = (current_setting('nimble.user_id'::text))::bytea) OR (read_for_users && '{""\\x00""}'::bytea[]) OR (read_for_users && ARRAY[(current_setting('nimble.user_id'::text))::bytea]) OR (read_for_groups && (string_to_array(current_setting('nimble.group_ids'::text), ','::text))::bytea[]) OR (edit_for_users && ARRAY[(current_setting('nimble.user_id'::text))::bytea]) OR (edit_for_groups && (string_to_array(current_setting('nimble.group_ids'::text), ','::text))::bytea[])))
30.          

Initplan (for Index Scan)

31. 0.000 0.000 ↓ 0.0 0

Function Scan on can_view_all_contacts_4 (cost=0.01..0.02 rows=1 width=1) (never executed)

Planning time : 5.371 ms
Execution time : 1.864 ms