Commit 1ceeda8a authored by Dan McGee's avatar Dan McGee Committed by Loui Chang
Browse files

Specify explicit joins for package search

Refactor the query to use explicit LEFT JOINs, which appears to be handled
by MySQL in a saner fashion than the previous implicit join syntax. This is
part two in a slight fixup for observed slow queries in the production
environment. With the new indexes and this fixup, a particular iteration of
this query will examine only 13346 rows instead of 272060.

Signed-off-by: default avatarDan McGee <>
Signed-off-by: default avatarLoui Chang <>
parent e2b3bd1c
......@@ -437,19 +437,19 @@ function pkg_search_page($SID="") {
Packages.Name, Packages.Version, Packages.Description, Packages.NumVotes,
Packages.ID, Packages.OutOfDate
FROM PackageCategories, PackageLocations, Packages
FROM Packages
LEFT JOIN Users ON (Packages.MaintainerUID = Users.ID) ";
if ($SID) {
$q .= "LEFT JOIN PackageVotes
ON (Packages.ID = PackageVotes.PackageID AND PackageVotes.UsersID = $myuid)
LEFT JOIN CommentNotify
ON (Packages.ID = CommentNotify.PkgID AND CommentNotify.UserID = $myuid) ";
$q .= "WHERE
Packages.CategoryID = PackageCategories.ID
AND Packages.LocationID = PackageLocations.ID
AND Packages.DummyPkg = 0 ";
$q .= "LEFT JOIN PackageCategories
ON (Packages.CategoryID = PackageCategories.ID)
LEFT JOIN PackageLocations
ON (Packages.LocationID = PackageLocations.ID)
WHERE Packages.DummyPkg = 0 ";
// TODO: possibly do string matching on category and
// location to make request variable values more sensible
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