Hi,
I have a problem with the query "permissions" in
acs-subsite/www/permissions/perm-include-postgresql.xql
This is called for instance under forums-->administration-->permissions of a forum
The same query worked under dotLRN 2.0.3
Now after upgrade to 2.1 it is never returning
After analyzing the query I found out, that removing the first sub query the query at least returns after 70 sec.
<h3>Full Query</h3>
select ptab.grantee_id,
acs_object__name(ptab.grantee_id) as grantee_name,
o.object_type,
sum(ptab.read_p) as read_p, (case when sum(ptab.read_p) > 0 then 'checked' else '' end) as read_checked, sum(ptab.create_p) as create_p, (case when sum(ptab.create_p) > 0 then 'checked' else '' end) as create_checked, sum(ptab.write_p) as write_p, (case when sum(ptab.write_p) > 0 then 'checked' else '' end) as write_checked, sum(ptab.admin_p) as admin_p, (case when sum(ptab.admin_p) > 0 then 'checked' else '' end) as admin_checked,
sum(read_p + create_p + write_p + admin_p) as any_perm_p_
from (select grantee_id,
(case when privilege='read' then 2 else 0 end) as read_p, (case when privilege='create' then 2 else 0 end) as create_p, (case when privilege='write' then 2 else 0 end) as write_p, (case when privilege='admin' then 2 else 0 end) as admin_p
from acs_permissions_all
where object_id = '367496'
union all
select grantee_id,
(case when privilege='read' then -1 else 0 end) as read_p, (case when privilege='create' then -1 else 0 end) as create_p, (case when privilege='write' then -1 else 0 end) as write_p, (case when privilege='admin' then -1 else 0 end) as admin_p
from acs_permissions
where object_id = '367496'
union all
select -1 as grantee_id,
0 as read_p, 0 as create_p, 0 as write_p, 0 as admin_p
union all
select -2 as grantee_id,
0 as read_p, 0 as create_p, 0 as write_p, 0 as admin_p
union all
select component_id as grantee_id,
0 as read_p, 0 as create_p, 0 as write_p, 0 as admin_p
from group_component_map
where group_id = '-2'
union all
select segment_id as grantee_id,
0 as read_p, 0 as create_p, 0 as write_p, 0 as admin_p
from rel_segments rel_seg
where rel_seg.group_id = '-2'
union all
select segment_id as grantee_id,
0 as read_p, 0 as create_p, 0 as write_p, 0 as admin_p
from rel_segments rel_seg,
group_component_map gcm
where gcm.group_id = '-2'
and rel_seg.group_id = gcm.group_id
) ptab,
acs_objects o
where o.object_id = ptab.grantee_id
and acs_permission__permission_p(0, ptab.grantee_id, 'admin') = 'f'
group by ptab.grantee_id, grantee_name, object_type
order by object_type desc, grantee_name
<h3>Deleted sub query</h3>
select grantee_id,
(case when privilege='read' then 2 else 0 end) as read_p, (case when privilege='create' then 2 else 0 end) as create_p, (case when privilege='write' then 2 else 0 end) as write_p, (case when privilege='admin' then 2 else 0 end) as admin_p
from acs_permissions_all
where object_id = '367496'
union all
<h3>Results of "explain analyze"</h3>
- <h4>Before Upgrade</h4>
QUERY PLAN
Sort (cost=4130.43..4130.44 rows=1 width=41) (actual time=703.53..703.54 rows=7 loops=1)
Sort Key: o.object_type, acs_object__name(ptab.grantee_id)
-> Aggregate (cost=4130.23..4130.42 rows=1 width=41) (actual time=703.38..703.46 rows=7 loops=1)
-> Group (cost=4130.23..4130.29 rows=6 width=41) (actual time=703.34..703.38 rows=10 loops=1)
-> Sort (cost=4130.23..4130.24 rows=6 width=41) (actual time=703.34..703.34 rows=10 loops=1)
Sort Key: ptab.grantee_id, acs_object__name(ptab.grantee_id), o.object_type
-> Nested Loop (cost=0.00..4130.15 rows=6 width=41) (actual time=3.49..703.25 rows=10 loops=1)
-> Subquery Scan ptab (cost=0.00..4110.07 rows=6 width=15) (actual time=0.98..680.43 rows=10 loops=1)
-> Append (cost=0.00..4110.07 rows=6 width=15) (actual time=0.97..680.36 rows=10 loops=1)
-> Subquery Scan "*SELECT* 1" (cost=0.00..30.91 rows=1 width=15) (actual time=0.97..3.03 rows=4 loops=1)
-> Index Scan using acs_permissions_pk on acs_permissions (cost=0.00..30.91 rows=1 width=15) (actual time=0.96..3.00 rows=4 loops=1)
Index Cond: (object_id = 367496)
Filter: (acs_permission__permission_p(0, grantee_id, 'admin'::character varying) = false)
-> Subquery Scan "*SELECT* 2" (cost=0.00..0.01 rows=1 width=0) (actual time=0.67..0.68 rows=1 loops=1)
-> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.67..0.67 rows=1 loops=1)
One-Time Filter: (acs_permission__permission_p(0, -1, 'admin'::character varying) = false)
-> Subquery Scan "*SELECT* 3" (cost=0.00..0.01 rows=1 width=0) (actual time=0.67..0.68 rows=1 loops=1)
-> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.67..0.67 rows=1 loops=1)
One-Time Filter: (acs_permission__permission_p(0, -2, 'admin'::character varying) = false)
-> Subquery Scan "*SELECT* 4" (cost=0.00..2863.14 rows=1 width=4) (actual time=72.34..72.34 rows=0 loops=1)
-> Seq Scan on group_element_index (cost=0.00..2863.14 rows=1 width=4) (actual time=72.34..72.34 rows=0 loops=1)
Filter: ((ancestor_rel_type = 'composition_rel'::character varying) AND (group_id = -2) AND (acs_permission__permission_p(0, element_id, 'admin'::character varying) = false))
-> Subquery Scan "*SELECT* 5" (cost=0.00..11.67 rows=1 width=4) (actual time=0.98..2.40 rows=4 loops=1)
-> Index Scan using rel_segments_grp_rel_type_uq on rel_segments rel_seg (cost=0.00..11.67 rows=1 width=4) (actual time=0.97..2.37 rows=4 loops=1)
Index Cond: (group_id = -2)
Filter: (acs_permission__permission_p(0, segment_id, 'admin'::character varying) = false)
-> Subquery Scan "*SELECT* 6" (cost=0.00..1204.32 rows=1 width=12) (actual time=601.19..601.19 rows=0 loops=1)
-> Nested Loop (cost=0.00..1204.32 rows=1 width=12) (actual time=601.19..601.19 rows=0 loops=1)
-> Seq Scan on rel_segments rel_seg (cost=0.00..13.75 rows=2 width=8) (actual time=0.47..176.74 rows=450 loops=1)
Filter: (acs_permission__permission_p(0, segment_id, 'admin'::character varying) = false)
-> Index Scan using group_elem_idx_group_idx on group_element_index (cost=0.00..529.13 rows=1 width=4) (actual time=0.94..0.94 rows=0 loops=450)
Index Cond: (("outer".group_id = group_element_index.group_id) AND (group_element_index.group_id = -2))
Filter: (ancestor_rel_type = 'composition_rel'::character varying)
-> Index Scan using acs_objects_pk on acs_objects o (cost=0.00..3.33 rows=1 width=21) (actual time=0.05..0.06 rows=1 loops=10)
Index Cond: (o.object_id = "outer".grantee_id)
Total runtime: 703.96 msec
- <h4>After Upgrade</h4>
QUERY PLAN
Sort (cost=3292.78..3292.78 rows=1 width=192) (actual time=66187.68..66187.69 rows=7 loops=1)
Sort Key: o.object_type, acs_object__name(ptab.grantee_id)
-> Aggregate (cost=3292.51..3292.77 rows=1 width=192) (actual time=66187.52..66187.60 rows=7 loops=1)
-> Group (cost=3292.51..3292.59 rows=8 width=192) (actual time=66187.47..66187.51 rows=10 loops=1)
-> Sort (cost=3292.51..3292.53 rows=8 width=192) (actual time=66187.46..66187.47 rows=10 loops=1)
Sort Key: ptab.grantee_id, acs_object__name(ptab.grantee_id), o.object_type
-> Nested Loop (cost=0.00..3292.39 rows=8 width=192) (actual time=218.35..66187.41 rows=10 loops=1)
-> Subquery Scan ptab (cost=0.00..3244.88 rows=8 width=172) (actual time=216.04..66074.82 rows=10 loops=1)
-> Append (cost=0.00..3244.88 rows=8 width=172) (actual time=216.03..66074.76 rows=10 loops=1)
-> Subquery Scan "*SELECT* 1" (cost=0.00..1684.72 rows=3 width=172) (actual time=216.03..760.72 rows=4 loops=1)
-> Index Scan using acs_permissions_pk on acs_permissions (cost=0.00..1684.72 rows=3 width=172) (actual time=216.02..760.69 rows=4 loops=1)
Index Cond: (object_id = 367496)
Filter: (acs_permission__permission_p(0, grantee_id, 'admin'::character varying) = false)
-> Subquery Scan "*SELECT* 2" (cost=0.00..0.01 rows=1 width=0) (actual time=132.87..132.87 rows=1 loops=1)
-> Result (cost=0.00..0.01 rows=1 width=0) (actual time=132.86..132.86 rows=1 loops=1)
One-Time Filter: (acs_permission__permission_p(0, -1, 'admin'::character varying) = false)
-> Subquery Scan "*SELECT* 3" (cost=0.00..0.01 rows=1 width=0) (actual time=131.24..131.24 rows=1 loops=1)
-> Result (cost=0.00..0.01 rows=1 width=0) (actual time=131.24..131.24 rows=1 loops=1)
One-Time Filter: (acs_permission__permission_p(0, -2, 'admin'::character varying) = false)
-> Subquery Scan "*SELECT* 4" (cost=0.00..1511.35 rows=1 width=4) (actual time=56.58..56.58 rows=0 loops=1)
-> Index Scan using group_elem_idx_group_idx on group_element_index (cost=0.00..1511.35 rows=1 width=4) (actual time=56.58..56.58 rows=0 loops=1)
Index Cond: (group_id = -2)
Filter: ((ancestor_rel_type = 'composition_rel'::character varying) AND (acs_permission__permission_p(0, element_id, 'admin'::character varying) = false))
-> Subquery Scan "*SELECT* 5" (cost=0.00..9.80 rows=1 width=4) (actual time=138.77..545.64 rows=4 loops=1)
-> Index Scan using rel_segments_grp_rel_type_uq on rel_segments rel_seg (cost=0.00..9.80 rows=1 width=4) (actual time=138.76..545.62 rows=4 loops=1)
Index Cond: (group_id = -2)
Filter: (acs_permission__permission_p(0, segment_id, 'admin'::character varying) = false)
-> Subquery Scan "*SELECT* 6" (cost=0.00..39.00 rows=1 width=12) (actual time=64447.67..64447.67 rows=0 loops=1)
-> Nested Loop (cost=0.00..39.00 rows=1 width=12) (actual time=64447.66..64447.66 rows=0 loops=1)
-> Seq Scan on rel_segments rel_seg (cost=0.00..13.75 rows=2 width=8) (actual time=132.99..64219.12 rows=458 loops=1)
Filter: (acs_permission__permission_p(0, segment_id, 'admin'::character varying) = false)
-> Index Scan using group_elem_idx_group_idx on group_element_index (cost=0.00..11.21 rows=1 width=4) (actual time=0.49..0.49 rows=0 loops=458)
Index Cond: (("outer".group_id = group_element_index.group_id) AND (group_element_index.group_id = -2))
Filter: (ancestor_rel_type = 'composition_rel'::character varying)
-> Index Scan using acs_objects_pk on acs_objects o (cost=0.00..6.01 rows=1 width=172) (actual time=9.28..9.28 rows=1 loops=10)
Index Cond: (o.object_id = "outer".grantee_id)
Total runtime: 66187.96 msec
Any idea why?
Greetings,
Nima