File nepomuk-2.diff of Package kdelibs4

commit f4e101db050c590db930dbb4d1ed060d4f8d3982
Author: Sebastian Trueg <trueg@kde.org>
Date:   Tue Jan 11 13:39:16 2011 +0100

    Yet another strange optimization: When using "?r nao:userVisible 1" to restrict to visible
    results the Virtuoso optimizer does treat this pattern with a high priority, using it to
    preselect results or something like that. This is not what we want. Since the big part of
    the resources is in fact visible we want that pattern to be used as a filter at the end of
    the query.
    The only way to force this (besides bypassing the Virtuoso query optimizer which would be
    a bad idea) is to use a filter that is not an equality: "?r nao:userVisible ?v . FILTER(?v>0)"

diff --git a/nepomuk/query/query.cpp b/nepomuk/query/query.cpp
index 8955c3d..775c641 100644
--- a/nepomuk/query/query.cpp
+++ b/nepomuk/query/query.cpp
@@ -369,11 +369,15 @@ QString Nepomuk::Query::Query::toSparqlQuery( SparqlFlags sparqlFlags ) const
     // - We use an integer instead of a boolean because Virtuoso does not support booleans and, thus, Soprano converts
     //   booleans into a fake type which is stored as a string. This makes comparision much slower.
     // - Instead of using crappy inference via "?r a ?t . ?t nao:userVisible true" we can directly check the resources.
+    // - Instead of restricting the visibility to 1 we trick the Virtuoso query optimizer so it won't try to use the visibility
+    //   as priority. We do this with a filter that does not test for equality. Using "?r nao:userVisible 1" has a drastic
+    //   performance impact which the filter has not.
     //
     QString userVisibilityRestriction;
     if( !(queryFlags()&NoResultRestrictions) ) {
-        userVisibilityRestriction = QString::fromLatin1("?r %1 1 . ")
-                .arg(Soprano::Node::resourceToN3(Soprano::Vocabulary::NAO::userVisible()));
+        userVisibilityRestriction = QString::fromLatin1("?r %1 %2 . FILTER(%2>0) . ")
+                .arg(Soprano::Node::resourceToN3(Soprano::Vocabulary::NAO::userVisible()),
+                     qbd.uniqueVarName());
     }
 
 
diff --git a/nepomuk/query/query.h b/nepomuk/query/query.h
index 07300e3..2c37520 100644
--- a/nepomuk/query/query.h
+++ b/nepomuk/query/query.h
@@ -400,6 +400,9 @@ namespace Nepomuk {
              * Convert the query into a SPARQL query which can be used with the
              * Nepomuk query service or directly in Soprano::Model::executeQuery.
              *
+             * It is recommended to use QueryServiceClient instead of creating
+             * the SPARQL query this way.
+             *
              * The resulting query will bind the results to variable \p 'r'. Request
              * properties will be bound to variables \p 'reqProp1' through \p 'reqPropN'
              * (the only exception is a count query created via the CreateCountQuery flag).
openSUSE Build Service is sponsored by