From: Jens Frank Date: Sat, 1 Jan 2005 11:50:19 +0000 (+0000) Subject: BUG#1244 Use a UNION to improve index use. X-Git-Tag: 1.5.0alpha1~1003 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=ceb415f7edb31fb027f210677361cc422baba5ba;p=lhc%2Fweb%2Fwiklou.git BUG#1244 Use a UNION to improve index use. --- diff --git a/includes/Block.php b/includes/Block.php index 3b4916c288..3f0ed48717 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -76,7 +76,14 @@ class Block $sql = "SELECT * FROM $ipblocks WHERE ipb_user={$user} $options"; } elseif ($user=="") { $sql = "SELECT * FROM $ipblocks WHERE ipb_address='" . $db->strencode( $address ) . "' $options"; + } elseif ( $options=='' ) { + # If there are no optiones (e.g. FOR UPDATE), use a UNION + # so that the query can make efficient use of indices + $sql = "SELECT * FROM $ipblocks WHERE ipb_address='" . $db->strencode( $address ) . + "' UNION SELECT * FROM $ipblocks WHERE ipb_user={$user}"; } else { + # If there are options, a UNION can not be used, use one + # SELECT instead. Will do a full table scan. $sql = "SELECT * FROM $ipblocks WHERE (ipb_address='" . $db->strencode( $address ) . "' OR ipb_user={$user}) $options"; }