Commit f51d4c32 authored by Florian Pritz's avatar Florian Pritz Committed by Lukas Fleischer
Browse files

Remove disjunction in pkg_providers query



For some reason, running the SELECT .. WHERE .. OR .. query takes e.g.
58ms on a randomly generated db for some dependency name. Splitting the
OR into two dedicated queries and UNIONing the result takes only 0.42ms.

On the Arch Linux installation, searching for the providers of e.g.
mongodb takes >=110ms when not cached by the query cache. The new query
takes <1ms even when not cached.

Signed-off-by: Florian Pritz's avatarFlorian Pritz <bluewind@xinu.at>
Signed-off-by: Lukas Fleischer's avatarLukas Fleischer <lfleischer@archlinux.org>
parent 34a0d399
......@@ -212,10 +212,12 @@ function pkg_groups($pkgid) {
function pkg_providers($name) {
$dbh = DB::connect();
$q = "SELECT p.ID, p.Name FROM Packages p ";
$q.= "WHERE p.Name = " . $dbh->quote($name) . " ";
$q.= "UNION ";
$q.= "SELECT p.ID, p.Name FROM Packages p ";
$q.= "LEFT JOIN PackageRelations pr ON pr.PackageID = p.ID ";
$q.= "LEFT JOIN RelationTypes rt ON rt.ID = pr.RelTypeID ";
$q.= "WHERE p.Name = " . $dbh->quote($name) . " ";
$q.= "OR (rt.Name = 'provides' ";
$q.= "WHERE (rt.Name = 'provides' ";
$q.= "AND pr.RelName = " . $dbh->quote($name) . ")";
$q.= "UNION ";
$q.= "SELECT 0, Name FROM OfficialProviders ";
......
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