Back

SQL Details

Executed SQL
EXPLAIN
SELECT accounts_group.id AS accounts_group_id, accounts_group.name AS accounts_group_name, accounts_group.description AS accounts_group_description, accounts_group.is_managed AS accounts_group_is_managed, accounts_group.privacy_policy AS accounts_group_privacy_policy, accounts_group.subscription_policy AS accounts_group_subscription_policy, accounts_group.created AS accounts_group_created, accounts_group.modified AS accounts_group_modified 
FROM accounts_group 
WHERE accounts_group.id IN (SELECT anon_1.accounts_group_id AS anon_1_accounts_group_id 
FROM (SELECT accounts_group.id AS accounts_group_id, accounts_group.name AS accounts_group_name, accounts_group.description AS accounts_group_description, accounts_group.is_managed AS accounts_group_is_managed, accounts_group.privacy_policy AS accounts_group_privacy_policy, accounts_group.subscription_policy AS accounts_group_subscription_policy, accounts_group.created AS accounts_group_created, accounts_group.modified AS accounts_group_modified 
FROM accounts_group JOIN accounts_group_members ON accounts_group.id = accounts_group_members.group_id 
WHERE accounts_group_members.user_id IS NULL AND accounts_group_members.state = %(state_1)s UNION SELECT accounts_group.id AS accounts_group_id, accounts_group.name AS accounts_group_name, accounts_group.description AS accounts_group_description, accounts_group.is_managed AS accounts_group_is_managed, accounts_group.privacy_policy AS accounts_group_privacy_policy, accounts_group.subscription_policy AS accounts_group_subscription_policy, accounts_group.created AS accounts_group_created, accounts_group.modified AS accounts_group_modified 
FROM accounts_group JOIN accounts_group_admin ON accounts_group.id = accounts_group_admin.group_id 
WHERE accounts_group_admin.admin_id IS NULL AND accounts_group_admin.admin_type = %(admin_type_1)s) AS anon_1)
Original query duration
1.2133 ms
QUERY PLAN
Hash Semi Join (cost=40.60..52.27 rows=2 width=585)
Hash Cond: (accounts_group.id = anon_1.accounts_group_id)
-> Seq Scan on accounts_group (cost=0.00..11.30 rows=130 width=585)
-> Hash (cost=40.58..40.58 rows=2 width=4)
-> Subquery Scan on anon_1 (cost=40.51..40.58 rows=2 width=4)
-> Unique (cost=40.51..40.56 rows=2 width=585)
-> Sort (cost=40.51..40.52 rows=2 width=585)
Sort Key: accounts_group_1.id, accounts_group_1.name, accounts_group_1.description, accounts_group_1.is_managed, accounts_group_1.privacy_policy, accounts_group_1.subscription_policy, accounts_group_1.created, accounts_group_1.modified
-> Append (cost=4.35..40.50 rows=2 width=585)
-> Nested Loop (cost=4.35..22.63 rows=1 width=585)
-> Bitmap Heap Scan on accounts_group_members (cost=4.21..14.35 rows=1 width=4)
Recheck Cond: (user_id IS NULL)
Filter: ((state)::text = 'M'::text)
-> Bitmap Index Scan on pk_accounts_group_members (cost=0.00..4.21 rows=7 width=0)
Index Cond: (user_id IS NULL)
-> Index Scan using pk_accounts_group on accounts_group accounts_group_1 (cost=0.14..8.16 rows=1 width=585)
Index Cond: (id = accounts_group_members.group_id)
-> Nested Loop (cost=0.29..17.84 rows=1 width=585)
-> Index Only Scan using uq_accounts_group_admin_group_id on accounts_group_admin (cost=0.14..9.55 rows=1 width=4)
Index Cond: ((admin_type = 'User'::text) AND (admin_id IS NULL))
-> Index Scan using pk_accounts_group on accounts_group accounts_group_2 (cost=0.14..8.16 rows=1 width=585)
Index Cond: (id = accounts_group_admin.group_id)