explain.depesz.com

PostgreSQL's explain analyze made readable

Result: 9eoW

Settings
# exclusive inclusive rows x rows loops node
1. 428.174 22,858.481 ↓ 1.0 4,693,321 1

Result (cost=0.56..65,238,332.36 rows=4,538,339 width=26) (actual time=1,079.560..22,858.481 rows=4,693,321 loops=1)

  • One-Time Filter: ((current_setting('nimble.company_id'::text))::bytea = '\x4c2118ad54397f271b000000'::bytea)
2. 7,454.454 22,430.307 ↓ 1.0 4,693,321 1

Index Only Scan using contacts_tags_associations_pkey on contacts_tags_associations (cost=0.56..65,238,332.36 rows=4,538,339 width=26) (actual time=1,079.556..22,430.307 rows=4,693,321 loops=1)

  • Index Cond: (company_id = '\x4c2118ad54397f271b000000'::bytea)
  • Filter: ((SubPlan 1) OR (alternatives: SubPlan 2 or hashed SubPlan 3) OR (SubPlan 4) OR (SubPlan 5) OR (SubPlan 6))
  • Rows Removed by Filter: 20,308
  • Heap Fetches: 4,713,629
3.          

SubPlan (for Index Only Scan)

4. 14,140.887 14,140.887 ↑ 1.0 1 4,713,629

Index Scan using contacts_pkey on contacts (cost=0.44..2.78 rows=1 width=0) (actual time=0.003..0.003 rows=1 loops=4,713,629)

  • Index Cond: ((company_id = (current_setting('nimble.company_id'::text))::bytea) AND (contacts_tags_associations.contact_id = id))
  • Filter: (((read_for_users IS NULL) OR (((string_to_array(current_setting('nimble.user_id'::text), ','::text))::bytea[] && read_for_users) AND (company_id = (current_setting('nimble.company_id'::text))::bytea)) OR (read_for_groups IS NULL) OR (((string_to_array(current_setting('nimble.group_ids'::text), ','::text))::bytea[] && read_for_groups) AND (company_id = (current_setting('nimble.company_id'::text))::bytea)) OR ((owner_id = (current_setting('nimble.user_id'::text))::bytea) AND (company_id = (current_setting('nimble.company_id'::text))::bytea)) OR (edit_for_users IS NULL) OR (((string_to_array(current_setting('nimble.user_id'::text), ','::text))::bytea[] && edit_for_users) AND (company_id = (current_setting('nimble.company_id'::text))::bytea)) OR (edit_for_groups IS NULL) OR (((string_to_array(current_setting('nimble.group_ids'::text), ','::text))::bytea[] && edit_for_groups) AND (company_id = (current_setting('nimble.company_id'::text))::bytea))) AND ((read_for_users IS NULL) OR ((string_to_array(current_setting('nimble.user_id'::text), ','::text))::bytea[] && read_for_users)))
  • Rows Removed by Filter: 0
5. 0.000 0.000 ↓ 0.0 0

Index Scan using contacts_pkey on contacts contacts_1 (cost=0.44..2.77 rows=1 width=0) (never executed)

  • Index Cond: ((company_id = (current_setting('nimble.company_id'::text))::bytea) AND (contacts_tags_associations.contact_id = id))
  • Filter: ((owner_id = (current_setting('nimble.user_id'::text))::bytea) AND ((read_for_users IS NULL) OR (((string_to_array(current_setting('nimble.user_id'::text), ','::text))::bytea[] && read_for_users) AND (company_id = (current_setting('nimble.company_id'::text))::bytea)) OR (read_for_groups IS NULL) OR (((string_to_array(current_setting('nimble.group_ids'::text), ','::text))::bytea[] && read_for_groups) AND (company_id = (current_setting('nimble.company_id'::text))::bytea)) OR ((owner_id = (current_setting('nimble.user_id'::text))::bytea) AND (company_id = (current_setting('nimble.company_id'::text))::bytea)) OR (edit_for_users IS NULL) OR (((string_to_array(current_setting('nimble.user_id'::text), ','::text))::bytea[] && edit_for_users) AND (company_id = (current_setting('nimble.company_id'::text))::bytea)) OR (edit_for_groups IS NULL) OR (((string_to_array(current_setting('nimble.group_ids'::text), ','::text))::bytea[] && edit_for_groups) AND (company_id = (current_setting('nimble.company_id'::text))::bytea))))
6. 0.012 0.012 ↓ 0.0 0 1

Index Scan using ix_company_id_owner_id on contacts contacts_2 (cost=0.44..18.60 rows=26 width=13) (actual time=0.012..0.012 rows=0 loops=1)

  • Index Cond: ((company_id = (current_setting('nimble.company_id'::text))::bytea) AND (owner_id = (current_setting('nimble.user_id'::text))::bytea))
  • Filter: ((read_for_users IS NULL) OR (((string_to_array(current_setting('nimble.user_id'::text), ','::text))::bytea[] && read_for_users) AND (company_id = (current_setting('nimble.company_id'::text))::bytea)) OR (read_for_groups IS NULL) OR (((string_to_array(current_setting('nimble.group_ids'::text), ','::text))::bytea[] && read_for_groups) AND (company_id = (current_setting('nimble.company_id'::text))::bytea)) OR ((owner_id = (current_setting('nimble.user_id'::text))::bytea) AND (company_id = (current_setting('nimble.company_id'::text))::bytea)) OR (edit_for_users IS NULL) OR (((string_to_array(current_setting('nimble.user_id'::text), ','::text))::bytea[] && edit_for_users) AND (company_id = (current_setting('nimble.company_id'::text))::bytea)) OR (edit_for_groups IS NULL) OR (((string_to_array(current_setting('nimble.group_ids'::text), ','::text))::bytea[] && edit_for_groups) AND (company_id = (current_setting('nimble.company_id'::text))::bytea)))
7. 347.562 347.562 ↓ 0.0 0 38,618

Index Scan using contacts_pkey on contacts contacts_3 (cost=0.44..2.78 rows=1 width=0) (actual time=0.009..0.009 rows=0 loops=38,618)

  • Index Cond: ((company_id = (current_setting('nimble.company_id'::text))::bytea) AND (contacts_tags_associations.contact_id = id))
  • Filter: (((read_for_users IS NULL) OR (((string_to_array(current_setting('nimble.user_id'::text), ','::text))::bytea[] && read_for_users) AND (company_id = (current_setting('nimble.company_id'::text))::bytea)) OR (read_for_groups IS NULL) OR (((string_to_array(current_setting('nimble.group_ids'::text), ','::text))::bytea[] && read_for_groups) AND (company_id = (current_setting('nimble.company_id'::text))::bytea)) OR ((owner_id = (current_setting('nimble.user_id'::text))::bytea) AND (company_id = (current_setting('nimble.company_id'::text))::bytea)) OR (edit_for_users IS NULL) OR (((string_to_array(current_setting('nimble.user_id'::text), ','::text))::bytea[] && edit_for_users) AND (company_id = (current_setting('nimble.company_id'::text))::bytea)) OR (edit_for_groups IS NULL) OR (((string_to_array(current_setting('nimble.group_ids'::text), ','::text))::bytea[] && edit_for_groups) AND (company_id = (current_setting('nimble.company_id'::text))::bytea))) AND ((read_for_groups IS NULL) OR ((string_to_array(current_setting('nimble.user_id'::text), ','::text))::bytea[] && read_for_groups)))
  • Rows Removed by Filter: 1
8. 243.696 243.696 ↓ 0.0 0 20,308

Index Scan using contacts_pkey on contacts contacts_4 (cost=0.44..2.78 rows=1 width=0) (actual time=0.012..0.012 rows=0 loops=20,308)

  • Index Cond: ((company_id = (current_setting('nimble.company_id'::text))::bytea) AND (contacts_tags_associations.contact_id = id))
  • Filter: (((read_for_users IS NULL) OR (((string_to_array(current_setting('nimble.user_id'::text), ','::text))::bytea[] && read_for_users) AND (company_id = (current_setting('nimble.company_id'::text))::bytea)) OR (read_for_groups IS NULL) OR (((string_to_array(current_setting('nimble.group_ids'::text), ','::text))::bytea[] && read_for_groups) AND (company_id = (current_setting('nimble.company_id'::text))::bytea)) OR ((owner_id = (current_setting('nimble.user_id'::text))::bytea) AND (company_id = (current_setting('nimble.company_id'::text))::bytea)) OR (edit_for_users IS NULL) OR (((string_to_array(current_setting('nimble.user_id'::text), ','::text))::bytea[] && edit_for_users) AND (company_id = (current_setting('nimble.company_id'::text))::bytea)) OR (edit_for_groups IS NULL) OR (((string_to_array(current_setting('nimble.group_ids'::text), ','::text))::bytea[] && edit_for_groups) AND (company_id = (current_setting('nimble.company_id'::text))::bytea))) AND ((edit_for_users IS NULL) OR ((string_to_array(current_setting('nimble.user_id'::text), ','::text))::bytea[] && edit_for_users)))
  • Rows Removed by Filter: 1
9. 243.696 243.696 ↓ 0.0 0 20,308

Index Scan using contacts_pkey on contacts contacts_5 (cost=0.44..2.78 rows=1 width=0) (actual time=0.012..0.012 rows=0 loops=20,308)

  • Index Cond: ((company_id = (current_setting('nimble.company_id'::text))::bytea) AND (contacts_tags_associations.contact_id = id))
  • Filter: (((read_for_users IS NULL) OR (((string_to_array(current_setting('nimble.user_id'::text), ','::text))::bytea[] && read_for_users) AND (company_id = (current_setting('nimble.company_id'::text))::bytea)) OR (read_for_groups IS NULL) OR (((string_to_array(current_setting('nimble.group_ids'::text), ','::text))::bytea[] && read_for_groups) AND (company_id = (current_setting('nimble.company_id'::text))::bytea)) OR ((owner_id = (current_setting('nimble.user_id'::text))::bytea) AND (company_id = (current_setting('nimble.company_id'::text))::bytea)) OR (edit_for_users IS NULL) OR (((string_to_array(current_setting('nimble.user_id'::text), ','::text))::bytea[] && edit_for_users) AND (company_id = (current_setting('nimble.company_id'::text))::bytea)) OR (edit_for_groups IS NULL) OR (((string_to_array(current_setting('nimble.group_ids'::text), ','::text))::bytea[] && edit_for_groups) AND (company_id = (current_setting('nimble.company_id'::text))::bytea))) AND ((edit_for_groups IS NULL) OR ((string_to_array(current_setting('nimble.user_id'::text), ','::text))::bytea[] && edit_for_groups)))
  • Rows Removed by Filter: 1
Planning time : 3.834 ms
Execution time : 23,025.400 ms