From fd3e17b04c4d83dc25566f6a44fc7a377e0fb2fc Mon Sep 17 00:00:00 2001 From: Oliver Bock Date: Fri, 4 Mar 2016 14:42:41 +0000 Subject: [PATCH] Improve DB queries * WHERE IN clauses perform really bad for long lists/sub-queries * Using INNER JOINs to speed up the queries * Down from a couple of minutes to less than a second :-) --- html/inc/util_ops.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/html/inc/util_ops.inc b/html/inc/util_ops.inc index d43457af9c..4cb091f2d4 100644 --- a/html/inc/util_ops.inc +++ b/html/inc/util_ops.inc @@ -359,8 +359,8 @@ if (!isset($skip_auth_ops) && array_key_exists("SERVER_PORT", $_SERVER)) { // function cancel_wus_where($clause) { $q1 = "CREATE TEMPORARY TABLE tmp SELECT id FROM workunit WHERE $clause;"; - $q2 = "UPDATE result SET server_state=5, outcome=5 WHERE server_state=2 AND workunitid in (SELECT id FROM tmp);"; - $q3 = "UPDATE workunit SET error_mask=error_mask|16, transition_time=0 WHERE id in (SELECT id FROM tmp);"; + $q2 = "UPDATE result r INNER JOIN tmp t on r.workunitid=t.id SET server_state=5, outcome=5 WHERE server_state=2;"; + $q3 = "UPDATE workunit w INNER JOIN tmp t on w.id=t.id SET error_mask=error_mask|16, transition_time=0;"; $q4 = "DROP TABLE tmp;"; if (!_mysql_query($q1)) {