Commit 61184b07 authored by Mike Hibler's avatar Mike Hibler
Browse files

Rewrite a query that took 6-10 seconds into one that is near instantaneous.

The old select that extracted external images visible to an experiment
had multiple left joins and examined 11M rows. The new query is a union
of two selects.
parent c9607dd3
......@@ -675,16 +675,23 @@ sub GenDefsFile($)
if (defined($this_user)) {
my $uid_idx = $this_user->uid_idx();
$query_result =
DBQueryFatal("select distinct o.pid,o.osname from os_info as o ".
"left join image_permissions as p1 on ".
" p1.imageid=o.osid and p1.permission_type='group' ".
"left join image_permissions as p2 on ".
" p2.imageid=o.osid and p2.permission_type='user' ".
"left join group_membership as g on ".
" g.gid_idx=p1.permission_idx ".
"where o.ezid!=0 and ".
" (g.uid_idx='$uid_idx' or ".
" p2.permission_idx='$uid_idx')");
DBQueryFatal("SELECT o.pid,o.osname FROM ".
" os_info AS o, ".
" image_permissions AS p ".
"WHERE o.ezid!=0 ".
" AND p.imageid=o.osid ".
" AND p.permission_type='user' ".
" AND p.permission_idx='$uid_idx' ".
"UNION DISTINCT ".
"SELECT o.pid,o.osname FROM ".
" os_info AS o, ".
" image_permissions AS p, ".
" group_membership as g ".
"WHERE o.ezid!=0 ".
" AND p.imageid=o.osid ".
" AND p.permission_type='group' ".
" AND p.permission_idx=g.gid_idx ".
" AND g.uid_idx='$uid_idx'");
while (my ($pid,$osname) = $query_result->fetchrow_array()) {
print TCL "set osids($pid/$osname) 1\n";
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment