# HG changeset patch # User Alain Mazy # Date 1789629150 -7200 # Node ID e942f6269e9f4efbb3f74ef28d6c61084b43798b # Parent 2cf181ce319a74529508d5aa8a8e752dbbb23070 optimized single resources FindRequest diff -r 2cf181ce319a -r e942f6269e9f Framework/Plugins/ISqlLookupFormatter.cpp --- a/Framework/Plugins/ISqlLookupFormatter.cpp Wed Sep 16 10:05:45 2026 +0200 +++ b/Framework/Plugins/ISqlLookupFormatter.cpp Thu Sep 17 09:12:30 2026 +0200 @@ -807,6 +807,11 @@ assert(upperLevel <= queryLevel && queryLevel <= lowerLevel); + const bool isOrthancIdentifiersDefined = (!request.orthanc_id_patient().empty() || + !request.orthanc_id_study().empty() || + !request.orthanc_id_series().empty() || + !request.orthanc_id_instance().empty()); + std::string orderingSql; std::string orderingJoins; @@ -878,7 +883,14 @@ } else { - orderingSql = "ROW_NUMBER() OVER (ORDER BY " + strQueryLevel + ".publicId) AS rowNumber"; // we need a default ordering in order to make default queries repeatable when using since&limit + if (isOrthancIdentifiersDefined && DetectLevel(request) == queryLevel) + { // this is a single resource, no need for ordering (ordering may prevents a lot of optimizations from the query planner) + orderingSql = "0 AS rowNumber"; + } + else + { + orderingSql = "ROW_NUMBER() OVER (ORDER BY " + strQueryLevel + ".publicId) AS rowNumber"; // we need a default ordering in order to make default queries repeatable when using since&limit + } } sql = ("SELECT " + @@ -890,11 +902,6 @@ std::string joins, comparisons; - const bool isOrthancIdentifiersDefined = (!request.orthanc_id_patient().empty() || - !request.orthanc_id_study().empty() || - !request.orthanc_id_series().empty() || - !request.orthanc_id_instance().empty()); - // handle parent constraints if (isOrthancIdentifiersDefined && Orthanc::IsResourceLevelAboveOrEqual(DetectLevel(request), queryLevel)) {